@superpanel-sdk/runtime 0.2.3 → 0.5.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/README.md +28 -8
- package/dist/builder/codegen/emit.d.ts +29 -11
- package/dist/builder/codegen/emit.js +328 -61
- package/dist/builder/codegen/generate.d.ts +21 -0
- package/dist/builder/codegen/generate.js +152 -20
- package/dist/builder/company-import-graph.d.ts +2 -0
- package/dist/builder/company-import-graph.js +40 -8
- package/dist/builder/company-imports.d.ts +24 -0
- package/dist/builder/company-imports.js +114 -0
- package/dist/builder/compile/compile-sequence.d.ts +59 -8
- package/dist/builder/compile/compile-sequence.js +279 -77
- package/dist/builder/compile/function-code.d.ts +12 -2
- package/dist/builder/compile/function-code.js +87 -39
- package/dist/builder/compile/registry.d.ts +7 -3
- package/dist/builder/compile/registry.js +24 -23
- package/dist/builder/load.d.ts +70 -10
- package/dist/builder/load.js +250 -61
- package/dist/builder/paths.d.ts +3 -0
- package/dist/builder/paths.js +16 -0
- package/dist/builder/schedules.d.ts +23 -0
- package/dist/builder/schedules.js +102 -0
- package/dist/builder/slot-schema-validation.d.ts +4 -0
- package/dist/builder/slot-schema-validation.js +10 -0
- package/dist/builder/typecheck.d.ts +8 -0
- package/dist/builder/typecheck.js +105 -0
- package/dist/builder/types.d.ts +91 -19
- package/dist/builder/types.js +2 -1
- package/dist/cli/auth/auth.d.ts +37 -0
- package/dist/cli/auth/auth.js +211 -0
- package/dist/cli/auth/backend-url.d.ts +5 -0
- package/dist/cli/auth/backend-url.js +25 -0
- package/dist/cli/auth/clipboard.d.ts +9 -0
- package/dist/cli/auth/clipboard.js +38 -0
- package/dist/cli/auth/http.d.ts +20 -0
- package/dist/cli/auth/http.js +27 -0
- package/dist/cli/auth/index.d.ts +10 -0
- package/dist/cli/auth/index.js +27 -0
- package/dist/cli/auth/progress.d.ts +12 -0
- package/dist/cli/auth/progress.js +15 -0
- package/dist/cli/auth/serve-login.d.ts +8 -0
- package/dist/cli/auth/serve-login.js +24 -0
- package/dist/cli/compile/index.js +3 -0
- package/dist/cli/config.d.ts +10 -0
- package/dist/cli/config.js +52 -0
- package/dist/cli/index.js +28 -8
- package/dist/cli/serve/index.d.ts +73 -3
- package/dist/cli/serve/index.js +365 -116
- package/dist/cli/type-gen/index.js +9 -8
- package/dist/compiler.d.ts +7 -0
- package/dist/compiler.js +7 -0
- package/dist/compute-host/compute-host.d.ts +15 -23
- package/dist/compute-host/compute-host.js +25 -28
- package/dist/compute-host/index.d.ts +2 -4
- package/dist/compute-host/index.js +1 -2
- package/dist/compute-host/source-compute-host.d.ts +11 -9
- package/dist/compute-host/source-compute-host.js +46 -32
- package/dist/core/case-orchestrator/contact-hours.d.ts +50 -0
- package/dist/core/case-orchestrator/contact-hours.js +108 -0
- package/dist/core/case-orchestrator/follow-ups.d.ts +31 -0
- package/dist/core/case-orchestrator/follow-ups.js +103 -0
- package/dist/core/case-orchestrator/index.d.ts +6 -0
- package/dist/core/case-orchestrator/index.js +6 -0
- package/dist/core/case-orchestrator/render.d.ts +75 -0
- package/dist/core/case-orchestrator/render.js +239 -0
- package/dist/core/case-orchestrator/time.d.ts +11 -0
- package/dist/core/case-orchestrator/time.js +29 -0
- package/dist/core/case-orchestrator/tools.d.ts +29 -0
- package/dist/core/case-orchestrator/tools.js +31 -0
- package/dist/core/case-orchestrator/types.d.ts +753 -0
- package/dist/core/case-orchestrator/types.js +46 -0
- package/dist/core/case-orchestrator/validate.d.ts +11 -0
- package/dist/core/case-orchestrator/validate.js +63 -0
- package/dist/core/context/call.d.ts +291 -0
- package/dist/core/context/call.js +94 -0
- package/dist/core/context/channels.d.ts +60 -0
- package/dist/core/context/channels.js +35 -0
- package/dist/core/context/contact.d.ts +96 -6
- package/dist/core/context/contact.js +48 -2
- package/dist/core/context/email-message.d.ts +159 -0
- package/dist/core/context/email-message.js +59 -0
- package/dist/core/context/email.d.ts +97 -0
- package/dist/core/context/email.js +91 -0
- package/dist/core/context/exchanges.d.ts +142 -0
- package/dist/core/context/exchanges.js +63 -0
- package/dist/core/context/instances.d.ts +278 -0
- package/dist/core/context/instances.js +123 -0
- package/dist/core/context/kv.d.ts +113 -0
- package/dist/core/context/kv.js +60 -0
- package/dist/core/context/platform-registry.d.ts +509 -4
- package/dist/core/context/platform-registry.js +14 -2
- package/dist/core/context/platform.d.ts +2 -1
- package/dist/core/context/sms.d.ts +147 -0
- package/dist/core/context/sms.js +57 -0
- package/dist/core/context/types.d.ts +51 -48
- package/dist/core/context/types.js +1 -7
- package/dist/core/conversation/index.d.ts +31 -0
- package/dist/core/conversation/index.js +14 -0
- package/dist/core/functions/define/bind.d.ts +25 -0
- package/dist/core/functions/define/bind.js +14 -0
- package/dist/core/functions/define/case.d.ts +9 -0
- package/dist/core/functions/define/case.js +13 -0
- package/dist/core/functions/define/events.d.ts +20 -0
- package/dist/core/functions/define/events.js +21 -0
- package/dist/core/functions/define/no-case.d.ts +4 -0
- package/dist/core/functions/define/no-case.js +9 -0
- package/dist/core/functions/events.d.ts +247 -0
- package/dist/core/functions/events.js +32 -0
- package/dist/core/functions/func-ref.d.ts +11 -2
- package/dist/core/functions/schedules.d.ts +51 -0
- package/dist/core/functions/schedules.js +20 -0
- package/dist/core/functions/types.d.ts +62 -51
- package/dist/core/functions/types.js +6 -1
- package/dist/core/office-hours/index.d.ts +39 -0
- package/dist/core/office-hours/index.js +187 -0
- package/dist/core/page/define.d.ts +834 -0
- package/dist/core/page/define.js +477 -0
- package/dist/core/page/ops.d.ts +58 -0
- package/dist/core/page/ops.js +220 -0
- package/dist/core/page/render.d.ts +253 -0
- package/dist/core/page/render.js +840 -0
- package/dist/core/page/time-format.d.ts +19 -0
- package/dist/core/page/time-format.js +41 -0
- package/dist/core/page/timeline.d.ts +40 -0
- package/dist/core/page/timeline.js +2 -0
- package/dist/core/page/typed.d.ts +642 -0
- package/dist/core/page/typed.js +2 -0
- package/dist/core/page/workspace.d.ts +33 -0
- package/dist/core/page/workspace.js +231 -0
- package/dist/core/party/index.d.ts +3 -0
- package/dist/core/party/index.js +3 -0
- package/dist/core/party/schema.d.ts +137 -0
- package/dist/core/party/schema.js +80 -0
- package/dist/core/party/types.d.ts +40 -0
- package/dist/core/party/types.js +15 -0
- package/dist/core/sequence/define.d.ts +57 -0
- package/dist/core/sequence/define.js +10 -0
- package/dist/core/sequence/index.d.ts +63 -0
- package/dist/core/sequence/index.js +231 -0
- package/dist/core/slot/binding.d.ts +40 -0
- package/dist/core/slot/binding.js +2 -0
- package/dist/core/slot/company-metadata.d.ts +113 -0
- package/dist/core/slot/company-metadata.js +563 -0
- package/dist/core/slot/compile-schema.d.ts +19 -13
- package/dist/core/slot/compile-schema.js +51 -248
- package/dist/core/slot/contact-timezone.d.ts +110 -0
- package/dist/core/slot/contact-timezone.js +186 -0
- package/dist/core/slot/field.d.ts +2 -24
- package/dist/core/slot/field.js +0 -69
- package/dist/core/slot/id-ref.d.ts +17 -2
- package/dist/core/slot/id-ref.js +16 -8
- package/dist/core/slot/index.d.ts +12 -13
- package/dist/core/slot/index.js +11 -12
- package/dist/core/slot/naming.d.ts +15 -0
- package/dist/core/slot/naming.js +96 -0
- package/dist/core/slot/platform-fields.d.ts +119 -0
- package/dist/core/slot/platform-fields.js +121 -0
- package/dist/core/slot/ref.d.ts +16 -0
- package/dist/core/slot/ref.js +14 -0
- package/dist/core/slot/row.d.ts +2 -9
- package/dist/core/slot/row.js +13 -23
- package/dist/core/slot/schema-compat.d.ts +16 -0
- package/dist/core/slot/schema-compat.js +112 -0
- package/dist/core/slot/schema.d.ts +409 -76
- package/dist/core/slot/schema.js +178 -10
- package/dist/core/slot/types.d.ts +27 -94
- package/dist/core/slot/value.d.ts +26 -3
- package/dist/core/slot/value.js +89 -57
- package/dist/dev-overlay/protocol.d.ts +41 -8
- package/dist/fn-context/build-context.d.ts +3 -1
- package/dist/fn-context/build-context.js +20 -10
- package/dist/fn-context/fake/empty-api.js +9 -28
- package/dist/fn-context/fake/index.d.ts +11 -4
- package/dist/fn-context/fake/index.js +27 -2
- package/dist/fn-context/fn-params.d.ts +6 -0
- package/dist/fn-context/fn-params.js +13 -0
- package/dist/fn-context/index.d.ts +5 -5
- package/dist/fn-context/index.js +4 -4
- package/dist/fn-context/log.js +2 -2
- package/dist/fn-context/make-ctx.d.ts +11 -0
- package/dist/fn-context/make-ctx.js +18 -8
- package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +24 -0
- package/dist/fn-context/rpc/case-orchestrator-tools.js +13 -0
- package/dist/fn-context/rpc/index.d.ts +3 -1
- package/dist/fn-context/rpc/index.js +3 -1
- package/dist/fn-context/rpc/integration/index.d.ts +4 -4
- package/dist/fn-context/rpc/integration/index.js +1 -1
- package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
- package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
- package/dist/fn-context/rpc/platform.d.ts +2 -2
- package/dist/fn-context/rpc/platform.js +1 -1
- package/dist/fn-context/rpc/records.d.ts +78 -0
- package/dist/fn-context/rpc/records.js +26 -0
- package/dist/fn-context/rpc/trpc-client.d.ts +2 -2
- package/dist/fn-context/rpc/trpc-client.js +88 -7
- package/dist/fn-context/rpc/trpc-init.d.ts +2 -2
- package/dist/fn-context/rpc/trpc-router-factory.d.ts +49 -3
- package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
- package/dist/fn-context/run-scope.d.ts +4 -0
- package/dist/fn-context/run-scope.js +9 -0
- package/dist/fn-context/types.d.ts +36 -3
- package/dist/index.d.ts +37 -46
- package/dist/index.js +33 -33
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +41 -0
- package/dist/platform.d.ts +76 -0
- package/dist/platform.js +56 -0
- package/dist/voice-service/actions.d.ts +71 -4
- package/dist/voice-service/types.d.ts +42 -5
- package/dist/worker.d.ts +10 -0
- package/dist/worker.js +10 -0
- package/package.json +38 -19
- package/dist/builder/compile/compile-agenda.d.ts +0 -15
- package/dist/builder/compile/compile-agenda.js +0 -64
- package/dist/builder/merge.d.ts +0 -4
- package/dist/builder/merge.js +0 -19
- package/dist/compute-host/read-only-cache.d.ts +0 -20
- package/dist/compute-host/read-only-cache.js +0 -61
- package/dist/core/context/db.d.ts +0 -69
- package/dist/core/context/db.js +0 -44
- package/dist/core/context/docusign.d.ts +0 -134
- package/dist/core/context/docusign.js +0 -108
- package/dist/core/context/filevine.d.ts +0 -323
- package/dist/core/context/filevine.js +0 -254
- package/dist/core/context/http.d.ts +0 -9
- package/dist/core/context/http.js +0 -4
- package/dist/core/context/hubspot.d.ts +0 -250
- package/dist/core/context/hubspot.js +0 -191
- package/dist/core/context/twilio.d.ts +0 -50
- package/dist/core/context/twilio.js +0 -42
- package/dist/core/functions/define/case-context.d.ts +0 -14
- package/dist/core/functions/define/case-context.js +0 -15
- package/dist/core/functions/define/compute.d.ts +0 -7
- package/dist/core/functions/define/compute.js +0 -17
- package/dist/core/functions/define/custom.d.ts +0 -4
- package/dist/core/functions/define/custom.js +0 -8
- package/dist/core/functions/define/system.d.ts +0 -7
- package/dist/core/functions/define/system.js +0 -12
- package/dist/core/slot/deps.d.ts +0 -15
- package/dist/core/slot/deps.js +0 -88
- package/dist/core/slot/derived.d.ts +0 -32
- package/dist/core/slot/derived.js +0 -115
- package/dist/core/slot/platform-session-fields.d.ts +0 -38
- package/dist/core/slot/platform-session-fields.js +0 -48
- package/dist/core/slot/sf-schema.d.ts +0 -23
- package/dist/core/slot/sf-schema.js +0 -125
- package/dist/core/slot/sf-validate.d.ts +0 -14
- package/dist/core/slot/sf-validate.js +0 -132
- package/dist/core/slot/snapshot.d.ts +0 -18
- package/dist/core/slot/snapshot.js +0 -138
- package/dist/core/slot/write.d.ts +0 -48
- package/dist/core/slot/write.js +0 -426
- package/dist/core/stage/builders.d.ts +0 -54
- package/dist/core/stage/builders.js +0 -31
- package/dist/core/stage/condition.d.ts +0 -17
- package/dist/core/stage/condition.js +0 -198
- package/dist/core/stage/drive.d.ts +0 -43
- package/dist/core/stage/drive.js +0 -78
- package/dist/core/stage/finish-when.d.ts +0 -20
- package/dist/core/stage/finish-when.js +0 -82
- package/dist/core/stage/flatten.d.ts +0 -27
- package/dist/core/stage/flatten.js +0 -466
- package/dist/core/stage/index.d.ts +0 -15
- package/dist/core/stage/index.js +0 -13
- package/dist/core/stage/interrupts.d.ts +0 -28
- package/dist/core/stage/interrupts.js +0 -120
- package/dist/core/stage/ivr-fields.d.ts +0 -9
- package/dist/core/stage/ivr-fields.js +0 -75
- package/dist/core/stage/simulate.d.ts +0 -24
- package/dist/core/stage/simulate.js +0 -33
- package/dist/core/stage/transfer-fields.d.ts +0 -19
- package/dist/core/stage/transfer-fields.js +0 -129
- package/dist/core/stage/transfer-spec.d.ts +0 -48
- package/dist/core/stage/transfer-spec.js +0 -113
- package/dist/core/stage/types.d.ts +0 -208
- package/dist/core/stage/types.js +0 -2
- package/dist/core/stage/validate.d.ts +0 -11
- package/dist/core/stage/validate.js +0 -330
- package/dist/core/stage/walk.d.ts +0 -39
- package/dist/core/stage/walk.js +0 -119
- package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
- package/dist/fn-context/system-args.d.ts +0 -6
- package/dist/fn-context/system-args.js +0 -14
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import { bindLogMeta } from './log.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
export async function buildActionContext(data, host, options = {}) {
|
|
7
|
-
const run = {
|
|
2
|
+
import { dayIn, formatTime } from '../core/page/time-format.js';
|
|
3
|
+
function resolveRunScope(data, options) {
|
|
4
|
+
return {
|
|
8
5
|
companyId: options.run?.companyId ?? data.meta.companyId,
|
|
9
6
|
environmentId: options.run?.environmentId ?? data.meta.environmentId,
|
|
10
|
-
sequenceId: options.run?.sequenceId ?? data.meta.sequenceId,
|
|
11
7
|
entry: options.run?.entry ?? data.meta.entry,
|
|
12
8
|
};
|
|
13
|
-
|
|
9
|
+
}
|
|
10
|
+
function assembleContext(data, meta, api) {
|
|
14
11
|
return {
|
|
15
|
-
time: data.time,
|
|
16
|
-
meta
|
|
12
|
+
time: { ...data.time, format: formatTime, day: dayIn },
|
|
13
|
+
meta,
|
|
17
14
|
config: data.config,
|
|
18
15
|
api: { ...api, log: bindLogMeta(api.log, data.meta) },
|
|
19
16
|
};
|
|
20
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Assemble ActionContext = JSON data slice + api from ApiHost.
|
|
20
|
+
* Shared by local unit, remote-fc, and (later) Worker-side invoke.
|
|
21
|
+
*/
|
|
22
|
+
export async function buildActionContext(data, host, options = {}) {
|
|
23
|
+
const api = await host.buildApi(resolveRunScope(data, options));
|
|
24
|
+
return assembleContext(data, data.meta, api);
|
|
25
|
+
}
|
|
26
|
+
/** Assemble the `orchestrator` ctx (without `params`), its api from the host. */
|
|
27
|
+
export async function buildCaseOrchestratorContext(data, host, options = {}) {
|
|
28
|
+
const api = await host.buildCaseOrchestratorApi(resolveRunScope(data, options));
|
|
29
|
+
return assembleContext(data, data.meta, api);
|
|
30
|
+
}
|
|
21
31
|
//# sourceMappingURL=build-context.js.map
|
|
@@ -1,43 +1,24 @@
|
|
|
1
1
|
import { platformSurfaces } from '../../core/context/platform-registry.js';
|
|
2
|
-
import {
|
|
2
|
+
import { emailMockService } from '../../core/context/email.js';
|
|
3
3
|
import { envMockService } from '../../core/context/env.js';
|
|
4
|
-
import { filevineMockService } from '../../core/context/filevine.js';
|
|
5
|
-
import { hubspotMockService } from '../../core/context/hubspot.js';
|
|
6
|
-
import { twilioMockService } from '../../core/context/twilio.js';
|
|
7
|
-
const MOCK_HUBSPOT_TARGET = { kind: 'account', id: 'mock-hubspot-main' };
|
|
8
|
-
const MOCK_TWILIO_TARGET = { kind: 'account', id: 'mock-twilio-main' };
|
|
9
|
-
const MOCK_FILEVINE_TARGET = { kind: 'account', id: 'mock-filevine-main' };
|
|
10
|
-
const MOCK_DOCUSIGN_TARGET = { kind: 'account', id: 'mock-docusign-main' };
|
|
11
4
|
const MOCK_ENV_TARGET = { kind: 'account', id: 'mock-env-main' };
|
|
5
|
+
const MOCK_EMAIL_TARGET = { kind: 'resource', id: 'mock-email-main' };
|
|
12
6
|
function mockAccount(target, name) {
|
|
13
7
|
return { target, name, credentials: {}, config: {} };
|
|
14
8
|
}
|
|
15
|
-
const hubspotStub = {
|
|
16
|
-
...mockAccount(MOCK_HUBSPOT_TARGET, 'main'),
|
|
17
|
-
...hubspotMockService,
|
|
18
|
-
};
|
|
19
|
-
const twilioStub = {
|
|
20
|
-
...mockAccount(MOCK_TWILIO_TARGET, 'main'),
|
|
21
|
-
...twilioMockService,
|
|
22
|
-
};
|
|
23
|
-
const filevineStub = {
|
|
24
|
-
...mockAccount(MOCK_FILEVINE_TARGET, 'main'),
|
|
25
|
-
...filevineMockService,
|
|
26
|
-
};
|
|
27
|
-
const docusignStub = {
|
|
28
|
-
...mockAccount(MOCK_DOCUSIGN_TARGET, 'main'),
|
|
29
|
-
...docusignMockService,
|
|
30
|
-
};
|
|
31
9
|
const envStub = {
|
|
32
10
|
...mockAccount(MOCK_ENV_TARGET, 'main'),
|
|
33
11
|
...envMockService,
|
|
34
12
|
};
|
|
13
|
+
const emailStub = {
|
|
14
|
+
...mockAccount(MOCK_EMAIL_TARGET, 'intake@example.com'),
|
|
15
|
+
address: 'intake@example.com',
|
|
16
|
+
provider: 'gmail',
|
|
17
|
+
...emailMockService,
|
|
18
|
+
};
|
|
35
19
|
export const emptyIntegration = () => ({
|
|
36
|
-
hubspots: [hubspotStub],
|
|
37
|
-
twilios: [twilioStub],
|
|
38
|
-
filevines: [filevineStub],
|
|
39
|
-
docusigns: [docusignStub],
|
|
40
20
|
envs: [envStub],
|
|
21
|
+
emails: [emailStub],
|
|
41
22
|
});
|
|
42
23
|
/** Each registered surface backed by its mock, with per-method overrides applied on top. */
|
|
43
24
|
export const defaultPlatformApis = (overrides = {}) => {
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
import { type CaseOrchestratorTools } from '../../core/case-orchestrator/types.js';
|
|
1
2
|
import type { IntegrationApi, Logger } from '../../core/context/types.js';
|
|
2
|
-
import {
|
|
3
|
-
import type { ApiHost } from '../types.js';
|
|
3
|
+
import type { Db } from '../../core/page/define.js';
|
|
4
|
+
import type { ApiHost, CaseOrchestratorApiHost } from '../types.js';
|
|
4
5
|
import { type PlatformApiOverrides } from './empty-api.js';
|
|
5
6
|
export type FakeApiHostOptions = PlatformApiOverrides & {
|
|
6
7
|
integration?: Partial<IntegrationApi>;
|
|
7
8
|
log?: Logger;
|
|
8
|
-
|
|
9
|
+
/** Case Orchestrator tools; a tool left out rejects when called. */
|
|
10
|
+
tools?: Partial<CaseOrchestratorTools>;
|
|
11
|
+
/** `ctx.api.db`; left out, every call rejects. */
|
|
12
|
+
db?: Db;
|
|
9
13
|
};
|
|
14
|
+
/** Every table, every method: rejects when called (`what` names it in the error). */
|
|
15
|
+
/** A stand-in whose every call rejects, saying it is not faked. */
|
|
16
|
+
export declare function unfaked<T extends object>(what: string): T;
|
|
10
17
|
/** In-process ApiHost for local unit tests (`makeCtx` uses this). */
|
|
11
|
-
export declare function createFakeApiHost(options?: FakeApiHostOptions): ApiHost;
|
|
18
|
+
export declare function createFakeApiHost(options?: FakeApiHostOptions): ApiHost & CaseOrchestratorApiHost;
|
|
12
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CASE_ORCHESTRATOR_TOOL_NAMES } from '../../core/case-orchestrator/types.js';
|
|
2
2
|
import { noopLog } from '../log.js';
|
|
3
3
|
import { defaultPlatformApis, emptyIntegration } from './empty-api.js';
|
|
4
|
+
/** Every table, every method: rejects when called (`what` names it in the error). */
|
|
5
|
+
/** A stand-in whose every call rejects, saying it is not faked. */
|
|
6
|
+
export function unfaked(what) {
|
|
7
|
+
return new Proxy({}, {
|
|
8
|
+
get: (_, table) => new Proxy({}, {
|
|
9
|
+
get: (__, method) => async () => {
|
|
10
|
+
throw new Error(`FakeApiHost: ${what}.${String(table)}.${String(method)} is not faked`);
|
|
11
|
+
},
|
|
12
|
+
}),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function fakeTools(overrides = {}) {
|
|
16
|
+
const tools = CASE_ORCHESTRATOR_TOOL_NAMES.map((tool) => [
|
|
17
|
+
tool,
|
|
18
|
+
overrides[tool] ??
|
|
19
|
+
(async () => {
|
|
20
|
+
throw new Error(`FakeApiHost: tools.${tool} is not faked`);
|
|
21
|
+
}),
|
|
22
|
+
]);
|
|
23
|
+
return Object.fromEntries(tools);
|
|
24
|
+
}
|
|
4
25
|
/** In-process ApiHost for local unit tests (`makeCtx` uses this). */
|
|
5
26
|
export function createFakeApiHost(options = {}) {
|
|
6
27
|
const integration = {
|
|
@@ -11,12 +32,16 @@ export function createFakeApiHost(options = {}) {
|
|
|
11
32
|
...defaultPlatformApis(options),
|
|
12
33
|
integration,
|
|
13
34
|
log: options.log ?? noopLog,
|
|
14
|
-
|
|
35
|
+
db: options.db ?? unfaked('db'),
|
|
15
36
|
};
|
|
37
|
+
const tools = fakeTools(options.tools);
|
|
16
38
|
return {
|
|
17
39
|
async buildApi() {
|
|
18
40
|
return api;
|
|
19
41
|
},
|
|
42
|
+
async buildCaseOrchestratorApi() {
|
|
43
|
+
return { ...api, tools };
|
|
44
|
+
},
|
|
20
45
|
};
|
|
21
46
|
}
|
|
22
47
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `invocation.params` for `case` / `noCase` functions: an object (empty when omitted).
|
|
3
|
+
* The case (`c`: `{ subject, instanceId }`) is passed apart, not here.
|
|
4
|
+
*/
|
|
5
|
+
export declare function resolveFnParams(params: unknown): object;
|
|
6
|
+
//# sourceMappingURL=fn-params.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `invocation.params` for `case` / `noCase` functions: an object (empty when omitted).
|
|
3
|
+
* The case (`c`: `{ subject, instanceId }`) is passed apart, not here.
|
|
4
|
+
*/
|
|
5
|
+
export function resolveFnParams(params) {
|
|
6
|
+
if (params == null)
|
|
7
|
+
return {};
|
|
8
|
+
if (typeof params !== 'object' || Array.isArray(params)) {
|
|
9
|
+
throw new Error('function params must be an object');
|
|
10
|
+
}
|
|
11
|
+
return params;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=fn-params.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export type { ActionContext, ActionDataSlice, ApiHost, RunScope } from './types.js';
|
|
2
|
-
export { buildActionContext, type BuildActionContextOptions } from './build-context.js';
|
|
3
|
-
export {
|
|
1
|
+
export type { ActionContext, ActionDataSlice, ApiHost, CaseOrchestratorActionContext, CaseOrchestratorApiHost, CaseOrchestratorRunScope, RunClaims, RunScope, } from './types.js';
|
|
2
|
+
export { buildActionContext, buildCaseOrchestratorContext, type BuildActionContextOptions, } from './build-context.js';
|
|
3
|
+
export { asCaseOrchestratorRun } from './run-scope.js';
|
|
4
|
+
export { resolveFnParams } from './fn-params.js';
|
|
4
5
|
export { createFakeApiHost, type FakeApiHostOptions } from './fake/index.js';
|
|
5
6
|
export { defaultPlatformApis, emptyIntegration, type PlatformApiOverrides } from './fake/empty-api.js';
|
|
6
7
|
export { createRpcApiHost, LOG_TAGS_HEADER, REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, encodeLogTagsHeader, formatRuntimeVersion, readLogTagsHeader, readRequestIdHeader, readRuntimeVersionHeader, } from './rpc/index.js';
|
|
7
8
|
export { bindLogMeta, noopLog } from './log.js';
|
|
8
|
-
export { makeCtx, makeCtxAsync } from './make-ctx.js';
|
|
9
|
-
export { defaultHttpApi } from '../core/context/http.js';
|
|
9
|
+
export { makeCaseOrchestratorCtx, makeCtx, makeCtxAsync } from './make-ctx.js';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/fn-context/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { buildActionContext } from './build-context.js';
|
|
2
|
-
export {
|
|
1
|
+
export { buildActionContext, buildCaseOrchestratorContext, } from './build-context.js';
|
|
2
|
+
export { asCaseOrchestratorRun } from './run-scope.js';
|
|
3
|
+
export { resolveFnParams } from './fn-params.js';
|
|
3
4
|
export { createFakeApiHost } from './fake/index.js';
|
|
4
5
|
export { defaultPlatformApis, emptyIntegration } from './fake/empty-api.js';
|
|
5
6
|
export { createRpcApiHost, LOG_TAGS_HEADER, REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, encodeLogTagsHeader, formatRuntimeVersion, readLogTagsHeader, readRequestIdHeader, readRuntimeVersionHeader, } from './rpc/index.js';
|
|
6
7
|
export { bindLogMeta, noopLog } from './log.js';
|
|
7
|
-
export { makeCtx, makeCtxAsync } from './make-ctx.js';
|
|
8
|
-
export { defaultHttpApi } from '../core/context/http.js';
|
|
8
|
+
export { makeCaseOrchestratorCtx, makeCtx, makeCtxAsync } from './make-ctx.js';
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/dist/fn-context/log.js
CHANGED
|
@@ -4,9 +4,9 @@ export const noopLog = {
|
|
|
4
4
|
error: () => { },
|
|
5
5
|
};
|
|
6
6
|
/** Identity fields that LogContext already stores first-class (mars ctx). */
|
|
7
|
-
const CONTEXT_KEYS = ['companyId', 'sequenceId'
|
|
7
|
+
const CONTEXT_KEYS = ['companyId', 'sequenceId'];
|
|
8
8
|
/** Remaining SystemContext.meta fields; carried on log extra. */
|
|
9
|
-
const EXTRA_META_KEYS = ['environmentId', 'entry', '
|
|
9
|
+
const EXTRA_META_KEYS = ['environmentId', 'entry', 'instanceId'];
|
|
10
10
|
/**
|
|
11
11
|
* Stamp every `ctx.api.log` call with SystemContext.meta. First-class ids stay
|
|
12
12
|
* on extra so RpcApiHost can send them; the backend lifts them into LogContext.
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import type { CaseOrchestratorTools } from '../core/case-orchestrator/types.js';
|
|
1
2
|
import type { MakeCtxOverrides, SystemContext } from '../core/context/types.js';
|
|
3
|
+
import type { Db } from '../core/page/define.js';
|
|
4
|
+
import type { CaseOrchestratorActionContext } from './types.js';
|
|
2
5
|
/**
|
|
3
6
|
* Build a fake SystemContext for local unit tests.
|
|
4
7
|
* Uses {@link createFakeApiHost}; sync because FakeApiHost has no I/O.
|
|
@@ -6,4 +9,12 @@ import type { MakeCtxOverrides, SystemContext } from '../core/context/types.js';
|
|
|
6
9
|
export declare function makeCtx(overrides?: MakeCtxOverrides): SystemContext;
|
|
7
10
|
/** Async makeCtx via {@link buildActionContext} + FakeApiHost (same result as {@link makeCtx}). */
|
|
8
11
|
export declare function makeCtxAsync(overrides?: MakeCtxOverrides): Promise<SystemContext>;
|
|
12
|
+
/**
|
|
13
|
+
* Fake `orchestrator` ctx (without `params`) for local unit tests: `tools` fakes `ctx.api.tools`,
|
|
14
|
+
* `db` fakes `ctx.api.db` (left out, every call rejects).
|
|
15
|
+
*/
|
|
16
|
+
export declare function makeCaseOrchestratorCtx(overrides?: MakeCtxOverrides & {
|
|
17
|
+
tools?: Partial<CaseOrchestratorTools>;
|
|
18
|
+
db?: Db;
|
|
19
|
+
}): Promise<CaseOrchestratorActionContext>;
|
|
9
20
|
//# sourceMappingURL=make-ctx.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { createFakeApiHost } from './fake/index.js';
|
|
1
|
+
import { buildActionContext, buildCaseOrchestratorContext } from './build-context.js';
|
|
2
|
+
import { createFakeApiHost, unfaked } from './fake/index.js';
|
|
4
3
|
import { defaultPlatformApis, emptyIntegration } from './fake/empty-api.js';
|
|
5
4
|
import { bindLogMeta, noopLog } from './log.js';
|
|
5
|
+
import { dayIn, formatTime } from '../core/page/time-format.js';
|
|
6
6
|
function toDataSlice(overrides) {
|
|
7
7
|
const timezone = overrides.timezone ?? 'UTC';
|
|
8
8
|
const today = overrides.today ?? '1970-01-01';
|
|
@@ -14,8 +14,7 @@ function toDataSlice(overrides) {
|
|
|
14
14
|
environmentId: 'sandbox',
|
|
15
15
|
sequenceId: 'sequence',
|
|
16
16
|
entry: 'test',
|
|
17
|
-
|
|
18
|
-
caseId: 'case',
|
|
17
|
+
instanceId: 'instance',
|
|
19
18
|
...overrides.meta,
|
|
20
19
|
},
|
|
21
20
|
config: {
|
|
@@ -35,9 +34,9 @@ export function makeCtx(overrides = {}) {
|
|
|
35
34
|
...defaultPlatformApis(overrides.api),
|
|
36
35
|
integration: { ...emptyIntegration(), ...overrides.api?.integration },
|
|
37
36
|
log: bindLogMeta(overrides.api?.log ?? noopLog, data.meta),
|
|
38
|
-
|
|
37
|
+
db: overrides.api?.db ?? unfaked('db'),
|
|
39
38
|
};
|
|
40
|
-
return { ...data, api };
|
|
39
|
+
return { ...data, meta: data.meta, time: { ...data.time, format: formatTime, day: dayIn }, api };
|
|
41
40
|
}
|
|
42
41
|
/** Async makeCtx via {@link buildActionContext} + FakeApiHost (same result as {@link makeCtx}). */
|
|
43
42
|
export async function makeCtxAsync(overrides = {}) {
|
|
@@ -45,7 +44,18 @@ export async function makeCtxAsync(overrides = {}) {
|
|
|
45
44
|
...overrides.api,
|
|
46
45
|
integration: overrides.api?.integration,
|
|
47
46
|
log: overrides.api?.log,
|
|
48
|
-
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Fake `orchestrator` ctx (without `params`) for local unit tests: `tools` fakes `ctx.api.tools`,
|
|
51
|
+
* `db` fakes `ctx.api.db` (left out, every call rejects).
|
|
52
|
+
*/
|
|
53
|
+
export async function makeCaseOrchestratorCtx(overrides = {}) {
|
|
54
|
+
return buildCaseOrchestratorContext(toDataSlice({ ...overrides, meta: { entry: 'orchestrator', ...overrides.meta } }), createFakeApiHost({
|
|
55
|
+
...overrides.api,
|
|
56
|
+
log: overrides.api?.log,
|
|
57
|
+
tools: overrides.tools,
|
|
58
|
+
db: overrides.db,
|
|
49
59
|
}));
|
|
50
60
|
}
|
|
51
61
|
//# sourceMappingURL=make-ctx.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type RpcContext } from './trpc-init.js';
|
|
2
|
+
export type CaseOrchestratorToolInvokeHandler = (input: {
|
|
3
|
+
tool: string;
|
|
4
|
+
input: unknown;
|
|
5
|
+
callKey: string;
|
|
6
|
+
ctx: RpcContext;
|
|
7
|
+
}) => Promise<unknown>;
|
|
8
|
+
export declare function createCaseOrchestratorToolsRouter(invoke: CaseOrchestratorToolInvokeHandler): import("@trpc/server").TRPCBuiltRouter<{
|
|
9
|
+
ctx: RpcContext;
|
|
10
|
+
meta: object;
|
|
11
|
+
errorShape: import("@trpc/server").TRPCDefaultErrorShape;
|
|
12
|
+
transformer: false;
|
|
13
|
+
}, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
14
|
+
invoke: import("@trpc/server").TRPCMutationProcedure<{
|
|
15
|
+
input: {
|
|
16
|
+
tool: string;
|
|
17
|
+
input: unknown;
|
|
18
|
+
callKey: string;
|
|
19
|
+
};
|
|
20
|
+
output: unknown;
|
|
21
|
+
meta: object;
|
|
22
|
+
}>;
|
|
23
|
+
}>>;
|
|
24
|
+
//# sourceMappingURL=case-orchestrator-tools.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { publicProcedure, router } from './trpc-init.js';
|
|
3
|
+
const invokeInput = z.object({
|
|
4
|
+
tool: z.string().min(1),
|
|
5
|
+
input: z.unknown(),
|
|
6
|
+
callKey: z.string().min(1).max(200),
|
|
7
|
+
});
|
|
8
|
+
export function createCaseOrchestratorToolsRouter(invoke) {
|
|
9
|
+
return router({
|
|
10
|
+
invoke: publicProcedure.input(invokeInput).mutation(({ ctx, input }) => invoke({ ...input, ctx })),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=case-orchestrator-tools.js.map
|
|
@@ -2,9 +2,11 @@ export { createAppRouter, type AppRouter } from './trpc-router-factory.js';
|
|
|
2
2
|
export type { RpcContext } from './trpc-init.js';
|
|
3
3
|
export { ScriptInputError, isRpcCodedError, parseScriptInput, type RpcCodedError, type RpcErrorCode, } from './errors.js';
|
|
4
4
|
export { createIntegrationRouter, type IntegrationInvokeHandler } from './integration/index.js';
|
|
5
|
-
export {
|
|
5
|
+
export { createListSurfacesProcedure } from './integration/list-surfaces.js';
|
|
6
6
|
export { createPlatformRouter, type PlatformInvokeHandler } from './platform.js';
|
|
7
7
|
export { createLogRouter, type LogEmitHandler } from './log.js';
|
|
8
8
|
export { createRpcApiHost } from './trpc-client.js';
|
|
9
|
+
export { createCaseOrchestratorToolsRouter, type CaseOrchestratorToolInvokeHandler, } from './case-orchestrator-tools.js';
|
|
10
|
+
export { createRecordsRouter, type RecordsReadInput, type RecordsHandlers, type RecordsResult, type RecordsWriteInput, } from './records.js';
|
|
9
11
|
export { LOG_TAGS_HEADER, REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, encodeLogTagsHeader, formatRuntimeVersion, readLogTagsHeader, readRequestIdHeader, readRuntimeVersionHeader, } from './request-id.js';
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { createAppRouter } from './trpc-router-factory.js';
|
|
2
2
|
export { ScriptInputError, isRpcCodedError, parseScriptInput, } from './errors.js';
|
|
3
3
|
export { createIntegrationRouter } from './integration/index.js';
|
|
4
|
-
export {
|
|
4
|
+
export { createListSurfacesProcedure } from './integration/list-surfaces.js';
|
|
5
5
|
export { createPlatformRouter } from './platform.js';
|
|
6
6
|
export { createLogRouter } from './log.js';
|
|
7
7
|
export { createRpcApiHost } from './trpc-client.js';
|
|
8
|
+
export { createCaseOrchestratorToolsRouter, } from './case-orchestrator-tools.js';
|
|
9
|
+
export { createRecordsRouter, } from './records.js';
|
|
8
10
|
export { LOG_TAGS_HEADER, REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, encodeLogTagsHeader, formatRuntimeVersion, readLogTagsHeader, readRequestIdHeader, readRuntimeVersionHeader, } from './request-id.js';
|
|
9
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IntegrationTarget } from '../../../core/context/types.js';
|
|
2
2
|
import { type RpcContext } from '../trpc-init.js';
|
|
3
|
-
import {
|
|
3
|
+
import { createListSurfacesProcedure } from './list-surfaces.js';
|
|
4
4
|
/**
|
|
5
5
|
* Provider-agnostic entry point for script surfaces: the target's provider decides
|
|
6
6
|
* which methods exist, so adding one never touches the RPC layer.
|
|
@@ -12,7 +12,7 @@ export type IntegrationInvokeHandler = (input: {
|
|
|
12
12
|
ctx: RpcContext;
|
|
13
13
|
}) => Promise<unknown>;
|
|
14
14
|
export declare function createIntegrationRouter(modules: {
|
|
15
|
-
|
|
15
|
+
listSurfaces: ReturnType<typeof createListSurfacesProcedure>;
|
|
16
16
|
invoke: IntegrationInvokeHandler;
|
|
17
17
|
}): import("@trpc/server").TRPCBuiltRouter<{
|
|
18
18
|
ctx: RpcContext;
|
|
@@ -20,10 +20,10 @@ export declare function createIntegrationRouter(modules: {
|
|
|
20
20
|
errorShape: import("@trpc/server").TRPCDefaultErrorShape;
|
|
21
21
|
transformer: false;
|
|
22
22
|
}, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
23
|
-
|
|
23
|
+
listSurfaces: import("@trpc/server").TRPCQueryProcedure<{
|
|
24
24
|
input: void;
|
|
25
25
|
output: {
|
|
26
|
-
surfaceKey: "
|
|
26
|
+
surfaceKey: "emails" | "envs";
|
|
27
27
|
target: {
|
|
28
28
|
kind: "account" | "resource";
|
|
29
29
|
id: string;
|
|
@@ -10,7 +10,7 @@ const integrationInvokeInput = z.object({
|
|
|
10
10
|
});
|
|
11
11
|
export function createIntegrationRouter(modules) {
|
|
12
12
|
return router({
|
|
13
|
-
|
|
13
|
+
listSurfaces: modules.listSurfaces,
|
|
14
14
|
invoke: publicProcedure
|
|
15
15
|
.input(integrationInvokeInput)
|
|
16
16
|
.mutation(async ({ ctx, input }) => modules.invoke({ target: input.target, method: input.method, params: input.params ?? {}, ctx })),
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type IntegrationSurfaceMeta } from '../../../core/context/types.js';
|
|
2
|
+
import { type RpcContext } from '../trpc-init.js';
|
|
3
|
+
export type ListSurfacesHandler = (opts: {
|
|
4
|
+
ctx: RpcContext;
|
|
5
|
+
}) => Promise<IntegrationSurfaceMeta[]>;
|
|
6
|
+
export declare function createListSurfacesProcedure(handler: ListSurfacesHandler): import("@trpc/server").TRPCQueryProcedure<{
|
|
7
|
+
input: void;
|
|
8
|
+
output: {
|
|
9
|
+
surfaceKey: "emails" | "envs";
|
|
10
|
+
target: {
|
|
11
|
+
kind: "account" | "resource";
|
|
12
|
+
id: string;
|
|
13
|
+
};
|
|
14
|
+
name: string;
|
|
15
|
+
methods: string[];
|
|
16
|
+
credentials: Record<string, unknown>;
|
|
17
|
+
config: Record<string, unknown>;
|
|
18
|
+
}[];
|
|
19
|
+
meta: object;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=list-surfaces.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { integrationSurfaceKeys } from '../../../core/context/types.js';
|
|
3
3
|
import { publicProcedure } from '../trpc-init.js';
|
|
4
|
-
const
|
|
4
|
+
const integrationSurfaceMeta = z.object({
|
|
5
5
|
surfaceKey: z.enum(integrationSurfaceKeys),
|
|
6
6
|
target: z.object({
|
|
7
7
|
kind: z.enum(['account', 'resource']),
|
|
@@ -12,7 +12,7 @@ const boundIntegrationMeta = z.object({
|
|
|
12
12
|
credentials: z.record(z.string(), z.unknown()),
|
|
13
13
|
config: z.record(z.string(), z.unknown()),
|
|
14
14
|
});
|
|
15
|
-
export function
|
|
16
|
-
return publicProcedure.output(z.array(
|
|
15
|
+
export function createListSurfacesProcedure(handler) {
|
|
16
|
+
return publicProcedure.output(z.array(integrationSurfaceMeta)).query(async (opts) => handler(opts));
|
|
17
17
|
}
|
|
18
|
-
//# sourceMappingURL=list-
|
|
18
|
+
//# sourceMappingURL=list-surfaces.js.map
|
|
@@ -6,7 +6,7 @@ import { type RpcContext } from './trpc-init.js';
|
|
|
6
6
|
export type PlatformInvokeHandler = (input: {
|
|
7
7
|
surface: string;
|
|
8
8
|
method: string;
|
|
9
|
-
params:
|
|
9
|
+
params: unknown;
|
|
10
10
|
ctx: RpcContext;
|
|
11
11
|
}) => Promise<unknown>;
|
|
12
12
|
export declare function createPlatformRouter(invoke: PlatformInvokeHandler): import("@trpc/server").TRPCBuiltRouter<{
|
|
@@ -19,7 +19,7 @@ export declare function createPlatformRouter(invoke: PlatformInvokeHandler): imp
|
|
|
19
19
|
input: {
|
|
20
20
|
surface: string;
|
|
21
21
|
method: string;
|
|
22
|
-
params?:
|
|
22
|
+
params?: unknown;
|
|
23
23
|
};
|
|
24
24
|
output: unknown;
|
|
25
25
|
meta: object;
|
|
@@ -3,7 +3,7 @@ import { publicProcedure, router } from './trpc-init.js';
|
|
|
3
3
|
const platformInvokeInput = z.object({
|
|
4
4
|
surface: z.string(),
|
|
5
5
|
method: z.string(),
|
|
6
|
-
params: z.
|
|
6
|
+
params: z.unknown().optional(),
|
|
7
7
|
});
|
|
8
8
|
export function createPlatformRouter(invoke) {
|
|
9
9
|
return router({
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type RpcContext } from './trpc-init.js';
|
|
3
|
+
/**
|
|
4
|
+
* `ctx.api.db` of every function and the Orchestrator (15 §10.16): the same
|
|
5
|
+
* reads and writes as a page script and its actions, over RPC, one call per request. A write carries
|
|
6
|
+
* its call key (its place in the run: `write:1`, `write:2`, …): within an Orchestrator Run the same
|
|
7
|
+
* request sent again returns the first answer instead of writing twice.
|
|
8
|
+
*/
|
|
9
|
+
declare const readInput: z.ZodObject<{
|
|
10
|
+
table: z.ZodString;
|
|
11
|
+
method: z.ZodEnum<{
|
|
12
|
+
count: "count";
|
|
13
|
+
findFirst: "findFirst";
|
|
14
|
+
findMany: "findMany";
|
|
15
|
+
findUnique: "findUnique";
|
|
16
|
+
}>;
|
|
17
|
+
args: z.ZodUnknown;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
declare const writeInput: z.ZodObject<{
|
|
20
|
+
table: z.ZodString;
|
|
21
|
+
method: z.ZodEnum<{
|
|
22
|
+
create: "create";
|
|
23
|
+
delete: "delete";
|
|
24
|
+
update: "update";
|
|
25
|
+
upsert: "upsert";
|
|
26
|
+
}>;
|
|
27
|
+
args: z.ZodUnknown;
|
|
28
|
+
callKey: z.ZodString;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export type RecordsReadInput = z.infer<typeof readInput>;
|
|
31
|
+
export type RecordsWriteInput = z.infer<typeof writeInput>;
|
|
32
|
+
/** What a read or write answers: its value, or the reason it was refused (with its code for a write). */
|
|
33
|
+
export type RecordsResult = {
|
|
34
|
+
ok: true;
|
|
35
|
+
value?: unknown;
|
|
36
|
+
} | {
|
|
37
|
+
ok: false;
|
|
38
|
+
error: {
|
|
39
|
+
code: string;
|
|
40
|
+
message: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export type RecordsHandlers = {
|
|
44
|
+
read(input: RecordsReadInput & {
|
|
45
|
+
ctx: RpcContext;
|
|
46
|
+
}): Promise<RecordsResult>;
|
|
47
|
+
write(input: RecordsWriteInput & {
|
|
48
|
+
ctx: RpcContext;
|
|
49
|
+
}): Promise<RecordsResult>;
|
|
50
|
+
};
|
|
51
|
+
export declare function createRecordsRouter(handlers: RecordsHandlers): import("@trpc/server").TRPCBuiltRouter<{
|
|
52
|
+
ctx: RpcContext;
|
|
53
|
+
meta: object;
|
|
54
|
+
errorShape: import("@trpc/server").TRPCDefaultErrorShape;
|
|
55
|
+
transformer: false;
|
|
56
|
+
}, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
57
|
+
read: import("@trpc/server").TRPCMutationProcedure<{
|
|
58
|
+
input: {
|
|
59
|
+
table: string;
|
|
60
|
+
method: "count" | "findFirst" | "findMany" | "findUnique";
|
|
61
|
+
args: unknown;
|
|
62
|
+
};
|
|
63
|
+
output: RecordsResult;
|
|
64
|
+
meta: object;
|
|
65
|
+
}>;
|
|
66
|
+
write: import("@trpc/server").TRPCMutationProcedure<{
|
|
67
|
+
input: {
|
|
68
|
+
table: string;
|
|
69
|
+
method: "create" | "delete" | "update" | "upsert";
|
|
70
|
+
args: unknown;
|
|
71
|
+
callKey: string;
|
|
72
|
+
};
|
|
73
|
+
output: RecordsResult;
|
|
74
|
+
meta: object;
|
|
75
|
+
}>;
|
|
76
|
+
}>>;
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=records.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { publicProcedure, router } from './trpc-init.js';
|
|
3
|
+
/**
|
|
4
|
+
* `ctx.api.db` of every function and the Orchestrator (15 §10.16): the same
|
|
5
|
+
* reads and writes as a page script and its actions, over RPC, one call per request. A write carries
|
|
6
|
+
* its call key (its place in the run: `write:1`, `write:2`, …): within an Orchestrator Run the same
|
|
7
|
+
* request sent again returns the first answer instead of writing twice.
|
|
8
|
+
*/
|
|
9
|
+
const readInput = z.object({
|
|
10
|
+
table: z.string().min(1),
|
|
11
|
+
method: z.enum(['findUnique', 'findFirst', 'findMany', 'count']),
|
|
12
|
+
args: z.unknown(),
|
|
13
|
+
});
|
|
14
|
+
const writeInput = z.object({
|
|
15
|
+
table: z.string().min(1),
|
|
16
|
+
method: z.enum(['create', 'update', 'upsert', 'delete']),
|
|
17
|
+
args: z.unknown(),
|
|
18
|
+
callKey: z.string().min(1).max(200),
|
|
19
|
+
});
|
|
20
|
+
export function createRecordsRouter(handlers) {
|
|
21
|
+
return router({
|
|
22
|
+
read: publicProcedure.input(readInput).mutation(({ ctx, input }) => handlers.read({ ...input, ctx })),
|
|
23
|
+
write: publicProcedure.input(writeInput).mutation(({ ctx, input }) => handlers.write({ ...input, ctx })),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=records.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiHost } from '../types.js';
|
|
1
|
+
import type { ApiHost, CaseOrchestratorApiHost } from '../types.js';
|
|
2
2
|
export declare function createRpcApiHost(options: {
|
|
3
3
|
baseUrl: string;
|
|
4
4
|
getToken: () => string | Promise<string>;
|
|
@@ -7,5 +7,5 @@ export declare function createRpcApiHost(options: {
|
|
|
7
7
|
getRequestId?: () => string | undefined;
|
|
8
8
|
getTags?: () => string[] | undefined;
|
|
9
9
|
waitUntil?: (promise: Promise<unknown>) => void;
|
|
10
|
-
}): ApiHost;
|
|
10
|
+
}): ApiHost & CaseOrchestratorApiHost;
|
|
11
11
|
//# sourceMappingURL=trpc-client.d.ts.map
|