@taggor/contract 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +61 -2
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/artifact-keys.d.ts +169 -0
  5. package/dist/artifact-keys.d.ts.map +1 -0
  6. package/dist/artifact-keys.js +195 -0
  7. package/dist/artifact-keys.js.map +1 -0
  8. package/dist/assets.d.ts +72 -0
  9. package/dist/assets.d.ts.map +1 -0
  10. package/dist/assets.js +94 -0
  11. package/dist/assets.js.map +1 -0
  12. package/dist/bounded-path.d.ts +29 -0
  13. package/dist/bounded-path.d.ts.map +1 -0
  14. package/dist/bounded-path.js +57 -0
  15. package/dist/bounded-path.js.map +1 -0
  16. package/dist/bounded.d.ts +47 -0
  17. package/dist/bounded.d.ts.map +1 -0
  18. package/dist/bounded.js +93 -0
  19. package/dist/bounded.js.map +1 -0
  20. package/dist/build-diagnostic.d.ts +89 -0
  21. package/dist/build-diagnostic.d.ts.map +1 -0
  22. package/dist/build-diagnostic.js +91 -0
  23. package/dist/build-diagnostic.js.map +1 -0
  24. package/dist/component-types.d.ts +61 -0
  25. package/dist/component-types.d.ts.map +1 -0
  26. package/dist/component-types.js +277 -0
  27. package/dist/component-types.js.map +1 -0
  28. package/dist/consent-text.d.ts +31 -0
  29. package/dist/consent-text.d.ts.map +1 -0
  30. package/dist/consent-text.js +41 -0
  31. package/dist/consent-text.js.map +1 -0
  32. package/dist/contract-version.d.ts +150 -0
  33. package/dist/contract-version.d.ts.map +1 -0
  34. package/dist/contract-version.js +198 -0
  35. package/dist/contract-version.js.map +1 -0
  36. package/dist/credential-fields.d.ts +31 -0
  37. package/dist/credential-fields.d.ts.map +1 -0
  38. package/dist/credential-fields.js +36 -0
  39. package/dist/credential-fields.js.map +1 -0
  40. package/dist/css-tokens.d.ts +46 -0
  41. package/dist/css-tokens.d.ts.map +1 -0
  42. package/dist/css-tokens.js +189 -0
  43. package/dist/css-tokens.js.map +1 -0
  44. package/dist/css-value.d.ts +42 -0
  45. package/dist/css-value.d.ts.map +1 -0
  46. package/dist/css-value.js +78 -0
  47. package/dist/css-value.js.map +1 -0
  48. package/dist/data-api.d.ts +127 -0
  49. package/dist/data-api.d.ts.map +1 -0
  50. package/dist/data-api.js +167 -0
  51. package/dist/data-api.js.map +1 -0
  52. package/dist/denylist-keys.d.ts +19 -0
  53. package/dist/denylist-keys.d.ts.map +1 -0
  54. package/dist/denylist-keys.js +48 -0
  55. package/dist/denylist-keys.js.map +1 -0
  56. package/dist/diagnostic-catalog.d.ts +1402 -0
  57. package/dist/diagnostic-catalog.d.ts.map +1 -0
  58. package/dist/diagnostic-catalog.js +1311 -0
  59. package/dist/diagnostic-catalog.js.map +1 -0
  60. package/dist/dom-members.snapshot.d.ts +33 -0
  61. package/dist/dom-members.snapshot.d.ts.map +1 -0
  62. package/dist/dom-members.snapshot.js +760 -0
  63. package/dist/dom-members.snapshot.js.map +1 -0
  64. package/dist/early-loading.d.ts +27 -0
  65. package/dist/early-loading.d.ts.map +1 -0
  66. package/dist/early-loading.js +44 -0
  67. package/dist/early-loading.js.map +1 -0
  68. package/dist/error-catalog.d.ts +749 -0
  69. package/dist/error-catalog.d.ts.map +1 -0
  70. package/dist/error-catalog.js +720 -0
  71. package/dist/error-catalog.js.map +1 -0
  72. package/dist/executable-config.d.ts +35 -0
  73. package/dist/executable-config.d.ts.map +1 -0
  74. package/dist/executable-config.js +44 -0
  75. package/dist/executable-config.js.map +1 -0
  76. package/dist/freeze.d.ts +17 -0
  77. package/dist/freeze.d.ts.map +1 -0
  78. package/dist/freeze.js +29 -0
  79. package/dist/freeze.js.map +1 -0
  80. package/dist/gunzip.d.ts +33 -0
  81. package/dist/gunzip.d.ts.map +1 -0
  82. package/dist/gunzip.js +330 -0
  83. package/dist/gunzip.js.map +1 -0
  84. package/dist/hostname.d.ts +74 -0
  85. package/dist/hostname.d.ts.map +1 -0
  86. package/dist/hostname.js +215 -0
  87. package/dist/hostname.js.map +1 -0
  88. package/dist/human-actions.d.ts +49 -0
  89. package/dist/human-actions.d.ts.map +1 -0
  90. package/dist/human-actions.js +272 -0
  91. package/dist/human-actions.js.map +1 -0
  92. package/dist/index.d.ts +73 -0
  93. package/dist/index.d.ts.map +1 -0
  94. package/dist/index.js +73 -0
  95. package/dist/index.js.map +1 -0
  96. package/dist/json-schema.d.ts +108 -0
  97. package/dist/json-schema.d.ts.map +1 -0
  98. package/dist/json-schema.js +240 -0
  99. package/dist/json-schema.js.map +1 -0
  100. package/dist/key-checksum.d.ts +33 -0
  101. package/dist/key-checksum.d.ts.map +1 -0
  102. package/dist/key-checksum.js +67 -0
  103. package/dist/key-checksum.js.map +1 -0
  104. package/dist/libraries.d.ts +60 -0
  105. package/dist/libraries.d.ts.map +1 -0
  106. package/dist/libraries.js +120 -0
  107. package/dist/libraries.js.map +1 -0
  108. package/dist/limit-catalog.d.ts +381 -0
  109. package/dist/limit-catalog.d.ts.map +1 -0
  110. package/dist/limit-catalog.js +429 -0
  111. package/dist/limit-catalog.js.map +1 -0
  112. package/dist/limits.d.ts +167 -0
  113. package/dist/limits.d.ts.map +1 -0
  114. package/dist/limits.js +175 -0
  115. package/dist/limits.js.map +1 -0
  116. package/dist/locale-tag.d.ts +21 -0
  117. package/dist/locale-tag.d.ts.map +1 -0
  118. package/dist/locale-tag.js +21 -0
  119. package/dist/locale-tag.js.map +1 -0
  120. package/dist/make-diagnostic.d.ts +74 -0
  121. package/dist/make-diagnostic.d.ts.map +1 -0
  122. package/dist/make-diagnostic.js +100 -0
  123. package/dist/make-diagnostic.js.map +1 -0
  124. package/dist/manifest-compat-diagnostics.d.ts +23 -0
  125. package/dist/manifest-compat-diagnostics.d.ts.map +1 -0
  126. package/dist/manifest-compat-diagnostics.js +150 -0
  127. package/dist/manifest-compat-diagnostics.js.map +1 -0
  128. package/dist/manifest-compat.d.ts +58 -0
  129. package/dist/manifest-compat.d.ts.map +1 -0
  130. package/dist/manifest-compat.js +377 -0
  131. package/dist/manifest-compat.js.map +1 -0
  132. package/dist/manifest.d.ts +1769 -0
  133. package/dist/manifest.d.ts.map +1 -0
  134. package/dist/manifest.js +421 -0
  135. package/dist/manifest.js.map +1 -0
  136. package/dist/metering.d.ts +126 -0
  137. package/dist/metering.d.ts.map +1 -0
  138. package/dist/metering.js +147 -0
  139. package/dist/metering.js.map +1 -0
  140. package/dist/migrate.d.ts +70 -0
  141. package/dist/migrate.d.ts.map +1 -0
  142. package/dist/migrate.js +159 -0
  143. package/dist/migrate.js.map +1 -0
  144. package/dist/money.d.ts +41 -0
  145. package/dist/money.d.ts.map +1 -0
  146. package/dist/money.js +52 -0
  147. package/dist/money.js.map +1 -0
  148. package/dist/names.d.ts +37 -0
  149. package/dist/names.d.ts.map +1 -0
  150. package/dist/names.js +55 -0
  151. package/dist/names.js.map +1 -0
  152. package/dist/overage-pricing.d.ts +89 -0
  153. package/dist/overage-pricing.d.ts.map +1 -0
  154. package/dist/overage-pricing.js +170 -0
  155. package/dist/overage-pricing.js.map +1 -0
  156. package/dist/plan-ids.d.ts +10 -0
  157. package/dist/plan-ids.d.ts.map +1 -0
  158. package/dist/plan-ids.js +8 -0
  159. package/dist/plan-ids.js.map +1 -0
  160. package/dist/plan-limits.d.ts +138 -0
  161. package/dist/plan-limits.d.ts.map +1 -0
  162. package/dist/plan-limits.js +112 -0
  163. package/dist/plan-limits.js.map +1 -0
  164. package/dist/plan-pricing.d.ts +145 -0
  165. package/dist/plan-pricing.d.ts.map +1 -0
  166. package/dist/plan-pricing.js +172 -0
  167. package/dist/plan-pricing.js.map +1 -0
  168. package/dist/plan-usage.d.ts +112 -0
  169. package/dist/plan-usage.d.ts.map +1 -0
  170. package/dist/plan-usage.js +134 -0
  171. package/dist/plan-usage.js.map +1 -0
  172. package/dist/preview-token.d.ts +52 -0
  173. package/dist/preview-token.d.ts.map +1 -0
  174. package/dist/preview-token.js +106 -0
  175. package/dist/preview-token.js.map +1 -0
  176. package/dist/prop-names.d.ts +51 -0
  177. package/dist/prop-names.d.ts.map +1 -0
  178. package/dist/prop-names.js +150 -0
  179. package/dist/prop-names.js.map +1 -0
  180. package/dist/prop-type-docs.d.ts +20 -0
  181. package/dist/prop-type-docs.d.ts.map +1 -0
  182. package/dist/prop-type-docs.js +89 -0
  183. package/dist/prop-type-docs.js.map +1 -0
  184. package/dist/prop-types.d.ts +97 -0
  185. package/dist/prop-types.d.ts.map +1 -0
  186. package/dist/prop-types.js +299 -0
  187. package/dist/prop-types.js.map +1 -0
  188. package/dist/props.d.ts +996 -0
  189. package/dist/props.d.ts.map +1 -0
  190. package/dist/props.js +183 -0
  191. package/dist/props.js.map +1 -0
  192. package/dist/proto-guard.d.ts +29 -0
  193. package/dist/proto-guard.d.ts.map +1 -0
  194. package/dist/proto-guard.js +79 -0
  195. package/dist/proto-guard.js.map +1 -0
  196. package/dist/runtime-errors.d.ts +42 -0
  197. package/dist/runtime-errors.d.ts.map +1 -0
  198. package/dist/runtime-errors.js +42 -0
  199. package/dist/runtime-errors.js.map +1 -0
  200. package/dist/runtime-pointers.d.ts +58 -0
  201. package/dist/runtime-pointers.d.ts.map +1 -0
  202. package/dist/runtime-pointers.js +84 -0
  203. package/dist/runtime-pointers.js.map +1 -0
  204. package/dist/secret-scan.d.ts +191 -0
  205. package/dist/secret-scan.d.ts.map +1 -0
  206. package/dist/secret-scan.js +542 -0
  207. package/dist/secret-scan.js.map +1 -0
  208. package/dist/semver.d.ts +89 -0
  209. package/dist/semver.d.ts.map +1 -0
  210. package/dist/semver.js +400 -0
  211. package/dist/semver.js.map +1 -0
  212. package/dist/server-key.d.ts +68 -0
  213. package/dist/server-key.d.ts.map +1 -0
  214. package/dist/server-key.js +150 -0
  215. package/dist/server-key.js.map +1 -0
  216. package/dist/site-manifest-keys.d.ts +107 -0
  217. package/dist/site-manifest-keys.d.ts.map +1 -0
  218. package/dist/site-manifest-keys.js +146 -0
  219. package/dist/site-manifest-keys.js.map +1 -0
  220. package/dist/site-manifest.d.ts +286 -0
  221. package/dist/site-manifest.d.ts.map +1 -0
  222. package/dist/site-manifest.js +100 -0
  223. package/dist/site-manifest.js.map +1 -0
  224. package/dist/source-archive.d.ts +119 -0
  225. package/dist/source-archive.d.ts.map +1 -0
  226. package/dist/source-archive.js +644 -0
  227. package/dist/source-archive.js.map +1 -0
  228. package/dist/source-package-corpus.d.ts +55 -0
  229. package/dist/source-package-corpus.d.ts.map +1 -0
  230. package/dist/source-package-corpus.js +303 -0
  231. package/dist/source-package-corpus.js.map +1 -0
  232. package/dist/source-package.d.ts +227 -0
  233. package/dist/source-package.d.ts.map +1 -0
  234. package/dist/source-package.js +361 -0
  235. package/dist/source-package.js.map +1 -0
  236. package/dist/source-secrets.d.ts +21 -0
  237. package/dist/source-secrets.d.ts.map +1 -0
  238. package/dist/source-secrets.js +43 -0
  239. package/dist/source-secrets.js.map +1 -0
  240. package/dist/ssr-cap.d.ts +61 -0
  241. package/dist/ssr-cap.d.ts.map +1 -0
  242. package/dist/ssr-cap.js +107 -0
  243. package/dist/ssr-cap.js.map +1 -0
  244. package/dist/ssr-kv.d.ts +18 -0
  245. package/dist/ssr-kv.d.ts.map +1 -0
  246. package/dist/ssr-kv.js +18 -0
  247. package/dist/ssr-kv.js.map +1 -0
  248. package/dist/ssr-version-ledger.d.ts +53 -0
  249. package/dist/ssr-version-ledger.d.ts.map +1 -0
  250. package/dist/ssr-version-ledger.js +88 -0
  251. package/dist/ssr-version-ledger.js.map +1 -0
  252. package/dist/style-references.d.ts +58 -0
  253. package/dist/style-references.d.ts.map +1 -0
  254. package/dist/style-references.js +241 -0
  255. package/dist/style-references.js.map +1 -0
  256. package/dist/tag-name.d.ts +87 -0
  257. package/dist/tag-name.d.ts.map +1 -0
  258. package/dist/tag-name.js +222 -0
  259. package/dist/tag-name.js.map +1 -0
  260. package/dist/tar-writer.d.ts +74 -0
  261. package/dist/tar-writer.d.ts.map +1 -0
  262. package/dist/tar-writer.js +148 -0
  263. package/dist/tar-writer.js.map +1 -0
  264. package/dist/testing.d.ts +11 -0
  265. package/dist/testing.d.ts.map +1 -0
  266. package/dist/testing.js +11 -0
  267. package/dist/testing.js.map +1 -0
  268. package/dist/text-codec.d.ts +36 -0
  269. package/dist/text-codec.d.ts.map +1 -0
  270. package/dist/text-codec.js +32 -0
  271. package/dist/text-codec.js.map +1 -0
  272. package/dist/url-value.d.ts +41 -0
  273. package/dist/url-value.d.ts.map +1 -0
  274. package/dist/url-value.js +147 -0
  275. package/dist/url-value.js.map +1 -0
  276. package/dist/usage-guard.d.ts +99 -0
  277. package/dist/usage-guard.d.ts.map +1 -0
  278. package/dist/usage-guard.js +104 -0
  279. package/dist/usage-guard.js.map +1 -0
  280. package/dist/usage-mirror.d.ts +55 -0
  281. package/dist/usage-mirror.d.ts.map +1 -0
  282. package/dist/usage-mirror.js +52 -0
  283. package/dist/usage-mirror.js.map +1 -0
  284. package/dist/value-check.d.ts +88 -0
  285. package/dist/value-check.d.ts.map +1 -0
  286. package/dist/value-check.js +279 -0
  287. package/dist/value-check.js.map +1 -0
  288. package/dist/value-patterns.d.ts +9 -0
  289. package/dist/value-patterns.d.ts.map +1 -0
  290. package/dist/value-patterns.js +17 -0
  291. package/dist/value-patterns.js.map +1 -0
  292. package/dist/value-schema.d.ts +796 -0
  293. package/dist/value-schema.d.ts.map +1 -0
  294. package/dist/value-schema.js +231 -0
  295. package/dist/value-schema.js.map +1 -0
  296. package/dist/zod-free.d.ts +60 -0
  297. package/dist/zod-free.d.ts.map +1 -0
  298. package/dist/zod-free.js +59 -0
  299. package/dist/zod-free.js.map +1 -0
  300. package/package.json +75 -3
  301. package/schema/DEPLOYED +12 -0
  302. package/schema/build-diagnostic.v1.json +63 -0
  303. package/schema/component-manifest.v1.json +1000 -0
  304. package/schema/data-api.v1.json +194 -0
  305. package/schema/library-manifest.v1.json +60 -0
  306. package/schema/published/SHA256SUMS +36 -0
  307. package/schema/published/build-diagnostic/v1.10.json +83 -0
  308. package/schema/published/build-diagnostic/v1.3.json +83 -0
  309. package/schema/published/build-diagnostic/v1.4.json +83 -0
  310. package/schema/published/build-diagnostic/v1.5.json +83 -0
  311. package/schema/published/build-diagnostic/v1.6.json +83 -0
  312. package/schema/published/build-diagnostic/v1.7.json +83 -0
  313. package/schema/published/build-diagnostic/v1.8.json +83 -0
  314. package/schema/published/build-diagnostic/v1.9.json +83 -0
  315. package/schema/published/component-manifest/v1.10.json +1443 -0
  316. package/schema/published/component-manifest/v1.3.json +1411 -0
  317. package/schema/published/component-manifest/v1.4.json +1419 -0
  318. package/schema/published/component-manifest/v1.5.json +1437 -0
  319. package/schema/published/component-manifest/v1.6.json +1437 -0
  320. package/schema/published/component-manifest/v1.7.json +1437 -0
  321. package/schema/published/component-manifest/v1.8.json +1437 -0
  322. package/schema/published/component-manifest/v1.9.json +1437 -0
  323. package/schema/published/data-api/v1.10.json +282 -0
  324. package/schema/published/data-api/v1.3.json +281 -0
  325. package/schema/published/data-api/v1.4.json +281 -0
  326. package/schema/published/data-api/v1.5.json +281 -0
  327. package/schema/published/data-api/v1.6.json +281 -0
  328. package/schema/published/data-api/v1.7.json +281 -0
  329. package/schema/published/data-api/v1.8.json +282 -0
  330. package/schema/published/data-api/v1.9.json +282 -0
  331. package/schema/published/library-manifest/v1.10.json +68 -0
  332. package/schema/published/library-manifest/v1.5.json +68 -0
  333. package/schema/published/library-manifest/v1.6.json +68 -0
  334. package/schema/published/library-manifest/v1.7.json +68 -0
  335. package/schema/published/library-manifest/v1.8.json +68 -0
  336. package/schema/published/library-manifest/v1.9.json +68 -0
  337. package/schema/published/taggor-config/v1.10.json +56 -0
  338. package/schema/published/taggor-config/v1.5.json +56 -0
  339. package/schema/published/taggor-config/v1.6.json +56 -0
  340. package/schema/published/taggor-config/v1.7.json +56 -0
  341. package/schema/published/taggor-config/v1.8.json +56 -0
  342. package/schema/published/taggor-config/v1.9.json +56 -0
  343. package/schema/taggor-config.v1.json +39 -0
@@ -0,0 +1,222 @@
1
+ /**
2
+ * Custom element tag rules of component contract v1 (TAG-201, extended by TAG-204): the tag pattern,
3
+ * the reserved names and prefix, the optional workspace tag prefix, and the explanation plus a
4
+ * valid suggestion for any refused name.
5
+ *
6
+ * The accepted set is a strict ASCII subset of the HTML "valid custom element name" (lowercase
7
+ * letters, digits and single hyphens, starting with a letter, at least one hyphen), minus the names
8
+ * the HTML spec reserves and the `taggor-` prefix. Everything here is pure: uniqueness inside a
9
+ * workspace and the workspace prefix are enforced by the API when a component is created (TAG-908);
10
+ * what the runtime does when a tag is already defined on the page is ADR 0018.
11
+ */
12
+ import * as z from "zod";
13
+ import { MANIFEST_LIMITS, WORKSPACE_LIMITS } from "./limits.js";
14
+ /**
15
+ * Names the HTML spec reserves even though they contain a hyphen (they are SVG and MathML
16
+ * elements); `customElements.define` throws for them.
17
+ */
18
+ export const RESERVED_TAG_NAMES = Object.freeze([
19
+ "annotation-xml",
20
+ "color-profile",
21
+ "font-face",
22
+ "font-face-src",
23
+ "font-face-uri",
24
+ "font-face-format",
25
+ "font-face-name",
26
+ "missing-glyph",
27
+ ]);
28
+ /** Prefix kept for elements Taggor itself defines (for example the generic tag of TAG-320). */
29
+ export const RESERVED_TAG_PREFIX = "taggor-";
30
+ /** Custom element name: ASCII subset of the HTML spec, hyphen required, deny lists applied. */
31
+ export const TAG_NAME_PATTERN = new RegExp(`^(?!${RESERVED_TAG_PREFIX})(?!(?:${RESERVED_TAG_NAMES.join("|")})$)[a-z][a-z0-9]*(?:-[a-z0-9]+)+$`);
32
+ /**
33
+ * Workspace tag prefix, written without the trailing hyphen (`acme` → tags `acme-…`): kebab-case,
34
+ * starting with a letter, and never `taggor` or `taggor-…`, which would produce reserved tags.
35
+ */
36
+ export const WORKSPACE_TAG_PREFIX_PATTERN = new RegExp(`^(?!${RESERVED_TAG_PREFIX.slice(0, -1)}(?:-|$))[a-z][a-z0-9]*(?:-[a-z0-9]+)*$`);
37
+ const PROBLEM_TEXT = Object.freeze({
38
+ empty: "it is empty",
39
+ "too-long": `it is longer than ${String(MANIFEST_LIMITS.nameMaxLength)} characters`,
40
+ "invalid-start": "it does not start with a lowercase ASCII letter",
41
+ "invalid-character": "it has characters other than lowercase ASCII letters, digits and hyphens (uppercase and non-ASCII letters are refused)",
42
+ "invalid-hyphens": "it has a hyphen at the end or two hyphens in a row",
43
+ "missing-hyphen": "it has no hyphen",
44
+ "reserved-name": "the HTML spec reserves this name",
45
+ "reserved-prefix": `the "${RESERVED_TAG_PREFIX}" prefix is reserved for Taggor's own elements`,
46
+ "missing-workspace-prefix": "it does not start with the workspace tag prefix",
47
+ });
48
+ const LENGTH_TEXT = `must be at most ${String(MANIFEST_LIMITS.nameMaxLength)} characters`;
49
+ const RULES_TEXT = `tag must be a valid custom element name: lowercase ASCII, starts with a letter, contains a hyphen, not reserved (${RESERVED_TAG_NAMES.join(", ")}) and not prefixed with "${RESERVED_TAG_PREFIX}"`;
50
+ /** Body used when nothing usable is left of the input (empty, only symbols, only non-Latin). */
51
+ const FALLBACK_BODY = "component";
52
+ /** Prefix the suggestion adds when the workspace has none (`simulator` → `x-simulator`). */
53
+ const NEUTRAL_PREFIX = "x";
54
+ /** Longest input slice the suggestion looks at; anything beyond would be cut anyway. */
55
+ const SUGGESTION_INPUT_MAX = MANIFEST_LIMITS.nameMaxLength * 4;
56
+ /** Longest echo of the refused input inside a message. */
57
+ const ECHO_MAX = MANIFEST_LIMITS.nameMaxLength + 8;
58
+ /** Placeholder shown in manifest errors, where the workspace is unknown. */
59
+ const PREFIX_PLACEHOLDER = "<workspace-prefix>";
60
+ function isReservedName(tag) {
61
+ return RESERVED_TAG_NAMES.includes(tag);
62
+ }
63
+ function assertWorkspacePrefix(prefix) {
64
+ if (prefix.length > WORKSPACE_LIMITS.tagPrefixMaxLength ||
65
+ !WORKSPACE_TAG_PREFIX_PATTERN.test(prefix)) {
66
+ throw new RangeError(`invalid workspace tag prefix ${JSON.stringify(prefix.slice(0, ECHO_MAX))}`);
67
+ }
68
+ }
69
+ /**
70
+ * Says whether a tag belongs to a workspace prefix (`acme-finance-simulator` with `acme`).
71
+ *
72
+ * Inputs: the tag and the workspace prefix (without the trailing hyphen), or `undefined` when the
73
+ * workspace has none, in which case every tag matches. Output: boolean. It does not check the rest
74
+ * of the tag rules (use `checkTagName`). Errors: none. Side effects: none.
75
+ */
76
+ export function tagMatchesWorkspacePrefix(tag, workspacePrefix) {
77
+ return workspacePrefix === undefined || tag.startsWith(`${workspacePrefix}-`);
78
+ }
79
+ /**
80
+ * Lists every rule a tag breaks, in a stable order.
81
+ *
82
+ * Inputs: the tag and, optionally, the workspace prefix (assumed valid). Output: the problems, empty
83
+ * when the tag is accepted (the result agrees with `TAG_NAME_PATTERN` plus the length limit and the
84
+ * prefix). Errors: none. Side effects: none.
85
+ */
86
+ export function tagNameProblems(tag, workspacePrefix) {
87
+ if (tag.length === 0)
88
+ return ["empty"];
89
+ const problems = [];
90
+ if (tag.length > MANIFEST_LIMITS.nameMaxLength)
91
+ problems.push("too-long");
92
+ if (!/^[a-z]/.test(tag))
93
+ problems.push("invalid-start");
94
+ if (/[^a-z0-9-]/.test(tag))
95
+ problems.push("invalid-character");
96
+ if (/-$|--/.test(tag))
97
+ problems.push("invalid-hyphens");
98
+ if (!tag.includes("-"))
99
+ problems.push("missing-hyphen");
100
+ if (isReservedName(tag))
101
+ problems.push("reserved-name");
102
+ if (tag.startsWith(RESERVED_TAG_PREFIX))
103
+ problems.push("reserved-prefix");
104
+ if (!tagMatchesWorkspacePrefix(tag, workspacePrefix))
105
+ problems.push("missing-workspace-prefix");
106
+ return problems;
107
+ }
108
+ /** Lowercase ASCII slug of any input: accents dropped, every other run of symbols becomes "-". */
109
+ function slugify(input) {
110
+ let slug = input
111
+ .slice(0, SUGGESTION_INPUT_MAX)
112
+ .toLowerCase()
113
+ .normalize("NFKD")
114
+ .replace(/\p{M}/gu, "")
115
+ .replace(/[^a-z0-9]+/g, "-")
116
+ .replace(/^-+|-+$/g, "");
117
+ while (slug.startsWith(RESERVED_TAG_PREFIX))
118
+ slug = slug.slice(RESERVED_TAG_PREFIX.length);
119
+ return slug;
120
+ }
121
+ /** Cuts a candidate to the length limit without leaving a trailing hyphen. */
122
+ function fitLength(tag) {
123
+ return tag.slice(0, MANIFEST_LIMITS.nameMaxLength).replace(/-+$/, "");
124
+ }
125
+ /**
126
+ * Turns any string into a valid tag close to it: `simulator` → `x-simulator`, `Simulação` →
127
+ * `x-simulacao`, `taggor-chat` → `x-chat`, with prefix `acme`: `simulator` → `acme-simulator`.
128
+ *
129
+ * Inputs: any string and, optionally, a workspace prefix accepted by `workspaceTagPrefixSchema`.
130
+ * Output: a tag accepted by `checkTagName(output, workspacePrefix)`; a tag that is already
131
+ * accepted comes back unchanged. Errors: throws `RangeError` when the workspace prefix itself is
132
+ * invalid (a caller bug: prefixes are validated when the workspace is saved). Side effects: none.
133
+ */
134
+ export function suggestTagName(input, workspacePrefix) {
135
+ if (workspacePrefix !== undefined)
136
+ assertWorkspacePrefix(workspacePrefix);
137
+ if (tagNameProblems(input, workspacePrefix).length === 0)
138
+ return input;
139
+ const slug = slugify(input);
140
+ if (workspacePrefix === undefined) {
141
+ const body = fitLength(slug) || FALLBACK_BODY;
142
+ const needsPrefix = !/^[a-z]/.test(body) || !body.includes("-") || isReservedName(body);
143
+ return needsPrefix ? fitLength(`${NEUTRAL_PREFIX}-${body}`) : body;
144
+ }
145
+ const head = `${workspacePrefix}-`;
146
+ const body = (slug.startsWith(head) ? slug.slice(head.length) : slug) || FALLBACK_BODY;
147
+ const tag = fitLength(head + body);
148
+ // A prefix such as `font` can rebuild a reserved name (`font-face`); push it out of the list.
149
+ return isReservedName(tag) ? fitLength(`${head}${NEUTRAL_PREFIX}-${body}`) : tag;
150
+ }
151
+ function echo(input) {
152
+ const cut = input.length > ECHO_MAX ? `${input.slice(0, ECHO_MAX)}…` : input;
153
+ return JSON.stringify(cut);
154
+ }
155
+ /**
156
+ * Builds the English message for a refused tag: the rules, what is wrong, and a valid suggestion.
157
+ * Without a workspace prefix it also shows the prefixed form with a placeholder.
158
+ */
159
+ function refusalMessage(tag, problems, workspacePrefix) {
160
+ const suggestion = suggestTagName(tag, workspacePrefix);
161
+ const why = problems.map((problem) => PROBLEM_TEXT[problem]).join("; ");
162
+ const rules = workspacePrefix === undefined
163
+ ? RULES_TEXT
164
+ : `${RULES_TEXT}, and must start with "${workspacePrefix}-"`;
165
+ let hint = `Try ${JSON.stringify(suggestion)}`;
166
+ if (workspacePrefix === undefined) {
167
+ // Same suggestion logic, with a stand-in prefix swapped for the placeholder afterwards.
168
+ const prefixed = suggestTagName(tag, NEUTRAL_PREFIX).slice(NEUTRAL_PREFIX.length);
169
+ hint += `, or "${PREFIX_PLACEHOLDER}${prefixed}" if your workspace sets a tag prefix`;
170
+ }
171
+ const message = `${rules}; ${echo(tag)}: ${why}. ${hint}`;
172
+ // Keeps the length error's historical lead (TAG-201), which clients may already match on.
173
+ const lead = problems.includes("too-long") ? `${LENGTH_TEXT}. ` : "";
174
+ return { message: lead + message, suggestion };
175
+ }
176
+ /**
177
+ * Checks a tag against every rule, including the workspace prefix when there is one. This is the
178
+ * check the API runs when a component is created (TAG-908, `invalid_tag_name` with the message in
179
+ * `detail`); uniqueness inside the workspace needs storage and stays in the API.
180
+ *
181
+ * Inputs: the tag and, optionally, a workspace prefix accepted by `workspaceTagPrefixSchema`.
182
+ * Output: `{ ok: true }`, or the problems, an English message and a suggestion that passes this
183
+ * same check. Errors: throws `RangeError` only for an invalid workspace prefix. Side effects: none.
184
+ */
185
+ export function checkTagName(tag, workspacePrefix) {
186
+ if (workspacePrefix !== undefined)
187
+ assertWorkspacePrefix(workspacePrefix);
188
+ const problems = tagNameProblems(tag, workspacePrefix);
189
+ if (problems.length === 0)
190
+ return { ok: true };
191
+ return { ok: false, problems, ...refusalMessage(tag, problems, workspacePrefix) };
192
+ }
193
+ /** Zod message for a refused manifest tag (no workspace is known at that point). */
194
+ function manifestTagError(issue) {
195
+ const tag = typeof issue.input === "string" ? issue.input : "";
196
+ return refusalMessage(tag, tagNameProblems(tag), undefined).message;
197
+ }
198
+ /**
199
+ * Custom element tag of a manifest. Workspace prefixes are checked by the API (TAG-908), not here:
200
+ * the same manifest serves several workspaces (templates). The error message says what is wrong and
201
+ * suggests a valid tag.
202
+ */
203
+ export const tagNameSchema = z
204
+ .string()
205
+ // `abort` keeps one issue per tag: the message already lists every problem.
206
+ .min(1, { error: manifestTagError, abort: true })
207
+ .max(MANIFEST_LIMITS.nameMaxLength, { error: manifestTagError, abort: true })
208
+ .regex(TAG_NAME_PATTERN, { error: manifestTagError })
209
+ .meta({ id: "TagName" });
210
+ /**
211
+ * Optional tag prefix of a workspace (`acme`, so tags look like `acme-finance-simulator`). Saved
212
+ * with the workspace settings by the API; the manifest never carries it.
213
+ */
214
+ export const workspaceTagPrefixSchema = z
215
+ .string()
216
+ .min(1)
217
+ .max(WORKSPACE_LIMITS.tagPrefixMaxLength)
218
+ .regex(WORKSPACE_TAG_PREFIX_PATTERN, {
219
+ error: `workspace tag prefix must be kebab-case (lowercase ASCII letters and digits separated by single hyphens, starting with a letter), written without the trailing hyphen, and must not be "taggor" or start with "${RESERVED_TAG_PREFIX}"`,
220
+ })
221
+ .meta({ id: "WorkspaceTagPrefix" });
222
+ //# sourceMappingURL=tag-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tag-name.js","sourceRoot":"","sources":["../src/tag-name.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEhE;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9C,gBAAgB;IAChB,eAAe;IACf,WAAW;IACX,eAAe;IACf,eAAe;IACf,kBAAkB;IAClB,gBAAgB;IAChB,eAAe;CACP,CAAC,CAAC;AAEZ,+FAA+F;A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,0 +1,74 @@
1
+ /**
2
+ * One archive entry; `type` is the tar typeflag (`0` file, `2` symlink, `5` directory, `x` pax
3
+ * header whose `content` is the raw pax body, …).
4
+ */
5
+ export interface TarEntry {
6
+ readonly path: string;
7
+ readonly content?: string | Uint8Array;
8
+ readonly type?: string;
9
+ readonly linkTarget?: string;
10
+ }
11
+ /** A header field: text or raw bytes, written from the field's start and cut to its length. */
12
+ export type TarField = string | Uint8Array;
13
+ /**
14
+ * The fields of one tar header, for tests that need a header no writer produces (a size field
15
+ * with a leading `\v`, a GNU magic, a prefix, a wrong checksum). Numbers are written as POSIX
16
+ * does (zero-padded octal and a NUL); text and bytes are written as given, NUL-padded.
17
+ */
18
+ export interface TarHeaderFields {
19
+ readonly name: TarField;
20
+ readonly mode?: number | TarField;
21
+ readonly uid?: number | TarField;
22
+ readonly gid?: number | TarField;
23
+ readonly size: number | TarField;
24
+ readonly mtime?: number | TarField;
25
+ /** The typeflag, one character (`0` file, `5` directory, `x` pax header…). */
26
+ readonly type: string;
27
+ readonly linkname?: TarField;
28
+ /** The eight bytes at offset 257: magic and version (default POSIX `ustar\0` + `00`). */
29
+ readonly magic?: TarField;
30
+ readonly uname?: TarField;
31
+ readonly gname?: TarField;
32
+ readonly prefix?: TarField;
33
+ /**
34
+ * The checksum field from the sum of the header's bytes (with the field as eight spaces);
35
+ * default: six octal digits, NUL and space, as POSIX writes it.
36
+ */
37
+ readonly checksum?: (sum: number) => TarField;
38
+ }
39
+ /**
40
+ * Writes one 512-byte tar header.
41
+ *
42
+ * Inputs: the fields (mode 0644, uid, gid and mtime 0, POSIX magic and checksum by default).
43
+ * Output: the header block. Errors: none. Side effects: none.
44
+ */
45
+ export declare function tarHeader(fields: TarHeaderFields): Uint8Array;
46
+ /**
47
+ * One pax record with its length in bytes, as POSIX defines it. Key and value may be raw bytes,
48
+ * for records no writer would produce (a BOM before the key, a value that is not UTF-8).
49
+ */
50
+ export declare function paxRecord(key: string | Uint8Array, value: string | Uint8Array): Uint8Array;
51
+ /** The parts joined into one array. */
52
+ export declare function concat(parts: readonly Uint8Array[]): Uint8Array;
53
+ /**
54
+ * Rewrites the checksum of the header at `offset` after a test edited it, so the reader judges
55
+ * the edit and not a bad checksum.
56
+ *
57
+ * Inputs: the archive (changed in place) and the header's byte offset. Side effects: writes the
58
+ * eight checksum bytes.
59
+ */
60
+ export declare function resealHeader(archive: Uint8Array, offset?: number): void;
61
+ /** The archive without its two closing zero blocks, to be embedded or concatenated. */
62
+ export declare function withoutEnd(archive: Uint8Array): Uint8Array;
63
+ /** A pax extended header (`x`) block with the given records, already padded. */
64
+ export declare function paxHeader(records: readonly (readonly [string, string])[] | Uint8Array): Uint8Array[];
65
+ /**
66
+ * Writes a tar archive.
67
+ *
68
+ * Inputs: the entries; a path over 100 bytes is written with a pax `path` record first. Output:
69
+ * the archive bytes, ending with two zero blocks. Errors: none. Side effects: none.
70
+ */
71
+ export declare function tarArchive(entries: readonly TarEntry[]): Uint8Array;
72
+ /** Shorthand: a regular file entry per `[path, content]` pair. */
73
+ export declare function sourceArchive(files: Readonly<Record<string, string>>): Uint8Array;
74
+ //# sourceMappingURL=tar-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tar-writer.d.ts","sourceRoot":"","sources":["../src/tar-writer.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IACvC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAYD,+FAA+F;AAC/F,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;AAE3C;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAA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CACvB,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,GAAG,UAAU,GAC3D,UAAU,EAAE,CAYd;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,GAAG,UAAU,CAuBnE;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,UAAU,CAEjF"}
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Tar writer for tests (TAG-401 as a test builder; moved to the contract by TAG-407): writes POSIX
3
+ * tar archives, so tests of the archive reader, the package validator, the builder's container
4
+ * and the API's upload use case can describe a source package as a list of entries, hostile ones
5
+ * included (symlinks, `..`, absolute paths, pax long names).
6
+ *
7
+ * A regular module, not a `*.builders.ts`, because it ships in the `@taggor/contract/testing`
8
+ * entry that the tests of other workspaces import; production code never imports that entry.
9
+ */
10
+ import { utf8Encoder } from "./text-codec.js";
11
+ const encoder = utf8Encoder;
12
+ function writeField(header, offset, length, value) {
13
+ header.set(encoder.encode(value).subarray(0, length), offset);
14
+ }
15
+ function writeOctal(header, offset, length, value) {
16
+ writeField(header, offset, length, `${value.toString(8).padStart(length - 1, "0")}\0`);
17
+ }
18
+ function writeRaw(header, offset, length, value) {
19
+ if (typeof value === "string")
20
+ writeField(header, offset, length, value);
21
+ else
22
+ header.set(value.subarray(0, length), offset);
23
+ }
24
+ function writeNumber(header, offset, length, value) {
25
+ if (typeof value === "number")
26
+ writeOctal(header, offset, length, value);
27
+ else
28
+ writeRaw(header, offset, length, value);
29
+ }
30
+ const POSIX_CHECKSUM = (sum) => `${sum.toString(8).padStart(6, "0")}\0 `;
31
+ /**
32
+ * Writes one 512-byte tar header.
33
+ *
34
+ * Inputs: the fields (mode 0644, uid, gid and mtime 0, POSIX magic and checksum by default).
35
+ * Output: the header block. Errors: none. Side effects: none.
36
+ */
37
+ export function tarHeader(fields) {
38
+ const header = new Uint8Array(512);
39
+ writeRaw(header, 0, 100, fields.name);
40
+ writeNumber(header, 100, 8, fields.mode ?? 0o644);
41
+ writeNumber(header, 108, 8, fields.uid ?? 0);
42
+ writeNumber(header, 116, 8, fields.gid ?? 0);
43
+ writeNumber(header, 124, 12, fields.size);
44
+ writeNumber(header, 136, 12, fields.mtime ?? 0);
45
+ header.fill(32, 148, 156);
46
+ header[156] = fields.type.charCodeAt(0);
47
+ writeRaw(header, 157, 100, fields.linkname ?? "");
48
+ writeRaw(header, 257, 8, fields.magic ?? "ustar\u000000");
49
+ writeRaw(header, 265, 32, fields.uname ?? "");
50
+ writeRaw(header, 297, 32, fields.gname ?? "");
51
+ writeRaw(header, 345, 155, fields.prefix ?? "");
52
+ const sum = header.reduce((total, byte) => total + byte, 0);
53
+ writeRaw(header, 148, 8, (fields.checksum ?? POSIX_CHECKSUM)(sum));
54
+ return header;
55
+ }
56
+ function headerBlock(path, size, type, linkTarget = "") {
57
+ return tarHeader({ name: path, size, type, linkname: linkTarget });
58
+ }
59
+ function padded(bytes) {
60
+ const out = new Uint8Array(Math.ceil(bytes.length / 512) * 512);
61
+ out.set(bytes);
62
+ return out;
63
+ }
64
+ /**
65
+ * One pax record with its length in bytes, as POSIX defines it. Key and value may be raw bytes,
66
+ * for records no writer would produce (a BOM before the key, a value that is not UTF-8).
67
+ */
68
+ export function paxRecord(key, value) {
69
+ const bytes = (part) => typeof part === "string" ? encoder.encode(part) : part;
70
+ const body = concat([encoder.encode(" "), bytes(key), encoder.encode("="), bytes(value)]);
71
+ // The length counts its own digits, the body and the final newline.
72
+ let length = body.length + 2;
73
+ while (String(length).length + body.length + 1 !== length)
74
+ length += 1;
75
+ return concat([encoder.encode(String(length)), body, encoder.encode("\n")]);
76
+ }
77
+ /** The parts joined into one array. */
78
+ export function concat(parts) {
79
+ const out = new Uint8Array(parts.reduce((sum, part) => sum + part.length, 0));
80
+ let offset = 0;
81
+ for (const part of parts) {
82
+ out.set(part, offset);
83
+ offset += part.length;
84
+ }
85
+ return out;
86
+ }
87
+ /**
88
+ * Rewrites the checksum of the header at `offset` after a test edited it, so the reader judges
89
+ * the edit and not a bad checksum.
90
+ *
91
+ * Inputs: the archive (changed in place) and the header's byte offset. Side effects: writes the
92
+ * eight checksum bytes.
93
+ */
94
+ export function resealHeader(archive, offset = 0) {
95
+ const header = archive.subarray(offset, offset + 512);
96
+ header.fill(32, 148, 156);
97
+ const sum = header.reduce((total, byte) => total + byte, 0);
98
+ header.set(encoder.encode(POSIX_CHECKSUM(sum)), 148);
99
+ }
100
+ /** The archive without its two closing zero blocks, to be embedded or concatenated. */
101
+ export function withoutEnd(archive) {
102
+ return archive.subarray(0, archive.length - 1024);
103
+ }
104
+ /** A pax extended header (`x`) block with the given records, already padded. */
105
+ export function paxHeader(records) {
106
+ const parts = records instanceof Uint8Array
107
+ ? [records]
108
+ : records.map(([key, value]) => paxRecord(key, value));
109
+ const body = new Uint8Array(parts.reduce((sum, part) => sum + part.length, 0));
110
+ let offset = 0;
111
+ for (const part of parts) {
112
+ body.set(part, offset);
113
+ offset += part.length;
114
+ }
115
+ return [headerBlock("PaxHeader", body.length, "x"), padded(body)];
116
+ }
117
+ /**
118
+ * Writes a tar archive.
119
+ *
120
+ * Inputs: the entries; a path over 100 bytes is written with a pax `path` record first. Output:
121
+ * the archive bytes, ending with two zero blocks. Errors: none. Side effects: none.
122
+ */
123
+ export function tarArchive(entries) {
124
+ const blocks = [];
125
+ for (const entry of entries) {
126
+ const content = typeof entry.content === "string"
127
+ ? encoder.encode(entry.content)
128
+ : (entry.content ?? new Uint8Array());
129
+ if (encoder.encode(entry.path).length > 100)
130
+ blocks.push(...paxHeader([["path", entry.path]]));
131
+ const shortPath = encoder.encode(entry.path).length > 100 ? "long-name-in-pax" : entry.path;
132
+ blocks.push(headerBlock(shortPath, content.length, entry.type ?? "0", entry.linkTarget), padded(content));
133
+ }
134
+ blocks.push(new Uint8Array(1024));
135
+ const total = blocks.reduce((sum, block) => sum + block.length, 0);
136
+ const out = new Uint8Array(total);
137
+ let offset = 0;
138
+ for (const block of blocks) {
139
+ out.set(block, offset);
140
+ offset += block.length;
141
+ }
142
+ return out;
143
+ }
144
+ /** Shorthand: a regular file entry per `[path, content]` pair. */
145
+ export function sourceArchive(files) {
146
+ return tarArchive(Object.entries(files).map(([path, content]) => ({ path, content })));
147
+ }
148
+ //# sourceMappingURL=tar-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tar-writer.js","sourceRoot":"","sources":["../src/tar-writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAa9C,MAAM,OAAO,GAAG,WAAW,CAAC;AAE5B,SAAS,UAAU,CAAC,MAAkB,EAAE,MAAc,EAAE,MAAc,EAAE,KAAa;IACnF,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,UAAU,CAAC,MAAkB,EAAE,MAAc,EAAE,MAAc,EAAE,KAAa;IACnF,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;AACzF,CAAC;AAgCD,SAAS,QAAQ,CAAC,MAAkB,EAAE,MAAc,EAAE,MAAc,EAAE,KAAe;IACnF,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;;QACpE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;AACrD,C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M,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACnE,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;IACzB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,aAAa,CAAC,KAAuC;IACnE,OAAO,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;AACzF,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@taggor/contract/testing` (TAG-407): test data builders for the contract's formats, shared by
3
+ * the tests of the contract, the builder and the API. Never imported by production code.
4
+ *
5
+ * Today: POSIX tar archives (`tarArchive`, `sourceArchive`, pax records), so a test can describe
6
+ * a source package, hostile entries included, as a list of entries; and the hostile source
7
+ * package corpus (`hostileSourcePackages`) with a valid package to compare against.
8
+ */
9
+ export { concat, paxHeader, paxRecord, resealHeader, sourceArchive, tarArchive, tarHeader, withoutEnd, type TarEntry, type TarField, type TarHeaderFields, } from "./tar-writer.js";
10
+ export { VALID_ENTRY, folderFlood, hostileGzipStreams, hostileSourcePackages, validSourcePackage, type HostileGzipStream, type HostileSourcePackage, } from "./source-package-corpus.js";
11
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,MAAM,EACN,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACb,UAAU,EACV,SAAS,EACT,UAAU,EACV,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,eAAe,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,GAC1B,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@taggor/contract/testing` (TAG-407): test data builders for the contract's formats, shared by
3
+ * the tests of the contract, the builder and the API. Never imported by production code.
4
+ *
5
+ * Today: POSIX tar archives (`tarArchive`, `sourceArchive`, pax records), so a test can describe
6
+ * a source package, hostile entries included, as a list of entries; and the hostile source
7
+ * package corpus (`hostileSourcePackages`) with a valid package to compare against.
8
+ */
9
+ export { concat, paxHeader, paxRecord, resealHeader, sourceArchive, tarArchive, tarHeader, withoutEnd, } from "./tar-writer.js";
10
+ export { VALID_ENTRY, folderFlood, hostileGzipStreams, hostileSourcePackages, validSourcePackage, } from "./source-package-corpus.js";
11
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,MAAM,EACN,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACb,UAAU,EACV,SAAS,EACT,UAAU,GAIX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,GAGnB,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Text encoding for the source package reader (TAG-407), typed without the DOM library.
3
+ *
4
+ * `TextDecoder` and `TextEncoder` exist in every place the contract runs (Workers, Node,
5
+ * browsers), but the contract builds against plain ES2023 (`types: []`, no DOM), so they are read
6
+ * from `globalThis` through the few members used here instead of declaring the globals, which
7
+ * would clash with the DOM and Node types of the workspaces that also see them.
8
+ *
9
+ * Pure: decoders keep no state between calls (`decode` without `stream`).
10
+ */
11
+ /** The decoding the reader uses. */
12
+ interface Decoder {
13
+ /** Inputs: bytes. Output: the text. Errors: `TypeError` for invalid input when `fatal`. */
14
+ decode(input: Uint8Array): string;
15
+ }
16
+ /** The encoding the test builders use. */
17
+ interface Encoder {
18
+ /** Inputs: text. Output: its UTF-8 bytes. Errors: none. */
19
+ encode(input: string): Uint8Array;
20
+ }
21
+ /**
22
+ * Strict UTF-8: `decode` throws `TypeError` on any invalid sequence, so a file or name that is not
23
+ * UTF-8 is refused instead of being read with U+FFFD in it. A leading BOM is dropped.
24
+ */
25
+ export declare const strictUtf8: Decoder;
26
+ /**
27
+ * Strict UTF-8 that keeps a leading U+FEFF, for tar names and pax keys and values: a dropped BOM
28
+ * would make this reader see another name than bsdtar (TAG-407 security review, M1).
29
+ */
30
+ export declare const strictUtf8KeepingBom: Decoder;
31
+ /** Latin-1: one character per byte, never throws (tar's numeric fields). */
32
+ export declare const latin1: Decoder;
33
+ /** UTF-8 encoder. */
34
+ export declare const utf8Encoder: Encoder;
35
+ export {};
36
+ //# sourceMappingURL=text-codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-codec.d.ts","sourceRoot":"","sources":["../src/text-codec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,oCAAoC;AACpC,UAAU,OAAO;IACf,2FAA2F;IAC3F,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC;CACnC;AAED,0CAA0C;AAC1C,UAAU,OAAO;IACf,2DAA2D;IAC3D,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;CACnC;AAYD;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,OAGvB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,OAGjC,CAAC;AAEH,4EAA4E;AAC5E,eAAO,MAAM,MAAM,EAAE,OAA0C,CAAC;AAEhE,qBAAqB;AACrB,eAAO,MAAM,WAAW,EAAE,OAAkC,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Text encoding for the source package reader (TAG-407), typed without the DOM library.
3
+ *
4
+ * `TextDecoder` and `TextEncoder` exist in every place the contract runs (Workers, Node,
5
+ * browsers), but the contract builds against plain ES2023 (`types: []`, no DOM), so they are read
6
+ * from `globalThis` through the few members used here instead of declaring the globals, which
7
+ * would clash with the DOM and Node types of the workspaces that also see them.
8
+ *
9
+ * Pure: decoders keep no state between calls (`decode` without `stream`).
10
+ */
11
+ const codecs = globalThis;
12
+ /**
13
+ * Strict UTF-8: `decode` throws `TypeError` on any invalid sequence, so a file or name that is not
14
+ * UTF-8 is refused instead of being read with U+FFFD in it. A leading BOM is dropped.
15
+ */
16
+ export const strictUtf8 = new codecs.TextDecoder("utf-8", {
17
+ fatal: true,
18
+ ignoreBOM: false,
19
+ });
20
+ /**
21
+ * Strict UTF-8 that keeps a leading U+FEFF, for tar names and pax keys and values: a dropped BOM
22
+ * would make this reader see another name than bsdtar (TAG-407 security review, M1).
23
+ */
24
+ export const strictUtf8KeepingBom = new codecs.TextDecoder("utf-8", {
25
+ fatal: true,
26
+ ignoreBOM: true,
27
+ });
28
+ /** Latin-1: one character per byte, never throws (tar's numeric fields). */
29
+ export const latin1 = new codecs.TextDecoder("latin1");
30
+ /** UTF-8 encoder. */
31
+ export const utf8Encoder = new codecs.TextEncoder();
32
+ //# sourceMappingURL=text-codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-codec.js","sourceRoot":"","sources":["../src/text-codec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAsBH,MAAM,MAAM,GAAG,UAA+B,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAY,IAAI,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;IACjE,KAAK,EAAE,IAAI;IACX,SAAS,EAAE,KAAK;CACjB,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAY,IAAI,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;IAC3E,KAAK,EAAE,IAAI;IACX,SAAS,EAAE,IAAI;CAChB,CAAC,CAAC;AAEH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,MAAM,GAAY,IAAI,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AAEhE,qBAAqB;AACrB,MAAM,CAAC,MAAM,WAAW,GAAY,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC"}
@@ -0,0 +1,41 @@
1
+ /** URL schemes a `url` prop may accept; `javascript:`, `data:` and the rest are impossible. */
2
+ export declare const URL_PROTOCOLS: readonly ["https", "http", "mailto"];
3
+ /** A URL scheme a `url` prop may accept. */
4
+ export type UrlProtocol = (typeof URL_PROTOCOLS)[number];
5
+ /** Schemes a `url` prop accepts when it declares none. */
6
+ export declare const DEFAULT_URL_PROTOCOLS: readonly UrlProtocol[];
7
+ /** Schemes of the `url` string format in value schemas (event details, collection fields). */
8
+ export declare const WEB_URL_PROTOCOLS: readonly UrlProtocol[];
9
+ /**
10
+ * Builds the text rule of a URL that uses one of `protocols`.
11
+ *
12
+ * Inputs: schemes from `URL_PROTOCOLS` (never manifest text). Output: an anchored pattern without
13
+ * flags. Errors: none. Side effects: none.
14
+ */
15
+ export declare function urlPattern(protocols: readonly UrlProtocol[]): RegExp;
16
+ /**
17
+ * The structural rule of any `url` prop default, whatever its `protocols`: the JSON Schema checks
18
+ * it, so a `javascript:` default is refused even by consumers that skip the Zod-only rules.
19
+ */
20
+ export declare const URL_VALUE_PATTERN: RegExp;
21
+ /**
22
+ * Tells whether a text is an acceptable URL for one of `protocols`.
23
+ *
24
+ * Inputs: any value and the accepted schemes; entries that are not in `URL_PROTOCOLS` (a newer
25
+ * contract's scheme, a hand-made manifest) are ignored, so they deny instead of widening. Output:
26
+ * `true` only for a string of at most `MANIFEST_LIMITS.urlMaxLength` characters that matches
27
+ * `urlPattern` of the known schemes, that the WHATWG URL parser accepts with that same scheme and
28
+ * that has no userinfo (`http`, `https`) or is a single address with only `subject`/`body`
29
+ * (`mailto`). Errors: none (parser errors mean `false`). Side effects: none.
30
+ */
31
+ export declare function isAllowedUrl(text: unknown, protocols: readonly UrlProtocol[]): text is string;
32
+ /**
33
+ * `isAllowedUrl(text, WEB_URL_PROTOCOLS)` without the `mailto:` rule, which it can never need: the
34
+ * `url` string format of value schemas uses it, so a bundle that only checks values (the SDK's
35
+ * `track`, TAG-203) leaves the `mailto:` code out (size budget of TAG-202, TAG-303).
36
+ *
37
+ * Inputs: any value. Output: `true` only for an `https://` or `http://` URL that `isAllowedUrl`
38
+ * accepts with those schemes. Errors: none. Side effects: none.
39
+ */
40
+ export declare function isAllowedWebUrl(text: unknown): text is string;
41
+ //# sourceMappingURL=url-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-value.d.ts","sourceRoot":"","sources":["../src/url-value.ts"],"names":[],"mappings":"AA0BA,+FAA+F;AAC/F,eAAO,MAAM,aAAa,sCAAsD,CAAC;AACjF,4CAA4C;AAC5C,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,0DAA0D;AAC1D,eAAO,MAAM,qBAAqB,EAAE,SAAS,WAAW,EAA6B,CAAC;AACtF,8FAA8F;AAC9F,eAAO,MAAM,iBAAiB,EAAE,SAAS,WAAW,EAAqC,CAAC;AAY1F;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,CAEpE;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAA4B,CAAC;AA8E3D;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,IAAI,MAAM,CAM7F;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAG7D"}