cloesce 0.0.3 → 0.0.4-unstable.1
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/README.md +488 -23
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +221 -254
- package/dist/common.d.ts +69 -1
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +72 -11
- package/dist/{extract.d.ts → extractor/extract.d.ts} +5 -2
- package/dist/extractor/extract.d.ts.map +1 -0
- package/dist/{extract.js → extractor/extract.js} +242 -43
- package/dist/generator.wasm +0 -0
- package/dist/orm.wasm +0 -0
- package/dist/router/crud.d.ts +22 -0
- package/dist/router/crud.d.ts.map +1 -0
- package/dist/router/crud.js +65 -0
- package/dist/router/router.d.ts +77 -0
- package/dist/router/router.d.ts.map +1 -0
- package/dist/router/router.js +358 -0
- package/dist/router/wasm.d.ts +37 -0
- package/dist/router/wasm.d.ts.map +1 -0
- package/dist/router/wasm.js +98 -0
- package/dist/ui/backend.d.ts +124 -0
- package/dist/ui/backend.d.ts.map +1 -0
- package/dist/ui/backend.js +201 -0
- package/dist/ui/client.d.ts +5 -0
- package/dist/ui/client.d.ts.map +1 -0
- package/dist/ui/client.js +7 -0
- package/package.json +70 -58
- package/LICENSE +0 -201
- package/dist/cli.wasm +0 -0
- package/dist/cloesce.d.ts +0 -108
- package/dist/cloesce.d.ts.map +0 -1
- package/dist/cloesce.js +0 -453
- package/dist/decorators.d.ts +0 -13
- package/dist/decorators.d.ts.map +0 -1
- package/dist/decorators.js +0 -13
- package/dist/dog.cloesce.js +0 -111
- package/dist/extract.d.ts.map +0 -1
- package/dist/index.d.ts +0 -24
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -24
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,88 +1,150 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { WASI } from "node:wasi";
|
|
3
3
|
import fs from "node:fs";
|
|
4
|
+
import { readFile } from "fs/promises";
|
|
4
5
|
import path from "node:path";
|
|
5
|
-
import {
|
|
6
|
-
import { command, run, subcommands, flag, option, optional, string, } from "cmd-ts";
|
|
6
|
+
import { command, run, subcommands, flag, string, positional, option, optional, } from "cmd-ts";
|
|
7
7
|
import { Project } from "ts-morph";
|
|
8
|
-
import { CidlExtractor } from "./extract.js";
|
|
8
|
+
import { CidlExtractor } from "./extractor/extract.js";
|
|
9
9
|
import { ExtractorError, ExtractorErrorCode, getErrorInfo } from "./common.js";
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
10
|
+
const cmds = subcommands({
|
|
11
|
+
name: "cloesce",
|
|
12
|
+
cmds: {
|
|
13
|
+
compile: command({
|
|
14
|
+
name: "compile",
|
|
15
|
+
description: "Run through the full compilation process.",
|
|
16
|
+
args: {
|
|
17
|
+
debug: flag({
|
|
18
|
+
long: "debug",
|
|
19
|
+
short: "d",
|
|
20
|
+
description: "Show debug output",
|
|
21
|
+
}),
|
|
22
|
+
},
|
|
23
|
+
handler: async (args) => {
|
|
24
|
+
const config = loadCloesceConfig(process.cwd(), args.debug);
|
|
25
|
+
if (!config.workersUrl || !config.clientUrl) {
|
|
26
|
+
console.error("Error: `workersUrl` and `clientUrl` must be defined in cloesce.config.json");
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
// Creates a `cidl.json` file. Exits the process on failure.
|
|
30
|
+
await extract({ debug: args.debug });
|
|
31
|
+
const outputDir = config.outputDir ?? ".generated";
|
|
32
|
+
const allConfig = {
|
|
33
|
+
name: "all",
|
|
34
|
+
wasmFile: "generator.wasm",
|
|
35
|
+
args: [
|
|
36
|
+
"generate",
|
|
37
|
+
"all",
|
|
38
|
+
path.join(outputDir, "cidl.pre.json"),
|
|
39
|
+
path.join(outputDir, "cidl.json"),
|
|
40
|
+
"wrangler.toml",
|
|
41
|
+
path.join(outputDir, "workers.ts"),
|
|
42
|
+
path.join(outputDir, "client.ts"),
|
|
43
|
+
config.clientUrl,
|
|
44
|
+
config.workersUrl,
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
// Runs a generator command. Exits the process on failure.
|
|
48
|
+
await generate(allConfig);
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
extract: command({
|
|
52
|
+
name: "extract",
|
|
53
|
+
description: "Extract models and write cidl.pre.json",
|
|
54
|
+
args: {
|
|
55
|
+
projectName: option({
|
|
56
|
+
long: "project-name",
|
|
57
|
+
type: optional(string),
|
|
58
|
+
description: "Project name",
|
|
59
|
+
}),
|
|
60
|
+
out: option({
|
|
61
|
+
long: "out",
|
|
62
|
+
short: "o",
|
|
63
|
+
type: optional(string),
|
|
64
|
+
}),
|
|
65
|
+
inp: option({
|
|
66
|
+
long: "in",
|
|
67
|
+
short: "i",
|
|
68
|
+
type: optional(string),
|
|
69
|
+
description: "Input file or directory",
|
|
70
|
+
}),
|
|
71
|
+
location: option({
|
|
72
|
+
long: "location",
|
|
73
|
+
short: "l",
|
|
74
|
+
type: optional(string),
|
|
75
|
+
description: "Project directory (default: cwd)",
|
|
76
|
+
}),
|
|
77
|
+
truncateSourcePaths: flag({
|
|
78
|
+
long: "truncateSourcePaths",
|
|
79
|
+
description: "Sets all source paths to just their file name",
|
|
80
|
+
}),
|
|
81
|
+
debug: flag({
|
|
82
|
+
long: "debug",
|
|
83
|
+
short: "d",
|
|
84
|
+
description: "Show debug output",
|
|
85
|
+
}),
|
|
86
|
+
},
|
|
87
|
+
handler: async (args) => {
|
|
88
|
+
await extract({ ...args });
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
migrate: command({
|
|
92
|
+
name: "migrate",
|
|
93
|
+
description: "Creates a database migration.",
|
|
94
|
+
args: {
|
|
95
|
+
name: positional({ type: string, displayName: "name" }),
|
|
96
|
+
debug: flag({
|
|
97
|
+
long: "debug",
|
|
98
|
+
short: "d",
|
|
99
|
+
description: "Show debug output",
|
|
100
|
+
}),
|
|
101
|
+
},
|
|
102
|
+
handler: async (args) => {
|
|
103
|
+
const config = loadCloesceConfig(process.cwd(), args.debug);
|
|
104
|
+
const cidlPath = path.join(config.outputDir ?? ".generated", "cidl.json");
|
|
105
|
+
if (!fs.existsSync(cidlPath)) {
|
|
106
|
+
console.error("Err: No cloesce file found, have you ran `cloesce compile`?");
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
const migrationsPath = "./migrations";
|
|
110
|
+
if (!fs.existsSync(migrationsPath)) {
|
|
111
|
+
fs.mkdirSync(migrationsPath);
|
|
112
|
+
}
|
|
113
|
+
const migrationPrefix = path.join(migrationsPath, `${timestamp()}_${args.name}`);
|
|
114
|
+
let wasmArgs = [
|
|
115
|
+
"migrations",
|
|
116
|
+
cidlPath,
|
|
117
|
+
`${migrationPrefix}.json`,
|
|
118
|
+
`${migrationPrefix}.sql`,
|
|
119
|
+
];
|
|
120
|
+
// Add last migration if exists
|
|
121
|
+
{
|
|
122
|
+
const files = fs.readdirSync(migrationsPath);
|
|
123
|
+
const jsonFiles = files.filter((f) => f.endsWith(".json"));
|
|
124
|
+
// Sort descending by filename
|
|
125
|
+
jsonFiles.sort((a, b) => b.localeCompare(a, undefined, { numeric: true }));
|
|
126
|
+
if (jsonFiles.length > 0) {
|
|
127
|
+
wasmArgs.push(path.join(migrationsPath, jsonFiles[0]));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const migrateConfig = {
|
|
131
|
+
name: "migrations",
|
|
132
|
+
wasmFile: "generator.wasm",
|
|
133
|
+
args: wasmArgs,
|
|
134
|
+
};
|
|
135
|
+
// Runs a generator command. Exits the process on failure.
|
|
136
|
+
await generate(migrateConfig);
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
async function extract(opts) {
|
|
80
142
|
const root = process.cwd();
|
|
81
143
|
const projectRoot = process.cwd();
|
|
82
144
|
const config = loadCloesceConfig(projectRoot, opts.debug);
|
|
83
145
|
const searchPaths = opts.inp ? [opts.inp] : (config.paths ?? [root]);
|
|
84
146
|
const outputDir = config.outputDir ?? ".generated";
|
|
85
|
-
const outPath = opts.out ?? path.join(outputDir, "cidl.json");
|
|
147
|
+
const outPath = opts.out ?? path.join(outputDir, "cidl.pre.json");
|
|
86
148
|
const truncate = opts.truncateSourcePaths ?? config.truncateSourcePaths ?? false;
|
|
87
149
|
const cloesceProjectName = opts.projectName ??
|
|
88
150
|
config.projectName ??
|
|
@@ -110,6 +172,9 @@ async function runExtractor(opts) {
|
|
|
110
172
|
if (truncate) {
|
|
111
173
|
ast.wrangler_env.source_path =
|
|
112
174
|
"./" + path.basename(ast.wrangler_env.source_path);
|
|
175
|
+
if (ast.app_source) {
|
|
176
|
+
ast.app_source = "./" + path.basename(ast.app_source);
|
|
177
|
+
}
|
|
113
178
|
for (const model of Object.values(ast.models)) {
|
|
114
179
|
model.source_path =
|
|
115
180
|
"./" + path.basename(model.source_path);
|
|
@@ -132,23 +197,22 @@ async function runExtractor(opts) {
|
|
|
132
197
|
process.exit(1);
|
|
133
198
|
}
|
|
134
199
|
}
|
|
135
|
-
async function
|
|
200
|
+
async function generate(config) {
|
|
136
201
|
const root = process.cwd();
|
|
137
|
-
|
|
138
|
-
const wranglerPath = path.join(root,
|
|
202
|
+
// Look for wrangler.toml in the root directory
|
|
203
|
+
const wranglerPath = path.join(root, "wrangler.toml");
|
|
139
204
|
if (!fs.existsSync(wranglerPath)) {
|
|
140
|
-
fs.mkdirSync(path.dirname(wranglerPath), { recursive: true });
|
|
141
205
|
fs.writeFileSync(wranglerPath, "");
|
|
142
206
|
}
|
|
143
207
|
const wasi = new WASI({
|
|
144
208
|
version: "preview1",
|
|
145
|
-
args: [
|
|
209
|
+
args: ["generate", ...config.args],
|
|
146
210
|
env: { ...process.env, ...config.env },
|
|
147
|
-
preopens: { "
|
|
211
|
+
preopens: { ".": root },
|
|
148
212
|
});
|
|
149
|
-
const
|
|
150
|
-
const mod = await WebAssembly.compile(
|
|
151
|
-
|
|
213
|
+
const wasm = await readFile(new URL("./generator.wasm", import.meta.url));
|
|
214
|
+
const mod = await WebAssembly.compile(new Uint8Array(wasm));
|
|
215
|
+
let instance = await WebAssembly.instantiate(mod, {
|
|
152
216
|
wasi_snapshot_preview1: wasi.wasiImport,
|
|
153
217
|
});
|
|
154
218
|
try {
|
|
@@ -158,180 +222,83 @@ async function runWasmCommand(config) {
|
|
|
158
222
|
console.error(`WASM execution failed for ${config.name}:`, err);
|
|
159
223
|
}
|
|
160
224
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}),
|
|
170
|
-
},
|
|
171
|
-
handler: async (args) => {
|
|
172
|
-
const config = loadCloesceConfig(process.cwd(), args.debug);
|
|
173
|
-
if (!config.workersUrl || !config.clientUrl) {
|
|
174
|
-
console.error("Error: workersUrl and clientUrl must be defined in cloesce-config.json");
|
|
175
|
-
process.exit(1);
|
|
225
|
+
function loadCloesceConfig(root, debug = false) {
|
|
226
|
+
const configPath = path.join(root, "cloesce.config.json");
|
|
227
|
+
if (fs.existsSync(configPath)) {
|
|
228
|
+
try {
|
|
229
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
230
|
+
if (debug)
|
|
231
|
+
console.log(`Loaded config from ${configPath}`);
|
|
232
|
+
return config;
|
|
176
233
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
// we should allow them to define that directory in the config
|
|
180
|
-
const outputDir = config.outputDir ?? ".generated";
|
|
181
|
-
const allConfig = {
|
|
182
|
-
name: "all",
|
|
183
|
-
wasmFile: "cli.wasm",
|
|
184
|
-
args: [
|
|
185
|
-
"generate",
|
|
186
|
-
"all",
|
|
187
|
-
path.join(outputDir, "cidl.json"),
|
|
188
|
-
path.join(outputDir, "wrangler.toml"),
|
|
189
|
-
path.join(outputDir, "migrations.sql"),
|
|
190
|
-
path.join(outputDir, "workers.ts"),
|
|
191
|
-
path.join(outputDir, "client.ts"),
|
|
192
|
-
config.clientUrl,
|
|
193
|
-
config.workersUrl,
|
|
194
|
-
],
|
|
195
|
-
};
|
|
196
|
-
await runWasmCommand(allConfig);
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
// In case the user wants to run individual steps we should probably allow them
|
|
200
|
-
const wranglerCmd = command({
|
|
201
|
-
name: "wrangler",
|
|
202
|
-
description: "Generate wrangler.toml configuration",
|
|
203
|
-
args: {},
|
|
204
|
-
handler: async () => {
|
|
205
|
-
const config = loadCloesceConfig(process.cwd());
|
|
206
|
-
const outputDir = config.outputDir ?? ".generated";
|
|
207
|
-
await runWasmCommand({
|
|
208
|
-
name: "wrangler",
|
|
209
|
-
wasmFile: "cli.wasm",
|
|
210
|
-
args: ["generate", "wrangler", path.join(outputDir, "wrangler.toml")],
|
|
211
|
-
});
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
|
-
const d1Cmd = command({
|
|
215
|
-
name: "d1",
|
|
216
|
-
description: "Generate database schema",
|
|
217
|
-
args: {},
|
|
218
|
-
handler: async () => {
|
|
219
|
-
const config = loadCloesceConfig(process.cwd());
|
|
220
|
-
const outputDir = config.outputDir ?? ".generated";
|
|
221
|
-
await runWasmCommand({
|
|
222
|
-
name: "d1",
|
|
223
|
-
wasmFile: "cli.wasm",
|
|
224
|
-
args: [
|
|
225
|
-
"generate",
|
|
226
|
-
"d1",
|
|
227
|
-
path.join(outputDir, "cidl.json"),
|
|
228
|
-
path.join(outputDir, "migrations.sql"),
|
|
229
|
-
],
|
|
230
|
-
});
|
|
231
|
-
},
|
|
232
|
-
});
|
|
233
|
-
const workersCmd = command({
|
|
234
|
-
name: "workers",
|
|
235
|
-
description: "Generate workers TypeScript",
|
|
236
|
-
args: {},
|
|
237
|
-
handler: async () => {
|
|
238
|
-
const config = loadCloesceConfig(process.cwd());
|
|
239
|
-
const outputDir = config.outputDir ?? ".generated";
|
|
240
|
-
if (!config.workersUrl) {
|
|
241
|
-
console.error("Error: workersUrl must be defined in cloesce-config.json");
|
|
242
|
-
process.exit(1);
|
|
234
|
+
catch (err) {
|
|
235
|
+
console.warn(`Failed to parse cloesce.config.json: ${err}`);
|
|
243
236
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
237
|
+
}
|
|
238
|
+
return {};
|
|
239
|
+
}
|
|
240
|
+
function timestamp() {
|
|
241
|
+
const d = new Date();
|
|
242
|
+
return (d.getFullYear().toString() +
|
|
243
|
+
String(d.getMonth() + 1).padStart(2, "0") +
|
|
244
|
+
String(d.getDate()).padStart(2, "0") +
|
|
245
|
+
"T" +
|
|
246
|
+
String(d.getHours()).padStart(2, "0") +
|
|
247
|
+
String(d.getMinutes()).padStart(2, "0") +
|
|
248
|
+
String(d.getSeconds()).padStart(2, "0"));
|
|
249
|
+
}
|
|
250
|
+
function readPackageJsonProjectName(cwd) {
|
|
251
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
252
|
+
let projectName = path.basename(cwd);
|
|
253
|
+
if (fs.existsSync(pkgPath)) {
|
|
254
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
255
|
+
projectName = pkg.name ?? projectName;
|
|
256
|
+
}
|
|
257
|
+
return projectName;
|
|
258
|
+
}
|
|
259
|
+
function findCloesceProject(root, searchPaths, project) {
|
|
260
|
+
for (const searchPath of searchPaths) {
|
|
261
|
+
let fullPath;
|
|
262
|
+
if (path.isAbsolute(searchPath) || searchPath.startsWith(root)) {
|
|
263
|
+
fullPath = path.normalize(searchPath);
|
|
268
264
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
type: optional(string),
|
|
307
|
-
description: "Project directory (default: cwd)",
|
|
308
|
-
}),
|
|
309
|
-
truncateSourcePaths: flag({
|
|
310
|
-
long: "truncateSourcePaths",
|
|
311
|
-
description: "Sets all source paths to just their file name",
|
|
312
|
-
}),
|
|
313
|
-
debug: flag({
|
|
314
|
-
long: "debug",
|
|
315
|
-
short: "d",
|
|
316
|
-
description: "Show debug output",
|
|
317
|
-
}),
|
|
318
|
-
},
|
|
319
|
-
handler: async (args) => {
|
|
320
|
-
await runExtractor({ ...args });
|
|
321
|
-
},
|
|
322
|
-
});
|
|
323
|
-
const router = subcommands({
|
|
324
|
-
name: "cloesce",
|
|
325
|
-
cmds: {
|
|
326
|
-
run: runCmd,
|
|
327
|
-
extract: extractCmd,
|
|
328
|
-
wrangler: wranglerCmd,
|
|
329
|
-
d1: d1Cmd,
|
|
330
|
-
workers: workersCmd,
|
|
331
|
-
client: clientCmd,
|
|
332
|
-
},
|
|
333
|
-
});
|
|
334
|
-
run(router, process.argv.slice(2)).catch((err) => {
|
|
265
|
+
else {
|
|
266
|
+
fullPath = path.resolve(root, searchPath);
|
|
267
|
+
}
|
|
268
|
+
if (!fs.existsSync(fullPath)) {
|
|
269
|
+
console.warn(`Warning: Path "${searchPath}" does not exist`);
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const stats = fs.statSync(fullPath);
|
|
273
|
+
if (stats.isFile() && /\.cloesce\.ts$/i.test(fullPath)) {
|
|
274
|
+
project.addSourceFileAtPath(fullPath);
|
|
275
|
+
}
|
|
276
|
+
else if (stats.isDirectory()) {
|
|
277
|
+
walkDirectory(fullPath, project);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function walkDirectory(dir, project) {
|
|
281
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
282
|
+
const fullPath = path.join(dir, entry.name);
|
|
283
|
+
if (entry.isDirectory() && !entry.name.startsWith(".")) {
|
|
284
|
+
walkDirectory(fullPath, project);
|
|
285
|
+
}
|
|
286
|
+
else if (entry.isFile() && /\.cloesce\.ts$/i.test(entry.name)) {
|
|
287
|
+
project.addSourceFileAtPath(fullPath);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function formatErr(e) {
|
|
293
|
+
const { description, suggestion } = getErrorInfo(e.code);
|
|
294
|
+
const contextLine = e.context ? `Context: ${e.context}\n` : "";
|
|
295
|
+
const snippetLine = e.snippet ? `${e.snippet}\n\n` : "";
|
|
296
|
+
return `==== CLOESCE ERROR ====
|
|
297
|
+
Error [${ExtractorErrorCode[e.code]}]: ${description}
|
|
298
|
+
Phase: TypeScript IDL Extraction
|
|
299
|
+
${contextLine}${snippetLine}Suggested fix: ${suggestion}`;
|
|
300
|
+
}
|
|
301
|
+
run(cmds, process.argv.slice(2)).catch((err) => {
|
|
335
302
|
console.error(err);
|
|
336
303
|
process.exit(1);
|
|
337
304
|
});
|
package/dist/common.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export type DeepPartial<T> = T extends (infer U)[] ? DeepPartial<U>[] : T extends object ? {
|
|
2
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
3
|
+
} : T;
|
|
1
4
|
export type Either<L, R> = {
|
|
2
5
|
ok: false;
|
|
3
6
|
value: L;
|
|
@@ -7,16 +10,73 @@ export type Either<L, R> = {
|
|
|
7
10
|
};
|
|
8
11
|
export declare function left<L>(value: L): Either<L, never>;
|
|
9
12
|
export declare function right<R>(value: R): Either<never, R>;
|
|
13
|
+
export declare enum ExtractorErrorCode {
|
|
14
|
+
MissingExport = 0,
|
|
15
|
+
AppMissingDefaultExport = 1,
|
|
16
|
+
UnknownType = 2,
|
|
17
|
+
MultipleGenericType = 3,
|
|
18
|
+
DataSourceMissingStatic = 4,
|
|
19
|
+
InvalidPartialType = 5,
|
|
20
|
+
InvalidIncludeTree = 6,
|
|
21
|
+
InvalidAttributeModifier = 7,
|
|
22
|
+
InvalidApiMethodModifier = 8,
|
|
23
|
+
UnknownNavigationPropertyReference = 9,
|
|
24
|
+
InvalidNavigationPropertyReference = 10,
|
|
25
|
+
MissingNavigationPropertyReference = 11,
|
|
26
|
+
MissingManyToManyUniqueId = 12,
|
|
27
|
+
MissingPrimaryKey = 13,
|
|
28
|
+
MissingWranglerEnv = 14,
|
|
29
|
+
TooManyWranglerEnvs = 15,
|
|
30
|
+
MissingFile = 16
|
|
31
|
+
}
|
|
32
|
+
export declare function getErrorInfo(code: ExtractorErrorCode): {
|
|
33
|
+
description: string;
|
|
34
|
+
suggestion: string;
|
|
35
|
+
};
|
|
36
|
+
export declare class ExtractorError {
|
|
37
|
+
code: ExtractorErrorCode;
|
|
38
|
+
context?: string;
|
|
39
|
+
snippet?: string;
|
|
40
|
+
constructor(code: ExtractorErrorCode);
|
|
41
|
+
addContext(fn: (val: string | undefined) => string | undefined): void;
|
|
42
|
+
}
|
|
10
43
|
export type HttpResult<T = unknown> = {
|
|
11
44
|
ok: boolean;
|
|
12
45
|
status: number;
|
|
13
46
|
data?: T;
|
|
14
47
|
message?: string;
|
|
15
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Dependency injection container, mapping an object type name to an instance of that object.
|
|
51
|
+
*
|
|
52
|
+
* Comes with the WranglerEnv and Request by default.
|
|
53
|
+
*/
|
|
54
|
+
export type InstanceRegistry = Map<string, any>;
|
|
55
|
+
export type MiddlewareFn = (request: Request, env: any, ir: InstanceRegistry) => Promise<HttpResult | undefined>;
|
|
56
|
+
export type KeysOfType<T, U> = {
|
|
57
|
+
[K in keyof T]: T[K] extends U ? (K extends string ? K : never) : never;
|
|
58
|
+
}[keyof T];
|
|
59
|
+
/**
|
|
60
|
+
* A container for middleware. If an instance is exported from `app.cloesce.ts`, it will be used in the
|
|
61
|
+
* appropriate location, with global middleware happening before any routing occurs.
|
|
62
|
+
*/
|
|
63
|
+
export declare class CloesceApp {
|
|
64
|
+
global: MiddlewareFn[];
|
|
65
|
+
model: Map<string, MiddlewareFn[]>;
|
|
66
|
+
method: Map<string, Map<string, MiddlewareFn[]>>;
|
|
67
|
+
useGlobal(m: MiddlewareFn): void;
|
|
68
|
+
useModel<T>(ctor: new () => T, m: MiddlewareFn): void;
|
|
69
|
+
useMethod<T>(ctor: new () => T, method: KeysOfType<T, (...args: any) => any>, m: MiddlewareFn): void;
|
|
70
|
+
}
|
|
71
|
+
export type CrudKind = "POST" | "GET" | "LIST";
|
|
16
72
|
export type CidlType = "Void" | "Integer" | "Real" | "Text" | "Blob" | {
|
|
73
|
+
DataSource: string;
|
|
74
|
+
} | {
|
|
17
75
|
Inject: string;
|
|
18
76
|
} | {
|
|
19
|
-
|
|
77
|
+
Object: string;
|
|
78
|
+
} | {
|
|
79
|
+
Partial: string;
|
|
20
80
|
} | {
|
|
21
81
|
Nullable: CidlType;
|
|
22
82
|
} | {
|
|
@@ -75,9 +135,15 @@ export interface Model {
|
|
|
75
135
|
data_sources: Record<string, DataSource>;
|
|
76
136
|
source_path: string;
|
|
77
137
|
}
|
|
138
|
+
export interface PlainOldObject {
|
|
139
|
+
name: string;
|
|
140
|
+
attributes: NamedTypedValue[];
|
|
141
|
+
source_path: string;
|
|
142
|
+
}
|
|
78
143
|
export interface CidlIncludeTree {
|
|
79
144
|
[key: string]: CidlIncludeTree;
|
|
80
145
|
}
|
|
146
|
+
export declare const NO_DATA_SOURCE = "none";
|
|
81
147
|
export interface DataSource {
|
|
82
148
|
name: string;
|
|
83
149
|
tree: CidlIncludeTree;
|
|
@@ -92,5 +158,7 @@ export interface CloesceAst {
|
|
|
92
158
|
language: "TypeScript";
|
|
93
159
|
wrangler_env: WranglerEnv;
|
|
94
160
|
models: Record<string, Model>;
|
|
161
|
+
poos: Record<string, PlainOldObject>;
|
|
162
|
+
app_source: string | null;
|
|
95
163
|
}
|
|
96
164
|
//# sourceMappingURL=common.d.ts.map
|
package/dist/common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC9C,WAAW,CAAC,CAAC,CAAC,EAAE,GAChB,CAAC,SAAS,MAAM,GACd;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GACtC,CAAC,CAAC;AAER,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAC5E,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAElD;AACD,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAEnD;AAED,oBAAY,kBAAkB;IAC5B,aAAa,IAAA;IACb,uBAAuB,IAAA;IACvB,WAAW,IAAA;IACX,mBAAmB,IAAA;IACnB,uBAAuB,IAAA;IACvB,kBAAkB,IAAA;IAClB,kBAAkB,IAAA;IAClB,wBAAwB,IAAA;IACxB,wBAAwB,IAAA;IACxB,kCAAkC,IAAA;IAClC,kCAAkC,KAAA;IAClC,kCAAkC,KAAA;IAClC,yBAAyB,KAAA;IACzB,iBAAiB,KAAA;IACjB,kBAAkB,KAAA;IAClB,mBAAmB,KAAA;IACnB,WAAW,KAAA;CACZ;AAmFD,wBAAgB,YAAY,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