ai-database 0.1.0 → 2.0.1
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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +9 -0
- package/README.md +381 -68
- package/TESTING.md +410 -0
- package/TEST_SUMMARY.md +250 -0
- package/TODO.md +128 -0
- package/dist/ai-promise-db.d.ts +370 -0
- package/dist/ai-promise-db.d.ts.map +1 -0
- package/dist/ai-promise-db.js +839 -0
- package/dist/ai-promise-db.js.map +1 -0
- package/dist/authorization.d.ts +531 -0
- package/dist/authorization.d.ts.map +1 -0
- package/dist/authorization.js +632 -0
- package/dist/authorization.js.map +1 -0
- package/dist/durable-clickhouse.d.ts +193 -0
- package/dist/durable-clickhouse.d.ts.map +1 -0
- package/dist/durable-clickhouse.js +422 -0
- package/dist/durable-clickhouse.js.map +1 -0
- package/dist/durable-promise.d.ts +182 -0
- package/dist/durable-promise.d.ts.map +1 -0
- package/dist/durable-promise.js +409 -0
- package/dist/durable-promise.js.map +1 -0
- package/dist/execution-queue.d.ts +239 -0
- package/dist/execution-queue.d.ts.map +1 -0
- package/dist/execution-queue.js +400 -0
- package/dist/execution-queue.js.map +1 -0
- package/dist/index.d.ts +50 -191
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -462
- package/dist/index.js.map +1 -0
- package/dist/linguistic.d.ts +115 -0
- package/dist/linguistic.d.ts.map +1 -0
- package/dist/linguistic.js +379 -0
- package/dist/linguistic.js.map +1 -0
- package/dist/memory-provider.d.ts +304 -0
- package/dist/memory-provider.d.ts.map +1 -0
- package/dist/memory-provider.js +785 -0
- package/dist/memory-provider.js.map +1 -0
- package/dist/schema.d.ts +899 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +1165 -0
- package/dist/schema.js.map +1 -0
- package/dist/tests.d.ts +107 -0
- package/dist/tests.d.ts.map +1 -0
- package/dist/tests.js +568 -0
- package/dist/tests.js.map +1 -0
- package/dist/types.d.ts +972 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +126 -0
- package/dist/types.js.map +1 -0
- package/package.json +37 -37
- package/src/ai-promise-db.ts +1243 -0
- package/src/authorization.ts +1102 -0
- package/src/durable-clickhouse.ts +596 -0
- package/src/durable-promise.ts +582 -0
- package/src/execution-queue.ts +608 -0
- package/src/index.test.ts +868 -0
- package/src/index.ts +337 -0
- package/src/linguistic.ts +404 -0
- package/src/memory-provider.test.ts +1036 -0
- package/src/memory-provider.ts +1119 -0
- package/src/schema.test.ts +1254 -0
- package/src/schema.ts +2296 -0
- package/src/tests.ts +725 -0
- package/src/types.ts +1177 -0
- package/test/README.md +153 -0
- package/test/edge-cases.test.ts +646 -0
- package/test/provider-resolution.test.ts +402 -0
- package/tsconfig.json +9 -0
- package/vitest.config.ts +19 -0
- package/dist/index.d.mts +0 -195
- package/dist/index.mjs +0 -430
package/dist/index.js
CHANGED
|
@@ -1,462 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
var getPayloadInstance = (options) => {
|
|
81
|
-
if (options.payload) {
|
|
82
|
-
return options.payload;
|
|
83
|
-
}
|
|
84
|
-
if (options.apiUrl) {
|
|
85
|
-
const restConfig = {
|
|
86
|
-
apiUrl: options.apiUrl,
|
|
87
|
-
apiKey: options.apiKey,
|
|
88
|
-
headers: options.headers,
|
|
89
|
-
fetchOptions: options.fetchOptions
|
|
90
|
-
};
|
|
91
|
-
return createRestClient(restConfig);
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
if (typeof global !== "undefined" && global.payload) {
|
|
95
|
-
return global.payload;
|
|
96
|
-
}
|
|
97
|
-
} catch (e) {
|
|
98
|
-
}
|
|
99
|
-
throw new Error("No Payload instance provided. Please provide a payload instance or apiUrl.");
|
|
100
|
-
};
|
|
101
|
-
var createRestClient = (config) => {
|
|
102
|
-
const { apiUrl, apiKey, headers = {}, fetchOptions = {} } = config;
|
|
103
|
-
const requestHeaders = {
|
|
104
|
-
"Content-Type": "application/json",
|
|
105
|
-
...headers
|
|
106
|
-
};
|
|
107
|
-
if (apiKey) {
|
|
108
|
-
requestHeaders["Authorization"] = `Bearer ${apiKey}`;
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
find: async (options) => {
|
|
112
|
-
const { collection, ...params } = options;
|
|
113
|
-
const searchParams = new URLSearchParams();
|
|
114
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
115
|
-
if (typeof value === "object") {
|
|
116
|
-
searchParams.append(key, JSON.stringify(value));
|
|
117
|
-
} else {
|
|
118
|
-
searchParams.append(key, String(value));
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
const url = `${apiUrl}/${collection}?${searchParams.toString()}`;
|
|
122
|
-
const response = await fetch(url, {
|
|
123
|
-
method: "GET",
|
|
124
|
-
headers: requestHeaders,
|
|
125
|
-
...fetchOptions
|
|
126
|
-
});
|
|
127
|
-
if (!response.ok) {
|
|
128
|
-
const error = await response.json();
|
|
129
|
-
throw new Error(error.message || `Failed to fetch from ${collection}`);
|
|
130
|
-
}
|
|
131
|
-
return response.json();
|
|
132
|
-
},
|
|
133
|
-
findByID: async (options) => {
|
|
134
|
-
const { collection, id, ...params } = options;
|
|
135
|
-
const searchParams = new URLSearchParams();
|
|
136
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
137
|
-
if (typeof value === "object") {
|
|
138
|
-
searchParams.append(key, JSON.stringify(value));
|
|
139
|
-
} else {
|
|
140
|
-
searchParams.append(key, String(value));
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
const url = `${apiUrl}/${collection}/${id}?${searchParams.toString()}`;
|
|
144
|
-
const response = await fetch(url, {
|
|
145
|
-
method: "GET",
|
|
146
|
-
headers: requestHeaders,
|
|
147
|
-
...fetchOptions
|
|
148
|
-
});
|
|
149
|
-
if (!response.ok) {
|
|
150
|
-
const error = await response.json();
|
|
151
|
-
throw new Error(error.message || `Failed to fetch ${id} from ${collection}`);
|
|
152
|
-
}
|
|
153
|
-
return response.json();
|
|
154
|
-
},
|
|
155
|
-
create: async (options) => {
|
|
156
|
-
const { collection, data } = options;
|
|
157
|
-
const url = `${apiUrl}/${collection}`;
|
|
158
|
-
const response = await fetch(url, {
|
|
159
|
-
method: "POST",
|
|
160
|
-
headers: requestHeaders,
|
|
161
|
-
body: JSON.stringify(data),
|
|
162
|
-
...fetchOptions
|
|
163
|
-
});
|
|
164
|
-
if (!response.ok) {
|
|
165
|
-
const error = await response.json();
|
|
166
|
-
throw new Error(error.message || `Failed to create document in ${collection}`);
|
|
167
|
-
}
|
|
168
|
-
return response.json();
|
|
169
|
-
},
|
|
170
|
-
update: async (options) => {
|
|
171
|
-
const { collection, id, data } = options;
|
|
172
|
-
const url = `${apiUrl}/${collection}/${id}`;
|
|
173
|
-
const response = await fetch(url, {
|
|
174
|
-
method: "PATCH",
|
|
175
|
-
headers: requestHeaders,
|
|
176
|
-
body: JSON.stringify(data),
|
|
177
|
-
...fetchOptions
|
|
178
|
-
});
|
|
179
|
-
if (!response.ok) {
|
|
180
|
-
const error = await response.json();
|
|
181
|
-
throw new Error(error.message || `Failed to update document ${id} in ${collection}`);
|
|
182
|
-
}
|
|
183
|
-
return response.json();
|
|
184
|
-
},
|
|
185
|
-
delete: async (options) => {
|
|
186
|
-
const { collection, id } = options;
|
|
187
|
-
const url = `${apiUrl}/${collection}/${id}`;
|
|
188
|
-
const response = await fetch(url, {
|
|
189
|
-
method: "DELETE",
|
|
190
|
-
headers: requestHeaders,
|
|
191
|
-
...fetchOptions
|
|
192
|
-
});
|
|
193
|
-
if (!response.ok) {
|
|
194
|
-
const error = await response.json();
|
|
195
|
-
throw new Error(error.message || `Failed to delete document ${id} from ${collection}`);
|
|
196
|
-
}
|
|
197
|
-
return response.json();
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
// src/collectionHandler.ts
|
|
203
|
-
var CollectionHandler = class {
|
|
204
|
-
payload;
|
|
205
|
-
collection;
|
|
206
|
-
/**
|
|
207
|
-
* Creates a new collection handler
|
|
208
|
-
* @param options Collection handler options
|
|
209
|
-
*/
|
|
210
|
-
constructor(options) {
|
|
211
|
-
this.payload = options.payload;
|
|
212
|
-
this.collection = options.collectionName;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Find documents in the collection
|
|
216
|
-
* @template T Type of documents to return
|
|
217
|
-
* @param options Query options including filtering, sorting, and pagination
|
|
218
|
-
* @returns Promise resolving to a list of documents
|
|
219
|
-
*/
|
|
220
|
-
async find(options = {}) {
|
|
221
|
-
try {
|
|
222
|
-
const transformedOptions = transformQueryOptions(options);
|
|
223
|
-
const result = await this.payload.find({
|
|
224
|
-
collection: this.collection,
|
|
225
|
-
...transformedOptions
|
|
226
|
-
});
|
|
227
|
-
return {
|
|
228
|
-
docs: result.docs || [],
|
|
229
|
-
totalDocs: result.totalDocs || 0,
|
|
230
|
-
page: result.page || 1,
|
|
231
|
-
totalPages: result.totalPages || 1,
|
|
232
|
-
limit: result.limit || 10,
|
|
233
|
-
hasPrevPage: result.hasPrevPage || false,
|
|
234
|
-
hasNextPage: result.hasNextPage || false,
|
|
235
|
-
prevPage: result.prevPage || null,
|
|
236
|
-
nextPage: result.nextPage || null
|
|
237
|
-
};
|
|
238
|
-
} catch (error) {
|
|
239
|
-
return handleError(error, "find", this.collection);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Find a single document by ID
|
|
244
|
-
* @template T Type of document to return
|
|
245
|
-
* @param id Document ID
|
|
246
|
-
* @returns Promise resolving to a single document
|
|
247
|
-
*/
|
|
248
|
-
async findOne(id) {
|
|
249
|
-
try {
|
|
250
|
-
return await this.payload.findByID({
|
|
251
|
-
collection: this.collection,
|
|
252
|
-
id
|
|
253
|
-
});
|
|
254
|
-
} catch (error) {
|
|
255
|
-
return handleError(error, "findOne", this.collection);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Create a new document in the collection
|
|
260
|
-
* @template T Type of document to create
|
|
261
|
-
* @param data Document data
|
|
262
|
-
* @returns Promise resolving to the created document
|
|
263
|
-
*/
|
|
264
|
-
async create(data) {
|
|
265
|
-
try {
|
|
266
|
-
return await this.payload.create({
|
|
267
|
-
collection: this.collection,
|
|
268
|
-
data
|
|
269
|
-
});
|
|
270
|
-
} catch (error) {
|
|
271
|
-
return handleError(error, "create", this.collection);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Update an existing document
|
|
276
|
-
* @template T Type of document to update
|
|
277
|
-
* @param id Document ID
|
|
278
|
-
* @param data Updated document data
|
|
279
|
-
* @returns Promise resolving to the updated document
|
|
280
|
-
*/
|
|
281
|
-
async update(id, data) {
|
|
282
|
-
try {
|
|
283
|
-
return await this.payload.update({
|
|
284
|
-
collection: this.collection,
|
|
285
|
-
id,
|
|
286
|
-
data
|
|
287
|
-
});
|
|
288
|
-
} catch (error) {
|
|
289
|
-
return handleError(error, "update", this.collection);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Delete a document
|
|
294
|
-
* @template T Type of deleted document
|
|
295
|
-
* @param id Document ID
|
|
296
|
-
* @returns Promise resolving to the deleted document
|
|
297
|
-
*/
|
|
298
|
-
async delete(id) {
|
|
299
|
-
try {
|
|
300
|
-
return await this.payload.delete({
|
|
301
|
-
collection: this.collection,
|
|
302
|
-
id
|
|
303
|
-
});
|
|
304
|
-
} catch (error) {
|
|
305
|
-
return handleError(error, "delete", this.collection);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Search for documents
|
|
310
|
-
* @template T Type of documents to search
|
|
311
|
-
* @param query Search query string
|
|
312
|
-
* @param options Query options
|
|
313
|
-
* @returns Promise resolving to a list of matching documents
|
|
314
|
-
*/
|
|
315
|
-
async search(query, options = {}) {
|
|
316
|
-
try {
|
|
317
|
-
const transformedOptions = transformQueryOptions(options);
|
|
318
|
-
if (typeof this.payload.search === "function") {
|
|
319
|
-
const result2 = await this.payload.search({
|
|
320
|
-
collection: this.collection,
|
|
321
|
-
query,
|
|
322
|
-
...transformedOptions
|
|
323
|
-
});
|
|
324
|
-
return {
|
|
325
|
-
docs: result2.docs || [],
|
|
326
|
-
totalDocs: result2.totalDocs || 0,
|
|
327
|
-
page: result2.page || 1,
|
|
328
|
-
totalPages: result2.totalPages || 1,
|
|
329
|
-
limit: result2.limit || 10,
|
|
330
|
-
hasPrevPage: result2.hasPrevPage || false,
|
|
331
|
-
hasNextPage: result2.hasNextPage || false,
|
|
332
|
-
prevPage: result2.prevPage || null,
|
|
333
|
-
nextPage: result2.nextPage || null
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
const result = await this.payload.find({
|
|
337
|
-
collection: this.collection,
|
|
338
|
-
search: query,
|
|
339
|
-
...transformedOptions
|
|
340
|
-
});
|
|
341
|
-
return {
|
|
342
|
-
docs: result.docs || [],
|
|
343
|
-
totalDocs: result.totalDocs || 0,
|
|
344
|
-
page: result.page || 1,
|
|
345
|
-
totalPages: result.totalPages || 1,
|
|
346
|
-
limit: result.limit || 10,
|
|
347
|
-
hasPrevPage: result.hasPrevPage || false,
|
|
348
|
-
hasNextPage: result.hasNextPage || false,
|
|
349
|
-
prevPage: result.prevPage || null,
|
|
350
|
-
nextPage: result.nextPage || null
|
|
351
|
-
};
|
|
352
|
-
} catch (error) {
|
|
353
|
-
return handleError(error, "search", this.collection);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
// src/adapters/node.ts
|
|
359
|
-
var createNodeClient = (options = {}) => {
|
|
360
|
-
return DB(options);
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
// src/adapters/edge.ts
|
|
364
|
-
var createEdgeClient = (options = {}) => {
|
|
365
|
-
if (!options.apiUrl) {
|
|
366
|
-
throw new Error("apiUrl is required for Edge environments");
|
|
367
|
-
}
|
|
368
|
-
return DB(options);
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
// src/embedding.ts
|
|
372
|
-
async function generateEmbedding(text, options = {}) {
|
|
373
|
-
try {
|
|
374
|
-
const modelName = options.model || "text-embedding-3-small";
|
|
375
|
-
const apiKey = options.apiKey || typeof globalThis !== "undefined" && globalThis.process?.env?.OPENAI_API_KEY;
|
|
376
|
-
if (!apiKey) {
|
|
377
|
-
throw new Error("apiKey option or OPENAI_API_KEY environment variable is required for embedding generation");
|
|
378
|
-
}
|
|
379
|
-
const input = Array.isArray(text) ? text : [text];
|
|
380
|
-
const response = await fetch("https://api.openai.com/v1/embeddings", {
|
|
381
|
-
method: "POST",
|
|
382
|
-
headers: {
|
|
383
|
-
"Content-Type": "application/json",
|
|
384
|
-
Authorization: `Bearer ${apiKey}`
|
|
385
|
-
},
|
|
386
|
-
body: JSON.stringify({
|
|
387
|
-
input,
|
|
388
|
-
model: modelName
|
|
389
|
-
})
|
|
390
|
-
});
|
|
391
|
-
if (!response.ok) {
|
|
392
|
-
const errorData = await response.json().catch(() => ({}));
|
|
393
|
-
throw new Error(`OpenAI API error: ${errorData.error?.message || response.statusText}`);
|
|
394
|
-
}
|
|
395
|
-
const data = await response.json();
|
|
396
|
-
const embeddings = [];
|
|
397
|
-
if (data && data.data && Array.isArray(data.data)) {
|
|
398
|
-
for (const item of data.data) {
|
|
399
|
-
if (item && item.embedding && Array.isArray(item.embedding)) {
|
|
400
|
-
embeddings.push(item.embedding);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return {
|
|
405
|
-
embedding: embeddings.length > 0 ? embeddings : null,
|
|
406
|
-
model: modelName,
|
|
407
|
-
success: embeddings.length > 0
|
|
408
|
-
};
|
|
409
|
-
} catch (error) {
|
|
410
|
-
console.error("Error generating embedding:", error);
|
|
411
|
-
return {
|
|
412
|
-
embedding: null,
|
|
413
|
-
model: options.model || "text-embedding-3-small",
|
|
414
|
-
success: false,
|
|
415
|
-
error: error instanceof Error ? error.message : String(error)
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
function calculateSimilarity(embedding1, embedding2) {
|
|
420
|
-
if (embedding1.length !== embedding2.length) {
|
|
421
|
-
throw new Error("Embeddings must have the same dimensions");
|
|
422
|
-
}
|
|
423
|
-
let dotProduct = 0;
|
|
424
|
-
let magnitude1 = 0;
|
|
425
|
-
let magnitude2 = 0;
|
|
426
|
-
for (let i = 0; i < embedding1.length; i++) {
|
|
427
|
-
dotProduct += embedding1[i] * embedding2[i];
|
|
428
|
-
magnitude1 += embedding1[i] * embedding1[i];
|
|
429
|
-
magnitude2 += embedding2[i] * embedding2[i];
|
|
430
|
-
}
|
|
431
|
-
magnitude1 = Math.sqrt(magnitude1);
|
|
432
|
-
magnitude2 = Math.sqrt(magnitude2);
|
|
433
|
-
if (magnitude1 === 0 || magnitude2 === 0) {
|
|
434
|
-
return 0;
|
|
435
|
-
}
|
|
436
|
-
return dotProduct / (magnitude1 * magnitude2);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
// src/index.ts
|
|
440
|
-
var DB = (options = {}) => {
|
|
441
|
-
const payload = getPayloadInstance(options);
|
|
442
|
-
return new Proxy({}, {
|
|
443
|
-
get: (target, prop) => {
|
|
444
|
-
if (typeof prop === "string" && prop !== "then") {
|
|
445
|
-
const collectionName = prop === "resources" ? "things" : String(prop);
|
|
446
|
-
return new CollectionHandler({ payload, collectionName });
|
|
447
|
-
}
|
|
448
|
-
return target[prop];
|
|
449
|
-
}
|
|
450
|
-
});
|
|
451
|
-
};
|
|
452
|
-
var db = DB();
|
|
453
|
-
var index_default = DB;
|
|
454
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
455
|
-
0 && (module.exports = {
|
|
456
|
-
DB,
|
|
457
|
-
calculateSimilarity,
|
|
458
|
-
createEdgeClient,
|
|
459
|
-
createNodeClient,
|
|
460
|
-
db,
|
|
461
|
-
generateEmbedding
|
|
462
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* ai-database - Schema-first database with promise pipelining
|
|
3
|
+
*
|
|
4
|
+
* Supports both direct and destructured usage:
|
|
5
|
+
*
|
|
6
|
+
* @example Direct usage - everything on one object
|
|
7
|
+
* ```ts
|
|
8
|
+
* const { db } = DB({
|
|
9
|
+
* Lead: {
|
|
10
|
+
* name: 'string',
|
|
11
|
+
* company: 'Company.leads',
|
|
12
|
+
* },
|
|
13
|
+
* Company: {
|
|
14
|
+
* name: 'string',
|
|
15
|
+
* }
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // Chain without await
|
|
19
|
+
* const leads = db.Lead.list()
|
|
20
|
+
* const qualified = await leads.filter(l => l.score > 80)
|
|
21
|
+
*
|
|
22
|
+
* // Batch relationship loading
|
|
23
|
+
* const withCompanies = await leads.map(l => ({
|
|
24
|
+
* name: l.name,
|
|
25
|
+
* company: l.company, // Batch loaded!
|
|
26
|
+
* }))
|
|
27
|
+
*
|
|
28
|
+
* // Natural language queries
|
|
29
|
+
* const results = await db.Lead`who closed deals this month?`
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* Provider is resolved transparently from environment (DATABASE_URL).
|
|
33
|
+
*
|
|
34
|
+
* @packageDocumentation
|
|
35
|
+
*/
|
|
36
|
+
export { DB } from './schema.js';
|
|
37
|
+
export {
|
|
38
|
+
// Thing conversion utilities
|
|
39
|
+
toExpanded, toFlat,
|
|
40
|
+
// Configuration
|
|
41
|
+
setProvider, setNLQueryGenerator,
|
|
42
|
+
// Schema parsing
|
|
43
|
+
parseSchema,
|
|
44
|
+
// Schema Definition
|
|
45
|
+
defineNoun, defineVerb, nounToSchema, Verbs,
|
|
46
|
+
// AI Inference
|
|
47
|
+
conjugate, pluralize, singularize, inferNoun, Type,
|
|
48
|
+
// URL utilities
|
|
49
|
+
resolveUrl, resolveShortUrl, parseUrl, } from './schema.js';
|
|
50
|
+
export { MemoryProvider, createMemoryProvider, Semaphore, } from './memory-provider.js';
|
|
51
|
+
// Promise pipelining exports
|
|
52
|
+
export { DBPromise, isDBPromise, getRawDBPromise, createListPromise, createEntityPromise, createSearchPromise, wrapEntityOperations, DB_PROMISE_SYMBOL, RAW_DB_PROMISE_SYMBOL, } from './ai-promise-db.js';
|
|
53
|
+
export {
|
|
54
|
+
// Standard definitions
|
|
55
|
+
StandardHierarchies, StandardPermissions, CRUDPermissions, createStandardRoles,
|
|
56
|
+
// Verb-scoped permissions
|
|
57
|
+
verbPermission, nounPermissions, matchesPermission,
|
|
58
|
+
// Helper functions
|
|
59
|
+
parseSubject, formatSubject, parseResource, formatResource, subjectMatches, resourceMatches,
|
|
60
|
+
// Schema integration
|
|
61
|
+
authorizeNoun, linkBusinessRole,
|
|
62
|
+
// In-memory engine
|
|
63
|
+
InMemoryAuthorizationEngine,
|
|
64
|
+
// Nouns
|
|
65
|
+
RoleNoun, AssignmentNoun, PermissionNoun, AuthorizationNouns, } from './authorization.js';
|
|
66
|
+
// =============================================================================
|
|
67
|
+
// Durable Promise - Time-agnostic execution
|
|
68
|
+
// =============================================================================
|
|
69
|
+
// Core durable promise exports
|
|
70
|
+
export { DurablePromise, isDurablePromise, durable, DURABLE_PROMISE_SYMBOL,
|
|
71
|
+
// Context management
|
|
72
|
+
getCurrentContext, withContext, setDefaultContext,
|
|
73
|
+
// Batch scheduler
|
|
74
|
+
getBatchScheduler, setBatchScheduler, } from './durable-promise.js';
|
|
75
|
+
// Execution queue for priority-based scheduling
|
|
76
|
+
export { ExecutionQueue, createExecutionQueue, getDefaultQueue, setDefaultQueue, } from './execution-queue.js';
|
|
77
|
+
// ClickHouse-backed durable provider
|
|
78
|
+
export { ClickHouseDurableProvider, createClickHouseDurableProvider, } from './durable-clickhouse.js';
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AA8EhC,OAAO;AACL,6BAA6B;AAC7B,UAAU,EACV,MAAM;AACN,gBAAgB;AAChB,WAAW,EACX,mBAAmB;AACnB,iBAAiB;AACjB,WAAW;AACX,oBAAoB;AACpB,UAAU,EACV,UAAU,EACV,YAAY,EACZ,KAAK;AACL,eAAe;AACf,SAAS,EACT,SAAS,EACT,WAAW,EACX,SAAS,EACT,IAAI;AACJ,gBAAgB;AAChB,UAAU,EACV,eAAe,EACf,QAAQ,GACT,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,SAAS,GACV,MAAM,sBAAsB,CAAA;AAc7B,6BAA6B;AAC7B,OAAO,EACL,SAAS,EACT,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,oBAAoB,CAAA;AA+C3B,OAAO;AACL,uBAAuB;AACvB,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,mBAAmB;AAEnB,0BAA0B;AAC1B,cAAc,EACd,eAAe,EACf,iBAAiB;AAEjB,mBAAmB;AACnB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe;AAEf,qBAAqB;AACrB,aAAa,EACb,gBAAgB;AAEhB,mBAAmB;AACnB,2BAA2B;AAE3B,QAAQ;AACR,QAAQ,EACR,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,oBAAoB,CAAA;AAmC3B,gFAAgF;AAChF,4CAA4C;AAC5C,gFAAgF;AAEhF,+BAA+B;AAC/B,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,sBAAsB;AACtB,qBAAqB;AACrB,iBAAiB,EACjB,WAAW,EACX,iBAAiB;AACjB,kBAAkB;AAClB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,sBAAsB,CAAA;AAS7B,gDAAgD;AAChD,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,eAAe,GAChB,MAAM,sBAAsB,CAAA;AAY7B,qCAAqC;AACrC,OAAO,EACL,yBAAyB,EACzB,+BAA+B,GAChC,MAAM,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linguistic Helpers
|
|
3
|
+
*
|
|
4
|
+
* Utilities for verb conjugation, noun pluralization, and linguistic inference.
|
|
5
|
+
* Used for auto-generating forms, events, and semantic metadata.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { Verbs, type Noun, type Verb, type TypeMeta } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Auto-conjugate a verb from just the base form
|
|
12
|
+
*
|
|
13
|
+
* Given just "publish", generates all forms:
|
|
14
|
+
* - actor: publisher
|
|
15
|
+
* - act: publishes
|
|
16
|
+
* - activity: publishing
|
|
17
|
+
* - result: publication
|
|
18
|
+
* - reverse: { at: publishedAt, by: publishedBy, ... }
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* conjugate('publish')
|
|
23
|
+
* // => { action: 'publish', actor: 'publisher', act: 'publishes', activity: 'publishing', ... }
|
|
24
|
+
*
|
|
25
|
+
* conjugate('create')
|
|
26
|
+
* // => { action: 'create', actor: 'creator', act: 'creates', activity: 'creating', ... }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function conjugate(action: string): Verb;
|
|
30
|
+
/**
|
|
31
|
+
* Auto-pluralize a noun
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* pluralize('post') // => 'posts'
|
|
36
|
+
* pluralize('category') // => 'categories'
|
|
37
|
+
* pluralize('person') // => 'people'
|
|
38
|
+
* pluralize('child') // => 'children'
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function pluralize(singular: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Auto-singularize a noun (reverse of pluralize)
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* singularize('posts') // => 'post'
|
|
48
|
+
* singularize('categories') // => 'category'
|
|
49
|
+
* singularize('people') // => 'person'
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function singularize(plural: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Infer a complete Noun from just a type name
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* inferNoun('BlogPost')
|
|
59
|
+
* // => { singular: 'blog post', plural: 'blog posts', ... }
|
|
60
|
+
*
|
|
61
|
+
* inferNoun('Category')
|
|
62
|
+
* // => { singular: 'category', plural: 'categories', ... }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function inferNoun(typeName: string): Noun;
|
|
66
|
+
/**
|
|
67
|
+
* Create TypeMeta from a type name - all linguistic forms auto-inferred
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const meta = createTypeMeta('BlogPost')
|
|
72
|
+
* meta.singular // 'blog post'
|
|
73
|
+
* meta.plural // 'blog posts'
|
|
74
|
+
* meta.slug // 'blog-post'
|
|
75
|
+
* meta.created // 'BlogPost.created'
|
|
76
|
+
* meta.createdAt // 'createdAt'
|
|
77
|
+
* meta.creator // 'creator'
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function createTypeMeta(typeName: string): TypeMeta;
|
|
81
|
+
/**
|
|
82
|
+
* Get or create TypeMeta for a type name (cached)
|
|
83
|
+
*/
|
|
84
|
+
export declare function getTypeMeta(typeName: string): TypeMeta;
|
|
85
|
+
/**
|
|
86
|
+
* Type proxy - provides dynamic access to type metadata
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const Post = Type('Post')
|
|
91
|
+
* Post.singular // 'post'
|
|
92
|
+
* Post.plural // 'posts'
|
|
93
|
+
* Post.created // 'Post.created'
|
|
94
|
+
*
|
|
95
|
+
* // In event handlers:
|
|
96
|
+
* on.create(thing => {
|
|
97
|
+
* console.log(thing.$type.plural) // 'posts'
|
|
98
|
+
* })
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function Type(name: string): TypeMeta;
|
|
102
|
+
/**
|
|
103
|
+
* Get reverse property names for a verb action
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* getVerbFields('create')
|
|
108
|
+
* // => { at: 'createdAt', by: 'createdBy', in: 'createdIn', for: 'createdFor' }
|
|
109
|
+
*
|
|
110
|
+
* getVerbFields('publish')
|
|
111
|
+
* // => { at: 'publishedAt', by: 'publishedBy' }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function getVerbFields(action: keyof typeof Verbs): Record<string, string>;
|
|
115
|
+
//# sourceMappingURL=linguistic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linguistic.d.ts","sourceRoot":"","sources":["../src/linguistic.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAA;AA0GvE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAsB9C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAsDlD;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAoDlD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAWhD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAwBzD;AAKD;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAOtD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAE3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,OAAO,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEhF"}
|