@prestack/thread 0.0.1

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 (248) hide show
  1. package/CHANGELOG.md +192 -0
  2. package/dist/attach.d.ts +1 -0
  3. package/dist/attach.js +1 -0
  4. package/dist/core/actor.d.ts +12 -0
  5. package/dist/core/actor.js +8 -0
  6. package/dist/core/asking.d.ts +180 -0
  7. package/dist/core/asking.js +1109 -0
  8. package/dist/core/attach.d.ts +54 -0
  9. package/dist/core/attach.js +510 -0
  10. package/dist/core/chain.d.ts +16 -0
  11. package/dist/core/chain.js +114 -0
  12. package/dist/core/cli.d.ts +2 -0
  13. package/dist/core/cli.js +1682 -0
  14. package/dist/core/condition.d.ts +52 -0
  15. package/dist/core/condition.js +198 -0
  16. package/dist/core/descend.d.ts +81 -0
  17. package/dist/core/descend.js +879 -0
  18. package/dist/core/finding.d.ts +12 -0
  19. package/dist/core/finding.js +23 -0
  20. package/dist/core/generators/meta.d.ts +2 -0
  21. package/dist/core/generators/meta.js +823 -0
  22. package/dist/core/init.d.ts +15 -0
  23. package/dist/core/init.js +134 -0
  24. package/dist/core/invoked.d.ts +9 -0
  25. package/dist/core/invoked.js +41 -0
  26. package/dist/core/round.d.ts +1 -0
  27. package/dist/core/round.js +57 -0
  28. package/dist/core/rows.d.ts +26 -0
  29. package/dist/core/rows.js +354 -0
  30. package/dist/core/scope.d.ts +6 -0
  31. package/dist/core/scope.js +12 -0
  32. package/dist/core/thread.d.ts +26 -0
  33. package/dist/core/thread.js +5 -0
  34. package/dist/core/tree.d.ts +12 -0
  35. package/dist/core/tree.js +56 -0
  36. package/dist/core/types.d.ts +49 -0
  37. package/dist/core/types.js +311 -0
  38. package/dist/derivation/attach.d.ts +2 -0
  39. package/dist/derivation/attach.js +61 -0
  40. package/dist/derivation/generators/build.d.ts +16 -0
  41. package/dist/derivation/generators/build.js +217 -0
  42. package/dist/derivation/generators/check.d.ts +18 -0
  43. package/dist/derivation/generators/check.js +78 -0
  44. package/dist/derivation/generators/derivation.d.ts +3 -0
  45. package/dist/derivation/generators/derivation.js +273 -0
  46. package/dist/derivation/generators/determinism.d.ts +20 -0
  47. package/dist/derivation/generators/determinism.js +110 -0
  48. package/dist/derivation/generators/release.d.ts +3 -0
  49. package/dist/derivation/generators/release.js +183 -0
  50. package/dist/derivation/makers/release.d.ts +1 -0
  51. package/dist/derivation/makers/release.js +107 -0
  52. package/dist/derivation/release.d.ts +10 -0
  53. package/dist/derivation/release.js +12 -0
  54. package/dist/integrations/attach.d.ts +6 -0
  55. package/dist/integrations/attach.js +177 -0
  56. package/dist/integrations/generators/read.d.ts +1 -0
  57. package/dist/integrations/generators/read.js +92 -0
  58. package/dist/integrations/generators/sdk.d.ts +1 -0
  59. package/dist/integrations/generators/sdk.js +148 -0
  60. package/dist/integrations/generators/secret.d.ts +1 -0
  61. package/dist/integrations/generators/secret.js +233 -0
  62. package/dist/integrations/generators/target.d.ts +1 -0
  63. package/dist/integrations/generators/target.js +765 -0
  64. package/dist/integrations/generators/vault.d.ts +1 -0
  65. package/dist/integrations/generators/vault.js +164 -0
  66. package/dist/integrations/sdk.d.ts +6 -0
  67. package/dist/integrations/sdk.js +151 -0
  68. package/dist/integrations/secret.d.ts +16 -0
  69. package/dist/integrations/secret.js +30 -0
  70. package/dist/integrations/target.d.ts +49 -0
  71. package/dist/integrations/target.js +225 -0
  72. package/dist/integrations/vault.d.ts +12 -0
  73. package/dist/integrations/vault.js +104 -0
  74. package/dist/integrity/attach.d.ts +2 -0
  75. package/dist/integrity/attach.js +213 -0
  76. package/dist/integrity/check-threads.d.ts +10 -0
  77. package/dist/integrity/check-threads.js +153 -0
  78. package/dist/integrity/constraint.d.ts +16 -0
  79. package/dist/integrity/constraint.js +1105 -0
  80. package/dist/integrity/generators/compiler.d.ts +1 -0
  81. package/dist/integrity/generators/compiler.js +130 -0
  82. package/dist/integrity/generators/gate.d.ts +1 -0
  83. package/dist/integrity/generators/gate.js +172 -0
  84. package/dist/integrity/generators/issues.d.ts +1 -0
  85. package/dist/integrity/generators/issues.js +100 -0
  86. package/dist/integrity/generators/publish.d.ts +1 -0
  87. package/dist/integrity/generators/publish.js +186 -0
  88. package/dist/integrity/generators/rule.d.ts +2 -0
  89. package/dist/integrity/generators/rule.js +213 -0
  90. package/dist/integrity/generators/seal.d.ts +4 -0
  91. package/dist/integrity/generators/seal.js +101 -0
  92. package/dist/integrity/generators/trial.d.ts +39 -0
  93. package/dist/integrity/generators/trial.js +254 -0
  94. package/dist/integrity/lint.d.ts +50 -0
  95. package/dist/integrity/lint.js +161 -0
  96. package/dist/integrity/lsp/bin.d.ts +2 -0
  97. package/dist/integrity/lsp/bin.js +35 -0
  98. package/dist/integrity/lsp/diagnostics.d.ts +25 -0
  99. package/dist/integrity/lsp/diagnostics.js +57 -0
  100. package/dist/integrity/lsp/findings.d.ts +20 -0
  101. package/dist/integrity/lsp/findings.js +39 -0
  102. package/dist/integrity/lsp/lint.d.ts +7 -0
  103. package/dist/integrity/lsp/lint.js +95 -0
  104. package/dist/integrity/lsp/protocol.d.ts +20 -0
  105. package/dist/integrity/lsp/protocol.js +57 -0
  106. package/dist/integrity/lsp/server.d.ts +15 -0
  107. package/dist/integrity/lsp/server.js +171 -0
  108. package/dist/integrity/sealed.d.ts +1 -0
  109. package/dist/integrity/sealed.js +56 -0
  110. package/dist/integrity/slopnator.d.ts +90 -0
  111. package/dist/integrity/slopnator.js +267 -0
  112. package/dist/integrity/slopnators/sl_broken_lineage.d.ts +2 -0
  113. package/dist/integrity/slopnators/sl_broken_lineage.js +35 -0
  114. package/dist/integrity/slopnators/sl_declared_elsewhere.d.ts +2 -0
  115. package/dist/integrity/slopnators/sl_declared_elsewhere.js +33 -0
  116. package/dist/integrity/slopnators/sl_derived_drift.d.ts +8 -0
  117. package/dist/integrity/slopnators/sl_derived_drift.js +91 -0
  118. package/dist/integrity/slopnators/sl_hardcoded_style.d.ts +2 -0
  119. package/dist/integrity/slopnators/sl_hardcoded_style.js +46 -0
  120. package/dist/integrity/slopnators/sl_inert_island.d.ts +2 -0
  121. package/dist/integrity/slopnators/sl_inert_island.js +85 -0
  122. package/dist/integrity/slopnators/sl_inert_slopnator.d.ts +2 -0
  123. package/dist/integrity/slopnators/sl_inert_slopnator.js +76 -0
  124. package/dist/integrity/slopnators/sl_missing_row.d.ts +2 -0
  125. package/dist/integrity/slopnators/sl_missing_row.js +180 -0
  126. package/dist/integrity/slopnators/sl_no_barrel.d.ts +2 -0
  127. package/dist/integrity/slopnators/sl_no_barrel.js +41 -0
  128. package/dist/integrity/slopnators/sl_no_child_process.d.ts +2 -0
  129. package/dist/integrity/slopnators/sl_no_child_process.js +61 -0
  130. package/dist/integrity/slopnators/sl_no_comment.d.ts +2 -0
  131. package/dist/integrity/slopnators/sl_no_comment.js +41 -0
  132. package/dist/integrity/slopnators/sl_no_dispatch_bypass.d.ts +2 -0
  133. package/dist/integrity/slopnators/sl_no_dispatch_bypass.js +301 -0
  134. package/dist/integrity/slopnators/sl_no_import_cycle.d.ts +2 -0
  135. package/dist/integrity/slopnators/sl_no_import_cycle.js +42 -0
  136. package/dist/integrity/slopnators/sl_no_such_command.d.ts +2 -0
  137. package/dist/integrity/slopnators/sl_no_such_command.js +55 -0
  138. package/dist/integrity/slopnators/sl_only_takes_a_literal.d.ts +2 -0
  139. package/dist/integrity/slopnators/sl_only_takes_a_literal.js +59 -0
  140. package/dist/integrity/slopnators/sl_secret_literal.d.ts +2 -0
  141. package/dist/integrity/slopnators/sl_secret_literal.js +89 -0
  142. package/dist/integrity/slopnators/sl_stale_path.d.ts +2 -0
  143. package/dist/integrity/slopnators/sl_stale_path.js +92 -0
  144. package/dist/integrity/slopnators/sl_twice_meant.d.ts +2 -0
  145. package/dist/integrity/slopnators/sl_twice_meant.js +30 -0
  146. package/dist/integrity/slopnators/sl_twice_parented.d.ts +2 -0
  147. package/dist/integrity/slopnators/sl_twice_parented.js +34 -0
  148. package/dist/integrity/slopnators/sl_undeclared_crossing.d.ts +2 -0
  149. package/dist/integrity/slopnators/sl_undeclared_crossing.js +78 -0
  150. package/dist/integrity/slopnators/sl_undeclared_destination.d.ts +2 -0
  151. package/dist/integrity/slopnators/sl_undeclared_destination.js +56 -0
  152. package/dist/integrity/slopnators/sl_undeclared_element.d.ts +2 -0
  153. package/dist/integrity/slopnators/sl_undeclared_element.js +34 -0
  154. package/dist/integrity/slopnators/sl_undeclared_node.d.ts +2 -0
  155. package/dist/integrity/slopnators/sl_undeclared_node.js +59 -0
  156. package/dist/integrity/slopnators/sl_undeclared_operation.d.ts +2 -0
  157. package/dist/integrity/slopnators/sl_undeclared_operation.js +120 -0
  158. package/dist/integrity/slopnators/sl_undeclared_variant.d.ts +2 -0
  159. package/dist/integrity/slopnators/sl_undeclared_variant.js +117 -0
  160. package/dist/integrity/slopnators/sl_undescribed.d.ts +2 -0
  161. package/dist/integrity/slopnators/sl_undescribed.js +54 -0
  162. package/dist/integrity/slopnators/sl_ungoverned_island.d.ts +2 -0
  163. package/dist/integrity/slopnators/sl_ungoverned_island.js +58 -0
  164. package/dist/integrity/slopnators/sl_unkept_rows.d.ts +2 -0
  165. package/dist/integrity/slopnators/sl_unkept_rows.js +104 -0
  166. package/dist/integrity/slopnators/sl_unnamed_island.d.ts +2 -0
  167. package/dist/integrity/slopnators/sl_unnamed_island.js +37 -0
  168. package/dist/integrity/slopnators/sl_unpaired_member.d.ts +2 -0
  169. package/dist/integrity/slopnators/sl_unpaired_member.js +114 -0
  170. package/dist/integrity/slopnators/sl_unpaired_slopnator.d.ts +2 -0
  171. package/dist/integrity/slopnators/sl_unpaired_slopnator.js +60 -0
  172. package/dist/integrity/slopnators/sl_unprefixed_member.d.ts +2 -0
  173. package/dist/integrity/slopnators/sl_unprefixed_member.js +126 -0
  174. package/dist/integrity/slopnators/sl_unseamed_reach.d.ts +2 -0
  175. package/dist/integrity/slopnators/sl_unseamed_reach.js +73 -0
  176. package/dist/integrity/slopnators/sl_unthreaded.d.ts +56 -0
  177. package/dist/integrity/slopnators/sl_unthreaded.js +352 -0
  178. package/dist/integrity/slopnators/sl_untranslated_key.d.ts +2 -0
  179. package/dist/integrity/slopnators/sl_untranslated_key.js +157 -0
  180. package/dist/integrity/slopnators/sl_unversioned.d.ts +2 -0
  181. package/dist/integrity/slopnators/sl_unversioned.js +31 -0
  182. package/dist/integrity/sweep.d.ts +24 -0
  183. package/dist/integrity/sweep.js +264 -0
  184. package/dist/knowledge/attach.d.ts +2 -0
  185. package/dist/knowledge/attach.js +339 -0
  186. package/dist/knowledge/generators/docsgen.d.ts +1 -0
  187. package/dist/knowledge/generators/docsgen.js +145 -0
  188. package/dist/knowledge/generators/glossary.d.ts +1 -0
  189. package/dist/knowledge/generators/glossary.js +56 -0
  190. package/dist/knowledge/generators/skills.d.ts +1 -0
  191. package/dist/knowledge/generators/skills.js +222 -0
  192. package/dist/knowledge/glossary.d.ts +6 -0
  193. package/dist/knowledge/glossary.js +1 -0
  194. package/dist/operations/access.d.ts +27 -0
  195. package/dist/operations/access.js +61 -0
  196. package/dist/operations/attach.d.ts +6 -0
  197. package/dist/operations/attach.js +414 -0
  198. package/dist/operations/capabilities.d.ts +37 -0
  199. package/dist/operations/capabilities.js +35 -0
  200. package/dist/operations/cost.d.ts +14 -0
  201. package/dist/operations/cost.js +37 -0
  202. package/dist/operations/dispatch.d.ts +14 -0
  203. package/dist/operations/dispatch.js +327 -0
  204. package/dist/operations/error-results.d.ts +4 -0
  205. package/dist/operations/error-results.js +25 -0
  206. package/dist/operations/errors/catalog.d.ts +58 -0
  207. package/dist/operations/errors/catalog.js +91 -0
  208. package/dist/operations/errors/classes.d.ts +73 -0
  209. package/dist/operations/errors/classes.js +22 -0
  210. package/dist/operations/errors/errors.d.ts +52 -0
  211. package/dist/operations/errors/errors.js +257 -0
  212. package/dist/operations/generators/capability.d.ts +5 -0
  213. package/dist/operations/generators/capability.js +603 -0
  214. package/dist/operations/generators/compile.d.ts +2 -0
  215. package/dist/operations/generators/compile.js +541 -0
  216. package/dist/operations/generators/grant.d.ts +1 -0
  217. package/dist/operations/generators/grant.js +267 -0
  218. package/dist/operations/generators/operation.d.ts +1 -0
  219. package/dist/operations/generators/operation.js +811 -0
  220. package/dist/operations/generators/permits.d.ts +1 -0
  221. package/dist/operations/generators/permits.js +196 -0
  222. package/dist/operations/generators/seed.d.ts +20 -0
  223. package/dist/operations/generators/seed.js +285 -0
  224. package/dist/operations/generators/trial.d.ts +53 -0
  225. package/dist/operations/generators/trial.js +376 -0
  226. package/dist/operations/http.d.ts +30 -0
  227. package/dist/operations/http.js +121 -0
  228. package/dist/operations/makers/capability.d.ts +1 -0
  229. package/dist/operations/makers/capability.js +117 -0
  230. package/dist/operations/makers/trial.d.ts +1 -0
  231. package/dist/operations/makers/trial.js +413 -0
  232. package/dist/operations/memory.d.ts +104 -0
  233. package/dist/operations/memory.js +365 -0
  234. package/dist/operations/metering.d.ts +55 -0
  235. package/dist/operations/metering.js +247 -0
  236. package/dist/operations/nodes.d.ts +35 -0
  237. package/dist/operations/nodes.js +15 -0
  238. package/dist/operations/operations.d.ts +18 -0
  239. package/dist/operations/operations.js +5 -0
  240. package/dist/operations/queue-policy.d.ts +3 -0
  241. package/dist/operations/queue-policy.js +8 -0
  242. package/dist/operations/result.d.ts +19 -0
  243. package/dist/operations/result.js +10 -0
  244. package/dist/operations/seams.d.ts +239 -0
  245. package/dist/operations/seams.js +45 -0
  246. package/dist/operations/store.d.ts +14 -0
  247. package/dist/operations/store.js +1 -0
  248. package/package.json +16 -0
@@ -0,0 +1,26 @@
1
+ export interface Quote {
2
+ readonly on: string;
3
+ readonly said: string;
4
+ }
5
+ export interface Threaded {
6
+ readonly id: string;
7
+ readonly at: string;
8
+ readonly describes: string;
9
+ readonly version?: number;
10
+ readonly cites?: readonly Quote[];
11
+ readonly requires?: readonly string[];
12
+ readonly takes?: readonly string[];
13
+ readonly by?: string;
14
+ readonly runs?: string;
15
+ readonly declares?: readonly Threaded[];
16
+ readonly derives?: readonly Threaded[];
17
+ readonly seeds?: readonly Threaded[];
18
+ }
19
+ export interface Member extends Threaded {
20
+ readonly version: number;
21
+ }
22
+ export declare const PREFIXES: {
23
+ readonly workflow: "wf_";
24
+ readonly view: "vw_";
25
+ readonly agent: "agt_";
26
+ };
@@ -0,0 +1,5 @@
1
+ export const PREFIXES = {
2
+ workflow: 'wf_',
3
+ view: 'vw_',
4
+ agent: 'agt_',
5
+ };
@@ -0,0 +1,12 @@
1
+ export interface Tree {
2
+ readonly at: string;
3
+ readonly dir: string;
4
+ readonly name: string;
5
+ readonly root: string;
6
+ }
7
+ export declare class UnthreadedRepositoryError extends Error {
8
+ constructor(from: string);
9
+ }
10
+ export declare function findTree(from?: string): Tree;
11
+ export declare function strayFiles(root: string, prefix: string, ends: string): readonly string[];
12
+ export declare function inTree(tree: Tree, file: string): string;
@@ -0,0 +1,56 @@
1
+ import { existsSync, readdirSync, statSync } from 'node:fs';
2
+ import { dirname, join, relative, resolve } from 'node:path';
3
+ import { cwd } from 'node:process';
4
+ const NAMES = ['_threads', 'threads'];
5
+ const ROOT = 'thread.ts';
6
+ export class UnthreadedRepositoryError extends Error {
7
+ constructor(from) {
8
+ super(`no tree above ${from} — looked for a ${NAMES.map((one) => `${one}/`).join(' or ')} directory in every directory up to the filesystem root. ` +
9
+ 'Run `thread init` to write one.');
10
+ this.name = 'UnthreadedRepositoryError';
11
+ }
12
+ }
13
+ export function findTree(from = cwd()) {
14
+ let at = resolve(from);
15
+ for (;;) {
16
+ for (const name of NAMES) {
17
+ const dir = join(at, name);
18
+ if (existsSync(dir) && statSync(dir).isDirectory())
19
+ return { at, dir, name, root: join(dir, ROOT) };
20
+ }
21
+ const up = dirname(at);
22
+ if (up === at)
23
+ throw new UnthreadedRepositoryError(from);
24
+ at = up;
25
+ }
26
+ }
27
+ export function strayFiles(root, prefix, ends) {
28
+ const skip = new Set(['node_modules', '.git', '.next', 'dist', '_generated', 'coverage']);
29
+ const found = [];
30
+ const walk = (dir) => {
31
+ let held;
32
+ try {
33
+ held = readdirSync(dir, { withFileTypes: true });
34
+ }
35
+ catch {
36
+ return;
37
+ }
38
+ for (const one of held) {
39
+ if (one.name.startsWith('.') || skip.has(one.name))
40
+ continue;
41
+ const path = join(dir, one.name);
42
+ if (one.isDirectory()) {
43
+ walk(path);
44
+ continue;
45
+ }
46
+ if (one.name.startsWith(prefix) && one.name.endsWith(ends)) {
47
+ found.push(relative(root, path).split('\\').join('/'));
48
+ }
49
+ }
50
+ };
51
+ walk(root);
52
+ return found.sort();
53
+ }
54
+ export function inTree(tree, file) {
55
+ return join(tree.dir, file);
56
+ }
@@ -0,0 +1,49 @@
1
+ export declare const VALUE_TYPES: readonly ["text", "number", "boolean", "date", "timestamp", "json"];
2
+ export type ValueType = (typeof VALUE_TYPES)[number];
3
+ export declare const KEYBOARDS: readonly ["text", "numeric", "decimal", "tel", "email", "url", "search"];
4
+ export type Keyboard = (typeof KEYBOARDS)[number];
5
+ export declare const ENTRY_MODES: readonly ["plain", "calculator", "masked"];
6
+ export type EntryMode = (typeof ENTRY_MODES)[number];
7
+ export type Checked = {
8
+ readonly ok: true;
9
+ readonly value: unknown;
10
+ } | {
11
+ readonly ok: false;
12
+ readonly because: string;
13
+ };
14
+ export declare const held: (value: unknown) => Checked;
15
+ export declare const refused: (because: string) => Checked;
16
+ export interface Facts {
17
+ readonly locale?: string;
18
+ readonly currency?: string;
19
+ readonly min?: number;
20
+ readonly max?: number;
21
+ readonly maxLen?: number;
22
+ readonly maxBytes?: number;
23
+ readonly maxDepth?: number;
24
+ readonly options?: readonly string[];
25
+ readonly now?: number;
26
+ }
27
+ export interface Format {
28
+ readonly name: string;
29
+ readonly type: ValueType;
30
+ readonly check: (raw: unknown, facts: Facts) => Checked;
31
+ readonly shown?: (value: unknown, facts: Facts) => string;
32
+ readonly keyboard?: Keyboard;
33
+ readonly accepts?: RegExp;
34
+ readonly maxChars?: number;
35
+ readonly entry?: EntryMode;
36
+ readonly mask?: string;
37
+ readonly secret?: boolean;
38
+ readonly autocomplete?: string;
39
+ readonly requires?: readonly string[];
40
+ }
41
+ export declare function stripControl(text: string): string;
42
+ export declare const BOUNDED: Readonly<Partial<Record<ValueType, string>>>;
43
+ export declare const FORMATS: readonly Format[];
44
+ export declare function formatsOf(type: ValueType): readonly Format[];
45
+ export declare function formatNamed(name: string): Format | undefined;
46
+ export declare function plainFormat(type: ValueType): Format;
47
+ export declare function formatFor(type: ValueType, name: string | undefined): Format | undefined;
48
+ export declare function checkValue(type: ValueType, name: string | undefined, raw: unknown, facts?: Facts): Checked;
49
+ export declare function showValue(type: ValueType, name: string | undefined, value: unknown, facts?: Facts): string;
@@ -0,0 +1,311 @@
1
+ export const VALUE_TYPES = ['text', 'number', 'boolean', 'date', 'timestamp', 'json'];
2
+ export const KEYBOARDS = ['text', 'numeric', 'decimal', 'tel', 'email', 'url', 'search'];
3
+ export const ENTRY_MODES = ['plain', 'calculator', 'masked'];
4
+ export const held = (value) => ({ ok: true, value });
5
+ export const refused = (because) => ({ ok: false, because });
6
+ export function stripControl(text) {
7
+ let out = '';
8
+ for (const character of text) {
9
+ const point = character.codePointAt(0) ?? 0;
10
+ const control = point <= 0x08 || point === 0x0b || point === 0x0c || (point >= 0x0e && point <= 0x1f) || (point >= 0x7f && point <= 0x9f);
11
+ if (!control)
12
+ out += character;
13
+ }
14
+ return out;
15
+ }
16
+ const numeric = (raw) => (typeof raw === 'number' ? raw : Number(raw));
17
+ const SCHEMES = new Set(['http:', 'https:', 'mailto:', 'tel:']);
18
+ export const BOUNDED = {
19
+ text: 'number of characters',
20
+ number: 'value',
21
+ };
22
+ function bounded(one, facts) {
23
+ if (facts.min !== undefined && one < facts.min)
24
+ return refused('format.number.below_min');
25
+ if (facts.max !== undefined && one > facts.max)
26
+ return refused('format.number.above_max');
27
+ return held(one);
28
+ }
29
+ function depthWithin(value, limit, depth = 0) {
30
+ if (depth > limit)
31
+ return false;
32
+ if (Array.isArray(value))
33
+ return value.every((one) => depthWithin(one, limit, depth + 1));
34
+ if (value !== null && typeof value === 'object')
35
+ return Object.values(value).every((one) => depthWithin(one, limit, depth + 1));
36
+ return true;
37
+ }
38
+ const instant = (raw) => typeof raw === 'string' && !Number.isNaN(Date.parse(raw))
39
+ ? held(new Date(raw).toISOString())
40
+ : refused('format.timestamp.unreadable');
41
+ const dated = (value, facts, options) => new Intl.DateTimeFormat(facts.locale, options).format(new Date(String(value)));
42
+ export const FORMATS = [
43
+ {
44
+ name: 'text',
45
+ type: 'text',
46
+ keyboard: 'text',
47
+ check: (raw, facts) => {
48
+ if (typeof raw !== 'string')
49
+ return refused('format.text.not_text');
50
+ const clean = stripControl(raw).trim();
51
+ return facts.maxLen !== undefined && clean.length > facts.maxLen ? refused('format.text.too_long') : held(clean);
52
+ },
53
+ },
54
+ {
55
+ name: 'email',
56
+ type: 'text',
57
+ keyboard: 'email',
58
+ autocomplete: 'email',
59
+ check: (raw) => {
60
+ if (typeof raw !== 'string')
61
+ return refused('format.email.invalid');
62
+ const one = raw.trim().toLowerCase();
63
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(one) ? held(one) : refused('format.email.invalid');
64
+ },
65
+ },
66
+ {
67
+ name: 'tel',
68
+ type: 'text',
69
+ keyboard: 'tel',
70
+ accepts: /[0-9+]/,
71
+ maxChars: 16,
72
+ autocomplete: 'tel',
73
+ check: (raw) => {
74
+ if (typeof raw !== 'string')
75
+ return refused('format.tel.invalid');
76
+ const digits = raw.replace(/[^\d+]/g, '');
77
+ return /^\+?\d{6,15}$/.test(digits) ? held(digits) : refused('format.tel.invalid');
78
+ },
79
+ },
80
+ {
81
+ name: 'url',
82
+ type: 'text',
83
+ keyboard: 'url',
84
+ check: (raw) => {
85
+ if (typeof raw !== 'string')
86
+ return refused('format.url.invalid');
87
+ let parsed;
88
+ try {
89
+ parsed = new URL(raw.trim());
90
+ }
91
+ catch {
92
+ return refused('format.url.invalid');
93
+ }
94
+ return SCHEMES.has(parsed.protocol) ? held(parsed.toString()) : refused('format.url.scheme');
95
+ },
96
+ },
97
+ {
98
+ name: 'password',
99
+ type: 'text',
100
+ secret: true,
101
+ maxChars: 256,
102
+ autocomplete: 'current-password',
103
+ check: (raw) => (typeof raw === 'string' && raw.length >= 8 ? held(raw) : refused('format.password.too_short')),
104
+ },
105
+ {
106
+ name: 'otp',
107
+ type: 'text',
108
+ keyboard: 'numeric',
109
+ accepts: /\d/,
110
+ maxChars: 6,
111
+ autocomplete: 'one-time-code',
112
+ check: (raw) => (typeof raw === 'string' && /^\d{6}$/.test(raw) ? held(raw) : refused('format.otp.invalid')),
113
+ },
114
+ {
115
+ name: 'ref',
116
+ type: 'text',
117
+ check: (raw) => (typeof raw === 'string' && /^ref:[a-z0-9/_-]+$/i.test(raw) ? held(raw) : refused('format.ref.invalid')),
118
+ },
119
+ {
120
+ name: 'choice',
121
+ type: 'text',
122
+ requires: ['options'],
123
+ check: (raw, facts) => {
124
+ if (facts.options === undefined)
125
+ return refused('format.choice.undeclared_options');
126
+ return typeof raw === 'string' && facts.options.includes(raw) ? held(raw) : refused('format.choice.undeclared');
127
+ },
128
+ },
129
+ {
130
+ name: 'number',
131
+ type: 'number',
132
+ keyboard: 'decimal',
133
+ accepts: /[0-9.,-]/,
134
+ check: (raw, facts) => {
135
+ const one = numeric(raw);
136
+ return Number.isFinite(one) ? bounded(one, facts) : refused('format.number.invalid');
137
+ },
138
+ },
139
+ {
140
+ name: 'integer',
141
+ type: 'number',
142
+ keyboard: 'numeric',
143
+ accepts: /[0-9-]/,
144
+ check: (raw, facts) => {
145
+ const one = numeric(raw);
146
+ return Number.isInteger(one) ? bounded(one, facts) : refused('format.integer.invalid');
147
+ },
148
+ },
149
+ {
150
+ name: 'money',
151
+ type: 'number',
152
+ keyboard: 'decimal',
153
+ accepts: /[0-9]/,
154
+ entry: 'calculator',
155
+ requires: ['currency'],
156
+ check: (raw, facts) => {
157
+ const one = numeric(raw);
158
+ return Number.isFinite(one) ? bounded(one, facts) : refused('format.money.invalid');
159
+ },
160
+ shown: (value, facts) => facts.currency === undefined
161
+ ? String(value)
162
+ : new Intl.NumberFormat(facts.locale, { style: 'currency', currency: facts.currency }).format(Number(value)),
163
+ },
164
+ {
165
+ name: 'percent',
166
+ type: 'number',
167
+ keyboard: 'decimal',
168
+ accepts: /[0-9.,]/,
169
+ check: (raw) => {
170
+ const one = numeric(raw);
171
+ return Number.isFinite(one) && one >= 0 && one <= 100 ? held(one) : refused('format.percent.range');
172
+ },
173
+ shown: (value, facts) => new Intl.NumberFormat(facts.locale, { style: 'percent', maximumFractionDigits: 1 }).format(Number(value) / 100),
174
+ },
175
+ {
176
+ name: 'duration',
177
+ type: 'number',
178
+ keyboard: 'numeric',
179
+ accepts: /[0-9]/,
180
+ check: (raw) => {
181
+ const one = numeric(raw);
182
+ if (!Number.isFinite(one))
183
+ return refused('format.number.invalid');
184
+ return one < 0 ? refused('format.duration.negative') : held(one);
185
+ },
186
+ },
187
+ {
188
+ name: 'rating',
189
+ type: 'number',
190
+ keyboard: 'numeric',
191
+ accepts: /[0-9]/,
192
+ check: (raw, facts) => {
193
+ const one = numeric(raw);
194
+ const ceiling = facts.max ?? 5;
195
+ return Number.isInteger(one) && one >= 1 && one <= ceiling ? held(one) : refused('format.rating.range');
196
+ },
197
+ },
198
+ {
199
+ name: 'boolean',
200
+ type: 'boolean',
201
+ check: (raw) => {
202
+ if (typeof raw === 'boolean')
203
+ return held(raw);
204
+ if (raw === 'true' || raw === 'false')
205
+ return held(raw === 'true');
206
+ return refused('format.boolean.invalid');
207
+ },
208
+ },
209
+ {
210
+ name: 'date',
211
+ type: 'date',
212
+ keyboard: 'numeric',
213
+ accepts: /[0-9-]/,
214
+ maxChars: 10,
215
+ mask: '0000-00-00',
216
+ entry: 'masked',
217
+ check: (raw) => {
218
+ if (typeof raw !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(raw))
219
+ return refused('format.date.shape');
220
+ return Number.isNaN(Date.parse(raw)) ? refused('format.date.invalid') : held(raw);
221
+ },
222
+ shown: (value, facts) => dated(`${String(value)}T00:00:00Z`, facts, { dateStyle: 'medium', timeZone: 'UTC' }),
223
+ },
224
+ {
225
+ name: 'timestamp',
226
+ type: 'timestamp',
227
+ check: instant,
228
+ shown: (value, facts) => dated(value, facts, { dateStyle: 'medium', timeStyle: 'short' }),
229
+ },
230
+ {
231
+ name: 'elapsed',
232
+ type: 'timestamp',
233
+ check: instant,
234
+ requires: ['now'],
235
+ shown: (value, facts) => {
236
+ const now = facts.now ?? Date.parse(new Date().toISOString());
237
+ const gap = Date.parse(String(value)) - now;
238
+ const UNITS = [
239
+ ['year', 31_536_000_000],
240
+ ['month', 2_592_000_000],
241
+ ['week', 604_800_000],
242
+ ['day', 86_400_000],
243
+ ['hour', 3_600_000],
244
+ ['minute', 60_000],
245
+ ['second', 1000],
246
+ ];
247
+ const spoken = new Intl.RelativeTimeFormat(facts.locale, { numeric: 'auto' });
248
+ for (const [unit, span] of UNITS) {
249
+ if (Math.abs(gap) >= span)
250
+ return spoken.format(Math.trunc(gap / span), unit);
251
+ }
252
+ return spoken.format(0, 'second');
253
+ },
254
+ },
255
+ {
256
+ name: 'json',
257
+ type: 'json',
258
+ check: (raw, facts) => {
259
+ if (facts.maxDepth !== undefined && !depthWithin(raw, facts.maxDepth))
260
+ return refused('format.json.too_deep');
261
+ const size = JSON.stringify(raw)?.length ?? 0;
262
+ return facts.maxBytes !== undefined && size > facts.maxBytes ? refused('format.json.too_large') : held(raw);
263
+ },
264
+ },
265
+ {
266
+ name: 'geo',
267
+ type: 'json',
268
+ check: (raw) => {
269
+ if (raw === null || typeof raw !== 'object')
270
+ return refused('format.geo.invalid');
271
+ const { lat, lng } = raw;
272
+ const within = typeof lat === 'number' && lat >= -90 && lat <= 90 && typeof lng === 'number' && lng >= -180 && lng <= 180;
273
+ return within ? held({ lat, lng }) : refused('format.geo.invalid');
274
+ },
275
+ },
276
+ {
277
+ name: 'richtext',
278
+ type: 'json',
279
+ check: (raw) => {
280
+ if (raw === null || typeof raw !== 'object')
281
+ return refused('format.richtext.invalid');
282
+ const blocks = raw.blocks;
283
+ return Array.isArray(blocks) ? held({ blocks }) : refused('format.richtext.invalid');
284
+ },
285
+ },
286
+ ];
287
+ const BY_NAME = new Map(FORMATS.map((one) => [one.name, one]));
288
+ export function formatsOf(type) {
289
+ return FORMATS.filter((one) => one.type === type);
290
+ }
291
+ export function formatNamed(name) {
292
+ return BY_NAME.get(name);
293
+ }
294
+ export function plainFormat(type) {
295
+ const one = BY_NAME.get(type);
296
+ if (one === undefined)
297
+ throw new Error(`no plain format is declared for value type "${type}"`);
298
+ return one;
299
+ }
300
+ export function formatFor(type, name) {
301
+ const one = name === undefined ? plainFormat(type) : BY_NAME.get(name);
302
+ return one === undefined || one.type !== type ? undefined : one;
303
+ }
304
+ export function checkValue(type, name, raw, facts = {}) {
305
+ const one = formatFor(type, name);
306
+ return one === undefined ? refused(`format.unusable.${name ?? type}`) : one.check(raw, facts);
307
+ }
308
+ export function showValue(type, name, value, facts = {}) {
309
+ const one = formatFor(type, name);
310
+ return one?.shown === undefined ? String(value) : one.shown(value, facts);
311
+ }
@@ -0,0 +1,2 @@
1
+ import type { Attaching } from '../core/attach.ts';
2
+ export declare const ATTACH: Attaching;
@@ -0,0 +1,61 @@
1
+ import { quoted } from "../core/rows.js";
2
+ const DESCRIBES = 'What turns a declaration into a file: the rows that state something is to be made, and the generators that make it. They are kept apart so you can read what an app declares without opening the machinery that builds it.';
3
+ const DERIVATION_SOURCE = [
4
+ "import type { Threaded } from '../core/thread.ts'",
5
+ '',
6
+ 'export const DERIVATION: Threaded = {',
7
+ " id: 'derivation',",
8
+ " at: '_threads/derivation.ts',",
9
+ ` describes: ${quoted(DESCRIBES)},`,
10
+ ' version: 1,',
11
+ ' derives: [],',
12
+ '}',
13
+ '',
14
+ 'export const GENERATORS: readonly Threaded[] = []',
15
+ '',
16
+ ].join('\n');
17
+ const SEEDED = {
18
+ attaches: [],
19
+ id: 'derivation',
20
+ declares: [
21
+ ' {',
22
+ ' id: \'derivation\',',
23
+ ' at: \'_threads/derivation.ts\',',
24
+ ' describes: \'What turns a declaration into a file: the rows that state something is to be made, and the generators that make it. They are kept apart so you can read what an app declares without opening the machinery that builds it.\',',
25
+ ' version: 1,',
26
+ ' },',
27
+ ].join('\n'),
28
+ };
29
+ const SHIPPED = [
30
+ {
31
+ into: 'derivation.ts',
32
+ list: 'GENERATORS',
33
+ id: 'build-generator',
34
+ source: " {\n id: 'build-generator',\n at: 'node_modules/@prestack/thread/dist/derivation/generators/build.js',\n describes: 'The builder of what this app ships — it reads the row that derives an artifact to learn the entry it comes from, and refuses to resolve any file inside the app the descent never reaches, so a file nothing declares has no way into the thing that runs.',\n version: 1,\n by: 'thread build',\n runs: 'thread build --check',\n },",
35
+ },
36
+ {
37
+ into: 'derivation.ts',
38
+ list: 'GENERATORS',
39
+ id: 'release-generator',
40
+ source: " {\n id: 'release-generator',\n at: 'node_modules/@prestack/thread/dist/derivation/generators/release.js',\n describes: 'The writer of what a host reads to run this app — it derives the config from what the app already declares, its own build and start commands and the names of every secret it says it must be given, and refuses its own output if a module of this framework ever appears in it, because what a host runs may hold nothing of the scaffolding that assembled it.',\n version: 1,\n by: 'thread release',\n runs: 'thread release --check',\n },",
41
+ },
42
+ {
43
+ into: 'derivation.ts',
44
+ list: 'GENERATORS',
45
+ id: 'release-noun',
46
+ source: " {\n id: 'release-noun',\n at: 'node_modules/@prestack/thread/dist/derivation/makers/release.js',\n describes: 'The command that declares where this app goes when it leaves your machine. It writes the row saying where this app goes and nothing else, because everything the config needs is already declared somewhere and asking for it again would be the app’s own facts typed a second time.',\n version: 1,\n by: 'thread create release',\n },",
47
+ },
48
+ {
49
+ into: 'derivation.ts',
50
+ list: 'GENERATORS',
51
+ id: 'generator-noun',
52
+ source: " {\n id: 'generator-noun',\n at: 'node_modules/@prestack/thread/dist/derivation/generators/derivation.js',\n describes: 'Declares a generator this app derives a file with. `thread create generator` asks what it is, where its file goes and the command that writes it, then writes the row and seeds the file beside it — so a generator arrives through the same wizard as everything else, and the command it names exists from that moment because the CLI reads every `by:` the tree states.',\n version: 1,\n by: 'thread create generator',\n },",
53
+ },
54
+ ];
55
+ export const ATTACH = {
56
+ attaches: SEEDED.attaches,
57
+ id: SEEDED.id,
58
+ declares: SEEDED.declares,
59
+ writes: [{ file: 'derivation.ts', source: DERIVATION_SOURCE }],
60
+ rows: SHIPPED,
61
+ };
@@ -0,0 +1,16 @@
1
+ import { type Pass } from '../../core/descend.ts';
2
+ declare function wanted(pass: Pass): readonly {
3
+ entry: string;
4
+ out: string;
5
+ }[];
6
+ declare function declared(): {
7
+ readonly name: string;
8
+ readonly setup: (build: {
9
+ onLoad: (opts: {
10
+ filter: RegExp;
11
+ }, run: (args: {
12
+ path: string;
13
+ }) => unknown) => void;
14
+ }) => void;
15
+ };
16
+ export { declared, wanted };