@aws-amplify/data-schema 0.14.0 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib-esm/src/ClientSchema.d.ts +25 -1
- package/lib-esm/src/CombineSchema.d.ts +18 -0
- package/lib-esm/src/CombineSchema.js +55 -0
- package/lib-esm/src/CustomOperation.d.ts +4 -4
- package/lib-esm/src/MappedTypes/CustomOperations.d.ts +1 -1
- package/lib-esm/src/ModelSchema.d.ts +2 -2
- package/lib-esm/src/index.d.ts +2 -1
- package/lib-esm/src/index.js +3 -1
- package/lib-esm/src/util/IndexLimit.d.ts +7 -0
- package/lib-esm/src/util/IndexLimit.js +2 -0
- package/lib-esm/src/util/SpreadTuple.d.ts +6 -0
- package/lib-esm/src/util/SpreadTuple.js +2 -0
- package/lib-esm/src/util/index.d.ts +2 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -5,7 +5,9 @@ import type { CreateImplicitModelsFromRelations, ResolveFieldProperties, Resolve
|
|
|
5
5
|
import type { ModelIdentifier, ModelSecondaryIndexes, RelationalMetadata } from './MappedTypes/ModelMetadata';
|
|
6
6
|
import type { ExtractNonModelTypes, NonModelTypesShape } from './MappedTypes/ExtractNonModelTypes';
|
|
7
7
|
import { ResolveCustomOperations, CustomOperationHandlerTypes } from './MappedTypes/CustomOperations';
|
|
8
|
-
|
|
8
|
+
import { CombinedModelSchema, CombinedSchemaIndexesUnion } from './CombineSchema';
|
|
9
|
+
import { SpreadTuple } from './util';
|
|
10
|
+
export type ClientSchema<Schema extends GenericModelSchema<any> | CombinedModelSchema<any>> = Schema extends GenericModelSchema<any> ? InternalClientSchema<Schema> : Schema extends CombinedModelSchema<any> ? InternalCombinedSchema<Schema> : never;
|
|
9
11
|
/**
|
|
10
12
|
* Types for unwrapping generic type args into client-consumable types
|
|
11
13
|
*
|
|
@@ -15,8 +17,11 @@ export type ClientSchema<Schema extends GenericModelSchema<any>> = InternalClien
|
|
|
15
17
|
* They should not receive external type args.
|
|
16
18
|
*
|
|
17
19
|
* @internal @typeParam NonModelTypes - Custom Types, Enums, and Custom Operations
|
|
20
|
+
* @internal @typeParam ResolvedSchema - Resolve the schema types used by other generics
|
|
18
21
|
* @internal @typeParam ImplicitModels - The implicit models created to represent relationships
|
|
22
|
+
* @internal @typeParam ImplicitModelsIdentifierMeta - The implicite model identifiers derived from ImplicitModels
|
|
19
23
|
* @internal @typeParam ResolvedFields - Resolved client-facing types used for CRUDL response shapes
|
|
24
|
+
* @internal @typeParam IdentifierMeta - Resolve the identifier fields for all models
|
|
20
25
|
* @internal @typeParam SecondaryIndexes - Map of model secondary index metadata
|
|
21
26
|
*/
|
|
22
27
|
type InternalClientSchema<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape = ExtractNonModelTypes<Schema>, ResolvedSchema = ResolveSchema<Schema>, ImplicitModels = Schema extends RDSModelSchema<any, any> ? object : CreateImplicitModelsFromRelations<ResolvedSchema>, ImplicitModelsIdentifierMeta = {
|
|
@@ -26,4 +31,23 @@ type InternalClientSchema<Schema extends GenericModelSchema<any>, NonModelTypes
|
|
|
26
31
|
}, ResolvedFields extends Record<string, unknown> = Schema extends RDSModelSchema<any, any> ? ResolveStaticFieldProperties<Schema, NonModelTypes, object> : ResolveFieldProperties<Schema, NonModelTypes, ImplicitModels>, IdentifierMeta extends Record<string, any> = ModelIdentifier<SchemaTypes<Schema>>, SecondaryIndexes extends Record<string, any> = Schema extends RDSModelSchema<any, any> ? object : ModelSecondaryIndexes<SchemaTypes<Schema>>> = CustomOperationHandlerTypes<ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>['customOperations']> & ResolvedFields & {
|
|
27
32
|
[__modelMeta__]: IdentifierMeta & ImplicitModelsIdentifierMeta & SecondaryIndexes & RelationalMetadata<ResolvedSchema, ResolvedFields, IdentifierMeta> & NonModelTypes & ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>;
|
|
28
33
|
};
|
|
34
|
+
type GetInternalClientSchema<Schema> = Schema extends GenericModelSchema<any> ? InternalClientSchema<Schema> : never;
|
|
35
|
+
type CombinedClientSchemas<Schemas extends CombinedModelSchema<any>['schemas']> = {
|
|
36
|
+
[Index in keyof Schemas]: Index extends CombinedSchemaIndexesUnion ? GetInternalClientSchema<Schemas[Index]> : never;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Types for unwrapping and combining generic type args into client-consumable types
|
|
40
|
+
* for multiple schemas
|
|
41
|
+
*
|
|
42
|
+
* @typeParam Combined - A container of multiple schemas
|
|
43
|
+
*
|
|
44
|
+
* @internal @typeParam ClientSchemas - The tuple of client schemas to combine
|
|
45
|
+
*/
|
|
46
|
+
type InternalCombinedSchema<Combined extends CombinedModelSchema<any>, ClientSchemas extends [...any] = CombinedClientSchemas<Combined['schemas']>> = SpreadTuple<{
|
|
47
|
+
[I in keyof ClientSchemas]: I extends CombinedSchemaIndexesUnion ? Exclude<ClientSchemas[I], typeof __modelMeta__> : never;
|
|
48
|
+
}> & {
|
|
49
|
+
[__modelMeta__]: SpreadTuple<{
|
|
50
|
+
[I in keyof ClientSchemas]: I extends CombinedSchemaIndexesUnion ? ClientSchemas[I][typeof __modelMeta__] : never;
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
29
53
|
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseSchema, GenericModelSchema } from './ModelSchema';
|
|
2
|
+
import { Brand, IndexLimitUnion } from './util';
|
|
3
|
+
declare const COMBINED_SCHEMA_LIMIT = 50;
|
|
4
|
+
export type CombinedSchemaIndexesUnion = IndexLimitUnion<typeof COMBINED_SCHEMA_LIMIT>[number];
|
|
5
|
+
declare const CombinedSchemaBrandName = "CombinedSchema";
|
|
6
|
+
export declare const combinedSchemaBrand: Brand<"CombinedSchema">;
|
|
7
|
+
export type CombinedSchemaBrand = Brand<typeof CombinedSchemaBrandName>;
|
|
8
|
+
export type CombinedModelSchema<Schemas extends GenericModelSchema<any>[]> = CombinedSchemaBrand & {
|
|
9
|
+
schemas: [...Schemas];
|
|
10
|
+
} & BaseSchema<any>;
|
|
11
|
+
/**
|
|
12
|
+
* The interface for merging up to 50 schemas into a single API.
|
|
13
|
+
* @param schemas The schemas to combine into a single API
|
|
14
|
+
* @returns An API and data model definition to be deployed with Amplify (Gen 2) experience (`processSchema(...)`)
|
|
15
|
+
* or with the Amplify Data CDK construct (`@aws-amplify/data-construct`)
|
|
16
|
+
*/
|
|
17
|
+
export declare function combine<Schema extends GenericModelSchema<any>[]>(schemas: [...Schema]): CombinedModelSchema<Schema>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.combine = exports.combinedSchemaBrand = void 0;
|
|
4
|
+
const util_1 = require("./util");
|
|
5
|
+
const COMBINED_SCHEMA_LIMIT = 50;
|
|
6
|
+
const CombinedSchemaBrandName = 'CombinedSchema';
|
|
7
|
+
exports.combinedSchemaBrand = (0, util_1.brand)(CombinedSchemaBrandName);
|
|
8
|
+
/**
|
|
9
|
+
* The interface for merging up to 50 schemas into a single API.
|
|
10
|
+
* @param schemas The schemas to combine into a single API
|
|
11
|
+
* @returns An API and data model definition to be deployed with Amplify (Gen 2) experience (`processSchema(...)`)
|
|
12
|
+
* or with the Amplify Data CDK construct (`@aws-amplify/data-construct`)
|
|
13
|
+
*/
|
|
14
|
+
function combine(schemas) {
|
|
15
|
+
return internalCombine(schemas);
|
|
16
|
+
}
|
|
17
|
+
exports.combine = combine;
|
|
18
|
+
function internalCombine(schemas) {
|
|
19
|
+
return {
|
|
20
|
+
schemas: schemas,
|
|
21
|
+
data: {
|
|
22
|
+
types: schemas.reduce((prev, schema) => ({ ...prev, ...schema.data.types }), {}),
|
|
23
|
+
},
|
|
24
|
+
models: schemas.reduce((prev, schema) => ({ ...prev, ...schema.models }), {}),
|
|
25
|
+
transform() {
|
|
26
|
+
const baseDefinition = {
|
|
27
|
+
functionSlots: [],
|
|
28
|
+
jsFunctions: [],
|
|
29
|
+
schema: '',
|
|
30
|
+
functionSchemaAccess: [],
|
|
31
|
+
lambdaFunctions: {},
|
|
32
|
+
};
|
|
33
|
+
return schemas.reduce((prev, schema) => {
|
|
34
|
+
const transformedSchema = schema.transform();
|
|
35
|
+
return {
|
|
36
|
+
functionSlots: [
|
|
37
|
+
...prev.functionSlots,
|
|
38
|
+
...transformedSchema.functionSlots,
|
|
39
|
+
],
|
|
40
|
+
jsFunctions: [...prev.jsFunctions, ...transformedSchema.jsFunctions],
|
|
41
|
+
schema: [prev.schema, transformedSchema.schema].join('\n'),
|
|
42
|
+
functionSchemaAccess: [
|
|
43
|
+
...prev.functionSchemaAccess,
|
|
44
|
+
...transformedSchema.functionSchemaAccess,
|
|
45
|
+
],
|
|
46
|
+
lambdaFunctions: {
|
|
47
|
+
...prev.lambdaFunctions,
|
|
48
|
+
...transformedSchema.lambdaFunctions,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}, baseDefinition);
|
|
52
|
+
},
|
|
53
|
+
...exports.combinedSchemaBrand,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -37,7 +37,7 @@ type InternalCustomData = CustomData & {
|
|
|
37
37
|
authorization: Authorization<any, any, any>[];
|
|
38
38
|
};
|
|
39
39
|
export type CustomOperationParamShape = {
|
|
40
|
-
arguments: CustomArguments;
|
|
40
|
+
arguments: CustomArguments | null;
|
|
41
41
|
returnType: CustomReturnType | null;
|
|
42
42
|
functionRef: string | null;
|
|
43
43
|
authorization: Authorization<any, any, any>[];
|
|
@@ -69,7 +69,7 @@ export type InternalCustom<B extends CustomOperationBrand = any> = CustomOperati
|
|
|
69
69
|
};
|
|
70
70
|
export type QueryCustomOperation = CustomOperation<CustomOperationParamShape, any, typeof queryBrand>;
|
|
71
71
|
export declare function query(): CustomOperation<{
|
|
72
|
-
arguments:
|
|
72
|
+
arguments: null;
|
|
73
73
|
returnType: null;
|
|
74
74
|
functionRef: null;
|
|
75
75
|
authorization: [];
|
|
@@ -78,7 +78,7 @@ export declare function query(): CustomOperation<{
|
|
|
78
78
|
}, never, typeof queryBrand>;
|
|
79
79
|
export type MutationCustomOperation = CustomOperation<CustomOperationParamShape, any, typeof mutationBrand>;
|
|
80
80
|
export declare function mutation(): CustomOperation<{
|
|
81
|
-
arguments:
|
|
81
|
+
arguments: null;
|
|
82
82
|
returnType: null;
|
|
83
83
|
functionRef: null;
|
|
84
84
|
authorization: [];
|
|
@@ -87,7 +87,7 @@ export declare function mutation(): CustomOperation<{
|
|
|
87
87
|
}, never, typeof mutationBrand>;
|
|
88
88
|
export type SubscriptionCustomOperation = CustomOperation<CustomOperationParamShape, any, typeof subscriptionBrand>;
|
|
89
89
|
export declare function subscription(): CustomOperation<{
|
|
90
|
-
arguments:
|
|
90
|
+
arguments: null;
|
|
91
91
|
returnType: null;
|
|
92
92
|
functionRef: null;
|
|
93
93
|
authorization: [];
|
|
@@ -28,7 +28,7 @@ export type CustomOpShapes<Schema extends GenericModelSchema<any>> = {
|
|
|
28
28
|
/**
|
|
29
29
|
* Digs out custom operation arguments, mapped to the intended graphql types.
|
|
30
30
|
*/
|
|
31
|
-
export type CustomOpArguments<Shape extends CustomOperationParamShape> = {
|
|
31
|
+
export type CustomOpArguments<Shape extends CustomOperationParamShape> = Shape['arguments'] extends null ? never : {
|
|
32
32
|
[FieldName in keyof Shape['arguments']]: Shape['arguments'][FieldName] extends ModelField<infer R, any, any> ? R : never;
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
@@ -54,14 +54,14 @@ export type InternalSchema = {
|
|
|
54
54
|
configuration: SchemaConfig<any, any>;
|
|
55
55
|
};
|
|
56
56
|
};
|
|
57
|
-
type BaseSchema<T extends ModelSchemaParamShape> = {
|
|
57
|
+
export type BaseSchema<T extends ModelSchemaParamShape> = {
|
|
58
58
|
data: T;
|
|
59
59
|
models: {
|
|
60
60
|
[TypeKey in keyof T['types']]: T['types'][TypeKey] extends ModelType<ModelTypeParamShape> ? SchemaModelType<T['types'][TypeKey]> : never;
|
|
61
61
|
};
|
|
62
62
|
transform: () => DerivedApiDefinition;
|
|
63
63
|
};
|
|
64
|
-
export type GenericModelSchema<T extends ModelSchemaParamShape> = BaseSchema<T> & Brand<
|
|
64
|
+
export type GenericModelSchema<T extends ModelSchemaParamShape> = BaseSchema<T> & Brand<typeof rdsSchemaBrandName | typeof ddbSchemaBrandName>;
|
|
65
65
|
export type ModelSchema<T extends ModelSchemaParamShape, UsedMethods extends 'authorization' = never> = Omit<{
|
|
66
66
|
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(auth: AuthRules[]) => ModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'>;
|
|
67
67
|
}, UsedMethods> & BaseSchema<T> & DDBSchemaBrand;
|
package/lib-esm/src/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { schema } from './ModelSchema';
|
|
2
|
+
import { combine } from './CombineSchema';
|
|
2
3
|
import { model } from './ModelType';
|
|
3
4
|
import { id, string, integer, float, boolean, date, time, datetime, timestamp, email, json, phone, url, ipAddress } from './ModelField';
|
|
4
5
|
import { ref } from './RefType';
|
|
@@ -8,4 +9,4 @@ import { customType } from './CustomType';
|
|
|
8
9
|
import { enumType } from './EnumType';
|
|
9
10
|
import { query, mutation, subscription } from './CustomOperation';
|
|
10
11
|
import { handler } from './Handler';
|
|
11
|
-
export { schema, model, ref, customType, enumType as enum, query, mutation, subscription, hasOne, hasMany, belongsTo, manyToMany, allow, id, string, integer, float, boolean, date, time, datetime, timestamp, email, json, phone, url, ipAddress, handler, };
|
|
12
|
+
export { schema, combine, model, ref, customType, enumType as enum, query, mutation, subscription, hasOne, hasMany, belongsTo, manyToMany, allow, id, string, integer, float, boolean, date, time, datetime, timestamp, email, json, phone, url, ipAddress, handler, };
|
package/lib-esm/src/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handler = 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.allow = exports.manyToMany = exports.belongsTo = exports.hasMany = exports.hasOne = exports.subscription = exports.mutation = exports.query = exports.enum = exports.customType = exports.ref = exports.model = exports.schema = void 0;
|
|
3
|
+
exports.handler = 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.allow = exports.manyToMany = exports.belongsTo = exports.hasMany = exports.hasOne = exports.subscription = exports.mutation = exports.query = exports.enum = exports.customType = exports.ref = exports.model = exports.combine = exports.schema = void 0;
|
|
4
4
|
const ModelSchema_1 = require("./ModelSchema");
|
|
5
5
|
Object.defineProperty(exports, "schema", { enumerable: true, get: function () { return ModelSchema_1.schema; } });
|
|
6
|
+
const CombineSchema_1 = require("./CombineSchema");
|
|
7
|
+
Object.defineProperty(exports, "combine", { enumerable: true, get: function () { return CombineSchema_1.combine; } });
|
|
6
8
|
const ModelType_1 = require("./ModelType");
|
|
7
9
|
Object.defineProperty(exports, "model", { enumerable: true, get: function () { return ModelType_1.model; } });
|
|
8
10
|
const ModelField_1 = require("./ModelField");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a type literal of numbers as index strings
|
|
3
|
+
* The resulting literal will include 0 up to (N - 1)
|
|
4
|
+
*
|
|
5
|
+
* @typeParam N - The number of literal values to include
|
|
6
|
+
*/
|
|
7
|
+
export type IndexLimitUnion<N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : IndexLimitUnion<N, [...Result, `${Result['length']}`]>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform into the type intersection of all items in a given tuple
|
|
3
|
+
*
|
|
4
|
+
* @typeParam T - The tuple of types to spread into a type intersection
|
|
5
|
+
*/
|
|
6
|
+
export type SpreadTuple<T extends readonly any[]> = T extends [infer F] ? F : T extends [infer F, ...infer R] ? F & SpreadTuple<R> : never;
|