zero-swift 0.1.0 → 0.1.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 +1 -0
- package/dist/bin.js +75 -18
- package/package.json +6 -6
package/README.md
CHANGED
package/dist/bin.js
CHANGED
|
@@ -567,13 +567,38 @@ function aliasName(type) {
|
|
|
567
567
|
}
|
|
568
568
|
|
|
569
569
|
// src/cli.ts
|
|
570
|
+
var usage = `Usage:
|
|
571
|
+
zero-swift codegen [--schema schema.ts] [--out Schema.swift]
|
|
572
|
+
[--config zero-swift.json] [--check]
|
|
573
|
+
zero-swift drift record [--samples drift-samples.ts]
|
|
574
|
+
[--out drift-vectors.json] [--check]
|
|
575
|
+
|
|
576
|
+
codegen generates Swift from the app's TypeScript schema. Options override
|
|
577
|
+
zero-swift.json, which is read when present.
|
|
578
|
+
drift record runs the app's TS queries and mutators on samples and records
|
|
579
|
+
what they did, for the Swift drift test.
|
|
580
|
+
--check fails when the output is out of date instead of writing it.
|
|
581
|
+
|
|
582
|
+
Docs: https://github.com/wevm/zero/tree/main/packages/zero-swift-cli
|
|
583
|
+
`;
|
|
584
|
+
var UsageError = class extends Error {
|
|
585
|
+
};
|
|
586
|
+
function mustExist(path, message) {
|
|
587
|
+
if (!existsSync(path)) {
|
|
588
|
+
throw new UsageError(message);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
570
591
|
async function codegenFile(config, cwd) {
|
|
571
592
|
const schemaPath = resolve2(cwd, config.schema ?? "schema.ts");
|
|
593
|
+
mustExist(
|
|
594
|
+
schemaPath,
|
|
595
|
+
`Schema ${relative(cwd, schemaPath)} doesn't exist. Pass --schema, or set "schema" in zero-swift.json.`
|
|
596
|
+
);
|
|
572
597
|
const exportName = config.export ?? "schema";
|
|
573
598
|
const module = await import(pathToFileURL(schemaPath).href);
|
|
574
599
|
const schema = module[exportName];
|
|
575
600
|
if (!schema || typeof schema !== "object" || !("tables" in schema)) {
|
|
576
|
-
throw new
|
|
601
|
+
throw new UsageError(
|
|
577
602
|
`${schemaPath} does not export a schema as "${exportName}"`
|
|
578
603
|
);
|
|
579
604
|
}
|
|
@@ -586,24 +611,41 @@ async function codegenFile(config, cwd) {
|
|
|
586
611
|
);
|
|
587
612
|
}
|
|
588
613
|
async function main(argv) {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
614
|
+
let parsed;
|
|
615
|
+
try {
|
|
616
|
+
parsed = parseArgs({
|
|
617
|
+
args: argv,
|
|
618
|
+
allowPositionals: true,
|
|
619
|
+
options: {
|
|
620
|
+
schema: { type: "string" },
|
|
621
|
+
out: { type: "string" },
|
|
622
|
+
config: { type: "string" },
|
|
623
|
+
samples: { type: "string" },
|
|
624
|
+
check: { type: "boolean" },
|
|
625
|
+
help: { type: "boolean", short: "h" }
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
} catch (e) {
|
|
629
|
+
process.stderr.write(`${e.message}
|
|
630
|
+
|
|
631
|
+
${usage}`);
|
|
632
|
+
return 2;
|
|
633
|
+
}
|
|
634
|
+
const { values, positionals } = parsed;
|
|
600
635
|
const [command = "codegen", subcommand] = positionals;
|
|
636
|
+
if (values.help || command === "help") {
|
|
637
|
+
process.stdout.write(usage);
|
|
638
|
+
return 0;
|
|
639
|
+
}
|
|
601
640
|
const cwd = process.cwd();
|
|
602
641
|
if (command === "drift" && subcommand === "record") {
|
|
603
|
-
const
|
|
604
|
-
|
|
605
|
-
|
|
642
|
+
const samples = resolve2(cwd, values.samples ?? "drift-samples.ts");
|
|
643
|
+
mustExist(
|
|
644
|
+
samples,
|
|
645
|
+
`Samples file ${relative(cwd, samples)} doesn't exist. Pass --samples.`
|
|
606
646
|
);
|
|
647
|
+
const { recordDriftFile } = await import("./drift-S756Q2ZA.js");
|
|
648
|
+
const vectors = await recordDriftFile(samples);
|
|
607
649
|
return writeOutput(
|
|
608
650
|
resolve2(cwd, values.out ?? "drift-vectors.json"),
|
|
609
651
|
vectors,
|
|
@@ -612,11 +654,17 @@ async function main(argv) {
|
|
|
612
654
|
);
|
|
613
655
|
}
|
|
614
656
|
if (command !== "codegen") {
|
|
615
|
-
process.stderr.write(
|
|
616
|
-
`)
|
|
657
|
+
process.stderr.write(
|
|
658
|
+
`Unknown command "${positionals.join(" ")}"
|
|
659
|
+
|
|
660
|
+
${usage}`
|
|
661
|
+
);
|
|
617
662
|
return 2;
|
|
618
663
|
}
|
|
619
664
|
const configPath = values.config ?? (existsSync(resolve2(cwd, "zero-swift.json")) ? "zero-swift.json" : void 0);
|
|
665
|
+
if (configPath) {
|
|
666
|
+
mustExist(resolve2(cwd, configPath), `Config ${configPath} doesn't exist.`);
|
|
667
|
+
}
|
|
620
668
|
const fileConfig = configPath ? JSON.parse(readFileSync(resolve2(cwd, configPath), "utf8")) : {};
|
|
621
669
|
const config = {
|
|
622
670
|
...fileConfig,
|
|
@@ -646,4 +694,13 @@ function writeOutput(output, contents, check, cwd) {
|
|
|
646
694
|
}
|
|
647
695
|
|
|
648
696
|
// src/bin.ts
|
|
649
|
-
|
|
697
|
+
try {
|
|
698
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
699
|
+
} catch (e) {
|
|
700
|
+
if (!(e instanceof UsageError)) {
|
|
701
|
+
throw e;
|
|
702
|
+
}
|
|
703
|
+
process.stderr.write(`zero-swift: ${e.message}
|
|
704
|
+
`);
|
|
705
|
+
process.exitCode = 1;
|
|
706
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zero-swift",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Generates the Swift row types and schema of a Zero app for the Zero Swift client.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"typescript": "6.0.3"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@types/node": "^22.
|
|
22
|
+
"@types/node": "^22.19.19",
|
|
23
23
|
"esbuild": "0.28.2",
|
|
24
|
-
"oxfmt": "^0.
|
|
24
|
+
"oxfmt": "^0.74.0",
|
|
25
25
|
"vitest": "^5.0.0",
|
|
26
|
-
"zero-schema": "0.0.0",
|
|
27
26
|
"@rocicorp/zero": "1.12.0",
|
|
28
|
-
"
|
|
29
|
-
"zero-types": "0.0.0"
|
|
27
|
+
"zero-schema": "0.0.0",
|
|
28
|
+
"zero-types": "0.0.0",
|
|
29
|
+
"zql": "0.0.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@rocicorp/zero": ">=1.11.0"
|