@blitznocode/blitz-orm 0.13.8 → 0.14.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
@@ -56,6 +56,7 @@ type QueryConfig = {
56
56
  returnNulls?: boolean;
57
57
  simplifiedLinks?: boolean;
58
58
  debugger?: boolean;
59
+ legacySurrealDBAdapter?: boolean;
59
60
  };
60
61
  type MutationConfig = {
61
62
  noMetadata?: boolean;
@@ -93,6 +94,30 @@ type AtLeastOne<T, U = {
93
94
  type DBHandles = AtLeastOne<AllDbHandles>;
94
95
  type DBHandleKey = keyof DBHandles;
95
96
 
97
+ type Request = {
98
+ rawBqlRequest: RawBQLQuery;
99
+ filledBqlRequest?: FilledBQLMutationBlock[] | FilledBQLMutationBlock;
100
+ bqlRequest?: {
101
+ query?: EnrichedBQLQuery;
102
+ mutation?: ParsedBQLMutation;
103
+ };
104
+ schema: EnrichedBormSchema;
105
+ config: BormConfig;
106
+ tqlRequest?: TQLRequest;
107
+ dbHandles: DBHandles;
108
+ enrichedBqlQuery?: any;
109
+ };
110
+ type BaseResponse = {
111
+ bqlRes?: BQLResponse | null;
112
+ };
113
+ type NextPipeline<Res extends BaseResponse> = {
114
+ req: Request;
115
+ res: Res;
116
+ pipeline: Pipeline<Res>;
117
+ };
118
+ type PipelineOperation<Res extends BaseResponse> = (req: Request, res: Res) => Promise<undefined | NextPipeline<Res>[]>;
119
+ type Pipeline<Res extends BaseResponse> = PipelineOperation<Res>[];
120
+
96
121
  type ThingType = 'entity' | 'relation';
97
122
  type BormMetadata = {
98
123
  $id: string;
@@ -109,90 +134,32 @@ type BQLResponseSingle = Record<string | symbol, any>;
109
134
  type BQLResponseMulti = BQLResponseSingle[];
110
135
  type BQLResponse = BQLResponseSingle | BQLResponseMulti;
111
136
 
112
- type BormSchema = {
113
- entities: {
114
- [s: string]: BormEntity;
115
- };
116
- relations: {
117
- [s: string]: BormRelation;
118
- };
119
- };
120
- type BormEntity = {
121
- extends: string;
122
- idFields?: readonly string[];
123
- defaultDBConnector: DBConnector;
124
- dataFields?: readonly DataField[];
125
- linkFields?: readonly LinkField[];
126
- refFields?: {
127
- [key: string]: RefField;
128
- };
129
- hooks?: Hooks;
130
- } | {
131
- idFields: readonly string[];
132
- defaultDBConnector: DBConnector;
133
- dataFields?: readonly DataField[];
134
- linkFields?: readonly LinkField[];
135
- refFields?: {
136
- [key: string]: RefField;
137
- };
138
- hooks?: Hooks;
139
- };
140
- type BormRelation = BormEntity & {
141
- defaultDBConnector: DBConnector & {
142
- path: string;
143
- };
137
+ type TQLRequest = {
138
+ entity?: string;
144
139
  roles?: {
145
- [key: string]: RoleField;
146
- };
147
- };
148
- type BormOperation = 'create' | 'update' | 'delete' | 'link' | 'unlink' | 'replace' | 'match';
149
- type BormTrigger = 'onCreate' | 'onUpdate' | 'onDelete' | 'onLink' | 'onUnlink' | 'onReplace' | 'onMatch';
150
- type Hooks = {
151
- pre?: readonly PreHook[];
152
- };
153
- type PreHook = {
154
- triggers?: {
155
- [K in BormTrigger]?: () => boolean;
156
- };
157
- actions: readonly Action[];
158
- };
159
- type Action = {
160
- name?: string;
161
- description?: string;
162
- } & (TransFormAction | ValidateAction);
163
- type NodeFunctionParams = [
164
- currentNode: EnrichedBQLMutationBlock,
165
- parentNode: EnrichedBQLMutationBlock,
166
- context: Record<string, any>,
167
- dbNode: EnrichedBQLMutationBlock | Record<string, never>
168
- ];
169
- type TransFormAction = {
170
- type: 'transform';
171
- fn: (...args: NodeFunctionParams) => Partial<EnrichedBQLMutationBlock>;
172
- };
173
- type ValidateAction = {
174
- type: 'validate';
175
- fn: (...args: NodeFunctionParams) => boolean;
176
- severity: 'error' | 'warning' | 'info';
177
- message: string;
140
+ path: string;
141
+ request: string;
142
+ owner: string;
143
+ }[];
144
+ relations?: {
145
+ relation: string;
146
+ entity: string;
147
+ request: string;
148
+ }[];
149
+ insertionMatches?: string;
150
+ deletionMatches?: string;
151
+ insertions?: string;
152
+ deletions?: string;
178
153
  };
179
-
180
- type AdapterContext = {
181
- mutation: {
182
- splitArray$Ids: boolean;
183
- requiresParseBQL: boolean;
184
- };
154
+ type TQLEntityMutation = {
155
+ entity: string;
156
+ relations?: {
157
+ relation: string;
158
+ entity: string;
159
+ request: string;
160
+ }[];
185
161
  };
186
162
 
187
- declare const Schema: unique symbol;
188
- declare const QueryPath: unique symbol;
189
- declare const EdgeType: unique symbol;
190
- declare const EdgeSchema: unique symbol;
191
- declare const DBNode: unique symbol;
192
- declare const FieldSchema: unique symbol;
193
- declare const SharedMetadata: unique symbol;
194
- declare const SuqlMetadata: unique symbol;
195
-
196
163
  type BormField = {
197
164
  path: string;
198
165
  cardinality?: DiscreteCardinality;
@@ -222,6 +189,7 @@ type LinkField = BormField & {
222
189
  } & ({
223
190
  target: 'role';
224
191
  filter?: Filter | Filter[];
192
+ targetRole: string;
225
193
  } | {
226
194
  target: 'relation';
227
195
  });
@@ -359,6 +327,107 @@ type BQLFieldObj = {
359
327
  } & Omit<RawBQLQuery, '$entity' | '$relation' | '$thing' | '$thingType'>;
360
328
  type BQLField = string | BQLFieldObj;
361
329
 
330
+ /**
331
+ * These types are design for SurrealDB query in mind. For other DBs or for mutation, they may be missing some fields.
332
+ */
333
+
334
+ type Index = SingleIndex | CompositeIndex;
335
+ interface SingleIndex {
336
+ type: 'single';
337
+ field: string;
338
+ }
339
+ interface CompositeIndex {
340
+ type: 'composite';
341
+ fields: [string, ...string[]];
342
+ }
343
+
344
+ type BormSchema = {
345
+ entities: {
346
+ [s: string]: BormEntity;
347
+ };
348
+ relations: {
349
+ [s: string]: BormRelation;
350
+ };
351
+ };
352
+ type BormEntity = {
353
+ extends: string;
354
+ idFields?: readonly string[];
355
+ defaultDBConnector: DBConnector;
356
+ dataFields?: readonly DataField[];
357
+ linkFields?: readonly LinkField[];
358
+ refFields?: {
359
+ [key: string]: RefField;
360
+ };
361
+ hooks?: Hooks;
362
+ indexes?: Index[];
363
+ } | {
364
+ idFields: readonly string[];
365
+ defaultDBConnector: DBConnector;
366
+ dataFields?: readonly DataField[];
367
+ linkFields?: readonly LinkField[];
368
+ refFields?: {
369
+ [key: string]: RefField;
370
+ };
371
+ hooks?: Hooks;
372
+ indexes?: Index[];
373
+ };
374
+ type BormRelation = BormEntity & {
375
+ defaultDBConnector: DBConnector & {
376
+ path: string;
377
+ };
378
+ roles?: {
379
+ [key: string]: RoleField;
380
+ };
381
+ indexes?: Index[];
382
+ };
383
+ type BormOperation = 'create' | 'update' | 'delete' | 'link' | 'unlink' | 'replace' | 'match';
384
+ type BormTrigger = 'onCreate' | 'onUpdate' | 'onDelete' | 'onLink' | 'onUnlink' | 'onReplace' | 'onMatch';
385
+ type Hooks = {
386
+ pre?: readonly PreHook[];
387
+ };
388
+ type PreHook = {
389
+ triggers?: {
390
+ [K in BormTrigger]?: () => boolean;
391
+ };
392
+ actions: readonly Action[];
393
+ };
394
+ type Action = {
395
+ name?: string;
396
+ description?: string;
397
+ } & (TransFormAction | ValidateAction);
398
+ type NodeFunctionParams = [
399
+ currentNode: EnrichedBQLMutationBlock,
400
+ parentNode: EnrichedBQLMutationBlock,
401
+ context: Record<string, any>,
402
+ dbNode: EnrichedBQLMutationBlock | Record<string, never>
403
+ ];
404
+ type TransFormAction = {
405
+ type: 'transform';
406
+ fn: (...args: NodeFunctionParams) => Partial<EnrichedBQLMutationBlock>;
407
+ };
408
+ type ValidateAction = {
409
+ type: 'validate';
410
+ fn: (...args: NodeFunctionParams) => boolean;
411
+ severity: 'error' | 'warning' | 'info';
412
+ message: string;
413
+ };
414
+
415
+ type AdapterContext = {
416
+ mutation: {
417
+ splitArray$Ids: boolean;
418
+ requiresParseBQL: boolean;
419
+ };
420
+ };
421
+
422
+ declare const Schema: unique symbol;
423
+ declare const QueryPath: unique symbol;
424
+ declare const EdgeType: unique symbol;
425
+ declare const EdgeSchema: unique symbol;
426
+ declare const DBNode: unique symbol;
427
+ declare const FieldSchema: unique symbol;
428
+ declare const SharedMetadata: unique symbol;
429
+ declare const SuqlMetadata: unique symbol;
430
+
362
431
  type EnrichedBormSchema = {
363
432
  entities: {
364
433
  [s: string]: EnrichedBormEntity;
@@ -657,32 +726,6 @@ type ParsedBQLMutation = {
657
726
  edges: BQLMutationBlock[];
658
727
  };
659
728
 
660
- type TQLRequest = {
661
- entity?: string;
662
- roles?: {
663
- path: string;
664
- request: string;
665
- owner: string;
666
- }[];
667
- relations?: {
668
- relation: string;
669
- entity: string;
670
- request: string;
671
- }[];
672
- insertionMatches?: string;
673
- deletionMatches?: string;
674
- insertions?: string;
675
- deletions?: string;
676
- };
677
- type TQLEntityMutation = {
678
- entity: string;
679
- relations?: {
680
- relation: string;
681
- entity: string;
682
- request: string;
683
- }[];
684
- };
685
-
686
729
  type ContentTypeToType<C extends keyof ContentTypeMapping> = ContentTypeMapping[C];
687
730
  type HandleCardinality<T, C extends 'ONE' | 'MANY'> = C extends 'MANY' ? T[] : T;
688
731
  type ContentTypeAndCardinality = {
@@ -731,30 +774,6 @@ type ExtractRoles<S> = 'roles' extends keyof S ? {
731
774
  } : Record<string, never>;
732
775
  type TypeGen<S extends BaseSchema> = ExtractDataFields<S> & ExtractLinkFields<S> & ExtractRoles<S>;
733
776
 
734
- type Request = {
735
- rawBqlRequest: RawBQLQuery;
736
- filledBqlRequest?: FilledBQLMutationBlock[] | FilledBQLMutationBlock;
737
- bqlRequest?: {
738
- query?: EnrichedBQLQuery;
739
- mutation?: ParsedBQLMutation;
740
- };
741
- schema: EnrichedBormSchema;
742
- config: BormConfig;
743
- tqlRequest?: TQLRequest;
744
- dbHandles: DBHandles;
745
- enrichedBqlQuery?: any;
746
- };
747
- type BaseResponse = {
748
- bqlRes?: BQLResponse | null;
749
- };
750
- type NextPipeline<Res extends BaseResponse> = {
751
- req: Request;
752
- res: Res;
753
- pipeline: Pipeline<Res>;
754
- };
755
- type PipelineOperation<Res extends BaseResponse> = (req: Request, res: Res) => Promise<undefined | NextPipeline<Res>[]>;
756
- type Pipeline<Res extends BaseResponse> = PipelineOperation<Res>[];
757
-
758
777
  type BormProps = {
759
778
  schema: BormSchema;
760
779
  config: BormConfig;