ai-database 0.1.0 → 0.2.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.
- package/.turbo/turbo-build.log +5 -0
- package/.turbo/turbo-test.log +102 -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/src/index.ts
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
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
|
+
|
|
37
|
+
export { DB } from './schema.js'
|
|
38
|
+
export type {
|
|
39
|
+
// Thing types (mdxld-based)
|
|
40
|
+
ThingFlat,
|
|
41
|
+
ThingExpanded,
|
|
42
|
+
// Schema types
|
|
43
|
+
DatabaseSchema,
|
|
44
|
+
EntitySchema,
|
|
45
|
+
FieldDefinition,
|
|
46
|
+
PrimitiveType,
|
|
47
|
+
ParsedSchema,
|
|
48
|
+
ParsedEntity,
|
|
49
|
+
ParsedField,
|
|
50
|
+
TypedDB,
|
|
51
|
+
EntityOperations,
|
|
52
|
+
PipelineEntityOperations,
|
|
53
|
+
DBProvider,
|
|
54
|
+
ListOptions,
|
|
55
|
+
SearchOptions,
|
|
56
|
+
InferEntity,
|
|
57
|
+
GenerateOptions,
|
|
58
|
+
// DB Result type
|
|
59
|
+
DBResult,
|
|
60
|
+
// Noun & Verb semantic types
|
|
61
|
+
Noun,
|
|
62
|
+
NounProperty,
|
|
63
|
+
NounRelationship,
|
|
64
|
+
Verb,
|
|
65
|
+
TypeMeta,
|
|
66
|
+
// API types
|
|
67
|
+
EventsAPI,
|
|
68
|
+
ActionsAPI,
|
|
69
|
+
ArtifactsAPI,
|
|
70
|
+
NounsAPI,
|
|
71
|
+
VerbsAPI,
|
|
72
|
+
// Event types
|
|
73
|
+
DBEvent,
|
|
74
|
+
ActorData,
|
|
75
|
+
CreateEventOptions as DBCreateEventOptions,
|
|
76
|
+
// Action types
|
|
77
|
+
DBAction,
|
|
78
|
+
CreateActionOptions as DBCreateActionOptions,
|
|
79
|
+
// Artifact types
|
|
80
|
+
DBArtifact,
|
|
81
|
+
// Natural Language Query types
|
|
82
|
+
NLQueryResult,
|
|
83
|
+
NLQueryFn,
|
|
84
|
+
NLQueryGenerator,
|
|
85
|
+
NLQueryContext,
|
|
86
|
+
NLQueryPlan,
|
|
87
|
+
// Graph Database Types (for @mdxdb adapters)
|
|
88
|
+
EntityId,
|
|
89
|
+
Thing,
|
|
90
|
+
Relationship,
|
|
91
|
+
// Query Types
|
|
92
|
+
QueryOptions,
|
|
93
|
+
ThingSearchOptions,
|
|
94
|
+
CreateOptions,
|
|
95
|
+
UpdateOptions,
|
|
96
|
+
RelateOptions,
|
|
97
|
+
// Event/Action/Artifact Option Types
|
|
98
|
+
StoreArtifactOptions,
|
|
99
|
+
EventQueryOptions,
|
|
100
|
+
ActionQueryOptions,
|
|
101
|
+
ActionStatus,
|
|
102
|
+
ArtifactType,
|
|
103
|
+
// Client Interfaces
|
|
104
|
+
DBClient,
|
|
105
|
+
DBClientExtended,
|
|
106
|
+
} from './schema.js'
|
|
107
|
+
|
|
108
|
+
// Export CreateEventOptions and CreateActionOptions from types.ts
|
|
109
|
+
// (the schema.js versions are for EventsAPI/ActionsAPI, these are for DBClientExtended)
|
|
110
|
+
export type {
|
|
111
|
+
CreateEventOptions,
|
|
112
|
+
CreateActionOptions,
|
|
113
|
+
} from './types.js'
|
|
114
|
+
|
|
115
|
+
export {
|
|
116
|
+
// Thing conversion utilities
|
|
117
|
+
toExpanded,
|
|
118
|
+
toFlat,
|
|
119
|
+
// Configuration
|
|
120
|
+
setProvider,
|
|
121
|
+
setNLQueryGenerator,
|
|
122
|
+
// Schema parsing
|
|
123
|
+
parseSchema,
|
|
124
|
+
// Schema Definition
|
|
125
|
+
defineNoun,
|
|
126
|
+
defineVerb,
|
|
127
|
+
nounToSchema,
|
|
128
|
+
Verbs,
|
|
129
|
+
// AI Inference
|
|
130
|
+
conjugate,
|
|
131
|
+
pluralize,
|
|
132
|
+
singularize,
|
|
133
|
+
inferNoun,
|
|
134
|
+
Type,
|
|
135
|
+
// URL utilities
|
|
136
|
+
resolveUrl,
|
|
137
|
+
resolveShortUrl,
|
|
138
|
+
parseUrl,
|
|
139
|
+
} from './schema.js'
|
|
140
|
+
|
|
141
|
+
export {
|
|
142
|
+
MemoryProvider,
|
|
143
|
+
createMemoryProvider,
|
|
144
|
+
Semaphore,
|
|
145
|
+
} from './memory-provider.js'
|
|
146
|
+
|
|
147
|
+
export type {
|
|
148
|
+
// Note: Event, Action, Artifact now exported from schema.js (types.ts)
|
|
149
|
+
// memory-provider has different Event/Action/Artifact types (ActivityStreams style)
|
|
150
|
+
Event as MemoryEvent,
|
|
151
|
+
Action as MemoryAction,
|
|
152
|
+
Artifact as MemoryArtifact,
|
|
153
|
+
MemoryProviderOptions,
|
|
154
|
+
} from './memory-provider.js'
|
|
155
|
+
|
|
156
|
+
// Event/Action/Artifact types for @mdxdb adapters (simple event sourcing style)
|
|
157
|
+
export type { Event, Action, Artifact } from './schema.js'
|
|
158
|
+
|
|
159
|
+
// Promise pipelining exports
|
|
160
|
+
export {
|
|
161
|
+
DBPromise,
|
|
162
|
+
isDBPromise,
|
|
163
|
+
getRawDBPromise,
|
|
164
|
+
createListPromise,
|
|
165
|
+
createEntityPromise,
|
|
166
|
+
createSearchPromise,
|
|
167
|
+
wrapEntityOperations,
|
|
168
|
+
DB_PROMISE_SYMBOL,
|
|
169
|
+
RAW_DB_PROMISE_SYMBOL,
|
|
170
|
+
} from './ai-promise-db.js'
|
|
171
|
+
|
|
172
|
+
export type {
|
|
173
|
+
DBPromiseOptions,
|
|
174
|
+
ForEachOptions,
|
|
175
|
+
ForEachResult,
|
|
176
|
+
ForEachProgress,
|
|
177
|
+
ForEachErrorAction,
|
|
178
|
+
} from './ai-promise-db.js'
|
|
179
|
+
|
|
180
|
+
// Authorization (FGA/RBAC) exports
|
|
181
|
+
export type {
|
|
182
|
+
// Core primitives
|
|
183
|
+
Subject,
|
|
184
|
+
SubjectType,
|
|
185
|
+
Resource,
|
|
186
|
+
ResourceRef,
|
|
187
|
+
ResourceType,
|
|
188
|
+
|
|
189
|
+
// Role & Permission
|
|
190
|
+
Permission,
|
|
191
|
+
Role,
|
|
192
|
+
RoleLevel,
|
|
193
|
+
|
|
194
|
+
// Assignment
|
|
195
|
+
Assignment,
|
|
196
|
+
AssignmentInput,
|
|
197
|
+
|
|
198
|
+
// Authorization checks
|
|
199
|
+
AuthzCheckRequest,
|
|
200
|
+
AuthzCheckResult,
|
|
201
|
+
AuthzBatchCheckRequest,
|
|
202
|
+
AuthzBatchCheckResult,
|
|
203
|
+
|
|
204
|
+
// Hierarchy
|
|
205
|
+
ResourceHierarchy,
|
|
206
|
+
|
|
207
|
+
// Schema integration
|
|
208
|
+
AuthorizedNoun,
|
|
209
|
+
|
|
210
|
+
// Business roles
|
|
211
|
+
BusinessRole,
|
|
212
|
+
|
|
213
|
+
// Engine interface
|
|
214
|
+
AuthorizationEngine,
|
|
215
|
+
} from './authorization.js'
|
|
216
|
+
|
|
217
|
+
export {
|
|
218
|
+
// Standard definitions
|
|
219
|
+
StandardHierarchies,
|
|
220
|
+
StandardPermissions,
|
|
221
|
+
CRUDPermissions,
|
|
222
|
+
createStandardRoles,
|
|
223
|
+
|
|
224
|
+
// Verb-scoped permissions
|
|
225
|
+
verbPermission,
|
|
226
|
+
nounPermissions,
|
|
227
|
+
matchesPermission,
|
|
228
|
+
|
|
229
|
+
// Helper functions
|
|
230
|
+
parseSubject,
|
|
231
|
+
formatSubject,
|
|
232
|
+
parseResource,
|
|
233
|
+
formatResource,
|
|
234
|
+
subjectMatches,
|
|
235
|
+
resourceMatches,
|
|
236
|
+
|
|
237
|
+
// Schema integration
|
|
238
|
+
authorizeNoun,
|
|
239
|
+
linkBusinessRole,
|
|
240
|
+
|
|
241
|
+
// In-memory engine
|
|
242
|
+
InMemoryAuthorizationEngine,
|
|
243
|
+
|
|
244
|
+
// Nouns
|
|
245
|
+
RoleNoun,
|
|
246
|
+
AssignmentNoun,
|
|
247
|
+
PermissionNoun,
|
|
248
|
+
AuthorizationNouns,
|
|
249
|
+
} from './authorization.js'
|
|
250
|
+
|
|
251
|
+
// Document Database Types (for @mdxdb adapters)
|
|
252
|
+
// These are environment-agnostic types that work in any runtime
|
|
253
|
+
export type {
|
|
254
|
+
// Document types
|
|
255
|
+
Document,
|
|
256
|
+
DocWithScore,
|
|
257
|
+
// List/Search options and results
|
|
258
|
+
DocListOptions,
|
|
259
|
+
DocListResult,
|
|
260
|
+
DocSearchOptions,
|
|
261
|
+
DocSearchResult,
|
|
262
|
+
// CRUD options and results
|
|
263
|
+
DocGetOptions,
|
|
264
|
+
DocSetOptions,
|
|
265
|
+
DocSetResult,
|
|
266
|
+
DocDeleteOptions,
|
|
267
|
+
DocDeleteResult,
|
|
268
|
+
// Database interfaces
|
|
269
|
+
DocumentDatabase,
|
|
270
|
+
DocumentDatabaseConfig,
|
|
271
|
+
CreateDocumentDatabase,
|
|
272
|
+
DocumentDatabaseWithViews,
|
|
273
|
+
// View types
|
|
274
|
+
ViewEntityItem,
|
|
275
|
+
ViewComponent,
|
|
276
|
+
ViewDocument,
|
|
277
|
+
ViewContext,
|
|
278
|
+
ViewRenderResult,
|
|
279
|
+
ViewRelationshipMutation,
|
|
280
|
+
ViewSyncResult,
|
|
281
|
+
ViewManager,
|
|
282
|
+
} from './types.js'
|
|
283
|
+
|
|
284
|
+
// =============================================================================
|
|
285
|
+
// Durable Promise - Time-agnostic execution
|
|
286
|
+
// =============================================================================
|
|
287
|
+
|
|
288
|
+
// Core durable promise exports
|
|
289
|
+
export {
|
|
290
|
+
DurablePromise,
|
|
291
|
+
isDurablePromise,
|
|
292
|
+
durable,
|
|
293
|
+
DURABLE_PROMISE_SYMBOL,
|
|
294
|
+
// Context management
|
|
295
|
+
getCurrentContext,
|
|
296
|
+
withContext,
|
|
297
|
+
setDefaultContext,
|
|
298
|
+
// Batch scheduler
|
|
299
|
+
getBatchScheduler,
|
|
300
|
+
setBatchScheduler,
|
|
301
|
+
} from './durable-promise.js'
|
|
302
|
+
|
|
303
|
+
export type {
|
|
304
|
+
ExecutionPriority,
|
|
305
|
+
DurablePromiseOptions,
|
|
306
|
+
DurablePromiseResult,
|
|
307
|
+
BatchScheduler,
|
|
308
|
+
} from './durable-promise.js'
|
|
309
|
+
|
|
310
|
+
// Execution queue for priority-based scheduling
|
|
311
|
+
export {
|
|
312
|
+
ExecutionQueue,
|
|
313
|
+
createExecutionQueue,
|
|
314
|
+
getDefaultQueue,
|
|
315
|
+
setDefaultQueue,
|
|
316
|
+
} from './execution-queue.js'
|
|
317
|
+
|
|
318
|
+
export type {
|
|
319
|
+
ExecutionQueueOptions,
|
|
320
|
+
QueueStats,
|
|
321
|
+
BatchSubmission,
|
|
322
|
+
BatchProvider,
|
|
323
|
+
BatchRequest,
|
|
324
|
+
BatchStatus,
|
|
325
|
+
BatchResult,
|
|
326
|
+
} from './execution-queue.js'
|
|
327
|
+
|
|
328
|
+
// ClickHouse-backed durable provider
|
|
329
|
+
export {
|
|
330
|
+
ClickHouseDurableProvider,
|
|
331
|
+
createClickHouseDurableProvider,
|
|
332
|
+
} from './durable-clickhouse.js'
|
|
333
|
+
|
|
334
|
+
export type {
|
|
335
|
+
ClickHouseExecutor,
|
|
336
|
+
ClickHouseDurableConfig,
|
|
337
|
+
} from './durable-clickhouse.js'
|