@superpanel-sdk/runtime 0.2.3 → 0.7.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 +30 -10
- package/dist/builder/codegen/emit.d.ts +25 -12
- package/dist/builder/codegen/emit.js +339 -78
- package/dist/builder/codegen/generate.d.ts +21 -2
- package/dist/builder/codegen/generate.js +147 -34
- 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 +29 -0
- package/dist/builder/company-imports.js +122 -0
- package/dist/builder/compile/compile-sequence.d.ts +61 -8
- package/dist/builder/compile/compile-sequence.js +334 -80
- package/dist/builder/compile/function-code.d.ts +19 -3
- package/dist/builder/compile/function-code.js +123 -45
- package/dist/builder/compile/registry.d.ts +7 -3
- package/dist/builder/compile/registry.js +30 -27
- package/dist/builder/errors.d.ts +9 -0
- package/dist/builder/errors.js +17 -0
- package/dist/builder/function-params.d.ts +10 -0
- package/dist/builder/function-params.js +203 -0
- package/dist/builder/load.d.ts +70 -10
- package/dist/builder/load.js +258 -67
- package/dist/builder/paths.d.ts +9 -1
- package/dist/builder/paths.js +32 -2
- package/dist/builder/schedules.d.ts +25 -0
- package/dist/builder/schedules.js +101 -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 +102 -0
- package/dist/builder/types.d.ts +127 -19
- package/dist/builder/types.js +21 -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/calls/index.d.ts +177 -0
- package/dist/cli/calls/index.js +96 -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/debug/index.d.ts +31 -0
- package/dist/cli/debug/index.js +119 -0
- package/dist/cli/exec/index.d.ts +39 -0
- package/dist/cli/exec/index.js +138 -0
- package/dist/cli/exec/session.d.ts +48 -0
- package/dist/cli/exec/session.js +82 -0
- package/dist/cli/exec/trace.d.ts +18 -0
- package/dist/cli/exec/trace.js +52 -0
- package/dist/cli/index.js +112 -9
- package/dist/cli/logs/index.d.ts +47 -0
- package/dist/cli/logs/index.js +113 -0
- package/dist/cli/mobile/index.d.ts +12 -0
- package/dist/cli/mobile/index.js +405 -0
- package/dist/cli/serve/index.d.ts +109 -3
- package/dist/cli/serve/index.js +506 -118
- package/dist/cli/turns/index.d.ts +105 -0
- package/dist/cli/turns/index.js +128 -0
- package/dist/cli/turns/run.d.ts +13 -0
- package/dist/cli/turns/run.js +57 -0
- package/dist/cli/turns/shadow.d.ts +112 -0
- package/dist/cli/turns/shadow.js +54 -0
- package/dist/cli/type-gen/index.js +9 -9
- package/dist/compiler.d.ts +7 -0
- package/dist/compiler.js +7 -0
- package/dist/compute-host/compute-host.d.ts +14 -23
- package/dist/compute-host/compute-host.js +18 -30
- 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 +10 -10
- package/dist/compute-host/source-compute-host.js +33 -40
- package/dist/core/case-orchestrator/contact-hours.d.ts +70 -0
- package/dist/core/case-orchestrator/contact-hours.js +127 -0
- package/dist/core/case-orchestrator/index.d.ts +3 -0
- package/dist/core/case-orchestrator/index.js +3 -0
- package/dist/core/case-orchestrator/render.d.ts +75 -0
- package/dist/core/case-orchestrator/render.js +244 -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/types.d.ts +708 -0
- package/dist/core/case-orchestrator/types.js +42 -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 +198 -0
- package/dist/core/context/email-message.js +86 -0
- package/dist/core/context/email.d.ts +109 -0
- package/dist/core/context/email.js +90 -0
- package/dist/core/context/exchanges.d.ts +167 -0
- package/dist/core/context/exchanges.js +81 -0
- package/dist/core/context/instances.d.ts +307 -0
- package/dist/core/context/instances.js +137 -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 +544 -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 +177 -0
- package/dist/core/context/sms.js +77 -0
- package/dist/core/context/types.d.ts +79 -48
- package/dist/core/context/types.js +1 -7
- package/dist/core/conversation/index.d.ts +85 -0
- package/dist/core/conversation/index.js +133 -0
- package/dist/core/functions/errors.d.ts +74 -0
- package/dist/core/functions/errors.js +26 -0
- package/dist/core/functions/events.d.ts +192 -0
- package/dist/core/functions/events.js +23 -0
- package/dist/core/functions/schedules.d.ts +50 -0
- package/dist/core/functions/schedules.js +20 -0
- package/dist/core/functions/types.d.ts +29 -73
- package/dist/core/functions/types.js +1 -4
- 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 +904 -0
- package/dist/core/page/define.js +518 -0
- package/dist/core/page/envelope.d.ts +55 -0
- package/dist/core/page/envelope.js +4 -0
- package/dist/core/page/fns.d.ts +448 -0
- package/dist/core/page/fns.js +539 -0
- package/dist/core/page/memory-reader.d.ts +27 -0
- package/dist/core/page/memory-reader.js +299 -0
- package/dist/core/page/ops.d.ts +58 -0
- package/dist/core/page/ops.js +220 -0
- package/dist/core/page/page-host.d.ts +20 -0
- package/dist/core/page/page-host.js +57 -0
- package/dist/core/page/records-query.d.ts +234 -0
- package/dist/core/page/records-query.js +780 -0
- package/dist/core/page/render.d.ts +295 -0
- package/dist/core/page/render.js +1060 -0
- package/dist/core/page/sandbox.d.ts +85 -0
- package/dist/core/page/sandbox.js +357 -0
- package/dist/core/page/time-format.d.ts +46 -0
- package/dist/core/page/time-format.js +125 -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 +648 -0
- package/dist/core/page/typed.js +2 -0
- package/dist/core/page/workspace.d.ts +57 -0
- package/dist/core/page/workspace.js +266 -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 +208 -0
- package/dist/core/party/schema.js +113 -0
- package/dist/core/party/types.d.ts +35 -0
- package/dist/core/party/types.js +15 -0
- package/dist/core/sequence/define.d.ts +56 -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 +102 -0
- package/dist/core/slot/company-metadata.js +536 -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 -25
- package/dist/core/slot/field.js +0 -71
- 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 +17 -0
- package/dist/core/slot/schema-compat.js +103 -0
- package/dist/core/slot/schema.d.ts +353 -76
- package/dist/core/slot/schema.js +163 -10
- package/dist/core/slot/types.d.ts +30 -103
- package/dist/core/slot/value.d.ts +28 -3
- package/dist/core/slot/value.js +93 -57
- package/dist/dev-overlay/protocol.d.ts +74 -8
- package/dist/fn-context/build-context.d.ts +3 -1
- package/dist/fn-context/build-context.js +26 -10
- package/dist/fn-context/fake/empty-api.js +9 -28
- package/dist/fn-context/fake/index.d.ts +13 -4
- package/dist/fn-context/fake/index.js +29 -2
- package/dist/fn-context/fn-params.d.ts +3 -0
- package/dist/fn-context/fn-params.js +10 -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 +20 -9
- package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +32 -0
- package/dist/fn-context/rpc/case-orchestrator-tools.js +12 -0
- package/dist/fn-context/rpc/errors.d.ts +13 -0
- package/dist/fn-context/rpc/errors.js +22 -0
- package/dist/fn-context/rpc/index.d.ts +4 -2
- package/dist/fn-context/rpc/index.js +4 -2
- package/dist/fn-context/rpc/integration/index.d.ts +15 -5
- 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/log.d.ts +11 -1
- package/dist/fn-context/rpc/platform.d.ts +13 -3
- package/dist/fn-context/rpc/platform.js +1 -1
- package/dist/fn-context/rpc/records.d.ts +85 -0
- package/dist/fn-context/rpc/records.js +24 -0
- package/dist/fn-context/rpc/trpc-client.d.ts +44 -2
- package/dist/fn-context/rpc/trpc-client.js +222 -12
- package/dist/fn-context/rpc/trpc-init.d.ts +21 -3
- package/dist/fn-context/rpc/trpc-init.js +10 -4
- package/dist/fn-context/rpc/trpc-router-factory.d.ts +111 -7
- 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 +52 -5
- package/dist/index.d.ts +36 -46
- package/dist/index.js +30 -33
- package/dist/logger.d.ts +11 -0
- package/dist/logger.js +49 -0
- package/dist/platform.d.ts +75 -0
- package/dist/platform.js +57 -0
- package/dist/testing-compile-child.d.ts +2 -0
- package/dist/testing-compile-child.js +20 -0
- package/dist/testing.d.ts +368 -0
- package/dist/testing.js +439 -0
- package/dist/voice-service/actions.d.ts +50 -6
- package/dist/voice-service/index.d.ts +2 -0
- package/dist/voice-service/index.js +2 -0
- package/dist/voice-service/protocol.d.ts +604 -0
- package/dist/voice-service/protocol.js +67 -0
- package/dist/voice-service/types.d.ts +55 -8
- package/dist/worker.d.ts +11 -0
- package/dist/worker.js +11 -0
- package/package.json +38 -15
- 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/functions/func-ref.d.ts +0 -16
- package/dist/core/functions/func-ref.js +0 -20
- 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,28 +1,27 @@
|
|
|
1
1
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { resolveCaseContextViewFn } from '../../core/functions/define/case-context.js';
|
|
5
|
-
import { resolveFuncName } from '../../core/functions/func-ref.js';
|
|
6
4
|
import { compileSlotSchema } from '../../core/slot/compile-schema.js';
|
|
5
|
+
import { subjectTableIssues } from '../../core/slot/company-metadata.js';
|
|
6
|
+
import { ensureCompanyStub, ensureStub } from '../codegen/generate.js';
|
|
7
7
|
import { withCompanyImportGraph } from '../company-import-graph.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/** SequenceBuild / SequenceConfigBuild cache key. Bump when compiled `code` shape changes. */
|
|
8
|
+
import { ORCHESTRATOR_FUNCTION, } from '../../core/case-orchestrator/types.js';
|
|
9
|
+
import { COMPANY_RESOLVE_FUNCTION, RESOLVE_FUNCTION, RESOLVE_MODULE } from '../../core/party/types.js';
|
|
10
|
+
import { compileVariables } from '../../core/sequence/index.js';
|
|
11
|
+
import { WEBHOOK_RECEIVED_FUNCTION } from '../../core/functions/events.js';
|
|
12
|
+
import { SCHEDULES_MODULE } from '../../core/functions/schedules.js';
|
|
13
|
+
import { isPlatformName, listSequenceIds, loadCompanySchema, loadCompanyWebhook, WEBHOOK_MODULE, loadOfficeHours, loadSequenceCaseOrchestrator, loadSequenceEvents, loadSequenceFunctions, loadSequenceDefinition, loadCompanyResolver, loadSequenceResolver, loadSequenceVariables, loadPageModule, loadSessionSchema, assertNoSlotsModule, assertNoChannelsModule, } from '../load.js';
|
|
14
|
+
import { findTsModule, requireCompanyResolveModule, requirePagePath, requireResolveModule, resolveTsModule } from '../paths.js';
|
|
15
|
+
import { fatalSlotSchemaIssues } from '../slot-schema-validation.js';
|
|
16
|
+
import { readFunctionParameters } from '../function-params.js';
|
|
17
|
+
import { typecheckRepo } from '../typecheck.js';
|
|
18
|
+
import { COMPANY_SCOPE, CONTEXT_PAGE_FUNCTION, functionKey, } from '../types.js';
|
|
19
|
+
import { compileExportModuleCode, compilePageModuleCode } from './function-code.js';
|
|
20
|
+
import { loadSchedules, scheduleRegistry } from '../schedules.js';
|
|
21
|
+
import { loadOnError } from '../errors.js';
|
|
22
|
+
import { ERRORS_MODULE, ON_ERROR_FUNCTION } from '../../core/functions/errors.js';
|
|
23
|
+
import { toEventRegistry, toFunctionRegistry } from './registry.js';
|
|
24
|
+
/** SequenceBuild cache key. Bump when compiled `code` shape changes. */
|
|
26
25
|
export function runtimePackageVersion() {
|
|
27
26
|
const pkgPath = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..', 'package.json');
|
|
28
27
|
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
@@ -40,101 +39,356 @@ export function runtimePackageSource(repoRoot) {
|
|
|
40
39
|
return 'npm';
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
|
-
/** Deep-clone company schema with derived computeFn normalized to string names. */
|
|
44
|
-
export function snapshotCompanySchema(company, functions) {
|
|
45
|
-
const tables = {};
|
|
46
|
-
for (const [tableName, table] of Object.entries(company)) {
|
|
47
|
-
const fields = {};
|
|
48
|
-
for (const [fieldName, field] of Object.entries(table.fields)) {
|
|
49
|
-
if (field.derived) {
|
|
50
|
-
fields[fieldName] = {
|
|
51
|
-
...field,
|
|
52
|
-
computeFn: resolveFuncName(field.computeFn, functions),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
fields[fieldName] = { ...field };
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
tables[tableName] = { ...table, fields };
|
|
60
|
-
}
|
|
61
|
-
return tables;
|
|
62
|
-
}
|
|
63
42
|
export function sequenceBuildPath(repoRoot, sequenceId) {
|
|
64
43
|
return path.join(repoRoot, 'sequences', sequenceId, 'build', 'sequence-build.json');
|
|
65
44
|
}
|
|
45
|
+
async function loadCompanySchemas(repoRoot) {
|
|
46
|
+
const schemaPath = resolveTsModule(repoRoot, 'schema', `No company schema found. Expected schema.ts or schema/index.ts under ${repoRoot}`);
|
|
47
|
+
return { company: await loadCompanySchema(schemaPath), session: await loadSessionSchema(repoRoot) };
|
|
48
|
+
}
|
|
49
|
+
/** The company schema, compiled; a schema error throws, with every issue in the message. */
|
|
50
|
+
function compileCompanySlotSchema({ company, session }) {
|
|
51
|
+
const { schema, validation } = compileSlotSchema(company, { session });
|
|
52
|
+
if (!validation.ok) {
|
|
53
|
+
const fatal = fatalSlotSchemaIssues(validation.issues);
|
|
54
|
+
if (fatal.length > 0)
|
|
55
|
+
throw new Error(fatal.map((issue) => issue.message).join('; '));
|
|
56
|
+
}
|
|
57
|
+
return schema;
|
|
58
|
+
}
|
|
66
59
|
export async function compileSequence(repoRoot, sequenceId, options = {}) {
|
|
67
|
-
return withCompanyImportGraph(repoRoot, () =>
|
|
60
|
+
return withCompanyImportGraph(repoRoot, async () => {
|
|
61
|
+
const { schemas: _, ...result } = await compileSequenceInGraph(repoRoot, sequenceId, options);
|
|
62
|
+
return result;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export async function compileSequenceBuild(repoRoot, sequenceId, options = {}) {
|
|
66
|
+
return withCompanyImportGraph(repoRoot, async () => {
|
|
67
|
+
const { schemas: _, ...result } = await compileSequenceInGraph(repoRoot, sequenceId, options);
|
|
68
|
+
return result;
|
|
69
|
+
});
|
|
68
70
|
}
|
|
69
71
|
async function compileSequenceInGraph(repoRoot, sequenceId, options) {
|
|
70
|
-
|
|
72
|
+
// The directory name is the sequence's identity in every environment (22 §10.2).
|
|
73
|
+
if (!isPlatformName(sequenceId)) {
|
|
74
|
+
throw new Error(`sequences/${sequenceId}: a sequence directory is named with letters, numbers and hyphens (at most 40)`);
|
|
75
|
+
}
|
|
71
76
|
const sequenceDir = path.join(repoRoot, 'sequences', sequenceId);
|
|
72
|
-
|
|
77
|
+
assertNoSlotsModule(sequenceDir, sequenceId);
|
|
78
|
+
// `functions/index.ts` (or `functions.ts`) is optional: without it the sequence has no functions (76 §5.5).
|
|
73
79
|
const functionsPath = findTsModule(sequenceDir, 'functions');
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
// `__gen/` is gitignored in company repos, so a fresh checkout (server-side compile from a git
|
|
81
|
+
// archive) has no `__gen/index.ts` — which functions.ts / events.ts import at runtime. Write the
|
|
82
|
+
// missing generated files first; existing ones are left untouched.
|
|
83
|
+
ensureStub(repoRoot, sequenceId);
|
|
84
|
+
const schemas = await loadCompanySchemas(repoRoot);
|
|
85
|
+
const { company, session } = schemas;
|
|
86
|
+
const authored = functionsPath ? await loadSequenceFunctions(functionsPath) : {};
|
|
87
|
+
// The conversation follows the page (17b): what to do next is worked out from it, not from an agenda.
|
|
88
|
+
for (const removed of ['agenda', 'agendas']) {
|
|
89
|
+
if (findTsModule(sequenceDir, removed)) {
|
|
90
|
+
throw new Error(`sequences/${sequenceId}/${removed}.ts is no longer supported: the conversation follows the page — write one page function per channel in context.page.ts`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const caseOrchestratorPath = findTsModule(sequenceDir, 'orchestrator');
|
|
94
|
+
if (Object.hasOwn(authored, ORCHESTRATOR_FUNCTION)) {
|
|
95
|
+
throw new Error(`functions must not define '${ORCHESTRATOR_FUNCTION}'; it is the Case Orchestrator's, from orchestrator.ts`);
|
|
96
|
+
}
|
|
97
|
+
for (const reserved of [RESOLVE_FUNCTION, COMPANY_RESOLVE_FUNCTION]) {
|
|
98
|
+
if (Object.hasOwn(authored, reserved)) {
|
|
99
|
+
throw new Error(`functions must not define '${reserved}'; it is a resolver in ${RESOLVE_MODULE}.ts`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// The page script is known by this name among the sequence's functions (`functionKey`).
|
|
103
|
+
if (Object.hasOwn(authored, CONTEXT_PAGE_FUNCTION)) {
|
|
104
|
+
throw new Error(`functions must not define '${CONTEXT_PAGE_FUNCTION}'; it is the page script's name (context.page.ts)`);
|
|
105
|
+
}
|
|
106
|
+
// Recurring jobs are the company's only (25 §6.4): the repository root's schedules.ts.
|
|
107
|
+
if (findTsModule(sequenceDir, SCHEDULES_MODULE)) {
|
|
108
|
+
throw new Error(`sequences/${sequenceId}/${SCHEDULES_MODULE}.ts is not supported: recurring jobs go in the repository root's ${SCHEDULES_MODULE}.ts (import the sequence's functions from there) (25 §6.4)`);
|
|
109
|
+
}
|
|
110
|
+
// onError is the company's only (67 §5): the repository root's errors.ts.
|
|
111
|
+
if (findTsModule(sequenceDir, ERRORS_MODULE)) {
|
|
112
|
+
throw new Error(`sequences/${sequenceId}/${ERRORS_MODULE}.ts is not supported: onError goes in the repository root's ${ERRORS_MODULE}.ts (67 §5)`);
|
|
113
|
+
}
|
|
114
|
+
if (findTsModule(sequenceDir, 'party')) {
|
|
115
|
+
throw new Error(`sequences/${sequenceId}/party.ts is no longer supported: export ${RESOLVE_FUNCTION} from sequences/${sequenceId}/${RESOLVE_MODULE}.ts`);
|
|
116
|
+
}
|
|
117
|
+
const resolvePath = requireResolveModule(sequenceDir, sequenceId);
|
|
118
|
+
const resolver = await loadSequenceResolver(resolvePath);
|
|
119
|
+
const caseOrchestratorFn = caseOrchestratorPath ? await loadSequenceCaseOrchestrator(caseOrchestratorPath) : null;
|
|
120
|
+
const functions = {
|
|
121
|
+
...authored,
|
|
122
|
+
[RESOLVE_FUNCTION]: resolver,
|
|
123
|
+
...(caseOrchestratorFn ? { [ORCHESTRATOR_FUNCTION]: caseOrchestratorFn } : {}),
|
|
124
|
+
};
|
|
125
|
+
const eventsPath = findTsModule(sequenceDir, 'events');
|
|
126
|
+
const events = eventsPath ? await loadSequenceEvents(eventsPath) : {};
|
|
127
|
+
const collisions = Object.keys(functions).filter((name) => Object.hasOwn(events, name));
|
|
128
|
+
if (collisions.length > 0) {
|
|
129
|
+
throw new Error(`functions and events must not share names: ${collisions.join(', ')}`);
|
|
130
|
+
}
|
|
131
|
+
// The Orchestrator reads with `ctx.api.db` (15 §10.16): no view.
|
|
132
|
+
if (findTsModule(sequenceDir, 'view')) {
|
|
133
|
+
throw new Error(`sequences/${sequenceId}/view.ts is no longer supported: the Orchestrator reads with ctx.api.db, and names who a Run may contact with contacts in orchestrator.ts`);
|
|
134
|
+
}
|
|
135
|
+
// The conversation's page is the page script, always (15 §10.2): no default page.
|
|
136
|
+
const pagePath = requirePagePath(sequenceDir, sequenceId);
|
|
137
|
+
// The page's actions (76 §2.11): `actions.ts`, optional, like `functions/`.
|
|
138
|
+
const actionsPath = findTsModule(sequenceDir, 'actions') ?? null;
|
|
139
|
+
// The FAQ is the page's (24 §7): `faq` in definePage, called when the conversation starts.
|
|
140
|
+
if (findTsModule(sequenceDir, 'knowledge')) {
|
|
141
|
+
throw new Error(`sequences/${sequenceId}/knowledge.ts is no longer supported: return the FAQ from definePage({ faq: (ctx) => [...] }) in context.page.ts (24 §7)`);
|
|
142
|
+
}
|
|
143
|
+
const { subject, label } = await loadSequenceDefinition(sequenceDir);
|
|
144
|
+
// One schema for the whole company (28 §2): the sequence only names its subject.
|
|
145
|
+
const { schema, validation } = compileSlotSchema(company, { session });
|
|
146
|
+
const subjectIssues = subjectTableIssues(company, subject);
|
|
147
|
+
if (subjectIssues.length > 0)
|
|
148
|
+
throw new Error(subjectIssues.map((i) => i.message).join('; '));
|
|
89
149
|
if (!validation.ok) {
|
|
90
|
-
const fatal = validation.issues
|
|
150
|
+
const fatal = fatalSlotSchemaIssues(validation.issues);
|
|
91
151
|
if (fatal.length > 0) {
|
|
92
152
|
throw new Error(fatal.map((i) => i.message).join('; '));
|
|
93
153
|
}
|
|
94
154
|
}
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
155
|
+
const declared = await loadSequenceVariables(sequenceDir);
|
|
156
|
+
const variables = compileVariables(declared.variables, declared.experiments);
|
|
157
|
+
if (variables.issues.length > 0) {
|
|
158
|
+
throw new Error(`sequences/${sequenceId}/variables.ts: ${variables.issues.join('; ')}`);
|
|
159
|
+
}
|
|
160
|
+
// The declarative load was removed (15 §10.15): the conversation reads in context.page.ts.
|
|
161
|
+
if (findTsModule(sequenceDir, 'load')) {
|
|
162
|
+
throw new Error(`sequences/${sequenceId}/load.ts: declarative load is no longer supported; read with db in context.page.ts`);
|
|
101
163
|
}
|
|
164
|
+
const orchestrator = caseOrchestratorFn ? { fn: ORCHESTRATOR_FUNCTION } : null;
|
|
102
165
|
const includeCode = options.includeCode ?? true;
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
166
|
+
const functionMaps = {};
|
|
167
|
+
const [functionsRegistry, resolveCompiled, caseOrchestratorCompiled, eventsRegistry, page,] = await Promise.all([
|
|
168
|
+
toFunctionRegistry(authored, { includeCode, ...(functionsPath ? { modulePath: functionsPath } : {}), sourceMaps: functionMaps }),
|
|
169
|
+
includeCode ? compileExportModuleCode(resolvePath, RESOLVE_FUNCTION) : Promise.resolve(undefined),
|
|
170
|
+
caseOrchestratorPath && includeCode
|
|
171
|
+
? compileExportModuleCode(caseOrchestratorPath, ORCHESTRATOR_FUNCTION)
|
|
172
|
+
: Promise.resolve(undefined),
|
|
173
|
+
toEventRegistry(events, { includeCode, modulePath: eventsPath, sourceMaps: functionMaps }),
|
|
174
|
+
compilePageModuleCode(pagePath, actionsPath),
|
|
106
175
|
]);
|
|
176
|
+
const resolveCode = codeKeepingMap(RESOLVE_FUNCTION, resolveCompiled, functionMaps);
|
|
177
|
+
const caseOrchestratorCode = codeKeepingMap(ORCHESTRATOR_FUNCTION, caseOrchestratorCompiled, functionMaps);
|
|
178
|
+
const pageCode = page.code;
|
|
179
|
+
const { channels, actions: actionNames } = loadPageModule(pageCode, sequenceId);
|
|
180
|
+
const runtimeVersion = runtimePackageVersion();
|
|
107
181
|
const build = {
|
|
108
182
|
sequenceId,
|
|
109
|
-
|
|
110
|
-
engineVersion:
|
|
183
|
+
label: typeof label === 'string' && label.trim() ? label.trim() : sequenceId,
|
|
184
|
+
engineVersion: runtimeVersion,
|
|
185
|
+
runtimeVersion,
|
|
111
186
|
runtimeSource: options.runtimeSource ?? runtimePackageSource(repoRoot),
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
187
|
+
subject: subject,
|
|
188
|
+
variables: variables.variables,
|
|
189
|
+
experiments: variables.experiments,
|
|
190
|
+
functions: {
|
|
191
|
+
...functionsRegistry,
|
|
192
|
+
[RESOLVE_FUNCTION]: resolveCode === undefined ? {} : { code: resolveCode },
|
|
193
|
+
...(caseOrchestratorPath ? { [ORCHESTRATOR_FUNCTION]: caseOrchestratorCode === undefined ? {} : { code: caseOrchestratorCode } } : {}),
|
|
194
|
+
},
|
|
195
|
+
events: eventsRegistry,
|
|
196
|
+
officeHours: await loadOfficeHours(sequenceDir),
|
|
197
|
+
orchestrator,
|
|
198
|
+
contextPage: { code: pageCode, channels, ...functionParameters(authored, functionsPath), ...actionParameters(actionsPath, actionNames, sequenceId) },
|
|
119
199
|
};
|
|
120
200
|
const outPath = sequenceBuildPath(repoRoot, sequenceId);
|
|
121
201
|
if (!options.dryRun) {
|
|
122
202
|
mkdirSync(path.dirname(outPath), { recursive: true });
|
|
123
203
|
writeFileSync(outPath, `${JSON.stringify(build, null, 2)}\n`, 'utf8');
|
|
124
204
|
}
|
|
125
|
-
return {
|
|
205
|
+
return {
|
|
206
|
+
sequenceId,
|
|
207
|
+
outPath,
|
|
208
|
+
build,
|
|
209
|
+
schema,
|
|
210
|
+
schemas,
|
|
211
|
+
sourceMaps: keyedMaps(sequenceId, { ...functionMaps, [CONTEXT_PAGE_FUNCTION]: page.map }),
|
|
212
|
+
wrote: !options.dryRun,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/** Maps by name in `scope`, keyed as the platform knows the code: its {@link functionKey}. */
|
|
216
|
+
function keyedMaps(scope, byName) {
|
|
217
|
+
return Object.fromEntries(Object.entries(byName).map(([name, map]) => [functionKey(scope, name), map]));
|
|
218
|
+
}
|
|
219
|
+
/** A compiled function's code, its map kept in `maps` by the function's name; nothing when not compiled. */
|
|
220
|
+
function codeKeepingMap(name, compiled, maps) {
|
|
221
|
+
if (!compiled)
|
|
222
|
+
return undefined;
|
|
223
|
+
maps[name] = compiled.map;
|
|
224
|
+
return compiled.code;
|
|
126
225
|
}
|
|
127
226
|
export async function compileAll(repoRoot, options = {}) {
|
|
128
227
|
return withCompanyImportGraph(repoRoot, async () => {
|
|
129
228
|
const ids = options.sequenceIds ?? listSequenceIds(repoRoot);
|
|
130
229
|
if (ids.length === 0) {
|
|
131
|
-
throw new Error(`No sequences
|
|
230
|
+
throw new Error(`No sequences found under ${path.join(repoRoot, 'sequences')} (a sequence is a directory with index.ts)`);
|
|
132
231
|
}
|
|
232
|
+
compileCompanySlotSchema(await loadCompanySchemas(repoRoot));
|
|
133
233
|
const results = [];
|
|
134
234
|
for (const sequenceId of ids) {
|
|
135
|
-
|
|
235
|
+
const { schemas: _, ...result } = await compileSequenceInGraph(repoRoot, sequenceId, options);
|
|
236
|
+
results.push(result);
|
|
136
237
|
}
|
|
137
238
|
return results;
|
|
138
239
|
});
|
|
139
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* The company part of the company build (22 §5): the root `resolve.ts` as `companyResolve`, the root
|
|
243
|
+
* `webhook.ts` as `webhook.received`, the root `schedules.ts` as `schedule.<name>` (25 §6.4), the root
|
|
244
|
+
* `errors.ts` as `onError` (67 §5), and the
|
|
245
|
+
* company schema with no subject. An error in it fails the
|
|
246
|
+
* whole compile.
|
|
247
|
+
*/
|
|
248
|
+
export async function compileCompanyPart(repoRoot, options = {}) {
|
|
249
|
+
return (await compileCompanyPartWithMaps(repoRoot, options)).part;
|
|
250
|
+
}
|
|
251
|
+
/** {@link compileCompanyPart}, with the source maps of its functions by `functionKey` (kept apart from the build). */
|
|
252
|
+
async function compileCompanyPartWithMaps(repoRoot, options) {
|
|
253
|
+
return withCompanyImportGraph(repoRoot, async () => {
|
|
254
|
+
const includeCode = options.includeCode ?? true;
|
|
255
|
+
// `resolve.ts` and `webhook.ts` import the root `__gen/`, which a fresh checkout does not have.
|
|
256
|
+
ensureCompanyStub(repoRoot);
|
|
257
|
+
// The schema first: an error in it fails the compile before any company code loads.
|
|
258
|
+
const schema = compileCompanySlotSchema(await loadCompanySchemas(repoRoot));
|
|
259
|
+
const companyResolvePath = requireCompanyResolveModule(repoRoot);
|
|
260
|
+
await loadCompanyResolver(companyResolvePath);
|
|
261
|
+
assertNoChannelsModule(repoRoot);
|
|
262
|
+
const webhookPath = findTsModule(repoRoot, WEBHOOK_MODULE);
|
|
263
|
+
if (webhookPath)
|
|
264
|
+
await loadCompanyWebhook(webhookPath);
|
|
265
|
+
const schedules = await loadSchedules(repoRoot);
|
|
266
|
+
const onError = await loadOnError(repoRoot);
|
|
267
|
+
const sourceMaps = {};
|
|
268
|
+
const [resolveCompiled, webhookCompiled, schedulesRegistry, onErrorCompiled] = await Promise.all([
|
|
269
|
+
includeCode ? compileExportModuleCode(companyResolvePath, RESOLVE_FUNCTION) : Promise.resolve(undefined),
|
|
270
|
+
includeCode && webhookPath ? compileExportModuleCode(webhookPath, 'received') : Promise.resolve(undefined),
|
|
271
|
+
schedules ? scheduleRegistry(schedules, includeCode, sourceMaps) : Promise.resolve({}),
|
|
272
|
+
includeCode && onError ? compileExportModuleCode(onError.path, ON_ERROR_FUNCTION) : Promise.resolve(undefined),
|
|
273
|
+
]);
|
|
274
|
+
const entry = (name, compiled) => {
|
|
275
|
+
const code = codeKeepingMap(name, compiled, sourceMaps);
|
|
276
|
+
return code === undefined ? {} : { code };
|
|
277
|
+
};
|
|
278
|
+
const part = {
|
|
279
|
+
functions: {
|
|
280
|
+
[COMPANY_RESOLVE_FUNCTION]: entry(COMPANY_RESOLVE_FUNCTION, resolveCompiled),
|
|
281
|
+
...(webhookPath ? { [WEBHOOK_RECEIVED_FUNCTION]: entry(WEBHOOK_RECEIVED_FUNCTION, webhookCompiled) } : {}),
|
|
282
|
+
...schedulesRegistry,
|
|
283
|
+
...(onError ? { [ON_ERROR_FUNCTION]: entry(ON_ERROR_FUNCTION, onErrorCompiled) } : {}),
|
|
284
|
+
},
|
|
285
|
+
...(schedules ? { schedules: schedules.manifest } : {}),
|
|
286
|
+
schema,
|
|
287
|
+
runtimeVersion: runtimePackageVersion(),
|
|
288
|
+
runtimeSource: options.runtimeSource ?? runtimePackageSource(repoRoot),
|
|
289
|
+
};
|
|
290
|
+
return { part, sourceMaps: keyedMaps(COMPANY_SCOPE, sourceMaps) };
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
export const COMPILE_CONCURRENCY = 4;
|
|
294
|
+
export const COMPILE_SEQUENCE_TIMEOUT_MS = 5 * 60_000;
|
|
295
|
+
function withDeadline(work, ms, message) {
|
|
296
|
+
return new Promise((resolve, reject) => {
|
|
297
|
+
const timer = setTimeout(() => reject(new Error(message)), ms);
|
|
298
|
+
work.then((value) => {
|
|
299
|
+
clearTimeout(timer);
|
|
300
|
+
resolve(value);
|
|
301
|
+
}, (error) => {
|
|
302
|
+
clearTimeout(timer);
|
|
303
|
+
reject(error);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
async function mapPool(items, limit, run) {
|
|
308
|
+
if (items.length === 0)
|
|
309
|
+
return;
|
|
310
|
+
let cursor = 0;
|
|
311
|
+
const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
312
|
+
while (cursor < items.length) {
|
|
313
|
+
const item = items[cursor];
|
|
314
|
+
cursor += 1;
|
|
315
|
+
if (item === undefined)
|
|
316
|
+
return;
|
|
317
|
+
await run(item);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
await Promise.all(workers);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Compile the company part (its schema first) once, then every named sequence in this process, then
|
|
324
|
+
* type-check the repository. A sequence error is collected; a company schema error or a type error
|
|
325
|
+
* rejects the whole call, a type error with the tsc output as its message.
|
|
326
|
+
*/
|
|
327
|
+
export async function compileRepo(repoRoot, options) {
|
|
328
|
+
return withCompanyImportGraph(repoRoot, async () => {
|
|
329
|
+
const runtimeSource = options.runtimeSource ?? runtimePackageSource(repoRoot);
|
|
330
|
+
const { part: company, sourceMaps: companySourceMaps } = await compileCompanyPartWithMaps(repoRoot, {
|
|
331
|
+
includeCode: true,
|
|
332
|
+
runtimeSource,
|
|
333
|
+
});
|
|
334
|
+
options.onEvent?.({
|
|
335
|
+
type: 'log',
|
|
336
|
+
text: `Repo build runtime: ${runtimePackageVersion()} (${runtimeSource})`,
|
|
337
|
+
});
|
|
338
|
+
const timeoutMs = options.sequenceTimeoutMs ?? COMPILE_SEQUENCE_TIMEOUT_MS;
|
|
339
|
+
const sequences = {};
|
|
340
|
+
await mapPool(options.sequences, options.concurrency ?? COMPILE_CONCURRENCY, async (sequenceId) => {
|
|
341
|
+
options.onEvent?.({ type: 'sequence-started', sequence: sequenceId });
|
|
342
|
+
options.onEvent?.({ type: 'log', sequence: sequenceId, text: `Compiling ${sequenceId}...` });
|
|
343
|
+
try {
|
|
344
|
+
const result = await withDeadline(compileSequenceInGraph(repoRoot, sequenceId, {
|
|
345
|
+
dryRun: true,
|
|
346
|
+
runtimeSource,
|
|
347
|
+
includeCode: true,
|
|
348
|
+
}), timeoutMs, `compile timed out after ${Math.round(timeoutMs / 60_000)} minutes`);
|
|
349
|
+
sequences[sequenceId] = { ok: true, build: result.build, sourceMaps: result.sourceMaps };
|
|
350
|
+
options.onEvent?.({ type: 'log', sequence: sequenceId, text: `Compiled ${sequenceId}` });
|
|
351
|
+
options.onEvent?.({ type: 'sequence-finished', sequence: sequenceId, ok: true });
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
355
|
+
sequences[sequenceId] = { ok: false, error: message };
|
|
356
|
+
options.onEvent?.({ type: 'sequence-finished', sequence: sequenceId, ok: false, error: message });
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
// A failed sequence already fails the release, and type:gen would only repeat its error.
|
|
360
|
+
if (Object.values(sequences).every((outcome) => outcome.ok)) {
|
|
361
|
+
await typecheckRepo(repoRoot, (text) => options.onEvent?.({ type: 'log', text }));
|
|
362
|
+
}
|
|
363
|
+
return { company, companySourceMaps, sequences };
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
/** The page actions' parameters, from their `args` types (76 §2.11): `actions` of `actions.ts`, as functions' are read; nothing without. */
|
|
367
|
+
function actionParameters(actionsPath, names, sequenceId) {
|
|
368
|
+
if (!actionsPath || names.length === 0)
|
|
369
|
+
return {};
|
|
370
|
+
const typed = readFunctionParameters(actionsPath, 'actions');
|
|
371
|
+
const out = {};
|
|
372
|
+
for (const name of names) {
|
|
373
|
+
const parameters = Object.hasOwn(typed, name) ? typed[name] : undefined;
|
|
374
|
+
if (!parameters)
|
|
375
|
+
throw new Error(`sequences/${sequenceId}/${path.basename(actionsPath)}: actions.${name}: the type checker does not see it as a function`);
|
|
376
|
+
out[name] = { parameters };
|
|
377
|
+
}
|
|
378
|
+
return { actions: out };
|
|
379
|
+
}
|
|
380
|
+
/** The functions' parameters, from their `args` types (38 §2.4), for the page's function buttons; nothing without functions. */
|
|
381
|
+
function functionParameters(functions, functionsPath) {
|
|
382
|
+
if (!functionsPath || Object.keys(functions).length === 0)
|
|
383
|
+
return {};
|
|
384
|
+
const typed = readFunctionParameters(functionsPath, 'functions');
|
|
385
|
+
const out = {};
|
|
386
|
+
for (const name of Object.keys(functions)) {
|
|
387
|
+
const parameters = Object.hasOwn(typed, name) ? typed[name] : undefined;
|
|
388
|
+
if (!parameters)
|
|
389
|
+
throw new Error(`${functionsPath}: functions.${name}: the type checker does not see it as a function`);
|
|
390
|
+
out[name] = { parameters };
|
|
391
|
+
}
|
|
392
|
+
return { functions: out };
|
|
393
|
+
}
|
|
140
394
|
//# sourceMappingURL=compile-sequence.js.map
|
|
@@ -1,10 +1,26 @@
|
|
|
1
|
+
import type { FunctionSourceMap } from '../types.js';
|
|
1
2
|
/**
|
|
2
3
|
* Compile a single function implementation to a standalone JS expression string
|
|
3
4
|
* suitable for QuickJS `eval` / registry `code` fields (minified).
|
|
4
5
|
*/
|
|
5
6
|
export declare function compileFunctionCode(fn: (...args: never[]) => unknown): Promise<string>;
|
|
7
|
+
/** A function's or page script's compiled code, and where its positions were in the company's files. */
|
|
8
|
+
export type CompiledModule = {
|
|
9
|
+
code: string;
|
|
10
|
+
map: FunctionSourceMap;
|
|
11
|
+
};
|
|
6
12
|
/** Bundle one registered function with module-local helpers and constants. */
|
|
7
|
-
export declare function compileFunctionModuleCode(modulePath: string, functionName: string): Promise<
|
|
8
|
-
/** Bundle
|
|
9
|
-
export declare function
|
|
13
|
+
export declare function compileFunctionModuleCode(modulePath: string, functionName: string): Promise<CompiledModule>;
|
|
14
|
+
/** Bundle one event handler (a plain function under the `events` export) with module-local helpers. */
|
|
15
|
+
export declare function compileEventModuleCode(modulePath: string, eventName: string): Promise<CompiledModule>;
|
|
16
|
+
/** Bundle one job's `run` of a `schedules.ts` (25 §6.4) with module-local helpers. */
|
|
17
|
+
export declare function compileScheduleModuleCode(modulePath: string, scheduleName: string): Promise<CompiledModule>;
|
|
18
|
+
/** Bundle a module's named export (a function) with its helpers. */
|
|
19
|
+
export declare function compileExportModuleCode(modulePath: string, exportName: string): Promise<CompiledModule>;
|
|
20
|
+
/**
|
|
21
|
+
* Bundle a sequence's page script (`context.page.ts`, 15 §10.2) with its helpers, and its page actions
|
|
22
|
+
* (`actions.ts`, 76 §2.11) when it has them: the result evaluates to `pageEntry(module, actions)`, which
|
|
23
|
+
* renders the page or runs one of its actions (`core/page/define.ts`).
|
|
24
|
+
*/
|
|
25
|
+
export declare function compilePageModuleCode(modulePath: string, actionsPath?: string | null): Promise<CompiledModule>;
|
|
10
26
|
//# sourceMappingURL=function-code.d.ts.map
|