dyna-record 0.4.0 → 0.4.6

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.
@@ -0,0 +1,432 @@
1
+ import { z } from "zod";
2
+ import type { EntityClass } from "../types";
3
+ import type DynaRecord from "../DynaRecord";
4
+ /**
5
+ * Zod schema that transforms table metadata to a serializable format.
6
+ * This is the main schema used to serialize {@link TableMetadata} instances,
7
+ * extracting only serializable values and converting EntityClass references to strings.
8
+ *
9
+ * @property {string} name - The name of the table
10
+ * @property {string} delimiter - The delimiter used in the table's composite keys (defaults to "#")
11
+ * @property {Record<string, AttributeMetadataTransform>} defaultAttributes - Default attributes for the entity, keyed by entity field names
12
+ * @property {Record<string, AttributeMetadataTransform>} defaultTableAttributes - Default attributes for the table, keyed by table field aliases
13
+ * @property {AttributeMetadataTransform} partitionKeyAttribute - Metadata for the table's partition key attribute
14
+ * @property {AttributeMetadataTransform} sortKeyAttribute - Metadata for the table's sort key attribute
15
+ * @property {Record<string, EntityMetadataTransform>} entities - Entities mapped to the table, keyed by entity class name
16
+ *
17
+ * @returns A serialized table metadata object containing only serializable values
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const metadata = TableMetadataTransform.parse(tableMetadataInstance);
22
+ * // Returns a plain object with all EntityClass references converted to strings
23
+ * ```
24
+ */
25
+ export declare const TableMetadataTransform: z.ZodObject<{
26
+ name: z.ZodString;
27
+ delimiter: z.ZodString;
28
+ defaultAttributes: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodObject<{
29
+ name: z.ZodString;
30
+ alias: z.ZodString;
31
+ nullable: z.ZodBoolean;
32
+ foreignKeyTarget: z.ZodOptional<z.ZodType<EntityClass<DynaRecord>, z.ZodTypeDef, EntityClass<DynaRecord>>>;
33
+ }, "strip", z.ZodTypeAny, {
34
+ name: string;
35
+ nullable: boolean;
36
+ alias: string;
37
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
38
+ }, {
39
+ name: string;
40
+ nullable: boolean;
41
+ alias: string;
42
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
43
+ }>, {
44
+ foreignKeyTarget?: string | undefined;
45
+ name: string;
46
+ alias: string;
47
+ nullable: boolean;
48
+ }, {
49
+ name: string;
50
+ nullable: boolean;
51
+ alias: string;
52
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
53
+ }>>;
54
+ defaultTableAttributes: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodObject<{
55
+ name: z.ZodString;
56
+ alias: z.ZodString;
57
+ nullable: z.ZodBoolean;
58
+ foreignKeyTarget: z.ZodOptional<z.ZodType<EntityClass<DynaRecord>, z.ZodTypeDef, EntityClass<DynaRecord>>>;
59
+ }, "strip", z.ZodTypeAny, {
60
+ name: string;
61
+ nullable: boolean;
62
+ alias: string;
63
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
64
+ }, {
65
+ name: string;
66
+ nullable: boolean;
67
+ alias: string;
68
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
69
+ }>, {
70
+ foreignKeyTarget?: string | undefined;
71
+ name: string;
72
+ alias: string;
73
+ nullable: boolean;
74
+ }, {
75
+ name: string;
76
+ nullable: boolean;
77
+ alias: string;
78
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
79
+ }>>;
80
+ partitionKeyAttribute: z.ZodEffects<z.ZodObject<{
81
+ name: z.ZodString;
82
+ alias: z.ZodString;
83
+ nullable: z.ZodBoolean;
84
+ foreignKeyTarget: z.ZodOptional<z.ZodType<EntityClass<DynaRecord>, z.ZodTypeDef, EntityClass<DynaRecord>>>;
85
+ }, "strip", z.ZodTypeAny, {
86
+ name: string;
87
+ nullable: boolean;
88
+ alias: string;
89
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
90
+ }, {
91
+ name: string;
92
+ nullable: boolean;
93
+ alias: string;
94
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
95
+ }>, {
96
+ foreignKeyTarget?: string | undefined;
97
+ name: string;
98
+ alias: string;
99
+ nullable: boolean;
100
+ }, {
101
+ name: string;
102
+ nullable: boolean;
103
+ alias: string;
104
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
105
+ }>;
106
+ sortKeyAttribute: z.ZodEffects<z.ZodObject<{
107
+ name: z.ZodString;
108
+ alias: z.ZodString;
109
+ nullable: z.ZodBoolean;
110
+ foreignKeyTarget: z.ZodOptional<z.ZodType<EntityClass<DynaRecord>, z.ZodTypeDef, EntityClass<DynaRecord>>>;
111
+ }, "strip", z.ZodTypeAny, {
112
+ name: string;
113
+ nullable: boolean;
114
+ alias: string;
115
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
116
+ }, {
117
+ name: string;
118
+ nullable: boolean;
119
+ alias: string;
120
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
121
+ }>, {
122
+ foreignKeyTarget?: string | undefined;
123
+ name: string;
124
+ alias: string;
125
+ nullable: boolean;
126
+ }, {
127
+ name: string;
128
+ nullable: boolean;
129
+ alias: string;
130
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
131
+ }>;
132
+ entities: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodObject<{
133
+ tableClassName: z.ZodString;
134
+ attributes: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodObject<{
135
+ name: z.ZodString;
136
+ alias: z.ZodString;
137
+ nullable: z.ZodBoolean;
138
+ foreignKeyTarget: z.ZodOptional<z.ZodType<EntityClass<DynaRecord>, z.ZodTypeDef, EntityClass<DynaRecord>>>;
139
+ }, "strip", z.ZodTypeAny, {
140
+ name: string;
141
+ nullable: boolean;
142
+ alias: string;
143
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
144
+ }, {
145
+ name: string;
146
+ nullable: boolean;
147
+ alias: string;
148
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
149
+ }>, {
150
+ foreignKeyTarget?: string | undefined;
151
+ name: string;
152
+ alias: string;
153
+ nullable: boolean;
154
+ }, {
155
+ name: string;
156
+ nullable: boolean;
157
+ alias: string;
158
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
159
+ }>>;
160
+ tableAttributes: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodObject<{
161
+ name: z.ZodString;
162
+ alias: z.ZodString;
163
+ nullable: z.ZodBoolean;
164
+ foreignKeyTarget: z.ZodOptional<z.ZodType<EntityClass<DynaRecord>, z.ZodTypeDef, EntityClass<DynaRecord>>>;
165
+ }, "strip", z.ZodTypeAny, {
166
+ name: string;
167
+ nullable: boolean;
168
+ alias: string;
169
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
170
+ }, {
171
+ name: string;
172
+ nullable: boolean;
173
+ alias: string;
174
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
175
+ }>, {
176
+ foreignKeyTarget?: string | undefined;
177
+ name: string;
178
+ alias: string;
179
+ nullable: boolean;
180
+ }, {
181
+ name: string;
182
+ nullable: boolean;
183
+ alias: string;
184
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
185
+ }>>;
186
+ relationships: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodObject<{
187
+ type: z.ZodString;
188
+ propertyName: z.ZodString;
189
+ target: z.ZodOptional<z.ZodType<EntityClass<DynaRecord>, z.ZodTypeDef, EntityClass<DynaRecord>>>;
190
+ foreignKey: z.ZodOptional<z.ZodString>;
191
+ joinTableName: z.ZodOptional<z.ZodString>;
192
+ uniDirectional: z.ZodOptional<z.ZodBoolean>;
193
+ }, "strip", z.ZodTypeAny, {
194
+ type: string;
195
+ propertyName: string;
196
+ foreignKey?: string | undefined;
197
+ uniDirectional?: boolean | undefined;
198
+ joinTableName?: string | undefined;
199
+ target?: EntityClass<DynaRecord> | undefined;
200
+ }, {
201
+ type: string;
202
+ propertyName: string;
203
+ foreignKey?: string | undefined;
204
+ uniDirectional?: boolean | undefined;
205
+ joinTableName?: string | undefined;
206
+ target?: EntityClass<DynaRecord> | undefined;
207
+ }>, {
208
+ uniDirectional?: boolean | undefined;
209
+ joinTableName?: string | undefined;
210
+ foreignKey?: string | undefined;
211
+ target?: string | undefined;
212
+ type: string;
213
+ propertyName: string;
214
+ }, {
215
+ type: string;
216
+ propertyName: string;
217
+ foreignKey?: string | undefined;
218
+ uniDirectional?: boolean | undefined;
219
+ joinTableName?: string | undefined;
220
+ target?: EntityClass<DynaRecord> | undefined;
221
+ }>>;
222
+ idField: z.ZodOptional<z.ZodString>;
223
+ }, "strip", z.ZodTypeAny, {
224
+ tableClassName: string;
225
+ attributes: Record<string, {
226
+ foreignKeyTarget?: string | undefined;
227
+ name: string;
228
+ alias: string;
229
+ nullable: boolean;
230
+ }>;
231
+ tableAttributes: Record<string, {
232
+ foreignKeyTarget?: string | undefined;
233
+ name: string;
234
+ alias: string;
235
+ nullable: boolean;
236
+ }>;
237
+ relationships: Record<string, {
238
+ uniDirectional?: boolean | undefined;
239
+ joinTableName?: string | undefined;
240
+ foreignKey?: string | undefined;
241
+ target?: string | undefined;
242
+ type: string;
243
+ propertyName: string;
244
+ }>;
245
+ idField?: string | undefined;
246
+ }, {
247
+ tableClassName: string;
248
+ attributes: Record<string, {
249
+ name: string;
250
+ nullable: boolean;
251
+ alias: string;
252
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
253
+ }>;
254
+ tableAttributes: Record<string, {
255
+ name: string;
256
+ nullable: boolean;
257
+ alias: string;
258
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
259
+ }>;
260
+ relationships: Record<string, {
261
+ type: string;
262
+ propertyName: string;
263
+ foreignKey?: string | undefined;
264
+ uniDirectional?: boolean | undefined;
265
+ joinTableName?: string | undefined;
266
+ target?: EntityClass<DynaRecord> | undefined;
267
+ }>;
268
+ idField?: string | undefined;
269
+ }>, {
270
+ idField?: string | undefined;
271
+ tableClassName: string;
272
+ attributes: Record<string, {
273
+ foreignKeyTarget?: string | undefined;
274
+ name: string;
275
+ alias: string;
276
+ nullable: boolean;
277
+ }>;
278
+ tableAttributes: Record<string, {
279
+ foreignKeyTarget?: string | undefined;
280
+ name: string;
281
+ alias: string;
282
+ nullable: boolean;
283
+ }>;
284
+ relationships: Record<string, {
285
+ uniDirectional?: boolean | undefined;
286
+ joinTableName?: string | undefined;
287
+ foreignKey?: string | undefined;
288
+ target?: string | undefined;
289
+ type: string;
290
+ propertyName: string;
291
+ }>;
292
+ }, {
293
+ tableClassName: string;
294
+ attributes: Record<string, {
295
+ name: string;
296
+ nullable: boolean;
297
+ alias: string;
298
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
299
+ }>;
300
+ tableAttributes: Record<string, {
301
+ name: string;
302
+ nullable: boolean;
303
+ alias: string;
304
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
305
+ }>;
306
+ relationships: Record<string, {
307
+ type: string;
308
+ propertyName: string;
309
+ foreignKey?: string | undefined;
310
+ uniDirectional?: boolean | undefined;
311
+ joinTableName?: string | undefined;
312
+ target?: EntityClass<DynaRecord> | undefined;
313
+ }>;
314
+ idField?: string | undefined;
315
+ }>>;
316
+ }, "strip", z.ZodTypeAny, {
317
+ name: string;
318
+ delimiter: string;
319
+ defaultAttributes: Record<string, {
320
+ foreignKeyTarget?: string | undefined;
321
+ name: string;
322
+ alias: string;
323
+ nullable: boolean;
324
+ }>;
325
+ defaultTableAttributes: Record<string, {
326
+ foreignKeyTarget?: string | undefined;
327
+ name: string;
328
+ alias: string;
329
+ nullable: boolean;
330
+ }>;
331
+ partitionKeyAttribute: {
332
+ foreignKeyTarget?: string | undefined;
333
+ name: string;
334
+ alias: string;
335
+ nullable: boolean;
336
+ };
337
+ sortKeyAttribute: {
338
+ foreignKeyTarget?: string | undefined;
339
+ name: string;
340
+ alias: string;
341
+ nullable: boolean;
342
+ };
343
+ entities: Record<string, {
344
+ idField?: string | undefined;
345
+ tableClassName: string;
346
+ attributes: Record<string, {
347
+ foreignKeyTarget?: string | undefined;
348
+ name: string;
349
+ alias: string;
350
+ nullable: boolean;
351
+ }>;
352
+ tableAttributes: Record<string, {
353
+ foreignKeyTarget?: string | undefined;
354
+ name: string;
355
+ alias: string;
356
+ nullable: boolean;
357
+ }>;
358
+ relationships: Record<string, {
359
+ uniDirectional?: boolean | undefined;
360
+ joinTableName?: string | undefined;
361
+ foreignKey?: string | undefined;
362
+ target?: string | undefined;
363
+ type: string;
364
+ propertyName: string;
365
+ }>;
366
+ }>;
367
+ }, {
368
+ name: string;
369
+ delimiter: string;
370
+ defaultAttributes: Record<string, {
371
+ name: string;
372
+ nullable: boolean;
373
+ alias: string;
374
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
375
+ }>;
376
+ defaultTableAttributes: Record<string, {
377
+ name: string;
378
+ nullable: boolean;
379
+ alias: string;
380
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
381
+ }>;
382
+ partitionKeyAttribute: {
383
+ name: string;
384
+ nullable: boolean;
385
+ alias: string;
386
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
387
+ };
388
+ sortKeyAttribute: {
389
+ name: string;
390
+ nullable: boolean;
391
+ alias: string;
392
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
393
+ };
394
+ entities: Record<string, {
395
+ tableClassName: string;
396
+ attributes: Record<string, {
397
+ name: string;
398
+ nullable: boolean;
399
+ alias: string;
400
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
401
+ }>;
402
+ tableAttributes: Record<string, {
403
+ name: string;
404
+ nullable: boolean;
405
+ alias: string;
406
+ foreignKeyTarget?: EntityClass<DynaRecord> | undefined;
407
+ }>;
408
+ relationships: Record<string, {
409
+ type: string;
410
+ propertyName: string;
411
+ foreignKey?: string | undefined;
412
+ uniDirectional?: boolean | undefined;
413
+ joinTableName?: string | undefined;
414
+ target?: EntityClass<DynaRecord> | undefined;
415
+ }>;
416
+ idField?: string | undefined;
417
+ }>;
418
+ }>;
419
+ /**
420
+ * Type representing the serialized output of table metadata.
421
+ * This type is inferred from the {@link TableMetadataTransform} schema and represents
422
+ * the structure of metadata after serialization, with all EntityClass references
423
+ * converted to strings and all non-serializable data (functions, Zod types, serializers) removed.
424
+ *
425
+ * @example
426
+ * ```typescript
427
+ * const metadata: SerializedTableMetadata = User.metadata();
428
+ * // metadata is a plain object with readonly properties
429
+ * ```
430
+ */
431
+ export type SerializedTableMetadata = z.output<typeof TableMetadataTransform>;
432
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/metadata/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AA4F5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQjC,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TableMetadataTransform = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Zod schema that transforms attribute metadata to a serializable format.
7
+ * Extracts only serializable properties (name, alias, nullable) and converts
8
+ * the foreignKeyTarget EntityClass reference to its class name string.
9
+ *
10
+ * @property {string} name - The name of the attribute as defined on the entity
11
+ * @property {string} alias - The alias of the attribute as defined in the database table
12
+ * @property {boolean} nullable - Indicates whether the attribute can be null
13
+ * @property {EntityClass<DynaRecord>} [foreignKeyTarget] - Optional entity class reference that will be converted to its name string
14
+ *
15
+ * @returns A serialized attribute metadata object with foreignKeyTarget as a string (class name) if present
16
+ */
17
+ const AttributeMetadataTransform = zod_1.z
18
+ .object({
19
+ name: zod_1.z.string(),
20
+ alias: zod_1.z.string(),
21
+ nullable: zod_1.z.boolean(),
22
+ foreignKeyTarget: zod_1.z.custom().optional()
23
+ })
24
+ .transform(attr => ({
25
+ name: attr.name,
26
+ alias: attr.alias,
27
+ nullable: attr.nullable,
28
+ ...(attr.foreignKeyTarget != null && {
29
+ foreignKeyTarget: attr.foreignKeyTarget.name
30
+ })
31
+ }));
32
+ /**
33
+ * Zod schema that transforms relationship metadata to a serializable format.
34
+ * Extracts serializable properties and converts EntityClass references to their class name strings.
35
+ *
36
+ * @property {string} type - The type of the relationship (e.g., "HasMany", "BelongsTo", "HasOne", "HasAndBelongsToMany", "OwnedBy")
37
+ * @property {string} propertyName - The property name on the source entity that holds the relationship
38
+ * @property {EntityClass<DynaRecord>} [target] - Optional target entity class reference that will be converted to its name string
39
+ * @property {string} [foreignKey] - Optional foreign key property name
40
+ * @property {string} [joinTableName] - Optional join table name for many-to-many relationships
41
+ * @property {boolean} [uniDirectional] - Optional flag indicating if the relationship is unidirectional
42
+ *
43
+ * @returns A serialized relationship metadata object with EntityClass references converted to strings
44
+ */
45
+ const RelationshipMetadataTransform = zod_1.z
46
+ .object({
47
+ type: zod_1.z.string(),
48
+ propertyName: zod_1.z.string(),
49
+ target: zod_1.z.custom().optional(),
50
+ foreignKey: zod_1.z.string().optional(),
51
+ joinTableName: zod_1.z.string().optional(),
52
+ uniDirectional: zod_1.z.boolean().optional()
53
+ })
54
+ .transform(rel => ({
55
+ type: rel.type,
56
+ propertyName: rel.propertyName,
57
+ ...(rel.target != null && { target: rel.target.name }),
58
+ ...(rel.foreignKey != null && { foreignKey: rel.foreignKey }),
59
+ ...(rel.joinTableName != null && { joinTableName: rel.joinTableName }),
60
+ ...(rel.uniDirectional !== undefined && {
61
+ uniDirectional: rel.uniDirectional
62
+ })
63
+ }));
64
+ /**
65
+ * Zod schema that transforms entity metadata to a serializable format.
66
+ * Extracts serializable properties and includes nested attribute and relationship metadata.
67
+ *
68
+ * @property {string} tableClassName - The name of the table class instance to which this entity belongs
69
+ * @property {Record<string, AttributeMetadataTransform>} attributes - Attribute metadata keyed by entity field names
70
+ * @property {Record<string, AttributeMetadataTransform>} tableAttributes - Attribute metadata keyed by table column names (aliases)
71
+ * @property {Record<string, RelationshipMetadataTransform>} relationships - Relationship metadata keyed by entity property names
72
+ * @property {string} [idField] - Optional custom id field name (used with @IdAttribute decorator)
73
+ *
74
+ * @returns A serialized entity metadata object with all nested metadata transformed
75
+ */
76
+ const EntityMetadataTransform = zod_1.z
77
+ .object({
78
+ tableClassName: zod_1.z.string(),
79
+ attributes: zod_1.z.record(AttributeMetadataTransform),
80
+ tableAttributes: zod_1.z.record(AttributeMetadataTransform),
81
+ relationships: zod_1.z.record(RelationshipMetadataTransform),
82
+ idField: zod_1.z.string().optional()
83
+ })
84
+ .transform(entity => ({
85
+ tableClassName: entity.tableClassName,
86
+ attributes: entity.attributes,
87
+ tableAttributes: entity.tableAttributes,
88
+ relationships: entity.relationships,
89
+ ...(entity.idField !== undefined &&
90
+ entity.idField !== "" && { idField: entity.idField })
91
+ }));
92
+ /**
93
+ * Zod schema that transforms table metadata to a serializable format.
94
+ * This is the main schema used to serialize {@link TableMetadata} instances,
95
+ * extracting only serializable values and converting EntityClass references to strings.
96
+ *
97
+ * @property {string} name - The name of the table
98
+ * @property {string} delimiter - The delimiter used in the table's composite keys (defaults to "#")
99
+ * @property {Record<string, AttributeMetadataTransform>} defaultAttributes - Default attributes for the entity, keyed by entity field names
100
+ * @property {Record<string, AttributeMetadataTransform>} defaultTableAttributes - Default attributes for the table, keyed by table field aliases
101
+ * @property {AttributeMetadataTransform} partitionKeyAttribute - Metadata for the table's partition key attribute
102
+ * @property {AttributeMetadataTransform} sortKeyAttribute - Metadata for the table's sort key attribute
103
+ * @property {Record<string, EntityMetadataTransform>} entities - Entities mapped to the table, keyed by entity class name
104
+ *
105
+ * @returns A serialized table metadata object containing only serializable values
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const metadata = TableMetadataTransform.parse(tableMetadataInstance);
110
+ * // Returns a plain object with all EntityClass references converted to strings
111
+ * ```
112
+ */
113
+ exports.TableMetadataTransform = zod_1.z.object({
114
+ name: zod_1.z.string(),
115
+ delimiter: zod_1.z.string(),
116
+ defaultAttributes: zod_1.z.record(AttributeMetadataTransform),
117
+ defaultTableAttributes: zod_1.z.record(AttributeMetadataTransform),
118
+ partitionKeyAttribute: AttributeMetadataTransform,
119
+ sortKeyAttribute: AttributeMetadataTransform,
120
+ entities: zod_1.z.record(EntityMetadataTransform)
121
+ });
@@ -1,7 +1,7 @@
1
1
  import type DynaRecord from "../../DynaRecord";
2
2
  import type { EntityClass } from "../../types";
3
3
  import OperationBase from "../OperationBase";
4
- import type { CreateOptions } from "./types";
4
+ import type { CreateOptions, CreateOperationOptions } from "./types";
5
5
  import { type EntityAttributesOnly } from "../types";
6
6
  /**
7
7
  * Represents an operation to create a new entity record in DynamoDB, including all necessary
@@ -37,11 +37,12 @@ declare class Create<T extends DynaRecord> extends OperationBase<T> {
37
37
  * partition (due to "BelongsTo" links), retrieves and inserts those link records.
38
38
  *
39
39
  * @param attributes - Attributes to initialize the new entity. Must be defined on the model and valid per schema constraints.
40
+ * @param options - Optional operation options including referentialIntegrityCheck flag.
40
41
  * @returns A promise that resolves to the newly created entity with all attributes, including automatically set fields.
41
42
  * @throws If the entity already exists, a uniqueness violation error is raised.
42
- * @throws If a required foreign key does not correspond to an existing entity, an error is raised.
43
+ * @throws If a required foreign key does not correspond to an existing entity, an error is raised (unless referentialIntegrityCheck is false).
43
44
  */
44
- run(attributes: CreateOptions<T>): Promise<EntityAttributesOnly<T>>;
45
+ run(attributes: CreateOptions<T>, options?: CreateOperationOptions): Promise<EntityAttributesOnly<T>>;
45
46
  /**
46
47
  * Builds and returns entity attributes that must be reserved for system usage.
47
48
  *
@@ -75,6 +76,7 @@ declare class Create<T extends DynaRecord> extends OperationBase<T> {
75
76
  *
76
77
  * @param entityData - The complete set of entity attributes for the new entity.
77
78
  * @param tableItem - The main entity's DynamoDB table item.
79
+ * @param referentialIntegrityCheck - Whether to perform referential integrity checks.
78
80
  * @private
79
81
  */
80
82
  private buildBelongsToTransactions;
@@ -83,6 +85,8 @@ declare class Create<T extends DynaRecord> extends OperationBase<T> {
83
85
  * Ensures referenced entities exist even when denormalised access patterns are not defined.
84
86
  *
85
87
  * @param entityData - Attributes being persisted for the new entity.
88
+ * @param referentialIntegrityCheck - Whether to perform referential integrity checks.
89
+ * @private
86
90
  */
87
91
  private buildStandaloneForeignKeyConditionChecks;
88
92
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAC;AAOhE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,UAAU,CAAC;AAIlB;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAG7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAKlC;;;;;;;;;;;;;;;;OAgBG;IACU,GAAG,CACd,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IA6BnC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,uBAAuB;IA8B/B;;;;;;;;;OASG;IACH,OAAO,CAAC,uBAAuB;IAiB/B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,0BAA0B;IAkClC;;;;;OAKG;IACH,OAAO,CAAC,wCAAwC;IA8BhD;;;;;;;;;;;OAWG;YACW,sBAAsB;IAmCpC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,2CAA2C;IAmBnD;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,uCAAuC;CA0BhD;AAED,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAC;AAOhE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,UAAU,CAAC;AAIlB;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAG7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAKlC;;;;;;;;;;;;;;;;;OAiBG;IACU,GAAG,CACd,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,EAC5B,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAuCnC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,uBAAuB;IA8B/B;;;;;;;;;OASG;IACH,OAAO,CAAC,uBAAuB;IAiB/B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,0BAA0B;IAqClC;;;;;;;OAOG;IACH,OAAO,CAAC,wCAAwC;IAkChD;;;;;;;;;;;OAWG;YACW,sBAAsB;IAmCpC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,2CAA2C;IAmBnD;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,uCAAuC;CA0BhD;AAED,eAAe,MAAM,CAAC"}
@@ -46,18 +46,20 @@ class Create extends OperationBase_1.default {
46
46
  * partition (due to "BelongsTo" links), retrieves and inserts those link records.
47
47
  *
48
48
  * @param attributes - Attributes to initialize the new entity. Must be defined on the model and valid per schema constraints.
49
+ * @param options - Optional operation options including referentialIntegrityCheck flag.
49
50
  * @returns A promise that resolves to the newly created entity with all attributes, including automatically set fields.
50
51
  * @throws If the entity already exists, a uniqueness violation error is raised.
51
- * @throws If a required foreign key does not correspond to an existing entity, an error is raised.
52
+ * @throws If a required foreign key does not correspond to an existing entity, an error is raised (unless referentialIntegrityCheck is false).
52
53
  */
53
- async run(attributes) {
54
+ async run(attributes, options) {
55
+ const referentialIntegrityCheck = options?.referentialIntegrityCheck ?? true;
54
56
  const entityAttrs = this.entityMetadata.parseRawEntityDefinedAttributes(attributes);
55
57
  const reservedAttrs = this.buildReservedAttributes(entityAttrs);
56
58
  const entityData = { ...reservedAttrs, ...entityAttrs };
57
59
  const tableItem = (0, utils_1.entityToTableItem)(this.EntityClass, entityData);
58
60
  this.buildPutItemTransaction(tableItem, entityData.id);
59
- this.buildBelongsToTransactions(entityData, tableItem);
60
- this.buildStandaloneForeignKeyConditionChecks(entityData);
61
+ this.buildBelongsToTransactions(entityData, tableItem, referentialIntegrityCheck);
62
+ this.buildStandaloneForeignKeyConditionChecks(entityData, referentialIntegrityCheck);
61
63
  // Attempt to fetch all belongs-to entities to properly create reverse denormalization links
62
64
  const belongsToTableItems = await this.getBelongsToTableItems(entityData);
63
65
  // If there are any belongs-to relationships, add the inverse link records into the new entity's partition
@@ -127,16 +129,19 @@ class Create extends OperationBase_1.default {
127
129
  *
128
130
  * @param entityData - The complete set of entity attributes for the new entity.
129
131
  * @param tableItem - The main entity's DynamoDB table item.
132
+ * @param referentialIntegrityCheck - Whether to perform referential integrity checks.
130
133
  * @private
131
134
  */
132
- buildBelongsToTransactions(entityData, tableItem) {
135
+ buildBelongsToTransactions(entityData, tableItem, referentialIntegrityCheck) {
133
136
  const tableName = this.tableMetadata.name;
134
137
  const relMetadata = this.entityMetadata.belongsToOrOwnedByRelationships;
135
138
  for (const relMeta of relMetadata) {
136
139
  const foreignKey = (0, utils_2.extractForeignKeyFromEntity)(relMeta, entityData);
137
140
  if (foreignKey !== undefined) {
138
141
  // Ensure referenced entity exists before linking
139
- this.buildRelationshipExistsConditionTransaction(relMeta, foreignKey);
142
+ if (referentialIntegrityCheck) {
143
+ this.buildRelationshipExistsConditionTransaction(relMeta, foreignKey);
144
+ }
140
145
  const key = (0, utils_2.buildBelongsToLinkKey)(this.EntityClass, entityData.id, relMeta, foreignKey);
141
146
  this.#transactionBuilder.addPut({
142
147
  TableName: tableName,
@@ -151,8 +156,13 @@ class Create extends OperationBase_1.default {
151
156
  * Ensures referenced entities exist even when denormalised access patterns are not defined.
152
157
  *
153
158
  * @param entityData - Attributes being persisted for the new entity.
159
+ * @param referentialIntegrityCheck - Whether to perform referential integrity checks.
160
+ * @private
154
161
  */
155
- buildStandaloneForeignKeyConditionChecks(entityData) {
162
+ buildStandaloneForeignKeyConditionChecks(entityData, referentialIntegrityCheck) {
163
+ if (!referentialIntegrityCheck) {
164
+ return;
165
+ }
156
166
  const standaloneForeignKeys = this.entityMetadata.standaloneForeignKeyAttributes;
157
167
  for (const attrMeta of standaloneForeignKeys) {
158
168
  const target = attrMeta.foreignKeyTarget;
@@ -1,5 +1,17 @@
1
1
  import type DynaRecord from "../../DynaRecord";
2
2
  import type { EntityDefinedAttributes } from "../types";
3
+ /**
4
+ * Options for create operations
5
+ */
6
+ export interface CreateOperationOptions {
7
+ /**
8
+ * Whether to perform referential integrity checks for foreign key references.
9
+ * When `true` (default), condition checks are added to verify that referenced entities exist.
10
+ * When `false`, these condition checks are skipped, allowing creation even if foreign key references don't exist.
11
+ * @default true
12
+ */
13
+ referentialIntegrityCheck?: boolean;
14
+ }
3
15
  /**
4
16
  * Entity attribute fields that can be set on create. Excludes that are managed by dyna-record
5
17
  */