@the_library/public 1.0.0

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 (90) hide show
  1. package/README.md +2298 -0
  2. package/assets/branding/data-pond.png +0 -0
  3. package/assets/branding/dsafe-logo.png +0 -0
  4. package/assets/branding/founder-photo.jpg +0 -0
  5. package/assets/branding/icon_transparent.png +0 -0
  6. package/assets/branding/library-favicon.png +0 -0
  7. package/assets/branding/pond-enterprise-logo.jpg +0 -0
  8. package/assets/branding/pond-enterprise-logo.svg +27 -0
  9. package/dist/branding/index.d.ts +48 -0
  10. package/dist/branding/index.js +67 -0
  11. package/dist/branding/index.js.map +1 -0
  12. package/dist/chunk-2HFOWE5R.js +296 -0
  13. package/dist/chunk-2HFOWE5R.js.map +1 -0
  14. package/dist/chunk-3L6LH2XK.js +465 -0
  15. package/dist/chunk-3L6LH2XK.js.map +1 -0
  16. package/dist/chunk-4CWVFPBN.js +28 -0
  17. package/dist/chunk-4CWVFPBN.js.map +1 -0
  18. package/dist/chunk-AGHPATVL.js +65 -0
  19. package/dist/chunk-AGHPATVL.js.map +1 -0
  20. package/dist/chunk-JDUYLUDJ.js +4835 -0
  21. package/dist/chunk-JDUYLUDJ.js.map +1 -0
  22. package/dist/chunk-OEZK7IX7.js +77 -0
  23. package/dist/chunk-OEZK7IX7.js.map +1 -0
  24. package/dist/chunk-PUYDAUCI.js +2873 -0
  25. package/dist/chunk-PUYDAUCI.js.map +1 -0
  26. package/dist/chunk-WHWMTS7D.js +99 -0
  27. package/dist/chunk-WHWMTS7D.js.map +1 -0
  28. package/dist/chunk-Y7RS6RTM.js +342 -0
  29. package/dist/chunk-Y7RS6RTM.js.map +1 -0
  30. package/dist/chunk-ZEZGI2TP.js +197 -0
  31. package/dist/chunk-ZEZGI2TP.js.map +1 -0
  32. package/dist/core-dao-core-logo-VDT2I5IW.svg +33 -0
  33. package/dist/downloader/dl2-sw.js +199 -0
  34. package/dist/downloader/dl2-sw.js.map +1 -0
  35. package/dist/downloader/file-worker-v2.js +258 -0
  36. package/dist/downloader/file-worker-v2.js.map +1 -0
  37. package/dist/downloader/index.d.ts +45 -0
  38. package/dist/downloader/index.js +538 -0
  39. package/dist/downloader/index.js.map +1 -0
  40. package/dist/downloader/mu-worker-v2.js +197 -0
  41. package/dist/downloader/mu-worker-v2.js.map +1 -0
  42. package/dist/downloader/react.d.ts +19 -0
  43. package/dist/downloader/react.js +32 -0
  44. package/dist/downloader/react.js.map +1 -0
  45. package/dist/downloader/solid.d.ts +21 -0
  46. package/dist/downloader/solid.js +19 -0
  47. package/dist/downloader/solid.js.map +1 -0
  48. package/dist/downloader/sw.d.ts +22 -0
  49. package/dist/downloader/sw.js +119 -0
  50. package/dist/downloader/sw.js.map +1 -0
  51. package/dist/downloader/vue.d.ts +23 -0
  52. package/dist/downloader/vue.js +19 -0
  53. package/dist/downloader/vue.js.map +1 -0
  54. package/dist/level-state-J3pj64Tr.d.ts +15 -0
  55. package/dist/models/astro.d.ts +47 -0
  56. package/dist/models/astro.js +44 -0
  57. package/dist/models/astro.js.map +1 -0
  58. package/dist/models/index.d.ts +244 -0
  59. package/dist/models/index.js +340 -0
  60. package/dist/models/index.js.map +1 -0
  61. package/dist/models/models.d.ts +524 -0
  62. package/dist/models/models.js +46 -0
  63. package/dist/models/models.js.map +1 -0
  64. package/dist/models/models_v2.global.js +1 -0
  65. package/dist/models/patch-worker.js +543 -0
  66. package/dist/models/patch-worker.js.map +1 -0
  67. package/dist/models/react.d.ts +43 -0
  68. package/dist/models/react.js +73 -0
  69. package/dist/models/react.js.map +1 -0
  70. package/dist/models/solid.d.ts +73 -0
  71. package/dist/models/solid.js +95 -0
  72. package/dist/models/solid.js.map +1 -0
  73. package/dist/models/vue.d.ts +51 -0
  74. package/dist/models/vue.js +98 -0
  75. package/dist/models/vue.js.map +1 -0
  76. package/dist/orm-BvkX0aBT.d.ts +507 -0
  77. package/dist/session-vqOnyxga.d.ts +184 -0
  78. package/dist/state-BTsp-E4v.d.ts +111 -0
  79. package/dist/types-Dn0EFMO_.d.ts +293 -0
  80. package/dist/types-Xb8Ta9tZ.d.ts +155 -0
  81. package/dist/web3/index.d.ts +820 -0
  82. package/dist/web3/index.js +1020 -0
  83. package/dist/web3/index.js.map +1 -0
  84. package/dist/web3/registry.d.ts +145 -0
  85. package/dist/web3/registry.js +23 -0
  86. package/dist/web3/registry.js.map +1 -0
  87. package/dist/web3/vue.d.ts +174 -0
  88. package/dist/web3/vue.js +391 -0
  89. package/dist/web3/vue.js.map +1 -0
  90. package/package.json +124 -0
@@ -0,0 +1,507 @@
1
+ declare enum PatchOperation {
2
+ EditPropertyString = 1,
3
+ EditPropertyNumber = 2,
4
+ EditInstanceFieldString = 3,
5
+ EditInstanceFieldNumber = 4,
6
+ EditRelation = 5,
7
+ SetAlias = 6,
8
+ CreateRecord = 7,
9
+ AddInstance = 8
10
+ }
11
+ declare enum PatchAction {
12
+ Remove = 0,
13
+ Add = 1
14
+ }
15
+ interface BasePatch {
16
+ operation: PatchOperation;
17
+ objectType: number;
18
+ objectId: number;
19
+ langId: number;
20
+ }
21
+ interface EditPropertyNumberObj extends BasePatch {
22
+ operation: PatchOperation.EditPropertyNumber;
23
+ propertyId: number;
24
+ value: number;
25
+ }
26
+ interface EditPropertyStringObj extends BasePatch {
27
+ operation: PatchOperation.EditPropertyString;
28
+ propertyId: number;
29
+ value: string;
30
+ }
31
+ interface EditInstanceFieldNumberObj extends BasePatch {
32
+ operation: PatchOperation.EditInstanceFieldNumber;
33
+ instanceIndex: number;
34
+ propertyId: number;
35
+ value: number;
36
+ }
37
+ interface EditInstanceFieldStringObj extends BasePatch {
38
+ operation: PatchOperation.EditInstanceFieldString;
39
+ instanceIndex: number;
40
+ propertyId: number;
41
+ value: string;
42
+ }
43
+ interface EditRelationObj extends BasePatch {
44
+ operation: PatchOperation.EditRelation;
45
+ relationId: number;
46
+ action: PatchAction;
47
+ targetId: number;
48
+ }
49
+ interface SetAliasObj {
50
+ operation: PatchOperation.SetAlias;
51
+ objectType: number;
52
+ fromUid: number;
53
+ toUid: number;
54
+ }
55
+ interface CreateRecordObj {
56
+ operation: PatchOperation.CreateRecord;
57
+ objectType: number;
58
+ objectId: number;
59
+ langId: 0;
60
+ }
61
+ interface AddInstanceObj extends BasePatch {
62
+ operation: PatchOperation.AddInstance;
63
+ objectType: number;
64
+ objectId: number;
65
+ langId: number;
66
+ instanceIndex: number;
67
+ }
68
+ type AnyPatch = EditPropertyNumberObj | EditPropertyStringObj | EditInstanceFieldNumberObj | EditInstanceFieldStringObj | EditRelationObj | SetAliasObj | CreateRecordObj | AddInstanceObj;
69
+ interface EnumLayout {
70
+ bits: number;
71
+ values: string[];
72
+ }
73
+ interface PropLayout {
74
+ name: string;
75
+ type: 'string' | 'number' | 'boolean' | 'enum';
76
+ bits: number;
77
+ enum?: string;
78
+ }
79
+ interface VersionEntry {
80
+ hash: string;
81
+ enums: Record<string, EnumLayout>;
82
+ props: Record<number, PropLayout>;
83
+ instanceFields: Record<number, number[]>;
84
+ }
85
+ interface VersionsFile {
86
+ current: number;
87
+ versions: Record<number, VersionEntry>;
88
+ }
89
+ interface VersionLayout {
90
+ hash: string;
91
+ enums: Record<string, EnumLayout>;
92
+ props: Record<number, PropLayout>;
93
+ instanceFields: Record<number, number[]>;
94
+ }
95
+ interface EvmPayload {
96
+ version: number;
97
+ patches: bigint[];
98
+ textIndex: number[];
99
+ textData: string[];
100
+ }
101
+ declare const LANG_ID_ENCODE: Record<string, number>;
102
+ declare const LANG_ID_DECODE: Record<number, string>;
103
+
104
+ /**
105
+ * Merges all version delta entries up to and including `version`.
106
+ *
107
+ * WARNING: COUPLING CONTRACT
108
+ * \`resolveLayout\` relies on \`computeVersionDelta\` emitting the FULL \`instanceFields\`
109
+ * array for any model that changed. It blindly overwrites the merged layout with the
110
+ * delta entry's array (\`merged.instanceFields[ot] = [...fields]\`). If future
111
+ * optimizations shrink \`versions.json\` by emitting only newly added fields, this
112
+ * function will silently corrupt the field layout by deleting historical fields.
113
+ */
114
+ declare function resolveLayout(version: number, versionsFile: VersionsFile): VersionLayout;
115
+ declare function packPatch(patch: AnyPatch, layout: VersionLayout): bigint;
116
+ declare function unpackPatch(packed: bigint, layout: VersionLayout): AnyPatch;
117
+ declare function patchToEvm(patches: AnyPatch[], layout: VersionLayout, version: number): EvmPayload;
118
+ declare function evmToPatch(payload: EvmPayload, versionsFile: VersionsFile): AnyPatch[];
119
+
120
+ declare enum LifecycleStatus {
121
+ Provisional = 0,
122
+ Submitted = 1,
123
+ CommunityPending = 2,
124
+ Canonical = 3
125
+ }
126
+
127
+ /**
128
+ * Local-only, non-EVM operations (analytics, local state).
129
+ * EVM-bound mutations use `PatchOperation` from `@the_library/db_schemas`
130
+ * (re-exported in `binary.ts`) — do not add EVM operation variants here.
131
+ */
132
+ declare enum ActionTypes {
133
+ Visit = 0,
134
+ VisitPart = 1,
135
+ Download = 2,
136
+ Rate = 3,
137
+ RatePart = 4,
138
+ Share = 5,
139
+ SharePart = 6
140
+ }
141
+ declare enum WorkerCommands {
142
+ Init = "init",// Initial load: fetch sidecars + local patches
143
+ SavePatches = "savePatches",
144
+ GetRecord = "getRecord",// LRU on-demand re-hydration (SPEC §2.5)
145
+ LoadLanguage = "loadLanguage"
146
+ }
147
+ declare enum Rating {
148
+ None = 0,
149
+ New = 1,
150
+ Keep = 2,
151
+ Trash = 3,
152
+ Shared = 4
153
+ }
154
+ declare enum WorkerEvent {
155
+ WorkerReady = "workerready",
156
+ WorkerLoadingError = "workerLoadingError",
157
+ DownloadStarted = "downloadStarted",
158
+ DownloadFinished = "downloadFinished",
159
+ DownloadError = "downloadError",
160
+ LevelUpdated = "levelUpdated"
161
+ }
162
+ declare enum DownloadState {
163
+ Unknown = 0,
164
+ Pending = 1,
165
+ InProgress = 2,
166
+ Done = 3,
167
+ Error = 4
168
+ }
169
+ /** Sidecar type byte in the DPM1 wire header (SPEC §4.1). */
170
+ declare enum SidecarType {
171
+ Slim = 0,
172
+ Extended = 1,
173
+ Provenance = 2
174
+ }
175
+
176
+ type Lang = string;
177
+ type uid = number;
178
+ interface RecordIdentityCluster {
179
+ sfcuid: string;
180
+ native: string;
181
+ aliases: string[];
182
+ wireId: number;
183
+ }
184
+ /**
185
+ * Key used in per-language value maps when a value is language-agnostic
186
+ * (patches with langId 0).
187
+ */
188
+ declare const LANG_AGNOSTIC: Lang;
189
+ /**
190
+ * One embedded instance (e.g. a PDF variant of a Book). Keys are the
191
+ * instanceField names from the schema; `isDefault` is appended by the
192
+ * sidecar writer and is not an instanceField.
193
+ */
194
+ type InstanceData = Record<string, string | number | boolean | null>;
195
+ /**
196
+ * V2 in-memory ORM tuple. All value maps are per-language (perLang defaults
197
+ * to true in the V2 schema); language-agnostic values use LANG_AGNOSTIC ("").
198
+ */
199
+ type CommonOrmJson = [
200
+ uid,
201
+ Map<number, Set<number>>,
202
+ Map<number, Set<number>>,
203
+ Map<number, Map<Lang, number>>,
204
+ Map<number, Map<Lang, boolean>>,
205
+ Map<number, Map<Lang, string>>,
206
+ Map<Lang, InstanceData[]>
207
+ ];
208
+ /** JSON-compatible serialization of CommonOrmJson (worker <-> main thread). */
209
+ type SerializedCommonOrmJson = [
210
+ uid,
211
+ Array<[number, Array<number>]>,
212
+ Array<[number, Array<number>]>,
213
+ Array<[number, Array<[Lang, number]>]>,
214
+ Array<[number, Array<[Lang, boolean]>]>,
215
+ Array<[number, Array<[Lang, string]>]>,
216
+ Array<[Lang, InstanceData[]]>
217
+ ];
218
+ type PropertyType = 'string' | 'number' | 'boolean' | 'enum';
219
+ interface BaseLocalOp {
220
+ ts: number;
221
+ action: ActionTypes;
222
+ objectType: number;
223
+ objectId: number;
224
+ }
225
+ interface RateOp extends BaseLocalOp {
226
+ rate: Rating;
227
+ }
228
+ interface PartOp extends BaseLocalOp {
229
+ part: number;
230
+ }
231
+ interface RatePartOp extends PartOp {
232
+ rate: Rating;
233
+ }
234
+ interface ShareOp extends BaseLocalOp {
235
+ socialMediaId: number;
236
+ }
237
+ interface SharePartOp extends PartOp {
238
+ socialMediaId: number;
239
+ }
240
+ type LocalOp = RateOp | RatePartOp | PartOp | ShareOp | SharePartOp | BaseLocalOp;
241
+ /**
242
+ * Anything the patcher queue can hold: EVM-bound V2 patches (`AnyPatch`,
243
+ * discriminated by `operation`) or local analytics ops (discriminated by `action`).
244
+ */
245
+ type QueueItem = AnyPatch | LocalOp;
246
+ declare const isEvmPatch: (item: QueueItem) => item is AnyPatch;
247
+ type SidecarUrls = {
248
+ objectType: number;
249
+ lang: Lang;
250
+ slimUrl?: string;
251
+ extendedUrl?: string;
252
+ provUrl?: string;
253
+ };
254
+ type InitPayload = {
255
+ cmd: WorkerCommands.Init;
256
+ payload: {
257
+ /** Flattened sidecar URLs for all selected languages. */
258
+ sidecars: Array<SidecarUrls>;
259
+ selectedLangs: Lang[];
260
+ };
261
+ };
262
+ type SavePatchesPayload = {
263
+ cmd: WorkerCommands.SavePatches;
264
+ payload: {
265
+ username: string;
266
+ patches: Array<QueueItem>;
267
+ };
268
+ };
269
+ type GetRecordPayload = {
270
+ cmd: WorkerCommands.GetRecord;
271
+ payload: {
272
+ objectType: number;
273
+ id: uid;
274
+ };
275
+ };
276
+ type LoadLanguagePayload = {
277
+ cmd: WorkerCommands.LoadLanguage;
278
+ payload: {
279
+ lang: Lang;
280
+ sidecars: Array<SidecarUrls>;
281
+ };
282
+ };
283
+ type WorkerPayload = InitPayload | SavePatchesPayload | GetRecordPayload | LoadLanguagePayload;
284
+ interface IThread {
285
+ sendRequest(payload: WorkerPayload, transferables?: Array<any>): Promise<any>;
286
+ }
287
+ type StatSummary = {
288
+ visits: Array<number>;
289
+ rating: Rating;
290
+ socialMediaId: Array<number>;
291
+ downloads: Array<number>;
292
+ parts: {
293
+ [partId: string]: {
294
+ rating: Rating;
295
+ socialMediaId: Array<number>;
296
+ visits: Array<number>;
297
+ };
298
+ };
299
+ };
300
+ interface BookData {
301
+ fileId: string;
302
+ parsed: boolean;
303
+ author: string;
304
+ title: string;
305
+ dimensions: Array<{
306
+ width: number;
307
+ height: number;
308
+ } | null>;
309
+ }
310
+ interface FileRecord {
311
+ id: string;
312
+ creationTime: number;
313
+ sizeKb: number;
314
+ content: Uint8Array;
315
+ local: boolean;
316
+ }
317
+
318
+ declare const PopulateStatsStore: (operations: Array<LocalOp>) => void;
319
+ declare const DownloadsByType: (objectType: number) => Array<number>;
320
+ declare const VisitsByType: (objectType: number) => Array<number>;
321
+ declare const FavoritesByTypes: (objectType: number) => Array<{
322
+ id: uid;
323
+ nbVisits: number;
324
+ rating: Rating;
325
+ }>;
326
+ declare class Stats {
327
+ private objectId;
328
+ protected objectType: number;
329
+ constructor(objectId: number, objectType: number);
330
+ favoriteParts(): Array<{
331
+ partId: number;
332
+ nbVisits: number;
333
+ rating: Rating;
334
+ }>;
335
+ check(): void;
336
+ visit(): void;
337
+ download(): void;
338
+ get rating(): Rating;
339
+ set rating(rating: Rating);
340
+ share(socialMediaId: number): void;
341
+ ratePart(partId: number, rating: Rating): void;
342
+ visitPart(partId: number): void;
343
+ }
344
+
345
+ interface UidFactory {
346
+ next(): Promise<{
347
+ wireId: number;
348
+ localId: number;
349
+ }>;
350
+ isUserCreated(wireId: number): boolean;
351
+ }
352
+
353
+ /**
354
+ * V2 model definition — the shape of the enriched JSON files in
355
+ * `@the_library/db_schemas/generated-src/*.json` (frozen numeric IDs).
356
+ */
357
+ interface SchemaProp {
358
+ name: string;
359
+ type: PropertyType;
360
+ source: 'slim' | 'extended';
361
+ propId: number;
362
+ enum?: string;
363
+ bits?: number;
364
+ nullable?: boolean;
365
+ }
366
+ interface SchemaInstanceField {
367
+ name: string;
368
+ type: PropertyType;
369
+ propId: number;
370
+ enum?: string;
371
+ bits?: number;
372
+ nullable?: boolean;
373
+ identityComponent?: boolean;
374
+ source?: 'slim' | 'extended';
375
+ }
376
+ interface SchemaRelation {
377
+ name: string;
378
+ targetType: string;
379
+ direction: 'has' | 'in';
380
+ inverted: string;
381
+ relationId: number;
382
+ }
383
+ /**
384
+ * Cols field name for a `has`-relation tail. The `authors` relation keeps its
385
+ * historical `authorIds` name for back-compat; every other relation uses its
386
+ * schema name directly (e.g. Tag.tags, Tag.books). Single source of truth for
387
+ * both the codegen (schemaGenerator.ts, which emits `${relationColName(rel)}`
388
+ * as the ExtendedCols field name) and the runtime reader (orm.ts's
389
+ * mergeExtended, which must look up that same field name on the incoming cols
390
+ * object) — they must never drift apart.
391
+ */
392
+ declare const relationColName: (rel: SchemaRelation) => string;
393
+ interface ModelDefinition {
394
+ name: string;
395
+ typePrefix: string;
396
+ objectId: number;
397
+ multipleInstances: boolean;
398
+ uidStrategy?: string | string[];
399
+ instanceUidStrategy?: string | string[];
400
+ standardPks?: Record<string, string>;
401
+ props: SchemaProp[];
402
+ instanceFields: SchemaInstanceField[];
403
+ relations: SchemaRelation[];
404
+ }
405
+ declare class SchemaRegistry {
406
+ private static instance;
407
+ private schemas;
408
+ private byName;
409
+ private constructor();
410
+ static getInstance(): SchemaRegistry;
411
+ register(schema: ModelDefinition): void;
412
+ get(id: number): ModelDefinition;
413
+ /** Lookup by model name (relation targetType resolution). */
414
+ getByName(name: string): ModelDefinition | undefined;
415
+ clear(): void;
416
+ }
417
+ declare const Registry: SchemaRegistry;
418
+
419
+ declare class Orm extends Stats {
420
+ readonly _id: uid;
421
+ protected _boolValues: Map<number, Map<string, boolean>>;
422
+ protected _stringValues: Map<number, Map<string, string>>;
423
+ protected _numberValues: Map<number, Map<string, number>>;
424
+ protected _has: Map<number, Set<number>>;
425
+ protected _in: Map<number, Set<number>>;
426
+ /** lang -> instance array (BookInstanceData structs, not ORM objects). */
427
+ protected _instances: Map<string, InstanceData[]>;
428
+ /** lang -> propId -> provenance code (2-bit: unset/AI/human/consensus). */
429
+ protected _provenance: Map<string, Map<number, number>>;
430
+ schema: ModelDefinition;
431
+ static createNewRequest(id: uid): CommonOrmJson;
432
+ static createNewRecord<T extends Orm>(this: {
433
+ new (json: any, creatorUsername?: string): T;
434
+ type: number;
435
+ }, uidFactory: UidFactory, creatorUsername: string): Promise<T>;
436
+ protected _creatorUsername?: string;
437
+ get creatorUsername(): string;
438
+ constructor(objectType: number, json: CommonOrmJson | SerializedCommonOrmJson, creatorUsername?: string);
439
+ toJSON(): SerializedCommonOrmJson;
440
+ get id(): number;
441
+ protected langOf(langId: number): Lang;
442
+ protected langIdOf(lang?: Lang): number;
443
+ get title(): string;
444
+ set title(value: string);
445
+ getTitle(lang: Lang): string;
446
+ setTitle(value: string, lang: Lang): void;
447
+ get description(): string;
448
+ set description(value: string);
449
+ getDescription(lang: Lang): string;
450
+ setDescription(value: string, lang: Lang): void;
451
+ get originalLang(): string;
452
+ set originalLang(value: string);
453
+ getOriginalLang(lang: Lang): string;
454
+ setOriginalLang(value: string, lang: Lang): void;
455
+ get ageGradeBand(): number;
456
+ set ageGradeBand(value: number);
457
+ get previewTxId(): string;
458
+ set previewTxId(value: string);
459
+ get safe(): boolean;
460
+ set safe(value: boolean);
461
+ get deleted(): boolean;
462
+ set deleted(value: boolean);
463
+ get lifecycleStatus(): LifecycleStatus;
464
+ set lifecycleStatus(value: LifecycleStatus);
465
+ protected dispatchString(propertyId: number, value: string, lang?: Lang): void;
466
+ protected dispatchNumber(propertyId: number, value: number, lang?: Lang): void;
467
+ protected dispatchRelation(relationId: number, action: PatchAction, targetId: number): void;
468
+ /**
469
+ * Raw in-memory relation mutation: no patch is emitted. Used by the
470
+ * generic inverse propagation in patch() and by generated in-side
471
+ * relation helpers. Idempotent (Set semantics).
472
+ */
473
+ protected applyRelationRaw(direction: 'has' | 'in', relationId: number, action: PatchAction, targetId: number): void;
474
+ /**
475
+ * Bulk-restores the inverse (`in`) edges implied by this record's forward
476
+ * (`has`) relations onto their target records. The sidecar serializes only
477
+ * the `has` direction (§3.7.1); `mergeExtended` fills `_has`, but the inverse
478
+ * side (`Person.authorOf`, `Tag.inTags`, …) stays empty until this runs.
479
+ *
480
+ * No patch emitted, no reactivity fired (bulk boot path). Idempotent (Set
481
+ * add). Targets must already be materialized — call after a full
482
+ * `hydrateAll` pass (see `rebuildInverseRelations`).
483
+ */
484
+ restoreInverses(): void;
485
+ /**
486
+ * Applies a V2 patch to the in-memory state. Triggers reactivity.
487
+ */
488
+ patch(patch: AnyPatch, _isMine?: boolean): void;
489
+ protected applyInstancePatch(p: EditInstanceFieldStringObj | EditInstanceFieldNumberObj): void;
490
+ protected getPropType(propId: number): 'string' | 'number' | 'boolean';
491
+ getProp(propId: number, lang?: Lang): any;
492
+ /** Direct state write — no patch emitted (used by merge methods). */
493
+ protected setRaw(propId: number, value: any, lang?: Lang): void;
494
+ getInstancesData(lang?: Lang): InstanceData[];
495
+ getDefaultInstanceData(lang?: Lang): InstanceData | undefined;
496
+ /** Direct state write — no patch emitted (used by mergeExtended/mergeSlim). */
497
+ setInstancesRaw(lang: Lang, instances: InstanceData[]): void;
498
+ growInstances(lang: Lang, toIndex: number): void;
499
+ addInstance(lang?: Lang): number;
500
+ getProvenance(propId: number, lang?: Lang): number;
501
+ setProvenanceRaw(lang: Lang, propId: number, value: number): void;
502
+ mergeSlim(cols: any, index: number, lang?: Lang): void;
503
+ mergeExtended(cols: any, index: number, lang?: Lang): void;
504
+ mergeProv(cols: any, index: number, lang?: Lang): void;
505
+ }
506
+
507
+ export { LANG_ID_DECODE as $, type AnyPatch as A, type BookData as B, type CommonOrmJson as C, DownloadState as D, type EvmPayload as E, type FileRecord as F, type GetRecordPayload as G, SchemaRegistry as H, type InstanceData as I, Registry as J, PatchOperation as K, type Lang as L, type ModelDefinition as M, PatchAction as N, Orm as O, type PropertyType as P, type QueueItem as Q, type RecordIdentityCluster as R, SidecarType as S, packPatch as T, unpackPatch as U, type VersionsFile as V, WorkerCommands as W, resolveLayout as X, patchToEvm as Y, evmToPatch as Z, LANG_ID_ENCODE as _, type SidecarUrls as a, type BasePatch as a0, type EditPropertyStringObj as a1, type EditPropertyNumberObj as a2, type EditInstanceFieldStringObj as a3, type EditInstanceFieldNumberObj as a4, type EditRelationObj as a5, type SetAliasObj as a6, type CreateRecordObj as a7, type AddInstanceObj as a8, type VersionEntry as a9, type EnumLayout as aa, type PropLayout as ab, PopulateStatsStore as ac, DownloadsByType as ad, VisitsByType as ae, FavoritesByTypes as af, Stats as ag, type SerializedCommonOrmJson as b, type VersionLayout as c, type IThread as d, ActionTypes as e, Rating as f, WorkerEvent as g, LANG_AGNOSTIC as h, type BaseLocalOp as i, type RateOp as j, type PartOp as k, type RatePartOp as l, type ShareOp as m, type SharePartOp as n, type LocalOp as o, isEvmPatch as p, type InitPayload as q, type SavePatchesPayload as r, type LoadLanguagePayload as s, type WorkerPayload as t, type uid as u, type StatSummary as v, type SchemaProp as w, type SchemaInstanceField as x, type SchemaRelation as y, relationColName as z };
@@ -0,0 +1,184 @@
1
+ import { S as SidecarType, I as InstanceData, L as Lang, a as SidecarUrls, Q as QueueItem, u as uid, O as Orm } from './orm-BvkX0aBT.js';
2
+
3
+ /**
4
+ * Sidecar binary wire format — parser and writer (SPEC §4).
5
+ *
6
+ * Every sidecar file begins with a 10-byte header (all multi-byte integers
7
+ * are big-endian):
8
+ *
9
+ * Offset Size Field
10
+ * 0 4 Magic number: 0x44504D31 ("DPM1")
11
+ * 4 1 Format version (0x02)
12
+ * 5 3 recordCount (uint24, big-endian, max 16,777,215)
13
+ * 8 1 columnCount (uint8)
14
+ * 9 1 sidecarType (0x00 = Slim, 0x01 = Extended, 0x02 = Provenance)
15
+ *
16
+ * Format version 0x01 used a uint16 recordCount (2 bytes, max 65,535) and
17
+ * uint16 relation target UIDs. Version 0x02 expands both to uint24.
18
+ *
19
+ * Columns follow sequentially: columnType (u8), nameLen (u8), name (UTF-8),
20
+ * then the column data block. Extended sidecars carry two structured tail
21
+ * sections after the columns: relations (self-describing) and instances.
22
+ */
23
+
24
+ /** Column type codes (SPEC §4.1). */
25
+ declare enum ColumnType {
26
+ Uint8 = 1,
27
+ Uint16 = 2,
28
+ NullableString = 3,
29
+ Relation = 4,// structured tail — flat uint32 stream
30
+ InstanceArray = 5,// structured tail — self-describing instance section
31
+ Uint32 = 6,
32
+ Bool = 7
33
+ }
34
+ /**
35
+ * One entry of the instance field descriptor embedded in Extended sidecars.
36
+ *
37
+ * The instances tail is SELF-DESCRIBING: the writer embeds
38
+ * `fieldCount + (typeCode, name)*` once per file, and instances are encoded
39
+ * in descriptor order. The parser never consults any model schema, so:
40
+ * - old files keep parsing correctly after instanceFields change,
41
+ * - any model with `multipleInstances: true` works with zero new code,
42
+ * - files written under an older schema simply yield InstanceData objects
43
+ * missing the newer fields.
44
+ */
45
+ interface InstanceFieldSpec {
46
+ name: string;
47
+ type: ColumnType;
48
+ }
49
+ type ColumnData = Uint8Array | Uint16Array | Uint32Array | Array<string | null>;
50
+ interface SidecarHeader {
51
+ formatVersion: number;
52
+ recordCount: number;
53
+ columnCount: number;
54
+ sidecarType: SidecarType;
55
+ }
56
+ interface ParsedSidecar {
57
+ header: SidecarHeader;
58
+ columns: Map<string, ColumnData>;
59
+ /**
60
+ * Per-record target-UID arrays for every `has`-direction relation, keyed by
61
+ * the schema relation name (Extended sidecars only). Self-describing: the
62
+ * writer embeds the relation names in the file, so the parser needs no
63
+ * schema and new relations parse with zero code change.
64
+ */
65
+ relations?: Map<string, number[][]>;
66
+ /** Back-compat alias for `relations.get('authors')`. */
67
+ authorIds?: number[][];
68
+ /** Field descriptor the instances were encoded with (Extended only). */
69
+ instanceFields?: InstanceFieldSpec[];
70
+ /** Per-record instance objects, keyed by field name (Extended only). */
71
+ instances?: InstanceData[][];
72
+ }
73
+
74
+ interface SidecarSet {
75
+ objectType: number;
76
+ lang: Lang;
77
+ slim?: ParsedSidecar;
78
+ extended?: ParsedSidecar;
79
+ prov?: ParsedSidecar;
80
+ /** uid -> array index, from the `ids` column of the slim tier. */
81
+ idIndex: Map<number, number>;
82
+ }
83
+
84
+ interface InitWorkersOptions {
85
+ workerPath?: string | URL;
86
+ sidecars: Array<SidecarUrls>;
87
+ selectedLangs: Lang[];
88
+ /** LRU limit per objectType — default 10 000 (use ~2 000 on mobile). */
89
+ cacheLimit?: number;
90
+ }
91
+ declare const InitPatchWorker: (options: InitWorkersOptions) => Promise<{
92
+ sidecars: Array<SidecarSet>;
93
+ patches: {
94
+ [user: string]: Array<QueueItem>;
95
+ };
96
+ }>;
97
+
98
+ /**
99
+ * Front-end boot orchestration for `@the_library/public/models`.
100
+ *
101
+ * Framework-agnostic: resolves sidecar locations (local folder OR registry_v2 →
102
+ * Arweave), spins up the worker, **eagerly hydrates the full corpus into the
103
+ * ORM**, and replays local patches. Framework adapters (e.g. the Solid
104
+ * `bootstrapModelsV2`) wrap this with reactivity + navigation persistence.
105
+ *
106
+ * Layer-clean: takes the registry data block structurally (no
107
+ * `web3-registry-addresses` dependency) and the model constructors from the
108
+ * caller (no constructor registry needed).
109
+ */
110
+
111
+ /** Per-objectType constructor the caller supplies (e.g. `{ type: Book.type, create: NewBookWithId }`). */
112
+ interface ModelFactory {
113
+ type: number;
114
+ create: (id: uid) => Orm;
115
+ }
116
+ /** Local `corpus-index.json` shape (the build artifact of `build-v2-corpus.ts`). */
117
+ interface LocalCorpusIndex {
118
+ lang?: string;
119
+ objects: Record<string, {
120
+ tiers: {
121
+ slim?: {
122
+ file: string;
123
+ }[];
124
+ extended?: {
125
+ file: string;
126
+ }[];
127
+ prov?: {
128
+ file: string;
129
+ }[];
130
+ };
131
+ }>;
132
+ }
133
+ /** registry_v2 manifest data block: `objects[type][lang][tier] = [txid, …]`. */
134
+ interface RegistryDataBlock {
135
+ objects?: Record<string, Record<string, {
136
+ slim?: string[];
137
+ extended?: string[];
138
+ prov?: string[];
139
+ }>>;
140
+ }
141
+ interface BootModelsV2Options {
142
+ /** Primary session language */
143
+ userLang: Lang;
144
+ /** Per-objectType constructors, e.g. `[{type:Book.type,create:NewBookWithId}, …]`. */
145
+ models: ModelFactory[];
146
+ selectedLangs?: Lang[];
147
+ /** Worker bundle URL (default `/patch-worker.js`). */
148
+ workerPath?: string | URL;
149
+ /**
150
+ * **Local mode** — base URL/path serving the `bin/` folder + `corpus-index.json`
151
+ * (book-manager dev: e.g. `/corpus_v2`). When set, the registry is ignored.
152
+ */
153
+ localMode?: string;
154
+ /** Pre-fetched local manifest (else fetched from `${localMode}/corpus-index.json`). */
155
+ localManifest?: LocalCorpusIndex;
156
+ /** **Registry mode** (used when `localMode` is absent) — resolved registry_v2 data block. */
157
+ registry?: {
158
+ dataBlock: RegistryDataBlock;
159
+ gateway?: string;
160
+ };
161
+ }
162
+ /**
163
+ * Full one-shot boot: resolve sidecar URLs (local folder or registry_v2 →
164
+ * Arweave) → init worker → eagerly hydrate the corpus → replay local patches.
165
+ * Returns the worker's `{ sidecars, patches }`.
166
+ */
167
+ declare function bootModelsV2(opts: BootModelsV2Options): Promise<Awaited<ReturnType<typeof InitPatchWorker>>>;
168
+ type BootResult = Awaited<ReturnType<typeof bootModelsV2>>;
169
+ interface SessionBootstrapOptions extends BootModelsV2Options {
170
+ /** Optional per-URL hook, fired after each Astro `<ClientRouter />` swap. */
171
+ onNavigate?: () => void;
172
+ /** Escape hatch — custom one-time boot, bypassing `bootModelsV2`'s source resolution. */
173
+ init?: () => void | Promise<void>;
174
+ /**
175
+ * Called once after the full boot completes (worker init + hydration + patch replay).
176
+ * Receives the raw worker result: `sidecars` (parsed SidecarSet[]) and `patches`
177
+ * (per-username QueueItem arrays). Use this instead of letting the result be discarded.
178
+ */
179
+ onBoot?: (data: BootResult) => void | Promise<void>;
180
+ }
181
+ /** Test/HMR helper — forgets the session so the next bootstrap re-inits. */
182
+ declare const resetModelsV2Session: () => void;
183
+
184
+ export { type SessionBootstrapOptions as S, resetModelsV2Session as r };