ai-database 2.1.1 → 2.3.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/CHANGELOG.md +47 -1
- package/README.md +1063 -186
- package/dist/actions.d.ts +2 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +1 -1
- package/dist/actions.js.map +1 -1
- package/dist/ai-promise-db.d.ts +52 -23
- package/dist/ai-promise-db.d.ts.map +1 -1
- package/dist/ai-promise-db.js +185 -164
- package/dist/ai-promise-db.js.map +1 -1
- package/dist/authorization.d.ts.map +1 -1
- package/dist/authorization.js +38 -30
- package/dist/authorization.js.map +1 -1
- package/dist/cascade-orchestrator.d.ts +404 -0
- package/dist/cascade-orchestrator.d.ts.map +1 -0
- package/dist/cascade-orchestrator.js +828 -0
- package/dist/cascade-orchestrator.js.map +1 -0
- package/dist/cascade-write-strategy.d.ts +584 -0
- package/dist/cascade-write-strategy.d.ts.map +1 -0
- package/dist/cascade-write-strategy.js +590 -0
- package/dist/cascade-write-strategy.js.map +1 -0
- package/dist/ch-adapter.d.ts +358 -0
- package/dist/ch-adapter.d.ts.map +1 -0
- package/dist/ch-adapter.js +929 -0
- package/dist/ch-adapter.js.map +1 -0
- package/dist/client/index.d.ts +42 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +43 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client.d.ts +266 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +81 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +64 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +52 -2
- package/dist/constants.js.map +1 -1
- package/dist/dataloader.d.ts +99 -0
- package/dist/dataloader.d.ts.map +1 -0
- package/dist/dataloader.js +225 -0
- package/dist/dataloader.js.map +1 -0
- package/dist/db-provider-port.d.ts +501 -0
- package/dist/db-provider-port.d.ts.map +1 -0
- package/dist/db-provider-port.js +113 -0
- package/dist/db-provider-port.js.map +1 -0
- package/dist/digital-objects-provider.d.ts +49 -0
- package/dist/digital-objects-provider.d.ts.map +1 -0
- package/dist/digital-objects-provider.js +55 -0
- package/dist/digital-objects-provider.js.map +1 -0
- package/dist/do-sqlite-adapter.d.ts +402 -0
- package/dist/do-sqlite-adapter.d.ts.map +1 -0
- package/dist/do-sqlite-adapter.js +745 -0
- package/dist/do-sqlite-adapter.js.map +1 -0
- package/dist/docs-rels/custom-types.d.ts +134 -0
- package/dist/docs-rels/custom-types.d.ts.map +1 -0
- package/dist/docs-rels/custom-types.js +70 -0
- package/dist/docs-rels/custom-types.js.map +1 -0
- package/dist/docs-rels/index.d.ts +16 -0
- package/dist/docs-rels/index.d.ts.map +1 -0
- package/dist/docs-rels/index.js +16 -0
- package/dist/docs-rels/index.js.map +1 -0
- package/dist/docs-rels/migrations/index.d.ts +30 -0
- package/dist/docs-rels/migrations/index.d.ts.map +1 -0
- package/dist/docs-rels/migrations/index.js +128 -0
- package/dist/docs-rels/migrations/index.js.map +1 -0
- package/dist/docs-rels/schema.d.ts +2961 -0
- package/dist/docs-rels/schema.d.ts.map +1 -0
- package/dist/docs-rels/schema.js +244 -0
- package/dist/docs-rels/schema.js.map +1 -0
- package/dist/durable-clickhouse.d.ts.map +1 -1
- package/dist/durable-clickhouse.js +16 -13
- package/dist/durable-clickhouse.js.map +1 -1
- package/dist/durable-promise.d.ts.map +1 -1
- package/dist/durable-promise.js +34 -15
- package/dist/durable-promise.js.map +1 -1
- package/dist/errors.d.ts +127 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +210 -0
- package/dist/errors.js.map +1 -0
- package/dist/eventbridge.d.ts +117 -0
- package/dist/eventbridge.d.ts.map +1 -0
- package/dist/eventbridge.js +238 -0
- package/dist/eventbridge.js.map +1 -0
- package/dist/events.d.ts +2 -2
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +1 -1
- package/dist/events.js.map +1 -1
- package/dist/execution-queue.d.ts.map +1 -1
- package/dist/execution-queue.js +4 -5
- package/dist/execution-queue.js.map +1 -1
- package/dist/index.d.ts +37 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +112 -6
- package/dist/index.js.map +1 -1
- package/dist/linguistic.d.ts +3 -108
- package/dist/linguistic.d.ts.map +1 -1
- package/dist/linguistic.js +3 -372
- package/dist/linguistic.js.map +1 -1
- package/dist/logger.d.ts +132 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +137 -0
- package/dist/logger.js.map +1 -0
- package/dist/memory-provider.d.ts +129 -0
- package/dist/memory-provider.d.ts.map +1 -1
- package/dist/memory-provider.js +592 -257
- package/dist/memory-provider.js.map +1 -1
- package/dist/pg-adapter.d.ts +424 -0
- package/dist/pg-adapter.d.ts.map +1 -0
- package/dist/pg-adapter.js +921 -0
- package/dist/pg-adapter.js.map +1 -0
- package/dist/pipelines-iceberg-emitter.d.ts +327 -0
- package/dist/pipelines-iceberg-emitter.d.ts.map +1 -0
- package/dist/pipelines-iceberg-emitter.js +351 -0
- package/dist/pipelines-iceberg-emitter.js.map +1 -0
- package/dist/provider-capabilities.d.ts +146 -0
- package/dist/provider-capabilities.d.ts.map +1 -0
- package/dist/provider-capabilities.js +214 -0
- package/dist/provider-capabilities.js.map +1 -0
- package/dist/rdb-provider-adapter.d.ts +195 -0
- package/dist/rdb-provider-adapter.d.ts.map +1 -0
- package/dist/rdb-provider-adapter.js +291 -0
- package/dist/rdb-provider-adapter.js.map +1 -0
- package/dist/schema/cascade.d.ts +49 -10
- package/dist/schema/cascade.d.ts.map +1 -1
- package/dist/schema/cascade.js +491 -273
- package/dist/schema/cascade.js.map +1 -1
- package/dist/schema/definition-caches.d.ts +24 -0
- package/dist/schema/definition-caches.d.ts.map +1 -0
- package/dist/schema/definition-caches.js +26 -0
- package/dist/schema/definition-caches.js.map +1 -0
- package/dist/schema/dependency-graph.d.ts +45 -0
- package/dist/schema/dependency-graph.d.ts.map +1 -0
- package/dist/schema/dependency-graph.js +47 -0
- package/dist/schema/dependency-graph.js.map +1 -0
- package/dist/schema/diff.d.ts +103 -0
- package/dist/schema/diff.d.ts.map +1 -0
- package/dist/schema/diff.js +329 -0
- package/dist/schema/diff.js.map +1 -0
- package/dist/schema/entity-operations.d.ts +99 -0
- package/dist/schema/entity-operations.d.ts.map +1 -0
- package/dist/schema/entity-operations.js +818 -0
- package/dist/schema/entity-operations.js.map +1 -0
- package/dist/schema/generation-context.d.ts +202 -0
- package/dist/schema/generation-context.d.ts.map +1 -0
- package/dist/schema/generation-context.js +393 -0
- package/dist/schema/generation-context.js.map +1 -0
- package/dist/schema/index.d.ts +32 -34
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +462 -519
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/migration.d.ts +205 -0
- package/dist/schema/migration.d.ts.map +1 -0
- package/dist/schema/migration.js +327 -0
- package/dist/schema/migration.js.map +1 -0
- package/dist/schema/nl-query-generator.d.ts +68 -0
- package/dist/schema/nl-query-generator.d.ts.map +1 -0
- package/dist/schema/nl-query-generator.js +362 -0
- package/dist/schema/nl-query-generator.js.map +1 -0
- package/dist/schema/nl-query.d.ts +65 -0
- package/dist/schema/nl-query.d.ts.map +1 -0
- package/dist/schema/nl-query.js +178 -0
- package/dist/schema/nl-query.js.map +1 -0
- package/dist/schema/parse.d.ts.map +1 -1
- package/dist/schema/parse.js +152 -89
- package/dist/schema/parse.js.map +1 -1
- package/dist/schema/provider.d.ts +38 -0
- package/dist/schema/provider.d.ts.map +1 -1
- package/dist/schema/provider.js +15 -7
- package/dist/schema/provider.js.map +1 -1
- package/dist/schema/resolve.d.ts +46 -5
- package/dist/schema/resolve.d.ts.map +1 -1
- package/dist/schema/resolve.js +334 -117
- package/dist/schema/resolve.js.map +1 -1
- package/dist/schema/search-utils.d.ts +76 -0
- package/dist/schema/search-utils.d.ts.map +1 -0
- package/dist/schema/search-utils.js +86 -0
- package/dist/schema/search-utils.js.map +1 -0
- package/dist/schema/seed.d.ts +53 -0
- package/dist/schema/seed.d.ts.map +1 -0
- package/dist/schema/seed.js +94 -0
- package/dist/schema/seed.js.map +1 -0
- package/dist/schema/semantic.d.ts +11 -0
- package/dist/schema/semantic.d.ts.map +1 -1
- package/dist/schema/semantic.js +262 -68
- package/dist/schema/semantic.js.map +1 -1
- package/dist/schema/sub-apis.d.ts +52 -0
- package/dist/schema/sub-apis.d.ts.map +1 -0
- package/dist/schema/sub-apis.js +216 -0
- package/dist/schema/sub-apis.js.map +1 -0
- package/dist/schema/system-entities.d.ts +42 -0
- package/dist/schema/system-entities.d.ts.map +1 -0
- package/dist/schema/system-entities.js +101 -0
- package/dist/schema/system-entities.js.map +1 -0
- package/dist/schema/types.d.ts +91 -9
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/union-fallback.d.ts +219 -0
- package/dist/schema/union-fallback.d.ts.map +1 -0
- package/dist/schema/union-fallback.js +331 -0
- package/dist/schema/union-fallback.js.map +1 -0
- package/dist/schema/value-generators/ai.d.ts +54 -0
- package/dist/schema/value-generators/ai.d.ts.map +1 -0
- package/dist/schema/value-generators/ai.js +136 -0
- package/dist/schema/value-generators/ai.js.map +1 -0
- package/dist/schema/value-generators/index.d.ts +126 -0
- package/dist/schema/value-generators/index.d.ts.map +1 -0
- package/dist/schema/value-generators/index.js +219 -0
- package/dist/schema/value-generators/index.js.map +1 -0
- package/dist/schema/value-generators/placeholder.d.ts +52 -0
- package/dist/schema/value-generators/placeholder.d.ts.map +1 -0
- package/dist/schema/value-generators/placeholder.js +328 -0
- package/dist/schema/value-generators/placeholder.js.map +1 -0
- package/dist/schema/value-generators/types.d.ts +116 -0
- package/dist/schema/value-generators/types.d.ts.map +1 -0
- package/dist/schema/value-generators/types.js +11 -0
- package/dist/schema/value-generators/types.js.map +1 -0
- package/dist/schema/verb-derivation.d.ts +167 -0
- package/dist/schema/verb-derivation.d.ts.map +1 -0
- package/dist/schema/verb-derivation.js +281 -0
- package/dist/schema/verb-derivation.js.map +1 -0
- package/dist/schema/version.d.ts +111 -0
- package/dist/schema/version.d.ts.map +1 -0
- package/dist/schema/version.js +190 -0
- package/dist/schema/version.js.map +1 -0
- package/dist/schema.d.ts +1095 -23
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2854 -38
- package/dist/schema.js.map +1 -1
- package/dist/semantic-vectors.d.ts +39 -0
- package/dist/semantic-vectors.d.ts.map +1 -0
- package/dist/semantic-vectors.js +334 -0
- package/dist/semantic-vectors.js.map +1 -0
- package/dist/semantic.d.ts +29 -1
- package/dist/semantic.d.ts.map +1 -1
- package/dist/semantic.js +26 -16
- package/dist/semantic.js.map +1 -1
- package/dist/telemetry.d.ts +128 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +305 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/tests.d.ts.map +1 -1
- package/dist/tests.js +30 -22
- package/dist/tests.js.map +1 -1
- package/dist/type-guards.d.ts +212 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/type-guards.js +318 -0
- package/dist/type-guards.js.map +1 -0
- package/dist/types.d.ts +33 -245
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +62 -72
- package/dist/types.js.map +1 -1
- package/dist/validation.d.ts +165 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +639 -0
- package/dist/validation.js.map +1 -0
- package/dist/worker/db-provider.d.ts +168 -0
- package/dist/worker/db-provider.d.ts.map +1 -0
- package/dist/worker/db-provider.js +277 -0
- package/dist/worker/db-provider.js.map +1 -0
- package/dist/worker/index.d.ts +35 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +37 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker.d.ts +779 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +2786 -0
- package/dist/worker.js.map +1 -0
- package/package.json +38 -8
- package/src/docs-rels/migrations/0001-init.sql +125 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type Guards for ai-promise-db.ts
|
|
3
|
+
*
|
|
4
|
+
* These type guards enable type-safe property access on proxy objects
|
|
5
|
+
* and entity markers, providing proper type narrowing.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// Type Guards
|
|
11
|
+
// =============================================================================
|
|
12
|
+
/**
|
|
13
|
+
* Check if a value has entity marker properties ($type, $id, or $isArrayRelation).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const value = someProxy.$type
|
|
18
|
+
* if (hasEntityMarker(value)) {
|
|
19
|
+
* // value is now typed as EntityMarker
|
|
20
|
+
* console.log(value.$type) // Safe access
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function hasEntityMarker(value) {
|
|
25
|
+
return (value !== null &&
|
|
26
|
+
typeof value === 'object' &&
|
|
27
|
+
('$type' in value || '$id' in value || '$isArrayRelation' in value));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Check if a value has a custom valueOf method that returns a string.
|
|
31
|
+
* This is used to detect thenable relation proxies that return IDs via valueOf().
|
|
32
|
+
*
|
|
33
|
+
* Note: We check if valueOf returns a string to distinguish from Object.prototype.valueOf
|
|
34
|
+
* which returns the object itself.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* if (isValueOfable(relationProxy)) {
|
|
39
|
+
* const id = relationProxy.valueOf()
|
|
40
|
+
* // id is now safely extracted
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function isValueOfable(value) {
|
|
45
|
+
if (value === null || typeof value !== 'object') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
// All objects have valueOf, but we check if it returns a string (custom implementation)
|
|
49
|
+
if ('valueOf' in value && typeof value.valueOf === 'function') {
|
|
50
|
+
const result = value.valueOf();
|
|
51
|
+
return typeof result === 'string';
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Check if a value has an explicit $id property.
|
|
57
|
+
*/
|
|
58
|
+
export function hasId(value) {
|
|
59
|
+
return (value !== null &&
|
|
60
|
+
typeof value === 'object' &&
|
|
61
|
+
'$id' in value &&
|
|
62
|
+
typeof value['$id'] === 'string');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if an array has entity relation markers ($type or $isArrayRelation).
|
|
66
|
+
* These markers are added by the hydration system to array relations.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* if (isEntityArray(members)) {
|
|
71
|
+
* // members is a relation array
|
|
72
|
+
* const type = members.$type // Safe access
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export function isEntityArray(value) {
|
|
77
|
+
if (!Array.isArray(value)) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
// Check for $type or $isArrayRelation properties on the array
|
|
81
|
+
const arr = value;
|
|
82
|
+
return ((arr['$type'] !== undefined && typeof arr['$type'] === 'string') ||
|
|
83
|
+
arr['$isArrayRelation'] === true);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check if a value is a non-null object (excluding arrays).
|
|
87
|
+
* Useful for narrowing before accessing properties.
|
|
88
|
+
*/
|
|
89
|
+
export function isPlainObject(value) {
|
|
90
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if an array contains relation elements (objects with $type markers).
|
|
94
|
+
*/
|
|
95
|
+
export function hasRelationElements(arr) {
|
|
96
|
+
return arr.some((v) => {
|
|
97
|
+
if (v === null || typeof v !== 'object') {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const obj = v;
|
|
101
|
+
return obj['$type'] !== undefined;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// =============================================================================
|
|
105
|
+
// Extraction Functions
|
|
106
|
+
// =============================================================================
|
|
107
|
+
/**
|
|
108
|
+
* Extract an entity ID from various sources.
|
|
109
|
+
*
|
|
110
|
+
* Supports:
|
|
111
|
+
* - String IDs (returned as-is)
|
|
112
|
+
* - Objects with valueOf() returning string (thenable proxies)
|
|
113
|
+
* - Objects with $id property (entities)
|
|
114
|
+
* - Objects with id property (generic objects)
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* // Works with strings
|
|
119
|
+
* extractEntityId('user-123') // 'user-123'
|
|
120
|
+
*
|
|
121
|
+
* // Works with thenable proxies
|
|
122
|
+
* extractEntityId(post.author) // 'author-id' via valueOf()
|
|
123
|
+
*
|
|
124
|
+
* // Works with entities
|
|
125
|
+
* extractEntityId(user) // user.$id
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export function extractEntityId(value) {
|
|
129
|
+
// Handle null/undefined
|
|
130
|
+
if (value === null || value === undefined) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
// Handle string directly
|
|
134
|
+
if (typeof value === 'string') {
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
// Handle objects
|
|
138
|
+
if (typeof value === 'object') {
|
|
139
|
+
const obj = value;
|
|
140
|
+
// Try valueOf() first (thenable proxies) - check if it returns a string
|
|
141
|
+
if ('valueOf' in obj && typeof obj.valueOf === 'function') {
|
|
142
|
+
const val = obj.valueOf();
|
|
143
|
+
if (typeof val === 'string') {
|
|
144
|
+
return val;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Try $id property (entity marker)
|
|
148
|
+
if ('$id' in obj && typeof obj['$id'] === 'string') {
|
|
149
|
+
return obj['$id'];
|
|
150
|
+
}
|
|
151
|
+
// Try plain id property (generic object)
|
|
152
|
+
if ('id' in obj && typeof obj['id'] === 'string') {
|
|
153
|
+
return obj['id'];
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Extract the $type marker from an entity or relation proxy.
|
|
160
|
+
* Uses direct property access to handle proxy objects that may not expose the 'in' trap.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* const entity = { $type: 'User', name: 'John' }
|
|
165
|
+
* extractMarkerType(entity) // 'User'
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export function extractMarkerType(value) {
|
|
169
|
+
if (value === null || typeof value !== 'object') {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
const obj = value;
|
|
173
|
+
const type = obj['$type'];
|
|
174
|
+
if (type !== undefined && typeof type === 'string') {
|
|
175
|
+
return type;
|
|
176
|
+
}
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Extract $type from an array relation.
|
|
181
|
+
*/
|
|
182
|
+
export function extractArrayRelationType(arr) {
|
|
183
|
+
if (isEntityArray(arr) && typeof arr.$type === 'string') {
|
|
184
|
+
return arr.$type;
|
|
185
|
+
}
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Safely access a property on an unknown value.
|
|
190
|
+
* Returns undefined if the value is not an object or the property doesn't exist.
|
|
191
|
+
*/
|
|
192
|
+
export function safeGet(value, key) {
|
|
193
|
+
if (isPlainObject(value)) {
|
|
194
|
+
return value[key];
|
|
195
|
+
}
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
// =============================================================================
|
|
199
|
+
// Type Assertion Helpers
|
|
200
|
+
// =============================================================================
|
|
201
|
+
/**
|
|
202
|
+
* Assert that a value is a record (for use after type narrowing).
|
|
203
|
+
* Use this after verifying that a value is an object to get proper type inference.
|
|
204
|
+
*/
|
|
205
|
+
export function asRecord(value) {
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Assert that a callback is properly typed.
|
|
210
|
+
* Used when the callback signature is known but TypeScript can't infer it.
|
|
211
|
+
*/
|
|
212
|
+
export function asCallback(fn) {
|
|
213
|
+
return fn;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Assert that a predicate is properly typed for array filter operations.
|
|
217
|
+
* Used when TypeScript can't infer the exact array element type.
|
|
218
|
+
*/
|
|
219
|
+
export function asPredicate(fn) {
|
|
220
|
+
return fn;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Assert that a comparator is properly typed for array sort operations.
|
|
224
|
+
* Used when TypeScript can't infer the exact array element type.
|
|
225
|
+
*/
|
|
226
|
+
export function asComparator(fn) {
|
|
227
|
+
return fn;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Type-safe access to symbol-keyed properties on objects.
|
|
231
|
+
* Used in proxy handlers where we need to access symbol properties.
|
|
232
|
+
*/
|
|
233
|
+
export function getSymbolProperty(obj, sym) {
|
|
234
|
+
return obj[sym];
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Cast an item to the expected type.
|
|
238
|
+
* Used when the item type is known but TypeScript sees it as unknown.
|
|
239
|
+
*/
|
|
240
|
+
export function asItem(value) {
|
|
241
|
+
return value;
|
|
242
|
+
}
|
|
243
|
+
// =============================================================================
|
|
244
|
+
// Draft/Resolve Type Guards
|
|
245
|
+
// =============================================================================
|
|
246
|
+
/**
|
|
247
|
+
* Check if an object is in draft phase.
|
|
248
|
+
* Draft objects have $phase === 'draft' and may have $refs.
|
|
249
|
+
*/
|
|
250
|
+
export function isDraft(value) {
|
|
251
|
+
return isPlainObject(value) && value['$phase'] === 'draft';
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Check if an object is in resolved phase.
|
|
255
|
+
* Resolved objects have $phase === 'resolved'.
|
|
256
|
+
*/
|
|
257
|
+
export function isResolved(value) {
|
|
258
|
+
return isPlainObject(value) && value['$phase'] === 'resolved';
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Extract $refs from a draft object safely.
|
|
262
|
+
* Returns undefined if the value is not a draft or has no $refs.
|
|
263
|
+
*/
|
|
264
|
+
export function extractRefs(value) {
|
|
265
|
+
if (isDraft(value) && isPlainObject(value['$refs'])) {
|
|
266
|
+
return value['$refs'];
|
|
267
|
+
}
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Set a property on a Record safely.
|
|
272
|
+
* Used to avoid type assertions when setting properties on draft/resolved objects.
|
|
273
|
+
*/
|
|
274
|
+
export function setProperty(obj, key, value) {
|
|
275
|
+
obj[key] = value;
|
|
276
|
+
}
|
|
277
|
+
// =============================================================================
|
|
278
|
+
// Dynamic Import Type Guards
|
|
279
|
+
// =============================================================================
|
|
280
|
+
/**
|
|
281
|
+
* Validate that a dynamic import result has the expected factory function.
|
|
282
|
+
* Provides type-safe access to dynamically imported modules.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```ts
|
|
286
|
+
* const module = await import('@mdxdb/fs')
|
|
287
|
+
* if (hasFactoryFunction(module, 'createFsProvider')) {
|
|
288
|
+
* const provider = module.createFsProvider({ root: './content' })
|
|
289
|
+
* }
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
export function hasFactoryFunction(module, functionName) {
|
|
293
|
+
return (module !== null &&
|
|
294
|
+
typeof module === 'object' &&
|
|
295
|
+
functionName in module &&
|
|
296
|
+
typeof module[functionName] === 'function');
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Check if a value is a function.
|
|
300
|
+
* Useful for validating dynamic imports.
|
|
301
|
+
*/
|
|
302
|
+
export function isFunction(value) {
|
|
303
|
+
return typeof value === 'function';
|
|
304
|
+
}
|
|
305
|
+
// =============================================================================
|
|
306
|
+
// Schema Type Guards
|
|
307
|
+
// =============================================================================
|
|
308
|
+
/**
|
|
309
|
+
* Safely access schema metadata fields.
|
|
310
|
+
* Returns undefined if the field is not present or not the expected type.
|
|
311
|
+
*/
|
|
312
|
+
export function getSchemaMetadata(schema, field) {
|
|
313
|
+
if (!schema || !isPlainObject(schema)) {
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
return schema[field];
|
|
317
|
+
}
|
|
318
|
+
//# sourceMappingURL=type-guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-guards.js","sourceRoot":"","sources":["../src/type-guards.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAuCH,gFAAgF;AAChF,cAAc;AACd,gFAAgF;AAEhF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,OAAO,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,kBAAkB,IAAI,KAAK,CAAC,CACpE,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO,KAAK,CAAA;IACd,CAAC;IACD,wFAAwF;IACxF,IAAI,SAAS,IAAI,KAAK,IAAI,OAAQ,KAAiC,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QAC3F,MAAM,MAAM,GAAI,KAAqB,CAAC,OAAO,EAAE,CAAA;QAC/C,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAA;IACnC,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,KAAc;IAClC,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,IAAI,KAAK;QACd,OAAQ,KAAiC,CAAC,KAAK,CAAC,KAAK,QAAQ,CAC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I,KAAK,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAA;AAC/D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QACpD,OAAO,KAAK,CAAC,OAAO,CAA4B,CAAA;IAClD,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAA4B,EAAE,GAAW,EAAE,KAAc;IACnF,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAClB,CAAC;AAED,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAEhF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAe,EACf,YAAe;IAEf,OAAO,CACL,MAAM,KAAK,IAAI;QACf,OAAO,MAAM,KAAK,QAAQ;QAC1B,YAAY,IAAI,MAAM;QACtB,OAAQ,MAAkC,CAAC,YAAY,CAAC,KAAK,UAAU,CACxE,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAA;AACpC,CAAC;AAED,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAA2C,EAC3C,KAAa;IAEb,IAAI,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAkB,CAAA;AACvC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -5,11 +5,16 @@
|
|
|
5
5
|
* - Thing types (mdxld-based entity structure)
|
|
6
6
|
* - Schema definition types
|
|
7
7
|
* - Parsed schema types
|
|
8
|
-
* - Noun & Verb semantic types
|
|
8
|
+
* - Noun & Verb semantic types (re-exported from @graphdl/core)
|
|
9
9
|
*
|
|
10
10
|
* @packageDocumentation
|
|
11
11
|
*/
|
|
12
12
|
import type { MDXLD } from 'mdxld';
|
|
13
|
+
import type { ParsedFieldType, RelationshipOperatorType } from '@org.ai/types';
|
|
14
|
+
import type { Verb, VerbReverse, Noun, NounProperty, NounRelationship, TypeMeta, PrimitiveType } from '@graphdl/core';
|
|
15
|
+
import { Verbs } from '@graphdl/core';
|
|
16
|
+
export type { Verb, VerbReverse, Noun, NounProperty, NounRelationship, TypeMeta, PrimitiveType };
|
|
17
|
+
export { Verbs };
|
|
13
18
|
/**
|
|
14
19
|
* Flat Thing shape with $-prefixed metadata fields
|
|
15
20
|
* Used for JSON-LD compatible serialization
|
|
@@ -64,10 +69,6 @@ export declare function toExpanded(flat: ThingFlat): ThingExpanded;
|
|
|
64
69
|
* Convert expanded thing to flat format
|
|
65
70
|
*/
|
|
66
71
|
export declare function toFlat(expanded: ThingExpanded): ThingFlat;
|
|
67
|
-
/**
|
|
68
|
-
* Primitive field types
|
|
69
|
-
*/
|
|
70
|
-
export type PrimitiveType = 'string' | 'number' | 'boolean' | 'date' | 'datetime' | 'json' | 'markdown' | 'url';
|
|
71
72
|
/**
|
|
72
73
|
* A field definition can be:
|
|
73
74
|
* - A primitive type: 'string', 'number', etc.
|
|
@@ -86,28 +87,37 @@ export type EntitySchema = Record<string, FieldDefinition>;
|
|
|
86
87
|
*/
|
|
87
88
|
export type DatabaseSchema = Record<string, EntitySchema>;
|
|
88
89
|
/**
|
|
89
|
-
* Parsed field information
|
|
90
|
+
* Parsed field information.
|
|
91
|
+
* Extends ParsedFieldType from @org.ai/types with database-specific fields.
|
|
90
92
|
*/
|
|
91
|
-
export interface ParsedField {
|
|
92
|
-
|
|
93
|
-
type: string;
|
|
93
|
+
export interface ParsedField extends ParsedFieldType {
|
|
94
|
+
/** Whether the field is an array (required, extends optional base field) */
|
|
94
95
|
isArray: boolean;
|
|
96
|
+
/** Whether the field is optional (required, extends optional base field) */
|
|
95
97
|
isOptional: boolean;
|
|
98
|
+
/** Whether this is a relationship field */
|
|
96
99
|
isRelation: boolean;
|
|
97
|
-
relatedType?: string;
|
|
98
|
-
backref?: string;
|
|
99
100
|
/** Operator used in field definition: ->, ~>, <-, <~ */
|
|
100
|
-
operator?:
|
|
101
|
+
operator?: RelationshipOperatorType;
|
|
101
102
|
/** Direction of the relationship */
|
|
102
103
|
direction?: 'forward' | 'backward';
|
|
103
104
|
/** Match mode for the relationship */
|
|
104
105
|
matchMode?: 'exact' | 'fuzzy';
|
|
105
106
|
/** Natural language prompt before operator */
|
|
106
107
|
prompt?: string;
|
|
107
|
-
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
/** Seed column mapping (e.g., '$.columnName') - maps source column to this field */
|
|
109
|
+
seedMapping?: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Seed configuration extracted from entity schema
|
|
113
|
+
*/
|
|
114
|
+
export interface SeedConfig {
|
|
115
|
+
/** URL to fetch seed data from */
|
|
116
|
+
url: string;
|
|
117
|
+
/** Column name to use as primary key (from $id field) */
|
|
118
|
+
idColumn: string;
|
|
119
|
+
/** Map of field names to source column names */
|
|
120
|
+
fieldMappings: Map<string, string>;
|
|
111
121
|
}
|
|
112
122
|
/**
|
|
113
123
|
* Parsed entity with all fields including auto-generated backrefs
|
|
@@ -117,6 +127,8 @@ export interface ParsedEntity {
|
|
|
117
127
|
fields: Map<string, ParsedField>;
|
|
118
128
|
/** Original raw schema for accessing metadata like $fuzzyThreshold */
|
|
119
129
|
schema?: EntitySchema;
|
|
130
|
+
/** Seed configuration if $seed is defined */
|
|
131
|
+
seedConfig?: SeedConfig;
|
|
120
132
|
}
|
|
121
133
|
/**
|
|
122
134
|
* Fully parsed schema with bi-directional relationships resolved
|
|
@@ -124,235 +136,6 @@ export interface ParsedEntity {
|
|
|
124
136
|
export interface ParsedSchema {
|
|
125
137
|
entities: Map<string, ParsedEntity>;
|
|
126
138
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Verb conjugations and related forms
|
|
129
|
-
*
|
|
130
|
-
* Maps an action to its various grammatical forms and semantic relationships.
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```ts
|
|
134
|
-
* const create: Verb = {
|
|
135
|
-
* action: 'create', // Base form (imperative)
|
|
136
|
-
* actor: 'creator', // Who does it (noun)
|
|
137
|
-
* act: 'creates', // Present tense (3rd person)
|
|
138
|
-
* activity: 'creating', // Gerund/continuous
|
|
139
|
-
* result: 'creation', // Result noun
|
|
140
|
-
* reverse: { // Passive/result properties
|
|
141
|
-
* at: 'createdAt',
|
|
142
|
-
* by: 'createdBy',
|
|
143
|
-
* in: 'createdIn',
|
|
144
|
-
* for: 'createdFor',
|
|
145
|
-
* },
|
|
146
|
-
* inverse: 'delete', // Opposite action
|
|
147
|
-
* }
|
|
148
|
-
* ```
|
|
149
|
-
*/
|
|
150
|
-
export interface Verb {
|
|
151
|
-
/** Base form / imperative (create, update, delete, publish) */
|
|
152
|
-
action: string;
|
|
153
|
-
/** Agent noun - who performs the action (creator, updater, author, publisher) */
|
|
154
|
-
actor?: string;
|
|
155
|
-
/** Present tense 3rd person singular (creates, updates, deletes, publishes) */
|
|
156
|
-
act?: string;
|
|
157
|
-
/** Present participle / gerund (creating, updating, deleting, publishing) */
|
|
158
|
-
activity?: string;
|
|
159
|
-
/** Result noun - what is produced (creation, update, deletion, publication) */
|
|
160
|
-
result?: string;
|
|
161
|
-
/** Reverse/passive forms - properties resulting from the action */
|
|
162
|
-
reverse?: {
|
|
163
|
-
/** Timestamp field (createdAt, updatedAt, deletedAt, publishedAt) */
|
|
164
|
-
at?: string;
|
|
165
|
-
/** Actor reference (createdBy, updatedBy, deletedBy, publishedBy) */
|
|
166
|
-
by?: string;
|
|
167
|
-
/** Location/context (createdIn, updatedIn, publishedIn) */
|
|
168
|
-
in?: string;
|
|
169
|
-
/** Purpose/target (createdFor, publishedFor) */
|
|
170
|
-
for?: string;
|
|
171
|
-
/** Additional reverse forms */
|
|
172
|
-
[key: string]: string | undefined;
|
|
173
|
-
};
|
|
174
|
-
/** Inverse action (create ↔ delete, publish ↔ unpublish, activate ↔ deactivate) */
|
|
175
|
-
inverse?: string;
|
|
176
|
-
/** Description of what this action does */
|
|
177
|
-
description?: string;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Standard CRUD verbs with pre-defined conjugations
|
|
181
|
-
*/
|
|
182
|
-
export declare const Verbs: {
|
|
183
|
-
readonly create: {
|
|
184
|
-
readonly action: "create";
|
|
185
|
-
readonly actor: "creator";
|
|
186
|
-
readonly act: "creates";
|
|
187
|
-
readonly activity: "creating";
|
|
188
|
-
readonly result: "creation";
|
|
189
|
-
readonly reverse: {
|
|
190
|
-
readonly at: "createdAt";
|
|
191
|
-
readonly by: "createdBy";
|
|
192
|
-
readonly in: "createdIn";
|
|
193
|
-
readonly for: "createdFor";
|
|
194
|
-
};
|
|
195
|
-
readonly inverse: "delete";
|
|
196
|
-
};
|
|
197
|
-
readonly update: {
|
|
198
|
-
readonly action: "update";
|
|
199
|
-
readonly actor: "updater";
|
|
200
|
-
readonly act: "updates";
|
|
201
|
-
readonly activity: "updating";
|
|
202
|
-
readonly result: "update";
|
|
203
|
-
readonly reverse: {
|
|
204
|
-
readonly at: "updatedAt";
|
|
205
|
-
readonly by: "updatedBy";
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
readonly delete: {
|
|
209
|
-
readonly action: "delete";
|
|
210
|
-
readonly actor: "deleter";
|
|
211
|
-
readonly act: "deletes";
|
|
212
|
-
readonly activity: "deleting";
|
|
213
|
-
readonly result: "deletion";
|
|
214
|
-
readonly reverse: {
|
|
215
|
-
readonly at: "deletedAt";
|
|
216
|
-
readonly by: "deletedBy";
|
|
217
|
-
};
|
|
218
|
-
readonly inverse: "create";
|
|
219
|
-
};
|
|
220
|
-
readonly publish: {
|
|
221
|
-
readonly action: "publish";
|
|
222
|
-
readonly actor: "publisher";
|
|
223
|
-
readonly act: "publishes";
|
|
224
|
-
readonly activity: "publishing";
|
|
225
|
-
readonly result: "publication";
|
|
226
|
-
readonly reverse: {
|
|
227
|
-
readonly at: "publishedAt";
|
|
228
|
-
readonly by: "publishedBy";
|
|
229
|
-
};
|
|
230
|
-
readonly inverse: "unpublish";
|
|
231
|
-
};
|
|
232
|
-
readonly archive: {
|
|
233
|
-
readonly action: "archive";
|
|
234
|
-
readonly actor: "archiver";
|
|
235
|
-
readonly act: "archives";
|
|
236
|
-
readonly activity: "archiving";
|
|
237
|
-
readonly result: "archive";
|
|
238
|
-
readonly reverse: {
|
|
239
|
-
readonly at: "archivedAt";
|
|
240
|
-
readonly by: "archivedBy";
|
|
241
|
-
};
|
|
242
|
-
readonly inverse: "unarchive";
|
|
243
|
-
};
|
|
244
|
-
};
|
|
245
|
-
/**
|
|
246
|
-
* Noun definition - semantic description of an entity type
|
|
247
|
-
*
|
|
248
|
-
* Describes a Thing with its properties, relationships, available actions,
|
|
249
|
-
* and metadata like singular/plural forms for natural language generation.
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* ```ts
|
|
253
|
-
* const Post: Noun = {
|
|
254
|
-
* singular: 'post',
|
|
255
|
-
* plural: 'posts',
|
|
256
|
-
* description: 'A blog post or article',
|
|
257
|
-
*
|
|
258
|
-
* properties: {
|
|
259
|
-
* title: { type: 'string', description: 'The post title' },
|
|
260
|
-
* content: { type: 'markdown', description: 'The post body' },
|
|
261
|
-
* status: { type: 'string', description: 'draft | published | archived' },
|
|
262
|
-
* },
|
|
263
|
-
*
|
|
264
|
-
* relationships: {
|
|
265
|
-
* author: { type: 'Author', backref: 'posts', description: 'Who wrote this' },
|
|
266
|
-
* tags: { type: 'Tag[]', backref: 'posts', description: 'Categorization' },
|
|
267
|
-
* },
|
|
268
|
-
*
|
|
269
|
-
* actions: ['create', 'update', 'delete', 'publish', 'archive'],
|
|
270
|
-
*
|
|
271
|
-
* events: ['created', 'updated', 'deleted', 'published', 'archived'],
|
|
272
|
-
* }
|
|
273
|
-
* ```
|
|
274
|
-
*/
|
|
275
|
-
export interface Noun {
|
|
276
|
-
/** Singular form (post, user, category) */
|
|
277
|
-
singular: string;
|
|
278
|
-
/** Plural form (posts, users, categories) */
|
|
279
|
-
plural: string;
|
|
280
|
-
/** Human-readable description */
|
|
281
|
-
description?: string;
|
|
282
|
-
/** Property definitions with descriptions */
|
|
283
|
-
properties?: Record<string, NounProperty>;
|
|
284
|
-
/** Relationship definitions with descriptions */
|
|
285
|
-
relationships?: Record<string, NounRelationship>;
|
|
286
|
-
/** Actions that can be performed on this noun (verbs) */
|
|
287
|
-
actions?: Array<string | Verb>;
|
|
288
|
-
/** Events that can occur to this noun */
|
|
289
|
-
events?: string[];
|
|
290
|
-
/** Additional metadata */
|
|
291
|
-
metadata?: Record<string, unknown>;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Property definition within a Noun
|
|
295
|
-
*/
|
|
296
|
-
export interface NounProperty {
|
|
297
|
-
/** Field type */
|
|
298
|
-
type: PrimitiveType | string;
|
|
299
|
-
/** Human-readable description (also used as generation prompt) */
|
|
300
|
-
description?: string;
|
|
301
|
-
/** Whether the field is optional */
|
|
302
|
-
optional?: boolean;
|
|
303
|
-
/** Whether the field is an array */
|
|
304
|
-
array?: boolean;
|
|
305
|
-
/** Default value */
|
|
306
|
-
default?: unknown;
|
|
307
|
-
/** Example values for documentation/generation */
|
|
308
|
-
examples?: unknown[];
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Relationship definition within a Noun
|
|
312
|
-
*/
|
|
313
|
-
export interface NounRelationship {
|
|
314
|
-
/** Related entity type (e.g., 'Author', 'Tag[]') */
|
|
315
|
-
type: string;
|
|
316
|
-
/** Backref field name on the related entity */
|
|
317
|
-
backref?: string;
|
|
318
|
-
/** Human-readable description */
|
|
319
|
-
description?: string;
|
|
320
|
-
/** Whether this is a required relationship */
|
|
321
|
-
required?: boolean;
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Type metadata - automatically inferred from type name
|
|
325
|
-
*
|
|
326
|
-
* Available on every entity via `entity.$type` or `db.Post.$meta`
|
|
327
|
-
*/
|
|
328
|
-
export interface TypeMeta {
|
|
329
|
-
/** Type name as defined in schema (e.g., 'Post', 'BlogPost') */
|
|
330
|
-
name: string;
|
|
331
|
-
/** Singular form (e.g., 'post', 'blog post') */
|
|
332
|
-
singular: string;
|
|
333
|
-
/** Plural form (e.g., 'posts', 'blog posts') */
|
|
334
|
-
plural: string;
|
|
335
|
-
/** URL-safe slug (e.g., 'post', 'blog-post') */
|
|
336
|
-
slug: string;
|
|
337
|
-
/** Plural slug (e.g., 'posts', 'blog-posts') */
|
|
338
|
-
slugPlural: string;
|
|
339
|
-
/** Creator relationship name */
|
|
340
|
-
creator: string;
|
|
341
|
-
/** Created timestamp field */
|
|
342
|
-
createdAt: string;
|
|
343
|
-
/** Created by field */
|
|
344
|
-
createdBy: string;
|
|
345
|
-
/** Updated timestamp field */
|
|
346
|
-
updatedAt: string;
|
|
347
|
-
/** Updated by field */
|
|
348
|
-
updatedBy: string;
|
|
349
|
-
/** Event type for creation (e.g., 'Post.created') */
|
|
350
|
-
created: string;
|
|
351
|
-
/** Event type for update (e.g., 'Post.updated') */
|
|
352
|
-
updated: string;
|
|
353
|
-
/** Event type for deletion (e.g., 'Post.deleted') */
|
|
354
|
-
deleted: string;
|
|
355
|
-
}
|
|
356
139
|
/**
|
|
357
140
|
* Base identifier for all entities (URL-centric)
|
|
358
141
|
*/
|
|
@@ -409,6 +192,11 @@ export declare function resolveUrl(entity: EntityId): string;
|
|
|
409
192
|
export declare function resolveShortUrl(entity: Pick<EntityId, 'ns' | 'id'>): string;
|
|
410
193
|
/**
|
|
411
194
|
* Parse a URL into EntityId components
|
|
195
|
+
*
|
|
196
|
+
* Supports both full URLs and type/id paths:
|
|
197
|
+
* - Full URL: 'https://example.com/User/john' -> { ns: 'example.com', type: 'User', id: 'john' }
|
|
198
|
+
* - Type/ID path: 'User/john' -> { ns: '', type: 'User', id: 'john' }
|
|
199
|
+
* - Nested path: 'User/org/team/john' -> { ns: '', type: 'User', id: 'org/team/john' }
|
|
412
200
|
*/
|
|
413
201
|
export declare function parseUrl(url: string): EntityId;
|
|
414
202
|
/**
|