@vercel/factory 0.0.3 → 0.0.4
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/dist/approval-h5aj8HYN.d.mts +510 -0
- package/dist/blob/index.d.mts +32 -0
- package/dist/blob/index.mjs +141 -0
- package/dist/blob/index.mjs.map +1 -0
- package/dist/connectors/index.d.mts +2 -0
- package/dist/connectors/index.mjs +49 -0
- package/dist/connectors/index.mjs.map +1 -0
- package/dist/driver-Bbd25rNM.mjs +23 -0
- package/dist/driver-Bbd25rNM.mjs.map +1 -0
- package/dist/driver-CrZsy7sm.d.mts +34 -0
- package/dist/eve/index.d.mts +1057 -0
- package/dist/eve/index.mjs +777 -0
- package/dist/eve/index.mjs.map +1 -0
- package/dist/github-5qQPCaXj.d.mts +123 -0
- package/dist/github.d.mts +2 -0
- package/dist/github.mjs +286 -0
- package/dist/github.mjs.map +1 -0
- package/dist/id-DwCihQr4.mjs +31 -0
- package/dist/id-DwCihQr4.mjs.map +1 -0
- package/dist/index-WNGZJRRH.d.mts +67 -0
- package/dist/index.d.mts +175 -0
- package/dist/index.mjs +882 -0
- package/dist/index.mjs.map +1 -0
- package/dist/next-page.d.mts +5 -0
- package/dist/next-page.mjs +71 -0
- package/dist/next-page.mjs.map +1 -0
- package/dist/next.d.mts +12 -0
- package/dist/{next.js → next.mjs} +13 -14
- package/dist/next.mjs.map +1 -0
- package/dist/postgres/index.d.mts +137 -0
- package/dist/postgres/index.mjs +96 -0
- package/dist/postgres/index.mjs.map +1 -0
- package/dist/signal-CHVEmzvI.d.mts +59 -0
- package/dist/task-Cj7Ei9Nh.mjs +336 -0
- package/dist/task-Cj7Ei9Nh.mjs.map +1 -0
- package/package.json +25 -22
- package/dist/approval-Z7iaWibT.d.ts +0 -541
- package/dist/blob/index.d.ts +0 -26
- package/dist/blob/index.js +0 -127
- package/dist/blob/index.js.map +0 -1
- package/dist/chunk-2JFES6BA.js +0 -41
- package/dist/chunk-2JFES6BA.js.map +0 -1
- package/dist/chunk-CEF6VJZC.js +0 -28
- package/dist/chunk-CEF6VJZC.js.map +0 -1
- package/dist/chunk-D2XMABG4.js +0 -311
- package/dist/chunk-D2XMABG4.js.map +0 -1
- package/dist/chunk-EFL4PDDE.js +0 -325
- package/dist/chunk-EFL4PDDE.js.map +0 -1
- package/dist/common-CaHaEOAS.d.ts +0 -18
- package/dist/connectors/index.d.ts +0 -53
- package/dist/connectors/index.js +0 -64
- package/dist/connectors/index.js.map +0 -1
- package/dist/driver-tRNggCCJ.d.ts +0 -32
- package/dist/eve/index.d.ts +0 -1053
- package/dist/eve/index.js +0 -752
- package/dist/eve/index.js.map +0 -1
- package/dist/github.d.ts +0 -139
- package/dist/github.js +0 -27
- package/dist/github.js.map +0 -1
- package/dist/index.d.ts +0 -164
- package/dist/index.js +0 -940
- package/dist/index.js.map +0 -1
- package/dist/next-page.d.ts +0 -5
- package/dist/next-page.js +0 -75
- package/dist/next-page.js.map +0 -1
- package/dist/next.d.ts +0 -12
- package/dist/next.js.map +0 -1
- package/dist/postgres/index.d.ts +0 -137
- package/dist/postgres/index.js +0 -118
- package/dist/postgres/index.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/blob/index.ts"],"sourcesContent":["import { get, list, put } from \"@vercel/blob\";\nimport {\n RecordExistsError,\n RecordNotFoundError,\n VersionConflictError,\n type CollectionName,\n type StoredEntry,\n type StoreDriver,\n} from \"../store/driver\";\n\nexport interface BlobObject {\n body: string;\n etag: string;\n}\n\n/** The narrow blob operations the driver needs; injectable for tests. */\nexport interface BlobClient {\n /** Must return the latest content, never a cached copy. */\n read(pathname: string): Promise<BlobObject | null>;\n /** Must reject if overwrite is false and the path exists, or if ifMatch is given and the ETag differs. */\n write(pathname: string, body: string, overwrite: boolean, ifMatch?: string): Promise<void>;\n listPaths(prefix: string): Promise<string[]>;\n}\n\n// @vercel/blob throws BlobNotFoundError with the message\n// \"Vercel Blob: The requested blob does not exist\".\nfunction isNotFoundError(error: unknown): boolean {\n return (\n error instanceof Error &&\n (error.name === \"BlobNotFoundError\" ||\n /does not exist|not.?found|404/iu.test(error.message))\n );\n}\n\nfunction isAlreadyExistsError(error: unknown): boolean {\n return (\n error instanceof Error &&\n /already exists|not allowed to overwrite|overwrite/iu.test(error.message)\n );\n}\n\n// @vercel/blob throws BlobPreconditionFailedError when ifMatch does not hold.\nfunction isPreconditionError(error: unknown): boolean {\n return (\n error instanceof Error &&\n (error.name === \"BlobPreconditionFailedError\" || /precondition|etag|412/iu.test(error.message))\n );\n}\n\nexport const vercelBlobClient: BlobClient = {\n async read(pathname) {\n let result;\n try {\n // Uncached: the ledger is read-modify-write and must see the latest version.\n result = await get(pathname, { access: \"private\", useCache: false });\n } catch (error) {\n if (isNotFoundError(error)) {\n return null;\n }\n throw error;\n }\n if (result === null || result.stream === null) {\n return null;\n }\n return { body: await new Response(result.stream).text(), etag: result.blob.etag };\n },\n\n async write(pathname, body, overwrite, ifMatch) {\n await put(pathname, body, {\n access: \"private\",\n allowOverwrite: overwrite,\n contentType: \"application/json\",\n ...(ifMatch === undefined ? {} : { ifMatch }),\n });\n },\n\n async listPaths(prefix) {\n const paths: string[] = [];\n let cursor: string | undefined;\n do {\n const page = await list({ prefix, cursor, limit: 1000 });\n paths.push(...page.blobs.map((blob) => blob.pathname));\n cursor = page.hasMore ? page.cursor : undefined;\n } while (cursor !== undefined);\n return paths;\n },\n};\n\nexport interface BlobDriverOptions {\n client?: BlobClient;\n /** Path prefix inside the blob store; defaults to \"factory\". */\n prefix?: string;\n}\n\n/**\n * Store driver on Vercel Blob: durable and dependency-free (one Blob store on\n * the project, no database). Inserts and receipts are exactly as safe as on\n * Postgres (create-if-absent is atomic). Updates read the latest content,\n * bypassing Blob's CDN cache, and write with an ETag precondition, so a\n * writer that lost a race gets a VersionConflictError rather than\n * overwriting the winner.\n */\nexport function createBlobDriver(options: BlobDriverOptions = {}): StoreDriver {\n const client = options.client ?? vercelBlobClient;\n const prefix = options.prefix ?? \"factory\";\n\n function pathFor(collection: CollectionName, id: string): string {\n return `${prefix}/${collection}/${id}.json`;\n }\n\n async function readRecord(\n collection: CollectionName,\n id: string,\n ): Promise<{ value: unknown; version: number; etag: string } | null> {\n let object: BlobObject | null;\n try {\n object = await client.read(pathFor(collection, id));\n } catch (error) {\n if (isNotFoundError(error)) {\n return null;\n }\n throw error;\n }\n if (object === null) {\n return null;\n }\n const parsed = JSON.parse(object.body) as { value: unknown; version: number };\n if (typeof parsed.version !== \"number\") {\n throw new Error(`malformed stored record at ${pathFor(collection, id)}`);\n }\n return { value: parsed.value, version: parsed.version, etag: object.etag };\n }\n\n return {\n name: \"blob\",\n\n async get(collection, id) {\n const record = await readRecord(collection, id);\n return record === null ? null : { value: record.value, version: record.version };\n },\n\n async insert(collection, id, value) {\n try {\n await client.write(\n pathFor(collection, id),\n JSON.stringify({ value, version: 1 }),\n false,\n );\n } catch (error) {\n if (isAlreadyExistsError(error)) {\n throw new RecordExistsError(collection, id);\n }\n throw error;\n }\n },\n\n async update(collection, id, value, expectedVersion) {\n const existing = await readRecord(collection, id);\n if (existing === null) {\n throw new RecordNotFoundError(collection, id);\n }\n if (existing.version !== expectedVersion) {\n throw new VersionConflictError(collection, id, expectedVersion);\n }\n try {\n await client.write(\n pathFor(collection, id),\n JSON.stringify({ value, version: expectedVersion + 1 }),\n true,\n // The write API's ifMatch rejects the weak form (W/\"…\") that reads return.\n existing.etag.replace(/^W\\//u, \"\"),\n );\n } catch (error) {\n if (isPreconditionError(error)) {\n throw new VersionConflictError(collection, id, expectedVersion);\n }\n throw error;\n }\n },\n\n async list(collection) {\n const dir = `${prefix}/${collection}/`;\n const paths = await client.listPaths(dir);\n const entries: StoredEntry[] = [];\n for (const pathname of paths) {\n const id = pathname.slice(dir.length).replace(/\\.json$/u, \"\");\n const record = await readRecord(collection, id);\n if (record !== null) {\n entries.push({ id, record: { value: record.value, version: record.version } });\n }\n }\n return entries;\n },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QAAQ,YAAY,EAAE,GACtB,KAAK,UAAU;KAAE;KAAO,SAAS,kBAAkB;IAAE,CAAC,GACtD,MAEA,SAAS,KAAK,QAAQ,SAAS,EAAE,CACnC;GACF,SAAS,OAAO;IACd,IAAI,oBAAoB,KAAK,GAC3B,MAAM,IAAI,qBAAqB,YAAY,IAAI,eAAe;IAEhE,MAAM;GACR;EACF;EAEA,MAAM,KAAK,YAAY;GACrB,MAAM,MAAM,GAAG,OAAO,GAAG,WAAW;GACpC,MAAM,QAAQ,MAAM,OAAO,UAAU,GAAG;GACxC,MAAM,UAAyB,CAAC;GAChC,KAAK,MAAM,YAAY,OAAO;IAC5B,MAAM,KAAK,SAAS,MAAM,IAAI,MAAM,CAAC,CAAC,QAAQ,YAAY,EAAE;IAC5D,MAAM,SAAS,MAAM,WAAW,YAAY,EAAE;IAC9C,IAAI,WAAW,MACb,QAAQ,KAAK;KAAE;KAAI,QAAQ;MAAE,OAAO,OAAO;MAAO,SAAS,OAAO;KAAQ;IAAE,CAAC;GAEjF;GACA,OAAO;EACT;CACF;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as NormalizedSignal, c as communicationEventSchema, d as createCommunicationRouter, i as CommunicationRouter, l as communicationOutcomeSchema, n as CommunicationEvent, o as SignalNormalizer, r as CommunicationOutcome, s as WebhookEvent, t as CommunicationAdapter, u as communicationOutcomes } from "../index-WNGZJRRH.mjs";
|
|
2
|
+
export { CommunicationAdapter, CommunicationEvent, CommunicationOutcome, CommunicationRouter, NormalizedSignal, SignalNormalizer, WebhookEvent, communicationEventSchema, communicationOutcomeSchema, communicationOutcomes, createCommunicationRouter };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { i as repositoryIdSchema, s as taskIdSchema, t as changeIdSchema, u as replyToSchema } from "../id-DwCihQr4.mjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/connectors/index.ts
|
|
4
|
+
const communicationOutcomes = [
|
|
5
|
+
"accepted",
|
|
6
|
+
"started",
|
|
7
|
+
"succeeded",
|
|
8
|
+
"failed",
|
|
9
|
+
"needs_human",
|
|
10
|
+
"question",
|
|
11
|
+
"digest",
|
|
12
|
+
"rolled_back",
|
|
13
|
+
"budget_warning",
|
|
14
|
+
"budget_exhausted",
|
|
15
|
+
"message"
|
|
16
|
+
];
|
|
17
|
+
const communicationOutcomeSchema = z.enum(communicationOutcomes).describe("Lifecycle outcome a connector should render and deliver.");
|
|
18
|
+
const communicationEventSchema = z.strictObject({
|
|
19
|
+
eventId: z.string().min(1).describe("Stable idempotency key for this delivery."),
|
|
20
|
+
repositoryId: repositoryIdSchema,
|
|
21
|
+
taskId: taskIdSchema.optional(),
|
|
22
|
+
changeId: changeIdSchema.optional(),
|
|
23
|
+
replyTo: replyToSchema,
|
|
24
|
+
outcome: communicationOutcomeSchema,
|
|
25
|
+
data: z.record(z.string(), z.unknown()).describe("Outcome-specific data rendered by the selected connector.")
|
|
26
|
+
});
|
|
27
|
+
function createCommunicationRouter(adapters) {
|
|
28
|
+
const byChannel = /* @__PURE__ */ new Map();
|
|
29
|
+
for (const adapter of adapters) {
|
|
30
|
+
const channel = adapter.channel.trim();
|
|
31
|
+
if (channel.length === 0) throw new Error("Communication adapter channel is required.");
|
|
32
|
+
if (byChannel.has(channel)) throw new Error(`Communication adapter ${channel} is registered more than once.`);
|
|
33
|
+
byChannel.set(channel, adapter);
|
|
34
|
+
}
|
|
35
|
+
const channels = Object.freeze([...byChannel.keys()]);
|
|
36
|
+
return Object.freeze({
|
|
37
|
+
channels,
|
|
38
|
+
async deliver(input) {
|
|
39
|
+
const event = communicationEventSchema.parse(input);
|
|
40
|
+
const adapter = byChannel.get(event.replyTo.channel);
|
|
41
|
+
if (adapter === void 0) throw new Error(`No communication adapter is registered for ${event.replyTo.channel}.`);
|
|
42
|
+
await adapter.deliver(event);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { communicationEventSchema, communicationOutcomeSchema, communicationOutcomes, createCommunicationRouter };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/connectors/index.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { changeIdSchema, repositoryIdSchema, taskIdSchema } from \"../schema/id\";\nimport { replyToSchema } from \"../schema/common\";\nimport type { ReplyTo } from \"../schema/common\";\nimport type { SignalSource } from \"../schema/signal\";\n\nexport interface WebhookEvent {\n deliveryId: string;\n event: string;\n payload: unknown;\n}\n\nexport interface NormalizedSignal<TSource extends SignalSource = SignalSource> {\n source: TSource;\n deliveryId: string;\n replyTo: ReplyTo;\n payload: unknown;\n}\n\nexport type SignalNormalizer<TSignal extends NormalizedSignal = NormalizedSignal> = (\n event: WebhookEvent,\n) => TSignal | null;\n\nexport const communicationOutcomes = [\n \"accepted\",\n \"started\",\n \"succeeded\",\n \"failed\",\n \"needs_human\",\n \"question\",\n \"digest\",\n \"rolled_back\",\n \"budget_warning\",\n \"budget_exhausted\",\n \"message\",\n] as const;\n\nexport const communicationOutcomeSchema = z\n .enum(communicationOutcomes)\n .describe(\"Lifecycle outcome a connector should render and deliver.\");\n\nexport const communicationEventSchema = z.strictObject({\n eventId: z.string().min(1).describe(\"Stable idempotency key for this delivery.\"),\n repositoryId: repositoryIdSchema,\n taskId: taskIdSchema.optional(),\n changeId: changeIdSchema.optional(),\n replyTo: replyToSchema,\n outcome: communicationOutcomeSchema,\n data: z\n .record(z.string(), z.unknown())\n .describe(\"Outcome-specific data rendered by the selected connector.\"),\n});\n\nexport type CommunicationOutcome = z.infer<typeof communicationOutcomeSchema>;\nexport type CommunicationEvent = z.infer<typeof communicationEventSchema>;\n\nexport interface CommunicationAdapter {\n readonly channel: string;\n deliver(event: CommunicationEvent): Promise<void>;\n}\n\nexport interface CommunicationRouter {\n readonly channels: readonly string[];\n deliver(event: CommunicationEvent): Promise<void>;\n}\n\nexport function createCommunicationRouter(\n adapters: readonly CommunicationAdapter[],\n): CommunicationRouter {\n const byChannel = new Map<string, CommunicationAdapter>();\n for (const adapter of adapters) {\n const channel = adapter.channel.trim();\n if (channel.length === 0) {\n throw new Error(\"Communication adapter channel is required.\");\n }\n if (byChannel.has(channel)) {\n throw new Error(`Communication adapter ${channel} is registered more than once.`);\n }\n byChannel.set(channel, adapter);\n }\n const channels = Object.freeze([...byChannel.keys()]);\n\n return Object.freeze({\n channels,\n async deliver(input: CommunicationEvent): Promise<void> {\n const event = communicationEventSchema.parse(input);\n const adapter = byChannel.get(event.replyTo.channel);\n if (adapter === undefined) {\n throw new Error(`No communication adapter is registered for ${event.replyTo.channel}.`);\n }\n await adapter.deliver(event);\n },\n });\n}\n"],"mappings":";;;AAuBA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,6BAA6B,EACvC,KAAK,qBAAqB,CAAC,CAC3B,SAAS,0DAA0D;AAEtE,MAAa,2BAA2B,EAAE,aAAa;CACrD,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,2CAA2C;CAC/E,cAAc;CACd,QAAQ,aAAa,SAAS;CAC9B,UAAU,eAAe,SAAS;CAClC,SAAS;CACT,SAAS;CACT,MAAM,EACH,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAC/B,SAAS,2DAA2D;AACzE,CAAC;AAeD,SAAgB,0BACd,UACqB;CACrB,MAAM,4BAAY,IAAI,IAAkC;CACxD,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,UAAU,QAAQ,QAAQ,KAAK;EACrC,IAAI,QAAQ,WAAW,GACrB,MAAM,IAAI,MAAM,4CAA4C;EAE9D,IAAI,UAAU,IAAI,OAAO,GACvB,MAAM,IAAI,MAAM,yBAAyB,QAAQ,+BAA+B;EAElF,UAAU,IAAI,SAAS,OAAO;CAChC;CACA,MAAM,WAAW,OAAO,OAAO,CAAC,GAAG,UAAU,KAAK,CAAC,CAAC;CAEpD,OAAO,OAAO,OAAO;EACnB;EACA,MAAM,QAAQ,OAA0C;GACtD,MAAM,QAAQ,yBAAyB,MAAM,KAAK;GAClD,MAAM,UAAU,UAAU,IAAI,MAAM,QAAQ,OAAO;GACnD,IAAI,YAAY,KAAA,GACd,MAAM,IAAI,MAAM,8CAA8C,MAAM,QAAQ,QAAQ,EAAE;GAExF,MAAM,QAAQ,QAAQ,KAAK;EAC7B;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/store/driver.ts
|
|
2
|
+
var RecordExistsError = class extends Error {
|
|
3
|
+
constructor(collection, id) {
|
|
4
|
+
super(`record "${id}" already exists in "${collection}"`);
|
|
5
|
+
this.name = "RecordExistsError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var RecordNotFoundError = class extends Error {
|
|
9
|
+
constructor(collection, id) {
|
|
10
|
+
super(`record "${id}" not found in "${collection}"`);
|
|
11
|
+
this.name = "RecordNotFoundError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var VersionConflictError = class extends Error {
|
|
15
|
+
constructor(collection, id, expectedVersion) {
|
|
16
|
+
super(`record "${id}" in "${collection}" changed since version ${expectedVersion} was read`);
|
|
17
|
+
this.name = "VersionConflictError";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { RecordNotFoundError as n, VersionConflictError as r, RecordExistsError as t };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=driver-Bbd25rNM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver-Bbd25rNM.mjs","names":[],"sources":["../src/store/driver.ts"],"sourcesContent":["export type CollectionName = \"repositories\" | \"signals\" | \"tasks\" | \"changes\" | \"receipts\";\n\nexport interface StoredRecord {\n readonly value: unknown;\n readonly version: number;\n}\n\nexport interface StoredEntry {\n readonly id: string;\n readonly record: StoredRecord;\n}\n\nexport class RecordExistsError extends Error {\n constructor(collection: CollectionName, id: string) {\n super(`record \"${id}\" already exists in \"${collection}\"`);\n this.name = \"RecordExistsError\";\n }\n}\n\nexport class RecordNotFoundError extends Error {\n constructor(collection: CollectionName, id: string) {\n super(`record \"${id}\" not found in \"${collection}\"`);\n this.name = \"RecordNotFoundError\";\n }\n}\n\nexport class VersionConflictError extends Error {\n constructor(collection: CollectionName, id: string, expectedVersion: number) {\n super(\n `record \"${id}\" in \"${collection}\" changed since version ${expectedVersion} was read`,\n );\n this.name = \"VersionConflictError\";\n }\n}\n\n/**\n * Raw persistence contract. Drivers store opaque values and enforce nothing\n * about their content; every invariant lives in the engine above. `update`\n * must be an atomic compare-and-swap on `expectedVersion`.\n */\nexport interface StoreDriver {\n readonly name: string;\n get(collection: CollectionName, id: string): Promise<StoredRecord | null>;\n insert(collection: CollectionName, id: string, value: unknown): Promise<void>;\n update(\n collection: CollectionName,\n id: string,\n value: unknown,\n expectedVersion: number,\n ): Promise<void>;\n list(collection: CollectionName): Promise<readonly StoredEntry[]>;\n}\n"],"mappings":";AAYA,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,YAA4B,IAAY;EAClD,MAAM,WAAW,GAAG,uBAAuB,WAAW,EAAE;EACxD,KAAK,OAAO;CACd;AACF;AAEA,IAAa,sBAAb,cAAyC,MAAM;CAC7C,YAAY,YAA4B,IAAY;EAClD,MAAM,WAAW,GAAG,kBAAkB,WAAW,EAAE;EACnD,KAAK,OAAO;CACd;AACF;AAEA,IAAa,uBAAb,cAA0C,MAAM;CAC9C,YAAY,YAA4B,IAAY,iBAAyB;EAC3E,MACE,WAAW,GAAG,QAAQ,WAAW,0BAA0B,gBAAgB,UAC7E;EACA,KAAK,OAAO;CACd;AACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/store/driver.d.ts
|
|
2
|
+
type CollectionName = "repositories" | "signals" | "tasks" | "changes" | "receipts";
|
|
3
|
+
interface StoredRecord {
|
|
4
|
+
readonly value: unknown;
|
|
5
|
+
readonly version: number;
|
|
6
|
+
}
|
|
7
|
+
interface StoredEntry {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly record: StoredRecord;
|
|
10
|
+
}
|
|
11
|
+
declare class RecordExistsError extends Error {
|
|
12
|
+
constructor(collection: CollectionName, id: string);
|
|
13
|
+
}
|
|
14
|
+
declare class RecordNotFoundError extends Error {
|
|
15
|
+
constructor(collection: CollectionName, id: string);
|
|
16
|
+
}
|
|
17
|
+
declare class VersionConflictError extends Error {
|
|
18
|
+
constructor(collection: CollectionName, id: string, expectedVersion: number);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Raw persistence contract. Drivers store opaque values and enforce nothing
|
|
22
|
+
* about their content; every invariant lives in the engine above. `update`
|
|
23
|
+
* must be an atomic compare-and-swap on `expectedVersion`.
|
|
24
|
+
*/
|
|
25
|
+
interface StoreDriver {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
get(collection: CollectionName, id: string): Promise<StoredRecord | null>;
|
|
28
|
+
insert(collection: CollectionName, id: string, value: unknown): Promise<void>;
|
|
29
|
+
update(collection: CollectionName, id: string, value: unknown, expectedVersion: number): Promise<void>;
|
|
30
|
+
list(collection: CollectionName): Promise<readonly StoredEntry[]>;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { StoredEntry as a, StoreDriver as i, RecordExistsError as n, StoredRecord as o, RecordNotFoundError as r, VersionConflictError as s, CollectionName as t };
|
|
34
|
+
//# sourceMappingURL=driver-CrZsy7sm.d.mts.map
|