diff --git a/.changeset/swift-bees-rescue.md b/.changeset/swift-bees-rescue.md new file mode 100644 index 000000000..496647528 --- /dev/null +++ b/.changeset/swift-bees-rescue.md @@ -0,0 +1,6 @@ +--- +"integration-tests": patch +"@aws-amplify/data-schema": patch +--- + +fix: Add exports for combine schema diff --git a/packages/data-schema/docs/data-schema.a.combine.md b/packages/data-schema/docs/data-schema.a.combine.md index ffe863e97..5830eb5f1 100644 --- a/packages/data-schema/docs/data-schema.a.combine.md +++ b/packages/data-schema/docs/data-schema.a.combine.md @@ -49,7 +49,7 @@ The schemas to combine into a single API **Returns:** -CombinedModelSchema<Schema> +[CombinedModelSchema](./data-schema.combinedmodelschema.md)<Schema> An API and data model definition to be deployed with Amplify (Gen 2) experience (`processSchema(...)`) or with the Amplify Data CDK construct (`@aws-amplify/data-construct`) diff --git a/packages/data-schema/docs/data-schema.clientschema.md b/packages/data-schema/docs/data-schema.clientschema.md index 413b1e99a..fb2f5ff88 100644 --- a/packages/data-schema/docs/data-schema.clientschema.md +++ b/packages/data-schema/docs/data-schema.clientschema.md @@ -9,3 +9,5 @@ ```typescript export type ClientSchema | CombinedModelSchema> = Schema extends GenericModelSchema ? InternalClientSchema : Schema extends CombinedModelSchema ? InternalCombinedSchema : never; ``` +**References:** [CombinedModelSchema](./data-schema.combinedmodelschema.md) + diff --git a/packages/data-schema/docs/data-schema.combinedmodelschema.md b/packages/data-schema/docs/data-schema.combinedmodelschema.md new file mode 100644 index 000000000..e5281972b --- /dev/null +++ b/packages/data-schema/docs/data-schema.combinedmodelschema.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [@aws-amplify/data-schema](./data-schema.md) > [CombinedModelSchema](./data-schema.combinedmodelschema.md) + +## CombinedModelSchema type + +CombinedModel schema definition interface + +**Signature:** + +```typescript +export type CombinedModelSchema[]> = CombinedSchemaBrand & { + schemas: [...Schemas]; +}; +``` diff --git a/packages/data-schema/docs/data-schema.md b/packages/data-schema/docs/data-schema.md index 308c2293d..ec01c8b59 100644 --- a/packages/data-schema/docs/data-schema.md +++ b/packages/data-schema/docs/data-schema.md @@ -112,6 +112,17 @@ Container for authorization schema definition content. + + + +[CombinedModelSchema](./data-schema.combinedmodelschema.md) + + + + +CombinedModel schema definition interface + + @@ -222,6 +233,17 @@ Model type definition interface Field type arg mutators + + + +[RDSModelSchema](./data-schema.rdsmodelschema.md) + + + + +RDSModel schema definition interface + + diff --git a/packages/data-schema/docs/data-schema.rdsmodelschema.md b/packages/data-schema/docs/data-schema.rdsmodelschema.md new file mode 100644 index 000000000..25c7d69ee --- /dev/null +++ b/packages/data-schema/docs/data-schema.rdsmodelschema.md @@ -0,0 +1,26 @@ + + +[Home](./index.md) > [@aws-amplify/data-schema](./data-schema.md) > [RDSModelSchema](./data-schema.rdsmodelschema.md) + +## RDSModelSchema type + +RDSModel schema definition interface + +**Signature:** + +```typescript +export type RDSModelSchema = Omit<{ + addToSchema: (types: AddedTypes) => RDSModelSchema, UsedMethods | 'addToSchema'>; + addQueries: >(types: Queries) => RDSModelSchema, UsedMethods | 'addQueries'>; + addMutations: >(types: Mutations) => RDSModelSchema, UsedMethods | 'addMutations'>; + addSubscriptions: >(types: Subscriptions) => RDSModelSchema, UsedMethods | 'addSubscriptions'>; + authorization: >(callback: (allow: AllowModifier) => AuthRules | AuthRules[]) => RDSModelSchema, UsedMethods | 'authorization'>; + setAuthorization: (callback: (models: OmitFromEach['models'], 'secondaryIndexes'>, schema: RDSModelSchema) => void) => RDSModelSchema; + setRelationships: >>>(callback: (models: OmitFromEach['models'], 'authorization' | 'fields' | 'secondaryIndexes'>) => Relationships) => RDSModelSchema; + }>, UsedMethods | 'setRelationships'>; + renameModels: ['models'] & string, const ChangeLog extends readonly [CurName, NewName][] = []>(callback: () => ChangeLog) => RDSModelSchema>, UsedMethods | 'renameModels'>; +}, UsedMethods> & BaseSchema & RDSSchemaBrand; +``` +**References:** [RDSModelSchema](./data-schema.rdsmodelschema.md) + diff --git a/packages/data-schema/src/CombineSchema.ts b/packages/data-schema/src/CombineSchema.ts index 97d74716d..d8c71f20f 100644 --- a/packages/data-schema/src/CombineSchema.ts +++ b/packages/data-schema/src/CombineSchema.ts @@ -11,6 +11,11 @@ const CombinedSchemaBrandName = 'CombinedSchema'; export const combinedSchemaBrand = brand(CombinedSchemaBrandName); export type CombinedSchemaBrand = Brand; +/** + * CombinedModel schema definition interface + * + * @param Schemas - The schemas to combine into a single API + */ export type CombinedModelSchema[]> = CombinedSchemaBrand & { schemas: [...Schemas] }; diff --git a/packages/data-schema/src/ModelSchema.ts b/packages/data-schema/src/ModelSchema.ts index 4d88eee2e..7ce78a52f 100644 --- a/packages/data-schema/src/ModelSchema.ts +++ b/packages/data-schema/src/ModelSchema.ts @@ -147,6 +147,12 @@ type RelationshipTemplate = Record< ModelRelationshipField >; +/** + * RDSModel schema definition interface + * + * @param T - The shape of the RDS model schema + * @param UsedMethods - The method keys already defined + */ export type RDSModelSchema< T extends RDSModelSchemaParamShape, UsedMethods extends RDSModelSchemaFunctions = never, diff --git a/packages/data-schema/src/index.ts b/packages/data-schema/src/index.ts index 654f01421..e2b485985 100644 --- a/packages/data-schema/src/index.ts +++ b/packages/data-schema/src/index.ts @@ -4,11 +4,11 @@ import { ClientSchema } from './ClientSchema'; export { a }; export type { ClientSchema }; - +export type {CombinedModelSchema} from './CombineSchema'; export type { Authorization } from './Authorization'; export type { CustomOperation } from './CustomOperation'; export type { ModelField, Nullable, Json } from './ModelField'; -export type { ModelSchema } from './ModelSchema'; +export type { ModelSchema, RDSModelSchema} from './ModelSchema'; export type { ModelType, ModelDefaultIdentifier } from './ModelType'; export type { RefType } from './RefType'; export type { CustomType } from './CustomType'; diff --git a/packages/e2e-tests/exports-test/src/index.ts b/packages/e2e-tests/exports-test/src/index.ts index 7e1d70666..867093d6e 100644 --- a/packages/e2e-tests/exports-test/src/index.ts +++ b/packages/e2e-tests/exports-test/src/index.ts @@ -1,4 +1,5 @@ import { a, defineFunction } from '@aws-amplify/backend'; +import { configure } from '@aws-amplify/data-schema/internals'; const defFunc = defineFunction({ entry: './handlers/test-handler.ts', @@ -35,6 +36,32 @@ export function buildDefaultSchema() { }); } +const fakeSecret = () => ({}) as any; +const datasourceConfigMySQL = { + engine: 'mysql', + connectionUri: fakeSecret(), +} as const; + +export function buildCombineSchema() { + const schemaA = a.schema({ + Todo: a + .model({ + content: a.string(), + }) + .authorization((allow) => [allow.guest()]), + }); + const sqlSchema = configure({ database: datasourceConfigMySQL }).schema({ + post: a + .model({ + id: a.string().required(), + title: a.string(), + author: a.string(), + }) + .identifier(['id']), + }); + return a.combine([schemaA, sqlSchema]) +} + export function buildComplicatedSchema() { return a .schema({