dyna-record 0.6.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -7
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -22
- package/dist/src/DynaRecord.d.ts +3 -3
- package/dist/src/DynaRecord.d.ts.map +1 -1
- package/dist/src/DynaRecord.js +24 -59
- package/dist/src/Logger.js +1 -3
- package/dist/src/decorators/Entity.d.ts +1 -1
- package/dist/src/decorators/Entity.d.ts.map +1 -1
- package/dist/src/decorators/Entity.js +3 -8
- package/dist/src/decorators/Table.d.ts +2 -2
- package/dist/src/decorators/Table.d.ts.map +1 -1
- package/dist/src/decorators/Table.js +3 -8
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/BooleanAttribute.js +6 -10
- package/dist/src/decorators/attributes/DateAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/DateAttribute.js +8 -12
- package/dist/src/decorators/attributes/EnumAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/EnumAttribute.js +7 -10
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ForeignKeyAttribute.js +6 -10
- package/dist/src/decorators/attributes/IdAttribute.d.ts +1 -1
- package/dist/src/decorators/attributes/IdAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/IdAttribute.js +3 -8
- package/dist/src/decorators/attributes/NumberAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/NumberAttribute.js +6 -10
- package/dist/src/decorators/attributes/ObjectAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/ObjectAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ObjectAttribute.js +17 -21
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/PartitionKeyAttribute.js +6 -10
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/SortKeyAttribute.js +6 -10
- package/dist/src/decorators/attributes/StringAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/StringAttribute.js +6 -10
- package/dist/src/decorators/attributes/index.d.ts +13 -13
- package/dist/src/decorators/attributes/index.d.ts.map +1 -1
- package/dist/src/decorators/attributes/index.js +11 -41
- package/dist/src/decorators/attributes/serializers.d.ts +2 -2
- package/dist/src/decorators/attributes/serializers.d.ts.map +1 -1
- package/dist/src/decorators/attributes/serializers.js +5 -12
- package/dist/src/decorators/attributes/types.js +1 -2
- package/dist/src/decorators/index.d.ts +5 -5
- package/dist/src/decorators/index.d.ts.map +1 -1
- package/dist/src/decorators/index.js +5 -27
- package/dist/src/decorators/relationships/BelongsTo.d.ts +4 -4
- package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -1
- package/dist/src/decorators/relationships/BelongsTo.js +3 -8
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts +3 -3
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasAndBelongsToMany.js +4 -9
- package/dist/src/decorators/relationships/HasMany.d.ts +3 -3
- package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasMany.js +4 -9
- package/dist/src/decorators/relationships/HasOne.d.ts +3 -3
- package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasOne.js +3 -8
- package/dist/src/decorators/relationships/index.d.ts +5 -5
- package/dist/src/decorators/relationships/index.d.ts.map +1 -1
- package/dist/src/decorators/relationships/index.js +5 -29
- package/dist/src/decorators/relationships/types.d.ts +3 -3
- package/dist/src/decorators/relationships/types.d.ts.map +1 -1
- package/dist/src/decorators/relationships/types.js +1 -2
- package/dist/src/decorators/types.d.ts +3 -3
- package/dist/src/decorators/types.d.ts.map +1 -1
- package/dist/src/decorators/types.js +1 -2
- package/dist/src/dynamo-utils/DynamoClient.d.ts +1 -1
- package/dist/src/dynamo-utils/DynamoClient.d.ts.map +1 -1
- package/dist/src/dynamo-utils/DynamoClient.js +13 -18
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts +1 -1
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts.map +1 -1
- package/dist/src/dynamo-utils/TransactGetBuilder.js +5 -10
- package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts +1 -1
- package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts.map +1 -1
- package/dist/src/dynamo-utils/TransactWriteBuilder.js +11 -16
- package/dist/src/dynamo-utils/errors.js +2 -7
- package/dist/src/dynamo-utils/index.d.ts +7 -7
- package/dist/src/dynamo-utils/index.d.ts.map +1 -1
- package/dist/src/dynamo-utils/index.js +7 -30
- package/dist/src/dynamo-utils/types.js +1 -2
- package/dist/src/errors.js +3 -9
- package/dist/src/id.d.ts +12 -0
- package/dist/src/id.d.ts.map +1 -0
- package/dist/src/id.js +11 -0
- package/dist/src/index.d.ts +8 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -20
- package/dist/src/metadata/AttributeMetadata.d.ts +6 -4
- package/dist/src/metadata/AttributeMetadata.d.ts.map +1 -1
- package/dist/src/metadata/AttributeMetadata.js +5 -3
- package/dist/src/metadata/EntityMetadata.d.ts +3 -3
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
- package/dist/src/metadata/EntityMetadata.js +18 -23
- package/dist/src/metadata/JoinTableMetadata.d.ts +3 -3
- package/dist/src/metadata/JoinTableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/JoinTableMetadata.js +1 -3
- package/dist/src/metadata/MetadataStorage.d.ts +7 -7
- package/dist/src/metadata/MetadataStorage.d.ts.map +1 -1
- package/dist/src/metadata/MetadataStorage.js +12 -17
- package/dist/src/metadata/TableMetadata.d.ts +3 -3
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/TableMetadata.js +22 -21
- package/dist/src/metadata/index.d.ts +9 -9
- package/dist/src/metadata/index.d.ts.map +1 -1
- package/dist/src/metadata/index.js +11 -34
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts +1 -1
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.js +1 -3
- package/dist/src/metadata/relationship-metadata/index.d.ts +6 -6
- package/dist/src/metadata/relationship-metadata/index.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/index.js +7 -31
- package/dist/src/metadata/relationship-metadata/types.d.ts +5 -5
- package/dist/src/metadata/relationship-metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/types.js +1 -2
- package/dist/src/metadata/relationship-metadata/utils.d.ts +1 -1
- package/dist/src/metadata/relationship-metadata/utils.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/utils.js +11 -18
- package/dist/src/metadata/schemas.d.ts +523 -36
- package/dist/src/metadata/schemas.d.ts.map +1 -1
- package/dist/src/metadata/schemas.js +71 -44
- package/dist/src/metadata/types.d.ts +17 -4
- package/dist/src/metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/types.js +1 -2
- package/dist/src/metadata/utils.d.ts +5 -5
- package/dist/src/metadata/utils.d.ts.map +1 -1
- package/dist/src/metadata/utils.js +14 -29
- package/dist/src/operations/Create/Create.d.ts +5 -5
- package/dist/src/operations/Create/Create.d.ts.map +1 -1
- package/dist/src/operations/Create/Create.js +18 -23
- package/dist/src/operations/Create/index.d.ts +2 -2
- package/dist/src/operations/Create/index.d.ts.map +1 -1
- package/dist/src/operations/Create/index.js +2 -23
- package/dist/src/operations/Create/types.d.ts +2 -2
- package/dist/src/operations/Create/types.d.ts.map +1 -1
- package/dist/src/operations/Create/types.js +1 -2
- package/dist/src/operations/Delete/Delete.d.ts +3 -3
- package/dist/src/operations/Delete/Delete.d.ts.map +1 -1
- package/dist/src/operations/Delete/Delete.js +28 -33
- package/dist/src/operations/Delete/index.d.ts +1 -1
- package/dist/src/operations/Delete/index.d.ts.map +1 -1
- package/dist/src/operations/Delete/index.js +1 -8
- package/dist/src/operations/Delete/types.js +1 -2
- package/dist/src/operations/FindById/FindById.d.ts +4 -4
- package/dist/src/operations/FindById/FindById.d.ts.map +1 -1
- package/dist/src/operations/FindById/FindById.js +17 -22
- package/dist/src/operations/FindById/index.d.ts +2 -2
- package/dist/src/operations/FindById/index.d.ts.map +1 -1
- package/dist/src/operations/FindById/index.js +2 -23
- package/dist/src/operations/FindById/types.d.ts +3 -3
- package/dist/src/operations/FindById/types.d.ts.map +1 -1
- package/dist/src/operations/FindById/types.js +1 -2
- package/dist/src/operations/OperationBase.d.ts +3 -3
- package/dist/src/operations/OperationBase.d.ts.map +1 -1
- package/dist/src/operations/OperationBase.js +4 -9
- package/dist/src/operations/Query/Query.d.ts +4 -4
- package/dist/src/operations/Query/Query.d.ts.map +1 -1
- package/dist/src/operations/Query/Query.js +15 -20
- package/dist/src/operations/Query/index.d.ts +2 -2
- package/dist/src/operations/Query/index.d.ts.map +1 -1
- package/dist/src/operations/Query/index.js +2 -23
- package/dist/src/operations/Query/types.d.ts +4 -4
- package/dist/src/operations/Query/types.d.ts.map +1 -1
- package/dist/src/operations/Query/types.js +1 -2
- package/dist/src/operations/Update/Update.d.ts +5 -5
- package/dist/src/operations/Update/Update.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.js +37 -42
- package/dist/src/operations/Update/UpdateDryRun.d.ts +2 -2
- package/dist/src/operations/Update/UpdateDryRun.d.ts.map +1 -1
- package/dist/src/operations/Update/UpdateDryRun.js +3 -8
- package/dist/src/operations/Update/index.d.ts +3 -3
- package/dist/src/operations/Update/index.d.ts.map +1 -1
- package/dist/src/operations/Update/index.js +3 -25
- package/dist/src/operations/Update/types.d.ts +2 -2
- package/dist/src/operations/Update/types.d.ts.map +1 -1
- package/dist/src/operations/Update/types.js +1 -2
- package/dist/src/operations/index.d.ts +6 -6
- package/dist/src/operations/index.d.ts.map +1 -1
- package/dist/src/operations/index.js +6 -22
- package/dist/src/operations/types.d.ts +3 -3
- package/dist/src/operations/types.d.ts.map +1 -1
- package/dist/src/operations/types.js +1 -2
- package/dist/src/operations/utils/expressionBuilder.d.ts +2 -2
- package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -1
- package/dist/src/operations/utils/expressionBuilder.js +1 -5
- package/dist/src/operations/utils/flattenObjectForUpdate.d.ts +2 -2
- package/dist/src/operations/utils/flattenObjectForUpdate.d.ts.map +1 -1
- package/dist/src/operations/utils/flattenObjectForUpdate.js +3 -6
- package/dist/src/operations/utils/index.d.ts +5 -5
- package/dist/src/operations/utils/index.d.ts.map +1 -1
- package/dist/src/operations/utils/index.js +5 -21
- package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts +1 -1
- package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts.map +1 -1
- package/dist/src/operations/utils/mergePartialObjectAttributes.js +1 -4
- package/dist/src/operations/utils/types.js +1 -2
- package/dist/src/operations/utils/utils.d.ts +4 -4
- package/dist/src/operations/utils/utils.d.ts.map +1 -1
- package/dist/src/operations/utils/utils.js +13 -23
- package/dist/src/query-utils/Filters.d.ts +2 -2
- package/dist/src/query-utils/Filters.d.ts.map +1 -1
- package/dist/src/query-utils/Filters.js +1 -4
- package/dist/src/query-utils/QueryBuilder.d.ts +1 -1
- package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -1
- package/dist/src/query-utils/QueryBuilder.js +8 -13
- package/dist/src/query-utils/index.d.ts +2 -2
- package/dist/src/query-utils/index.d.ts.map +1 -1
- package/dist/src/query-utils/index.js +2 -23
- package/dist/src/query-utils/types.js +1 -2
- package/dist/src/relationships/JoinTable.d.ts +2 -2
- package/dist/src/relationships/JoinTable.d.ts.map +1 -1
- package/dist/src/relationships/JoinTable.js +14 -19
- package/dist/src/relationships/index.d.ts +1 -1
- package/dist/src/relationships/index.d.ts.map +1 -1
- package/dist/src/relationships/index.js +1 -8
- package/dist/src/types.d.ts +2 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +1 -2
- package/dist/src/utils.d.ts +3 -3
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +16 -31
- package/package.json +28 -24
|
@@ -1,34 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Common serialized fields shared by every attribute kind.
|
|
4
|
+
*/
|
|
5
|
+
const baseAttributeShape = {
|
|
6
|
+
name: z.string(),
|
|
7
|
+
alias: z.string(),
|
|
8
|
+
nullable: z.boolean()
|
|
9
|
+
};
|
|
10
|
+
const simpleAttributeShape = (kind) => z.object({ ...baseAttributeShape, kind: z.literal(kind) });
|
|
5
11
|
/**
|
|
6
12
|
* 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
13
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
+
* Emits a discriminated union keyed on `kind`. Every attribute carries
|
|
15
|
+
* `{ name, alias, nullable, kind }`; some kinds carry an additional payload:
|
|
14
16
|
*
|
|
15
|
-
*
|
|
17
|
+
* - `kind: "enum"` → `values: readonly [string, ...string[]]`
|
|
18
|
+
* - `kind: "object"` → `schema: ObjectSchema` (the user-authored schema)
|
|
19
|
+
* - `kind: "foreignKey"` → `foreignKeyTarget: string` (target entity class name)
|
|
20
|
+
*
|
|
21
|
+
* Non-serializable internals (Zod types, serializers, partial types) are dropped.
|
|
16
22
|
*/
|
|
17
|
-
const AttributeMetadataTransform =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
nullable: attr.nullable,
|
|
28
|
-
...(attr.foreignKeyTarget != null && {
|
|
29
|
-
foreignKeyTarget: attr.foreignKeyTarget.name
|
|
23
|
+
const AttributeMetadataTransform = z.discriminatedUnion("kind", [
|
|
24
|
+
simpleAttributeShape("string"),
|
|
25
|
+
simpleAttributeShape("number"),
|
|
26
|
+
simpleAttributeShape("boolean"),
|
|
27
|
+
simpleAttributeShape("date"),
|
|
28
|
+
z
|
|
29
|
+
.object({
|
|
30
|
+
...baseAttributeShape,
|
|
31
|
+
kind: z.literal("enum"),
|
|
32
|
+
enumValues: z.array(z.string()).nonempty()
|
|
30
33
|
})
|
|
31
|
-
})
|
|
34
|
+
.transform(({ enumValues, ...rest }) => ({
|
|
35
|
+
...rest,
|
|
36
|
+
values: enumValues
|
|
37
|
+
})),
|
|
38
|
+
z
|
|
39
|
+
.object({
|
|
40
|
+
...baseAttributeShape,
|
|
41
|
+
kind: z.literal("object"),
|
|
42
|
+
objectSchema: z.custom()
|
|
43
|
+
})
|
|
44
|
+
.transform(({ objectSchema, ...rest }) => ({
|
|
45
|
+
...rest,
|
|
46
|
+
schema: objectSchema
|
|
47
|
+
})),
|
|
48
|
+
z
|
|
49
|
+
.object({
|
|
50
|
+
...baseAttributeShape,
|
|
51
|
+
kind: z.literal("foreignKey"),
|
|
52
|
+
foreignKeyTarget: z.custom()
|
|
53
|
+
})
|
|
54
|
+
.transform(({ foreignKeyTarget, ...rest }) => ({
|
|
55
|
+
...rest,
|
|
56
|
+
foreignKeyTarget: foreignKeyTarget.name
|
|
57
|
+
}))
|
|
58
|
+
]);
|
|
32
59
|
/**
|
|
33
60
|
* Zod schema that transforms relationship metadata to a serializable format.
|
|
34
61
|
* Extracts serializable properties and converts EntityClass references to their class name strings.
|
|
@@ -42,14 +69,14 @@ const AttributeMetadataTransform = zod_1.z
|
|
|
42
69
|
*
|
|
43
70
|
* @returns A serialized relationship metadata object with EntityClass references converted to strings
|
|
44
71
|
*/
|
|
45
|
-
const RelationshipMetadataTransform =
|
|
72
|
+
const RelationshipMetadataTransform = z
|
|
46
73
|
.object({
|
|
47
|
-
type:
|
|
48
|
-
propertyName:
|
|
49
|
-
target:
|
|
50
|
-
foreignKey:
|
|
51
|
-
joinTableName:
|
|
52
|
-
uniDirectional:
|
|
74
|
+
type: z.string(),
|
|
75
|
+
propertyName: z.string(),
|
|
76
|
+
target: z.custom().optional(),
|
|
77
|
+
foreignKey: z.string().optional(),
|
|
78
|
+
joinTableName: z.string().optional(),
|
|
79
|
+
uniDirectional: z.boolean().optional()
|
|
53
80
|
})
|
|
54
81
|
.transform(rel => ({
|
|
55
82
|
type: rel.type,
|
|
@@ -73,13 +100,13 @@ const RelationshipMetadataTransform = zod_1.z
|
|
|
73
100
|
*
|
|
74
101
|
* @returns A serialized entity metadata object with all nested metadata transformed
|
|
75
102
|
*/
|
|
76
|
-
const EntityMetadataTransform =
|
|
103
|
+
const EntityMetadataTransform = z
|
|
77
104
|
.object({
|
|
78
|
-
tableClassName:
|
|
79
|
-
attributes:
|
|
80
|
-
tableAttributes:
|
|
81
|
-
relationships:
|
|
82
|
-
idField:
|
|
105
|
+
tableClassName: z.string(),
|
|
106
|
+
attributes: z.record(z.string(), AttributeMetadataTransform),
|
|
107
|
+
tableAttributes: z.record(z.string(), AttributeMetadataTransform),
|
|
108
|
+
relationships: z.record(z.string(), RelationshipMetadataTransform),
|
|
109
|
+
idField: z.string().optional()
|
|
83
110
|
})
|
|
84
111
|
.transform(entity => ({
|
|
85
112
|
tableClassName: entity.tableClassName,
|
|
@@ -110,12 +137,12 @@ const EntityMetadataTransform = zod_1.z
|
|
|
110
137
|
* // Returns a plain object with all EntityClass references converted to strings
|
|
111
138
|
* ```
|
|
112
139
|
*/
|
|
113
|
-
|
|
114
|
-
name:
|
|
115
|
-
delimiter:
|
|
116
|
-
defaultAttributes:
|
|
117
|
-
defaultTableAttributes:
|
|
140
|
+
export const TableMetadataTransform = z.object({
|
|
141
|
+
name: z.string(),
|
|
142
|
+
delimiter: z.string(),
|
|
143
|
+
defaultAttributes: z.record(z.string(), AttributeMetadataTransform),
|
|
144
|
+
defaultTableAttributes: z.record(z.string(), AttributeMetadataTransform),
|
|
118
145
|
partitionKeyAttribute: AttributeMetadataTransform,
|
|
119
146
|
sortKeyAttribute: AttributeMetadataTransform,
|
|
120
|
-
entities:
|
|
147
|
+
entities: z.record(z.string(), EntityMetadataTransform)
|
|
121
148
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { NativeAttributeValue } from "@aws-sdk/util-dynamodb";
|
|
2
|
-
import type { AttributeMetadata, BelongsToRelationship, EntityMetadata, JoinTableMetadata, OwnedByRelationship, RelationshipMetadata, TableMetadata } from ".";
|
|
3
|
-
import type DynaRecord from "../DynaRecord";
|
|
4
|
-
import type { EntityClass, MakeOptional } from "../types";
|
|
2
|
+
import type { AttributeMetadata, BelongsToRelationship, EntityMetadata, JoinTableMetadata, OwnedByRelationship, RelationshipMetadata, TableMetadata } from "./index.js";
|
|
3
|
+
import type DynaRecord from "../DynaRecord.js";
|
|
4
|
+
import type { EntityClass, MakeOptional } from "../types.js";
|
|
5
5
|
import type { ZodType } from "zod";
|
|
6
|
-
import type { ObjectSchema } from "../decorators/attributes/types";
|
|
6
|
+
import type { ObjectSchema } from "../decorators/attributes/types.js";
|
|
7
7
|
/**
|
|
8
8
|
* Represents relationship metadata that includes a foreign key reference to another entity.
|
|
9
9
|
*/
|
|
@@ -81,6 +81,13 @@ export interface Serializers {
|
|
|
81
81
|
*/
|
|
82
82
|
toTableAttribute: TableSerializer;
|
|
83
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Discriminator identifying which `@…Attribute` decorator produced an
|
|
86
|
+
* {@link AttributeMetadata} record. Exposed in the serialized metadata
|
|
87
|
+
* returned by `DynaRecord.metadata()` so consumers can switch on the
|
|
88
|
+
* attribute's logical type.
|
|
89
|
+
*/
|
|
90
|
+
export type AttributeKind = "string" | "number" | "boolean" | "date" | "enum" | "object" | "foreignKey";
|
|
84
91
|
/**
|
|
85
92
|
* Defines the options for configuring attribute metadata within the ORM system. This interface specifies the settings used to describe and manage an attribute's representation and behavior in both the entity model and the underlying database schema, particularly focusing on attributes' names, aliases, nullability, and serialization strategies.
|
|
86
93
|
*
|
|
@@ -91,10 +98,16 @@ export interface Serializers {
|
|
|
91
98
|
*/
|
|
92
99
|
export interface AttributeMetadataOptions {
|
|
93
100
|
attributeName: string;
|
|
101
|
+
kind: AttributeKind;
|
|
94
102
|
type: ZodType;
|
|
95
103
|
alias?: string;
|
|
96
104
|
nullable?: boolean;
|
|
97
105
|
serializers?: Serializers;
|
|
106
|
+
/**
|
|
107
|
+
* For `kind: "enum"` attributes, the allowed string values. Forwarded to
|
|
108
|
+
* the serialized metadata so consumers can introspect the enum domain.
|
|
109
|
+
*/
|
|
110
|
+
enumValues?: readonly [string, ...string[]];
|
|
98
111
|
/**
|
|
99
112
|
* When the attribute represents a foreign key, this references the target entity class.
|
|
100
113
|
* Used to enforce referential integrity even when a relationship decorator is not present.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/metadata/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACd,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/metadata/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACd,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK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MAAM,WAAW,2BAA4B,SAAQ,iBAAiB;IACpE,gBAAgB,EAAE,WAAW,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,CAAC;CACtE"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { RelationshipMetadata, HasManyRelationship, BelongsToRelationship, HasOneRelationship, HasAndBelongsToManyRelationship, OwnedByRelationship, ForeignKeyAttributeMetadata } from ".";
|
|
2
|
-
import type DynaRecord from "../DynaRecord";
|
|
3
|
-
import type { BelongsToOrOwnedByRelationship, RelationshipMetadataWithForeignKey } from "./types";
|
|
4
|
-
import type { EntityClass } from "../types";
|
|
5
|
-
import type AttributeMetadata from "./AttributeMetadata";
|
|
1
|
+
import type { RelationshipMetadata, HasManyRelationship, BelongsToRelationship, HasOneRelationship, HasAndBelongsToManyRelationship, OwnedByRelationship, ForeignKeyAttributeMetadata } from "./index.js";
|
|
2
|
+
import type DynaRecord from "../DynaRecord.js";
|
|
3
|
+
import type { BelongsToOrOwnedByRelationship, RelationshipMetadataWithForeignKey } from "./types.js";
|
|
4
|
+
import type { EntityClass } from "../types.js";
|
|
5
|
+
import type AttributeMetadata from "./AttributeMetadata.js";
|
|
6
6
|
/**
|
|
7
7
|
* Type guard to check if the relationship is a HasMany
|
|
8
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/metadata/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,+BAA+B,EAC/B,mBAAmB,EACnB,2BAA2B,EAC5B,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/metadata/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oB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AA8B,KAClC,OAMF,CAAC"}
|
|
@@ -1,73 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.doesEntityBelongToRelAsHasMany = exports.doesEntityBelongToRelAsHasOne = exports.isForeignKeyAttributeMetadata = exports.isRelationshipMetadataWithForeignKey = exports.isOwnedByRelationship = exports.isHasAndBelongsToManyRelationship = exports.isHasOneRelationship = exports.isBelongsToRelationship = exports.isHasManyRelationship = void 0;
|
|
7
|
-
const _1 = __importDefault(require("./"));
|
|
1
|
+
import Metadata from "./index.js";
|
|
8
2
|
/**
|
|
9
3
|
* Type guard to check if the relationship is a HasMany
|
|
10
4
|
*/
|
|
11
|
-
const isHasManyRelationship = (rel) => {
|
|
5
|
+
export const isHasManyRelationship = (rel) => {
|
|
12
6
|
return rel.type === "HasMany" && "foreignKey" in rel;
|
|
13
7
|
};
|
|
14
|
-
exports.isHasManyRelationship = isHasManyRelationship;
|
|
15
8
|
/**
|
|
16
9
|
* Type guard to check if the relationship is a BelongsTo
|
|
17
10
|
*/
|
|
18
|
-
const isBelongsToRelationship = (rel) => {
|
|
11
|
+
export const isBelongsToRelationship = (rel) => {
|
|
19
12
|
return rel.type === "BelongsTo" && "foreignKey" in rel;
|
|
20
13
|
};
|
|
21
|
-
exports.isBelongsToRelationship = isBelongsToRelationship;
|
|
22
14
|
/**
|
|
23
15
|
* Type guard to check if the relationship is a HasOne
|
|
24
16
|
*/
|
|
25
|
-
const isHasOneRelationship = (rel) => {
|
|
17
|
+
export const isHasOneRelationship = (rel) => {
|
|
26
18
|
return rel.type === "HasOne" && "foreignKey" in rel;
|
|
27
19
|
};
|
|
28
|
-
exports.isHasOneRelationship = isHasOneRelationship;
|
|
29
20
|
/**
|
|
30
21
|
* Type guard to check if the relationship is a HasOne
|
|
31
22
|
*/
|
|
32
|
-
const isHasAndBelongsToManyRelationship = (rel) => {
|
|
23
|
+
export const isHasAndBelongsToManyRelationship = (rel) => {
|
|
33
24
|
return rel.type === "HasAndBelongsToMany" && "joinTableName" in rel;
|
|
34
25
|
};
|
|
35
|
-
exports.isHasAndBelongsToManyRelationship = isHasAndBelongsToManyRelationship;
|
|
36
26
|
/**
|
|
37
27
|
* Type guard to check if the relationship is of type OwnedBy
|
|
38
28
|
*/
|
|
39
|
-
const isOwnedByRelationship = (rel) => {
|
|
29
|
+
export const isOwnedByRelationship = (rel) => {
|
|
40
30
|
return rel.type === "OwnedBy";
|
|
41
31
|
};
|
|
42
|
-
exports.isOwnedByRelationship = isOwnedByRelationship;
|
|
43
32
|
/**
|
|
44
33
|
* Type guard to check if the relationship metadata includes a foreignKey
|
|
45
34
|
* @param rel
|
|
46
35
|
* @returns
|
|
47
36
|
*/
|
|
48
|
-
const isRelationshipMetadataWithForeignKey = (rel) => {
|
|
37
|
+
export const isRelationshipMetadataWithForeignKey = (rel) => {
|
|
49
38
|
return "foreignKey" in rel;
|
|
50
39
|
};
|
|
51
|
-
exports.isRelationshipMetadataWithForeignKey = isRelationshipMetadataWithForeignKey;
|
|
52
40
|
/**
|
|
53
41
|
* Type guard that checks whether attribute metadata represents a foreign key.
|
|
54
42
|
* Returns {@link ForeignKeyAttributeMetadata} with a guaranteed target entity.
|
|
55
43
|
*/
|
|
56
|
-
const isForeignKeyAttributeMetadata = (attr) => {
|
|
44
|
+
export const isForeignKeyAttributeMetadata = (attr) => {
|
|
57
45
|
return attr.foreignKeyTarget !== undefined;
|
|
58
46
|
};
|
|
59
|
-
exports.isForeignKeyAttributeMetadata = isForeignKeyAttributeMetadata;
|
|
60
47
|
/**
|
|
61
48
|
* Returns true if an "Entity" BelongsTo the provided relationship as a HasOne
|
|
62
49
|
* @param Entity
|
|
63
50
|
* @param rel
|
|
64
51
|
* @returns
|
|
65
52
|
*/
|
|
66
|
-
const doesEntityBelongToRelAsHasOne = (Entity, rel) => {
|
|
67
|
-
const relMetadata =
|
|
68
|
-
return Object.values(relMetadata.relationships).some(rel =>
|
|
53
|
+
export const doesEntityBelongToRelAsHasOne = (Entity, rel) => {
|
|
54
|
+
const relMetadata = Metadata.getEntity(rel.target.name);
|
|
55
|
+
return Object.values(relMetadata.relationships).some(rel => isHasOneRelationship(rel) && rel.target === Entity);
|
|
69
56
|
};
|
|
70
|
-
exports.doesEntityBelongToRelAsHasOne = doesEntityBelongToRelAsHasOne;
|
|
71
57
|
/**
|
|
72
58
|
* Returns true if an "Entity" BelongsTo the provided relationship as a HasMany
|
|
73
59
|
* @param Entity
|
|
@@ -75,8 +61,7 @@ exports.doesEntityBelongToRelAsHasOne = doesEntityBelongToRelAsHasOne;
|
|
|
75
61
|
* @param foreignKey
|
|
76
62
|
* @returns
|
|
77
63
|
*/
|
|
78
|
-
const doesEntityBelongToRelAsHasMany = (Entity, rel) => {
|
|
79
|
-
const relMetadata =
|
|
80
|
-
return Object.values(relMetadata.relationships).some(rel =>
|
|
64
|
+
export const doesEntityBelongToRelAsHasMany = (Entity, rel) => {
|
|
65
|
+
const relMetadata = Metadata.getEntity(rel.target.name);
|
|
66
|
+
return Object.values(relMetadata.relationships).some(rel => isHasManyRelationship(rel) && rel.target === Entity);
|
|
81
67
|
};
|
|
82
|
-
exports.doesEntityBelongToRelAsHasMany = doesEntityBelongToRelAsHasMany;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type DynaRecord from "../../DynaRecord";
|
|
2
|
-
import type { EntityClass } from "../../types";
|
|
3
|
-
import OperationBase from "../OperationBase";
|
|
4
|
-
import type { CreateOptions, CreateOperationOptions } from "./types";
|
|
5
|
-
import { type EntityAttributesOnly } from "../types";
|
|
1
|
+
import type DynaRecord from "../../DynaRecord.js";
|
|
2
|
+
import type { EntityClass } from "../../types.js";
|
|
3
|
+
import OperationBase from "../OperationBase.js";
|
|
4
|
+
import type { CreateOptions, CreateOperationOptions } from "./types.js";
|
|
5
|
+
import { type EntityAttributesOnly } from "../types.js";
|
|
6
6
|
/**
|
|
7
7
|
* Represents an operation to create a new entity record in DynamoDB, including all necessary
|
|
8
8
|
* denormalized relationship records. This ensures that "BelongsTo" and "HasMany" relationships
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAElD,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAOnE,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAKhD,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAC;AAIrB;;;;;;;;;;;;;;;;;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"}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const dynamo_utils_1 = require("../../dynamo-utils");
|
|
8
|
-
const utils_1 = require("../../utils");
|
|
9
|
-
const OperationBase_1 = __importDefault(require("../OperationBase"));
|
|
10
|
-
const utils_2 = require("../utils");
|
|
11
|
-
const utils_3 = require("../../metadata/utils");
|
|
1
|
+
import { generateId } from "../../id.js";
|
|
2
|
+
import { TransactGetBuilder, TransactWriteBuilder } from "../../dynamo-utils/index.js";
|
|
3
|
+
import { entityToTableItem, isString, tableItemToEntity } from "../../utils.js";
|
|
4
|
+
import OperationBase from "../OperationBase.js";
|
|
5
|
+
import { extractForeignKeyFromEntity, buildBelongsToLinkKey } from "../utils/index.js";
|
|
6
|
+
import { isBelongsToRelationship } from "../../metadata/utils.js";
|
|
12
7
|
/**
|
|
13
8
|
* Represents an operation to create a new entity record in DynamoDB, including all necessary
|
|
14
9
|
* denormalized relationship records. This ensures that "BelongsTo" and "HasMany" relationships
|
|
@@ -27,11 +22,11 @@ const utils_3 = require("../../metadata/utils");
|
|
|
27
22
|
*
|
|
28
23
|
* @template T - The type of the entity being created, extending `DynaRecord`.
|
|
29
24
|
*/
|
|
30
|
-
class Create extends
|
|
25
|
+
class Create extends OperationBase {
|
|
31
26
|
#transactionBuilder;
|
|
32
27
|
constructor(Entity) {
|
|
33
28
|
super(Entity);
|
|
34
|
-
this.#transactionBuilder = new
|
|
29
|
+
this.#transactionBuilder = new TransactWriteBuilder();
|
|
35
30
|
}
|
|
36
31
|
/**
|
|
37
32
|
* Executes the create operation.
|
|
@@ -56,7 +51,7 @@ class Create extends OperationBase_1.default {
|
|
|
56
51
|
const entityAttrs = this.entityMetadata.parseRawEntityDefinedAttributes(attributes);
|
|
57
52
|
const reservedAttrs = this.buildReservedAttributes(entityAttrs);
|
|
58
53
|
const entityData = { ...reservedAttrs, ...entityAttrs };
|
|
59
|
-
const tableItem =
|
|
54
|
+
const tableItem = entityToTableItem(this.EntityClass, entityData);
|
|
60
55
|
this.buildPutItemTransaction(tableItem, entityData.id);
|
|
61
56
|
this.buildBelongsToTransactions(entityData, tableItem, referentialIntegrityCheck);
|
|
62
57
|
this.buildStandaloneForeignKeyConditionChecks(entityData, referentialIntegrityCheck);
|
|
@@ -67,7 +62,7 @@ class Create extends OperationBase_1.default {
|
|
|
67
62
|
this.buildAddBelongsToLinkToSelfTransactions(reservedAttrs.id, belongsToTableItems);
|
|
68
63
|
}
|
|
69
64
|
await this.#transactionBuilder.executeTransaction();
|
|
70
|
-
return
|
|
65
|
+
return tableItemToEntity(this.EntityClass, tableItem);
|
|
71
66
|
}
|
|
72
67
|
/**
|
|
73
68
|
* Builds and returns entity attributes that must be reserved for system usage.
|
|
@@ -84,7 +79,7 @@ class Create extends OperationBase_1.default {
|
|
|
84
79
|
buildReservedAttributes(entityAttrs) {
|
|
85
80
|
const { idField } = this.entityMetadata;
|
|
86
81
|
const id = idField === undefined
|
|
87
|
-
? (
|
|
82
|
+
? generateId()
|
|
88
83
|
: entityAttrs[idField];
|
|
89
84
|
const createdAt = new Date();
|
|
90
85
|
const pk = this.tableMetadata.partitionKeyAttribute.name;
|
|
@@ -136,13 +131,13 @@ class Create extends OperationBase_1.default {
|
|
|
136
131
|
const tableName = this.tableMetadata.name;
|
|
137
132
|
const relMetadata = this.entityMetadata.belongsToOrOwnedByRelationships;
|
|
138
133
|
for (const relMeta of relMetadata) {
|
|
139
|
-
const foreignKey =
|
|
134
|
+
const foreignKey = extractForeignKeyFromEntity(relMeta, entityData);
|
|
140
135
|
if (foreignKey != null) {
|
|
141
136
|
// Ensure referenced entity exists before linking
|
|
142
137
|
if (referentialIntegrityCheck) {
|
|
143
138
|
this.buildRelationshipExistsConditionTransaction(relMeta, foreignKey);
|
|
144
139
|
}
|
|
145
|
-
const key =
|
|
140
|
+
const key = buildBelongsToLinkKey(this.EntityClass, entityData.id, relMeta, foreignKey);
|
|
146
141
|
this.#transactionBuilder.addPut({
|
|
147
142
|
TableName: tableName,
|
|
148
143
|
Item: { ...tableItem, ...key },
|
|
@@ -167,7 +162,7 @@ class Create extends OperationBase_1.default {
|
|
|
167
162
|
for (const attrMeta of standaloneForeignKeys) {
|
|
168
163
|
const target = attrMeta.foreignKeyTarget;
|
|
169
164
|
const foreignKeyValue = entityData[attrMeta.name];
|
|
170
|
-
if (!
|
|
165
|
+
if (!isString(foreignKeyValue))
|
|
171
166
|
continue;
|
|
172
167
|
const foreignKey = foreignKeyValue;
|
|
173
168
|
const errMsg = `${target.name} with ID '${foreignKey}' does not exist`;
|
|
@@ -196,11 +191,11 @@ class Create extends OperationBase_1.default {
|
|
|
196
191
|
*/
|
|
197
192
|
async getBelongsToTableItems(entityData) {
|
|
198
193
|
const { name: tableName } = this.tableMetadata;
|
|
199
|
-
const transactionBuilder = new
|
|
194
|
+
const transactionBuilder = new TransactGetBuilder();
|
|
200
195
|
const relMetas = this.entityMetadata.relationships;
|
|
201
|
-
const belongsToRelMetas = Object.values(relMetas).filter(relMeta =>
|
|
196
|
+
const belongsToRelMetas = Object.values(relMetas).filter(relMeta => isBelongsToRelationship(relMeta));
|
|
202
197
|
belongsToRelMetas.forEach(relMeta => {
|
|
203
|
-
const fk =
|
|
198
|
+
const fk = extractForeignKeyFromEntity(relMeta, entityData);
|
|
204
199
|
if (fk != null) {
|
|
205
200
|
transactionBuilder.addGet({
|
|
206
201
|
TableName: tableName,
|
|
@@ -274,4 +269,4 @@ class Create extends OperationBase_1.default {
|
|
|
274
269
|
});
|
|
275
270
|
}
|
|
276
271
|
}
|
|
277
|
-
|
|
272
|
+
export default Create;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default as Create } from "./Create";
|
|
2
|
-
export * from "./types";
|
|
1
|
+
export { default as Create } from "./Create.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,cAAc,YAAY,CAAC"}
|
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.Create = void 0;
|
|
21
|
-
var Create_1 = require("./Create");
|
|
22
|
-
Object.defineProperty(exports, "Create", { enumerable: true, get: function () { return __importDefault(Create_1).default; } });
|
|
23
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
export { default as Create } from "./Create.js";
|
|
2
|
+
export * from "./types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,UAAU,IAAI,uBAAuB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type DynaRecord from "../../DynaRecord";
|
|
2
|
-
import type { EntityClass } from "../../types";
|
|
3
|
-
import OperationBase from "../OperationBase";
|
|
1
|
+
import type DynaRecord from "../../DynaRecord.js";
|
|
2
|
+
import type { EntityClass } from "../../types.js";
|
|
3
|
+
import OperationBase from "../OperationBase.js";
|
|
4
4
|
/**
|
|
5
5
|
* Implements the operation for deleting an entity and its related data from the database within the ORM framework.
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Delete.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/Delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"Delete.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/Delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAYlD,OAAO,KAAK,EAEV,WAAW,EAEZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,aAAa,MAAM,qBAAqB,CAAC;AA2BhD;;;;;;;;;GASG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAS7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAiBlC;;;;;;;OAOG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgC3C;;;;OAIG;YACW,QAAQ;IAiCtB;;;;OAIG;IACH,OAAO,CAAC,iCAAiC;IASzC;;;OAGG;IACH,OAAO,CAAC,2BAA2B;IAOnC;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAalC;;;OAGG;IACH,OAAO,CAAC,4BAA4B;IAkBpC;;;;OAIG;YACW,iCAAiC;IA2B/C;;;;OAIG;IACH,OAAO,CAAC,uCAAuC;IAyB/C;;;OAGG;IACH,OAAO,CAAC,mCAAmC;IAiB3C;;;OAGG;IACH,OAAO,CAAC,+BAA+B;IAqBvC;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,cAAc;CAcvB;AAED,eAAe,MAAM,CAAC"}
|