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/.prettierrc
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"tabWidth": 2,
|
|
3
|
-
"semi": true,
|
|
4
|
-
"bracketSpacing": true,
|
|
5
|
-
"arrowParens": "always",
|
|
6
|
-
"printWidth": 80
|
|
7
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"tabWidth": 2,
|
|
3
|
+
"semi": true,
|
|
4
|
+
"bracketSpacing": true,
|
|
5
|
+
"arrowParens": "always",
|
|
6
|
+
"printWidth": 80
|
|
7
|
+
}
|
package/dist/compile/analyze.js
CHANGED
|
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.analyze =
|
|
36
|
+
exports.analyze = analyze;
|
|
27
37
|
const ts = __importStar(require("typescript"));
|
|
28
38
|
const program_1 = require("./program");
|
|
29
39
|
/**
|
|
@@ -52,7 +62,6 @@ function analyze(program, fileNames) {
|
|
|
52
62
|
resources.sort((a, b) => a.app === b.app ? a.model.localeCompare(b.model) : a.app.localeCompare(b.app));
|
|
53
63
|
return resources;
|
|
54
64
|
}
|
|
55
|
-
exports.analyze = analyze;
|
|
56
65
|
function isResourceCall(node) {
|
|
57
66
|
return (ts.isCallExpression(node) &&
|
|
58
67
|
ts.isIdentifier(node.expression) &&
|
|
@@ -60,7 +69,6 @@ function isResourceCall(node) {
|
|
|
60
69
|
node.arguments.length >= 3);
|
|
61
70
|
}
|
|
62
71
|
function analyzeResourceCall(call, checker) {
|
|
63
|
-
var _a;
|
|
64
72
|
const app = stringLiteralArg(call.arguments[0]);
|
|
65
73
|
const model = stringLiteralArg(call.arguments[1]);
|
|
66
74
|
const fieldsArg = call.arguments[2];
|
|
@@ -87,7 +95,7 @@ function analyzeResourceCall(call, checker) {
|
|
|
87
95
|
});
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
|
-
const options =
|
|
98
|
+
const options = literalToValue(call.arguments[3]) ?? {};
|
|
91
99
|
return {
|
|
92
100
|
app,
|
|
93
101
|
model,
|
package/dist/compile/index.js
CHANGED
|
@@ -15,18 +15,33 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
37
|
};
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
39
|
+
exports.buildOpenApi = exports.buildManifest = exports.analyze = void 0;
|
|
40
|
+
exports.resolveResourceFiles = resolveResourceFiles;
|
|
41
|
+
exports.analyzeResources = analyzeResources;
|
|
42
|
+
exports.compile = compile;
|
|
43
|
+
exports.collisions = collisions;
|
|
44
|
+
exports.urlsFor = urlsFor;
|
|
30
45
|
const fs = __importStar(require("fs"));
|
|
31
46
|
const path = __importStar(require("path"));
|
|
32
47
|
const analyze_1 = require("./analyze");
|
|
@@ -43,9 +58,9 @@ __exportStar(require("./model"), exports);
|
|
|
43
58
|
/** List every `.ts` resource file under a directory (or accept explicit files). */
|
|
44
59
|
function resolveResourceFiles(input) {
|
|
45
60
|
const stat = fs.existsSync(input) ? fs.statSync(input) : undefined;
|
|
46
|
-
if (stat
|
|
61
|
+
if (stat?.isFile())
|
|
47
62
|
return [path.resolve(input)];
|
|
48
|
-
if (stat
|
|
63
|
+
if (stat?.isDirectory()) {
|
|
49
64
|
return fs
|
|
50
65
|
.readdirSync(input)
|
|
51
66
|
.filter((f) => f.endsWith(".ts") && !f.endsWith(".d.ts"))
|
|
@@ -54,14 +69,12 @@ function resolveResourceFiles(input) {
|
|
|
54
69
|
}
|
|
55
70
|
throw new Error(`No such resources path: ${input}`);
|
|
56
71
|
}
|
|
57
|
-
exports.resolveResourceFiles = resolveResourceFiles;
|
|
58
72
|
/** Analyse resource definitions into the canonical model (no file output). */
|
|
59
73
|
function analyzeResources(input) {
|
|
60
74
|
const files = resolveResourceFiles(input);
|
|
61
75
|
const program = (0, program_1.createProgram)(files);
|
|
62
76
|
return (0, analyze_1.analyze)(program, files);
|
|
63
77
|
}
|
|
64
|
-
exports.analyzeResources = analyzeResources;
|
|
65
78
|
/** Compile resource definitions to a manifest + OpenAPI, writing both to disk. */
|
|
66
79
|
function compile(input, outDir) {
|
|
67
80
|
const resources = analyzeResources(input);
|
|
@@ -74,17 +87,15 @@ function compile(input, outDir) {
|
|
|
74
87
|
fs.writeFileSync(openapiPath, (0, openapi_1.openApiToJson)(openapi), { flag: "w" });
|
|
75
88
|
return { manifest, openapi, files: [manifestPath, openapiPath] };
|
|
76
89
|
}
|
|
77
|
-
exports.compile = compile;
|
|
78
90
|
// -- introspection (replaces `manage.py rastack check|list|urls`) -----------
|
|
79
91
|
/** Detect duplicate `app.model` definitions and dangling FK targets. */
|
|
80
92
|
function collisions(resources) {
|
|
81
|
-
var _a;
|
|
82
93
|
const errors = [];
|
|
83
94
|
const seen = new Map();
|
|
84
95
|
const keys = new Set(resources.map((r) => `${r.app}.${r.model}`));
|
|
85
96
|
for (const r of resources) {
|
|
86
97
|
const key = `${r.app}.${r.model}`;
|
|
87
|
-
seen.set(key, (
|
|
98
|
+
seen.set(key, (seen.get(key) ?? 0) + 1);
|
|
88
99
|
for (const rel of r.relations) {
|
|
89
100
|
if (!keys.has(rel.target)) {
|
|
90
101
|
errors.push(`${key}.${rel.field} references unknown resource ${rel.target}.`);
|
|
@@ -97,11 +108,9 @@ function collisions(resources) {
|
|
|
97
108
|
}
|
|
98
109
|
return errors;
|
|
99
110
|
}
|
|
100
|
-
exports.collisions = collisions;
|
|
101
111
|
function urlsFor(resources) {
|
|
102
112
|
return resources.flatMap((r) => [
|
|
103
113
|
`/api/${r.app}/v1/${r.model}/`,
|
|
104
114
|
`/api/${r.app}/v1/${r.model}/{id}/`,
|
|
105
115
|
]);
|
|
106
116
|
}
|
|
107
|
-
exports.urlsFor = urlsFor;
|
package/dist/compile/manifest.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.buildManifest = buildManifest;
|
|
4
|
+
exports.manifestToJson = manifestToJson;
|
|
4
5
|
/** Assemble the canonical manifest from analysed resources. */
|
|
5
6
|
function buildManifest(resources) {
|
|
6
7
|
return { version: 1, resources };
|
|
7
8
|
}
|
|
8
|
-
exports.buildManifest = buildManifest;
|
|
9
9
|
function manifestToJson(manifest) {
|
|
10
10
|
return JSON.stringify(manifest, null, 2) + "\n";
|
|
11
11
|
}
|
|
12
|
-
exports.manifestToJson = manifestToJson;
|
package/dist/compile/openapi.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.buildOpenApi = buildOpenApi;
|
|
4
|
+
exports.openApiToJson = openApiToJson;
|
|
4
5
|
/**
|
|
5
6
|
* Emit an OpenAPI 3 document from the analysed resources. The output reproduces
|
|
6
7
|
* the *exact* contract the existing `tools/` codegen and `stack/` runtime rely
|
|
@@ -10,14 +11,13 @@ exports.openApiToJson = exports.buildOpenApi = void 0;
|
|
|
10
11
|
* follow relations.
|
|
11
12
|
*/
|
|
12
13
|
function buildOpenApi(resources) {
|
|
13
|
-
var _a;
|
|
14
14
|
const paths = {};
|
|
15
15
|
const schemas = {};
|
|
16
16
|
for (const resource of resources) {
|
|
17
17
|
const P = pascal(resource.model);
|
|
18
18
|
const listUrl = `/api/${resource.app}/v1/${resource.model}/`;
|
|
19
19
|
const detailUrl = `${listUrl}{id}/`;
|
|
20
|
-
const local =
|
|
20
|
+
const local = resource.sync?.mode === "local";
|
|
21
21
|
schemas[P] = readSchema(resource);
|
|
22
22
|
schemas[`Paginated${P}List`] = paginatedSchema(P);
|
|
23
23
|
schemas[`${P}Request`] = writeSchema(resource, false);
|
|
@@ -69,11 +69,9 @@ function buildOpenApi(resources) {
|
|
|
69
69
|
components: { schemas },
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
exports.buildOpenApi = buildOpenApi;
|
|
73
72
|
function openApiToJson(doc) {
|
|
74
73
|
return JSON.stringify(doc, null, 2) + "\n";
|
|
75
74
|
}
|
|
76
|
-
exports.openApiToJson = openApiToJson;
|
|
77
75
|
// -- schema builders --------------------------------------------------------
|
|
78
76
|
function readSchema(resource) {
|
|
79
77
|
const properties = {
|
|
@@ -133,11 +131,10 @@ function fieldProperty(field) {
|
|
|
133
131
|
return base;
|
|
134
132
|
}
|
|
135
133
|
function idProperty(resource) {
|
|
136
|
-
var _a;
|
|
137
134
|
const pk = resource.fields.find((f) => f.primaryKey);
|
|
138
135
|
if (pk)
|
|
139
|
-
return
|
|
140
|
-
if (
|
|
136
|
+
return { ...scalarProperty(pk.type), readOnly: true };
|
|
137
|
+
if (resource.sync?.clientIds) {
|
|
141
138
|
return { type: "string", format: "uuid" };
|
|
142
139
|
}
|
|
143
140
|
return { type: "integer", readOnly: true };
|
package/dist/compile/program.js
CHANGED
|
@@ -15,15 +15,26 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
36
|
+
exports.createProgram = createProgram;
|
|
37
|
+
exports.resourceSourceFiles = resourceSourceFiles;
|
|
27
38
|
const path = __importStar(require("path"));
|
|
28
39
|
const ts = __importStar(require("typescript"));
|
|
29
40
|
/**
|
|
@@ -50,7 +61,6 @@ function createProgram(fileNames) {
|
|
|
50
61
|
};
|
|
51
62
|
return ts.createProgram(fileNames, options);
|
|
52
63
|
}
|
|
53
|
-
exports.createProgram = createProgram;
|
|
54
64
|
/** Every non-declaration source file the program was rooted at. */
|
|
55
65
|
function resourceSourceFiles(program, fileNames) {
|
|
56
66
|
const wanted = new Set(fileNames.map((f) => path.resolve(f)));
|
|
@@ -58,4 +68,3 @@ function resourceSourceFiles(program, fileNames) {
|
|
|
58
68
|
.getSourceFiles()
|
|
59
69
|
.filter((sf) => !sf.isDeclarationFile && wanted.has(path.resolve(sf.fileName)));
|
|
60
70
|
}
|
|
61
|
-
exports.resourceSourceFiles = resourceSourceFiles;
|
package/dist/csv-schema.js
CHANGED
|
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.parseCsv = parseCsv;
|
|
7
|
+
exports.inferSchema = inferSchema;
|
|
8
|
+
exports.discoverCsvFiles = discoverCsvFiles;
|
|
7
9
|
const fs_1 = __importDefault(require("fs"));
|
|
8
10
|
const path_1 = __importDefault(require("path"));
|
|
9
11
|
const minimatch_1 = require("minimatch");
|
|
@@ -103,7 +105,6 @@ function parseCsv(content) {
|
|
|
103
105
|
const rows = lines.slice(1).map(splitLine);
|
|
104
106
|
return { headers, rows };
|
|
105
107
|
}
|
|
106
|
-
exports.parseCsv = parseCsv;
|
|
107
108
|
function fingerprint(schema) {
|
|
108
109
|
const sig = schema.columns.map((c) => `${c.name}:${c.type}:${c.pii}`).join("|");
|
|
109
110
|
// Simple hash — not crypto, just change-detection
|
|
@@ -120,7 +121,7 @@ function inferSchema(csvPath, repoRoot) {
|
|
|
120
121
|
const tableName = path_1.default.basename(csvPath, ".csv");
|
|
121
122
|
const piiViolations = [];
|
|
122
123
|
const columns = headers.map((name, i) => {
|
|
123
|
-
const values = rows.map((r) =>
|
|
124
|
+
const values = rows.map((r) => r[i] ?? "");
|
|
124
125
|
const type = inferType(values);
|
|
125
126
|
const nullable = values.some((v) => v.trim() === "" || v.toLowerCase() === "null");
|
|
126
127
|
const nonEmpty = values.filter((v) => v.trim() !== "");
|
|
@@ -148,9 +149,8 @@ function inferSchema(csvPath, repoRoot) {
|
|
|
148
149
|
return { name, type, nullable, unique, primaryKey: isPrimary, pii, piiReason };
|
|
149
150
|
});
|
|
150
151
|
const base = { tableName, sourceFile: csvPath, columns, rowCount: rows.length };
|
|
151
|
-
return { schema:
|
|
152
|
+
return { schema: { ...base, fingerprint: fingerprint(base) }, piiViolations };
|
|
152
153
|
}
|
|
153
|
-
exports.inferSchema = inferSchema;
|
|
154
154
|
function discoverCsvFiles(dir) {
|
|
155
155
|
if (!fs_1.default.existsSync(dir))
|
|
156
156
|
return [];
|
|
@@ -159,4 +159,3 @@ function discoverCsvFiles(dir) {
|
|
|
159
159
|
.filter((f) => f.endsWith(".csv"))
|
|
160
160
|
.map((f) => path_1.default.join(dir, f));
|
|
161
161
|
}
|
|
162
|
-
exports.discoverCsvFiles = discoverCsvFiles;
|
package/dist/define/index.js
CHANGED
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.
|
|
27
|
+
exports.s = void 0;
|
|
28
|
+
exports.resource = resource;
|
|
28
29
|
/**
|
|
29
30
|
* Field builders. Each returns a phantom value whose *type* encodes the field
|
|
30
31
|
* kind; the runtime object is never used at compile time (the compiler analyses
|
|
@@ -71,4 +72,3 @@ function resource(app, model, fields, options = {}) {
|
|
|
71
72
|
options,
|
|
72
73
|
};
|
|
73
74
|
}
|
|
74
|
-
exports.resource = resource;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateDeleteAPIMethod =
|
|
3
|
+
exports.generateDeleteAPIMethod = generateDeleteAPIMethod;
|
|
4
4
|
const capitalise_first_letter_1 = require("../schema/capitalise-first-letter");
|
|
5
5
|
function generateDeleteAPIMethod(url, operationId, listQueryCacheKey) {
|
|
6
|
-
var _a;
|
|
7
6
|
const operationIdUpper = (0, capitalise_first_letter_1.capitaliseFirstLetter)(operationId);
|
|
8
7
|
let urlStructure = `'${url}'`;
|
|
9
|
-
const pathParams =
|
|
8
|
+
const pathParams = url.match(/{([^}]+)}/g)?.map((param) => param.slice(1, -1)) || [];
|
|
10
9
|
if (pathParams.length > 0) {
|
|
11
10
|
urlStructure = url.replace(/{([^}]+)}/g, "${$1}");
|
|
12
11
|
const paramList = pathParams.join(", ");
|
|
@@ -18,14 +17,13 @@ function generateDeleteAPIMethod(url, operationId, listQueryCacheKey) {
|
|
|
18
17
|
? `\n listQueryCacheKey: ${listQueryCacheKey},`
|
|
19
18
|
: "";
|
|
20
19
|
return [
|
|
21
|
-
`
|
|
22
|
-
export function use${operationIdUpper}() {
|
|
23
|
-
return useDeleteQuery({
|
|
24
|
-
deleteUrl: ${urlStructure},${cacheKeyLine}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
20
|
+
`
|
|
21
|
+
export function use${operationIdUpper}() {
|
|
22
|
+
return useDeleteQuery({
|
|
23
|
+
deleteUrl: ${urlStructure},${cacheKeyLine}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
27
26
|
`,
|
|
28
27
|
importStatements,
|
|
29
28
|
];
|
|
30
29
|
}
|
|
31
|
-
exports.generateDeleteAPIMethod = generateDeleteAPIMethod;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateUpdateFormMethod =
|
|
3
|
+
exports.generateUpdateFormMethod = generateUpdateFormMethod;
|
|
4
4
|
const to_pastel_case_1 = require("../schema/to-pastel-case");
|
|
5
5
|
function generateUpdateFormMethod(appName, modelName, mutationOperations) {
|
|
6
6
|
const modelDetail = (0, to_pastel_case_1.toPascalCase)(modelName);
|
|
@@ -32,7 +32,6 @@ function generateUpdateFormMethod(appName, modelName, mutationOperations) {
|
|
|
32
32
|
.join("\n\n");
|
|
33
33
|
return [formCodeGen, importStatements];
|
|
34
34
|
}
|
|
35
|
-
exports.generateUpdateFormMethod = generateUpdateFormMethod;
|
|
36
35
|
function cleanGroupDetail(groupDetail) {
|
|
37
36
|
return groupDetail
|
|
38
37
|
.replace("V1", "")
|
|
@@ -42,94 +41,93 @@ function cleanGroupDetail(groupDetail) {
|
|
|
42
41
|
.replace(/{([^}]+)}/g, "");
|
|
43
42
|
}
|
|
44
43
|
function generateFormMethod(groupDetailClean, mutations) {
|
|
45
|
-
return `
|
|
46
|
-
export function useUpdate${groupDetailClean}Form<
|
|
47
|
-
TFormValues extends object,
|
|
48
|
-
TPostParams,
|
|
49
|
-
TPutParams,
|
|
50
|
-
TPatchParams,
|
|
51
|
-
TPostPayload,
|
|
52
|
-
TPutPayload,
|
|
53
|
-
TPatchPayload,
|
|
54
|
-
TPostResult,
|
|
55
|
-
TPutResult,
|
|
56
|
-
TPatchResult,
|
|
57
|
-
TFormUpdate extends FormUpdate,
|
|
58
|
-
TSourceId extends string | undefined,
|
|
59
|
-
>({
|
|
60
|
-
id,
|
|
61
|
-
sourceData = {},
|
|
62
|
-
formValues,
|
|
63
|
-
formatResponse,
|
|
64
|
-
transformRequest,
|
|
65
|
-
transformResponse,
|
|
66
|
-
mutations = {
|
|
67
|
-
${mutations}
|
|
68
|
-
},
|
|
69
|
-
updateType,
|
|
70
|
-
onSuccess
|
|
71
|
-
}: FormProps<
|
|
72
|
-
TFormValues,
|
|
73
|
-
TPostParams,
|
|
74
|
-
TPutParams,
|
|
75
|
-
TPatchParams,
|
|
76
|
-
TPostPayload,
|
|
77
|
-
TPutPayload,
|
|
78
|
-
TPatchPayload,
|
|
79
|
-
TPostResult,
|
|
80
|
-
TPutResult,
|
|
81
|
-
TPatchResult,
|
|
82
|
-
TFormUpdate,
|
|
83
|
-
TSourceId
|
|
84
|
-
>) {
|
|
85
|
-
return useForm<
|
|
86
|
-
TFormValues,
|
|
87
|
-
TPostParams,
|
|
88
|
-
TPutParams,
|
|
89
|
-
TPatchParams,
|
|
90
|
-
TPostPayload,
|
|
91
|
-
TPutPayload,
|
|
92
|
-
TPatchPayload,
|
|
93
|
-
TPostResult,
|
|
94
|
-
TPutResult,
|
|
95
|
-
TPatchResult,
|
|
96
|
-
TFormUpdate,
|
|
97
|
-
TSourceId
|
|
98
|
-
>({
|
|
99
|
-
id,
|
|
100
|
-
mutations,
|
|
101
|
-
formValues,
|
|
102
|
-
sourceData,
|
|
103
|
-
formatResponse,
|
|
104
|
-
transformRequest,
|
|
105
|
-
transformResponse,
|
|
106
|
-
updateType,
|
|
107
|
-
onSuccess
|
|
108
|
-
});
|
|
44
|
+
return `
|
|
45
|
+
export function useUpdate${groupDetailClean}Form<
|
|
46
|
+
TFormValues extends object,
|
|
47
|
+
TPostParams,
|
|
48
|
+
TPutParams,
|
|
49
|
+
TPatchParams,
|
|
50
|
+
TPostPayload,
|
|
51
|
+
TPutPayload,
|
|
52
|
+
TPatchPayload,
|
|
53
|
+
TPostResult,
|
|
54
|
+
TPutResult,
|
|
55
|
+
TPatchResult,
|
|
56
|
+
TFormUpdate extends FormUpdate,
|
|
57
|
+
TSourceId extends string | undefined,
|
|
58
|
+
>({
|
|
59
|
+
id,
|
|
60
|
+
sourceData = {},
|
|
61
|
+
formValues,
|
|
62
|
+
formatResponse,
|
|
63
|
+
transformRequest,
|
|
64
|
+
transformResponse,
|
|
65
|
+
mutations = {
|
|
66
|
+
${mutations}
|
|
67
|
+
},
|
|
68
|
+
updateType,
|
|
69
|
+
onSuccess
|
|
70
|
+
}: FormProps<
|
|
71
|
+
TFormValues,
|
|
72
|
+
TPostParams,
|
|
73
|
+
TPutParams,
|
|
74
|
+
TPatchParams,
|
|
75
|
+
TPostPayload,
|
|
76
|
+
TPutPayload,
|
|
77
|
+
TPatchPayload,
|
|
78
|
+
TPostResult,
|
|
79
|
+
TPutResult,
|
|
80
|
+
TPatchResult,
|
|
81
|
+
TFormUpdate,
|
|
82
|
+
TSourceId
|
|
83
|
+
>) {
|
|
84
|
+
return useForm<
|
|
85
|
+
TFormValues,
|
|
86
|
+
TPostParams,
|
|
87
|
+
TPutParams,
|
|
88
|
+
TPatchParams,
|
|
89
|
+
TPostPayload,
|
|
90
|
+
TPutPayload,
|
|
91
|
+
TPatchPayload,
|
|
92
|
+
TPostResult,
|
|
93
|
+
TPutResult,
|
|
94
|
+
TPatchResult,
|
|
95
|
+
TFormUpdate,
|
|
96
|
+
TSourceId
|
|
97
|
+
>({
|
|
98
|
+
id,
|
|
99
|
+
mutations,
|
|
100
|
+
formValues,
|
|
101
|
+
sourceData,
|
|
102
|
+
formatResponse,
|
|
103
|
+
transformRequest,
|
|
104
|
+
transformResponse,
|
|
105
|
+
updateType,
|
|
106
|
+
onSuccess
|
|
107
|
+
});
|
|
109
108
|
}`;
|
|
110
109
|
}
|
|
111
110
|
function generateMutations(operations) {
|
|
112
|
-
var _a, _b, _c, _d, _e, _f;
|
|
113
111
|
const mutationStrings = [];
|
|
114
|
-
if (
|
|
115
|
-
mutationStrings.push(`post: {
|
|
116
|
-
// @ts-ignore
|
|
117
|
-
mutation: usePost${operations.post.operationId}(),
|
|
118
|
-
validation: Deref${operations.post.schema}
|
|
112
|
+
if (operations.post?.operationId && operations.post?.schema) {
|
|
113
|
+
mutationStrings.push(`post: {
|
|
114
|
+
// @ts-ignore
|
|
115
|
+
mutation: usePost${operations.post.operationId}(),
|
|
116
|
+
validation: Deref${operations.post.schema}
|
|
119
117
|
}`);
|
|
120
118
|
}
|
|
121
|
-
if (
|
|
122
|
-
mutationStrings.push(`put: {
|
|
123
|
-
// @ts-ignore
|
|
124
|
-
mutation: usePut${operations.put.operationId}(),
|
|
125
|
-
validation: Deref${operations.put.schema}
|
|
119
|
+
if (operations.put?.operationId && operations.put?.schema) {
|
|
120
|
+
mutationStrings.push(`put: {
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
mutation: usePut${operations.put.operationId}(),
|
|
123
|
+
validation: Deref${operations.put.schema}
|
|
126
124
|
}`);
|
|
127
125
|
}
|
|
128
|
-
if (
|
|
129
|
-
mutationStrings.push(`patch: {
|
|
130
|
-
// @ts-ignore
|
|
131
|
-
mutation: usePatch${operations.patch.operationId}(),
|
|
132
|
-
validation: Deref${operations.patch.schema}
|
|
126
|
+
if (operations.patch?.operationId && operations.patch?.schema) {
|
|
127
|
+
mutationStrings.push(`patch: {
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
mutation: usePatch${operations.patch.operationId}(),
|
|
130
|
+
validation: Deref${operations.patch.schema}
|
|
133
131
|
}`);
|
|
134
132
|
}
|
|
135
133
|
return mutationStrings.join(",\n ");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateGetAPIMethod =
|
|
3
|
+
exports.generateGetAPIMethod = generateGetAPIMethod;
|
|
4
4
|
const capitalise_first_letter_1 = require("../schema/capitalise-first-letter");
|
|
5
5
|
const to_camel_case_1 = require("../schema/to-camel-case");
|
|
6
6
|
function generateGetAPIMethod(url, model, operationId, responseBody, isList, pathParameters, requiredParameters, method, requestBodySchema) {
|
|
@@ -15,23 +15,23 @@ function generateGetAPIMethod(url, model, operationId, responseBody, isList, pat
|
|
|
15
15
|
if (isList) {
|
|
16
16
|
importStatements.add(`ListQueryOptions, useGetPaginatedQueryList, useUpdateQuery`);
|
|
17
17
|
importStatements.add(paramNames);
|
|
18
|
-
importStatements.add(responseBody
|
|
18
|
+
importStatements.add(responseBody ?? "");
|
|
19
19
|
return [
|
|
20
|
-
`
|
|
21
|
-
export function use${operationIdUpper}(
|
|
22
|
-
options?: ListQueryOptions<${paramNames}, ${responseBody}>
|
|
23
|
-
) {
|
|
24
|
-
const { isAuthenticated } = useAuth0();
|
|
25
|
-
const pathParameters: (keyof ${paramNames})[] = [${pathParameters.map((item) => `'${item}'`).join(", ")}]
|
|
26
|
-
${pathParameterString.join("\n")}
|
|
27
|
-
|
|
28
|
-
return useGetPaginatedQueryList<${paramNames}, ${responseBody}>({
|
|
29
|
-
${method}Url: \`${url}\`,
|
|
30
|
-
queryKey: ${modelCamel}QueriesKeys.${operationId},
|
|
31
|
-
pathParameters,
|
|
32
|
-
isAuthenticated,
|
|
33
|
-
options,
|
|
34
|
-
});
|
|
20
|
+
`
|
|
21
|
+
export function use${operationIdUpper}(
|
|
22
|
+
options?: ListQueryOptions<${paramNames}, ${responseBody}>
|
|
23
|
+
) {
|
|
24
|
+
const { isAuthenticated } = useAuth0();
|
|
25
|
+
const pathParameters: (keyof ${paramNames})[] = [${pathParameters.map((item) => `'${item}'`).join(", ")}]
|
|
26
|
+
${pathParameterString.join("\n")}
|
|
27
|
+
|
|
28
|
+
return useGetPaginatedQueryList<${paramNames}, ${responseBody}>({
|
|
29
|
+
${method}Url: \`${url}\`,
|
|
30
|
+
queryKey: ${modelCamel}QueriesKeys.${operationId},
|
|
31
|
+
pathParameters,
|
|
32
|
+
isAuthenticated,
|
|
33
|
+
options,
|
|
34
|
+
});
|
|
35
35
|
}`,
|
|
36
36
|
importStatements,
|
|
37
37
|
];
|
|
@@ -41,27 +41,26 @@ function generateGetAPIMethod(url, model, operationId, responseBody, isList, pat
|
|
|
41
41
|
importStatements.add(paramNames);
|
|
42
42
|
importStatements.add(responseBody || "");
|
|
43
43
|
return [
|
|
44
|
-
`
|
|
45
|
-
export function use${operationIdUpper}(
|
|
46
|
-
options?: GetQueryOptions<${paramNames}>
|
|
47
|
-
) {
|
|
48
|
-
const { isAuthenticated } = useAuth0();
|
|
49
|
-
const pathParameters: string[] = [${pathParameters.map((item) => `'${item}'`).join(", ")}]
|
|
50
|
-
${pathParameterString.join("\n")}
|
|
51
|
-
const requiredParams: string[] = [${requiredParameters.map((item) => `'${item}'`).join(", ")}]
|
|
52
|
-
return useGetQuery<${paramNames}, ${responseBody}>({
|
|
53
|
-
${method}Url: \`${url}\`,
|
|
54
|
-
queryKey: ${modelCamel}QueriesKeys.${operationId},
|
|
55
|
-
//@ts-ignore
|
|
56
|
-
pathParameters,
|
|
57
|
-
//@ts-ignore
|
|
58
|
-
requiredParams,
|
|
59
|
-
isAuthenticated,
|
|
60
|
-
options,
|
|
61
|
-
});
|
|
44
|
+
`
|
|
45
|
+
export function use${operationIdUpper}(
|
|
46
|
+
options?: GetQueryOptions<${paramNames}>
|
|
47
|
+
) {
|
|
48
|
+
const { isAuthenticated } = useAuth0();
|
|
49
|
+
const pathParameters: string[] = [${pathParameters.map((item) => `'${item}'`).join(", ")}]
|
|
50
|
+
${pathParameterString.join("\n")}
|
|
51
|
+
const requiredParams: string[] = [${requiredParameters.map((item) => `'${item}'`).join(", ")}]
|
|
52
|
+
return useGetQuery<${paramNames}, ${responseBody}>({
|
|
53
|
+
${method}Url: \`${url}\`,
|
|
54
|
+
queryKey: ${modelCamel}QueriesKeys.${operationId},
|
|
55
|
+
//@ts-ignore
|
|
56
|
+
pathParameters,
|
|
57
|
+
//@ts-ignore
|
|
58
|
+
requiredParams,
|
|
59
|
+
isAuthenticated,
|
|
60
|
+
options,
|
|
61
|
+
});
|
|
62
62
|
}`,
|
|
63
63
|
importStatements,
|
|
64
64
|
];
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
exports.generateGetAPIMethod = generateGetAPIMethod;
|