@swirls/looms 0.0.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -2
- package/dist/actor/cell.d.ts +9 -4
- package/dist/actor/cell.js +7 -11
- package/dist/actor/host.d.ts +7 -3
- package/dist/actor/host.js +57 -33
- package/dist/actor/index.d.ts +1 -1
- package/dist/actor/index.js +1 -1
- package/dist/actor/routing.d.ts +12 -1
- package/dist/actor/routing.js +57 -51
- package/dist/agent/agent-session.d.ts +5 -0
- package/dist/agent/agent-session.js +270 -0
- package/dist/agent/debugger/agent-chat.d.ts +2 -0
- package/dist/agent/debugger/agent-chat.js +176 -0
- package/dist/agent/debugger/index.d.ts +5 -0
- package/dist/agent/debugger/index.js +19 -0
- package/dist/agent/debugger/summarize.d.ts +2 -0
- package/dist/agent/debugger/summarize.js +51 -0
- package/dist/agent/debugger/token-usage.d.ts +3 -0
- package/dist/agent/debugger/token-usage.js +11 -0
- package/dist/agent/definitions-store.d.ts +2 -3
- package/dist/agent/definitions-store.js +2 -4
- package/dist/agent/definitions.d.ts +47 -29
- package/dist/agent/definitions.js +39 -12
- package/dist/agent/effects.d.ts +359 -2
- package/dist/agent/effects.js +60 -34
- package/dist/agent/events.d.ts +175 -19
- package/dist/agent/events.js +45 -10
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.js +1 -0
- package/dist/agent/llm.d.ts +11 -2
- package/dist/agent/llm.js +13 -3
- package/dist/agent/module.d.ts +812 -78
- package/dist/agent/module.js +16 -4
- package/dist/agent/scope.d.ts +174 -18
- package/dist/agent/signals.d.ts +26 -1
- package/dist/agent/signals.js +79 -0
- package/dist/agent/threads.d.ts +3 -33
- package/dist/agent/threads.js +20 -25
- package/dist/agent/tool-schema.d.ts +1 -17
- package/dist/agent/tool-schema.js +3 -43
- package/dist/agent/types.d.ts +49 -4
- package/dist/agent/types.js +5 -5
- package/dist/ai-vercel/index.d.ts +1 -0
- package/dist/ai-vercel/index.js +1 -0
- package/dist/ai-vercel/messages.js +22 -7
- package/dist/ai-vercel/vercel-evaluator.d.ts +36 -0
- package/dist/ai-vercel/vercel-evaluator.js +73 -0
- package/dist/ai-vercel/vercel-llm.js +64 -44
- package/dist/approval/debugger/approvals-view.d.ts +3 -0
- package/dist/approval/debugger/approvals-view.js +16 -0
- package/dist/approval/debugger/index.d.ts +4 -0
- package/dist/approval/debugger/index.js +11 -0
- package/dist/approval/debugger/summarize.d.ts +2 -0
- package/dist/approval/debugger/summarize.js +17 -0
- package/dist/approval/effects.d.ts +89 -0
- package/dist/approval/module.d.ts +179 -29
- package/dist/approval/projections.d.ts +0 -14
- package/dist/approval/projections.js +20 -3
- package/dist/approval/signals.d.ts +2 -0
- package/dist/approval/signals.js +18 -2
- package/dist/cli/cli.js +2 -0
- package/dist/cli/commands.js +12 -16
- package/dist/client/client.d.ts +1213 -18
- package/dist/client/client.js +120 -120
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/sse.d.ts +13 -0
- package/dist/client/sse.js +38 -44
- package/dist/cloudflare/alarm-scheduler.d.ts +12 -2
- package/dist/cloudflare/alarm-scheduler.js +34 -7
- package/dist/cloudflare/durable-object.d.ts +10 -2
- package/dist/cloudflare/durable-object.js +59 -28
- package/dist/cloudflare/event-store.d.ts +7 -2
- package/dist/cloudflare/event-store.js +8 -7
- package/dist/cloudflare/index.d.ts +2 -2
- package/dist/cloudflare/index.js +2 -2
- package/dist/cloudflare/router.d.ts +1 -1
- package/dist/cloudflare/router.js +15 -16
- package/dist/core/catalog.d.ts +3 -3
- package/dist/core/catalog.js +2 -5
- package/dist/core/coalesce.js +5 -3
- package/dist/core/compose.d.ts +2 -1
- package/dist/core/compose.js +19 -2
- package/dist/core/debugger-host.d.ts +16 -0
- package/dist/core/debugger-host.js +1 -0
- package/dist/core/definition-store.d.ts +11 -0
- package/dist/core/definition-store.js +6 -0
- package/dist/core/effects.d.ts +127 -15
- package/dist/core/effects.js +89 -17
- package/dist/core/envelope.d.ts +27 -7
- package/dist/core/envelope.js +20 -6
- package/dist/core/event-codec.d.ts +4 -2
- package/dist/core/event-codec.js +10 -5
- package/dist/core/event-index.js +1 -3
- package/dist/core/fold.d.ts +3 -0
- package/dist/core/fold.js +171 -24
- package/dist/core/ids.d.ts +5 -0
- package/dist/core/ids.js +35 -2
- package/dist/core/index.d.ts +7 -1
- package/dist/core/index.js +6 -1
- package/dist/core/kind.d.ts +22 -0
- package/dist/core/kind.js +17 -0
- package/dist/core/limits.d.ts +34 -0
- package/dist/core/limits.js +46 -0
- package/dist/core/match.d.ts +1 -0
- package/dist/core/match.js +10 -1
- package/dist/core/module-scope.d.ts +22 -20
- package/dist/core/module-scope.js +38 -28
- package/dist/core/module.d.ts +18 -5
- package/dist/core/module.js +4 -0
- package/dist/core/projection.d.ts +13 -13
- package/dist/core/projection.js +9 -5
- package/dist/core/protocol.d.ts +68 -11
- package/dist/core/protocol.js +82 -11
- package/dist/core/published.d.ts +43 -0
- package/dist/core/published.js +44 -0
- package/dist/core/replay.d.ts +312 -3
- package/dist/core/replay.js +11 -1
- package/dist/core/schema.d.ts +11 -20
- package/dist/core/schema.js +63 -80
- package/dist/core/serialize.js +2 -4
- package/dist/core/snapshot-store.d.ts +6 -1
- package/dist/core/snapshot-store.js +15 -2
- package/dist/core/snapshots.d.ts +5 -1
- package/dist/core/snapshots.js +10 -15
- package/dist/core/sqlite-store.js +95 -11
- package/dist/core/state.d.ts +142 -4
- package/dist/core/state.js +78 -0
- package/dist/core/store.d.ts +38 -3
- package/dist/core/store.js +77 -22
- package/dist/core/thread.d.ts +10 -9
- package/dist/core/types.d.ts +5 -8
- package/dist/core/types.js +28 -24
- package/dist/core/validate-event.js +14 -4
- package/dist/core/worker-callback.d.ts +17 -0
- package/dist/core/worker-callback.js +1 -0
- package/dist/debugger/app/assets/index-B3Ah8WAE.css +2 -0
- package/dist/debugger/app/assets/index-Qb371t_O.js +22 -0
- package/dist/debugger/app/assets/rolldown-runtime-CbXtAM7H.js +1 -0
- package/dist/debugger/app/assets/routes-CjtEHgPQ.js +47 -0
- package/dist/debugger/app/index.html +14 -0
- package/dist/debugger/components/composer.d.ts +17 -0
- package/dist/debugger/components/composer.js +25 -0
- package/dist/debugger/components/debugger-split.d.ts +2 -1
- package/dist/debugger/components/debugger-split.js +2 -2
- package/dist/debugger/components/event-inspector.d.ts +2 -1
- package/dist/debugger/components/event-inspector.js +25 -16
- package/dist/debugger/components/event-stream.d.ts +2 -1
- package/dist/debugger/components/event-stream.js +14 -74
- package/dist/debugger/components/follow-list.d.ts +19 -0
- package/dist/debugger/components/follow-list.js +96 -0
- package/dist/debugger/components/json-tree.d.ts +11 -0
- package/dist/debugger/components/json-tree.js +120 -0
- package/dist/debugger/components/json-view.js +2 -2
- package/dist/debugger/components/run-tree.js +53 -20
- package/dist/debugger/components/status-dot.d.ts +4 -0
- package/dist/debugger/components/status-dot.js +6 -2
- package/dist/debugger/context.d.ts +14 -0
- package/dist/debugger/context.js +17 -0
- package/dist/debugger/contracts.d.ts +7 -4
- package/dist/debugger/events/builtin-families.d.ts +3 -0
- package/dist/debugger/events/builtin-families.js +9 -0
- package/dist/debugger/events/catalog.d.ts +3 -4
- package/dist/debugger/events/catalog.js +27 -17
- package/dist/debugger/events/protocol-summarize.d.ts +1 -2
- package/dist/debugger/events/protocol-summarize.js +42 -24
- package/dist/debugger/index.d.ts +20 -6
- package/dist/debugger/index.js +19 -5
- package/dist/debugger/lib/cn.d.ts +1 -0
- package/dist/debugger/lib/cn.js +3 -0
- package/dist/debugger/lib/event-meta.d.ts +2 -3
- package/dist/debugger/lib/event-meta.js +6 -12
- package/dist/debugger/lib/json.d.ts +25 -0
- package/dist/debugger/lib/json.js +87 -0
- package/dist/debugger/lib/payload.d.ts +7 -0
- package/dist/debugger/lib/payload.js +11 -0
- package/dist/debugger/lib/time.d.ts +3 -0
- package/dist/debugger/lib/time.js +24 -0
- package/dist/debugger/plugin.d.ts +36 -0
- package/dist/debugger/plugin.js +14 -0
- package/dist/debugger/server/index.d.ts +14 -0
- package/dist/debugger/server/index.js +114 -0
- package/dist/debugger/shell/debugger-shell.d.ts +15 -0
- package/dist/debugger/shell/debugger-shell.js +43 -0
- package/dist/debugger/shell/definition-key.d.ts +3 -0
- package/dist/debugger/shell/definition-key.js +4 -0
- package/dist/debugger/shell/events-pane.d.ts +12 -0
- package/dist/debugger/shell/events-pane.js +25 -0
- package/dist/debugger/shell/projections-panel.d.ts +4 -0
- package/dist/debugger/shell/projections-panel.js +59 -0
- package/dist/debugger/shell/run-controls.d.ts +4 -0
- package/dist/debugger/shell/run-controls.js +72 -0
- package/dist/debugger/shell/run-search.d.ts +6 -0
- package/dist/debugger/shell/run-search.js +102 -0
- package/dist/debugger/shell/run-type-menu.d.ts +6 -0
- package/dist/debugger/shell/run-type-menu.js +11 -0
- package/dist/debugger/shell/schema-form.d.ts +31 -0
- package/dist/debugger/shell/schema-form.js +117 -0
- package/dist/debugger/shell/start-form.d.ts +3 -0
- package/dist/debugger/shell/start-form.js +75 -0
- package/dist/debugger/shell/use-start-run.d.ts +14 -0
- package/dist/debugger/shell/use-start-run.js +32 -0
- package/dist/debugger/shell/workspace.d.ts +6 -0
- package/dist/debugger/shell/workspace.js +15 -0
- package/dist/debugger/styles.css +111 -27
- package/dist/debugger/ui/button.d.ts +24 -0
- package/dist/debugger/ui/button.js +24 -0
- package/dist/debugger/ui/command.d.ts +9 -0
- package/dist/debugger/ui/command.js +24 -0
- package/dist/debugger/ui/dropdown-menu.d.ts +13 -0
- package/dist/debugger/ui/dropdown-menu.js +37 -0
- package/dist/debugger/ui/panel.d.ts +14 -0
- package/dist/debugger/ui/panel.js +16 -0
- package/dist/debugger/ui/popover.d.ts +7 -0
- package/dist/debugger/ui/popover.js +17 -0
- package/dist/debugger/ui/resizable.d.ts +7 -0
- package/dist/debugger/ui/resizable.js +14 -0
- package/dist/debugger/ui/scroll-area.d.ts +2 -1
- package/dist/debugger/ui/scroll-area.js +5 -3
- package/dist/debugger/ui/select.d.ts +10 -0
- package/dist/debugger/ui/select.js +21 -0
- package/dist/debugger/ui/tabs.js +2 -2
- package/dist/debugger/ui/textarea.d.ts +3 -0
- package/dist/debugger/ui/textarea.js +7 -0
- package/dist/evaluator/definitions-store.d.ts +11 -0
- package/dist/evaluator/definitions-store.js +8 -0
- package/dist/evaluator/definitions.d.ts +18 -0
- package/dist/evaluator/definitions.js +4 -0
- package/dist/evaluator/effects.d.ts +226 -0
- package/dist/evaluator/effects.js +132 -0
- package/dist/evaluator/evaluator.d.ts +24 -0
- package/dist/evaluator/evaluator.js +67 -0
- package/dist/evaluator/events.d.ts +59 -0
- package/dist/evaluator/events.js +21 -0
- package/dist/evaluator/index.d.ts +11 -0
- package/dist/evaluator/index.js +11 -0
- package/dist/evaluator/module.d.ts +606 -0
- package/dist/evaluator/module.js +25 -0
- package/dist/evaluator/projections.d.ts +50 -0
- package/dist/evaluator/projections.js +20 -0
- package/dist/evaluator/scope.d.ts +59 -0
- package/dist/evaluator/scope.js +7 -0
- package/dist/evaluator/signals.d.ts +3 -0
- package/dist/evaluator/signals.js +17 -0
- package/dist/evaluator/threads.d.ts +62 -0
- package/dist/evaluator/threads.js +117 -0
- package/dist/evaluator/types.d.ts +125 -0
- package/dist/evaluator/types.js +51 -0
- package/dist/projectors/delivery.d.ts +83 -0
- package/dist/projectors/delivery.js +182 -0
- package/dist/projectors/index-model.d.ts +1 -1
- package/dist/projectors/index-model.js +4 -6
- package/dist/projectors/index.d.ts +2 -0
- package/dist/projectors/index.js +2 -0
- package/dist/projectors/memory.d.ts +1 -1
- package/dist/projectors/memory.js +10 -8
- package/dist/projectors/postgres.js +44 -58
- package/dist/projectors/projector.d.ts +17 -0
- package/dist/projectors/projector.js +26 -1
- package/dist/projectors/sqlite-delivery.d.ts +4 -0
- package/dist/projectors/sqlite-delivery.js +147 -0
- package/dist/projectors/sqlite.js +23 -23
- package/dist/projectors/with-projectors.d.ts +7 -2
- package/dist/projectors/with-projectors.js +27 -28
- package/dist/react/notify.js +11 -8
- package/dist/react/react.d.ts +2 -3
- package/dist/react/react.js +14 -30
- package/dist/react/sse.d.ts +1 -1
- package/dist/react/sse.js +1 -1
- package/dist/react/store.d.ts +3 -3
- package/dist/react/store.js +109 -119
- package/dist/runtime/cancellation.d.ts +16 -0
- package/dist/runtime/cancellation.js +129 -0
- package/dist/runtime/deadline-transition-planner.d.ts +31 -0
- package/dist/runtime/deadline-transition-planner.js +139 -0
- package/dist/runtime/dispatch-effect.d.ts +3 -2
- package/dist/runtime/dispatch-effect.js +7 -13
- package/dist/runtime/errors.d.ts +51 -0
- package/dist/runtime/errors.js +39 -0
- package/dist/runtime/{runtime-helpers.d.ts → helpers.d.ts} +24 -4
- package/dist/runtime/{runtime-helpers.js → helpers.js} +56 -19
- package/dist/runtime/index.d.ts +3 -3
- package/dist/runtime/index.js +3 -3
- package/dist/runtime/ingress.d.ts +15 -0
- package/dist/runtime/ingress.js +42 -0
- package/dist/runtime/local-effect-executor.d.ts +21 -0
- package/dist/runtime/local-effect-executor.js +137 -0
- package/dist/runtime/looms.d.ts +30 -4
- package/dist/runtime/looms.js +57 -37
- package/dist/runtime/observer.d.ts +45 -0
- package/dist/runtime/observer.js +11 -0
- package/dist/runtime/repository.d.ts +55 -0
- package/dist/runtime/repository.js +293 -0
- package/dist/runtime/retry-policy.d.ts +16 -0
- package/dist/runtime/retry-policy.js +29 -0
- package/dist/runtime/run-execution-context.d.ts +30 -0
- package/dist/runtime/run-execution-context.js +56 -0
- package/dist/runtime/run-start.d.ts +4 -0
- package/dist/runtime/run-start.js +44 -0
- package/dist/runtime/runtime.d.ts +6 -87
- package/dist/runtime/runtime.js +248 -470
- package/dist/runtime/server/auth.d.ts +41 -0
- package/dist/runtime/server/auth.js +45 -0
- package/dist/runtime/server/debugger-host.d.ts +11 -0
- package/dist/runtime/server/debugger-host.js +32 -0
- package/dist/runtime/server/fetch-handler.d.ts +18 -0
- package/dist/runtime/server/fetch-handler.js +62 -0
- package/dist/runtime/server/http.d.ts +38 -0
- package/dist/runtime/server/http.js +66 -0
- package/dist/runtime/server/route-table.d.ts +55 -0
- package/dist/runtime/server/route-table.js +74 -0
- package/dist/runtime/server/routes/definitions.d.ts +3 -0
- package/dist/runtime/server/routes/definitions.js +20 -0
- package/dist/runtime/server/routes/effects.d.ts +3 -0
- package/dist/runtime/server/routes/effects.js +59 -0
- package/dist/runtime/server/routes/operations.d.ts +3 -0
- package/dist/runtime/server/routes/operations.js +14 -0
- package/dist/runtime/server/routes/runs.d.ts +3 -0
- package/dist/runtime/server/routes/runs.js +199 -0
- package/dist/runtime/server.d.ts +4 -8
- package/dist/runtime/server.js +6 -211
- package/dist/runtime/sse.d.ts +2 -1
- package/dist/runtime/sse.js +24 -17
- package/dist/runtime/types.d.ts +117 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/wake-engine.d.ts +20 -0
- package/dist/runtime/wake-engine.js +311 -0
- package/dist/runtime/wake-scheduler.d.ts +3 -4
- package/dist/runtime/wake-scheduler.js +25 -31
- package/dist/runtime/worker-callbacks.d.ts +16 -0
- package/dist/runtime/worker-callbacks.js +167 -0
- package/dist/runtime/worker-effect-dispatch.d.ts +36 -0
- package/dist/runtime/worker-effect-dispatch.js +126 -0
- package/dist/s2/config.d.ts +1 -1
- package/dist/s2/config.js +1 -1
- package/dist/s2/lite.js +70 -82
- package/dist/s2/pagination.d.ts +15 -0
- package/dist/s2/pagination.js +36 -0
- package/dist/s2/projector.js +6 -5
- package/dist/s2/snapshot-store.js +188 -161
- package/dist/s2/store.d.ts +3 -21
- package/dist/s2/store.js +71 -165
- package/dist/testing/index.d.ts +15 -0
- package/dist/testing/index.js +53 -16
- package/dist/workflow/debugger/index.d.ts +4 -0
- package/dist/workflow/debugger/index.js +11 -0
- package/dist/workflow/debugger/nodes-view.d.ts +3 -0
- package/dist/workflow/debugger/nodes-view.js +13 -0
- package/dist/workflow/debugger/summarize.d.ts +2 -0
- package/dist/workflow/debugger/summarize.js +30 -0
- package/dist/workflow/definitions-store.d.ts +2 -3
- package/dist/workflow/definitions-store.js +2 -2
- package/dist/workflow/definitions.d.ts +78 -22
- package/dist/workflow/definitions.js +80 -14
- package/dist/workflow/effects.d.ts +453 -107
- package/dist/workflow/effects.js +214 -115
- package/dist/workflow/events.d.ts +149 -5
- package/dist/workflow/events.js +27 -5
- package/dist/workflow/graph.d.ts +56 -0
- package/dist/workflow/graph.js +207 -0
- package/dist/workflow/index.d.ts +1 -0
- package/dist/workflow/index.js +1 -0
- package/dist/workflow/module.d.ts +1047 -266
- package/dist/workflow/projections.d.ts +14 -12
- package/dist/workflow/projections.js +30 -8
- package/dist/workflow/scope.d.ts +146 -4
- package/dist/workflow/threads.d.ts +383 -155
- package/dist/workflow/threads.js +308 -110
- package/package.json +26 -2
- package/dist/debugger/events/domain-summarize.d.ts +0 -3
- package/dist/debugger/events/domain-summarize.js +0 -107
- package/dist/debugger/events/family.d.ts +0 -8
- package/dist/debugger/events/family.js +0 -44
- package/dist/runtime/events-api.d.ts +0 -4
- package/dist/runtime/events-api.js +0 -84
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Database } from 'bun:sqlite';
|
|
2
2
|
import { createIndexProjector, } from './index-model.js';
|
|
3
|
+
import { runProjectorSync } from './projector.js';
|
|
3
4
|
import { SQLITE_SCHEMA_SQL } from './schema.js';
|
|
4
5
|
export { SQLITE_SCHEMA_SQL } from './schema.js';
|
|
5
6
|
function hasDb(options) {
|
|
@@ -48,39 +49,38 @@ export function sqlite(options = {}) {
|
|
|
48
49
|
const createdDb = !hasDb(options);
|
|
49
50
|
const db = hasDb(options) ? options.db : new Database(options.path ?? ':memory:');
|
|
50
51
|
const backend = {
|
|
51
|
-
init:
|
|
52
|
+
init: () => runProjectorSync('sqlite', () => {
|
|
52
53
|
db.exec(SQLITE_SCHEMA_SQL);
|
|
53
|
-
},
|
|
54
|
-
applyOps:
|
|
54
|
+
}),
|
|
55
|
+
applyOps: (ops) => runProjectorSync('sqlite', () => {
|
|
55
56
|
const apply = db.transaction((batch) => {
|
|
56
57
|
for (const op of batch) {
|
|
57
58
|
applyOp(db, op);
|
|
58
59
|
}
|
|
59
60
|
});
|
|
60
61
|
apply(ops);
|
|
61
|
-
},
|
|
62
|
-
getActor:
|
|
62
|
+
}),
|
|
63
|
+
getActor: (actorId) => runProjectorSync('sqlite', () => {
|
|
63
64
|
const row = db
|
|
64
65
|
.query(`SELECT actor_id, kind, status, definition_name, parent_actor_id, updated_at
|
|
65
|
-
|
|
66
|
+
FROM looms_actors WHERE actor_id = ?`)
|
|
66
67
|
.get(actorId);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
listReviews: async (actorId) => {
|
|
68
|
+
return row
|
|
69
|
+
? {
|
|
70
|
+
actorId: row.actor_id,
|
|
71
|
+
kind: row.kind,
|
|
72
|
+
status: row.status,
|
|
73
|
+
definitionName: row.definition_name,
|
|
74
|
+
parentActorId: row.parent_actor_id,
|
|
75
|
+
updatedAt: row.updated_at,
|
|
76
|
+
}
|
|
77
|
+
: null;
|
|
78
|
+
}),
|
|
79
|
+
listReviews: (actorId) => runProjectorSync('sqlite', () => {
|
|
80
80
|
const rows = actorId
|
|
81
81
|
? db
|
|
82
82
|
.query(`SELECT review_id, actor_id, status, title, updated_at
|
|
83
|
-
|
|
83
|
+
FROM looms_reviews WHERE actor_id = ?`)
|
|
84
84
|
.all(actorId)
|
|
85
85
|
: db
|
|
86
86
|
.query(`SELECT review_id, actor_id, status, title, updated_at FROM looms_reviews`)
|
|
@@ -92,12 +92,12 @@ export function sqlite(options = {}) {
|
|
|
92
92
|
title: row.title,
|
|
93
93
|
updatedAt: row.updated_at,
|
|
94
94
|
}));
|
|
95
|
-
},
|
|
96
|
-
dispose:
|
|
95
|
+
}),
|
|
96
|
+
dispose: () => runProjectorSync('sqlite', () => {
|
|
97
97
|
if (createdDb) {
|
|
98
98
|
db.close();
|
|
99
99
|
}
|
|
100
|
-
},
|
|
100
|
+
}),
|
|
101
101
|
};
|
|
102
102
|
return createIndexProjector('sqlite', backend);
|
|
103
103
|
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { Layer } from 'effect';
|
|
2
2
|
import { EventStoreTag, type EventStore, type EventEnvelope } from '@swirls/looms/core';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ProjectorDelivery } from './delivery';
|
|
4
|
+
import { type Projector, type ProjectorErrorHandler } from './projector';
|
|
4
5
|
export interface WithProjectorsOptions {
|
|
5
6
|
onError?: ProjectorErrorHandler;
|
|
7
|
+
/** Durable cursor runner. When present, appends trigger catch-up from its persisted cursor. */
|
|
8
|
+
delivery?: ProjectorDelivery;
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
11
|
* Wrap an EventStore so every successful append is also projected.
|
|
9
|
-
*
|
|
12
|
+
* The primary log stays authoritative: once an append commits, projection can never turn it into
|
|
13
|
+
* a failure. With a durable delivery runner, failures are persisted for retry; without one, they
|
|
14
|
+
* are reported to `onError` and the projection is skipped.
|
|
10
15
|
*/
|
|
11
16
|
export declare function withProjectors(store: EventStore, projectors: ReadonlyArray<Projector>, options?: WithProjectorsOptions): EventStore;
|
|
12
17
|
/** Project events after the fact (e.g. from a runtime hook). */
|
|
@@ -1,51 +1,50 @@
|
|
|
1
1
|
import { Effect, Layer } from 'effect';
|
|
2
2
|
import { EventStoreTag, snapshotStoreOf, withSnapshotStore, } from '@swirls/looms/core';
|
|
3
|
+
import { runProjectorEffect } from './projector.js';
|
|
3
4
|
function defaultOnError(error, projector) {
|
|
4
|
-
|
|
5
|
+
Effect.runFork(Effect.logWarning(`[@swirls/looms/projectors] ${projector.name} failed to project`, error));
|
|
6
|
+
}
|
|
7
|
+
function logDeliveryFailure(runId, cause) {
|
|
8
|
+
return Effect.logWarning(`[@swirls/looms/projectors] delivery for ${runId} failed`, cause);
|
|
5
9
|
}
|
|
6
10
|
/**
|
|
7
11
|
* Wrap an EventStore so every successful append is also projected.
|
|
8
|
-
*
|
|
12
|
+
* The primary log stays authoritative: once an append commits, projection can never turn it into
|
|
13
|
+
* a failure. With a durable delivery runner, failures are persisted for retry; without one, they
|
|
14
|
+
* are reported to `onError` and the projection is skipped.
|
|
9
15
|
*/
|
|
10
16
|
export function withProjectors(store, projectors, options) {
|
|
11
17
|
const onError = options?.onError ?? defaultOnError;
|
|
18
|
+
const delivery = options?.delivery;
|
|
19
|
+
const project = (runId, sequences) => {
|
|
20
|
+
if (delivery) {
|
|
21
|
+
return delivery.deliver(runId).pipe(Effect.catch((cause) => logDeliveryFailure(runId, cause)));
|
|
22
|
+
}
|
|
23
|
+
const fromSeq = sequences[0];
|
|
24
|
+
if (fromSeq === undefined) {
|
|
25
|
+
return Effect.void;
|
|
26
|
+
}
|
|
27
|
+
return store.read(runId, { fromSeq, limit: sequences.length }).pipe(Effect.flatMap((written) => Effect.forEach(projectors, (projector) => runProjectorEffect(projector.name, () => projector.project(written)).pipe(Effect.catch((error) => Effect.sync(() => {
|
|
28
|
+
onError(error, projector, written);
|
|
29
|
+
}))), { concurrency: 'unbounded', discard: true })), Effect.catch((cause) => logDeliveryFailure(runId, cause)));
|
|
30
|
+
};
|
|
12
31
|
const wrapped = {
|
|
13
|
-
append: (runId, events, appendOptions) =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (fromSeq !== undefined && projectors.length > 0) {
|
|
17
|
-
const written = yield* store.read(runId, {
|
|
18
|
-
fromSeq,
|
|
19
|
-
limit: result.sequences.length,
|
|
20
|
-
});
|
|
21
|
-
yield* Effect.promise(async () => {
|
|
22
|
-
for (const projector of projectors) {
|
|
23
|
-
try {
|
|
24
|
-
await projector.project(written);
|
|
25
|
-
}
|
|
26
|
-
catch (cause) {
|
|
27
|
-
onError(cause instanceof Error ? cause : new Error(String(cause)), projector, written);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
}),
|
|
32
|
+
append: (runId, events, appendOptions) => store
|
|
33
|
+
.append(runId, events, appendOptions)
|
|
34
|
+
.pipe(Effect.tap((result) => projectors.length === 0 ? Effect.void : project(runId, result.sequences))),
|
|
34
35
|
read: (runId, readOptions) => store.read(runId, readOptions),
|
|
35
36
|
tail: (runId) => store.tail(runId),
|
|
36
37
|
bounds: store.bounds ? (runId) => store.bounds(runId) : undefined,
|
|
37
38
|
trim: store.trim ? (runId, beforeSeq) => store.trim(runId, beforeSeq) : undefined,
|
|
38
39
|
subscribe: (runId, subscribeOptions) => store.subscribe(runId, subscribeOptions),
|
|
39
|
-
listRuns:
|
|
40
|
+
listRuns: store.listRuns,
|
|
40
41
|
};
|
|
41
42
|
const snapshots = snapshotStoreOf(store);
|
|
42
43
|
return snapshots ? withSnapshotStore(wrapped, snapshots) : wrapped;
|
|
43
44
|
}
|
|
44
45
|
/** Project events after the fact (e.g. from a runtime hook). */
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
await projector.project(events);
|
|
48
|
-
}
|
|
46
|
+
export function projectEvents(projectors, events) {
|
|
47
|
+
return Effect.runPromise(Effect.forEach(projectors, (projector) => runProjectorEffect(projector.name, () => projector.project(events)), { concurrency: 'unbounded', discard: true }));
|
|
49
48
|
}
|
|
50
49
|
/**
|
|
51
50
|
* Layer that decorates a base EventStore with projection.
|
package/dist/react/notify.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Predicate } from 'effect';
|
|
1
|
+
import { DateTime, Effect, Fiber, Predicate } from 'effect';
|
|
2
2
|
/** Quiet→burst threshold for `adaptive` coalesce (ms since last notify). */
|
|
3
3
|
const ADAPTIVE_BURST_WINDOW_MS = 8;
|
|
4
4
|
function nowMs() {
|
|
5
5
|
const perf = globalThis.performance;
|
|
6
|
-
return perf === undefined ?
|
|
6
|
+
return perf === undefined ? DateTime.toEpochMillis(DateTime.nowUnsafe()) : perf.now();
|
|
7
7
|
}
|
|
8
8
|
export function createNotifyScheduler(coalesce, onNotify) {
|
|
9
9
|
let notifyScheduled = false;
|
|
@@ -17,12 +17,15 @@ export function createNotifyScheduler(coalesce, onNotify) {
|
|
|
17
17
|
lastNotifyAt = nowMs();
|
|
18
18
|
onNotify();
|
|
19
19
|
};
|
|
20
|
+
const scheduleTimer = (delayMs) => {
|
|
21
|
+
notifyTimer = Effect.runFork(Effect.sleep(delayMs).pipe(Effect.andThen(Effect.sync(fire))));
|
|
22
|
+
};
|
|
20
23
|
const scheduleFrame = () => {
|
|
21
24
|
if (Predicate.isFunction(globalThis.requestAnimationFrame)) {
|
|
22
25
|
notifyRaf = requestAnimationFrame(fire);
|
|
23
26
|
}
|
|
24
27
|
else {
|
|
25
|
-
|
|
28
|
+
scheduleTimer(0);
|
|
26
29
|
}
|
|
27
30
|
};
|
|
28
31
|
const cancel = () => {
|
|
@@ -31,7 +34,7 @@ export function createNotifyScheduler(coalesce, onNotify) {
|
|
|
31
34
|
}
|
|
32
35
|
notifyScheduled = false;
|
|
33
36
|
if (notifyTimer !== undefined) {
|
|
34
|
-
|
|
37
|
+
Effect.runFork(Fiber.interrupt(notifyTimer));
|
|
35
38
|
notifyTimer = undefined;
|
|
36
39
|
}
|
|
37
40
|
if (notifyRaf !== undefined && Predicate.isFunction(globalThis.cancelAnimationFrame)) {
|
|
@@ -54,7 +57,7 @@ export function createNotifyScheduler(coalesce, onNotify) {
|
|
|
54
57
|
scheduleFrame();
|
|
55
58
|
}
|
|
56
59
|
else {
|
|
57
|
-
|
|
60
|
+
scheduleTimer(0);
|
|
58
61
|
}
|
|
59
62
|
return;
|
|
60
63
|
}
|
|
@@ -64,11 +67,11 @@ export function createNotifyScheduler(coalesce, onNotify) {
|
|
|
64
67
|
}
|
|
65
68
|
if (Predicate.isObject(coalesce) && 'delayMs' in coalesce) {
|
|
66
69
|
const delayMs = Predicate.isNumber(coalesce.delayMs) ? Math.max(0, coalesce.delayMs) : 0;
|
|
67
|
-
|
|
70
|
+
scheduleTimer(delayMs);
|
|
68
71
|
return;
|
|
69
72
|
}
|
|
70
|
-
const
|
|
71
|
-
void
|
|
73
|
+
const exhaustiveCheck = coalesce;
|
|
74
|
+
void exhaustiveCheck;
|
|
72
75
|
};
|
|
73
76
|
const flush = () => {
|
|
74
77
|
if (notifyScheduled) {
|
package/dist/react/react.d.ts
CHANGED
|
@@ -24,10 +24,9 @@ export interface UseRunStoreOptions {
|
|
|
24
24
|
* Retains the store in memory while mounted; does NOT trigger component re-renders.
|
|
25
25
|
* Use data hooks (`useRunEvents`, `useProjection`, `useRunSummary`, etc.) to subscribe.
|
|
26
26
|
*/
|
|
27
|
-
export declare function useRunStore
|
|
28
|
-
/** Subscribe to incremental projection state
|
|
27
|
+
export declare function useRunStore(runId: string, options?: UseRunStoreOptions): LoomsClientStore;
|
|
28
|
+
/** Subscribe to incremental projection state. */
|
|
29
29
|
export declare function useProjection<S, TEvent extends AnyEventEnvelope = RegisteredEvent>(store: LoomsClientStore<TEvent>, definition: ProjectionDefinition<S>): S;
|
|
30
|
-
export declare function useProjection<S, Selected, TEvent extends AnyEventEnvelope = RegisteredEvent>(store: LoomsClientStore<TEvent>, definition: ProjectionDefinition<S>, selector: (state: S) => Selected, isEqual?: (a: Selected, b: Selected) => boolean): Selected;
|
|
31
30
|
/** Subscribe to arbitrary store derivations with an equality check. */
|
|
32
31
|
export declare function useRunSelector<Selected, TEvent extends AnyEventEnvelope = RegisteredEvent>(store: LoomsClientStore<TEvent>, selector: (store: LoomsClientStore<TEvent>) => Selected, isEqual?: (a: Selected, b: Selected) => boolean): Selected;
|
|
33
32
|
export interface RunSummary {
|
package/dist/react/react.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Effect, Fiber } from 'effect';
|
|
1
2
|
import { createContext, createElement, useCallback, useContext, useEffect, useMemo, useRef, useSyncExternalStore, } from 'react';
|
|
2
3
|
import { threadTree, toThreadTree } from '@swirls/looms/core';
|
|
3
4
|
import { createFold, foldEvents } from './derived.js';
|
|
@@ -16,11 +17,13 @@ function disposeEntry(key) {
|
|
|
16
17
|
entry.store.dispose();
|
|
17
18
|
registry.delete(key);
|
|
18
19
|
}
|
|
20
|
+
function scheduleDisposal(key) {
|
|
21
|
+
return Effect.runFork(Effect.sleep(GRACE_MS).pipe(Effect.andThen(Effect.sync(() => disposeEntry(key)))));
|
|
22
|
+
}
|
|
19
23
|
function peekStore(runId, endpoint, reconnectDelayMs, coalesce) {
|
|
20
24
|
const key = registryKey(endpoint, runId);
|
|
21
25
|
const existing = registry.get(key);
|
|
22
26
|
if (existing) {
|
|
23
|
-
// SAFETY: registry stores share the app-registered event catalog.
|
|
24
27
|
return existing.store;
|
|
25
28
|
}
|
|
26
29
|
const store = createLoomsStore({
|
|
@@ -30,10 +33,9 @@ function peekStore(runId, endpoint, reconnectDelayMs, coalesce) {
|
|
|
30
33
|
coalesce,
|
|
31
34
|
});
|
|
32
35
|
registry.set(key, {
|
|
33
|
-
|
|
34
|
-
store: store,
|
|
36
|
+
store,
|
|
35
37
|
refs: 0,
|
|
36
|
-
|
|
38
|
+
disposal: scheduleDisposal(key),
|
|
37
39
|
});
|
|
38
40
|
return store;
|
|
39
41
|
}
|
|
@@ -45,9 +47,9 @@ function retainStore(runId, endpoint, reconnectDelayMs, coalesce) {
|
|
|
45
47
|
return;
|
|
46
48
|
}
|
|
47
49
|
entry.refs += 1;
|
|
48
|
-
if (entry.
|
|
49
|
-
|
|
50
|
-
entry.
|
|
50
|
+
if (entry.disposal !== undefined) {
|
|
51
|
+
Effect.runFork(Fiber.interrupt(entry.disposal));
|
|
52
|
+
entry.disposal = undefined;
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
function releaseStore(runId, endpoint) {
|
|
@@ -57,8 +59,8 @@ function releaseStore(runId, endpoint) {
|
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
61
|
entry.refs = Math.max(0, entry.refs - 1);
|
|
60
|
-
if (entry.refs === 0 && entry.
|
|
61
|
-
entry.
|
|
62
|
+
if (entry.refs === 0 && entry.disposal === undefined) {
|
|
63
|
+
entry.disposal = scheduleDisposal(key);
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
/** Root provider that supplies the Looms host endpoint to run stores. */
|
|
@@ -87,27 +89,9 @@ function useStoreSnapshot(store, getSnapshot) {
|
|
|
87
89
|
const subscribe = useCallback((onChange) => store.subscribe(onChange), [store]);
|
|
88
90
|
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
89
91
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export function useProjection(store, definition, selector, isEqual = Object.is) {
|
|
94
|
-
const lastSelected = useRef(undefined);
|
|
95
|
-
const lastState = useRef(undefined);
|
|
96
|
-
// SAFETY: When selector is undefined, Selected equals S so identitySelector satisfies the signature.
|
|
97
|
-
const select = selector ?? identitySelector;
|
|
98
|
-
const getSnapshot = useCallback(() => {
|
|
99
|
-
const state = store.project(definition);
|
|
100
|
-
if (lastState.current === state && lastSelected.current !== undefined) {
|
|
101
|
-
return lastSelected.current;
|
|
102
|
-
}
|
|
103
|
-
const nextSelected = select(state);
|
|
104
|
-
lastState.current = state;
|
|
105
|
-
if (lastSelected.current !== undefined && isEqual(lastSelected.current, nextSelected)) {
|
|
106
|
-
return lastSelected.current;
|
|
107
|
-
}
|
|
108
|
-
lastSelected.current = nextSelected;
|
|
109
|
-
return nextSelected;
|
|
110
|
-
}, [store, definition, select, isEqual]);
|
|
92
|
+
/** Subscribe to incremental projection state. */
|
|
93
|
+
export function useProjection(store, definition) {
|
|
94
|
+
const getSnapshot = useCallback(() => store.project(definition), [store, definition]);
|
|
111
95
|
return useStoreSnapshot(store, getSnapshot);
|
|
112
96
|
}
|
|
113
97
|
/** Subscribe to arbitrary store derivations with an equality check. */
|
package/dist/react/sse.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { consumeSseStream, delay, eventsFromSseData, parseSseFrame, type SseFrame, } from '@swirls/looms/client';
|
|
1
|
+
export { consumeSseStream, consumeSseStreamEffect, delay, eventsFromSseData, parseSseFrame, type SseFrame, } from '@swirls/looms/client';
|
package/dist/react/sse.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { consumeSseStream, delay, eventsFromSseData, parseSseFrame, } from '@swirls/looms/client';
|
|
1
|
+
export { consumeSseStream, consumeSseStreamEffect, delay, eventsFromSseData, parseSseFrame, } from '@swirls/looms/client';
|
package/dist/react/store.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface LoomsClientStoreOptions {
|
|
|
12
12
|
storeId: string;
|
|
13
13
|
/**
|
|
14
14
|
* Base URL of the Looms host (e.g. http://127.0.0.1:8787).
|
|
15
|
-
* Opens `${endpoint}/
|
|
15
|
+
* Opens `${endpoint}/runs/:id/events?live=true` as an SSE stream.
|
|
16
16
|
*/
|
|
17
17
|
endpoint: string;
|
|
18
18
|
/** Backoff between SSE reconnects. */
|
|
@@ -45,7 +45,7 @@ export interface LoomsClientStore<TEvent extends AnyEventEnvelope = RegisteredEv
|
|
|
45
45
|
project<S>(definition: ProjectionDefinition<S>): S;
|
|
46
46
|
fold<S>(definition: EventFoldDefinition<S, TEvent>): S;
|
|
47
47
|
flush: () => void;
|
|
48
|
-
commit: (event: EventInput) => Promise<void>;
|
|
48
|
+
commit: (event: EventInput | readonly EventInput[]) => Promise<void>;
|
|
49
49
|
sync: () => Promise<void>;
|
|
50
50
|
dispose: () => void;
|
|
51
51
|
}
|
|
@@ -53,4 +53,4 @@ export interface LoomsClientStore<TEvent extends AnyEventEnvelope = RegisteredEv
|
|
|
53
53
|
* In-memory client store that follows a run's event log over SSE and
|
|
54
54
|
* materializes generic `runs` / `threads` tables.
|
|
55
55
|
*/
|
|
56
|
-
export declare function createLoomsStore
|
|
56
|
+
export declare function createLoomsStore(options: LoomsClientStoreOptions): LoomsClientStore;
|