@sjunepark/fs 0.1.0
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/LICENSE +202 -0
- package/README.md +73 -0
- package/assets/guide/authoring.md +125 -0
- package/dist/application.js +34 -0
- package/dist/application.js.map +1 -0
- package/dist/assets.js +20 -0
- package/dist/assets.js.map +1 -0
- package/dist/bin.js +9 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.js +150 -0
- package/dist/cli.js.map +1 -0
- package/dist/content.js +47 -0
- package/dist/content.js.map +1 -0
- package/dist/io.js +76 -0
- package/dist/io.js.map +1 -0
- package/dist/json.js +291 -0
- package/dist/json.js.map +1 -0
- package/dist/limits.js +15 -0
- package/dist/limits.js.map +1 -0
- package/dist/logger.js +26 -0
- package/dist/logger.js.map +1 -0
- package/dist/node-services.js +9 -0
- package/dist/node-services.js.map +1 -0
- package/dist/pathless.js +72 -0
- package/dist/pathless.js.map +1 -0
- package/dist/process.js +317 -0
- package/dist/process.js.map +1 -0
- package/dist/record-validation.js +44 -0
- package/dist/record-validation.js.map +1 -0
- package/dist/render.js +250 -0
- package/dist/render.js.map +1 -0
- package/dist/validation/calculate.js +102 -0
- package/dist/validation/calculate.js.map +1 -0
- package/dist/validation/decimal.js +63 -0
- package/dist/validation/decimal.js.map +1 -0
- package/dist/validation/identity.js +4 -0
- package/dist/validation/identity.js.map +1 -0
- package/dist/validation/model.js +10 -0
- package/dist/validation/model.js.map +1 -0
- package/dist/validation/schema.js +106 -0
- package/dist/validation/schema.js.map +1 -0
- package/dist/validation/semantic.js +179 -0
- package/dist/validation/semantic.js.map +1 -0
- package/dist/validation/snapshot.js +74 -0
- package/dist/validation/snapshot.js.map +1 -0
- package/dist/validation/validate.js +154 -0
- package/dist/validation/validate.js.map +1 -0
- package/dist/writer.js +107 -0
- package/dist/writer.js.map +1 -0
- package/examples/README.md +37 -0
- package/examples/manufacturing-group.json +439 -0
- package/examples/minimal.json +45 -0
- package/package.json +80 -0
- package/schema/fs-document.schema.json +335 -0
- package/schema/snapshot-diff.schema.json +96 -0
- package/schema/validation-result.schema.json +165 -0
package/dist/content.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Effect, Result } from "effect";
|
|
2
|
+
import { isAbsolute, resolve } from "node:path";
|
|
3
|
+
import { exampleAsset, schemaAsset } from "./assets.js";
|
|
4
|
+
import { ApplicationIO } from "./io.js";
|
|
5
|
+
const suggestion = (...arguments_) => ({
|
|
6
|
+
executable: "fs",
|
|
7
|
+
arguments: arguments_
|
|
8
|
+
});
|
|
9
|
+
const result = (value, exitCode) => ({
|
|
10
|
+
stdout: Buffer.from(`${JSON.stringify(value)}\n`, "utf8"),
|
|
11
|
+
stderr: Buffer.alloc(0),
|
|
12
|
+
exitCode
|
|
13
|
+
});
|
|
14
|
+
const failure = (operation, code, help, path, message = "The requested operation could not be completed.") => result({
|
|
15
|
+
error: { operation, code, message, ...(path === undefined ? {} : { path }) },
|
|
16
|
+
help
|
|
17
|
+
}, 1);
|
|
18
|
+
const run = (request) => Effect.gen(function* () {
|
|
19
|
+
const io = yield* ApplicationIO;
|
|
20
|
+
const output = "output" in request ? request.output : undefined;
|
|
21
|
+
if (output === undefined || (request.command === "example" && request.name === null)) {
|
|
22
|
+
throw new Error("Pathless content request escaped the CLI edge");
|
|
23
|
+
}
|
|
24
|
+
const destinationResult = yield* Effect.result(isAbsolute(output)
|
|
25
|
+
? Effect.succeed(output)
|
|
26
|
+
: io.cwd.pipe(Effect.map((cwd) => resolve(cwd, output))));
|
|
27
|
+
if (Result.isFailure(destinationResult)) {
|
|
28
|
+
return failure(request.command, "working-directory-unavailable", [], undefined, "The current working directory is unavailable.");
|
|
29
|
+
}
|
|
30
|
+
const bytes = request.command === "schema"
|
|
31
|
+
? schemaAsset(request.name)
|
|
32
|
+
: exampleAsset(request.name);
|
|
33
|
+
const help = request.command === "schema"
|
|
34
|
+
? [suggestion("schema", "--output", "<new-path>", request.name)]
|
|
35
|
+
: [suggestion("example", "--output", "<new-path>", request.name)];
|
|
36
|
+
const written = yield* Effect.result(io.writeFile(destinationResult.success, bytes));
|
|
37
|
+
if (Result.isFailure(written)) {
|
|
38
|
+
return failure(request.command, "write-failed", help, output);
|
|
39
|
+
}
|
|
40
|
+
if (written.success !== null) {
|
|
41
|
+
return failure(request.command, written.success, help, output);
|
|
42
|
+
}
|
|
43
|
+
return result({ output: { status: "created", path: output } }, 0);
|
|
44
|
+
});
|
|
45
|
+
export const executeContentWithIO = (request) => run(request).pipe(Effect.catchDefect(() => Effect.succeed(failure(request.command, "internal-error", []))));
|
|
46
|
+
export const executeContent = (request) => run(request).pipe(Effect.provide(ApplicationIO.live), Effect.catchDefect(() => Effect.succeed(failure(request.command, "internal-error", []))));
|
|
47
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAG/C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAOvC,MAAM,UAAU,GAAG,CAAC,GAAG,UAAiC,EAAqB,EAAE,CAAC,CAAC;IAC/E,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,UAAU;CACtB,CAAC,CAAA;AAEF,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,QAAe,EAAiB,EAAE,CAAC,CAAC;IAClE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC;IACzD,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACvB,QAAQ;CACT,CAAC,CAA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AW,CAAC,GAAG,EAAE,CACtB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,CAAC,CAAC,CAC/D,CACF,CAAA;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,OAA4B,EACE,EAAE,CAChC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CACf,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,EAClC,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,CACtB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,CAAC,CAAC,CAC/D,CACF,CAAA"}
|
package/dist/io.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Context, Data, Effect, Layer, Stdio, Stream } from "effect";
|
|
2
|
+
import { closeSync, openSync, readSync } from "node:fs";
|
|
3
|
+
import { inputLimits } from "./limits.js";
|
|
4
|
+
import { outputEntryExists, writeNewFile } from "./writer.js";
|
|
5
|
+
export class ApplicationIOError extends Data.TaggedError("ApplicationIOError") {
|
|
6
|
+
}
|
|
7
|
+
const dependencyError = (operation, error) => {
|
|
8
|
+
if (error instanceof ApplicationIOError)
|
|
9
|
+
return error;
|
|
10
|
+
const code = typeof error === "object" &&
|
|
11
|
+
error !== null &&
|
|
12
|
+
"code" in error &&
|
|
13
|
+
typeof error.code === "string"
|
|
14
|
+
? error.code
|
|
15
|
+
: undefined;
|
|
16
|
+
return new ApplicationIOError({ operation, ...(code === undefined ? {} : { code }) });
|
|
17
|
+
};
|
|
18
|
+
const byteLimitError = (operation) => new ApplicationIOError({
|
|
19
|
+
operation,
|
|
20
|
+
budget: "input-bytes",
|
|
21
|
+
limit: inputLimits.bytes
|
|
22
|
+
});
|
|
23
|
+
const readBoundedFile = (path) => {
|
|
24
|
+
const descriptor = openSync(path, "r");
|
|
25
|
+
const chunks = [];
|
|
26
|
+
let total = 0;
|
|
27
|
+
try {
|
|
28
|
+
while (true) {
|
|
29
|
+
const capacity = Math.min(65_536, inputLimits.bytes - total + 1);
|
|
30
|
+
const chunk = Buffer.allocUnsafe(capacity);
|
|
31
|
+
const count = readSync(descriptor, chunk, 0, capacity, null);
|
|
32
|
+
if (count === 0)
|
|
33
|
+
return Buffer.concat(chunks, total);
|
|
34
|
+
total += count;
|
|
35
|
+
if (total > inputLimits.bytes)
|
|
36
|
+
throw byteLimitError("read-file");
|
|
37
|
+
chunks.push(Buffer.from(chunk.subarray(0, count)));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
closeSync(descriptor);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const readStdin = Effect.gen(function* () {
|
|
45
|
+
const stdio = yield* Stdio.Stdio;
|
|
46
|
+
return yield* Stream.runFoldEffect(stdio.stdin, () => ({ chunks: [], total: 0 }), (state, bytes) => {
|
|
47
|
+
const chunk = Buffer.from(bytes);
|
|
48
|
+
const total = state.total + chunk.length;
|
|
49
|
+
if (total > inputLimits.bytes)
|
|
50
|
+
return Effect.fail(byteLimitError("read-stdin"));
|
|
51
|
+
state.chunks.push(chunk);
|
|
52
|
+
return Effect.succeed({ chunks: state.chunks, total });
|
|
53
|
+
}).pipe(Effect.map(({ chunks, total }) => Buffer.concat(chunks, total)), Effect.mapError((error) => dependencyError("read-stdin", error)));
|
|
54
|
+
});
|
|
55
|
+
export class ApplicationIO extends Context.Service()("@sjunepark/fs/ApplicationIO") {
|
|
56
|
+
static live = Layer.succeed(ApplicationIO, {
|
|
57
|
+
cwd: Effect.try({
|
|
58
|
+
try: () => process.cwd(),
|
|
59
|
+
catch: (error) => dependencyError("working-directory", error)
|
|
60
|
+
}),
|
|
61
|
+
readFile: (path) => Effect.try({
|
|
62
|
+
try: () => readBoundedFile(path),
|
|
63
|
+
catch: (error) => dependencyError("read-file", error)
|
|
64
|
+
}),
|
|
65
|
+
readStdin,
|
|
66
|
+
outputExists: (path) => Effect.try({
|
|
67
|
+
try: () => outputEntryExists(path),
|
|
68
|
+
catch: (error) => dependencyError("output-exists", error)
|
|
69
|
+
}),
|
|
70
|
+
writeFile: (path, contents) => Effect.try({
|
|
71
|
+
try: () => writeNewFile(path, contents),
|
|
72
|
+
catch: (error) => dependencyError("write-file", error)
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=io.js.map
|
package/dist/io.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.js","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAoB7D,MAAM,OAAO,kBAAmB,SAAQ,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAK3E;CAAG;AAEL,MAAM,eAAe,GAAG,CACtB,SAAiC,EACjC,KAAc,EACM,EAAE;IACtB,IAAI,KAAK,YAAY,kBAAkB;QAAE,OAAO,KAAK,CAAA;IACrD,MAAM,IAAI,GACR,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC5B,CAAC,CAAC,KAAK,CAAC,IAAI;QACZ,CAAC,CAAC,SAAS,CAAA;IACf,OAAO,IAAI,kBAAkB,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,E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AE;YACxB,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,mBAAmB,EAAE,KAAK,CAAC;SAC9D,CAAC;QACF,QAAQ,EAAE,CAAC,IAAY,EAAE,EAAE,CACzB,MAAM,CAAC,GAAG,CAAC;YACT,GAAG,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC;YAChC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,WAAW,EAAE,KAAK,CAAC;SACtD,CAAC;QACJ,SAAS;QACT,YAAY,EAAE,CAAC,IAAY,EAAE,EAAE,CAC7B,MAAM,CAAC,GAAG,CAAC;YACT,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC;YAClC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,eAAe,EAAE,KAAK,CAAC;SAC1D,CAAC;QACJ,SAAS,EAAE,CAAC,IAAY,EAAE,QAAgB,EAAE,EAAE,CAC5C,MAAM,CAAC,GAAG,CAAC;YACT,GAAG,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC;YACvC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,YAAY,EAAE,KAAK,CAAC;SACvD,CAAC;KACL,CAAC,CAAA"}
|
package/dist/json.js
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { inputLimitFailure, inputLimits } from "./limits.js";
|
|
2
|
+
const maximumBoundaryInteger = "9007199254740992";
|
|
3
|
+
class OwnedJsonError extends Error {
|
|
4
|
+
}
|
|
5
|
+
class JsonLimitError extends Error {
|
|
6
|
+
failure;
|
|
7
|
+
constructor(failure) {
|
|
8
|
+
super(failure.message);
|
|
9
|
+
this.failure = failure;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const owned = (message) => {
|
|
13
|
+
throw new OwnedJsonError(message);
|
|
14
|
+
};
|
|
15
|
+
const integerMagnitudeWithinBoundary = (lexeme) => {
|
|
16
|
+
const match = /^-?(\d+)(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/u.exec(lexeme);
|
|
17
|
+
if (match === null)
|
|
18
|
+
return false;
|
|
19
|
+
const whole = match[1] ?? "";
|
|
20
|
+
const fraction = match[2] ?? "";
|
|
21
|
+
const digits = `${whole}${fraction}`;
|
|
22
|
+
if (!/[1-9]/u.test(digits))
|
|
23
|
+
return true;
|
|
24
|
+
const exponentLexeme = match[3] ?? "0";
|
|
25
|
+
const exponentNegative = exponentLexeme.startsWith("-");
|
|
26
|
+
const exponentDigits = exponentLexeme.replace(/^[+-]?0*/u, "") || "0";
|
|
27
|
+
if (exponentDigits.length > 6)
|
|
28
|
+
return false;
|
|
29
|
+
const exponentMagnitude = Number(exponentDigits);
|
|
30
|
+
if (!Number.isSafeInteger(exponentMagnitude))
|
|
31
|
+
return false;
|
|
32
|
+
const exponent = exponentNegative ? -exponentMagnitude : exponentMagnitude;
|
|
33
|
+
const decimalIndex = whole.length + exponent;
|
|
34
|
+
if (decimalIndex <= 0 || /[1-9]/u.test(digits.slice(decimalIndex)))
|
|
35
|
+
return false;
|
|
36
|
+
const integerPrefix = digits.slice(0, Math.min(decimalIndex, digits.length)).replace(/^0+/u, "");
|
|
37
|
+
const trailingZeros = Math.max(0, decimalIndex - digits.length);
|
|
38
|
+
const magnitudeLength = integerPrefix.length + trailingZeros;
|
|
39
|
+
if (magnitudeLength !== maximumBoundaryInteger.length) {
|
|
40
|
+
return magnitudeLength < maximumBoundaryInteger.length;
|
|
41
|
+
}
|
|
42
|
+
const magnitude = `${integerPrefix}${"0".repeat(trailingZeros)}`;
|
|
43
|
+
return magnitude <= maximumBoundaryInteger;
|
|
44
|
+
};
|
|
45
|
+
class JsonScanner {
|
|
46
|
+
text;
|
|
47
|
+
index = 0;
|
|
48
|
+
values = 0;
|
|
49
|
+
rootComplete = false;
|
|
50
|
+
stack = [];
|
|
51
|
+
constructor(text) {
|
|
52
|
+
this.text = text;
|
|
53
|
+
}
|
|
54
|
+
scan() {
|
|
55
|
+
this.whitespace();
|
|
56
|
+
this.value();
|
|
57
|
+
while (!this.rootComplete) {
|
|
58
|
+
const frame = this.stack.at(-1);
|
|
59
|
+
if (frame === undefined)
|
|
60
|
+
throw new OwnedJsonError("JSON contains invalid syntax.");
|
|
61
|
+
if (frame.kind === "object")
|
|
62
|
+
this.objectStep(frame);
|
|
63
|
+
else
|
|
64
|
+
this.arrayStep(frame);
|
|
65
|
+
}
|
|
66
|
+
this.whitespace();
|
|
67
|
+
if (this.index !== this.text.length)
|
|
68
|
+
owned("JSON contains trailing content.");
|
|
69
|
+
return this.values;
|
|
70
|
+
}
|
|
71
|
+
whitespace() {
|
|
72
|
+
while (/^[\t\n\r ]$/u.test(this.text[this.index] ?? ""))
|
|
73
|
+
this.index += 1;
|
|
74
|
+
}
|
|
75
|
+
completePrimitive() {
|
|
76
|
+
if (this.stack.length === 0)
|
|
77
|
+
this.rootComplete = true;
|
|
78
|
+
}
|
|
79
|
+
closeContainer() {
|
|
80
|
+
this.stack.pop();
|
|
81
|
+
if (this.stack.length === 0)
|
|
82
|
+
this.rootComplete = true;
|
|
83
|
+
}
|
|
84
|
+
countValue() {
|
|
85
|
+
this.values += 1;
|
|
86
|
+
if (this.values > inputLimits.jsonValues) {
|
|
87
|
+
throw new JsonLimitError(inputLimitFailure("json-values", inputLimits.jsonValues));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
value() {
|
|
91
|
+
const character = this.text[this.index];
|
|
92
|
+
if (character === "{" || character === "[") {
|
|
93
|
+
this.countValue();
|
|
94
|
+
if (this.stack.length + 1 > inputLimits.jsonNesting) {
|
|
95
|
+
throw new JsonLimitError(inputLimitFailure("json-nesting", inputLimits.jsonNesting));
|
|
96
|
+
}
|
|
97
|
+
this.index += 1;
|
|
98
|
+
this.stack.push(character === "{"
|
|
99
|
+
? { kind: "object", state: "first-key-or-end", members: new Set() }
|
|
100
|
+
: { kind: "array", state: "first-value-or-end" });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (character === '"') {
|
|
104
|
+
this.countValue();
|
|
105
|
+
this.string();
|
|
106
|
+
this.completePrimitive();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
for (const literal of ["true", "false", "null"]) {
|
|
110
|
+
if (this.text.startsWith(literal, this.index)) {
|
|
111
|
+
this.countValue();
|
|
112
|
+
this.index += literal.length;
|
|
113
|
+
this.completePrimitive();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const end = this.numberEnd();
|
|
118
|
+
if (end === this.index)
|
|
119
|
+
owned("JSON contains invalid syntax.");
|
|
120
|
+
this.countValue();
|
|
121
|
+
this.number(this.text.slice(this.index, end));
|
|
122
|
+
this.index = end;
|
|
123
|
+
this.completePrimitive();
|
|
124
|
+
}
|
|
125
|
+
numberEnd() {
|
|
126
|
+
let cursor = this.index;
|
|
127
|
+
if (this.text[cursor] === "-")
|
|
128
|
+
cursor += 1;
|
|
129
|
+
if (this.text[cursor] === "0") {
|
|
130
|
+
cursor += 1;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const first = this.text[cursor];
|
|
134
|
+
if (first === undefined || first < "1" || first > "9")
|
|
135
|
+
return this.index;
|
|
136
|
+
while (/^\d$/u.test(this.text[cursor] ?? ""))
|
|
137
|
+
cursor += 1;
|
|
138
|
+
}
|
|
139
|
+
if (this.text[cursor] === ".") {
|
|
140
|
+
cursor += 1;
|
|
141
|
+
const start = cursor;
|
|
142
|
+
while (/^\d$/u.test(this.text[cursor] ?? ""))
|
|
143
|
+
cursor += 1;
|
|
144
|
+
if (cursor === start)
|
|
145
|
+
owned("JSON contains invalid syntax.");
|
|
146
|
+
}
|
|
147
|
+
if (this.text[cursor] === "e" || this.text[cursor] === "E") {
|
|
148
|
+
cursor += 1;
|
|
149
|
+
if (this.text[cursor] === "+" || this.text[cursor] === "-")
|
|
150
|
+
cursor += 1;
|
|
151
|
+
const start = cursor;
|
|
152
|
+
while (/^\d$/u.test(this.text[cursor] ?? ""))
|
|
153
|
+
cursor += 1;
|
|
154
|
+
if (cursor === start)
|
|
155
|
+
owned("JSON contains invalid syntax.");
|
|
156
|
+
}
|
|
157
|
+
return cursor;
|
|
158
|
+
}
|
|
159
|
+
number(lexeme) {
|
|
160
|
+
const numeric = Number(lexeme);
|
|
161
|
+
if (!Number.isFinite(numeric))
|
|
162
|
+
owned("JSON number is outside the supported finite range.");
|
|
163
|
+
if (Number.isInteger(numeric) && !integerMagnitudeWithinBoundary(lexeme)) {
|
|
164
|
+
owned("JSON number cannot be represented without precision loss.");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
string() {
|
|
168
|
+
const start = this.index;
|
|
169
|
+
this.index += 1;
|
|
170
|
+
while (this.index < this.text.length) {
|
|
171
|
+
const character = this.text[this.index];
|
|
172
|
+
if (character === '"') {
|
|
173
|
+
this.index += 1;
|
|
174
|
+
try {
|
|
175
|
+
return JSON.parse(this.text.slice(start, this.index));
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
if (error instanceof SyntaxError)
|
|
179
|
+
owned("JSON contains an invalid string.");
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (character === "\\") {
|
|
184
|
+
this.index += 1;
|
|
185
|
+
const escape = this.text[this.index];
|
|
186
|
+
if (escape === "u") {
|
|
187
|
+
const digits = this.text.slice(this.index + 1, this.index + 5);
|
|
188
|
+
if (!/^[0-9A-Fa-f]{4}$/u.test(digits))
|
|
189
|
+
owned("JSON contains an invalid escape.");
|
|
190
|
+
this.index += 5;
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (!['"', "\\", "/", "b", "f", "n", "r", "t"].includes(escape ?? "")) {
|
|
194
|
+
owned("JSON contains an invalid escape.");
|
|
195
|
+
}
|
|
196
|
+
this.index += 1;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (character === undefined || character.charCodeAt(0) < 0x20) {
|
|
200
|
+
owned("JSON contains an invalid string.");
|
|
201
|
+
}
|
|
202
|
+
this.index += 1;
|
|
203
|
+
}
|
|
204
|
+
throw new OwnedJsonError("JSON contains an unterminated string.");
|
|
205
|
+
}
|
|
206
|
+
objectStep(frame) {
|
|
207
|
+
this.whitespace();
|
|
208
|
+
if (frame.state === "comma-or-end") {
|
|
209
|
+
if (this.text[this.index] === "}") {
|
|
210
|
+
this.index += 1;
|
|
211
|
+
this.closeContainer();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (this.text[this.index] !== ",")
|
|
215
|
+
owned("JSON object members are not separated.");
|
|
216
|
+
this.index += 1;
|
|
217
|
+
frame.state = "key";
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (frame.state === "first-key-or-end" && this.text[this.index] === "}") {
|
|
221
|
+
this.index += 1;
|
|
222
|
+
this.closeContainer();
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (this.text[this.index] !== '"')
|
|
226
|
+
owned("JSON object key is not a string.");
|
|
227
|
+
const member = this.string();
|
|
228
|
+
if (frame.members.has(member))
|
|
229
|
+
owned("JSON object contains a duplicate member.");
|
|
230
|
+
frame.members.add(member);
|
|
231
|
+
this.whitespace();
|
|
232
|
+
if (this.text[this.index] !== ":")
|
|
233
|
+
owned("JSON object member lacks a colon.");
|
|
234
|
+
this.index += 1;
|
|
235
|
+
this.whitespace();
|
|
236
|
+
frame.state = "comma-or-end";
|
|
237
|
+
this.value();
|
|
238
|
+
}
|
|
239
|
+
arrayStep(frame) {
|
|
240
|
+
this.whitespace();
|
|
241
|
+
if (frame.state === "comma-or-end") {
|
|
242
|
+
if (this.text[this.index] === "]") {
|
|
243
|
+
this.index += 1;
|
|
244
|
+
this.closeContainer();
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (this.text[this.index] !== ",")
|
|
248
|
+
owned("JSON array values are not separated.");
|
|
249
|
+
this.index += 1;
|
|
250
|
+
frame.state = "value";
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (frame.state === "first-value-or-end" && this.text[this.index] === "]") {
|
|
254
|
+
this.index += 1;
|
|
255
|
+
this.closeContainer();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
frame.state = "comma-or-end";
|
|
259
|
+
this.value();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
export const decodeJson = (bytes) => {
|
|
263
|
+
let text;
|
|
264
|
+
try {
|
|
265
|
+
text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
if (error instanceof TypeError) {
|
|
269
|
+
return { ok: false, kind: "invalid-json", message: "Input is not valid UTF-8." };
|
|
270
|
+
}
|
|
271
|
+
throw error;
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
const values = new JsonScanner(text).scan();
|
|
275
|
+
return { ok: true, value: JSON.parse(text), values };
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
if (error instanceof JsonLimitError) {
|
|
279
|
+
return { ok: false, kind: "input-limit", ...error.failure };
|
|
280
|
+
}
|
|
281
|
+
if (error instanceof OwnedJsonError || error instanceof SyntaxError) {
|
|
282
|
+
return {
|
|
283
|
+
ok: false,
|
|
284
|
+
kind: "invalid-json",
|
|
285
|
+
message: error.message.length > 0 ? error.message : "Input is not valid JSON."
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
//# sourceMappingURL=json.js.map
|
package/dist/json.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAA0B,MAAM,aAAa,CAAA;AAOpF,MAAM,sBAAsB,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16_777_216,
|
|
3
|
+
jsonNesting: 64,
|
|
4
|
+
jsonValues: 200_000,
|
|
5
|
+
invalidDocumentValues: 256,
|
|
6
|
+
validationDiagnosticBytes: 1_048_576,
|
|
7
|
+
decimalDigits: 1_000,
|
|
8
|
+
totalDecimalDigits: 1_000_000
|
|
9
|
+
};
|
|
10
|
+
export const inputLimitFailure = (budget, limit) => ({
|
|
11
|
+
budget,
|
|
12
|
+
limit,
|
|
13
|
+
message: `Input exceeds the ${budget} budget of ${limit}.`
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.js","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,UAAU;IACjB,WAAW,EAAE,EAAE;IACf,UAAU,EAAE,OAAO;IACnB,qBAAqB,EAAE,GAAG;IAC1B,yBAAyB,EAAE,SAAS;IACpC,aAAa,EAAE,KAAK;IACpB,kBAAkB,EAAE,SAAS;CACrB,CAAA;AAiBV,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAmB,EACnB,KAAa,EACM,EAAE,CAAC,CAAC;IACvB,MAAM;IACN,KAAK;IACL,OAAO,EAAE,qBAAqB,MAAM,cAAc,KAAK,GAAG;CAC3D,CAAC,CAAA"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const ranks = {
|
|
2
|
+
trace: 0,
|
|
3
|
+
debug: 1,
|
|
4
|
+
info: 2,
|
|
5
|
+
warn: 3,
|
|
6
|
+
error: 4,
|
|
7
|
+
fatal: 5
|
|
8
|
+
};
|
|
9
|
+
export class DiagnosticLogger {
|
|
10
|
+
threshold;
|
|
11
|
+
records = [];
|
|
12
|
+
constructor(threshold) {
|
|
13
|
+
this.threshold = threshold;
|
|
14
|
+
}
|
|
15
|
+
emit(level, event, operation, context) {
|
|
16
|
+
if (this.threshold === "none" || ranks[level] < ranks[this.threshold])
|
|
17
|
+
return;
|
|
18
|
+
this.records.push({ level, event, operation, ...context });
|
|
19
|
+
}
|
|
20
|
+
bytes() {
|
|
21
|
+
return this.records.length === 0
|
|
22
|
+
? Buffer.alloc(0)
|
|
23
|
+
: Buffer.from(`${this.records.map((record) => JSON.stringify(record)).join("\n")}\n`, "utf8");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAIA,MAAM,KAAK,GAA2C;IACpD,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;CACT,CAAA;AAED,MAAM,OAAO,gBAAgB;IAGE;IAFZ,OAAO,GAAqD,EAAE,CAAA;IAE/E,YAA6B,SAAmB;QAAnB,cAAS,GAAT,SAAS,CAAU;IAAG,CAAC;IAEpD,IAAI,CAAC,KAAmB,EAAE,KAAa,EAAE,SAAiB,EAAE,OAAkD;QAC5G,IAAI,IAAI,CAAC,SAAS,KAAK,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;YAAE,OAAM;QAC7E,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;IAC5D,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;YAC9B,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACjB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACjG,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as NodeChildProcessSpawner from "@effect/platform-node-shared/NodeChildProcessSpawner";
|
|
2
|
+
import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem";
|
|
3
|
+
import * as NodePath from "@effect/platform-node-shared/NodePath";
|
|
4
|
+
import * as NodeStdio from "@effect/platform-node-shared/NodeStdio";
|
|
5
|
+
import * as NodeTerminal from "@effect/platform-node-shared/NodeTerminal";
|
|
6
|
+
import { Layer } from "effect";
|
|
7
|
+
const baseServices = Layer.mergeAll(NodeFileSystem.layer, NodePath.layer, NodeStdio.layer, NodeTerminal.layer);
|
|
8
|
+
export const nodeServices = NodeChildProcessSpawner.layer.pipe(Layer.provideMerge(baseServices));
|
|
9
|
+
//# sourceMappingURL=node-services.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-services.js","sourceRoot":"","sources":["../src/node-services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,uBAAuB,MAAM,sDAAsD,CAAA;AAC/F,OAAO,KAAK,cAAc,MAAM,6CAA6C,CAAA;AAC7E,OAAO,KAAK,QAAQ,MAAM,uCAAuC,CAAA;AACjE,OAAO,KAAK,SAAS,MAAM,wCAAwC,CAAA;AACnE,OAAO,KAAK,YAAY,MAAM,2CAA2C,CAAA;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAE9B,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CACjC,cAAc,CAAC,KAAK,EACpB,QAAQ,CAAC,KAAK,EACd,SAAS,CAAC,KAAK,EACf,YAAY,CAAC,KAAK,CACnB,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,uBAAuB,CAAC,KAAK,CAAC,IAAI,CAC5D,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CACjC,CAAA"}
|
package/dist/pathless.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { authoringGuide, exampleAsset, schemaAsset } from "./assets.js";
|
|
2
|
+
const commandSuggestion = (...arguments_) => ({
|
|
3
|
+
executable: "fs",
|
|
4
|
+
arguments: arguments_
|
|
5
|
+
});
|
|
6
|
+
const empty = Buffer.alloc(0);
|
|
7
|
+
const jsonResult = (value) => ({
|
|
8
|
+
stdout: Buffer.from(`${JSON.stringify(value)}\n`, "utf8"),
|
|
9
|
+
stderr: empty,
|
|
10
|
+
exitCode: 0
|
|
11
|
+
});
|
|
12
|
+
const bytesResult = (stdout) => ({ stdout, stderr: empty, exitCode: 0 });
|
|
13
|
+
const discovery = {
|
|
14
|
+
executable: "fs",
|
|
15
|
+
package: "@sjunepark/fs",
|
|
16
|
+
input: null,
|
|
17
|
+
artifact: {
|
|
18
|
+
versions: ["0.1"],
|
|
19
|
+
serializations: ["json"]
|
|
20
|
+
},
|
|
21
|
+
commands: [
|
|
22
|
+
{ name: "guide", access: "read" },
|
|
23
|
+
{ name: "schema", access: "read-write" },
|
|
24
|
+
{ name: "example", access: "read-write" },
|
|
25
|
+
{ name: "validate", access: "read" },
|
|
26
|
+
{ name: "create", access: "write" },
|
|
27
|
+
{ name: "record-validation", access: "write" },
|
|
28
|
+
{ name: "render", access: "write" }
|
|
29
|
+
],
|
|
30
|
+
help: [
|
|
31
|
+
commandSuggestion("guide", "authoring"),
|
|
32
|
+
commandSuggestion("schema", "document"),
|
|
33
|
+
commandSuggestion("example"),
|
|
34
|
+
commandSuggestion("validate", "<document|->"),
|
|
35
|
+
commandSuggestion("render", "--output", "<new-html>", "<document|->")
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
const examples = {
|
|
39
|
+
examples: [
|
|
40
|
+
{
|
|
41
|
+
name: "minimal",
|
|
42
|
+
purpose: "Smallest complete document with no rollups.",
|
|
43
|
+
calculationStatus: "not-defined"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "manufacturing-group",
|
|
47
|
+
purpose: "Representative multi-statement document with a deliberate rollup inconsistency.",
|
|
48
|
+
calculationStatus: "inconsistent"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
help: [commandSuggestion("example", "minimal"), commandSuggestion("example", "manufacturing-group")]
|
|
52
|
+
};
|
|
53
|
+
export const runPathless = (request) => {
|
|
54
|
+
switch (request.command) {
|
|
55
|
+
case "fs":
|
|
56
|
+
return jsonResult(discovery);
|
|
57
|
+
case "guide":
|
|
58
|
+
return bytesResult(authoringGuide());
|
|
59
|
+
case "schema":
|
|
60
|
+
return request.output === undefined ? bytesResult(schemaAsset(request.name)) : undefined;
|
|
61
|
+
case "example":
|
|
62
|
+
if (request.name === null)
|
|
63
|
+
return jsonResult(examples);
|
|
64
|
+
return request.output === undefined ? bytesResult(exampleAsset(request.name)) : undefined;
|
|
65
|
+
case "validate":
|
|
66
|
+
case "create":
|
|
67
|
+
case "record-validation":
|
|
68
|
+
case "render":
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=pathless.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathless.js","sourceRoot":"","sources":["../src/pathless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAQvE,MAAM,iBAAiB,GAAG,CAAC,GAAG,UAAiC,EAAqB,EAAE,CAAC,CAAC;IACtF,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,UAAU;CACtB,CAAC,CAAA;AAEF,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAE7B,MAAM,UAAU,GAAG,CAAC,KAAc,EAAiB,EAAE,CAAC,CAAC;IACrD,MAAM,EAAE,MAAM,CAAC,IAA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