@graphrefly/ts 0.0.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.
Files changed (210) hide show
  1. package/LICENSE +21 -0
  2. package/dist/adapters/index.cjs +9015 -0
  3. package/dist/adapters/index.cjs.map +1 -0
  4. package/dist/adapters/index.d.cts +678 -0
  5. package/dist/adapters/index.d.ts +678 -0
  6. package/dist/adapters/index.js +2894 -0
  7. package/dist/adapters/index.js.map +1 -0
  8. package/dist/adapters/observe-storage.cjs +260 -0
  9. package/dist/adapters/observe-storage.cjs.map +1 -0
  10. package/dist/adapters/observe-storage.d.cts +77 -0
  11. package/dist/adapters/observe-storage.d.ts +77 -0
  12. package/dist/adapters/observe-storage.js +161 -0
  13. package/dist/adapters/observe-storage.js.map +1 -0
  14. package/dist/append-log-DisvEReb.d.cts +189 -0
  15. package/dist/append-log-DzKMmjxx.d.ts +189 -0
  16. package/dist/chunk-2ILL7HQI.js +1189 -0
  17. package/dist/chunk-2ILL7HQI.js.map +1 -0
  18. package/dist/chunk-4VLAQHZI.js +330 -0
  19. package/dist/chunk-4VLAQHZI.js.map +1 -0
  20. package/dist/chunk-6PHB5CJS.js +229 -0
  21. package/dist/chunk-6PHB5CJS.js.map +1 -0
  22. package/dist/chunk-COHO25CZ.js +2449 -0
  23. package/dist/chunk-COHO25CZ.js.map +1 -0
  24. package/dist/chunk-D6BG7U6A.js +161 -0
  25. package/dist/chunk-D6BG7U6A.js.map +1 -0
  26. package/dist/chunk-DJC4CHLQ.js +818 -0
  27. package/dist/chunk-DJC4CHLQ.js.map +1 -0
  28. package/dist/chunk-DK554R7P.js +67 -0
  29. package/dist/chunk-DK554R7P.js.map +1 -0
  30. package/dist/chunk-DKP56CSW.js +322 -0
  31. package/dist/chunk-DKP56CSW.js.map +1 -0
  32. package/dist/chunk-G4M3NHRJ.js +688 -0
  33. package/dist/chunk-G4M3NHRJ.js.map +1 -0
  34. package/dist/chunk-GAJW5I5P.js +1 -0
  35. package/dist/chunk-GAJW5I5P.js.map +1 -0
  36. package/dist/chunk-GDL26N2T.js +282 -0
  37. package/dist/chunk-GDL26N2T.js.map +1 -0
  38. package/dist/chunk-GTPCOEOZ.js +741 -0
  39. package/dist/chunk-GTPCOEOZ.js.map +1 -0
  40. package/dist/chunk-H2HTHFVN.js +1 -0
  41. package/dist/chunk-H2HTHFVN.js.map +1 -0
  42. package/dist/chunk-HDRL4VQQ.js +218 -0
  43. package/dist/chunk-HDRL4VQQ.js.map +1 -0
  44. package/dist/chunk-I3IHOHCJ.js +2267 -0
  45. package/dist/chunk-I3IHOHCJ.js.map +1 -0
  46. package/dist/chunk-JIMUDQN3.js +965 -0
  47. package/dist/chunk-JIMUDQN3.js.map +1 -0
  48. package/dist/chunk-JR4IKCR2.js +462 -0
  49. package/dist/chunk-JR4IKCR2.js.map +1 -0
  50. package/dist/chunk-K3FXTC3I.js +165 -0
  51. package/dist/chunk-K3FXTC3I.js.map +1 -0
  52. package/dist/chunk-OOEN33FB.js +65 -0
  53. package/dist/chunk-OOEN33FB.js.map +1 -0
  54. package/dist/chunk-PKVBHGBM.js +554 -0
  55. package/dist/chunk-PKVBHGBM.js.map +1 -0
  56. package/dist/chunk-RIIOUTGM.js +1857 -0
  57. package/dist/chunk-RIIOUTGM.js.map +1 -0
  58. package/dist/chunk-SCRFRCGR.js +33 -0
  59. package/dist/chunk-SCRFRCGR.js.map +1 -0
  60. package/dist/chunk-SWTLEQL6.js +53 -0
  61. package/dist/chunk-SWTLEQL6.js.map +1 -0
  62. package/dist/chunk-SZAETNNA.js +1 -0
  63. package/dist/chunk-SZAETNNA.js.map +1 -0
  64. package/dist/chunk-TEW47IVR.js +49 -0
  65. package/dist/chunk-TEW47IVR.js.map +1 -0
  66. package/dist/chunk-Y3ZLRGHC.js +1482 -0
  67. package/dist/chunk-Y3ZLRGHC.js.map +1 -0
  68. package/dist/chunk-Z2ANQ6JW.js +149 -0
  69. package/dist/chunk-Z2ANQ6JW.js.map +1 -0
  70. package/dist/codec-BB7p8fJc.d.cts +38 -0
  71. package/dist/codec-BB7p8fJc.d.ts +38 -0
  72. package/dist/composition/index.cjs +2505 -0
  73. package/dist/composition/index.cjs.map +1 -0
  74. package/dist/composition/index.d.cts +95 -0
  75. package/dist/composition/index.d.ts +95 -0
  76. package/dist/composition/index.js +19 -0
  77. package/dist/composition/index.js.map +1 -0
  78. package/dist/core/index.cjs +2475 -0
  79. package/dist/core/index.cjs.map +1 -0
  80. package/dist/core/index.d.cts +25 -0
  81. package/dist/core/index.d.ts +25 -0
  82. package/dist/core/index.js +74 -0
  83. package/dist/core/index.js.map +1 -0
  84. package/dist/cqrs/index.cjs +595 -0
  85. package/dist/cqrs/index.cjs.map +1 -0
  86. package/dist/cqrs/index.d.cts +200 -0
  87. package/dist/cqrs/index.d.ts +200 -0
  88. package/dist/cqrs/index.js +557 -0
  89. package/dist/cqrs/index.js.map +1 -0
  90. package/dist/data-structures/index.cjs +4277 -0
  91. package/dist/data-structures/index.cjs.map +1 -0
  92. package/dist/data-structures/index.d.cts +22 -0
  93. package/dist/data-structures/index.d.ts +22 -0
  94. package/dist/data-structures/index.js +31 -0
  95. package/dist/data-structures/index.js.map +1 -0
  96. package/dist/describe-BZb7AS2y.d.ts +57 -0
  97. package/dist/describe-Ciu8SUnN.d.cts +57 -0
  98. package/dist/graph/index.cjs +7832 -0
  99. package/dist/graph/index.cjs.map +1 -0
  100. package/dist/graph/index.d.cts +251 -0
  101. package/dist/graph/index.d.ts +251 -0
  102. package/dist/graph/index.js +131 -0
  103. package/dist/graph/index.js.map +1 -0
  104. package/dist/graph-DfdF9zy4.d.ts +666 -0
  105. package/dist/graph-s23RbbFO.d.cts +666 -0
  106. package/dist/index-CAEmLCYF.d.cts +166 -0
  107. package/dist/index-SnzZu3x7.d.ts +166 -0
  108. package/dist/index.cjs +15409 -0
  109. package/dist/index.cjs.map +1 -0
  110. package/dist/index.d.cts +23 -0
  111. package/dist/index.d.ts +23 -0
  112. package/dist/index.js +582 -0
  113. package/dist/index.js.map +1 -0
  114. package/dist/messages-BZqrGGm1.d.cts +55 -0
  115. package/dist/messages-BZqrGGm1.d.ts +55 -0
  116. package/dist/messaging/index.cjs +818 -0
  117. package/dist/messaging/index.cjs.map +1 -0
  118. package/dist/messaging/index.d.cts +235 -0
  119. package/dist/messaging/index.d.ts +235 -0
  120. package/dist/messaging/index.js +767 -0
  121. package/dist/messaging/index.js.map +1 -0
  122. package/dist/observe-event-log-0SVsx7JG.d.cts +88 -0
  123. package/dist/observe-event-log-Dnm76owp.d.ts +88 -0
  124. package/dist/operators/index.cjs +3774 -0
  125. package/dist/operators/index.cjs.map +1 -0
  126. package/dist/operators/index.d.cts +308 -0
  127. package/dist/operators/index.d.ts +308 -0
  128. package/dist/operators/index.js +112 -0
  129. package/dist/operators/index.js.map +1 -0
  130. package/dist/orchestration/index.cjs +3541 -0
  131. package/dist/orchestration/index.cjs.map +1 -0
  132. package/dist/orchestration/index.d.cts +302 -0
  133. package/dist/orchestration/index.d.ts +302 -0
  134. package/dist/orchestration/index.js +1004 -0
  135. package/dist/orchestration/index.js.map +1 -0
  136. package/dist/patterns/index.cjs +1045 -0
  137. package/dist/patterns/index.cjs.map +1 -0
  138. package/dist/patterns/index.d.cts +39 -0
  139. package/dist/patterns/index.d.ts +39 -0
  140. package/dist/patterns/index.js +33 -0
  141. package/dist/patterns/index.js.map +1 -0
  142. package/dist/reactive-collection-BxBqtIOE.d.cts +344 -0
  143. package/dist/reactive-collection-Cb1II1Fi.d.ts +344 -0
  144. package/dist/reactive-collection-storage-BNiEc-Gd.d.ts +217 -0
  145. package/dist/reactive-collection-storage-D-KmjE0J.d.cts +217 -0
  146. package/dist/reactive-map-BcB4KsQR.d.ts +256 -0
  147. package/dist/reactive-map-D-g3dv8I.d.cts +256 -0
  148. package/dist/read-through-B1CYPfq_.d.cts +82 -0
  149. package/dist/read-through-DwyJhGs1.d.ts +82 -0
  150. package/dist/render/index.cjs +250 -0
  151. package/dist/render/index.cjs.map +1 -0
  152. package/dist/render/index.d.cts +58 -0
  153. package/dist/render/index.d.ts +58 -0
  154. package/dist/render/index.js +20 -0
  155. package/dist/render/index.js.map +1 -0
  156. package/dist/resilience-Dig3Q7n0.d.cts +45 -0
  157. package/dist/resilience-Dig3Q7n0.d.ts +45 -0
  158. package/dist/semantic-memory-graph-BYoIlP35.d.cts +356 -0
  159. package/dist/semantic-memory-graph-CxyXLms3.d.ts +356 -0
  160. package/dist/solutions/index.cjs +3249 -0
  161. package/dist/solutions/index.cjs.map +1 -0
  162. package/dist/solutions/index.d.cts +520 -0
  163. package/dist/solutions/index.d.ts +520 -0
  164. package/dist/solutions/index.js +31 -0
  165. package/dist/solutions/index.js.map +1 -0
  166. package/dist/sources/browser.cjs +3095 -0
  167. package/dist/sources/browser.cjs.map +1 -0
  168. package/dist/sources/browser.d.cts +39 -0
  169. package/dist/sources/browser.d.ts +39 -0
  170. package/dist/sources/browser.js +137 -0
  171. package/dist/sources/browser.js.map +1 -0
  172. package/dist/sources/index.cjs +3021 -0
  173. package/dist/sources/index.cjs.map +1 -0
  174. package/dist/sources/index.d.cts +7 -0
  175. package/dist/sources/index.d.ts +7 -0
  176. package/dist/sources/index.js +63 -0
  177. package/dist/sources/index.js.map +1 -0
  178. package/dist/sources/node.cjs +675 -0
  179. package/dist/sources/node.cjs.map +1 -0
  180. package/dist/sources/node.d.cts +109 -0
  181. package/dist/sources/node.d.ts +109 -0
  182. package/dist/sources/node.js +639 -0
  183. package/dist/sources/node.js.map +1 -0
  184. package/dist/storage/browser.cjs +777 -0
  185. package/dist/storage/browser.cjs.map +1 -0
  186. package/dist/storage/browser.d.cts +40 -0
  187. package/dist/storage/browser.d.ts +40 -0
  188. package/dist/storage/browser.js +275 -0
  189. package/dist/storage/browser.js.map +1 -0
  190. package/dist/storage/index.cjs +1989 -0
  191. package/dist/storage/index.cjs.map +1 -0
  192. package/dist/storage/index.d.cts +92 -0
  193. package/dist/storage/index.d.ts +92 -0
  194. package/dist/storage/index.js +161 -0
  195. package/dist/storage/index.js.map +1 -0
  196. package/dist/storage/node.cjs +898 -0
  197. package/dist/storage/node.cjs.map +1 -0
  198. package/dist/storage/node.d.cts +66 -0
  199. package/dist/storage/node.d.ts +66 -0
  200. package/dist/storage/node.js +402 -0
  201. package/dist/storage/node.js.map +1 -0
  202. package/dist/testing/index.cjs +95 -0
  203. package/dist/testing/index.cjs.map +1 -0
  204. package/dist/testing/index.d.cts +20 -0
  205. package/dist/testing/index.d.ts +20 -0
  206. package/dist/testing/index.js +8 -0
  207. package/dist/testing/index.js.map +1 -0
  208. package/dist/types-bNMSWKqF.d.cts +732 -0
  209. package/dist/types-h12mNYbq.d.ts +732 -0
  210. package/package.json +250 -0
@@ -0,0 +1,675 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/sources/node.ts
21
+ var node_exports = {};
22
+ __export(node_exports, {
23
+ fromFSWatch: () => fromFSWatch,
24
+ fromGitHook: () => fromGitHook,
25
+ fromSpawn: () => fromSpawn,
26
+ nodeProcessDriver: () => nodeProcessDriver,
27
+ runProcess: () => runProcess
28
+ });
29
+ module.exports = __toCommonJS(node_exports);
30
+ var import_node_child_process = require("child_process");
31
+ var import_node_fs = require("fs");
32
+ var import_node_path = require("path");
33
+
34
+ // src/protocol/messages.ts
35
+ var SENTINEL = void 0;
36
+ function isInvalidErrorPayload(v) {
37
+ return v === SENTINEL || typeof v === "boolean";
38
+ }
39
+ function errorPayload(reason, fallback = "error without a valid payload") {
40
+ return isInvalidErrorPayload(reason) ? new Error(fallback) : reason;
41
+ }
42
+
43
+ // src/sources/node.ts
44
+ function source(factory, setup) {
45
+ return {
46
+ factory,
47
+ body: (ctx) => {
48
+ const cleanup = setup(ctx);
49
+ if (typeof cleanup === "function") ctx.onDeactivation(cleanup);
50
+ }
51
+ };
52
+ }
53
+ function normalizePath(path) {
54
+ return path.replaceAll("\\", "/");
55
+ }
56
+ function escapeRegExp(value) {
57
+ return value.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
58
+ }
59
+ function globToRegExp(pattern) {
60
+ let out = "^";
61
+ for (let i = 0; i < pattern.length; i += 1) {
62
+ const ch = pattern[i];
63
+ if (ch === "*") {
64
+ if (pattern[i + 1] === "*") {
65
+ out += ".*";
66
+ i += 1;
67
+ } else {
68
+ out += "[^/]*";
69
+ }
70
+ } else {
71
+ out += escapeRegExp(ch);
72
+ }
73
+ }
74
+ return new RegExp(`${out}$`);
75
+ }
76
+ function matchesAny(value, patterns) {
77
+ return patterns.some((pattern) => pattern.test(value));
78
+ }
79
+ function timestampNsNow() {
80
+ return (BigInt(Date.now()) * 1000000n).toString();
81
+ }
82
+ function validatePositiveFinite(name, value) {
83
+ if (!Number.isFinite(value) || value <= 0) {
84
+ throw new RangeError(`${name} must be a positive finite number`);
85
+ }
86
+ }
87
+ function validateNonNegativeFinite(name, value) {
88
+ if (!Number.isFinite(value) || value < 0) {
89
+ throw new RangeError(`${name} must be a non-negative finite number`);
90
+ }
91
+ }
92
+ function eventTypeFor(eventType, path) {
93
+ if (eventType === "change") return "change";
94
+ try {
95
+ return (0, import_node_fs.existsSync)(path) ? "create" : "delete";
96
+ } catch {
97
+ return "rename";
98
+ }
99
+ }
100
+ function scanFiles(root, recursive, isExcluded) {
101
+ const resolved = (0, import_node_path.resolve)(root);
102
+ try {
103
+ const st = (0, import_node_fs.statSync)(resolved);
104
+ if (st.isFile()) return [resolved];
105
+ if (!st.isDirectory()) return [];
106
+ } catch {
107
+ return [];
108
+ }
109
+ const out = [];
110
+ function walk(dir) {
111
+ let entries;
112
+ try {
113
+ entries = (0, import_node_fs.readdirSync)(dir, { withFileTypes: true });
114
+ } catch {
115
+ return;
116
+ }
117
+ for (const entry of entries) {
118
+ const abs = (0, import_node_path.join)(dir, entry.name);
119
+ const rel = (0, import_node_path.relative)(resolved, abs);
120
+ if (entry.isFile()) {
121
+ out.push(abs);
122
+ } else if (recursive && entry.isDirectory() && !isExcluded(abs, rel)) {
123
+ walk(abs);
124
+ }
125
+ }
126
+ }
127
+ walk(resolved);
128
+ return out;
129
+ }
130
+ function fromFSWatch(paths, opts = {}) {
131
+ const list = (Array.isArray(paths) ? paths : [paths]).map((path) => (0, import_node_path.resolve)(path));
132
+ if (list.length === 0) throw new RangeError("fromFSWatch: paths must not be empty");
133
+ const {
134
+ recursive = false,
135
+ debounceMs = 100,
136
+ initialScan = false,
137
+ include,
138
+ exclude = ["**/node_modules/**", "**/.git/**", "**/dist/**"],
139
+ signal
140
+ } = opts;
141
+ if (!Number.isFinite(debounceMs) || debounceMs < 0) {
142
+ throw new RangeError("fromFSWatch: debounceMs must be a non-negative finite number");
143
+ }
144
+ const includePatterns = (include ?? []).map(globToRegExp);
145
+ const excludePatterns = exclude.map(globToRegExp);
146
+ const accepts = (abs, rel) => {
147
+ const normalized = normalizePath(abs);
148
+ const relNormalized = normalizePath(rel);
149
+ const included = includePatterns.length === 0 || matchesAny(normalized, includePatterns) || matchesAny(relNormalized, includePatterns);
150
+ if (!included) return false;
151
+ return !isExcluded(normalized, relNormalized);
152
+ };
153
+ const isExcluded = (abs, rel) => {
154
+ const normalized = normalizePath(abs);
155
+ const relNormalized = normalizePath(rel);
156
+ return matchesAny(normalized, excludePatterns) || matchesAny(relNormalized, excludePatterns) || matchesAny(`${normalized}/`, excludePatterns) || relNormalized !== "" && matchesAny(`${relNormalized}/`, excludePatterns);
157
+ };
158
+ return source("fromFSWatch", (ctx) => {
159
+ let stopped = false;
160
+ let terminal = false;
161
+ let ready = initialScan === false;
162
+ let generation = 0;
163
+ let timer;
164
+ const watchers = [];
165
+ const pending = /* @__PURE__ */ new Map();
166
+ const buffered = /* @__PURE__ */ new Map();
167
+ const close = () => {
168
+ for (const watcher of watchers.splice(0)) watcher.close();
169
+ };
170
+ const cleanup = () => {
171
+ stopped = true;
172
+ generation += 1;
173
+ if (timer !== void 0) clearTimeout(timer);
174
+ timer = void 0;
175
+ signal?.removeEventListener("abort", onAbort);
176
+ close();
177
+ pending.clear();
178
+ buffered.clear();
179
+ };
180
+ const emitError = (err) => {
181
+ if (terminal) return;
182
+ terminal = true;
183
+ cleanup();
184
+ ctx.down([["ERROR", errorPayload(err)]]);
185
+ };
186
+ function onAbort() {
187
+ emitError(signal?.reason);
188
+ }
189
+ const flush = (token) => {
190
+ timer = void 0;
191
+ if (stopped || terminal || token !== generation || pending.size === 0) return;
192
+ const msgs = [...pending.values()].map((event) => ["DATA", event]);
193
+ pending.clear();
194
+ ctx.down(msgs);
195
+ };
196
+ const schedule = () => {
197
+ if (timer !== void 0) clearTimeout(timer);
198
+ const token = generation;
199
+ if (debounceMs === 0) flush(token);
200
+ else timer = setTimeout(() => flush(token), debounceMs);
201
+ };
202
+ const enqueue = (event) => {
203
+ if (!ready) {
204
+ buffered.set(event.path, event);
205
+ return;
206
+ }
207
+ pending.set(event.path, event);
208
+ schedule();
209
+ };
210
+ const eventFor = (basePath, eventType, fileName) => {
211
+ const root = normalizePath((0, import_node_path.resolve)(basePath));
212
+ const abs = normalizePath(fileName == null ? root : (0, import_node_path.resolve)(basePath, String(fileName)));
213
+ const rel = normalizePath(fileName == null ? "" : (0, import_node_path.relative)(root, abs));
214
+ if (!accepts(abs, rel)) return void 0;
215
+ return {
216
+ type: eventTypeFor(eventType, abs),
217
+ path: abs,
218
+ root,
219
+ relativePath: rel
220
+ };
221
+ };
222
+ if (signal?.aborted) {
223
+ onAbort();
224
+ return cleanup;
225
+ }
226
+ signal?.addEventListener("abort", onAbort, { once: true });
227
+ try {
228
+ for (const basePath of list) {
229
+ const watcher = (0, import_node_fs.watch)(basePath, { recursive }, (eventType, fileName) => {
230
+ if (stopped || terminal) return;
231
+ const event = eventFor(basePath, eventType, fileName);
232
+ if (event !== void 0) enqueue(event);
233
+ });
234
+ watcher.on("error", emitError);
235
+ watchers.push(watcher);
236
+ }
237
+ } catch (err) {
238
+ emitError(err);
239
+ return cleanup;
240
+ }
241
+ if (initialScan !== false) {
242
+ try {
243
+ for (const basePath of list) {
244
+ const root = normalizePath((0, import_node_path.resolve)(basePath));
245
+ let relRoot = root;
246
+ try {
247
+ if ((0, import_node_fs.statSync)(basePath).isFile()) relRoot = (0, import_node_path.dirname)(root);
248
+ } catch {
249
+ relRoot = root;
250
+ }
251
+ for (const absPath of scanFiles(basePath, recursive, isExcluded)) {
252
+ if (stopped || terminal) return cleanup;
253
+ const abs = normalizePath(absPath);
254
+ const rel = normalizePath((0, import_node_path.relative)(relRoot, abs));
255
+ if (!accepts(abs, rel)) continue;
256
+ pending.set(abs, {
257
+ type: "create",
258
+ path: abs,
259
+ root,
260
+ relativePath: rel
261
+ });
262
+ }
263
+ }
264
+ ready = true;
265
+ for (const [key, event] of buffered) pending.set(key, event);
266
+ buffered.clear();
267
+ if (pending.size > 0) schedule();
268
+ } catch (err) {
269
+ emitError(err);
270
+ }
271
+ }
272
+ return cleanup;
273
+ });
274
+ }
275
+ function fromSpawn(cmd, args = [], opts = {}) {
276
+ if (typeof cmd !== "string" || cmd.length === 0) {
277
+ throw new TypeError("fromSpawn: cmd must be a non-empty string");
278
+ }
279
+ const killGraceMs = opts.killGraceMs ?? 1e3;
280
+ validateNonNegativeFinite("fromSpawn: killGraceMs", killGraceMs);
281
+ return source("fromSpawn", (ctx) => {
282
+ let alive = true;
283
+ let terminal = false;
284
+ let exitInfo;
285
+ let child;
286
+ let killTimer;
287
+ const clearKillTimer = () => {
288
+ if (killTimer !== void 0) clearTimeout(killTimer);
289
+ killTimer = void 0;
290
+ };
291
+ const stop = () => {
292
+ alive = false;
293
+ child?.stdout?.removeAllListeners("data");
294
+ child?.stderr?.removeAllListeners("data");
295
+ if (!terminal) {
296
+ try {
297
+ child?.kill("SIGTERM");
298
+ } catch {
299
+ }
300
+ killTimer = setTimeout(() => {
301
+ if (!terminal) {
302
+ try {
303
+ child?.kill("SIGKILL");
304
+ } catch {
305
+ }
306
+ }
307
+ }, killGraceMs);
308
+ killTimer.unref?.();
309
+ }
310
+ };
311
+ try {
312
+ child = (0, import_node_child_process.spawn)(cmd, [...args], {
313
+ cwd: opts.cwd,
314
+ env: opts.env,
315
+ shell: opts.shell,
316
+ signal: opts.signal,
317
+ stdio: opts.stdio ?? "pipe"
318
+ });
319
+ } catch (err) {
320
+ terminal = true;
321
+ ctx.down([["ERROR", errorPayload(err)]]);
322
+ return () => void 0;
323
+ }
324
+ child.stdout?.on("data", (chunk) => {
325
+ if (alive) ctx.down([["DATA", { kind: "stdout", chunk }]]);
326
+ });
327
+ child.stderr?.on("data", (chunk) => {
328
+ if (alive) ctx.down([["DATA", { kind: "stderr", chunk }]]);
329
+ });
330
+ child.on("error", (err) => {
331
+ if (!alive || terminal) return;
332
+ terminal = true;
333
+ alive = false;
334
+ ctx.down([["ERROR", errorPayload(err)]]);
335
+ });
336
+ child.on("exit", (code, signal) => {
337
+ exitInfo = { code, signal };
338
+ });
339
+ child.on("close", () => {
340
+ clearKillTimer();
341
+ if (!alive || terminal) return;
342
+ terminal = true;
343
+ alive = false;
344
+ const info = exitInfo ?? { code: null, signal: null };
345
+ ctx.down([["DATA", { kind: "exit", code: info.code, signal: info.signal }], ["COMPLETE"]]);
346
+ });
347
+ return stop;
348
+ });
349
+ }
350
+ function nodeProcessDriver(opts = {}) {
351
+ const killGraceMs = opts.killGraceMs ?? 1e3;
352
+ const maxBufferBytes = opts.maxBufferBytes ?? 16 * 1024 * 1024;
353
+ validateNonNegativeFinite("nodeProcessDriver: killGraceMs", killGraceMs);
354
+ validateNonNegativeFinite("nodeProcessDriver: maxBufferBytes", maxBufferBytes);
355
+ return {
356
+ run(command, callback) {
357
+ return runNodeProcessCommand(command, callback, {
358
+ killGraceMs,
359
+ maxBufferBytes,
360
+ shell: opts.shell
361
+ });
362
+ }
363
+ };
364
+ }
365
+ function runProcess(cmd, args = [], opts = {}) {
366
+ if (typeof cmd !== "string" || cmd.length === 0) {
367
+ throw new TypeError("runProcess: cmd must be a non-empty string");
368
+ }
369
+ const killGraceMs = opts.killGraceMs ?? 1e3;
370
+ validateNonNegativeFinite("runProcess: killGraceMs", killGraceMs);
371
+ return source("runProcess", (ctx) => {
372
+ let alive = true;
373
+ let terminal = false;
374
+ const stdoutChunks = [];
375
+ const stderrChunks = [];
376
+ let exitInfo;
377
+ let child;
378
+ let killTimer;
379
+ const clearKillTimer = () => {
380
+ if (killTimer !== void 0) clearTimeout(killTimer);
381
+ killTimer = void 0;
382
+ };
383
+ const stop = () => {
384
+ alive = false;
385
+ child?.stdout?.removeAllListeners("data");
386
+ child?.stderr?.removeAllListeners("data");
387
+ if (!terminal) {
388
+ try {
389
+ child?.kill("SIGTERM");
390
+ } catch {
391
+ }
392
+ killTimer = setTimeout(() => {
393
+ if (!terminal) {
394
+ try {
395
+ child?.kill("SIGKILL");
396
+ } catch {
397
+ }
398
+ }
399
+ }, killGraceMs);
400
+ killTimer.unref?.();
401
+ }
402
+ };
403
+ try {
404
+ child = (0, import_node_child_process.spawn)(cmd, [...args], {
405
+ cwd: opts.cwd,
406
+ env: opts.env,
407
+ shell: opts.shell,
408
+ signal: opts.signal,
409
+ stdio: opts.stdio ?? "pipe"
410
+ });
411
+ } catch (err) {
412
+ terminal = true;
413
+ ctx.down([["ERROR", errorPayload(err)]]);
414
+ return () => void 0;
415
+ }
416
+ child.stdout?.on("data", (chunk) => {
417
+ if (alive) stdoutChunks.push(chunk);
418
+ });
419
+ child.stderr?.on("data", (chunk) => {
420
+ if (alive) stderrChunks.push(chunk);
421
+ });
422
+ child.on("error", (err) => {
423
+ if (!alive || terminal) return;
424
+ terminal = true;
425
+ alive = false;
426
+ ctx.down([["ERROR", errorPayload(err)]]);
427
+ });
428
+ child.on("exit", (code, signal) => {
429
+ exitInfo = { code, signal };
430
+ });
431
+ child.on("close", () => {
432
+ clearKillTimer();
433
+ if (!alive || terminal) return;
434
+ terminal = true;
435
+ alive = false;
436
+ const info = exitInfo ?? { code: null, signal: null };
437
+ ctx.down([
438
+ [
439
+ "DATA",
440
+ {
441
+ stdout: Buffer.concat(stdoutChunks).toString("utf8"),
442
+ stderr: Buffer.concat(stderrChunks).toString("utf8"),
443
+ exitCode: info.code,
444
+ signal: info.signal
445
+ }
446
+ ],
447
+ ["COMPLETE"]
448
+ ]);
449
+ });
450
+ return stop;
451
+ });
452
+ }
453
+ function runNodeProcessCommand(command, callback, opts) {
454
+ if (typeof command.program !== "string" || command.program.length === 0) {
455
+ callback({
456
+ ok: false,
457
+ error: new TypeError("nodeProcessDriver: program must be a non-empty string")
458
+ });
459
+ return () => void 0;
460
+ }
461
+ let alive = true;
462
+ let terminal = false;
463
+ const stdoutChunks = [];
464
+ const stderrChunks = [];
465
+ let bufferedBytes = 0;
466
+ let exitInfo;
467
+ let child;
468
+ let killTimer;
469
+ const clearKillTimer = () => {
470
+ if (killTimer !== void 0) clearTimeout(killTimer);
471
+ killTimer = void 0;
472
+ };
473
+ const stop = () => {
474
+ if (!alive) return;
475
+ alive = false;
476
+ child?.stdout?.removeAllListeners("data");
477
+ child?.stderr?.removeAllListeners("data");
478
+ if (!terminal) {
479
+ try {
480
+ child?.kill("SIGTERM");
481
+ } catch {
482
+ }
483
+ killTimer = setTimeout(() => {
484
+ if (!terminal) {
485
+ try {
486
+ child?.kill("SIGKILL");
487
+ } catch {
488
+ }
489
+ }
490
+ }, opts.killGraceMs);
491
+ killTimer.unref?.();
492
+ }
493
+ };
494
+ try {
495
+ child = (0, import_node_child_process.spawn)(command.program, [...command.args], {
496
+ cwd: command.cwd,
497
+ env: command.env === void 0 ? void 0 : Object.fromEntries(command.env),
498
+ shell: opts.shell,
499
+ stdio: ["ignore", "pipe", "pipe"]
500
+ });
501
+ } catch (err) {
502
+ terminal = true;
503
+ callback({ ok: false, error: err });
504
+ return () => void 0;
505
+ }
506
+ const fail = (error) => {
507
+ clearKillTimer();
508
+ if (!alive || terminal) return;
509
+ terminal = true;
510
+ alive = false;
511
+ child.stdout?.removeAllListeners("data");
512
+ child.stderr?.removeAllListeners("data");
513
+ try {
514
+ child.kill("SIGTERM");
515
+ } catch {
516
+ }
517
+ killTimer = setTimeout(() => {
518
+ try {
519
+ child.kill("SIGKILL");
520
+ } catch {
521
+ }
522
+ }, opts.killGraceMs);
523
+ killTimer.unref?.();
524
+ callback({ ok: false, error });
525
+ };
526
+ const pushOutput = (chunks, chunk) => {
527
+ if (!alive) return;
528
+ bufferedBytes += chunk.byteLength;
529
+ if (bufferedBytes > opts.maxBufferBytes) {
530
+ fail(
531
+ new RangeError(
532
+ `nodeProcessDriver: stdout/stderr exceeded maxBufferBytes (${opts.maxBufferBytes})`
533
+ )
534
+ );
535
+ return;
536
+ }
537
+ chunks.push(chunk);
538
+ };
539
+ child.stdout?.on("data", (chunk) => {
540
+ pushOutput(stdoutChunks, chunk);
541
+ });
542
+ child.stderr?.on("data", (chunk) => {
543
+ pushOutput(stderrChunks, chunk);
544
+ });
545
+ child.on("error", (err) => {
546
+ clearKillTimer();
547
+ if (!alive || terminal) return;
548
+ terminal = true;
549
+ alive = false;
550
+ callback({ ok: false, error: err });
551
+ });
552
+ child.on("exit", (code, signal) => {
553
+ exitInfo = { code, signal };
554
+ });
555
+ child.on("close", () => {
556
+ clearKillTimer();
557
+ if (!alive || terminal) return;
558
+ terminal = true;
559
+ alive = false;
560
+ const info = exitInfo ?? { code: null, signal: null };
561
+ callback({
562
+ ok: true,
563
+ value: {
564
+ stdout: Buffer.concat(stdoutChunks).toString("utf8"),
565
+ stderr: Buffer.concat(stderrChunks).toString("utf8"),
566
+ exitCode: info.code,
567
+ signal: info.signal
568
+ }
569
+ });
570
+ });
571
+ return stop;
572
+ }
573
+ function stripFinalLineBreak(value) {
574
+ return value.replace(/\r?\n$/, "");
575
+ }
576
+ function gitText(repoPath, args) {
577
+ return stripFinalLineBreak((0, import_node_child_process.execFileSync)("git", ["-C", repoPath, ...args], { encoding: "utf8" }));
578
+ }
579
+ function gitPathList(repoPath, args) {
580
+ const out = (0, import_node_child_process.execFileSync)("git", ["-C", repoPath, ...args, "-z"]);
581
+ const text = out.toString("utf8");
582
+ if (text.length === 0) return [];
583
+ return text.split("\0").filter((part) => part.length > 0);
584
+ }
585
+ function readGitHead(repoPath, previousHead) {
586
+ const head = gitText(repoPath, ["rev-parse", "HEAD"]);
587
+ if (head.length === 0 || head === previousHead) return void 0;
588
+ const files = previousHead === void 0 ? [] : gitPathList(repoPath, ["diff", "--name-only", `${previousHead}..${head}`]);
589
+ return {
590
+ head,
591
+ files,
592
+ message: gitText(repoPath, ["log", "-1", "--format=%s", head]),
593
+ author: gitText(repoPath, ["log", "-1", "--format=%an", head])
594
+ };
595
+ }
596
+ function fromGitHook(repoPath, opts = {}) {
597
+ const { pollMs = 5e3, include, exclude, maxConsecutiveErrors = 1, signal } = opts;
598
+ validatePositiveFinite("fromGitHook: pollMs", pollMs);
599
+ if (!Number.isFinite(maxConsecutiveErrors) && maxConsecutiveErrors !== Infinity) {
600
+ throw new RangeError("fromGitHook: maxConsecutiveErrors must be finite or Infinity");
601
+ }
602
+ if (maxConsecutiveErrors <= 0) {
603
+ throw new RangeError("fromGitHook: maxConsecutiveErrors must be positive");
604
+ }
605
+ const resolvedRepoPath = (0, import_node_path.resolve)(repoPath);
606
+ const includePatterns = (include ?? []).map(globToRegExp);
607
+ const excludePatterns = (exclude ?? []).map(globToRegExp);
608
+ const accepts = (file) => {
609
+ const normalized = normalizePath(file);
610
+ const included = includePatterns.length === 0 || matchesAny(normalized, includePatterns);
611
+ return included && !matchesAny(normalized, excludePatterns);
612
+ };
613
+ return source("fromGitHook", (ctx) => {
614
+ let done = false;
615
+ let lastSeen;
616
+ let consecutiveErrors = 0;
617
+ let intervalId;
618
+ const cleanup = () => {
619
+ done = true;
620
+ if (intervalId !== void 0) clearInterval(intervalId);
621
+ intervalId = void 0;
622
+ signal?.removeEventListener("abort", onAbort);
623
+ };
624
+ const fail = (err) => {
625
+ if (done) return;
626
+ cleanup();
627
+ ctx.down([["ERROR", errorPayload(err)]]);
628
+ };
629
+ const onAbort = () => fail(signal?.reason);
630
+ const poll = () => {
631
+ if (done) return;
632
+ try {
633
+ const result = readGitHead(resolvedRepoPath, lastSeen);
634
+ consecutiveErrors = 0;
635
+ if (result === void 0) return;
636
+ const isBaseline = lastSeen === void 0;
637
+ lastSeen = result.head;
638
+ if (isBaseline) return;
639
+ ctx.down([
640
+ [
641
+ "DATA",
642
+ {
643
+ hook: "post-commit",
644
+ commit: result.head,
645
+ files: result.files.filter(accepts),
646
+ message: result.message,
647
+ author: result.author,
648
+ timestamp_ns: timestampNsNow()
649
+ }
650
+ ]
651
+ ]);
652
+ } catch (err) {
653
+ consecutiveErrors += 1;
654
+ if (consecutiveErrors >= maxConsecutiveErrors) fail(err);
655
+ }
656
+ };
657
+ if (signal?.aborted) {
658
+ onAbort();
659
+ return cleanup;
660
+ }
661
+ signal?.addEventListener("abort", onAbort, { once: true });
662
+ poll();
663
+ if (!done) intervalId = setInterval(poll, pollMs);
664
+ return cleanup;
665
+ });
666
+ }
667
+ // Annotate the CommonJS export names for ESM import in node:
668
+ 0 && (module.exports = {
669
+ fromFSWatch,
670
+ fromGitHook,
671
+ fromSpawn,
672
+ nodeProcessDriver,
673
+ runProcess
674
+ });
675
+ //# sourceMappingURL=node.cjs.map