@blitznocode/blitz-orm 0.7.4 → 0.8.2
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/index.js +49 -40
- package/dist/index.mjs +49 -40
- package/package.json +14 -14
- package/dist/index.d.mts +0 -404
- package/dist/index.d.ts +0 -404
package/dist/index.d.mts
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
import { TypeDBCredential, TypeDBDriver, TypeDBSession } from 'typedb-driver';
|
|
2
|
-
|
|
3
|
-
interface TypeDBProviderObject {
|
|
4
|
-
provider: 'typeDB';
|
|
5
|
-
url: string;
|
|
6
|
-
}
|
|
7
|
-
interface TypeDBClusterProviderObject {
|
|
8
|
-
provider: 'typeDBCluster';
|
|
9
|
-
addresses: string[];
|
|
10
|
-
credentials: TypeDBCredential;
|
|
11
|
-
}
|
|
12
|
-
type TypeDBHandles = Map<string, {
|
|
13
|
-
client: TypeDBDriver;
|
|
14
|
-
session: TypeDBSession;
|
|
15
|
-
}>;
|
|
16
|
-
|
|
17
|
-
type QueryConfig = {
|
|
18
|
-
noMetadata?: boolean;
|
|
19
|
-
returnNulls?: boolean;
|
|
20
|
-
simplifiedLinks?: boolean;
|
|
21
|
-
debugger?: boolean;
|
|
22
|
-
};
|
|
23
|
-
type MutateConfig = {
|
|
24
|
-
noMetadata?: boolean;
|
|
25
|
-
preQuery?: boolean;
|
|
26
|
-
ignoreNonexistingThings?: boolean;
|
|
27
|
-
};
|
|
28
|
-
type BormConfig = {
|
|
29
|
-
server: {
|
|
30
|
-
provider: 'blitz-orm-js';
|
|
31
|
-
};
|
|
32
|
-
query?: QueryConfig;
|
|
33
|
-
mutation?: MutateConfig;
|
|
34
|
-
dbConnectors: [ProviderObject, ...ProviderObject[]];
|
|
35
|
-
};
|
|
36
|
-
type ProviderObject = (TypeDBProviderObject & CommonProperties) | (TypeDBClusterProviderObject & CommonProperties);
|
|
37
|
-
interface CommonProperties {
|
|
38
|
-
id: string;
|
|
39
|
-
dbName: string;
|
|
40
|
-
}
|
|
41
|
-
type Provider = 'typeDB' | 'typeDBCluster';
|
|
42
|
-
type DBConnector = {
|
|
43
|
-
id: string;
|
|
44
|
-
subs?: string;
|
|
45
|
-
path?: string;
|
|
46
|
-
as?: string;
|
|
47
|
-
};
|
|
48
|
-
type DBHandles = {
|
|
49
|
-
typeDB: TypeDBHandles;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
type ThingType = 'entity' | 'relation' | 'attribute';
|
|
53
|
-
type BormMetadata = {
|
|
54
|
-
$id: string;
|
|
55
|
-
$op?: string;
|
|
56
|
-
$entity?: string;
|
|
57
|
-
$relation?: string;
|
|
58
|
-
$tempId?: string;
|
|
59
|
-
};
|
|
60
|
-
type WithBormMetadata<T> = T extends any[] ? T[number] extends object ? Array<WithBormMetadataObject<T[number]>> : T : T extends object ? WithBormMetadataObject<T> : T;
|
|
61
|
-
type WithBormMetadataObject<T> = {
|
|
62
|
-
[K in keyof T]: WithBormMetadata<T[K]>;
|
|
63
|
-
} & BormMetadata;
|
|
64
|
-
type BQLResponseSingle = Record<string, any>;
|
|
65
|
-
type BQLResponseMulti = BQLResponseSingle[];
|
|
66
|
-
type BQLResponse = BQLResponseSingle | BQLResponseMulti;
|
|
67
|
-
|
|
68
|
-
type LinkFilter = {
|
|
69
|
-
$thing?: string;
|
|
70
|
-
$thingType?: string;
|
|
71
|
-
$role?: string;
|
|
72
|
-
[key: string]: string | number | Filter | undefined;
|
|
73
|
-
};
|
|
74
|
-
type Filter = DataFilter | LinkFilter | MiddleFilter;
|
|
75
|
-
type MiddleFilter = {
|
|
76
|
-
$and?: Filter[];
|
|
77
|
-
$or?: Filter[];
|
|
78
|
-
};
|
|
79
|
-
type RequireAtLeastOne<T> = {
|
|
80
|
-
[K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>;
|
|
81
|
-
}[keyof T];
|
|
82
|
-
type DataFilter = RequireAtLeastOne<{
|
|
83
|
-
$eq?: any;
|
|
84
|
-
$ge?: number | string;
|
|
85
|
-
}>;
|
|
86
|
-
|
|
87
|
-
type RequiredKey<T, K extends keyof T> = T & {
|
|
88
|
-
[P in K]-?: T[P];
|
|
89
|
-
};
|
|
90
|
-
type WithRequired<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> & RequiredKey<T, K>;
|
|
91
|
-
type BQLMutationBlock = {
|
|
92
|
-
[key: string]: any;
|
|
93
|
-
$id?: string | string[];
|
|
94
|
-
$filter?: Filter | Filter[];
|
|
95
|
-
$tempId?: string;
|
|
96
|
-
$op?: string;
|
|
97
|
-
} & ({
|
|
98
|
-
$entity: string;
|
|
99
|
-
} | {
|
|
100
|
-
$relation: string;
|
|
101
|
-
} | {
|
|
102
|
-
$thing: string;
|
|
103
|
-
$thingType: 'entity' | 'relation';
|
|
104
|
-
});
|
|
105
|
-
type FilledBQLMutationBlock = WithRequired<BQLMutationBlock, '$tempId' | '$op'>;
|
|
106
|
-
type RawBQLMutation<T extends Record<string, any> = Record<string, any>> = ({
|
|
107
|
-
$id?: string;
|
|
108
|
-
$op?: 'create' | 'delete' | 'update';
|
|
109
|
-
$tempId?: string;
|
|
110
|
-
} | {
|
|
111
|
-
$entity: string;
|
|
112
|
-
} | {
|
|
113
|
-
$relation: string;
|
|
114
|
-
}) & T;
|
|
115
|
-
type ParsedBQLMutation = {
|
|
116
|
-
things: BQLMutationBlock[];
|
|
117
|
-
edges: BQLMutationBlock[];
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
type RawBQLQuery = {
|
|
121
|
-
$id?: string | string[];
|
|
122
|
-
$filter?: Record<string, any>;
|
|
123
|
-
$fields?: BQLField[];
|
|
124
|
-
$excludedFields?: BQLField[];
|
|
125
|
-
} & ({
|
|
126
|
-
$entity: string;
|
|
127
|
-
} | {
|
|
128
|
-
$relation: string;
|
|
129
|
-
} | {
|
|
130
|
-
$thing: string;
|
|
131
|
-
$thingType: 'entity' | 'relation';
|
|
132
|
-
});
|
|
133
|
-
type ParsedBQLQuery = Omit<RawBQLQuery, '$entity' | '$relation' | '$thing' | '$thingType'> & {
|
|
134
|
-
$localFilters?: Record<string, any>;
|
|
135
|
-
$nestedFilters?: Record<string, any>;
|
|
136
|
-
} & ({
|
|
137
|
-
$entity: EnrichedBormEntity;
|
|
138
|
-
} | {
|
|
139
|
-
$relation: EnrichedBormRelation;
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
type TQLRequest = {
|
|
143
|
-
entity?: string;
|
|
144
|
-
roles?: {
|
|
145
|
-
path: string;
|
|
146
|
-
request: string;
|
|
147
|
-
owner: string;
|
|
148
|
-
}[];
|
|
149
|
-
relations?: {
|
|
150
|
-
relation: string;
|
|
151
|
-
entity: string;
|
|
152
|
-
request: string;
|
|
153
|
-
}[];
|
|
154
|
-
insertionMatches?: string;
|
|
155
|
-
deletionMatches?: string;
|
|
156
|
-
insertions?: string;
|
|
157
|
-
deletions?: string;
|
|
158
|
-
};
|
|
159
|
-
type TQLEntityMutation = {
|
|
160
|
-
entity: string;
|
|
161
|
-
relations?: {
|
|
162
|
-
relation: string;
|
|
163
|
-
entity: string;
|
|
164
|
-
request: string;
|
|
165
|
-
}[];
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
type BormSchema = {
|
|
169
|
-
entities: {
|
|
170
|
-
[s: string]: BormEntity;
|
|
171
|
-
};
|
|
172
|
-
relations: {
|
|
173
|
-
[s: string]: BormRelation;
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
|
-
type BormEntity = {
|
|
177
|
-
extends: string;
|
|
178
|
-
idFields?: readonly string[];
|
|
179
|
-
defaultDBConnector: DBConnector;
|
|
180
|
-
dataFields?: readonly DataField[];
|
|
181
|
-
linkFields?: readonly LinkField[];
|
|
182
|
-
hooks?: Hooks;
|
|
183
|
-
} | {
|
|
184
|
-
extends?: string;
|
|
185
|
-
idFields: readonly string[];
|
|
186
|
-
defaultDBConnector: DBConnector;
|
|
187
|
-
dataFields?: readonly DataField[];
|
|
188
|
-
linkFields?: readonly LinkField[];
|
|
189
|
-
};
|
|
190
|
-
type BormRelation = BormEntity & {
|
|
191
|
-
defaultDBConnector: DBConnector & {
|
|
192
|
-
path: string;
|
|
193
|
-
};
|
|
194
|
-
roles?: {
|
|
195
|
-
[key: string]: RoleField;
|
|
196
|
-
};
|
|
197
|
-
};
|
|
198
|
-
type BormOperation = 'create' | 'update' | 'delete' | 'link' | 'unlink';
|
|
199
|
-
type BormTrigger = 'onCreate' | 'onUpdate' | 'onDelete' | 'onLink' | 'onUnlink';
|
|
200
|
-
type Hooks = {
|
|
201
|
-
pre?: readonly PreHook[];
|
|
202
|
-
};
|
|
203
|
-
type PreHook = {
|
|
204
|
-
triggers: {
|
|
205
|
-
[K in BormTrigger]?: () => boolean;
|
|
206
|
-
};
|
|
207
|
-
actions: readonly Action[];
|
|
208
|
-
};
|
|
209
|
-
type Action = {
|
|
210
|
-
type: 'validate';
|
|
211
|
-
fn: (entity: FilledBQLMutationBlock) => boolean;
|
|
212
|
-
severity: 'error' | 'warning' | 'info';
|
|
213
|
-
message: string;
|
|
214
|
-
} | {
|
|
215
|
-
type: 'transform';
|
|
216
|
-
fn: (entity: FilledBQLMutationBlock) => Partial<FilledBQLMutationBlock>;
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
type BormField = {
|
|
220
|
-
path: string;
|
|
221
|
-
cardinality: CardinalityType;
|
|
222
|
-
ordered?: boolean;
|
|
223
|
-
embedded?: boolean;
|
|
224
|
-
rights?: readonly RightType[];
|
|
225
|
-
};
|
|
226
|
-
type RoleField = {
|
|
227
|
-
cardinality: CardinalityType;
|
|
228
|
-
dbConnector?: DBConnector;
|
|
229
|
-
};
|
|
230
|
-
type LinkField = BormField & {
|
|
231
|
-
relation: string;
|
|
232
|
-
plays: string;
|
|
233
|
-
} & ({
|
|
234
|
-
target: 'role';
|
|
235
|
-
filter?: Filter | Filter[];
|
|
236
|
-
} | {
|
|
237
|
-
target: 'relation';
|
|
238
|
-
});
|
|
239
|
-
type LinkedFieldWithThing = LinkField & {
|
|
240
|
-
thing: string;
|
|
241
|
-
thingType: ThingType;
|
|
242
|
-
};
|
|
243
|
-
type DataField = BormField & {
|
|
244
|
-
shared?: boolean;
|
|
245
|
-
default?: any;
|
|
246
|
-
contentType: ContentType;
|
|
247
|
-
validations?: any;
|
|
248
|
-
isVirtual?: boolean;
|
|
249
|
-
dbConnectors?: [DBConnector, ...DBConnector[]];
|
|
250
|
-
};
|
|
251
|
-
type ContentType = 'ID' | 'JSON' | 'COLOR' | 'BOOLEAN' | 'POINT' | 'FILE' | 'EMAIL' | 'PHONE' | 'WEEK_DAY' | 'DURATION' | 'HOUR' | 'TIME' | 'DATE' | 'RATING' | 'CURRENCY' | 'PERCENTAGE' | 'NUMBER_DECIMAL' | 'NUMBER' | 'URL' | 'PASSWORD' | 'LANGUAGE_TEXT' | 'RICH_TEXT' | 'TEXT';
|
|
252
|
-
type ContentTypeMapping = {
|
|
253
|
-
ID: string;
|
|
254
|
-
JSON: any;
|
|
255
|
-
COLOR: string;
|
|
256
|
-
BOOLEAN: boolean;
|
|
257
|
-
POINT: {
|
|
258
|
-
x: number;
|
|
259
|
-
y: number;
|
|
260
|
-
};
|
|
261
|
-
FILE: string;
|
|
262
|
-
EMAIL: string;
|
|
263
|
-
PHONE: string;
|
|
264
|
-
WEEK_DAY: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
|
|
265
|
-
DURATION: number;
|
|
266
|
-
HOUR: number;
|
|
267
|
-
TIME: Date;
|
|
268
|
-
DATE: Date;
|
|
269
|
-
RATING: number;
|
|
270
|
-
CURRENCY: number;
|
|
271
|
-
PERCENTAGE: number;
|
|
272
|
-
NUMBER_DECIMAL: number;
|
|
273
|
-
NUMBER: number;
|
|
274
|
-
URL: string;
|
|
275
|
-
PASSWORD: string;
|
|
276
|
-
LANGUAGE_TEXT: string;
|
|
277
|
-
RICH_TEXT: string;
|
|
278
|
-
TEXT: string;
|
|
279
|
-
};
|
|
280
|
-
type CardinalityType = 'ONE' | 'MANY' | 'INTERVAL';
|
|
281
|
-
type RightType = 'CREATE' | 'DELETE' | 'UPDATE' | 'LINK' | 'UNLINK';
|
|
282
|
-
type BQLFieldObj = {
|
|
283
|
-
$path: string;
|
|
284
|
-
$as?: string;
|
|
285
|
-
} & Omit<RawBQLQuery, '$entity' | '$relation' | '$thing' | '$thingType'>;
|
|
286
|
-
type BQLField = string | BQLFieldObj;
|
|
287
|
-
|
|
288
|
-
type EnrichedBormSchema = {
|
|
289
|
-
entities: {
|
|
290
|
-
[s: string]: EnrichedBormEntity;
|
|
291
|
-
};
|
|
292
|
-
relations: {
|
|
293
|
-
[s: string]: EnrichedBormRelation;
|
|
294
|
-
};
|
|
295
|
-
};
|
|
296
|
-
type EnrichedBormEntity = Omit<BormEntity, 'linkFields' | 'idFields' | 'dataFields'> & {
|
|
297
|
-
extends?: string;
|
|
298
|
-
allExtends?: string[];
|
|
299
|
-
idFields: string[];
|
|
300
|
-
thingType: 'entity';
|
|
301
|
-
name: string;
|
|
302
|
-
computedFields: string[];
|
|
303
|
-
virtualFields: string[];
|
|
304
|
-
linkFields?: EnrichedLinkField[];
|
|
305
|
-
dataFields?: EnrichedDataField[];
|
|
306
|
-
};
|
|
307
|
-
type EnrichedBormRelation = Omit<BormRelation, 'linkFields' | 'dataFields'> & {
|
|
308
|
-
thingType: 'relation';
|
|
309
|
-
name: string;
|
|
310
|
-
computedFields: string[];
|
|
311
|
-
virtualFields: string[];
|
|
312
|
-
linkFields?: EnrichedLinkField[];
|
|
313
|
-
dataFields?: EnrichedDataField[];
|
|
314
|
-
roles: {
|
|
315
|
-
[key: string]: EnrichedRoleField;
|
|
316
|
-
};
|
|
317
|
-
};
|
|
318
|
-
type EnrichedRoleField = RoleField & {
|
|
319
|
-
playedBy?: LinkedFieldWithThing[];
|
|
320
|
-
name: string;
|
|
321
|
-
};
|
|
322
|
-
type EnrichedDataField = DataField & {
|
|
323
|
-
dbPath: string;
|
|
324
|
-
};
|
|
325
|
-
type EnrichedLinkField = BormField & {
|
|
326
|
-
name: string;
|
|
327
|
-
relation: string;
|
|
328
|
-
plays: string;
|
|
329
|
-
} & ({
|
|
330
|
-
target: 'role';
|
|
331
|
-
filter?: Filter | Filter[];
|
|
332
|
-
oppositeLinkFieldsPlayedBy: LinkedFieldWithThing[];
|
|
333
|
-
} | {
|
|
334
|
-
target: 'relation';
|
|
335
|
-
oppositeLinkFieldsPlayedBy: Pick<LinkedFieldWithThing, 'thing' | 'thingType' | 'plays'>[];
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
type ContentTypeToType<C extends keyof ContentTypeMapping> = ContentTypeMapping[C];
|
|
339
|
-
type HandleCardinality<T, C extends 'ONE' | 'MANY'> = C extends 'MANY' ? T[] : T;
|
|
340
|
-
type ContentTypeAndCardinality = {
|
|
341
|
-
contentType: keyof ContentTypeMapping;
|
|
342
|
-
cardinality: 'ONE' | 'MANY';
|
|
343
|
-
};
|
|
344
|
-
type ForDataField = {
|
|
345
|
-
path: string;
|
|
346
|
-
contentType: keyof ContentTypeMapping;
|
|
347
|
-
cardinality: 'ONE' | 'MANY';
|
|
348
|
-
};
|
|
349
|
-
type ForLinkField = {
|
|
350
|
-
path: string;
|
|
351
|
-
cardinality: 'ONE' | 'MANY';
|
|
352
|
-
};
|
|
353
|
-
type ForRoleFIeld = {
|
|
354
|
-
cardinality: 'ONE' | 'MANY';
|
|
355
|
-
};
|
|
356
|
-
type BaseSchemaEntity = {
|
|
357
|
-
dataFields: readonly ForDataField[];
|
|
358
|
-
linkFields?: readonly ForLinkField[];
|
|
359
|
-
};
|
|
360
|
-
type BaseSchemaRelation = BaseSchemaEntity & {
|
|
361
|
-
roles?: Record<string, ForRoleFIeld[]>;
|
|
362
|
-
};
|
|
363
|
-
type BaseSchema = BaseSchemaEntity | BaseSchemaRelation;
|
|
364
|
-
type FieldToType<F extends ContentTypeAndCardinality> = HandleCardinality<ContentTypeToType<F['contentType']>, F['cardinality']>;
|
|
365
|
-
type ExtractDataFields<S extends {
|
|
366
|
-
dataFields: readonly ForDataField[];
|
|
367
|
-
}> = {
|
|
368
|
-
[K in S['dataFields'][number]['path']]?: FieldToType<Extract<S['dataFields'][number], {
|
|
369
|
-
path: K;
|
|
370
|
-
}>>;
|
|
371
|
-
};
|
|
372
|
-
type ExtractLinkFields<S> = S extends {
|
|
373
|
-
linkFields?: readonly ForLinkField[];
|
|
374
|
-
} ? S['linkFields'] extends readonly ForLinkField[] ? {
|
|
375
|
-
[K in S['linkFields'][number]['path']]?: HandleCardinality<string, Extract<S['linkFields'][number], {
|
|
376
|
-
path: K;
|
|
377
|
-
}>['cardinality']>;
|
|
378
|
-
} : {} : {};
|
|
379
|
-
type ExtractRoles<S> = 'roles' extends keyof S ? {
|
|
380
|
-
[K in keyof S['roles']]?: S['roles'][K] extends {
|
|
381
|
-
cardinality: 'ONE' | 'MANY';
|
|
382
|
-
} ? HandleCardinality<string, S['roles'][K]['cardinality']> : never;
|
|
383
|
-
} : {};
|
|
384
|
-
type TypeGen<S extends BaseSchema> = ExtractDataFields<S> & ExtractLinkFields<S> & ExtractRoles<S>;
|
|
385
|
-
|
|
386
|
-
type BormProps = {
|
|
387
|
-
schema: BormSchema;
|
|
388
|
-
config: BormConfig;
|
|
389
|
-
};
|
|
390
|
-
declare class BormClient {
|
|
391
|
-
#private;
|
|
392
|
-
private schema;
|
|
393
|
-
private config;
|
|
394
|
-
private dbHandles?;
|
|
395
|
-
constructor({ schema, config }: BormProps);
|
|
396
|
-
init: () => Promise<void>;
|
|
397
|
-
introspect: () => Promise<BormSchema>;
|
|
398
|
-
define: () => Promise<void>;
|
|
399
|
-
query: (query: RawBQLQuery | RawBQLQuery[], queryConfig?: QueryConfig) => Promise<BQLResponse>;
|
|
400
|
-
mutate: (mutation: RawBQLMutation | RawBQLMutation[], mutationConfig?: MutateConfig) => Promise<BQLResponseMulti>;
|
|
401
|
-
close: () => Promise<void>;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
export { Action, BQLField, BQLFieldObj, BQLMutationBlock, BQLResponse, BQLResponseMulti, BQLResponseSingle, BormConfig, BormEntity, BormField, BormMetadata, BormOperation, BormRelation, BormSchema, BormTrigger, CardinalityType, CommonProperties, ContentType, ContentTypeMapping, DBConnector, DBHandles, DataField, DataFilter, EnrichedBormEntity, EnrichedBormRelation, EnrichedBormSchema, EnrichedDataField, EnrichedLinkField, EnrichedRoleField, FilledBQLMutationBlock, Filter, Hooks, LinkField, LinkFilter, LinkedFieldWithThing, MiddleFilter, MutateConfig, ParsedBQLMutation, ParsedBQLQuery, PreHook, Provider, ProviderObject, QueryConfig, RawBQLMutation, RawBQLQuery, RightType, RoleField, TQLEntityMutation, TQLRequest, ThingType, TypeDBClusterProviderObject, TypeDBHandles, TypeDBProviderObject, TypeGen, WithBormMetadata, BormClient as default };
|