@fluidgrids/workflows 0.0.0-stage → 2026.1027.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.
Files changed (60) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +208 -2
  3. package/dist/assemble-CrpUyd_3.d.ts +587 -0
  4. package/dist/assemble-DEf3znGD.d.cts +587 -0
  5. package/dist/chunk-3M34AUIY.cjs +27 -0
  6. package/dist/chunk-5AW745OG.js +25 -0
  7. package/dist/chunk-5LUIDMF4.js +42 -0
  8. package/dist/chunk-6AIAC2FP.cjs +185 -0
  9. package/dist/chunk-6BEW4QD6.js +95 -0
  10. package/dist/chunk-6U446SKY.js +263 -0
  11. package/dist/chunk-7YR7DI7B.cjs +274 -0
  12. package/dist/chunk-CSYBNN3V.cjs +252 -0
  13. package/dist/chunk-E3APHA6O.cjs +199 -0
  14. package/dist/chunk-EEAIM35V.js +748 -0
  15. package/dist/chunk-G4UEPUGO.cjs +46 -0
  16. package/dist/chunk-IHKXLG6I.js +246 -0
  17. package/dist/chunk-MBBKGD7K.js +440 -0
  18. package/dist/chunk-OSPTJCDI.cjs +102 -0
  19. package/dist/chunk-TQF7MYEN.cjs +771 -0
  20. package/dist/chunk-TWOYB4Y7.cjs +76 -0
  21. package/dist/chunk-UB2BHU2M.js +174 -0
  22. package/dist/chunk-UJNHTS6D.js +181 -0
  23. package/dist/chunk-UWQWD7BP.cjs +931 -0
  24. package/dist/chunk-W32BSO3M.js +74 -0
  25. package/dist/chunk-XBIID5DY.js +893 -0
  26. package/dist/chunk-Y7NWR3WH.cjs +450 -0
  27. package/dist/codegen/index.cjs +18 -0
  28. package/dist/codegen/index.d.cts +15 -0
  29. package/dist/codegen/index.d.ts +15 -0
  30. package/dist/codegen/index.js +5 -0
  31. package/dist/expressions-DhHaqyar.d.cts +62 -0
  32. package/dist/expressions-DhHaqyar.d.ts +62 -0
  33. package/dist/hash-CZkTXPCX.d.cts +15 -0
  34. package/dist/hash-CZkTXPCX.d.ts +15 -0
  35. package/dist/index.cjs +117 -0
  36. package/dist/index.d.cts +27 -0
  37. package/dist/index.d.ts +27 -0
  38. package/dist/index.js +4 -0
  39. package/dist/ir/index.cjs +1246 -0
  40. package/dist/ir/index.d.cts +838 -0
  41. package/dist/ir/index.d.ts +838 -0
  42. package/dist/ir/index.js +1122 -0
  43. package/dist/lower-CXggJTIo.d.ts +67 -0
  44. package/dist/lower-DAzvsJCo.d.cts +67 -0
  45. package/dist/manifest-Bp9ZJlav.d.ts +60 -0
  46. package/dist/manifest-Duf-gHdO.d.cts +60 -0
  47. package/dist/node-evaluator-CH3XCJND.cjs +17 -0
  48. package/dist/node-evaluator-TULXA3WE.js +8 -0
  49. package/dist/quickjs/index.cjs +46 -0
  50. package/dist/quickjs/index.d.cts +18 -0
  51. package/dist/quickjs/index.d.ts +18 -0
  52. package/dist/quickjs/index.js +44 -0
  53. package/dist/roundtrip/index.cjs +1448 -0
  54. package/dist/roundtrip/index.d.cts +290 -0
  55. package/dist/roundtrip/index.d.ts +290 -0
  56. package/dist/roundtrip/index.js +1397 -0
  57. package/dist/types-Dr2Fn1Ax.d.cts +225 -0
  58. package/dist/types-Dr2Fn1Ax.d.ts +225 -0
  59. package/package.json +143 -4
  60. package/schema/ir-v2.schema.json +655 -0
@@ -0,0 +1,274 @@
1
+ 'use strict';
2
+
3
+ var chunkG4UEPUGO_cjs = require('./chunk-G4UEPUGO.cjs');
4
+ var chunkCSYBNN3V_cjs = require('./chunk-CSYBNN3V.cjs');
5
+ var chunkE3APHA6O_cjs = require('./chunk-E3APHA6O.cjs');
6
+
7
+ // src/ir/node-types.ts
8
+ var EXECUTOR_INTERNAL_TYPES = /* @__PURE__ */ new Set([
9
+ "internal:if",
10
+ "internal:switch",
11
+ "internal:loop",
12
+ "internal:merge",
13
+ "internal:set",
14
+ "internal:filter",
15
+ "internal:aggregate",
16
+ "internal:wait",
17
+ "internal:noop",
18
+ "internal:code",
19
+ "internal:http",
20
+ "internal:transform",
21
+ "internal:validate",
22
+ "internal:log",
23
+ "internal:error",
24
+ "internal:subworkflow",
25
+ "internal:compare-datasets",
26
+ "internal:split-out",
27
+ "internal:limit",
28
+ "internal:dedupe",
29
+ "internal:sort",
30
+ "internal:datatable",
31
+ "internal:respond-to-webhook",
32
+ "internal:send-and-wait",
33
+ "if",
34
+ "switch",
35
+ "loop",
36
+ "merge",
37
+ "set",
38
+ "filter",
39
+ "aggregate",
40
+ "wait",
41
+ "noop",
42
+ "code",
43
+ "http",
44
+ "transform",
45
+ "validate",
46
+ "log",
47
+ "error",
48
+ "subworkflow"
49
+ ]);
50
+ var CODE_WORKFLOW_NODE_TYPE = "internal:code-workflow";
51
+ var WAIT_FOR_SIGNAL_NODE_TYPE = "internal:wait-for-signal";
52
+ var V2_NODE_TYPES = /* @__PURE__ */ new Set([
53
+ CODE_WORKFLOW_NODE_TYPE,
54
+ WAIT_FOR_SIGNAL_NODE_TYPE
55
+ ]);
56
+ var INTERNAL_TRIGGER_TYPES = /* @__PURE__ */ new Set([
57
+ "internal:api",
58
+ "internal:schedule",
59
+ "internal:webhook",
60
+ "internal:form",
61
+ "internal:error-trigger",
62
+ "internal:workflow-call",
63
+ "internal:rss-feed",
64
+ "internal:http-poll",
65
+ "internal:database-poll",
66
+ "internal:email-imap",
67
+ "internal:file-upload",
68
+ "internal:record-change",
69
+ "internal:state-change"
70
+ ]);
71
+ function usesMergedParameters(type) {
72
+ const lower = type.toLowerCase();
73
+ return EXECUTOR_INTERNAL_TYPES.has(lower) || V2_NODE_TYPES.has(lower);
74
+ }
75
+
76
+ // src/ir/normalize.ts
77
+ function isNonEmptyString(value) {
78
+ return typeof value === "string" && value !== "";
79
+ }
80
+ function firstTruthy(...values) {
81
+ for (const value of values) if (value) return value;
82
+ return void 0;
83
+ }
84
+ function readPosition(value) {
85
+ if (!chunkE3APHA6O_cjs.isRecord(value)) return void 0;
86
+ const { x, y } = value;
87
+ return typeof x === "number" && typeof y === "number" && Number.isFinite(x) && Number.isFinite(y) ? { x, y } : void 0;
88
+ }
89
+ function removeIfEmpty(parent, key) {
90
+ const value = parent[key];
91
+ if (chunkE3APHA6O_cjs.isRecord(value) && Object.keys(value).length === 0) delete parent[key];
92
+ }
93
+ function normalizeLabel(node, data) {
94
+ if (node["label"] === void 0 && typeof data["label"] === "string")
95
+ node["label"] = data["label"];
96
+ if (data["label"] !== void 0 && chunkE3APHA6O_cjs.deepEqual(data["label"], node["label"])) delete data["label"];
97
+ }
98
+ function normalizeOperation(node, data) {
99
+ if (!isNonEmptyString(node["operation_name"]) && isNonEmptyString(data["operation_name"])) {
100
+ node["operation_name"] = data["operation_name"];
101
+ }
102
+ }
103
+ function normalizeVersion(node, data, merged) {
104
+ if (merged) return;
105
+ const effective = firstTruthy(data["version"], node["version"]);
106
+ if (typeof effective === "string") node["version"] = effective;
107
+ if (data["nodeVersion"] !== void 0 && chunkE3APHA6O_cjs.deepEqual(data["nodeVersion"], node["version"])) {
108
+ delete data["nodeVersion"];
109
+ }
110
+ }
111
+ function normalizeExternalState(node, data) {
112
+ const args = chunkE3APHA6O_cjs.isRecord(node["args"]) ? node["args"] : void 0;
113
+ const dataArgs = chunkE3APHA6O_cjs.isRecord(data["args"]) ? data["args"] : void 0;
114
+ const effective = firstTruthy(args?.["state"], dataArgs?.["state"]);
115
+ if (effective !== void 0 && args?.["state"] === void 0) {
116
+ const nextArgs = args ?? {};
117
+ nextArgs["state"] = effective;
118
+ node["args"] = nextArgs;
119
+ }
120
+ const rootState = chunkE3APHA6O_cjs.isRecord(node["args"]) ? node["args"]["state"] : void 0;
121
+ if (dataArgs && dataArgs["state"] !== void 0 && chunkE3APHA6O_cjs.deepEqual(dataArgs["state"], rootState)) {
122
+ delete dataArgs["state"];
123
+ }
124
+ }
125
+ function normalizeMergedState(node, data) {
126
+ const args = chunkE3APHA6O_cjs.isRecord(node["args"]) ? node["args"] : {};
127
+ const dataArgs = chunkE3APHA6O_cjs.isRecord(data["args"]) ? data["args"] : void 0;
128
+ const config = chunkE3APHA6O_cjs.isRecord(node["config"]) ? node["config"] : void 0;
129
+ const dataState = chunkE3APHA6O_cjs.isRecord(dataArgs?.["state"]) ? dataArgs["state"] : void 0;
130
+ const rootState = chunkE3APHA6O_cjs.isRecord(args["state"]) ? args["state"] : void 0;
131
+ if (config === void 0 && dataState === void 0) return;
132
+ args["state"] = { ...config, ...dataState, ...rootState };
133
+ node["args"] = args;
134
+ if (config !== void 0) delete node["config"];
135
+ if (dataArgs && dataState !== void 0) delete dataArgs["state"];
136
+ }
137
+ function normalizeConnections(node, data) {
138
+ const dataArgs = chunkE3APHA6O_cjs.isRecord(data["args"]) ? data["args"] : void 0;
139
+ if (!dataArgs) return;
140
+ for (const key of ["connections", "credentials"]) {
141
+ const args = chunkE3APHA6O_cjs.isRecord(node["args"]) ? node["args"] : void 0;
142
+ if (!args?.[key] && dataArgs[key]) {
143
+ const nextArgs = args ?? {};
144
+ nextArgs[key] = dataArgs[key];
145
+ node["args"] = nextArgs;
146
+ }
147
+ const rootValue = chunkE3APHA6O_cjs.isRecord(node["args"]) ? node["args"][key] : void 0;
148
+ if (dataArgs[key] !== void 0 && chunkE3APHA6O_cjs.deepEqual(dataArgs[key], rootValue)) delete dataArgs[key];
149
+ }
150
+ }
151
+ function normalizeContext(node, data) {
152
+ const dataArgs = chunkE3APHA6O_cjs.isRecord(data["args"]) ? data["args"] : void 0;
153
+ const args = chunkE3APHA6O_cjs.isRecord(node["args"]) ? node["args"] : void 0;
154
+ if (!dataArgs || dataArgs["context"] === void 0) return;
155
+ if (args && chunkE3APHA6O_cjs.deepEqual(dataArgs["context"], args["context"])) delete dataArgs["context"];
156
+ }
157
+ function normalizeErrorConfig(node, data) {
158
+ const dataArgs = chunkE3APHA6O_cjs.isRecord(data["args"]) ? data["args"] : void 0;
159
+ const dataState = chunkE3APHA6O_cjs.isRecord(dataArgs?.["state"]) ? dataArgs["state"] : void 0;
160
+ const effective = node["errorConfig"] ?? data["errorConfig"] ?? dataState?.["errorConfig"];
161
+ if (effective !== void 0 && effective !== null) node["errorConfig"] = effective;
162
+ else if (node["errorConfig"] === null) delete node["errorConfig"];
163
+ if (data["errorConfig"] !== void 0 && chunkE3APHA6O_cjs.deepEqual(data["errorConfig"], node["errorConfig"])) {
164
+ delete data["errorConfig"];
165
+ }
166
+ }
167
+ function normalizeExecutionSettings(node, data) {
168
+ const root = chunkE3APHA6O_cjs.isRecord(node["executionSettings"]) ? node["executionSettings"] : void 0;
169
+ const mirror = chunkE3APHA6O_cjs.isRecord(data["executionSettings"]) ? data["executionSettings"] : void 0;
170
+ if (!root && !mirror) return;
171
+ const merged = { ...root };
172
+ for (const [key, value] of Object.entries(mirror ?? {}))
173
+ if (!Object.hasOwn(merged, key)) chunkE3APHA6O_cjs.setOwn(merged, key, value);
174
+ if (root?.["executeOnce"] === true || mirror?.["executeOnce"] === true)
175
+ merged["executeOnce"] = true;
176
+ if (mirror && Object.hasOwn(mirror, "runOn")) {
177
+ merged["runOn"] = mirror["runOn"];
178
+ data["executionSettings"] = { runOn: mirror["runOn"] };
179
+ } else {
180
+ if (mirror) delete data["executionSettings"];
181
+ }
182
+ node["executionSettings"] = merged;
183
+ }
184
+ function normalizeDisabled(node, data) {
185
+ if (node["disabled"] === true || data["disabled"] === true) node["disabled"] = true;
186
+ delete data["disabled"];
187
+ }
188
+ function normalizeNode(raw) {
189
+ if (!chunkE3APHA6O_cjs.isRecord(raw)) return raw;
190
+ const node = chunkE3APHA6O_cjs.cloneJson(raw);
191
+ const type = typeof node["type"] === "string" ? node["type"] : "";
192
+ const merged = usesMergedParameters(type);
193
+ const data = chunkE3APHA6O_cjs.isRecord(node["data"]) ? node["data"] : {};
194
+ normalizeLabel(node, data);
195
+ normalizeOperation(node, data);
196
+ normalizeVersion(node, data, merged);
197
+ normalizeErrorConfig(node, data);
198
+ if (merged) normalizeMergedState(node, data);
199
+ else normalizeExternalState(node, data);
200
+ normalizeConnections(node, data);
201
+ normalizeContext(node, data);
202
+ normalizeExecutionSettings(node, data);
203
+ normalizeDisabled(node, data);
204
+ if (chunkE3APHA6O_cjs.isRecord(data["args"])) removeIfEmpty(data, "args");
205
+ if (Object.keys(data).length === 0) delete node["data"];
206
+ else node["data"] = data;
207
+ return node;
208
+ }
209
+ function normalizeDefinition(definition) {
210
+ if (!chunkE3APHA6O_cjs.isRecord(definition) || !chunkE3APHA6O_cjs.isRecord(definition["data"])) return definition;
211
+ const doc = chunkE3APHA6O_cjs.cloneJson(definition);
212
+ const data = doc["data"];
213
+ const rawNodes = Array.isArray(data["nodes"]) ? data["nodes"] : [];
214
+ const nodes = rawNodes.map(normalizeNode);
215
+ data["nodes"] = nodes;
216
+ const edges = Array.isArray(data["edges"]) ? data["edges"].filter(chunkE3APHA6O_cjs.isRecord) : [];
217
+ const ids = nodes.flatMap(
218
+ (node) => chunkE3APHA6O_cjs.isRecord(node) && typeof node["id"] === "string" ? [node["id"]] : []
219
+ );
220
+ const missing = nodes.some(
221
+ (node) => chunkE3APHA6O_cjs.isRecord(node) && readPosition(node["position"]) === void 0
222
+ );
223
+ if (missing) {
224
+ const meta = chunkE3APHA6O_cjs.isRecord(doc["meta"]) ? doc["meta"] : void 0;
225
+ const metaLayout = chunkE3APHA6O_cjs.isRecord(meta?.["layout"]) ? meta["layout"] : void 0;
226
+ const computed = chunkG4UEPUGO_cjs.autoLayout(
227
+ ids,
228
+ edges.flatMap(
229
+ (edge) => typeof edge["source"] === "string" && typeof edge["target"] === "string" ? [{ source: edge["source"], target: edge["target"] }] : []
230
+ )
231
+ );
232
+ for (const node of nodes) {
233
+ if (!chunkE3APHA6O_cjs.isRecord(node) || typeof node["id"] !== "string") continue;
234
+ if (readPosition(node["position"]) !== void 0) continue;
235
+ const fromMeta = readPosition(metaLayout?.[node["id"]]);
236
+ const position = fromMeta ?? computed.get(node["id"]);
237
+ if (position) node["position"] = { x: position.x, y: position.y };
238
+ }
239
+ }
240
+ doc["schemaVersion"] = 2;
241
+ return doc;
242
+ }
243
+
244
+ // src/ir/hash.ts
245
+ function hashedProjection(definition) {
246
+ const normalized = normalizeDefinition(definition);
247
+ if (!chunkE3APHA6O_cjs.isRecord(normalized)) return normalized;
248
+ const copy = { ...normalized };
249
+ delete copy["authoring"];
250
+ return copy;
251
+ }
252
+ function irHash(definition) {
253
+ return chunkCSYBNN3V_cjs.sha256Tagged(chunkCSYBNN3V_cjs.canonicalJson(hashedProjection(definition)));
254
+ }
255
+ function sourceHash(files) {
256
+ const entries = [...files].sort(
257
+ (a, b) => a.path === b.path ? a.content < b.content ? -1 : a.content > b.content ? 1 : 0 : a.path < b.path ? -1 : 1
258
+ ).map((file) => [file.path, file.content]);
259
+ return chunkCSYBNN3V_cjs.sha256Tagged(chunkCSYBNN3V_cjs.canonicalJson(entries));
260
+ }
261
+ function buildIdOf(bundle) {
262
+ return chunkCSYBNN3V_cjs.sha256Tagged(bundle);
263
+ }
264
+
265
+ exports.CODE_WORKFLOW_NODE_TYPE = CODE_WORKFLOW_NODE_TYPE;
266
+ exports.INTERNAL_TRIGGER_TYPES = INTERNAL_TRIGGER_TYPES;
267
+ exports.V2_NODE_TYPES = V2_NODE_TYPES;
268
+ exports.WAIT_FOR_SIGNAL_NODE_TYPE = WAIT_FOR_SIGNAL_NODE_TYPE;
269
+ exports.buildIdOf = buildIdOf;
270
+ exports.hashedProjection = hashedProjection;
271
+ exports.irHash = irHash;
272
+ exports.normalizeDefinition = normalizeDefinition;
273
+ exports.sourceHash = sourceHash;
274
+ exports.usesMergedParameters = usesMergedParameters;
@@ -0,0 +1,252 @@
1
+ 'use strict';
2
+
3
+ var chunkE3APHA6O_cjs = require('./chunk-E3APHA6O.cjs');
4
+
5
+ // src/ir/canonical-json.ts
6
+ var CanonicalJsonError = class extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "CanonicalJsonError";
10
+ }
11
+ };
12
+ function isPlainObject(value) {
13
+ const proto = Object.getPrototypeOf(value);
14
+ return proto === Object.prototype || proto === null;
15
+ }
16
+ function serialize(value, path, out) {
17
+ if (value === null) {
18
+ out.push("null");
19
+ return;
20
+ }
21
+ switch (typeof value) {
22
+ case "boolean":
23
+ out.push(value ? "true" : "false");
24
+ return;
25
+ case "number":
26
+ if (!Number.isFinite(value)) {
27
+ throw new CanonicalJsonError(`${path} is not a finite number`);
28
+ }
29
+ out.push(JSON.stringify(value));
30
+ return;
31
+ case "string":
32
+ out.push(JSON.stringify(value));
33
+ return;
34
+ case "object":
35
+ break;
36
+ default:
37
+ throw new CanonicalJsonError(`${path} is a ${typeof value}, which JSON cannot represent`);
38
+ }
39
+ if (Array.isArray(value)) {
40
+ out.push("[");
41
+ value.forEach((item, index) => {
42
+ if (item === void 0) {
43
+ throw new CanonicalJsonError(`${path}[${index}] is undefined`);
44
+ }
45
+ if (index > 0) out.push(",");
46
+ serialize(item, `${path}[${index}]`, out);
47
+ });
48
+ out.push("]");
49
+ return;
50
+ }
51
+ if (!isPlainObject(value)) {
52
+ throw new CanonicalJsonError(`${path} is not a plain JSON object`);
53
+ }
54
+ const record = value;
55
+ const keys = Object.keys(record).filter((key) => record[key] !== void 0).sort();
56
+ out.push("{");
57
+ keys.forEach((key, index) => {
58
+ if (index > 0) out.push(",");
59
+ out.push(JSON.stringify(key), ":");
60
+ serialize(record[key], `${path}.${key}`, out);
61
+ });
62
+ out.push("}");
63
+ }
64
+ function canonicalJson(value) {
65
+ const out = [];
66
+ serialize(value, "$", out);
67
+ return out.join("");
68
+ }
69
+ function sortKeysDeep(value) {
70
+ if (Array.isArray(value)) return value.map(sortKeysDeep);
71
+ if (value !== null && typeof value === "object") {
72
+ const record = value;
73
+ const sorted = {};
74
+ for (const key of Object.keys(record).sort()) {
75
+ if (record[key] !== void 0) chunkE3APHA6O_cjs.setOwn(sorted, key, sortKeysDeep(record[key]));
76
+ }
77
+ return sorted;
78
+ }
79
+ return value;
80
+ }
81
+ function stableStringify(value) {
82
+ canonicalJson(value);
83
+ return `${JSON.stringify(sortKeysDeep(value), null, 2)}
84
+ `;
85
+ }
86
+
87
+ // src/ir/sha256.ts
88
+ var K = new Uint32Array([
89
+ 1116352408,
90
+ 1899447441,
91
+ 3049323471,
92
+ 3921009573,
93
+ 961987163,
94
+ 1508970993,
95
+ 2453635748,
96
+ 2870763221,
97
+ 3624381080,
98
+ 310598401,
99
+ 607225278,
100
+ 1426881987,
101
+ 1925078388,
102
+ 2162078206,
103
+ 2614888103,
104
+ 3248222580,
105
+ 3835390401,
106
+ 4022224774,
107
+ 264347078,
108
+ 604807628,
109
+ 770255983,
110
+ 1249150122,
111
+ 1555081692,
112
+ 1996064986,
113
+ 2554220882,
114
+ 2821834349,
115
+ 2952996808,
116
+ 3210313671,
117
+ 3336571891,
118
+ 3584528711,
119
+ 113926993,
120
+ 338241895,
121
+ 666307205,
122
+ 773529912,
123
+ 1294757372,
124
+ 1396182291,
125
+ 1695183700,
126
+ 1986661051,
127
+ 2177026350,
128
+ 2456956037,
129
+ 2730485921,
130
+ 2820302411,
131
+ 3259730800,
132
+ 3345764771,
133
+ 3516065817,
134
+ 3600352804,
135
+ 4094571909,
136
+ 275423344,
137
+ 430227734,
138
+ 506948616,
139
+ 659060556,
140
+ 883997877,
141
+ 958139571,
142
+ 1322822218,
143
+ 1537002063,
144
+ 1747873779,
145
+ 1955562222,
146
+ 2024104815,
147
+ 2227730452,
148
+ 2361852424,
149
+ 2428436474,
150
+ 2756734187,
151
+ 3204031479,
152
+ 3329325298
153
+ ]);
154
+ function rotr(value, bits) {
155
+ return value >>> bits | value << 32 - bits;
156
+ }
157
+ function utf8(text) {
158
+ const bytes = [];
159
+ for (const char of text) {
160
+ let code = char.codePointAt(0) ?? 0;
161
+ if (code >= 55296 && code <= 57343) code = 65533;
162
+ if (code < 128) {
163
+ bytes.push(code);
164
+ } else if (code < 2048) {
165
+ bytes.push(192 | code >> 6, 128 | code & 63);
166
+ } else if (code < 65536) {
167
+ bytes.push(224 | code >> 12, 128 | code >> 6 & 63, 128 | code & 63);
168
+ } else {
169
+ bytes.push(
170
+ 240 | code >> 18,
171
+ 128 | code >> 12 & 63,
172
+ 128 | code >> 6 & 63,
173
+ 128 | code & 63
174
+ );
175
+ }
176
+ }
177
+ return Uint8Array.from(bytes);
178
+ }
179
+ function sha256Hex(text) {
180
+ const message = utf8(text);
181
+ const bitLength = message.length * 8;
182
+ const paddedLength = Math.ceil((message.length + 9) / 64) * 64;
183
+ const padded = new Uint8Array(paddedLength);
184
+ padded.set(message);
185
+ padded[message.length] = 128;
186
+ const view = new DataView(padded.buffer);
187
+ view.setUint32(paddedLength - 8, Math.floor(bitLength / 4294967296));
188
+ view.setUint32(paddedLength - 4, bitLength >>> 0);
189
+ const hash = new Uint32Array([
190
+ 1779033703,
191
+ 3144134277,
192
+ 1013904242,
193
+ 2773480762,
194
+ 1359893119,
195
+ 2600822924,
196
+ 528734635,
197
+ 1541459225
198
+ ]);
199
+ const w = new Uint32Array(64);
200
+ for (let offset = 0; offset < paddedLength; offset += 64) {
201
+ for (let i = 0; i < 16; i++) w[i] = view.getUint32(offset + i * 4);
202
+ for (let i = 16; i < 64; i++) {
203
+ const w15 = w[i - 15] ?? 0;
204
+ const w2 = w[i - 2] ?? 0;
205
+ const s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ w15 >>> 3;
206
+ const s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ w2 >>> 10;
207
+ w[i] = (w[i - 16] ?? 0) + s0 + (w[i - 7] ?? 0) + s1 >>> 0;
208
+ }
209
+ let a = hash[0] ?? 0;
210
+ let b = hash[1] ?? 0;
211
+ let c = hash[2] ?? 0;
212
+ let d = hash[3] ?? 0;
213
+ let e = hash[4] ?? 0;
214
+ let f = hash[5] ?? 0;
215
+ let g = hash[6] ?? 0;
216
+ let h = hash[7] ?? 0;
217
+ for (let i = 0; i < 64; i++) {
218
+ const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
219
+ const ch = e & f ^ ~e & g;
220
+ const t1 = h + s1 + ch + (K[i] ?? 0) + (w[i] ?? 0) >>> 0;
221
+ const s0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
222
+ const maj = a & b ^ a & c ^ b & c;
223
+ const t2 = s0 + maj >>> 0;
224
+ h = g;
225
+ g = f;
226
+ f = e;
227
+ e = d + t1 >>> 0;
228
+ d = c;
229
+ c = b;
230
+ b = a;
231
+ a = t1 + t2 >>> 0;
232
+ }
233
+ hash[0] = (hash[0] ?? 0) + a >>> 0;
234
+ hash[1] = (hash[1] ?? 0) + b >>> 0;
235
+ hash[2] = (hash[2] ?? 0) + c >>> 0;
236
+ hash[3] = (hash[3] ?? 0) + d >>> 0;
237
+ hash[4] = (hash[4] ?? 0) + e >>> 0;
238
+ hash[5] = (hash[5] ?? 0) + f >>> 0;
239
+ hash[6] = (hash[6] ?? 0) + g >>> 0;
240
+ hash[7] = (hash[7] ?? 0) + h >>> 0;
241
+ }
242
+ return Array.from(hash, (word) => word.toString(16).padStart(8, "0")).join("");
243
+ }
244
+ function sha256Tagged(text) {
245
+ return `sha256:${sha256Hex(text)}`;
246
+ }
247
+
248
+ exports.CanonicalJsonError = CanonicalJsonError;
249
+ exports.canonicalJson = canonicalJson;
250
+ exports.sha256Hex = sha256Hex;
251
+ exports.sha256Tagged = sha256Tagged;
252
+ exports.stableStringify = stableStringify;