@agentshouse/mdruntime 0.1.0-alpha.24 → 0.1.0-alpha.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +36 -0
- package/dist/change-set.d.ts +4 -11
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +8 -16
- package/dist/change-set.js.map +1 -1
- package/dist/client.d.ts +7 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -2
- package/dist/client.js.map +1 -1
- package/dist/collection.d.ts +0 -2
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +0 -5
- package/dist/collection.js.map +1 -1
- package/dist/connection.d.ts +7 -5
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +52 -68
- package/dist/connection.js.map +1 -1
- package/dist/conversation.d.ts +4 -4
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +12 -6
- package/dist/conversation.js.map +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +8 -0
- package/dist/paths.js.map +1 -1
- package/dist/query.d.ts +199 -10
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +450 -14
- package/dist/query.js.map +1 -1
- package/dist/read-side.d.ts +10 -0
- package/dist/read-side.d.ts.map +1 -0
- package/dist/read-side.js +374 -0
- package/dist/read-side.js.map +1 -0
- package/dist/rows.d.ts +39 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +85 -0
- package/dist/rows.js.map +1 -0
- package/dist/wire.d.ts +1 -1
- package/dist/wire.js +1 -1
- package/dist/wire.js.map +1 -1
- package/package.json +2 -2
package/dist/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime/src/query.ts"],"sourcesContent":["import type { QueryOptions, QueryResult } from '@agentshouse/query';\nimport type { Document } from '@agentshouse/mdmodel';\nimport type { TypesResult } from './model.js';\n\nexport type QueryInput = {\n room: string;\n roomVersion: string;\n documents: Readonly<Record<string, Document>>;\n model: TypesResult;\n typedSelection: TypesResult | null;\n};\nexport type QueryBinding = (rooms: readonly QueryInput[], options: QueryOptions) => QueryResult;\nexport function rawQuery(rooms: readonly QueryInput[]): QueryResult {\n return {\n roomVersions: Object.fromEntries(rooms.map((room) => [room.room, room.roomVersion])),\n groups: null,\n documents: rooms.flatMap((room) =>\n Object.entries(room.documents)\n .filter(([path]) => path.endsWith('.md'))\n .map(([path, document]) => ({\n ...structuredClone(document),\n type: document.type ?? 'any',\n room: room.room,\n path,\n backlinks: [],\n })),\n ),\n };\n}\n"],"names":["rawQuery","rooms","roomVersions","Object","fromEntries","map","room","roomVersion","groups","documents","flatMap","entries","filter","path","endsWith","document","structuredClone","type","backlinks"],"mappings":"AAYA,OAAO,SAASA,SAASC,KAA4B;IACnD,OAAO;QACLC,cAAcC,OAAOC,WAAW,CAACH,MAAMI,GAAG,CAAC,CAACC,OAAS;gBAACA,KAAKA,IAAI;gBAAEA,KAAKC,WAAW;aAAC;QAClFC,QAAQ;QACRC,WAAWR,MAAMS,OAAO,CAAC,CAACJ,OACxBH,OAAOQ,OAAO,CAACL,KAAKG,SAAS,EAC1BG,MAAM,CAAC,CAAC,CAACC,KAAK,GAAKA,KAAKC,QAAQ,CAAC,QACjCT,GAAG,CAAC,CAAC,CAACQ,MAAME,SAAS,GAAM,CAAA;oBAC1B,GAAGC,gBAAgBD,SAAS;oBAC5BE,MAAMF,SAASE,IAAI,IAAI;oBACvBX,MAAMA,KAAKA,IAAI;oBACfO;oBACAK,WAAW,EAAE;gBACf,CAAA;IAEN;AACF"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime/src/query.ts"],"sourcesContent":["import type { Definition, FieldSpec } from '@agentshouse/mdmodel';\nimport { normalize } from './paths.js';\n\nexport type Value = string | number | boolean | null;\n\nexport type Predicate =\n | Value\n | { $eq: Value }\n | { $ne: Value }\n | { $in: readonly Value[] }\n | { $nin: readonly Value[] }\n | { $gt?: Value; $gte?: Value; $lt?: Value; $lte?: Value }\n | { $all: readonly Value[] }\n | { $size: number }\n | { $exists: boolean };\n\nexport type Where = {\n $and?: readonly Where[];\n $or?: readonly Where[];\n [field: string]: Predicate | readonly Where[] | undefined;\n};\n\nexport type Related = { types?: readonly string[]; where?: Where; pathPrefix?: string };\n\nexport type Filter = {\n rooms?: readonly string[];\n types?: readonly string[];\n where?: Where;\n pathPrefix?: string;\n hop?: Related & { field: string };\n backlinks?: Related & { field?: string };\n};\n\nexport type Key = 'room' | 'path' | 'type' | { field: string };\n\nexport type Select =\n | 'all'\n | {\n fields?: 'all' | readonly string[];\n sections?: 'all' | readonly string[];\n preamble?: true;\n markdown?: true;\n backlinks?: true;\n };\n\nexport type OrderOptions = {\n nulls?: 'first' | 'last';\n stringSort?: 'lexical' | 'locale';\n locale?: string;\n localeOptions?: Readonly<Record<string, unknown>>;\n};\n\nexport type Direction = 'asc' | 'desc';\n\nexport type DocumentQuery = Filter & {\n select: Select;\n orderBy?: readonly ({ by: Key; direction?: Direction } & OrderOptions)[];\n limit?: number;\n};\n\nexport type GroupQuery = Filter & {\n groupBy: readonly Exclude<Key, 'path'>[];\n orderBy?: readonly { by: 'count' | Exclude<Key, 'path'>; direction?: Direction }[];\n limit?: number;\n};\n\nexport type LocalQuery = DocumentQuery | GroupQuery;\n\nexport type Backlink = { path: string; type: string; field: string };\n\nexport type QueryDocument = {\n room: string;\n path: string;\n type: string;\n fields?: Readonly<Record<string, unknown>>;\n sections?: Readonly<Record<string, string>>;\n preamble?: string;\n markdown?: string;\n backlinks?: readonly Backlink[];\n};\n\nexport type QueryGroup = { key: readonly unknown[]; count: number };\n\nexport type DocumentResult = { documents: readonly QueryDocument[] };\n\nexport type GroupResult = { groups: readonly QueryGroup[] };\n\nexport type QueryResult = DocumentResult | GroupResult;\n\nexport type QueryErrorCode = 'invalid-query' | 'unknown-type' | 'unknown-field' | 'wrong-kind';\n\nexport type RoomFacts = {\n locator: string;\n available: boolean;\n types: readonly Definition[];\n};\n\nexport type HeldRooms = {\n listed: boolean;\n rooms: readonly RoomFacts[];\n};\n\nexport type Test =\n | { op: 'eq'; value: Value }\n | { op: 'ne'; value: Value }\n | { op: 'in'; values: readonly Value[] }\n | { op: 'nin'; values: readonly Value[] }\n | { op: 'range'; bounds: readonly (readonly ['gt' | 'gte' | 'lt' | 'lte', Value])[] }\n | { op: 'all'; values: readonly Value[] }\n | { op: 'size'; size: number }\n | { op: 'exists'; exists: boolean };\n\nexport type Condition =\n | { every: readonly Condition[] }\n | { some: readonly Condition[] }\n | { field: string; test: Test };\n\nexport type Scope = {\n types: readonly string[] | null;\n where: Condition | null;\n pathPrefix: string | null;\n};\n\nexport type KeyPlan =\n | { of: 'room' }\n | { of: 'path' }\n | { of: 'type' }\n | { of: 'field'; field: string };\n\nexport type DocumentShape = {\n kind: 'documents';\n fields: 'all' | readonly string[] | null;\n sections: 'all' | readonly string[] | null;\n preamble: boolean;\n markdown: boolean;\n backlinks: boolean;\n orderBy: readonly { key: KeyPlan; options: OrderOptions & { direction: Direction } }[];\n};\n\nexport type GroupShape = {\n kind: 'groups';\n groupBy: readonly KeyPlan[];\n orderBy: readonly { by: 'count' | number; direction: Direction }[];\n};\n\nexport type Plan = {\n rooms: readonly string[] | null;\n root: Scope;\n hop: (Scope & { field: string }) | null;\n backlinks: (Scope & { field: string | null }) | null;\n shape: DocumentShape | GroupShape;\n limit: number | null;\n};\n\nexport class QueryError extends Error {\n constructor(code: QueryErrorCode, at: string, problem: string) {\n super(`${code} at ${at}: ${problem}`);\n }\n}\n\ntype Entries = Readonly<Record<string, unknown>>;\n\ntype Typing = { untyped: boolean; types: readonly Definition[] };\n\nconst RANGE = ['$gt', '$gte', '$lt', '$lte'] as const;\nconst SINGLE = ['$eq', '$ne', '$in', '$nin', '$all', '$size', '$exists'] as const;\nconst FILTER = ['rooms', 'types', 'where', 'pathPrefix', 'hop', 'backlinks', 'orderBy', 'limit'];\nconst RELATED = ['types', 'where', 'pathPrefix', 'field'];\nconst PARTS = ['fields', 'sections', 'preamble', 'markdown', 'backlinks'];\nconst ORDER = ['by', 'direction', 'nulls', 'stringSort', 'locale', 'localeOptions'];\nconst CALENDAR_DATE = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\n\nfunction invalid(at: string, problem: string): never {\n throw new QueryError('invalid-query', at, problem);\n}\n\nfunction place(at: string, name: string): string {\n return at === '' ? name : `${at}.${name}`;\n}\n\nfunction plain(value: unknown): value is Entries {\n return (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)\n );\n}\n\nfunction known(value: Entries, allowed: readonly string[], at: string) {\n for (const name of Object.keys(value)) {\n if (!allowed.includes(name)) invalid(place(at, name), 'unknown part');\n }\n}\n\nfunction list(input: unknown, at: string): readonly unknown[] {\n if (!Array.isArray(input)) invalid(at, 'expects a list');\n return input;\n}\n\nfunction value(input: unknown, at: string): Value {\n if (Array.isArray(input)) invalid(at, 'a list is not a value');\n if (\n input !== null &&\n typeof input !== 'string' &&\n typeof input !== 'boolean' &&\n !(typeof input === 'number' && Number.isFinite(input))\n ) {\n invalid(at, 'not a value');\n }\n return input;\n}\n\nfunction values(input: unknown, at: string): readonly Value[] {\n return list(input, at).map((item, index) => value(item, `${at}[${index}]`));\n}\n\nfunction names(input: unknown, at: string): readonly string[] {\n const listed = list(input, at);\n if (listed.some((item) => typeof item !== 'string')) invalid(at, 'expects a list of names');\n return [...new Set(listed as readonly string[])].sort();\n}\n\nfunction directory(input: unknown, at: string): string {\n if (typeof input !== 'string' || normalize(input) !== input) {\n invalid(at, 'expects a normalized directory');\n }\n return input;\n}\n\nfunction calendarDate(value: string): boolean {\n const match = CALENDAR_DATE.exec(value);\n if (match === null) return false;\n const [year, month, day] = match.slice(1).map(Number);\n const date = new Date(Date.UTC(year, month - 1, day));\n return (\n date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day\n );\n}\n\nfunction fits(spec: FieldSpec, value: Value): boolean {\n const item = spec.kind === 'list' ? spec.of : spec;\n if (item.kind === 'number') return typeof value === 'number';\n if (typeof value !== 'string') return false;\n if (item.kind === 'enum') return item.values.includes(value);\n if (item.kind === 'date') return calendarDate(value);\n if (item.kind === 'reference') return value !== '' && normalize(value) === value;\n return true;\n}\n\nfunction reference(spec: FieldSpec): boolean {\n return spec.kind === 'reference' || (spec.kind === 'list' && spec.of.kind === 'reference');\n}\n\nfunction typing(\n facts: HeldRooms,\n rooms: readonly string[] | null,\n types: readonly string[] | null,\n at: string,\n): Typing {\n const read =\n rooms === null ? facts.rooms : facts.rooms.filter((room) => rooms.includes(room.locator));\n const acquiring =\n !facts.listed &&\n (rooms === null ||\n rooms.some((locator) => !facts.rooms.some((room) => room.locator === locator)));\n const available = !acquiring && read.every((room) => room.available);\n const declared = read.flatMap((room) => room.types);\n for (const name of types ?? []) {\n if (name === 'any' || !available || declared.some((type) => type.name === name)) continue;\n throw new QueryError('unknown-type', place(at, 'types'), `no model it reads declares ${name}`);\n }\n return {\n untyped: types === null || types.includes('any') || !available,\n types: types === null ? declared : declared.filter((type) => types.includes(type.name)),\n };\n}\n\nfunction specs(typed: Typing, field: string, at: string): readonly FieldSpec[] {\n const declared = typed.types.flatMap((type) =>\n Object.hasOwn(type.fields, field) ? [type.fields[field]] : [],\n );\n if (declared.length === 0 && !typed.untyped) {\n throw new QueryError('unknown-field', at, `no MD Type it reads declares ${field}`);\n }\n return declared;\n}\n\nfunction kind(declared: readonly FieldSpec[], checked: Value, at: string) {\n if (checked === null || declared.length === 0 || declared.some((spec) => fits(spec, checked))) {\n return;\n }\n throw new QueryError('wrong-kind', at, `${JSON.stringify(checked)} is not of its field's kind`);\n}\n\nfunction listed(declared: readonly FieldSpec[], list: boolean): boolean {\n return declared.length > 0 && declared.every((spec) => (spec.kind === 'list') === list);\n}\n\nfunction test(declared: readonly FieldSpec[], input: unknown, at: string): Test {\n if (!plain(input)) {\n const equal = value(input, at);\n kind(declared, equal, at);\n return { op: 'eq', value: equal };\n }\n const operators = Object.keys(input);\n if (operators.length === 0) invalid(at, 'names no operator');\n if (operators.some((operator) => (RANGE as readonly string[]).includes(operator))) {\n const stray = operators.find((operator) => !(RANGE as readonly string[]).includes(operator));\n if (stray !== undefined) invalid(place(at, stray), 'cannot join a range');\n if (listed(declared, true)) invalid(at, 'a range on a list');\n return {\n op: 'range',\n bounds: RANGE.filter((operator) => operators.includes(operator)).map((operator) => {\n const bound = value(input[operator], place(at, operator));\n if (bound === null) invalid(place(at, operator), 'a range bound is never null');\n kind(declared, bound, place(at, operator));\n return [operator.slice(1) as 'gt' | 'gte' | 'lt' | 'lte', bound] as const;\n }),\n };\n }\n if (operators.length > 1) invalid(place(at, operators[1]), 'names a second operator');\n const [operator] = operators;\n const where = place(at, operator);\n if (!(SINGLE as readonly string[]).includes(operator)) invalid(where, 'unknown operator');\n const operand = input[operator];\n if (operator === '$eq' || operator === '$ne') {\n const compared = value(operand, where);\n kind(declared, compared, where);\n return operator === '$eq' ? { op: 'eq', value: compared } : { op: 'ne', value: compared };\n }\n if (operator === '$in' || operator === '$nin' || operator === '$all') {\n const compared = values(operand, where);\n compared.forEach((item, index) => kind(declared, item, `${where}[${index}]`));\n if (operator === '$in') return { op: 'in', values: compared };\n if (operator === '$nin') return { op: 'nin', values: compared };\n if (compared.includes(null)) invalid(where, 'a list holds no null');\n if (listed(declared, false)) invalid(where, 'the field is not a list');\n return { op: 'all', values: compared };\n }\n if (operator === '$size') {\n if (!Number.isSafeInteger(operand) || (operand as number) < 0) {\n invalid(where, 'expects a nonnegative integer');\n }\n if (listed(declared, false)) invalid(where, 'the field is not a list');\n return { op: 'size', size: operand as number };\n }\n if (typeof operand !== 'boolean') invalid(where, 'expects true or false');\n return { op: 'exists', exists: operand };\n}\n\nfunction condition(typed: Typing, input: unknown, at: string): Condition {\n if (!plain(input)) invalid(at, 'expects an object of field predicates');\n const conditions: Condition[] = [];\n for (const name of Object.keys(input).sort()) {\n const where = place(at, name);\n const entry = input[name];\n if (name === '$and' || name === '$or') {\n const nested = list(entry, where).map((item, index) =>\n condition(typed, item, `${where}[${index}]`),\n );\n if (nested.length === 0) invalid(where, 'expects a nonempty list');\n conditions.push(name === '$and' ? { every: nested } : { some: nested });\n continue;\n }\n if (name.startsWith('$')) invalid(where, 'unknown operator');\n conditions.push({ field: name, test: test(specs(typed, name, where), entry, where) });\n }\n if (conditions.length === 0) invalid(at, 'names no field');\n return conditions.length === 1 ? conditions[0] : { every: conditions };\n}\n\nfunction scope(\n facts: HeldRooms,\n rooms: readonly string[] | null,\n input: Entries,\n at: string,\n): Scope & { typed: Typing } {\n const types = input.types === undefined ? null : names(input.types, place(at, 'types'));\n const typed = typing(facts, rooms, types, at);\n return {\n typed,\n types,\n where:\n input.where === undefined || (plain(input.where) && Object.keys(input.where).length === 0)\n ? null\n : condition(typed, input.where, place(at, 'where')),\n pathPrefix:\n input.pathPrefix === undefined ? null : directory(input.pathPrefix, place(at, 'pathPrefix')),\n };\n}\n\nfunction referenceField(typed: Typing, field: unknown, at: string): string {\n if (typeof field !== 'string') invalid(at, 'expects a field name');\n const declared = specs(typed, field, at);\n if (declared.length > 0 && !declared.some(reference)) invalid(at, 'not a reference field');\n return field;\n}\n\nfunction hopOf(\n facts: HeldRooms,\n rooms: readonly string[] | null,\n root: Typing,\n input: unknown,\n): Plan['hop'] {\n if (!plain(input)) invalid('hop', 'expects an object');\n known(input, RELATED, 'hop');\n const field = referenceField(root, input.field, 'hop.field');\n const { types, where, pathPrefix } = scope(facts, rooms, input, 'hop');\n return { types, where, pathPrefix, field };\n}\n\nfunction backlinksOf(\n facts: HeldRooms,\n rooms: readonly string[] | null,\n input: unknown,\n): Plan['backlinks'] {\n if (!plain(input)) invalid('backlinks', 'expects an object');\n known(input, RELATED, 'backlinks');\n const { typed, types, where, pathPrefix } = scope(facts, rooms, input, 'backlinks');\n const field =\n input.field === undefined ? null : referenceField(typed, input.field, 'backlinks.field');\n return { types, where, pathPrefix, field };\n}\n\nfunction keyPlan(typed: Typing, input: unknown, at: string, path: boolean): KeyPlan {\n if (input === 'room' || input === 'type' || (path && input === 'path')) return { of: input };\n if (plain(input) && typeof input.field === 'string' && Object.keys(input).length === 1) {\n specs(typed, input.field, place(at, 'field'));\n return { of: 'field', field: input.field };\n }\n return invalid(\n at,\n path ? 'expects room, path, type or a field' : 'expects room, type or a field',\n );\n}\n\nfunction direction(input: unknown, at: string): Direction {\n if (input === undefined) return 'asc';\n if (input !== 'asc' && input !== 'desc') invalid(at, 'expects asc or desc');\n return input;\n}\n\nfunction orderOptions(input: Entries, at: string): OrderOptions & { direction: Direction } {\n const options: OrderOptions & { direction: Direction } = {\n direction: direction(input.direction, place(at, 'direction')),\n };\n if (input.nulls !== undefined) {\n if (input.nulls !== 'first' && input.nulls !== 'last') {\n invalid(place(at, 'nulls'), 'expects first or last');\n }\n options.nulls = input.nulls;\n }\n if (input.stringSort !== undefined) {\n if (input.stringSort !== 'lexical' && input.stringSort !== 'locale') {\n invalid(place(at, 'stringSort'), 'expects lexical or locale');\n }\n options.stringSort = input.stringSort;\n }\n if (input.locale !== undefined) {\n if (typeof input.locale !== 'string' || !collates(input.locale, undefined)) {\n invalid(place(at, 'locale'), 'expects a locale name');\n }\n options.locale = input.locale;\n }\n if (input.localeOptions !== undefined) {\n if (!plain(input.localeOptions) || !collates(options.locale, input.localeOptions)) {\n invalid(place(at, 'localeOptions'), 'expects collation options');\n }\n options.localeOptions = input.localeOptions;\n }\n return options;\n}\n\nfunction collates(locale: string | undefined, options: Entries | undefined): boolean {\n try {\n ''.localeCompare('', locale, options);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction parts(typed: Typing, input: unknown, at: string, fields: boolean) {\n if (input === undefined) return null;\n if (input === 'all') return 'all';\n const named = list(input, at);\n named.forEach((name, index) => {\n if (typeof name !== 'string') invalid(`${at}[${index}]`, 'expects a name');\n if (fields) specs(typed, name, `${at}[${index}]`);\n });\n return named as readonly string[];\n}\n\nfunction flag(input: unknown, at: string): boolean {\n if (input === undefined) return false;\n if (input !== true) invalid(at, 'expects true');\n return true;\n}\n\nfunction documentShape(typed: Typing, input: Entries): DocumentShape {\n const orderBy = (input.orderBy === undefined ? [] : list(input.orderBy, 'orderBy')).map(\n (clause, index) => {\n const at = `orderBy[${index}]`;\n if (!plain(clause)) invalid(at, 'expects an order clause');\n known(clause, ORDER, at);\n return {\n key: keyPlan(typed, clause.by, place(at, 'by'), true),\n options: orderOptions(clause, at),\n };\n },\n );\n const select = input.select;\n if (select === 'all') {\n return {\n kind: 'documents',\n fields: 'all',\n sections: 'all',\n preamble: true,\n markdown: true,\n backlinks: true,\n orderBy,\n };\n }\n if (!plain(select)) invalid('select', \"expects 'all' or the parts to return\");\n known(select, PARTS, 'select');\n return {\n kind: 'documents',\n fields: parts(typed, select.fields, 'select.fields', true),\n sections: parts(typed, select.sections, 'select.sections', false),\n preamble: flag(select.preamble, 'select.preamble'),\n markdown: flag(select.markdown, 'select.markdown'),\n backlinks: flag(select.backlinks, 'select.backlinks'),\n orderBy,\n };\n}\n\nfunction groupShape(typed: Typing, input: Entries): GroupShape {\n const groupBy = list(input.groupBy, 'groupBy').map((key, index) =>\n keyPlan(typed, key, `groupBy[${index}]`, false),\n );\n if (groupBy.length === 0) invalid('groupBy', 'names no key');\n const grouped = groupBy.map((key) => JSON.stringify(key));\n const orderBy = (input.orderBy === undefined ? [] : list(input.orderBy, 'orderBy')).map(\n (clause, index) => {\n const at = `orderBy[${index}]`;\n if (!plain(clause)) invalid(at, 'expects an order clause');\n known(clause, ['by', 'direction'], at);\n const by =\n clause.by === 'count'\n ? ('count' as const)\n : grouped.indexOf(JSON.stringify(keyPlan(typed, clause.by, place(at, 'by'), false)));\n if (by === -1) invalid(place(at, 'by'), 'orders by a key the query does not group by');\n return { by, direction: direction(clause.direction, place(at, 'direction')) };\n },\n );\n return { kind: 'groups', groupBy, orderBy };\n}\n\nexport function planOf(input: unknown, facts: HeldRooms): Plan {\n if (!plain(input)) invalid('query', 'expects a query object');\n const grouped = input.groupBy !== undefined;\n if (grouped && input.select !== undefined) invalid('select', 'a grouped query selects nothing');\n if (!grouped && input.select === undefined) invalid('select', 'a Document query must select');\n known(input, [...FILTER, grouped ? 'groupBy' : 'select'], '');\n if (\n input.limit !== undefined &&\n (!Number.isSafeInteger(input.limit) || (input.limit as number) < 0)\n ) {\n invalid('limit', 'expects a nonnegative integer');\n }\n const rooms = input.rooms === undefined ? null : names(input.rooms, 'rooms');\n const { typed, ...root } = scope(facts, rooms, input, '');\n return {\n rooms,\n root,\n hop: input.hop === undefined ? null : hopOf(facts, rooms, typed, input.hop),\n backlinks: input.backlinks === undefined ? null : backlinksOf(facts, rooms, input.backlinks),\n shape: grouped ? groupShape(typed, input) : documentShape(typed, input),\n limit: (input.limit as number | undefined) ?? null,\n };\n}\n\nfunction canonical(value: unknown): string {\n if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;\n if (typeof value === 'object' && value !== null) {\n return `{${Object.keys(value)\n .sort()\n .map((name) => `${JSON.stringify(name)}:${canonical((value as Entries)[name])}`)\n .join(',')}}`;\n }\n return JSON.stringify(value);\n}\n\nexport function identityOf(plan: Plan): string {\n return canonical(plan);\n}\n"],"names":["normalize","QueryError","Error","code","at","problem","RANGE","SINGLE","FILTER","RELATED","PARTS","ORDER","CALENDAR_DATE","invalid","place","name","plain","value","Array","isArray","Object","getPrototypeOf","prototype","known","allowed","keys","includes","list","input","Number","isFinite","values","map","item","index","names","listed","some","Set","sort","directory","calendarDate","match","exec","year","month","day","slice","date","Date","UTC","getUTCFullYear","getUTCMonth","getUTCDate","fits","spec","kind","of","reference","typing","facts","rooms","types","read","filter","room","locator","acquiring","available","every","declared","flatMap","type","untyped","specs","typed","field","hasOwn","fields","length","checked","JSON","stringify","test","equal","op","operators","operator","stray","find","undefined","bounds","bound","where","operand","compared","forEach","isSafeInteger","size","exists","condition","conditions","entry","nested","push","startsWith","scope","pathPrefix","referenceField","hopOf","root","backlinksOf","keyPlan","path","direction","orderOptions","options","nulls","stringSort","locale","collates","localeOptions","localeCompare","parts","named","flag","documentShape","orderBy","clause","key","by","select","sections","preamble","markdown","backlinks","groupShape","groupBy","grouped","indexOf","planOf","limit","hop","shape","canonical","join","identityOf","plan"],"mappings":"AACA,SAASA,SAAS,QAAQ,aAAa;AAyJvC,OAAO,MAAMC,mBAAmBC;IAC9B,YAAYC,IAAoB,EAAEC,EAAU,EAAEC,OAAe,CAAE;QAC7D,KAAK,CAAC,GAAGF,KAAK,IAAI,EAAEC,GAAG,EAAE,EAAEC,SAAS;IACtC;AACF;AAMA,MAAMC,QAAQ;IAAC;IAAO;IAAQ;IAAO;CAAO;AAC5C,MAAMC,SAAS;IAAC;IAAO;IAAO;IAAO;IAAQ;IAAQ;IAAS;CAAU;AACxE,MAAMC,SAAS;IAAC;IAAS;IAAS;IAAS;IAAc;IAAO;IAAa;IAAW;CAAQ;AAChG,MAAMC,UAAU;IAAC;IAAS;IAAS;IAAc;CAAQ;AACzD,MAAMC,QAAQ;IAAC;IAAU;IAAY;IAAY;IAAY;CAAY;AACzE,MAAMC,QAAQ;IAAC;IAAM;IAAa;IAAS;IAAc;IAAU;CAAgB;AACnF,MAAMC,gBAAgB;AAEtB,SAASC,QAAQT,EAAU,EAAEC,OAAe;IAC1C,MAAM,IAAIJ,WAAW,iBAAiBG,IAAIC;AAC5C;AAEA,SAASS,MAAMV,EAAU,EAAEW,IAAY;IACrC,OAAOX,OAAO,KAAKW,OAAO,GAAGX,GAAG,CAAC,EAAEW,MAAM;AAC3C;AAEA,SAASC,MAAMC,KAAc;IAC3B,OACE,OAAOA,UAAU,YACjBA,UAAU,QACV,CAACC,MAAMC,OAAO,CAACF,UACdG,CAAAA,OAAOC,cAAc,CAACJ,WAAWG,OAAOE,SAA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AMiC,KAAK,KAAK6B,YAAY,OAAOvD,MAAMP,MAAMiC,KAAK,EAAE;IACpE,MAAM,EAAEc,KAAK,EAAE,GAAGmC,MAAM,GAAGJ,MAAM9C,OAAOC,OAAOjC,OAAO;IACtD,OAAO;QACLiC;QACAiD;QACAgC,KAAKlH,MAAMkH,GAAG,KAAKpD,YAAY,OAAOmB,MAAMjD,OAAOC,OAAOc,OAAO/C,MAAMkH,GAAG;QAC1EP,WAAW3G,MAAM2G,SAAS,KAAK7C,YAAY,OAAOqB,YAAYnD,OAAOC,OAAOjC,MAAM2G,SAAS;QAC3FQ,OAAOL,UAAUF,WAAW7D,OAAO/C,SAASkG,cAAcnD,OAAO/C;QACjEiH,OAAO,AAACjH,MAAMiH,KAAK,IAA2B;IAChD;AACF;AAEA,SAASG,UAAU/H,KAAc;IAC/B,IAAIC,MAAMC,OAAO,CAACF,QAAQ,OAAO,CAAC,CAAC,EAAEA,MAAMe,GAAG,CAACgH,WAAWC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtE,IAAI,OAAOhI,UAAU,YAAYA,UAAU,MAAM;QAC/C,OAAO,CAAC,CAAC,EAAEG,OAAOK,IAAI,CAACR,OACpBsB,IAAI,GACJP,GAAG,CAAC,CAACjB,OAAS,GAAGkE,KAAKC,SAAS,CAACnE,MAAM,CAAC,EAAEiI,UAAU,AAAC/H,KAAiB,CAACF,KAAK,GAAG,EAC9EkI,IAAI,CAAC,KAAK,CAAC,CAAC;IACjB;IACA,OAAOhE,KAAKC,SAAS,CAACjE;AACxB;AAEA,OAAO,SAASiI,WAAWC,IAAU;IACnC,OAAOH,UAAUG;AACnB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ChangeSet } from './change-set.js';
|
|
2
|
+
import type { Plan, QueryResult } from './query.js';
|
|
3
|
+
export type ReadSide = {
|
|
4
|
+
apply(set: ChangeSet): void;
|
|
5
|
+
query(plan: Plan): Promise<QueryResult>;
|
|
6
|
+
observe(plan: Plan, identity: string, listener: (result: QueryResult) => void): () => void;
|
|
7
|
+
close(): void;
|
|
8
|
+
};
|
|
9
|
+
export declare function createReadSide(): ReadSide;
|
|
10
|
+
//# sourceMappingURL=read-side.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-side.d.ts","sourceRoot":"","sources":["../src/read-side.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAOV,IAAI,EAEJ,WAAW,EAIZ,MAAM,YAAY,CAAC;AAqDpB,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC3F,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAqPF,wBAAgB,cAAc,IAAI,QAAQ,CAgGzC"}
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { and, BasicIndex, configureIndexDevMode, count, createCollection, createLiveQueryCollection, deepEquals, eq, gt, gte, inArray, isNull, isUndefined, lt, lte, not, or, toArray } from '@tanstack/db';
|
|
2
|
+
function every(expressions) {
|
|
3
|
+
const [first, second, ...rest] = expressions;
|
|
4
|
+
return second === undefined ? first : and(first, second, ...rest);
|
|
5
|
+
}
|
|
6
|
+
function some(expressions) {
|
|
7
|
+
const [first, second, ...rest] = expressions;
|
|
8
|
+
return second === undefined ? first : or(first, second, ...rest);
|
|
9
|
+
}
|
|
10
|
+
function equal(field, value) {
|
|
11
|
+
return or(eq(field, value), inArray(value, field));
|
|
12
|
+
}
|
|
13
|
+
function tested(test, field, size, written) {
|
|
14
|
+
if (test.op === 'eq') return test.value === null ? isNull(field) : equal(field, test.value);
|
|
15
|
+
if (test.op === 'ne') {
|
|
16
|
+
return test.value === null ? not(isNull(field)) : or(isUndefined(field), isNull(field), not(equal(field, test.value)));
|
|
17
|
+
}
|
|
18
|
+
if (test.op === 'in' || test.op === 'nin') {
|
|
19
|
+
const matches = test.values.length === 0 ? inArray(field, []) : some(test.values.map((value)=>value === null ? isNull(field) : equal(field, value)));
|
|
20
|
+
if (test.op === 'in') return matches;
|
|
21
|
+
return some([
|
|
22
|
+
isUndefined(field),
|
|
23
|
+
...test.values.includes(null) ? [] : [
|
|
24
|
+
isNull(field)
|
|
25
|
+
],
|
|
26
|
+
not(matches)
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
if (test.op === 'range') {
|
|
30
|
+
const compare = {
|
|
31
|
+
gt,
|
|
32
|
+
gte,
|
|
33
|
+
lt,
|
|
34
|
+
lte
|
|
35
|
+
};
|
|
36
|
+
return every(test.bounds.map(([operator, bound])=>compare[operator](field, bound)));
|
|
37
|
+
}
|
|
38
|
+
if (test.op === 'all') {
|
|
39
|
+
return every([
|
|
40
|
+
not(isUndefined(size)),
|
|
41
|
+
...test.values.map((value)=>inArray(value, field))
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
if (test.op === 'size') return eq(size, test.size);
|
|
45
|
+
return test.exists ? not(isUndefined(written)) : isUndefined(written);
|
|
46
|
+
}
|
|
47
|
+
function conditioned(condition, row) {
|
|
48
|
+
if ('every' in condition) return every(condition.every.map((item)=>conditioned(item, row)));
|
|
49
|
+
if ('some' in condition) return some(condition.some.map((item)=>conditioned(item, row)));
|
|
50
|
+
return tested(condition.test, row.values[condition.field], row.sizes[condition.field], row.fields[condition.field]);
|
|
51
|
+
}
|
|
52
|
+
function scoped(scope, row, rooms) {
|
|
53
|
+
return every([
|
|
54
|
+
eq(row.kind, 'document'),
|
|
55
|
+
...rooms === null ? [] : [
|
|
56
|
+
inArray(row.room, [
|
|
57
|
+
...rooms
|
|
58
|
+
])
|
|
59
|
+
],
|
|
60
|
+
...scope.types === null ? [] : [
|
|
61
|
+
inArray(row.type, [
|
|
62
|
+
...scope.types
|
|
63
|
+
])
|
|
64
|
+
],
|
|
65
|
+
...scope.pathPrefix === null ? [] : [
|
|
66
|
+
inArray(scope.pathPrefix, row.directories)
|
|
67
|
+
],
|
|
68
|
+
...scope.where === null ? [] : [
|
|
69
|
+
conditioned(scope.where, row)
|
|
70
|
+
]
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
73
|
+
function keyed(key, row) {
|
|
74
|
+
return key.of === 'field' ? row.values[key.field] : row[key.of];
|
|
75
|
+
}
|
|
76
|
+
function live(query) {
|
|
77
|
+
return createLiveQueryCollection({
|
|
78
|
+
query: query,
|
|
79
|
+
startSync: true
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function related(q, rows, scope, field, kept) {
|
|
83
|
+
const matched = kept === 'source' ? 'target' : 'source';
|
|
84
|
+
const from = q.from({
|
|
85
|
+
r: rows
|
|
86
|
+
});
|
|
87
|
+
return from.where(({ r })=>every([
|
|
88
|
+
eq(r.kind, 'reference'),
|
|
89
|
+
...field === null ? [] : [
|
|
90
|
+
eq(r.field, field)
|
|
91
|
+
]
|
|
92
|
+
])).innerJoin({
|
|
93
|
+
m: rows
|
|
94
|
+
}, ({ r, m })=>eq(r[matched], m.key)).where(({ m })=>scoped(scope, m, null)).groupBy(({ r })=>r[kept]).select(({ r })=>({
|
|
95
|
+
key: r[kept]
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
function filtered(q, rows, plan) {
|
|
99
|
+
const from = q.from({
|
|
100
|
+
d: rows
|
|
101
|
+
});
|
|
102
|
+
let query = from.where(({ d })=>scoped(plan.root, d, plan.rooms));
|
|
103
|
+
if (plan.hop !== null) {
|
|
104
|
+
const hop = related(q, rows, plan.hop, plan.hop.field, 'source');
|
|
105
|
+
query = query.innerJoin({
|
|
106
|
+
h: hop
|
|
107
|
+
}, ({ d, h })=>eq(d.key, h.key));
|
|
108
|
+
}
|
|
109
|
+
if (plan.backlinks !== null) {
|
|
110
|
+
const backlinks = related(q, rows, plan.backlinks, plan.backlinks.field, 'target');
|
|
111
|
+
query = query.innerJoin({
|
|
112
|
+
k: backlinks
|
|
113
|
+
}, ({ d, k })=>eq(d.key, k.key));
|
|
114
|
+
}
|
|
115
|
+
return query;
|
|
116
|
+
}
|
|
117
|
+
function named(prefix, names, source) {
|
|
118
|
+
return Object.fromEntries(names.map((name, index)=>[
|
|
119
|
+
`${prefix}${index}`,
|
|
120
|
+
source[name]
|
|
121
|
+
]));
|
|
122
|
+
}
|
|
123
|
+
function documents(q, rows, plan, shape) {
|
|
124
|
+
let query = filtered(q, rows, plan);
|
|
125
|
+
if (shape.sections !== null || shape.preamble || shape.markdown) {
|
|
126
|
+
query = query.innerJoin({
|
|
127
|
+
b: rows
|
|
128
|
+
}, ({ d, b })=>eq(d.body, b.key));
|
|
129
|
+
}
|
|
130
|
+
for (const { key, options } of shape.orderBy){
|
|
131
|
+
query = query.orderBy(({ d })=>keyed(key, d), options);
|
|
132
|
+
}
|
|
133
|
+
if (shape.orderBy.length === 0 && plan.limit !== null) {
|
|
134
|
+
query = query.orderBy(({ d })=>d.key, {
|
|
135
|
+
stringSort: 'lexical'
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (plan.limit !== null) query = query.limit(plan.limit);
|
|
139
|
+
return query.select(({ d, b })=>({
|
|
140
|
+
room: d.room,
|
|
141
|
+
path: d.path,
|
|
142
|
+
type: d.type,
|
|
143
|
+
...shape.fields === 'all' ? {
|
|
144
|
+
fields: d.fields
|
|
145
|
+
} : {},
|
|
146
|
+
...Array.isArray(shape.fields) ? named('field', shape.fields, d.fields) : {},
|
|
147
|
+
...shape.sections === 'all' ? {
|
|
148
|
+
sections: b.sections
|
|
149
|
+
} : {},
|
|
150
|
+
...Array.isArray(shape.sections) ? named('section', shape.sections, b.sections) : {},
|
|
151
|
+
...shape.preamble ? {
|
|
152
|
+
preamble: b.preamble
|
|
153
|
+
} : {},
|
|
154
|
+
...shape.markdown ? {
|
|
155
|
+
markdown: b.markdown
|
|
156
|
+
} : {},
|
|
157
|
+
...shape.backlinks ? {
|
|
158
|
+
backlinks: toArray(backlinked(q, rows, d))
|
|
159
|
+
} : {}
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
function backlinked(q, rows, document) {
|
|
163
|
+
const from = q.from({
|
|
164
|
+
r: rows
|
|
165
|
+
});
|
|
166
|
+
return from.where(({ r })=>eq(r.target, document.key)).orderBy(({ r })=>r.path, {
|
|
167
|
+
stringSort: 'lexical'
|
|
168
|
+
}).orderBy(({ r })=>r.field, {
|
|
169
|
+
stringSort: 'lexical'
|
|
170
|
+
}).select(({ r })=>({
|
|
171
|
+
path: r.path,
|
|
172
|
+
type: r.type,
|
|
173
|
+
field: r.field
|
|
174
|
+
}));
|
|
175
|
+
}
|
|
176
|
+
function groups(q, stage, shape, limit) {
|
|
177
|
+
const keys = shape.groupBy.map((_, index)=>`key${index}`);
|
|
178
|
+
const from = q.from({
|
|
179
|
+
m: stage
|
|
180
|
+
});
|
|
181
|
+
let query = from.groupBy(({ m })=>keys.map((key)=>m[key]));
|
|
182
|
+
for (const { by, direction } of shape.orderBy){
|
|
183
|
+
query = query.orderBy(({ m })=>by === 'count' ? count(m.key) : m[keys[by]], direction);
|
|
184
|
+
}
|
|
185
|
+
if (limit !== null && shape.orderBy.length > 0) query = query.limit(limit);
|
|
186
|
+
return query.select(({ m })=>({
|
|
187
|
+
...Object.fromEntries(keys.map((key)=>[
|
|
188
|
+
key,
|
|
189
|
+
m[key]
|
|
190
|
+
])),
|
|
191
|
+
count: count(m.key)
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
function built(rows, plan) {
|
|
195
|
+
const shape = plan.shape;
|
|
196
|
+
if (shape.kind === 'documents') {
|
|
197
|
+
const collection = live((q)=>documents(q, rows, plan, shape));
|
|
198
|
+
return {
|
|
199
|
+
live: collection,
|
|
200
|
+
dispose: ()=>void collection.cleanup()
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const stage = live((q)=>filtered(q, rows, plan).select(({ d })=>({
|
|
204
|
+
key: d.key,
|
|
205
|
+
...Object.fromEntries(shape.groupBy.map((key, index)=>[
|
|
206
|
+
`key${index}`,
|
|
207
|
+
keyed(key, d)
|
|
208
|
+
]))
|
|
209
|
+
})));
|
|
210
|
+
const collection = live((q)=>groups(q, stage, shape, plan.limit));
|
|
211
|
+
return {
|
|
212
|
+
live: collection,
|
|
213
|
+
dispose: ()=>{
|
|
214
|
+
void collection.cleanup();
|
|
215
|
+
void stage.cleanup();
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function present(entries) {
|
|
220
|
+
return Object.fromEntries(entries.filter(([, value])=>value !== undefined));
|
|
221
|
+
}
|
|
222
|
+
function part(row, prefix, names, whole) {
|
|
223
|
+
if (names === 'all') return whole;
|
|
224
|
+
return present(names.map((name, index)=>[
|
|
225
|
+
name,
|
|
226
|
+
row[`${prefix}${index}`]
|
|
227
|
+
]));
|
|
228
|
+
}
|
|
229
|
+
function documentOf(row, shape) {
|
|
230
|
+
return {
|
|
231
|
+
room: row.room,
|
|
232
|
+
path: row.path,
|
|
233
|
+
type: row.type,
|
|
234
|
+
...shape.fields === null ? {} : {
|
|
235
|
+
fields: part(row, 'field', shape.fields, row.fields)
|
|
236
|
+
},
|
|
237
|
+
...shape.sections === null ? {} : {
|
|
238
|
+
sections: part(row, 'section', shape.sections, row.sections)
|
|
239
|
+
},
|
|
240
|
+
...shape.preamble ? {
|
|
241
|
+
preamble: row.preamble
|
|
242
|
+
} : {},
|
|
243
|
+
...shape.markdown ? {
|
|
244
|
+
markdown: row.markdown
|
|
245
|
+
} : {},
|
|
246
|
+
...shape.backlinks ? {
|
|
247
|
+
backlinks: row.backlinks.map(({ path, type, field })=>({
|
|
248
|
+
path,
|
|
249
|
+
type,
|
|
250
|
+
field
|
|
251
|
+
}))
|
|
252
|
+
} : {}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function resultOf(plan, rows) {
|
|
256
|
+
const shape = plan.shape;
|
|
257
|
+
if (shape.kind === 'documents') {
|
|
258
|
+
return structuredClone({
|
|
259
|
+
documents: rows.map((row)=>documentOf(row, shape))
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
const bounded = shape.orderBy.length === 0 && plan.limit !== null ? rows.slice(0, plan.limit) : rows;
|
|
263
|
+
return structuredClone({
|
|
264
|
+
groups: bounded.map((row)=>({
|
|
265
|
+
key: shape.groupBy.map((_, index)=>row[`key${index}`]),
|
|
266
|
+
count: row.count
|
|
267
|
+
}))
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
export function createReadSide() {
|
|
271
|
+
configureIndexDevMode({
|
|
272
|
+
enabled: false
|
|
273
|
+
});
|
|
274
|
+
let sync;
|
|
275
|
+
const rows = createCollection({
|
|
276
|
+
getKey: (row)=>row.key,
|
|
277
|
+
gcTime: 0,
|
|
278
|
+
startSync: true,
|
|
279
|
+
autoIndex: 'eager',
|
|
280
|
+
defaultIndexType: BasicIndex,
|
|
281
|
+
sync: {
|
|
282
|
+
rowUpdateMode: 'full',
|
|
283
|
+
sync: (params)=>{
|
|
284
|
+
sync = params;
|
|
285
|
+
params.markReady();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
const shared = new Map();
|
|
290
|
+
function publish(entry) {
|
|
291
|
+
const next = resultOf(entry.plan, entry.built.live.toArray);
|
|
292
|
+
if (deepEquals(entry.result, next)) return;
|
|
293
|
+
entry.result = next;
|
|
294
|
+
for (const listener of entry.listeners)listener(next);
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
apply (set) {
|
|
298
|
+
const next = new Map();
|
|
299
|
+
for (const change of set.documents){
|
|
300
|
+
for (const row of change.before)next.set(row.key, null);
|
|
301
|
+
for (const row of change.after)next.set(row.key, row);
|
|
302
|
+
}
|
|
303
|
+
if (next.size === 0) return;
|
|
304
|
+
sync.begin();
|
|
305
|
+
for (const [key, row] of next){
|
|
306
|
+
if (row === null) {
|
|
307
|
+
if (rows.has(key)) sync.write({
|
|
308
|
+
type: 'delete',
|
|
309
|
+
key
|
|
310
|
+
});
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
sync.write({
|
|
314
|
+
type: rows.has(key) ? 'update' : 'insert',
|
|
315
|
+
value: row
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
sync.commit();
|
|
319
|
+
},
|
|
320
|
+
async query (plan) {
|
|
321
|
+
const { live: collection, dispose } = built(rows, plan);
|
|
322
|
+
try {
|
|
323
|
+
return resultOf(plan, await collection.toArrayWhenReady());
|
|
324
|
+
} finally{
|
|
325
|
+
dispose();
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
observe (plan, identity, listener) {
|
|
329
|
+
let entry = shared.get(identity);
|
|
330
|
+
if (entry === undefined) {
|
|
331
|
+
const created = {
|
|
332
|
+
plan,
|
|
333
|
+
built: built(rows, plan),
|
|
334
|
+
result: undefined,
|
|
335
|
+
listeners: new Set(),
|
|
336
|
+
subscription: null
|
|
337
|
+
};
|
|
338
|
+
created.built.live.on('status:change', ({ status })=>{
|
|
339
|
+
if (status === 'cleaned-up' && created.listeners.size === 0) shared.delete(identity);
|
|
340
|
+
});
|
|
341
|
+
shared.set(identity, created);
|
|
342
|
+
entry = created;
|
|
343
|
+
}
|
|
344
|
+
const observed = entry;
|
|
345
|
+
observed.listeners.add(listener);
|
|
346
|
+
observed.built.live.onFirstReady(()=>{
|
|
347
|
+
if (!observed.listeners.has(listener)) return;
|
|
348
|
+
if (observed.subscription === null) {
|
|
349
|
+
observed.result = resultOf(observed.plan, observed.built.live.toArray);
|
|
350
|
+
observed.subscription = observed.built.live.subscribeChanges(()=>{
|
|
351
|
+
publish(observed);
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
listener(observed.result);
|
|
355
|
+
});
|
|
356
|
+
return ()=>{
|
|
357
|
+
if (!observed.listeners.delete(listener) || observed.listeners.size > 0) return;
|
|
358
|
+
observed.subscription?.unsubscribe();
|
|
359
|
+
observed.subscription = null;
|
|
360
|
+
};
|
|
361
|
+
},
|
|
362
|
+
close () {
|
|
363
|
+
for (const entry of shared.values()){
|
|
364
|
+
entry.listeners.clear();
|
|
365
|
+
entry.subscription?.unsubscribe();
|
|
366
|
+
entry.built.dispose();
|
|
367
|
+
}
|
|
368
|
+
shared.clear();
|
|
369
|
+
void rows.cleanup();
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
//# sourceMappingURL=read-side.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime/src/read-side.ts"],"sourcesContent":["import {\n and,\n BasicIndex,\n configureIndexDevMode,\n count,\n createCollection,\n createLiveQueryCollection,\n deepEquals,\n eq,\n gt,\n gte,\n inArray,\n isNull,\n isUndefined,\n lt,\n lte,\n not,\n or,\n toArray,\n type Collection,\n type Context,\n type InitialQueryBuilder,\n type QueryBuilder,\n type Ref,\n type SyncConfig,\n} from '@tanstack/db';\nimport type { ChangeSet } from './change-set.js';\nimport type {\n Condition,\n Direction,\n DocumentShape,\n GroupShape,\n KeyPlan,\n OrderOptions,\n Plan,\n QueryDocument,\n QueryResult,\n Scope,\n Test,\n Value,\n} from './query.js';\nimport type { Row } from './rows.js';\n\ntype Stored = {\n key: string;\n kind: string;\n room: string;\n path: string;\n type: string;\n body: string;\n source: string;\n target: string;\n field: string;\n fields: Readonly<Record<string, unknown>>;\n values: Readonly<Record<string, unknown>>;\n sizes: Readonly<Record<string, number>>;\n directories: readonly string[];\n preamble: string;\n sections: Readonly<Record<string, string>>;\n markdown: string;\n} & Readonly<Record<string, unknown>>;\n\ntype Reference = Ref<Stored>;\n\ntype Field = Reference['values'][string];\n\ntype Size = Reference['sizes'][string];\n\ntype Refs = Readonly<Record<string, Reference>>;\n\ntype Expression = ReturnType<typeof eq>;\n\ntype Builder = {\n where(callback: (refs: Refs) => Expression): Builder;\n innerJoin(source: Readonly<Record<string, unknown>>, on: (refs: Refs) => Expression): Builder;\n groupBy(callback: (refs: Refs) => unknown): Builder;\n orderBy(callback: (refs: Refs) => unknown, options: Direction | OrderOptions): Builder;\n limit(count: number): Builder;\n select(callback: (refs: Refs) => object): object;\n};\n\ntype Live = Collection<Stored, string | number>;\n\ntype Built = { live: Live; dispose(): void };\n\ntype Shared = {\n plan: Plan;\n built: Built;\n result: QueryResult | undefined;\n listeners: Set<(result: QueryResult) => void>;\n subscription: { unsubscribe(): void } | null;\n};\n\nexport type ReadSide = {\n apply(set: ChangeSet): void;\n query(plan: Plan): Promise<QueryResult>;\n observe(plan: Plan, identity: string, listener: (result: QueryResult) => void): () => void;\n close(): void;\n};\n\nfunction every(expressions: readonly Expression[]): Expression {\n const [first, second, ...rest] = expressions;\n return second === undefined ? first : and(first, second, ...rest);\n}\n\nfunction some(expressions: readonly Expression[]): Expression {\n const [first, second, ...rest] = expressions;\n return second === undefined ? first : or(first, second, ...rest);\n}\n\nfunction equal(field: Field, value: Exclude<Value, null>): Expression {\n return or(eq(field, value), inArray(value, field));\n}\n\nfunction tested(test: Test, field: Field, size: Size, written: Field): Expression {\n if (test.op === 'eq') return test.value === null ? isNull(field) : equal(field, test.value);\n if (test.op === 'ne') {\n return test.value === null\n ? not(isNull(field))\n : or(isUndefined(field), isNull(field), not(equal(field, test.value)));\n }\n if (test.op === 'in' || test.op === 'nin') {\n const matches =\n test.values.length === 0\n ? inArray(field, [])\n : some(test.values.map((value) => (value === null ? isNull(field) : equal(field, value))));\n if (test.op === 'in') return matches;\n return some([\n isUndefined(field),\n ...(test.values.includes(null) ? [] : [isNull(field)]),\n not(matches),\n ]);\n }\n if (test.op === 'range') {\n const compare = { gt, gte, lt, lte };\n return every(test.bounds.map(([operator, bound]) => compare[operator](field, bound)));\n }\n if (test.op === 'all') {\n return every([not(isUndefined(size)), ...test.values.map((value) => inArray(value, field))]);\n }\n if (test.op === 'size') return eq(size, test.size);\n return test.exists ? not(isUndefined(written)) : isUndefined(written);\n}\n\nfunction conditioned(condition: Condition, row: Reference): Expression {\n if ('every' in condition) return every(condition.every.map((item) => conditioned(item, row)));\n if ('some' in condition) return some(condition.some.map((item) => conditioned(item, row)));\n return tested(\n condition.test,\n row.values[condition.field],\n row.sizes[condition.field],\n row.fields[condition.field],\n );\n}\n\nfunction scoped(scope: Scope, row: Reference, rooms: readonly string[] | null): Expression {\n return every([\n eq(row.kind, 'document'),\n ...(rooms === null ? [] : [inArray(row.room, [...rooms])]),\n ...(scope.types === null ? [] : [inArray(row.type, [...scope.types])]),\n ...(scope.pathPrefix === null ? [] : [inArray(scope.pathPrefix, row.directories)]),\n ...(scope.where === null ? [] : [conditioned(scope.where, row)]),\n ]);\n}\n\nfunction keyed(key: KeyPlan, row: Reference): Field | Reference['room'] {\n return key.of === 'field' ? row.values[key.field] : row[key.of];\n}\n\nfunction live(query: (q: InitialQueryBuilder) => object): Live {\n return createLiveQueryCollection({\n query: query as (q: InitialQueryBuilder) => QueryBuilder<Context>,\n startSync: true,\n }) as unknown as Live;\n}\n\nfunction related(\n q: InitialQueryBuilder,\n rows: Collection<Stored, string>,\n scope: Scope,\n field: string | null,\n kept: 'source' | 'target',\n): object {\n const matched = kept === 'source' ? 'target' : 'source';\n const from: Builder = q.from({ r: rows });\n return from\n .where(({ r }) =>\n every([eq(r.kind, 'reference'), ...(field === null ? [] : [eq(r.field, field)])]),\n )\n .innerJoin({ m: rows }, ({ r, m }) => eq(r[matched], m.key))\n .where(({ m }) => scoped(scope, m, null))\n .groupBy(({ r }) => r[kept])\n .select(({ r }) => ({ key: r[kept] }));\n}\n\nfunction filtered(q: InitialQueryBuilder, rows: Collection<Stored, string>, plan: Plan): Builder {\n const from: Builder = q.from({ d: rows });\n let query = from.where(({ d }) => scoped(plan.root, d, plan.rooms));\n if (plan.hop !== null) {\n const hop = related(q, rows, plan.hop, plan.hop.field, 'source');\n query = query.innerJoin({ h: hop }, ({ d, h }) => eq(d.key, h.key));\n }\n if (plan.backlinks !== null) {\n const backlinks = related(q, rows, plan.backlinks, plan.backlinks.field, 'target');\n query = query.innerJoin({ k: backlinks }, ({ d, k }) => eq(d.key, k.key));\n }\n return query;\n}\n\nfunction named<T>(prefix: string, names: readonly string[], source: Readonly<Record<string, T>>) {\n return Object.fromEntries(names.map((name, index) => [`${prefix}${index}`, source[name]]));\n}\n\nfunction documents(\n q: InitialQueryBuilder,\n rows: Collection<Stored, string>,\n plan: Plan,\n shape: DocumentShape,\n): object {\n let query = filtered(q, rows, plan);\n if (shape.sections !== null || shape.preamble || shape.markdown) {\n query = query.innerJoin({ b: rows }, ({ d, b }) => eq(d.body, b.key));\n }\n for (const { key, options } of shape.orderBy) {\n query = query.orderBy(({ d }) => keyed(key, d), options);\n }\n if (shape.orderBy.length === 0 && plan.limit !== null) {\n query = query.orderBy(({ d }) => d.key, { stringSort: 'lexical' });\n }\n if (plan.limit !== null) query = query.limit(plan.limit);\n return query.select(({ d, b }) => ({\n room: d.room,\n path: d.path,\n type: d.type,\n ...(shape.fields === 'all' ? { fields: d.fields } : {}),\n ...(Array.isArray(shape.fields) ? named('field', shape.fields, d.fields) : {}),\n ...(shape.sections === 'all' ? { sections: b.sections } : {}),\n ...(Array.isArray(shape.sections) ? named('section', shape.sections, b.sections) : {}),\n ...(shape.preamble ? { preamble: b.preamble } : {}),\n ...(shape.markdown ? { markdown: b.markdown } : {}),\n ...(shape.backlinks ? { backlinks: toArray(backlinked(q, rows, d)) } : {}),\n }));\n}\n\nfunction backlinked(q: InitialQueryBuilder, rows: Collection<Stored, string>, document: Reference) {\n const from: Builder = q.from({ r: rows });\n return from\n .where(({ r }) => eq(r.target, document.key))\n .orderBy(({ r }) => r.path, { stringSort: 'lexical' })\n .orderBy(({ r }) => r.field, { stringSort: 'lexical' })\n .select(({ r }) => ({ path: r.path, type: r.type, field: r.field })) as QueryBuilder<Context>;\n}\n\nfunction groups(q: InitialQueryBuilder, stage: Live, shape: GroupShape, limit: number | null) {\n const keys = shape.groupBy.map((_, index) => `key${index}`);\n const from: Builder = q.from({ m: stage });\n let query = from.groupBy(({ m }) => keys.map((key) => m[key]));\n for (const { by, direction } of shape.orderBy) {\n query = query.orderBy(({ m }) => (by === 'count' ? count(m.key) : m[keys[by]]), direction);\n }\n if (limit !== null && shape.orderBy.length > 0) query = query.limit(limit);\n return query.select(({ m }) => ({\n ...Object.fromEntries(keys.map((key) => [key, m[key]])),\n count: count(m.key),\n }));\n}\n\nfunction built(rows: Collection<Stored, string>, plan: Plan): Built {\n const shape = plan.shape;\n if (shape.kind === 'documents') {\n const collection = live((q) => documents(q, rows, plan, shape));\n return { live: collection, dispose: () => void collection.cleanup() };\n }\n const stage = live((q) =>\n filtered(q, rows, plan).select(({ d }) => ({\n key: d.key,\n ...Object.fromEntries(shape.groupBy.map((key, index) => [`key${index}`, keyed(key, d)])),\n })),\n );\n const collection = live((q) => groups(q, stage, shape, plan.limit));\n return {\n live: collection,\n dispose: () => {\n void collection.cleanup();\n void stage.cleanup();\n },\n };\n}\n\nfunction present(entries: readonly (readonly [string, unknown])[]) {\n return Object.fromEntries(entries.filter(([, value]) => value !== undefined));\n}\n\nfunction part(\n row: Readonly<Record<string, unknown>>,\n prefix: string,\n names: 'all' | readonly string[],\n whole: unknown,\n) {\n if (names === 'all') return whole;\n return present(names.map((name, index) => [name, row[`${prefix}${index}`]] as const));\n}\n\nfunction documentOf(row: Readonly<Record<string, unknown>>, shape: DocumentShape): QueryDocument {\n return {\n room: row.room as string,\n path: row.path as string,\n type: row.type as string,\n ...(shape.fields === null\n ? {}\n : { fields: part(row, 'field', shape.fields, row.fields) as QueryDocument['fields'] }),\n ...(shape.sections === null\n ? {}\n : {\n sections: part(row, 'section', shape.sections, row.sections) as QueryDocument['sections'],\n }),\n ...(shape.preamble ? { preamble: row.preamble as string } : {}),\n ...(shape.markdown ? { markdown: row.markdown as string } : {}),\n ...(shape.backlinks\n ? {\n backlinks: (row.backlinks as readonly Readonly<Record<string, string>>[]).map(\n ({ path, type, field }) => ({ path, type, field }),\n ),\n }\n : {}),\n };\n}\n\nfunction resultOf(plan: Plan, rows: readonly Readonly<Record<string, unknown>>[]): QueryResult {\n const shape = plan.shape;\n if (shape.kind === 'documents') {\n return structuredClone({ documents: rows.map((row) => documentOf(row, shape)) });\n }\n const bounded =\n shape.orderBy.length === 0 && plan.limit !== null ? rows.slice(0, plan.limit) : rows;\n return structuredClone({\n groups: bounded.map((row) => ({\n key: shape.groupBy.map((_, index) => row[`key${index}`]),\n count: row.count as number,\n })),\n });\n}\n\nexport function createReadSide(): ReadSide {\n configureIndexDevMode({ enabled: false });\n let sync!: Parameters<SyncConfig<Stored, string>['sync']>[0];\n const rows = createCollection<Stored, string>({\n getKey: (row) => row.key,\n gcTime: 0,\n startSync: true,\n autoIndex: 'eager',\n defaultIndexType: BasicIndex,\n sync: {\n rowUpdateMode: 'full',\n sync: (params) => {\n sync = params;\n params.markReady();\n },\n },\n });\n const shared = new Map<string, Shared>();\n\n function publish(entry: Shared) {\n const next = resultOf(entry.plan, entry.built.live.toArray);\n if (deepEquals(entry.result, next)) return;\n entry.result = next;\n for (const listener of entry.listeners) listener(next);\n }\n\n return {\n apply(set) {\n const next = new Map<string, Row | null>();\n for (const change of set.documents) {\n for (const row of change.before) next.set(row.key, null);\n for (const row of change.after) next.set(row.key, row);\n }\n if (next.size === 0) return;\n sync.begin();\n for (const [key, row] of next) {\n if (row === null) {\n if (rows.has(key)) sync.write({ type: 'delete', key });\n continue;\n }\n sync.write({ type: rows.has(key) ? 'update' : 'insert', value: row as Stored });\n }\n sync.commit();\n },\n async query(plan) {\n const { live: collection, dispose } = built(rows, plan);\n try {\n return resultOf(plan, await collection.toArrayWhenReady());\n } finally {\n dispose();\n }\n },\n observe(plan, identity, listener) {\n let entry = shared.get(identity);\n if (entry === undefined) {\n const created: Shared = {\n plan,\n built: built(rows, plan),\n result: undefined,\n listeners: new Set(),\n subscription: null,\n };\n created.built.live.on('status:change', ({ status }) => {\n if (status === 'cleaned-up' && created.listeners.size === 0) shared.delete(identity);\n });\n shared.set(identity, created);\n entry = created;\n }\n const observed = entry;\n observed.listeners.add(listener);\n observed.built.live.onFirstReady(() => {\n if (!observed.listeners.has(listener)) return;\n if (observed.subscription === null) {\n observed.result = resultOf(observed.plan, observed.built.live.toArray);\n observed.subscription = observed.built.live.subscribeChanges(() => {\n publish(observed);\n });\n }\n listener(observed.result as QueryResult);\n });\n return () => {\n if (!observed.listeners.delete(listener) || observed.listeners.size > 0) return;\n observed.subscription?.unsubscribe();\n observed.subscription = null;\n };\n },\n close() {\n for (const entry of shared.values()) {\n entry.listeners.clear();\n entry.subscription?.unsubscribe();\n entry.built.dispose();\n }\n shared.clear();\n void rows.cleanup();\n },\n };\n}\n"],"names":["and","BasicIndex","configureIndexDevMode","count","createCollection","createLiveQueryCollection","deepEquals","eq","gt","gte","inArray","isNull","isUndefined","lt","lte","not","or","toArray","every","expressions","first","second","rest","undefined","some","equal","field","value","tested","test","size","written","op","matches","values","length","map","includes","compare","bounds","operator","bound","exists","conditioned","condition","row","item","sizes","fields","scoped","scope","rooms","kind","room","types","type","pathPrefix","directories","where","keyed","key","of","live","query","startSync","related","q","rows","kept","matched","from","r","innerJoin","m","groupBy","select","filtered","plan","d","root","hop","h","backlinks","k","named","prefix","names","source","Object","fromEntries","name","index","documents","shape","sections","preamble","markdown","b","body","options","orderBy","limit","stringSort","path","Array","isArray","backlinked","document","target","groups","stage","keys","_","by","direction","built","collection","dispose","cleanup","present","entries","filter","part","whole","documentOf","resultOf","structuredClone","bounded","slice","createReadSide","enabled","sync","getKey","gcTime","autoIndex","defaultIndexType","rowUpdateMode","params","markReady","shared","Map","publish","entry","next","result","listener","listeners","apply","set","change","before","after","begin","has","write","commit","toArrayWhenReady","observe","identity","get","created","Set","subscription","on","status","delete","observed","add","onFirstReady","subscribeChanges","un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MI,SAAS,CAAC0B,KAAK;gBACrB9B,MAAMoB,YAAY,EAAEQ;gBACpB5B,MAAM3B,KAAK,CAACE,OAAO;YACrB;YACAsB,OAAOiC,KAAK;YACZ,KAAKzG,KAAKmD,OAAO;QACnB;IACF;AACF"}
|
package/dist/rows.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Document } from '@agentshouse/mdmodel';
|
|
2
|
+
import { type Composition } from './collection.js';
|
|
3
|
+
type Fields = Readonly<Record<string, unknown>>;
|
|
4
|
+
export type DocumentRow = {
|
|
5
|
+
key: string;
|
|
6
|
+
kind: 'document';
|
|
7
|
+
room: string;
|
|
8
|
+
path: string;
|
|
9
|
+
type: string;
|
|
10
|
+
fields: Fields;
|
|
11
|
+
values: Fields;
|
|
12
|
+
sizes: Readonly<Record<string, number>>;
|
|
13
|
+
directories: readonly string[];
|
|
14
|
+
body: string;
|
|
15
|
+
};
|
|
16
|
+
export type BodyRow = {
|
|
17
|
+
key: string;
|
|
18
|
+
kind: 'body';
|
|
19
|
+
room: string;
|
|
20
|
+
path: string;
|
|
21
|
+
preamble: string;
|
|
22
|
+
sections: Readonly<Record<string, string>>;
|
|
23
|
+
markdown: string;
|
|
24
|
+
};
|
|
25
|
+
export type ReferenceRow = {
|
|
26
|
+
key: string;
|
|
27
|
+
kind: 'reference';
|
|
28
|
+
room: string;
|
|
29
|
+
source: string;
|
|
30
|
+
target: string;
|
|
31
|
+
field: string;
|
|
32
|
+
path: string;
|
|
33
|
+
type: string;
|
|
34
|
+
};
|
|
35
|
+
export type Row = DocumentRow | BodyRow | ReferenceRow;
|
|
36
|
+
export declare function documentKey(room: string, path: string): string;
|
|
37
|
+
export declare function rowsOf(room: string, path: string, document: Document, composition: Composition): readonly Row[];
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=rows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],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