@aws-amplify/data-schema 1.1.5 → 1.2.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/dist/cjs/ModelSchema.js +19 -0
- package/dist/cjs/ModelSchema.js.map +1 -1
- package/dist/cjs/SchemaProcessor.js +1 -4
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/cjs/util/Brand.js +4 -4
- package/dist/cjs/util/Brand.js.map +1 -1
- package/dist/cjs/util/usedMethods.js +4 -0
- package/dist/cjs/util/usedMethods.js.map +1 -0
- package/dist/esm/CustomOperation.d.ts +3 -3
- package/dist/esm/CustomType.d.ts +3 -3
- package/dist/esm/EnumType.d.ts +7 -9
- package/dist/esm/MappedTypes/CustomOperations.d.ts +3 -3
- package/dist/esm/MappedTypes/ExtractNonModelTypes.d.ts +4 -4
- package/dist/esm/MappedTypes/ResolveFieldProperties.d.ts +2 -2
- package/dist/esm/MappedTypes/ResolveSchema.d.ts +6 -6
- package/dist/esm/ModelField.d.ts +15 -12
- package/dist/esm/ModelSchema.d.ts +17 -5
- package/dist/esm/ModelSchema.mjs +20 -1
- package/dist/esm/ModelSchema.mjs.map +1 -1
- package/dist/esm/ModelType.d.ts +16 -12
- package/dist/esm/SchemaProcessor.mjs +1 -4
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/util/Brand.d.ts +1 -2
- package/dist/esm/util/Brand.mjs +1 -1
- package/dist/esm/util/Brand.mjs.map +1 -1
- package/dist/esm/util/usedMethods.d.ts +4 -0
- package/dist/esm/util/usedMethods.mjs +2 -0
- package/dist/esm/util/usedMethods.mjs.map +1 -0
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/CustomOperation.ts +3 -7
- package/src/CustomType.ts +4 -8
- package/src/EnumType.ts +16 -22
- package/src/MappedTypes/CustomOperations.ts +4 -6
- package/src/MappedTypes/ExtractNonModelTypes.ts +39 -40
- package/src/MappedTypes/ResolveFieldProperties.ts +2 -2
- package/src/MappedTypes/ResolveSchema.ts +18 -21
- package/src/ModelField.ts +33 -18
- package/src/ModelSchema.ts +51 -13
- package/src/ModelType.ts +30 -34
- package/src/SchemaProcessor.ts +23 -48
- package/src/util/Brand.ts +1 -1
- package/src/util/usedMethods.ts +5 -0
package/dist/esm/EnumType.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { brandSymbol } from './util/Brand.js';
|
|
2
|
+
type EnumTypeParamShape<values extends readonly string[] = readonly string[]> = {
|
|
3
3
|
type: 'enum';
|
|
4
|
-
values:
|
|
5
|
-
};
|
|
6
|
-
export type EnumType<T extends EnumTypeParamShape> = T & Brand<'enum'>;
|
|
7
|
-
type EnumTypeArgFactory<Values extends readonly string[]> = {
|
|
8
|
-
type: 'enum';
|
|
9
|
-
values: Values;
|
|
4
|
+
values: values;
|
|
10
5
|
};
|
|
6
|
+
export interface EnumType<values extends readonly string[] = readonly string[]> extends EnumTypeParamShape<values> {
|
|
7
|
+
[brandSymbol]: 'enum';
|
|
8
|
+
}
|
|
11
9
|
/**
|
|
12
10
|
* this type param pattern allows us to infer literal type values from the array without using the `as const` suffix
|
|
13
11
|
*/
|
|
14
|
-
export declare function enumType<
|
|
12
|
+
export declare function enumType<const values extends readonly string[]>(values: values): EnumType<values>;
|
|
15
13
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GenericModelSchema } from '../ModelSchema';
|
|
2
2
|
import type { NonModelTypesShape } from './ExtractNonModelTypes';
|
|
3
3
|
import type { CustomOperation, CustomOperationParamShape } from '../CustomOperation';
|
|
4
|
-
import type {
|
|
4
|
+
import type { BaseModelField } from '../ModelField';
|
|
5
5
|
import type { RefType, RefTypeParamShape } from '../RefType';
|
|
6
6
|
import type { ResolveFieldRequirements, ResolveRefsOfCustomType, ResolveRefValueArrayTraits } from './ResolveFieldProperties';
|
|
7
7
|
import type { AppSyncResolverHandler } from 'aws-lambda';
|
|
@@ -30,14 +30,14 @@ export type CustomOpShapes<Schema extends GenericModelSchema<any>> = {
|
|
|
30
30
|
* Digs out custom operation arguments, mapped to the intended graphql types.
|
|
31
31
|
*/
|
|
32
32
|
export type CustomOpArguments<Shape extends CustomOperationParamShape> = Shape['arguments'] extends null ? never : ResolveFieldRequirements<{
|
|
33
|
-
[FieldName in keyof Shape['arguments']]: Shape['arguments'][FieldName] extends
|
|
33
|
+
[FieldName in keyof Shape['arguments']]: Shape['arguments'][FieldName] extends BaseModelField<infer R> ? R : never;
|
|
34
34
|
}>;
|
|
35
35
|
/**
|
|
36
36
|
* Computes the return type from the `returnType` of a custom operation shape.
|
|
37
37
|
*
|
|
38
38
|
* This entails dereferencing refs and inferring graphql types from field-type defs.
|
|
39
39
|
*/
|
|
40
|
-
export type CustomOpReturnType<Shape extends CustomOperationParamShape, FullyResolvedSchema extends Record<string, unknown>, NonModelTypes extends NonModelTypesShape, CustomOperations extends Record<string, CustomOperationParamShape>> = Shape['returnType'] extends RefType<infer RefShape, any, any> ? RefShape['link'] extends keyof CustomOperations ? CustomOpReturnType<CustomOperations[RefShape['link']], FullyResolvedSchema, NonModelTypes, CustomOperations> : ResolveRef<RefShape, FullyResolvedSchema, NonModelTypes, CustomOperations> : Shape['returnType'] extends
|
|
40
|
+
export type CustomOpReturnType<Shape extends CustomOperationParamShape, FullyResolvedSchema extends Record<string, unknown>, NonModelTypes extends NonModelTypesShape, CustomOperations extends Record<string, CustomOperationParamShape>> = Shape['returnType'] extends RefType<infer RefShape, any, any> ? RefShape['link'] extends keyof CustomOperations ? CustomOpReturnType<CustomOperations[RefShape['link']], FullyResolvedSchema, NonModelTypes, CustomOperations> : ResolveRef<RefShape, FullyResolvedSchema, NonModelTypes, CustomOperations> : Shape['returnType'] extends BaseModelField<infer R> ? R : Shape['returnType'] extends CustomType<infer R> ? ResolveFieldRequirements<FieldTypesOfCustomType<{
|
|
41
41
|
thisCustomType: R['fields'];
|
|
42
42
|
}>['thisCustomType']> | null : never;
|
|
43
43
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { UnionToIntersection } from '@aws-amplify/data-schema-types';
|
|
2
2
|
import type { CustomType, CustomTypeParamShape } from '../CustomType';
|
|
3
|
-
import type { EnumType
|
|
3
|
+
import type { EnumType } from '../EnumType';
|
|
4
4
|
import type { SchemaTypes, ModelAndCustomTypes, FieldTypesOfCustomType } from './ResolveSchema';
|
|
5
5
|
import type { ModelType, ModelTypeParamShape } from '../ModelType';
|
|
6
6
|
export type NonModelTypesShape = {
|
|
7
|
-
enums: Record<string,
|
|
7
|
+
enums: Record<string, any>;
|
|
8
8
|
customTypes: Record<string, any>;
|
|
9
9
|
};
|
|
10
10
|
export type ExtractNonModelTypes<Schema> = ResolveNonModelFields<ResolveNonModelTypes<Schema, ExtractImplicitNonModelTypes<Schema>>>;
|
|
@@ -40,7 +40,7 @@ export type ExtractNonModelTypes<Schema> = ResolveNonModelFields<ResolveNonModel
|
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
42
|
export type ExtractAndFlattenImplicitNonModelTypesFromFields<ParentTypeName extends string, Fields> = {
|
|
43
|
-
[FieldProp in keyof Fields as Fields[FieldProp] extends EnumType
|
|
43
|
+
[FieldProp in keyof Fields as Fields[FieldProp] extends EnumType | CustomType<CustomTypeParamShape> ? FieldProp : never]: (x: NonNullable<Fields[FieldProp]> extends infer FieldType ? FieldType extends EnumType ? {
|
|
44
44
|
[Key in `${ParentTypeName}${Capitalize<FieldProp & string>}`]: Fields[FieldProp];
|
|
45
45
|
} : FieldType extends CustomType<infer CustomTypeShape extends CustomTypeParamShape> ? // recursively extract to the Nested CustomType, and return the
|
|
46
46
|
ExtractAndFlattenImplicitNonModelTypesFromFields<`${ParentTypeName}${Capitalize<FieldProp & string>}`, CustomTypeShape['fields']> & {
|
|
@@ -60,7 +60,7 @@ export type ExtractImplicitNonModelTypes<Schema, Targets = ModelAndCustomTypes<S
|
|
|
60
60
|
}[keyof Targets]>;
|
|
61
61
|
type ResolveNonModelTypes<Schema, Extracted, ResolvedSchema = SchemaTypes<Schema> & Extracted> = {
|
|
62
62
|
enums: {
|
|
63
|
-
[Model in keyof ResolvedSchema as ResolvedSchema[Model] extends EnumType
|
|
63
|
+
[Model in keyof ResolvedSchema as ResolvedSchema[Model] extends EnumType ? Model : never]: ResolvedSchema[Model] extends EnumType<infer values> ? values[number] : never;
|
|
64
64
|
};
|
|
65
65
|
customTypes: {
|
|
66
66
|
[Model in keyof ResolvedSchema as ResolvedSchema[Model] extends CustomType<CustomTypeParamShape> ? Model : never]: ResolvedSchema[Model] extends CustomType<infer R extends CustomTypeParamShape> ? R['fields'] : never;
|
|
@@ -11,7 +11,7 @@ import type { ModelIdentifier } from './ModelMetadata';
|
|
|
11
11
|
import type { RefType, RefTypeParamShape } from '../RefType';
|
|
12
12
|
import type { NonModelTypesShape } from './ExtractNonModelTypes';
|
|
13
13
|
import type { CustomType, CustomTypeParamShape } from '../CustomType';
|
|
14
|
-
import type { EnumType
|
|
14
|
+
import type { EnumType } from '../EnumType';
|
|
15
15
|
import type { CustomOperation, CustomOperationParamShape } from '../CustomOperation';
|
|
16
16
|
export type ResolveFieldProperties<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape, ResolvedSchema = ResolveSchema<Schema>, IdentifierMeta extends Record<string, {
|
|
17
17
|
identifier: PrimaryIndexIrShape;
|
|
@@ -57,7 +57,7 @@ type Intersection<A = Record<never, never>, B = Record<never, never>, C = Record
|
|
|
57
57
|
[P in keyof U]: U[P];
|
|
58
58
|
} : never;
|
|
59
59
|
export type ModelImpliedAuthFields<Schema extends GenericModelSchema<any>> = {
|
|
60
|
-
[ModelKey in keyof Schema['data']['types'] as Schema['data']['types'][ModelKey] extends EnumType
|
|
60
|
+
[ModelKey in keyof Schema['data']['types'] as Schema['data']['types'][ModelKey] extends EnumType ? never : Schema['data']['types'][ModelKey] extends CustomType<CustomTypeParamShape> ? never : Schema['data']['types'][ModelKey] extends CustomOperation<CustomOperationParamShape, any> ? never : ModelKey]: Schema['data']['types'][ModelKey] extends ModelType<infer Model, any> ? AllAuthFieldsForModel<Schema, Model> : object;
|
|
61
61
|
};
|
|
62
62
|
type AllAuthFieldsForModel<Schema extends GenericModelSchema<any>, Model extends Schema['data']['types'][keyof Schema['data']['types']]> = (Model['authorization'][number] extends never ? Schema['data']['authorization'][number] extends never ? object : ImpliedAuthFields<Schema['data']['authorization'][number]> : ImpliedAuthFields<Model['authorization'][number]>) & ImpliedAuthFieldsFromFields<Model>;
|
|
63
63
|
type ImpliedAuthFieldsFromFields<T> = UnionToIntersection<T extends ModelTypeParamShape ? T['fields'][keyof T['fields']] extends ModelField<any, any, infer Auth> | ModelRelationalField<any, any, any, infer Auth> | RefType<any, any, infer Auth> ? Auth extends Authorization<any, any, any> ? ImpliedAuthFields<Auth> : object : object : object>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ModelType } from '../ModelType';
|
|
2
2
|
import type { GenericModelSchema } from '../ModelSchema';
|
|
3
3
|
import type { ModelRelationalField, ModelRelationshipTypes, RelationTypeFunctionOmitMapping } from '../ModelRelationalField';
|
|
4
|
-
import type {
|
|
4
|
+
import type { BaseModelField } from '../ModelField';
|
|
5
5
|
import type { CustomType, CustomTypeParamShape } from '../CustomType';
|
|
6
|
-
import type { EnumType
|
|
6
|
+
import type { EnumType } from '../EnumType';
|
|
7
7
|
import type { RefType, RefTypeParamShape } from '../RefType';
|
|
8
8
|
import type { CustomOperation, CustomOperationParamShape } from '../CustomOperation';
|
|
9
9
|
export type ResolveSchema<Schema> = FieldTypes<ModelTypes<SchemaTypes<Schema>>>;
|
|
@@ -16,14 +16,14 @@ export type SchemaTypes<T> = T extends GenericModelSchema<any> ? T['data']['type
|
|
|
16
16
|
* added to ModelMeta in ClientSchema.ts
|
|
17
17
|
*/
|
|
18
18
|
export type ModelTypes<Schema> = {
|
|
19
|
-
[Model in keyof Schema as Schema[Model] extends EnumType
|
|
19
|
+
[Model in keyof Schema as Schema[Model] extends EnumType | CustomType<CustomTypeParamShape> | CustomOperation<CustomOperationParamShape, any> ? never : Model]: Schema[Model] extends ModelType<infer R, any> ? R['fields'] : never;
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
22
|
* Gets the collection of all ModelTypes and CustomTypes which are explicitly
|
|
23
23
|
* defined in the schema.
|
|
24
24
|
*/
|
|
25
25
|
export type ModelAndCustomTypes<Schema> = {
|
|
26
|
-
[Model in keyof Schema as Schema[Model] extends EnumType
|
|
26
|
+
[Model in keyof Schema as Schema[Model] extends EnumType | CustomOperation<CustomOperationParamShape, any> ? never : Model]: Schema[Model] extends ModelType<any, any> | CustomType<CustomTypeParamShape> ? Schema[Model] : never;
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
29
|
* Resolves field types
|
|
@@ -32,7 +32,7 @@ export type ModelAndCustomTypes<Schema> = {
|
|
|
32
32
|
*/
|
|
33
33
|
export type FieldTypes<T> = {
|
|
34
34
|
[ModelProp in keyof T]: {
|
|
35
|
-
[FieldProp in keyof T[ModelProp]]: T[ModelProp][FieldProp] extends
|
|
35
|
+
[FieldProp in keyof T[ModelProp]]: T[ModelProp][FieldProp] extends BaseModelField<infer R> ? R : T[ModelProp][FieldProp] extends RefType<infer R extends RefTypeParamShape, any, any> ? R['valueRequired'] extends true ? T[ModelProp][FieldProp] : T[ModelProp][FieldProp] | null : T[ModelProp][FieldProp] extends EnumType | CustomType<CustomTypeParamShape> ? RefType<{
|
|
36
36
|
link: `${Capitalize<ModelProp & string>}${Capitalize<FieldProp & string>}`;
|
|
37
37
|
type: 'ref';
|
|
38
38
|
valueRequired: false;
|
|
@@ -52,7 +52,7 @@ export type FieldTypes<T> = {
|
|
|
52
52
|
*/
|
|
53
53
|
export type FieldTypesOfCustomType<T> = {
|
|
54
54
|
[CustomTypeName in keyof T]: {
|
|
55
|
-
[FieldProp in keyof T[CustomTypeName]]: T[CustomTypeName][FieldProp] extends
|
|
55
|
+
[FieldProp in keyof T[CustomTypeName]]: T[CustomTypeName][FieldProp] extends BaseModelField<infer R> ? R : T[CustomTypeName][FieldProp] extends RefType<infer R extends RefTypeParamShape, any, any> ? R['valueRequired'] extends true ? T[CustomTypeName][FieldProp] : T[CustomTypeName][FieldProp] | null : T[CustomTypeName][FieldProp] extends EnumType | CustomType<CustomTypeParamShape> ? RefType<{
|
|
56
56
|
link: `${Capitalize<CustomTypeName & string>}${Capitalize<FieldProp & string>}`;
|
|
57
57
|
type: 'ref';
|
|
58
58
|
valueRequired: false;
|
package/dist/esm/ModelField.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Brand } from './util';
|
|
2
1
|
import { AllowModifier, Authorization } from './Authorization';
|
|
2
|
+
import type { methodKeyOf, satisfy } from './util/usedMethods.js';
|
|
3
|
+
import type { brandSymbol } from './util/Brand.js';
|
|
3
4
|
/**
|
|
4
5
|
* Used to "attach" auth types to ModelField without exposing them on the builder.
|
|
5
6
|
*/
|
|
@@ -45,42 +46,44 @@ export type ModelFieldTypeParamOuter = ModelFieldTypeParamInner | Array<ModelFie
|
|
|
45
46
|
export type Nullable<T> = T | null;
|
|
46
47
|
export type Required<T> = Exclude<T, null>;
|
|
47
48
|
export type ArrayField<T> = [T] extends [ModelFieldTypeParamInner] ? Array<T> | null : never;
|
|
49
|
+
export type BaseModelField<T extends ModelFieldTypeParamOuter = ModelFieldTypeParamOuter> = ModelField<T, UsableModelFieldKey, any>;
|
|
50
|
+
export type UsableModelFieldKey = satisfy<methodKeyOf<ModelField>, 'required' | 'default' | 'authorization'>;
|
|
48
51
|
/**
|
|
49
52
|
* Public API for the chainable builder methods exposed by Model Field.
|
|
50
53
|
* The type is narrowing e.g., after calling .array() it will be omitted from intellisense suggestions
|
|
51
54
|
*
|
|
52
55
|
* @typeParam T - holds the JS data type of the field
|
|
53
|
-
* @typeParam
|
|
56
|
+
* @typeParam UsedMethod - union of strings representing already-invoked method names. Used to improve Intellisense
|
|
54
57
|
*/
|
|
55
|
-
export type ModelField<T extends ModelFieldTypeParamOuter,
|
|
58
|
+
export type ModelField<T extends ModelFieldTypeParamOuter = ModelFieldTypeParamOuter, UsedMethod extends UsableModelFieldKey = never, Auth = undefined> = Omit<{
|
|
59
|
+
[__auth]?: Auth;
|
|
60
|
+
[brandSymbol]: typeof brandName;
|
|
56
61
|
/**
|
|
57
62
|
* Marks a field as required.
|
|
58
63
|
*/
|
|
59
|
-
required(): ModelField<Required<T>,
|
|
64
|
+
required(): ModelField<Required<T>, UsedMethod | 'required'>;
|
|
60
65
|
/**
|
|
61
66
|
* Converts a field type definition to an array of the field type.
|
|
62
67
|
*/
|
|
63
|
-
array(): ModelField<ArrayField<T>, Exclude<
|
|
68
|
+
array(): ModelField<ArrayField<T>, Exclude<UsedMethod, 'required'>>;
|
|
64
69
|
/**
|
|
65
70
|
* Sets a default value for the scalar type.
|
|
66
71
|
* @param value the default value
|
|
67
72
|
*/
|
|
68
|
-
default(value: ModelFieldTypeParamOuter): ModelField<T,
|
|
73
|
+
default(value: ModelFieldTypeParamOuter): ModelField<T, UsedMethod | 'default'>;
|
|
69
74
|
/**
|
|
70
75
|
* Configures field-level authorization rules. Pass in an array of authorizations `(allow => allow.____)` to mix and match
|
|
71
76
|
* multiple authorization rules for this field.
|
|
72
77
|
*/
|
|
73
|
-
authorization<AuthRuleType extends Authorization<any, any, any>>(callback: (allow: Omit<AllowModifier, 'resource'>) => AuthRuleType | AuthRuleType[]): ModelField<T,
|
|
74
|
-
},
|
|
75
|
-
[__auth]?: Auth;
|
|
76
|
-
} & Brand<typeof brandName>;
|
|
78
|
+
authorization<AuthRuleType extends Authorization<any, any, any>>(callback: (allow: Omit<AllowModifier, 'resource'>) => AuthRuleType | AuthRuleType[]): ModelField<T, UsedMethod | 'authorization', AuthRuleType>;
|
|
79
|
+
}, UsedMethod>;
|
|
77
80
|
/**
|
|
78
81
|
* Internal representation of Model Field that exposes the `data` property.
|
|
79
82
|
* Used at buildtime.
|
|
80
83
|
*/
|
|
81
|
-
export
|
|
84
|
+
export interface InternalField extends ModelField {
|
|
82
85
|
data: FieldData;
|
|
83
|
-
}
|
|
86
|
+
}
|
|
84
87
|
/**
|
|
85
88
|
* A unique identifier scalar type. This scalar is serialized like a String but isn't meant to be human-readable.
|
|
86
89
|
* If not specified on create operations, a ULID will be auto-generated service-side.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DerivedApiDefinition, SetTypeSubArg, SchemaConfiguration, DataSourceConfiguration, DatasourceEngine, UnionToIntersection } from '@aws-amplify/data-schema-types';
|
|
2
|
-
import { type
|
|
3
|
-
import type { EnumType
|
|
2
|
+
import { type InternalModel, SchemaModelType, AddRelationshipFieldsToModelTypeFields, type BaseModelType } from './ModelType';
|
|
3
|
+
import type { EnumType } from './EnumType';
|
|
4
4
|
import type { CustomType, CustomTypeParamShape } from './CustomType';
|
|
5
5
|
import type { CustomOperation, CustomOperationParamShape, InternalCustom, MutationCustomOperation, QueryCustomOperation, SubscriptionCustomOperation } from './CustomOperation';
|
|
6
6
|
import { AllowModifier, SchemaAuthorization } from './Authorization';
|
|
@@ -11,7 +11,9 @@ export declare const rdsSchemaBrand: Brand<"RDSSchema">;
|
|
|
11
11
|
export type RDSSchemaBrand = Brand<typeof rdsSchemaBrandName>;
|
|
12
12
|
export declare const ddbSchemaBrandName = "DDBSchema";
|
|
13
13
|
export type DDBSchemaBrand = Brand<typeof ddbSchemaBrandName>;
|
|
14
|
-
type SchemaContent =
|
|
14
|
+
type SchemaContent = BaseModelType | CustomType<CustomTypeParamShape> | EnumType | CustomOperation<CustomOperationParamShape, any>;
|
|
15
|
+
type AddToSchemaContent = Exclude<SchemaContent, BaseModelType>;
|
|
16
|
+
type AddToSchemaContents = Record<string, AddToSchemaContent>;
|
|
15
17
|
type NonEmpty<T> = keyof T extends never ? never : T;
|
|
16
18
|
type ModelSchemaContents = Record<string, SchemaContent>;
|
|
17
19
|
type InternalSchemaModels = Record<string, InternalModel | EnumType<any> | CustomType<any> | InternalCustom>;
|
|
@@ -31,7 +33,7 @@ export type InternalSchema = {
|
|
|
31
33
|
export type BaseSchema<T extends ModelSchemaParamShape, IsRDS extends boolean = false> = {
|
|
32
34
|
data: T;
|
|
33
35
|
models: {
|
|
34
|
-
[TypeKey in keyof T['types']]: T['types'][TypeKey] extends
|
|
36
|
+
[TypeKey in keyof T['types']]: T['types'][TypeKey] extends BaseModelType ? SchemaModelType<T['types'][TypeKey], TypeKey & string, IsRDS> : never;
|
|
35
37
|
};
|
|
36
38
|
transform: () => DerivedApiDefinition;
|
|
37
39
|
};
|
|
@@ -39,10 +41,20 @@ export type GenericModelSchema<T extends ModelSchemaParamShape> = BaseSchema<T>
|
|
|
39
41
|
export type ModelSchema<T extends ModelSchemaParamShape, UsedMethods extends 'authorization' | 'relationships' = never> = Omit<{
|
|
40
42
|
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(callback: (allow: AllowModifier) => AuthRules | AuthRules[]) => ModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'>;
|
|
41
43
|
}, UsedMethods> & BaseSchema<T> & DDBSchemaBrand;
|
|
42
|
-
type RDSModelSchemaFunctions = 'addQueries' | 'addMutations' | 'addSubscriptions' | 'authorization' | 'setRelationships' | 'setAuthorization' | 'renameModelFields' | 'renameModels';
|
|
44
|
+
type RDSModelSchemaFunctions = 'addToSchema' | 'addQueries' | 'addMutations' | 'addSubscriptions' | 'authorization' | 'setRelationships' | 'setAuthorization' | 'renameModelFields' | 'renameModels';
|
|
43
45
|
export type RDSModelSchema<T extends RDSModelSchemaParamShape, UsedMethods extends RDSModelSchemaFunctions = never, RelationshipTemplate extends Record<string, ModelRelationalField<ModelRelationalFieldParamShape, string, any, any>> = Record<string, ModelRelationalField<ModelRelationalFieldParamShape, string, any, any>>> = Omit<{
|
|
46
|
+
addToSchema: <AddedTypes extends AddToSchemaContents>(types: AddedTypes) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & AddedTypes>, UsedMethods | 'addToSchema'>;
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated use `addToSchema()` to add operations to a SQL schema
|
|
49
|
+
*/
|
|
44
50
|
addQueries: <Queries extends Record<string, QueryCustomOperation>>(types: Queries) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Queries>, UsedMethods | 'addQueries'>;
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated use `addToSchema()` to add operations to a SQL schema
|
|
53
|
+
*/
|
|
45
54
|
addMutations: <Mutations extends Record<string, MutationCustomOperation>>(types: Mutations) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Mutations>, UsedMethods | 'addMutations'>;
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated use `addToSchema()` to add operations to a SQL schema
|
|
57
|
+
*/
|
|
46
58
|
addSubscriptions: <Subscriptions extends Record<string, SubscriptionCustomOperation>>(types: Subscriptions) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Subscriptions>, UsedMethods | 'addSubscriptions'>;
|
|
47
59
|
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(callback: (allow: AllowModifier) => AuthRules | AuthRules[]) => RDSModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'>;
|
|
48
60
|
setAuthorization: (callback: (models: BaseSchema<T, true>['models'], schema: RDSModelSchema<T, UsedMethods | 'setAuthorization'>) => void) => RDSModelSchema<T>;
|
package/dist/esm/ModelSchema.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isSchemaModelType } from './ModelType.mjs';
|
|
2
2
|
import { processSchema } from './SchemaProcessor.mjs';
|
|
3
3
|
import { allow } from './Authorization.mjs';
|
|
4
|
-
import { brand } from './util/Brand.mjs';
|
|
4
|
+
import { brand, getBrand } from './util/Brand.mjs';
|
|
5
5
|
|
|
6
6
|
const rdsSchemaBrandName = 'RDSSchema';
|
|
7
7
|
const rdsSchemaBrand = brand(rdsSchemaBrandName);
|
|
@@ -32,6 +32,19 @@ const filterSchemaModelTypes = (schemaContents) => {
|
|
|
32
32
|
const isModelSchema = (schema) => {
|
|
33
33
|
return typeof schema === 'object' && schema.data !== undefined;
|
|
34
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Ensures that only supported entities are being added to the SQL schema through `addToSchema`
|
|
37
|
+
* Models are not supported for brownfield SQL
|
|
38
|
+
*
|
|
39
|
+
* @param types - purposely widened to ModelSchemaContents, because we need to validate at runtime that a model is not being passed in here
|
|
40
|
+
*/
|
|
41
|
+
function validateAddToSchema(types) {
|
|
42
|
+
for (const [name, type] of Object.entries(types)) {
|
|
43
|
+
if (getBrand(type) === 'modelType') {
|
|
44
|
+
throw new Error(`Invalid value specified for ${name} in addToSchema(). Models cannot be manually added to a SQL schema.`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
35
48
|
function _rdsSchema(types, config) {
|
|
36
49
|
const data = {
|
|
37
50
|
types,
|
|
@@ -52,6 +65,12 @@ function _rdsSchema(types, config) {
|
|
|
52
65
|
const { authorization: _, ...rest } = this;
|
|
53
66
|
return rest;
|
|
54
67
|
},
|
|
68
|
+
addToSchema(types) {
|
|
69
|
+
validateAddToSchema(types);
|
|
70
|
+
this.data.types = { ...this.data.types, ...types };
|
|
71
|
+
const { addToSchema: _, ...rest } = this;
|
|
72
|
+
return rest;
|
|
73
|
+
},
|
|
55
74
|
addQueries(types) {
|
|
56
75
|
this.data.types = { ...this.data.types, ...types };
|
|
57
76
|
const { addQueries: _, ...rest } = this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelSchema.mjs","sources":["../../src/ModelSchema.ts"],"sourcesContent":["import { isSchemaModelType, } from './ModelType';\nimport { processSchema } from './SchemaProcessor';\nimport { allow } from './Authorization';\nimport { brand } from './util';\nexport const rdsSchemaBrandName = 'RDSSchema';\nexport const rdsSchemaBrand = brand(rdsSchemaBrandName);\nexport const ddbSchemaBrandName = 'DDBSchema';\nconst ddbSchemaBrand = brand(ddbSchemaBrandName);\n/**\n * Filter the schema types down to only include the ModelTypes as SchemaModelType\n *\n * @param schemaContents The object containing all SchemaContent for this schema\n * @returns Only the schemaContents that are ModelTypes, coerced to the SchemaModelType surface\n */\nconst filterSchemaModelTypes = (schemaContents) => {\n const modelTypes = {};\n if (schemaContents) {\n Object.entries(schemaContents).forEach(([key, content]) => {\n if (isSchemaModelType(content)) {\n modelTypes[key] = content;\n }\n });\n }\n return modelTypes;\n};\n/**\n * Model Schema type guard\n * @param schema - api-next ModelSchema or string\n * @returns true if the given value is a ModelSchema\n */\nexport const isModelSchema = (schema) => {\n return typeof schema === 'object' && schema.data !== undefined;\n};\nfunction _rdsSchema(types, config) {\n const data = {\n types,\n authorization: [],\n configuration: config,\n };\n const models = filterSchemaModelTypes(data.types);\n return {\n data,\n models,\n transform() {\n const internalSchema = { data };\n return processSchema({ schema: internalSchema });\n },\n authorization(callback) {\n const rules = callback(allow);\n this.data.authorization = Array.isArray(rules) ? rules : [rules];\n const { authorization: _, ...rest } = this;\n return rest;\n },\n addQueries(types) {\n this.data.types = { ...this.data.types, ...types };\n const { addQueries: _, ...rest } = this;\n return rest;\n },\n addMutations(types) {\n this.data.types = { ...this.data.types, ...types };\n const { addMutations: _, ...rest } = this;\n return rest;\n },\n addSubscriptions(types) {\n this.data.types = { ...this.data.types, ...types };\n const { addSubscriptions: _, ...rest } = this;\n return rest;\n },\n setAuthorization(callback) {\n callback(models, this);\n const { setAuthorization: _, ...rest } = this;\n return rest;\n },\n setRelationships(callback) {\n const { setRelationships: _, ...rest } = this;\n // The relationships are added via `models.<Model>.relationships`\n // modifiers that's being called within the callback. They are modifying\n // by references on each model, so there is not anything else to be done\n // here.\n callback(models);\n return rest;\n },\n renameModels(callback) {\n const { renameModels: _, ...rest } = this;\n // returns an array of tuples [curName, newName]\n const changeLog = callback();\n changeLog.forEach(([curName, newName]) => {\n const currentType = data.types[curName];\n if (currentType === undefined) {\n throw new Error(`Invalid renameModels call. ${curName} is not defined in the schema`);\n }\n if (typeof newName !== 'string' || newName.length < 1) {\n throw new Error(`Invalid renameModels call. New name must be a non-empty string. Received: \"${newName}\"`);\n }\n models[newName] = currentType;\n data.types[newName] = currentType;\n models[newName].data.originalName = curName;\n delete models[curName];\n delete data.types[curName];\n });\n return rest;\n },\n ...rdsSchemaBrand,\n };\n}\nfunction _ddbSchema(types, config) {\n const data = {\n types,\n authorization: [],\n configuration: config,\n };\n return {\n data,\n transform() {\n const internalSchema = { data };\n return processSchema({ schema: internalSchema });\n },\n authorization(callback) {\n const rules = callback(allow);\n this.data.authorization = Array.isArray(rules) ? rules : [rules];\n const { authorization: _, ...rest } = this;\n return rest;\n },\n models: filterSchemaModelTypes(data.types),\n ...ddbSchemaBrand,\n };\n}\nfunction bindConfigToSchema(config) {\n return (types) => {\n return (config.database.engine === 'dynamodb'\n ? _ddbSchema(types, config)\n : _rdsSchema(types, config));\n };\n}\n/**\n * The API and data model definition for Amplify Data. Pass in `{ <NAME>: a.model(...) }` to create a database table\n * and exposes CRUDL operations via an API.\n * @param types The API and data model definition\n * @returns An API and data model definition to be deployed with Amplify (Gen 2) experience (`processSchema(...)`)\n * or with the Amplify Data CDK construct (`@aws-amplify/data-construct`)\n */\nexport const schema = bindConfigToSchema({ database: { engine: 'dynamodb' } });\n/**\n * Configure wraps schema definition with non-default config to allow usecases other than\n * the default DynamoDB use-case.\n *\n * @param config The SchemaConfig augments the schema with content like the database type\n * @returns\n */\nexport function configure(config) {\n return {\n schema: bindConfigToSchema(config),\n };\n}\nexport function isCustomPathData(obj) {\n return ('stack' in obj &&\n (typeof obj.stack === 'undefined' || typeof obj.stack === 'string') &&\n 'entry' in obj &&\n typeof obj.entry === 'string');\n}\n"],"names":[],"mappings":";;;;;AAIY,MAAC,kBAAkB,GAAG,YAAY;AAClC,MAAC,cAAc,GAAG,KAAK,CAAC,kBAAkB,EAAE;AAC5C,MAAC,kBAAkB,GAAG,YAAY;AAC9C,MAAM,cAAc,GAAG,KAAK,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AAK,EAAE,MAAM,CAAC;AACvC,cAAc,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE;AACzC,KAAK,CAAC;AACN,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE;AAC/E;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,SAAS,CAAC,MAAM,EAAE;AAClC,IAAI,OAAO;AACX,QAAQ,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC;AAC1C,KAAK,CAAC;AACN,CAAC;AACM,SAAS,gBAAgB,CAAC,GAAG,EAAE;AACtC,IAAI,QAAQ,OAAO,IAAI,GAAG;AAC1B,SAAS,OAAO,GAAG,CAAC,KAAK,KAAK,WAAW,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,CAAC;AAC3E,QAAQ,OAAO,IAAI,GAAG;AACtB,QAAQ,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,EAAE;AACvC;;;;"}
|
|
1
|
+
{"version":3,"file":"ModelSchema.mjs","sources":["../../src/ModelSchema.ts"],"sourcesContent":["import { isSchemaModelType, } from './ModelType';\nimport { processSchema } from './SchemaProcessor';\nimport { allow } from './Authorization';\nimport { brand, getBrand } from './util';\nexport const rdsSchemaBrandName = 'RDSSchema';\nexport const rdsSchemaBrand = brand(rdsSchemaBrandName);\nexport const ddbSchemaBrandName = 'DDBSchema';\nconst ddbSchemaBrand = brand(ddbSchemaBrandName);\n/**\n * Filter the schema types down to only include the ModelTypes as SchemaModelType\n *\n * @param schemaContents The object containing all SchemaContent for this schema\n * @returns Only the schemaContents that are ModelTypes, coerced to the SchemaModelType surface\n */\nconst filterSchemaModelTypes = (schemaContents) => {\n const modelTypes = {};\n if (schemaContents) {\n Object.entries(schemaContents).forEach(([key, content]) => {\n if (isSchemaModelType(content)) {\n modelTypes[key] = content;\n }\n });\n }\n return modelTypes;\n};\n/**\n * Model Schema type guard\n * @param schema - api-next ModelSchema or string\n * @returns true if the given value is a ModelSchema\n */\nexport const isModelSchema = (schema) => {\n return typeof schema === 'object' && schema.data !== undefined;\n};\n/**\n * Ensures that only supported entities are being added to the SQL schema through `addToSchema`\n * Models are not supported for brownfield SQL\n *\n * @param types - purposely widened to ModelSchemaContents, because we need to validate at runtime that a model is not being passed in here\n */\nfunction validateAddToSchema(types) {\n for (const [name, type] of Object.entries(types)) {\n if (getBrand(type) === 'modelType') {\n throw new Error(`Invalid value specified for ${name} in addToSchema(). Models cannot be manually added to a SQL schema.`);\n }\n }\n}\nfunction _rdsSchema(types, config) {\n const data = {\n types,\n authorization: [],\n configuration: config,\n };\n const models = filterSchemaModelTypes(data.types);\n return {\n data,\n models,\n transform() {\n const internalSchema = { data };\n return processSchema({ schema: internalSchema });\n },\n authorization(callback) {\n const rules = callback(allow);\n this.data.authorization = Array.isArray(rules) ? rules : [rules];\n const { authorization: _, ...rest } = this;\n return rest;\n },\n addToSchema(types) {\n validateAddToSchema(types);\n this.data.types = { ...this.data.types, ...types };\n const { addToSchema: _, ...rest } = this;\n return rest;\n },\n addQueries(types) {\n this.data.types = { ...this.data.types, ...types };\n const { addQueries: _, ...rest } = this;\n return rest;\n },\n addMutations(types) {\n this.data.types = { ...this.data.types, ...types };\n const { addMutations: _, ...rest } = this;\n return rest;\n },\n addSubscriptions(types) {\n this.data.types = { ...this.data.types, ...types };\n const { addSubscriptions: _, ...rest } = this;\n return rest;\n },\n setAuthorization(callback) {\n callback(models, this);\n const { setAuthorization: _, ...rest } = this;\n return rest;\n },\n setRelationships(callback) {\n const { setRelationships: _, ...rest } = this;\n // The relationships are added via `models.<Model>.relationships`\n // modifiers that's being called within the callback. They are modifying\n // by references on each model, so there is not anything else to be done\n // here.\n callback(models);\n return rest;\n },\n renameModels(callback) {\n const { renameModels: _, ...rest } = this;\n // returns an array of tuples [curName, newName]\n const changeLog = callback();\n changeLog.forEach(([curName, newName]) => {\n const currentType = data.types[curName];\n if (currentType === undefined) {\n throw new Error(`Invalid renameModels call. ${curName} is not defined in the schema`);\n }\n if (typeof newName !== 'string' || newName.length < 1) {\n throw new Error(`Invalid renameModels call. New name must be a non-empty string. Received: \"${newName}\"`);\n }\n models[newName] = currentType;\n data.types[newName] = currentType;\n models[newName].data.originalName = curName;\n delete models[curName];\n delete data.types[curName];\n });\n return rest;\n },\n ...rdsSchemaBrand,\n };\n}\nfunction _ddbSchema(types, config) {\n const data = {\n types,\n authorization: [],\n configuration: config,\n };\n return {\n data,\n transform() {\n const internalSchema = { data };\n return processSchema({ schema: internalSchema });\n },\n authorization(callback) {\n const rules = callback(allow);\n this.data.authorization = Array.isArray(rules) ? rules : [rules];\n const { authorization: _, ...rest } = this;\n return rest;\n },\n models: filterSchemaModelTypes(data.types),\n ...ddbSchemaBrand,\n };\n}\nfunction bindConfigToSchema(config) {\n return (types) => {\n return (config.database.engine === 'dynamodb'\n ? _ddbSchema(types, config)\n : _rdsSchema(types, config));\n };\n}\n/**\n * The API and data model definition for Amplify Data. Pass in `{ <NAME>: a.model(...) }` to create a database table\n * and exposes CRUDL operations via an API.\n * @param types The API and data model definition\n * @returns An API and data model definition to be deployed with Amplify (Gen 2) experience (`processSchema(...)`)\n * or with the Amplify Data CDK construct (`@aws-amplify/data-construct`)\n */\nexport const schema = bindConfigToSchema({ database: { engine: 'dynamodb' } });\n/**\n * Configure wraps schema definition with non-default config to allow usecases other than\n * the default DynamoDB use-case.\n *\n * @param config The SchemaConfig augments the schema with content like the database type\n * @returns\n */\nexport function configure(config) {\n return {\n schema: bindConfigToSchema(config),\n };\n}\nexport function isCustomPathData(obj) {\n return ('stack' in obj &&\n (typeof obj.stack === 'undefined' || typeof obj.stack === 'string') &&\n 'entry' in obj &&\n typeof obj.entry === 'string');\n}\n"],"names":[],"mappings":";;;;;AAIY,MAAC,kBAAkB,GAAG,YAAY;AAClC,MAAC,cAAc,GAAG,KAAK,CAAC,kBAAkB,EAA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I,GAAG;AAC1B,SAAS,OAAO,GAAG,CAAC,KAAK,KAAK,WAAW,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,CAAC;AAC3E,QAAQ,OAAO,IAAI,GAAG;AACtB,QAAQ,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,EAAE;AACvC;;;;"}
|
package/dist/esm/ModelType.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import type { SetTypeSubArg } from '@aws-amplify/data-schema-types';
|
|
2
2
|
import type { PrimaryIndexIrShape, SecondaryIndexIrShape } from './runtime';
|
|
3
|
-
import {
|
|
4
|
-
import type { ModelField, InternalField } from './ModelField';
|
|
3
|
+
import type { InternalField, BaseModelField } from './ModelField';
|
|
5
4
|
import type { ModelRelationalField, InternalRelationalField, ModelRelationalFieldParamShape } from './ModelRelationalField';
|
|
6
5
|
import { type AllowModifier, type Authorization } from './Authorization';
|
|
7
6
|
import type { RefType, RefTypeParamShape } from './RefType';
|
|
8
|
-
import type { EnumType
|
|
7
|
+
import type { EnumType } from './EnumType';
|
|
9
8
|
import type { CustomType, CustomTypeParamShape } from './CustomType';
|
|
10
9
|
import { type ModelIndexType, type InternalModelIndexType } from './ModelIndex';
|
|
11
10
|
import type { PrimaryIndexFieldsToIR, SecondaryIndexToIR } from './MappedTypes/MapIndexes';
|
|
11
|
+
import type { brandSymbol } from './util/Brand.js';
|
|
12
|
+
import type { methodKeyOf } from './util/usedMethods.js';
|
|
12
13
|
declare const brandName = "modelType";
|
|
13
14
|
export type deferredRefResolvingPrefix = 'deferredRefResolving:';
|
|
14
|
-
type ModelFields = Record<string,
|
|
15
|
+
type ModelFields = Record<string, BaseModelField | ModelRelationalField<any, string, any, any> | RefType<any, any, any> | EnumType | CustomType<CustomTypeParamShape>>;
|
|
15
16
|
type InternalModelFields = Record<string, InternalField | InternalRelationalField>;
|
|
16
17
|
type ModelData = {
|
|
17
18
|
fields: ModelFields;
|
|
@@ -47,21 +48,24 @@ export type ModelTypeParamShape = {
|
|
|
47
48
|
* packages/data-schema/src/runtime/client/index.ts
|
|
48
49
|
*/
|
|
49
50
|
export type ExtractSecondaryIndexIRFields<T extends ModelTypeParamShape, RequiredOnly extends boolean = false> = {
|
|
50
|
-
[FieldProp in keyof T['fields'] as T['fields'][FieldProp] extends
|
|
51
|
+
[FieldProp in keyof T['fields'] as T['fields'][FieldProp] extends BaseModelField<infer R> ? NonNullable<R> extends string | number ? RequiredOnly extends false ? FieldProp : null extends R ? never : FieldProp : never : T['fields'][FieldProp] extends EnumType | RefType<RefTypeParamShape, any, any> ? FieldProp : never]: T['fields'][FieldProp] extends BaseModelField<infer R> ? R : T['fields'][FieldProp] extends EnumType<infer values> ? values[number] : T['fields'][FieldProp] extends RefType<infer R, any, any> ? `${deferredRefResolvingPrefix}${R['link']}` : never;
|
|
51
52
|
};
|
|
52
53
|
export type AddRelationshipFieldsToModelTypeFields<Model, RelationshipFields extends Record<string, ModelRelationalField<ModelRelationalFieldParamShape, string, any, any>>> = Model extends ModelType<infer ModelParam extends ModelTypeParamShape, infer HiddenKeys> ? ModelType<SetTypeSubArg<ModelParam, 'fields', ModelParam['fields'] & RelationshipFields>, HiddenKeys> : never;
|
|
53
|
-
export type
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
export type BaseModelType<T extends ModelTypeParamShape = ModelTypeParamShape> = ModelType<T, UsableModelTypeKey>;
|
|
55
|
+
export type UsableModelTypeKey = methodKeyOf<ModelType>;
|
|
56
|
+
export type ModelType<T extends ModelTypeParamShape = ModelTypeParamShape, UsedMethod extends UsableModelTypeKey = never> = Omit<{
|
|
57
|
+
[brandSymbol]: typeof brandName;
|
|
58
|
+
identifier<PrimaryIndexFields = ExtractSecondaryIndexIRFields<T, true>, PrimaryIndexPool extends string = keyof PrimaryIndexFields & string, const ID extends ReadonlyArray<PrimaryIndexPool> = readonly [], const PrimaryIndexIR extends PrimaryIndexIrShape = PrimaryIndexFieldsToIR<ID, PrimaryIndexFields>>(identifier: ID): ModelType<SetTypeSubArg<T, 'identifier', PrimaryIndexIR>, UsedMethod | 'identifier'>;
|
|
59
|
+
secondaryIndexes<const SecondaryIndexFields = ExtractSecondaryIndexIRFields<T>, const SecondaryIndexPKPool extends string = keyof SecondaryIndexFields & string, const Indexes extends readonly ModelIndexType<string, string, unknown, readonly [], any>[] = readonly [], const IndexesIR extends readonly any[] = SecondaryIndexToIR<Indexes, SecondaryIndexFields>>(callback: (index: <PK extends SecondaryIndexPKPool>(pk: PK) => ModelIndexType<SecondaryIndexPKPool, PK, ReadonlyArray<Exclude<SecondaryIndexPKPool, PK>>>) => Indexes): ModelType<SetTypeSubArg<T, 'secondaryIndexes', IndexesIR>, UsedMethod | 'secondaryIndexes'>;
|
|
60
|
+
authorization<AuthRuleType extends Authorization<any, any, any>>(callback: (allow: Omit<AllowModifier, 'resource'>) => AuthRuleType | AuthRuleType[]): ModelType<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, UsedMethod | 'authorization'>;
|
|
61
|
+
}, UsedMethod>;
|
|
58
62
|
/**
|
|
59
63
|
* External representation of Model Type that exposes the `relationships` modifier.
|
|
60
64
|
* Used on the complete schema object.
|
|
61
65
|
*/
|
|
62
|
-
export type SchemaModelType<T extends
|
|
66
|
+
export type SchemaModelType<T extends BaseModelType = ModelType<ModelTypeParamShape, 'identifier'>, ModelName extends string = string, IsRDS extends boolean = false> = IsRDS extends true ? T & {
|
|
63
67
|
relationships<Param extends Record<string, ModelRelationalField<any, string, any, any>> = Record<never, never>>(relationships: Param): Record<ModelName, Param>;
|
|
64
|
-
fields: T extends ModelType<infer R
|
|
68
|
+
fields: T extends ModelType<infer R, any> ? R['fields'] : never;
|
|
65
69
|
} : T;
|
|
66
70
|
/**
|
|
67
71
|
* Internal representation of Model Type that exposes the `data` property.
|
|
@@ -736,7 +736,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
736
736
|
const databaseType = schema.data.configuration.database.engine === 'dynamodb'
|
|
737
737
|
? 'dynamodb'
|
|
738
738
|
: 'sql';
|
|
739
|
-
const staticSchema =
|
|
739
|
+
const staticSchema = databaseType === 'sql';
|
|
740
740
|
const topLevelTypes = sortTopLevelTypes(Object.entries(schema.data.types));
|
|
741
741
|
const { schemaAuth, functionSchemaAccess } = extractFunctionSchemaAccess(schema.data.authorization);
|
|
742
742
|
const getRefType = getRefTypeForSchema(schema);
|
|
@@ -800,9 +800,6 @@ const schemaPreprocessor = (schema) => {
|
|
|
800
800
|
const identifier = typeDef.data.identifier;
|
|
801
801
|
const [partitionKey] = identifier;
|
|
802
802
|
const { authString, authFields } = calculateAuth(mostRelevantAuthRules);
|
|
803
|
-
if (authString == '') {
|
|
804
|
-
throw new Error(`Model \`${typeName}\` is missing authorization rules. Add global rules to the schema or ensure every model has its own rules.`);
|
|
805
|
-
}
|
|
806
803
|
const fieldLevelAuthRules = processFieldLevelAuthRules(fields, authFields);
|
|
807
804
|
validateStaticFields(fields, authFields);
|
|
808
805
|
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, identifier, partitionKey);
|