@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,15 @@
1
+ export const STOPPED = Symbol.for('thread.operation.stopped');
2
+ export function stopped(thrown) {
3
+ if (typeof thrown !== 'object' || thrown === null)
4
+ return undefined;
5
+ if (thrown[STOPPED] !== true)
6
+ return undefined;
7
+ return { value: thrown.value };
8
+ }
9
+ export const nd_read = (block) => ({ type: 'nd_read' });
10
+ export const nd_action = (block) => ({ type: 'nd_action' });
11
+ export const nd_branch = (choose, ways) => ({ type: 'nd_branch' });
12
+ export const nd_each = (over, block) => ({ type: 'nd_each' });
13
+ export const nd_parallel = (blocks) => ({ type: 'nd_parallel' });
14
+ export const nd_repeat = (ceiling, block) => ({ type: 'nd_repeat' });
15
+ export const nd_stop = (block) => ({ type: 'nd_stop' });
@@ -0,0 +1,18 @@
1
+ import type { z } from 'zod';
2
+ import type { Member } from '../core/thread.ts';
3
+ import type { Handed, Row, Supplied } from './seams.ts';
4
+ export declare const OPERATIONS_FILE = "operations.ts";
5
+ export declare const TRIALS_AT = "operations/_trials.json";
6
+ export declare const NODES_FILE = "nodes.ts";
7
+ export declare const MEMBERS_LIST = "MEMBERS";
8
+ export interface Operation<I = unknown, R extends string = Supplied> {
9
+ readonly id: string;
10
+ readonly input: z.ZodType<I>;
11
+ readonly requires: readonly string[];
12
+ readonly run: (hands: Handed<R>, held: {
13
+ readonly input: I;
14
+ } & Readonly<Record<string, unknown>>) => Promise<unknown>;
15
+ readonly estimate: number;
16
+ readonly resource: (input: I) => Row | null;
17
+ }
18
+ export declare const OPERATIONS: readonly Member[];
@@ -0,0 +1,5 @@
1
+ export const OPERATIONS_FILE = 'operations.ts';
2
+ export const TRIALS_AT = 'operations/_trials.json';
3
+ export const NODES_FILE = 'nodes.ts';
4
+ export const MEMBERS_LIST = 'MEMBERS';
5
+ export const OPERATIONS = [];
@@ -0,0 +1,3 @@
1
+ export declare const MAX_ATTEMPTS = 5;
2
+ export declare function backoffMs(attempts: number): number;
3
+ export declare function isExhausted(attempts: number): boolean;
@@ -0,0 +1,8 @@
1
+ export const MAX_ATTEMPTS = 5;
2
+ export function backoffMs(attempts) {
3
+ const base = 1_000 * 2 ** Math.max(0, attempts - 1);
4
+ return Math.min(base, 5 * 60_000);
5
+ }
6
+ export function isExhausted(attempts) {
7
+ return attempts >= MAX_ATTEMPTS;
8
+ }
@@ -0,0 +1,19 @@
1
+ import type { ErrorCode, ErrorDef } from './errors/catalog.ts';
2
+ import type { ErrorClass } from './errors/classes.ts';
3
+ export type ResultCode = 'denied' | 'invalid' | 'rate_limited' | 'feature_denied' | 'quota_exceeded' | 'error';
4
+ export type FailureIdentity = Pick<ErrorDef, 'code' | 'class'>;
5
+ export type Result<O> = {
6
+ ok: true;
7
+ value: O;
8
+ } | {
9
+ ok: false;
10
+ code: ResultCode;
11
+ error: string;
12
+ because?: string;
13
+ errorCode?: ErrorCode;
14
+ errorClass?: ErrorClass;
15
+ };
16
+ export declare const ok: <O>(value: O) => Result<O>;
17
+ export declare const fail: <O>(code: ResultCode, error: string, because?: string, identity?: FailureIdentity) => Result<O>;
18
+ export declare class ValidationError extends Error {
19
+ }
@@ -0,0 +1,10 @@
1
+ export const ok = (value) => ({ ok: true, value });
2
+ export const fail = (code, error, because, identity) => ({
3
+ ok: false,
4
+ code,
5
+ error,
6
+ because,
7
+ ...(identity === undefined ? {} : { errorCode: identity.code, errorClass: identity.class }),
8
+ });
9
+ export class ValidationError extends Error {
10
+ }
@@ -0,0 +1,239 @@
1
+ import type { Actor } from '../core/actor.ts';
2
+ export type { FieldList, ReadField, Row, Store } from './store.ts';
3
+ import type { Row, Store } from './store.ts';
4
+ export interface Span {
5
+ ok(): void;
6
+ error(e: unknown): void;
7
+ end(): void;
8
+ }
9
+ export interface Telemetry {
10
+ start(action: string, run: string, tags: Record<string, unknown>): Span;
11
+ record?(span: {
12
+ readonly key: string;
13
+ readonly traceId: string;
14
+ readonly spanId: string;
15
+ readonly durationMs: number;
16
+ readonly ok: boolean;
17
+ readonly attrs?: Record<string, unknown>;
18
+ readonly actor?: Actor;
19
+ readonly nodeId?: string;
20
+ readonly workflowId?: string;
21
+ readonly error?: string;
22
+ }): void;
23
+ }
24
+ export type PropertyValue = string | number | boolean | null | readonly (string | number | boolean)[];
25
+ export type LogLevel = 'info' | 'warn' | 'error';
26
+ export interface Log {
27
+ write(level: LogLevel, action: string, actor: Actor, data: Record<string, unknown>): void;
28
+ }
29
+ export interface AuditRecord {
30
+ readonly action: string;
31
+ readonly outcome: AuditOutcome;
32
+ readonly subject: {
33
+ type: string;
34
+ id: string;
35
+ };
36
+ readonly changed?: readonly string[];
37
+ readonly because?: string;
38
+ }
39
+ export interface Audit {
40
+ append(actor: Actor, record: AuditRecord): Promise<void>;
41
+ }
42
+ export interface ErrorRecord {
43
+ readonly code: string;
44
+ readonly class: string;
45
+ readonly action: string;
46
+ readonly because?: string;
47
+ }
48
+ export interface Errors {
49
+ record(actor: Actor, error: ErrorRecord): Promise<void>;
50
+ }
51
+ export interface Search {
52
+ index(actor: Actor, entity: string, row: Row): Promise<void>;
53
+ query(actor: Actor, entity: string, q: string): Promise<Row[]>;
54
+ }
55
+ export interface Views {
56
+ query<T = Record<string, unknown>>(actor: Actor, sql: string, params: readonly unknown[]): Promise<readonly T[]>;
57
+ }
58
+ export interface Cost {
59
+ meter(action: string, actor: Actor, units?: number): void;
60
+ }
61
+ export interface Idempotency {
62
+ check(key: string | undefined, action: string): Promise<unknown | null>;
63
+ store(key: string | undefined, action: string, output: unknown): Promise<void>;
64
+ }
65
+ export interface PlatformEvent {
66
+ kind: string;
67
+ entity?: string;
68
+ id?: string;
69
+ run?: string;
70
+ actor: string | null;
71
+ at: number;
72
+ payload?: Readonly<Record<string, unknown>>;
73
+ }
74
+ export interface EventBus {
75
+ publish(event: PlatformEvent): Promise<void>;
76
+ }
77
+ export interface RateLimiter {
78
+ check(actor: Actor, action: string, operation?: string): Promise<boolean>;
79
+ checkPolicy(actor: Actor, policy: string): Promise<boolean>;
80
+ }
81
+ export interface FeatureGate {
82
+ check(actor: Actor, feature: string): Promise<boolean>;
83
+ }
84
+ export interface QuotaHold {
85
+ readonly ok: boolean;
86
+ readonly behavior: string | null;
87
+ readonly retryAfterSeconds: number;
88
+ commit(actual: number): Promise<void>;
89
+ release(): Promise<void>;
90
+ }
91
+ export interface Quotas {
92
+ reserve(actor: Actor, meter: string, estimate: number): Promise<QuotaHold>;
93
+ lower?(actor: Actor, meter: string, amount: number): Promise<void>;
94
+ }
95
+ export interface Outbox {
96
+ emit(actor: Actor, event: PlatformEvent): Promise<void>;
97
+ }
98
+ export interface Transactional {
99
+ transaction<T>(actor: Actor, fn: () => Promise<T>): Promise<T>;
100
+ }
101
+ export declare function isTransactional(store: Store): store is Store & Transactional;
102
+ export interface Job<T = unknown> {
103
+ id: string;
104
+ kind: string;
105
+ payload: T;
106
+ attempts: number;
107
+ actor: Actor;
108
+ }
109
+ export interface EnqueueOpts {
110
+ runAt?: number;
111
+ dedupeKey?: string;
112
+ }
113
+ export interface SchedulerSeam {
114
+ readonly endpoint: string;
115
+ readonly secret: string;
116
+ register(app: {
117
+ id: string;
118
+ endpoint: string;
119
+ secret: string;
120
+ }): Promise<void>;
121
+ schedule(call: {
122
+ appId: string;
123
+ runAt: Date;
124
+ reason: string;
125
+ runId?: string;
126
+ dedupeKey?: string;
127
+ }): Promise<string>;
128
+ cancelForRun(appId: string, runId: string): Promise<void>;
129
+ }
130
+ export interface Queue {
131
+ enqueue<T>(actor: Actor, kind: string, payload: T, opts?: EnqueueOpts): Promise<string>;
132
+ poll(kinds: string[], limit: number, now: number): Promise<Job[]>;
133
+ ack(id: string): Promise<void>;
134
+ fail(id: string, error: string, now: number): Promise<void>;
135
+ deadLetter(id: string, error: string): Promise<void>;
136
+ deadLetters(): Promise<Job[]>;
137
+ }
138
+ export interface Files {
139
+ put(actor: Actor, key: string, body: Uint8Array, contentType: string): Promise<{
140
+ size: number;
141
+ }>;
142
+ get(actor: Actor, key: string): Promise<{
143
+ body: Uint8Array;
144
+ contentType: string;
145
+ } | null>;
146
+ signedUrl(actor: Actor, key: string, expiresInSeconds: number): Promise<string>;
147
+ remove(actor: Actor, key: string): Promise<void>;
148
+ }
149
+ export interface Clock {
150
+ now(): number;
151
+ }
152
+ export interface Random {
153
+ next(): number;
154
+ uuid(): string;
155
+ }
156
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
157
+ export interface HttpRequest {
158
+ readonly target: string;
159
+ readonly address: string;
160
+ readonly method: HttpMethod;
161
+ readonly path: string;
162
+ readonly headers?: Readonly<Record<string, string>>;
163
+ readonly body?: Uint8Array;
164
+ readonly contentType?: string;
165
+ readonly idempotencyKey?: string;
166
+ }
167
+ export interface HttpResponse {
168
+ readonly status: number;
169
+ readonly headers: Readonly<Record<string, string>>;
170
+ readonly body: Uint8Array;
171
+ readonly bytesSent: number;
172
+ readonly bytesReceived: number;
173
+ readonly durationMs: number;
174
+ }
175
+ export interface Http {
176
+ call(request: HttpRequest): Promise<HttpResponse>;
177
+ }
178
+ export interface Vault {
179
+ resolve(refs: readonly string[]): Promise<Readonly<Record<string, string>>>;
180
+ }
181
+ export interface Seams {
182
+ store: Store;
183
+ search: Search;
184
+ events: EventBus;
185
+ queue: Queue;
186
+ telemetry?: Telemetry;
187
+ log: Log;
188
+ audit: Audit;
189
+ errors: Errors;
190
+ cost?: Cost;
191
+ idempotency?: Idempotency;
192
+ rateLimiter?: RateLimiter;
193
+ flush?: () => Promise<void>;
194
+ scheduler?: SchedulerSeam;
195
+ featureGate?: FeatureGate;
196
+ permits?: {
197
+ check(actor: Actor, action: string, resource: Row | null): Promise<{
198
+ readonly allow: boolean;
199
+ readonly because?: string;
200
+ }>;
201
+ };
202
+ quotas?: Quotas;
203
+ outbox?: Outbox;
204
+ drainKick?: () => void;
205
+ vault?: Vault;
206
+ views?: Views;
207
+ clock: Clock;
208
+ random: Random;
209
+ files?: Files;
210
+ http?: Http;
211
+ }
212
+ export type AuditOutcome = 'ok' | 'denied' | 'rate_limited' | 'failed' | 'feature_denied' | 'quota_exceeded';
213
+ export declare function isRow(v: unknown): v is Row;
214
+ export declare const SUPPLY: {
215
+ readonly sm_store: "store";
216
+ readonly sm_search: "search";
217
+ readonly sm_queue: "queue";
218
+ readonly sm_events: "events";
219
+ readonly sm_clock: "clock";
220
+ readonly sm_random: "random";
221
+ readonly sm_vault: "vault";
222
+ readonly sm_views: "views";
223
+ readonly sm_files: "files";
224
+ };
225
+ export type Supplied = keyof typeof SUPPLY;
226
+ export declare const SUPPLIES: readonly Supplied[];
227
+ export declare const supplies: (one: string) => one is Supplied;
228
+ export type Handed<R extends string = Supplied> = {
229
+ readonly actor: Actor;
230
+ } & {
231
+ readonly [K in R as K extends Supplied ? (typeof SUPPLY)[K] : K]: K extends Supplied ? NonNullable<Seams[(typeof SUPPLY)[K]]> : Readonly<Record<string, (given?: {
232
+ readonly fills?: Readonly<Record<string, string | number>>;
233
+ readonly json?: unknown;
234
+ readonly body?: Uint8Array;
235
+ readonly contentType?: string;
236
+ }) => Promise<HttpResponse>>>;
237
+ };
238
+ export type Reads<H> = Pick<H, Extract<keyof H, 'actor' | 'store' | 'search' | 'views'>>;
239
+ export declare const SAID: Readonly<Record<keyof Seams, string>>;
@@ -0,0 +1,45 @@
1
+ export function isTransactional(store) {
2
+ return typeof store.transaction === 'function';
3
+ }
4
+ export function isRow(v) {
5
+ return typeof v === 'object' && v !== null && typeof v.id === 'string';
6
+ }
7
+ export const SUPPLY = {
8
+ sm_store: 'store',
9
+ sm_search: 'search',
10
+ sm_queue: 'queue',
11
+ sm_events: 'events',
12
+ sm_clock: 'clock',
13
+ sm_random: 'random',
14
+ sm_vault: 'vault',
15
+ sm_views: 'views',
16
+ sm_files: 'files',
17
+ };
18
+ export const SUPPLIES = Object.keys(SUPPLY);
19
+ export const supplies = (one) => one in SUPPLY;
20
+ export const SAID = {
21
+ store: 'where rows are kept: insert, get, list, update and remove, bound to whoever asked',
22
+ search: 'indexing a row and querying an index, for what cannot be found by id',
23
+ events: 'announcing that something happened, to whoever is listening',
24
+ queue: 'handing work to something else to run later',
25
+ telemetry: 'the span opened around every run, and where it is recorded',
26
+ log: 'the line written for every run: its outcome, who was allowed, what it spent',
27
+ audit: 'the record of what was done, by whom, to what',
28
+ errors: 'the record of every failure, by code and class',
29
+ cost: 'metering what a run spent',
30
+ idempotency: 'remembering an answer under its key, so a repeated request is answered once',
31
+ rateLimiter: 'refusing a caller who asks too often',
32
+ flush: 'what runs when the process is about to stop, so nothing buffered is lost',
33
+ scheduler: 'registering this app with a scheduler and booking a later run',
34
+ featureGate: 'refusing an operation the caller\'s plan does not include',
35
+ permits: 'the gate every operation passes: who may ask for what, from the grants',
36
+ quotas: 'reserving what a run may spend before it starts, and settling it after',
37
+ outbox: 'events written with the transaction and published after it commits',
38
+ drainKick: 'nudging the queue worker that work has arrived',
39
+ vault: 'opening a secret by name at the moment of use',
40
+ views: 'reading through a declared view rather than a table',
41
+ clock: 'the current time',
42
+ random: 'randomness: a number, a uuid',
43
+ files: 'putting a file somewhere, fetching one back, handing out a signed link to one',
44
+ http: 'how a call leaves the process, and what it comes back with',
45
+ };
@@ -0,0 +1,14 @@
1
+ import type { Actor } from '../core/actor.ts';
2
+ export type Row = Record<string, unknown>;
3
+ export type ReadField = `fld_${string}` | `rel_${string}` | (string & {});
4
+ export type FieldList = readonly [ReadField, ...ReadField[]];
5
+ export interface Store {
6
+ insert(actor: Actor, entity: string, row: Row): Promise<Row>;
7
+ get(actor: Actor, entity: string, key: string | number, fields: FieldList): Promise<Row | null>;
8
+ list(actor: Actor, entity: string, opts?: {
9
+ limit?: number;
10
+ where?: Readonly<Record<string, string | number | boolean | null>>;
11
+ }): Promise<Row[]>;
12
+ update(actor: Actor, entity: string, key: string | number, patch: Record<string, unknown>, expectedVersion?: number): Promise<Row>;
13
+ remove(actor: Actor, entity: string, key: string | number): Promise<void>;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@prestack/thread",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "files": [
6
+ "dist",
7
+ "CHANGELOG.md"
8
+ ],
9
+ "exports": {
10
+ "./package.json": "./package.json",
11
+ "./*": "./dist/*.js"
12
+ },
13
+ "bin": {
14
+ "thread": "dist/core/cli.js"
15
+ }
16
+ }