rastack 0.0.16 → 0.0.19
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/CHANGELOG.md +43874 -43013
- package/dist/.prettierrc +7 -7
- package/dist/compile/analyze.js +19 -11
- package/dist/compile/index.js +26 -17
- package/dist/compile/manifest.js +2 -3
- package/dist/compile/openapi.js +5 -8
- package/dist/compile/program.js +19 -10
- package/dist/csv-schema.js +5 -6
- package/dist/define/index.js +2 -2
- package/dist/entity-generation/delete-method.js +8 -10
- package/dist/entity-generation/form.js +80 -82
- package/dist/entity-generation/get-method.js +35 -36
- package/dist/entity-generation/imports.js +24 -20
- package/dist/entity-generation/sync-method.d.ts +1 -1
- package/dist/entity-generation/sync-method.js +45 -46
- package/dist/entity-generation/update-method.js +9 -10
- package/dist/rad-wasm-build.d.ts +1 -1
- package/dist/rad-wasm-build.js +15 -6
- package/dist/rad.js +9 -2
- package/dist/schema/camel-to-pastel.js +1 -2
- package/dist/schema/capitalise-first-letter.js +1 -2
- package/dist/schema/extract-response.js +3 -4
- package/dist/schema/fetch-schema.js +4 -16
- package/dist/schema/remove-non-model-paths.js +1 -2
- package/dist/schema/to-camel-case.js +1 -2
- package/dist/schema/to-pastel-case.js +1 -2
- package/dist/schema-convert.js +22 -33
- package/dist/schema-entities.js +177 -189
- package/dist/schema-fetch.js +46 -63
- package/dist/schema-full.js +23 -36
- package/dist/schema-index.js +16 -27
- package/dist/schema-params.js +11 -22
- package/dist/seed.js +95 -97
- package/hooks/form/form.ts +207 -207
- package/hooks/form/index.ts +8 -8
- package/hooks/form/interfaces.ts +217 -217
- package/hooks/form/structure.ts +39 -39
- package/hooks/form/validate-schema.ts +49 -49
- package/hooks/index.ts +3 -3
- package/hooks/query/api.ts +42 -42
- package/hooks/query/delete.ts +45 -45
- package/hooks/query/fetch.ts +48 -48
- package/hooks/query/index.ts +21 -21
- package/hooks/query/interfaces.ts +111 -111
- package/hooks/query/list.ts +286 -286
- package/hooks/query/update.ts +88 -88
- package/hooks/query/url.ts +31 -31
- package/hooks/real-time/index.ts +1 -1
- package/hooks/real-time/pusher.ts +43 -43
- package/jest.config.cjs +6 -6
- package/package.json +57 -57
- package/provider/index.ts +13 -13
- package/provider/provider.tsx +187 -187
- package/provider/types.ts +114 -114
- package/provider/warehouse.ts +167 -167
- package/provider/wasm.ts +124 -124
- package/runtime.ts +3 -3
- package/src/.prettierrc +7 -7
- package/src/compile/analyze.ts +224 -224
- package/src/compile/index.ts +86 -86
- package/src/compile/manifest.ts +10 -10
- package/src/compile/model.ts +69 -69
- package/src/compile/openapi.ts +266 -266
- package/src/compile/program.ts +40 -40
- package/src/csv-schema.ts +187 -187
- package/src/define/index.ts +162 -162
- package/src/entity-generation/delete-method.ts +37 -37
- package/src/entity-generation/form.ts +169 -169
- package/src/entity-generation/get-method.ts +80 -80
- package/src/entity-generation/imports.ts +110 -110
- package/src/entity-generation/sync-method.ts +222 -222
- package/src/entity-generation/update-method.ts +38 -38
- package/src/index.ts +77 -77
- package/src/rad-compile.ts +88 -88
- package/src/rad-wasm-build.ts +102 -102
- package/src/rad.ts +101 -101
- package/src/scan.ts +89 -89
- package/src/schema/camel-to-pastel.ts +3 -3
- package/src/schema/capitalise-first-letter.ts +3 -3
- package/src/schema/extract-response.ts +38 -38
- package/src/schema/fetch-schema.ts +12 -12
- package/src/schema/remove-non-model-paths.ts +13 -13
- package/src/schema/to-camel-case.ts +7 -7
- package/src/schema/to-pastel-case.ts +6 -6
- package/src/schema-convert.ts +61 -61
- package/src/schema-entities.ts +401 -401
- package/src/schema-fetch.ts +82 -82
- package/src/schema-full.ts +38 -38
- package/src/schema-index.ts +29 -29
- package/src/schema-params.ts +116 -116
- package/src/seed.ts +297 -297
- package/sync/engine.ts +392 -392
- package/sync/hooks.ts +450 -450
- package/sync/index.ts +8 -8
- package/sync/persistence.ts +237 -237
- package/sync/provider.tsx +91 -91
- package/sync/registry.ts +36 -36
- package/sync/store.ts +126 -126
- package/sync/transactions.ts +300 -300
- package/sync/types.ts +94 -94
- package/test/compile.spec.ts +192 -192
- package/test/csv-schema.spec.ts +143 -143
- package/test/schema-entities.spec.ts +688 -688
- package/tsconfig.json +24 -24
- package/types.ts +18 -18
package/dist/schema-entities.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
3
|
+
exports.collectEntityMeta = collectEntityMeta;
|
|
4
|
+
exports.generateFolders = generateFolders;
|
|
5
|
+
exports.generateFiles = generateFiles;
|
|
6
|
+
exports.main = main;
|
|
13
7
|
const fs_1 = require("fs");
|
|
14
8
|
const path_1 = require("path");
|
|
15
9
|
const extract_response_1 = require("./schema/extract-response");
|
|
@@ -89,202 +83,196 @@ function collectEntityMeta(paths) {
|
|
|
89
83
|
});
|
|
90
84
|
return meta;
|
|
91
85
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
(0, fs_1.mkdirSync)(appFolder, { recursive: true });
|
|
101
|
-
(0, fs_1.mkdirSync)(modelFolder, { recursive: true });
|
|
102
|
-
});
|
|
86
|
+
async function generateFolders(entitiesPath, paths) {
|
|
87
|
+
Object.keys(paths).forEach((key) => {
|
|
88
|
+
const appName = key.split("/")[2];
|
|
89
|
+
const modelName = key.split("/")[4];
|
|
90
|
+
const appFolder = (0, path_1.join)(entitiesPath, appName);
|
|
91
|
+
const modelFolder = (0, path_1.join)(appFolder, modelName);
|
|
92
|
+
(0, fs_1.mkdirSync)(appFolder, { recursive: true });
|
|
93
|
+
(0, fs_1.mkdirSync)(modelFolder, { recursive: true });
|
|
103
94
|
});
|
|
104
95
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
96
|
+
async function generateFiles(entitiesPath, paths) {
|
|
97
|
+
const uniqueOperationNames = [];
|
|
98
|
+
const modelFileImports = {};
|
|
99
|
+
const modelFileData = {};
|
|
100
|
+
const keysFileData = {};
|
|
101
|
+
const modelImportsFileData = {};
|
|
102
|
+
const formMutationOperations = {};
|
|
103
|
+
const entityMeta = collectEntityMeta(paths);
|
|
104
|
+
Object.keys(paths).forEach((pathKey) => {
|
|
105
|
+
const appName = pathKey.split("/")[2];
|
|
106
|
+
const modelName = pathKey.split("/")[4];
|
|
107
|
+
const indexKey = `${appName}|${modelName}`;
|
|
108
|
+
if (!formMutationOperations[indexKey]) {
|
|
109
|
+
formMutationOperations[indexKey] = {
|
|
110
|
+
post: {
|
|
111
|
+
operationId: undefined,
|
|
112
|
+
schema: undefined,
|
|
113
|
+
},
|
|
114
|
+
put: {
|
|
115
|
+
operationId: undefined,
|
|
116
|
+
schema: undefined,
|
|
117
|
+
},
|
|
118
|
+
patch: {
|
|
119
|
+
operationId: undefined,
|
|
120
|
+
schema: undefined,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (!modelImportsFileData[appName]) {
|
|
125
|
+
modelImportsFileData[appName] = [modelName];
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
if (!modelImportsFileData[appName].includes(modelName)) {
|
|
129
|
+
modelImportsFileData[appName].push(modelName);
|
|
137
130
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
}
|
|
132
|
+
Object.keys(paths[pathKey]).forEach((method) => {
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
const methodInformation = paths[pathKey][method];
|
|
135
|
+
const methodParameters = methodInformation.parameters;
|
|
136
|
+
const pathParameters = methodParameters
|
|
137
|
+
? methodParameters
|
|
138
|
+
.filter((item) => item.required)
|
|
139
|
+
.filter((item) => item.in === "path")
|
|
140
|
+
.map((item) => item.name)
|
|
141
|
+
: [];
|
|
142
|
+
const requestBody = methodInformation.requestBody;
|
|
143
|
+
// @ts-ignore
|
|
144
|
+
const requestBodySchema = requestBody?.content?.["application/json"]?.schema["$ref"]?.replace("#/components/schemas/", "");
|
|
145
|
+
let [responseBodySchema, isList] = (0, extract_response_1.extractResponseBodySchema)(methodInformation);
|
|
146
|
+
const requiredParameters = methodParameters
|
|
147
|
+
? methodParameters
|
|
148
|
+
.filter((item) => item.required)
|
|
149
|
+
.map((item) => item.name)
|
|
150
|
+
: [];
|
|
151
|
+
const operationId = methodInformation.operationId;
|
|
152
|
+
if (!uniqueOperationNames.includes(operationId)) {
|
|
153
|
+
uniqueOperationNames.push(operationId);
|
|
154
|
+
let apiMethods = "";
|
|
155
|
+
let importStatements = new Set();
|
|
156
|
+
const isPostListEndpoint = method === "post" &&
|
|
157
|
+
(operationId.includes("List") || operationId.includes("list"));
|
|
158
|
+
const isListEndpoint = isList || isPostListEndpoint;
|
|
159
|
+
const meta = entityMeta[indexKey];
|
|
160
|
+
const isSyncEntity = meta?.sync === true;
|
|
161
|
+
const isConfirmedOperation = methodInformation["x-rastack-sync"] === "confirmed" &&
|
|
162
|
+
method !== "get";
|
|
163
|
+
const modelCamel = (0, to_camel_case_1.toCamelCase)(modelName);
|
|
164
|
+
const listKeyRef = meta?.listOperationId
|
|
165
|
+
? `${modelCamel}QueriesKeys.${meta.listOperationId}`
|
|
166
|
+
: undefined;
|
|
167
|
+
const itemKeyRef = meta?.detailOperationId
|
|
168
|
+
? `${modelCamel}QueriesKeys.${meta.detailOperationId}`
|
|
169
|
+
: undefined;
|
|
170
|
+
if (isConfirmedOperation) {
|
|
171
|
+
[apiMethods, importStatements] = (0, sync_method_1.generateConfirmedMethod)(pathKey, method, operationId, requestBodySchema ? `I${requestBodySchema}` : undefined, responseBodySchema ? `I${responseBodySchema}` : undefined);
|
|
172
|
+
formMutationOperations[indexKey] = {
|
|
173
|
+
...formMutationOperations[indexKey],
|
|
174
|
+
[pathKey]: {
|
|
175
|
+
[method]: {
|
|
176
|
+
operationId: (0, camel_to_pastel_1.camelToPastel)(operationId),
|
|
177
|
+
schema: requestBodySchema ? `I${requestBodySchema}` : "",
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
};
|
|
141
181
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// @ts-ignore
|
|
146
|
-
const methodInformation = paths[pathKey][method];
|
|
147
|
-
const methodParameters = methodInformation.parameters;
|
|
148
|
-
const pathParameters = methodParameters
|
|
149
|
-
? methodParameters
|
|
150
|
-
.filter((item) => item.required)
|
|
151
|
-
.filter((item) => item.in === "path")
|
|
152
|
-
.map((item) => item.name)
|
|
153
|
-
: [];
|
|
154
|
-
const requestBody = methodInformation.requestBody;
|
|
155
|
-
// @ts-ignore
|
|
156
|
-
const requestBodySchema = (_c = (_b = (_a = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content) === null || _a === void 0 ? void 0 : _a["application/json"]) === null || _b === void 0 ? void 0 : _b.schema["$ref"]) === null || _c === void 0 ? void 0 : _c.replace("#/components/schemas/", "");
|
|
157
|
-
let [responseBodySchema, isList] = (0, extract_response_1.extractResponseBodySchema)(methodInformation);
|
|
158
|
-
const requiredParameters = methodParameters
|
|
159
|
-
? methodParameters
|
|
160
|
-
.filter((item) => item.required)
|
|
161
|
-
.map((item) => item.name)
|
|
162
|
-
: [];
|
|
163
|
-
const operationId = methodInformation.operationId;
|
|
164
|
-
if (!uniqueOperationNames.includes(operationId)) {
|
|
165
|
-
uniqueOperationNames.push(operationId);
|
|
166
|
-
let apiMethods = "";
|
|
167
|
-
let importStatements = new Set();
|
|
168
|
-
const isPostListEndpoint = method === "post" &&
|
|
169
|
-
(operationId.includes("List") || operationId.includes("list"));
|
|
170
|
-
const isListEndpoint = isList || isPostListEndpoint;
|
|
171
|
-
const meta = entityMeta[indexKey];
|
|
172
|
-
const isSyncEntity = (meta === null || meta === void 0 ? void 0 : meta.sync) === true;
|
|
173
|
-
const isConfirmedOperation = methodInformation["x-rastack-sync"] === "confirmed" &&
|
|
174
|
-
method !== "get";
|
|
175
|
-
const modelCamel = (0, to_camel_case_1.toCamelCase)(modelName);
|
|
176
|
-
const listKeyRef = (meta === null || meta === void 0 ? void 0 : meta.listOperationId)
|
|
177
|
-
? `${modelCamel}QueriesKeys.${meta.listOperationId}`
|
|
178
|
-
: undefined;
|
|
179
|
-
const itemKeyRef = (meta === null || meta === void 0 ? void 0 : meta.detailOperationId)
|
|
180
|
-
? `${modelCamel}QueriesKeys.${meta.detailOperationId}`
|
|
181
|
-
: undefined;
|
|
182
|
-
if (isConfirmedOperation) {
|
|
183
|
-
[apiMethods, importStatements] = (0, sync_method_1.generateConfirmedMethod)(pathKey, method, operationId, requestBodySchema ? `I${requestBodySchema}` : undefined, responseBodySchema ? `I${responseBodySchema}` : undefined);
|
|
184
|
-
formMutationOperations[indexKey] = Object.assign(Object.assign({}, formMutationOperations[indexKey]), { [pathKey]: {
|
|
185
|
-
[method]: {
|
|
186
|
-
operationId: (0, camel_to_pastel_1.camelToPastel)(operationId),
|
|
187
|
-
schema: requestBodySchema ? `I${requestBodySchema}` : "",
|
|
188
|
-
},
|
|
189
|
-
} });
|
|
182
|
+
else if (method === "get" || isPostListEndpoint) {
|
|
183
|
+
if (isSyncEntity && isListEndpoint) {
|
|
184
|
+
[apiMethods, importStatements] = (0, sync_method_1.generateSyncListMethod)(modelName, operationId, meta.rowSchema);
|
|
190
185
|
}
|
|
191
|
-
else if (
|
|
192
|
-
|
|
193
|
-
[
|
|
194
|
-
|
|
195
|
-
else if (isSyncEntity && pathKey.includes("{")) {
|
|
196
|
-
const urlParams = ((_d = pathKey.match(/{([^}]+)}/g)) === null || _d === void 0 ? void 0 : _d.map((param) => param.slice(1, -1))) ||
|
|
197
|
-
[];
|
|
198
|
-
[apiMethods, importStatements] = (0, sync_method_1.generateSyncRecordMethod)(modelName, operationId, meta.rowSchema, pathParameters.length > 0 ? pathParameters : urlParams);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
[apiMethods, importStatements] = (0, get_method_1.generateGetAPIMethod)(pathKey, modelName, operationId, responseBodySchema ? `I${responseBodySchema}` : undefined, isListEndpoint, pathParameters, requiredParameters, method, requestBodySchema !== undefined ? requestBodySchema : "");
|
|
202
|
-
}
|
|
186
|
+
else if (isSyncEntity && pathKey.includes("{")) {
|
|
187
|
+
const urlParams = pathKey.match(/{([^}]+)}/g)?.map((param) => param.slice(1, -1)) ||
|
|
188
|
+
[];
|
|
189
|
+
[apiMethods, importStatements] = (0, sync_method_1.generateSyncRecordMethod)(modelName, operationId, meta.rowSchema, pathParameters.length > 0 ? pathParameters : urlParams);
|
|
203
190
|
}
|
|
204
|
-
else
|
|
205
|
-
method
|
|
206
|
-
method === "patch") {
|
|
207
|
-
if (isSyncEntity) {
|
|
208
|
-
[apiMethods, importStatements] = (0, sync_method_1.generateSyncUpdateMethod)(pathKey, method, modelName, operationId, requestBodySchema ? `I${requestBodySchema}` : undefined, responseBodySchema ? `I${responseBodySchema}` : undefined, pathParameters);
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
[apiMethods, importStatements] = (0, update_method_1.generateUpdateAPIMethod)(pathKey, method, operationId, requestBodySchema ? `I${requestBodySchema}` : undefined, responseBodySchema ? `I${responseBodySchema}` : undefined, listKeyRef, itemKeyRef);
|
|
212
|
-
}
|
|
213
|
-
formMutationOperations[indexKey] = Object.assign(Object.assign({}, formMutationOperations[indexKey]), { [pathKey]: {
|
|
214
|
-
[method]: {
|
|
215
|
-
operationId: (0, camel_to_pastel_1.camelToPastel)(operationId),
|
|
216
|
-
schema: requestBodySchema ? `I${requestBodySchema}` : "",
|
|
217
|
-
},
|
|
218
|
-
} });
|
|
191
|
+
else {
|
|
192
|
+
[apiMethods, importStatements] = (0, get_method_1.generateGetAPIMethod)(pathKey, modelName, operationId, responseBodySchema ? `I${responseBodySchema}` : undefined, isListEndpoint, pathParameters, requiredParameters, method, requestBodySchema !== undefined ? requestBodySchema : "");
|
|
219
193
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
194
|
+
}
|
|
195
|
+
else if (method === "post" ||
|
|
196
|
+
method === "put" ||
|
|
197
|
+
method === "patch") {
|
|
198
|
+
if (isSyncEntity) {
|
|
199
|
+
[apiMethods, importStatements] = (0, sync_method_1.generateSyncUpdateMethod)(pathKey, method, modelName, operationId, requestBodySchema ? `I${requestBodySchema}` : undefined, responseBodySchema ? `I${responseBodySchema}` : undefined, pathParameters);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
[apiMethods, importStatements] = (0, update_method_1.generateUpdateAPIMethod)(pathKey, method, operationId, requestBodySchema ? `I${requestBodySchema}` : undefined, responseBodySchema ? `I${responseBodySchema}` : undefined, listKeyRef, itemKeyRef);
|
|
227
203
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
204
|
+
formMutationOperations[indexKey] = {
|
|
205
|
+
...formMutationOperations[indexKey],
|
|
206
|
+
[pathKey]: {
|
|
207
|
+
[method]: {
|
|
208
|
+
operationId: (0, camel_to_pastel_1.camelToPastel)(operationId),
|
|
209
|
+
schema: requestBodySchema ? `I${requestBodySchema}` : "",
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
};
|
|
237
213
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const [updateFormMethod, importStatements] = (0, form_1.generateUpdateFormMethod)(appName, modelName, formMutationOperations[key]);
|
|
248
|
-
const indexKey = `${appName}|${modelName}`;
|
|
249
|
-
modelFileImports[indexKey] = new Set([
|
|
250
|
-
...(modelFileImports[indexKey] || []),
|
|
251
|
-
...importStatements,
|
|
252
|
-
]);
|
|
253
|
-
let entityDescriptor = "";
|
|
254
|
-
if ((_a = entityMeta[key]) === null || _a === void 0 ? void 0 : _a.sync) {
|
|
255
|
-
const [descriptorCode, descriptorImports] = (0, sync_method_1.generateEntityDescriptor)(appName, modelName, entityMeta[key]);
|
|
256
|
-
entityDescriptor = descriptorCode;
|
|
214
|
+
else if (method === "delete") {
|
|
215
|
+
if (isSyncEntity) {
|
|
216
|
+
[apiMethods, importStatements] = (0, sync_method_1.generateSyncDeleteMethod)(pathKey, modelName, operationId);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
[apiMethods, importStatements] = (0, delete_method_1.generateDeleteAPIMethod)(pathKey, operationId, listKeyRef);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
modelFileData[indexKey] = (modelFileData[indexKey] || "") + apiMethods;
|
|
257
223
|
modelFileImports[indexKey] = new Set([
|
|
258
224
|
...(modelFileImports[indexKey] || []),
|
|
259
|
-
...
|
|
225
|
+
...importStatements,
|
|
260
226
|
]);
|
|
227
|
+
keysFileData[indexKey] = [
|
|
228
|
+
...(keysFileData[indexKey] || []),
|
|
229
|
+
operationId,
|
|
230
|
+
];
|
|
261
231
|
}
|
|
262
|
-
const importData = (0, imports_1.generateImportStatements)(modelFileImports[key], modelName);
|
|
263
|
-
const apiFileText = `${importData}\n${keyImports}\n${entityDescriptor}${modelFileData[key]}\n${updateFormMethod}`;
|
|
264
|
-
const indexImports = (0, imports_1.generateIndexImports)(modelName, keysFileData[key]);
|
|
265
|
-
(0, fs_1.writeFileSync)(apiFile, apiFileText, { flag: "w" });
|
|
266
|
-
(0, fs_1.writeFileSync)(indexFile, indexImports, { flag: "w" });
|
|
267
|
-
});
|
|
268
|
-
// create an index file with all the file names per model
|
|
269
|
-
Object.keys(modelImportsFileData).forEach((key) => {
|
|
270
|
-
const modelFolder = (0, path_1.join)(entitiesPath, key);
|
|
271
|
-
const indexFile = (0, path_1.join)(modelFolder, "index.ts");
|
|
272
|
-
const indexImports = (0, imports_1.generateFolderImports)(modelImportsFileData[key]);
|
|
273
|
-
(0, fs_1.writeFileSync)(indexFile, indexImports, { flag: "w" });
|
|
274
232
|
});
|
|
275
233
|
});
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
234
|
+
Object.keys(modelFileData).forEach((key) => {
|
|
235
|
+
const [appName, modelName] = key.split("|");
|
|
236
|
+
const modelFolder = (0, path_1.join)(entitiesPath, appName, modelName);
|
|
237
|
+
const apiFile = (0, path_1.join)(modelFolder, "api.ts");
|
|
238
|
+
const indexFile = (0, path_1.join)(modelFolder, "index.ts");
|
|
239
|
+
const keyImports = (0, imports_1.generateKeyImports)(modelName, keysFileData[key]);
|
|
240
|
+
const [updateFormMethod, importStatements] = (0, form_1.generateUpdateFormMethod)(appName, modelName, formMutationOperations[key]);
|
|
241
|
+
const indexKey = `${appName}|${modelName}`;
|
|
242
|
+
modelFileImports[indexKey] = new Set([
|
|
243
|
+
...(modelFileImports[indexKey] || []),
|
|
244
|
+
...importStatements,
|
|
245
|
+
]);
|
|
246
|
+
let entityDescriptor = "";
|
|
247
|
+
if (entityMeta[key]?.sync) {
|
|
248
|
+
const [descriptorCode, descriptorImports] = (0, sync_method_1.generateEntityDescriptor)(appName, modelName, entityMeta[key]);
|
|
249
|
+
entityDescriptor = descriptorCode;
|
|
250
|
+
modelFileImports[indexKey] = new Set([
|
|
251
|
+
...(modelFileImports[indexKey] || []),
|
|
252
|
+
...descriptorImports,
|
|
253
|
+
]);
|
|
254
|
+
}
|
|
255
|
+
const importData = (0, imports_1.generateImportStatements)(modelFileImports[key], modelName);
|
|
256
|
+
const apiFileText = `${importData}\n${keyImports}\n${entityDescriptor}${modelFileData[key]}\n${updateFormMethod}`;
|
|
257
|
+
const indexImports = (0, imports_1.generateIndexImports)(modelName, keysFileData[key]);
|
|
258
|
+
(0, fs_1.writeFileSync)(apiFile, apiFileText, { flag: "w" });
|
|
259
|
+
(0, fs_1.writeFileSync)(indexFile, indexImports, { flag: "w" });
|
|
260
|
+
});
|
|
261
|
+
// create an index file with all the file names per model
|
|
262
|
+
Object.keys(modelImportsFileData).forEach((key) => {
|
|
263
|
+
const modelFolder = (0, path_1.join)(entitiesPath, key);
|
|
264
|
+
const indexFile = (0, path_1.join)(modelFolder, "index.ts");
|
|
265
|
+
const indexImports = (0, imports_1.generateFolderImports)(modelImportsFileData[key]);
|
|
266
|
+
(0, fs_1.writeFileSync)(indexFile, indexImports, { flag: "w" });
|
|
285
267
|
});
|
|
286
268
|
}
|
|
287
|
-
|
|
269
|
+
async function main(url, entitiesPath) {
|
|
270
|
+
console.log("Generating Entities");
|
|
271
|
+
const data = await (0, fetch_schema_1.fetchSchema)(url);
|
|
272
|
+
const filteredPaths = (0, remove_non_model_paths_1.removeNonModelPaths)(data.paths);
|
|
273
|
+
await generateFolders(entitiesPath, filteredPaths);
|
|
274
|
+
await generateFiles(entitiesPath, filteredPaths);
|
|
275
|
+
}
|
|
288
276
|
if (require.main === module) {
|
|
289
277
|
const args = process.argv.slice(2);
|
|
290
278
|
const url = args[0];
|
package/dist/schema-fetch.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -15,67 +6,59 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
6
|
const fs_1 = require("fs");
|
|
16
7
|
const path_1 = require("path");
|
|
17
8
|
const axios_1 = __importDefault(require("axios"));
|
|
18
|
-
function fetchSchema(url, schemaPath) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
async function fetchSchema(url, schemaPath) {
|
|
10
|
+
const response = await axios_1.default.get(url);
|
|
11
|
+
(0, fs_1.writeFileSync)(schemaPath, JSON.stringify(response.data, null, 2));
|
|
12
|
+
return response.data;
|
|
13
|
+
}
|
|
14
|
+
async function generateFiles(basePath, components) {
|
|
15
|
+
const schemas = components.schemas;
|
|
16
|
+
Object.keys(schemas).forEach((key) => {
|
|
17
|
+
const schema = schemas[key];
|
|
18
|
+
let schemaKey = key;
|
|
19
|
+
if (key.endsWith("Enum")) {
|
|
20
|
+
schemaKey = key.replace("Enum", "");
|
|
21
|
+
schemaKey = `E${schemaKey}`;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
schemaKey = `I${schemaKey}`;
|
|
25
|
+
}
|
|
26
|
+
const schemaFolderPath = (0, path_1.join)(basePath, "api-schema");
|
|
27
|
+
const fileName = `${schemaFolderPath}/${schemaKey}.json`;
|
|
28
|
+
(0, fs_1.writeFileSync)(fileName, JSON.stringify(schema, null, 2));
|
|
23
29
|
});
|
|
24
30
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
async function replaceReferences(basePath) {
|
|
32
|
+
const schemaFolderPath = (0, path_1.join)(basePath, "api-schema");
|
|
33
|
+
const schemaFiles = (0, fs_1.readdirSync)(schemaFolderPath);
|
|
34
|
+
schemaFiles.forEach((file) => {
|
|
35
|
+
const filePath = (0, path_1.join)(schemaFolderPath, file);
|
|
36
|
+
const fileContent = JSON.parse((0, fs_1.readFileSync)(filePath, "utf8"));
|
|
37
|
+
let convertedSchema = JSON.stringify(fileContent);
|
|
38
|
+
const searchPattern = /"#\/components\/schemas\/([A-Za-z0-9_-]+)"/g;
|
|
39
|
+
convertedSchema = convertedSchema.replace(searchPattern, (_, matchedSchemaName) => {
|
|
40
|
+
let updatedSchemaName = matchedSchemaName;
|
|
41
|
+
if (updatedSchemaName.endsWith("Enum")) {
|
|
42
|
+
updatedSchemaName = updatedSchemaName.replace("Enum", "");
|
|
43
|
+
updatedSchemaName = `E${updatedSchemaName}`;
|
|
34
44
|
}
|
|
35
45
|
else {
|
|
36
|
-
|
|
46
|
+
updatedSchemaName = `I${updatedSchemaName}`;
|
|
37
47
|
}
|
|
38
|
-
|
|
39
|
-
const fileName = `${schemaFolderPath}/${schemaKey}.json`;
|
|
40
|
-
(0, fs_1.writeFileSync)(fileName, JSON.stringify(schema, null, 2));
|
|
48
|
+
return `"${updatedSchemaName}.json"`;
|
|
41
49
|
});
|
|
50
|
+
const writeSchema = JSON.parse(convertedSchema);
|
|
51
|
+
(0, fs_1.writeFileSync)(filePath, JSON.stringify(writeSchema, null, 2));
|
|
42
52
|
});
|
|
43
53
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
convertedSchema = convertedSchema.replace(searchPattern, (_, matchedSchemaName) => {
|
|
54
|
-
let updatedSchemaName = matchedSchemaName;
|
|
55
|
-
if (updatedSchemaName.endsWith("Enum")) {
|
|
56
|
-
updatedSchemaName = updatedSchemaName.replace("Enum", "");
|
|
57
|
-
updatedSchemaName = `E${updatedSchemaName}`;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
updatedSchemaName = `I${updatedSchemaName}`;
|
|
61
|
-
}
|
|
62
|
-
return `"${updatedSchemaName}.json"`;
|
|
63
|
-
});
|
|
64
|
-
const writeSchema = JSON.parse(convertedSchema);
|
|
65
|
-
(0, fs_1.writeFileSync)(filePath, JSON.stringify(writeSchema, null, 2));
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
function main() {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
console.log("Fetching Schema");
|
|
72
|
-
const args = process.argv.slice(2);
|
|
73
|
-
const url = args[0];
|
|
74
|
-
const basePath = args[1];
|
|
75
|
-
const schemaPath = (0, path_1.join)(basePath, "schema.json");
|
|
76
|
-
const { components } = yield fetchSchema(url, schemaPath);
|
|
77
|
-
yield generateFiles(basePath, components);
|
|
78
|
-
yield replaceReferences(basePath);
|
|
79
|
-
});
|
|
54
|
+
async function main() {
|
|
55
|
+
console.log("Fetching Schema");
|
|
56
|
+
const args = process.argv.slice(2);
|
|
57
|
+
const url = args[0];
|
|
58
|
+
const basePath = args[1];
|
|
59
|
+
const schemaPath = (0, path_1.join)(basePath, "schema.json");
|
|
60
|
+
const { components } = await fetchSchema(url, schemaPath);
|
|
61
|
+
await generateFiles(basePath, components);
|
|
62
|
+
await replaceReferences(basePath);
|
|
80
63
|
}
|
|
81
64
|
main();
|
package/dist/schema-full.js
CHANGED
|
@@ -1,45 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const fs_1 = require("fs");
|
|
13
4
|
const path_1 = require("path");
|
|
14
5
|
const $RefParser = require("@apidevtools/json-schema-ref-parser");
|
|
15
|
-
function generateDereferencedSchema(schemaPath) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
});
|
|
6
|
+
async function generateDereferencedSchema(schemaPath) {
|
|
7
|
+
try {
|
|
8
|
+
const schemaContent = (0, fs_1.readFileSync)(schemaPath, "utf8");
|
|
9
|
+
const schemaObject = JSON.parse(schemaContent);
|
|
10
|
+
const dereferencedSchema = await $RefParser.dereference(schemaObject);
|
|
11
|
+
return JSON.stringify(dereferencedSchema, null, 2);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
27
16
|
}
|
|
28
|
-
function main() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(0, fs_1.writeFileSync)(outputFilePath, generatedCode);
|
|
41
|
-
}));
|
|
42
|
-
let results = yield Promise.all(compilePromises);
|
|
17
|
+
async function main() {
|
|
18
|
+
console.log("Resolving Schemas");
|
|
19
|
+
const args = process.argv.slice(2);
|
|
20
|
+
const basePath = args[0];
|
|
21
|
+
const schemaFolderPath = (0, path_1.join)(basePath, "api-schema");
|
|
22
|
+
const outputFolder = (0, path_1.join)(basePath, "form-schema");
|
|
23
|
+
const schemaFiles = (0, fs_1.readdirSync)(schemaFolderPath);
|
|
24
|
+
let compilePromises = schemaFiles.map(async (schemaFile) => {
|
|
25
|
+
const schemaFilePath = (0, path_1.join)(schemaFolderPath, schemaFile);
|
|
26
|
+
const generatedCode = await generateDereferencedSchema(schemaFilePath);
|
|
27
|
+
const outputFilePath = (0, path_1.join)(outputFolder, schemaFile);
|
|
28
|
+
(0, fs_1.writeFileSync)(outputFilePath, generatedCode);
|
|
43
29
|
});
|
|
30
|
+
let results = await Promise.all(compilePromises);
|
|
44
31
|
}
|
|
45
32
|
main();
|