@blitznocode/blitz-orm 0.7.3 → 0.8.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
@@ -84,6 +84,191 @@ type DataFilter = RequireAtLeastOne<{
84
84
  $ge?: number | string;
85
85
  }>;
86
86
 
87
+ type BormField = {
88
+ path: string;
89
+ cardinality: CardinalityType;
90
+ ordered?: boolean;
91
+ embedded?: boolean;
92
+ rights?: readonly RightType[];
93
+ };
94
+ type RoleField = {
95
+ cardinality: CardinalityType;
96
+ dbConnector?: DBConnector;
97
+ };
98
+ type LinkField = BormField & {
99
+ relation: string;
100
+ plays: string;
101
+ } & ({
102
+ target: 'role';
103
+ filter?: Filter | Filter[];
104
+ } | {
105
+ target: 'relation';
106
+ });
107
+ type LinkedFieldWithThing = LinkField & {
108
+ thing: string;
109
+ thingType: ThingType;
110
+ };
111
+ type StringField = BormField & {
112
+ contentType: 'ID' | 'COLOR' | 'DATE' | 'FILE' | 'EMAIL' | 'PHONE' | 'URL' | 'PASSWORD' | 'LANGUAGE_TEXT' | 'RICH_TEXT' | 'TEXT';
113
+ default?: {
114
+ type: 'fn';
115
+ fn: (currentNode: BQLMutationBlock) => string;
116
+ } | {
117
+ type: 'value';
118
+ value: string;
119
+ };
120
+ validations?: {
121
+ enum?: string[];
122
+ unique?: boolean;
123
+ fn?: (value: string) => boolean;
124
+ };
125
+ };
126
+ type NumberField = BormField & {
127
+ contentType: 'DURATION' | 'HOUR' | 'RATING' | 'CURRENCY' | 'PERCENTAGE' | 'NUMBER_DECIMAL' | 'NUMBER';
128
+ default?: {
129
+ type: 'fn';
130
+ fn: (currentNode: BQLMutationBlock) => number;
131
+ } | {
132
+ type: 'value';
133
+ value: number;
134
+ };
135
+ validations?: {
136
+ enum?: number[];
137
+ unique?: boolean;
138
+ fn?: (value: number) => boolean;
139
+ };
140
+ };
141
+ type DateField = BormField & {
142
+ contentType: 'TIME';
143
+ default?: {
144
+ type: 'fn';
145
+ fn: (currentNode: BQLMutationBlock) => Date;
146
+ } | {
147
+ type: 'value';
148
+ value: Date;
149
+ };
150
+ validations?: {
151
+ enum: Date[];
152
+ fn?: (value: Date) => boolean;
153
+ };
154
+ };
155
+ type BooleanField = BormField & {
156
+ contentType: 'BOOLEAN';
157
+ default?: {
158
+ type: 'fn';
159
+ fn: (currentNode: BQLMutationBlock) => boolean;
160
+ } | {
161
+ type: 'value';
162
+ value: boolean;
163
+ };
164
+ validations?: {
165
+ enum?: boolean[];
166
+ fn?: (value: boolean) => boolean;
167
+ };
168
+ };
169
+ type AllDataField = StringField | NumberField | DateField | BooleanField;
170
+ type DataField = BormField & {
171
+ shared?: boolean;
172
+ validations?: {
173
+ required?: boolean;
174
+ unique?: boolean;
175
+ };
176
+ isVirtual?: boolean;
177
+ dbConnectors?: [DBConnector, ...DBConnector[]];
178
+ } & AllDataField;
179
+ type ContentType = keyof ContentTypeMapping;
180
+ type ContentTypeMapping = {
181
+ ID: string;
182
+ JSON: unknown;
183
+ COLOR: string;
184
+ BOOLEAN: boolean;
185
+ POINT: {
186
+ x: number;
187
+ y: number;
188
+ };
189
+ FILE: string;
190
+ EMAIL: string;
191
+ PHONE: string;
192
+ WEEK_DAY: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
193
+ DURATION: number;
194
+ HOUR: number;
195
+ TIME: Date;
196
+ DATE: string;
197
+ RATING: number;
198
+ CURRENCY: number;
199
+ PERCENTAGE: number;
200
+ NUMBER_DECIMAL: number;
201
+ NUMBER: number;
202
+ URL: string;
203
+ PASSWORD: string;
204
+ LANGUAGE_TEXT: string;
205
+ RICH_TEXT: string;
206
+ TEXT: string;
207
+ };
208
+ type CardinalityType = 'ONE' | 'MANY' | 'INTERVAL';
209
+ type RightType = 'CREATE' | 'DELETE' | 'UPDATE' | 'LINK' | 'UNLINK';
210
+ type BQLFieldObj = {
211
+ $path: string;
212
+ $as?: string;
213
+ } & Omit<RawBQLQuery, '$entity' | '$relation' | '$thing' | '$thingType'>;
214
+ type BQLField = string | BQLFieldObj;
215
+
216
+ type EnrichedBormSchema = {
217
+ entities: {
218
+ [s: string]: EnrichedBormEntity;
219
+ };
220
+ relations: {
221
+ [s: string]: EnrichedBormRelation;
222
+ };
223
+ };
224
+ type EnrichedBormEntity = Omit<BormEntity, 'linkFields' | 'idFields' | 'dataFields'> & {
225
+ extends?: string;
226
+ allExtends?: string[];
227
+ idFields: string[];
228
+ thingType: 'entity';
229
+ name: string;
230
+ computedFields: string[];
231
+ virtualFields: string[];
232
+ requiredFields: string[];
233
+ enumFields: string[];
234
+ linkFields?: EnrichedLinkField[];
235
+ dataFields?: EnrichedDataField[];
236
+ };
237
+ type EnrichedBormRelation = Omit<BormRelation, 'linkFields' | 'dataFields'> & {
238
+ thingType: 'relation';
239
+ name: string;
240
+ computedFields: string[];
241
+ virtualFields: string[];
242
+ requiredFields: string[];
243
+ enumFields: string[];
244
+ linkFields?: EnrichedLinkField[];
245
+ dataFields?: EnrichedDataField[];
246
+ roles: {
247
+ [key: string]: EnrichedRoleField;
248
+ };
249
+ };
250
+ type EnrichedRoleField = RoleField & {
251
+ playedBy?: LinkedFieldWithThing[];
252
+ name: string;
253
+ };
254
+ type EnrichedDataField = DataField & {
255
+ dbPath: string;
256
+ };
257
+ type EnrichedLinkField = BormField & {
258
+ name: string;
259
+ relation: string;
260
+ plays: string;
261
+ } & ({
262
+ target: 'role';
263
+ filter?: Filter | Filter[];
264
+ oppositeLinkFieldsPlayedBy: LinkedFieldWithThing[];
265
+ } | {
266
+ target: 'relation';
267
+ oppositeLinkFieldsPlayedBy: Pick<LinkedFieldWithThing, 'thing' | 'thingType' | 'plays'>[];
268
+ });
269
+
270
+ declare const Schema: unique symbol;
271
+
87
272
  type RequiredKey<T, K extends keyof T> = T & {
88
273
  [P in K]-?: T[P];
89
274
  };
@@ -102,7 +287,10 @@ type BQLMutationBlock = {
102
287
  $thing: string;
103
288
  $thingType: 'entity' | 'relation';
104
289
  });
105
- type FilledBQLMutationBlock = WithRequired<BQLMutationBlock, '$tempId' | '$op'>;
290
+ type FilledBQLMutationBlock = WithRequired<BQLMutationBlock, '$tempId' | '$op'> & {
291
+ $entity?: string;
292
+ [Schema]: EnrichedBormEntity | EnrichedBormRelation;
293
+ };
106
294
  type RawBQLMutation<T extends Record<string, any> = Record<string, any>> = ({
107
295
  $id?: string;
108
296
  $op?: 'create' | 'delete' | 'update';
@@ -179,6 +367,7 @@ type BormEntity = {
179
367
  defaultDBConnector: DBConnector;
180
368
  dataFields?: readonly DataField[];
181
369
  linkFields?: readonly LinkField[];
370
+ hooks?: Hooks;
182
371
  } | {
183
372
  extends?: string;
184
373
  idFields: readonly string[];
@@ -194,125 +383,26 @@ type BormRelation = BormEntity & {
194
383
  [key: string]: RoleField;
195
384
  };
196
385
  };
197
-
198
- type BormField = {
199
- path: string;
200
- cardinality: CardinalityType;
201
- ordered?: boolean;
202
- embedded?: boolean;
203
- rights?: readonly RightType[];
204
- };
205
- type RoleField = {
206
- cardinality: CardinalityType;
207
- dbConnector?: DBConnector;
208
- };
209
- type LinkField = BormField & {
210
- relation: string;
211
- plays: string;
212
- } & ({
213
- target: 'role';
214
- filter?: Filter | Filter[];
215
- } | {
216
- target: 'relation';
217
- });
218
- type LinkedFieldWithThing = LinkField & {
219
- thing: string;
220
- thingType: ThingType;
221
- };
222
- type DataField = BormField & {
223
- shared?: boolean;
224
- default?: any;
225
- contentType: ContentType;
226
- validations?: any;
227
- isVirtual?: boolean;
228
- dbConnectors?: [DBConnector, ...DBConnector[]];
386
+ type BormOperation = 'create' | 'update' | 'delete' | 'link' | 'unlink';
387
+ type BormTrigger = 'onCreate' | 'onUpdate' | 'onDelete' | 'onLink' | 'onUnlink';
388
+ type Hooks = {
389
+ pre?: readonly PreHook[];
229
390
  };
230
- 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';
231
- type ContentTypeMapping = {
232
- ID: string;
233
- JSON: any;
234
- COLOR: string;
235
- BOOLEAN: boolean;
236
- POINT: {
237
- x: number;
238
- y: number;
239
- };
240
- FILE: string;
241
- EMAIL: string;
242
- PHONE: string;
243
- WEEK_DAY: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
244
- DURATION: number;
245
- HOUR: number;
246
- TIME: Date;
247
- DATE: Date;
248
- RATING: number;
249
- CURRENCY: number;
250
- PERCENTAGE: number;
251
- NUMBER_DECIMAL: number;
252
- NUMBER: number;
253
- URL: string;
254
- PASSWORD: string;
255
- LANGUAGE_TEXT: string;
256
- RICH_TEXT: string;
257
- TEXT: string;
258
- };
259
- type CardinalityType = 'ONE' | 'MANY' | 'INTERVAL';
260
- type RightType = 'CREATE' | 'DELETE' | 'UPDATE' | 'LINK' | 'UNLINK';
261
- type BQLFieldObj = {
262
- $path: string;
263
- $as?: string;
264
- } & Omit<RawBQLQuery, '$entity' | '$relation' | '$thing' | '$thingType'>;
265
- type BQLField = string | BQLFieldObj;
266
-
267
- type EnrichedBormSchema = {
268
- entities: {
269
- [s: string]: EnrichedBormEntity;
270
- };
271
- relations: {
272
- [s: string]: EnrichedBormRelation;
391
+ type PreHook = {
392
+ triggers: {
393
+ [K in BormTrigger]?: () => boolean;
273
394
  };
395
+ actions: readonly Action[];
274
396
  };
275
- type EnrichedBormEntity = Omit<BormEntity, 'linkFields' | 'idFields' | 'dataFields'> & {
276
- extends?: string;
277
- allExtends?: string[];
278
- idFields: string[];
279
- thingType: 'entity';
280
- name: string;
281
- computedFields: string[];
282
- virtualFields: string[];
283
- linkFields?: EnrichedLinkField[];
284
- dataFields?: EnrichedDataField[];
285
- };
286
- type EnrichedBormRelation = Omit<BormRelation, 'linkFields' | 'dataFields'> & {
287
- thingType: 'relation';
288
- name: string;
289
- computedFields: string[];
290
- virtualFields: string[];
291
- linkFields?: EnrichedLinkField[];
292
- dataFields?: EnrichedDataField[];
293
- roles: {
294
- [key: string]: EnrichedRoleField;
295
- };
296
- };
297
- type EnrichedRoleField = RoleField & {
298
- playedBy?: LinkedFieldWithThing[];
299
- name: string;
300
- };
301
- type EnrichedDataField = DataField & {
302
- dbPath: string;
303
- };
304
- type EnrichedLinkField = BormField & {
305
- name: string;
306
- relation: string;
307
- plays: string;
308
- } & ({
309
- target: 'role';
310
- filter?: Filter | Filter[];
311
- oppositeLinkFieldsPlayedBy: LinkedFieldWithThing[];
397
+ type Action = {
398
+ type: 'validate';
399
+ fn: (entity: FilledBQLMutationBlock) => boolean;
400
+ severity: 'error' | 'warning' | 'info';
401
+ message: string;
312
402
  } | {
313
- target: 'relation';
314
- oppositeLinkFieldsPlayedBy: Pick<LinkedFieldWithThing, 'thing' | 'thingType' | 'plays'>[];
315
- });
403
+ type: 'transform';
404
+ fn: (entity: FilledBQLMutationBlock) => Partial<FilledBQLMutationBlock>;
405
+ };
316
406
 
317
407
  type ContentTypeToType<C extends keyof ContentTypeMapping> = ContentTypeMapping[C];
318
408
  type HandleCardinality<T, C extends 'ONE' | 'MANY'> = C extends 'MANY' ? T[] : T;
@@ -380,4 +470,4 @@ declare class BormClient {
380
470
  close: () => Promise<void>;
381
471
  }
382
472
 
383
- export { BQLField, BQLFieldObj, BQLMutationBlock, BQLResponse, BQLResponseMulti, BQLResponseSingle, BormConfig, BormEntity, BormField, BormMetadata, BormRelation, BormSchema, CardinalityType, CommonProperties, ContentType, ContentTypeMapping, DBConnector, DBHandles, DataField, DataFilter, EnrichedBormEntity, EnrichedBormRelation, EnrichedBormSchema, EnrichedDataField, EnrichedLinkField, EnrichedRoleField, FilledBQLMutationBlock, Filter, LinkField, LinkFilter, LinkedFieldWithThing, MiddleFilter, MutateConfig, ParsedBQLMutation, ParsedBQLQuery, Provider, ProviderObject, QueryConfig, RawBQLMutation, RawBQLQuery, RightType, RoleField, TQLEntityMutation, TQLRequest, ThingType, TypeDBClusterProviderObject, TypeDBHandles, TypeDBProviderObject, TypeGen, WithBormMetadata, BormClient as default };
473
+ 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 };