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
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.removeDuplicateImports = removeDuplicateImports;
|
|
4
|
+
exports.generateImportStatements = generateImportStatements;
|
|
5
|
+
exports.generateKeyImports = generateKeyImports;
|
|
6
|
+
exports.generateIndexImports = generateIndexImports;
|
|
7
|
+
exports.generateFolderImports = generateFolderImports;
|
|
4
8
|
function removeDuplicateImports(importStatements) {
|
|
5
9
|
const importLines = importStatements.split("\n");
|
|
6
10
|
const uniqueImports = new Set();
|
|
@@ -8,20 +12,25 @@ function removeDuplicateImports(importStatements) {
|
|
|
8
12
|
const radSyncImports = new Set();
|
|
9
13
|
const schemaImports = new Set();
|
|
10
14
|
importLines.forEach((line) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.
|
|
15
|
+
if (line.includes("rastack/sync")) {
|
|
16
|
+
const imports = line
|
|
17
|
+
.match(/\{([^}]+)\}/)?.[1]
|
|
18
|
+
.split(",")
|
|
19
|
+
.map((s) => s.trim()) || [];
|
|
15
20
|
imports.forEach((imp) => radSyncImports.add(imp));
|
|
16
21
|
}
|
|
17
|
-
else if (line.includes("
|
|
18
|
-
const imports =
|
|
19
|
-
.match(/\{([^}]+)\}/)
|
|
22
|
+
else if (line.includes("rastack/hooks")) {
|
|
23
|
+
const imports = line
|
|
24
|
+
.match(/\{([^}]+)\}/)?.[1]
|
|
25
|
+
.split(",")
|
|
26
|
+
.map((s) => s.trim()) || [];
|
|
20
27
|
imports.forEach((imp) => radStackImports.add(imp));
|
|
21
28
|
}
|
|
22
29
|
else if (line.includes("@repo/schema/schema")) {
|
|
23
|
-
const imports =
|
|
24
|
-
.match(/\{([^}]+)\}/)
|
|
30
|
+
const imports = line
|
|
31
|
+
.match(/\{([^}]+)\}/)?.[1]
|
|
32
|
+
.split(",")
|
|
33
|
+
.map((s) => s.trim()) || [];
|
|
25
34
|
imports.forEach((imp) => schemaImports.add(imp));
|
|
26
35
|
}
|
|
27
36
|
else {
|
|
@@ -30,17 +39,16 @@ function removeDuplicateImports(importStatements) {
|
|
|
30
39
|
});
|
|
31
40
|
let result = Array.from(uniqueImports).join("\n") + "\n";
|
|
32
41
|
if (radStackImports.size > 0) {
|
|
33
|
-
result += `import { ${Array.from(radStackImports).join(", ")} } from '
|
|
42
|
+
result += `import { ${Array.from(radStackImports).join(", ")} } from 'rastack/hooks';\n`;
|
|
34
43
|
}
|
|
35
44
|
if (radSyncImports.size > 0) {
|
|
36
|
-
result += `import { ${Array.from(radSyncImports).join(", ")} } from '
|
|
45
|
+
result += `import { ${Array.from(radSyncImports).join(", ")} } from 'rastack/sync';\n`;
|
|
37
46
|
}
|
|
38
47
|
if (schemaImports.size > 0) {
|
|
39
48
|
result += `import { ${Array.from(schemaImports).join(", ")} } from '@repo/schema/schema';\n`;
|
|
40
49
|
}
|
|
41
50
|
return result;
|
|
42
51
|
}
|
|
43
|
-
exports.removeDuplicateImports = removeDuplicateImports;
|
|
44
52
|
function generateImportStatements(importStatements, modelName) {
|
|
45
53
|
const entries = Array.from(importStatements);
|
|
46
54
|
const syncImports = entries
|
|
@@ -53,20 +61,19 @@ function generateImportStatements(importStatements, modelName) {
|
|
|
53
61
|
const schemaImports = entries
|
|
54
62
|
.filter((importStatement) => importStatement.startsWith("I") || importStatement.startsWith("Deref"))
|
|
55
63
|
.join(", ");
|
|
56
|
-
let importData = "import { useForm, FormProps, FormUpdate, useUpdateQuery } from '
|
|
64
|
+
let importData = "import { useForm, FormProps, FormUpdate, useUpdateQuery } from 'rastack/hooks';\n";
|
|
57
65
|
importData = importData + 'import { useAuth0 } from "@auth0/auth0-react";\n';
|
|
58
66
|
if (queryImports) {
|
|
59
|
-
importData += `import { ${queryImports} } from '
|
|
67
|
+
importData += `import { ${queryImports} } from 'rastack/hooks';\n`;
|
|
60
68
|
}
|
|
61
69
|
if (syncImports) {
|
|
62
|
-
importData += `import { ${syncImports} } from '
|
|
70
|
+
importData += `import { ${syncImports} } from 'rastack/sync';\n`;
|
|
63
71
|
}
|
|
64
72
|
if (schemaImports) {
|
|
65
73
|
importData += `import { ${schemaImports} } from '@repo/schema/schema';\n`;
|
|
66
74
|
}
|
|
67
75
|
return removeDuplicateImports(importData);
|
|
68
76
|
}
|
|
69
|
-
exports.generateImportStatements = generateImportStatements;
|
|
70
77
|
function generateKeyImports(model, operations) {
|
|
71
78
|
model = model.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
72
79
|
let keyData = `export const ${model}QueriesKeys = {\n`;
|
|
@@ -76,11 +83,9 @@ function generateKeyImports(model, operations) {
|
|
|
76
83
|
});
|
|
77
84
|
return `${keyData}}`;
|
|
78
85
|
}
|
|
79
|
-
exports.generateKeyImports = generateKeyImports;
|
|
80
86
|
function generateIndexImports(model, operations) {
|
|
81
87
|
return `export * from "./api"`;
|
|
82
88
|
}
|
|
83
|
-
exports.generateIndexImports = generateIndexImports;
|
|
84
89
|
function generateFolderImports(models) {
|
|
85
90
|
let importData = "";
|
|
86
91
|
models.map((model) => {
|
|
@@ -88,4 +93,3 @@ function generateFolderImports(models) {
|
|
|
88
93
|
});
|
|
89
94
|
return importData;
|
|
90
95
|
}
|
|
91
|
-
exports.generateFolderImports = generateFolderImports;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* local store, writes enqueue optimistic transactions, and operations the
|
|
5
5
|
* fat class marked as confirmed become blocking online-only mutations.
|
|
6
6
|
*
|
|
7
|
-
* Imports prefixed with "sync:" are routed to '
|
|
7
|
+
* Imports prefixed with "sync:" are routed to 'rastack/sync' by
|
|
8
8
|
* generateImportStatements.
|
|
9
9
|
*/
|
|
10
10
|
export interface EntitySyncMeta {
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.entityConstName = entityConstName;
|
|
4
|
+
exports.generateEntityDescriptor = generateEntityDescriptor;
|
|
5
|
+
exports.generateSyncListMethod = generateSyncListMethod;
|
|
6
|
+
exports.generateSyncRecordMethod = generateSyncRecordMethod;
|
|
7
|
+
exports.generateSyncUpdateMethod = generateSyncUpdateMethod;
|
|
8
|
+
exports.generateSyncDeleteMethod = generateSyncDeleteMethod;
|
|
9
|
+
exports.generateConfirmedMethod = generateConfirmedMethod;
|
|
4
10
|
const capitalise_first_letter_1 = require("../schema/capitalise-first-letter");
|
|
5
11
|
const to_camel_case_1 = require("../schema/to-camel-case");
|
|
6
12
|
function entityConstName(model) {
|
|
7
13
|
return `${(0, to_camel_case_1.toCamelCase)(model)}Entity`;
|
|
8
14
|
}
|
|
9
|
-
exports.entityConstName = entityConstName;
|
|
10
15
|
function generateEntityDescriptor(appName, modelName, meta) {
|
|
11
16
|
const importStatements = new Set();
|
|
12
17
|
importStatements.add("sync:defineEntity");
|
|
@@ -22,18 +27,17 @@ function generateEntityDescriptor(appName, modelName, meta) {
|
|
|
22
27
|
const lazyLine = meta.lazy ? `\n lazy: true,` : "";
|
|
23
28
|
const clientIdsLine = meta.clientIds ? `\n clientIds: true,` : "";
|
|
24
29
|
return [
|
|
25
|
-
`
|
|
26
|
-
export const ${entityConstName(modelName)} = defineEntity<${rowType}>({
|
|
27
|
-
app: "${appName}",
|
|
28
|
-
model: "${modelName}",
|
|
29
|
-
listUrl: \`${listUrl}\`,
|
|
30
|
-
detailUrl: (id) => \`${detailUrl}\`,${lazyLine}${clientIdsLine}
|
|
31
|
-
});
|
|
30
|
+
`
|
|
31
|
+
export const ${entityConstName(modelName)} = defineEntity<${rowType}>({
|
|
32
|
+
app: "${appName}",
|
|
33
|
+
model: "${modelName}",
|
|
34
|
+
listUrl: \`${listUrl}\`,
|
|
35
|
+
detailUrl: (id) => \`${detailUrl}\`,${lazyLine}${clientIdsLine}
|
|
36
|
+
});
|
|
32
37
|
`,
|
|
33
38
|
importStatements,
|
|
34
39
|
];
|
|
35
40
|
}
|
|
36
|
-
exports.generateEntityDescriptor = generateEntityDescriptor;
|
|
37
41
|
function generateSyncListMethod(modelName, operationId, rowSchema) {
|
|
38
42
|
const operationIdUpper = (0, capitalise_first_letter_1.capitaliseFirstLetter)(operationId);
|
|
39
43
|
const rowType = rowSchema || "any";
|
|
@@ -44,16 +48,15 @@ function generateSyncListMethod(modelName, operationId, rowSchema) {
|
|
|
44
48
|
importStatements.add(rowSchema);
|
|
45
49
|
}
|
|
46
50
|
return [
|
|
47
|
-
`
|
|
48
|
-
export function use${operationIdUpper}(
|
|
49
|
-
options?: EntityListOptions<${rowType}>
|
|
50
|
-
) {
|
|
51
|
-
return useEntityList<${rowType}>(${entityConstName(modelName)}, options);
|
|
51
|
+
`
|
|
52
|
+
export function use${operationIdUpper}(
|
|
53
|
+
options?: EntityListOptions<${rowType}>
|
|
54
|
+
) {
|
|
55
|
+
return useEntityList<${rowType}>(${entityConstName(modelName)}, options);
|
|
52
56
|
}`,
|
|
53
57
|
importStatements,
|
|
54
58
|
];
|
|
55
59
|
}
|
|
56
|
-
exports.generateSyncListMethod = generateSyncListMethod;
|
|
57
60
|
function generateSyncRecordMethod(modelName, operationId, rowSchema, pathParameters) {
|
|
58
61
|
const operationIdUpper = (0, capitalise_first_letter_1.capitaliseFirstLetter)(operationId);
|
|
59
62
|
const rowType = rowSchema || "any";
|
|
@@ -67,17 +70,16 @@ function generateSyncRecordMethod(modelName, operationId, rowSchema, pathParamet
|
|
|
67
70
|
importStatements.add(rowSchema);
|
|
68
71
|
}
|
|
69
72
|
return [
|
|
70
|
-
`
|
|
71
|
-
export function use${operationIdUpper}(
|
|
72
|
-
options?: GetQueryOptions<${paramNames}>
|
|
73
|
-
) {
|
|
74
|
-
const id = options?.params?.${idParam};
|
|
75
|
-
return useEntityRecord<${rowType}>(${entityConstName(modelName)}, id as string | number | undefined);
|
|
73
|
+
`
|
|
74
|
+
export function use${operationIdUpper}(
|
|
75
|
+
options?: GetQueryOptions<${paramNames}>
|
|
76
|
+
) {
|
|
77
|
+
const id = options?.params?.${idParam};
|
|
78
|
+
return useEntityRecord<${rowType}>(${entityConstName(modelName)}, id as string | number | undefined);
|
|
76
79
|
}`,
|
|
77
80
|
importStatements,
|
|
78
81
|
];
|
|
79
82
|
}
|
|
80
|
-
exports.generateSyncRecordMethod = generateSyncRecordMethod;
|
|
81
83
|
function generateSyncUpdateMethod(url, method, modelName, operationId, requestBody, responseBody, pathParameters) {
|
|
82
84
|
const operationIdUpper = (0, capitalise_first_letter_1.capitaliseFirstLetter)(operationId);
|
|
83
85
|
const paramNames = `I${operationIdUpper}Params`;
|
|
@@ -99,35 +101,33 @@ function generateSyncUpdateMethod(url, method, modelName, operationId, requestBo
|
|
|
99
101
|
? ""
|
|
100
102
|
: `\n id: (params) => params.${idParam} as string | number | undefined,`;
|
|
101
103
|
return [
|
|
102
|
-
`
|
|
103
|
-
export function use${methodUpper}${operationIdUpper}() {
|
|
104
|
-
return useEntityMutation<${paramNames}, ${requestBody || "any"}, ${responseBody || "any"}>(${entityConstName(modelName)}, {
|
|
105
|
-
op: "${isCreate ? "create" : "update"}",
|
|
106
|
-
method: "${method}",
|
|
107
|
-
url: ${urlStructure},${idLine}
|
|
108
|
-
});
|
|
104
|
+
`
|
|
105
|
+
export function use${methodUpper}${operationIdUpper}() {
|
|
106
|
+
return useEntityMutation<${paramNames}, ${requestBody || "any"}, ${responseBody || "any"}>(${entityConstName(modelName)}, {
|
|
107
|
+
op: "${isCreate ? "create" : "update"}",
|
|
108
|
+
method: "${method}",
|
|
109
|
+
url: ${urlStructure},${idLine}
|
|
110
|
+
});
|
|
109
111
|
}`,
|
|
110
112
|
importStatements,
|
|
111
113
|
];
|
|
112
114
|
}
|
|
113
|
-
exports.generateSyncUpdateMethod = generateSyncUpdateMethod;
|
|
114
115
|
function generateSyncDeleteMethod(url, modelName, operationId) {
|
|
115
116
|
const operationIdUpper = (0, capitalise_first_letter_1.capitaliseFirstLetter)(operationId);
|
|
116
117
|
const urlStructure = url.replace(/{[^}]+}/, "${id}");
|
|
117
118
|
const importStatements = new Set();
|
|
118
119
|
importStatements.add("sync:useEntityDelete");
|
|
119
120
|
return [
|
|
120
|
-
`
|
|
121
|
-
export function use${operationIdUpper}() {
|
|
122
|
-
return useEntityDelete(${entityConstName(modelName)}, {
|
|
123
|
-
url: (id) => \`${urlStructure}\`,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
121
|
+
`
|
|
122
|
+
export function use${operationIdUpper}() {
|
|
123
|
+
return useEntityDelete(${entityConstName(modelName)}, {
|
|
124
|
+
url: (id) => \`${urlStructure}\`,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
126
127
|
`,
|
|
127
128
|
importStatements,
|
|
128
129
|
];
|
|
129
130
|
}
|
|
130
|
-
exports.generateSyncDeleteMethod = generateSyncDeleteMethod;
|
|
131
131
|
function generateConfirmedMethod(url, method, operationId, requestBody, responseBody) {
|
|
132
132
|
const operationIdUpper = (0, capitalise_first_letter_1.capitaliseFirstLetter)(operationId);
|
|
133
133
|
const paramNames = `I${operationIdUpper}Params`;
|
|
@@ -144,15 +144,14 @@ function generateConfirmedMethod(url, method, operationId, requestBody, response
|
|
|
144
144
|
importStatements.add(responseBody);
|
|
145
145
|
}
|
|
146
146
|
return [
|
|
147
|
-
`
|
|
148
|
-
// Confirmed ("sync") operation: blocking, online-only, no optimistic apply.
|
|
149
|
-
export function use${methodUpper}${operationIdUpper}() {
|
|
150
|
-
return useConfirmedMutation<${paramNames}, ${requestBody || "any"}, ${responseBody || "any"}>({
|
|
151
|
-
method: "${method}",
|
|
152
|
-
url: ${urlStructure},
|
|
153
|
-
});
|
|
147
|
+
`
|
|
148
|
+
// Confirmed ("sync") operation: blocking, online-only, no optimistic apply.
|
|
149
|
+
export function use${methodUpper}${operationIdUpper}() {
|
|
150
|
+
return useConfirmedMutation<${paramNames}, ${requestBody || "any"}, ${responseBody || "any"}>({
|
|
151
|
+
method: "${method}",
|
|
152
|
+
url: ${urlStructure},
|
|
153
|
+
});
|
|
154
154
|
}`,
|
|
155
155
|
importStatements,
|
|
156
156
|
];
|
|
157
157
|
}
|
|
158
|
-
exports.generateConfirmedMethod = generateConfirmedMethod;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateUpdateAPIMethod =
|
|
3
|
+
exports.generateUpdateAPIMethod = generateUpdateAPIMethod;
|
|
4
4
|
const capitalise_first_letter_1 = require("../schema/capitalise-first-letter");
|
|
5
5
|
function generateUpdateAPIMethod(url, method, operationId, requestBody, responseBody, listQueryCacheKey, itemQueryCacheKey) {
|
|
6
6
|
const operationIdUpper = (0, capitalise_first_letter_1.capitaliseFirstLetter)(operationId);
|
|
@@ -9,21 +9,20 @@ function generateUpdateAPIMethod(url, method, operationId, requestBody, response
|
|
|
9
9
|
urlStructure = `(params) => \`${urlStructure}\``;
|
|
10
10
|
const methodUpper = method.charAt(0).toUpperCase() + method.slice(1);
|
|
11
11
|
const importStatements = new Set();
|
|
12
|
-
importStatements.add(paramNames
|
|
13
|
-
importStatements.add(requestBody
|
|
14
|
-
importStatements.add(responseBody
|
|
12
|
+
importStatements.add(paramNames ?? "");
|
|
13
|
+
importStatements.add(requestBody ?? "");
|
|
14
|
+
importStatements.add(responseBody ?? "");
|
|
15
15
|
const cacheKeyLines = [
|
|
16
16
|
listQueryCacheKey ? `\n listQueryCacheKey: ${listQueryCacheKey},` : "",
|
|
17
17
|
itemQueryCacheKey ? `\n itemQueryCacheKey: ${itemQueryCacheKey},` : "",
|
|
18
18
|
].join("");
|
|
19
19
|
return [
|
|
20
|
-
`
|
|
21
|
-
export function use${methodUpper}${operationIdUpper}() {
|
|
22
|
-
return useUpdateQuery<${paramNames}, ${requestBody}, ${responseBody}>({
|
|
23
|
-
${method}Url: ${urlStructure},${cacheKeyLines}
|
|
24
|
-
});
|
|
20
|
+
`
|
|
21
|
+
export function use${methodUpper}${operationIdUpper}() {
|
|
22
|
+
return useUpdateQuery<${paramNames}, ${requestBody}, ${responseBody}>({
|
|
23
|
+
${method}Url: ${urlStructure},${cacheKeyLines}
|
|
24
|
+
});
|
|
25
25
|
}`,
|
|
26
26
|
importStatements,
|
|
27
27
|
];
|
|
28
28
|
}
|
|
29
|
-
exports.generateUpdateAPIMethod = generateUpdateAPIMethod;
|
package/dist/rad-wasm-build.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* 2. wasm-bindgen --target web → stack/wasm/rad_wasm.js + rad_wasm_bg.wasm
|
|
8
8
|
* 3. wasm-opt -Oz (if available) to shrink the binary
|
|
9
9
|
*
|
|
10
|
-
* The generated bundle is what `<
|
|
10
|
+
* The generated bundle is what `<RAStackProvider mode="local">` loads. Prereqs:
|
|
11
11
|
* rustup target add wasm32-unknown-unknown
|
|
12
12
|
* cargo install wasm-bindgen-cli (version must match the wasm-bindgen crate)
|
|
13
13
|
*/
|
package/dist/rad-wasm-build.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* 2. wasm-bindgen --target web → stack/wasm/rad_wasm.js + rad_wasm_bg.wasm
|
|
9
9
|
* 3. wasm-opt -Oz (if available) to shrink the binary
|
|
10
10
|
*
|
|
11
|
-
* The generated bundle is what `<
|
|
11
|
+
* The generated bundle is what `<RAStackProvider mode="local">` loads. Prereqs:
|
|
12
12
|
* rustup target add wasm32-unknown-unknown
|
|
13
13
|
* cargo install wasm-bindgen-cli (version must match the wasm-bindgen crate)
|
|
14
14
|
*/
|
|
@@ -21,11 +21,17 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
21
21
|
const path_1 = __importDefault(require("path"));
|
|
22
22
|
const repoRoot = path_1.default.resolve(__dirname, "..", "..");
|
|
23
23
|
const rustDir = path_1.default.join(repoRoot, "rust");
|
|
24
|
-
const outDir = path_1.default.join(repoRoot, "
|
|
24
|
+
const outDir = path_1.default.join(repoRoot, "tools", "wasm");
|
|
25
25
|
const wasmPath = path_1.default.join(rustDir, "target", "wasm32-unknown-unknown", "release", "rad_wasm.wasm");
|
|
26
26
|
function run(cmd, args, cwd = repoRoot) {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
// Local build tool: `cmd`/`args` are the fixed toolchain invocations below
|
|
28
|
+
// (cargo, wasm-bindgen, wasm-opt), not untrusted input — no injection surface.
|
|
29
|
+
// nosemgrep: javascript.lang.security.detect-child-process.detect-child-process
|
|
30
|
+
const result = (0, child_process_1.spawnSync)(cmd, args, {
|
|
31
|
+
stdio: "inherit",
|
|
32
|
+
cwd,
|
|
33
|
+
env: process.env,
|
|
34
|
+
});
|
|
29
35
|
if (result.error) {
|
|
30
36
|
console.error(`\nCould not run \`${cmd}\`. Is it installed and on PATH?`);
|
|
31
37
|
if (cmd === "wasm-bindgen") {
|
|
@@ -34,10 +40,13 @@ function run(cmd, args, cwd = repoRoot) {
|
|
|
34
40
|
process.exit(1);
|
|
35
41
|
}
|
|
36
42
|
if (result.status !== 0) {
|
|
37
|
-
process.exit(
|
|
43
|
+
process.exit(result.status ?? 1);
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
function has(cmd) {
|
|
47
|
+
// Probes a fixed toolchain name (e.g. "wasm-opt") for availability; not
|
|
48
|
+
// untrusted input.
|
|
49
|
+
// nosemgrep: javascript.lang.security.detect-child-process.detect-child-process
|
|
41
50
|
return (0, child_process_1.spawnSync)(cmd, ["--version"], { stdio: "ignore" }).status === 0;
|
|
42
51
|
}
|
|
43
52
|
console.log("→ cargo build -p rad-wasm --release (wasm32-unknown-unknown)");
|
|
@@ -60,7 +69,7 @@ run("wasm-bindgen", [
|
|
|
60
69
|
wasmPath,
|
|
61
70
|
]);
|
|
62
71
|
// Mark the emitted bundle as ESM so Node and bundlers treat it correctly
|
|
63
|
-
// without forcing the parent
|
|
72
|
+
// without forcing the parent rastack package to be a module.
|
|
64
73
|
fs_1.default.writeFileSync(path_1.default.join(outDir, "package.json"), JSON.stringify({ type: "module", sideEffects: false }, null, 2) + "\n");
|
|
65
74
|
if (has("wasm-opt")) {
|
|
66
75
|
console.log("→ wasm-opt -Oz");
|
package/dist/rad.js
CHANGED
|
@@ -23,6 +23,10 @@ const child_process_1 = require("child_process");
|
|
|
23
23
|
const path_1 = __importDefault(require("path"));
|
|
24
24
|
const [command, ...rest] = process.argv.slice(2);
|
|
25
25
|
function run(script, args = rest) {
|
|
26
|
+
// `rad` is a local developer CLI: `script` is a fixed internal dist filename
|
|
27
|
+
// and `args` come from the developer's own shell (process.argv), not from an
|
|
28
|
+
// untrusted network request — there is no command-injection surface here.
|
|
29
|
+
// nosemgrep: javascript.lang.security.detect-child-process.detect-child-process
|
|
26
30
|
(0, child_process_1.execSync)(`node ${path_1.default.join(__dirname, script)} ${args.join(" ")}`, {
|
|
27
31
|
stdio: "inherit",
|
|
28
32
|
env: process.env,
|
|
@@ -30,10 +34,13 @@ function run(script, args = rest) {
|
|
|
30
34
|
}
|
|
31
35
|
/** Invoke the compiled Rust server binary (built by `cargo build` in rust/). */
|
|
32
36
|
function runRust(subcommand) {
|
|
33
|
-
var _a;
|
|
34
37
|
const repoRoot = path_1.default.resolve(__dirname, "..", "..");
|
|
35
38
|
const binary = process.env.RAD_SERVER_BIN ||
|
|
36
39
|
path_1.default.join(repoRoot, "rust", "target", "release", "rad-server");
|
|
40
|
+
// Runs the locally-built Rust server binary with a fixed internal subcommand
|
|
41
|
+
// ("serve"/"admin"); `rest` is the developer's own CLI args, not untrusted
|
|
42
|
+
// input — no command-injection surface.
|
|
43
|
+
// nosemgrep: javascript.lang.security.detect-child-process.detect-child-process
|
|
37
44
|
const result = (0, child_process_1.spawnSync)(binary, [subcommand, ...rest], {
|
|
38
45
|
stdio: "inherit",
|
|
39
46
|
env: process.env,
|
|
@@ -43,7 +50,7 @@ function runRust(subcommand) {
|
|
|
43
50
|
` cd rust && cargo build --release\n`);
|
|
44
51
|
process.exit(1);
|
|
45
52
|
}
|
|
46
|
-
process.exit(
|
|
53
|
+
process.exit(result.status ?? 0);
|
|
47
54
|
}
|
|
48
55
|
switch (command) {
|
|
49
56
|
case "compile":
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.camelToPastel =
|
|
3
|
+
exports.camelToPastel = camelToPastel;
|
|
4
4
|
function camelToPastel(str) {
|
|
5
5
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
6
6
|
}
|
|
7
|
-
exports.camelToPastel = camelToPastel;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.capitaliseFirstLetter =
|
|
3
|
+
exports.capitaliseFirstLetter = capitaliseFirstLetter;
|
|
4
4
|
function capitaliseFirstLetter(str) {
|
|
5
5
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
6
6
|
}
|
|
7
|
-
exports.capitaliseFirstLetter = capitaliseFirstLetter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractResponseBodySchema =
|
|
3
|
+
exports.extractResponseBodySchema = extractResponseBodySchema;
|
|
4
4
|
function extractResponseBodySchema(methodInformation) {
|
|
5
5
|
let responseBodySchema;
|
|
6
6
|
let isList = false;
|
|
@@ -9,9 +9,9 @@ function extractResponseBodySchema(methodInformation) {
|
|
|
9
9
|
Object.keys(methodInformation.responses).forEach((responseKey) => {
|
|
10
10
|
// @ts-ignore
|
|
11
11
|
const responseData = methodInformation.responses[responseKey];
|
|
12
|
-
if (responseData
|
|
12
|
+
if (responseData?.content) {
|
|
13
13
|
const mediaType = responseData.content["application/json"];
|
|
14
|
-
if (mediaType
|
|
14
|
+
if (mediaType?.schema) {
|
|
15
15
|
const refSchema = mediaType.schema.$ref;
|
|
16
16
|
if (refSchema) {
|
|
17
17
|
responseBodySchema = refSchema.replace("#/components/schemas/", "");
|
|
@@ -27,4 +27,3 @@ function extractResponseBodySchema(methodInformation) {
|
|
|
27
27
|
});
|
|
28
28
|
return [responseBodySchema, isList];
|
|
29
29
|
}
|
|
30
|
-
exports.extractResponseBodySchema = extractResponseBodySchema;
|
|
@@ -1,23 +1,11 @@
|
|
|
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
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.fetchSchema =
|
|
6
|
+
exports.fetchSchema = fetchSchema;
|
|
16
7
|
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
function fetchSchema(url) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return response.data;
|
|
21
|
-
});
|
|
8
|
+
async function fetchSchema(url) {
|
|
9
|
+
const response = await axios_1.default.get(url);
|
|
10
|
+
return response.data;
|
|
22
11
|
}
|
|
23
|
-
exports.fetchSchema = fetchSchema;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeNonModelPaths =
|
|
3
|
+
exports.removeNonModelPaths = removeNonModelPaths;
|
|
4
4
|
function removeNonModelPaths(paths) {
|
|
5
5
|
const filteredPaths = {};
|
|
6
6
|
Object.keys(paths).forEach((key) => {
|
|
@@ -12,4 +12,3 @@ function removeNonModelPaths(paths) {
|
|
|
12
12
|
});
|
|
13
13
|
return filteredPaths;
|
|
14
14
|
}
|
|
15
|
-
exports.removeNonModelPaths = removeNonModelPaths;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toCamelCase =
|
|
3
|
+
exports.toCamelCase = toCamelCase;
|
|
4
4
|
function toCamelCase(str) {
|
|
5
5
|
const pastel = str
|
|
6
6
|
.split("-")
|
|
@@ -8,4 +8,3 @@ function toCamelCase(str) {
|
|
|
8
8
|
.join("");
|
|
9
9
|
return pastel.charAt(0).toLowerCase() + pastel.slice(1);
|
|
10
10
|
}
|
|
11
|
-
exports.toCamelCase = toCamelCase;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toPascalCase =
|
|
3
|
+
exports.toPascalCase = toPascalCase;
|
|
4
4
|
function toPascalCase(str) {
|
|
5
5
|
return str
|
|
6
6
|
.split("-")
|
|
7
7
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
8
8
|
.join("");
|
|
9
9
|
}
|
|
10
|
-
exports.toPascalCase = toPascalCase;
|
package/dist/schema-convert.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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const fs_1 = require("fs");
|
|
13
4
|
const path_1 = require("path");
|
|
@@ -33,31 +24,29 @@ function removeDuplicates(code) {
|
|
|
33
24
|
});
|
|
34
25
|
return filteredCode;
|
|
35
26
|
}
|
|
36
|
-
function main() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return removedSignature + "\n";
|
|
54
|
-
});
|
|
27
|
+
async function main() {
|
|
28
|
+
console.log("Converting Schema");
|
|
29
|
+
const args = process.argv.slice(2);
|
|
30
|
+
const basePath = args[0];
|
|
31
|
+
const schemaFolderPath = (0, path_1.join)(basePath, "api-schema");
|
|
32
|
+
let interfaceFileData = "";
|
|
33
|
+
const schemaFiles = (0, fs_1.readdirSync)(schemaFolderPath);
|
|
34
|
+
let compilePromises = schemaFiles.map((schemaFile) => {
|
|
35
|
+
const schemaFilePath = (0, path_1.join)(schemaFolderPath, schemaFile);
|
|
36
|
+
return (0, json_schema_to_typescript_1.compileFromFile)(schemaFilePath, {
|
|
37
|
+
bannerComment: "",
|
|
38
|
+
style: { useTabs: false, tabWidth: 2 },
|
|
39
|
+
ignoreMinAndMaxItems: true,
|
|
40
|
+
strictIndexSignatures: false,
|
|
41
|
+
}).then((result) => {
|
|
42
|
+
const removedSignature = removeUnknownIndexSignature(result);
|
|
43
|
+
return removedSignature + "\n";
|
|
55
44
|
});
|
|
56
|
-
let results = yield Promise.all(compilePromises);
|
|
57
|
-
interfaceFileData = results.join("\n");
|
|
58
|
-
interfaceFileData = removeDuplicates(interfaceFileData);
|
|
59
|
-
const outputFile = (0, path_1.join)(basePath, "interface.ts");
|
|
60
|
-
(0, fs_1.writeFileSync)(outputFile, interfaceFileData);
|
|
61
45
|
});
|
|
46
|
+
let results = await Promise.all(compilePromises);
|
|
47
|
+
interfaceFileData = results.join("\n");
|
|
48
|
+
interfaceFileData = removeDuplicates(interfaceFileData);
|
|
49
|
+
const outputFile = (0, path_1.join)(basePath, "interface.ts");
|
|
50
|
+
(0, fs_1.writeFileSync)(outputFile, interfaceFileData);
|
|
62
51
|
}
|
|
63
52
|
main().catch((error) => console.error(error));
|