@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.
Files changed (319) hide show
  1. package/README.md +30 -10
  2. package/dist/builder/codegen/emit.d.ts +25 -12
  3. package/dist/builder/codegen/emit.js +339 -78
  4. package/dist/builder/codegen/generate.d.ts +21 -2
  5. package/dist/builder/codegen/generate.js +147 -34
  6. package/dist/builder/company-import-graph.d.ts +2 -0
  7. package/dist/builder/company-import-graph.js +40 -8
  8. package/dist/builder/company-imports.d.ts +29 -0
  9. package/dist/builder/company-imports.js +122 -0
  10. package/dist/builder/compile/compile-sequence.d.ts +61 -8
  11. package/dist/builder/compile/compile-sequence.js +334 -80
  12. package/dist/builder/compile/function-code.d.ts +19 -3
  13. package/dist/builder/compile/function-code.js +123 -45
  14. package/dist/builder/compile/registry.d.ts +7 -3
  15. package/dist/builder/compile/registry.js +30 -27
  16. package/dist/builder/errors.d.ts +9 -0
  17. package/dist/builder/errors.js +17 -0
  18. package/dist/builder/function-params.d.ts +10 -0
  19. package/dist/builder/function-params.js +203 -0
  20. package/dist/builder/load.d.ts +70 -10
  21. package/dist/builder/load.js +258 -67
  22. package/dist/builder/paths.d.ts +9 -1
  23. package/dist/builder/paths.js +32 -2
  24. package/dist/builder/schedules.d.ts +25 -0
  25. package/dist/builder/schedules.js +101 -0
  26. package/dist/builder/slot-schema-validation.d.ts +4 -0
  27. package/dist/builder/slot-schema-validation.js +10 -0
  28. package/dist/builder/typecheck.d.ts +8 -0
  29. package/dist/builder/typecheck.js +102 -0
  30. package/dist/builder/types.d.ts +127 -19
  31. package/dist/builder/types.js +21 -1
  32. package/dist/cli/auth/auth.d.ts +37 -0
  33. package/dist/cli/auth/auth.js +211 -0
  34. package/dist/cli/auth/backend-url.d.ts +5 -0
  35. package/dist/cli/auth/backend-url.js +25 -0
  36. package/dist/cli/auth/clipboard.d.ts +9 -0
  37. package/dist/cli/auth/clipboard.js +38 -0
  38. package/dist/cli/auth/http.d.ts +20 -0
  39. package/dist/cli/auth/http.js +27 -0
  40. package/dist/cli/auth/index.d.ts +10 -0
  41. package/dist/cli/auth/index.js +27 -0
  42. package/dist/cli/auth/progress.d.ts +12 -0
  43. package/dist/cli/auth/progress.js +15 -0
  44. package/dist/cli/auth/serve-login.d.ts +8 -0
  45. package/dist/cli/auth/serve-login.js +24 -0
  46. package/dist/cli/calls/index.d.ts +177 -0
  47. package/dist/cli/calls/index.js +96 -0
  48. package/dist/cli/compile/index.js +3 -0
  49. package/dist/cli/config.d.ts +10 -0
  50. package/dist/cli/config.js +52 -0
  51. package/dist/cli/debug/index.d.ts +31 -0
  52. package/dist/cli/debug/index.js +119 -0
  53. package/dist/cli/exec/index.d.ts +39 -0
  54. package/dist/cli/exec/index.js +138 -0
  55. package/dist/cli/exec/session.d.ts +48 -0
  56. package/dist/cli/exec/session.js +82 -0
  57. package/dist/cli/exec/trace.d.ts +18 -0
  58. package/dist/cli/exec/trace.js +52 -0
  59. package/dist/cli/index.js +112 -9
  60. package/dist/cli/logs/index.d.ts +47 -0
  61. package/dist/cli/logs/index.js +113 -0
  62. package/dist/cli/mobile/index.d.ts +12 -0
  63. package/dist/cli/mobile/index.js +405 -0
  64. package/dist/cli/serve/index.d.ts +109 -3
  65. package/dist/cli/serve/index.js +506 -118
  66. package/dist/cli/turns/index.d.ts +105 -0
  67. package/dist/cli/turns/index.js +128 -0
  68. package/dist/cli/turns/run.d.ts +13 -0
  69. package/dist/cli/turns/run.js +57 -0
  70. package/dist/cli/turns/shadow.d.ts +112 -0
  71. package/dist/cli/turns/shadow.js +54 -0
  72. package/dist/cli/type-gen/index.js +9 -9
  73. package/dist/compiler.d.ts +7 -0
  74. package/dist/compiler.js +7 -0
  75. package/dist/compute-host/compute-host.d.ts +14 -23
  76. package/dist/compute-host/compute-host.js +18 -30
  77. package/dist/compute-host/index.d.ts +2 -4
  78. package/dist/compute-host/index.js +1 -2
  79. package/dist/compute-host/source-compute-host.d.ts +10 -10
  80. package/dist/compute-host/source-compute-host.js +33 -40
  81. package/dist/core/case-orchestrator/contact-hours.d.ts +70 -0
  82. package/dist/core/case-orchestrator/contact-hours.js +127 -0
  83. package/dist/core/case-orchestrator/index.d.ts +3 -0
  84. package/dist/core/case-orchestrator/index.js +3 -0
  85. package/dist/core/case-orchestrator/render.d.ts +75 -0
  86. package/dist/core/case-orchestrator/render.js +244 -0
  87. package/dist/core/case-orchestrator/time.d.ts +11 -0
  88. package/dist/core/case-orchestrator/time.js +29 -0
  89. package/dist/core/case-orchestrator/types.d.ts +708 -0
  90. package/dist/core/case-orchestrator/types.js +42 -0
  91. package/dist/core/context/call.d.ts +291 -0
  92. package/dist/core/context/call.js +94 -0
  93. package/dist/core/context/channels.d.ts +60 -0
  94. package/dist/core/context/channels.js +35 -0
  95. package/dist/core/context/contact.d.ts +96 -6
  96. package/dist/core/context/contact.js +48 -2
  97. package/dist/core/context/email-message.d.ts +198 -0
  98. package/dist/core/context/email-message.js +86 -0
  99. package/dist/core/context/email.d.ts +109 -0
  100. package/dist/core/context/email.js +90 -0
  101. package/dist/core/context/exchanges.d.ts +167 -0
  102. package/dist/core/context/exchanges.js +81 -0
  103. package/dist/core/context/instances.d.ts +307 -0
  104. package/dist/core/context/instances.js +137 -0
  105. package/dist/core/context/kv.d.ts +113 -0
  106. package/dist/core/context/kv.js +60 -0
  107. package/dist/core/context/platform-registry.d.ts +544 -4
  108. package/dist/core/context/platform-registry.js +14 -2
  109. package/dist/core/context/platform.d.ts +2 -1
  110. package/dist/core/context/sms.d.ts +177 -0
  111. package/dist/core/context/sms.js +77 -0
  112. package/dist/core/context/types.d.ts +79 -48
  113. package/dist/core/context/types.js +1 -7
  114. package/dist/core/conversation/index.d.ts +85 -0
  115. package/dist/core/conversation/index.js +133 -0
  116. package/dist/core/functions/errors.d.ts +74 -0
  117. package/dist/core/functions/errors.js +26 -0
  118. package/dist/core/functions/events.d.ts +192 -0
  119. package/dist/core/functions/events.js +23 -0
  120. package/dist/core/functions/schedules.d.ts +50 -0
  121. package/dist/core/functions/schedules.js +20 -0
  122. package/dist/core/functions/types.d.ts +29 -73
  123. package/dist/core/functions/types.js +1 -4
  124. package/dist/core/office-hours/index.d.ts +39 -0
  125. package/dist/core/office-hours/index.js +187 -0
  126. package/dist/core/page/define.d.ts +904 -0
  127. package/dist/core/page/define.js +518 -0
  128. package/dist/core/page/envelope.d.ts +55 -0
  129. package/dist/core/page/envelope.js +4 -0
  130. package/dist/core/page/fns.d.ts +448 -0
  131. package/dist/core/page/fns.js +539 -0
  132. package/dist/core/page/memory-reader.d.ts +27 -0
  133. package/dist/core/page/memory-reader.js +299 -0
  134. package/dist/core/page/ops.d.ts +58 -0
  135. package/dist/core/page/ops.js +220 -0
  136. package/dist/core/page/page-host.d.ts +20 -0
  137. package/dist/core/page/page-host.js +57 -0
  138. package/dist/core/page/records-query.d.ts +234 -0
  139. package/dist/core/page/records-query.js +780 -0
  140. package/dist/core/page/render.d.ts +295 -0
  141. package/dist/core/page/render.js +1060 -0
  142. package/dist/core/page/sandbox.d.ts +85 -0
  143. package/dist/core/page/sandbox.js +357 -0
  144. package/dist/core/page/time-format.d.ts +46 -0
  145. package/dist/core/page/time-format.js +125 -0
  146. package/dist/core/page/timeline.d.ts +40 -0
  147. package/dist/core/page/timeline.js +2 -0
  148. package/dist/core/page/typed.d.ts +648 -0
  149. package/dist/core/page/typed.js +2 -0
  150. package/dist/core/page/workspace.d.ts +57 -0
  151. package/dist/core/page/workspace.js +266 -0
  152. package/dist/core/party/index.d.ts +3 -0
  153. package/dist/core/party/index.js +3 -0
  154. package/dist/core/party/schema.d.ts +208 -0
  155. package/dist/core/party/schema.js +113 -0
  156. package/dist/core/party/types.d.ts +35 -0
  157. package/dist/core/party/types.js +15 -0
  158. package/dist/core/sequence/define.d.ts +56 -0
  159. package/dist/core/sequence/define.js +10 -0
  160. package/dist/core/sequence/index.d.ts +63 -0
  161. package/dist/core/sequence/index.js +231 -0
  162. package/dist/core/slot/binding.d.ts +40 -0
  163. package/dist/core/slot/binding.js +2 -0
  164. package/dist/core/slot/company-metadata.d.ts +102 -0
  165. package/dist/core/slot/company-metadata.js +536 -0
  166. package/dist/core/slot/compile-schema.d.ts +19 -13
  167. package/dist/core/slot/compile-schema.js +51 -248
  168. package/dist/core/slot/contact-timezone.d.ts +110 -0
  169. package/dist/core/slot/contact-timezone.js +186 -0
  170. package/dist/core/slot/field.d.ts +2 -25
  171. package/dist/core/slot/field.js +0 -71
  172. package/dist/core/slot/id-ref.d.ts +17 -2
  173. package/dist/core/slot/id-ref.js +16 -8
  174. package/dist/core/slot/index.d.ts +12 -13
  175. package/dist/core/slot/index.js +11 -12
  176. package/dist/core/slot/naming.d.ts +15 -0
  177. package/dist/core/slot/naming.js +96 -0
  178. package/dist/core/slot/platform-fields.d.ts +119 -0
  179. package/dist/core/slot/platform-fields.js +121 -0
  180. package/dist/core/slot/ref.d.ts +16 -0
  181. package/dist/core/slot/ref.js +14 -0
  182. package/dist/core/slot/row.d.ts +2 -9
  183. package/dist/core/slot/row.js +13 -23
  184. package/dist/core/slot/schema-compat.d.ts +17 -0
  185. package/dist/core/slot/schema-compat.js +103 -0
  186. package/dist/core/slot/schema.d.ts +353 -76
  187. package/dist/core/slot/schema.js +163 -10
  188. package/dist/core/slot/types.d.ts +30 -103
  189. package/dist/core/slot/value.d.ts +28 -3
  190. package/dist/core/slot/value.js +93 -57
  191. package/dist/dev-overlay/protocol.d.ts +74 -8
  192. package/dist/fn-context/build-context.d.ts +3 -1
  193. package/dist/fn-context/build-context.js +26 -10
  194. package/dist/fn-context/fake/empty-api.js +9 -28
  195. package/dist/fn-context/fake/index.d.ts +13 -4
  196. package/dist/fn-context/fake/index.js +29 -2
  197. package/dist/fn-context/fn-params.d.ts +3 -0
  198. package/dist/fn-context/fn-params.js +10 -0
  199. package/dist/fn-context/index.d.ts +5 -5
  200. package/dist/fn-context/index.js +4 -4
  201. package/dist/fn-context/log.js +2 -2
  202. package/dist/fn-context/make-ctx.d.ts +11 -0
  203. package/dist/fn-context/make-ctx.js +20 -9
  204. package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +32 -0
  205. package/dist/fn-context/rpc/case-orchestrator-tools.js +12 -0
  206. package/dist/fn-context/rpc/errors.d.ts +13 -0
  207. package/dist/fn-context/rpc/errors.js +22 -0
  208. package/dist/fn-context/rpc/index.d.ts +4 -2
  209. package/dist/fn-context/rpc/index.js +4 -2
  210. package/dist/fn-context/rpc/integration/index.d.ts +15 -5
  211. package/dist/fn-context/rpc/integration/index.js +1 -1
  212. package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
  213. package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
  214. package/dist/fn-context/rpc/log.d.ts +11 -1
  215. package/dist/fn-context/rpc/platform.d.ts +13 -3
  216. package/dist/fn-context/rpc/platform.js +1 -1
  217. package/dist/fn-context/rpc/records.d.ts +85 -0
  218. package/dist/fn-context/rpc/records.js +24 -0
  219. package/dist/fn-context/rpc/trpc-client.d.ts +44 -2
  220. package/dist/fn-context/rpc/trpc-client.js +222 -12
  221. package/dist/fn-context/rpc/trpc-init.d.ts +21 -3
  222. package/dist/fn-context/rpc/trpc-init.js +10 -4
  223. package/dist/fn-context/rpc/trpc-router-factory.d.ts +111 -7
  224. package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
  225. package/dist/fn-context/run-scope.d.ts +4 -0
  226. package/dist/fn-context/run-scope.js +9 -0
  227. package/dist/fn-context/types.d.ts +52 -5
  228. package/dist/index.d.ts +36 -46
  229. package/dist/index.js +30 -33
  230. package/dist/logger.d.ts +11 -0
  231. package/dist/logger.js +49 -0
  232. package/dist/platform.d.ts +75 -0
  233. package/dist/platform.js +57 -0
  234. package/dist/testing-compile-child.d.ts +2 -0
  235. package/dist/testing-compile-child.js +20 -0
  236. package/dist/testing.d.ts +368 -0
  237. package/dist/testing.js +439 -0
  238. package/dist/voice-service/actions.d.ts +50 -6
  239. package/dist/voice-service/index.d.ts +2 -0
  240. package/dist/voice-service/index.js +2 -0
  241. package/dist/voice-service/protocol.d.ts +604 -0
  242. package/dist/voice-service/protocol.js +67 -0
  243. package/dist/voice-service/types.d.ts +55 -8
  244. package/dist/worker.d.ts +11 -0
  245. package/dist/worker.js +11 -0
  246. package/package.json +38 -15
  247. package/dist/builder/compile/compile-agenda.d.ts +0 -15
  248. package/dist/builder/compile/compile-agenda.js +0 -64
  249. package/dist/builder/merge.d.ts +0 -4
  250. package/dist/builder/merge.js +0 -19
  251. package/dist/compute-host/read-only-cache.d.ts +0 -20
  252. package/dist/compute-host/read-only-cache.js +0 -61
  253. package/dist/core/context/db.d.ts +0 -69
  254. package/dist/core/context/db.js +0 -44
  255. package/dist/core/context/docusign.d.ts +0 -134
  256. package/dist/core/context/docusign.js +0 -108
  257. package/dist/core/context/filevine.d.ts +0 -323
  258. package/dist/core/context/filevine.js +0 -254
  259. package/dist/core/context/http.d.ts +0 -9
  260. package/dist/core/context/http.js +0 -4
  261. package/dist/core/context/hubspot.d.ts +0 -250
  262. package/dist/core/context/hubspot.js +0 -191
  263. package/dist/core/context/twilio.d.ts +0 -50
  264. package/dist/core/context/twilio.js +0 -42
  265. package/dist/core/functions/define/case-context.d.ts +0 -14
  266. package/dist/core/functions/define/case-context.js +0 -15
  267. package/dist/core/functions/define/compute.d.ts +0 -7
  268. package/dist/core/functions/define/compute.js +0 -17
  269. package/dist/core/functions/define/custom.d.ts +0 -4
  270. package/dist/core/functions/define/custom.js +0 -8
  271. package/dist/core/functions/define/system.d.ts +0 -7
  272. package/dist/core/functions/define/system.js +0 -12
  273. package/dist/core/functions/func-ref.d.ts +0 -16
  274. package/dist/core/functions/func-ref.js +0 -20
  275. package/dist/core/slot/deps.d.ts +0 -15
  276. package/dist/core/slot/deps.js +0 -88
  277. package/dist/core/slot/derived.d.ts +0 -32
  278. package/dist/core/slot/derived.js +0 -115
  279. package/dist/core/slot/platform-session-fields.d.ts +0 -38
  280. package/dist/core/slot/platform-session-fields.js +0 -48
  281. package/dist/core/slot/sf-schema.d.ts +0 -23
  282. package/dist/core/slot/sf-schema.js +0 -125
  283. package/dist/core/slot/sf-validate.d.ts +0 -14
  284. package/dist/core/slot/sf-validate.js +0 -132
  285. package/dist/core/slot/snapshot.d.ts +0 -18
  286. package/dist/core/slot/snapshot.js +0 -138
  287. package/dist/core/slot/write.d.ts +0 -48
  288. package/dist/core/slot/write.js +0 -426
  289. package/dist/core/stage/builders.d.ts +0 -54
  290. package/dist/core/stage/builders.js +0 -31
  291. package/dist/core/stage/condition.d.ts +0 -17
  292. package/dist/core/stage/condition.js +0 -198
  293. package/dist/core/stage/drive.d.ts +0 -43
  294. package/dist/core/stage/drive.js +0 -78
  295. package/dist/core/stage/finish-when.d.ts +0 -20
  296. package/dist/core/stage/finish-when.js +0 -82
  297. package/dist/core/stage/flatten.d.ts +0 -27
  298. package/dist/core/stage/flatten.js +0 -466
  299. package/dist/core/stage/index.d.ts +0 -15
  300. package/dist/core/stage/index.js +0 -13
  301. package/dist/core/stage/interrupts.d.ts +0 -28
  302. package/dist/core/stage/interrupts.js +0 -120
  303. package/dist/core/stage/ivr-fields.d.ts +0 -9
  304. package/dist/core/stage/ivr-fields.js +0 -75
  305. package/dist/core/stage/simulate.d.ts +0 -24
  306. package/dist/core/stage/simulate.js +0 -33
  307. package/dist/core/stage/transfer-fields.d.ts +0 -19
  308. package/dist/core/stage/transfer-fields.js +0 -129
  309. package/dist/core/stage/transfer-spec.d.ts +0 -48
  310. package/dist/core/stage/transfer-spec.js +0 -113
  311. package/dist/core/stage/types.d.ts +0 -208
  312. package/dist/core/stage/types.js +0 -2
  313. package/dist/core/stage/validate.d.ts +0 -11
  314. package/dist/core/stage/validate.js +0 -330
  315. package/dist/core/stage/walk.d.ts +0 -39
  316. package/dist/core/stage/walk.js +0 -119
  317. package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
  318. package/dist/fn-context/system-args.d.ts +0 -6
  319. package/dist/fn-context/system-args.js +0 -14
@@ -1,56 +1,145 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
1
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
2
  import path from 'node:path';
3
+ import { subjectTableIssues } from '../../core/slot/company-metadata.js';
4
+ import { compileSlotSchema } from '../../core/slot/compile-schema.js';
3
5
  import { withCompanyImportGraph } from '../company-import-graph.js';
4
- import { listSequenceIds, loadCompanySchema, loadSequenceSlots } from '../load.js';
5
- import { mergeEffectiveSchema } from '../merge.js';
6
- import { findTsModule, resolveTsModule } from '../paths.js';
7
- import { emitCaseContextSource, emitCaseContextStub, emitSlotsSource, emitSlotsStub } from './emit.js';
6
+ import { assertNoSlotsModule, listSequenceIds, loadCompanySchema, loadSequenceDefinition, loadSessionSchema, } from '../load.js';
7
+ import { findTsModule, requirePagePath, resolveTsModule } from '../paths.js';
8
+ import { fatalSlotSchemaIssues } from '../slot-schema-validation.js';
9
+ import { emitCompanyGenIndexSource, emitCompanyTablesSource, emitCompanyTablesStub, emitGenIndexSource, emitSlotsSource, emitSlotsStub, } from './emit.js';
8
10
  export { listSequenceIds };
11
+ /** The repository root's `__gen/`: types for `resolve.ts` and `webhook.ts`, bound to the company's tables. */
12
+ export function companyGenPaths(repoRoot) {
13
+ return {
14
+ tablesOutPath: path.join(repoRoot, '__gen', 'tables.type.ts'),
15
+ indexOutPath: path.join(repoRoot, '__gen', 'index.ts'),
16
+ };
17
+ }
9
18
  function sequenceSlotsGenPath(repoRoot, sequenceId) {
10
19
  return path.join(repoRoot, 'sequences', sequenceId, '__gen', 'slots.type.ts');
11
20
  }
12
- function sequenceCaseContextGenPath(repoRoot, sequenceId) {
21
+ /** Generated for `slots.ts`, which was removed (15 §10.17 第 1 条); type:gen deletes a leftover one. */
22
+ function legacySlotsConfigGenPath(repoRoot, sequenceId) {
23
+ return path.join(repoRoot, 'sequences', sequenceId, '__gen', 'slots-config.type.ts');
24
+ }
25
+ /** `__gen/case-context.type.ts` (`CaseInput`, the old `c`): no entry gets a `c` any more (38 §2.2). */
26
+ function legacyCaseContextGenPath(repoRoot, sequenceId) {
13
27
  return path.join(repoRoot, 'sequences', sequenceId, '__gen', 'case-context.type.ts');
14
28
  }
29
+ /** Generated for the declarative load, which was removed (15 §10.15); type:gen deletes a leftover one. */
30
+ function legacyLoadGenPath(repoRoot, sequenceId) {
31
+ return path.join(repoRoot, 'sequences', sequenceId, '__gen', 'load.type.ts');
32
+ }
33
+ function sequenceGenIndexPath(repoRoot, sequenceId) {
34
+ return path.join(repoRoot, 'sequences', sequenceId, '__gen', 'index.ts');
35
+ }
36
+ /** The sequence's `functions` module as `__gen/index.ts` imports it, or `null` when it has none. */
37
+ function functionsImportFor(repoRoot, sequenceId) {
38
+ return moduleImportFor(repoRoot, sequenceId, 'functions');
39
+ }
40
+ /** A module of the sequence (`functions`, `variables`, `actions`) as `__gen/index.ts` imports it; null when absent. */
41
+ function moduleImportFor(repoRoot, sequenceId, name) {
42
+ const sequenceDir = path.join(repoRoot, 'sequences', sequenceId);
43
+ const found = findTsModule(sequenceDir, name);
44
+ if (!found)
45
+ return null;
46
+ return path.relative(path.join(sequenceDir, '__gen'), found).split(path.sep).join('/');
47
+ }
48
+ function errorMessage(error) {
49
+ return error instanceof Error ? error.message : String(error);
50
+ }
51
+ function throwGenerationFailures(failures) {
52
+ const errors = failures.map(({ sequenceId, error }) => new Error(`Sequence ${sequenceId}: ${errorMessage(error)}`, { cause: error }));
53
+ throw new AggregateError(errors, errors.map((error) => error.message).join('\n'));
54
+ }
15
55
  export async function generateSequence(repoRoot, sequenceId, options = {}) {
16
- return withCompanyImportGraph(repoRoot, () => generateSequenceInGraph(repoRoot, sequenceId, options));
56
+ return withCompanyImportGraph(repoRoot, async () => generateSequenceInGraph(repoRoot, sequenceId, options, await loadCompanySchemas(repoRoot)));
17
57
  }
18
- async function generateSequenceInGraph(repoRoot, sequenceId, options) {
58
+ /** The company's tables (`schema/index.ts`) and session fields (`schema/session.ts`). */
59
+ async function loadCompanySchemas(repoRoot) {
19
60
  const schemaPath = resolveTsModule(repoRoot, 'schema', `No company schema found. Expected schema.ts or schema/index.ts under ${repoRoot}`);
20
- const slotsPath = resolveTsModule(path.join(repoRoot, 'sequences', sequenceId), 'slots', `No sequence slots found. Expected sequences/${sequenceId}/slots.ts or sequences/${sequenceId}/slots/index.ts`);
21
- const company = await loadCompanySchema(schemaPath);
22
- const slots = await loadSequenceSlots(slotsPath);
23
- const effective = mergeEffectiveSchema(company, slots);
61
+ return { company: await loadCompanySchema(schemaPath), session: await loadSessionSchema(repoRoot) };
62
+ }
63
+ /** The root `__gen/` texts: the company's tables with no subject, as the company part compiles them. */
64
+ function companyGenSources({ company, session }) {
65
+ const { schema, validation } = compileSlotSchema(company, { session });
66
+ if (!validation.ok) {
67
+ const fatal = fatalSlotSchemaIssues(validation.issues);
68
+ if (fatal.length > 0)
69
+ throw new Error(fatal.map((issue) => issue.message).join('; '));
70
+ }
71
+ return { tablesSource: emitCompanyTablesSource(schema), indexSource: emitCompanyGenIndexSource() };
72
+ }
73
+ function writeCompanyGen(repoRoot, schemas) {
74
+ const { tablesOutPath, indexOutPath } = companyGenPaths(repoRoot);
75
+ const { tablesSource, indexSource } = companyGenSources(schemas);
76
+ mkdirSync(path.dirname(tablesOutPath), { recursive: true });
77
+ writeFileSync(tablesOutPath, tablesSource, 'utf8');
78
+ writeFileSync(indexOutPath, indexSource, 'utf8');
79
+ }
80
+ async function generateSequenceInGraph(repoRoot, sequenceId, options, { company, session }) {
24
81
  const sequenceDir = path.join(repoRoot, 'sequences', sequenceId);
25
- const hasCaseContextView = findTsModule(sequenceDir, 'view') !== undefined;
26
- const source = emitSlotsSource(effective);
27
- const caseContextSource = emitCaseContextSource({ hasCaseContextView });
82
+ assertNoSlotsModule(sequenceDir, sequenceId);
83
+ if (!options.dryRun)
84
+ ensureStub(repoRoot, sequenceId);
85
+ // The table types are the company's (root `__gen`); the sequence only names its subject (28 §2.2).
86
+ const { subject } = await loadSequenceDefinition(sequenceDir);
87
+ const subjectIssues = subjectTableIssues(company, subject);
88
+ if (subjectIssues.length > 0)
89
+ throw new Error(subjectIssues.map((issue) => issue.message).join('; '));
90
+ // The company schema is checked either way; a real run also writes the root `__gen` the sequence's types import.
91
+ const { tablesSource } = companyGenSources({ company, session });
92
+ if (!options.dryRun)
93
+ writeCompanyGen(repoRoot, { company, session });
94
+ // Every sequence has a page script (15 §10.2): the generated page types read it.
95
+ requirePagePath(sequenceDir, sequenceId);
96
+ const source = emitSlotsSource(subject);
97
+ const indexSource = emitGenIndexSource(functionsImportFor(repoRoot, sequenceId), moduleImportFor(repoRoot, sequenceId, 'variables'), moduleImportFor(repoRoot, sequenceId, 'actions'));
28
98
  const outPath = sequenceSlotsGenPath(repoRoot, sequenceId);
29
- const caseContextOutPath = sequenceCaseContextGenPath(repoRoot, sequenceId);
99
+ const indexOutPath = sequenceGenIndexPath(repoRoot, sequenceId);
30
100
  if (!options.dryRun) {
31
101
  mkdirSync(path.dirname(outPath), { recursive: true });
32
102
  writeFileSync(outPath, source, 'utf8');
33
- writeFileSync(caseContextOutPath, caseContextSource, 'utf8');
103
+ writeFileSync(indexOutPath, indexSource, 'utf8');
104
+ rmSync(legacyLoadGenPath(repoRoot, sequenceId), { force: true });
105
+ rmSync(legacyCaseContextGenPath(repoRoot, sequenceId), { force: true });
106
+ rmSync(legacySlotsConfigGenPath(repoRoot, sequenceId), { force: true });
34
107
  }
35
108
  return {
36
109
  sequenceId,
37
110
  outPath,
38
- caseContextOutPath,
111
+ indexOutPath,
39
112
  source,
40
- caseContextSource,
113
+ indexSource,
114
+ tablesSource,
41
115
  wrote: !options.dryRun,
42
116
  };
43
117
  }
118
+ /**
119
+ * The root `__gen/` and every sequence's (or only `sequenceIds`'). A repository with no sequence gets the
120
+ * root's alone, as the release type check does (22 §11), so `type:gen` and `typecheck` pass on it locally too.
121
+ */
44
122
  export async function generateAll(repoRoot, options = {}) {
45
123
  return withCompanyImportGraph(repoRoot, async () => {
46
124
  const ids = options.sequenceIds ?? listSequenceIds(repoRoot);
47
- if (ids.length === 0) {
48
- throw new Error(`No sequences with slots found under ${path.join(repoRoot, 'sequences')} (expected slots.ts or slots/index.ts)`);
49
- }
125
+ const schemas = await loadCompanySchemas(repoRoot);
126
+ // The root's types depend on the schema only: written with every full run (a schema change is one).
127
+ if (!options.dryRun && !options.sequenceIds)
128
+ writeCompanyGen(repoRoot, schemas);
129
+ // Keeps going after failures so valid sequences still regenerate and the caller receives every
130
+ // sequence error in one AggregateError.
131
+ const failures = [];
50
132
  const results = [];
51
133
  for (const sequenceId of ids) {
52
- results.push(await generateSequence(repoRoot, sequenceId, options));
134
+ try {
135
+ results.push(await generateSequenceInGraph(repoRoot, sequenceId, options, schemas));
136
+ }
137
+ catch (error) {
138
+ failures.push({ sequenceId, error });
139
+ }
53
140
  }
141
+ if (failures.length > 0)
142
+ throwGenerationFailures(failures);
54
143
  return results;
55
144
  });
56
145
  }
@@ -67,30 +156,54 @@ function assertFileMatches(outPath, next, repoRoot) {
67
156
  }
68
157
  }
69
158
  export async function checkSequence(repoRoot, sequenceId) {
70
- const { outPath, caseContextOutPath, source, caseContextSource } = await generateSequence(repoRoot, sequenceId, {
71
- dryRun: true,
72
- });
159
+ const { outPath, indexOutPath, source, indexSource } = await generateSequence(repoRoot, sequenceId, { dryRun: true });
73
160
  assertFileMatches(outPath, source, repoRoot);
74
- assertFileMatches(caseContextOutPath, caseContextSource, repoRoot);
161
+ assertFileMatches(indexOutPath, indexSource, repoRoot);
75
162
  }
163
+ /** The root `__gen/` matches the company schema. */
164
+ export async function checkCompany(repoRoot) {
165
+ const { tablesSource, indexSource } = await withCompanyImportGraph(repoRoot, async () => companyGenSources(await loadCompanySchemas(repoRoot)));
166
+ const { tablesOutPath, indexOutPath } = companyGenPaths(repoRoot);
167
+ assertFileMatches(tablesOutPath, tablesSource, repoRoot);
168
+ assertFileMatches(indexOutPath, indexSource, repoRoot);
169
+ }
170
+ /** The root `__gen/` and every sequence's are up to date; with no sequence, the root's alone. */
76
171
  export async function checkAll(repoRoot) {
77
172
  const ids = listSequenceIds(repoRoot);
78
- if (ids.length === 0) {
79
- throw new Error(`No sequences with slots found under ${path.join(repoRoot, 'sequences')} (expected slots.ts or slots/index.ts)`);
80
- }
173
+ await checkCompany(repoRoot);
174
+ const failures = [];
81
175
  for (const sequenceId of ids) {
82
- await checkSequence(repoRoot, sequenceId);
176
+ try {
177
+ await checkSequence(repoRoot, sequenceId);
178
+ }
179
+ catch (error) {
180
+ failures.push({ sequenceId, error });
181
+ }
83
182
  }
183
+ if (failures.length > 0)
184
+ throwGenerationFailures(failures);
84
185
  }
85
186
  export function ensureStub(repoRoot, sequenceId) {
86
187
  const slotsPath = sequenceSlotsGenPath(repoRoot, sequenceId);
87
- const caseContextPath = sequenceCaseContextGenPath(repoRoot, sequenceId);
88
188
  mkdirSync(path.dirname(slotsPath), { recursive: true });
89
189
  if (!existsSync(slotsPath)) {
90
190
  writeFileSync(slotsPath, emitSlotsStub(), 'utf8');
91
191
  }
92
- if (!existsSync(caseContextPath)) {
93
- writeFileSync(caseContextPath, emitCaseContextStub(), 'utf8');
192
+ const indexPath = sequenceGenIndexPath(repoRoot, sequenceId);
193
+ if (!existsSync(indexPath)) {
194
+ writeFileSync(indexPath, emitGenIndexSource(functionsImportFor(repoRoot, sequenceId), moduleImportFor(repoRoot, sequenceId, 'variables'), moduleImportFor(repoRoot, sequenceId, 'actions')), 'utf8');
94
195
  }
95
196
  }
197
+ /**
198
+ * Writes the root `__gen/` files that are missing (a fresh checkout has none: `__gen/` is gitignored),
199
+ * so `resolve.ts` and `webhook.ts` can import it; existing ones are left untouched.
200
+ */
201
+ export function ensureCompanyStub(repoRoot) {
202
+ const { tablesOutPath, indexOutPath } = companyGenPaths(repoRoot);
203
+ mkdirSync(path.dirname(tablesOutPath), { recursive: true });
204
+ if (!existsSync(tablesOutPath))
205
+ writeFileSync(tablesOutPath, emitCompanyTablesStub(), 'utf8');
206
+ if (!existsSync(indexOutPath))
207
+ writeFileSync(indexOutPath, emitCompanyGenIndexSource(), 'utf8');
208
+ }
96
209
  //# sourceMappingURL=generate.js.map
@@ -1,3 +1,5 @@
1
+ /** The repository the current company import graph loads, or null outside one. */
2
+ export declare function companyRepoRoot(): string | null;
1
3
  /** Stamp a company-repo entry URL, or return it unchanged outside a graph. */
2
4
  export declare function companyImportGraphHref(fileHref: string): string;
3
5
  /**
@@ -3,6 +3,7 @@ import { realpathSync } from 'node:fs';
3
3
  import { registerHooks } from 'node:module';
4
4
  import path from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
+ import { COMMONJS_ISSUE, companyImportError, resolvedIssue, specifierIssue } from './company-imports.js';
6
7
  const COMPANY_GRAPH_GEN_QUERY = 'spgen';
7
8
  const COMPANY_GRAPH_ROOT_QUERY = 'sproot';
8
9
  const graph = new AsyncLocalStorage();
@@ -34,16 +35,23 @@ function inNodeModules(filePath, url) {
34
35
  filePath.includes(`${path.sep}node_modules${path.sep}`));
35
36
  }
36
37
  function stampCompanyResolve(specifier, context, nextResolve) {
37
- const result = nextResolve(specifier, context);
38
- if (!result.url.startsWith('file:'))
39
- return result;
40
- const resolved = new URL(result.url);
41
- if (resolved.searchParams.has(COMPANY_GRAPH_GEN_QUERY))
42
- return result;
43
38
  const parent = context.parentURL ? new URL(context.parentURL) : null;
44
39
  const graphGeneration = parent?.searchParams.get(COMPANY_GRAPH_GEN_QUERY);
45
40
  const repoRoot = parent?.searchParams.get(COMPANY_GRAPH_ROOT_QUERY);
46
- if (!graphGeneration || !repoRoot)
41
+ // A company file's import is checked before it loads: what company code may import (company-imports.ts).
42
+ const importer = parent && graphGeneration && repoRoot ? filePathFromUrl(parent.href) : null;
43
+ if (importer && repoRoot) {
44
+ const issue = specifierIssue(specifier);
45
+ if (issue)
46
+ throw companyImportError(importer, repoRoot, issue);
47
+ }
48
+ const result = nextResolve(specifier, context);
49
+ if (!result.url.startsWith('file:')) {
50
+ if (importer && repoRoot)
51
+ throw companyImportError(importer, repoRoot, `'${specifier}' is not a file of the repository`);
52
+ return result;
53
+ }
54
+ if (!importer || !graphGeneration || !repoRoot)
47
55
  return result;
48
56
  let resolvedFile;
49
57
  try {
@@ -52,6 +60,12 @@ function stampCompanyResolve(specifier, context, nextResolve) {
52
60
  catch {
53
61
  return result;
54
62
  }
63
+ const issue = resolvedIssue(specifier, resolvedFile, repoRoot);
64
+ if (issue)
65
+ throw companyImportError(importer, repoRoot, issue);
66
+ const resolved = new URL(result.url);
67
+ if (resolved.searchParams.has(COMPANY_GRAPH_GEN_QUERY))
68
+ return result;
55
69
  if (inNodeModules(resolvedFile, result.url))
56
70
  return result;
57
71
  if (!underRoot(resolvedFile, repoRoot))
@@ -60,11 +74,29 @@ function stampCompanyResolve(specifier, context, nextResolve) {
60
74
  resolved.searchParams.set(COMPANY_GRAPH_ROOT_QUERY, repoRoot);
61
75
  return { ...result, url: resolved.href };
62
76
  }
77
+ /**
78
+ * A company file Node loads as CommonJS (a `.ts` under a `"type": "commonjs"` package.json; `.cts` and
79
+ * `.cjs` are refused when imported) is refused: its `require` calls would go unchecked.
80
+ */
81
+ const refuseCommonJs = (url, context, nextLoad) => {
82
+ const result = nextLoad(url, context);
83
+ if (result.format !== 'commonjs' && result.format !== 'commonjs-typescript')
84
+ return result;
85
+ const loaded = new URL(url);
86
+ const repoRoot = loaded.searchParams.get(COMPANY_GRAPH_ROOT_QUERY);
87
+ if (!repoRoot || !loaded.searchParams.has(COMPANY_GRAPH_GEN_QUERY))
88
+ return result;
89
+ throw companyImportError(filePathFromUrl(url), repoRoot, COMMONJS_ISSUE);
90
+ };
63
91
  function ensureHookRegistered() {
64
92
  if (registered)
65
93
  return;
66
94
  registered = true;
67
- registerHooks({ resolve: stampCompanyResolve });
95
+ registerHooks({ resolve: stampCompanyResolve, load: refuseCommonJs });
96
+ }
97
+ /** The repository the current company import graph loads, or null outside one. */
98
+ export function companyRepoRoot() {
99
+ return graph.getStore()?.repoRoot ?? null;
68
100
  }
69
101
  /** Stamp a company-repo entry URL, or return it unchanged outside a graph. */
70
102
  export function companyImportGraphHref(fileHref) {
@@ -0,0 +1,29 @@
1
+ /**
2
+ * What company code may import (09-runtime-compat §6): the company API, `@superpanel-sdk/runtime`, and
3
+ * the repository's own files. No other package, no Node module, no other runtime entry and no file of
4
+ * the runtime's own. The compile checks every import of a company file against this twice: in Node,
5
+ * as it loads the repo (`company-import-graph.ts`), and in esbuild, as it bundles a code string
6
+ * (`function-code.ts`). Both use this one rule, so serve, `compile` and a release agree.
7
+ */
8
+ export declare const RUNTIME_PACKAGE = "@superpanel-sdk/runtime";
9
+ /**
10
+ * The runtime's test helpers (`testing.ts`): a test file's import. The compile never loads a test file
11
+ * (it loads a repository from its entries), and refuses this entry in every file it does load.
12
+ */
13
+ export declare const RUNTIME_TESTING_ENTRY = "@superpanel-sdk/runtime/testing";
14
+ export declare function realPath(filePath: string): string;
15
+ /** The directory of the nearest `package.json` above `file`, else the file's own directory. */
16
+ export declare function packageRootOf(file: string): string;
17
+ /** Whether `file` is a runtime package's company API: `dist/index.js`, its types, or `src/index.ts`. */
18
+ export declare function isCompanyApiFile(file: string): boolean;
19
+ /**
20
+ * Why company code may not import `specifier`, known before resolving it; null when only the resolved
21
+ * file can tell (a path, a `#…` import, or the company API).
22
+ */
23
+ export declare function specifierIssue(specifier: string): string | null;
24
+ /** Why `specifier`, resolved to `file`, may not be imported by a file of the company repo at `repoRoot`; null when it may. */
25
+ export declare function resolvedIssue(specifier: string, file: string, repoRoot: string): string | null;
26
+ export declare const COMMONJS_ISSUE = "is CommonJS (.cts, .cjs, or \"type\": \"commonjs\"): company code is ES modules";
27
+ /** The message a refused import fails the compile with: which file, what it imported, and why not. */
28
+ export declare function companyImportError(importer: string, repoRoot: string, issue: string): Error;
29
+ //# sourceMappingURL=company-imports.d.ts.map
@@ -0,0 +1,122 @@
1
+ import { existsSync, readFileSync, realpathSync } from 'node:fs';
2
+ import { isBuiltin } from 'node:module';
3
+ import path from 'node:path';
4
+ /**
5
+ * What company code may import (09-runtime-compat §6): the company API, `@superpanel-sdk/runtime`, and
6
+ * the repository's own files. No other package, no Node module, no other runtime entry and no file of
7
+ * the runtime's own. The compile checks every import of a company file against this twice: in Node,
8
+ * as it loads the repo (`company-import-graph.ts`), and in esbuild, as it bundles a code string
9
+ * (`function-code.ts`). Both use this one rule, so serve, `compile` and a release agree.
10
+ */
11
+ export const RUNTIME_PACKAGE = '@superpanel-sdk/runtime';
12
+ /**
13
+ * The runtime's test helpers (`testing.ts`): a test file's import. The compile never loads a test file
14
+ * (it loads a repository from its entries), and refuses this entry in every file it does load.
15
+ */
16
+ export const RUNTIME_TESTING_ENTRY = `${RUNTIME_PACKAGE}/testing`;
17
+ /**
18
+ * The company API's files in a runtime package: built (with its types, which a tsconfig `paths` may
19
+ * name), or the source the runtime's own tests run.
20
+ */
21
+ const COMPANY_API_FILES = new Set(['index'].flatMap((name) => [path.join('dist', `${name}.js`), path.join('dist', `${name}.d.ts`), path.join('src', `${name}.ts`)]));
22
+ const packageNames = new Map();
23
+ export function realPath(filePath) {
24
+ try {
25
+ return realpathSync(filePath);
26
+ }
27
+ catch {
28
+ return path.resolve(filePath);
29
+ }
30
+ }
31
+ /** The directory of the nearest `package.json` above `file`, else the file's own directory. */
32
+ export function packageRootOf(file) {
33
+ for (let dir = path.dirname(path.resolve(file));; dir = path.dirname(dir)) {
34
+ if (existsSync(path.join(dir, 'package.json')))
35
+ return dir;
36
+ if (path.dirname(dir) === dir)
37
+ return path.dirname(path.resolve(file));
38
+ }
39
+ }
40
+ /** The directory and name of the package that holds `file`: the nearest `package.json` above it. */
41
+ function owningPackage(file) {
42
+ let dir = path.dirname(file);
43
+ for (;;) {
44
+ let name = packageNames.get(dir);
45
+ if (name === undefined) {
46
+ try {
47
+ const pkg = JSON.parse(readFileSync(path.join(dir, 'package.json'), 'utf8'));
48
+ name = typeof pkg.name === 'string' ? pkg.name : null;
49
+ }
50
+ catch {
51
+ name = null;
52
+ }
53
+ packageNames.set(dir, name);
54
+ }
55
+ if (name !== null)
56
+ return { dir, name };
57
+ const parent = path.dirname(dir);
58
+ if (parent === dir)
59
+ return null;
60
+ dir = parent;
61
+ }
62
+ }
63
+ /** Whether `file` is a runtime package's company API: `dist/index.js`, its types, or `src/index.ts`. */
64
+ export function isCompanyApiFile(file) {
65
+ const resolved = realPath(file);
66
+ const owner = owningPackage(resolved);
67
+ return owner?.name === RUNTIME_PACKAGE && COMPANY_API_FILES.has(path.relative(owner.dir, resolved));
68
+ }
69
+ /**
70
+ * A package name or a Node module, as opposed to a path (`./x`, `/x`), a URL (`file:`, `node:`) or a
71
+ * `#…` import the repo's package.json maps (which the resolved file decides, like a path).
72
+ */
73
+ function isBareSpecifier(specifier) {
74
+ return (!specifier.startsWith('.') &&
75
+ !specifier.startsWith('/') &&
76
+ !specifier.startsWith('#') &&
77
+ !/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(specifier));
78
+ }
79
+ /**
80
+ * Why company code may not import `specifier`, known before resolving it; null when only the resolved
81
+ * file can tell (a path, a `#…` import, or the company API).
82
+ */
83
+ export function specifierIssue(specifier) {
84
+ if (isBuiltin(specifier)) {
85
+ return `'${specifier}' is a Node module: company code is bundled into self-contained code that cannot import one, and the page's sandbox has no Node`;
86
+ }
87
+ if (!isBareSpecifier(specifier) || specifier === RUNTIME_PACKAGE)
88
+ return null;
89
+ if (specifier === RUNTIME_TESTING_ENTRY) {
90
+ return `'${specifier}' is for test files only (sequences/<id>/tests/*.test.ts); code a sequence runs imports '${RUNTIME_PACKAGE}'`;
91
+ }
92
+ if (specifier.startsWith(`${RUNTIME_PACKAGE}/`))
93
+ return `'${specifier}' is the platform's; company code imports '${RUNTIME_PACKAGE}'`;
94
+ return `'${specifier}' is a package; company code imports only '${RUNTIME_PACKAGE}' and the repository's own files`;
95
+ }
96
+ /** Why `specifier`, resolved to `file`, may not be imported by a file of the company repo at `repoRoot`; null when it may. */
97
+ export function resolvedIssue(specifier, file, repoRoot) {
98
+ if (specifier === RUNTIME_PACKAGE) {
99
+ return isCompanyApiFile(file) ? null : `'${specifier}' resolves to ${file}, not the runtime's company API`;
100
+ }
101
+ const resolved = realPath(file);
102
+ const relative = path.relative(realPath(repoRoot), resolved);
103
+ const inRepo = relative !== '' && !relative.startsWith('..') && !path.isAbsolute(relative);
104
+ if (!inRepo || relative.split(path.sep).includes('node_modules')) {
105
+ return `'${specifier}' resolves to ${inRepo ? relative : resolved}, outside the repository's own files`;
106
+ }
107
+ if (COMMONJS_EXTENSIONS.has(path.extname(resolved)))
108
+ return `'${specifier}' ${COMMONJS_ISSUE}`;
109
+ return null;
110
+ }
111
+ /**
112
+ * Company code is ES modules. A CommonJS file's `require` calls reach Node's resolve hook without the
113
+ * import graph's stamp, so nothing would check what it loads: the compile refuses the file instead.
114
+ */
115
+ const COMMONJS_EXTENSIONS = new Set(['.cjs', '.cts']);
116
+ export const COMMONJS_ISSUE = 'is CommonJS (.cts, .cjs, or "type": "commonjs"): company code is ES modules';
117
+ /** The message a refused import fails the compile with: which file, what it imported, and why not. */
118
+ export function companyImportError(importer, repoRoot, issue) {
119
+ const where = path.relative(realPath(repoRoot), realPath(importer)) || importer;
120
+ return new Error(`${where}: ${issue} (AGENTS.md, "Imports")`);
121
+ }
122
+ //# sourceMappingURL=company-imports.js.map
@@ -1,18 +1,13 @@
1
- import type { FuncMap } from '../../core/functions/types.js';
2
- import type { CompanySchema } from '../../core/slot/schema.js';
3
- import type { RuntimePackageSource, SequenceBuild } from '../types.js';
4
- /** SequenceBuild / SequenceConfigBuild cache key. Bump when compiled `code` shape changes. */
1
+ import type { CompiledSlotSchema } from '../../core/slot/types.js';
2
+ import { type CompanyPart, type RuntimePackageSource, type SequenceBuild, type SourceMaps } from '../types.js';
3
+ /** SequenceBuild cache key. Bump when compiled `code` shape changes. */
5
4
  export declare function runtimePackageVersion(): string;
6
5
  export declare function runtimePackageSource(repoRoot: string): RuntimePackageSource;
7
- /** Deep-clone company schema with derived computeFn normalized to string names. */
8
- export declare function snapshotCompanySchema(company: CompanySchema, functions?: FuncMap): CompanySchema;
9
6
  export declare function sequenceBuildPath(repoRoot: string, sequenceId: string): string;
10
7
  export type CompileSequenceOptions = {
11
8
  dryRun?: boolean;
12
9
  /** When false, skip esbuild and omit registry `code` (local serve overlay). Default true. */
13
10
  includeCode?: boolean;
14
- /** Persist on SequenceBuild.sha. Defaults to `local`. */
15
- sha?: string;
16
11
  /** Dependency source captured before deployment rewrites package.json. */
17
12
  runtimeSource?: RuntimePackageSource;
18
13
  };
@@ -20,10 +15,68 @@ export type CompileSequenceResult = {
20
15
  sequenceId: string;
21
16
  outPath: string;
22
17
  build: SequenceBuild;
18
+ /** The company schema the build runs against (28 §2): what the company part of the build carries. */
19
+ schema: CompiledSlotSchema;
20
+ /** Where the build's code came from in the company's files, by `functionKey`: kept apart from the build. */
21
+ sourceMaps: SourceMaps;
23
22
  wrote: boolean;
24
23
  };
25
24
  export declare function compileSequence(repoRoot: string, sequenceId: string, options?: CompileSequenceOptions): Promise<CompileSequenceResult>;
25
+ export declare function compileSequenceBuild(repoRoot: string, sequenceId: string, options?: CompileSequenceOptions): Promise<CompileSequenceResult>;
26
26
  export declare function compileAll(repoRoot: string, options?: CompileSequenceOptions & {
27
27
  sequenceIds?: string[];
28
28
  }): Promise<CompileSequenceResult[]>;
29
+ /**
30
+ * The company part of the company build (22 §5): the root `resolve.ts` as `companyResolve`, the root
31
+ * `webhook.ts` as `webhook.received`, the root `schedules.ts` as `schedule.<name>` (25 §6.4), the root
32
+ * `errors.ts` as `onError` (67 §5), and the
33
+ * company schema with no subject. An error in it fails the
34
+ * whole compile.
35
+ */
36
+ export declare function compileCompanyPart(repoRoot: string, options?: {
37
+ includeCode?: boolean;
38
+ runtimeSource?: RuntimePackageSource;
39
+ }): Promise<CompanyPart>;
40
+ export declare const COMPILE_CONCURRENCY = 4;
41
+ export declare const COMPILE_SEQUENCE_TIMEOUT_MS: number;
42
+ export type CompileRepoEvent = {
43
+ type: 'log';
44
+ sequence?: string;
45
+ text: string;
46
+ } | {
47
+ type: 'sequence-started';
48
+ sequence: string;
49
+ } | {
50
+ type: 'sequence-finished';
51
+ sequence: string;
52
+ ok: boolean;
53
+ error?: string;
54
+ };
55
+ export type CompileRepoSequenceResult = {
56
+ ok: true;
57
+ build: SequenceBuild;
58
+ /** Where its code came from in the company's files, by `functionKey` (kept apart from the build). */
59
+ sourceMaps: SourceMaps;
60
+ } | {
61
+ ok: false;
62
+ error: string;
63
+ };
64
+ export type CompileRepoOptions = {
65
+ sequences: string[];
66
+ runtimeSource?: RuntimePackageSource;
67
+ concurrency?: number;
68
+ sequenceTimeoutMs?: number;
69
+ onEvent?: (event: CompileRepoEvent) => void;
70
+ };
71
+ /**
72
+ * Compile the company part (its schema first) once, then every named sequence in this process, then
73
+ * type-check the repository. A sequence error is collected; a company schema error or a type error
74
+ * rejects the whole call, a type error with the tsc output as its message.
75
+ */
76
+ export declare function compileRepo(repoRoot: string, options: CompileRepoOptions): Promise<{
77
+ company: CompanyPart;
78
+ /** The company functions' source maps, by `functionKey` (kept apart from the build). */
79
+ companySourceMaps: SourceMaps;
80
+ sequences: Record<string, CompileRepoSequenceResult>;
81
+ }>;
29
82
  //# sourceMappingURL=compile-sequence.d.ts.map