@aws-amplify/data-schema 1.1.5 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/cjs/util/Brand.js +4 -4
  2. package/dist/cjs/util/Brand.js.map +1 -1
  3. package/dist/cjs/util/usedMethods.js +4 -0
  4. package/dist/cjs/util/usedMethods.js.map +1 -0
  5. package/dist/esm/CustomOperation.d.ts +3 -3
  6. package/dist/esm/CustomType.d.ts +3 -3
  7. package/dist/esm/EnumType.d.ts +7 -9
  8. package/dist/esm/MappedTypes/CustomOperations.d.ts +3 -3
  9. package/dist/esm/MappedTypes/ExtractNonModelTypes.d.ts +4 -4
  10. package/dist/esm/MappedTypes/ResolveFieldProperties.d.ts +2 -2
  11. package/dist/esm/MappedTypes/ResolveSchema.d.ts +6 -6
  12. package/dist/esm/ModelField.d.ts +15 -12
  13. package/dist/esm/ModelSchema.d.ts +4 -4
  14. package/dist/esm/ModelType.d.ts +16 -12
  15. package/dist/esm/util/Brand.d.ts +1 -2
  16. package/dist/esm/util/Brand.mjs +1 -1
  17. package/dist/esm/util/Brand.mjs.map +1 -1
  18. package/dist/esm/util/usedMethods.d.ts +4 -0
  19. package/dist/esm/util/usedMethods.mjs +2 -0
  20. package/dist/esm/util/usedMethods.mjs.map +1 -0
  21. package/dist/meta/cjs.tsbuildinfo +1 -1
  22. package/package.json +1 -1
  23. package/src/CustomOperation.ts +3 -7
  24. package/src/CustomType.ts +4 -8
  25. package/src/EnumType.ts +16 -22
  26. package/src/MappedTypes/CustomOperations.ts +4 -6
  27. package/src/MappedTypes/ExtractNonModelTypes.ts +39 -40
  28. package/src/MappedTypes/ResolveFieldProperties.ts +2 -2
  29. package/src/MappedTypes/ResolveSchema.ts +18 -21
  30. package/src/ModelField.ts +33 -18
  31. package/src/ModelSchema.ts +8 -12
  32. package/src/ModelType.ts +30 -34
  33. package/src/SchemaProcessor.ts +21 -41
  34. package/src/util/Brand.ts +1 -1
  35. package/src/util/usedMethods.ts +5 -0
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getBrand = exports.brand = void 0;
5
- const brandSymbol = Symbol('brand');
4
+ exports.getBrand = exports.brand = exports.brandSymbol = void 0;
5
+ exports.brandSymbol = Symbol('brand');
6
6
  /**
7
7
  * Create an object of a specific type Brand
8
8
  * string branded type.
@@ -18,7 +18,7 @@ const brandSymbol = Symbol('brand');
18
18
  */
19
19
  function brand(brand) {
20
20
  return {
21
- [brandSymbol]: brand,
21
+ [exports.brandSymbol]: brand,
22
22
  };
23
23
  }
24
24
  exports.brand = brand;
@@ -28,7 +28,7 @@ exports.brand = brand;
28
28
  * @returns The string brand value
29
29
  */
30
30
  function getBrand(branded) {
31
- return branded[brandSymbol];
31
+ return branded[exports.brandSymbol];
32
32
  }
33
33
  exports.getBrand = getBrand;
34
34
  //# sourceMappingURL=Brand.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Brand.js","sources":["../../../src/util/Brand.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getBrand = exports.brand = void 0;\nconst brandSymbol = Symbol('brand');\n/**\n * Create an object of a specific type Brand\n * string branded type.\n *\n * @param brand: The string to Brand onto a simple object\n * @returns A branded empty object\n *\n * @example\n * brand('example') => {[brandSymbol]: 'example'}\n *\n * Which I might use like this:\n * const myType = {content: \"default content\", ...brand<'example'>}\n */\nfunction brand(brand) {\n return {\n [brandSymbol]: brand,\n };\n}\nexports.brand = brand;\n/**\n *\n * @param branded: Branded object\n * @returns The string brand value\n */\nfunction getBrand(branded) {\n return branded[brandSymbol];\n}\nexports.getBrand = getBrand;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;AAC1C,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,KAAK,CAAC,KAAK,EAAE;AACtB,IAAI,OAAO;AACX,QAAQ,CAAC,WAAW,GAAG,KAAK;AAC5B,KAAK,CAAC;AACN,CAAC;AACD,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;AACtB;AACA;AACA;AACA;AACA;AACA,SAAS,QAAQ,CAAC,OAAO,EAAE;AAC3B,IAAI,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC;AAChC,CAAC;AACD,OAAO,CAAC,QAAQ,GAAG,QAAQ;;"}
1
+ {"version":3,"file":"Brand.js","sources":["../../../src/util/Brand.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getBrand = exports.brand = exports.brandSymbol = void 0;\nexports.brandSymbol = Symbol('brand');\n/**\n * Create an object of a specific type Brand\n * string branded type.\n *\n * @param brand: The string to Brand onto a simple object\n * @returns A branded empty object\n *\n * @example\n * brand('example') => {[brandSymbol]: 'example'}\n *\n * Which I might use like this:\n * const myType = {content: \"default content\", ...brand<'example'>}\n */\nfunction brand(brand) {\n return {\n [exports.brandSymbol]: brand,\n };\n}\nexports.brand = brand;\n/**\n *\n * @param branded: Branded object\n * @returns The string brand value\n */\nfunction getBrand(branded) {\n return branded[exports.brandSymbol];\n}\nexports.getBrand = getBrand;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,CAAC;AAChE,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,KAAK,CAAC,KAAK,EAAE;AACtB,IAAI,OAAO;AACX,QAAQ,CAAC,OAAO,CAAC,WAAW,GAAG,KAAK;AACpC,KAAK,CAAC;AACN,CAAC;AACD,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;AACtB;AACA;AACA;AACA;AACA;AACA,SAAS,QAAQ,CAAC,OAAO,EAAE;AAC3B,IAAI,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AACxC,CAAC;AACD,OAAO,CAAC,QAAQ,GAAG,QAAQ;;"}
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=usedMethods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usedMethods.js","sources":["../../../src/util/usedMethods.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;;"}
@@ -1,16 +1,16 @@
1
1
  import { SetTypeSubArg } from '@aws-amplify/data-schema-types';
2
2
  import { Brand } from './util';
3
- import { ModelField, InternalField } from './ModelField';
3
+ import { InternalField, type BaseModelField } from './ModelField';
4
4
  import { AllowModifierForCustomOperation, Authorization } from './Authorization';
5
5
  import { RefType, InternalRef } from './RefType';
6
- import { EnumType, EnumTypeParamShape } from './EnumType';
6
+ import { EnumType } from './EnumType';
7
7
  import { CustomType } from './CustomType';
8
8
  import type { CustomHandler, FunctionHandler, HandlerType as Handler } from './Handler';
9
9
  declare const queryBrand = "queryCustomOperation";
10
10
  declare const mutationBrand = "mutationCustomOperation";
11
11
  declare const subscriptionBrand = "subscriptionCustomOperation";
12
12
  type CustomOperationBrand = typeof queryBrand | typeof mutationBrand | typeof subscriptionBrand;
13
- type CustomArguments = Record<string, ModelField<any, any> | EnumType<EnumTypeParamShape>>;
13
+ type CustomArguments = Record<string, BaseModelField | EnumType>;
14
14
  type SubscriptionSource = RefType<any, any>;
15
15
  type InternalSubscriptionSource = InternalRef;
16
16
  type CustomReturnType = RefType<any> | CustomType<any>;
@@ -1,7 +1,7 @@
1
1
  import type { Brand } from './util';
2
- import type { ModelField, InternalField, ModelFieldTypeParamOuter } from './ModelField';
2
+ import type { InternalField, BaseModelField } from './ModelField';
3
3
  import type { RefType } from './RefType';
4
- import type { EnumType, EnumTypeParamShape } from './EnumType';
4
+ import type { EnumType } from './EnumType';
5
5
  /**
6
6
  * Custom Types
7
7
  *
@@ -9,7 +9,7 @@ import type { EnumType, EnumTypeParamShape } from './EnumType';
9
9
  *
10
10
  */
11
11
  export type CustomTypeAllowedModifiers = 'authorization' | 'array' | 'required';
12
- type CustomTypeFields = Record<string, ModelField<ModelFieldTypeParamOuter, CustomTypeAllowedModifiers, any> | RefType<any, any, any> | EnumType<EnumTypeParamShape> | CustomType<CustomTypeParamShape>>;
12
+ type CustomTypeFields = Record<string, BaseModelField | RefType<any, any, any> | EnumType | CustomType<CustomTypeParamShape>>;
13
13
  type InternalModelFields = Record<string, InternalField>;
14
14
  type CustomTypeData = {
15
15
  fields: CustomTypeFields;
@@ -1,15 +1,13 @@
1
- import { Brand } from './util';
2
- export type EnumTypeParamShape = {
1
+ import type { brandSymbol } from './util/Brand.js';
2
+ type EnumTypeParamShape<values extends readonly string[] = readonly string[]> = {
3
3
  type: 'enum';
4
- values: readonly string[];
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<Value extends string, T extends readonly Value[]>(values: T): EnumType<EnumTypeArgFactory<T>>;
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 { ModelField } from '../ModelField';
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 ModelField<infer R, any, any> ? R : never;
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 ModelField<infer R, any, any> ? R : Shape['returnType'] extends CustomType<infer R> ? ResolveFieldRequirements<FieldTypesOfCustomType<{
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, EnumTypeParamShape } from '../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, EnumType<any>>;
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<EnumTypeParamShape> | CustomType<CustomTypeParamShape> ? FieldProp : never]: (x: NonNullable<Fields[FieldProp]> extends infer FieldType ? FieldType extends EnumType<EnumTypeParamShape> ? {
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<EnumTypeParamShape> ? Model : never]: ResolvedSchema[Model] extends EnumType<infer R extends EnumTypeParamShape> ? R['values'][number] : never;
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, EnumTypeParamShape } from '../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<EnumTypeParamShape> ? 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;
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 { ModelField } from '../ModelField';
4
+ import type { BaseModelField } from '../ModelField';
5
5
  import type { CustomType, CustomTypeParamShape } from '../CustomType';
6
- import type { EnumType, EnumTypeParamShape } from '../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<EnumTypeParamShape> | CustomType<CustomTypeParamShape> | CustomOperation<CustomOperationParamShape, any> ? never : Model]: Schema[Model] extends ModelType<infer R, any> ? R['fields'] : never;
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<EnumTypeParamShape> | CustomOperation<CustomOperationParamShape, any> ? never : Model]: Schema[Model] extends ModelType<any, any> ? Schema[Model] : Schema[Model] extends CustomType<CustomTypeParamShape> ? Schema[Model] : never;
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 ModelField<infer R, any, any> ? 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<EnumTypeParamShape> | CustomType<CustomTypeParamShape> ? RefType<{
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 ModelField<infer R, any, any> ? 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<EnumTypeParamShape> | CustomType<CustomTypeParamShape> ? RefType<{
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;
@@ -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 K - union of strings representing already-invoked method names. Used to improve Intellisense
56
+ * @typeParam UsedMethod - union of strings representing already-invoked method names. Used to improve Intellisense
54
57
  */
55
- export type ModelField<T extends ModelFieldTypeParamOuter, K extends keyof ModelField<T> = never, Auth = undefined> = Omit<{
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>, K | 'required'>;
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<K, 'required'> | 'array'>;
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, K | 'default'>;
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, K | 'authorization', AuthRuleType>;
74
- }, K> & {
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 type InternalField = ModelField<ModelFieldTypeParamOuter, never> & {
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 ModelType, type ModelTypeParamShape, type InternalModel, SchemaModelType, AddRelationshipFieldsToModelTypeFields } from './ModelType';
3
- import type { EnumType, EnumTypeParamShape } from './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,7 @@ 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 = ModelType<ModelTypeParamShape, any> | CustomType<CustomTypeParamShape> | EnumType<EnumTypeParamShape> | CustomOperation<CustomOperationParamShape, any>;
14
+ type SchemaContent = BaseModelType | CustomType<CustomTypeParamShape> | EnumType | CustomOperation<CustomOperationParamShape, any>;
15
15
  type NonEmpty<T> = keyof T extends never ? never : T;
16
16
  type ModelSchemaContents = Record<string, SchemaContent>;
17
17
  type InternalSchemaModels = Record<string, InternalModel | EnumType<any> | CustomType<any> | InternalCustom>;
@@ -31,7 +31,7 @@ export type InternalSchema = {
31
31
  export type BaseSchema<T extends ModelSchemaParamShape, IsRDS extends boolean = false> = {
32
32
  data: T;
33
33
  models: {
34
- [TypeKey in keyof T['types']]: T['types'][TypeKey] extends ModelType<ModelTypeParamShape, never | 'identifier'> ? SchemaModelType<T['types'][TypeKey], TypeKey & string, IsRDS> : never;
34
+ [TypeKey in keyof T['types']]: T['types'][TypeKey] extends BaseModelType ? SchemaModelType<T['types'][TypeKey], TypeKey & string, IsRDS> : never;
35
35
  };
36
36
  transform: () => DerivedApiDefinition;
37
37
  };
@@ -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 { type Brand } from './util';
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, EnumTypeParamShape } from './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, ModelField<any, any, any> | ModelRelationalField<any, string, any, any> | RefType<any, any, any> | EnumType<EnumTypeParamShape> | CustomType<CustomTypeParamShape>>;
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 ModelField<infer R, any, any> ? NonNullable<R> extends string | number ? RequiredOnly extends false ? FieldProp : null extends R ? never : FieldProp : never : T['fields'][FieldProp] extends EnumType<EnumTypeParamShape> | RefType<RefTypeParamShape, any, any> ? FieldProp : never]: T['fields'][FieldProp] extends ModelField<infer R, any, any> ? R : T['fields'][FieldProp] extends EnumType<infer R> ? R['values'][number] : T['fields'][FieldProp] extends RefType<infer R, any, any> ? `${deferredRefResolvingPrefix}${R['link']}` : never;
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 ModelType<T extends ModelTypeParamShape, K extends keyof ModelType<T> = never> = Omit<{
54
- 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>, K | 'identifier'>;
55
- 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>, K | 'secondaryIndexes'>;
56
- authorization<AuthRuleType extends Authorization<any, any, any>>(callback: (allow: Omit<AllowModifier, 'resource'>) => AuthRuleType | AuthRuleType[]): ModelType<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, K | 'authorization'>;
57
- }, K> & Brand<typeof brandName>;
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 ModelType<ModelTypeParamShape, never | 'identifier'> = ModelType<ModelTypeParamShape, never | 'identifier'>, ModelName extends string = string, IsRDS extends boolean = false> = IsRDS extends true ? T & {
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 extends ModelTypeParamShape, any> ? R['fields'] : never;
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.
@@ -1,4 +1,4 @@
1
- declare const brandSymbol: unique symbol;
1
+ export declare const brandSymbol: unique symbol;
2
2
  /**
3
3
  * @typeParam BrandStr - String type to brand this object with
4
4
  * @returns A branded empty object type
@@ -32,4 +32,3 @@ export declare function brand<BrandStr extends string>(brand: BrandStr): Brand<B
32
32
  * @returns The string brand value
33
33
  */
34
34
  export declare function getBrand(branded: Brand<string>): string;
35
- export {};
@@ -26,5 +26,5 @@ function getBrand(branded) {
26
26
  return branded[brandSymbol];
27
27
  }
28
28
 
29
- export { brand, getBrand };
29
+ export { brand, brandSymbol, getBrand };
30
30
  //# sourceMappingURL=Brand.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Brand.mjs","sources":["../../../src/util/Brand.ts"],"sourcesContent":["const brandSymbol = Symbol('brand');\n/**\n * Create an object of a specific type Brand\n * string branded type.\n *\n * @param brand: The string to Brand onto a simple object\n * @returns A branded empty object\n *\n * @example\n * brand('example') => {[brandSymbol]: 'example'}\n *\n * Which I might use like this:\n * const myType = {content: \"default content\", ...brand<'example'>}\n */\nexport function brand(brand) {\n return {\n [brandSymbol]: brand,\n };\n}\n/**\n *\n * @param branded: Branded object\n * @returns The string brand value\n */\nexport function getBrand(branded) {\n return branded[brandSymbol];\n}\n"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,CAAC,KAAK,EAAE;AAC7B,IAAI,OAAO;AACX,QAAQ,CAAC,WAAW,GAAG,KAAK;AAC5B,KAAK,CAAC;AACN,CAAC;AACD;AACA;AACA;AACA;AACA;AACO,SAAS,QAAQ,CAAC,OAAO,EAAE;AAClC,IAAI,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC;AAChC;;;;"}
1
+ {"version":3,"file":"Brand.mjs","sources":["../../../src/util/Brand.ts"],"sourcesContent":["export const brandSymbol = Symbol('brand');\n/**\n * Create an object of a specific type Brand\n * string branded type.\n *\n * @param brand: The string to Brand onto a simple object\n * @returns A branded empty object\n *\n * @example\n * brand('example') => {[brandSymbol]: 'example'}\n *\n * Which I might use like this:\n * const myType = {content: \"default content\", ...brand<'example'>}\n */\nexport function brand(brand) {\n return {\n [brandSymbol]: brand,\n };\n}\n/**\n *\n * @param branded: Branded object\n * @returns The string brand value\n */\nexport function getBrand(branded) {\n return branded[brandSymbol];\n}\n"],"names":[],"mappings":"AAAY,MAAC,WAAW,GAAG,MAAM,CAAC,OAAO,EAAE;AAC3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,CAAC,KAAK,EAAE;AAC7B,IAAI,OAAO;AACX,QAAQ,CAAC,WAAW,GAAG,KAAK;AAC5B,KAAK,CAAC;AACN,CAAC;AACD;AACA;AACA;AACA;AACA;AACO,SAAS,QAAQ,CAAC,OAAO,EAAE;AAClC,IAAI,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC;AAChC;;;;"}
@@ -0,0 +1,4 @@
1
+ export type methodKeyOf<o> = {
2
+ [k in keyof o]-?: o[k] extends (...args: never) => unknown ? k : never;
3
+ }[keyof o];
4
+ export type satisfy<base, t extends base> = t;
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=usedMethods.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usedMethods.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}