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.
Files changed (105) hide show
  1. package/CHANGELOG.md +43874 -43013
  2. package/dist/.prettierrc +7 -7
  3. package/dist/compile/analyze.js +19 -11
  4. package/dist/compile/index.js +26 -17
  5. package/dist/compile/manifest.js +2 -3
  6. package/dist/compile/openapi.js +5 -8
  7. package/dist/compile/program.js +19 -10
  8. package/dist/csv-schema.js +5 -6
  9. package/dist/define/index.js +2 -2
  10. package/dist/entity-generation/delete-method.js +8 -10
  11. package/dist/entity-generation/form.js +80 -82
  12. package/dist/entity-generation/get-method.js +35 -36
  13. package/dist/entity-generation/imports.js +24 -20
  14. package/dist/entity-generation/sync-method.d.ts +1 -1
  15. package/dist/entity-generation/sync-method.js +45 -46
  16. package/dist/entity-generation/update-method.js +9 -10
  17. package/dist/rad-wasm-build.d.ts +1 -1
  18. package/dist/rad-wasm-build.js +15 -6
  19. package/dist/rad.js +9 -2
  20. package/dist/schema/camel-to-pastel.js +1 -2
  21. package/dist/schema/capitalise-first-letter.js +1 -2
  22. package/dist/schema/extract-response.js +3 -4
  23. package/dist/schema/fetch-schema.js +4 -16
  24. package/dist/schema/remove-non-model-paths.js +1 -2
  25. package/dist/schema/to-camel-case.js +1 -2
  26. package/dist/schema/to-pastel-case.js +1 -2
  27. package/dist/schema-convert.js +22 -33
  28. package/dist/schema-entities.js +177 -189
  29. package/dist/schema-fetch.js +46 -63
  30. package/dist/schema-full.js +23 -36
  31. package/dist/schema-index.js +16 -27
  32. package/dist/schema-params.js +11 -22
  33. package/dist/seed.js +95 -97
  34. package/hooks/form/form.ts +207 -207
  35. package/hooks/form/index.ts +8 -8
  36. package/hooks/form/interfaces.ts +217 -217
  37. package/hooks/form/structure.ts +39 -39
  38. package/hooks/form/validate-schema.ts +49 -49
  39. package/hooks/index.ts +3 -3
  40. package/hooks/query/api.ts +42 -42
  41. package/hooks/query/delete.ts +45 -45
  42. package/hooks/query/fetch.ts +48 -48
  43. package/hooks/query/index.ts +21 -21
  44. package/hooks/query/interfaces.ts +111 -111
  45. package/hooks/query/list.ts +286 -286
  46. package/hooks/query/update.ts +88 -88
  47. package/hooks/query/url.ts +31 -31
  48. package/hooks/real-time/index.ts +1 -1
  49. package/hooks/real-time/pusher.ts +43 -43
  50. package/jest.config.cjs +6 -6
  51. package/package.json +57 -57
  52. package/provider/index.ts +13 -13
  53. package/provider/provider.tsx +187 -187
  54. package/provider/types.ts +114 -114
  55. package/provider/warehouse.ts +167 -167
  56. package/provider/wasm.ts +124 -124
  57. package/runtime.ts +3 -3
  58. package/src/.prettierrc +7 -7
  59. package/src/compile/analyze.ts +224 -224
  60. package/src/compile/index.ts +86 -86
  61. package/src/compile/manifest.ts +10 -10
  62. package/src/compile/model.ts +69 -69
  63. package/src/compile/openapi.ts +266 -266
  64. package/src/compile/program.ts +40 -40
  65. package/src/csv-schema.ts +187 -187
  66. package/src/define/index.ts +162 -162
  67. package/src/entity-generation/delete-method.ts +37 -37
  68. package/src/entity-generation/form.ts +169 -169
  69. package/src/entity-generation/get-method.ts +80 -80
  70. package/src/entity-generation/imports.ts +110 -110
  71. package/src/entity-generation/sync-method.ts +222 -222
  72. package/src/entity-generation/update-method.ts +38 -38
  73. package/src/index.ts +77 -77
  74. package/src/rad-compile.ts +88 -88
  75. package/src/rad-wasm-build.ts +102 -102
  76. package/src/rad.ts +101 -101
  77. package/src/scan.ts +89 -89
  78. package/src/schema/camel-to-pastel.ts +3 -3
  79. package/src/schema/capitalise-first-letter.ts +3 -3
  80. package/src/schema/extract-response.ts +38 -38
  81. package/src/schema/fetch-schema.ts +12 -12
  82. package/src/schema/remove-non-model-paths.ts +13 -13
  83. package/src/schema/to-camel-case.ts +7 -7
  84. package/src/schema/to-pastel-case.ts +6 -6
  85. package/src/schema-convert.ts +61 -61
  86. package/src/schema-entities.ts +401 -401
  87. package/src/schema-fetch.ts +82 -82
  88. package/src/schema-full.ts +38 -38
  89. package/src/schema-index.ts +29 -29
  90. package/src/schema-params.ts +116 -116
  91. package/src/seed.ts +297 -297
  92. package/sync/engine.ts +392 -392
  93. package/sync/hooks.ts +450 -450
  94. package/sync/index.ts +8 -8
  95. package/sync/persistence.ts +237 -237
  96. package/sync/provider.tsx +91 -91
  97. package/sync/registry.ts +36 -36
  98. package/sync/store.ts +126 -126
  99. package/sync/transactions.ts +300 -300
  100. package/sync/types.ts +94 -94
  101. package/test/compile.spec.ts +192 -192
  102. package/test/csv-schema.spec.ts +143 -143
  103. package/test/schema-entities.spec.ts +688 -688
  104. package/tsconfig.json +24 -24
  105. package/types.ts +18 -18
@@ -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.main = exports.generateFiles = exports.generateFolders = exports.collectEntityMeta = void 0;
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
- exports.collectEntityMeta = collectEntityMeta;
93
- function generateFolders(entitiesPath, paths) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- Object.keys(paths).forEach((key) => {
96
- const appName = key.split("/")[2];
97
- const modelName = key.split("/")[4];
98
- const appFolder = (0, path_1.join)(entitiesPath, appName);
99
- const modelFolder = (0, path_1.join)(appFolder, modelName);
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
- exports.generateFolders = generateFolders;
106
- function generateFiles(entitiesPath, paths) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- const uniqueOperationNames = [];
109
- const modelFileImports = {};
110
- const modelFileData = {};
111
- const keysFileData = {};
112
- const modelImportsFileData = {};
113
- const formMutationOperations = {};
114
- const entityMeta = collectEntityMeta(paths);
115
- Object.keys(paths).forEach((pathKey) => {
116
- const appName = pathKey.split("/")[2];
117
- const modelName = pathKey.split("/")[4];
118
- const indexKey = `${appName}|${modelName}`;
119
- if (!formMutationOperations[indexKey]) {
120
- formMutationOperations[indexKey] = {
121
- post: {
122
- operationId: undefined,
123
- schema: undefined,
124
- },
125
- put: {
126
- operationId: undefined,
127
- schema: undefined,
128
- },
129
- patch: {
130
- operationId: undefined,
131
- schema: undefined,
132
- },
133
- };
134
- }
135
- if (!modelImportsFileData[appName]) {
136
- modelImportsFileData[appName] = [modelName];
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
- else {
139
- if (!modelImportsFileData[appName].includes(modelName)) {
140
- modelImportsFileData[appName].push(modelName);
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
- Object.keys(paths[pathKey]).forEach((method) => {
144
- var _a, _b, _c, _d;
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 (method === "get" || isPostListEndpoint) {
192
- if (isSyncEntity && isListEndpoint) {
193
- [apiMethods, importStatements] = (0, sync_method_1.generateSyncListMethod)(modelName, operationId, meta.rowSchema);
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 if (method === "post" ||
205
- method === "put" ||
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
- else if (method === "delete") {
221
- if (isSyncEntity) {
222
- [apiMethods, importStatements] = (0, sync_method_1.generateSyncDeleteMethod)(pathKey, modelName, operationId);
223
- }
224
- else {
225
- [apiMethods, importStatements] = (0, delete_method_1.generateDeleteAPIMethod)(pathKey, operationId, listKeyRef);
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
- modelFileData[indexKey] = (modelFileData[indexKey] || "") + apiMethods;
229
- modelFileImports[indexKey] = new Set([
230
- ...(modelFileImports[indexKey] || []),
231
- ...importStatements,
232
- ]);
233
- keysFileData[indexKey] = [
234
- ...(keysFileData[indexKey] || []),
235
- operationId,
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
- Object.keys(modelFileData).forEach((key) => {
241
- var _a;
242
- const [appName, modelName] = key.split("|");
243
- const modelFolder = (0, path_1.join)(entitiesPath, appName, modelName);
244
- const apiFile = (0, path_1.join)(modelFolder, "api.ts");
245
- const indexFile = (0, path_1.join)(modelFolder, "index.ts");
246
- const keyImports = (0, imports_1.generateKeyImports)(modelName, keysFileData[key]);
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
- ...descriptorImports,
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
- exports.generateFiles = generateFiles;
278
- function main(url, entitiesPath) {
279
- return __awaiter(this, void 0, void 0, function* () {
280
- console.log("Generating Entities");
281
- const data = yield (0, fetch_schema_1.fetchSchema)(url);
282
- const filteredPaths = (0, remove_non_model_paths_1.removeNonModelPaths)(data.paths);
283
- yield generateFolders(entitiesPath, filteredPaths);
284
- yield generateFiles(entitiesPath, filteredPaths);
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
- exports.main = main;
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];
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
20
- const response = yield axios_1.default.get(url);
21
- (0, fs_1.writeFileSync)(schemaPath, JSON.stringify(response.data, null, 2));
22
- return response.data;
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 generateFiles(basePath, components) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const schemas = components.schemas;
28
- Object.keys(schemas).forEach((key) => {
29
- const schema = schemas[key];
30
- let schemaKey = key;
31
- if (key.endsWith("Enum")) {
32
- schemaKey = key.replace("Enum", "");
33
- schemaKey = `E${schemaKey}`;
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
- schemaKey = `I${schemaKey}`;
46
+ updatedSchemaName = `I${updatedSchemaName}`;
37
47
  }
38
- const schemaFolderPath = (0, path_1.join)(basePath, "api-schema");
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 replaceReferences(basePath) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const schemaFolderPath = (0, path_1.join)(basePath, "api-schema");
47
- const schemaFiles = (0, fs_1.readdirSync)(schemaFolderPath);
48
- schemaFiles.forEach((file) => {
49
- const filePath = (0, path_1.join)(schemaFolderPath, file);
50
- const fileContent = JSON.parse((0, fs_1.readFileSync)(filePath, "utf8"));
51
- let convertedSchema = JSON.stringify(fileContent);
52
- const searchPattern = /"#\/components\/schemas\/([A-Za-z0-9_-]+)"/g;
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();
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
17
- try {
18
- const schemaContent = (0, fs_1.readFileSync)(schemaPath, "utf8");
19
- const schemaObject = JSON.parse(schemaContent);
20
- const dereferencedSchema = yield $RefParser.dereference(schemaObject);
21
- return JSON.stringify(dereferencedSchema, null, 2);
22
- }
23
- catch (error) {
24
- return "";
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
- return __awaiter(this, void 0, void 0, function* () {
30
- console.log("Resolving Schemas");
31
- const args = process.argv.slice(2);
32
- const basePath = args[0];
33
- const schemaFolderPath = (0, path_1.join)(basePath, "api-schema");
34
- const outputFolder = (0, path_1.join)(basePath, "form-schema");
35
- const schemaFiles = (0, fs_1.readdirSync)(schemaFolderPath);
36
- let compilePromises = schemaFiles.map((schemaFile) => __awaiter(this, void 0, void 0, function* () {
37
- const schemaFilePath = (0, path_1.join)(schemaFolderPath, schemaFile);
38
- const generatedCode = yield generateDereferencedSchema(schemaFilePath);
39
- const outputFilePath = (0, path_1.join)(outputFolder, schemaFile);
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();