@teurons/vds 0.0.0-stage → 0.0.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/dist/vds.js ADDED
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/bin.js
4
+ import { readdirSync, readFileSync as readFileSync2 } from "node:fs";
5
+ import { join, resolve } from "node:path";
6
+
7
+ // ../../specs/js/load.js
8
+ import { readFileSync } from "node:fs";
9
+ var compiled = /* @__PURE__ */ new Map();
10
+ function compile(url, build) {
11
+ const key = String(url);
12
+ if (!compiled.has(key)) {
13
+ let bytes;
14
+ try {
15
+ bytes = readFileSync(url);
16
+ } catch {
17
+ throw new Error(`${key.split("/").pop()} is missing. Build it with: ${build}`);
18
+ }
19
+ compiled.set(key, new WebAssembly.Module(bytes));
20
+ }
21
+ return compiled.get(key);
22
+ }
23
+
24
+ // ../../specs/js/bridge.js
25
+ var enc = new TextEncoder();
26
+ var dec = new TextDecoder();
27
+ function instanceOf(module) {
28
+ return new WebAssembly.Instance(module, {});
29
+ }
30
+ function bridge(instance) {
31
+ const x = instance.exports;
32
+ const read = (packed) => {
33
+ const ptr = Number(packed >> 32n);
34
+ const len = Number(packed & 0xffffffffn);
35
+ const text = dec.decode(new Uint8Array(x.memory.buffer, ptr, len));
36
+ x.dealloc(ptr, len);
37
+ return text;
38
+ };
39
+ const call = (fn, input) => {
40
+ const bytes = enc.encode(input);
41
+ const ptr = x.alloc(bytes.length);
42
+ new Uint8Array(x.memory.buffer, ptr, bytes.length).set(bytes);
43
+ return read(x[fn](ptr, bytes.length));
44
+ };
45
+ return {
46
+ call,
47
+ /** Calls an export with a value as JSON and returns its answer parsed. */
48
+ json: (fn, input) => JSON.parse(call(fn, JSON.stringify(input))),
49
+ /** Calls an export that takes nothing and returns its answer parsed. */
50
+ none: (fn) => JSON.parse(read(x[fn]()))
51
+ };
52
+ }
53
+
54
+ // ../../mapper/js/index.js
55
+ function bind(instance) {
56
+ const { call, json } = bridge(instance);
57
+ return {
58
+ validate: (files) => json("validate", files),
59
+ v2Check: (files) => json("v2_check", files),
60
+ v2Index: (files) => call("v2_index", JSON.stringify(files)),
61
+ load: (files) => json("load", files),
62
+ check: (changes) => json("check", changes),
63
+ apply: (changes) => json("apply", changes),
64
+ toYaml: (doc) => call("to_yaml", typeof doc === "string" ? doc : JSON.stringify(doc)),
65
+ toYamlOver: (original, doc) => call("to_yaml_over", JSON.stringify({ original, doc })),
66
+ parseYaml: (text) => {
67
+ const r = JSON.parse(call("parse_yaml", text));
68
+ if ("error" in r) throw new Error(r.error);
69
+ return r.ok;
70
+ },
71
+ nextId: (kind, parent) => json("next_id", { kind, parent: parent ?? null }).id ?? null,
72
+ readSettings: (text) => json("read_settings", { settings: text ?? null }),
73
+ workspaceFiles: (paths) => json("workspace_files", paths),
74
+ classify: (files) => json("classify", files),
75
+ pathOf: (input) => json("path_of", input).path,
76
+ describe: (settings, path) => json("path_of", { settings: settings ?? null, of: "describe", path }),
77
+ parseFeature: (text) => JSON.parse(call("parse_feature", text)),
78
+ writeFeature: (input) => call("write_feature", JSON.stringify(input)),
79
+ retitleFeature: (text, requirement, title) => call("retitle_feature", JSON.stringify({ text, requirement, title })),
80
+ putScenario: (text, scenario) => call("put_scenario", JSON.stringify({ text, scenario })),
81
+ removeScenario: (text, id) => call("remove_scenario", JSON.stringify({ text, id }))
82
+ };
83
+ }
84
+ function instantiate(module) {
85
+ return bind(instanceOf(module));
86
+ }
87
+
88
+ // ../../mapper/js/node.js
89
+ function mapperModule() {
90
+ return compile(new URL("./vds_mapper.wasm", import.meta.url), "pnpm --filter @vds/mapper build");
91
+ }
92
+ function loadMapper() {
93
+ return instantiate(mapperModule());
94
+ }
95
+
96
+ // src/bin.js
97
+ var FOLDERS = ["capabilities", "flows", "scenarios"];
98
+ function readWorkspace(root) {
99
+ const files = {};
100
+ for (const dir of FOLDERS) {
101
+ let names = [];
102
+ try {
103
+ names = readdirSync(join(root, dir));
104
+ } catch {
105
+ continue;
106
+ }
107
+ for (const name of names) files[`${dir}/${name}`] = readFileSync2(join(root, dir, name), "utf8");
108
+ }
109
+ return files;
110
+ }
111
+ async function main([command, folder = "."]) {
112
+ const mapper = await loadMapper();
113
+ const files = readWorkspace(resolve(folder));
114
+ if (command === "check") {
115
+ const findings = mapper.v2Check(files);
116
+ if ("error" in findings) throw new Error(findings.error);
117
+ if (findings.length === 0) {
118
+ console.log("valid");
119
+ return 0;
120
+ }
121
+ console.error(`${findings.length} problem(s):`);
122
+ for (const f of findings) console.error(`- ${f.path}: ${f.message} [${f.code}]`);
123
+ return 1;
124
+ }
125
+ if (command === "index") {
126
+ process.stdout.write(mapper.v2Index(files));
127
+ return 0;
128
+ }
129
+ console.error("usage: vds check [folder] | vds index [folder]");
130
+ return 2;
131
+ }
132
+ process.exitCode = await main(process.argv.slice(2));
Binary file
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@teurons/vds",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "description": "The vds command: check, index and run a VDS workspace on your machine.",
5
+ "type": "module",
6
+ "bin": {
7
+ "vds": "dist/vds.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "engines": {
13
+ "node": ">=20"
14
+ },
15
+ "scripts": {
16
+ "build": "node build.mjs",
17
+ "test": "vitest run",
18
+ "prepack": "node build.mjs",
19
+ "release": "node release.mjs"
20
+ },
21
+ "dependencies": {},
22
+ "devDependencies": {
23
+ "@vds/mapper": "workspace:*",
24
+ "esbuild": "0.28.1",
25
+ "vitest": "5.0.1"
26
+ },
27
+ "license": "UNLICENSED",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/teurons/vds.git"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public",
34
+ "tag": "next"
35
+ }
36
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.