Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add exports to build customer declaration files for combine schema #386

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/swift-bees-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"integration-tests": patch
"@aws-amplify/data-schema": patch
---

fix: Add exports for combine schema
2 changes: 1 addition & 1 deletion packages/data-schema/docs/data-schema.a.combine.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The schemas to combine into a single API
</tbody></table>
**Returns:**

CombinedModelSchema&lt;Schema&gt;
[CombinedModelSchema](./data-schema.combinedmodelschema.md)<!-- -->&lt;Schema&gt;

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`<!-- -->)

2 changes: 2 additions & 0 deletions packages/data-schema/docs/data-schema.clientschema.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
```typescript
export type ClientSchema<Schema extends GenericModelSchema<any> | CombinedModelSchema<any>> = Schema extends GenericModelSchema<any> ? InternalClientSchema<Schema> : Schema extends CombinedModelSchema<any> ? InternalCombinedSchema<Schema> : never;
```
**References:** [CombinedModelSchema](./data-schema.combinedmodelschema.md)

15 changes: 15 additions & 0 deletions packages/data-schema/docs/data-schema.combinedmodelschema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@aws-amplify/data-schema](./data-schema.md) &gt; [CombinedModelSchema](./data-schema.combinedmodelschema.md)

## CombinedModelSchema type

CombinedModel schema definition interface

**Signature:**

```typescript
export type CombinedModelSchema<Schemas extends GenericModelSchema<any>[]> = CombinedSchemaBrand & {
schemas: [...Schemas];
};
```
22 changes: 22 additions & 0 deletions packages/data-schema/docs/data-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ Container for authorization schema definition content.
</td><td>


</td></tr>
<tr><td>

[CombinedModelSchema](./data-schema.combinedmodelschema.md)


</td><td>

CombinedModel schema definition interface


</td></tr>
<tr><td>

Expand Down Expand Up @@ -222,6 +233,17 @@ Model type definition interface
Field type arg mutators


</td></tr>
<tr><td>

[RDSModelSchema](./data-schema.rdsmodelschema.md)


</td><td>

RDSModel schema definition interface


</td></tr>
<tr><td>

Expand Down
26 changes: 26 additions & 0 deletions packages/data-schema/docs/data-schema.rdsmodelschema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@aws-amplify/data-schema](./data-schema.md) &gt; [RDSModelSchema](./data-schema.rdsmodelschema.md)

## RDSModelSchema type

RDSModel schema definition interface

**Signature:**

```typescript
export type RDSModelSchema<T extends RDSModelSchemaParamShape, UsedMethods extends RDSModelSchemaFunctions = never> = Omit<{
addToSchema: <AddedTypes extends AddToSchemaContents>(types: AddedTypes) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & AddedTypes>, UsedMethods | 'addToSchema'>;
addQueries: <Queries extends Record<string, QueryCustomOperation>>(types: Queries) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Queries>, UsedMethods | 'addQueries'>;
addMutations: <Mutations extends Record<string, MutationCustomOperation>>(types: Mutations) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Mutations>, UsedMethods | 'addMutations'>;
addSubscriptions: <Subscriptions extends Record<string, SubscriptionCustomOperation>>(types: Subscriptions) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Subscriptions>, UsedMethods | 'addSubscriptions'>;
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(callback: (allow: AllowModifier) => AuthRules | AuthRules[]) => RDSModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'>;
setAuthorization: (callback: (models: OmitFromEach<BaseSchema<T, true>['models'], 'secondaryIndexes'>, schema: RDSModelSchema<T, UsedMethods | 'setAuthorization'>) => void) => RDSModelSchema<T>;
setRelationships: <Relationships extends ReadonlyArray<Partial<Record<keyof T['types'], RelationshipTemplate>>>>(callback: (models: OmitFromEach<BaseSchema<T, true>['models'], 'authorization' | 'fields' | 'secondaryIndexes'>) => Relationships) => RDSModelSchema<SetTypeSubArg<T, 'types', {
[ModelName in keyof T['types']]: ModelWithRelationships<T['types'], Relationships, ModelName>;
}>, UsedMethods | 'setRelationships'>;
renameModels: <NewName extends string, CurName extends string = keyof BaseSchema<T>['models'] & string, const ChangeLog extends readonly [CurName, NewName][] = []>(callback: () => ChangeLog) => RDSModelSchema<SetTypeSubArg<T, 'types', RenameUsingTuples<T['types'], ChangeLog>>, UsedMethods | 'renameModels'>;
}, UsedMethods> & BaseSchema<T, true> & RDSSchemaBrand;
```
**References:** [RDSModelSchema](./data-schema.rdsmodelschema.md)

5 changes: 5 additions & 0 deletions packages/data-schema/src/CombineSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const CombinedSchemaBrandName = 'CombinedSchema';
export const combinedSchemaBrand = brand(CombinedSchemaBrandName);
export type CombinedSchemaBrand = Brand<typeof CombinedSchemaBrandName>;

/**
* CombinedModel schema definition interface
*
* @param Schemas - The schemas to combine into a single API
*/
export type CombinedModelSchema<Schemas extends GenericModelSchema<any>[]> =
CombinedSchemaBrand & { schemas: [...Schemas] };

Expand Down
6 changes: 6 additions & 0 deletions packages/data-schema/src/ModelSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ type RelationshipTemplate = Record<
ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>
>;

/**
* 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,
Expand Down
4 changes: 2 additions & 2 deletions packages/data-schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
27 changes: 27 additions & 0 deletions packages/e2e-tests/exports-test/src/index.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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({
Expand Down
Loading