@pgfsm/api 0.0.0-stage → 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 (118) hide show
  1. package/esm/_dnt.polyfills.d.ts +17 -0
  2. package/esm/_dnt.polyfills.js +15 -0
  3. package/esm/_dnt.shims.d.ts +5 -0
  4. package/esm/_dnt.shims.js +61 -0
  5. package/esm/database-src/generated/database.types.d.ts +2131 -0
  6. package/esm/database-src/generated/database.types.js +21 -0
  7. package/esm/deps/jsr.io/@std/cli/1.0.31/parse_args.d.ts +342 -0
  8. package/esm/deps/jsr.io/@std/cli/1.0.31/parse_args.js +372 -0
  9. package/esm/fsm-api-ts/env.d.ts +143 -0
  10. package/esm/fsm-api-ts/env.js +72 -0
  11. package/esm/fsm-api-ts/lib/configure-open-api.d.ts +3 -0
  12. package/esm/fsm-api-ts/lib/configure-open-api.js +25 -0
  13. package/esm/fsm-api-ts/lib/constants.d.ts +15 -0
  14. package/esm/fsm-api-ts/lib/constants.js +11 -0
  15. package/esm/fsm-api-ts/lib/create-app.d.ts +19 -0
  16. package/esm/fsm-api-ts/lib/create-app.js +137 -0
  17. package/esm/fsm-api-ts/lib/create-router.d.ts +3 -0
  18. package/esm/fsm-api-ts/lib/create-router.js +10 -0
  19. package/esm/fsm-api-ts/lib/license.d.ts +13 -0
  20. package/esm/fsm-api-ts/lib/license.js +15 -0
  21. package/esm/fsm-api-ts/lib/types.d.ts +19 -0
  22. package/esm/fsm-api-ts/lib/types.js +1 -0
  23. package/esm/fsm-api-ts/logger.d.ts +3 -0
  24. package/esm/fsm-api-ts/logger.js +20 -0
  25. package/esm/fsm-api-ts/middlewares/api-key-auth.d.ts +34 -0
  26. package/esm/fsm-api-ts/middlewares/api-key-auth.js +70 -0
  27. package/esm/fsm-api-ts/middlewares/logtape-logger.d.ts +2 -0
  28. package/esm/fsm-api-ts/middlewares/logtape-logger.js +33 -0
  29. package/esm/fsm-api-ts/middlewares/otel-trace.d.ts +2 -0
  30. package/esm/fsm-api-ts/middlewares/otel-trace.js +29 -0
  31. package/esm/fsm-api-ts/middlewares/supabase.d.ts +10 -0
  32. package/esm/fsm-api-ts/middlewares/supabase.js +34 -0
  33. package/esm/fsm-api-ts/mod.d.ts +2 -0
  34. package/esm/fsm-api-ts/mod.js +6 -0
  35. package/esm/fsm-api-ts/routes/admin/admin.handlers.d.ts +8 -0
  36. package/esm/fsm-api-ts/routes/admin/admin.handlers.js +98 -0
  37. package/esm/fsm-api-ts/routes/admin/admin.index.d.ts +189 -0
  38. package/esm/fsm-api-ts/routes/admin/admin.index.js +11 -0
  39. package/esm/fsm-api-ts/routes/admin/admin.routes.d.ts +473 -0
  40. package/esm/fsm-api-ts/routes/admin/admin.routes.js +130 -0
  41. package/esm/fsm-api-ts/routes/definitions/definitions.handlers.d.ts +5 -0
  42. package/esm/fsm-api-ts/routes/definitions/definitions.handlers.js +29 -0
  43. package/esm/fsm-api-ts/routes/definitions/definitions.index.d.ts +86 -0
  44. package/esm/fsm-api-ts/routes/definitions/definitions.index.js +8 -0
  45. package/esm/fsm-api-ts/routes/definitions/definitions.routes.d.ts +204 -0
  46. package/esm/fsm-api-ts/routes/definitions/definitions.routes.js +56 -0
  47. package/esm/fsm-api-ts/routes/index.route.d.ts +19 -0
  48. package/esm/fsm-api-ts/routes/index.route.js +31 -0
  49. package/esm/fsm-api-ts/routes/instances/instances.handlers.d.ts +8 -0
  50. package/esm/fsm-api-ts/routes/instances/instances.handlers.js +108 -0
  51. package/esm/fsm-api-ts/routes/instances/instances.index.d.ts +237 -0
  52. package/esm/fsm-api-ts/routes/instances/instances.index.js +11 -0
  53. package/esm/fsm-api-ts/routes/instances/instances.routes.d.ts +411 -0
  54. package/esm/fsm-api-ts/routes/instances/instances.routes.js +104 -0
  55. package/esm/fsm-api-ts/src/cli/index.d.ts +2 -0
  56. package/esm/fsm-api-ts/src/cli/index.js +197 -0
  57. package/esm/fsm-api-ts/src/cli/invocation.node.d.ts +1 -0
  58. package/esm/fsm-api-ts/src/cli/invocation.node.js +4 -0
  59. package/esm/fsm-api-ts/src/cli/key-bootstrap.d.ts +14 -0
  60. package/esm/fsm-api-ts/src/cli/key-bootstrap.js +35 -0
  61. package/esm/fsm-api-ts/src/cli/serve.node.d.ts +6 -0
  62. package/esm/fsm-api-ts/src/cli/serve.node.js +20 -0
  63. package/esm/fsm-api-ts/src/cli/version.node.d.ts +1 -0
  64. package/esm/fsm-api-ts/src/cli/version.node.js +2 -0
  65. package/esm/fsm-api-ts/stoker-src/http-status-codes.d.ts +354 -0
  66. package/esm/fsm-api-ts/stoker-src/http-status-codes.js +356 -0
  67. package/esm/fsm-api-ts/stoker-src/http-status-phrases.d.ts +354 -0
  68. package/esm/fsm-api-ts/stoker-src/http-status-phrases.js +356 -0
  69. package/esm/fsm-api-ts/stoker-src/middlewares/index.d.ts +3 -0
  70. package/esm/fsm-api-ts/stoker-src/middlewares/index.js +3 -0
  71. package/esm/fsm-api-ts/stoker-src/middlewares/not-found.d.ts +3 -0
  72. package/esm/fsm-api-ts/stoker-src/middlewares/not-found.js +8 -0
  73. package/esm/fsm-api-ts/stoker-src/middlewares/on-error.d.ts +3 -0
  74. package/esm/fsm-api-ts/stoker-src/middlewares/on-error.js +19 -0
  75. package/esm/fsm-api-ts/stoker-src/middlewares/serve-emoji-favicon.d.ts +3 -0
  76. package/esm/fsm-api-ts/stoker-src/middlewares/serve-emoji-favicon.js +10 -0
  77. package/esm/fsm-api-ts/stoker-src/openapi/default-hook.d.ts +3 -0
  78. package/esm/fsm-api-ts/stoker-src/openapi/default-hook.js +11 -0
  79. package/esm/fsm-api-ts/stoker-src/openapi/helpers/index.d.ts +4 -0
  80. package/esm/fsm-api-ts/stoker-src/openapi/helpers/index.js +4 -0
  81. package/esm/fsm-api-ts/stoker-src/openapi/helpers/json-content-one-of.d.ts +12 -0
  82. package/esm/fsm-api-ts/stoker-src/openapi/helpers/json-content-one-of.js +14 -0
  83. package/esm/fsm-api-ts/stoker-src/openapi/helpers/json-content-required.d.ts +11 -0
  84. package/esm/fsm-api-ts/stoker-src/openapi/helpers/json-content-required.js +8 -0
  85. package/esm/fsm-api-ts/stoker-src/openapi/helpers/json-content.d.ts +10 -0
  86. package/esm/fsm-api-ts/stoker-src/openapi/helpers/json-content.js +11 -0
  87. package/esm/fsm-api-ts/stoker-src/openapi/helpers/one-of.d.ts +3 -0
  88. package/esm/fsm-api-ts/stoker-src/openapi/helpers/one-of.js +13 -0
  89. package/esm/fsm-api-ts/stoker-src/openapi/helpers/types.d.ts +2 -0
  90. package/esm/fsm-api-ts/stoker-src/openapi/helpers/types.js +1 -0
  91. package/esm/fsm-api-ts/stoker-src/openapi/index.d.ts +3 -0
  92. package/esm/fsm-api-ts/stoker-src/openapi/index.js +3 -0
  93. package/esm/fsm-api-ts/stoker-src/openapi/schemas/create-error-schema.d.ts +56 -0
  94. package/esm/fsm-api-ts/stoker-src/openapi/schemas/create-error-schema.js +25 -0
  95. package/esm/fsm-api-ts/stoker-src/openapi/schemas/create-message-object.d.ts +9 -0
  96. package/esm/fsm-api-ts/stoker-src/openapi/schemas/create-message-object.js +11 -0
  97. package/esm/fsm-api-ts/stoker-src/openapi/schemas/id-params.d.ts +9 -0
  98. package/esm/fsm-api-ts/stoker-src/openapi/schemas/id-params.js +13 -0
  99. package/esm/fsm-api-ts/stoker-src/openapi/schemas/id-uuid-params.d.ts +9 -0
  100. package/esm/fsm-api-ts/stoker-src/openapi/schemas/id-uuid-params.js +13 -0
  101. package/esm/fsm-api-ts/stoker-src/openapi/schemas/index.d.ts +5 -0
  102. package/esm/fsm-api-ts/stoker-src/openapi/schemas/index.js +5 -0
  103. package/esm/fsm-api-ts/stoker-src/openapi/schemas/slug-params.d.ts +9 -0
  104. package/esm/fsm-api-ts/stoker-src/openapi/schemas/slug-params.js +18 -0
  105. package/esm/fsm-core-db-ts/src/database.types.d.ts +4 -0
  106. package/esm/fsm-core-db-ts/src/database.types.js +17 -0
  107. package/esm/package.json +3 -0
  108. package/package.json +45 -3
  109. package/script/_dnt.polyfills.d.ts +17 -0
  110. package/script/_dnt.polyfills.js +16 -0
  111. package/script/_dnt.shims.d.ts +5 -0
  112. package/script/_dnt.shims.js +65 -0
  113. package/script/fsm-api-ts/mod.d.ts +2 -0
  114. package/script/fsm-api-ts/mod.js +10 -0
  115. package/script/fsm-api-ts/src/cli/version.node.d.ts +1 -0
  116. package/script/fsm-api-ts/src/cli/version.node.js +5 -0
  117. package/script/package.json +3 -0
  118. package/README.md +0 -3
@@ -0,0 +1,372 @@
1
+ // Copyright 2018-2026 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ const FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.*))?$/s;
4
+ const LETTER_REGEXP = /[A-Za-z]/;
5
+ const NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
6
+ const HYPHEN_REGEXP = /^(-|--)[^-]/;
7
+ const VALUE_REGEXP = /=(?<value>.+)/;
8
+ const FLAG_NAME_REGEXP = /^--[^=]+$/;
9
+ const SPECIAL_CHAR_REGEXP = /\W/;
10
+ const NON_WHITESPACE_REGEXP = /\S/;
11
+ function isNumber(string) {
12
+ return NON_WHITESPACE_REGEXP.test(string) && Number.isFinite(Number(string));
13
+ }
14
+ function isConstructorOrProto(obj, key) {
15
+ return (key === "constructor" && typeof obj[key] === "function") ||
16
+ key === "__proto__";
17
+ }
18
+ function setNested(object, keys, value, collect = false) {
19
+ keys = [...keys];
20
+ const key = keys.pop();
21
+ for (const k of keys) {
22
+ if (isConstructorOrProto(object, k))
23
+ return;
24
+ object = (object[k] ??= {});
25
+ }
26
+ if (isConstructorOrProto(object, key))
27
+ return;
28
+ if (collect) {
29
+ const v = object[key];
30
+ if (Array.isArray(v)) {
31
+ v.push(value);
32
+ return;
33
+ }
34
+ value = v ? [v, value] : [value];
35
+ }
36
+ object[key] = value;
37
+ }
38
+ function hasNested(object, keys) {
39
+ for (const key of keys) {
40
+ const value = object[key];
41
+ if (!Object.hasOwn(object, key))
42
+ return false;
43
+ object = value;
44
+ }
45
+ return true;
46
+ }
47
+ function aliasIsBoolean(aliasMap, booleanSet, key) {
48
+ const set = aliasMap.get(key);
49
+ if (set === undefined)
50
+ return false;
51
+ for (const alias of set)
52
+ if (booleanSet.has(alias))
53
+ return true;
54
+ return false;
55
+ }
56
+ function isBooleanString(value) {
57
+ return value === "true" || value === "false";
58
+ }
59
+ function parseBooleanString(value) {
60
+ return value !== "false";
61
+ }
62
+ /**
63
+ * Take a set of command line arguments, optionally with a set of options, and
64
+ * return an object representing the flags found in the passed arguments.
65
+ *
66
+ * By default, any arguments starting with `-` or `--` are considered boolean
67
+ * flags. If the argument name is followed by an equal sign (`=`) it is
68
+ * considered a key-value pair. Any arguments which could not be parsed are
69
+ * available in the `_` property of the returned object.
70
+ *
71
+ * By default, this module tries to determine the type of all arguments
72
+ * automatically and the return type of this function will have an index
73
+ * signature with `any` as value (`{ [x: string]: any }`).
74
+ *
75
+ * If the `string`, `boolean` or `collect` option is set, the return value of
76
+ * this function will be fully typed and the index signature of the return
77
+ * type will change to `{ [x: string]: unknown }`.
78
+ *
79
+ * Any arguments after `'--'` will not be parsed and will end up in `parsedArgs._`.
80
+ *
81
+ * Numeric-looking arguments will be returned as numbers unless `options.string`
82
+ * or `options.boolean` is set for that argument name.
83
+ *
84
+ * See {@linkcode ParseOptions} for more information.
85
+ *
86
+ * @param args An array of command line arguments.
87
+ * @param options Options for the parse function.
88
+ *
89
+ * @typeParam TArgs Type of result.
90
+ * @typeParam TDoubleDash Used by `TArgs` for the result.
91
+ * @typeParam TBooleans Used by `TArgs` for the result.
92
+ * @typeParam TStrings Used by `TArgs` for the result.
93
+ * @typeParam TCollectable Used by `TArgs` for the result.
94
+ * @typeParam TNegatable Used by `TArgs` for the result.
95
+ * @typeParam TDefaults Used by `TArgs` for the result.
96
+ * @typeParam TAliases Used by `TArgs` for the result.
97
+ * @typeParam TAliasArgNames Used by `TArgs` for the result.
98
+ * @typeParam TAliasNames Used by `TArgs` for the result.
99
+ *
100
+ * @return The parsed arguments.
101
+ *
102
+ * @example Usage
103
+ * ```ts
104
+ * import { parseArgs } from "@std/cli/parse-args";
105
+ * import { assertEquals } from "@std/assert/equals";
106
+ *
107
+ * // For proper use, one should use `parseArgs(Deno.args)`
108
+ * assertEquals(parseArgs(["--foo", "--bar=baz", "./quux.txt"]), {
109
+ * foo: true,
110
+ * bar: "baz",
111
+ * _: ["./quux.txt"],
112
+ * });
113
+ * ```
114
+ *
115
+ * @example `string` and `boolean` options
116
+ *
117
+ * Use `string` and `boolean` options to specify the type of the argument.
118
+ *
119
+ * ```ts
120
+ * import { parseArgs } from "@std/cli/parse-args";
121
+ * import { assertEquals } from "@std/assert/equals";
122
+ *
123
+ * const args = parseArgs(["--foo", "--bar", "baz"], {
124
+ * boolean: ["foo"],
125
+ * string: ["bar"],
126
+ * });
127
+ *
128
+ * assertEquals(args, { foo: true, bar: "baz", _: [] });
129
+ * ```
130
+ *
131
+ * @example `collect` option
132
+ *
133
+ * `collect` option tells the parser to treat the option as an array. All
134
+ * values will be collected into one array. If a non-collectable option is used
135
+ * multiple times, the last value is used.
136
+ *
137
+ * ```ts
138
+ * import { parseArgs } from "@std/cli/parse-args";
139
+ * import { assertEquals } from "@std/assert/equals";
140
+ *
141
+ * const args = parseArgs(["--foo", "bar", "--foo", "baz"], {
142
+ * collect: ["foo"],
143
+ * });
144
+ *
145
+ * assertEquals(args, { foo: ["bar", "baz"], _: [] });
146
+ * ```
147
+ *
148
+ * @example `negatable` option
149
+ *
150
+ * `negatable` option tells the parser to treat the option can be negated by
151
+ * prefixing them with `--no-`, like `--no-config`.
152
+ *
153
+ * ```ts
154
+ * import { parseArgs } from "@std/cli/parse-args";
155
+ * import { assertEquals } from "@std/assert/equals";
156
+ *
157
+ * const args = parseArgs(["--no-foo"], {
158
+ * boolean: ["foo"],
159
+ * negatable: ["foo"],
160
+ * });
161
+ *
162
+ * assertEquals(args, { foo: false, _: [] });
163
+ * ```
164
+ */
165
+ export function parseArgs(args, options) {
166
+ const { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], collect = [], negatable = [], unknown: unknownFn = (i) => i, } = options ?? {};
167
+ const aliasMap = new Map();
168
+ const booleanSet = new Set();
169
+ const stringSet = new Set();
170
+ const collectSet = new Set();
171
+ const negatableSet = new Set();
172
+ let allBools = false;
173
+ if (alias) {
174
+ for (const [key, value] of Object.entries(alias)) {
175
+ if (value === undefined) {
176
+ throw new TypeError("Alias value must be defined");
177
+ }
178
+ const aliases = Array.isArray(value) ? value : [value];
179
+ aliasMap.set(key, new Set(aliases));
180
+ aliases.forEach((alias) => aliasMap.set(alias, new Set([key, ...aliases.filter((it) => it !== alias)])));
181
+ }
182
+ }
183
+ if (boolean) {
184
+ if (typeof boolean === "boolean") {
185
+ allBools = boolean;
186
+ }
187
+ else {
188
+ const booleanArgs = Array.isArray(boolean) ? boolean : [boolean];
189
+ for (const key of booleanArgs.filter(Boolean)) {
190
+ booleanSet.add(key);
191
+ aliasMap.get(key)?.forEach((al) => {
192
+ booleanSet.add(al);
193
+ });
194
+ }
195
+ }
196
+ }
197
+ if (string) {
198
+ const stringArgs = Array.isArray(string) ? string : [string];
199
+ for (const key of stringArgs.filter(Boolean)) {
200
+ stringSet.add(key);
201
+ aliasMap.get(key)?.forEach((al) => stringSet.add(al));
202
+ }
203
+ }
204
+ if (collect) {
205
+ const collectArgs = Array.isArray(collect) ? collect : [collect];
206
+ for (const key of collectArgs.filter(Boolean)) {
207
+ collectSet.add(key);
208
+ aliasMap.get(key)?.forEach((al) => collectSet.add(al));
209
+ }
210
+ }
211
+ if (negatable) {
212
+ const negatableArgs = Array.isArray(negatable) ? negatable : [negatable];
213
+ for (const key of negatableArgs.filter(Boolean)) {
214
+ negatableSet.add(key);
215
+ aliasMap.get(key)?.forEach((alias) => negatableSet.add(alias));
216
+ }
217
+ }
218
+ const argv = { _: [] };
219
+ function setArgument(key, value, arg, collect) {
220
+ if (!booleanSet.has(key) &&
221
+ !stringSet.has(key) &&
222
+ !aliasMap.has(key) &&
223
+ !collectSet.has(key) &&
224
+ !(allBools && FLAG_NAME_REGEXP.test(arg)) &&
225
+ unknownFn?.(arg, key, value) === false) {
226
+ return;
227
+ }
228
+ if (typeof value === "string" && !stringSet.has(key)) {
229
+ value = isNumber(value) ? Number(value) : value;
230
+ }
231
+ const collectable = collect && collectSet.has(key);
232
+ setNested(argv, key.split("."), value, collectable);
233
+ aliasMap.get(key)?.forEach((key) => {
234
+ setNested(argv, key.split("."), value, collectable);
235
+ });
236
+ }
237
+ let notFlags = [];
238
+ // all args after "--" are not parsed
239
+ const index = args.indexOf("--");
240
+ if (index !== -1) {
241
+ notFlags = args.slice(index + 1);
242
+ args = args.slice(0, index);
243
+ }
244
+ argsLoop: for (let i = 0; i < args.length; i++) {
245
+ const arg = args[i];
246
+ const groups = arg.match(FLAG_REGEXP)?.groups;
247
+ if (groups) {
248
+ const { doubleDash, negated } = groups;
249
+ let key = groups.key;
250
+ let value = groups.value;
251
+ if (doubleDash) {
252
+ if (value != null) {
253
+ if (booleanSet.has(key))
254
+ value = parseBooleanString(value);
255
+ setArgument(key, value, arg, true);
256
+ continue;
257
+ }
258
+ if (negated) {
259
+ if (negatableSet.has(key)) {
260
+ setArgument(key, false, arg, false);
261
+ continue;
262
+ }
263
+ key = `no-${key}`;
264
+ }
265
+ const next = args[i + 1];
266
+ if (next) {
267
+ if (!booleanSet.has(key) &&
268
+ !allBools &&
269
+ !next.startsWith("-") &&
270
+ (!aliasMap.has(key) || !aliasIsBoolean(aliasMap, booleanSet, key))) {
271
+ value = next;
272
+ i++;
273
+ setArgument(key, value, arg, true);
274
+ continue;
275
+ }
276
+ if (isBooleanString(next)) {
277
+ value = parseBooleanString(next);
278
+ i++;
279
+ setArgument(key, value, arg, true);
280
+ continue;
281
+ }
282
+ }
283
+ value = stringSet.has(key) ? "" : true;
284
+ setArgument(key, value, arg, true);
285
+ continue;
286
+ }
287
+ const letters = arg.slice(1, -1).split("");
288
+ for (const [j, letter] of letters.entries()) {
289
+ const next = arg.slice(j + 2);
290
+ if (next === "-") {
291
+ setArgument(letter, next, arg, true);
292
+ continue;
293
+ }
294
+ if (next === "=") {
295
+ setArgument(letter, "", arg, true);
296
+ continue argsLoop;
297
+ }
298
+ if (LETTER_REGEXP.test(letter)) {
299
+ const groups = VALUE_REGEXP.exec(next)?.groups;
300
+ if (groups) {
301
+ setArgument(letter, groups.value, arg, true);
302
+ continue argsLoop;
303
+ }
304
+ if (NUMBER_REGEXP.test(next)) {
305
+ setArgument(letter, next, arg, true);
306
+ continue argsLoop;
307
+ }
308
+ }
309
+ if (letters[j + 1]?.match(SPECIAL_CHAR_REGEXP)) {
310
+ setArgument(letter, arg.slice(j + 2), arg, true);
311
+ continue argsLoop;
312
+ }
313
+ setArgument(letter, stringSet.has(letter) ? "" : true, arg, true);
314
+ }
315
+ key = arg.slice(-1);
316
+ if (key === "-")
317
+ continue;
318
+ const nextArg = args[i + 1];
319
+ if (nextArg) {
320
+ if (!HYPHEN_REGEXP.test(nextArg) &&
321
+ !booleanSet.has(key) &&
322
+ (!aliasMap.has(key) || !aliasIsBoolean(aliasMap, booleanSet, key))) {
323
+ setArgument(key, nextArg, arg, true);
324
+ i++;
325
+ continue;
326
+ }
327
+ if (isBooleanString(nextArg)) {
328
+ const value = parseBooleanString(nextArg);
329
+ setArgument(key, value, arg, true);
330
+ i++;
331
+ continue;
332
+ }
333
+ }
334
+ setArgument(key, stringSet.has(key) ? "" : true, arg, true);
335
+ continue;
336
+ }
337
+ if (unknownFn?.(arg) !== false) {
338
+ argv._.push(stringSet.has("_") || !isNumber(arg) ? arg : Number(arg));
339
+ }
340
+ if (stopEarly) {
341
+ argv._.push(...args.slice(i + 1));
342
+ break;
343
+ }
344
+ }
345
+ for (const [key, value] of Object.entries(defaults)) {
346
+ const keys = key.split(".");
347
+ if (!hasNested(argv, keys)) {
348
+ setNested(argv, keys, value);
349
+ aliasMap.get(key)?.forEach((key) => setNested(argv, key.split("."), value));
350
+ }
351
+ }
352
+ for (const key of booleanSet.keys()) {
353
+ const keys = key.split(".");
354
+ if (!hasNested(argv, keys)) {
355
+ const value = collectSet.has(key) ? [] : false;
356
+ setNested(argv, keys, value);
357
+ }
358
+ }
359
+ for (const key of stringSet.keys()) {
360
+ const keys = key.split(".");
361
+ if (!hasNested(argv, keys) && collectSet.has(key)) {
362
+ setNested(argv, keys, []);
363
+ }
364
+ }
365
+ if (doubleDash) {
366
+ argv["--"] = notFlags;
367
+ }
368
+ else {
369
+ argv._.push(...notFlags);
370
+ }
371
+ return argv;
372
+ }
@@ -0,0 +1,143 @@
1
+ import { z } from "zod";
2
+ declare const EnvSchema: z.ZodEffects<z.ZodObject<{
3
+ NODE_ENV: z.ZodDefault<z.ZodString>;
4
+ PORT: z.ZodDefault<z.ZodNumber>;
5
+ LOG_LEVEL: z.ZodDefault<z.ZodEnum<["debug", "info", "warning", "error", "fatal", "silent"]>>;
6
+ LOG_LEVEL_API: z.ZodOptional<z.ZodEnum<["debug", "info", "warning", "error", "fatal", "silent"]>>;
7
+ LOG_LEVEL_WORKER: z.ZodOptional<z.ZodEnum<["debug", "info", "warning", "error", "fatal", "silent"]>>;
8
+ LOG_LEVEL_COMPILER: z.ZodOptional<z.ZodEnum<["debug", "info", "warning", "error", "fatal", "silent"]>>;
9
+ LOG_LEVEL_DB: z.ZodOptional<z.ZodEnum<["debug", "info", "warning", "error", "fatal", "silent"]>>;
10
+ DB_TYPE: z.ZodDefault<z.ZodEnum<["postgres", "supabase", "supabase_and_postgres"]>>;
11
+ SUPABASE_URL: z.ZodOptional<z.ZodString>;
12
+ SUPABASE_SERVICE_ROLE_KEY: z.ZodOptional<z.ZodString>;
13
+ SUPABASE_ANON_KEY: z.ZodOptional<z.ZodString>;
14
+ DATABASE_URL: z.ZodString;
15
+ DATABASE_AUTH_TOKEN: z.ZodOptional<z.ZodString>;
16
+ CORS_ORIGIN: z.ZodDefault<z.ZodString>;
17
+ PARSEFSM: z.ZodDefault<z.ZodOptional<z.ZodString>>;
18
+ OTEL_DENO: z.ZodDefault<z.ZodOptional<z.ZodString>>;
19
+ OTEL_EXPORTER_OTLP_ENDPOINT: z.ZodOptional<z.ZodString>;
20
+ OTEL_SERVICE_NAME: z.ZodDefault<z.ZodString>;
21
+ PGFSM_SOURCE_URL: z.ZodDefault<z.ZodString>;
22
+ PGFSM_NO_AUTH: z.ZodEffects<z.ZodDefault<z.ZodEnum<["true", "false"]>>, boolean, "true" | "false" | undefined>;
23
+ PGFSM_ENABLE_ADMIN_API: z.ZodEffects<z.ZodDefault<z.ZodEnum<["true", "false"]>>, boolean, "true" | "false" | undefined>;
24
+ PGFSM_AUTH_CACHE_TTL_MS: z.ZodDefault<z.ZodNumber>;
25
+ }, "strip", z.ZodTypeAny, {
26
+ NODE_ENV: string;
27
+ PORT: number;
28
+ LOG_LEVEL: "error" | "debug" | "info" | "warning" | "fatal" | "silent";
29
+ DB_TYPE: "postgres" | "supabase" | "supabase_and_postgres";
30
+ DATABASE_URL: string;
31
+ CORS_ORIGIN: string;
32
+ PARSEFSM: string;
33
+ OTEL_DENO: string;
34
+ OTEL_SERVICE_NAME: string;
35
+ PGFSM_SOURCE_URL: string;
36
+ PGFSM_NO_AUTH: boolean;
37
+ PGFSM_ENABLE_ADMIN_API: boolean;
38
+ PGFSM_AUTH_CACHE_TTL_MS: number;
39
+ LOG_LEVEL_API?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
40
+ LOG_LEVEL_WORKER?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
41
+ LOG_LEVEL_COMPILER?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
42
+ LOG_LEVEL_DB?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
43
+ SUPABASE_URL?: string | undefined;
44
+ SUPABASE_SERVICE_ROLE_KEY?: string | undefined;
45
+ SUPABASE_ANON_KEY?: string | undefined;
46
+ DATABASE_AUTH_TOKEN?: string | undefined;
47
+ OTEL_EXPORTER_OTLP_ENDPOINT?: string | undefined;
48
+ }, {
49
+ DATABASE_URL: string;
50
+ NODE_ENV?: string | undefined;
51
+ PORT?: number | undefined;
52
+ LOG_LEVEL?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
53
+ LOG_LEVEL_API?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
54
+ LOG_LEVEL_WORKER?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
55
+ LOG_LEVEL_COMPILER?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
56
+ LOG_LEVEL_DB?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
57
+ DB_TYPE?: "postgres" | "supabase" | "supabase_and_postgres" | undefined;
58
+ SUPABASE_URL?: string | undefined;
59
+ SUPABASE_SERVICE_ROLE_KEY?: string | undefined;
60
+ SUPABASE_ANON_KEY?: string | undefined;
61
+ DATABASE_AUTH_TOKEN?: string | undefined;
62
+ CORS_ORIGIN?: string | undefined;
63
+ PARSEFSM?: string | undefined;
64
+ OTEL_DENO?: string | undefined;
65
+ OTEL_EXPORTER_OTLP_ENDPOINT?: string | undefined;
66
+ OTEL_SERVICE_NAME?: string | undefined;
67
+ PGFSM_SOURCE_URL?: string | undefined;
68
+ PGFSM_NO_AUTH?: "true" | "false" | undefined;
69
+ PGFSM_ENABLE_ADMIN_API?: "true" | "false" | undefined;
70
+ PGFSM_AUTH_CACHE_TTL_MS?: number | undefined;
71
+ }>, {
72
+ NODE_ENV: string;
73
+ PORT: number;
74
+ LOG_LEVEL: "error" | "debug" | "info" | "warning" | "fatal" | "silent";
75
+ DB_TYPE: "postgres" | "supabase" | "supabase_and_postgres";
76
+ DATABASE_URL: string;
77
+ CORS_ORIGIN: string;
78
+ PARSEFSM: string;
79
+ OTEL_DENO: string;
80
+ OTEL_SERVICE_NAME: string;
81
+ PGFSM_SOURCE_URL: string;
82
+ PGFSM_NO_AUTH: boolean;
83
+ PGFSM_ENABLE_ADMIN_API: boolean;
84
+ PGFSM_AUTH_CACHE_TTL_MS: number;
85
+ LOG_LEVEL_API?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
86
+ LOG_LEVEL_WORKER?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
87
+ LOG_LEVEL_COMPILER?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
88
+ LOG_LEVEL_DB?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
89
+ SUPABASE_URL?: string | undefined;
90
+ SUPABASE_SERVICE_ROLE_KEY?: string | undefined;
91
+ SUPABASE_ANON_KEY?: string | undefined;
92
+ DATABASE_AUTH_TOKEN?: string | undefined;
93
+ OTEL_EXPORTER_OTLP_ENDPOINT?: string | undefined;
94
+ }, {
95
+ DATABASE_URL: string;
96
+ NODE_ENV?: string | undefined;
97
+ PORT?: number | undefined;
98
+ LOG_LEVEL?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
99
+ LOG_LEVEL_API?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
100
+ LOG_LEVEL_WORKER?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
101
+ LOG_LEVEL_COMPILER?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
102
+ LOG_LEVEL_DB?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
103
+ DB_TYPE?: "postgres" | "supabase" | "supabase_and_postgres" | undefined;
104
+ SUPABASE_URL?: string | undefined;
105
+ SUPABASE_SERVICE_ROLE_KEY?: string | undefined;
106
+ SUPABASE_ANON_KEY?: string | undefined;
107
+ DATABASE_AUTH_TOKEN?: string | undefined;
108
+ CORS_ORIGIN?: string | undefined;
109
+ PARSEFSM?: string | undefined;
110
+ OTEL_DENO?: string | undefined;
111
+ OTEL_EXPORTER_OTLP_ENDPOINT?: string | undefined;
112
+ OTEL_SERVICE_NAME?: string | undefined;
113
+ PGFSM_SOURCE_URL?: string | undefined;
114
+ PGFSM_NO_AUTH?: "true" | "false" | undefined;
115
+ PGFSM_ENABLE_ADMIN_API?: "true" | "false" | undefined;
116
+ PGFSM_AUTH_CACHE_TTL_MS?: number | undefined;
117
+ }>;
118
+ export type env = z.infer<typeof EnvSchema>;
119
+ declare const _default: {
120
+ NODE_ENV: string;
121
+ PORT: number;
122
+ LOG_LEVEL: "error" | "debug" | "info" | "warning" | "fatal" | "silent";
123
+ DB_TYPE: "postgres" | "supabase" | "supabase_and_postgres";
124
+ DATABASE_URL: string;
125
+ CORS_ORIGIN: string;
126
+ PARSEFSM: string;
127
+ OTEL_DENO: string;
128
+ OTEL_SERVICE_NAME: string;
129
+ PGFSM_SOURCE_URL: string;
130
+ PGFSM_NO_AUTH: boolean;
131
+ PGFSM_ENABLE_ADMIN_API: boolean;
132
+ PGFSM_AUTH_CACHE_TTL_MS: number;
133
+ LOG_LEVEL_API?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
134
+ LOG_LEVEL_WORKER?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
135
+ LOG_LEVEL_COMPILER?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
136
+ LOG_LEVEL_DB?: "error" | "debug" | "info" | "warning" | "fatal" | "silent" | undefined;
137
+ SUPABASE_URL?: string | undefined;
138
+ SUPABASE_SERVICE_ROLE_KEY?: string | undefined;
139
+ SUPABASE_ANON_KEY?: string | undefined;
140
+ DATABASE_AUTH_TOKEN?: string | undefined;
141
+ OTEL_EXPORTER_OTLP_ENDPOINT?: string | undefined;
142
+ };
143
+ export default _default;
@@ -0,0 +1,72 @@
1
+ import { z } from "zod";
2
+ // Reads the process environment once, at import. The CLI loads --env-file
3
+ // (default ./.env) into it first; the dev entry (deno.ts) gets it from
4
+ // `deno run --env-file`.
5
+ const LogTapeLevel = z.enum([
6
+ "debug",
7
+ "info",
8
+ "warning",
9
+ "error",
10
+ "fatal",
11
+ "silent",
12
+ ]);
13
+ const EnvSchema = z.object({
14
+ NODE_ENV: z.string().default("development"),
15
+ PORT: z.coerce.number().default(9999),
16
+ LOG_LEVEL: LogTapeLevel.default("info"),
17
+ LOG_LEVEL_API: LogTapeLevel.optional(),
18
+ LOG_LEVEL_WORKER: LogTapeLevel.optional(),
19
+ LOG_LEVEL_COMPILER: LogTapeLevel.optional(),
20
+ LOG_LEVEL_DB: LogTapeLevel.optional(),
21
+ DB_TYPE: z.enum(["postgres", "supabase", "supabase_and_postgres"]).default("postgres"),
22
+ // Only for DB_TYPE=supabase / supabase_and_postgres (with --no-auth).
23
+ SUPABASE_URL: z.string().url().optional(),
24
+ SUPABASE_SERVICE_ROLE_KEY: z.string().min(1).optional(),
25
+ SUPABASE_ANON_KEY: z.string().min(1).optional(),
26
+ DATABASE_URL: z.string().url(),
27
+ DATABASE_AUTH_TOKEN: z.string().optional(),
28
+ CORS_ORIGIN: z.string().url().default("http://localhost:5173"),
29
+ PARSEFSM: z.string().optional().default("false"),
30
+ OTEL_DENO: z.string().optional().default("false"),
31
+ OTEL_EXPORTER_OTLP_ENDPOINT: z.string().url().optional(),
32
+ OTEL_SERVICE_NAME: z.string().default("pgfsm-api"),
33
+ // Where the running API's source is (SPEC-017, AGPL-3.0 §13): GET / and the
34
+ // OpenAPI document report it. A modified API points it at its own source.
35
+ PGFSM_SOURCE_URL: z.string().url().default("https://github.com/pgfsm/fsm"),
36
+ // SPEC-009 §3. Auth is on unless PGFSM_NO_AUTH=true (refused in production).
37
+ PGFSM_NO_AUTH: z.enum(["true", "false"]).default("false").transform((v) => v === "true"),
38
+ PGFSM_ENABLE_ADMIN_API: z.enum(["true", "false"]).default("false")
39
+ .transform((v) => v === "true"),
40
+ // Key-verification cache; also the upper bound on revocation latency.
41
+ PGFSM_AUTH_CACHE_TTL_MS: z.coerce.number().int().min(0).max(30_000)
42
+ .default(30_000),
43
+ }).superRefine((input, ctx) => {
44
+ if (input.DB_TYPE !== "postgres") {
45
+ for (const key of ["SUPABASE_URL", "SUPABASE_ANON_KEY"]) {
46
+ if (!input[key]) {
47
+ ctx.addIssue({
48
+ code: z.ZodIssueCode.custom,
49
+ path: [key],
50
+ message: `Must be set when DB_TYPE is '${input.DB_TYPE}'`,
51
+ });
52
+ }
53
+ }
54
+ }
55
+ if (input.NODE_ENV === "production" && !input.DATABASE_AUTH_TOKEN) {
56
+ ctx.addIssue({
57
+ code: z.ZodIssueCode.invalid_type,
58
+ expected: "string",
59
+ received: "undefined",
60
+ path: ["DATABASE_AUTH_TOKEN"],
61
+ message: "Must be set when NODE_ENV is 'production'",
62
+ });
63
+ }
64
+ });
65
+ // eslint-disable-next-line ts/no-redeclare
66
+ const { data: env, error } = EnvSchema.safeParse(process.env);
67
+ if (error) {
68
+ console.error("❌ Invalid env:");
69
+ console.error(JSON.stringify(error.flatten().fieldErrors, null, 2));
70
+ process.exit(1);
71
+ }
72
+ export default env;
@@ -0,0 +1,3 @@
1
+ import { type LicenseNotice } from "./license.js";
2
+ import type { AppOpenAPI } from "./types.js";
3
+ export default function configureOpenAPI(app: AppOpenAPI, basePath?: string, notice?: LicenseNotice): void;
@@ -0,0 +1,25 @@
1
+ import { apiReference } from "@scalar/hono-api-reference";
2
+ import { LICENSE_URL, licenseNotice } from "./license.js";
3
+ export default function configureOpenAPI(app, basePath = "", notice = licenseNotice()) {
4
+ const prefixed = basePath || "";
5
+ const specUrl = `${prefixed}/openapi`;
6
+ app.doc("/openapi", {
7
+ openapi: "3.0.0",
8
+ info: {
9
+ version: "1.0.0",
10
+ title: "FSM API",
11
+ // SPEC-017: the API's licence and, for AGPL-3.0 §13, its source.
12
+ license: { name: notice.license, url: LICENSE_URL },
13
+ },
14
+ externalDocs: { description: "Source code", url: notice.source },
15
+ servers: [{ url: prefixed || "/" }],
16
+ });
17
+ app.get("/docs", apiReference({
18
+ theme: "kepler",
19
+ layout: "classic",
20
+ defaultHttpClient: { targetKey: "js", clientKey: "fetch" },
21
+ // @scalar/hono-api-reference v0.9 takes `url` directly (the old
22
+ // `spec: { url }` wrapper was removed).
23
+ url: specUrl,
24
+ }));
25
+ }
@@ -0,0 +1,15 @@
1
+ export declare const ZOD_ERROR_MESSAGES: {
2
+ REQUIRED: string;
3
+ EXPECTED_NUMBER: string;
4
+ NO_UPDATES: string;
5
+ };
6
+ export declare const ZOD_ERROR_CODES: {
7
+ INVALID_UPDATES: string;
8
+ };
9
+ export declare const notFoundSchema: import("zod").ZodObject<{
10
+ message: import("zod").ZodString;
11
+ }, "strip", import("zod").ZodTypeAny, {
12
+ message: string;
13
+ }, {
14
+ message: string;
15
+ }>;
@@ -0,0 +1,11 @@
1
+ import * as HttpStatusPhrases from "../stoker-src/http-status-phrases.js";
2
+ import { createMessageObjectSchema } from "../stoker-src/openapi/schemas/index.js";
3
+ export const ZOD_ERROR_MESSAGES = {
4
+ REQUIRED: "Required",
5
+ EXPECTED_NUMBER: "Expected number, received nan",
6
+ NO_UPDATES: "No updates provided",
7
+ };
8
+ export const ZOD_ERROR_CODES = {
9
+ INVALID_UPDATES: "invalid_updates",
10
+ };
11
+ export const notFoundSchema = createMessageObjectSchema(HttpStatusPhrases.NOT_FOUND);
@@ -0,0 +1,19 @@
1
+ import { Pool } from "pg";
2
+ import { createRouter } from "./create-router.js";
3
+ export { createRouter };
4
+ export type CreateAppOptions = {
5
+ /** Pool the API runs requests on. Default: a new Pool on DATABASE_URL. */
6
+ pool?: Pool;
7
+ /** Require API keys (SPEC-009 §3). Default: on, unless PGFSM_NO_AUTH. */
8
+ auth?: boolean;
9
+ /** Mount /admin/* routes. Default: PGFSM_ENABLE_ADMIN_API. */
10
+ adminApi?: boolean;
11
+ /** Key-verification cache TTL in ms. Default: PGFSM_AUTH_CACHE_TTL_MS. */
12
+ authCacheTtlMs?: number;
13
+ };
14
+ /**
15
+ * The REST API. It only serves HTTP: fsmlets run as separate worker
16
+ * processes (root CLAUDE.md #3; the API used to embed one, which stopped
17
+ * compiling once the fsmlet moved to compiled registries in #341).
18
+ */
19
+ export default function createApp(basePath?: string, options?: CreateAppOptions): Promise<import("@hono/zod-openapi").OpenAPIHono<import("./types.js").AppBindings, {}, "/">>;