@sifr-dev/loom 0.0.0-stage → 1.0.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.
- package/CHANGELOG.md +112 -0
- package/LICENSE +21 -0
- package/README.ar.md +253 -0
- package/README.md +262 -2
- package/dist/browser.js +2717 -0
- package/dist/cli.js +15 -0
- package/dist/index.js +4854 -0
- package/dist/types/args.d.ts +14 -0
- package/dist/types/base64.d.ts +9 -0
- package/dist/types/browser.d.ts +57 -0
- package/dist/types/canonical.d.ts +20 -0
- package/dist/types/cli.d.ts +12 -0
- package/dist/types/commands/context.d.ts +30 -0
- package/dist/types/commands/diff.d.ts +18 -0
- package/dist/types/commands/doctor.d.ts +19 -0
- package/dist/types/commands/export.d.ts +30 -0
- package/dist/types/commands/migrate.d.ts +9 -0
- package/dist/types/commands/serve.d.ts +18 -0
- package/dist/types/commands/snapshot.d.ts +15 -0
- package/dist/types/commands/sync.d.ts +17 -0
- package/dist/types/commands/verify.d.ts +9 -0
- package/dist/types/commands/watch.d.ts +25 -0
- package/dist/types/compute.d.ts +49 -0
- package/dist/types/concurrency.d.ts +31 -0
- package/dist/types/config.d.ts +132 -0
- package/dist/types/diff.d.ts +57 -0
- package/dist/types/digest.d.ts +11 -0
- package/dist/types/entities.d.ts +27 -0
- package/dist/types/errors.d.ts +37 -0
- package/dist/types/fs.d.ts +23 -0
- package/dist/types/github/cache.d.ts +44 -0
- package/dist/types/github/client.d.ts +91 -0
- package/dist/types/github/collect.d.ts +36 -0
- package/dist/types/github/discovery.d.ts +39 -0
- package/dist/types/github/fixture.d.ts +26 -0
- package/dist/types/github/guard.d.ts +14 -0
- package/dist/types/github/memory-cache.d.ts +34 -0
- package/dist/types/index.d.ts +44 -0
- package/dist/types/log.d.ts +16 -0
- package/dist/types/metrics.d.ts +21 -0
- package/dist/types/migrate.d.ts +24 -0
- package/dist/types/pipeline.d.ts +73 -0
- package/dist/types/queue.d.ts +33 -0
- package/dist/types/sdk.d.ts +165 -0
- package/dist/types/secrets.d.ts +28 -0
- package/dist/types/serve-handler.d.ts +46 -0
- package/dist/types/sha256.d.ts +13 -0
- package/dist/types/site-module.d.ts +23 -0
- package/dist/types/site.d.ts +135 -0
- package/dist/types/snapshot.d.ts +16 -0
- package/dist/types/store.d.ts +119 -0
- package/dist/types/triggers.d.ts +67 -0
- package/dist/types/types.d.ts +176 -0
- package/dist/types/version.d.ts +7 -0
- package/dist/types/webhook/delivery.d.ts +45 -0
- package/dist/types/webhook/receiver.d.ts +46 -0
- package/dist/types/webhook/signature.d.ts +43 -0
- package/docs/CONFIGURATION.md +213 -0
- package/docs/DEPLOYMENT.md +316 -0
- package/docs/SDK.md +351 -0
- package/docs/SITE_CONTRACT.md +318 -0
- package/docs/VERIFICATION.md +130 -0
- package/package.json +83 -4
- package/schema/site@1.json +188 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { type CollectConfig, type LoomConfig } from "./config.js";
|
|
2
|
+
import { type SyncOutcome } from "./pipeline.js";
|
|
3
|
+
import { SnapshotStore } from "./store.js";
|
|
4
|
+
import { type DiffResult } from "./diff.js";
|
|
5
|
+
import { type SiteRecord } from "./site.js";
|
|
6
|
+
import { type SiteModuleOptions } from "./site-module.js";
|
|
7
|
+
import { type DiscoveryResult } from "./github/discovery.js";
|
|
8
|
+
import { GitHubClient, type FetchLike } from "./github/client.js";
|
|
9
|
+
import type { ResponseCache } from "./github/memory-cache.js";
|
|
10
|
+
import { WebhookReceiver, type WebhookDecision, type WebhookInput } from "./webhook/receiver.js";
|
|
11
|
+
import type { TriggerEnv, TriggerResult } from "./triggers.js";
|
|
12
|
+
import type { Snapshot, SnapshotError } from "./types.js";
|
|
13
|
+
import { LoomError } from "./errors.js";
|
|
14
|
+
export type Logger = (message: string, detail?: Record<string, unknown>) => void;
|
|
15
|
+
/** Lifecycle hooks. A plugin is awaited in order; a throw aborts the sync. */
|
|
16
|
+
export type LoomPluginContext = {
|
|
17
|
+
config: LoomConfig;
|
|
18
|
+
storeRoot: string;
|
|
19
|
+
now: Date;
|
|
20
|
+
};
|
|
21
|
+
export type LoomPlugin = {
|
|
22
|
+
name: string;
|
|
23
|
+
onSnapshot?: (snapshot: Snapshot, context: LoomPluginContext) => void | Promise<void>;
|
|
24
|
+
onDiff?: (diff: DiffResult, context: LoomPluginContext) => void | Promise<void>;
|
|
25
|
+
onDeploy?: (results: TriggerResult[], context: LoomPluginContext) => void | Promise<void>;
|
|
26
|
+
onError?: (error: unknown, context: LoomPluginContext) => void;
|
|
27
|
+
};
|
|
28
|
+
export type LoomEvent = {
|
|
29
|
+
type: "sync";
|
|
30
|
+
outcome: SyncOutcome;
|
|
31
|
+
} | {
|
|
32
|
+
type: "snapshot";
|
|
33
|
+
snapshot: Snapshot;
|
|
34
|
+
} | {
|
|
35
|
+
type: "diff";
|
|
36
|
+
diff: DiffResult;
|
|
37
|
+
} | {
|
|
38
|
+
type: "deploy";
|
|
39
|
+
results: TriggerResult[];
|
|
40
|
+
} | {
|
|
41
|
+
type: "error";
|
|
42
|
+
error: unknown;
|
|
43
|
+
};
|
|
44
|
+
export type LoomListener = (event: LoomEvent) => void;
|
|
45
|
+
export type LoomOptions = {
|
|
46
|
+
/** Working directory for a relative config/store path. */
|
|
47
|
+
cwd?: string;
|
|
48
|
+
/** GitHub PAT or App token. Read from `tokenEnv` when omitted. */
|
|
49
|
+
token?: string | null;
|
|
50
|
+
/** Environment variable holding the token. Defaults to `GITHUB_TOKEN`. */
|
|
51
|
+
tokenEnv?: string;
|
|
52
|
+
/** Injected fetch for tests, proxies, or an enterprise base URL. */
|
|
53
|
+
fetch?: FetchLike;
|
|
54
|
+
/** Injected fetch for deploy triggers (tests, proxies). */
|
|
55
|
+
dispatchFetch?: FetchLike;
|
|
56
|
+
/** Recorded fixture directory; when set, no network is used. */
|
|
57
|
+
fixtureDir?: string | null;
|
|
58
|
+
/** Cache override; `null` forces an in-memory cache. */
|
|
59
|
+
cache?: ResponseCache | null;
|
|
60
|
+
/** Environment used for trigger secrets. Defaults to `process.env`. */
|
|
61
|
+
env?: TriggerEnv;
|
|
62
|
+
logger?: Logger;
|
|
63
|
+
now?: () => number;
|
|
64
|
+
plugins?: readonly LoomPlugin[];
|
|
65
|
+
signal?: AbortSignal;
|
|
66
|
+
concurrency?: number;
|
|
67
|
+
tolerateErrors?: boolean;
|
|
68
|
+
/** Open the store for writing (default true). */
|
|
69
|
+
createStore?: boolean;
|
|
70
|
+
};
|
|
71
|
+
export type LoomSyncOptions = {
|
|
72
|
+
dryRun?: boolean;
|
|
73
|
+
dispatch?: boolean;
|
|
74
|
+
allowMissingTriggers?: boolean;
|
|
75
|
+
signal?: AbortSignal;
|
|
76
|
+
env?: TriggerEnv;
|
|
77
|
+
/** Cross-process store lock. Defaults to true unless dryRun. */
|
|
78
|
+
lock?: boolean;
|
|
79
|
+
tolerateErrors?: boolean;
|
|
80
|
+
concurrency?: number;
|
|
81
|
+
};
|
|
82
|
+
export type SiteExportOptions = SiteModuleOptions & {
|
|
83
|
+
/** `json` (default) returns the canonical wire record; `ts` a typed module. */
|
|
84
|
+
format?: "json" | "ts";
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* A stateful Loom instance. It owns nothing global: two instances with two
|
|
88
|
+
* stores can run in one process. `close()` aborts in-flight work and drains the
|
|
89
|
+
* store lock, so a server can shut down deterministically.
|
|
90
|
+
*/
|
|
91
|
+
export declare class Loom {
|
|
92
|
+
#private;
|
|
93
|
+
readonly config: LoomConfig;
|
|
94
|
+
readonly store: SnapshotStore;
|
|
95
|
+
private constructor();
|
|
96
|
+
/**
|
|
97
|
+
* Resolve a config from a path, a raw object, or nothing (defaults), then
|
|
98
|
+
* open its store. `input` may be a `LoomConfig`, a raw config object, or a
|
|
99
|
+
* path; `undefined` uses `loom.config.json` when present.
|
|
100
|
+
*/
|
|
101
|
+
static open(input?: LoomConfig | Record<string, unknown> | string | null, options?: LoomOptions): Promise<Loom>;
|
|
102
|
+
/** Wrap an already-opened store (used by the CLI). */
|
|
103
|
+
static attach(config: LoomConfig, store: SnapshotStore, options?: LoomOptions): Loom;
|
|
104
|
+
get closed(): boolean;
|
|
105
|
+
/** Effective token: explicit option, then the configured env var. Never logged. */
|
|
106
|
+
get token(): string | null;
|
|
107
|
+
/** Subscribe to sync lifecycle events. Returns an unsubscribe function. */
|
|
108
|
+
subscribe(listener: LoomListener): () => void;
|
|
109
|
+
/** Add a plugin after construction; returns the instance for chaining. */
|
|
110
|
+
use(plugin: LoomPlugin): this;
|
|
111
|
+
/** Discover public repositories for `config.discovery.owners` without committing. */
|
|
112
|
+
discover(options?: {
|
|
113
|
+
signal?: AbortSignal;
|
|
114
|
+
}): Promise<DiscoveryResult>;
|
|
115
|
+
/**
|
|
116
|
+
* One synchronisation. Reads public state, diffs it against the committed
|
|
117
|
+
* head, commits only on change, and dispatches the durable outbox. Plugins
|
|
118
|
+
* and subscribers observe the outcome before the promise resolves.
|
|
119
|
+
*/
|
|
120
|
+
sync(options?: LoomSyncOptions): Promise<SyncOutcome>;
|
|
121
|
+
/** Compute the current snapshot without committing it. */
|
|
122
|
+
snapshot(): Promise<Snapshot>;
|
|
123
|
+
/** Diff the committed head against another snapshot, or the committed state against a fresh read. */
|
|
124
|
+
diff(options?: {
|
|
125
|
+
from?: Snapshot | null;
|
|
126
|
+
to?: Snapshot;
|
|
127
|
+
}): Promise<DiffResult>;
|
|
128
|
+
/** Build the site record from a snapshot (defaults to the committed head). */
|
|
129
|
+
siteRecord(snapshot?: Snapshot): Promise<SiteRecord>;
|
|
130
|
+
/** Render the typed website module from a record. */
|
|
131
|
+
siteModule(options?: SiteModuleOptions): Promise<string>;
|
|
132
|
+
/** Content address of the site record, usable as a cache/deploy key. */
|
|
133
|
+
siteDigest(): Promise<string>;
|
|
134
|
+
/**
|
|
135
|
+
* Open the signed-webhook receiver for this store. The secret comes from the
|
|
136
|
+
* configured environment variable unless `secret` is given explicitly.
|
|
137
|
+
*/
|
|
138
|
+
receiver(options?: {
|
|
139
|
+
secret?: string;
|
|
140
|
+
secrets?: string[];
|
|
141
|
+
}): Promise<WebhookReceiver>;
|
|
142
|
+
/** Verify a raw webhook request against the configured secret. */
|
|
143
|
+
verifyWebhook(input: WebhookInput, options?: {
|
|
144
|
+
secret?: string;
|
|
145
|
+
}): Promise<WebhookDecision>;
|
|
146
|
+
/** Abort in-flight work and wait for it to settle. Idempotent. */
|
|
147
|
+
close(): Promise<void>;
|
|
148
|
+
/** Alias for `close()` used by servers that drain before exiting. */
|
|
149
|
+
drain(): Promise<void>;
|
|
150
|
+
/** Programmatic errors, mirrors `SnapshotError`. */
|
|
151
|
+
static describeError(error: unknown): SnapshotError | {
|
|
152
|
+
code: string;
|
|
153
|
+
message: string;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/** Convenience constructor: `createLoom(config, options)`. */
|
|
157
|
+
export declare function createLoom(input?: LoomConfig | Record<string, unknown> | string | null, options?: LoomOptions): Promise<Loom>;
|
|
158
|
+
/** A ready-made GitHub client for callers that only need raw reads. */
|
|
159
|
+
export declare function createGitHubClient(config: LoomConfig, options?: Omit<LoomOptions, "config">): GitHubClient;
|
|
160
|
+
/** Exported so consumers can type their own collection policy. */
|
|
161
|
+
export type { CollectConfig, LoomConfig };
|
|
162
|
+
/** Error classes a consumer may catch. */
|
|
163
|
+
export { LoomError };
|
|
164
|
+
/** Recognised config schemas, for forward-compatible consumers. */
|
|
165
|
+
export declare const SUPPORTED_CONFIG_SCHEMAS: readonly string[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret-shaped strings never belong in a public snapshot. Loom refuses to
|
|
3
|
+
* write a blob that matches a credential pattern, and `verify` re-scans the
|
|
4
|
+
* whole store. Reports name the pattern and offset only: the match itself is
|
|
5
|
+
* never echoed into logs.
|
|
6
|
+
*/
|
|
7
|
+
export type SecretPattern = {
|
|
8
|
+
name: string;
|
|
9
|
+
pattern: RegExp;
|
|
10
|
+
};
|
|
11
|
+
export declare const SECRET_PATTERNS: readonly SecretPattern[];
|
|
12
|
+
export type SecretMatch = {
|
|
13
|
+
pattern: string;
|
|
14
|
+
offset: number;
|
|
15
|
+
};
|
|
16
|
+
/** Pattern names and offsets, never the matched text. */
|
|
17
|
+
export declare function findSecrets(text: string): SecretMatch[];
|
|
18
|
+
/** Redact a URL for logs, keeping the origin and the path shape only. */
|
|
19
|
+
export declare function redactUrl(raw: string): string;
|
|
20
|
+
/** Redact a token for logs: keep a 4-character prefix, drop the rest. */
|
|
21
|
+
export declare function redactToken(token: string | null | undefined): string;
|
|
22
|
+
/**
|
|
23
|
+
* Replace credential-shaped substrings in free text (error messages, logs).
|
|
24
|
+
* The replacement names the pattern only; the matched bytes never survive.
|
|
25
|
+
*/
|
|
26
|
+
export declare function redactText(text: string): string;
|
|
27
|
+
/** Redact every string value of a log detail object, recursively. */
|
|
28
|
+
export declare function redactDetail(value: unknown, depth?: number): unknown;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { LoomConfig } from "./config.js";
|
|
2
|
+
import type { SnapshotStore } from "./store.js";
|
|
3
|
+
import type { SyncOutcome } from "./pipeline.js";
|
|
4
|
+
import { Metrics } from "./metrics.js";
|
|
5
|
+
import { SyncQueue, type QueueStats } from "./queue.js";
|
|
6
|
+
import type { WebhookDecision, WebhookReceiver } from "./webhook/receiver.js";
|
|
7
|
+
export declare const WEBHOOK_RESPONSE_SCHEMA = "loom/webhook-response@1";
|
|
8
|
+
export type ServeHandlerDeps = {
|
|
9
|
+
receiver: WebhookReceiver;
|
|
10
|
+
config: LoomConfig;
|
|
11
|
+
store: SnapshotStore;
|
|
12
|
+
onSync: (decision: WebhookDecision) => Promise<SyncOutcome>;
|
|
13
|
+
/** Reconciliation poll; when set, runs on `config.serve.pollIntervalSeconds`. */
|
|
14
|
+
onPoll?: () => Promise<SyncOutcome>;
|
|
15
|
+
logger?: (message: string, detail?: Record<string, unknown>) => void;
|
|
16
|
+
now?: () => number;
|
|
17
|
+
metrics?: Metrics;
|
|
18
|
+
/** Inject a queue for tests; otherwise one is created from config. */
|
|
19
|
+
queue?: SyncQueue;
|
|
20
|
+
};
|
|
21
|
+
export type ServeHandler = ((request: Request) => Promise<Response>) & {
|
|
22
|
+
readonly metrics: Metrics;
|
|
23
|
+
readonly queue: SyncQueue;
|
|
24
|
+
drain: (timeoutMs?: number) => Promise<{
|
|
25
|
+
drained: boolean;
|
|
26
|
+
stats: QueueStats;
|
|
27
|
+
}>;
|
|
28
|
+
close: () => void;
|
|
29
|
+
stats: () => {
|
|
30
|
+
queue: QueueStats;
|
|
31
|
+
startedAt: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* HTTP surface of `loom serve`:
|
|
36
|
+
* GET /healthz liveness, current snapshot, queue depth
|
|
37
|
+
* GET /readyz readiness; 503 while draining or when the store is unreadable
|
|
38
|
+
* GET /state manifest summary
|
|
39
|
+
* GET /metrics Prometheus text
|
|
40
|
+
* POST <webhook> verify -> dedupe -> enqueue -> serial sync -> trigger
|
|
41
|
+
*
|
|
42
|
+
* Webhooks return 202 once the sync is accepted by the queue. Backpressure is
|
|
43
|
+
* explicit: a full queue answers 503 with Retry-After so GitHub retries later
|
|
44
|
+
* instead of the process accumulating unbounded work.
|
|
45
|
+
*/
|
|
46
|
+
export declare function createHandler(deps: ServeHandlerDeps): ServeHandler;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA-256 with no runtime dependency.
|
|
3
|
+
*
|
|
4
|
+
* Loom addresses snapshots, site records, and objects by SHA-256. The data path
|
|
5
|
+
* has to produce the same bytes in a browser, in Bun, and in Node, so the
|
|
6
|
+
* digest is implemented here instead of importing `node:crypto`. The output is
|
|
7
|
+
* byte-identical to the platform implementation; `tests/digest.test.ts` checks
|
|
8
|
+
* that against `node:crypto` on every run.
|
|
9
|
+
*/
|
|
10
|
+
/** SHA-256 of a byte sequence, as 32 bytes. */
|
|
11
|
+
export declare function sha256Bytes(input: Uint8Array): Uint8Array;
|
|
12
|
+
/** Lowercase hex SHA-256 of a UTF-8 string or a byte sequence. */
|
|
13
|
+
export declare function sha256Hex(input: string | Uint8Array): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SiteRecord } from "./site.js";
|
|
2
|
+
export type CuratedValue = string | number | boolean | null | string[];
|
|
3
|
+
export type CuratedEntry = Record<string, CuratedValue>;
|
|
4
|
+
export type SiteModuleOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Import specifier for the SDK types. Defaults to the published package.
|
|
7
|
+
* Pass `"none"` (or `null`) to emit the types locally so the module needs no
|
|
8
|
+
* `@sifr-dev/loom` install - the supported mode for a deployed site.
|
|
9
|
+
*/
|
|
10
|
+
packageName?: string | null;
|
|
11
|
+
/** Curated enrichment keyed by project id (case-insensitive). */
|
|
12
|
+
curated?: Record<string, CuratedEntry>;
|
|
13
|
+
/** Name of the generated module's banner source line. */
|
|
14
|
+
generatedBy?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Render the typed module. `PROJECTS` carries generic discovered data only;
|
|
18
|
+
* `CURATED` is optional, keyed by id, and never required for a project to
|
|
19
|
+
* render. `enrich()` is the only merge the site needs.
|
|
20
|
+
*/
|
|
21
|
+
export declare function renderSiteModule(record: SiteRecord, options?: SiteModuleOptions): string;
|
|
22
|
+
/** Stable content address helper for tests and cache keys. */
|
|
23
|
+
export declare function siteModuleDigest(record: SiteRecord, options?: SiteModuleOptions): string;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { RepoSnapshot, Snapshot, SnapshotError } from "./types.js";
|
|
2
|
+
export declare const SITE_SCHEMA = "loom/site@1";
|
|
3
|
+
export type SiteRelease = {
|
|
4
|
+
tag: string;
|
|
5
|
+
name: string | null;
|
|
6
|
+
publishedAt: string | null;
|
|
7
|
+
prerelease: boolean;
|
|
8
|
+
url: string | null;
|
|
9
|
+
};
|
|
10
|
+
export type SiteHead = {
|
|
11
|
+
sha: string;
|
|
12
|
+
shortSha: string;
|
|
13
|
+
message: string;
|
|
14
|
+
author: string | null;
|
|
15
|
+
committedAt: string | null;
|
|
16
|
+
url: string;
|
|
17
|
+
};
|
|
18
|
+
export type SiteReadme = {
|
|
19
|
+
path: string;
|
|
20
|
+
sha: string;
|
|
21
|
+
size: number;
|
|
22
|
+
htmlUrl: string | null;
|
|
23
|
+
downloadUrl: string | null;
|
|
24
|
+
excerpt: string | null;
|
|
25
|
+
};
|
|
26
|
+
export type SiteBranch = {
|
|
27
|
+
name: string;
|
|
28
|
+
sha: string;
|
|
29
|
+
shortSha: string;
|
|
30
|
+
protected: boolean;
|
|
31
|
+
default: boolean;
|
|
32
|
+
};
|
|
33
|
+
export type SiteComment = {
|
|
34
|
+
id: number | string;
|
|
35
|
+
body: string;
|
|
36
|
+
author: string | null;
|
|
37
|
+
createdAt: string | null;
|
|
38
|
+
url: string | null;
|
|
39
|
+
};
|
|
40
|
+
export type SiteWorkflow = {
|
|
41
|
+
id: number | string;
|
|
42
|
+
name: string;
|
|
43
|
+
path: string;
|
|
44
|
+
state: string;
|
|
45
|
+
};
|
|
46
|
+
export type SiteCi = {
|
|
47
|
+
workflow: string | null;
|
|
48
|
+
runId: number | string;
|
|
49
|
+
status: string | null;
|
|
50
|
+
conclusion: string | null;
|
|
51
|
+
branch: string | null;
|
|
52
|
+
sha: string | null;
|
|
53
|
+
shortSha: string | null;
|
|
54
|
+
url: string | null;
|
|
55
|
+
updatedAt: string | null;
|
|
56
|
+
};
|
|
57
|
+
export type SiteProject = {
|
|
58
|
+
/** Stable key: `owner/name` lowercased. */
|
|
59
|
+
id: string;
|
|
60
|
+
/** URL-safe leaf name, `owner` + `name` fields. */
|
|
61
|
+
slug: string;
|
|
62
|
+
owner: string;
|
|
63
|
+
name: string;
|
|
64
|
+
fullName: string;
|
|
65
|
+
description: string | null;
|
|
66
|
+
homepage: string | null;
|
|
67
|
+
topics: string[];
|
|
68
|
+
language: string | null;
|
|
69
|
+
/** Sorted by bytes descending, then name, so the site needs no ordering logic. */
|
|
70
|
+
languages: {
|
|
71
|
+
name: string;
|
|
72
|
+
bytes: number;
|
|
73
|
+
}[];
|
|
74
|
+
license: string | null;
|
|
75
|
+
stars: number;
|
|
76
|
+
forks: number;
|
|
77
|
+
watchers: number;
|
|
78
|
+
openIssues: number;
|
|
79
|
+
archived: boolean;
|
|
80
|
+
fork: boolean;
|
|
81
|
+
defaultBranch: string;
|
|
82
|
+
htmlUrl: string;
|
|
83
|
+
createdAt: string | null;
|
|
84
|
+
updatedAt: string | null;
|
|
85
|
+
pushedAt: string | null;
|
|
86
|
+
/** Newest non-draft release, or null. */
|
|
87
|
+
release: SiteRelease | null;
|
|
88
|
+
/** Every exported release, newest first. */
|
|
89
|
+
releases: SiteRelease[];
|
|
90
|
+
head: SiteHead | null;
|
|
91
|
+
/** Present only when the snapshot collected README state. */
|
|
92
|
+
readme?: SiteReadme | null;
|
|
93
|
+
/** Present only when the snapshot collected branches. */
|
|
94
|
+
branches?: SiteBranch[];
|
|
95
|
+
/** Present only when the snapshot collected commit comments. */
|
|
96
|
+
commitComments?: SiteComment[];
|
|
97
|
+
/** Present only when the snapshot collected issue/PR comments. */
|
|
98
|
+
issueComments?: SiteComment[];
|
|
99
|
+
/** Present only when the snapshot collected workflow definitions. */
|
|
100
|
+
workflows?: SiteWorkflow[];
|
|
101
|
+
/** Latest CI run on the default branch, when collected. */
|
|
102
|
+
ci?: SiteCi | null;
|
|
103
|
+
};
|
|
104
|
+
export type SiteRecord = {
|
|
105
|
+
schema: typeof SITE_SCHEMA;
|
|
106
|
+
/** Content address of the snapshot this record was derived from. */
|
|
107
|
+
snapshot: string;
|
|
108
|
+
/** False when some configured repository had no data (partial failure). */
|
|
109
|
+
complete: boolean;
|
|
110
|
+
/** Stable ordering by project id. */
|
|
111
|
+
projects: SiteProject[];
|
|
112
|
+
/** Old repository id -> current id, resolved through alias chains. */
|
|
113
|
+
aliases: {
|
|
114
|
+
from: string;
|
|
115
|
+
to: string;
|
|
116
|
+
}[];
|
|
117
|
+
/** Old owner login -> current login, applied before repository aliases. */
|
|
118
|
+
ownerAliases: {
|
|
119
|
+
from: string;
|
|
120
|
+
to: string;
|
|
121
|
+
}[];
|
|
122
|
+
/** Errors are metadata, never rendered as projects. */
|
|
123
|
+
errors: SnapshotError[];
|
|
124
|
+
};
|
|
125
|
+
export type SiteRecordOptions = {
|
|
126
|
+
/** Config alias table, so a renamed project keeps a stable consumer mapping. */
|
|
127
|
+
aliases?: Record<string, string>;
|
|
128
|
+
/** Owner alias table, so an account rename canonicalises every project. */
|
|
129
|
+
ownerAliases?: Record<string, string>;
|
|
130
|
+
};
|
|
131
|
+
export declare function siteProject(repo: RepoSnapshot, ownerAliases?: Record<string, string>): SiteProject;
|
|
132
|
+
/** Build the site record. No timestamps of its own: same snapshot, same bytes. */
|
|
133
|
+
export declare function buildSiteRecord(snapshot: Snapshot, options?: SiteRecordOptions): SiteRecord;
|
|
134
|
+
/** Content address of the record, useful as a cache key or deploy dedupe token. */
|
|
135
|
+
export declare function siteDigest(record: SiteRecord): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type SnapshotPayload, type SnapshotStats, type Snapshot } from "./types.js";
|
|
2
|
+
declare function byCodeUnit(a: string, b: string): number;
|
|
3
|
+
/**
|
|
4
|
+
* Force a payload into its canonical shape: repositories and releases sorted by
|
|
5
|
+
* stable ids, topics and error lists sorted, duplicate repos collapsed. The
|
|
6
|
+
* digest is taken over the result, so input order never changes the snapshot id.
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeSnapshot(payload: SnapshotPayload): SnapshotPayload;
|
|
9
|
+
/** Normalise a payload and compute its content address. */
|
|
10
|
+
export declare function buildSnapshot(payload: SnapshotPayload): Snapshot;
|
|
11
|
+
/** Recompute the id of an already-normalised payload. */
|
|
12
|
+
export declare function snapshotId(payload: SnapshotPayload): string;
|
|
13
|
+
export declare function snapshotSummary(payload: SnapshotPayload): SnapshotStats;
|
|
14
|
+
/** Look up a repository by case-insensitive id. */
|
|
15
|
+
export declare function findRepo(payload: SnapshotPayload, repo: string): SnapshotPayload["repos"][number] | null;
|
|
16
|
+
export { byCodeUnit };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { DiffResult } from "./diff.js";
|
|
2
|
+
import { type Snapshot, type SnapshotSource, type SnapshotStats } from "./types.js";
|
|
3
|
+
export declare const MANIFEST_SCHEMA = "loom/manifest@1";
|
|
4
|
+
export declare const OUTBOX_SCHEMA = "loom/outbox@1";
|
|
5
|
+
export declare const STORE_VERSION = 1;
|
|
6
|
+
export type Manifest = {
|
|
7
|
+
schema: typeof MANIFEST_SCHEMA;
|
|
8
|
+
/** Content address of the current snapshot payload. */
|
|
9
|
+
snapshot: string;
|
|
10
|
+
/** ISO timestamp of the commit that made this snapshot current. */
|
|
11
|
+
createdAt: string;
|
|
12
|
+
stats: SnapshotStats;
|
|
13
|
+
source: SnapshotSource;
|
|
14
|
+
};
|
|
15
|
+
export type VerifyCheck = {
|
|
16
|
+
name: string;
|
|
17
|
+
ok: boolean;
|
|
18
|
+
detail: string;
|
|
19
|
+
};
|
|
20
|
+
export type VerifyReport = {
|
|
21
|
+
schema: "loom/verify@1";
|
|
22
|
+
ok: boolean;
|
|
23
|
+
snapshot: string | null;
|
|
24
|
+
objects: number;
|
|
25
|
+
checks: VerifyCheck[];
|
|
26
|
+
problems: string[];
|
|
27
|
+
};
|
|
28
|
+
export type CommitMeta = {
|
|
29
|
+
createdAt?: string;
|
|
30
|
+
source: SnapshotSource;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Durable dispatch outbox. A snapshot is committed before any trigger runs, so
|
|
34
|
+
* a crash between the two must not lose the deploy. The outbox holds the diff
|
|
35
|
+
* that still needs dispatching; it is cleared only after every trigger
|
|
36
|
+
* acknowledges, and a replay carries the snapshot id as an idempotency key.
|
|
37
|
+
*/
|
|
38
|
+
export type Outbox = {
|
|
39
|
+
schema: typeof OUTBOX_SCHEMA;
|
|
40
|
+
snapshot: string;
|
|
41
|
+
previous: string | null;
|
|
42
|
+
createdAt: string;
|
|
43
|
+
attempts: number;
|
|
44
|
+
nextAttemptAt: string;
|
|
45
|
+
diff: DiffResult;
|
|
46
|
+
};
|
|
47
|
+
export type RecoveryReport = {
|
|
48
|
+
tempFilesRemoved: number;
|
|
49
|
+
quarantined: string[];
|
|
50
|
+
warnings: string[];
|
|
51
|
+
};
|
|
52
|
+
export type StoreLock = {
|
|
53
|
+
path: string;
|
|
54
|
+
release: () => Promise<void>;
|
|
55
|
+
};
|
|
56
|
+
export type PutResult = {
|
|
57
|
+
digest: string;
|
|
58
|
+
path: string;
|
|
59
|
+
created: boolean;
|
|
60
|
+
bytes: number;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Content-addressed store.
|
|
64
|
+
*
|
|
65
|
+
* `objects/<2 hex>/<62 hex>.json` holds canonical JSON bytes named by their
|
|
66
|
+
* own SHA-256. `manifest.json` is the only pointer and is replaced atomically,
|
|
67
|
+
* so a reader sees either the previous snapshot or the next one, never a mix.
|
|
68
|
+
*/
|
|
69
|
+
export declare class SnapshotStore {
|
|
70
|
+
readonly root: string;
|
|
71
|
+
/** Non-fatal recovery notes produced while reading this store. */
|
|
72
|
+
readonly warnings: string[];
|
|
73
|
+
private constructor();
|
|
74
|
+
static open(root: string, options?: {
|
|
75
|
+
create?: boolean;
|
|
76
|
+
}): Promise<SnapshotStore>;
|
|
77
|
+
get objectsDir(): string;
|
|
78
|
+
get manifestPath(): string;
|
|
79
|
+
get cachePath(): string;
|
|
80
|
+
get webhookStatePath(): string;
|
|
81
|
+
get outboxPath(): string;
|
|
82
|
+
get lockPath(): string;
|
|
83
|
+
get sitePath(): string;
|
|
84
|
+
objectPath(digest: string): string;
|
|
85
|
+
has(digest: string): Promise<boolean>;
|
|
86
|
+
/** Write a JSON value as a canonical blob. Identical values dedupe by address. */
|
|
87
|
+
put(value: unknown): Promise<PutResult>;
|
|
88
|
+
get<T>(digest: string): Promise<T>;
|
|
89
|
+
getSnapshot(digest: string): Promise<Snapshot>;
|
|
90
|
+
readManifest(): Promise<Manifest | null>;
|
|
91
|
+
/** Read the current snapshot, or null when the store is empty. */
|
|
92
|
+
head(): Promise<Snapshot | null>;
|
|
93
|
+
readOutbox(): Promise<Outbox | null>;
|
|
94
|
+
writeOutbox(outbox: Outbox): Promise<void>;
|
|
95
|
+
clearOutbox(): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Single-writer lock. Multiple Loom processes against one store would race
|
|
98
|
+
* the manifest and the outbox; a stale lock from a killed process is taken
|
|
99
|
+
* over after `staleMs` so a crash does not require manual cleanup.
|
|
100
|
+
*/
|
|
101
|
+
acquireLock(options?: {
|
|
102
|
+
staleMs?: number;
|
|
103
|
+
now?: () => number;
|
|
104
|
+
}): Promise<StoreLock>;
|
|
105
|
+
/**
|
|
106
|
+
* Crash debris cleanup: temp files from interrupted atomic writes and
|
|
107
|
+
* unreadable cache/outbox files. Never deletes a content-addressed object.
|
|
108
|
+
*/
|
|
109
|
+
recover(): Promise<RecoveryReport>;
|
|
110
|
+
/**
|
|
111
|
+
* Make a snapshot current. Re-committing the snapshot that is already current
|
|
112
|
+
* is a no-op: the manifest and its `createdAt` stay untouched.
|
|
113
|
+
*/
|
|
114
|
+
commit(snapshot: Snapshot, meta: CommitMeta): Promise<Manifest>;
|
|
115
|
+
/** All digests present in the store, sorted. */
|
|
116
|
+
listDigests(): Promise<string[]>;
|
|
117
|
+
/** Recompute every address, re-serialise every blob, and re-check the manifest. */
|
|
118
|
+
verify(): Promise<VerifyReport>;
|
|
119
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { TriggerConfig } from "./config.js";
|
|
2
|
+
import type { DiffResult } from "./diff.js";
|
|
3
|
+
import type { FetchLike } from "./github/client.js";
|
|
4
|
+
export declare const TRIGGER_SCHEMA = "loom/trigger@1";
|
|
5
|
+
export declare const TRIGGER_EVENT_HEADER = "X-Loom-Event";
|
|
6
|
+
export declare const TRIGGER_SIGNATURE_HEADER = "X-Loom-Signature-256";
|
|
7
|
+
export declare const TRIGGER_DELIVERY_HEADER = "X-Loom-Delivery";
|
|
8
|
+
export declare const TRIGGER_ATTEMPT_HEADER = "X-Loom-Attempt";
|
|
9
|
+
export type TriggerEnv = Record<string, string | undefined>;
|
|
10
|
+
export type TriggerContext = {
|
|
11
|
+
diff: DiffResult;
|
|
12
|
+
env?: TriggerEnv;
|
|
13
|
+
dryRun: boolean;
|
|
14
|
+
fetch?: FetchLike;
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
/** Stable per-snapshot key so a consumer can make dispatches idempotent. */
|
|
17
|
+
idempotencyKey?: string;
|
|
18
|
+
attempt?: number;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
logger?: (message: string, detail?: Record<string, unknown>) => void;
|
|
21
|
+
};
|
|
22
|
+
export type TriggerPlan = {
|
|
23
|
+
index: number;
|
|
24
|
+
kind: TriggerConfig["kind"];
|
|
25
|
+
/** Real URL. Never logged; use `publicPlan` when reporting. */
|
|
26
|
+
url: string | null;
|
|
27
|
+
/** Redacted target, safe to log and serialise. */
|
|
28
|
+
target: string;
|
|
29
|
+
method: "POST";
|
|
30
|
+
headers: Record<string, string>;
|
|
31
|
+
body: string | null;
|
|
32
|
+
/** Environment variable that must be set; when missing the trigger cannot run. */
|
|
33
|
+
requiresEnv: string | null;
|
|
34
|
+
ready: boolean;
|
|
35
|
+
skipReason: string | null;
|
|
36
|
+
};
|
|
37
|
+
export type PublicTriggerPlan = Omit<TriggerPlan, "url">;
|
|
38
|
+
export type TriggerResult = {
|
|
39
|
+
index: number;
|
|
40
|
+
kind: TriggerConfig["kind"];
|
|
41
|
+
target: string;
|
|
42
|
+
ok: boolean;
|
|
43
|
+
status: number | null;
|
|
44
|
+
dryRun: boolean;
|
|
45
|
+
skipped: boolean;
|
|
46
|
+
error: string | null;
|
|
47
|
+
};
|
|
48
|
+
/** Strip the secret-bearing URL from a plan before it is printed. */
|
|
49
|
+
export declare function publicPlan(plan: TriggerPlan): PublicTriggerPlan;
|
|
50
|
+
export declare function triggerPayload(diff: DiffResult, context?: Partial<TriggerContext>): Record<string, unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* Resolve triggers into concrete requests without performing them. Secrets are
|
|
53
|
+
* read from the environment by name and never copied into the returned plan.
|
|
54
|
+
*/
|
|
55
|
+
export declare function planTriggers(configs: readonly TriggerConfig[], context: TriggerContext): TriggerPlan[];
|
|
56
|
+
/** Execute a plan. In dry-run mode nothing leaves the process. */
|
|
57
|
+
export declare function dispatchPlan(plans: readonly TriggerPlan[], context: TriggerContext): Promise<TriggerResult[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Run every configured trigger. Dry-run plans are reported but never sent.
|
|
60
|
+
* A missing secret is a hard error unless `allowMissing` is set.
|
|
61
|
+
*/
|
|
62
|
+
export declare function dispatchTriggers(configs: readonly TriggerConfig[], context: TriggerContext & {
|
|
63
|
+
allowMissing?: boolean;
|
|
64
|
+
}): Promise<{
|
|
65
|
+
plans: PublicTriggerPlan[];
|
|
66
|
+
results: TriggerResult[];
|
|
67
|
+
}>;
|