mcard-js 2.1.39 → 2.1.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AbstractSqlEngine-BSfp8S_Y.d.cts +451 -0
- package/dist/AbstractSqlEngine-BSfp8S_Y.d.ts +451 -0
- package/dist/CardCollection-MXTUJV4J.js +9 -0
- package/dist/EventProducer-AWD6YMZR.js +47 -0
- package/dist/Handle-3N4QOA3U.js +13 -0
- package/dist/IndexedDBEngine-2G5KCISA.js +11 -0
- package/dist/LLMRuntime-LBWUJ7ON.js +16 -0
- package/dist/LambdaRuntime-B6D6IQKZ.js +18 -0
- package/dist/Loader-3LSJXJQG.js +11 -0
- package/dist/MCard-H56VOJLR.js +8 -0
- package/dist/NetworkRuntime-IAFHPQSX.js +1570 -0
- package/dist/OllamaProvider-QPX2JXL2.js +8 -0
- package/dist/chunk-2R4ESMZB.js +110 -0
- package/dist/chunk-3EIBJPNF.js +17 -0
- package/dist/chunk-3LPY36OG.js +355 -0
- package/dist/chunk-3MMMJ7NH.js +1068 -0
- package/dist/chunk-42VF42KH.js +273 -0
- package/dist/chunk-4PDYHPR6.js +297 -0
- package/dist/chunk-ADV52544.js +95 -0
- package/dist/chunk-FIE4LAJG.js +215 -0
- package/dist/chunk-PNKVD2UK.js +26 -0
- package/dist/chunk-RSTKX7WM.js +907 -0
- package/dist/chunk-VXV35I5J.js +2315 -0
- package/dist/index.browser.cjs +375 -276
- package/dist/index.browser.d.cts +4 -4
- package/dist/index.browser.d.ts +4 -4
- package/dist/index.browser.js +18 -13
- package/dist/index.cjs +382 -453
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +26 -21
- package/dist/storage/SqliteNodeEngine.cjs +395 -270
- package/dist/storage/SqliteNodeEngine.d.cts +9 -94
- package/dist/storage/SqliteNodeEngine.d.ts +9 -94
- package/dist/storage/SqliteNodeEngine.js +6 -5
- package/dist/storage/SqliteWasmEngine.cjs +382 -252
- package/dist/storage/SqliteWasmEngine.d.cts +8 -29
- package/dist/storage/SqliteWasmEngine.d.ts +8 -29
- package/dist/storage/SqliteWasmEngine.js +6 -5
- 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, MCard as M, type Page as P, type StorageEngine as S };
|