@blitznocode/blitz-orm 0.9.18 → 0.10.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/dist/index.d.mts CHANGED
@@ -1,10 +1,27 @@
1
1
  import { TypeDBCredential, TypeDBDriver, TypeDBSession } from 'typedb-driver';
2
+ import { Surreal } from 'surrealdb.node';
2
3
 
3
- interface TypeDBProviderObject {
4
+ type ThingType = 'entity' | 'relation';
5
+ type BormMetadata = {
6
+ $id: string;
7
+ $op?: string;
8
+ $entity?: string;
9
+ $relation?: string;
10
+ $tempId?: string;
11
+ };
12
+ type WithBormMetadata<T> = T extends any[] ? T[number] extends object ? Array<WithBormMetadataObject<T[number]>> : T : T extends object ? WithBormMetadataObject<T> : T;
13
+ type WithBormMetadataObject<T> = {
14
+ [K in keyof T]: WithBormMetadata<T[K]>;
15
+ } & BormMetadata;
16
+ type BQLResponseSingle = Record<string | symbol, any>;
17
+ type BQLResponseMulti = BQLResponseSingle[];
18
+ type BQLResponse = BQLResponseSingle | BQLResponseMulti;
19
+
20
+ interface TypeDBProvider extends CommonProvider {
4
21
  provider: 'typeDB';
5
22
  url: string;
6
23
  }
7
- interface TypeDBClusterProviderObject {
24
+ interface TypeDBClusterProvider extends CommonProvider {
8
25
  provider: 'typeDBCluster';
9
26
  addresses: string[];
10
27
  credentials: TypeDBCredential;
@@ -14,6 +31,17 @@ type TypeDBHandles = Map<string, {
14
31
  session: TypeDBSession;
15
32
  }>;
16
33
 
34
+ interface SurrealDBProviderObject extends CommonProvider {
35
+ provider: 'surrealDB';
36
+ url: string;
37
+ namespace: string;
38
+ username: string;
39
+ password: string;
40
+ }
41
+ type SurrealDBHandles = Map<string, {
42
+ client: Surreal;
43
+ }>;
44
+
17
45
  type QueryConfig = {
18
46
  noMetadata?: boolean;
19
47
  returnNulls?: boolean;
@@ -32,14 +60,13 @@ type BormConfig = {
32
60
  };
33
61
  query?: QueryConfig;
34
62
  mutation?: MutationConfig;
35
- dbConnectors: [ProviderObject, ...ProviderObject[]];
63
+ dbConnectors: [Provider, ...Provider[]];
36
64
  };
37
- type ProviderObject = (TypeDBProviderObject & CommonProperties) | (TypeDBClusterProviderObject & CommonProperties);
38
- interface CommonProperties {
65
+ type Provider = TypeDBProvider | TypeDBClusterProvider | SurrealDBProviderObject;
66
+ interface CommonProvider {
39
67
  id: string;
40
68
  dbName: string;
41
69
  }
42
- type Provider = 'typeDB' | 'typeDBCluster';
43
70
  type DBConnector = {
44
71
  id: string;
45
72
  subs?: string;
@@ -48,7 +75,7 @@ type DBConnector = {
48
75
  };
49
76
  type AllDbHandles = {
50
77
  typeDB: TypeDBHandles;
51
- surrealDB: any;
78
+ surrealDB: SurrealDBHandles;
52
79
  };
53
80
  type AtLeastOne<T, U = {
54
81
  [K in keyof T]: Pick<T, K>;
@@ -56,41 +83,6 @@ type AtLeastOne<T, U = {
56
83
  type DBHandles = AtLeastOne<AllDbHandles>;
57
84
  type DBHandleKey = keyof DBHandles;
58
85
 
59
- type ThingType = 'entity' | 'relation';
60
- type BormMetadata = {
61
- $id: string;
62
- $op?: string;
63
- $entity?: string;
64
- $relation?: string;
65
- $tempId?: string;
66
- };
67
- type WithBormMetadata<T> = T extends any[] ? T[number] extends object ? Array<WithBormMetadataObject<T[number]>> : T : T extends object ? WithBormMetadataObject<T> : T;
68
- type WithBormMetadataObject<T> = {
69
- [K in keyof T]: WithBormMetadata<T[K]>;
70
- } & BormMetadata;
71
- type BQLResponseSingle = Record<string, any>;
72
- type BQLResponseMulti = BQLResponseSingle[];
73
- type BQLResponse = BQLResponseSingle | BQLResponseMulti;
74
-
75
- type LinkFilter = {
76
- $thing?: string;
77
- $thingType?: string;
78
- $role?: string;
79
- [key: string]: string | number | Filter | undefined;
80
- };
81
- type Filter = DataFilter | LinkFilter | MiddleFilter;
82
- type MiddleFilter = {
83
- $and?: Filter[];
84
- $or?: Filter[];
85
- };
86
- type RequireAtLeastOne<T> = {
87
- [K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>;
88
- }[keyof T];
89
- type DataFilter = RequireAtLeastOne<{
90
- $eq?: any;
91
- $ge?: number | string;
92
- }>;
93
-
94
86
  type BormSchema = {
95
87
  entities: {
96
88
  [s: string]: BormEntity;
@@ -161,18 +153,18 @@ type AdapterContext = {
161
153
 
162
154
  type BormField = {
163
155
  path: string;
164
- cardinality?: CardinalityType;
156
+ cardinality?: DiscreteCardinality;
165
157
  ordered?: boolean;
166
158
  embedded?: boolean;
167
159
  rights?: readonly RightType[];
168
160
  };
169
161
  type RoleField = {
170
- cardinality: CardinalityType;
162
+ cardinality: DiscreteCardinality;
171
163
  dbConnector?: DBConnector;
172
164
  };
173
165
  type LinkField = BormField & {
174
166
  relation: string;
175
- cardinality: CardinalityType;
167
+ cardinality: DiscreteCardinality;
176
168
  plays: string;
177
169
  } & ({
178
170
  target: 'role';
@@ -185,7 +177,7 @@ type LinkedFieldWithThing = LinkField & {
185
177
  thingType: ThingType;
186
178
  };
187
179
  type StringField = BormField & {
188
- contentType: 'ID' | 'COLOR' | 'DATE' | 'FILE' | 'EMAIL' | 'PHONE' | 'URL' | 'PASSWORD' | 'LANGUAGE_TEXT' | 'RICH_TEXT' | 'TEXT';
180
+ contentType: 'ID' | 'COLOR' | 'DATE' | 'FILE' | 'EMAIL' | 'PHONE' | 'URL' | 'PASSWORD' | 'LANGUAGE_TEXT' | 'RICH_TEXT' | 'TEXT' | 'JSON';
189
181
  default?: {
190
182
  type: 'fn';
191
183
  fn: (currentNode: BQLMutationBlock) => string;
@@ -244,6 +236,7 @@ type BooleanField = BormField & {
244
236
  };
245
237
  type AllDataField = StringField | NumberField | DateField | BooleanField;
246
238
  type DataField = BormField & {
239
+ cardinality?: Cardinality;
247
240
  shared?: boolean;
248
241
  validations?: {
249
242
  required?: boolean;
@@ -255,7 +248,7 @@ type DataField = BormField & {
255
248
  type ContentType = keyof ContentTypeMapping;
256
249
  type ContentTypeMapping = {
257
250
  ID: string;
258
- JSON: unknown;
251
+ JSON: string;
259
252
  COLOR: string;
260
253
  BOOLEAN: boolean;
261
254
  POINT: {
@@ -281,7 +274,8 @@ type ContentTypeMapping = {
281
274
  RICH_TEXT: string;
282
275
  TEXT: string;
283
276
  };
284
- type CardinalityType = 'ONE' | 'MANY' | 'INTERVAL';
277
+ type DiscreteCardinality = 'ONE' | 'MANY';
278
+ type Cardinality = DiscreteCardinality | 'INTERVAL';
285
279
  type RightType = 'CREATE' | 'DELETE' | 'UPDATE' | 'LINK' | 'UNLINK';
286
280
  type BQLFieldObj = {
287
281
  $path: string;
@@ -329,7 +323,7 @@ type EnrichedRoleField = RoleField & {
329
323
  type EnrichedDataField = DataField & {
330
324
  dbPath: string;
331
325
  };
332
- type EnrichedLinkField = BormField & {
326
+ type EnrichedLinkField = LinkField & {
333
327
  name: string;
334
328
  relation: string;
335
329
  plays: string;
@@ -344,9 +338,133 @@ type EnrichedLinkField = BormField & {
344
338
  });
345
339
 
346
340
  declare const Schema: unique symbol;
341
+ declare const QueryPath: unique symbol;
347
342
  declare const EdgeType: unique symbol;
348
343
  declare const EdgeSchema: unique symbol;
349
344
 
345
+ type Sorter = {
346
+ field: string;
347
+ desc?: boolean;
348
+ } | string;
349
+ type FilterValue = string | number | boolean | string[] | number[] | boolean[];
350
+ type PositiveFilter = {
351
+ [field: string]: FilterValue;
352
+ };
353
+ type NegativeFilter = {
354
+ $not?: PositiveFilter;
355
+ };
356
+ type Filter = PositiveFilter | NegativeFilter;
357
+ type RawBQLQuery = {
358
+ $id?: string | string[];
359
+ $filter?: Filter;
360
+ $fields?: BQLField[];
361
+ $excludedFields?: BQLField[];
362
+ $sort?: Sorter[];
363
+ $offset?: number;
364
+ $limit?: number;
365
+ } & ({
366
+ $entity: string;
367
+ } | {
368
+ $relation: string;
369
+ } | {
370
+ $thing: string;
371
+ $thingType: 'entity' | 'relation';
372
+ });
373
+ type EnrichedAttributeQuery = {
374
+ $fieldType: 'data';
375
+ $thingType: 'attribute';
376
+ $path: string;
377
+ $dbPath: string;
378
+ $as: string;
379
+ $var: string;
380
+ $justId: boolean;
381
+ $id: string;
382
+ $isVirtual?: boolean;
383
+ };
384
+ type PlayedBy = {
385
+ path: string;
386
+ cardinality: 'ONE' | 'MANY';
387
+ relation: string;
388
+ plays: string;
389
+ target: 'role' | 'relation';
390
+ thing: string;
391
+ thingType: 'entity' | 'relation';
392
+ };
393
+ type EnrichedLinkQuery = {
394
+ $fieldType: 'link';
395
+ $thingType: 'entity' | 'relation';
396
+ $thing: string;
397
+ $plays: string;
398
+ $playedBy: PlayedBy;
399
+ $path: string;
400
+ $dbPath: string;
401
+ $as: string;
402
+ $var: string;
403
+ $fields: EnrichedFieldQuery[];
404
+ $target: 'relation' | 'role';
405
+ $intermediary?: string;
406
+ $justId: boolean;
407
+ $id: string;
408
+ $idNotIncluded?: boolean;
409
+ $filter?: Filter;
410
+ $filterByUnique: boolean;
411
+ $filterProcessed: boolean;
412
+ $sort?: Sorter[];
413
+ $offset?: number;
414
+ $limit?: number;
415
+ [QueryPath]: string;
416
+ };
417
+ type EnrichedRoleQuery = {
418
+ $fieldType: 'role';
419
+ $thingType: 'relation';
420
+ $thing: string;
421
+ $path: string;
422
+ $dbPath: string;
423
+ $as: string;
424
+ $var: string;
425
+ $fields: EnrichedFieldQuery[];
426
+ $intermediary: string;
427
+ $justId: string;
428
+ $id: string;
429
+ $idNotIncluded?: boolean;
430
+ $filter?: Filter;
431
+ $filterByUnique: boolean;
432
+ $playedBy: PlayedBy;
433
+ $filterProcessed: boolean;
434
+ $sort?: Sorter[];
435
+ $offset?: number;
436
+ $limit?: number;
437
+ [QueryPath]: string;
438
+ };
439
+ type EnrichedFieldQuery = EnrichedAttributeQuery | EnrichedLinkQuery | EnrichedRoleQuery;
440
+ type EnrichedEntityQuery = {
441
+ $thingType: 'entity';
442
+ $thing: string;
443
+ $path: string;
444
+ $fields: (EnrichedAttributeQuery | EnrichedLinkQuery)[];
445
+ $idNotIncluded?: boolean;
446
+ $filter?: Filter;
447
+ $filterByUnique: boolean;
448
+ $sort?: Sorter[];
449
+ $offset?: number;
450
+ $limit?: number;
451
+ [QueryPath]: string;
452
+ };
453
+ type EnrichedRelationQuery = {
454
+ $thingType: 'relation';
455
+ $thing: string;
456
+ $path: string;
457
+ $fields: EnrichedFieldQuery[];
458
+ $idNotIncluded?: boolean;
459
+ $filter?: Filter;
460
+ $filterByUnique: boolean;
461
+ $sort?: Sorter[];
462
+ $offset?: number;
463
+ $limit?: number;
464
+ [QueryPath]: string;
465
+ };
466
+ type EnrichedBQLQuery = EnrichedEntityQuery | EnrichedRelationQuery;
467
+
350
468
  type RequiredKey<T, K extends keyof T> = T & {
351
469
  [P in K]-?: T[P];
352
470
  };
@@ -355,7 +473,7 @@ type BQLMutation = RootBQLMutationBlock | RootBQLMutationBlock[];
355
473
  type RootBQLMutationBlock = {
356
474
  [key: string]: any;
357
475
  $id?: string | string[];
358
- $filter?: Filter | Filter[];
476
+ $filter?: Filter;
359
477
  $tempId?: string;
360
478
  $op?: string;
361
479
  } & ({
@@ -369,7 +487,7 @@ type RootBQLMutationBlock = {
369
487
  type BQLMutationBlock = {
370
488
  [key: string]: any;
371
489
  $id?: string | string[];
372
- $filter?: Filter | Filter[];
490
+ $filter?: Filter;
373
491
  $tempId?: string;
374
492
  $op?: string;
375
493
  $entity?: string;
@@ -386,7 +504,7 @@ type FilledBQLMutationBlock = WithRequired<BQLMutationBlock, '$op'> & {
386
504
  type EnrichedBQLMutationBlock = {
387
505
  [key: string]: any;
388
506
  $id?: string | string[];
389
- $filter?: Filter | Filter[];
507
+ $filter?: Filter;
390
508
  $tempId?: string;
391
509
  $op: BormOperation;
392
510
  $thing: string;
@@ -408,28 +526,6 @@ type ParsedBQLMutation = {
408
526
  edges: BQLMutationBlock[];
409
527
  };
410
528
 
411
- type RawBQLQuery = {
412
- $id?: string | string[];
413
- $filter?: Record<string, any>;
414
- $fields?: BQLField[];
415
- $excludedFields?: BQLField[];
416
- } & ({
417
- $entity: string;
418
- } | {
419
- $relation: string;
420
- } | {
421
- $thing: string;
422
- $thingType: 'entity' | 'relation';
423
- });
424
- type ParsedBQLQuery = Omit<RawBQLQuery, '$entity' | '$relation' | '$thing' | '$thingType'> & {
425
- $localFilters?: Record<string, any>;
426
- $nestedFilters?: Record<string, any>;
427
- } & ({
428
- $entity: EnrichedBormEntity;
429
- } | {
430
- $relation: EnrichedBormRelation;
431
- });
432
-
433
529
  type TQLRequest = {
434
530
  entity?: string;
435
531
  roles?: {
@@ -504,6 +600,30 @@ type ExtractRoles<S> = 'roles' extends keyof S ? {
504
600
  } : {};
505
601
  type TypeGen<S extends BaseSchema> = ExtractDataFields<S> & ExtractLinkFields<S> & ExtractRoles<S>;
506
602
 
603
+ type Request = {
604
+ rawBqlRequest: RawBQLQuery;
605
+ filledBqlRequest?: FilledBQLMutationBlock[] | FilledBQLMutationBlock;
606
+ bqlRequest?: {
607
+ query?: EnrichedBQLQuery;
608
+ mutation?: ParsedBQLMutation;
609
+ };
610
+ schema: EnrichedBormSchema;
611
+ config: BormConfig;
612
+ tqlRequest?: TQLRequest;
613
+ dbHandles: DBHandles;
614
+ enrichedBqlQuery?: any;
615
+ };
616
+ type BaseResponse = {
617
+ bqlRes?: BQLResponse | null;
618
+ };
619
+ type NextPipeline<Res extends BaseResponse> = {
620
+ req: Request;
621
+ res: Res;
622
+ pipeline: Pipeline<Res>;
623
+ };
624
+ type PipelineOperation<Res extends BaseResponse> = (req: Request, res: Res) => Promise<void | NextPipeline<Res>[]>;
625
+ type Pipeline<Res extends BaseResponse> = PipelineOperation<Res>[];
626
+
507
627
  type BormProps = {
508
628
  schema: BormSchema;
509
629
  config: BormConfig;
@@ -518,9 +638,9 @@ declare class BormClient {
518
638
  init: () => Promise<void>;
519
639
  introspect: () => Promise<BormSchema>;
520
640
  define: () => Promise<void>;
521
- query: (query: RawBQLQuery | RawBQLQuery[], queryConfig?: QueryConfig) => Promise<BQLResponse>;
641
+ query: (query: RawBQLQuery | RawBQLQuery[], queryConfig?: QueryConfig) => Promise<BQLResponseSingle | BQLResponse[]>;
522
642
  mutate: (mutation: BQLMutation, mutationConfig?: MutationConfig) => Promise<BQLResponseMulti>;
523
643
  close: () => Promise<void>;
524
644
  }
525
645
 
526
- export { type Action, type BQLField, type BQLFieldObj, type BQLMutation, type BQLMutationBlock, type BQLResponse, type BQLResponseMulti, type BQLResponseSingle, type BormConfig, type BormEntity, type BormField, type BormMetadata, type BormOperation, type BormRelation, type BormSchema, type BormTrigger, type CardinalityType, type CommonProperties, type ContentType, type ContentTypeMapping, type DBConnector, type DBHandleKey, type DBHandles, type DataField, type DataFilter, type EnrichedBQLMutationBlock, type EnrichedBormEntity, type EnrichedBormRelation, type EnrichedBormSchema, type EnrichedDataField, type EnrichedLinkField, type EnrichedRoleField, type FilledBQLMutationBlock, type Filter, type Hooks, type LinkField, type LinkFilter, type LinkedFieldWithThing, type MiddleFilter, type MutationConfig, type NodeFunctionParams, type ParsedBQLMutation, type ParsedBQLQuery, type PreHook, type Provider, type ProviderObject, type QueryConfig, type RawBQLMutation, type RawBQLQuery, type RightType, type RoleField, type RootBQLMutationBlock, type TQLEntityMutation, type TQLRequest, type ThingType, type TransFormAction, type TypeDBClusterProviderObject, type TypeDBHandles, type TypeDBProviderObject, type TypeGen, type ValidateAction, type WithBormMetadata, BormClient as default };
646
+ export { type Action, type BQLField, type BQLFieldObj, type BQLMutation, type BQLMutationBlock, type BQLResponse, type BQLResponseMulti, type BQLResponseSingle, type BaseResponse, type BormConfig, type BormEntity, type BormField, type BormMetadata, type BormOperation, type BormRelation, type BormSchema, type BormTrigger, type Cardinality, type CommonProvider, type ContentType, type ContentTypeMapping, type DBConnector, type DBHandleKey, type DBHandles, type DataField, type DiscreteCardinality, type EnrichedAttributeQuery, type EnrichedBQLMutationBlock, type EnrichedBQLQuery, type EnrichedBormEntity, type EnrichedBormRelation, type EnrichedBormSchema, type EnrichedDataField, type EnrichedEntityQuery, type EnrichedFieldQuery, type EnrichedLinkField, type EnrichedLinkQuery, type EnrichedRelationQuery, type EnrichedRoleField, type EnrichedRoleQuery, type FilledBQLMutationBlock, type Filter, type FilterValue, type Hooks, type LinkField, type LinkedFieldWithThing, type MutationConfig, type NegativeFilter, type NodeFunctionParams, type ParsedBQLMutation, type Pipeline, type PipelineOperation, type PlayedBy, type PositiveFilter, type PreHook, type Provider, type QueryConfig, type RawBQLMutation, type RawBQLQuery, type Request, type RightType, type RoleField, type RootBQLMutationBlock, type Sorter, type TQLEntityMutation, type TQLRequest, type ThingType, type TransFormAction, type TypeDBClusterProvider, type TypeDBHandles, type TypeDBProvider, type TypeGen, type ValidateAction, type WithBormMetadata, BormClient as default };