|
1 | 1 | import { assert, assertEquals, assertExists, assertMatch } from "@std/assert"; |
2 | 2 | import { refer } from "merkle-reference"; |
3 | | -import { SchemaContext } from "@commontools/runner"; |
| 3 | +import { JSONSchema, SchemaContext } from "@commontools/runner"; |
4 | 4 | import * as Changes from "../changes.ts"; |
5 | 5 | import * as Commit from "../commit.ts"; |
6 | 6 | import * as Fact from "../fact.ts"; |
@@ -2013,3 +2013,105 @@ test( |
2013 | 2013 | ); |
2014 | 2014 | }, |
2015 | 2015 | ); |
| 2016 | + |
| 2017 | +test( |
| 2018 | + "returns all entries from charm list", |
| 2019 | + DB, |
| 2020 | + async (session) => { |
| 2021 | + const charmSchema = { |
| 2022 | + type: "object", |
| 2023 | + properties: { |
| 2024 | + ["$NAME"]: { type: "string" }, |
| 2025 | + ["$UI"]: { type: "object" }, |
| 2026 | + }, |
| 2027 | + required: ["$UI", "$NAME"], |
| 2028 | + } as const satisfies JSONSchema; |
| 2029 | + |
| 2030 | + const charmListSchema = { |
| 2031 | + type: "array", |
| 2032 | + items: { ...charmSchema, asCell: true }, |
| 2033 | + } as const satisfies JSONSchema; |
| 2034 | + |
| 2035 | + const c1 = Fact.assert({ |
| 2036 | + the, |
| 2037 | + of: doc1, |
| 2038 | + is: { |
| 2039 | + "value": { "$NAME": "test 1", "$UI": { "type": "vnode" } }, |
| 2040 | + }, |
| 2041 | + }); |
| 2042 | + |
| 2043 | + const c2 = Fact.assert({ |
| 2044 | + the, |
| 2045 | + of: doc2, |
| 2046 | + is: { |
| 2047 | + "value": { "$NAME": "test 2", "$UI": { "type": "vnode" } }, |
| 2048 | + }, |
| 2049 | + }); |
| 2050 | + |
| 2051 | + const c_list = Fact.assert({ |
| 2052 | + the, |
| 2053 | + of: doc3, |
| 2054 | + is: { |
| 2055 | + "value": [ |
| 2056 | + { |
| 2057 | + "space": space.did(), |
| 2058 | + "cell": { "/": doc1.slice(3) }, |
| 2059 | + "path": [], |
| 2060 | + "schema": charmSchema, |
| 2061 | + }, |
| 2062 | + { |
| 2063 | + "space": space.did(), |
| 2064 | + "cell": { "/": doc2.slice(3) }, |
| 2065 | + "path": [], |
| 2066 | + "schema": charmSchema, |
| 2067 | + }, |
| 2068 | + ], |
| 2069 | + }, |
| 2070 | + }); |
| 2071 | + |
| 2072 | + const tr1 = Transaction.create({ |
| 2073 | + issuer: alice.did(), |
| 2074 | + subject: space.did(), |
| 2075 | + changes: Changes.from([c1, c2, c_list]), |
| 2076 | + }); |
| 2077 | + const write1 = await session.transact(tr1); |
| 2078 | + assert(write1.ok); |
| 2079 | + |
| 2080 | + const schemaSelector: SchemaSelector = { |
| 2081 | + [doc3]: { |
| 2082 | + [the]: { |
| 2083 | + _: { |
| 2084 | + path: [], |
| 2085 | + schemaContext: { |
| 2086 | + schema: charmListSchema, |
| 2087 | + rootSchema: charmListSchema, |
| 2088 | + }, |
| 2089 | + }, |
| 2090 | + }, |
| 2091 | + }, |
| 2092 | + }; |
| 2093 | + |
| 2094 | + const result = session.querySchema({ |
| 2095 | + cmd: "/memory/graph/query", |
| 2096 | + iss: alice.did(), |
| 2097 | + sub: space.did(), |
| 2098 | + args: { |
| 2099 | + selectSchema: schemaSelector, |
| 2100 | + }, |
| 2101 | + prf: [], |
| 2102 | + }); |
| 2103 | + |
| 2104 | + assertExists( |
| 2105 | + getResultForDoc(result, space.did(), doc1), |
| 2106 | + "doc1 should be in the result", |
| 2107 | + ); |
| 2108 | + assertExists( |
| 2109 | + getResultForDoc(result, space.did(), doc2), |
| 2110 | + "doc2 should be in the result", |
| 2111 | + ); |
| 2112 | + assertExists( |
| 2113 | + getResultForDoc(result, space.did(), doc3), |
| 2114 | + "doc3 should be in the result", |
| 2115 | + ); |
| 2116 | + }, |
| 2117 | +); |
0 commit comments