@aws-amplify/data-schema 0.11.0
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/lib-esm/index.d.ts +4 -0
- package/lib-esm/index.js +28 -0
- package/lib-esm/src/Authorization.d.ts +262 -0
- package/lib-esm/src/Authorization.js +309 -0
- package/lib-esm/src/ClientSchema.d.ts +27 -0
- package/lib-esm/src/ClientSchema.js +3 -0
- package/lib-esm/src/CustomType.d.ts +33 -0
- package/lib-esm/src/CustomType.js +14 -0
- package/lib-esm/src/EnumType.d.ts +15 -0
- package/lib-esm/src/EnumType.js +17 -0
- package/lib-esm/src/MappedTypes/ExtractNonModelTypes.d.ts +32 -0
- package/lib-esm/src/MappedTypes/ExtractNonModelTypes.js +2 -0
- package/lib-esm/src/MappedTypes/ForeignKeys.d.ts +83 -0
- package/lib-esm/src/MappedTypes/ForeignKeys.js +2 -0
- package/lib-esm/src/MappedTypes/ImplicitFieldInjector.d.ts +37 -0
- package/lib-esm/src/MappedTypes/ImplicitFieldInjector.js +2 -0
- package/lib-esm/src/MappedTypes/ModelMetadata.d.ts +20 -0
- package/lib-esm/src/MappedTypes/ModelMetadata.js +2 -0
- package/lib-esm/src/MappedTypes/ResolveFieldProperties.d.ts +58 -0
- package/lib-esm/src/MappedTypes/ResolveFieldProperties.js +2 -0
- package/lib-esm/src/MappedTypes/ResolveSchema.d.ts +35 -0
- package/lib-esm/src/MappedTypes/ResolveSchema.js +2 -0
- package/lib-esm/src/ModelField.d.ts +158 -0
- package/lib-esm/src/ModelField.js +206 -0
- package/lib-esm/src/ModelRelationalField.d.ts +106 -0
- package/lib-esm/src/ModelRelationalField.js +113 -0
- package/lib-esm/src/ModelSchema.d.ts +39 -0
- package/lib-esm/src/ModelSchema.js +34 -0
- package/lib-esm/src/ModelType.d.ts +107 -0
- package/lib-esm/src/ModelType.js +32 -0
- package/lib-esm/src/RefType.d.ts +45 -0
- package/lib-esm/src/RefType.js +29 -0
- package/lib-esm/src/SchemaProcessor.d.ts +10 -0
- package/lib-esm/src/SchemaProcessor.js +408 -0
- package/lib-esm/src/index.d.ts +9 -0
- package/lib-esm/src/index.js +35 -0
- package/lib-esm/src/types.d.ts +18 -0
- package/lib-esm/src/types.js +8 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processSchema = void 0;
|
|
4
|
+
const ModelField_1 = require("./ModelField");
|
|
5
|
+
const ModelRelationalField_1 = require("./ModelRelationalField");
|
|
6
|
+
const Authorization_1 = require("./Authorization");
|
|
7
|
+
function isInternalModel(model) {
|
|
8
|
+
if (model.data && model.data?.type !== 'customType') {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
function isEnumType(data) {
|
|
14
|
+
if (data?.type === 'enum') {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
function isCustomType(data) {
|
|
20
|
+
if (data?.data?.type === 'customType') {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
function isModelFieldDef(data) {
|
|
26
|
+
return data?.fieldType === 'model';
|
|
27
|
+
}
|
|
28
|
+
function isScalarFieldDef(data) {
|
|
29
|
+
return data?.fieldType !== 'model';
|
|
30
|
+
}
|
|
31
|
+
function isRefFieldDef(data) {
|
|
32
|
+
return data?.type === 'ref';
|
|
33
|
+
}
|
|
34
|
+
function isModelField(field) {
|
|
35
|
+
return isModelFieldDef(field.data);
|
|
36
|
+
}
|
|
37
|
+
function isScalarField(field) {
|
|
38
|
+
return isScalarFieldDef(field.data);
|
|
39
|
+
}
|
|
40
|
+
function isRefField(field) {
|
|
41
|
+
return isRefFieldDef(field.data);
|
|
42
|
+
}
|
|
43
|
+
function scalarFieldToGql(fieldDef, identifier) {
|
|
44
|
+
const { fieldType, required, array, arrayRequired, default: _default, } = fieldDef;
|
|
45
|
+
let field = fieldType;
|
|
46
|
+
if (identifier !== undefined) {
|
|
47
|
+
field += '!';
|
|
48
|
+
if (identifier.length > 1) {
|
|
49
|
+
const [_pk, ...sk] = identifier;
|
|
50
|
+
field += ` @primaryKey(sortKeyFields: ${JSON.stringify(sk)})`;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
field += ' @primaryKey';
|
|
54
|
+
}
|
|
55
|
+
return field;
|
|
56
|
+
}
|
|
57
|
+
if (required === true) {
|
|
58
|
+
field += '!';
|
|
59
|
+
}
|
|
60
|
+
if (array) {
|
|
61
|
+
field = `[${field}]`;
|
|
62
|
+
if (arrayRequired === true) {
|
|
63
|
+
field += '!';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (_default !== undefined) {
|
|
67
|
+
field += ` @default(value: "${_default?.toString()}")`;
|
|
68
|
+
}
|
|
69
|
+
return field;
|
|
70
|
+
}
|
|
71
|
+
function modelFieldToGql(fieldDef) {
|
|
72
|
+
const { type, relatedModel, array, relationName, valueRequired, arrayRequired, } = fieldDef;
|
|
73
|
+
let field = relatedModel;
|
|
74
|
+
if (valueRequired === true) {
|
|
75
|
+
field += '!';
|
|
76
|
+
}
|
|
77
|
+
if (array) {
|
|
78
|
+
field = `[${field}]`;
|
|
79
|
+
}
|
|
80
|
+
if (arrayRequired === true) {
|
|
81
|
+
field += '!';
|
|
82
|
+
}
|
|
83
|
+
field += ` @${type}`;
|
|
84
|
+
// TODO: accept other relationship options e.g. `fields`
|
|
85
|
+
if (type === 'manyToMany') {
|
|
86
|
+
field += `(relationName: "${relationName}")`;
|
|
87
|
+
}
|
|
88
|
+
return field;
|
|
89
|
+
}
|
|
90
|
+
function refFieldToGql(fieldDef) {
|
|
91
|
+
const { link, required } = fieldDef;
|
|
92
|
+
let field = link;
|
|
93
|
+
if (required === true) {
|
|
94
|
+
field += '!';
|
|
95
|
+
}
|
|
96
|
+
// if (array) {
|
|
97
|
+
// field = `[${field}]`;
|
|
98
|
+
// }
|
|
99
|
+
// if (arrayRequired === true) {
|
|
100
|
+
// field += '!';
|
|
101
|
+
// }
|
|
102
|
+
return field;
|
|
103
|
+
}
|
|
104
|
+
function calculateAuth(authorization) {
|
|
105
|
+
const authFields = {};
|
|
106
|
+
const rules = [];
|
|
107
|
+
for (const entry of authorization) {
|
|
108
|
+
const rule = (0, Authorization_1.accessData)(entry);
|
|
109
|
+
const ruleParts = [];
|
|
110
|
+
if (rule.strategy) {
|
|
111
|
+
ruleParts.push([`allow: ${rule.strategy}`]);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
return {
|
|
115
|
+
authFields,
|
|
116
|
+
authString: '',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (rule.provider) {
|
|
120
|
+
ruleParts.push(`provider: ${rule.provider}`);
|
|
121
|
+
}
|
|
122
|
+
if (rule.operations) {
|
|
123
|
+
ruleParts.push(`operations: [${rule.operations.join(', ')}]`);
|
|
124
|
+
}
|
|
125
|
+
if (rule.groupOrOwnerField) {
|
|
126
|
+
// directive attribute, depending whether it's owner or group auth
|
|
127
|
+
if (rule.strategy === 'groups') {
|
|
128
|
+
// does this need to be escaped?
|
|
129
|
+
ruleParts.push(`groupsField: "${rule.groupOrOwnerField}"`);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
// does this need to be escaped?
|
|
133
|
+
ruleParts.push(`ownerField: "${rule.groupOrOwnerField}"`);
|
|
134
|
+
}
|
|
135
|
+
// model field dep, type of which depends on whether multiple owner/group
|
|
136
|
+
// is required.
|
|
137
|
+
if (rule.multiOwner) {
|
|
138
|
+
authFields[rule.groupOrOwnerField] = (0, ModelField_1.string)().array();
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
authFields[rule.groupOrOwnerField] = (0, ModelField_1.string)();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (rule.groups) {
|
|
145
|
+
// does `group` need to be escaped?
|
|
146
|
+
ruleParts.push(`groups: [${rule.groups.map((group) => `"${group}"`).join(', ')}]`);
|
|
147
|
+
}
|
|
148
|
+
// identityClaim
|
|
149
|
+
if (rule.identityClaim) {
|
|
150
|
+
// does this need to be escaped?
|
|
151
|
+
ruleParts.push(`identityClaim: "${rule.identityClaim}"`);
|
|
152
|
+
}
|
|
153
|
+
// groupClaim
|
|
154
|
+
if (rule.groupClaim) {
|
|
155
|
+
// does this need to be escaped?
|
|
156
|
+
ruleParts.push(`groupClaim: "${rule.groupClaim}"`);
|
|
157
|
+
}
|
|
158
|
+
rules.push(`{${ruleParts.join(', ')}}`);
|
|
159
|
+
}
|
|
160
|
+
const authString = rules.length > 0 ? `@auth(rules: [${rules.join(',\n ')}])` : '';
|
|
161
|
+
return { authString, authFields };
|
|
162
|
+
}
|
|
163
|
+
function capitalize(s) {
|
|
164
|
+
return `${s[0].toUpperCase()}${s.slice(1)}`;
|
|
165
|
+
}
|
|
166
|
+
function uncapitalize(s) {
|
|
167
|
+
return `${s[0].toLowerCase()}${s.slice(1)}`;
|
|
168
|
+
}
|
|
169
|
+
function fkName(model, field, identifier) {
|
|
170
|
+
return `${uncapitalize(model)}${capitalize(field)}${capitalize(identifier)}`;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Returns all explicitly defined and implied fields from a model.
|
|
174
|
+
*
|
|
175
|
+
* @param schema The schema the model is part of. Necessary to derive implied FK's.
|
|
176
|
+
* @param model The model to extract fields from and derive fields for.
|
|
177
|
+
* @returns
|
|
178
|
+
*/
|
|
179
|
+
const allImpliedFKs = (schema) => {
|
|
180
|
+
const fks = {};
|
|
181
|
+
function addFk({ onModel, asField, fieldDef, }) {
|
|
182
|
+
fks[onModel] = fks[onModel] || {};
|
|
183
|
+
fks[onModel][asField] = fieldDef;
|
|
184
|
+
}
|
|
185
|
+
// implied FK's
|
|
186
|
+
for (const [modelName, typeDef] of Object.entries(schema.data.types)) {
|
|
187
|
+
if (!isInternalModel(typeDef))
|
|
188
|
+
continue;
|
|
189
|
+
for (const [fieldName, fieldDef] of Object.entries(typeDef.data.fields)) {
|
|
190
|
+
if (!isModelField(fieldDef))
|
|
191
|
+
continue;
|
|
192
|
+
const relatedModel = schema.data.types[fieldDef.data.relatedModel];
|
|
193
|
+
switch (fieldDef.data.type) {
|
|
194
|
+
case ModelRelationalField_1.ModelRelationshipTypes.hasOne:
|
|
195
|
+
for (const idField of relatedModel.data.identifier) {
|
|
196
|
+
addFk({
|
|
197
|
+
onModel: modelName,
|
|
198
|
+
asField: fkName(modelName, fieldName, idField),
|
|
199
|
+
fieldDef: {
|
|
200
|
+
data: {
|
|
201
|
+
...fieldDef.data,
|
|
202
|
+
fieldType: relatedModel.data.fields[idField]?.data.fieldType ||
|
|
203
|
+
ModelField_1.ModelFieldType.Id,
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
case ModelRelationalField_1.ModelRelationshipTypes.hasMany:
|
|
210
|
+
{
|
|
211
|
+
let authorization = [];
|
|
212
|
+
let required = false;
|
|
213
|
+
const [_belongsToName, belongsToDef] = Object.entries(relatedModel.data.fields).find(([_name, def]) => {
|
|
214
|
+
return (isModelField(def) &&
|
|
215
|
+
def.data.type === ModelRelationalField_1.ModelRelationshipTypes.belongsTo &&
|
|
216
|
+
def.data.relatedModel === fieldName);
|
|
217
|
+
}) || [];
|
|
218
|
+
if (belongsToDef && isModelField(belongsToDef)) {
|
|
219
|
+
authorization = belongsToDef.data.authorization;
|
|
220
|
+
required = belongsToDef.data.valueRequired;
|
|
221
|
+
}
|
|
222
|
+
for (const idField of typeDef.data.identifier) {
|
|
223
|
+
addFk({
|
|
224
|
+
onModel: fieldDef.data.relatedModel,
|
|
225
|
+
asField: fkName(modelName, fieldName, idField),
|
|
226
|
+
fieldDef: {
|
|
227
|
+
data: {
|
|
228
|
+
...(typeDef.data.fields[idField]?.data ||
|
|
229
|
+
(0, ModelField_1.id)().data),
|
|
230
|
+
authorization,
|
|
231
|
+
required,
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
break;
|
|
238
|
+
case ModelRelationalField_1.ModelRelationshipTypes.belongsTo:
|
|
239
|
+
{
|
|
240
|
+
// only create if corresponds to hasOne
|
|
241
|
+
const [_hasOneName, hasOneDef] = Object.entries(relatedModel.data.fields).find(([_name, def]) => {
|
|
242
|
+
return (isModelField(def) &&
|
|
243
|
+
def.data.type === ModelRelationalField_1.ModelRelationshipTypes.hasOne &&
|
|
244
|
+
def.data.relatedModel === modelName);
|
|
245
|
+
}) || [];
|
|
246
|
+
if (hasOneDef && isModelField(hasOneDef)) {
|
|
247
|
+
for (const idField of relatedModel.data.identifier) {
|
|
248
|
+
addFk({
|
|
249
|
+
onModel: modelName,
|
|
250
|
+
asField: fkName(modelName, fieldName, idField),
|
|
251
|
+
fieldDef: {
|
|
252
|
+
data: {
|
|
253
|
+
...typeDef.data,
|
|
254
|
+
fieldType: relatedModel.data.fields[idField]?.data.fieldType ||
|
|
255
|
+
ModelField_1.ModelFieldType.Id,
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
break;
|
|
263
|
+
case ModelRelationalField_1.ModelRelationshipTypes.manyToMany:
|
|
264
|
+
// pretty sure there's nothing to do here.
|
|
265
|
+
// the implicit join table already has everything, AFAIK.
|
|
266
|
+
break;
|
|
267
|
+
default:
|
|
268
|
+
// nothing to do.
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return fks;
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* Determines if implicit date fields are in effect for a given model. If they are,
|
|
276
|
+
* returns those implicit fields.
|
|
277
|
+
*
|
|
278
|
+
* NOTE: For now, we *only* support the default implicit fields.
|
|
279
|
+
*
|
|
280
|
+
* @param _model Model to find date fields for.
|
|
281
|
+
*/
|
|
282
|
+
const implicitTimestampFields = (_model) => {
|
|
283
|
+
return {
|
|
284
|
+
createdAt: (0, ModelField_1.datetime)().required(),
|
|
285
|
+
updatedAt: (0, ModelField_1.datetime)().required(),
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Generates default Pk fields for a model, based on identifier designation.
|
|
290
|
+
*
|
|
291
|
+
* The fields from this function are just default values. They should be overridden
|
|
292
|
+
* by ID field definitions that are explicit in the model.
|
|
293
|
+
*
|
|
294
|
+
* @param _model Model to find PK fields for.
|
|
295
|
+
*/
|
|
296
|
+
const idFields = (model) => {
|
|
297
|
+
const fields = {};
|
|
298
|
+
for (const fieldName of model.data.identifier) {
|
|
299
|
+
fields[fieldName] = (0, ModelField_1.id)().required();
|
|
300
|
+
}
|
|
301
|
+
return fields;
|
|
302
|
+
};
|
|
303
|
+
function processFieldLevelAuthRules(fields, authFields) {
|
|
304
|
+
const fieldLevelAuthRules = {};
|
|
305
|
+
for (const [fieldName, fieldDef] of Object.entries(fields)) {
|
|
306
|
+
const { authString, authFields: fieldAuthField } = calculateAuth(fieldDef?.data?.authorization || []);
|
|
307
|
+
if (authString)
|
|
308
|
+
fieldLevelAuthRules[fieldName] = authString;
|
|
309
|
+
if (fieldAuthField) {
|
|
310
|
+
Object.assign(authFields, fieldAuthField);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return fieldLevelAuthRules;
|
|
314
|
+
}
|
|
315
|
+
function processFields(fields, fieldLevelAuthRules, identifier, partitionKey) {
|
|
316
|
+
const gqlFields = [];
|
|
317
|
+
const models = [];
|
|
318
|
+
for (const [fieldName, fieldDef] of Object.entries(fields)) {
|
|
319
|
+
const fieldAuth = fieldLevelAuthRules[fieldName]
|
|
320
|
+
? ` ${fieldLevelAuthRules[fieldName]}`
|
|
321
|
+
: '';
|
|
322
|
+
if (isModelField(fieldDef)) {
|
|
323
|
+
gqlFields.push(`${fieldName}: ${modelFieldToGql(fieldDef.data)}${fieldAuth}`);
|
|
324
|
+
}
|
|
325
|
+
else if (isScalarField(fieldDef)) {
|
|
326
|
+
if (fieldName === partitionKey) {
|
|
327
|
+
gqlFields.push(`${fieldName}: ${scalarFieldToGql(fieldDef.data, identifier)}${fieldAuth}`);
|
|
328
|
+
}
|
|
329
|
+
else if (isRefField(fieldDef)) {
|
|
330
|
+
gqlFields.push(`${fieldName}: ${refFieldToGql(fieldDef.data)}${fieldAuth}`);
|
|
331
|
+
}
|
|
332
|
+
else if (isEnumType(fieldDef)) {
|
|
333
|
+
const enumName = capitalize(fieldName);
|
|
334
|
+
models.push([enumName, fieldDef]);
|
|
335
|
+
gqlFields.push(`${fieldName}: ${enumName}`);
|
|
336
|
+
}
|
|
337
|
+
else if (isCustomType(fieldDef)) {
|
|
338
|
+
const customTypeName = capitalize(fieldName);
|
|
339
|
+
models.push([customTypeName, fieldDef]);
|
|
340
|
+
gqlFields.push(`${fieldName}: ${customTypeName}`);
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
gqlFields.push(`${fieldName}: ${scalarFieldToGql(fieldDef.data)}${fieldAuth}`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
throw new Error(`Unexpected field definition: ${fieldDef}`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return { gqlFields, models };
|
|
351
|
+
}
|
|
352
|
+
const schemaPreprocessor = (schema) => {
|
|
353
|
+
const gqlModels = [];
|
|
354
|
+
const fkFields = allImpliedFKs(schema);
|
|
355
|
+
const topLevelTypes = Object.entries(schema.data.types);
|
|
356
|
+
for (const [typeName, typeDef] of topLevelTypes) {
|
|
357
|
+
if (!isInternalModel(typeDef)) {
|
|
358
|
+
if (isEnumType(typeDef)) {
|
|
359
|
+
const enumType = `enum ${typeName} {\n${typeDef.values.join('\n')}\n}`;
|
|
360
|
+
gqlModels.push(enumType);
|
|
361
|
+
}
|
|
362
|
+
else if (isCustomType(typeDef)) {
|
|
363
|
+
const fields = typeDef.data.fields;
|
|
364
|
+
const authString = '';
|
|
365
|
+
const authFields = {};
|
|
366
|
+
const fieldLevelAuthRules = processFieldLevelAuthRules(fields, authFields);
|
|
367
|
+
const { gqlFields, models } = processFields(fields, fieldLevelAuthRules);
|
|
368
|
+
topLevelTypes.push(...models);
|
|
369
|
+
const joined = gqlFields.join('\n ');
|
|
370
|
+
const model = `type ${typeName} ${authString}\n{\n ${joined}\n}`;
|
|
371
|
+
gqlModels.push(model);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
const fields = {
|
|
376
|
+
...typeDef.data.fields,
|
|
377
|
+
...fkFields[typeName],
|
|
378
|
+
};
|
|
379
|
+
const identifier = typeDef.data.identifier;
|
|
380
|
+
const [partitionKey] = identifier;
|
|
381
|
+
const { authString, authFields } = calculateAuth(typeDef.data.authorization);
|
|
382
|
+
const fieldLevelAuthRules = processFieldLevelAuthRules(fields, authFields);
|
|
383
|
+
const { gqlFields, models } = processFields({
|
|
384
|
+
// idFields first, so they can be overridden by customer definitions when present.
|
|
385
|
+
...idFields(typeDef),
|
|
386
|
+
...fields,
|
|
387
|
+
...authFields,
|
|
388
|
+
...implicitTimestampFields(typeDef),
|
|
389
|
+
}, fieldLevelAuthRules, identifier, partitionKey);
|
|
390
|
+
topLevelTypes.push(...models);
|
|
391
|
+
const joined = gqlFields.join('\n ');
|
|
392
|
+
const model = `type ${typeName} @model ${authString}\n{\n ${joined}\n}`;
|
|
393
|
+
gqlModels.push(model);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const processedSchema = gqlModels.join('\n\n');
|
|
397
|
+
return processedSchema;
|
|
398
|
+
};
|
|
399
|
+
/**
|
|
400
|
+
* Returns API definition from ModelSchema or string schema
|
|
401
|
+
* @param arg - { schema }
|
|
402
|
+
* @returns DerivedApiDefinition that conforms to IAmplifyGraphqlDefinition
|
|
403
|
+
*/
|
|
404
|
+
function processSchema(arg) {
|
|
405
|
+
const schema = schemaPreprocessor(arg.schema);
|
|
406
|
+
return { schema, functionSlots: [] };
|
|
407
|
+
}
|
|
408
|
+
exports.processSchema = processSchema;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { schema } from './ModelSchema';
|
|
2
|
+
import { model } from './ModelType';
|
|
3
|
+
import { id, string, integer, float, boolean, date, time, datetime, timestamp, email, json, phone, url, ipAddress } from './ModelField';
|
|
4
|
+
import { ref } from './RefType';
|
|
5
|
+
import { hasOne, hasMany, belongsTo, manyToMany } from './ModelRelationalField';
|
|
6
|
+
import { allow } from './Authorization';
|
|
7
|
+
import { customType } from './CustomType';
|
|
8
|
+
import { enumType } from './EnumType';
|
|
9
|
+
export { schema, model, ref, customType, enumType as enum, hasOne, hasMany, belongsTo, manyToMany, allow, id, string, integer, float, boolean, date, time, datetime, timestamp, email, json, phone, url, ipAddress, };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ipAddress = exports.url = exports.phone = exports.json = exports.email = exports.timestamp = exports.datetime = exports.time = exports.date = exports.boolean = exports.float = exports.integer = exports.string = exports.id = exports.allow = exports.manyToMany = exports.belongsTo = exports.hasMany = exports.hasOne = exports.enum = exports.customType = exports.ref = exports.model = exports.schema = void 0;
|
|
4
|
+
const ModelSchema_1 = require("./ModelSchema");
|
|
5
|
+
Object.defineProperty(exports, "schema", { enumerable: true, get: function () { return ModelSchema_1.schema; } });
|
|
6
|
+
const ModelType_1 = require("./ModelType");
|
|
7
|
+
Object.defineProperty(exports, "model", { enumerable: true, get: function () { return ModelType_1.model; } });
|
|
8
|
+
const ModelField_1 = require("./ModelField");
|
|
9
|
+
Object.defineProperty(exports, "id", { enumerable: true, get: function () { return ModelField_1.id; } });
|
|
10
|
+
Object.defineProperty(exports, "string", { enumerable: true, get: function () { return ModelField_1.string; } });
|
|
11
|
+
Object.defineProperty(exports, "integer", { enumerable: true, get: function () { return ModelField_1.integer; } });
|
|
12
|
+
Object.defineProperty(exports, "float", { enumerable: true, get: function () { return ModelField_1.float; } });
|
|
13
|
+
Object.defineProperty(exports, "boolean", { enumerable: true, get: function () { return ModelField_1.boolean; } });
|
|
14
|
+
Object.defineProperty(exports, "date", { enumerable: true, get: function () { return ModelField_1.date; } });
|
|
15
|
+
Object.defineProperty(exports, "time", { enumerable: true, get: function () { return ModelField_1.time; } });
|
|
16
|
+
Object.defineProperty(exports, "datetime", { enumerable: true, get: function () { return ModelField_1.datetime; } });
|
|
17
|
+
Object.defineProperty(exports, "timestamp", { enumerable: true, get: function () { return ModelField_1.timestamp; } });
|
|
18
|
+
Object.defineProperty(exports, "email", { enumerable: true, get: function () { return ModelField_1.email; } });
|
|
19
|
+
Object.defineProperty(exports, "json", { enumerable: true, get: function () { return ModelField_1.json; } });
|
|
20
|
+
Object.defineProperty(exports, "phone", { enumerable: true, get: function () { return ModelField_1.phone; } });
|
|
21
|
+
Object.defineProperty(exports, "url", { enumerable: true, get: function () { return ModelField_1.url; } });
|
|
22
|
+
Object.defineProperty(exports, "ipAddress", { enumerable: true, get: function () { return ModelField_1.ipAddress; } });
|
|
23
|
+
const RefType_1 = require("./RefType");
|
|
24
|
+
Object.defineProperty(exports, "ref", { enumerable: true, get: function () { return RefType_1.ref; } });
|
|
25
|
+
const ModelRelationalField_1 = require("./ModelRelationalField");
|
|
26
|
+
Object.defineProperty(exports, "hasOne", { enumerable: true, get: function () { return ModelRelationalField_1.hasOne; } });
|
|
27
|
+
Object.defineProperty(exports, "hasMany", { enumerable: true, get: function () { return ModelRelationalField_1.hasMany; } });
|
|
28
|
+
Object.defineProperty(exports, "belongsTo", { enumerable: true, get: function () { return ModelRelationalField_1.belongsTo; } });
|
|
29
|
+
Object.defineProperty(exports, "manyToMany", { enumerable: true, get: function () { return ModelRelationalField_1.manyToMany; } });
|
|
30
|
+
const Authorization_1 = require("./Authorization");
|
|
31
|
+
Object.defineProperty(exports, "allow", { enumerable: true, get: function () { return Authorization_1.allow; } });
|
|
32
|
+
const CustomType_1 = require("./CustomType");
|
|
33
|
+
Object.defineProperty(exports, "customType", { enumerable: true, get: function () { return CustomType_1.customType; } });
|
|
34
|
+
const EnumType_1 = require("./EnumType");
|
|
35
|
+
Object.defineProperty(exports, "enum", { enumerable: true, get: function () { return EnumType_1.enumType; } });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* references IAmplifyGraphqlDefinition from:
|
|
3
|
+
* https://github.com/aws-amplify/amplify-category-api/blob/4c0ea253a0bae51f775383929ba4748593185bc1/packages/amplify-graphql-api-construct/src/types.ts#L491-L503
|
|
4
|
+
*
|
|
5
|
+
* function slots is any'd for now. Will add actual type when we add support for this feature
|
|
6
|
+
*/
|
|
7
|
+
export interface DerivedApiDefinition {
|
|
8
|
+
/**
|
|
9
|
+
* Return the schema definition as a graphql string, with amplify directives allowed.
|
|
10
|
+
* @returns the rendered schema.
|
|
11
|
+
*/
|
|
12
|
+
readonly schema: string;
|
|
13
|
+
/**
|
|
14
|
+
* Retrieve any function slots defined explicitly in the Api definition.
|
|
15
|
+
* @returns generated function slots
|
|
16
|
+
*/
|
|
17
|
+
readonly functionSlots: any[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* references IAmplifyGraphqlDefinition from:
|
|
4
|
+
* https://github.com/aws-amplify/amplify-category-api/blob/4c0ea253a0bae51f775383929ba4748593185bc1/packages/amplify-graphql-api-construct/src/types.ts#L491-L503
|
|
5
|
+
*
|
|
6
|
+
* function slots is any'd for now. Will add actual type when we add support for this feature
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|