dyna-record 0.4.1 → 0.4.7
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/src/DynaRecord.d.ts +15 -0
- package/dist/src/DynaRecord.d.ts.map +1 -1
- package/dist/src/DynaRecord.js +18 -0
- package/dist/src/metadata/MetadataStorage.d.ts +7 -1
- package/dist/src/metadata/MetadataStorage.d.ts.map +1 -1
- package/dist/src/metadata/MetadataStorage.js +15 -0
- package/dist/src/metadata/TableMetadata.d.ts +9 -1
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/TableMetadata.js +13 -0
- package/dist/src/metadata/schemas.d.ts +432 -0
- package/dist/src/metadata/schemas.d.ts.map +1 -0
- package/dist/src/metadata/schemas.js +121 -0
- package/dist/src/operations/FindById/types.d.ts +1 -1
- package/dist/src/operations/FindById/types.d.ts.map +1 -1
- package/package.json +4 -2
package/dist/src/DynaRecord.d.ts
CHANGED
|
@@ -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 {
|
|
@@ -290,6 +291,20 @@ declare abstract class DynaRecord implements DynaRecordBase {
|
|
|
290
291
|
* @returns The partition key of the entity
|
|
291
292
|
*/
|
|
292
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"]>;
|
|
293
308
|
}
|
|
294
309
|
export default DynaRecord;
|
|
295
310
|
//# sourceMappingURL=DynaRecord.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynaRecord.d.ts","sourceRoot":"","sources":["../../src/DynaRecord.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DynaRecord.d.ts","sourceRoot":"","sources":["../../src/DynaRecord.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAsB,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAE9E,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,CAAC;AAGtE,UAAU,cAAc;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,uBAAe,UAAW,YAAW,cAAc;IACjD;;OAEG;IACH,SACgB,EAAE,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,SACgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,SACgB,SAAS,EAAE,IAAI,CAAC;IAEhC;;OAEG;IACH,SACgB,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AC,EACjB,SAAS,EAAE,eAAe,GACzB,wBAAwB,CAAC,CAAC,CAAC;IAW9B;;;OAGG;IACI,iBAAiB,IAAI,MAAM;IAIlC;;;;;;;;;;;;OAYG;WACW,QAAQ,IAAI,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;CAK9D;AAED,eAAe,UAAU,CAAC"}
|
package/dist/src/DynaRecord.js
CHANGED
|
@@ -279,6 +279,24 @@ let DynaRecord = (() => {
|
|
|
279
279
|
partitionKeyValue() {
|
|
280
280
|
return this.constructor.partitionKeyValue(this.id);
|
|
281
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
|
+
}
|
|
282
300
|
constructor() {
|
|
283
301
|
__runInitializers(this, _updatedAt_extraInitializers);
|
|
284
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,
|
|
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;AA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AgB,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,
|
|
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,EAC5B,qBAAqB,EACtB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,KAAK,uBAAuB,EAE7B,MAAM,WAAW,CAAC;AAEnB,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,aAAa;IACjB,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,iBAAiB,EAAE,MAAM,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;
|
|
@@ -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
|
+
});
|
|
@@ -40,7 +40,7 @@ type IncludedKeys<T extends DynaRecord, Inc extends IncludedAssociations<T> = []
|
|
|
40
40
|
* entity attributes with included associations.
|
|
41
41
|
*/
|
|
42
42
|
type EntityKeysWithIncludedAssociations<T extends DynaRecord, P extends keyof T> = {
|
|
43
|
-
[K in P]: T[K] extends DynaRecord ? EntityAttributesOnly<T> : T[K] extends DynaRecord[] ? Array<EntityAttributesOnly<T[K][number]>> : T[K];
|
|
43
|
+
[K in P]: T[K] extends DynaRecord ? EntityAttributesOnly<T[K]> : T[K] extends DynaRecord[] ? Array<EntityAttributesOnly<T[K][number]>> : T[K];
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
46
|
* The result type for a FindById operation that includes associations.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/FindById/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EACV,oBAAoB,EACpB,cAAc,EACd,0BAA0B,EAC3B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,UAAU,IAAI,KAAK,CAAC;IAC7D,WAAW,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAC;CAC5C,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAC9B,CAAC,SAAS,UAAU,EACpB,GAAG,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,EAAE;IAExC,OAAO,CAAC,EAAE,GAAG,CAAC;IACd;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC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AAC,UAAU,CAAC,CAAC;IACjC,eAAe,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;CAC3C;AAED;;GAEG;AACH,KAAK,YAAY,CACf,CAAC,SAAS,UAAU,EACpB,GAAG,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,EAAE,IACtC,GAAG,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC;AAE/B;;;GAGG;AACH,KAAK,kCAAkC,CACrC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,MAAM,CAAC,IACf;KACD,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GAC7B,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1B,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,EAAE,GACvB,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GACzC,CAAC,CAAC,CAAC,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,CAC7B,CAAC,SAAS,UAAU,EACpB,GAAG,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,EAAE,IACtC,kCAAkC,CACpC,CAAC,EACD,MAAM,oBAAoB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CACzE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dyna-record",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "Typescript Data Modeler and ORM for Dynamo",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"watch": "tsc -w",
|
|
10
|
-
"
|
|
10
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.dev.json --noEmit",
|
|
11
|
+
"typecheck:tests": "tsc -p tsconfig.dev.json --noEmit",
|
|
12
|
+
"test": "tsc -p tsconfig.dev.json --noEmit && jest",
|
|
11
13
|
"test:watch": "jest --watch",
|
|
12
14
|
"eslint": "npx eslint . --ext .ts",
|
|
13
15
|
"eslint:fix": "npx eslint . --ext .ts --fix",
|