@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,108 @@
1
+ import * as HttpStatusCodes from "../../stoker-src/http-status-codes.js";
2
+ import { getLogger } from "@logtape/logtape";
3
+ import { createFsmInstanceFromName, getFSMData, getFsmDataResolveStateValue, listFsmInstances, resumeEventForFsmWorker, sendEventToFsmQueueWithEventLogs, stopEventForFsmWorker, } from "@pgfsm/db";
4
+ const logger = getLogger(["@pgfsm/api", "instances"]);
5
+ const NOT_FOUND = { message: "FSM instance not found" };
6
+ const UNEXPECTED = { error: "Unexpected error" };
7
+ // Every route runs inside the API key's role (SPEC-009 §3): `db` is that
8
+ // role's transaction, set by the auth middleware.
9
+ // Some Hono/zod-openapi resolutions (an older deno.lock) hit TS2589 "type
10
+ // instantiation is excessively deep" on this assignment; CI's fresh resolution
11
+ // doesn't. @ts-ignore, not @ts-expect-error: it must pass in both. The body
12
+ // stays fully typed.
13
+ // @ts-ignore TS2589 under some dependency resolutions (see above)
14
+ export const list = async (c) => {
15
+ const deps = { db: c.get("db"), useSupabase: false };
16
+ const q = c.req.valid("query");
17
+ const instances = await listFsmInstances(deps, {
18
+ fsmName: q.fsm_name,
19
+ fsmVersion: q.fsm_version,
20
+ status: q.status,
21
+ limit: q.limit,
22
+ });
23
+ return c.json({ data: instances }, HttpStatusCodes.OK);
24
+ };
25
+ export const getOne = async (c) => {
26
+ const deps = { db: c.get("db"), useSupabase: false };
27
+ const { id } = c.req.valid("param");
28
+ try {
29
+ // get_fsm_data_resolve_state_value_v2 raises for an unknown id, so check
30
+ // first: an unknown instance is a 404, as on every /instances/{id} route.
31
+ if (!(await getFSMData(deps, id))) {
32
+ return c.json(NOT_FOUND, HttpStatusCodes.NOT_FOUND);
33
+ }
34
+ const result = await getFsmDataResolveStateValue(deps, id);
35
+ if (!result)
36
+ return c.json(NOT_FOUND, HttpStatusCodes.NOT_FOUND);
37
+ return c.json({ data: result }, HttpStatusCodes.OK);
38
+ }
39
+ catch (err) {
40
+ logger.error("GET /instances/{id}: {error}", { id, error: err });
41
+ return c.json(UNEXPECTED, HttpStatusCodes.INTERNAL_SERVER_ERROR);
42
+ }
43
+ };
44
+ // Creates the instance and its pgmq queue, sends initialTransition_event, and
45
+ // enqueues it to fsm_dispatch_queue for the scheduler and an fsmlet.
46
+ export const create = async (c) => {
47
+ const deps = { db: c.get("db"), useSupabase: false };
48
+ const { fsm_name, fsm_version, input } = c.req.valid("json");
49
+ try {
50
+ const instance = await createFsmInstanceFromName(deps, fsm_name, fsm_version, (input ?? {}), true);
51
+ if (!instance?.fsm_instance_id) {
52
+ return c.json({ error: "FSM instance creation failed" }, HttpStatusCodes.INTERNAL_SERVER_ERROR);
53
+ }
54
+ return c.json({ data: instance }, HttpStatusCodes.OK);
55
+ }
56
+ catch (err) {
57
+ logger.error("POST /instances: {error}", { error: err });
58
+ return c.json(UNEXPECTED, HttpStatusCodes.INTERNAL_SERVER_ERROR);
59
+ }
60
+ };
61
+ export const sendEvent = async (c) => {
62
+ const deps = { db: c.get("db"), useSupabase: false };
63
+ const { id } = c.req.valid("param");
64
+ const event = c.req.valid("json");
65
+ try {
66
+ const instance = await getFSMData(deps, id);
67
+ if (!instance)
68
+ return c.json(NOT_FOUND, HttpStatusCodes.NOT_FOUND);
69
+ const data = await sendEventToFsmQueueWithEventLogs(deps, id, instance.fsm_type ?? null, instance.fsm_version ?? null, event.type, "external", event, 0);
70
+ return c.json({ data }, HttpStatusCodes.OK);
71
+ }
72
+ catch (err) {
73
+ logger.error("POST /instances/{id}/events: {error}", { id, error: err });
74
+ return c.json(UNEXPECTED, HttpStatusCodes.INTERNAL_SERVER_ERROR);
75
+ }
76
+ };
77
+ // One call: resume_event_for_fsm_worker_v2 looks up the instance's FSM,
78
+ // re-enqueues it to fsm_dispatch_queue and notifies the scheduler.
79
+ export const resume = async (c) => {
80
+ const deps = { db: c.get("db"), useSupabase: false };
81
+ const { id } = c.req.valid("param");
82
+ try {
83
+ const result = await resumeEventForFsmWorker(deps, id);
84
+ if (result.status === "fsm_not_found") {
85
+ return c.json(NOT_FOUND, HttpStatusCodes.NOT_FOUND);
86
+ }
87
+ return c.json({ data: result }, HttpStatusCodes.OK);
88
+ }
89
+ catch (err) {
90
+ logger.error("POST /instances/{id}/resume: {error}", { id, error: err });
91
+ return c.json(UNEXPECTED, HttpStatusCodes.INTERNAL_SERVER_ERROR);
92
+ }
93
+ };
94
+ export const stop = async (c) => {
95
+ const deps = { db: c.get("db"), useSupabase: false };
96
+ const { id } = c.req.valid("param");
97
+ try {
98
+ if (!(await getFSMData(deps, id))) {
99
+ return c.json(NOT_FOUND, HttpStatusCodes.NOT_FOUND);
100
+ }
101
+ await stopEventForFsmWorker(deps, id);
102
+ return c.json({}, HttpStatusCodes.OK);
103
+ }
104
+ catch (err) {
105
+ logger.error("POST /instances/{id}/stop: {error}", { id, error: err });
106
+ return c.json(UNEXPECTED, HttpStatusCodes.INTERNAL_SERVER_ERROR);
107
+ }
108
+ };
@@ -0,0 +1,237 @@
1
+ declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../lib/types.js").AppBindings, {
2
+ "/instances": {
3
+ $get: {
4
+ input: {
5
+ query: {
6
+ status?: "error" | "active" | "done" | "stopped" | undefined;
7
+ fsm_name?: string | undefined;
8
+ fsm_version?: string | undefined;
9
+ limit?: number | undefined;
10
+ };
11
+ };
12
+ output: {
13
+ error: string;
14
+ };
15
+ outputFormat: "json";
16
+ status: 500;
17
+ } | {
18
+ input: {
19
+ query: {
20
+ status?: "error" | "active" | "done" | "stopped" | undefined;
21
+ fsm_name?: string | undefined;
22
+ fsm_version?: string | undefined;
23
+ limit?: number | undefined;
24
+ };
25
+ };
26
+ output: {
27
+ data: {
28
+ [x: string]: import("hono/utils/types").JSONValue;
29
+ id: string;
30
+ fsm_name: string | null;
31
+ fsm_version: string | null;
32
+ fsm_instance_status?: import("hono/utils/types").JSONValue | undefined;
33
+ }[];
34
+ };
35
+ outputFormat: "json";
36
+ status: 200;
37
+ };
38
+ };
39
+ } & {
40
+ "/instances/:id": {
41
+ $get: {
42
+ input: {
43
+ param: {
44
+ id: string;
45
+ };
46
+ };
47
+ output: {
48
+ error: string;
49
+ };
50
+ outputFormat: "json";
51
+ status: 500;
52
+ } | {
53
+ input: {
54
+ param: {
55
+ id: string;
56
+ };
57
+ };
58
+ output: {
59
+ message: string;
60
+ };
61
+ outputFormat: "json";
62
+ status: 404;
63
+ } | {
64
+ input: {
65
+ param: {
66
+ id: string;
67
+ };
68
+ };
69
+ output: {
70
+ data: {
71
+ fsm_instance_row: {
72
+ [x: string]: import("hono/utils/types").JSONValue;
73
+ };
74
+ resolved_state_value?: import("hono/utils/types").JSONValue | undefined;
75
+ };
76
+ };
77
+ outputFormat: "json";
78
+ status: 200;
79
+ };
80
+ };
81
+ } & {
82
+ "/instances": {
83
+ $post: {
84
+ input: {
85
+ json: {
86
+ fsm_name: string;
87
+ fsm_version: string;
88
+ input?: Record<string, unknown> | undefined;
89
+ };
90
+ };
91
+ output: {
92
+ error: string;
93
+ };
94
+ outputFormat: "json";
95
+ status: 500;
96
+ } | {
97
+ input: {
98
+ json: {
99
+ fsm_name: string;
100
+ fsm_version: string;
101
+ input?: Record<string, unknown> | undefined;
102
+ };
103
+ };
104
+ output: {
105
+ data: {
106
+ [x: string]: import("hono/utils/types").JSONValue;
107
+ };
108
+ };
109
+ outputFormat: "json";
110
+ status: 200;
111
+ };
112
+ };
113
+ } & {
114
+ "/instances/:id/events": {
115
+ $post: {
116
+ input: {
117
+ param: {
118
+ id: string;
119
+ };
120
+ } & {
121
+ json: import("zod").objectInputType<{
122
+ type: import("zod").ZodString;
123
+ }, import("zod").ZodTypeAny, "passthrough">;
124
+ };
125
+ output: {
126
+ error: string;
127
+ };
128
+ outputFormat: "json";
129
+ status: 500;
130
+ } | {
131
+ input: {
132
+ param: {
133
+ id: string;
134
+ };
135
+ } & {
136
+ json: import("zod").objectInputType<{
137
+ type: import("zod").ZodString;
138
+ }, import("zod").ZodTypeAny, "passthrough">;
139
+ };
140
+ output: {
141
+ message: string;
142
+ };
143
+ outputFormat: "json";
144
+ status: 404;
145
+ } | {
146
+ input: {
147
+ param: {
148
+ id: string;
149
+ };
150
+ } & {
151
+ json: import("zod").objectInputType<{
152
+ type: import("zod").ZodString;
153
+ }, import("zod").ZodTypeAny, "passthrough">;
154
+ };
155
+ output: {
156
+ data?: any;
157
+ };
158
+ outputFormat: "json";
159
+ status: 200;
160
+ };
161
+ };
162
+ } & {
163
+ "/instances/:id/resume": {
164
+ $post: {
165
+ input: {
166
+ param: {
167
+ id: string;
168
+ };
169
+ };
170
+ output: {
171
+ error: string;
172
+ };
173
+ outputFormat: "json";
174
+ status: 500;
175
+ } | {
176
+ input: {
177
+ param: {
178
+ id: string;
179
+ };
180
+ };
181
+ output: {
182
+ message: string;
183
+ };
184
+ outputFormat: "json";
185
+ status: 404;
186
+ } | {
187
+ input: {
188
+ param: {
189
+ id: string;
190
+ };
191
+ };
192
+ output: {
193
+ data: {
194
+ [x: string]: import("hono/utils/types").JSONValue;
195
+ };
196
+ };
197
+ outputFormat: "json";
198
+ status: 200;
199
+ };
200
+ };
201
+ } & {
202
+ "/instances/:id/stop": {
203
+ $post: {
204
+ input: {
205
+ param: {
206
+ id: string;
207
+ };
208
+ };
209
+ output: {
210
+ error: string;
211
+ };
212
+ outputFormat: "json";
213
+ status: 500;
214
+ } | {
215
+ input: {
216
+ param: {
217
+ id: string;
218
+ };
219
+ };
220
+ output: {
221
+ message: string;
222
+ };
223
+ outputFormat: "json";
224
+ status: 404;
225
+ } | {
226
+ input: {
227
+ param: {
228
+ id: string;
229
+ };
230
+ };
231
+ output: {};
232
+ outputFormat: "json";
233
+ status: 200;
234
+ };
235
+ };
236
+ }, "/">;
237
+ export default router;
@@ -0,0 +1,11 @@
1
+ import { createRouter } from "../../lib/create-router.js";
2
+ import * as handlers from "./instances.handlers.js";
3
+ import * as routes from "./instances.routes.js";
4
+ const router = createRouter()
5
+ .openapi(routes.list, handlers.list)
6
+ .openapi(routes.getOne, handlers.getOne)
7
+ .openapi(routes.create, handlers.create)
8
+ .openapi(routes.sendEvent, handlers.sendEvent)
9
+ .openapi(routes.resume, handlers.resume)
10
+ .openapi(routes.stop, handlers.stop);
11
+ export default router;