@aws-amplify/data-schema 0.11.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.
Files changed (42) hide show
  1. package/LICENSE +175 -0
  2. package/NOTICE +1 -0
  3. package/lib-esm/index.d.ts +4 -0
  4. package/lib-esm/index.js +28 -0
  5. package/lib-esm/src/Authorization.d.ts +262 -0
  6. package/lib-esm/src/Authorization.js +309 -0
  7. package/lib-esm/src/ClientSchema.d.ts +27 -0
  8. package/lib-esm/src/ClientSchema.js +3 -0
  9. package/lib-esm/src/CustomType.d.ts +33 -0
  10. package/lib-esm/src/CustomType.js +14 -0
  11. package/lib-esm/src/EnumType.d.ts +15 -0
  12. package/lib-esm/src/EnumType.js +17 -0
  13. package/lib-esm/src/MappedTypes/ExtractNonModelTypes.d.ts +32 -0
  14. package/lib-esm/src/MappedTypes/ExtractNonModelTypes.js +2 -0
  15. package/lib-esm/src/MappedTypes/ForeignKeys.d.ts +83 -0
  16. package/lib-esm/src/MappedTypes/ForeignKeys.js +2 -0
  17. package/lib-esm/src/MappedTypes/ImplicitFieldInjector.d.ts +37 -0
  18. package/lib-esm/src/MappedTypes/ImplicitFieldInjector.js +2 -0
  19. package/lib-esm/src/MappedTypes/ModelMetadata.d.ts +20 -0
  20. package/lib-esm/src/MappedTypes/ModelMetadata.js +2 -0
  21. package/lib-esm/src/MappedTypes/ResolveFieldProperties.d.ts +58 -0
  22. package/lib-esm/src/MappedTypes/ResolveFieldProperties.js +2 -0
  23. package/lib-esm/src/MappedTypes/ResolveSchema.d.ts +35 -0
  24. package/lib-esm/src/MappedTypes/ResolveSchema.js +2 -0
  25. package/lib-esm/src/ModelField.d.ts +158 -0
  26. package/lib-esm/src/ModelField.js +206 -0
  27. package/lib-esm/src/ModelRelationalField.d.ts +106 -0
  28. package/lib-esm/src/ModelRelationalField.js +113 -0
  29. package/lib-esm/src/ModelSchema.d.ts +39 -0
  30. package/lib-esm/src/ModelSchema.js +34 -0
  31. package/lib-esm/src/ModelType.d.ts +107 -0
  32. package/lib-esm/src/ModelType.js +32 -0
  33. package/lib-esm/src/RefType.d.ts +45 -0
  34. package/lib-esm/src/RefType.js +29 -0
  35. package/lib-esm/src/SchemaProcessor.d.ts +10 -0
  36. package/lib-esm/src/SchemaProcessor.js +408 -0
  37. package/lib-esm/src/index.d.ts +9 -0
  38. package/lib-esm/src/index.js +35 -0
  39. package/lib-esm/src/types.d.ts +18 -0
  40. package/lib-esm/src/types.js +8 -0
  41. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  42. package/package.json +39 -0
@@ -0,0 +1,58 @@
1
+ import type { UnionToIntersection, LazyLoader, ExcludeEmpty } from '@aws-amplify/data-schema-types';
2
+ import type { Authorization, ImpliedAuthFields } from '../Authorization';
3
+ import type { ModelField } from '../ModelField';
4
+ import type { ModelType, ModelTypeParamShape } from '../ModelType';
5
+ import type { ModelSchema } from '../ModelSchema';
6
+ import type { ModelRelationalField, ModelRelationalFieldParamShape, ModelRelationalTypeArgFactory } from '../ModelRelationalField';
7
+ import type { AllImpliedFKs } from './ForeignKeys';
8
+ import type { ResolveSchema, SchemaTypes } from './ResolveSchema';
9
+ import type { InjectImplicitModelFields } from './ImplicitFieldInjector';
10
+ import type { ModelIdentifier } from './ModelMetadata';
11
+ import type { RefType, RefTypeParamShape } from '../RefType';
12
+ import type { NonModelTypesShape } from './ExtractNonModelTypes';
13
+ import type { CustomType, CustomTypeParamShape } from '../CustomType';
14
+ import type { EnumType, EnumTypeParamShape } from '../EnumType';
15
+ export type ResolveFieldProperties<Schema extends ModelSchema<any>, NonModelTypes extends NonModelTypesShape, ResolvedSchema = ResolveSchema<Schema>, IdentifierMeta extends Record<string, {
16
+ identifier: string;
17
+ }> = ModelIdentifier<SchemaTypes<Schema>>, FieldsWithInjectedModels = InjectImplicitModels<ResolvedSchema>, FieldsWithInjectedImplicitFields = InjectImplicitModelFields<FieldsWithInjectedModels, IdentifierMeta>, FieldsWithRelationships = ResolveRelationships<FieldsWithInjectedImplicitFields, NonModelTypes>> = Intersection<FilterFieldTypes<RequiredFieldTypes<FieldsWithRelationships>>, FilterFieldTypes<OptionalFieldTypes<FieldsWithRelationships>>, FilterFieldTypes<ModelImpliedAuthFields<Schema>>, AllImpliedFKs<ResolvedSchema, IdentifierMeta>>;
18
+ type ExtractImplicitModelNames<Schema> = UnionToIntersection<ExcludeEmpty<{
19
+ [ModelProp in keyof Schema]: {
20
+ [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]: {
21
+ id?: string;
22
+ } & Record<`${Lowercase<ModelProp & string>}`, ModelRelationalTypeArgFactory<ModelProp & string, 'hasMany', false>>;
23
+ };
24
+ }[keyof Schema]>>;
25
+ type InjectImplicitModels<Schema> = Schema & ExtractImplicitModelNames<Schema>;
26
+ 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']>;
27
+ type ResolveRelationalFieldsForModel<Schema, ModelName extends keyof Schema, Flat extends boolean> = {
28
+ [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];
29
+ };
30
+ type ResolveRef<NonModelTypes extends NonModelTypesShape, Ref extends RefTypeParamShape, Link extends string = Ref['link'], Value = Link extends keyof NonModelTypes['enums'] ? NonModelTypes['enums'][Link] : Link extends keyof NonModelTypes['customTypes'] ? NonModelTypes['customTypes'][Link] : never> = Ref['required'] extends true ? Value : Value | null;
31
+ type ResolveRelationships<Schema, NonModelTypes extends NonModelTypesShape, Flat extends boolean = false> = {
32
+ [ModelProp in keyof Schema]: {
33
+ [FieldProp in keyof Schema[ModelProp]]: Schema[ModelProp][FieldProp] extends RefType<infer R extends RefTypeParamShape, never | 'required' | 'authorization', never | Authorization<any, any>> | null ? ResolveRef<NonModelTypes, R> : Schema[ModelProp][FieldProp] extends ModelRelationalFieldParamShape ? Schema[ModelProp][FieldProp]['relatedModel'] extends keyof Schema ? Schema[ModelProp][FieldProp]['relationshipType'] extends 'manyToMany' ? Schema[ModelProp][FieldProp]['relationName'] extends keyof Schema ? GetRelationshipRef<Schema, Schema[ModelProp][FieldProp]['relationName'], Schema[ModelProp][FieldProp], Flat> : never : GetRelationshipRef<Schema, Schema[ModelProp][FieldProp]['relatedModel'], Schema[ModelProp][FieldProp], Flat> : never : Schema[ModelProp][FieldProp];
34
+ };
35
+ };
36
+ type FilterFieldTypes<Schema> = {
37
+ [ModelProp in keyof Schema]: {
38
+ [FieldProp in keyof Schema[ModelProp] as Schema[ModelProp][FieldProp] extends undefined ? never : FieldProp]: Schema[ModelProp][FieldProp];
39
+ };
40
+ };
41
+ type OptionalFieldTypes<Schema> = {
42
+ [ModelProp in keyof Schema]: Partial<{
43
+ [FieldProp in keyof Schema[ModelProp]]: null extends Schema[ModelProp][FieldProp] ? Schema[ModelProp][FieldProp] : never;
44
+ }>;
45
+ };
46
+ type RequiredFieldTypes<Schema> = {
47
+ [ModelProp in keyof Schema]: {
48
+ [FieldProp in keyof Schema[ModelProp]]: null extends Schema[ModelProp][FieldProp] ? never : Schema[ModelProp][FieldProp];
49
+ };
50
+ };
51
+ type Intersection<A, B, C, D> = A & B & C & D extends infer U ? {
52
+ [P in keyof U]: U[P];
53
+ } : never;
54
+ export type ModelImpliedAuthFields<Schema extends ModelSchema<any>> = {
55
+ [ModelKey in keyof Schema['data']['types'] as Schema['data']['types'][ModelKey] extends EnumType<EnumTypeParamShape> ? never : Schema['data']['types'][ModelKey] extends CustomType<CustomTypeParamShape> ? never : ModelKey]: Schema['data']['types'][ModelKey] extends ModelType<infer Model, any> ? ImpliedAuthFields<Model['authorization'][number]> & ImpliedAuthFieldsFromFields<Model> : object;
56
+ };
57
+ 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> ? ImpliedAuthFields<Auth> : object : object : object>;
58
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,35 @@
1
+ import type { ModelType } from '../ModelType';
2
+ import type { ModelSchema } from '../ModelSchema';
3
+ import type { ModelRelationalField, ModelRelationshipTypes, RelationTypeFunctionOmitMapping } from '../ModelRelationalField';
4
+ import type { ModelField } from '../ModelField';
5
+ import type { CustomType, CustomTypeParamShape } from '../CustomType';
6
+ import type { EnumType, EnumTypeParamShape } from '../EnumType';
7
+ import type { RefType, RefTypeParamShape } from '../RefType';
8
+ import { Authorization } from '../Authorization';
9
+ export type ResolveSchema<Schema> = FieldTypes<ModelTypes<SchemaTypes<Schema>>>;
10
+ export type SchemaTypes<T> = T extends ModelSchema<infer R> ? R['types'] : never;
11
+ /**
12
+ * Resolves model types
13
+ *
14
+ * Removes CustomTypes and Enums from resolved schema.
15
+ * They are extracted separately in ExtractNonModelTypes.ts and
16
+ * added to ModelMeta in ClientSchema.ts
17
+ */
18
+ export type ModelTypes<Schema> = {
19
+ [Model in keyof Schema as Schema[Model] extends EnumType<EnumTypeParamShape> ? never : Schema[Model] extends CustomType<CustomTypeParamShape> ? never : Model]: Schema[Model] extends ModelType<infer R, any> ? R['fields'] : never;
20
+ };
21
+ /**
22
+ * Resolves field types
23
+ *
24
+ * Non-model types are replaced with Refs. Refs remain and are resolved in ResolveFieldProperties.ts
25
+ */
26
+ export type FieldTypes<T> = {
27
+ [ModelProp in keyof T]: {
28
+ [FieldProp in keyof T[ModelProp]]: T[ModelProp][FieldProp] extends RefType<infer R extends RefTypeParamShape, never | 'required' | 'authorization', never | Authorization<any, any>> ? R['required'] extends true ? T[ModelProp][FieldProp] : T[ModelProp][FieldProp] | null : T[ModelProp][FieldProp] extends EnumType<EnumTypeParamShape> | CustomType<CustomTypeParamShape> ? RefType<{
29
+ link: Capitalize<FieldProp & string>;
30
+ type: 'ref';
31
+ required: false;
32
+ authorization: [];
33
+ }> | null : T[ModelProp][FieldProp] extends ModelRelationalField<infer R, string, RelationTypeFunctionOmitMapping<ModelRelationshipTypes>, any> ? R : T[ModelProp][FieldProp] extends ModelField<infer R, any, any> ? R : never;
34
+ };
35
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,158 @@
1
+ import { Authorization } from './Authorization';
2
+ /**
3
+ * Used to "attach" auth types to ModelField without exposing them on the builder.
4
+ */
5
+ export declare const __auth: unique symbol;
6
+ export declare enum ModelFieldType {
7
+ Id = "ID",
8
+ String = "String",
9
+ Integer = "Int",
10
+ Float = "Float",
11
+ Boolean = "Boolean",
12
+ Date = "AWSDate",
13
+ Time = "AWSTime",
14
+ DateTime = "AWSDateTime",
15
+ Timestamp = "AWSTimestamp",
16
+ Email = "AWSEmail",
17
+ JSON = "AWSJSON",
18
+ Phone = "AWSPhone",
19
+ Url = "AWSURL",
20
+ IPAddress = "AWSIPAddress"
21
+ }
22
+ export declare enum ModelFieldDataType {
23
+ String = "string",
24
+ Number = "number",
25
+ Boolean = "boolean",
26
+ Date = "Date",
27
+ JSON = "any"
28
+ }
29
+ type FieldData = {
30
+ fieldType: ModelFieldType;
31
+ required: boolean;
32
+ array: boolean;
33
+ arrayRequired: boolean;
34
+ default: undefined | ModelFieldTypeParamOuter;
35
+ authorization: Authorization<any, any>[];
36
+ };
37
+ type ModelFieldTypeParamInner = string | number | boolean | Date | null;
38
+ export type ModelFieldTypeParamOuter = ModelFieldTypeParamInner | Array<ModelFieldTypeParamInner> | null;
39
+ /**
40
+ * Field type arg mutators
41
+ */
42
+ export type Nullable<T> = T | null;
43
+ export type Required<T> = Exclude<T, null>;
44
+ export type ArrayField<T> = [T] extends [ModelFieldTypeParamInner] ? Array<T> | null : never;
45
+ /**
46
+ * Public API for the chainable builder methods exposed by Model Field.
47
+ * The type is narrowing e.g., after calling .array() it will be omitted from intellisense suggestions
48
+ *
49
+ * @typeParam T - holds the JS data type of the field
50
+ * @typeParam K - union of strings representing already-invoked method names. Used to improve Intellisense
51
+ */
52
+ export type ModelField<T extends ModelFieldTypeParamOuter, K extends keyof ModelField<T> = never, Auth = undefined> = Omit<{
53
+ /**
54
+ * Marks a field as required.
55
+ */
56
+ required(): ModelField<Required<T>, K | 'required'>;
57
+ /**
58
+ * Converts a field type definition to an array of the field type.
59
+ */
60
+ array(): ModelField<ArrayField<T>, Exclude<K, 'required'> | 'array'>;
61
+ /**
62
+ * Sets a default value for the scalar type.
63
+ * @param value the default value
64
+ */
65
+ default(value: ModelFieldTypeParamOuter): ModelField<T, K | 'default'>;
66
+ /**
67
+ * Configures field-level authorization rules. Pass in an array of authorizations `(a.allow.____)` to mix and match
68
+ * multiple authorization rules for this field.
69
+ */
70
+ authorization<AuthRuleType extends Authorization<any, any>>(rules: AuthRuleType[]): ModelField<T, K | 'authorization', AuthRuleType>;
71
+ }, K> & {
72
+ [__auth]?: Auth;
73
+ };
74
+ /**
75
+ * Internal representation of Model Field that exposes the `data` property.
76
+ * Used at buildtime.
77
+ */
78
+ export type InternalField = ModelField<ModelFieldTypeParamOuter, never> & {
79
+ data: FieldData;
80
+ };
81
+ /**
82
+ * A unique identifier scalar type. This scalar is serialized like a String but isn't meant to be human-readable.
83
+ * If not specified on create operations, a ULID will be auto-generated service-side.
84
+ * @returns ID field definition
85
+ */
86
+ export declare function id(): ModelField<Nullable<string>>;
87
+ /**
88
+ * A string scalar type that is represented server-side as a UTF-8 character sequence.
89
+ * @returns string field definition
90
+ */
91
+ export declare function string(): ModelField<Nullable<string>>;
92
+ /**
93
+ * An integer scalar type with a supported value range between -(2^31) and 2^31-1.
94
+ * @returns integer field definition
95
+ */
96
+ export declare function integer(): ModelField<Nullable<number>>;
97
+ /**
98
+ * A float scalar type following represented server-side as an IEEE 754 floating point value.
99
+ * @returns float field definition
100
+ */
101
+ export declare function float(): ModelField<Nullable<number>>;
102
+ /**
103
+ * A boolean scalar type that can be either true or false.
104
+ * @returns boolean field definition
105
+ */
106
+ export declare function boolean(): ModelField<Nullable<boolean>>;
107
+ /**
108
+ * A date scalar type that is represented server-side as an extended ISO 8601 date string in the format `YYYY-MM-DD`.
109
+ * @returns date field definition
110
+ */
111
+ export declare function date(): ModelField<Nullable<string>>;
112
+ /**
113
+ * A time scalar type that is represented server-side as an extended ISO 8601 time string in the format `hh:mm:ss.sss`.
114
+ * @returns time field definition
115
+ */
116
+ export declare function time(): ModelField<Nullable<string>>;
117
+ /**
118
+ * A date time scalar type that is represented server-side as an extended ISO 8601 date and time string in the format `YYYY-MM-DDThh:mm:ss.sssZ`.
119
+ * @returns datetime field definition
120
+ */
121
+ export declare function datetime(): ModelField<Nullable<string>>;
122
+ /**
123
+ * A timestamp scalar type that is represented by an integer value of the number of seconds before or after `1970-01-01-T00:00Z`.
124
+ * @returns timestamp field definition
125
+ */
126
+ export declare function timestamp(): ModelField<Nullable<number>>;
127
+ /**
128
+ * An email scalar type that is represented server-side in the format `local-part@domain-part` as defined by RFC 822.
129
+ * @returns email field definition
130
+ */
131
+ export declare function email(): ModelField<Nullable<string>>;
132
+ /**
133
+ * A JSON scalar type that is automatically parsed and loaded server-side as maps, lists, or scalar values
134
+ * rather than as the literal input strings.
135
+ * @returns JSON field definition
136
+ */
137
+ export declare function json(): ModelField<Nullable<any>>;
138
+ /**
139
+ * A phone number scalar type thas is stored as a string server-side. Phone numbers can contain either spaces
140
+ * or hyphens to separate digit groups. Phone numbers without a country code are assumed to be US/North American numbers adhering
141
+ * to the North American Numbering Plan.
142
+ * @returns phone number field definition
143
+ */
144
+ export declare function phone(): ModelField<Nullable<string>>;
145
+ /**
146
+ * A URL scalar type as defined by RFC 1738. For example, https://www.amazon.com/dp/B000NZW3KC/ or mailto:example@example.com.
147
+ * URLs must contain a schema (http, mailto) and can't contain two forward slashes (//) in the path part.
148
+ * @returns URL field definition
149
+ */
150
+ export declare function url(): ModelField<Nullable<string>>;
151
+ /**
152
+ * A valid IPv4 or IPv6 address scalar type. IPv4 addresses are expected in quad-dotted notation (123.12.34.56). IPv6 addresses
153
+ * are expected in non-bracketed, colon-separated format (1a2b:3c4b:🔢4567). You can include an optional CIDR suffix (123.45.67.89/16)
154
+ * to indicate subnet mask.
155
+ * @returns IP address field definition
156
+ */
157
+ export declare function ipAddress(): ModelField<Nullable<string>>;
158
+ export {};
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ipAddress = exports.url = exports.phone = exports.json = exports.email = exports.timestamp = exports.datetime = exports.time = exports.date = exports.boolean = exports.float = exports.integer = exports.string = exports.id = exports.ModelFieldDataType = exports.ModelFieldType = exports.__auth = void 0;
4
+ /**
5
+ * Used to "attach" auth types to ModelField without exposing them on the builder.
6
+ */
7
+ exports.__auth = Symbol('__auth');
8
+ var ModelFieldType;
9
+ (function (ModelFieldType) {
10
+ ModelFieldType["Id"] = "ID";
11
+ ModelFieldType["String"] = "String";
12
+ ModelFieldType["Integer"] = "Int";
13
+ ModelFieldType["Float"] = "Float";
14
+ ModelFieldType["Boolean"] = "Boolean";
15
+ ModelFieldType["Date"] = "AWSDate";
16
+ ModelFieldType["Time"] = "AWSTime";
17
+ ModelFieldType["DateTime"] = "AWSDateTime";
18
+ ModelFieldType["Timestamp"] = "AWSTimestamp";
19
+ ModelFieldType["Email"] = "AWSEmail";
20
+ ModelFieldType["JSON"] = "AWSJSON";
21
+ ModelFieldType["Phone"] = "AWSPhone";
22
+ ModelFieldType["Url"] = "AWSURL";
23
+ ModelFieldType["IPAddress"] = "AWSIPAddress";
24
+ })(ModelFieldType || (exports.ModelFieldType = ModelFieldType = {}));
25
+ var ModelFieldDataType;
26
+ (function (ModelFieldDataType) {
27
+ ModelFieldDataType["String"] = "string";
28
+ ModelFieldDataType["Number"] = "number";
29
+ ModelFieldDataType["Boolean"] = "boolean";
30
+ ModelFieldDataType["Date"] = "Date";
31
+ ModelFieldDataType["JSON"] = "any";
32
+ })(ModelFieldDataType || (exports.ModelFieldDataType = ModelFieldDataType = {}));
33
+ /**
34
+ * Model Field Implementation
35
+ *
36
+ * @typeParam T - holds the JS data type of the field; invoking the public methods changes this type accordingly
37
+ * @example
38
+ * string() => T = string | null
39
+ * string().array() => T = Array<string | null> | null
40
+ * string().array().required() => T = Array<string | null>
41
+ * string().required().array().required() => T = Array<string>
42
+ *
43
+ * @param fieldType - stores the GraphQL data type of the field
44
+ */
45
+ function _field(fieldType) {
46
+ const _meta = {
47
+ lastInvokedMethod: null,
48
+ };
49
+ const data = {
50
+ fieldType,
51
+ required: false,
52
+ array: false,
53
+ arrayRequired: false,
54
+ default: undefined,
55
+ authorization: [],
56
+ };
57
+ const builder = {
58
+ required() {
59
+ if (_meta.lastInvokedMethod === 'array') {
60
+ data.arrayRequired = true;
61
+ }
62
+ else {
63
+ data.required = true;
64
+ }
65
+ _meta.lastInvokedMethod = 'required';
66
+ return this;
67
+ },
68
+ array() {
69
+ data.array = true;
70
+ _meta.lastInvokedMethod = 'array';
71
+ return this;
72
+ },
73
+ default(val) {
74
+ data.default = val;
75
+ _meta.lastInvokedMethod = 'default';
76
+ return this;
77
+ },
78
+ authorization(rules) {
79
+ data.authorization = rules;
80
+ _meta.lastInvokedMethod = 'authorization';
81
+ return this;
82
+ },
83
+ };
84
+ // this double cast gives us a Subtyping Constraint i.e., hides `data` from the public API,
85
+ // but makes it available internally when needed
86
+ return { ...builder, data };
87
+ }
88
+ /**
89
+ * A unique identifier scalar type. This scalar is serialized like a String but isn't meant to be human-readable.
90
+ * If not specified on create operations, a ULID will be auto-generated service-side.
91
+ * @returns ID field definition
92
+ */
93
+ function id() {
94
+ return _field(ModelFieldType.Id);
95
+ }
96
+ exports.id = id;
97
+ /**
98
+ * A string scalar type that is represented server-side as a UTF-8 character sequence.
99
+ * @returns string field definition
100
+ */
101
+ function string() {
102
+ return _field(ModelFieldType.String);
103
+ }
104
+ exports.string = string;
105
+ /**
106
+ * An integer scalar type with a supported value range between -(2^31) and 2^31-1.
107
+ * @returns integer field definition
108
+ */
109
+ function integer() {
110
+ return _field(ModelFieldType.Integer);
111
+ }
112
+ exports.integer = integer;
113
+ /**
114
+ * A float scalar type following represented server-side as an IEEE 754 floating point value.
115
+ * @returns float field definition
116
+ */
117
+ function float() {
118
+ return _field(ModelFieldType.Float);
119
+ }
120
+ exports.float = float;
121
+ /**
122
+ * A boolean scalar type that can be either true or false.
123
+ * @returns boolean field definition
124
+ */
125
+ function boolean() {
126
+ return _field(ModelFieldType.Boolean);
127
+ }
128
+ exports.boolean = boolean;
129
+ /**
130
+ * A date scalar type that is represented server-side as an extended ISO 8601 date string in the format `YYYY-MM-DD`.
131
+ * @returns date field definition
132
+ */
133
+ function date() {
134
+ return _field(ModelFieldType.Date);
135
+ }
136
+ exports.date = date;
137
+ /**
138
+ * A time scalar type that is represented server-side as an extended ISO 8601 time string in the format `hh:mm:ss.sss`.
139
+ * @returns time field definition
140
+ */
141
+ function time() {
142
+ return _field(ModelFieldType.Time);
143
+ }
144
+ exports.time = time;
145
+ /**
146
+ * A date time scalar type that is represented server-side as an extended ISO 8601 date and time string in the format `YYYY-MM-DDThh:mm:ss.sssZ`.
147
+ * @returns datetime field definition
148
+ */
149
+ function datetime() {
150
+ return _field(ModelFieldType.DateTime);
151
+ }
152
+ exports.datetime = datetime;
153
+ /**
154
+ * A timestamp scalar type that is represented by an integer value of the number of seconds before or after `1970-01-01-T00:00Z`.
155
+ * @returns timestamp field definition
156
+ */
157
+ function timestamp() {
158
+ return _field(ModelFieldType.Timestamp);
159
+ }
160
+ exports.timestamp = timestamp;
161
+ /**
162
+ * An email scalar type that is represented server-side in the format `local-part@domain-part` as defined by RFC 822.
163
+ * @returns email field definition
164
+ */
165
+ function email() {
166
+ return _field(ModelFieldType.Email);
167
+ }
168
+ exports.email = email;
169
+ /**
170
+ * A JSON scalar type that is automatically parsed and loaded server-side as maps, lists, or scalar values
171
+ * rather than as the literal input strings.
172
+ * @returns JSON field definition
173
+ */
174
+ function json() {
175
+ return _field(ModelFieldType.JSON);
176
+ }
177
+ exports.json = json;
178
+ /**
179
+ * A phone number scalar type thas is stored as a string server-side. Phone numbers can contain either spaces
180
+ * or hyphens to separate digit groups. Phone numbers without a country code are assumed to be US/North American numbers adhering
181
+ * to the North American Numbering Plan.
182
+ * @returns phone number field definition
183
+ */
184
+ function phone() {
185
+ return _field(ModelFieldType.Phone);
186
+ }
187
+ exports.phone = phone;
188
+ /**
189
+ * A URL scalar type as defined by RFC 1738. For example, https://www.amazon.com/dp/B000NZW3KC/ or mailto:example@example.com.
190
+ * URLs must contain a schema (http, mailto) and can't contain two forward slashes (//) in the path part.
191
+ * @returns URL field definition
192
+ */
193
+ function url() {
194
+ return _field(ModelFieldType.Url);
195
+ }
196
+ exports.url = url;
197
+ /**
198
+ * A valid IPv4 or IPv6 address scalar type. IPv4 addresses are expected in quad-dotted notation (123.12.34.56). IPv6 addresses
199
+ * are expected in non-bracketed, colon-separated format (1a2b:3c4b:🔢4567). You can include an optional CIDR suffix (123.45.67.89/16)
200
+ * to indicate subnet mask.
201
+ * @returns IP address field definition
202
+ */
203
+ function ipAddress() {
204
+ return _field(ModelFieldType.IPAddress);
205
+ }
206
+ exports.ipAddress = ipAddress;
@@ -0,0 +1,106 @@
1
+ import { SetTypeSubArg } from '@aws-amplify/data-schema-types';
2
+ import { Authorization } from './Authorization';
3
+ /**
4
+ * Used to "attach" auth types to ModelField without exposing them on the builder.
5
+ */
6
+ export declare const __auth: unique symbol;
7
+ export declare enum ModelRelationshipTypes {
8
+ hasOne = "hasOne",
9
+ hasMany = "hasMany",
10
+ belongsTo = "belongsTo",
11
+ manyToMany = "manyToMany"
12
+ }
13
+ type RelationshipTypes = `${ModelRelationshipTypes}`;
14
+ type ModelRelationalFieldData = {
15
+ fieldType: 'model';
16
+ type: ModelRelationshipTypes;
17
+ relatedModel: string;
18
+ array: boolean;
19
+ valueRequired: boolean;
20
+ arrayRequired: boolean;
21
+ relationName?: string;
22
+ authorization: Authorization<any, any>[];
23
+ };
24
+ export type ModelRelationalFieldParamShape = {
25
+ type: 'model';
26
+ relationshipType: string;
27
+ relatedModel: string;
28
+ array: boolean;
29
+ valueRequired: boolean;
30
+ arrayRequired: boolean;
31
+ relationName?: string;
32
+ };
33
+ export type ModelRelationalField<T extends ModelRelationalFieldParamShape, RM extends string | symbol, K extends keyof ModelRelationalField<T, RM> = never, Auth = undefined> = Omit<{
34
+ /**
35
+ * When set, it requires the value of the relationship type to be required.
36
+ */
37
+ valueRequired(): ModelRelationalField<SetTypeSubArg<T, 'valueRequired', true>, K | 'valueRequired'>;
38
+ /**
39
+ * When set, it requires the relationship to always return a value
40
+ */
41
+ required(): ModelRelationalField<SetTypeSubArg<T, 'arrayRequired', true>, K | 'required'>;
42
+ /**
43
+ * When set, it requires the relationship to always return an array value
44
+ */
45
+ arrayRequired(): ModelRelationalField<SetTypeSubArg<T, 'arrayRequired', true>, K | 'arrayRequired'>;
46
+ /**
47
+ * Configures field-level authorization rules. Pass in an array of authorizations `(a.allow.____)` to mix and match
48
+ * multiple authorization rules for this field.
49
+ */
50
+ authorization<AuthRuleType extends Authorization<any, any>>(rules: AuthRuleType[]): ModelRelationalField<T, K | 'authorization', K, AuthRuleType>;
51
+ }, K> & {
52
+ [__auth]?: Auth;
53
+ };
54
+ /**
55
+ * Internal representation of Model Field that exposes the `data` property.
56
+ * Used at buildtime.
57
+ */
58
+ export type InternalRelationalField = ModelRelationalField<ModelRelationalFieldParamShape, string, never> & {
59
+ data: ModelRelationalFieldData;
60
+ };
61
+ export type RelationTypeFunctionOmitMapping<Type extends ModelRelationshipTypes> = Type extends ModelRelationshipTypes.belongsTo ? 'required' | 'arrayRequired' | 'valueRequired' : Type extends ModelRelationshipTypes.hasMany ? 'required' : Type extends ModelRelationshipTypes.hasOne ? 'arrayRequired' | 'valueRequired' : Type extends ModelRelationshipTypes.manyToMany ? 'required' : never;
62
+ export type ModelRelationalTypeArgFactory<RM extends string, RT extends RelationshipTypes, IsArray extends boolean, RelationName extends string | undefined = undefined> = {
63
+ type: 'model';
64
+ relatedModel: RM;
65
+ relationshipType: RT;
66
+ array: IsArray;
67
+ valueRequired: false;
68
+ arrayRequired: false;
69
+ relationName: RelationName;
70
+ };
71
+ /**
72
+ * Create a one-directional one-to-one relationship between two models using the `hasOne("MODEL_NAME")` method.
73
+ * A hasOne relationship always uses a reference to the related model's identifier. Typically this is the `id` field
74
+ * unless overwritten with the `identifier()` method.
75
+ * @param relatedModel the name of the related model
76
+ * @returns a one-to-one relationship definition
77
+ */
78
+ export declare function hasOne<RM extends string>(relatedModel: RM): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.hasOne, false, undefined>, RM, "valueRequired" | "arrayRequired", undefined>;
79
+ /**
80
+ * Create a one-directional one-to-many relationship between two models using the `hasMany()` method.
81
+ * @param relatedModel the name of the related model
82
+ * @returns a one-to-many relationship definition
83
+ */
84
+ export declare function hasMany<RM extends string>(relatedModel: RM): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.hasMany, true, undefined>, RM, "required", undefined>;
85
+ /**
86
+ * Make a `hasOne()` or `hasMany()` relationship bi-directional using the `belongsTo()` method.
87
+ * The belongsTo() method requires that a hasOne() or hasMany() relationship already exists from
88
+ * parent to the related model.
89
+ * @param relatedModel name of the related `.hasOne()` or `.hasMany()` model
90
+ * @returns a belong-to relationship definition
91
+ */
92
+ export declare function belongsTo<RM extends string>(relatedModel: RM): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.belongsTo, false, undefined>, RM, "required" | "valueRequired" | "arrayRequired", undefined>;
93
+ /**
94
+ * Create a many-to-many relationship between two models with the manyToMany() method.
95
+ * Provide a common relationName on both models to join them into a many-to-many relationship.
96
+ * Under the hood a many-to-many relationship is modeled with a "join table" with corresponding
97
+ * `hasMany()` relationships between the two related models. You must set the same `manyToMany()`
98
+ * field on both models of the relationship.
99
+ * @param relatedModel name of the related model
100
+ * @param opts pass in the `relationName` that will serve as the join table name for this many-to-many relationship
101
+ * @returns a many-to-many relationship definition
102
+ */
103
+ export declare function manyToMany<RM extends string, RN extends string>(relatedModel: RM, opts: {
104
+ relationName: RN;
105
+ }): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.manyToMany, true, RN>, RM, "required", undefined>;
106
+ export {};