@gaganref/confect-test 10.3.1-fork.91 → 10.3.1-fork.93

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.
Files changed (51) hide show
  1. package/dist/TestConfect.d.ts +26 -0
  2. package/dist/TestConfect.d.ts.map +1 -1
  3. package/dist/TestConfect.js +9 -1
  4. package/dist/TestConfect.js.map +1 -1
  5. package/dist/internal/Attempt.d.ts +14 -1
  6. package/dist/internal/Attempt.d.ts.map +1 -1
  7. package/dist/internal/Attempt.js +18 -1
  8. package/dist/internal/Attempt.js.map +1 -1
  9. package/dist/internal/ConvexTest.d.ts +26 -1
  10. package/dist/internal/ConvexTest.d.ts.map +1 -1
  11. package/dist/internal/ConvexTest.js +55 -27
  12. package/dist/internal/ConvexTest.js.map +1 -1
  13. package/dist/internal/Execution.d.ts +151 -1
  14. package/dist/internal/Execution.d.ts.map +1 -1
  15. package/dist/internal/Execution.js +731 -214
  16. package/dist/internal/Execution.js.map +1 -1
  17. package/dist/internal/KernelQuery.d.ts +8 -3
  18. package/dist/internal/KernelQuery.d.ts.map +1 -1
  19. package/dist/internal/KernelQuery.js +10 -3
  20. package/dist/internal/KernelQuery.js.map +1 -1
  21. package/dist/internal/KernelRefusal.d.ts +134 -0
  22. package/dist/internal/KernelRefusal.d.ts.map +1 -1
  23. package/dist/internal/KernelRefusal.js +134 -1
  24. package/dist/internal/KernelRefusal.js.map +1 -1
  25. package/dist/internal/Metering.d.ts +186 -0
  26. package/dist/internal/Metering.d.ts.map +1 -0
  27. package/dist/internal/Metering.js +401 -0
  28. package/dist/internal/Metering.js.map +1 -0
  29. package/dist/internal/Redaction.d.ts +142 -0
  30. package/dist/internal/Redaction.d.ts.map +1 -0
  31. package/dist/internal/Redaction.js +448 -0
  32. package/dist/internal/Redaction.js.map +1 -0
  33. package/dist/internal/Snapshot.d.ts +298 -0
  34. package/dist/internal/Snapshot.d.ts.map +1 -0
  35. package/dist/internal/Snapshot.js +532 -0
  36. package/dist/internal/Snapshot.js.map +1 -0
  37. package/dist/internal/Subscriptions.d.ts +13 -0
  38. package/dist/internal/Subscriptions.d.ts.map +1 -1
  39. package/dist/internal/Subscriptions.js +27 -3
  40. package/dist/internal/Subscriptions.js.map +1 -1
  41. package/package.json +3 -3
  42. package/src/TestConfect.ts +63 -4
  43. package/src/internal/Attempt.ts +24 -0
  44. package/src/internal/ConvexTest.ts +135 -38
  45. package/src/internal/Execution.ts +1141 -324
  46. package/src/internal/KernelQuery.ts +17 -6
  47. package/src/internal/KernelRefusal.ts +160 -0
  48. package/src/internal/Metering.ts +520 -0
  49. package/src/internal/Redaction.ts +730 -0
  50. package/src/internal/Snapshot.ts +945 -0
  51. package/src/internal/Subscriptions.ts +34 -4
@@ -35,9 +35,11 @@ const resolveSource = (view, query) => {
35
35
  let order;
36
36
  let table;
37
37
  let range = [];
38
+ let index;
38
39
  switch (source.type) {
39
40
  case "FullTableScan":
40
41
  table = source.tableName;
42
+ index = "by_creation_time";
41
43
  docs = [...view.scan(source.tableName)];
42
44
  order = source.order ?? "asc";
43
45
  fieldPathsToSortBy = ["_creationTime"];
@@ -45,15 +47,16 @@ const resolveSource = (view, query) => {
45
47
  case "IndexRange": {
46
48
  const [tableName, indexName] = source.indexName.split(".");
47
49
  table = tableName;
50
+ index = indexName;
48
51
  range = source.range;
49
52
  order = source.order ?? "asc";
50
53
  let fields;
51
54
  if (indexName === "by_creation_time") fields = ["_creationTime", "_id"];
52
55
  else if (indexName === "by_id") fields = ["_id"];
53
56
  else {
54
- const index = view.schema?.tables.get(tableName)?.indexes.find(({ indexDescriptor }) => indexDescriptor === indexName);
55
- if (index === void 0) throw new Error(`Cannot use index "${indexName}" for table "${tableName}" because it is not declared in the schema.`);
56
- fields = index.fields.concat(["_creationTime", "_id"]);
57
+ const declared = view.schema?.tables.get(tableName)?.indexes.find(({ indexDescriptor }) => indexDescriptor === indexName);
58
+ if (declared === void 0) throw new Error(`Cannot use index "${indexName}" for table "${tableName}" because it is not declared in the schema.`);
59
+ fields = declared.fields.concat(["_creationTime", "_id"]);
57
60
  }
58
61
  fieldPathsToSortBy = fields;
59
62
  validateIndexRangeExpression(source, fields);
@@ -79,6 +82,7 @@ const resolveSource = (view, query) => {
79
82
  order,
80
83
  interval: {
81
84
  kind: "interval",
85
+ index,
82
86
  table,
83
87
  fields: fieldPathsToSortBy.includes("_id") ? fieldPathsToSortBy : [...fieldPathsToSortBy, "_id"],
84
88
  order,
@@ -98,6 +102,7 @@ const stream = (view, query) => {
98
102
  let returned = 0;
99
103
  for (const doc of sortedDocs) {
100
104
  if (limit !== null && returned >= limit) return;
105
+ view.examine(interval.table, doc);
101
106
  examined(keyOf(interval.fields, doc));
102
107
  if (filterFn(doc)) {
103
108
  returned++;
@@ -158,6 +163,7 @@ const paginate = (view, { query, cursor, endCursor, pageSize, maximumRowsRead, m
158
163
  reachedEnd = false;
159
164
  examined(endCursorKeys);
160
165
  if (cmp === 0) {
166
+ view.examine(interval.table, doc);
161
167
  rowsRead += 1;
162
168
  bytesRead += getDocumentSize(doc);
163
169
  readDocCursors.push(encodeCursor(doc, cursorFields));
@@ -167,6 +173,7 @@ const paginate = (view, { query, cursor, endCursor, pageSize, maximumRowsRead, m
167
173
  break;
168
174
  }
169
175
  }
176
+ view.examine(interval.table, doc);
170
177
  rowsRead += 1;
171
178
  bytesRead += getDocumentSize(doc);
172
179
  readDocCursors.push(encodeCursor(doc, cursorFields));
@@ -1 +1 @@
1
- {"version":3,"file":"KernelQuery.js","names":["KernelRefusal.requiresBinary","ReadSet.keyOf"],"sources":["../../src/internal/KernelQuery.ts"],"sourcesContent":["// Derived from convex-test 0.0.65 (index.ts, `DatabaseFake`), Copyright Convex,\n// Inc., licensed under the Apache License, Version 2.0\n// (https://www.apache.org/licenses/LICENSE-2.0). The ordering, index range and\n// pagination rules are convex-test's. They read a table through the attempt\n// that runs the query instead of convex-test's database, and record the\n// interval each query examined.\n\nimport type {\n GenericDocument,\n GenericSchema,\n SchemaDefinition,\n} from \"convex/server\";\nimport {\n compareValues,\n convexToJson,\n getDocumentSize,\n jsonToConvex,\n} from \"convex/values\";\nimport * as KernelRefusal from \"./KernelRefusal.js\";\nimport * as ReadSet from \"./ReadSet.js\";\nimport type {\n FilterJson,\n Index,\n SerializedQuery,\n SerializedRangeExpression,\n StoredDocument,\n ValidatorJSON,\n} from \"./KernelValues.js\";\nimport {\n evaluateFieldPath,\n evaluateFilter,\n evaluateRangeFilter,\n isValidIdentifier,\n resolvePendingValues,\n validateFieldNames,\n validateIndexRangeExpression,\n validateValidator,\n} from \"./KernelValues.js\";\n\n/**\n * A component's tables as its schema declares them.\n */\nexport interface KernelSchema {\n readonly schemaValidation: boolean;\n readonly tables: ReadonlyMap<\n string,\n {\n readonly indexes: ReadonlyArray<Index>;\n readonly documentType: ValidatorJSON;\n }\n >;\n}\n\nexport const exportSchema = (\n schema: SchemaDefinition<GenericSchema, boolean> | null | undefined,\n): KernelSchema | null => {\n if (schema === null || schema === undefined) return null;\n const exported: KernelSchema = {\n schemaValidation: (schema as unknown as { schemaValidation: boolean })\n .schemaValidation,\n tables: new Map(\n Object.entries(schema.tables).map(([name, table]) => [\n name,\n (table as unknown as { export: () => any }).export(),\n ]),\n ),\n };\n exported.tables.forEach((table, tableName) => {\n if (!isValidIdentifier(tableName)) {\n throw new Error(\n `Table names must be valid identifiers, got \"${tableName}\"`,\n );\n }\n validateFieldNames(table.documentType);\n table.indexes.forEach(({ indexDescriptor }) => {\n if (!isValidIdentifier(indexDescriptor)) {\n throw new Error(\n `Index names must be valid identifiers, got \"${indexDescriptor}\"`,\n );\n }\n });\n });\n return exported;\n};\n\n/**\n * Check a document against its table's declared type, as the backend does\n * before a write.\n */\nexport const validateDocument = (\n schema: KernelSchema | null,\n tableName: string,\n doc: Record<string, unknown>,\n) => {\n if (schema === null || !schema.schemaValidation) return;\n const validator = schema.tables.get(tableName)?.documentType;\n if (validator === undefined) return;\n validateValidator(validator, resolvePendingValues(doc as GenericDocument));\n};\n\n/**\n * An interval a query reads, before it says where it starts and how far it got.\n */\nexport type Interval = Omit<\n ReadSet.IntervalRead,\n \"componentPath\" | \"after\" | \"through\"\n>;\n\n/**\n * What a query reads: one table of one component, as the running attempt sees\n * it. `read` records an interval in the attempt's read set and returns how to\n * advance it.\n */\nexport interface TableView {\n readonly schema: KernelSchema | null;\n readonly scan: (tableName: string) => ReadonlyArray<StoredDocument>;\n readonly read: (\n interval: Interval,\n after: ReadSet.Key | null,\n ) => (through: ReadSet.Key | \"end\") => void;\n}\n\ninterface ResolvedSource {\n readonly sortedDocs: ReadonlyArray<GenericDocument>;\n readonly filterFn: (doc: GenericDocument) => boolean;\n readonly limit: number | null;\n readonly order: \"asc\" | \"desc\";\n readonly interval: Interval;\n}\n\nconst resolveSource = (\n view: TableView,\n query: SerializedQuery,\n): ResolvedSource => {\n const source = query.source;\n let docs: Array<GenericDocument>;\n let fieldPathsToSortBy: Array<string>;\n let order: \"asc\" | \"desc\";\n let table: string;\n let range: ReadonlyArray<SerializedRangeExpression> = [];\n switch (source.type) {\n case \"FullTableScan\": {\n table = source.tableName;\n docs = [...view.scan(source.tableName)];\n order = source.order ?? \"asc\";\n fieldPathsToSortBy = [\"_creationTime\"];\n break;\n }\n case \"IndexRange\": {\n const [tableName, indexName] = source.indexName.split(\".\") as [\n string,\n string,\n ];\n table = tableName;\n range = source.range;\n order = source.order ?? \"asc\";\n let fields: Array<string>;\n if (indexName === \"by_creation_time\") {\n fields = [\"_creationTime\", \"_id\"];\n } else if (indexName === \"by_id\") {\n fields = [\"_id\"];\n } else {\n const index = view.schema?.tables\n .get(tableName)\n ?.indexes.find(\n ({ indexDescriptor }) => indexDescriptor === indexName,\n );\n if (index === undefined) {\n throw new Error(\n `Cannot use index \"${indexName}\" for table \"${tableName}\" because ` +\n `it is not declared in the schema.`,\n );\n }\n fields = index.fields.concat([\"_creationTime\", \"_id\"]);\n }\n fieldPathsToSortBy = fields;\n validateIndexRangeExpression(source, fields);\n docs = view\n .scan(tableName)\n .filter((doc) =>\n source.range.every((filter) => evaluateRangeFilter(doc, filter)),\n );\n break;\n }\n case \"Search\": {\n throw KernelRefusal.requiresBinary(\"textSearch\");\n }\n }\n\n const filters = query.operators\n .filter(\n (operator): operator is { filter: FilterJson } => \"filter\" in operator,\n )\n .map((operator) => operator.filter);\n const limit =\n query.operators.find(\n (operator): operator is { limit: number } => \"limit\" in operator,\n ) ?? null;\n\n const orderMultiplier = order === \"asc\" ? 1 : -1;\n docs.sort((a, b) => {\n for (const fp of fieldPathsToSortBy) {\n const v = compareValues(\n evaluateFieldPath(fp, a),\n evaluateFieldPath(fp, b),\n );\n if (v !== 0) return v * orderMultiplier;\n }\n return 0;\n });\n\n return {\n sortedDocs: docs,\n filterFn: (doc) => filters.every((f) => evaluateFilter(doc, f)),\n limit: limit?.limit ?? null,\n order,\n interval: {\n kind: \"interval\",\n table,\n fields: fieldPathsToSortBy.includes(\"_id\")\n ? fieldPathsToSortBy\n : [...fieldPathsToSortBy, \"_id\"],\n order,\n range,\n },\n };\n};\n\n/**\n * A query's documents in order. The source is read when the query starts, as a\n * snapshot, and consumed lazily. The read set holds the prefix the stream has\n * examined, filtered documents included, or the whole range once it ends.\n */\nexport const stream = (\n view: TableView,\n query: SerializedQuery,\n): Iterator<GenericDocument> => {\n const { sortedDocs, filterFn, limit, interval } = resolveSource(view, query);\n const examined = view.read(interval, null);\n return (function* () {\n let returned = 0;\n for (const doc of sortedDocs) {\n if (limit !== null && returned >= limit) return;\n examined(ReadSet.keyOf(interval.fields, doc as StoredDocument));\n if (filterFn(doc)) {\n returned++;\n yield doc;\n }\n }\n examined(\"end\");\n })();\n};\n\nconst encodeCursor = (\n doc: GenericDocument,\n fieldPaths: ReadonlyArray<string>,\n): string =>\n JSON.stringify(\n fieldPaths.map((fp) => {\n const k = evaluateFieldPath(fp, doc);\n return k === undefined ? null : JSON.stringify(convexToJson(k));\n }),\n );\n\nconst parseCursor = (c: string | null | undefined) =>\n c\n ? (JSON.parse(c) as Array<string | null>).map((k) =>\n k === null ? undefined : jsonToConvex(JSON.parse(k)),\n )\n : null;\n\nconst compareToCursor = (\n doc: GenericDocument,\n cursorKeys: ReadonlyArray<unknown>,\n fieldPaths: ReadonlyArray<string>,\n order: \"asc\" | \"desc\",\n): number => {\n const orderMultiplier = order === \"asc\" ? 1 : -1;\n for (let i = 0; i < fieldPaths.length; i++) {\n const cmp = compareValues(\n evaluateFieldPath(fieldPaths[i]!, doc),\n cursorKeys[i] as any,\n );\n if (cmp !== 0) return cmp * orderMultiplier;\n }\n return 0;\n};\n\nexport interface PageRequest {\n readonly query: SerializedQuery;\n readonly cursor: string | null;\n readonly endCursor?: string | null;\n readonly pageSize: number;\n readonly maximumRowsRead?: number | null;\n readonly maximumBytesRead?: number | null;\n}\n\nexport const paginate = (\n view: TableView,\n {\n query,\n cursor,\n endCursor,\n pageSize,\n maximumRowsRead,\n maximumBytesRead,\n }: PageRequest,\n) => {\n const { sortedDocs, filterFn, order, interval } = resolveSource(view, query);\n // A page from the terminal cursor reads the empty interval past the end, so\n // it depends on nothing.\n if (cursor === \"_end_cursor\") {\n return {\n page: [],\n isDone: true,\n continueCursor: \"_end_cursor\",\n splitCursor: null,\n pageStatus: null,\n };\n }\n const cursorFields = interval.fields;\n const cursorKeys = parseCursor(cursor);\n const hasEndBoundary = !!endCursor && endCursor !== \"_end_cursor\";\n const endCursorKeys = hasEndBoundary ? parseCursor(endCursor) : null;\n const examined = view.read(interval, cursorKeys);\n let reachedEnd = true;\n\n const page: Array<GenericDocument> = [];\n let isInPage = cursor === null;\n let continueCursor = \"_end_cursor\";\n let splitCursor: string | null = null;\n let pageStatus: \"SplitRecommended\" | \"SplitRequired\" | null = null;\n let rowsRead = 0;\n let bytesRead = 0;\n const readDocCursors: Array<string> = [];\n\n for (let i = 0; i < sortedDocs.length; i++) {\n const doc = sortedDocs[i]!;\n const isLastDoc = i === sortedDocs.length - 1;\n if (!isInPage) {\n if (cursorKeys) {\n if (compareToCursor(doc, cursorKeys, cursorFields, order) > 0) {\n isInPage = true;\n } else {\n continue;\n }\n }\n }\n if (hasEndBoundary && endCursorKeys) {\n const cmp = compareToCursor(doc, endCursorKeys, cursorFields, order);\n if (cmp >= 0) {\n reachedEnd = false;\n examined(endCursorKeys);\n if (cmp === 0) {\n rowsRead += 1;\n bytesRead += getDocumentSize(doc);\n readDocCursors.push(encodeCursor(doc, cursorFields));\n if (filterFn(doc)) page.push(doc);\n continueCursor = encodeCursor(doc, cursorFields);\n }\n break;\n }\n }\n rowsRead += 1;\n bytesRead += getDocumentSize(doc);\n readDocCursors.push(encodeCursor(doc, cursorFields));\n examined(ReadSet.keyOf(cursorFields, doc as StoredDocument));\n const hitLimit =\n (!!maximumRowsRead && rowsRead >= maximumRowsRead) ||\n (!!maximumBytesRead && bytesRead >= maximumBytesRead);\n if (filterFn(doc)) page.push(doc);\n if (hitLimit) {\n reachedEnd = false;\n pageStatus = \"SplitRequired\";\n continueCursor = encodeCursor(doc, cursorFields);\n break;\n }\n if (!endCursor && page.length >= pageSize) {\n reachedEnd = isLastDoc;\n if (!isLastDoc) continueCursor = encodeCursor(doc, cursorFields);\n break;\n }\n }\n // A page bounded by an end cursor examined the range only up to it.\n if (reachedEnd) examined(endCursorKeys ?? \"end\");\n\n if (pageStatus === \"SplitRequired\" && readDocCursors.length >= 2) {\n splitCursor = readDocCursors[Math.floor((readDocCursors.length - 1) / 2)]!;\n } else if (\n pageStatus === null &&\n rowsRead > pageSize + 1 &&\n readDocCursors.length >= 2\n ) {\n pageStatus = \"SplitRecommended\";\n splitCursor = readDocCursors[Math.floor((readDocCursors.length - 1) / 2)]!;\n }\n\n return {\n page,\n isDone: continueCursor === \"_end_cursor\",\n continueCursor,\n splitCursor,\n pageStatus,\n };\n};\n"],"mappings":";;;;;AAqDA,MAAa,gBACX,WACwB;CACxB,IAAI,WAAW,QAAQ,WAAW,KAAA,GAAW,OAAO;CACpD,MAAM,WAAyB;EAC7B,kBAAmB,OAChB;EACH,QAAQ,IAAI,IAC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eAAe,SAAS,KAAK,CAAC;MAClE,IACL,eAAe,QACf,WAAW,WAAW,KACtB,eAAe,UAAU,GACzB;EACA,aAAa;EACb,cAAc,eAAe,KAAK,OAAO,eAAe,SAAS,KAAK,CAAC;CACzE;CAEA,OAAO;EACL;EACA,QAAQ,mBAAmB;EAC3B;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"KernelQuery.js","names":["KernelRefusal.requiresBinary","ReadSet.keyOf"],"sources":["../../src/internal/KernelQuery.ts"],"sourcesContent":["// Derived from convex-test 0.0.65 (index.ts, `DatabaseFake`), Copyright Convex,\n// Inc., licensed under the Apache License, Version 2.0\n// (https://www.apache.org/licenses/LICENSE-2.0). The ordering, index range and\n// pagination rules are convex-test's. They read a table through the attempt\n// that runs the query instead of convex-test's database, and record the\n// interval each query examined.\n\nimport type {\n GenericDocument,\n GenericSchema,\n SchemaDefinition,\n} from \"convex/server\";\nimport {\n compareValues,\n convexToJson,\n getDocumentSize,\n jsonToConvex,\n} from \"convex/values\";\nimport * as KernelRefusal from \"./KernelRefusal.js\";\nimport * as ReadSet from \"./ReadSet.js\";\nimport type {\n FilterJson,\n Index,\n SerializedQuery,\n SerializedRangeExpression,\n StoredDocument,\n ValidatorJSON,\n} from \"./KernelValues.js\";\nimport {\n evaluateFieldPath,\n evaluateFilter,\n evaluateRangeFilter,\n isValidIdentifier,\n resolvePendingValues,\n validateFieldNames,\n validateIndexRangeExpression,\n validateValidator,\n} from \"./KernelValues.js\";\n\n/**\n * A component's tables as its schema declares them.\n */\nexport interface KernelSchema {\n readonly schemaValidation: boolean;\n readonly tables: ReadonlyMap<\n string,\n {\n readonly indexes: ReadonlyArray<Index>;\n readonly documentType: ValidatorJSON;\n }\n >;\n}\n\nexport const exportSchema = (\n schema: SchemaDefinition<GenericSchema, boolean> | null | undefined,\n): KernelSchema | null => {\n if (schema === null || schema === undefined) return null;\n const exported: KernelSchema = {\n schemaValidation: (schema as unknown as { schemaValidation: boolean })\n .schemaValidation,\n tables: new Map(\n Object.entries(schema.tables).map(([name, table]) => [\n name,\n (table as unknown as { export: () => any }).export(),\n ]),\n ),\n };\n exported.tables.forEach((table, tableName) => {\n if (!isValidIdentifier(tableName)) {\n throw new Error(\n `Table names must be valid identifiers, got \"${tableName}\"`,\n );\n }\n validateFieldNames(table.documentType);\n table.indexes.forEach(({ indexDescriptor }) => {\n if (!isValidIdentifier(indexDescriptor)) {\n throw new Error(\n `Index names must be valid identifiers, got \"${indexDescriptor}\"`,\n );\n }\n });\n });\n return exported;\n};\n\n/**\n * Check a document against its table's declared type, as the backend does\n * before a write.\n */\nexport const validateDocument = (\n schema: KernelSchema | null,\n tableName: string,\n doc: Record<string, unknown>,\n) => {\n if (schema === null || !schema.schemaValidation) return;\n const validator = schema.tables.get(tableName)?.documentType;\n if (validator === undefined) return;\n validateValidator(validator, resolvePendingValues(doc as GenericDocument));\n};\n\n/**\n * An interval a query reads, before it says where it starts and how far it got,\n * and the index it reads it from.\n */\nexport type Interval = Omit<\n ReadSet.IntervalRead,\n \"componentPath\" | \"after\" | \"through\"\n> & { readonly index: string };\n\n/**\n * What a query reads: one table of one component, as the running attempt sees\n * it. `read` records an interval in the attempt's read set and returns how to\n * advance it. `examine` charges one document the query examined, before the\n * query's filters see it.\n */\nexport interface TableView {\n readonly schema: KernelSchema | null;\n readonly scan: (tableName: string) => ReadonlyArray<StoredDocument>;\n readonly read: (\n interval: Interval,\n after: ReadSet.Key | null,\n ) => (through: ReadSet.Key | \"end\") => void;\n readonly examine: (table: string, doc: GenericDocument) => void;\n}\n\ninterface ResolvedSource {\n readonly sortedDocs: ReadonlyArray<GenericDocument>;\n readonly filterFn: (doc: GenericDocument) => boolean;\n readonly limit: number | null;\n readonly order: \"asc\" | \"desc\";\n readonly interval: Interval;\n}\n\nconst resolveSource = (\n view: TableView,\n query: SerializedQuery,\n): ResolvedSource => {\n const source = query.source;\n let docs: Array<GenericDocument>;\n let fieldPathsToSortBy: Array<string>;\n let order: \"asc\" | \"desc\";\n let table: string;\n let range: ReadonlyArray<SerializedRangeExpression> = [];\n let index: string;\n switch (source.type) {\n case \"FullTableScan\": {\n table = source.tableName;\n // The binary scans a whole table through its creation-time index.\n index = \"by_creation_time\";\n docs = [...view.scan(source.tableName)];\n order = source.order ?? \"asc\";\n fieldPathsToSortBy = [\"_creationTime\"];\n break;\n }\n case \"IndexRange\": {\n const [tableName, indexName] = source.indexName.split(\".\") as [\n string,\n string,\n ];\n table = tableName;\n index = indexName;\n range = source.range;\n order = source.order ?? \"asc\";\n let fields: Array<string>;\n if (indexName === \"by_creation_time\") {\n fields = [\"_creationTime\", \"_id\"];\n } else if (indexName === \"by_id\") {\n fields = [\"_id\"];\n } else {\n const declared = view.schema?.tables\n .get(tableName)\n ?.indexes.find(\n ({ indexDescriptor }) => indexDescriptor === indexName,\n );\n if (declared === undefined) {\n throw new Error(\n `Cannot use index \"${indexName}\" for table \"${tableName}\" because ` +\n `it is not declared in the schema.`,\n );\n }\n fields = declared.fields.concat([\"_creationTime\", \"_id\"]);\n }\n fieldPathsToSortBy = fields;\n validateIndexRangeExpression(source, fields);\n docs = view\n .scan(tableName)\n .filter((doc) =>\n source.range.every((filter) => evaluateRangeFilter(doc, filter)),\n );\n break;\n }\n case \"Search\": {\n throw KernelRefusal.requiresBinary(\"textSearch\");\n }\n }\n\n const filters = query.operators\n .filter(\n (operator): operator is { filter: FilterJson } => \"filter\" in operator,\n )\n .map((operator) => operator.filter);\n const limit =\n query.operators.find(\n (operator): operator is { limit: number } => \"limit\" in operator,\n ) ?? null;\n\n const orderMultiplier = order === \"asc\" ? 1 : -1;\n docs.sort((a, b) => {\n for (const fp of fieldPathsToSortBy) {\n const v = compareValues(\n evaluateFieldPath(fp, a),\n evaluateFieldPath(fp, b),\n );\n if (v !== 0) return v * orderMultiplier;\n }\n return 0;\n });\n\n return {\n sortedDocs: docs,\n filterFn: (doc) => filters.every((f) => evaluateFilter(doc, f)),\n limit: limit?.limit ?? null,\n order,\n interval: {\n kind: \"interval\",\n index,\n table,\n fields: fieldPathsToSortBy.includes(\"_id\")\n ? fieldPathsToSortBy\n : [...fieldPathsToSortBy, \"_id\"],\n order,\n range,\n },\n };\n};\n\n/**\n * A query's documents in order. The source is read when the query starts, as a\n * snapshot, and consumed lazily. The read set holds the prefix the stream has\n * examined, filtered documents included, or the whole range once it ends.\n */\nexport const stream = (\n view: TableView,\n query: SerializedQuery,\n): Iterator<GenericDocument> => {\n const { sortedDocs, filterFn, limit, interval } = resolveSource(view, query);\n const examined = view.read(interval, null);\n return (function* () {\n let returned = 0;\n for (const doc of sortedDocs) {\n if (limit !== null && returned >= limit) return;\n view.examine(interval.table, doc);\n examined(ReadSet.keyOf(interval.fields, doc as StoredDocument));\n if (filterFn(doc)) {\n returned++;\n yield doc;\n }\n }\n examined(\"end\");\n })();\n};\n\nconst encodeCursor = (\n doc: GenericDocument,\n fieldPaths: ReadonlyArray<string>,\n): string =>\n JSON.stringify(\n fieldPaths.map((fp) => {\n const k = evaluateFieldPath(fp, doc);\n return k === undefined ? null : JSON.stringify(convexToJson(k));\n }),\n );\n\nconst parseCursor = (c: string | null | undefined) =>\n c\n ? (JSON.parse(c) as Array<string | null>).map((k) =>\n k === null ? undefined : jsonToConvex(JSON.parse(k)),\n )\n : null;\n\nconst compareToCursor = (\n doc: GenericDocument,\n cursorKeys: ReadonlyArray<unknown>,\n fieldPaths: ReadonlyArray<string>,\n order: \"asc\" | \"desc\",\n): number => {\n const orderMultiplier = order === \"asc\" ? 1 : -1;\n for (let i = 0; i < fieldPaths.length; i++) {\n const cmp = compareValues(\n evaluateFieldPath(fieldPaths[i]!, doc),\n cursorKeys[i] as any,\n );\n if (cmp !== 0) return cmp * orderMultiplier;\n }\n return 0;\n};\n\nexport interface PageRequest {\n readonly query: SerializedQuery;\n readonly cursor: string | null;\n readonly endCursor?: string | null;\n readonly pageSize: number;\n readonly maximumRowsRead?: number | null;\n readonly maximumBytesRead?: number | null;\n}\n\nexport const paginate = (\n view: TableView,\n {\n query,\n cursor,\n endCursor,\n pageSize,\n maximumRowsRead,\n maximumBytesRead,\n }: PageRequest,\n) => {\n const { sortedDocs, filterFn, order, interval } = resolveSource(view, query);\n // A page from the terminal cursor reads the empty interval past the end, so\n // it depends on nothing.\n if (cursor === \"_end_cursor\") {\n return {\n page: [],\n isDone: true,\n continueCursor: \"_end_cursor\",\n splitCursor: null,\n pageStatus: null,\n };\n }\n const cursorFields = interval.fields;\n const cursorKeys = parseCursor(cursor);\n const hasEndBoundary = !!endCursor && endCursor !== \"_end_cursor\";\n const endCursorKeys = hasEndBoundary ? parseCursor(endCursor) : null;\n const examined = view.read(interval, cursorKeys);\n let reachedEnd = true;\n\n const page: Array<GenericDocument> = [];\n let isInPage = cursor === null;\n let continueCursor = \"_end_cursor\";\n let splitCursor: string | null = null;\n let pageStatus: \"SplitRecommended\" | \"SplitRequired\" | null = null;\n let rowsRead = 0;\n let bytesRead = 0;\n const readDocCursors: Array<string> = [];\n\n for (let i = 0; i < sortedDocs.length; i++) {\n const doc = sortedDocs[i]!;\n const isLastDoc = i === sortedDocs.length - 1;\n if (!isInPage) {\n if (cursorKeys) {\n if (compareToCursor(doc, cursorKeys, cursorFields, order) > 0) {\n isInPage = true;\n } else {\n continue;\n }\n }\n }\n if (hasEndBoundary && endCursorKeys) {\n const cmp = compareToCursor(doc, endCursorKeys, cursorFields, order);\n if (cmp >= 0) {\n reachedEnd = false;\n examined(endCursorKeys);\n if (cmp === 0) {\n view.examine(interval.table, doc);\n rowsRead += 1;\n bytesRead += getDocumentSize(doc);\n readDocCursors.push(encodeCursor(doc, cursorFields));\n if (filterFn(doc)) page.push(doc);\n continueCursor = encodeCursor(doc, cursorFields);\n }\n break;\n }\n }\n view.examine(interval.table, doc);\n rowsRead += 1;\n bytesRead += getDocumentSize(doc);\n readDocCursors.push(encodeCursor(doc, cursorFields));\n examined(ReadSet.keyOf(cursorFields, doc as StoredDocument));\n const hitLimit =\n (!!maximumRowsRead && rowsRead >= maximumRowsRead) ||\n (!!maximumBytesRead && bytesRead >= maximumBytesRead);\n if (filterFn(doc)) page.push(doc);\n if (hitLimit) {\n reachedEnd = false;\n pageStatus = \"SplitRequired\";\n continueCursor = encodeCursor(doc, cursorFields);\n break;\n }\n if (!endCursor && page.length >= pageSize) {\n reachedEnd = isLastDoc;\n if (!isLastDoc) continueCursor = encodeCursor(doc, cursorFields);\n break;\n }\n }\n // A page bounded by an end cursor examined the range only up to it.\n if (reachedEnd) examined(endCursorKeys ?? \"end\");\n\n if (pageStatus === \"SplitRequired\" && readDocCursors.length >= 2) {\n splitCursor = readDocCursors[Math.floor((readDocCursors.length - 1) / 2)]!;\n } else if (\n pageStatus === null &&\n rowsRead > pageSize + 1 &&\n readDocCursors.length >= 2\n ) {\n pageStatus = \"SplitRecommended\";\n splitCursor = readDocCursors[Math.floor((readDocCursors.length - 1) / 2)]!;\n }\n\n return {\n page,\n isDone: continueCursor === \"_end_cursor\",\n continueCursor,\n splitCursor,\n pageStatus,\n };\n};\n"],"mappings":";;;;;AAqDA,MAAa,gBACX,WACwB;CACxB,IAAI,WAAW,QAAQ,WAAW,KAAA,GAAW,OAAO;CACpD,MAAM,WAAyB;EAC7B,kBAAmB,OAChB;EACH,QAAQ,IAAI,IACV,OAAO,QAAQ,OAAO,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CACnD,MACC,MAA2C,OAAO,CACrD,CAAC,CACH;CACF;CACA,SAAS,OAAO,SAAS,OAAO,cAAc;EAC5C,IAAI,CAAC,kBAAkB,SAAS,GAC9B,MAAM,IAAI,MACR,+CAA+C,UAAU,EAC3D;EAEF,mBAAmB,MAAM,YAAY;EACrC,MAAM,QAAQ,SAAS,EAAE,sBAAsB;GAC7C,IAAI,CAAC,kBAAkB,eAAe,GACpC,MAAM,IAAI,MACR,+CAA+C,gBAAgB,EACjE;EAEJ,CAAC;CACH,CAAC;CACD,OAAO;AACT;;;;;AAMA,MAAa,oBACX,QACA,WACA,QACG;CACH,IAAI,WAAW,QAAQ,CAAC,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K,eAAe,cAAc,KAAK;GACnE,IAAI,OAAO,GAAG;IACZ,aAAa;IACb,SAAS,aAAa;IACtB,IAAI,QAAQ,GAAG;KACb,KAAK,QAAQ,SAAS,OAAO,GAAG;KAChC,YAAY;KACZ,aAAa,gBAAgB,GAAG;KAChC,eAAe,KAAK,aAAa,KAAK,YAAY,CAAC;KACnD,IAAI,SAAS,GAAG,GAAG,KAAK,KAAK,GAAG;KAChC,iBAAiB,aAAa,KAAK,YAAY;IACjD;IACA;GACF;EACF;EACA,KAAK,QAAQ,SAAS,OAAO,GAAG;EAChC,YAAY;EACZ,aAAa,gBAAgB,GAAG;EAChC,eAAe,KAAK,aAAa,KAAK,YAAY,CAAC;EACnD,SAASA,MAAc,cAAc,GAAqB,CAAC;EAC3D,MAAM,WACH,CAAC,CAAC,mBAAmB,YAAY,mBACjC,CAAC,CAAC,oBAAoB,aAAa;EACtC,IAAI,SAAS,GAAG,GAAG,KAAK,KAAK,GAAG;EAChC,IAAI,UAAU;GACZ,aAAa;GACb,aAAa;GACb,iBAAiB,aAAa,KAAK,YAAY;GAC/C;EACF;EACA,IAAI,CAAC,aAAa,KAAK,UAAU,UAAU;GACzC,aAAa;GACb,IAAI,CAAC,WAAW,iBAAiB,aAAa,KAAK,YAAY;GAC/D;EACF;CACF;CAEA,IAAI,YAAY,SAAS,iBAAiB,KAAK;CAE/C,IAAI,eAAe,mBAAmB,eAAe,UAAU,GAC7D,cAAc,eAAe,KAAK,OAAO,eAAe,SAAS,KAAK,CAAC;MAClE,IACL,eAAe,QACf,WAAW,WAAW,KACtB,eAAe,UAAU,GACzB;EACA,aAAa;EACb,cAAc,eAAe,KAAK,OAAO,eAAe,SAAS,KAAK,CAAC;CACzE;CAEA,OAAO;EACL;EACA,QAAQ,mBAAmB;EAC3B;EACA;EACA;CACF;AACF"}
@@ -98,5 +98,139 @@ export declare class UnknownStandingSource extends UnknownStandingSource_base {
98
98
  }
99
99
  export declare const requiresBinary: (operation: RequiresBinary["operation"]) => RequiresBinary;
100
100
  export declare const rowPending: (operation: string, row: number) => KernelRowPending;
101
+ declare const SnapshotMalformed_base: Schema.Class<SnapshotMalformed, Schema.TaggedStruct<"SnapshotMalformed", {
102
+ readonly reason: Schema.String;
103
+ readonly message: Schema.String;
104
+ }>, import("effect/Cause").YieldableError>;
105
+ /**
106
+ * Snapshot bytes are not a kernel snapshot this kernel reads: an unknown
107
+ * header, a body that is not the snapshot's JSON, or a value that does not
108
+ * decode.
109
+ */
110
+ export declare class SnapshotMalformed extends SnapshotMalformed_base {
111
+ }
112
+ declare const SnapshotDigestMismatch_base: Schema.Class<SnapshotDigestMismatch, Schema.TaggedStruct<"SnapshotDigestMismatch", {
113
+ readonly expected: Schema.String;
114
+ readonly actual: Schema.String;
115
+ readonly message: Schema.String;
116
+ }>, import("effect/Cause").YieldableError>;
117
+ /**
118
+ * A snapshot's body does not hash to the digest its header names, so its bytes
119
+ * changed after export.
120
+ */
121
+ export declare class SnapshotDigestMismatch extends SnapshotDigestMismatch_base {
122
+ }
123
+ declare const SnapshotComponentMismatch_base: Schema.Class<SnapshotComponentMismatch, Schema.TaggedStruct<"SnapshotComponentMismatch", {
124
+ readonly snapshot: Schema.$Array<Schema.String>;
125
+ readonly registered: Schema.$Array<Schema.String>;
126
+ readonly message: Schema.String;
127
+ }>, import("effect/Cause").YieldableError>;
128
+ /**
129
+ * A snapshot's components are not the components registered on the world
130
+ * restoring it.
131
+ */
132
+ export declare class SnapshotComponentMismatch extends SnapshotComponentMismatch_base {
133
+ }
134
+ declare const SnapshotWorldUnresolved_base: Schema.Class<SnapshotWorldUnresolved, Schema.TaggedStruct<"SnapshotWorldUnresolved", {
135
+ readonly name: Schema.String;
136
+ readonly reason: Schema.Literals<readonly ["missing", "ambiguous"]>;
137
+ readonly message: Schema.String;
138
+ }>, import("effect/Cause").YieldableError>;
139
+ /**
140
+ * A job's test world is named by no world, or by more than one, so the job
141
+ * could not run under the world that scheduled it.
142
+ */
143
+ export declare class SnapshotWorldUnresolved extends SnapshotWorldUnresolved_base {
144
+ }
145
+ declare const SnapshotWorldBusy_base: Schema.Class<SnapshotWorldBusy, Schema.TaggedStruct<"SnapshotWorldBusy", {
146
+ readonly version: Schema.Int;
147
+ readonly held: Schema.$Array<Schema.String>;
148
+ readonly message: Schema.String;
149
+ }>, import("effect/Cause").YieldableError>;
150
+ /**
151
+ * A world holds work a snapshot does not carry: attempts held for `apply`, or,
152
+ * when it restores, commits of its own.
153
+ */
154
+ export declare class SnapshotWorldBusy extends SnapshotWorldBusy_base {
155
+ }
156
+ declare const SnapshotSecretMissing_base: Schema.Class<SnapshotSecretMissing, Schema.TaggedStruct<"SnapshotSecretMissing", {
157
+ readonly ref: Schema.String;
158
+ readonly message: Schema.String;
159
+ }>, import("effect/Cause").YieldableError>;
160
+ /**
161
+ * A snapshot marks a secret the restore was not given, so the raw value its
162
+ * replay needs is not in memory.
163
+ */
164
+ export declare class SnapshotSecretMissing extends SnapshotSecretMissing_base {
165
+ }
166
+ declare const SnapshotWorldRunning_base: Schema.Class<SnapshotWorldRunning, Schema.TaggedStruct<"SnapshotWorldRunning", {
167
+ readonly registry: Schema.Literals<readonly ["running", "walks", "functions"]>;
168
+ readonly count: Schema.Int;
169
+ readonly message: Schema.String;
170
+ }>, import("effect/Cause").YieldableError>;
171
+ /**
172
+ * A world is running work a snapshot taken or restored now would split: calls
173
+ * from the test, scheduler walks, or function executions, nested and detached
174
+ * ones included.
175
+ */
176
+ export declare class SnapshotWorldRunning extends SnapshotWorldRunning_base {
177
+ }
178
+ declare const SnapshotSubscribed_base: Schema.Class<SnapshotSubscribed, Schema.TaggedStruct<"SnapshotSubscribed", {
179
+ readonly subscribers: Schema.Int;
180
+ readonly message: Schema.String;
181
+ }>, import("effect/Cause").YieldableError>;
182
+ /**
183
+ * A world has subscribers, whose identity versions a restore would rewind.
184
+ * Subscriptions are live client state, so a restore needs a world with none.
185
+ */
186
+ export declare class SnapshotSubscribed extends SnapshotSubscribed_base {
187
+ }
188
+ declare const SnapshotAllocatorBehind_base: Schema.Class<SnapshotAllocatorBehind, Schema.TaggedStruct<"SnapshotAllocatorBehind", {
189
+ readonly allocator: Schema.Literals<readonly ["nextDocumentId", "lastCreationTime", "nextAttemptId", "identityEpoch"]>;
190
+ readonly value: Schema.Finite;
191
+ readonly required: Schema.Finite;
192
+ readonly message: Schema.String;
193
+ }>, import("effect/Cause").YieldableError>;
194
+ /**
195
+ * A snapshot's identity counters stand at or behind an identity its state
196
+ * already holds, so the next allocation would reuse one.
197
+ */
198
+ export declare class SnapshotAllocatorBehind extends SnapshotAllocatorBehind_base {
199
+ }
200
+ declare const SnapshotRowInconsistent_base: Schema.Class<SnapshotRowInconsistent, Schema.TaggedStruct<"SnapshotRowInconsistent", {
201
+ readonly componentPath: Schema.String;
202
+ readonly id: Schema.String;
203
+ readonly reason: Schema.Literals<readonly ["id", "component", "log", "row", "systemFields", "duplicate"]>;
204
+ readonly message: Schema.String;
205
+ }>, import("effect/Cause").YieldableError>;
206
+ /**
207
+ * A snapshot's rows are not what its write log publishes: a row filed under
208
+ * another table or an unregistered component, a version the log does not give
209
+ * it, or a log change whose before value is not the row it replaced.
210
+ */
211
+ export declare class SnapshotRowInconsistent extends SnapshotRowInconsistent_base {
212
+ }
213
+ declare const SnapshotTimestampInconsistent_base: Schema.Class<SnapshotTimestampInconsistent, Schema.TaggedStruct<"SnapshotTimestampInconsistent", {
214
+ readonly version: Schema.Int;
215
+ readonly commitTs: Schema.String;
216
+ readonly message: Schema.String;
217
+ }>, import("effect/Cause").YieldableError>;
218
+ /**
219
+ * A snapshot's commit timestamps do not strictly increase through its write
220
+ * log, or its latest commit timestamp is not the log's last.
221
+ */
222
+ export declare class SnapshotTimestampInconsistent extends SnapshotTimestampInconsistent_base {
223
+ }
224
+ declare const SnapshotJobInconsistent_base: Schema.Class<SnapshotJobInconsistent, Schema.TaggedStruct<"SnapshotJobInconsistent", {
225
+ readonly id: Schema.String;
226
+ readonly reason: Schema.Literals<readonly ["row", "untargeted", "inProgress", "component", "function", "duplicate"]>;
227
+ readonly message: Schema.String;
228
+ }>, import("effect/Cause").YieldableError>;
229
+ /**
230
+ * A snapshot's jobs and job rows disagree: a job with no row, a row with no
231
+ * job, a job left running, or a target no registered component exports.
232
+ */
233
+ export declare class SnapshotJobInconsistent extends SnapshotJobInconsistent_base {
234
+ }
101
235
  export {};
102
236
  //# sourceMappingURL=KernelRefusal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"KernelRefusal.d.ts","sourceRoot":"","sources":["../../src/internal/KernelRefusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;;;;;AAExC;;GAEG;AACH,qBAAa,cAAe,SAAQ,mBAMnC;CAAG;;;;;;AAEJ;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,qBAOrC;CAAG;;;;;AAEJ;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,wBAGxC;CAAG;;;;;AAEJ;;;GAGG;AACH,qBAAa,mCAAoC,SAAQ,wCAGxD;CAAG;;;;;AAEJ;;;GAGG;AACH,qBAAa,aAAc,SAAQ,kBAGlC;CAAG;;;;;AAEJ;;;GAGG;AACH,qBAAa,YAAa,SAAQ,iBAGjC;CAAG;;;;;;;AAEJ;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,0BAQ1C;CAAG;;;;;;;;;AAEJ;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,wBASxC;CAAG;;;;;;AAEJ;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,0BAG1C;CAAG;AAEJ,eAAO,MAAM,cAAc,cAAe,cAAc,CAAC,WAAW,CAAC,mBAIjE,CAAC;AAEL,eAAO,MAAM,UAAU,cAAe,MAAM,OAAO,MAAM,qBAKrD,CAAC"}
1
+ {"version":3,"file":"KernelRefusal.d.ts","sourceRoot":"","sources":["../../src/internal/KernelRefusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;;;;;AAExC;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wB,SAAQ,4BAa5C;CAAG;;;;;;;AAEJ;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,4BAe5C;CAAG;;;;;;AAEJ;;;GAGG;AACH,qBAAa,6BAA8B,SAAQ,kCAGlD;CAAG;;;;;;AAEJ;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,4BAc5C;CAAG"}
@@ -88,7 +88,140 @@ const rowPending = (operation, row) => new KernelRowPending({
88
88
  row,
89
89
  message: `The test kernel supplies ${operation} in build-order row ${row}.`
90
90
  });
91
+ /**
92
+ * Snapshot bytes are not a kernel snapshot this kernel reads: an unknown
93
+ * header, a body that is not the snapshot's JSON, or a value that does not
94
+ * decode.
95
+ */
96
+ var SnapshotMalformed = class extends Schema.TaggedError()("SnapshotMalformed", {
97
+ reason: Schema.String,
98
+ message: Schema.String
99
+ }) {};
100
+ /**
101
+ * A snapshot's body does not hash to the digest its header names, so its bytes
102
+ * changed after export.
103
+ */
104
+ var SnapshotDigestMismatch = class extends Schema.TaggedError()("SnapshotDigestMismatch", {
105
+ expected: Schema.String,
106
+ actual: Schema.String,
107
+ message: Schema.String
108
+ }) {};
109
+ /**
110
+ * A snapshot's components are not the components registered on the world
111
+ * restoring it.
112
+ */
113
+ var SnapshotComponentMismatch = class extends Schema.TaggedError()("SnapshotComponentMismatch", {
114
+ snapshot: Schema.Array(Schema.String),
115
+ registered: Schema.Array(Schema.String),
116
+ message: Schema.String
117
+ }) {};
118
+ /**
119
+ * A job's test world is named by no world, or by more than one, so the job
120
+ * could not run under the world that scheduled it.
121
+ */
122
+ var SnapshotWorldUnresolved = class extends Schema.TaggedError()("SnapshotWorldUnresolved", {
123
+ name: Schema.String,
124
+ reason: Schema.Literals(["missing", "ambiguous"]),
125
+ message: Schema.String
126
+ }) {};
127
+ /**
128
+ * A world holds work a snapshot does not carry: attempts held for `apply`, or,
129
+ * when it restores, commits of its own.
130
+ */
131
+ var SnapshotWorldBusy = class extends Schema.TaggedError()("SnapshotWorldBusy", {
132
+ version: Schema.Int,
133
+ held: Schema.Array(Schema.String),
134
+ message: Schema.String
135
+ }) {};
136
+ /**
137
+ * A snapshot marks a secret the restore was not given, so the raw value its
138
+ * replay needs is not in memory.
139
+ */
140
+ var SnapshotSecretMissing = class extends Schema.TaggedError()("SnapshotSecretMissing", {
141
+ ref: Schema.String,
142
+ message: Schema.String
143
+ }) {};
144
+ /**
145
+ * A world is running work a snapshot taken or restored now would split: calls
146
+ * from the test, scheduler walks, or function executions, nested and detached
147
+ * ones included.
148
+ */
149
+ var SnapshotWorldRunning = class extends Schema.TaggedError()("SnapshotWorldRunning", {
150
+ registry: Schema.Literals([
151
+ "running",
152
+ "walks",
153
+ "functions"
154
+ ]),
155
+ count: Schema.Int,
156
+ message: Schema.String
157
+ }) {};
158
+ /**
159
+ * A world has subscribers, whose identity versions a restore would rewind.
160
+ * Subscriptions are live client state, so a restore needs a world with none.
161
+ */
162
+ var SnapshotSubscribed = class extends Schema.TaggedError()("SnapshotSubscribed", {
163
+ subscribers: Schema.Int,
164
+ message: Schema.String
165
+ }) {};
166
+ /**
167
+ * A snapshot's identity counters stand at or behind an identity its state
168
+ * already holds, so the next allocation would reuse one.
169
+ */
170
+ var SnapshotAllocatorBehind = class extends Schema.TaggedError()("SnapshotAllocatorBehind", {
171
+ allocator: Schema.Literals([
172
+ "nextDocumentId",
173
+ "lastCreationTime",
174
+ "nextAttemptId",
175
+ "identityEpoch"
176
+ ]),
177
+ value: Schema.Finite,
178
+ required: Schema.Finite,
179
+ message: Schema.String
180
+ }) {};
181
+ /**
182
+ * A snapshot's rows are not what its write log publishes: a row filed under
183
+ * another table or an unregistered component, a version the log does not give
184
+ * it, or a log change whose before value is not the row it replaced.
185
+ */
186
+ var SnapshotRowInconsistent = class extends Schema.TaggedError()("SnapshotRowInconsistent", {
187
+ componentPath: Schema.String,
188
+ id: Schema.String,
189
+ reason: Schema.Literals([
190
+ "id",
191
+ "component",
192
+ "log",
193
+ "row",
194
+ "systemFields",
195
+ "duplicate"
196
+ ]),
197
+ message: Schema.String
198
+ }) {};
199
+ /**
200
+ * A snapshot's commit timestamps do not strictly increase through its write
201
+ * log, or its latest commit timestamp is not the log's last.
202
+ */
203
+ var SnapshotTimestampInconsistent = class extends Schema.TaggedError()("SnapshotTimestampInconsistent", {
204
+ version: Schema.Int,
205
+ commitTs: Schema.String,
206
+ message: Schema.String
207
+ }) {};
208
+ /**
209
+ * A snapshot's jobs and job rows disagree: a job with no row, a row with no
210
+ * job, a job left running, or a target no registered component exports.
211
+ */
212
+ var SnapshotJobInconsistent = class extends Schema.TaggedError()("SnapshotJobInconsistent", {
213
+ id: Schema.String,
214
+ reason: Schema.Literals([
215
+ "row",
216
+ "untargeted",
217
+ "inProgress",
218
+ "component",
219
+ "function",
220
+ "duplicate"
221
+ ]),
222
+ message: Schema.String
223
+ }) {};
91
224
  //#endregion
92
- export { ClosedAttempt, CommitTsNotIncreasing, DrainBudgetExceeded, KernelRowPending, OptimisticConcurrencyControlFailure, RegisteredAfterOpen, RequiresBinary, StaleAttempt, UnknownStandingSource, requiresBinary, rowPending };
225
+ export { ClosedAttempt, CommitTsNotIncreasing, DrainBudgetExceeded, KernelRowPending, OptimisticConcurrencyControlFailure, RegisteredAfterOpen, RequiresBinary, SnapshotAllocatorBehind, SnapshotComponentMismatch, SnapshotDigestMismatch, SnapshotJobInconsistent, SnapshotMalformed, SnapshotRowInconsistent, SnapshotSecretMissing, SnapshotSubscribed, SnapshotTimestampInconsistent, SnapshotWorldBusy, SnapshotWorldRunning, SnapshotWorldUnresolved, StaleAttempt, UnknownStandingSource, requiresBinary, rowPending };
93
226
 
94
227
  //# sourceMappingURL=KernelRefusal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KernelRefusal.js","names":[],"sources":["../../src/internal/KernelRefusal.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\n\n/**\n * The kernel never answers this operation in process. Only the binary does.\n */\nexport class RequiresBinary extends Schema.TaggedError<RequiresBinary>()(\n \"RequiresBinary\",\n {\n operation: Schema.Literals([\"textSearch\", \"vectorSearch\"]),\n message: Schema.String,\n },\n) {}\n\n/**\n * A later kernel row supplies this operation. Until then the kernel refuses it\n * rather than answer with convex-test's behaviour.\n */\nexport class KernelRowPending extends Schema.TaggedError<KernelRowPending>()(\n \"KernelRowPending\",\n {\n operation: Schema.String,\n row: Schema.Int,\n message: Schema.String,\n },\n) {}\n\n/**\n * A component was registered after the test backend opened, so its modules\n * would load after a function had already run.\n */\nexport class RegisteredAfterOpen extends Schema.TaggedError<RegisteredAfterOpen>()(\n \"RegisteredAfterOpen\",\n { componentPath: Schema.String, message: Schema.String },\n) {}\n\n/**\n * Every attempt of a mutation read data a commit changed before it could\n * publish. The kernel gives up on attempt 5.\n */\nexport class OptimisticConcurrencyControlFailure extends Schema.TaggedError<OptimisticConcurrencyControlFailure>()(\n \"OptimisticConcurrencyControlFailure\",\n { attempts: Schema.Int, message: Schema.String },\n) {}\n\n/**\n * A syscall reached a mutation's attempt after the mutation returned and its\n * syscalls drained, so the attempt was already held or published.\n */\nexport class ClosedAttempt extends Schema.TaggedError<ClosedAttempt>()(\n \"ClosedAttempt\",\n { operation: Schema.String, message: Schema.String },\n) {}\n\n/**\n * `apply` named an attempt the kernel does not hold: it was already applied, or\n * never prepared.\n */\nexport class StaleAttempt extends Schema.TaggedError<StaleAttempt>()(\n \"StaleAttempt\",\n { id: Schema.String, message: Schema.String },\n) {}\n\n/**\n * The runtime answered a commit timestamp no greater than the previous\n * commit's.\n */\nexport class CommitTsNotIncreasing extends Schema.TaggedError<CommitTsNotIncreasing>()(\n \"CommitTsNotIncreasing\",\n {\n version: Schema.Int,\n previous: Schema.BigInt,\n commitTs: Schema.BigInt,\n message: Schema.String,\n },\n) {}\n\n/**\n * Draining scheduled functions ran its budget of jobs and work still remained.\n * A self-rescheduling function keeps the drain from ending unless its kit\n * declares it standing.\n */\nexport class DrainBudgetExceeded extends Schema.TaggedError<DrainBudgetExceeded>()(\n \"DrainBudgetExceeded\",\n {\n budget: Schema.Int,\n pending: Schema.Array(\n Schema.Struct({ componentPath: Schema.String, name: Schema.String }),\n ),\n message: Schema.String,\n },\n) {}\n\n/**\n * A component declared a standing source its modules do not export.\n */\nexport class UnknownStandingSource extends Schema.TaggedError<UnknownStandingSource>()(\n \"UnknownStandingSource\",\n { componentPath: Schema.String, name: Schema.String, message: Schema.String },\n) {}\n\nexport const requiresBinary = (operation: RequiresBinary[\"operation\"]) =>\n new RequiresBinary({\n operation,\n message: `The test kernel does not simulate ${operation}. Run this case against the Convex binary.`,\n });\n\nexport const rowPending = (operation: string, row: number) =>\n new KernelRowPending({\n operation,\n row,\n message: `The test kernel supplies ${operation} in build-order row ${row}.`,\n });\n"],"mappings":";;;;;AAKA,IAAa,iBAAb,cAAoC,OAAO,YAA4B,CAAC,CACtE,kBACA;CACE,WAAW,OAAO,SAAS,CAAC,cAAc,cAAc,CAAC;CACzD,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAC1E,oBACA;CACE,WAAW,OAAO;CAClB,KAAK,OAAO;CACZ,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAChF,uBACA;CAAE,eAAe,OAAO;CAAQ,SAAS,OAAO;AAAO,CACzD,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,sCAAb,cAAyD,OAAO,YAAiD,CAAC,CAChH,uCACA;CAAE,UAAU,OAAO;CAAK,SAAS,OAAO;AAAO,CACjD,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,gBAAb,cAAmC,OAAO,YAA2B,CAAC,CACpE,iBACA;CAAE,WAAW,OAAO;CAAQ,SAAS,OAAO;AAAO,CACrD,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,eAAb,cAAkC,OAAO,YAA0B,CAAC,CAClE,gBACA;CAAE,IAAI,OAAO;CAAQ,SAAS,OAAO;AAAO,CAC9C,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,wBAAb,cAA2C,OAAO,YAAmC,CAAC,CACpF,yBACA;CACE,SAAS,OAAO;CAChB,UAAU,OAAO;CACjB,UAAU,OAAO;CACjB,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;;;;;AAOH,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAChF,uBACA;CACE,QAAQ,OAAO;CACf,SAAS,OAAO,MACd,OAAO,OAAO;EAAE,eAAe,OAAO;EAAQ,MAAM,OAAO;CAAO,CAAC,CACrE;CACA,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;;;AAKH,IAAa,wBAAb,cAA2C,OAAO,YAAmC,CAAC,CACpF,yBACA;CAAE,eAAe,OAAO;CAAQ,MAAM,OAAO;CAAQ,SAAS,OAAO;AAAO,CAC9E,CAAC,CAAC,CAAC;AAEH,MAAa,kBAAkB,cAC7B,IAAI,eAAe;CACjB;CACA,SAAS,qCAAqC,UAAU;AAC1D,CAAC;AAEH,MAAa,cAAc,WAAmB,QAC5C,IAAI,iBAAiB;CACnB;CACA;CACA,SAAS,4BAA4B,UAAU,sBAAsB,IAAI;AAC3E,CAAC"}
1
+ {"version":3,"file":"KernelRefusal.js","names":[],"sources":["../../src/internal/KernelRefusal.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\n\n/**\n * The kernel never answers this operation in process. Only the binary does.\n */\nexport class RequiresBinary extends Schema.TaggedError<RequiresBinary>()(\n \"RequiresBinary\",\n {\n operation: Schema.Literals([\"textSearch\", \"vectorSearch\"]),\n message: Schema.String,\n },\n) {}\n\n/**\n * A later kernel row supplies this operation. Until then the kernel refuses it\n * rather than answer with convex-test's behaviour.\n */\nexport class KernelRowPending extends Schema.TaggedError<KernelRowPending>()(\n \"KernelRowPending\",\n {\n operation: Schema.String,\n row: Schema.Int,\n message: Schema.String,\n },\n) {}\n\n/**\n * A component was registered after the test backend opened, so its modules\n * would load after a function had already run.\n */\nexport class RegisteredAfterOpen extends Schema.TaggedError<RegisteredAfterOpen>()(\n \"RegisteredAfterOpen\",\n { componentPath: Schema.String, message: Schema.String },\n) {}\n\n/**\n * Every attempt of a mutation read data a commit changed before it could\n * publish. The kernel gives up on attempt 5.\n */\nexport class OptimisticConcurrencyControlFailure extends Schema.TaggedError<OptimisticConcurrencyControlFailure>()(\n \"OptimisticConcurrencyControlFailure\",\n { attempts: Schema.Int, message: Schema.String },\n) {}\n\n/**\n * A syscall reached a mutation's attempt after the mutation returned and its\n * syscalls drained, so the attempt was already held or published.\n */\nexport class ClosedAttempt extends Schema.TaggedError<ClosedAttempt>()(\n \"ClosedAttempt\",\n { operation: Schema.String, message: Schema.String },\n) {}\n\n/**\n * `apply` named an attempt the kernel does not hold: it was already applied, or\n * never prepared.\n */\nexport class StaleAttempt extends Schema.TaggedError<StaleAttempt>()(\n \"StaleAttempt\",\n { id: Schema.String, message: Schema.String },\n) {}\n\n/**\n * The runtime answered a commit timestamp no greater than the previous\n * commit's.\n */\nexport class CommitTsNotIncreasing extends Schema.TaggedError<CommitTsNotIncreasing>()(\n \"CommitTsNotIncreasing\",\n {\n version: Schema.Int,\n previous: Schema.BigInt,\n commitTs: Schema.BigInt,\n message: Schema.String,\n },\n) {}\n\n/**\n * Draining scheduled functions ran its budget of jobs and work still remained.\n * A self-rescheduling function keeps the drain from ending unless its kit\n * declares it standing.\n */\nexport class DrainBudgetExceeded extends Schema.TaggedError<DrainBudgetExceeded>()(\n \"DrainBudgetExceeded\",\n {\n budget: Schema.Int,\n pending: Schema.Array(\n Schema.Struct({ componentPath: Schema.String, name: Schema.String }),\n ),\n message: Schema.String,\n },\n) {}\n\n/**\n * A component declared a standing source its modules do not export.\n */\nexport class UnknownStandingSource extends Schema.TaggedError<UnknownStandingSource>()(\n \"UnknownStandingSource\",\n { componentPath: Schema.String, name: Schema.String, message: Schema.String },\n) {}\n\nexport const requiresBinary = (operation: RequiresBinary[\"operation\"]) =>\n new RequiresBinary({\n operation,\n message: `The test kernel does not simulate ${operation}. Run this case against the Convex binary.`,\n });\n\nexport const rowPending = (operation: string, row: number) =>\n new KernelRowPending({\n operation,\n row,\n message: `The test kernel supplies ${operation} in build-order row ${row}.`,\n });\n\n/**\n * Snapshot bytes are not a kernel snapshot this kernel reads: an unknown\n * header, a body that is not the snapshot's JSON, or a value that does not\n * decode.\n */\nexport class SnapshotMalformed extends Schema.TaggedError<SnapshotMalformed>()(\n \"SnapshotMalformed\",\n { reason: Schema.String, message: Schema.String },\n) {}\n\n/**\n * A snapshot's body does not hash to the digest its header names, so its bytes\n * changed after export.\n */\nexport class SnapshotDigestMismatch extends Schema.TaggedError<SnapshotDigestMismatch>()(\n \"SnapshotDigestMismatch\",\n { expected: Schema.String, actual: Schema.String, message: Schema.String },\n) {}\n\n/**\n * A snapshot's components are not the components registered on the world\n * restoring it.\n */\nexport class SnapshotComponentMismatch extends Schema.TaggedError<SnapshotComponentMismatch>()(\n \"SnapshotComponentMismatch\",\n {\n snapshot: Schema.Array(Schema.String),\n registered: Schema.Array(Schema.String),\n message: Schema.String,\n },\n) {}\n\n/**\n * A job's test world is named by no world, or by more than one, so the job\n * could not run under the world that scheduled it.\n */\nexport class SnapshotWorldUnresolved extends Schema.TaggedError<SnapshotWorldUnresolved>()(\n \"SnapshotWorldUnresolved\",\n {\n name: Schema.String,\n reason: Schema.Literals([\"missing\", \"ambiguous\"]),\n message: Schema.String,\n },\n) {}\n\n/**\n * A world holds work a snapshot does not carry: attempts held for `apply`, or,\n * when it restores, commits of its own.\n */\nexport class SnapshotWorldBusy extends Schema.TaggedError<SnapshotWorldBusy>()(\n \"SnapshotWorldBusy\",\n {\n version: Schema.Int,\n held: Schema.Array(Schema.String),\n message: Schema.String,\n },\n) {}\n\n/**\n * A snapshot marks a secret the restore was not given, so the raw value its\n * replay needs is not in memory.\n */\nexport class SnapshotSecretMissing extends Schema.TaggedError<SnapshotSecretMissing>()(\n \"SnapshotSecretMissing\",\n { ref: Schema.String, message: Schema.String },\n) {}\n\n/**\n * A world is running work a snapshot taken or restored now would split: calls\n * from the test, scheduler walks, or function executions, nested and detached\n * ones included.\n */\nexport class SnapshotWorldRunning extends Schema.TaggedError<SnapshotWorldRunning>()(\n \"SnapshotWorldRunning\",\n {\n registry: Schema.Literals([\"running\", \"walks\", \"functions\"]),\n count: Schema.Int,\n message: Schema.String,\n },\n) {}\n\n/**\n * A world has subscribers, whose identity versions a restore would rewind.\n * Subscriptions are live client state, so a restore needs a world with none.\n */\nexport class SnapshotSubscribed extends Schema.TaggedError<SnapshotSubscribed>()(\n \"SnapshotSubscribed\",\n { subscribers: Schema.Int, message: Schema.String },\n) {}\n\n/**\n * A snapshot's identity counters stand at or behind an identity its state\n * already holds, so the next allocation would reuse one.\n */\nexport class SnapshotAllocatorBehind extends Schema.TaggedError<SnapshotAllocatorBehind>()(\n \"SnapshotAllocatorBehind\",\n {\n allocator: Schema.Literals([\n \"nextDocumentId\",\n \"lastCreationTime\",\n \"nextAttemptId\",\n \"identityEpoch\",\n ]),\n value: Schema.Finite,\n required: Schema.Finite,\n message: Schema.String,\n },\n) {}\n\n/**\n * A snapshot's rows are not what its write log publishes: a row filed under\n * another table or an unregistered component, a version the log does not give\n * it, or a log change whose before value is not the row it replaced.\n */\nexport class SnapshotRowInconsistent extends Schema.TaggedError<SnapshotRowInconsistent>()(\n \"SnapshotRowInconsistent\",\n {\n componentPath: Schema.String,\n id: Schema.String,\n reason: Schema.Literals([\n \"id\",\n \"component\",\n \"log\",\n \"row\",\n \"systemFields\",\n \"duplicate\",\n ]),\n message: Schema.String,\n },\n) {}\n\n/**\n * A snapshot's commit timestamps do not strictly increase through its write\n * log, or its latest commit timestamp is not the log's last.\n */\nexport class SnapshotTimestampInconsistent extends Schema.TaggedError<SnapshotTimestampInconsistent>()(\n \"SnapshotTimestampInconsistent\",\n { version: Schema.Int, commitTs: Schema.String, message: Schema.String },\n) {}\n\n/**\n * A snapshot's jobs and job rows disagree: a job with no row, a row with no\n * job, a job left running, or a target no registered component exports.\n */\nexport class SnapshotJobInconsistent extends Schema.TaggedError<SnapshotJobInconsistent>()(\n \"SnapshotJobInconsistent\",\n {\n id: Schema.String,\n reason: Schema.Literals([\n \"row\",\n \"untargeted\",\n \"inProgress\",\n \"component\",\n \"function\",\n \"duplicate\",\n ]),\n message: Schema.String,\n },\n) {}\n"],"mappings":";;;;;AAKA,IAAa,iBAAb,cAAoC,OAAO,YAA4B,CAAC,CACtE,kBACA;CACE,WAAW,OAAO,SAAS,CAAC,cAAc,cAAc,CAAC;CACzD,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAC1E,oBACA;CACE,WAAW,OAAO;CAClB,KAAK,OAAO;CACZ,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAChF,uBACA;CAAE,eAAe,OAAO;CAAQ,SAAS,OAAO;AAAO,CACzD,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,sCAAb,cAAyD,OAAO,YAAiD,CAAC,CAChH,uCACA;CAAE,UAAU,OAAO;CAAK,SAAS,OAAO;AAAO,CACjD,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,gBAAb,cAAmC,OAAO,YAA2B,CAAC,CACpE,iBACA;CAAE,WAAW,OAAO;CAAQ,SAAS,OAAO;AAAO,CACrD,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,eAAb,cAAkC,OAAO,YAA0B,CAAC,CAClE,gBACA;CAAE,IAAI,OAAO;CAAQ,SAAS,OAAO;AAAO,CAC9C,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,wBAAb,cAA2C,OAAO,YAAmC,CAAC,CACpF,yBACA;CACE,SAAS,OAAO;CAChB,UAAU,OAAO;CACjB,UAAU,OAAO;CACjB,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;;;;;AAOH,IAAa,sBAAb,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