@wazootech/worlds-sdk 0.0.0-stage → 0.11.3

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 (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +288 -2
  3. package/THIRD_PARTY_NOTICES.md +279 -0
  4. package/dist/ai-sdk.d.ts +27 -0
  5. package/dist/ai-sdk.js +28 -0
  6. package/dist/build-search-result-id-qxdmXp0V.js +12 -0
  7. package/dist/chunk-and-embed-0crm0xLl.js +75 -0
  8. package/dist/client-BJ45zmXU.d.ts +74 -0
  9. package/dist/client-BWh0UAM0.js +45 -0
  10. package/dist/embedding-service-DebRMVmn.d.ts +15 -0
  11. package/dist/embedding-service.d.ts +3 -0
  12. package/dist/embedding-service.js +19 -0
  13. package/dist/index.d.ts +8 -0
  14. package/dist/index.js +9 -0
  15. package/dist/memory.d.ts +26 -0
  16. package/dist/memory.js +29 -0
  17. package/dist/mod-8Zh1f9vW.d.ts +24 -0
  18. package/dist/mod-BuF_B_xU.d.ts +362 -0
  19. package/dist/mod-CHiiyEER.d.ts +79 -0
  20. package/dist/mod-ClDFMN-C.d.ts +625 -0
  21. package/dist/mod-Dmrdrb03.d.ts +13 -0
  22. package/dist/quad-chunker.d.ts +2 -0
  23. package/dist/quad-chunker.js +1 -0
  24. package/dist/quad-store-BGCOUBxK.js +851 -0
  25. package/dist/quad-store.d.ts +2 -0
  26. package/dist/quad-store.js +3 -0
  27. package/dist/rdf-formats-BkGt5RDB.js +93 -0
  28. package/dist/rdfjs-BNVjLSNL.js +190 -0
  29. package/dist/rdfjs.d.ts +79 -0
  30. package/dist/rdfjs.js +1 -0
  31. package/dist/search-index.d.ts +2 -0
  32. package/dist/search-index.js +219 -0
  33. package/dist/sparql-engine.d.ts +2 -0
  34. package/dist/sparql-engine.js +0 -0
  35. package/dist/testing.d.ts +301 -0
  36. package/dist/testing.js +786 -0
  37. package/dist/tfjs-use.d.ts +42 -0
  38. package/dist/tfjs-use.js +315 -0
  39. package/dist/wazoo.d.ts +86 -0
  40. package/dist/wazoo.js +347 -0
  41. package/package.json +119 -4
@@ -0,0 +1,301 @@
1
+ /**
2
+ * The @wazootech/worlds-sdk/testing subpath is the shared parity harness for the
3
+ * durable-backend family (per the shared parity/benchmark suite definition,
4
+ * wazootech/workspace#72). It is a thin driver over the existing WorldsSdk seam —
5
+ * no new interfaces, no new runtime surface — consumed by backend repos as a
6
+ * devDependency in their phase-4 parity suites.
7
+ *
8
+ * - `parity-fixtures.ts` — the shared fixture corpus (multi-graph worlds,
9
+ * typed literals, RDF-star [declared], chunk-boundary texts, empty world,
10
+ * replace-mode) as plain N-Quads data.
11
+ * - `run-parity-suite.ts` — `runParitySuite`, comparing a candidate backend
12
+ * against a reference WorldsSdk on the corpus. Backend suites pin
13
+ * `createMemoryWorldsSdk` as the portable reference; `@wazootech/worlds-sqlite` is the
14
+ * durable source of truth for SQLite-family behavior.
15
+ */
16
+ import { D as SearchRequest, T as SearchIndexOnImport } from "./mod-BuF_B_xU.js";
17
+ import { o as SparqlValue } from "./mod-8Zh1f9vW.js";
18
+ import { n as WorldsSdkInterface } from "./client-BJ45zmXU.js";
19
+ import * as rdfjs from "@rdfjs/types";
20
+ import { U as TransactionContext, Y as Patch } from "./mod-ClDFMN-C.js";
21
+ import { t as EmbeddingService } from "./embedding-service-DebRMVmn.js";
22
+ /**
23
+ * Parity fixtures are the shared corpus every durable backend runs in its
24
+ * phase-4 parity suite (per the shared parity/benchmark suite definition,
25
+ * wazootech/workspace#72). Fixtures are plain data — N-Quads serialized
26
+ * strings parsed by the engine's TriG-superset grammar — so the corpus is
27
+ * backend-agnostic and versionable with the seam package.
28
+ */
29
+ /**
30
+ * SparqlExpectation is a hand-authored SPARQL result for a fixture query.
31
+ * SPARQL semantics are engine-independent, so these are the reliable
32
+ * deterministic expectations; search ranking is not (bm25 vs ts_rank_cd vs
33
+ * vector distance), so search cases are compared candidate-vs-reference
34
+ * instead of against authored snapshots.
35
+ */
36
+ export type SparqlExpectation = {
37
+ kind: "select";
38
+ bindings: Array<Record<string, SparqlValue>>;
39
+ } | {
40
+ kind: "ask";
41
+ boolean: boolean;
42
+ };
43
+ /** A search case: the same request runs against both Sdks; results must match. */
44
+ export interface ParitySearchCase {
45
+ /** name identifies the case in the parity report. */
46
+ name: string;
47
+ /** request is the search executed against both Sdks. */
48
+ request: SearchRequest;
49
+ }
50
+ /** A SPARQL case: the query runs against both Sdks and must match the authored expectation. */
51
+ export interface ParitySparqlCase {
52
+ /** name identifies the case in the parity report. */
53
+ name: string;
54
+ /** query is the SPARQL query executed against both Sdks. */
55
+ query: string;
56
+ /** expected is the hand-authored result both Sdks must satisfy. */
57
+ expected: SparqlExpectation;
58
+ }
59
+ /**
60
+ * gate controls corpus strictness:
61
+ * - "reference" (default): the case must pass on the reference WorldsSdk (libsql)
62
+ * and on the candidate. New fixtures default here.
63
+ * - "declared": the corpus category is declared but the durable reference does
64
+ * not support it yet (e.g. RDF-star storage — the backend-neutral Term
65
+ * layer still throws "Unsupported term type: Quad"). The case runs and is
66
+ * reported, but never fails the suite until the reference lands support.
67
+ */
68
+ export type ParityGate = "reference" | "declared";
69
+ /** ParityFixture is one world in the corpus plus its cases. */
70
+ export interface ParityFixture {
71
+ /** name identifies the fixture in the parity report. */
72
+ name: string;
73
+ /** nquads is the world serialized as N-Quads (engine TriG-superset grammar). */
74
+ nquads: string;
75
+ /** totalQuads is the exact quad count after a merge import. */
76
+ totalQuads: number;
77
+ /** graphSizes maps graph term values ("" = default graph) to exact quad counts. */
78
+ graphSizes?: Record<string, number>;
79
+ /** search compares the candidate's results to the reference's (order-sensitive by default). */
80
+ search?: ParitySearchCase[];
81
+ /** sparql runs against both Sdks and must match the authored expectation. */
82
+ sparql?: ParitySparqlCase[];
83
+ /** gate controls strictness; defaults to "reference". */
84
+ gate?: ParityGate;
85
+ }
86
+ /** ParityReplaceCase exercises replace-mode imports: `second` must fully replace `first`. */
87
+ export interface ParityReplaceCase {
88
+ /** name identifies the case in the parity report. */
89
+ name: string;
90
+ /** first is imported with replace mode first. */
91
+ first: string;
92
+ /** second is imported with replace mode second. */
93
+ second: string;
94
+ /** resultCount is the exact quad count after the second replace import. */
95
+ resultCount: number;
96
+ }
97
+ /** ParityCorpus is the full fixture registry consumed by runParitySuite. */
98
+ export interface ParityCorpus {
99
+ fixtures: ParityFixture[];
100
+ replaceCases: ParityReplaceCase[];
101
+ }
102
+ /**
103
+ * multiGraphWorld exercises the one-world-many-graphs guarantee
104
+ * (wazootech/workspace#71): default-graph quads plus named public and private
105
+ * graphs with overlapping subjects, searchable and queryable per graph.
106
+ */
107
+ export declare const multiGraphWorld: ParityFixture;
108
+ /**
109
+ * typedLiteralsWorld covers the literal type surface: plain (xsd:string),
110
+ * language-tagged (en/es/ar incl. RTL unicode), and typed literals
111
+ * (integer, double, date, boolean).
112
+ */
113
+ export declare const typedLiteralsWorld: ParityFixture;
114
+ /**
115
+ * rdfStarWorld declares the RDF-star corpus category (RDF 1.2 quoted-triple
116
+ * syntax). Under RDF 1.2 occurrence semantics, the quoted-triple subject
117
+ * statement expands to a reification quad (an anonymous reifier with
118
+ * rdf:reifies) plus the claim, so the world holds 3 quads. The SPARQL engine
119
+ * models quoted triples, but the durable reference cannot store them yet
120
+ * (the backend-neutral Term layer throws on Quad terms), so this fixture is
121
+ * gated "declared": it runs and is reported, but does not fail the suite
122
+ * until the reference lands RDF-star storage.
123
+ */
124
+ export declare const rdfStarWorld: ParityFixture;
125
+ /**
126
+ * chunkBoundaryWorld exercises the search chunker with a literal far longer
127
+ * than the reference's default 1000-char chunk size, plus a short needle
128
+ * literal. Both Sdks must produce identical chunk-derived search result ids.
129
+ */
130
+ export declare const chunkBoundaryWorld: ParityFixture;
131
+ /** emptyWorld verifies zero-quad behavior end to end. */
132
+ export declare const emptyWorld: ParityFixture;
133
+ /**
134
+ * replaceModeCase exercises replace-mode import: the second import must fully
135
+ * wipe the first (the reference's commit-patch replace-mode contract).
136
+ */
137
+ export declare const replaceModeCase: ParityReplaceCase;
138
+ /** parityCorpus is the full registry run by runParitySuite by default. */
139
+ export declare const parityCorpus: ParityCorpus;
140
+ /** WorldsSdkFactory constructs a fresh WorldsSdk (quad store + search + SPARQL wired) for one case. */
141
+ type WorldsSdkFactory = () => Promise<WorldsSdkInterface> | WorldsSdkInterface;
142
+ /** ParitySuiteOptions configures a parity run: the reference, the candidate, and the corpus. */
143
+ interface ParitySuiteOptions {
144
+ /**
145
+ * reference is the known-good WorldsSdk that candidates must match — the
146
+ * parity baseline per the shared suite definition. Backend suites pin
147
+ * `createMemoryWorldsSdk` (the portable in-memory reference); durable
148
+ * source-of-truth status lives in ARCHITECTURE.md, not in this option.
149
+ */
150
+ reference: WorldsSdkFactory;
151
+ /** candidate is the backend under test. */
152
+ candidate: WorldsSdkFactory;
153
+ /** fixtures overrides the corpus fixtures (defaults to parityCorpus.fixtures). */
154
+ fixtures?: ParityFixture[];
155
+ /** replaceCases overrides the corpus replace cases (defaults to parityCorpus.replaceCases). */
156
+ replaceCases?: ParityReplaceCase[];
157
+ /**
158
+ * strictSearchOrder enforces top-K result ordering equality between the
159
+ * reference and the candidate (default true — top-K ordering is part of the
160
+ * parity contract). Set false to compare result sets order-insensitively.
161
+ */
162
+ strictSearchOrder?: boolean;
163
+ }
164
+ /** ParityCaseResult is one fixture or replace case's verdict. */
165
+ interface ParityCaseResult {
166
+ /** name is the fixture or replace-case name. */
167
+ name: string;
168
+ /** ok is true when the case passed (declared-gate cases never fail the suite). */
169
+ ok: boolean;
170
+ /** failures lists concrete mismatches. */
171
+ failures: string[];
172
+ /** notes records informational observations (e.g. declared-gate skips). */
173
+ notes?: string[];
174
+ }
175
+ /** ParityReport aggregates every case in the run. */
176
+ interface ParityReport {
177
+ /** ok is true when every case passed. */
178
+ ok: boolean;
179
+ /** results is one entry per fixture and replace case. */
180
+ results: ParityCaseResult[];
181
+ /** notes records run-level observations, such as an optional case that was skipped. */
182
+ notes?: string[];
183
+ }
184
+ /**
185
+ * runParitySuite verifies a candidate durable backend against a reference
186
+ * WorldsSdk on the shared fixture corpus. Every fixture is imported into a fresh
187
+ * pair of WorldsSdks, then checked for: exact quad counts, per-graph counts,
188
+ * idempotent serialized export round-trips, SPARQL results against
189
+ * hand-authored expectations (both WorldsSdks), and search results compared to the
190
+ * reference (order-sensitive by default). See the shared parity/benchmark
191
+ * suite definition (wazootech/workspace#72).
192
+ */
193
+ export declare function runParitySuite(options: ParitySuiteOptions): Promise<ParityReport>;
194
+ /**
195
+ * CommitConformanceContract is what a backend promises about failures and
196
+ * defaults. The suite checks the promise, so a backend that cannot be atomic
197
+ * (D1, Vectorize) declares that instead of failing the suite.
198
+ */
199
+ interface CommitConformanceContract {
200
+ /**
201
+ * atomic is true when a failed write leaves no new quads and no new chunk
202
+ * rows. When false, the backend still promises no chunk row refers to a quad
203
+ * that is not stored.
204
+ */
205
+ atomic: boolean;
206
+ /**
207
+ * embeddingFailure is "throws": an embedding error rejects the commit before
208
+ * anything is written, on every backend. It is the only value; the field
209
+ * stays so existing contracts compile.
210
+ */
211
+ embeddingFailure: "throws";
212
+ /**
213
+ * replaceImportFailure is what a replace-mode import that fails during its
214
+ * write leaves behind: the old graph untouched, or an empty graph (the wipe
215
+ * ran, the new data did not land). Neither may leave orphan chunk rows.
216
+ */
217
+ replaceImportFailure: "keeps-old-graph" | "empties-graph";
218
+ /** defaultSearchIndexOnImport is the mode used when `searchIndexOnImport` is unset. */
219
+ defaultSearchIndexOnImport: SearchIndexOnImport;
220
+ /**
221
+ * laterWriteFailure is what a commit leaves behind when a write that comes
222
+ * after its quad writes fails (see `failLaterWrite`). Optional; the default is
223
+ * "restores-prior-state". An atomic backend always restores the prior state, so
224
+ * the field is ignored when `atomic` is true.
225
+ *
226
+ * - "restores-prior-state": the failed commit's quads and chunk rows are gone
227
+ * (rolled back, or removed by a cleanup).
228
+ * - "keeps-written-quads": the quads already written stay stored. The backend
229
+ * still promises no chunk row refers to a quad that is not stored.
230
+ */
231
+ laterWriteFailure?: "restores-prior-state" | "keeps-written-quads";
232
+ }
233
+ /** CommitConformanceCreateOptions is what the suite configures on each fresh subject. */
234
+ interface CommitConformanceCreateOptions {
235
+ /** searchIndexOnImport is the mode under test; undefined must select the declared default. */
236
+ searchIndexOnImport?: SearchIndexOnImport;
237
+ /**
238
+ * embeddingService is the service to wire. It returns 32-dimension vectors, or
239
+ * rejects on purpose; the subject must wire it as given (vectorDimensions 32).
240
+ */
241
+ embeddingService: EmbeddingService;
242
+ }
243
+ /**
244
+ * CommitConformanceSubject is a backend's commit path under test, wired with a
245
+ * text splitter that keeps each literal as one chunk and with failure hooks.
246
+ */
247
+ interface CommitConformanceSubject {
248
+ /** commit runs the backend's real commit path (the same one `Transaction.commit` reaches). */
249
+ commit(patch: Patch, context?: TransactionContext): Promise<void>;
250
+ /** storedQuads returns every quad the backend currently stores. */
251
+ storedQuads(): Promise<rdfjs.Quad[]>;
252
+ /** chunkedQuadIds returns the quad hash of every search chunk row, one entry per row. */
253
+ chunkedQuadIds(): Promise<string[]>;
254
+ /**
255
+ * failNextWrite makes the next write to durable storage fail once, after any
256
+ * embedding has finished. Earlier and later writes are unaffected.
257
+ */
258
+ failNextWrite(): void;
259
+ /**
260
+ * failLaterWrite is optional. It makes the next commit fail on a write that
261
+ * comes after that commit's quad writes have been applied, once: a chunk-row
262
+ * write inside the same transaction or batch, or a later batch of a chunked
263
+ * commit. `failNextWrite` hits the first write, so it cannot tell an atomic
264
+ * backend (which rolls the quad writes back) from a non-atomic one (which must
265
+ * clean them up, or declare `laterWriteFailure: "keeps-written-quads"`).
266
+ * Without this hook the suite skips the later-write case and says so in
267
+ * `report.notes`. The commit that fails must insert at least two novel textual
268
+ * quads under `searchIndexOnImport: "incremental"`, so a chunk write follows
269
+ * the quad writes; a backend whose commit is chunked should size its batches
270
+ * so the failing write is not the first batch.
271
+ */
272
+ failLaterWrite?(): void;
273
+ /** fullRebuildCount returns how many full search-index rebuilds have run. */
274
+ fullRebuildCount(): number;
275
+ }
276
+ /** CommitConformanceFactory creates a fresh, empty subject. */
277
+ type CommitConformanceFactory = (options: CommitConformanceCreateOptions) => Promise<CommitConformanceSubject> | CommitConformanceSubject;
278
+ /** CommitConformanceSuiteOptions configures one run of the suite. */
279
+ interface CommitConformanceSuiteOptions {
280
+ /** create builds a fresh subject per case. */
281
+ create: CommitConformanceFactory;
282
+ /** contract declares the backend's failure and default behavior. */
283
+ contract: CommitConformanceContract;
284
+ }
285
+ /**
286
+ * runCommitConformanceSuite checks one backend's commit and search-projection
287
+ * behavior against the shared contract: the `searchIndexOnImport` modes, the
288
+ * default mode, idempotent and delete-then-re-add writes, and what an embedding
289
+ * failure, a failed write, a failed replace import, and a failed later write
290
+ * (after the quad writes) leave behind.
291
+ *
292
+ * The later-write case needs the optional subject hook `failLaterWrite`. A
293
+ * subject without it keeps all other cases unchanged: the case is left out of
294
+ * `results` and the reason is added to `report.notes`.
295
+ *
296
+ * Each case runs on a fresh subject from `options.create`. The result has the
297
+ * same shape as `runParitySuite`'s report: assert `report.ok`, and print
298
+ * `failures` per case when it is false. A case that throws unexpectedly fails.
299
+ */
300
+ export declare function runCommitConformanceSuite(options: CommitConformanceSuiteOptions): Promise<ParityReport>;
301
+ export type { CommitConformanceContract, CommitConformanceCreateOptions, CommitConformanceFactory, CommitConformanceSubject, CommitConformanceSuiteOptions, ParityCaseResult, ParityReport, ParitySuiteOptions, WorldsSdkFactory };