UNPKG

7.5 kBTypeScriptView Raw
1import { Headers } from '../../clients';
2import { AtLeastOne } from '../types';
3export interface LibraryAPIOptions {
4 GraphQL?: {
5 headers?(options?: {
6 query?: string;
7 variables?: Record<string, DocumentType>;
8 }): Promise<Headers | Record<string, unknown>>;
9 withCredentials?: boolean;
10 };
11 REST?: {
12 headers?(options: {
13 apiName: string;
14 }): Promise<Headers>;
15 };
16}
17export interface APIGraphQLConfig {
18 /**
19 * Required GraphQL endpoint, must be a valid URL string.
20 */
21 endpoint: string;
22 /**
23 * Optional region string used to sign the request. Required only if the auth mode is 'iam'.
24 */
25 region?: string;
26 /**
27 * Optional API key string. Required only if the auth mode is 'apiKey'.
28 */
29 apiKey?: string;
30 /**
31 * Custom domain endpoint for GraphQL API.
32 */
33 customEndpoint?: string;
34 /**
35 * Optional region string used to sign the request to `customEndpoint`. Effective only if `customEndpoint` is
36 * specified, and the auth mode is 'iam'.
37 */
38 customEndpointRegion?: string;
39 /**
40 * Default auth mode for all the API calls to given service.
41 */
42 defaultAuthMode: GraphQLAuthMode;
43 modelIntrospection?: ModelIntrospectionSchema;
44}
45/**
46 * @experimental
47 */
48export interface APIEventsConfig {
49 /**
50 * Required GraphQL endpoint, must be a valid URL string.
51 */
52 endpoint: string;
53 /**
54 * Optional region string used to sign the request. Required only if the auth mode is 'iam'.
55 */
56 region?: string;
57 /**
58 * Optional API key string. Required only if the auth mode is 'apiKey'.
59 */
60 apiKey?: string;
61 /**
62 * Custom domain endpoint for GraphQL API.
63 */
64 customEndpoint?: string;
65 /**
66 * Optional region string used to sign the request to `customEndpoint`. Effective only if `customEndpoint` is
67 * specified, and the auth mode is 'iam'.
68 */
69 customEndpointRegion?: string;
70 /**
71 * Default auth mode for all the API calls to given service.
72 */
73 defaultAuthMode: GraphQLAuthMode;
74}
75export interface APIRestConfig {
76 /**
77 * Required REST endpoint, must be a valid URL string.
78 */
79 endpoint: string;
80 /**
81 * Optional region string used to sign the request with IAM credentials. If Omitted, region will be extracted from
82 * the endpoint.
83 *
84 * @default 'us-east-1'
85 */
86 region?: string;
87 /**
88 * Optional service name string to sign the request with IAM credentials.
89 *
90 * @default 'execute-api'
91 */
92 service?: string;
93}
94export interface RESTProviderConfig {
95 REST: Record<string, APIRestConfig>;
96}
97export interface GraphQLProviderConfig {
98 GraphQL: APIGraphQLConfig;
99}
100export interface EventsProviderConfig {
101 Events: APIEventsConfig;
102}
103export type APIConfig = AtLeastOne<RESTProviderConfig & GraphQLProviderConfig & EventsProviderConfig>;
104export type GraphQLAuthMode = 'apiKey' | 'oidc' | 'userPool' | 'iam' | 'identityPool' | 'lambda' | 'none';
105/**
106 * Type representing a plain JavaScript object that can be serialized to JSON.
107 */
108export type DocumentType = null | boolean | number | string | DocumentType[] | {
109 [prop: string]: DocumentType;
110};
111/**
112 * Root model instrospection schema shape.
113 *
114 * Borrowed from: https://github.com/aws-amplify/samsara-cli/pull/377/commits/c08ea2c1a43f36aafe63b6d14d03f884e9c0c671#diff-21ae6faa2f22c15bb25ff9b272eaab7846c0650e2d267ab720546c19559583d0R4-R108
115 */
116export interface ModelIntrospectionSchema {
117 version: 1;
118 models: SchemaModels;
119 nonModels: SchemaNonModels;
120 enums: SchemaEnums;
121 queries?: CustomOperations;
122 mutations?: CustomOperations;
123 subscriptions?: CustomOperations;
124 conversations?: SchemaConversationRoutes;
125 generations?: SchemaGenerationRoutes;
126}
127/**
128 * Top-level Entities on a Schema
129 */
130export type SchemaModels = Record<string, SchemaModel>;
131export type SchemaNonModels = Record<string, SchemaNonModel>;
132export type SchemaEnums = Record<string, SchemaEnum>;
133export type CustomOperations = Record<string, CustomOperation>;
134type SchemaConversationRoutes = Record<string, SchemaConversationRoute>;
135type SchemaGenerationRoutes = Record<string, CustomOperation>;
136interface SchemaConversationRoute {
137 name: string;
138 models: SchemaModels;
139 nonModels: SchemaNonModels;
140 enums: SchemaEnums;
141 conversation: SchemaConversation;
142 message: SchemaConversationMessage;
143}
144interface SchemaConversation {
145 modelName: string;
146}
147interface SchemaConversationMessage {
148 modelName: string;
149 subscribe: CustomOperation;
150 send: CustomOperation;
151}
152export interface SchemaModel {
153 name: string;
154 attributes?: ModelAttribute[];
155 fields: Fields;
156 pluralName: string;
157 syncable?: boolean;
158 primaryKeyInfo: PrimaryKeyInfo;
159}
160export interface SchemaNonModel {
161 name: string;
162 fields: Fields;
163}
164export interface SchemaEnum {
165 name: string;
166 values: string[];
167}
168export interface ModelAttribute {
169 type: string;
170 properties?: Record<string, any>;
171}
172export interface SecondaryIndexAttribute {
173 type: 'key';
174 properties: {
175 name: string;
176 queryField: string;
177 fields: string[];
178 };
179}
180export interface CustomOperation {
181 name: string;
182 type: FieldType;
183 isArray: boolean;
184 isRequired: boolean;
185 arguments?: CustomOperationArguments;
186}
187export type CustomOperationArguments = Record<string, CustomOperationArgument>;
188export interface CustomOperationArgument {
189 name: string;
190 type: InputFieldType;
191 isArray: boolean;
192 isRequired: boolean;
193 isArrayNullable?: boolean;
194}
195/**
196 * Field Definition
197 */
198export type Fields = Record<string, Field>;
199export interface Field {
200 name: string;
201 type: FieldType;
202 isArray: boolean;
203 isRequired: boolean;
204 isReadOnly?: boolean;
205 isArrayNullable?: boolean;
206 attributes?: FieldAttribute[];
207 association?: AssociationType;
208}
209export interface ModelFieldType {
210 model: string;
211}
212export interface NonModelFieldType {
213 nonModel: string;
214}
215interface EnumType {
216 enum: string;
217}
218interface InputType {
219 input: string;
220}
221type ScalarType = 'ID' | 'String' | 'Int' | 'Float' | 'AWSDate' | 'AWSTime' | 'AWSDateTime' | 'AWSTimestamp' | 'AWSEmail' | 'AWSURL' | 'AWSIPAddress' | 'Boolean' | 'AWSJSON' | 'AWSPhone';
222type FieldType = ScalarType | EnumType | ModelFieldType | NonModelFieldType;
223type InputFieldType = ScalarType | EnumType | InputType;
224export type FieldAttribute = ModelAttribute;
225/**
226 * Field-level Relationship Definitions
227 */
228export declare enum CodeGenConnectionType {
229 HAS_ONE = "HAS_ONE",
230 BELONGS_TO = "BELONGS_TO",
231 HAS_MANY = "HAS_MANY"
232}
233export interface AssociationBaseType {
234 connectionType: CodeGenConnectionType;
235}
236export type AssociationHasMany = AssociationBaseType & {
237 connectionType: CodeGenConnectionType.HAS_MANY;
238 associatedWith: string[];
239};
240export type AssociationHasOne = AssociationBaseType & {
241 connectionType: CodeGenConnectionType.HAS_ONE;
242 associatedWith: string[];
243 targetNames: string[];
244};
245export type AssociationBelongsTo = AssociationBaseType & {
246 connectionType: CodeGenConnectionType.BELONGS_TO;
247 targetNames: string[];
248};
249export type AssociationType = AssociationHasMany | AssociationHasOne | AssociationBelongsTo;
250export interface PrimaryKeyInfo {
251 isCustomPrimaryKey: boolean;
252 primaryKeyFieldName: string;
253 sortKeyFieldNames: string[];
254}
255export {};