Skip to content

Commit

Permalink
Merge pull request #53 from aws-amplify/tb-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
david-mcafee authored Nov 11, 2023
2 parents 19391ae + 7d9ec1c commit 8c653be
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-clocks-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/data-schema-types': minor
---

add types for custom headers
68 changes: 59 additions & 9 deletions packages/data-schema-types/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,12 @@ export type LazyLoader<Model, IsArray extends boolean> = (
authToken?: string;
limit?: number;
nextToken?: string | null;
headers?: CustomHeaders;
}
: {
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
) => IsArray extends true
? ListReturnValue<Prettify<Model>>
Expand Down Expand Up @@ -454,17 +456,29 @@ type ModelTypesClient<
> = {
create: (
model: Prettify<MutationInput<Model, ModelMeta>>,
options?: { authMode?: AuthMode; authToken?: string },
options?: {
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
) => SingularReturnValue<Model>;
update: (
model: Prettify<
ModelIdentifier<ModelMeta> & Partial<MutationInput<Model, ModelMeta>>
>,
options?: { authMode?: AuthMode; authToken?: string },
options?: {
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
) => SingularReturnValue<Model>;
delete: (
identifier: ModelIdentifier<ModelMeta>,
options?: { authMode?: AuthMode; authToken?: string },
options?: {
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
) => SingularReturnValue<Model>;
get<
FlatModel extends Record<string, unknown> = ResolvedModel<Model>,
Expand All @@ -475,6 +489,7 @@ type ModelTypesClient<
selectionSet?: SelectionSet;
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
): SingularReturnValue<ReturnValue<Model, FlatModel, SelectionSet>>;
list<
Expand All @@ -487,6 +502,7 @@ type ModelTypesClient<
selectionSet?: SelectionSet;
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
}): ListReturnValue<ReturnValue<Model, FlatModel, SelectionSet>>;
onCreate<
FlatModel extends Record<string, unknown> = ResolvedModel<Model>,
Expand Down Expand Up @@ -530,17 +546,29 @@ type ModelTypesSSRCookies<
> = {
create: (
model: Prettify<MutationInput<Model, ModelMeta>>,
options?: { authMode?: AuthMode; authToken?: string },
options?: {
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
) => SingularReturnValue<Model>;
update: (
model: Prettify<
ModelIdentifier<ModelMeta> & Partial<MutationInput<Model, ModelMeta>>
>,
options?: { authMode?: AuthMode; authToken?: string },
options?: {
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
) => SingularReturnValue<Model>;
delete: (
identifier: ModelIdentifier<ModelMeta>,
options?: { authMode?: AuthMode; authToken?: string },
options?: {
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
) => SingularReturnValue<Model>;
get<
FlatModel extends Record<string, unknown> = ResolvedModel<Model>,
Expand All @@ -551,6 +579,7 @@ type ModelTypesSSRCookies<
selectionSet?: SelectionSet;
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
): SingularReturnValue<ReturnValue<Model, FlatModel, SelectionSet>>;
list<
Expand All @@ -563,6 +592,7 @@ type ModelTypesSSRCookies<
selectionSet?: SelectionSet;
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
}): ListReturnValue<ReturnValue<Model, FlatModel, SelectionSet>>;
};

Expand All @@ -574,19 +604,31 @@ type ModelTypesSSRRequest<
// TODO: actual type
contextSpec: any,
model: Prettify<MutationInput<Model, ModelMeta>>,
options?: { authMode?: AuthMode; authToken?: string },
options?: {
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
) => SingularReturnValue<Model>;
update: (
contextSpec: any,
model: Prettify<
ModelIdentifier<ModelMeta> & Partial<MutationInput<Model, ModelMeta>>
>,
options?: { authMode?: AuthMode; authToken?: string },
options?: {
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
) => SingularReturnValue<Model>;
delete: (
contextSpec: any,
identifier: ModelIdentifier<ModelMeta>,
options?: { authMode?: AuthMode; authToken?: string },
options?: {
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
) => SingularReturnValue<Model>;
get<
FlatModel extends Record<string, unknown> = ResolvedModel<Model>,
Expand All @@ -598,6 +640,7 @@ type ModelTypesSSRRequest<
selectionSet?: SelectionSet;
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
): SingularReturnValue<ReturnValue<Model, FlatModel, SelectionSet>>;
list<
Expand All @@ -612,6 +655,7 @@ type ModelTypesSSRRequest<
selectionSet?: SelectionSet;
authMode?: AuthMode;
authToken?: string;
headers?: CustomHeaders;
},
): ListReturnValue<ReturnValue<Model, FlatModel, SelectionSet>>;
};
Expand All @@ -635,3 +679,9 @@ export type ModelTypes<
: never
: never;
};

/**
* Custom headers that can be passed either to the client or to individual
* calls, either as a static object or a function that returns a promise.
*/
export type CustomHeaders = Record<string, string> | (() => Promise<Headers>);
6 changes: 6 additions & 0 deletions packages/data-schema-types/src/client/index.v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ export type ModelTypes<
> = any;

export type SelectionSet<_Model, _Path> = any;

/**
* Custom headers that can be passed either to the client or to individual
* calls, either as a static object or a function that returns a promise.
*/
export type CustomHeaders = Record<string, string> | (() => Promise<Headers>);
7 changes: 4 additions & 3 deletions packages/data-schema-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib-esm",
"rootDir": "src",
"outDir": "lib-esm",
"declaration": true,
"emitDeclarationOnly": true,
},
"lib": ["DOM"]
}
}

0 comments on commit 8c653be

Please sign in to comment.