@aws-amplify/data-schema 0.14.14 → 0.15.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/lib-esm/src/ClientSchema.d.ts +8 -14
- package/lib-esm/src/ClientSchema.d.ts.map +1 -1
- package/lib-esm/src/MappedTypes/ModelMetadata.d.ts +1 -1
- package/lib-esm/src/MappedTypes/ModelMetadata.d.ts.map +1 -1
- package/lib-esm/src/MappedTypes/ResolveFieldProperties.d.ts +7 -13
- package/lib-esm/src/MappedTypes/ResolveFieldProperties.d.ts.map +1 -1
- package/lib-esm/src/ModelRelationalField.d.ts +8 -29
- package/lib-esm/src/ModelRelationalField.d.ts.map +1 -1
- package/lib-esm/src/ModelRelationalField.js +13 -38
- package/lib-esm/src/SchemaProcessor.d.ts.map +1 -1
- package/lib-esm/src/SchemaProcessor.js +2 -133
- package/lib-esm/src/index.d.ts +2 -2
- package/lib-esm/src/index.d.ts.map +1 -1
- package/lib-esm/src/index.js +1 -2
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/lib-esm/src/MappedTypes/ForeignKeys.d.ts +0 -84
- package/lib-esm/src/MappedTypes/ForeignKeys.d.ts.map +0 -1
- package/lib-esm/src/MappedTypes/ForeignKeys.js +0 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { __modelMeta__ } from '@aws-amplify/data-schema-types';
|
|
2
|
+
import type { GenericModelSchema, RDSModelSchema } from './ModelSchema';
|
|
3
3
|
import type { ResolveSchema, SchemaTypes } from './MappedTypes/ResolveSchema';
|
|
4
|
-
import type {
|
|
4
|
+
import type { ResolveFieldProperties, ResolveStaticFieldProperties } from './MappedTypes/ResolveFieldProperties';
|
|
5
5
|
import type { ModelIdentifier, ModelSecondaryIndexes, RelationalMetadata } from './MappedTypes/ModelMetadata';
|
|
6
6
|
import type { ExtractNonModelTypes, NonModelTypesShape } from './MappedTypes/ExtractNonModelTypes';
|
|
7
|
-
import { ResolveCustomOperations, CustomOperationHandlerTypes } from './MappedTypes/CustomOperations';
|
|
8
|
-
import { CombinedModelSchema, CombinedSchemaIndexesUnion } from './CombineSchema';
|
|
9
|
-
import { SpreadTuple } from './util';
|
|
7
|
+
import type { ResolveCustomOperations, CustomOperationHandlerTypes } from './MappedTypes/CustomOperations';
|
|
8
|
+
import type { CombinedModelSchema, CombinedSchemaIndexesUnion } from './CombineSchema';
|
|
9
|
+
import type { SpreadTuple } from './util';
|
|
10
10
|
export type ClientSchema<Schema extends GenericModelSchema<any> | CombinedModelSchema<any>> = Schema extends GenericModelSchema<any> ? InternalClientSchema<Schema> : Schema extends CombinedModelSchema<any> ? InternalCombinedSchema<Schema> : never;
|
|
11
11
|
/**
|
|
12
12
|
* Types for unwrapping generic type args into client-consumable types
|
|
@@ -18,18 +18,12 @@ export type ClientSchema<Schema extends GenericModelSchema<any> | CombinedModelS
|
|
|
18
18
|
*
|
|
19
19
|
* @internal @typeParam NonModelTypes - Custom Types, Enums, and Custom Operations
|
|
20
20
|
* @internal @typeParam ResolvedSchema - Resolve the schema types used by other generics
|
|
21
|
-
* @internal @typeParam ImplicitModels - The implicit models created to represent relationships
|
|
22
|
-
* @internal @typeParam ImplicitModelsIdentifierMeta - The implicite model identifiers derived from ImplicitModels
|
|
23
21
|
* @internal @typeParam ResolvedFields - Resolved client-facing types used for CRUDL response shapes
|
|
24
22
|
* @internal @typeParam IdentifierMeta - Resolve the identifier fields for all models
|
|
25
23
|
* @internal @typeParam SecondaryIndexes - Map of model secondary index metadata
|
|
26
24
|
*/
|
|
27
|
-
type InternalClientSchema<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape = ExtractNonModelTypes<Schema>, ResolvedSchema = ResolveSchema<Schema>,
|
|
28
|
-
[
|
|
29
|
-
identifier: 'id';
|
|
30
|
-
};
|
|
31
|
-
}, ResolvedFields extends Record<string, unknown> = Schema extends RDSModelSchema<any, any> ? ResolveStaticFieldProperties<Schema, NonModelTypes, object> : ResolveFieldProperties<Schema, NonModelTypes, ImplicitModels>, IdentifierMeta extends Record<string, any> = ModelIdentifier<SchemaTypes<Schema>>, SecondaryIndexes extends Record<string, any> = Schema extends RDSModelSchema<any, any> ? object : ModelSecondaryIndexes<SchemaTypes<Schema>>> = CustomOperationHandlerTypes<ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>['customOperations']> & ResolvedFields & {
|
|
32
|
-
[__modelMeta__]: IdentifierMeta & ImplicitModelsIdentifierMeta & SecondaryIndexes & RelationalMetadata<ResolvedSchema, ResolvedFields, IdentifierMeta> & NonModelTypes & ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>;
|
|
25
|
+
type InternalClientSchema<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape = ExtractNonModelTypes<Schema>, ResolvedSchema = ResolveSchema<Schema>, ResolvedFields extends Record<string, unknown> = Schema extends RDSModelSchema<any, any> ? ResolveStaticFieldProperties<Schema, NonModelTypes, object> : ResolveFieldProperties<Schema, NonModelTypes>, IdentifierMeta extends Record<string, any> = ModelIdentifier<SchemaTypes<Schema>>, SecondaryIndexes extends Record<string, any> = Schema extends RDSModelSchema<any, any> ? object : ModelSecondaryIndexes<SchemaTypes<Schema>>> = CustomOperationHandlerTypes<ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>['customOperations']> & ResolvedFields & {
|
|
26
|
+
[__modelMeta__]: IdentifierMeta & SecondaryIndexes & RelationalMetadata<ResolvedSchema, ResolvedFields, IdentifierMeta> & NonModelTypes & ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>;
|
|
33
27
|
};
|
|
34
28
|
type GetInternalClientSchema<Schema> = Schema extends GenericModelSchema<any> ? InternalClientSchema<Schema> : never;
|
|
35
29
|
type CombinedClientSchemas<Schemas extends CombinedModelSchema<any>['schemas']> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientSchema.d.ts","sourceRoot":"","sources":["../../src/ClientSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ClientSchema.d.ts","sourceRoot":"","sources":["../../src/ClientSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGxE,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EACV,sBAAsB,EACtB,4BAA4B,EAC7B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EACV,uBAAuB,EACvB,2BAA2B,EAC5B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,mBAAmB,EACnB,0BAA0B,EAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1C,MAAM,MAAM,YAAY,CACtB,MAAM,SAAS,kBAAkB,CAAC,GAAG,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,IAEjE,MAAM,SAAS,kBAAkB,CAAC,GAAG,CAAC,GAClC,oBAAoB,CAAC,MAAM,CAAC,GAC5B,MAAM,SAAS,mBAAmB,CAAC,GAAG,CAAC,GACrC,sBAAsB,CAAC,MAAM,CAAC,GAC9B,KAAK,CAAC;AAEd;;;;;;;;;;;;;GAaG;AACH,KAAK,oBAAoB,CACvB,MAAM,SAAS,kBAAkB,CAAC,GAAG,CAAC,EACtC,aAAa,SAAS,kBAAkB,GAAG,oBAAoB,CAAC,MAAM,CAAC,EACvE,cAAc,GAAG,aAAa,CAAC,MAAM,CA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AAa,SAAS,CAAC,GAAG,GAAG,CAAC,GAAG,qBAAqB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,IACzE,WAAW,CAAC;KACb,CAAC,IAAI,MAAM,aAAa,GAAG,CAAC,SAAS,0BAA0B,GAC5D,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,aAAa,CAAC,GAC5C,KAAK;CACV,CAAC,GAAG;IACH,CAAC,aAAa,CAAC,EAAE,WAAW,CAAC;SAC1B,CAAC,IAAI,MAAM,aAAa,GAAG,CAAC,SAAS,0BAA0B,GAC5D,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,aAAa,CAAC,GACtC,KAAK;KACV,CAAC,CAAC;CACJ,CAAC"}
|
|
@@ -13,7 +13,7 @@ export type ModelSecondaryIndexes<T> = {
|
|
|
13
13
|
};
|
|
14
14
|
export type RelationalMetadata<ResolvedSchema, ResolvedFields extends Record<string, unknown>, IdentifierMeta extends Record<string, any>> = UnionToIntersection<ExcludeEmpty<{
|
|
15
15
|
[ModelName in keyof ResolvedSchema]: {
|
|
16
|
-
[Field in keyof ResolvedSchema[ModelName] as ResolvedSchema[ModelName][Field] extends ModelRelationalFieldParamShape ? ResolvedSchema[ModelName][Field]['relationshipType'] extends 'hasOne' | 'belongsTo' ? ModelName :
|
|
16
|
+
[Field in keyof ResolvedSchema[ModelName] as ResolvedSchema[ModelName][Field] extends ModelRelationalFieldParamShape ? ResolvedSchema[ModelName][Field]['relationshipType'] extends 'hasOne' | 'belongsTo' ? ModelName : never : never]: ResolvedSchema[ModelName][Field] extends ModelRelationalFieldParamShape ? ResolvedSchema[ModelName][Field] extends ModelRelationalFieldParamShape ? ResolvedSchema[ModelName][Field]['relationshipType'] extends 'hasMany' ? {
|
|
17
17
|
relationalInputFields: Partial<Record<`${Uncapitalize<ModelName & string>}`, NormalizeInputFields<ResolvedFields[ModelName & string], ExtractModelIdentifier<ModelName, IdentifierMeta>>>>;
|
|
18
18
|
} : {
|
|
19
19
|
relationalInputFields: Partial<Record<Field, NormalizeInputFields<ResolvedFields[ResolvedSchema[ModelName][Field]['relatedModel']], ExtractModelIdentifier<`${Capitalize<Field & string>}`, IdentifierMeta>>>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelMetadata.d.ts","sourceRoot":"","sources":["../../../src/MappedTypes/ModelMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAElB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAE9E,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;KAC9B,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,GAE9D,CAAC,CAAC,YAAY,CAAC,SAAS,GAAG,EAAE,GAC3B;QAAE,UAAU,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;KAAE,GACvC,KAAK,GACP,KAAK;CACV,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAAC,CAAC,IAAI;KACpC,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,GAE9D,CAAC,CAAC,kBAAkB,CAAC,SAAS,GAAG,EAAE,GACjC;QAAE,gBAAgB,EAAE,CAAC,CAAC,kBAAkB,CAAC,CAAA;KAAE,GAC3C,KAAK,GACP,KAAK;CACV,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAC5B,cAAc,EACd,cAAc,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9C,cAAc,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IACxC,mBAAmB,CACrB,YAAY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M,cAAc,GAAG,cAAc,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;AAE7E,KAAK,oBAAoB,CACvB,WAAW,EACX,cAAc,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IACxC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,GAC1D,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { UnionToIntersection, LazyLoader
|
|
1
|
+
import type { UnionToIntersection, LazyLoader } from '@aws-amplify/data-schema-types';
|
|
2
2
|
import type { Authorization, ImpliedAuthFields } from '../Authorization';
|
|
3
3
|
import type { ModelField } from '../ModelField';
|
|
4
4
|
import type { ModelType, ModelTypeParamShape } from '../ModelType';
|
|
5
5
|
import type { GenericModelSchema } from '../ModelSchema';
|
|
6
|
-
import type { ModelRelationalField, ModelRelationalFieldParamShape
|
|
7
|
-
import type { AllImpliedFKs } from './ForeignKeys';
|
|
6
|
+
import type { ModelRelationalField, ModelRelationalFieldParamShape } from '../ModelRelationalField';
|
|
8
7
|
import type { ResolveSchema, SchemaTypes } from './ResolveSchema';
|
|
9
8
|
import type { InjectImplicitModelFields } from './ImplicitFieldInjector';
|
|
10
9
|
import type { ModelIdentifier } from './ModelMetadata';
|
|
@@ -13,15 +12,10 @@ import type { NonModelTypesShape } from './ExtractNonModelTypes';
|
|
|
13
12
|
import type { CustomType, CustomTypeParamShape } from '../CustomType';
|
|
14
13
|
import type { EnumType, EnumTypeParamShape } from '../EnumType';
|
|
15
14
|
import type { CustomOperation, CustomOperationParamShape } from '../CustomOperation';
|
|
16
|
-
export type ResolveFieldProperties<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape,
|
|
15
|
+
export type ResolveFieldProperties<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape, ResolvedSchema = ResolveSchema<Schema>, IdentifierMeta extends Record<string, {
|
|
17
16
|
identifier: string;
|
|
18
|
-
}> = ModelIdentifier<SchemaTypes<Schema>>, FieldsWithInjectedImplicitFields = InjectImplicitModelFields<ResolvedSchema
|
|
19
|
-
export type ResolveStaticFieldProperties<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape, ImplicitModelsSchema, ResolvedSchema = ResolveSchema<Schema>, FieldsWithInjectedImplicitFields = InjectImplicitModelFields<ResolvedSchema & ImplicitModelsSchema, object>, FieldsWithRelationships =
|
|
20
|
-
export type CreateImplicitModelsFromRelations<Schema> = UnionToIntersection<ExcludeEmpty<{
|
|
21
|
-
[ModelProp in keyof Schema]: {
|
|
22
|
-
[FieldProp in keyof Schema[ModelProp] as Schema[ModelProp][FieldProp] extends ModelRelationalFieldParamShape ? Schema[ModelProp][FieldProp]['relationName'] extends string ? Schema[ModelProp][FieldProp]['relationName'] extends keyof Schema ? never : Schema[ModelProp][FieldProp]['relationName'] : never : never]: Record<`${Lowercase<ModelProp & string>}`, ModelRelationalTypeArgFactory<ModelProp & string, ModelRelationshipTypes.hasMany, false>>;
|
|
23
|
-
};
|
|
24
|
-
}[keyof Schema]>>;
|
|
17
|
+
}> = ModelIdentifier<SchemaTypes<Schema>>, FieldsWithInjectedImplicitFields = InjectImplicitModelFields<ResolvedSchema, IdentifierMeta>, FieldsWithRelationships = ResolveModelsRelationalAndRefFields<FieldsWithInjectedImplicitFields, NonModelTypes>> = Intersection<FilterFieldTypes<MarkModelsNonNullableFieldsRequired<FieldsWithRelationships>>, FilterFieldTypes<MarkModelsNullableFieldsOptional<FieldsWithRelationships>>, FilterFieldTypes<ModelImpliedAuthFields<Schema>>>;
|
|
18
|
+
export type ResolveStaticFieldProperties<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape, ImplicitModelsSchema, ResolvedSchema = ResolveSchema<Schema>, FieldsWithInjectedImplicitFields = InjectImplicitModelFields<ResolvedSchema & ImplicitModelsSchema, object>, FieldsWithRelationships = ResolveModelsRelationalAndRefFields<FieldsWithInjectedImplicitFields, NonModelTypes>> = Intersection<FilterFieldTypes<MarkModelsNonNullableFieldsRequired<FieldsWithRelationships>>, FilterFieldTypes<MarkModelsNullableFieldsOptional<FieldsWithRelationships>>>;
|
|
25
19
|
type GetRelationshipRef<T, RM extends keyof T, TypeArg extends ModelRelationalFieldParamShape, Flat extends boolean, ResolvedModel = ResolveRelationalFieldsForModel<T, RM, Flat>, Model = TypeArg['valueRequired'] extends true ? ResolvedModel : ResolvedModel | null | undefined> = LazyLoader<Model, TypeArg['array']>;
|
|
26
20
|
type ResolveRelationalFieldsForModel<Schema, ModelName extends keyof Schema, Flat extends boolean> = {
|
|
27
21
|
[FieldName in keyof Schema[ModelName]]: Schema[ModelName][FieldName] extends ModelRelationalFieldParamShape ? Schema[ModelName][FieldName]['relatedModel'] extends keyof Schema ? GetRelationshipRef<Schema, Schema[ModelName][FieldName]['relatedModel'], Schema[ModelName][FieldName], Flat> : never : Schema[ModelName][FieldName];
|
|
@@ -36,9 +30,9 @@ export type ResolveRefsOfCustomType<NonModelTypes extends NonModelTypesShape, T>
|
|
|
36
30
|
[Prop in keyof T]: T[Prop] extends RefType<infer R extends RefTypeParamShape, any, any> | null ? ResolveRef<NonModelTypes, R> : T[Prop];
|
|
37
31
|
} extends infer Resolved ? ResolveCustomTypeFieldsRequirements<Resolved> : never;
|
|
38
32
|
export type ResolveCustomTypeFieldsRequirements<Resolved> = Intersection<ExtractNullableFieldsToOptionalFields<Resolved>, ExtractNonNullableFieldsToRequiredFields<Resolved>>;
|
|
39
|
-
type
|
|
33
|
+
type ResolveModelsRelationalAndRefFields<Schema, NonModelTypes extends NonModelTypesShape, Flat extends boolean = false> = {
|
|
40
34
|
[ModelProp in keyof Schema]: {
|
|
41
|
-
[FieldProp in keyof Schema[ModelProp]]: Schema[ModelProp][FieldProp] extends RefType<infer R extends RefTypeParamShape, any, any> | null ? ResolveRef<NonModelTypes, R> : Schema[ModelProp][FieldProp] extends ModelRelationalFieldParamShape ? Schema[ModelProp][FieldProp]['relatedModel'] extends keyof Schema ?
|
|
35
|
+
[FieldProp in keyof Schema[ModelProp]]: Schema[ModelProp][FieldProp] extends RefType<infer R extends RefTypeParamShape, any, any> | null ? ResolveRef<NonModelTypes, R> : Schema[ModelProp][FieldProp] extends ModelRelationalFieldParamShape ? Schema[ModelProp][FieldProp]['relatedModel'] extends keyof Schema ? GetRelationshipRef<Schema, Schema[ModelProp][FieldProp]['relatedModel'], Schema[ModelProp][FieldProp], Flat> : never : Schema[ModelProp][FieldProp];
|
|
42
36
|
};
|
|
43
37
|
};
|
|
44
38
|
type FilterFieldTypes<Schema> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResolveFieldProperties.d.ts","sourceRoot":"","sources":["../../../src/MappedTypes/ResolveFieldProperties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,
|
|
1
|
+
{"version":3,"file":"ResolveFieldProperties.d.ts","sourceRoot":"","sources":["../../../src/MappedTypes/ResolveFieldProperties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EACX,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EACV,oBAAoB,EACpB,8BAA8B,EAC/B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACzE,O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C"}
|
|
@@ -9,8 +9,7 @@ declare const brandName = "modelRelationalField";
|
|
|
9
9
|
export declare enum ModelRelationshipTypes {
|
|
10
10
|
hasOne = "hasOne",
|
|
11
11
|
hasMany = "hasMany",
|
|
12
|
-
belongsTo = "belongsTo"
|
|
13
|
-
manyToMany = "manyToMany"
|
|
12
|
+
belongsTo = "belongsTo"
|
|
14
13
|
}
|
|
15
14
|
type RelationshipTypes = `${ModelRelationshipTypes}`;
|
|
16
15
|
type ModelRelationalFieldData = {
|
|
@@ -20,8 +19,7 @@ type ModelRelationalFieldData = {
|
|
|
20
19
|
array: boolean;
|
|
21
20
|
valueRequired: boolean;
|
|
22
21
|
arrayRequired: boolean;
|
|
23
|
-
|
|
24
|
-
references?: string[];
|
|
22
|
+
references: string[];
|
|
25
23
|
authorization: Authorization<any, any, any>[];
|
|
26
24
|
};
|
|
27
25
|
export type ModelRelationalFieldParamShape = {
|
|
@@ -30,19 +28,14 @@ export type ModelRelationalFieldParamShape = {
|
|
|
30
28
|
relatedModel: string;
|
|
31
29
|
array: boolean;
|
|
32
30
|
valueRequired: boolean;
|
|
33
|
-
references
|
|
31
|
+
references: string[];
|
|
34
32
|
arrayRequired: boolean;
|
|
35
|
-
relationName?: string;
|
|
36
33
|
};
|
|
37
34
|
type ModelRelationalFieldFunctions<T extends ModelRelationalFieldParamShape, RM extends string | symbol, K extends keyof ModelRelationalField<T, RM> = never> = {
|
|
38
35
|
/**
|
|
39
36
|
* When set, it requires the value of the relationship type to be required.
|
|
40
37
|
*/
|
|
41
38
|
valueRequired(): ModelRelationalField<SetTypeSubArg<T, 'valueRequired', true>, K | 'valueRequired'>;
|
|
42
|
-
/**
|
|
43
|
-
* Reference sets the foreign key on which to establish the relationship
|
|
44
|
-
*/
|
|
45
|
-
references(references: string[]): ModelRelationalField<SetTypeSubArg<T, 'references', string[]>, K | 'references'>;
|
|
46
39
|
/**
|
|
47
40
|
* When set, it requires the relationship to always return a value
|
|
48
41
|
*/
|
|
@@ -69,15 +62,14 @@ export type ModelRelationalField<T extends ModelRelationalFieldParamShape, RM ex
|
|
|
69
62
|
export type InternalRelationalField = ModelRelationalField<ModelRelationalFieldParamShape, string, never> & {
|
|
70
63
|
data: ModelRelationalFieldData;
|
|
71
64
|
};
|
|
72
|
-
export type RelationTypeFunctionOmitMapping<Type extends ModelRelationshipTypes> = Type extends ModelRelationshipTypes.belongsTo ? 'required' | 'arrayRequired' | 'valueRequired' : Type extends ModelRelationshipTypes.hasMany ? 'required' : Type extends ModelRelationshipTypes.hasOne ? 'arrayRequired' | 'valueRequired' :
|
|
73
|
-
export type ModelRelationalTypeArgFactory<RM extends string, RT extends RelationshipTypes, IsArray extends boolean
|
|
65
|
+
export type RelationTypeFunctionOmitMapping<Type extends ModelRelationshipTypes> = Type extends ModelRelationshipTypes.belongsTo ? 'required' | 'arrayRequired' | 'valueRequired' : Type extends ModelRelationshipTypes.hasMany ? 'required' : Type extends ModelRelationshipTypes.hasOne ? 'arrayRequired' | 'valueRequired' : never;
|
|
66
|
+
export type ModelRelationalTypeArgFactory<RM extends string, RT extends RelationshipTypes, IsArray extends boolean> = {
|
|
74
67
|
type: 'model';
|
|
75
68
|
relatedModel: RM;
|
|
76
69
|
relationshipType: RT;
|
|
77
70
|
array: IsArray;
|
|
78
71
|
valueRequired: false;
|
|
79
72
|
arrayRequired: false;
|
|
80
|
-
relationName: RelationName;
|
|
81
73
|
references: string[];
|
|
82
74
|
};
|
|
83
75
|
/**
|
|
@@ -87,13 +79,13 @@ export type ModelRelationalTypeArgFactory<RM extends string, RT extends Relation
|
|
|
87
79
|
* @param relatedModel the name of the related model
|
|
88
80
|
* @returns a one-to-one relationship definition
|
|
89
81
|
*/
|
|
90
|
-
export declare function hasOne<RM extends string>(relatedModel: RM): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.hasOne, false
|
|
82
|
+
export declare function hasOne<RM extends string>(relatedModel: RM, references: string | string[]): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.hasOne, false>, RM, "valueRequired" | "arrayRequired", undefined>;
|
|
91
83
|
/**
|
|
92
84
|
* Create a one-directional one-to-many relationship between two models using the `hasMany()` method.
|
|
93
85
|
* @param relatedModel the name of the related model
|
|
94
86
|
* @returns a one-to-many relationship definition
|
|
95
87
|
*/
|
|
96
|
-
export declare function hasMany<RM extends string>(relatedModel: RM): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.hasMany, true
|
|
88
|
+
export declare function hasMany<RM extends string>(relatedModel: RM, references: string | string[]): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.hasMany, true>, RM, "required", undefined>;
|
|
97
89
|
/**
|
|
98
90
|
* Make a `hasOne()` or `hasMany()` relationship bi-directional using the `belongsTo()` method.
|
|
99
91
|
* The belongsTo() method requires that a hasOne() or hasMany() relationship already exists from
|
|
@@ -101,19 +93,6 @@ export declare function hasMany<RM extends string>(relatedModel: RM): ModelRelat
|
|
|
101
93
|
* @param relatedModel name of the related `.hasOne()` or `.hasMany()` model
|
|
102
94
|
* @returns a belong-to relationship definition
|
|
103
95
|
*/
|
|
104
|
-
export declare function belongsTo<RM extends string>(relatedModel: RM): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.belongsTo, false
|
|
105
|
-
/**
|
|
106
|
-
* Create a many-to-many relationship between two models with the manyToMany() method.
|
|
107
|
-
* Provide a common relationName on both models to join them into a many-to-many relationship.
|
|
108
|
-
* Under the hood a many-to-many relationship is modeled with a "join table" with corresponding
|
|
109
|
-
* `hasMany()` relationships between the two related models. You must set the same `manyToMany()`
|
|
110
|
-
* field on both models of the relationship.
|
|
111
|
-
* @param relatedModel name of the related model
|
|
112
|
-
* @param opts pass in the `relationName` that will serve as the join table name for this many-to-many relationship
|
|
113
|
-
* @returns a many-to-many relationship definition
|
|
114
|
-
*/
|
|
115
|
-
export declare function manyToMany<RM extends string, RN extends string>(relatedModel: RM, opts: {
|
|
116
|
-
relationName: RN;
|
|
117
|
-
}): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.manyToMany, true, RN>, RM, "required" | "references", undefined>;
|
|
96
|
+
export declare function belongsTo<RM extends string>(relatedModel: RM, references: string | string[]): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.belongsTo, false>, RM, "required" | "valueRequired" | "arrayRequired", undefined>;
|
|
118
97
|
export {};
|
|
119
98
|
//# sourceMappingURL=ModelRelationalField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelRelationalField.d.ts","sourceRoot":"","sources":["../../src/ModelRelationalField.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,MAAM,eAAmB,CAAC;AAEvC,QAAA,MAAM,SAAS,yBAAyB,CAAC;AAEzC,oBAAY,sBAAsB;IAChC,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,SAAS,cAAc;
|
|
1
|
+
{"version":3,"file":"ModelRelationalField.d.ts","sourceRoot":"","sources":["../../src/ModelRelationalField.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,MAAM,eAAmB,CAAC;AAEvC,QAAA,MAAM,SAAS,yBAAyB,CAAC;AAEzC,oBAAY,sBAAsB;IAChC,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,SAAS,cAAc;CACxB;AAED,KAAK,iBAAiB,GAAG,GAAG,sBAAsB,EAAE,CAAC;AAErD,KAAK,wBAAw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C;CACtB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,EAAE,SAAS,MAAM,EACtC,YAAY,EAAE,EAAE,EAChB,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,mJAW9B;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,EAAE,SAAS,MAAM,EACvC,YAAY,EAAE,EAAE,EAChB,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,4HAW9B;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,EAAE,SAAS,MAAM,EACzC,YAAY,EAAE,EAAE,EAChB,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,mKAW9B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.belongsTo = exports.hasMany = exports.hasOne = exports.ModelRelationshipTypes = exports.__auth = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Used to "attach" auth types to ModelField without exposing them on the builder.
|
|
6
6
|
*/
|
|
@@ -11,23 +11,19 @@ var ModelRelationshipTypes;
|
|
|
11
11
|
ModelRelationshipTypes["hasOne"] = "hasOne";
|
|
12
12
|
ModelRelationshipTypes["hasMany"] = "hasMany";
|
|
13
13
|
ModelRelationshipTypes["belongsTo"] = "belongsTo";
|
|
14
|
-
ModelRelationshipTypes["manyToMany"] = "manyToMany";
|
|
15
14
|
})(ModelRelationshipTypes || (exports.ModelRelationshipTypes = ModelRelationshipTypes = {}));
|
|
16
|
-
const arrayTypeRelationships = ['hasMany', 'manyToMany'];
|
|
17
15
|
const relationalModifiers = [
|
|
18
16
|
'required',
|
|
19
17
|
'arrayRequired',
|
|
20
18
|
'valueRequired',
|
|
21
|
-
'references',
|
|
22
19
|
'authorization',
|
|
23
20
|
];
|
|
24
21
|
const relationModifierMap = {
|
|
25
|
-
belongsTo: ['authorization'
|
|
26
|
-
hasMany: ['arrayRequired', 'valueRequired', 'authorization'
|
|
27
|
-
hasOne: ['required', 'authorization'
|
|
28
|
-
manyToMany: ['arrayRequired', 'valueRequired', 'authorization'],
|
|
22
|
+
belongsTo: ['authorization'],
|
|
23
|
+
hasMany: ['arrayRequired', 'valueRequired', 'authorization'],
|
|
24
|
+
hasOne: ['required', 'authorization'],
|
|
29
25
|
};
|
|
30
|
-
function _modelRelationalField(type, relatedModel,
|
|
26
|
+
function _modelRelationalField(type, relatedModel, references) {
|
|
31
27
|
const data = {
|
|
32
28
|
relatedModel,
|
|
33
29
|
type,
|
|
@@ -35,13 +31,10 @@ function _modelRelationalField(type, relatedModel, relationName) {
|
|
|
35
31
|
array: false,
|
|
36
32
|
valueRequired: false,
|
|
37
33
|
arrayRequired: false,
|
|
38
|
-
references
|
|
39
|
-
relationName,
|
|
34
|
+
references,
|
|
40
35
|
authorization: [],
|
|
41
36
|
};
|
|
42
|
-
|
|
43
|
-
data.array = true;
|
|
44
|
-
}
|
|
37
|
+
data.array = type === 'hasMany';
|
|
45
38
|
const relationshipBuilderFunctions = {
|
|
46
39
|
required() {
|
|
47
40
|
data.arrayRequired = true;
|
|
@@ -55,10 +48,6 @@ function _modelRelationalField(type, relatedModel, relationName) {
|
|
|
55
48
|
data.valueRequired = true;
|
|
56
49
|
return this;
|
|
57
50
|
},
|
|
58
|
-
references(references) {
|
|
59
|
-
data.references = references;
|
|
60
|
-
return this;
|
|
61
|
-
},
|
|
62
51
|
authorization(rules) {
|
|
63
52
|
data.authorization = rules;
|
|
64
53
|
return this;
|
|
@@ -80,8 +69,8 @@ function _modelRelationalField(type, relatedModel, relationName) {
|
|
|
80
69
|
* @param relatedModel the name of the related model
|
|
81
70
|
* @returns a one-to-one relationship definition
|
|
82
71
|
*/
|
|
83
|
-
function hasOne(relatedModel) {
|
|
84
|
-
return _modelRelationalField(ModelRelationshipTypes.hasOne, relatedModel);
|
|
72
|
+
function hasOne(relatedModel, references) {
|
|
73
|
+
return _modelRelationalField(ModelRelationshipTypes.hasOne, relatedModel, Array.isArray(references) ? references : [references]);
|
|
85
74
|
}
|
|
86
75
|
exports.hasOne = hasOne;
|
|
87
76
|
/**
|
|
@@ -89,8 +78,8 @@ exports.hasOne = hasOne;
|
|
|
89
78
|
* @param relatedModel the name of the related model
|
|
90
79
|
* @returns a one-to-many relationship definition
|
|
91
80
|
*/
|
|
92
|
-
function hasMany(relatedModel) {
|
|
93
|
-
return _modelRelationalField(ModelRelationshipTypes.hasMany, relatedModel);
|
|
81
|
+
function hasMany(relatedModel, references) {
|
|
82
|
+
return _modelRelationalField(ModelRelationshipTypes.hasMany, relatedModel, Array.isArray(references) ? references : [references]);
|
|
94
83
|
}
|
|
95
84
|
exports.hasMany = hasMany;
|
|
96
85
|
/**
|
|
@@ -100,21 +89,7 @@ exports.hasMany = hasMany;
|
|
|
100
89
|
* @param relatedModel name of the related `.hasOne()` or `.hasMany()` model
|
|
101
90
|
* @returns a belong-to relationship definition
|
|
102
91
|
*/
|
|
103
|
-
function belongsTo(relatedModel) {
|
|
104
|
-
return _modelRelationalField(ModelRelationshipTypes.belongsTo, relatedModel);
|
|
92
|
+
function belongsTo(relatedModel, references) {
|
|
93
|
+
return _modelRelationalField(ModelRelationshipTypes.belongsTo, relatedModel, Array.isArray(references) ? references : [references]);
|
|
105
94
|
}
|
|
106
95
|
exports.belongsTo = belongsTo;
|
|
107
|
-
/**
|
|
108
|
-
* Create a many-to-many relationship between two models with the manyToMany() method.
|
|
109
|
-
* Provide a common relationName on both models to join them into a many-to-many relationship.
|
|
110
|
-
* Under the hood a many-to-many relationship is modeled with a "join table" with corresponding
|
|
111
|
-
* `hasMany()` relationships between the two related models. You must set the same `manyToMany()`
|
|
112
|
-
* field on both models of the relationship.
|
|
113
|
-
* @param relatedModel name of the related model
|
|
114
|
-
* @param opts pass in the `relationName` that will serve as the join table name for this many-to-many relationship
|
|
115
|
-
* @returns a many-to-many relationship definition
|
|
116
|
-
*/
|
|
117
|
-
function manyToMany(relatedModel, opts) {
|
|
118
|
-
return _modelRelationalField(ModelRelationshipTypes.manyToMany, relatedModel, opts.relationName);
|
|
119
|
-
}
|
|
120
|
-
exports.manyToMany = manyToMany;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaProcessor.d.ts","sourceRoot":"","sources":["../../src/SchemaProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"SchemaProcessor.d.ts","sourceRoot":"","sources":["../../src/SchemaProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAiBzE,OAAO,EACL,oBAAoB,EAMrB,MAAM,gCAAgC,CAAC;AA49CxC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE;IACjC,MAAM,EAAE,cAAc,CAAC;CACxB,GAAG,oBAAoB,CAiBvB"}
|
|
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.processSchema = void 0;
|
|
27
27
|
const ModelField_1 = require("./ModelField");
|
|
28
|
-
const ModelRelationalField_1 = require("./ModelRelationalField");
|
|
29
28
|
const Authorization_1 = require("./Authorization");
|
|
30
29
|
const CustomOperation_1 = require("./CustomOperation");
|
|
31
30
|
const util_1 = require("./util");
|
|
@@ -118,7 +117,7 @@ function scalarFieldToGql(fieldDef, identifier, secondaryIndexes = []) {
|
|
|
118
117
|
return field;
|
|
119
118
|
}
|
|
120
119
|
function modelFieldToGql(fieldDef) {
|
|
121
|
-
const { type, relatedModel, array,
|
|
120
|
+
const { type, relatedModel, array, valueRequired, arrayRequired, references, } = fieldDef;
|
|
122
121
|
let field = relatedModel;
|
|
123
122
|
if (valueRequired === true) {
|
|
124
123
|
field += '!';
|
|
@@ -135,10 +134,6 @@ function modelFieldToGql(fieldDef) {
|
|
|
135
134
|
else {
|
|
136
135
|
field += ` @${type}`;
|
|
137
136
|
}
|
|
138
|
-
// TODO: accept other relationship options e.g. `fields`
|
|
139
|
-
if (type === 'manyToMany') {
|
|
140
|
-
field += `(relationName: "${relationName}")`;
|
|
141
|
-
}
|
|
142
137
|
return field;
|
|
143
138
|
}
|
|
144
139
|
function refFieldToGql(fieldDef) {
|
|
@@ -375,22 +370,6 @@ function validateImpliedFields(existing, implicitFields) {
|
|
|
375
370
|
}
|
|
376
371
|
}
|
|
377
372
|
}
|
|
378
|
-
/**
|
|
379
|
-
* Produces a new field definition object from every field definition object
|
|
380
|
-
* given as an argument. Performs validation (conflict detection) as objects
|
|
381
|
-
* are merged together.
|
|
382
|
-
*
|
|
383
|
-
* @param fieldsObjects A list of field definition objects to merge.
|
|
384
|
-
* @returns
|
|
385
|
-
*/
|
|
386
|
-
function mergeFieldObjects(...fieldsObjects) {
|
|
387
|
-
const result = {};
|
|
388
|
-
for (const fields of fieldsObjects) {
|
|
389
|
-
if (fields)
|
|
390
|
-
addFields(result, fields);
|
|
391
|
-
}
|
|
392
|
-
return result;
|
|
393
|
-
}
|
|
394
373
|
/**
|
|
395
374
|
* Throws if resource/lambda auth is configured at the model or field level
|
|
396
375
|
*
|
|
@@ -551,114 +530,6 @@ function calculateCustomAuth(authorization) {
|
|
|
551
530
|
function capitalize(s) {
|
|
552
531
|
return `${s[0].toUpperCase()}${s.slice(1)}`;
|
|
553
532
|
}
|
|
554
|
-
function uncapitalize(s) {
|
|
555
|
-
return `${s[0].toLowerCase()}${s.slice(1)}`;
|
|
556
|
-
}
|
|
557
|
-
function fkName(model, field, identifier) {
|
|
558
|
-
return `${uncapitalize(model)}${capitalize(field)}${capitalize(identifier)}`;
|
|
559
|
-
}
|
|
560
|
-
/**
|
|
561
|
-
* Returns all explicitly defined and implied fields from a model.
|
|
562
|
-
*
|
|
563
|
-
* @param schema The schema the model is part of. Necessary to derive implied FK's.
|
|
564
|
-
* @param model The model to extract fields from and derive fields for.
|
|
565
|
-
* @returns
|
|
566
|
-
*/
|
|
567
|
-
const allImpliedFKs = (schema) => {
|
|
568
|
-
const fks = {};
|
|
569
|
-
function addFk({ onModel, asField, fieldDef, }) {
|
|
570
|
-
fks[onModel] = fks[onModel] || {};
|
|
571
|
-
fks[onModel][asField] = fieldDef;
|
|
572
|
-
}
|
|
573
|
-
// implied FK's
|
|
574
|
-
for (const [modelName, typeDef] of Object.entries(schema.data.types)) {
|
|
575
|
-
if (!isInternalModel(typeDef))
|
|
576
|
-
continue;
|
|
577
|
-
for (const [fieldName, fieldDef] of Object.entries(typeDef.data.fields)) {
|
|
578
|
-
if (!isModelField(fieldDef))
|
|
579
|
-
continue;
|
|
580
|
-
const relatedModel = schema.data.types[fieldDef.data.relatedModel];
|
|
581
|
-
switch (fieldDef.data.type) {
|
|
582
|
-
case ModelRelationalField_1.ModelRelationshipTypes.hasOne:
|
|
583
|
-
for (const idField of relatedModel.data.identifier) {
|
|
584
|
-
addFk({
|
|
585
|
-
onModel: modelName,
|
|
586
|
-
asField: fkName(modelName, fieldName, idField),
|
|
587
|
-
fieldDef: {
|
|
588
|
-
data: {
|
|
589
|
-
...fieldDef.data,
|
|
590
|
-
fieldType: relatedModel.data.fields[idField]?.data.fieldType ||
|
|
591
|
-
ModelField_1.ModelFieldType.Id,
|
|
592
|
-
},
|
|
593
|
-
},
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
break;
|
|
597
|
-
case ModelRelationalField_1.ModelRelationshipTypes.hasMany:
|
|
598
|
-
{
|
|
599
|
-
let authorization = [];
|
|
600
|
-
let required = false;
|
|
601
|
-
const [_belongsToName, belongsToDef] = Object.entries(relatedModel.data.fields).find(([_name, def]) => {
|
|
602
|
-
return (isModelField(def) &&
|
|
603
|
-
def.data.type === ModelRelationalField_1.ModelRelationshipTypes.belongsTo &&
|
|
604
|
-
def.data.relatedModel === fieldName);
|
|
605
|
-
}) || [];
|
|
606
|
-
if (belongsToDef && isModelField(belongsToDef)) {
|
|
607
|
-
authorization = belongsToDef.data.authorization;
|
|
608
|
-
required = belongsToDef.data.valueRequired;
|
|
609
|
-
}
|
|
610
|
-
for (const idField of typeDef.data.identifier) {
|
|
611
|
-
addFk({
|
|
612
|
-
onModel: fieldDef.data.relatedModel,
|
|
613
|
-
asField: fkName(modelName, fieldName, idField),
|
|
614
|
-
fieldDef: {
|
|
615
|
-
data: {
|
|
616
|
-
...(typeDef.data.fields[idField]?.data ||
|
|
617
|
-
(0, ModelField_1.id)().data),
|
|
618
|
-
authorization,
|
|
619
|
-
required,
|
|
620
|
-
},
|
|
621
|
-
},
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
break;
|
|
626
|
-
case ModelRelationalField_1.ModelRelationshipTypes.belongsTo:
|
|
627
|
-
{
|
|
628
|
-
// only create if corresponds to hasOne
|
|
629
|
-
const [_hasOneName, hasOneDef] = Object.entries(relatedModel.data.fields).find(([_name, def]) => {
|
|
630
|
-
return (isModelField(def) &&
|
|
631
|
-
def.data.type === ModelRelationalField_1.ModelRelationshipTypes.hasOne &&
|
|
632
|
-
def.data.relatedModel === modelName);
|
|
633
|
-
}) || [];
|
|
634
|
-
if (hasOneDef && isModelField(hasOneDef)) {
|
|
635
|
-
for (const idField of relatedModel.data.identifier) {
|
|
636
|
-
addFk({
|
|
637
|
-
onModel: modelName,
|
|
638
|
-
asField: fkName(modelName, fieldName, idField),
|
|
639
|
-
fieldDef: {
|
|
640
|
-
data: {
|
|
641
|
-
...typeDef.data,
|
|
642
|
-
fieldType: relatedModel.data.fields[idField]?.data.fieldType ||
|
|
643
|
-
ModelField_1.ModelFieldType.Id,
|
|
644
|
-
},
|
|
645
|
-
},
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
break;
|
|
651
|
-
case ModelRelationalField_1.ModelRelationshipTypes.manyToMany:
|
|
652
|
-
// pretty sure there's nothing to do here.
|
|
653
|
-
// the implicit join table already has everything, AFAIK.
|
|
654
|
-
break;
|
|
655
|
-
default:
|
|
656
|
-
// nothing to do.
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
return fks;
|
|
661
|
-
};
|
|
662
533
|
function processFieldLevelAuthRules(fields, authFields) {
|
|
663
534
|
const fieldLevelAuthRules = {};
|
|
664
535
|
for (const [fieldName, fieldDef] of Object.entries(fields)) {
|
|
@@ -825,7 +696,6 @@ const schemaPreprocessor = (schema) => {
|
|
|
825
696
|
? 'dynamodb'
|
|
826
697
|
: 'sql';
|
|
827
698
|
const staticSchema = schema.data.configuration.database.engine === 'dynamodb' ? false : true;
|
|
828
|
-
const fkFields = staticSchema ? {} : allImpliedFKs(schema);
|
|
829
699
|
const topLevelTypes = Object.entries(schema.data.types);
|
|
830
700
|
const { schemaAuth, functionSchemaAccess } = extractFunctionSchemaAccess(schema.data.authorization);
|
|
831
701
|
const getRefType = getRefTypeForSchema(schema);
|
|
@@ -884,7 +754,6 @@ const schemaPreprocessor = (schema) => {
|
|
|
884
754
|
const fields = { ...typeDef.data.fields };
|
|
885
755
|
const identifier = typeDef.data.identifier;
|
|
886
756
|
const [partitionKey] = identifier;
|
|
887
|
-
validateStaticFields(fields, fkFields[typeName]);
|
|
888
757
|
const { authString, authFields } = calculateAuth(mostRelevantAuthRules);
|
|
889
758
|
if (authString == '') {
|
|
890
759
|
throw new Error(`Model \`${typeName}\` is missing authorization rules. Add global rules to the schema or ensure every model has its own rules.`);
|
|
@@ -898,7 +767,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
898
767
|
gqlModels.push(model);
|
|
899
768
|
}
|
|
900
769
|
else {
|
|
901
|
-
const fields =
|
|
770
|
+
const fields = typeDef.data.fields;
|
|
902
771
|
const identifier = typeDef.data.identifier;
|
|
903
772
|
const [partitionKey] = identifier;
|
|
904
773
|
const transformedSecondaryIndexes = transformedSecondaryIndexesForModel(typeDef.data.secondaryIndexes);
|
package/lib-esm/src/index.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { combine } from './CombineSchema';
|
|
|
3
3
|
import { model } from './ModelType';
|
|
4
4
|
import { id, string, integer, float, boolean, date, time, datetime, timestamp, email, json, phone, url, ipAddress } from './ModelField';
|
|
5
5
|
import { ref } from './RefType';
|
|
6
|
-
import { hasOne, hasMany, belongsTo
|
|
6
|
+
import { hasOne, hasMany, belongsTo } from './ModelRelationalField';
|
|
7
7
|
import { allow } from './Authorization';
|
|
8
8
|
import { customType } from './CustomType';
|
|
9
9
|
import { enumType } from './EnumType';
|
|
10
10
|
import { query, mutation, subscription } from './CustomOperation';
|
|
11
11
|
import { handler } from './Handler';
|
|
12
|
-
export { schema, combine, model, ref, customType, enumType as enum, query, mutation, subscription, hasOne, hasMany, belongsTo,
|
|
12
|
+
export { schema, combine, model, ref, customType, enumType as enum, query, mutation, subscription, hasOne, hasMany, belongsTo, allow, id, string, integer, float, boolean, date, time, datetime, timestamp, email, json, phone, url, ipAddress, handler, };
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EACL,EAAE,EACF,MAAM,EACN,OAAO,EACP,KAAK,EACL,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,KAAK,EACL,IAAI,EACJ,KAAK,EACL,GAAG,EACH,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"m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