@kubohiroya/turbowarp-http-server 0.2.0 → 0.3.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 (237) hide show
  1. package/README.ja.md +32 -14
  2. package/README.md +104 -43
  3. package/assets/block-icon.svg +1 -0
  4. package/dist/cli.js +131 -17
  5. package/dist/cli.js.map +1 -1
  6. package/dist/compiler/adapters/cloudflare.d.ts +2 -0
  7. package/dist/compiler/adapters/cloudflare.js +477 -0
  8. package/dist/compiler/adapters/cloudflare.js.map +1 -0
  9. package/dist/compiler/adapters/firebase.d.ts +2 -0
  10. package/dist/compiler/adapters/firebase.js +489 -0
  11. package/dist/compiler/adapters/firebase.js.map +1 -0
  12. package/dist/compiler/adapters/index.d.ts +2 -0
  13. package/dist/compiler/adapters/index.js +3 -0
  14. package/dist/compiler/adapters/index.js.map +1 -0
  15. package/dist/compiler/binary/codec.d.ts +4 -0
  16. package/dist/compiler/binary/codec.js +45 -0
  17. package/dist/compiler/binary/codec.js.map +1 -0
  18. package/dist/compiler/binary/error.d.ts +3 -0
  19. package/dist/compiler/binary/error.js +21 -0
  20. package/dist/compiler/binary/error.js.map +1 -0
  21. package/dist/compiler/binary/index.d.ts +4 -0
  22. package/dist/compiler/binary/index.js +5 -0
  23. package/dist/compiler/binary/index.js.map +1 -0
  24. package/dist/compiler/binary/runtime.d.ts +18 -0
  25. package/dist/compiler/binary/runtime.js +123 -0
  26. package/dist/compiler/binary/runtime.js.map +1 -0
  27. package/dist/compiler/binary/types.d.ts +17 -0
  28. package/dist/compiler/binary/types.js +2 -0
  29. package/dist/compiler/binary/types.js.map +1 -0
  30. package/dist/compiler/feature-flags.d.ts +4 -0
  31. package/dist/compiler/feature-flags.js +4 -0
  32. package/dist/compiler/feature-flags.js.map +1 -0
  33. package/dist/compiler/index.d.ts +35 -0
  34. package/dist/compiler/index.js +84 -0
  35. package/dist/compiler/index.js.map +1 -0
  36. package/dist/compiler/ir-v2/canonical.d.ts +3 -0
  37. package/dist/compiler/ir-v2/canonical.js +50 -0
  38. package/dist/compiler/ir-v2/canonical.js.map +1 -0
  39. package/dist/compiler/ir-v2/index.d.ts +4 -0
  40. package/dist/compiler/ir-v2/index.js +5 -0
  41. package/dist/compiler/ir-v2/index.js.map +1 -0
  42. package/dist/compiler/ir-v2/parse.d.ts +10 -0
  43. package/dist/compiler/ir-v2/parse.js +753 -0
  44. package/dist/compiler/ir-v2/parse.js.map +1 -0
  45. package/dist/compiler/ir-v2/strict-json.d.ts +4 -0
  46. package/dist/compiler/ir-v2/strict-json.js +133 -0
  47. package/dist/compiler/ir-v2/strict-json.js.map +1 -0
  48. package/dist/compiler/ir-v2/types.d.ts +412 -0
  49. package/dist/compiler/ir-v2/types.js +84 -0
  50. package/dist/compiler/ir-v2/types.js.map +1 -0
  51. package/dist/compiler/kvs/lowering.d.ts +13 -0
  52. package/dist/compiler/kvs/lowering.js +77 -0
  53. package/dist/compiler/kvs/lowering.js.map +1 -0
  54. package/dist/compiler/manifest/error.d.ts +7 -0
  55. package/dist/compiler/manifest/error.js +9 -0
  56. package/dist/compiler/manifest/error.js.map +1 -0
  57. package/dist/compiler/manifest/index.d.ts +6 -0
  58. package/dist/compiler/manifest/index.js +7 -0
  59. package/dist/compiler/manifest/index.js.map +1 -0
  60. package/dist/compiler/manifest/operations.d.ts +12 -0
  61. package/dist/compiler/manifest/operations.js +60 -0
  62. package/dist/compiler/manifest/operations.js.map +1 -0
  63. package/dist/compiler/manifest/parse.d.ts +9 -0
  64. package/dist/compiler/manifest/parse.js +280 -0
  65. package/dist/compiler/manifest/parse.js.map +1 -0
  66. package/dist/compiler/manifest/registry.d.ts +3 -0
  67. package/dist/compiler/manifest/registry.js +48 -0
  68. package/dist/compiler/manifest/registry.js.map +1 -0
  69. package/dist/compiler/manifest/resolve.d.ts +14 -0
  70. package/dist/compiler/manifest/resolve.js +116 -0
  71. package/dist/compiler/manifest/resolve.js.map +1 -0
  72. package/dist/compiler/manifest/types.d.ts +95 -0
  73. package/dist/compiler/manifest/types.js +3 -0
  74. package/dist/compiler/manifest/types.js.map +1 -0
  75. package/dist/compiler/named-body/index.d.ts +1 -0
  76. package/dist/compiler/named-body/index.js +2 -0
  77. package/dist/compiler/named-body/index.js.map +1 -0
  78. package/dist/compiler/named-body/lowering.d.ts +18 -0
  79. package/dist/compiler/named-body/lowering.js +83 -0
  80. package/dist/compiler/named-body/lowering.js.map +1 -0
  81. package/dist/compiler/pipeline/compiler.d.ts +18 -0
  82. package/dist/compiler/pipeline/compiler.js +105 -0
  83. package/dist/compiler/pipeline/compiler.js.map +1 -0
  84. package/dist/compiler/pipeline/core-generator.d.ts +3 -0
  85. package/dist/compiler/pipeline/core-generator.js +483 -0
  86. package/dist/compiler/pipeline/core-generator.js.map +1 -0
  87. package/dist/compiler/pipeline/index.d.ts +5 -0
  88. package/dist/compiler/pipeline/index.js +6 -0
  89. package/dist/compiler/pipeline/index.js.map +1 -0
  90. package/dist/compiler/pipeline/registry.d.ts +7 -0
  91. package/dist/compiler/pipeline/registry.js +17 -0
  92. package/dist/compiler/pipeline/registry.js.map +1 -0
  93. package/dist/compiler/pipeline/requirements.d.ts +9 -0
  94. package/dist/compiler/pipeline/requirements.js +135 -0
  95. package/dist/compiler/pipeline/requirements.js.map +1 -0
  96. package/dist/compiler/pipeline/types.d.ts +65 -0
  97. package/dist/compiler/pipeline/types.js +2 -0
  98. package/dist/compiler/pipeline/types.js.map +1 -0
  99. package/dist/compiler/runtime/error.d.ts +6 -0
  100. package/dist/compiler/runtime/error.js +9 -0
  101. package/dist/compiler/runtime/error.js.map +1 -0
  102. package/dist/compiler/runtime/index.d.ts +1 -0
  103. package/dist/compiler/runtime/index.js +2 -0
  104. package/dist/compiler/runtime/index.js.map +1 -0
  105. package/dist/compiler/structured-data/index.d.ts +3 -0
  106. package/dist/compiler/structured-data/index.js +4 -0
  107. package/dist/compiler/structured-data/index.js.map +1 -0
  108. package/dist/compiler/structured-data/lowering.d.ts +30 -0
  109. package/dist/compiler/structured-data/lowering.js +202 -0
  110. package/dist/compiler/structured-data/lowering.js.map +1 -0
  111. package/dist/compiler/structured-data/path.d.ts +2 -0
  112. package/dist/compiler/structured-data/path.js +60 -0
  113. package/dist/compiler/structured-data/path.js.map +1 -0
  114. package/dist/compiler/structured-data/runtime.d.ts +20 -0
  115. package/dist/compiler/structured-data/runtime.js +210 -0
  116. package/dist/compiler/structured-data/runtime.js.map +1 -0
  117. package/dist/compiler/turbowarp-v2.d.ts +8 -0
  118. package/dist/compiler/turbowarp-v2.js +479 -0
  119. package/dist/compiler/turbowarp-v2.js.map +1 -0
  120. package/dist/compiler/validator/index.d.ts +4 -0
  121. package/dist/compiler/validator/index.js +5 -0
  122. package/dist/compiler/validator/index.js.map +1 -0
  123. package/dist/compiler/validator/ir-validator.d.ts +10 -0
  124. package/dist/compiler/validator/ir-validator.js +463 -0
  125. package/dist/compiler/validator/ir-validator.js.map +1 -0
  126. package/dist/compiler/validator/resource-lifetime.d.ts +18 -0
  127. package/dist/compiler/validator/resource-lifetime.js +106 -0
  128. package/dist/compiler/validator/resource-lifetime.js.map +1 -0
  129. package/dist/compiler/validator/turbowarp-subset.d.ts +3 -0
  130. package/dist/compiler/validator/turbowarp-subset.js +241 -0
  131. package/dist/compiler/validator/turbowarp-subset.js.map +1 -0
  132. package/dist/compiler/validator/types.d.ts +30 -0
  133. package/dist/compiler/validator/types.js +7 -0
  134. package/dist/compiler/validator/types.js.map +1 -0
  135. package/dist/config.d.ts +11 -0
  136. package/dist/config.js +12 -0
  137. package/dist/config.js.map +1 -0
  138. package/dist/digest-cli.js +0 -0
  139. package/dist/extension-manifest.json +102 -0
  140. package/dist/named-body.d.ts +57 -0
  141. package/dist/named-body.js +396 -0
  142. package/dist/named-body.js.map +1 -0
  143. package/dist/named-data-namespace.d.ts +3 -0
  144. package/dist/named-data-namespace.js +6 -0
  145. package/dist/named-data-namespace.js.map +1 -0
  146. package/dist/protocol.d.ts +13 -1
  147. package/dist/protocol.js +34 -0
  148. package/dist/protocol.js.map +1 -1
  149. package/dist/resource-named-body-provider.d.ts +8 -0
  150. package/dist/resource-named-body-provider.js +88 -0
  151. package/dist/resource-named-body-provider.js.map +1 -0
  152. package/dist/server.d.ts +10 -1
  153. package/dist/server.js +37 -7
  154. package/dist/server.js.map +1 -1
  155. package/dist/turbowarp-http-server.js +1614 -1099
  156. package/docs/binary-resource-semantics.ja.md +84 -0
  157. package/docs/cloudflare-worker-compiler.ja.md +90 -0
  158. package/docs/compiler-manifest-registry.ja.md +79 -0
  159. package/docs/compiler-platform-pipeline.ja.md +94 -0
  160. package/docs/deploy-ir-v2.ja.md +123 -0
  161. package/docs/fixed-input-editors.ja.md +23 -0
  162. package/docs/index.html +86 -0
  163. package/docs/ir-v2-conformance.ja.md +65 -0
  164. package/docs/named-response-body.ja.md +120 -0
  165. package/docs/platform-storage-adapters.ja.md +99 -0
  166. package/docs/server-executable-subset.ja.md +88 -0
  167. package/docs/structured-data-lowering.ja.md +63 -0
  168. package/docs/turbowarp-http-server.architecture.html +4 -0
  169. package/examples/compiler/message-app.v2.ir.json +41 -0
  170. package/package.json +45 -20
  171. package/schemas/block-editor-fixed-inputs.schema.json +85 -0
  172. package/schemas/compiler-extension-manifest.schema.json +126 -0
  173. package/schemas/compiler-manifest-lock-v1.schema.json +48 -0
  174. package/schemas/deploy-ir-v2.schema.json +835 -0
  175. package/schemas/ir-v2-conformance-fixture.schema.json +44 -0
  176. package/src/block-definitions.json +76 -0
  177. package/src/cli.ts +136 -23
  178. package/src/compiler/adapters/cloudflare.ts +510 -0
  179. package/src/compiler/adapters/firebase.ts +538 -0
  180. package/src/compiler/adapters/index.ts +2 -0
  181. package/src/compiler/binary/codec.ts +61 -0
  182. package/src/compiler/binary/error.ts +25 -0
  183. package/src/compiler/binary/index.ts +4 -0
  184. package/src/compiler/binary/runtime.ts +133 -0
  185. package/src/compiler/binary/types.ts +26 -0
  186. package/src/compiler/feature-flags.ts +7 -0
  187. package/src/compiler/index.ts +114 -0
  188. package/src/compiler/ir-v2/canonical.ts +46 -0
  189. package/src/compiler/ir-v2/index.ts +9 -0
  190. package/src/compiler/ir-v2/parse.ts +921 -0
  191. package/src/compiler/ir-v2/strict-json.ts +129 -0
  192. package/src/compiler/ir-v2/types.ts +462 -0
  193. package/src/compiler/kvs/lowering.ts +88 -0
  194. package/src/compiler/manifest/error.ts +29 -0
  195. package/src/compiler/manifest/index.ts +17 -0
  196. package/src/compiler/manifest/operations.ts +175 -0
  197. package/src/compiler/manifest/parse.ts +390 -0
  198. package/src/compiler/manifest/registry.ts +74 -0
  199. package/src/compiler/manifest/resolve.ts +159 -0
  200. package/src/compiler/manifest/types.ts +112 -0
  201. package/src/compiler/named-body/index.ts +1 -0
  202. package/src/compiler/named-body/lowering.ts +186 -0
  203. package/src/compiler/pipeline/compiler.ts +138 -0
  204. package/src/compiler/pipeline/core-generator.ts +486 -0
  205. package/src/compiler/pipeline/index.ts +5 -0
  206. package/src/compiler/pipeline/registry.ts +18 -0
  207. package/src/compiler/pipeline/requirements.ts +139 -0
  208. package/src/compiler/pipeline/types.ts +59 -0
  209. package/src/compiler/runtime/error.ts +11 -0
  210. package/src/compiler/runtime/index.ts +1 -0
  211. package/src/compiler/structured-data/index.ts +3 -0
  212. package/src/compiler/structured-data/lowering.ts +314 -0
  213. package/src/compiler/structured-data/path.ts +53 -0
  214. package/src/compiler/structured-data/runtime.ts +221 -0
  215. package/src/compiler/turbowarp-v2.ts +610 -0
  216. package/src/compiler/validator/index.ts +4 -0
  217. package/src/compiler/validator/ir-validator.ts +812 -0
  218. package/src/compiler/validator/resource-lifetime.ts +153 -0
  219. package/src/compiler/validator/turbowarp-subset.ts +387 -0
  220. package/src/compiler/validator/types.ts +68 -0
  221. package/src/config.ts +1 -1
  222. package/src/extension.ts +87 -1
  223. package/src/fixed-input-editors.ts +181 -0
  224. package/src/fixed-input-schema.ts +15 -0
  225. package/src/named-body.ts +495 -0
  226. package/src/named-data-namespace.ts +6 -0
  227. package/src/protocol.ts +50 -1
  228. package/src/resource-named-body-provider.ts +106 -0
  229. package/src/server.ts +88 -8
  230. package/docs/turbowarp-http-server.architecture.visual-check.1440x900.dark.png +0 -0
  231. package/docs/turbowarp-http-server.architecture.visual-check.1440x900.light.png +0 -0
  232. package/docs/turbowarp-http-server.architecture.visual-check.2048x1320.dark.png +0 -0
  233. package/docs/turbowarp-http-server.architecture.visual-check.2048x1320.light.png +0 -0
  234. package/docs/turbowarp-http-server.architecture.visual-check.html +0 -32
  235. package/docs/turbowarp-http-server.architecture.visual-check.json +0 -547
  236. package/schemas/extension-manifest.schema.json +0 -49
  237. package/src/extension-manifest.ts +0 -149
@@ -0,0 +1,84 @@
1
+ export const DEPLOY_IR_V2_VERSION = 2;
2
+ export const IR_V2_EXPRESSION_KINDS = [
3
+ 'literal',
4
+ 'request',
5
+ 'request-value',
6
+ 'concat',
7
+ 'handler-variable',
8
+ 'handler-variable-exists',
9
+ 'handler-variable-names',
10
+ 'kvs-get-text',
11
+ 'kvs-has',
12
+ 'kvs-list-keys',
13
+ 'binding',
14
+ 'json-text-coerce',
15
+ 'json-parse',
16
+ 'json-stringify',
17
+ 'json-is-valid',
18
+ 'json-get',
19
+ 'json-has',
20
+ 'json-set',
21
+ 'json-delete',
22
+ 'json-keys',
23
+ 'json-length',
24
+ 'iteration-key',
25
+ 'iteration-index',
26
+ 'iteration-value'
27
+ ];
28
+ export const IR_V2_STATEMENT_KINDS = [
29
+ 'set-status',
30
+ 'set-header',
31
+ 'remove-header',
32
+ 'set-handler-variable',
33
+ 'change-handler-variable',
34
+ 'delete-handler-variable',
35
+ 'clear-handler-variables',
36
+ 'kvs-set-text',
37
+ 'kvs-delete',
38
+ 'record-create',
39
+ 'record-list',
40
+ 'record-get',
41
+ 'record-delete',
42
+ 'asset-resolve',
43
+ 'request-body-binary',
44
+ 'asset-object-get',
45
+ 'asset-object-put',
46
+ 'asset-object-delete',
47
+ 'if',
48
+ 'bounded-loop',
49
+ 'json-for-each',
50
+ 'respond-binary',
51
+ 'respond-named-body',
52
+ 'respond'
53
+ ];
54
+ export const IR_V2_STATEMENT_EFFECTS = {
55
+ 'set-status': ['response-write'],
56
+ 'set-header': ['response-write'],
57
+ 'remove-header': ['response-write'],
58
+ 'set-handler-variable': ['handler-state-write'],
59
+ 'change-handler-variable': ['handler-state-write'],
60
+ 'delete-handler-variable': ['handler-state-write'],
61
+ 'clear-handler-variables': ['handler-state-write'],
62
+ 'kvs-set-text': ['key-value-write'],
63
+ 'kvs-delete': ['key-value-write'],
64
+ 'record-create': ['record-write'],
65
+ 'record-list': ['record-read'],
66
+ 'record-get': ['record-read'],
67
+ 'record-delete': ['record-write'],
68
+ 'asset-resolve': ['object-read'],
69
+ 'request-body-binary': ['control'],
70
+ 'asset-object-get': ['object-read'],
71
+ 'asset-object-put': ['object-write', 'binary-consume'],
72
+ 'asset-object-delete': ['object-write'],
73
+ if: ['control'],
74
+ 'bounded-loop': ['control'],
75
+ 'json-for-each': ['control'],
76
+ 'respond-binary': ['response-write', 'binary-consume'],
77
+ 'respond-named-body': ['response-write'],
78
+ respond: ['response-write']
79
+ };
80
+ export const JSON_VALUE_TYPE_V2 = {
81
+ kind: 'union',
82
+ members: ['null', 'boolean', 'number', 'string', 'json-array', 'json-object']
83
+ };
84
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/compiler/ir-v2/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAU,CAAC;AAE/C,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,SAAS;IACT,SAAS;IACT,eAAe;IACf,QAAQ;IACR,kBAAkB;IAClB,yBAAyB;IACzB,wBAAwB;IACxB,cAAc;IACd,SAAS;IACT,eAAe;IACf,SAAS;IACT,kBAAkB;IAClB,YAAY;IACZ,gBAAgB;IAChB,eAAe;IACf,UAAU;IACV,UAAU;IACV,UAAU;IACV,aAAa;IACb,W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AC;IAC3B,eAAe,EAAE,CAAC,SAAS,CAAC;IAC5B,gBAAgB,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IACtD,oBAAoB,EAAE,CAAC,gBAAgB,CAAC;IACxC,OAAO,EAAE,CAAC,gBAAgB,CAAC;CAC+D,CAAC;AAgE7F,MAAM,CAAC,MAAM,kBAAkB,GAAoB;IACjD,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,CAAC;CAC9E,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { CompilerDiagnosticV2, ExpressionIrV2, SourceRefV2, StatementIrV2 } from '../ir-v2/types.js';
2
+ import type { CompilerOpcodeRegistryEntry } from '../manifest/types.js';
3
+ export type KvsArguments = Readonly<Record<string, ExpressionIrV2>>;
4
+ export declare class KvsLoweringContext {
5
+ readonly diagnostics: CompilerDiagnosticV2[];
6
+ constructor(diagnostics?: CompilerDiagnosticV2[]);
7
+ lowerStatement(entry: CompilerOpcodeRegistryEntry, args: KvsArguments, sourceRef: SourceRefV2): StatementIrV2 | undefined;
8
+ lowerReporter(entry: CompilerOpcodeRegistryEntry, args: KvsArguments, sourceRef: SourceRefV2): ExpressionIrV2 | undefined;
9
+ private operation;
10
+ private missingArgument;
11
+ private unsupported;
12
+ }
13
+ export declare function isKvsEntry(entry: CompilerOpcodeRegistryEntry): boolean;
@@ -0,0 +1,77 @@
1
+ const EXTENSION_ID = 'kubohiroyakvs';
2
+ const PACKAGE_NAME = '@kubohiroya/turbowarp-kvs';
3
+ const PACKAGE_VERSION = '0.1.0';
4
+ export class KvsLoweringContext {
5
+ constructor(diagnostics = []) {
6
+ this.diagnostics = diagnostics;
7
+ }
8
+ lowerStatement(entry, args, sourceRef) {
9
+ const operation = this.operation(entry, sourceRef);
10
+ if (operation === undefined)
11
+ return undefined;
12
+ const namespace = args.NAMESPACE;
13
+ const key = args.KEY;
14
+ if (namespace === undefined || key === undefined)
15
+ return this.missingArgument(sourceRef);
16
+ if (operation === 'kvs.delete')
17
+ return { kind: 'kvs-delete', namespace, key, sourceRef };
18
+ if (operation === 'kvs.setText') {
19
+ const value = args.VALUE;
20
+ return value === undefined
21
+ ? this.missingArgument(sourceRef)
22
+ : { kind: 'kvs-set-text', namespace, key, value, sourceRef };
23
+ }
24
+ return this.unsupported(operation, sourceRef);
25
+ }
26
+ lowerReporter(entry, args, sourceRef) {
27
+ const operation = this.operation(entry, sourceRef);
28
+ if (operation === undefined)
29
+ return undefined;
30
+ const namespace = args.NAMESPACE;
31
+ if (namespace === undefined)
32
+ return this.missingArgument(sourceRef);
33
+ if (operation === 'kvs.listKeys') {
34
+ return { kind: 'kvs-list-keys', valueType: 'json-text', namespace, sourceRef };
35
+ }
36
+ const key = args.KEY;
37
+ if (key === undefined)
38
+ return this.missingArgument(sourceRef);
39
+ if (operation === 'kvs.getText')
40
+ return { kind: 'kvs-get-text', valueType: 'string', namespace, key, sourceRef };
41
+ if (operation === 'kvs.has')
42
+ return { kind: 'kvs-has', valueType: 'boolean', namespace, key, sourceRef };
43
+ return this.unsupported(operation, sourceRef);
44
+ }
45
+ operation(entry, sourceRef) {
46
+ if (entry.extensionId !== EXTENSION_ID ||
47
+ entry.packageName !== PACKAGE_NAME ||
48
+ entry.packageVersion !== PACKAGE_VERSION ||
49
+ entry.block.server?.supported !== true ||
50
+ entry.block.server.irOperation === undefined) {
51
+ return this.unsupported(entry.projectOpcode, sourceRef);
52
+ }
53
+ return entry.block.server.irOperation;
54
+ }
55
+ missingArgument(sourceRef) {
56
+ this.diagnostics.push({
57
+ severity: 'error',
58
+ code: 'TW2_KVS_SIGNATURE_MISMATCH',
59
+ message: 'The KVS block does not match its locked manifest signature.',
60
+ sourceRef
61
+ });
62
+ return undefined;
63
+ }
64
+ unsupported(operation, sourceRef) {
65
+ this.diagnostics.push({
66
+ severity: 'error',
67
+ code: 'TW2_UNSUPPORTED_OPERATION',
68
+ message: `KVS operation is not supported by this lowering phase: ${operation}`,
69
+ sourceRef
70
+ });
71
+ return undefined;
72
+ }
73
+ }
74
+ export function isKvsEntry(entry) {
75
+ return entry.extensionId === EXTENSION_ID;
76
+ }
77
+ //# sourceMappingURL=lowering.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lowering.js","sourceRoot":"","sources":["../../../src/compiler/kvs/lowering.ts"],"names":[],"mappings":"AAGA,MAAM,YAAY,GAAG,eAAe,CAAC;AACrC,MAAM,YAAY,GAAG,2BAA2B,CAAC;AACjD,MAAM,eAAe,GAAG,OAAO,CAAC;AAIhC,MAAM,OAAO,kBAAkB;IAC7B,YAAmC,cAAsC,EAAE;QAAxC,gBAAW,GAAX,WAAW,CAA6B;IAAG,CAAC;IAExE,cAAc,CACnB,KAAkC,EAClC,IAAkB,EAClB,SAAsB;QAEtB,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACnD,IAAI,SAAS,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACrB,IAAI,SAAS,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QACzF,IAAI,SAAS,KAAK,YAAY;YAAE,OAAO,EAAC,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAC,CAAC;QACvF,IAAI,SAAS,KAAK,aAAa,EAAE,CAAC;YAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;YACzB,OAAO,KAAK,KAAK,SAAS;gBACxB,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC;gBACjC,CAAC,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,SAAS,EAAE,GAAG,EAAE,KAA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' | 'TW2_MANIFEST_INTEGRITY_MISMATCH' | 'TW2_MANIFEST_SOURCE_UNSAFE' | 'TW2_MANIFEST_SOURCE_NOT_FOUND' | 'TW2_MANIFEST_OPERATION_MISMATCH' | 'TW2_MANIFEST_UNKNOWN_OPCODE';
2
+ export declare class CompilerManifestError extends Error {
3
+ readonly code: CompilerManifestDiagnosticCode;
4
+ readonly cause?: unknown | undefined;
5
+ readonly name = "CompilerManifestError";
6
+ constructor(code: CompilerManifestDiagnosticCode, message: string, cause?: unknown | undefined);
7
+ }
@@ -0,0 +1,9 @@
1
+ export class CompilerManifestError extends Error {
2
+ constructor(code, message, cause) {
3
+ super(message);
4
+ this.code = code;
5
+ this.cause = cause;
6
+ this.name = 'CompilerManifestError';
7
+ }
8
+ }
9
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/compiler/manifest/error.ts"],"names":[],"mappings":"AAkBA,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAG9C,YACkB,IAAoC,EACpD,OAAe,EACC,KAAe;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAJ,IAAI,CAAgC;QAEpC,UAAK,GAAL,KAAK,CAAU;QALjB,SAAI,GAAG,uBAAuB,CAAC;IAQ/C,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export { CompilerManifestError, type CompilerManifestDiagnosticCode } from './error.js';
2
+ export { KNOWN_SERVER_OPERATIONS, validateServerOperationHint } from './operations.js';
3
+ export { DEFAULT_COMPILER_MANIFEST_LIMITS, parseCompilerExtensionManifestJson, parseCompilerManifestLockJson, type CompilerManifestLimits } from './parse.js';
4
+ export { buildCompilerOpcodeRegistry, resolveCompilerProjectOpcode } from './registry.js';
5
+ export { manifestIntegrity, resolveCompilerManifestLock, type BundledCompilerManifests, type ResolveCompilerManifestOptions, type ResolvedCompilerManifestLock } from './resolve.js';
6
+ export * from './types.js';
@@ -0,0 +1,7 @@
1
+ export { CompilerManifestError } from './error.js';
2
+ export { KNOWN_SERVER_OPERATIONS, validateServerOperationHint } from './operations.js';
3
+ export { DEFAULT_COMPILER_MANIFEST_LIMITS, parseCompilerExtensionManifestJson, parseCompilerManifestLockJson } from './parse.js';
4
+ export { buildCompilerOpcodeRegistry, resolveCompilerProjectOpcode } from './registry.js';
5
+ export { manifestIntegrity, resolveCompilerManifestLock } from './resolve.js';
6
+ export * from './types.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/compiler/manifest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAsC,MAAM,YAAY,CAAC;AACtF,OAAO,EAAC,uBAAuB,EAAE,2BAA2B,EAAC,MAAM,iBAAiB,CAAC;AACrF,OAAO,EACL,gCAAgC,EAChC,kCAAkC,EAClC,6BAA6B,EAE9B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAC,2BAA2B,EAAE,4BAA4B,EAAC,MAAM,eAAe,CAAC;AACxF,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAI5B,MAAM,cAAc,CAAC;AACtB,cAAc,YAAY,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { CompilerManifestArgument, CompilerManifestBlock, ManifestBlockType, ManifestEffect, ManifestResultType } from './types.js';
2
+ interface ServerOperationSignature {
3
+ opcode: string;
4
+ blockType: ManifestBlockType;
5
+ arguments: readonly CompilerManifestArgument[];
6
+ resultType: ManifestResultType;
7
+ effect: ManifestEffect;
8
+ immutable: boolean;
9
+ }
10
+ export declare const KNOWN_SERVER_OPERATIONS: Readonly<Record<string, ServerOperationSignature>>;
11
+ export declare function validateServerOperationHint(block: CompilerManifestBlock): void;
12
+ export {};
@@ -0,0 +1,60 @@
1
+ import { CompilerManifestError } from './error.js';
2
+ const STRING = 'STRING';
3
+ const NUMBER = 'NUMBER';
4
+ export const KNOWN_SERVER_OPERATIONS = {
5
+ 'kvs.delete': signature('deleteKey', 'COMMAND', [{ id: 'KEY', type: STRING }, { id: 'NAMESPACE', type: STRING }], 'void', 'storage-write', false),
6
+ 'kvs.getText': signature('getValue', 'REPORTER', [{ id: 'KEY', type: STRING }, { id: 'NAMESPACE', type: STRING }], 'string', 'storage-read'),
7
+ 'kvs.has': signature('hasKey', 'BOOLEAN', [{ id: 'KEY', type: STRING }, { id: 'NAMESPACE', type: STRING }], 'boolean', 'storage-read'),
8
+ 'kvs.listKeys': signature('listKeys', 'REPORTER', [{ id: 'NAMESPACE', type: STRING }], 'json', 'storage-read'),
9
+ 'kvs.setText': signature('setValue', 'COMMAND', [{ id: 'KEY', type: STRING }, { id: 'NAMESPACE', type: STRING }, { id: 'VALUE', type: STRING }], 'void', 'storage-write', false),
10
+ 'structuredData.currentIndex': signature('currentIndex', 'REPORTER', [], 'number', 'control'),
11
+ 'structuredData.currentKey': signature('currentKey', 'REPORTER', [], 'string', 'control'),
12
+ 'structuredData.currentValue': signature('currentValueJson', 'REPORTER', [], 'json', 'control'),
13
+ 'structuredData.delete': signature('deleteAtPath', 'REPORTER', [{ id: 'JSON', type: STRING }, pathArgument()], 'json', 'immutable'),
14
+ 'structuredData.forEach': signature('forEachAtPath', 'LOOP', [
15
+ { id: 'JSON', type: STRING },
16
+ { id: 'MAX', type: NUMBER, staticLiteral: true, minimum: 1, maximum: 1000 },
17
+ pathArgument()
18
+ ], 'void', 'control'),
19
+ 'structuredData.get': signature('getJsonAtPath', 'REPORTER', [{ id: 'JSON', type: STRING }, pathArgument()], 'json', 'pure'),
20
+ 'structuredData.has': signature('hasPath', 'BOOLEAN', [{ id: 'JSON', type: STRING }, pathArgument()], 'boolean', 'pure'),
21
+ 'structuredData.isValidJson': signature('isValidJson', 'BOOLEAN', [{ id: 'JSON', type: STRING }], 'boolean', 'pure'),
22
+ 'structuredData.keys': signature('keysAtPath', 'REPORTER', [{ id: 'JSON', type: STRING }, pathArgument()], 'json', 'pure'),
23
+ 'structuredData.length': signature('lengthAtPath', 'REPORTER', [{ id: 'JSON', type: STRING }, pathArgument()], 'number', 'pure'),
24
+ 'structuredData.normalizeJson': signature('normalizeJson', 'REPORTER', [{ id: 'JSON', type: STRING }], 'json', 'pure'),
25
+ 'structuredData.set': signature('setJsonAtPath', 'REPORTER', [{ id: 'JSON', type: STRING }, pathArgument(), { id: 'VALUE', type: STRING }], 'json', 'immutable')
26
+ };
27
+ export function validateServerOperationHint(block) {
28
+ const operation = block.server?.irOperation;
29
+ if (block.server?.supported !== true) {
30
+ if (operation !== undefined)
31
+ operationMismatch(block, operation, 'unsupported blocks must not declare an operation');
32
+ return;
33
+ }
34
+ if (operation === undefined)
35
+ operationMismatch(block, '<missing>', 'supported blocks require an operation');
36
+ const expected = KNOWN_SERVER_OPERATIONS[operation];
37
+ if (expected === undefined)
38
+ operationMismatch(block, operation, 'operation is not in the compiler allowlist');
39
+ const actual = {
40
+ opcode: block.opcode,
41
+ blockType: block.blockType,
42
+ arguments: block.arguments,
43
+ resultType: block.resultType,
44
+ effect: block.effect,
45
+ immutable: block.immutable
46
+ };
47
+ if (JSON.stringify(actual) !== JSON.stringify(expected)) {
48
+ operationMismatch(block, operation, 'block signature does not match the compiler allowlist');
49
+ }
50
+ }
51
+ function signature(opcode, blockType, argumentsValue, resultType, effect, immutable = true) {
52
+ return { opcode, blockType, arguments: argumentsValue, resultType, effect, immutable };
53
+ }
54
+ function pathArgument() {
55
+ return { id: 'PATH', type: STRING, normalizesTo: 'pathSegments' };
56
+ }
57
+ function operationMismatch(block, operation, reason) {
58
+ throw new CompilerManifestError('TW2_MANIFEST_OPERATION_MISMATCH', `Manifest operation ${operation} on block ${block.opcode} is invalid: ${reason}.`);
59
+ }
60
+ //# sourceMappingURL=operations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations.js","sourceRoot":"","sources":["../../../src/compiler/manifest/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAC,MAAM,YAAY,CAAC;AAkBjD,M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AC,MAAM;QACpB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAC;IACF,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxD,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,uDAAuD,CAAC,CAAC;IAC/F,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAChB,MAAc,EACd,SAA4B,EAC5B,cAAmD,EACnD,UAA8B,EAC9B,MAAsB,EACtB,SAAS,GAAG,IAAI;IAEhB,OAAO,EAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAC,CAAC;AACvF,CAAC;AAED,SAAS,YAAY;IACnB,OAAO,EAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAC,CAAC;AAClE,CAAC;AAED,SAAS,iBAAiB,CAAC,KAA4B,EAAE,SAAiB,EAAE,MAAc;IACxF,MAAM,IAAI,qBAAqB,CAC7B,iCAAiC,EACjC,sBAAsB,SAAS,aAAa,KAAK,CAAC,MAAM,gBAAgB,MAAM,GAAG,CAClF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { type CompilerExtensionManifest, type CompilerManifestLock } from './types.js';
2
+ export interface CompilerManifestLimits {
3
+ maxBytes: number;
4
+ maxDepth: number;
5
+ maxBlocks: number;
6
+ }
7
+ export declare const DEFAULT_COMPILER_MANIFEST_LIMITS: Readonly<CompilerManifestLimits>;
8
+ export declare function parseCompilerExtensionManifestJson(text: string, limits?: Readonly<CompilerManifestLimits>): CompilerExtensionManifest;
9
+ export declare function parseCompilerManifestLockJson(text: string, limits?: Readonly<Pick<CompilerManifestLimits, 'maxBytes' | 'maxDepth'>>): CompilerManifestLock;
@@ -0,0 +1,280 @@
1
+ import { parseJsonWithoutDuplicateKeys } from '../ir-v2/strict-json.js';
2
+ import { CompilerManifestError } from './error.js';
3
+ import { COMPILER_MANIFEST_LOCK_VERSION } from './types.js';
4
+ export const DEFAULT_COMPILER_MANIFEST_LIMITS = {
5
+ maxBytes: 1024 * 1024,
6
+ maxDepth: 64,
7
+ maxBlocks: 2048
8
+ };
9
+ const BLOCK_TYPES = new Set(['COMMAND', 'REPORTER', 'BOOLEAN', 'HAT', 'LOOP']);
10
+ const ARGUMENT_TYPES = new Set(['STRING', 'NUMBER', 'BOOLEAN']);
11
+ const RESULT_TYPES = new Set(['json', 'boolean', 'number', 'string', 'void', 'jsonText', 'yamlText']);
12
+ const EFFECTS = new Set([
13
+ 'pure',
14
+ 'immutable',
15
+ 'control',
16
+ 'request-read',
17
+ 'response-write',
18
+ 'storage-read',
19
+ 'storage-write',
20
+ 'binary-read',
21
+ 'binary-write',
22
+ 'state'
23
+ ]);
24
+ const EXTENSION_ID = /^[a-z0-9]+$/;
25
+ const OPCODE = /^[A-Za-z][A-Za-z0-9_]*$/;
26
+ const EXACT_PACKAGE_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
27
+ const INTEGRITY = /^sha256-([A-Za-z0-9+/]{43}=)$/;
28
+ export function parseCompilerExtensionManifestJson(text, limits = DEFAULT_COMPILER_MANIFEST_LIMITS) {
29
+ assertByteLimit(text, limits.maxBytes, 'manifest');
30
+ const value = parseStrictJson(text, limits.maxDepth);
31
+ const root = object(value, 'manifest');
32
+ exactKeys(root, ['formatVersion', 'id', 'pathSegmentType', 'dataReferenceType', 'blocks', 'menus'], 'manifest');
33
+ const formatVersion = manifestFormatVersion(root.formatVersion, 'manifest.formatVersion');
34
+ const id = extensionId(root.id, 'manifest.id');
35
+ const rawBlocks = array(root.blocks, 'manifest.blocks');
36
+ if (rawBlocks.length === 0)
37
+ schemaError('manifest.blocks must not be empty.');
38
+ if (rawBlocks.length > limits.maxBlocks) {
39
+ throw new CompilerManifestError('TW2_MANIFEST_TOO_MANY_BLOCKS', `manifest.blocks exceeds the ${limits.maxBlocks} block limit.`);
40
+ }
41
+ const blocks = rawBlocks.map((block, index) => parseBlock(block, `manifest.blocks[${index}]`, formatVersion));
42
+ rejectDuplicates(blocks.map((block) => block.opcode), 'TW2_MANIFEST_DUPLICATE_OPCODE', 'manifest opcode');
43
+ const pathSegmentType = root.pathSegmentType === undefined
44
+ ? undefined
45
+ : parsePathSegmentType(root.pathSegmentType, 'manifest.pathSegmentType');
46
+ const dataReferenceType = root.dataReferenceType === undefined
47
+ ? undefined
48
+ : parseDataReferenceType(root.dataReferenceType, 'manifest.dataReferenceType');
49
+ const menus = root.menus === undefined ? undefined : array(root.menus, 'manifest.menus');
50
+ return optional(optional(optional({ formatVersion, id, blocks }, 'pathSegmentType', pathSegmentType), 'dataReferenceType', dataReferenceType), 'menus', menus);
51
+ }
52
+ /** The counterpart of pathSegmentType: what the values an extension hands out refer to. */
53
+ function parseDataReferenceType(value, location) {
54
+ const reference = object(value, location);
55
+ exactKeys(reference, ['kind', 'scope', 'lifetime', 'valueType'], location);
56
+ return {
57
+ kind: nonEmptyString(reference.kind, `${location}.kind`),
58
+ scope: nonEmptyString(reference.scope, `${location}.scope`),
59
+ lifetime: nonEmptyString(reference.lifetime, `${location}.lifetime`),
60
+ valueType: nonEmptyString(reference.valueType, `${location}.valueType`)
61
+ };
62
+ }
63
+ export function parseCompilerManifestLockJson(text, limits = DEFAULT_COMPILER_MANIFEST_LIMITS) {
64
+ assertByteLimit(text, limits.maxBytes, 'manifest lock');
65
+ const root = object(parseStrictJson(text, limits.maxDepth), 'manifest lock');
66
+ exactKeys(root, ['lockVersion', 'extensions'], 'manifest lock');
67
+ if (root.lockVersion !== COMPILER_MANIFEST_LOCK_VERSION) {
68
+ throw new CompilerManifestError('TW2_MANIFEST_UNSUPPORTED_VERSION', `manifest lock.lockVersion must be ${COMPILER_MANIFEST_LOCK_VERSION}.`);
69
+ }
70
+ const extensions = array(root.extensions, 'manifest lock.extensions').map((entry, index) => parseLockEntry(entry, `manifest lock.extensions[${index}]`));
71
+ rejectDuplicates(extensions.map((entry) => entry.extensionId), 'TW2_MANIFEST_DUPLICATE_EXTENSION', 'locked extension ID');
72
+ return {
73
+ lockVersion: COMPILER_MANIFEST_LOCK_VERSION,
74
+ extensions: extensions.sort((left, right) => lexicalCompare(left.extensionId, right.extensionId))
75
+ };
76
+ }
77
+ function parseBlock(value, location, formatVersion) {
78
+ const block = object(value, location);
79
+ exactKeys(block, ['opcode', 'blockType', 'arguments', 'resultType', 'effect', 'immutable', 'errors', 'server'], location);
80
+ const opcode = matches(block.opcode, OPCODE, `${location}.opcode`);
81
+ const blockType = enumValue(block.blockType, BLOCK_TYPES, `${location}.blockType`);
82
+ const args = array(block.arguments, `${location}.arguments`).map((argument, index) => parseArgument(argument, `${location}.arguments[${index}]`));
83
+ rejectDuplicates(args.map((argument) => argument.id), 'TW2_MANIFEST_SCHEMA', `${location} argument ID`);
84
+ const resultType = optionalEnum(block.resultType, RESULT_TYPES, `${location}.resultType`);
85
+ const effect = optionalEnum(block.effect, EFFECTS, `${location}.effect`);
86
+ const immutable = optionalBoolean(block.immutable, `${location}.immutable`);
87
+ const errors = optionalStringArray(block.errors, `${location}.errors`);
88
+ const server = block.server === undefined ? undefined : parseServerHint(block.server, `${location}.server`);
89
+ if (formatVersion === 2 && [resultType, effect, immutable, errors, server].some((item) => item === undefined)) {
90
+ schemaError(`${location} is missing formatVersion 2 compiler metadata.`);
91
+ }
92
+ return optional(optional(optional(optional(optional({ opcode, blockType, arguments: args }, 'resultType', resultType), 'effect', effect), 'immutable', immutable), 'errors', errors), 'server', server);
93
+ }
94
+ function parseArgument(value, location) {
95
+ const argument = object(value, location);
96
+ exactKeys(argument, ['id', 'type', 'menu', 'normalizesTo', 'staticLiteral', 'minimum', 'maximum'], location);
97
+ const id = nonEmptyString(argument.id, `${location}.id`);
98
+ const type = enumValue(argument.type, ARGUMENT_TYPES, `${location}.type`);
99
+ const menu = optionalString(argument.menu, `${location}.menu`);
100
+ const rawNormalizesTo = argument.normalizesTo;
101
+ if (rawNormalizesTo !== undefined && rawNormalizesTo !== 'pathSegments') {
102
+ schemaError(`${location}.normalizesTo must be pathSegments.`);
103
+ }
104
+ const normalizesTo = rawNormalizesTo;
105
+ const staticLiteral = optionalBoolean(argument.staticLiteral, `${location}.staticLiteral`);
106
+ const minimum = optionalFiniteNumber(argument.minimum, `${location}.minimum`);
107
+ const maximum = optionalFiniteNumber(argument.maximum, `${location}.maximum`);
108
+ if (minimum !== undefined && maximum !== undefined && minimum > maximum) {
109
+ schemaError(`${location}.minimum must not exceed maximum.`);
110
+ }
111
+ return optional(optional(optional(optional(optional({ id, type }, 'menu', menu), 'normalizesTo', normalizesTo), 'staticLiteral', staticLiteral), 'minimum', minimum), 'maximum', maximum);
112
+ }
113
+ function parseServerHint(value, location) {
114
+ const server = object(value, location);
115
+ exactKeys(server, ['supported', 'irOperation'], location);
116
+ const supported = boolean(server.supported, `${location}.supported`);
117
+ const irOperation = optionalString(server.irOperation, `${location}.irOperation`);
118
+ if (supported && irOperation === undefined)
119
+ schemaError(`${location}.irOperation is required when supported is true.`);
120
+ return optional({ supported }, 'irOperation', irOperation);
121
+ }
122
+ function parsePathSegmentType(value, location) {
123
+ const pathType = object(value, location);
124
+ exactKeys(pathType, ['kind', 'variants'], location);
125
+ if (pathType.kind !== 'discriminatedUnion')
126
+ schemaError(`${location}.kind must be discriminatedUnion.`);
127
+ const variants = array(pathType.variants, `${location}.variants`);
128
+ if (variants.length !== 2)
129
+ schemaError(`${location}.variants must contain key and index in that order.`);
130
+ const key = object(variants[0], `${location}.variants[0]`);
131
+ const index = object(variants[1], `${location}.variants[1]`);
132
+ exactKeys(key, ['kind', 'valueType'], `${location}.variants[0]`);
133
+ exactKeys(index, ['kind', 'valueType'], `${location}.variants[1]`);
134
+ if (key.kind !== 'key' || key.valueType !== 'string')
135
+ schemaError(`${location}.variants[0] must be a string key.`);
136
+ if (index.kind !== 'index' || index.valueType !== 'nonNegativeInteger') {
137
+ schemaError(`${location}.variants[1] must be a non-negative integer index.`);
138
+ }
139
+ return {
140
+ kind: 'discriminatedUnion',
141
+ variants: [
142
+ { kind: 'key', valueType: 'string' },
143
+ { kind: 'index', valueType: 'nonNegativeInteger' }
144
+ ]
145
+ };
146
+ }
147
+ function parseLockEntry(value, location) {
148
+ const entry = object(value, location);
149
+ exactKeys(entry, ['extensionId', 'packageName', 'packageVersion', 'manifestFormatVersion', 'integrity', 'source'], location);
150
+ const extensionIdValue = extensionId(entry.extensionId, `${location}.extensionId`);
151
+ const packageName = nonEmptyString(entry.packageName, `${location}.packageName`);
152
+ const packageVersion = matches(entry.packageVersion, EXACT_PACKAGE_VERSION, `${location}.packageVersion`);
153
+ const manifestFormatVersion = manifestFormatVersionValue(entry.manifestFormatVersion, `${location}.manifestFormatVersion`);
154
+ const integrity = matches(entry.integrity, INTEGRITY, `${location}.integrity`);
155
+ const source = parseSource(entry.source, `${location}.source`);
156
+ return { extensionId: extensionIdValue, packageName, packageVersion, manifestFormatVersion, integrity, source };
157
+ }
158
+ function parseSource(value, location) {
159
+ const source = object(value, location);
160
+ const kind = nonEmptyString(source.kind, `${location}.kind`);
161
+ if (kind === 'bundled') {
162
+ exactKeys(source, ['kind', 'id'], location);
163
+ return { kind, id: nonEmptyString(source.id, `${location}.id`) };
164
+ }
165
+ if (kind === 'local') {
166
+ exactKeys(source, ['kind', 'path'], location);
167
+ return { kind, path: nonEmptyString(source.path, `${location}.path`) };
168
+ }
169
+ schemaError(`${location}.kind is unsupported: ${kind}`);
170
+ }
171
+ function manifestFormatVersion(value, location) {
172
+ return manifestFormatVersionValue(value, location);
173
+ }
174
+ function manifestFormatVersionValue(value, location) {
175
+ if (value !== 1 && value !== 2) {
176
+ throw new CompilerManifestError('TW2_MANIFEST_UNSUPPORTED_VERSION', `${location} must be 1 or 2.`);
177
+ }
178
+ return value;
179
+ }
180
+ function parseStrictJson(text, maxDepth) {
181
+ try {
182
+ return parseJsonWithoutDuplicateKeys(text, { maxDepth });
183
+ }
184
+ catch (error) {
185
+ const message = error instanceof Error ? error.message : String(error);
186
+ const code = message.startsWith('Duplicate object key:')
187
+ ? 'TW2_MANIFEST_DUPLICATE_KEY'
188
+ : message.startsWith('JSON nesting depth exceeds')
189
+ ? 'TW2_MANIFEST_TOO_DEEP'
190
+ : 'TW2_MANIFEST_JSON_SYNTAX';
191
+ throw new CompilerManifestError(code, message, error);
192
+ }
193
+ }
194
+ function assertByteLimit(text, maxBytes, label) {
195
+ const bytes = Buffer.byteLength(text, 'utf8');
196
+ if (bytes > maxBytes) {
197
+ throw new CompilerManifestError('TW2_MANIFEST_TOO_LARGE', `${label} is ${bytes} bytes; limit is ${maxBytes}.`);
198
+ }
199
+ }
200
+ function rejectDuplicates(values, code, label) {
201
+ const seen = new Set();
202
+ for (const value of values) {
203
+ if (seen.has(value))
204
+ throw new CompilerManifestError(code, `Duplicate ${label}: ${value}`);
205
+ seen.add(value);
206
+ }
207
+ }
208
+ function object(value, location) {
209
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
210
+ schemaError(`${location} must be an object.`);
211
+ return value;
212
+ }
213
+ function array(value, location) {
214
+ if (!Array.isArray(value))
215
+ schemaError(`${location} must be an array.`);
216
+ return value;
217
+ }
218
+ function exactKeys(record, allowed, location) {
219
+ const allowedSet = new Set(allowed);
220
+ const unknown = Object.keys(record).filter((key) => !allowedSet.has(key)).sort()[0];
221
+ if (unknown !== undefined)
222
+ schemaError(`${location} contains unknown field: ${unknown}`);
223
+ }
224
+ function extensionId(value, location) {
225
+ return matches(value, EXTENSION_ID, location);
226
+ }
227
+ function matches(value, pattern, location) {
228
+ const text = nonEmptyString(value, location);
229
+ if (!pattern.test(text))
230
+ schemaError(`${location} has an invalid format.`);
231
+ return text;
232
+ }
233
+ function nonEmptyString(value, location) {
234
+ if (typeof value !== 'string' || value.length === 0)
235
+ schemaError(`${location} must be a non-empty string.`);
236
+ return value;
237
+ }
238
+ function optionalString(value, location) {
239
+ return value === undefined ? undefined : nonEmptyString(value, location);
240
+ }
241
+ function boolean(value, location) {
242
+ if (typeof value !== 'boolean')
243
+ schemaError(`${location} must be a boolean.`);
244
+ return value;
245
+ }
246
+ function optionalBoolean(value, location) {
247
+ return value === undefined ? undefined : boolean(value, location);
248
+ }
249
+ function optionalFiniteNumber(value, location) {
250
+ if (value === undefined)
251
+ return undefined;
252
+ if (typeof value !== 'number' || !Number.isFinite(value))
253
+ schemaError(`${location} must be a finite number.`);
254
+ return value;
255
+ }
256
+ function enumValue(value, allowed, location) {
257
+ if (typeof value !== 'string' || !allowed.has(value))
258
+ schemaError(`${location} is unsupported.`);
259
+ return value;
260
+ }
261
+ function optionalEnum(value, allowed, location) {
262
+ return value === undefined ? undefined : enumValue(value, allowed, location);
263
+ }
264
+ function optionalStringArray(value, location) {
265
+ if (value === undefined)
266
+ return undefined;
267
+ const values = array(value, location).map((item, index) => matches(item, /^[A-Z][A-Z0-9_]*$/, `${location}[${index}]`));
268
+ rejectDuplicates(values, 'TW2_MANIFEST_SCHEMA', `${location} value`);
269
+ return values;
270
+ }
271
+ function schemaError(message) {
272
+ throw new CompilerManifestError('TW2_MANIFEST_SCHEMA', message);
273
+ }
274
+ function lexicalCompare(left, right) {
275
+ return left < right ? -1 : left > right ? 1 : 0;
276
+ }
277
+ function optional(base, key, value) {
278
+ return value === undefined ? base : { ...base, [key]: value };
279
+ }
280
+ //# sourceMappingURL=parse.js.map