mcard-js 2.1.48 → 2.1.49

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 (37) hide show
  1. package/dist/AbstractSqlEngine-DKka6XjT.d.cts +451 -0
  2. package/dist/AbstractSqlEngine-DKka6XjT.d.ts +451 -0
  3. package/dist/CardCollection-ZQ3G3Q3A.js +10 -0
  4. package/dist/IndexedDBEngine-BWXAB46W.js +12 -0
  5. package/dist/LLMRuntime-PH3MOQ2Y.js +17 -0
  6. package/dist/LambdaRuntime-YH74FHIW.js +19 -0
  7. package/dist/Loader-WZXYG4GE.js +12 -0
  8. package/dist/NetworkRuntime-S4DZCGVN.js +1598 -0
  9. package/dist/OllamaProvider-SPGO5Z5E.js +9 -0
  10. package/dist/chunk-3FFEA2XK.js +149 -0
  11. package/dist/chunk-7AXRV7NS.js +112 -0
  12. package/dist/chunk-HIVVDGE5.js +497 -0
  13. package/dist/chunk-KVZYFZJ5.js +427 -0
  14. package/dist/chunk-NGTY4P6A.js +275 -0
  15. package/dist/chunk-OUW2SUGM.js +368 -0
  16. package/dist/chunk-QKH3N62B.js +2360 -0
  17. package/dist/chunk-QPVEUPMU.js +299 -0
  18. package/dist/chunk-VYDZR4ZD.js +364 -0
  19. package/dist/chunk-XJZOEM5F.js +903 -0
  20. package/dist/chunk-Z7EFXSTO.js +217 -0
  21. package/dist/index.browser.cjs +37 -1
  22. package/dist/index.browser.d.cts +20 -2
  23. package/dist/index.browser.d.ts +20 -2
  24. package/dist/index.browser.js +10 -6
  25. package/dist/index.cjs +618 -146
  26. package/dist/index.d.cts +723 -4
  27. package/dist/index.d.ts +723 -4
  28. package/dist/index.js +527 -89
  29. package/dist/storage/SqliteNodeEngine.cjs +7 -1
  30. package/dist/storage/SqliteNodeEngine.d.cts +1 -1
  31. package/dist/storage/SqliteNodeEngine.d.ts +1 -1
  32. package/dist/storage/SqliteNodeEngine.js +3 -3
  33. package/dist/storage/SqliteWasmEngine.cjs +7 -1
  34. package/dist/storage/SqliteWasmEngine.d.cts +1 -1
  35. package/dist/storage/SqliteWasmEngine.d.ts +1 -1
  36. package/dist/storage/SqliteWasmEngine.js +3 -3
  37. package/package.json +1 -1
@@ -0,0 +1,451 @@
1
+ /**
2
+ * DOTS Vocabulary Types
3
+ *
4
+ * From the Double Operadic Theory of Systems (DOTS), this module provides
5
+ * a minimal, domain-independent vocabulary for describing compositional systems.
6
+ *
7
+ * The MVP Cards architecture maps directly to DOTS:
8
+ * - MCard → Carrier (the actual data/systems)
9
+ * - PCard → Lens (tight) + Chart (loose)
10
+ * - VCard → Arena + Action
11
+ *
12
+ * Reference: docs/WorkingNotes/Hub/Theory/Integration/DOTS Vocabulary as Efficient Representation for ABC Curriculum.md
13
+ */
14
+ /**
15
+ * DOTS Role enumeration
16
+ *
17
+ * These nine terms (seven structural + Action + Unit) form a complete,
18
+ * compositional language for describing any system, interface, or interaction.
19
+ */
20
+ declare enum DOTSRole {
21
+ /**
22
+ * CARRIER - Category Car(S) of all actual data/systems
23
+ *
24
+ * MCard is the Carrier. Each MCard is an Object in the Carrier category;
25
+ * each hash-link is a Morphism in Car(S).
26
+ *
27
+ * Polynomial Form: Objects = MCards, Morphisms = hash references
28
+ */
29
+ CARRIER = "Carrier",
30
+ /**
31
+ * LENS - Tight morphism (structure-preserving interface map)
32
+ *
33
+ * PCard's abstract_spec ↔ concrete_impl relationship is a Lens.
34
+ * Ensures type safety: Abstract types match Concrete types.
35
+ *
36
+ * Lens = (get, put) pair with coherence laws
37
+ */
38
+ LENS = "Lens",
39
+ /**
40
+ * CHART - Loose morphism (behavioral interaction pattern)
41
+ *
42
+ * PCard's balanced_expectations (tests) describe the wiring.
43
+ * Enables flexibility: same Abstract spec via different Concrete implementations.
44
+ *
45
+ * Chart = horizontal morphism in Target double category
46
+ */
47
+ CHART = "Chart",
48
+ /**
49
+ * ARENA - Interface type (what can interact)
50
+ *
51
+ * VCard is the Arena. It defines the subject_did, capabilities[],
52
+ * and ExternalRef[]. An Arena is a pair of sets (Inputs, Outputs).
53
+ *
54
+ * Arena = (I, O) → Polynomial functor P(X) = Σ_{i∈I} X^{O(i)}
55
+ */
56
+ ARENA = "Arena",
57
+ /**
58
+ * ACTION - Module structure where interactions act on systems
59
+ *
60
+ * VCard enables Action: interactions (Charts/PCards) act on
61
+ * systems (MCards/Carrier) to produce new systems.
62
+ * The VCard authorization gate is the mechanism of this action.
63
+ *
64
+ * Action = Loose(I) ⊛ Car(S) → Car(S)
65
+ */
66
+ ACTION = "Action",
67
+ /**
68
+ * TARGET - Double category I of all interfaces and interactions
69
+ *
70
+ * The CLM design space. Contains all possible Arenas (objects),
71
+ * Lenses (tight morphisms), and Charts (loose morphisms).
72
+ */
73
+ TARGET = "Target",
74
+ /**
75
+ * TIGHT - Vertical composition direction (strict)
76
+ *
77
+ * Prerequisites chains. Cannot skip foundational concepts.
78
+ * Ensures type safety across compositions.
79
+ *
80
+ * Vertical = mandatory sequential dependency
81
+ */
82
+ TIGHT = "Tight",
83
+ /**
84
+ * LOOSE - Horizontal composition direction (flexible)
85
+ *
86
+ * Same concept via different interaction patterns.
87
+ * Enables behavioral flexibility while preserving semantics.
88
+ *
89
+ * Horizontal = parallel/interchangeable alternatives
90
+ */
91
+ LOOSE = "Loose",
92
+ /**
93
+ * UNIT - Identity object for parallel composition
94
+ *
95
+ * Empty MCard / Root Namespace. The neutral element.
96
+ * For any system S: Unit ⊗ S ≅ S
97
+ */
98
+ UNIT = "Unit"
99
+ }
100
+ /**
101
+ * EOS (Experimental-Operational Symmetry) Role
102
+ *
103
+ * Each MVP Card type enforces a specific dimension of symmetry
104
+ * to ensure environment-invariant correctness.
105
+ */
106
+ declare enum EOSRole {
107
+ /**
108
+ * INVARIANT_CONTENT - The Galois Root
109
+ *
110
+ * MCard: Hash(Content) is a pure function.
111
+ * Same content in Dev = Same hash in Prod.
112
+ * Environment-invariant identity.
113
+ */
114
+ INVARIANT_CONTENT = "InvariantContent",
115
+ /**
116
+ * GENERATIVE_LENS - Controlled Symmetry Breaking 1
117
+ *
118
+ * PCard: Pure function f(x)=y.
119
+ * Invariant in definition, variant only in input.
120
+ * The logic is environment-invariant.
121
+ */
122
+ GENERATIVE_LENS = "GenerativeLens",
123
+ /**
124
+ * SOVEREIGN_DECISION - Controlled Symmetry Breaking 2
125
+ *
126
+ * VCard: The Gap Junction.
127
+ * Breaks symmetry by introducing Authority.
128
+ * Decisional reality creation.
129
+ */
130
+ SOVEREIGN_DECISION = "SovereignDecision"
131
+ }
132
+ /**
133
+ * Card Plane in the MVP Cards architecture
134
+ *
135
+ * Maps to SDN (Software-Defined Networking) plane separation:
136
+ * Data Plane → Control Plane → Application Plane
137
+ */
138
+ declare enum CardPlane {
139
+ /**
140
+ * DATA_PLANE - MCard
141
+ *
142
+ * Immutable, content-addressable storage.
143
+ * The monadic foundation that wraps effects.
144
+ * CRD-only operations (Create, Retrieve, Delete).
145
+ */
146
+ DATA = "Data",
147
+ /**
148
+ * CONTROL_PLANE - PCard
149
+ *
150
+ * Polynomial functor composition.
151
+ * Monadic execution via PTR.
152
+ * Policy and logic gating.
153
+ */
154
+ CONTROL = "Control",
155
+ /**
156
+ * APPLICATION_PLANE - VCard
157
+ *
158
+ * Value exchange and authentication.
159
+ * Side effect management (IO Monad).
160
+ * Sovereign memory and authorization.
161
+ */
162
+ APPLICATION = "Application"
163
+ }
164
+ /**
165
+ * Polynomial Functor Type
166
+ *
167
+ * The mathematical foundation for DOTS.
168
+ * Every DOTS component is a polynomial functor of the form:
169
+ * P(X) = Σ_{i∈I} X^{O(i)}
170
+ */
171
+ interface PolynomialFunctor {
172
+ /** Positions (I) - input types, system states */
173
+ positions: string[];
174
+ /** Directions O(i) - output types per position */
175
+ directions: Record<string, string[]>;
176
+ }
177
+ /**
178
+ * DOTS metadata that can be attached to any card type
179
+ */
180
+ interface DOTSMetadata {
181
+ /** Primary DOTS role (Carrier, Lens, Chart, Arena, Action) */
182
+ role: DOTSRole;
183
+ /** EOS symmetry role */
184
+ eosRole?: EOSRole;
185
+ /** Card plane (Data, Control, Application) */
186
+ plane: CardPlane;
187
+ /** Polynomial functor representation (optional) */
188
+ polynomial?: PolynomialFunctor;
189
+ /** Tight morphism references (prerequisite hashes) */
190
+ tightRefs?: string[];
191
+ /** Loose morphism references (alternative implementation hashes) */
192
+ looseRefs?: string[];
193
+ }
194
+
195
+ /**
196
+ * MCard - Content-addressable data container (The Monad)
197
+ *
198
+ * ## Category Theory Role: MONAD
199
+ *
200
+ * MCard is the **Monad** in the MVP Cards categorical hierarchy:
201
+ * - **MCard (Monad)**: Data container with `unit` (create) and `bind` (chain)
202
+ * - **PCard (Functor)**: Pure transformation, `fmap` over MCard content
203
+ * - **VCard (Applicative)**: Context-aware application with pre-conditions
204
+ *
205
+ * ## Scale-Free Monadic Infrastructure: Spinoza-Leibniz Synthesis
206
+ *
207
+ * MCard implements the dual philosophical foundation:
208
+ *
209
+ * | Philosopher | Contribution | MCard Implementation |
210
+ * |-------------|--------------|---------------------|
211
+ * | **Spinoza** | One Substance (Deus sive Natura) | Fixed 3-field schema (Terminal Object) |
212
+ * | **Leibniz** | Infinite Monads (Pre-Established Harmony) | Infinite content-addressed entries |
213
+ * | **Both** | No windows / Internal causation | Content-addressing (same hash = same truth) |
214
+ *
215
+ * This enables **Experimental-Operational Symmetry (EOS)**: same behavior from
216
+ * a single user's PKC (100MB) to a planetary LLM registry (1PB).
217
+ *
218
+ * ## DOTS Vocabulary Role: CARRIER
219
+ *
220
+ * MCard is the **Carrier** in the Double Operadic Theory of Systems (DOTS).
221
+ * - Each MCard is an **Object** in the Carrier category Car(S)
222
+ * - Hash-links between MCards are **Morphisms** in Car(S)
223
+ * - The Carrier is the category of all actual data/systems
224
+ *
225
+ * ## Petri Net Role: TOKEN CONTENT
226
+ *
227
+ * In the Categorical Petri Net model:
228
+ * - **MCard content** is what tokens carry
229
+ * - **VCard** is the token type (Applicative wrapper)
230
+ * - **PCard** is the transition that transforms tokens
231
+ *
232
+ * ## MVP Cards Architecture: Data Plane
233
+ *
234
+ * ```
235
+ * ┌───────────────────────────────────────────────────────┐
236
+ * │ APPLICATION PLANE (VCard) │
237
+ * │ Petri Net Token / AuthN/AuthZ / Side Effects │
238
+ * └─────────────────────────┬─────────────────────────────┘
239
+ * │ (Pre-Condition Check)
240
+ * ┌─────────────────────────▼─────────────────────────────┐
241
+ * │ CONTROL PLANE (PCard) │
242
+ * │ Petri Net Transition / CLM Logic / Pure Function │
243
+ * └─────────────────────────┬─────────────────────────────┘
244
+ * │ (Content Transformation)
245
+ * ┌─────────────────────────▼─────────────────────────────┐
246
+ * │ DATA PLANE (MCard) ◀── YOU ARE HERE │
247
+ * │ Monad / Content-Addressable / Scale-Free Substrate │
248
+ * └───────────────────────────────────────────────────────┘
249
+ * ```
250
+ *
251
+ * ## The Empty Schema Principle (Kenosis)
252
+ *
253
+ * MCard embodies the Empty Schema Principle:
254
+ * - Schema contains NO domain-specific terms (only hash, content, g_time)
255
+ * - Domain customization happens via data (INSERT), not schema changes
256
+ * - Universal applicability: same structure for ANY domain
257
+ * - This emptiness enables universality (Kenosis in code)
258
+ *
259
+ * ## Three Tables as Irreducible Semiotic Triad
260
+ *
261
+ * The MCard infrastructure uses three tables (Peirce's semiotics):
262
+ * - `card` (Object/Referent): what the content means
263
+ * - `handle_registry` (Representamen/Sign): which concept is named
264
+ * - `handle_history` (Interpretant): how understanding evolved
265
+ *
266
+ * ## Functional Requirements
267
+ *
268
+ * | ID | Requirement | Implementation |
269
+ * |----|-------------|----------------|
270
+ * | M-1 | Content-addressable via hash | `this.hash = SHA-256(content)` |
271
+ * | M-2 | CRD-only (no UPDATE) | Immutable class, `readonly` fields |
272
+ * | M-3 | Include g_time for ordering | `this.g_time` field |
273
+ * | M-4 | Human-readable content | `getContentAsText()` method |
274
+ * | MONAD-1 | Unit (pure) operation | `MCard.create(content)` |
275
+ * | MONAD-2 | Bind (chain) operation | `MCard.bind(f)` via hash reference |
276
+ * | EOS-M1 | Hash is pure function | No side effects in hash computation |
277
+ * | EOS-M2 | Content is immutable | All fields are `readonly` |
278
+ *
279
+ * @see {@link DOTSRole.CARRIER} for DOTS vocabulary definition
280
+ * @see {@link EOSRole.INVARIANT_CONTENT} for EOS role definition
281
+ * @see docs/MCard_Impl.md for full implementation specification
282
+ */
283
+ declare class MCard {
284
+ readonly content: Uint8Array;
285
+ readonly hash: string;
286
+ readonly g_time: string;
287
+ readonly contentType: string;
288
+ readonly hashFunction: string;
289
+ protected constructor(content: Uint8Array, hash: string, g_time: string, contentType: string, hashFunction: string);
290
+ /**
291
+ * Create a new MCard from content
292
+ */
293
+ static create(content: string | Uint8Array, hashAlgorithm?: string): Promise<MCard>;
294
+ /**
295
+ * Create an MCard from existing data (e.g., from database)
296
+ */
297
+ static fromData(content: Uint8Array, hash: string, g_time: string): MCard;
298
+ /**
299
+ * Get content as text (UTF-8 decoded)
300
+ */
301
+ getContentAsText(): string;
302
+ /**
303
+ * Get content as raw bytes
304
+ */
305
+ getContent(): Uint8Array;
306
+ /**
307
+ * Convert to plain object
308
+ */
309
+ toObject(): {
310
+ hash: string;
311
+ content: string;
312
+ g_time: string;
313
+ contentType: string;
314
+ hashFunction: string;
315
+ };
316
+ /**
317
+ * Get DOTS vocabulary metadata for this MCard
318
+ *
319
+ * Returns the DOTS role information that positions this MCard
320
+ * in the Double Operadic Theory of Systems framework.
321
+ *
322
+ * MCard is always a CARRIER object in the Data Plane.
323
+ *
324
+ * @param tightRefs - Optional array of prerequisite MCard hashes (vertical composition)
325
+ * @param looseRefs - Optional array of alternative MCard hashes (horizontal composition)
326
+ * @returns DOTSMetadata describing this card's role in the compositional system
327
+ *
328
+ * @example
329
+ * ```typescript
330
+ * const card = await MCard.create('Hello World');
331
+ * const meta = card.getDOTSMetadata();
332
+ * console.log(meta.role); // 'Carrier'
333
+ * console.log(meta.plane); // 'Data'
334
+ * ```
335
+ */
336
+ getDOTSMetadata(tightRefs?: string[], looseRefs?: string[]): DOTSMetadata;
337
+ }
338
+
339
+ /**
340
+ * Page - Pagination container for query results
341
+ */
342
+ interface Page<T> {
343
+ items: T[];
344
+ totalItems: number;
345
+ pageNumber: number;
346
+ pageSize: number;
347
+ totalPages: number;
348
+ hasNext: boolean;
349
+ hasPrevious: boolean;
350
+ }
351
+ /**
352
+ * StorageEngine - Abstract interface for storage backends
353
+ *
354
+ * Implementations: IndexedDBEngine, SqliteWasmEngine
355
+ */
356
+ interface StorageEngine {
357
+ add(card: MCard): Promise<string>;
358
+ get(hash: string): Promise<MCard | null>;
359
+ delete(hash: string): Promise<void>;
360
+ searchByHash(hashPrefix: string): Promise<MCard[]>;
361
+ getPage(pageNumber: number, pageSize: number): Promise<Page<MCard>>;
362
+ search(query: string, pageNumber: number, pageSize: number): Promise<Page<MCard>>;
363
+ getAll(): Promise<MCard[]>;
364
+ count(): Promise<number>;
365
+ clear(): Promise<void>;
366
+ registerHandle(handle: string, hash: string): Promise<void>;
367
+ resolveHandle(handle: string): Promise<string | null>;
368
+ getByHandle(handle: string): Promise<MCard | null>;
369
+ updateHandle(handle: string, newHash: string): Promise<string>;
370
+ getHandleHistory(handle: string): Promise<{
371
+ previousHash: string;
372
+ changedAt: string;
373
+ }[]>;
374
+ pruneHandleHistory?(handle: string, options: {
375
+ olderThan?: string;
376
+ deleteAll?: boolean;
377
+ }): Promise<number>;
378
+ /** List all registered handles with their current hashes. */
379
+ getAllHandles(): Promise<{
380
+ handle: string;
381
+ hash: string;
382
+ }[]>;
383
+ /** Remove a handle and all its history entries. Does NOT delete the underlying card(s). */
384
+ removeHandle(handle: string): Promise<void>;
385
+ /** Rename a handle: update the handle key in registry and all history entries atomically. */
386
+ renameHandle(oldHandle: string, newHandle: string): Promise<void>;
387
+ /** Delete a single history entry by handle + previousHash, stitching the chain. */
388
+ deleteHistoryEntry(handle: string, previousHash: string): Promise<void>;
389
+ }
390
+
391
+ /**
392
+ * AbstractSqlEngine — Base class for SQL-backed StorageEngine implementations.
393
+ *
394
+ * Provides concrete implementations of all handle operations (register, resolve,
395
+ * update, rename, prune, delete history, etc.) using two abstract primitives
396
+ * that each SQL engine must implement:
397
+ *
398
+ * - queryRows(sql, ...params) — Run a SELECT and return row objects
399
+ * - execSql(sql, ...params) — Run a write statement and return rows-changed
400
+ *
401
+ * Card operations (add, get, delete, getPage, search, etc.) remain abstract
402
+ * because they involve engine-specific row ↔ MCard conversion logic.
403
+ */
404
+
405
+ declare abstract class AbstractSqlEngine implements StorageEngine {
406
+ /** Run a SELECT query and return row objects. */
407
+ protected abstract queryRows(sql: string, ...params: unknown[]): Promise<Record<string, unknown>[]>;
408
+ /** Run a write statement (INSERT/UPDATE/DELETE) and return rows-changed count. */
409
+ protected abstract execSql(sql: string, ...params: unknown[]): Promise<number>;
410
+ /** Convert a row object into an MCard. Engine-specific because of content types. */
411
+ protected abstract rowToCard(row: Record<string, unknown>): MCard;
412
+ /**
413
+ * SQL expression for casting content to text in search queries.
414
+ * Override in subclasses: SQLite uses 'TEXT', DuckDB uses 'VARCHAR'.
415
+ */
416
+ protected get castContentAs(): string;
417
+ /**
418
+ * Add a card. Default uses INSERT OR REPLACE (SQLite).
419
+ * DuckDB overrides with DELETE + INSERT.
420
+ */
421
+ add(card: MCard): Promise<string>;
422
+ get(hash: string): Promise<MCard | null>;
423
+ delete(hash: string): Promise<void>;
424
+ getPage(pageNumber?: number, pageSize?: number): Promise<Page<MCard>>;
425
+ count(): Promise<number>;
426
+ searchByHash(hashPrefix: string): Promise<MCard[]>;
427
+ search(queryStr: string, pageNumber?: number, pageSize?: number): Promise<Page<MCard>>;
428
+ getAll(): Promise<MCard[]>;
429
+ clear(): Promise<void>;
430
+ registerHandle(handle: string, hash: string): Promise<void>;
431
+ resolveHandle(handle: string): Promise<string | null>;
432
+ getByHandle(handle: string): Promise<MCard | null>;
433
+ updateHandle(handle: string, newHash: string): Promise<string>;
434
+ getHandleHistory(handle: string): Promise<{
435
+ previousHash: string;
436
+ changedAt: string;
437
+ }[]>;
438
+ pruneHandleHistory(handle: string, options?: {
439
+ olderThan?: string;
440
+ deleteAll?: boolean;
441
+ }): Promise<number>;
442
+ getAllHandles(): Promise<{
443
+ handle: string;
444
+ hash: string;
445
+ }[]>;
446
+ removeHandle(handle: string): Promise<void>;
447
+ renameHandle(oldHandle: string, newHandle: string): Promise<void>;
448
+ deleteHistoryEntry(handle: string, previousHash: string): Promise<void>;
449
+ }
450
+
451
+ export { AbstractSqlEngine as A, type DOTSMetadata as D, MCard as M, type Page as P, type StorageEngine as S };