@aws-amplify/data-schema 0.0.0-20240412222732
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/LICENSE +175 -0
- package/NOTICE +1 -0
- package/internals/package.json +6 -0
- package/lib-esm/index.d.ts +5 -0
- package/lib-esm/index.d.ts.map +1 -0
- package/lib-esm/index.js +28 -0
- package/lib-esm/src/Authorization.d.ts +287 -0
- package/lib-esm/src/Authorization.d.ts.map +1 -0
- package/lib-esm/src/Authorization.js +332 -0
- package/lib-esm/src/ClientSchema.d.ts +54 -0
- package/lib-esm/src/ClientSchema.d.ts.map +1 -0
- package/lib-esm/src/ClientSchema.js +2 -0
- package/lib-esm/src/CombineSchema.d.ts +19 -0
- package/lib-esm/src/CombineSchema.d.ts.map +1 -0
- package/lib-esm/src/CombineSchema.js +40 -0
- package/lib-esm/src/CustomOperation.d.ts +98 -0
- package/lib-esm/src/CustomOperation.d.ts.map +1 -0
- package/lib-esm/src/CustomOperation.js +67 -0
- package/lib-esm/src/CustomType.d.ts +36 -0
- package/lib-esm/src/CustomType.d.ts.map +1 -0
- package/lib-esm/src/CustomType.js +14 -0
- package/lib-esm/src/EnumType.d.ts +16 -0
- package/lib-esm/src/EnumType.d.ts.map +1 -0
- package/lib-esm/src/EnumType.js +17 -0
- package/lib-esm/src/Handler.d.ts +58 -0
- package/lib-esm/src/Handler.d.ts.map +1 -0
- package/lib-esm/src/Handler.js +48 -0
- package/lib-esm/src/MappedTypes/CustomOperations.d.ts +127 -0
- package/lib-esm/src/MappedTypes/CustomOperations.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/CustomOperations.js +2 -0
- package/lib-esm/src/MappedTypes/ExtractNonModelTypes.d.ts +74 -0
- package/lib-esm/src/MappedTypes/ExtractNonModelTypes.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/ExtractNonModelTypes.js +2 -0
- package/lib-esm/src/MappedTypes/ForeignKeys.d.ts +84 -0
- package/lib-esm/src/MappedTypes/ForeignKeys.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/ForeignKeys.js +2 -0
- package/lib-esm/src/MappedTypes/ImplicitFieldInjector.d.ts +38 -0
- package/lib-esm/src/MappedTypes/ImplicitFieldInjector.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/ImplicitFieldInjector.js +2 -0
- package/lib-esm/src/MappedTypes/MapSecondaryIndexes.d.ts +61 -0
- package/lib-esm/src/MappedTypes/MapSecondaryIndexes.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/MapSecondaryIndexes.js +2 -0
- package/lib-esm/src/MappedTypes/ModelMetadata.d.ts +26 -0
- package/lib-esm/src/MappedTypes/ModelMetadata.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/ModelMetadata.js +2 -0
- package/lib-esm/src/MappedTypes/ResolveFieldProperties.d.ts +70 -0
- package/lib-esm/src/MappedTypes/ResolveFieldProperties.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/ResolveFieldProperties.js +2 -0
- package/lib-esm/src/MappedTypes/ResolveSchema.d.ts +65 -0
- package/lib-esm/src/MappedTypes/ResolveSchema.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/ResolveSchema.js +2 -0
- package/lib-esm/src/ModelField.d.ts +162 -0
- package/lib-esm/src/ModelField.d.ts.map +1 -0
- package/lib-esm/src/ModelField.js +209 -0
- package/lib-esm/src/ModelIndex.d.ts +19 -0
- package/lib-esm/src/ModelIndex.d.ts.map +1 -0
- package/lib-esm/src/ModelIndex.js +33 -0
- package/lib-esm/src/ModelRelationalField.d.ts +119 -0
- package/lib-esm/src/ModelRelationalField.d.ts.map +1 -0
- package/lib-esm/src/ModelRelationalField.js +120 -0
- package/lib-esm/src/ModelSchema.d.ts +107 -0
- package/lib-esm/src/ModelSchema.d.ts.map +1 -0
- package/lib-esm/src/ModelSchema.js +162 -0
- package/lib-esm/src/ModelType.d.ts +85 -0
- package/lib-esm/src/ModelType.d.ts.map +1 -0
- package/lib-esm/src/ModelType.js +64 -0
- package/lib-esm/src/RefType.d.ts +59 -0
- package/lib-esm/src/RefType.d.ts.map +1 -0
- package/lib-esm/src/RefType.js +47 -0
- package/lib-esm/src/SchemaProcessor.d.ts +11 -0
- package/lib-esm/src/SchemaProcessor.d.ts.map +1 -0
- package/lib-esm/src/SchemaProcessor.js +1106 -0
- package/lib-esm/src/index.d.ts +13 -0
- package/lib-esm/src/index.d.ts.map +1 -0
- package/lib-esm/src/index.js +43 -0
- package/lib-esm/src/internals/index.d.ts +2 -0
- package/lib-esm/src/internals/index.d.ts.map +1 -0
- package/lib-esm/src/internals/index.js +5 -0
- package/lib-esm/src/util/Brand.d.ts +36 -0
- package/lib-esm/src/util/Brand.d.ts.map +1 -0
- package/lib-esm/src/util/Brand.js +32 -0
- package/lib-esm/src/util/IndexLimit.d.ts +8 -0
- package/lib-esm/src/util/IndexLimit.d.ts.map +1 -0
- package/lib-esm/src/util/IndexLimit.js +2 -0
- package/lib-esm/src/util/SpreadTuple.d.ts +7 -0
- package/lib-esm/src/util/SpreadTuple.d.ts.map +1 -0
- package/lib-esm/src/util/SpreadTuple.js +2 -0
- package/lib-esm/src/util/index.d.ts +4 -0
- package/lib-esm/src/util/index.d.ts.map +1 -0
- package/lib-esm/src/util/index.js +6 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.accessSchemaData = exports.accessData = exports.allow = exports.ResourceOperations = exports.Operations = exports.Strategies = exports.CustomProviders = exports.GroupProviders = exports.OwnerProviders = exports.PrivateProviders = exports.PublicProviders = exports.Providers = void 0;
|
|
4
|
+
const __data = Symbol('data');
|
|
5
|
+
/**
|
|
6
|
+
* All possible providers.
|
|
7
|
+
*
|
|
8
|
+
* This list should not be used if you need to restrict available providers
|
|
9
|
+
* according to an auth strategcy. E.g., `public` auth can only be facilitated
|
|
10
|
+
* by `apiKey` and `iam` providers.
|
|
11
|
+
*/
|
|
12
|
+
exports.Providers = [
|
|
13
|
+
'apiKey',
|
|
14
|
+
'iam',
|
|
15
|
+
'userPools',
|
|
16
|
+
'oidc',
|
|
17
|
+
'function',
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* The subset of auth providers that can facilitate `public` auth.
|
|
21
|
+
*/
|
|
22
|
+
exports.PublicProviders = ['apiKey', 'iam'];
|
|
23
|
+
/**
|
|
24
|
+
* The subset of auth providers that can facilitate `private` auth.
|
|
25
|
+
*/
|
|
26
|
+
exports.PrivateProviders = ['userPools', 'oidc', 'iam'];
|
|
27
|
+
/**
|
|
28
|
+
* The subset of auth providers that can facilitate `owner` auth.
|
|
29
|
+
*/
|
|
30
|
+
exports.OwnerProviders = ['userPools', 'oidc'];
|
|
31
|
+
/**
|
|
32
|
+
* The subset of auth providers that can facilitate `group` auth.
|
|
33
|
+
*/
|
|
34
|
+
exports.GroupProviders = ['userPools', 'oidc'];
|
|
35
|
+
/**
|
|
36
|
+
* The subset of auth providers that can facilitate `custom` auth.
|
|
37
|
+
*/
|
|
38
|
+
exports.CustomProviders = ['function'];
|
|
39
|
+
exports.Strategies = [
|
|
40
|
+
'public',
|
|
41
|
+
'private',
|
|
42
|
+
'owner',
|
|
43
|
+
'groups',
|
|
44
|
+
'custom',
|
|
45
|
+
];
|
|
46
|
+
/**
|
|
47
|
+
* The operations that can be performed against an API.
|
|
48
|
+
*/
|
|
49
|
+
exports.Operations = [
|
|
50
|
+
'create',
|
|
51
|
+
'update',
|
|
52
|
+
'delete',
|
|
53
|
+
'read',
|
|
54
|
+
'get',
|
|
55
|
+
'list',
|
|
56
|
+
'sync',
|
|
57
|
+
'listen',
|
|
58
|
+
'search',
|
|
59
|
+
];
|
|
60
|
+
/**
|
|
61
|
+
* The operations that can be performed against an API by a Lambda function.
|
|
62
|
+
*/
|
|
63
|
+
exports.ResourceOperations = ['query', 'mutate', 'listen'];
|
|
64
|
+
/**
|
|
65
|
+
* Creates a shallow copy of an object with an individual field pruned away.
|
|
66
|
+
*
|
|
67
|
+
* @param original The original object to prune.
|
|
68
|
+
* @param without The field to prune.
|
|
69
|
+
* @returns The pruned object.
|
|
70
|
+
*/
|
|
71
|
+
function omit(original, without) {
|
|
72
|
+
const pruned = { ...original };
|
|
73
|
+
delete pruned[without];
|
|
74
|
+
return pruned;
|
|
75
|
+
}
|
|
76
|
+
function to(operations) {
|
|
77
|
+
this[__data].operations = operations;
|
|
78
|
+
return omit(this, 'to');
|
|
79
|
+
}
|
|
80
|
+
function inField(field) {
|
|
81
|
+
this[__data].groupOrOwnerField = field;
|
|
82
|
+
const built = omit(this, 'inField');
|
|
83
|
+
return built;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Specifies a property of the identity JWT to use in place of `sub::username`
|
|
87
|
+
* as the value to match against the owner field for authorization.
|
|
88
|
+
*
|
|
89
|
+
* @param this Authorization object to operate against.
|
|
90
|
+
* @param property A property of identity JWT.
|
|
91
|
+
* @returns A copy of the Authorization object with the claim attached.
|
|
92
|
+
*/
|
|
93
|
+
function identityClaim(property) {
|
|
94
|
+
this[__data].identityClaim = property;
|
|
95
|
+
return omit(this, 'identityClaim');
|
|
96
|
+
}
|
|
97
|
+
function withClaimIn(property) {
|
|
98
|
+
this[__data].groupClaim = property;
|
|
99
|
+
return omit(this, 'withClaimIn');
|
|
100
|
+
}
|
|
101
|
+
function validateProvider(needle, haystack) {
|
|
102
|
+
if (needle && !haystack.includes(needle)) {
|
|
103
|
+
throw new Error(`Invalid provider (${needle}) given!`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function authData(defaults, builderMethods) {
|
|
107
|
+
return {
|
|
108
|
+
[__data]: {
|
|
109
|
+
strategy: 'public',
|
|
110
|
+
provider: undefined,
|
|
111
|
+
operations: undefined,
|
|
112
|
+
groupOrOwnerField: undefined,
|
|
113
|
+
multiOwner: false,
|
|
114
|
+
identityClaim: undefined,
|
|
115
|
+
groups: undefined,
|
|
116
|
+
...defaults,
|
|
117
|
+
},
|
|
118
|
+
...builderMethods,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Defines an authorization rule for your data models and fields. First choose an authorization strategy (`public`,
|
|
123
|
+
* `private`, `owner`, `group`, or `custom`), then choose an auth provider (`apiKey`, `iam`, `userPools`, `oidc`, or `function`)
|
|
124
|
+
* and optionally use `.to(...)` to specify the operations that can be performed against your data models and fields.
|
|
125
|
+
*/
|
|
126
|
+
exports.allow = {
|
|
127
|
+
/**
|
|
128
|
+
* Authorize unauthenticated users. By default, `.public()` uses an API key based authorization. You can additionally
|
|
129
|
+
* use `.public('iam')` to use IAM based authorization for unauthenticated users.
|
|
130
|
+
* @param provider the authentication provider - supports "apiKey" or "iam" as valid providers
|
|
131
|
+
* @returns an authorization rule for unauthenticated users
|
|
132
|
+
*/
|
|
133
|
+
public(provider) {
|
|
134
|
+
validateProvider(provider, exports.PublicProviders);
|
|
135
|
+
return authData({
|
|
136
|
+
strategy: 'public',
|
|
137
|
+
provider,
|
|
138
|
+
}, {
|
|
139
|
+
to,
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
/**
|
|
143
|
+
* Authorize authenticated users. By default, `.private()` uses an Amazon Cognito user pool based authorization. You can additionally
|
|
144
|
+
* use `.private("iam")` or `.private("oidc")` to use IAM or OIDC based authorization for authenticated users.
|
|
145
|
+
* @param provider the authentication provider - supports "userPools", "iam", or "oidc"
|
|
146
|
+
* @returns an authorization rule for authenticated users
|
|
147
|
+
*/
|
|
148
|
+
private(provider) {
|
|
149
|
+
validateProvider(provider, exports.PrivateProviders);
|
|
150
|
+
return authData({
|
|
151
|
+
strategy: 'private',
|
|
152
|
+
provider,
|
|
153
|
+
}, {
|
|
154
|
+
to,
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
/**
|
|
158
|
+
* Authorize access on a per-user (owner) basis. By setting owner-based authorization, a new `owner: a.string()`
|
|
159
|
+
* field will be added to the model to store which user "owns" the item. Upon item creation, the "owner field" is
|
|
160
|
+
* auto-populated with the authenticated user's information. You can which field should be used as the owner field
|
|
161
|
+
* by chaining the * `.inField(...)` method.
|
|
162
|
+
*
|
|
163
|
+
* By default, `.owner()` uses an Amazon Cognito user pool based authorization. You can additionally
|
|
164
|
+
* use `.owner("oidc")` to use OIDC based authentication to designate the owner.
|
|
165
|
+
*
|
|
166
|
+
* To change the specific claim that should be used as the user identifier within the owner field, chain the
|
|
167
|
+
* `.identityClaim(...)` method.
|
|
168
|
+
*
|
|
169
|
+
* @param provider the authentication provider - supports "userPools", "iam", or "oidc"
|
|
170
|
+
* @returns an authorization rule for authenticated users
|
|
171
|
+
*/
|
|
172
|
+
owner(provider) {
|
|
173
|
+
validateProvider(provider, exports.OwnerProviders);
|
|
174
|
+
return authData({
|
|
175
|
+
strategy: 'owner',
|
|
176
|
+
provider,
|
|
177
|
+
groupOrOwnerField: 'owner',
|
|
178
|
+
}, {
|
|
179
|
+
to,
|
|
180
|
+
inField,
|
|
181
|
+
identityClaim,
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
/**
|
|
185
|
+
* Authorize access for multi-user / multi-owner access. By setting multi-owner-based authorization, a new `owners: a.string().array()`
|
|
186
|
+
* field will be added to the model to store which users "own" the item. Upon item creation, the "owners field" is
|
|
187
|
+
* auto-populated with the authenticated user's information. To grant other users access to the item, append their user identifier into the `owners` array.
|
|
188
|
+
* You can which field should be used as the owners field by chaining the * `.inField(...)` method.
|
|
189
|
+
*
|
|
190
|
+
* By default, `.multipleOwners()` uses an Amazon Cognito user pool based authorization. You can additionally
|
|
191
|
+
* use `.multipleOwners("oidc")` to use OIDC based authentication to designate the owner.
|
|
192
|
+
*
|
|
193
|
+
* To change the specific claim that should be used as the user identifier within the owners field, chain the
|
|
194
|
+
* `.identityClaim(...)` method.
|
|
195
|
+
*
|
|
196
|
+
* @param provider the authentication provider - supports "userPools", "iam", or "oidc"
|
|
197
|
+
* @returns an authorization rule for authenticated users
|
|
198
|
+
*/
|
|
199
|
+
multipleOwners(provider) {
|
|
200
|
+
validateProvider(provider, exports.OwnerProviders);
|
|
201
|
+
return authData({
|
|
202
|
+
strategy: 'owner',
|
|
203
|
+
multiOwner: true,
|
|
204
|
+
provider,
|
|
205
|
+
groupOrOwnerField: 'owner',
|
|
206
|
+
}, {
|
|
207
|
+
to,
|
|
208
|
+
inField,
|
|
209
|
+
identityClaim,
|
|
210
|
+
});
|
|
211
|
+
},
|
|
212
|
+
/**
|
|
213
|
+
* Authorize a specific user group. Provide the name of the specific user group to have access.
|
|
214
|
+
*
|
|
215
|
+
* By default, `.specificGroup()` uses an Amazon Cognito user pool based authorization. You can additionally
|
|
216
|
+
* use `.specificGroup("group-name", "oidc")` to use OIDC based authentication to designate the user group.
|
|
217
|
+
*
|
|
218
|
+
* To change the specific claim that should be used as the user group identifier, chain the
|
|
219
|
+
* `.withClaimIn(...)` method.
|
|
220
|
+
* @param group the name of the group to authorize
|
|
221
|
+
* @param provider the authentication provider - supports "userPools" or "oidc"
|
|
222
|
+
* @returns an authorization rule to grant access by a specific group
|
|
223
|
+
*/
|
|
224
|
+
specificGroup(group, provider) {
|
|
225
|
+
return authData({
|
|
226
|
+
strategy: 'groups',
|
|
227
|
+
provider,
|
|
228
|
+
groups: [group],
|
|
229
|
+
}, {
|
|
230
|
+
to,
|
|
231
|
+
withClaimIn,
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
/**
|
|
235
|
+
* Authorize multiple specific user groups. Provide the names of the specific user groups to have access.
|
|
236
|
+
*
|
|
237
|
+
* By default, `.specificGroups()` uses an Amazon Cognito user pool based authorization. You can additionally
|
|
238
|
+
* use `.specificGroups(["group-a", "group-b"], "oidc")` to use OIDC based authentication to designate the user group.
|
|
239
|
+
*
|
|
240
|
+
* To change the specific claim that should be used as the user group identifier, chain the
|
|
241
|
+
* `.withClaimIn(...)` method.
|
|
242
|
+
* @param groups the names of the group to authorize defined as an array
|
|
243
|
+
* @param provider the authentication provider - supports "userPools" or "oidc"
|
|
244
|
+
* @returns an authorization rule to grant access by a specific group
|
|
245
|
+
*/
|
|
246
|
+
specificGroups(groups, provider) {
|
|
247
|
+
return authData({
|
|
248
|
+
strategy: 'groups',
|
|
249
|
+
provider,
|
|
250
|
+
groups,
|
|
251
|
+
}, {
|
|
252
|
+
to,
|
|
253
|
+
withClaimIn,
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
/**
|
|
257
|
+
* Authorize if a user is part of a group defined in a data model field.
|
|
258
|
+
*
|
|
259
|
+
* By default, `.groupDefinedIn()` uses an Amazon Cognito user pool based authorization. You can additionally
|
|
260
|
+
* use `.groupDefinedIn("field-name", "oidc")` to use OIDC based authentication to designate the user group.
|
|
261
|
+
*
|
|
262
|
+
* To change the specific claim that should be used as the user group identifier within the groups field, chain the
|
|
263
|
+
* `.withClaimIn(...)` method.
|
|
264
|
+
* @param groupsField the field that should store the authorized user group information
|
|
265
|
+
* @param provider the authentication provider - supports "userPools" or "oidc"
|
|
266
|
+
* @returns an authorization rule to grant access by a specific group
|
|
267
|
+
*/
|
|
268
|
+
groupDefinedIn(groupsField, provider) {
|
|
269
|
+
return authData({
|
|
270
|
+
strategy: 'groups',
|
|
271
|
+
provider,
|
|
272
|
+
groupOrOwnerField: groupsField,
|
|
273
|
+
}, {
|
|
274
|
+
to,
|
|
275
|
+
withClaimIn,
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
/**
|
|
279
|
+
* Authorize if a user is part of a one of the groups defined in a data model field.
|
|
280
|
+
*
|
|
281
|
+
* By default, `.groupsDefinedIn()` uses an Amazon Cognito user pool based authorization. You can additionally
|
|
282
|
+
* use `.groupsDefinedIn("field-name", "oidc")` to use OIDC based authentication to designate the user group.
|
|
283
|
+
*
|
|
284
|
+
* To change the specific claim that should be used as the user group identifier within the groups field, chain the
|
|
285
|
+
* `.withClaimIn(...)` method.
|
|
286
|
+
* @param groupsField the field that should store the list of authorized user groups
|
|
287
|
+
* @param provider the authentication provider - supports "userPools" or "oidc"
|
|
288
|
+
* @returns an authorization rule to grant access by a specific group
|
|
289
|
+
*/
|
|
290
|
+
groupsDefinedIn(groupsField, provider) {
|
|
291
|
+
return authData({
|
|
292
|
+
strategy: 'groups',
|
|
293
|
+
provider,
|
|
294
|
+
groupOrOwnerField: groupsField,
|
|
295
|
+
multiOwner: true,
|
|
296
|
+
}, {
|
|
297
|
+
to,
|
|
298
|
+
withClaimIn,
|
|
299
|
+
});
|
|
300
|
+
},
|
|
301
|
+
custom(provider) {
|
|
302
|
+
return authData({
|
|
303
|
+
strategy: 'custom',
|
|
304
|
+
provider,
|
|
305
|
+
}, {
|
|
306
|
+
to,
|
|
307
|
+
});
|
|
308
|
+
},
|
|
309
|
+
resource(fn) {
|
|
310
|
+
return resourceAuthData(fn, {
|
|
311
|
+
to: resourceTo,
|
|
312
|
+
});
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
function resourceTo(operations) {
|
|
316
|
+
this[__data].operations = operations;
|
|
317
|
+
return omit(this, 'to');
|
|
318
|
+
}
|
|
319
|
+
function resourceAuthData(resource, builderMethods) {
|
|
320
|
+
return {
|
|
321
|
+
[__data]: {
|
|
322
|
+
strategy: 'resource',
|
|
323
|
+
resource,
|
|
324
|
+
},
|
|
325
|
+
...builderMethods,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
const accessData = (authorization) => authorization[__data];
|
|
329
|
+
exports.accessData = accessData;
|
|
330
|
+
// TODO: delete when we make resource auth available at each level in the schema (model, field)
|
|
331
|
+
const accessSchemaData = (authorization) => authorization[__data];
|
|
332
|
+
exports.accessSchemaData = accessSchemaData;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type __modelMeta__ } from '@aws-amplify/data-schema-types';
|
|
2
|
+
import { type GenericModelSchema, type RDSModelSchema } from './ModelSchema';
|
|
3
|
+
import type { ResolveSchema, SchemaTypes } from './MappedTypes/ResolveSchema';
|
|
4
|
+
import type { CreateImplicitModelsFromRelations, ResolveFieldProperties, ResolveStaticFieldProperties } from './MappedTypes/ResolveFieldProperties';
|
|
5
|
+
import type { ModelIdentifier, ModelSecondaryIndexes, RelationalMetadata } from './MappedTypes/ModelMetadata';
|
|
6
|
+
import type { ExtractNonModelTypes, NonModelTypesShape } from './MappedTypes/ExtractNonModelTypes';
|
|
7
|
+
import { ResolveCustomOperations, CustomOperationHandlerTypes } from './MappedTypes/CustomOperations';
|
|
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;
|
|
11
|
+
/**
|
|
12
|
+
* Types for unwrapping generic type args into client-consumable types
|
|
13
|
+
*
|
|
14
|
+
* @typeParam Schema - Data schema builder model type
|
|
15
|
+
*
|
|
16
|
+
* The following params are used solely as variables in order to simplify mapped type usage.
|
|
17
|
+
* They should not receive external type args.
|
|
18
|
+
*
|
|
19
|
+
* @internal @typeParam NonModelTypes - Custom Types, Enums, and Custom Operations
|
|
20
|
+
* @internal @typeParam ResolvedSchema - Resolve the schema types used by other generics
|
|
21
|
+
* @internal @typeParam ImplicitModels - The implicit models created to represent relationships
|
|
22
|
+
* @internal @typeParam ImplicitModelsIdentifierMeta - The implicite model identifiers derived from ImplicitModels
|
|
23
|
+
* @internal @typeParam ResolvedFields - Resolved client-facing types used for CRUDL response shapes
|
|
24
|
+
* @internal @typeParam IdentifierMeta - Resolve the identifier fields for all models
|
|
25
|
+
* @internal @typeParam SecondaryIndexes - Map of model secondary index metadata
|
|
26
|
+
*/
|
|
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 = {
|
|
28
|
+
[ImplicitModel in keyof ImplicitModels]: {
|
|
29
|
+
identifier: 'id';
|
|
30
|
+
};
|
|
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 & {
|
|
32
|
+
[__modelMeta__]: IdentifierMeta & ImplicitModelsIdentifierMeta & SecondaryIndexes & RelationalMetadata<ResolvedSchema, ResolvedFields, IdentifierMeta> & NonModelTypes & ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>;
|
|
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 ? Omit<ClientSchemas[I], typeof __modelMeta__> : never;
|
|
48
|
+
}> & {
|
|
49
|
+
[__modelMeta__]: SpreadTuple<{
|
|
50
|
+
[I in keyof ClientSchemas]: I extends CombinedSchemaIndexesUnion ? ClientSchemas[I][typeof __modelMeta__] : never;
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=ClientSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientSchema.d.ts","sourceRoot":"","sources":["../../src/ClientSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAG7E,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EACV,iCAAiC,EACjC,sBAAsB,EACtB,4BAA4B,EAC7B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,uBAAuB,EACvB,2BAA2B,EAC5B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,MAAM,MAAM,YAAY,CACtB,MAAM,SAAS,kBAAkB,CAAC,GAAG,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,IAC/D,MAAM,SAAS,kBAAkB,CAAC,GAAG,CAAC,GACtC,oBAAoB,CAAC,MAAM,CAAC,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ClE,aAAa,GACb,uBAAuB,CAAC,MAAM,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;CAClE,CAAC;AAEJ,KAAK,uBAAuB,CAAC,MAAM,IAAI,MAAM,SAAS,kBAAkB,CAAC,GAAG,CAAC,GACzE,oBAAoB,CAAC,MAAM,CAAC,GAC5B,KAAK,CAAC;AAEV,KAAK,qBAAqB,CACxB,OAAO,SAAS,mBAAmB,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,IACjD;KACD,KAAK,IAAI,MAAM,OAAO,GAAG,KAAK,SAAS,0BAA0B,GAC9D,uBAAuB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GACvC,KAAK;CACV,CAAC;AAEF;;;;;;;GAOG;AACH,KAAK,sBAAsB,CACzB,QAAQ,SAAS,mBAAmB,CAAC,GAAG,CAAC,EACzC,aAAa,SAAS,CAAC,GAAG,GAAG,CAAC,GAAG,qBAAqB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,IACzE,WAAW,CAAC;KACb,CAAC,IAAI,MAAM,aAAa,GAAG,CAAC,SAAS,0BAA0B,GAC5D,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,aAAa,CAAC,GAC5C,KAAK;CACV,CAAC,GAAG;IACH,CAAC,aAAa,CAAC,EAAE,WAAW,CAAC;SAC1B,CAAC,IAAI,MAAM,aAAa,GAAG,CAAC,SAAS,0BAA0B,GAC5D,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,aAAa,CAAC,GACtC,KAAK;KACV,CAAC,CAAC;CACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { 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
|
+
};
|
|
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 {};
|
|
19
|
+
//# sourceMappingURL=CombineSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CombineSchema.d.ts","sourceRoot":"","sources":["../../src/CombineSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAS,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEvD,QAAA,MAAM,qBAAqB,KAAK,CAAC;AAEjC,MAAM,MAAM,0BAA0B,GAAG,eAAe,CACtD,OAAO,qBAAqB,CAC7B,CAAC,MAAM,CAAC,CAAC;AAEV,QAAA,MAAM,uBAAuB,mBAAmB,CAAC;AACjD,eAAO,MAAM,mBAAmB,yBAAiC,CAAC;AAClE,MAAM,MAAM,mBAAmB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,MAAM,MAAM,mBAAmB,CAAC,OAAO,SAAS,kBAAkB,CAAC,GAAG,CAAC,EAAE,IACvE,mBAAmB,GAAG;IAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAA;CAAE,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,MAAM,SAAS,kBAAkB,CAAC,GAAG,CAAC,EAAE,EAC9D,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,GACnB,mBAAmB,CAAC,MAAM,CAAC,CAE7B"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
validateDuplicateTypeNames(schemas);
|
|
20
|
+
return {
|
|
21
|
+
...exports.combinedSchemaBrand,
|
|
22
|
+
schemas: schemas,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function validateDuplicateTypeNames(schemas) {
|
|
26
|
+
const allSchemaKeys = schemas.flatMap((s) => Object.keys(s.data.types));
|
|
27
|
+
const keySet = new Set();
|
|
28
|
+
const duplicateKeySet = new Set();
|
|
29
|
+
allSchemaKeys.forEach((key) => {
|
|
30
|
+
if (keySet.has(key)) {
|
|
31
|
+
duplicateKeySet.add(key);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
keySet.add(key);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (duplicateKeySet.size > 0) {
|
|
38
|
+
throw new Error(`The schemas you are attempting to combine have a name collision. Please remove or rename ${Array.from(duplicateKeySet).join(', ')}.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { SetTypeSubArg } from '@aws-amplify/data-schema-types';
|
|
2
|
+
import { Brand } from './util';
|
|
3
|
+
import { ModelField, InternalField } from './ModelField';
|
|
4
|
+
import { Authorization } from './Authorization';
|
|
5
|
+
import { RefType, InternalRef } from './RefType';
|
|
6
|
+
import { EnumType, EnumTypeParamShape } from './EnumType';
|
|
7
|
+
import { CustomType } from './CustomType';
|
|
8
|
+
import type { CustomHandler, FunctionHandler, HandlerType as Handler } from './Handler';
|
|
9
|
+
declare const queryBrand = "queryCustomOperation";
|
|
10
|
+
declare const mutationBrand = "mutationCustomOperation";
|
|
11
|
+
declare const subscriptionBrand = "subscriptionCustomOperation";
|
|
12
|
+
type CustomOperationBrand = typeof queryBrand | typeof mutationBrand | typeof subscriptionBrand;
|
|
13
|
+
type CustomArguments = Record<string, ModelField<any, any> | EnumType<EnumTypeParamShape>>;
|
|
14
|
+
type SubscriptionSource = RefType<any, any>;
|
|
15
|
+
type InternalSubscriptionSource = InternalRef;
|
|
16
|
+
type CustomReturnType = RefType<any> | CustomType<any>;
|
|
17
|
+
type CustomFunctionRefType = string;
|
|
18
|
+
type InternalCustomArguments = Record<string, InternalField>;
|
|
19
|
+
type InternalCustomReturnType = InternalRef;
|
|
20
|
+
type HandlerInputType = FunctionHandler[] | CustomHandler[] | Handler;
|
|
21
|
+
export declare const CustomOperationNames: readonly ["Query", "Mutation", "Subscription"];
|
|
22
|
+
type CustomOperationName = (typeof CustomOperationNames)[number];
|
|
23
|
+
type CustomData = {
|
|
24
|
+
arguments: CustomArguments;
|
|
25
|
+
returnType: CustomReturnType | null;
|
|
26
|
+
functionRef: string | null;
|
|
27
|
+
authorization: Authorization<any, any, any>[];
|
|
28
|
+
typeName: CustomOperationName;
|
|
29
|
+
handlers: Handler[] | null;
|
|
30
|
+
subscriptionSource: SubscriptionSource[];
|
|
31
|
+
};
|
|
32
|
+
type InternalCustomData = CustomData & {
|
|
33
|
+
arguments: InternalCustomArguments;
|
|
34
|
+
returnType: InternalCustomReturnType;
|
|
35
|
+
functionRef: string | null;
|
|
36
|
+
subscriptionSource: InternalSubscriptionSource[];
|
|
37
|
+
authorization: Authorization<any, any, any>[];
|
|
38
|
+
};
|
|
39
|
+
export type CustomOperationParamShape = {
|
|
40
|
+
arguments: CustomArguments | null;
|
|
41
|
+
returnType: CustomReturnType | null;
|
|
42
|
+
functionRef: string | null;
|
|
43
|
+
authorization: Authorization<any, any, any>[];
|
|
44
|
+
typeName: CustomOperationName;
|
|
45
|
+
handlers: Handler | null;
|
|
46
|
+
};
|
|
47
|
+
export type CustomOperation<T extends CustomOperationParamShape, K extends keyof CustomOperation<T> = never, B extends CustomOperationBrand = CustomOperationBrand> = Omit<{
|
|
48
|
+
arguments<Arguments extends CustomArguments>(args: Arguments): CustomOperation<SetTypeSubArg<T, 'arguments', Arguments>, K | 'arguments', B>;
|
|
49
|
+
returns<ReturnType extends CustomReturnType>(returnType: ReturnType): CustomOperation<SetTypeSubArg<T, 'returnType', ReturnType>, K | 'returns', B>;
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @deprecated
|
|
53
|
+
* `.function` should no longer be used and will be removed
|
|
54
|
+
* in the next minor version of this package.
|
|
55
|
+
*
|
|
56
|
+
* Use `.handler(a.handler.function())` instead
|
|
57
|
+
*/
|
|
58
|
+
function<FunctionRef extends CustomFunctionRefType>(functionRefOrName: FunctionRef): CustomOperation<SetTypeSubArg<T, 'functionRef', FunctionRef>, K | 'function', B>;
|
|
59
|
+
authorization<AuthRuleType extends Authorization<any, any, any>>(rules: AuthRuleType[]): CustomOperation<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, K | 'authorization', B>;
|
|
60
|
+
handler<H extends HandlerInputType>(handlers: H): CustomOperation<T, K | 'handler', B>;
|
|
61
|
+
for<Source extends SubscriptionSource>(source: Source | Source[]): CustomOperation<T['typeName'] extends 'Subscription' ? SetTypeSubArg<T, 'returnType', Source extends SubscriptionSource[] ? Source[number] : Source> : T, K | 'for', B>;
|
|
62
|
+
}, K> & Brand<B>;
|
|
63
|
+
/**
|
|
64
|
+
* Internal representation of Custom Type that exposes the `data` property.
|
|
65
|
+
* Used at buildtime.
|
|
66
|
+
*/
|
|
67
|
+
export type InternalCustom<B extends CustomOperationBrand = any> = CustomOperation<any, never, B> & {
|
|
68
|
+
data: InternalCustomData;
|
|
69
|
+
};
|
|
70
|
+
export type QueryCustomOperation = CustomOperation<CustomOperationParamShape, any, typeof queryBrand>;
|
|
71
|
+
export declare function query(): CustomOperation<{
|
|
72
|
+
arguments: null;
|
|
73
|
+
returnType: null;
|
|
74
|
+
functionRef: null;
|
|
75
|
+
authorization: [];
|
|
76
|
+
typeName: 'Query';
|
|
77
|
+
handlers: null;
|
|
78
|
+
}, never, typeof queryBrand>;
|
|
79
|
+
export type MutationCustomOperation = CustomOperation<CustomOperationParamShape, any, typeof mutationBrand>;
|
|
80
|
+
export declare function mutation(): CustomOperation<{
|
|
81
|
+
arguments: null;
|
|
82
|
+
returnType: null;
|
|
83
|
+
functionRef: null;
|
|
84
|
+
authorization: [];
|
|
85
|
+
typeName: 'Mutation';
|
|
86
|
+
handlers: null;
|
|
87
|
+
}, never, typeof mutationBrand>;
|
|
88
|
+
export type SubscriptionCustomOperation = CustomOperation<CustomOperationParamShape, any, typeof subscriptionBrand>;
|
|
89
|
+
export declare function subscription(): CustomOperation<{
|
|
90
|
+
arguments: null;
|
|
91
|
+
returnType: null;
|
|
92
|
+
functionRef: null;
|
|
93
|
+
authorization: [];
|
|
94
|
+
typeName: 'Subscription';
|
|
95
|
+
handlers: null;
|
|
96
|
+
}, 'returns', typeof subscriptionBrand>;
|
|
97
|
+
export {};
|
|
98
|
+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,CAC7C;IACE,SAAS,EAAE,IAAI,CAAC;IAChB,UAAU,EAAE,IAAI,CAAC;IACjB,WAAW,EAAE,IAAI,CAAC;IAClB,aAAa,EAAE,EAAE,CAAC;IAClB,QAAQ,EAAE,cAAc,CAAC;IACzB,QAAQ,EAAE,IAAI,CAAC;CAChB,EACD,SAAS,EACT,OAAO,iBAAiB,CACzB,CAEA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscription = exports.mutation = exports.query = exports.CustomOperationNames = void 0;
|
|
4
|
+
const util_1 = require("./util");
|
|
5
|
+
const queryBrand = 'queryCustomOperation';
|
|
6
|
+
const mutationBrand = 'mutationCustomOperation';
|
|
7
|
+
const subscriptionBrand = 'subscriptionCustomOperation';
|
|
8
|
+
exports.CustomOperationNames = [
|
|
9
|
+
'Query',
|
|
10
|
+
'Mutation',
|
|
11
|
+
'Subscription',
|
|
12
|
+
];
|
|
13
|
+
function brandedBuilder(builder, brandValue) {
|
|
14
|
+
return { ...builder, ...(0, util_1.brand)(brandValue) };
|
|
15
|
+
}
|
|
16
|
+
function _custom(typeName, brand) {
|
|
17
|
+
const data = {
|
|
18
|
+
arguments: {},
|
|
19
|
+
returnType: null,
|
|
20
|
+
functionRef: null,
|
|
21
|
+
authorization: [],
|
|
22
|
+
typeName: typeName,
|
|
23
|
+
handlers: null,
|
|
24
|
+
subscriptionSource: [],
|
|
25
|
+
};
|
|
26
|
+
const builder = brandedBuilder({
|
|
27
|
+
arguments(args) {
|
|
28
|
+
data.arguments = args;
|
|
29
|
+
return this;
|
|
30
|
+
},
|
|
31
|
+
returns(returnType) {
|
|
32
|
+
data.returnType = returnType;
|
|
33
|
+
return this;
|
|
34
|
+
},
|
|
35
|
+
function(functionRefOrName) {
|
|
36
|
+
data.functionRef = functionRefOrName;
|
|
37
|
+
return this;
|
|
38
|
+
},
|
|
39
|
+
authorization(rules) {
|
|
40
|
+
data.authorization = rules;
|
|
41
|
+
return this;
|
|
42
|
+
},
|
|
43
|
+
handler(handlers) {
|
|
44
|
+
data.handlers = Array.isArray(handlers)
|
|
45
|
+
? handlers
|
|
46
|
+
: [handlers];
|
|
47
|
+
return this;
|
|
48
|
+
},
|
|
49
|
+
for(source) {
|
|
50
|
+
data.subscriptionSource = Array.isArray(source) ? source : [source];
|
|
51
|
+
return this;
|
|
52
|
+
},
|
|
53
|
+
}, brand);
|
|
54
|
+
return { ...builder, data };
|
|
55
|
+
}
|
|
56
|
+
function query() {
|
|
57
|
+
return _custom('Query', queryBrand);
|
|
58
|
+
}
|
|
59
|
+
exports.query = query;
|
|
60
|
+
function mutation() {
|
|
61
|
+
return _custom('Mutation', mutationBrand);
|
|
62
|
+
}
|
|
63
|
+
exports.mutation = mutation;
|
|
64
|
+
function subscription() {
|
|
65
|
+
return _custom('Subscription', subscriptionBrand);
|
|
66
|
+
}
|
|
67
|
+
exports.subscription = subscription;
|