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.
package/README.md CHANGED
@@ -357,6 +357,25 @@ const grade: Grade = await Grade.create({
357
357
  });
358
358
  ```
359
359
 
360
+ #### Skipping Referential Integrity Checks
361
+
362
+ By default, when creating entities with foreign key references, dyna-record performs condition checks to ensure that referenced entities exist. This prevents creating entities with invalid foreign key references. However, in high-contention or high-throughput systems where the same foreign key may be referenced in parallel operations, these condition checks can fail due to transaction conflicts. In scenarios such as bulk imports or when you've already verified the references, you may want to skip these checks to prevent such failures.
363
+
364
+ To skip referential integrity checks, pass an options object as the second parameter with `referentialIntegrityCheck: false`:
365
+
366
+ ```typescript
367
+ const grade: Grade = await Grade.create(
368
+ {
369
+ gradeValue: "A+",
370
+ assignmentId: "123",
371
+ studentId: "456"
372
+ },
373
+ { referentialIntegrityCheck: false }
374
+ );
375
+ ```
376
+
377
+ **Note:** When `referentialIntegrityCheck` is set to `false`, the condition checks that verify foreign key references exist are skipped. This means you can create entities even if the referenced entities don't exist, which may lead to data integrity issues. Use this option with caution.
378
+
360
379
  #### Error handling
361
380
 
362
381
  The method is designed to throw errors under various conditions, such as transaction cancellation due to failed conditional checks. For instance, if you attempt to create a `Grade` for an `Assignment` that already has one, the method throws a [TransactionWriteFailedError](https://dyna-record.com/classes/TransactionWriteFailedError.html).
@@ -549,6 +568,31 @@ const updatedInstance = await petInstance.update({
549
568
  });
550
569
  ```
551
570
 
571
+ #### Skipping Referential Integrity Checks
572
+
573
+ By default, when updating entities with foreign key references, dyna-record performs condition checks to ensure that referenced entities exist. This prevents updating entities with invalid foreign key references. However, in high-contention or high-throughput systems where the same foreign key may be referenced in parallel operations, these condition checks can fail due to transaction conflicts. In scenarios such as bulk updates or when you've already verified the references, you may want to skip these checks to prevent such failures.
574
+
575
+ To skip referential integrity checks, pass an options object as the third parameter with `referentialIntegrityCheck: false`:
576
+
577
+ ```typescript
578
+ await PaymentMethod.update(
579
+ "123",
580
+ { customerId: "456" },
581
+ { referentialIntegrityCheck: false }
582
+ );
583
+ ```
584
+
585
+ For instance methods:
586
+
587
+ ```typescript
588
+ const updatedInstance = await paymentMethodInstance.update(
589
+ { customerId: "456" },
590
+ { referentialIntegrityCheck: false }
591
+ );
592
+ ```
593
+
594
+ **Note:** When `referentialIntegrityCheck` is set to `false`, the condition checks that verify foreign key references exist are skipped. This means you can update entities even if the referenced entities don't exist, which may lead to data integrity issues. Use this option with caution.
595
+
552
596
  ### Delete
553
597
 
554
598
  [Docs](https://dyna-record.com/classes/default.html#delete)
@@ -1,3 +1,4 @@
1
+ import { type TableMetadata } from "./metadata";
1
2
  import { type FindByIdOptions, type FindByIdIncludesRes, type EntityKeyConditions, type QueryResults, Create, type CreateOptions, type UpdateOptions, type EntityAttributesInstance, type IncludedAssociations, type IndexKeyConditions, type OptionsWithoutIndex, type OptionsWithIndex } from "./operations";
2
3
  import type { DynamoTableItem, EntityClass, Optional } from "./types";
3
4
  interface DynaRecordBase {
@@ -181,24 +182,36 @@ declare abstract class DynaRecord implements DynaRecordBase {
181
182
  */
182
183
  static query<T extends DynaRecord>(this: EntityClass<T>, key: IndexKeyConditions<T>, options: OptionsWithIndex): Promise<QueryResults<T>>;
183
184
  /**
184
- * Create an entity. If foreign keys are included in the attributes then links will be demoralized accordingly
185
+ * Create an entity. If foreign keys are included in the attributes then links will be denormalized accordingly
185
186
  * @param attributes - Attributes of the model to create
187
+ * @param options - Optional operation options including referentialIntegrityCheck flag
186
188
  * @returns The new Entity
187
189
  *
190
+ * @example Basic usage
188
191
  * ```typescript
189
192
  * const newUser = await User.create({ name: "Alice", email: "alice@example.com", profileId: "123" });
190
193
  * ```
194
+ *
195
+ * @example With referential integrity check disabled
196
+ * ```typescript
197
+ * const newUser = await User.create(
198
+ * { name: "Alice", email: "alice@example.com", profileId: "123" },
199
+ * { referentialIntegrityCheck: false }
200
+ * );
201
+ * ```
191
202
  */
192
- static create<T extends DynaRecord>(this: EntityClass<T>, attributes: CreateOptions<T>): Promise<ReturnType<Create<T>["run"]>>;
203
+ static create<T extends DynaRecord>(this: EntityClass<T>, attributes: CreateOptions<T>, options?: {
204
+ referentialIntegrityCheck?: boolean;
205
+ }): Promise<ReturnType<Create<T>["run"]>>;
193
206
  /**
194
- * Update an entity. If foreign keys are included in the attribute then:
207
+ * Update an entity. If foreign keys are included in the attributes then:
195
208
  * - Manages associated relationship links as needed
196
209
  * - If the entity already had a foreign key relationship, then denormalized records will be deleted from each partition
197
210
  * - If the foreign key is not nullable then a {@link NullConstraintViolationError} is thrown.
198
211
  * - Validation errors will be thrown if the attribute being removed is not nullable
199
212
  * @param id - The id of the entity to update
200
213
  * @param attributes - Attributes to update
201
- *
214
+ * @param options - Optional operation options including referentialIntegrityCheck flag
202
215
  *
203
216
  * @example Updating an entity.
204
217
  * ```typescript
@@ -209,12 +222,22 @@ declare abstract class DynaRecord implements DynaRecordBase {
209
222
  * ```typescript
210
223
  * await User.update("userId", { email: "newemail@example.com", someKey: null });
211
224
  * ```
225
+ *
226
+ * @example With referential integrity check disabled
227
+ * ```typescript
228
+ * await User.update(
229
+ * "userId",
230
+ * { email: "newemail@example.com", profileId: 789 },
231
+ * { referentialIntegrityCheck: false }
232
+ * );
233
+ * ```
212
234
  */
213
- static update<T extends DynaRecord>(this: EntityClass<T>, id: string, attributes: UpdateOptions<T>): Promise<void>;
235
+ static update<T extends DynaRecord>(this: EntityClass<T>, id: string, attributes: UpdateOptions<T>, options?: {
236
+ referentialIntegrityCheck?: boolean;
237
+ }): Promise<void>;
214
238
  /**
215
239
  * Same as the static `update` method but on an instance. Returns the full updated instance
216
240
  *
217
- *
218
241
  * @example Updating an entity.
219
242
  * ```typescript
220
243
  * const updatedInstance = await instance.update({ email: "newemail@example.com", profileId: 789 });
@@ -224,8 +247,18 @@ declare abstract class DynaRecord implements DynaRecordBase {
224
247
  * ```typescript
225
248
  * const updatedInstance = await instance.update({ email: "newemail@example.com", someKey: null });
226
249
  * ```
250
+ *
251
+ * @example With referential integrity check disabled
252
+ * ```typescript
253
+ * const updatedInstance = await instance.update(
254
+ * { email: "newemail@example.com", profileId: 789 },
255
+ * { referentialIntegrityCheck: false }
256
+ * );
257
+ * ```
227
258
  */
228
- update<T extends this>(attributes: UpdateOptions<T>): Promise<EntityAttributesInstance<T>>;
259
+ update<T extends this>(attributes: UpdateOptions<T>, options?: {
260
+ referentialIntegrityCheck?: boolean;
261
+ }): Promise<EntityAttributesInstance<T>>;
229
262
  /**
230
263
  * Delete an entity by ID
231
264
  * - Delete all denormalized records
@@ -258,6 +291,20 @@ declare abstract class DynaRecord implements DynaRecordBase {
258
291
  * @returns The partition key of the entity
259
292
  */
260
293
  partitionKeyValue(): string;
294
+ /**
295
+ * Returns serialized table metadata containing only serializable values.
296
+ * This method returns a plain object representation of the table metadata,
297
+ * with functions, class instances, and other non-serializable data converted
298
+ * to their string representations or omitted.
299
+ * @returns A plain object representation of the table metadata
300
+ *
301
+ * @example
302
+ * ```typescript
303
+ * const metadata = User.metadata();
304
+ * // Returns a serialized object with all metadata information
305
+ * ```
306
+ */
307
+ static metadata(): ReturnType<TableMetadata["toJSON"]>;
261
308
  }
262
309
  export default DynaRecord;
263
310
  //# sourceMappingURL=DynaRecord.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DynaRecord.d.ts","sourceRoot":"","sources":["../../src/DynaRecord.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EAExB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,MAAM,EACN,KAAK,aAAa,EAElB,KAAK,aAAa,EAGlB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAEtB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,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iB,IAAI,MAAM;IAIlC;;;;;;;;;;;;OAYG;WACW,QAAQ,IAAI,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;CAK9D;AAED,eAAe,UAAU,CAAC"}
@@ -145,27 +145,37 @@ let DynaRecord = (() => {
145
145
  return await op.run(key, options);
146
146
  }
147
147
  /**
148
- * Create an entity. If foreign keys are included in the attributes then links will be demoralized accordingly
148
+ * Create an entity. If foreign keys are included in the attributes then links will be denormalized accordingly
149
149
  * @param attributes - Attributes of the model to create
150
+ * @param options - Optional operation options including referentialIntegrityCheck flag
150
151
  * @returns The new Entity
151
152
  *
153
+ * @example Basic usage
152
154
  * ```typescript
153
155
  * const newUser = await User.create({ name: "Alice", email: "alice@example.com", profileId: "123" });
154
156
  * ```
157
+ *
158
+ * @example With referential integrity check disabled
159
+ * ```typescript
160
+ * const newUser = await User.create(
161
+ * { name: "Alice", email: "alice@example.com", profileId: "123" },
162
+ * { referentialIntegrityCheck: false }
163
+ * );
164
+ * ```
155
165
  */
156
- static async create(attributes) {
166
+ static async create(attributes, options) {
157
167
  const op = new operations_1.Create(this);
158
- return await op.run(attributes);
168
+ return await op.run(attributes, options);
159
169
  }
160
170
  /**
161
- * Update an entity. If foreign keys are included in the attribute then:
171
+ * Update an entity. If foreign keys are included in the attributes then:
162
172
  * - Manages associated relationship links as needed
163
173
  * - If the entity already had a foreign key relationship, then denormalized records will be deleted from each partition
164
174
  * - If the foreign key is not nullable then a {@link NullConstraintViolationError} is thrown.
165
175
  * - Validation errors will be thrown if the attribute being removed is not nullable
166
176
  * @param id - The id of the entity to update
167
177
  * @param attributes - Attributes to update
168
- *
178
+ * @param options - Optional operation options including referentialIntegrityCheck flag
169
179
  *
170
180
  * @example Updating an entity.
171
181
  * ```typescript
@@ -176,15 +186,23 @@ let DynaRecord = (() => {
176
186
  * ```typescript
177
187
  * await User.update("userId", { email: "newemail@example.com", someKey: null });
178
188
  * ```
189
+ *
190
+ * @example With referential integrity check disabled
191
+ * ```typescript
192
+ * await User.update(
193
+ * "userId",
194
+ * { email: "newemail@example.com", profileId: 789 },
195
+ * { referentialIntegrityCheck: false }
196
+ * );
197
+ * ```
179
198
  */
180
- static async update(id, attributes) {
199
+ static async update(id, attributes, options) {
181
200
  const op = new operations_1.Update(this);
182
- await op.run(id, attributes);
201
+ await op.run(id, attributes, options);
183
202
  }
184
203
  /**
185
204
  * Same as the static `update` method but on an instance. Returns the full updated instance
186
205
  *
187
- *
188
206
  * @example Updating an entity.
189
207
  * ```typescript
190
208
  * const updatedInstance = await instance.update({ email: "newemail@example.com", profileId: 789 });
@@ -194,11 +212,19 @@ let DynaRecord = (() => {
194
212
  * ```typescript
195
213
  * const updatedInstance = await instance.update({ email: "newemail@example.com", someKey: null });
196
214
  * ```
215
+ *
216
+ * @example With referential integrity check disabled
217
+ * ```typescript
218
+ * const updatedInstance = await instance.update(
219
+ * { email: "newemail@example.com", profileId: 789 },
220
+ * { referentialIntegrityCheck: false }
221
+ * );
222
+ * ```
197
223
  */
198
- async update(attributes) {
224
+ async update(attributes, options) {
199
225
  const InstanceClass = this.constructor;
200
226
  const op = new operations_1.Update(InstanceClass);
201
- const updatedAttributes = await op.run(this.id, attributes);
227
+ const updatedAttributes = await op.run(this.id, attributes, options);
202
228
  const clone = structuredClone(this);
203
229
  // Update the current instance with new attributes
204
230
  Object.assign(clone, updatedAttributes);
@@ -253,6 +279,24 @@ let DynaRecord = (() => {
253
279
  partitionKeyValue() {
254
280
  return this.constructor.partitionKeyValue(this.id);
255
281
  }
282
+ /**
283
+ * Returns serialized table metadata containing only serializable values.
284
+ * This method returns a plain object representation of the table metadata,
285
+ * with functions, class instances, and other non-serializable data converted
286
+ * to their string representations or omitted.
287
+ * @returns A plain object representation of the table metadata
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * const metadata = User.metadata();
292
+ * // Returns a serialized object with all metadata information
293
+ * ```
294
+ */
295
+ static metadata() {
296
+ const tableMetadata = metadata_1.default.getTable(this.name);
297
+ const entities = metadata_1.default.getEntitiesForTable(this.name);
298
+ return tableMetadata.toJSON(entities);
299
+ }
256
300
  constructor() {
257
301
  __runInitializers(this, _updatedAt_extraInitializers);
258
302
  }
@@ -4,7 +4,7 @@ import TableMetadata from "./TableMetadata";
4
4
  import EntityMetadata from "./EntityMetadata";
5
5
  import JoinTableMetadata from "./JoinTableMetadata";
6
6
  import type { RelationshipMetadata } from "./relationship-metadata";
7
- import type { AttributeMetadataStorage, TableMetadataOptions, AttributeMetadataOptions } from "./types";
7
+ import type { AttributeMetadataStorage, EntityMetadataStorage, TableMetadataOptions, AttributeMetadataOptions } from "./types";
8
8
  /**
9
9
  * Central storage for managing and accessing all metadata related to entities, attributes, relationships, and tables within the ORM.
10
10
  * It provides methods for retrieving and adding metadata for entities and their corresponding tables, handling relationships
@@ -36,6 +36,12 @@ declare class MetadataStorage {
36
36
  * @returns joinTableName metadata
37
37
  */
38
38
  getJoinTable(joinTableName: string): JoinTableMetadata[];
39
+ /**
40
+ * Returns all entities that belong to a specific table
41
+ * @param {string} tableClassName - Name of the table class
42
+ * @returns Record of entity metadata keyed by entity class name
43
+ */
44
+ getEntitiesForTable(tableClassName: string): EntityMetadataStorage;
39
45
  /**
40
46
  * Returns attribute metadata for attributes defined keyed by entity key
41
47
  * @returns - {@link AttributeMetadataStorage}
@@ -1 +1 @@
1
- {"version":3,"file":"MetadataStorage.d.ts","sourceRoot":"","sources":["../../../src/metadata/MetadataStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,KAAK,EACV,wBAAwB,EAIxB,oBAAo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ACI,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,IAAI;IAI5E;;;;OAIG;IACI,SAAS,CACd,WAAW,EAAE,cAAc,CAAC,aAAa,CAAC,EAC1C,cAAc,EAAE,MAAM,GACrB,IAAI;IAOP;;;;OAIG;IACI,qBAAqB,CAC1B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,oBAAoB,GAC5B,IAAI;IAQP;;;;OAIG;IACI,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI;IAa5E;;;;OAIG;IACI,kBAAkB,CACvB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,YAAY,CAAC,wBAAwB,EAAE,OAAO,CAAC,GACvD,IAAI;IAYP;;;;OAIG;IACI,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAKpE;;;;OAIG;IACI,wBAAwB,CAC7B,WAAW,EAAE,UAAU,EACvB,OAAO,EAAE,UAAU,CAAC,aAAa,CAAC,0BAA0B,CAAC,CAAC,CAAC,MAAM,CAAC,GACrE,IAAI;IAQP;;;;OAIG;IACI,mBAAmB,CACxB,WAAW,EAAE,UAAU,EACvB,OAAO,EAAE,UAAU,CAAC,aAAa,CAAC,0BAA0B,CAAC,CAAC,CAAC,MAAM,CAAC,GACrE,IAAI;IAQP;;OAEG;IACH,OAAO,CAAC,IAAI;IAUZ;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;CAa/B;AAED,eAAe,eAAe,CAAC"}
@@ -55,6 +55,21 @@ class MetadataStorage {
55
55
  this.init();
56
56
  return this.#joinTables[joinTableName];
57
57
  }
58
+ /**
59
+ * Returns all entities that belong to a specific table
60
+ * @param {string} tableClassName - Name of the table class
61
+ * @returns Record of entity metadata keyed by entity class name
62
+ */
63
+ getEntitiesForTable(tableClassName) {
64
+ this.init();
65
+ const entities = {};
66
+ for (const [entityName, entityMetadata] of Object.entries(this.#entities)) {
67
+ if (entityMetadata.tableClassName === tableClassName) {
68
+ entities[entityName] = entityMetadata;
69
+ }
70
+ }
71
+ return entities;
72
+ }
58
73
  /**
59
74
  * Returns attribute metadata for attributes defined keyed by entity key
60
75
  * @returns - {@link AttributeMetadataStorage}
@@ -1,5 +1,6 @@
1
1
  import { AttributeMetadata } from ".";
2
- import type { TableMetadataOptions, DefaultFields, KeysAttributeMetadataOptions } from "./types";
2
+ import type { TableMetadataOptions, DefaultFields, KeysAttributeMetadataOptions, EntityMetadataStorage } from "./types";
3
+ import { type SerializedTableMetadata } from "./schemas";
3
4
  export declare const defaultTableKeys: {
4
5
  readonly partitionKey: "PK";
5
6
  readonly sortKey: "SK";
@@ -66,6 +67,13 @@ declare class TableMetadata {
66
67
  * @param options
67
68
  */
68
69
  addSortKeyAttribute(options: KeysAttributeMetadataOptions): void;
70
+ /**
71
+ * Serializes the table metadata to a plain object containing only serializable values.
72
+ * This removes functions, Zod types, serializers, and other non-serializable data.
73
+ * @param {EntityMetadataStorage} entities - Entities that belong to this table, keyed by entity class name
74
+ * @returns A plain object representation of the metadata
75
+ */
76
+ toJSON(entities: EntityMetadataStorage): SerializedTableMetadata;
69
77
  }
70
78
  export default TableMetadata;
71
79
  //# sourceMappingURL=TableMetadata.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TableMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/TableMetadata.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEtC,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EAGb,4BAA4B,EAC7B,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,gBAAgB;;;CAAiD,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CACrC,aAAa,EACb;IAAE,KAAK,EAAE,aAAa,CAAA;CAAE,CAMhB,CAAC;AAEX;;;;;;;;;;;;;GAaG;AACH,cAAM,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CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;IAC5E,SAAgB,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACnE,qBAAqB,EAAE,iBAAiB,CAAC;IACzC,gBAAgB,EAAE,iBAAiB,CAAC;IAE3C;;;;;;;;;;;;;;;;OAgBG;IACI,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAE9B,OAAO,EAAE,oBAAoB;IA4BzC;;;;OAIG;IACH,OAAO,CAAC,8BAA8B;IAgCtC;;;OAGG;IACI,wBAAwB,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI;IAO5E;;;OAGG;IACI,mBAAmB,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI;IAOvE;;;;;OAKG;IACI,MAAM,CAAC,QAAQ,EAAE,qBAAqB,GAAG,uBAAuB;CAMxE;AAED,eAAe,aAAa,CAAC"}
@@ -4,6 +4,7 @@ exports.tableDefaultFields = exports.defaultTableKeys = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const _1 = require(".");
6
6
  const decorators_1 = require("../decorators");
7
+ const schemas_1 = require("./schemas");
7
8
  exports.defaultTableKeys = { partitionKey: "PK", sortKey: "SK" };
8
9
  /**
9
10
  * Default fields with default table alias. Can be overwritten through {@link TableMetadataOptions} defaultFields
@@ -121,5 +122,17 @@ class TableMetadata {
121
122
  // Set the user defined primary key as reserved key so that its managed by dyna-record
122
123
  this.reservedKeys[options.attributeName] = true;
123
124
  }
125
+ /**
126
+ * Serializes the table metadata to a plain object containing only serializable values.
127
+ * This removes functions, Zod types, serializers, and other non-serializable data.
128
+ * @param {EntityMetadataStorage} entities - Entities that belong to this table, keyed by entity class name
129
+ * @returns A plain object representation of the metadata
130
+ */
131
+ toJSON(entities) {
132
+ return schemas_1.TableMetadataTransform.parse({
133
+ ...this,
134
+ entities
135
+ });
136
+ }
124
137
  }
125
138
  exports.default = TableMetadata;