@feltdb/feltkit 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -2
  3. package/bin/feltkit.js +3 -0
  4. package/dist/app.d.ts +247 -0
  5. package/dist/app.js +181 -0
  6. package/dist/app.js.map +1 -0
  7. package/dist/cli/deploy.d.ts +8 -0
  8. package/dist/cli/deploy.js +125 -0
  9. package/dist/cli/deploy.js.map +1 -0
  10. package/dist/cli/main.d.ts +9 -0
  11. package/dist/cli/main.js +581 -0
  12. package/dist/cli/main.js.map +1 -0
  13. package/dist/cli/output.d.ts +18 -0
  14. package/dist/cli/output.js +87 -0
  15. package/dist/cli/output.js.map +1 -0
  16. package/dist/cli/skills.d.ts +39 -0
  17. package/dist/cli/skills.js +125 -0
  18. package/dist/cli/skills.js.map +1 -0
  19. package/dist/client/index.d.ts +125 -0
  20. package/dist/client/index.js +306 -0
  21. package/dist/client/index.js.map +1 -0
  22. package/dist/dashboard/assets/index--1Tqbv_A.css +1 -0
  23. package/dist/dashboard/assets/index-Bm4qCYpv.js +15 -0
  24. package/dist/dashboard/index.html +16 -0
  25. package/dist/errors.d.ts +33 -0
  26. package/dist/errors.js +56 -0
  27. package/dist/errors.js.map +1 -0
  28. package/dist/index.d.ts +18 -0
  29. package/dist/index.js +12 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/react/index.d.ts +40 -0
  32. package/dist/react/index.js +85 -0
  33. package/dist/react/index.js.map +1 -0
  34. package/dist/runtime/activity.d.ts +110 -0
  35. package/dist/runtime/activity.js +113 -0
  36. package/dist/runtime/activity.js.map +1 -0
  37. package/dist/runtime/agent.d.ts +353 -0
  38. package/dist/runtime/agent.js +1345 -0
  39. package/dist/runtime/agent.js.map +1 -0
  40. package/dist/runtime/authority.d.ts +98 -0
  41. package/dist/runtime/authority.js +240 -0
  42. package/dist/runtime/authority.js.map +1 -0
  43. package/dist/runtime/changes.d.ts +42 -0
  44. package/dist/runtime/changes.js +85 -0
  45. package/dist/runtime/changes.js.map +1 -0
  46. package/dist/runtime/content.d.ts +33 -0
  47. package/dist/runtime/content.js +46 -0
  48. package/dist/runtime/content.js.map +1 -0
  49. package/dist/runtime/context.d.ts +76 -0
  50. package/dist/runtime/context.js +2 -0
  51. package/dist/runtime/context.js.map +1 -0
  52. package/dist/runtime/credentials.d.ts +42 -0
  53. package/dist/runtime/credentials.js +32 -0
  54. package/dist/runtime/credentials.js.map +1 -0
  55. package/dist/runtime/data.d.ts +145 -0
  56. package/dist/runtime/data.js +439 -0
  57. package/dist/runtime/data.js.map +1 -0
  58. package/dist/runtime/decisions.d.ts +131 -0
  59. package/dist/runtime/decisions.js +301 -0
  60. package/dist/runtime/decisions.js.map +1 -0
  61. package/dist/runtime/environment.d.ts +36 -0
  62. package/dist/runtime/environment.js +73 -0
  63. package/dist/runtime/environment.js.map +1 -0
  64. package/dist/runtime/idempotency.d.ts +37 -0
  65. package/dist/runtime/idempotency.js +88 -0
  66. package/dist/runtime/idempotency.js.map +1 -0
  67. package/dist/runtime/instance.d.ts +82 -0
  68. package/dist/runtime/instance.js +253 -0
  69. package/dist/runtime/instance.js.map +1 -0
  70. package/dist/runtime/integrations.d.ts +120 -0
  71. package/dist/runtime/integrations.js +412 -0
  72. package/dist/runtime/integrations.js.map +1 -0
  73. package/dist/runtime/loader.d.ts +15 -0
  74. package/dist/runtime/loader.js +121 -0
  75. package/dist/runtime/loader.js.map +1 -0
  76. package/dist/runtime/projects.d.ts +52 -0
  77. package/dist/runtime/projects.js +141 -0
  78. package/dist/runtime/projects.js.map +1 -0
  79. package/dist/runtime/readiness.d.ts +29 -0
  80. package/dist/runtime/readiness.js +154 -0
  81. package/dist/runtime/readiness.js.map +1 -0
  82. package/dist/runtime/runtime.d.ts +227 -0
  83. package/dist/runtime/runtime.js +664 -0
  84. package/dist/runtime/runtime.js.map +1 -0
  85. package/dist/runtime/services.d.ts +327 -0
  86. package/dist/runtime/services.js +686 -0
  87. package/dist/runtime/services.js.map +1 -0
  88. package/dist/runtime/sessions.d.ts +44 -0
  89. package/dist/runtime/sessions.js +109 -0
  90. package/dist/runtime/sessions.js.map +1 -0
  91. package/dist/schema.d.ts +56 -0
  92. package/dist/schema.js +44 -0
  93. package/dist/schema.js.map +1 -0
  94. package/dist/server/admin.d.ts +141 -0
  95. package/dist/server/admin.js +828 -0
  96. package/dist/server/admin.js.map +1 -0
  97. package/dist/server/http.d.ts +19 -0
  98. package/dist/server/http.js +99 -0
  99. package/dist/server/http.js.map +1 -0
  100. package/dist/server/index.d.ts +54 -0
  101. package/dist/server/index.js +305 -0
  102. package/dist/server/index.js.map +1 -0
  103. package/dist/server/management.d.ts +12 -0
  104. package/dist/server/management.js +177 -0
  105. package/dist/server/management.js.map +1 -0
  106. package/dist/server/mcp.d.ts +214 -0
  107. package/dist/server/mcp.js +135 -0
  108. package/dist/server/mcp.js.map +1 -0
  109. package/dist/server/operators.d.ts +77 -0
  110. package/dist/server/operators.js +162 -0
  111. package/dist/server/operators.js.map +1 -0
  112. package/dist/server/project.d.ts +60 -0
  113. package/dist/server/project.js +344 -0
  114. package/dist/server/project.js.map +1 -0
  115. package/dist/server/public.d.ts +14 -0
  116. package/dist/server/public.js +15 -0
  117. package/dist/server/public.js.map +1 -0
  118. package/dist/testing/index.d.ts +20 -0
  119. package/dist/testing/index.js +65 -0
  120. package/dist/testing/index.js.map +1 -0
  121. package/package.json +91 -4
  122. package/skills/.claude-plugin/marketplace.json +16 -0
  123. package/skills/.claude-plugin/plugin.json +24 -0
  124. package/skills/README.md +44 -0
  125. package/skills/feltkit-agent/SKILL.md +84 -0
  126. package/skills/feltkit-build/SKILL.md +143 -0
  127. package/skills/feltkit-data/SKILL.md +79 -0
  128. package/skills/feltkit-operations/SKILL.md +72 -0
  129. package/skills/feltkit-services/SKILL.md +102 -0
@@ -0,0 +1,85 @@
1
+ export class ChangeFeed {
2
+ #db;
3
+ #listeners = new Set();
4
+ #intervalMs;
5
+ #position;
6
+ #timer;
7
+ #running = null;
8
+ #pending = false;
9
+ lastError = null;
10
+ constructor(db, options = {}) {
11
+ this.#db = db;
12
+ this.#intervalMs = options.intervalMs ?? 150;
13
+ this.#position = safeSequence(db);
14
+ }
15
+ get position() {
16
+ return this.#position;
17
+ }
18
+ start() {
19
+ if (this.#timer)
20
+ return;
21
+ this.#timer = setInterval(() => void this.check(), this.#intervalMs);
22
+ this.#timer.unref();
23
+ }
24
+ stop() {
25
+ if (this.#timer)
26
+ clearInterval(this.#timer);
27
+ this.#timer = undefined;
28
+ }
29
+ subscribe(listener) {
30
+ this.#listeners.add(listener);
31
+ return () => this.#listeners.delete(listener);
32
+ }
33
+ /** Check the journal now (called after commits for low latency, and on a timer). */
34
+ check() {
35
+ if (this.#running) {
36
+ this.#pending = true;
37
+ return this.#running;
38
+ }
39
+ this.#running = this.#check().finally(() => {
40
+ this.#running = null;
41
+ if (this.#pending) {
42
+ this.#pending = false;
43
+ void this.check();
44
+ }
45
+ });
46
+ return this.#running;
47
+ }
48
+ async #check() {
49
+ const sequence = safeSequence(this.#db);
50
+ if (sequence <= this.#position)
51
+ return;
52
+ const since = this.#position;
53
+ let collections;
54
+ try {
55
+ const operations = await this.#db.exportOperations(since);
56
+ collections = [...new Set(operations.filter((op) => op.sequence > since).map((op) => op.collection))];
57
+ this.lastError = null;
58
+ }
59
+ catch (error) {
60
+ // The journal could not be read (for example after compaction). Report the
61
+ // position change without names; subscribers treat that as "anything changed".
62
+ this.lastError = error.message;
63
+ collections = ["*"];
64
+ }
65
+ this.#position = sequence;
66
+ const event = { sequence, collections, at: new Date().toISOString() };
67
+ for (const listener of this.#listeners) {
68
+ try {
69
+ listener(event);
70
+ }
71
+ catch {
72
+ /* a broken subscriber must not stop delivery to others */
73
+ }
74
+ }
75
+ }
76
+ }
77
+ function safeSequence(db) {
78
+ try {
79
+ return db.getSequence();
80
+ }
81
+ catch {
82
+ return 0;
83
+ }
84
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CAAC,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,MAAM,KAAK,GAAgB,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC;QACnF,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACvC,IAAI,CAAC;gBACH,QAAQ,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC;YAAC,MAAM,CAAC;gBACP,0DAA0D;YAC5D,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,SAAS,YAAY,CAAC,EAAgB;IACpC,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,WAAW,EAAE,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * File bytes, in the `_feltkit_file_content` collection on the application's instance.
3
+ *
4
+ * Each upload stores its bytes as one row (base64, with their SHA-256) before the file's
5
+ * metadata is committed, so a file record never points at bytes that were not stored; if
6
+ * the metadata commit fails the row is removed. Every read re-hashes the bytes and refuses
7
+ * a mismatch. Deleting a file removes its bytes.
8
+ *
9
+ * FeltDB 0.15's content store (`db.storeContent` / `db.acquireContent`) is not used yet,
10
+ * although it is content-addressed and integrity-checked, because it cannot keep two
11
+ * guarantees FeltKit's files have: it has no deletion, so a deleted file's bytes would
12
+ * stay on disk (UPSTREAM-GAPS F8), and the memory runtime has none, so files would stop
13
+ * working there (F9). Move to it when FeltDB releases both.
14
+ */
15
+ import type { StateFirstDB } from "@feltdb/core";
16
+ /** Where file bytes are kept, one row per file. */
17
+ export declare const FILE_CONTENT_COLLECTION = "_feltkit_file_content";
18
+ export declare class FileContent {
19
+ #private;
20
+ constructor(db: StateFirstDB);
21
+ /** Store bytes durably for a file about to be recorded. Returns its storage key and checksum (SHA-256, hex). */
22
+ store(bytes: Uint8Array): Promise<{
23
+ storageKey: string;
24
+ checksum: string;
25
+ }>;
26
+ /** The bytes behind a storage key, verified against their digest. */
27
+ read(fileId: string, storageKey: string, checksum?: string): Promise<{
28
+ bytes: Uint8Array;
29
+ collection: string;
30
+ }>;
31
+ /** Remove a file's bytes: after the file is deleted, or when its metadata could not be committed. */
32
+ release(storageKey: string): Promise<void>;
33
+ }
@@ -0,0 +1,46 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { FeltKitError } from "../errors.js";
3
+ /** Where file bytes are kept, one row per file. */
4
+ export const FILE_CONTENT_COLLECTION = "_feltkit_file_content";
5
+ const PREFIX = "feltkit-content:";
6
+ export class FileContent {
7
+ #db;
8
+ constructor(db) {
9
+ this.#db = db;
10
+ }
11
+ /** Store bytes durably for a file about to be recorded. Returns its storage key and checksum (SHA-256, hex). */
12
+ async store(bytes) {
13
+ const checksum = createHash("sha256").update(bytes).digest("hex");
14
+ const id = randomUUID();
15
+ await this.#db.transaction({
16
+ operations: [
17
+ { collection: FILE_CONTENT_COLLECTION, id, requireAbsent: true, value: { id, data: Buffer.from(bytes).toString("base64"), size: bytes.byteLength, checksum } },
18
+ ],
19
+ });
20
+ return { storageKey: `${PREFIX}${id}`, checksum };
21
+ }
22
+ /** The bytes behind a storage key, verified against their digest. */
23
+ async read(fileId, storageKey, checksum) {
24
+ if (!storageKey.startsWith(PREFIX))
25
+ throw new FeltKitError("NOT_FOUND", `File ${fileId} has no stored content.`);
26
+ const record = (await this.#db.collection(FILE_CONTENT_COLLECTION).get(storageKey.slice(PREFIX.length))) ?? null;
27
+ if (!record)
28
+ throw new FeltKitError("NOT_FOUND", `The content for file ${fileId} is missing.`);
29
+ const bytes = new Uint8Array(Buffer.from(record.data, "base64"));
30
+ const digest = createHash("sha256").update(bytes).digest("hex");
31
+ if (digest !== record.checksum || (checksum && digest !== checksum)) {
32
+ throw new FeltKitError("INTERNAL", `File ${fileId} failed its checksum; the stored bytes do not match the recorded digest.`);
33
+ }
34
+ return { bytes, collection: FILE_CONTENT_COLLECTION };
35
+ }
36
+ /** Remove a file's bytes: after the file is deleted, or when its metadata could not be committed. */
37
+ async release(storageKey) {
38
+ if (!storageKey.startsWith(PREFIX))
39
+ return;
40
+ const id = storageKey.slice(PREFIX.length);
41
+ const row = await this.#db.collection(FILE_CONTENT_COLLECTION).get(id);
42
+ if (row)
43
+ await this.#db.transaction({ operations: [{ collection: FILE_CONTENT_COLLECTION, id, ifVersion: row.__version }] });
44
+ }
45
+ }
46
+ //# sourceMappingURL=content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/runtime/content.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,mDAAmD;AACnD,MAAM,CAAC,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AAC/D,MAAM,MAAM,GAAG,kBAAkB,CAAC;AAElC,MAAM,OAAO,WAAW;IACb,GAAG,CAAe;IAE3B,YAAY,EAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,gHAAgH;IAChH,KAAK,CAAC,KAAK,CAAC,KAAiB;QAC3B,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAClE,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;QACxB,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;YACzB,UAAU,EAAE;gBACV,EAAE,UAAU,EAAE,uBAAuB,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,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AAC,UAAU,CAAC,MAAM,CAAC;YAAE,OAAO;QAC3C,MAAM,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAwB,uBAAuB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC9F,IAAI,GAAG;YAAE,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,uBAAuB,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;IAC/H,CAAC;CACF"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * What a query or mutation handler receives.
3
+ */
4
+ import type { StateFirstDB } from "@feltdb/core";
5
+ import type { AuthContext } from "./authority.js";
6
+ import type { DatabaseReader, DatabaseWriter } from "./data.js";
7
+ import type { ConfigurationReader, ConfigurationWriter, FilesReader, FilesWriter, NotificationsReader, NotificationsWriter, JobsWriter, WebhooksWriter } from "./services.js";
8
+ export interface Logger {
9
+ info(message: string, fields?: Record<string, unknown>): void;
10
+ warn(message: string, fields?: Record<string, unknown>): void;
11
+ error(message: string, fields?: Record<string, unknown>): void;
12
+ }
13
+ export interface EnvironmentInfo {
14
+ name: string;
15
+ production: boolean;
16
+ }
17
+ export interface QueryCtx {
18
+ /** Read-only. Queries cannot write. */
19
+ readonly db: DatabaseReader;
20
+ readonly auth: AuthContext;
21
+ readonly services: {
22
+ readonly files: FilesReader;
23
+ readonly notifications: NotificationsReader;
24
+ readonly configuration: ConfigurationReader;
25
+ };
26
+ readonly environment: EnvironmentInfo;
27
+ readonly requestId: string;
28
+ readonly log: Logger;
29
+ }
30
+ export interface MutationCtx {
31
+ /** Writes are buffered and commit atomically when the handler returns. */
32
+ readonly db: DatabaseWriter;
33
+ readonly auth: AuthContext;
34
+ /** Service effects commit on their own; they are not part of the mutation's transaction. */
35
+ readonly services: {
36
+ readonly files: FilesWriter;
37
+ readonly notifications: NotificationsWriter;
38
+ readonly configuration: ConfigurationWriter;
39
+ /** Enqueue background work (services.jobs). Runs later as the caller. */
40
+ readonly jobs: JobsWriter;
41
+ /** Emit an event to registered webhook endpoints (services.webhooks). Delivered asynchronously. */
42
+ readonly webhooks: WebhooksWriter;
43
+ };
44
+ readonly environment: EnvironmentInfo;
45
+ readonly requestId: string;
46
+ readonly log: Logger;
47
+ /** The FeltKit agent, as the caller. */
48
+ readonly agent: AgentWriter;
49
+ /**
50
+ * Escape hatch: this environment's FeltDB instance. Writes made here are not
51
+ * validated, not part of the mutation's transaction, and not shown as the
52
+ * mutation's writes in the activity log. Prefer ctx.db.
53
+ */
54
+ readonly unsafe: {
55
+ readonly feltdb: StateFirstDB;
56
+ };
57
+ }
58
+ /** Start agent work from a mutation. Nothing happens unless the mutation commits. */
59
+ export interface AgentWriter {
60
+ /**
61
+ * After this mutation commits, open a task that puts `decision` to the environment's
62
+ * model. The model chooses among the options the caller may perform (plus "escalate");
63
+ * the choice becomes a proposal in the action lifecycle, never an execution by itself.
64
+ * Returns the task id now, so the mutation can store it. Needs feltkit.agent.write.
65
+ */
66
+ start(input: {
67
+ objective: string;
68
+ decision: import("./agent.js").DecisionSpec;
69
+ subject?: {
70
+ collection: string;
71
+ id: string;
72
+ };
73
+ }): {
74
+ taskId: string;
75
+ };
76
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/runtime/context.ts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Credential custody for AppPort Services.
3
+ *
4
+ * AppPort Services stores only references (`credential-ref:<id>`) and asks the host's
5
+ * `ScopedSecretsResolver` for the value inside the one effect that needs it (signing a
6
+ * webhook, calling a model provider). FeltKit resolves a reference from the process
7
+ * environment:
8
+ *
9
+ * credential-ref:stripe-signing → FELTKIT_CREDENTIAL_STRIPE_SIGNING
10
+ *
11
+ * Values therefore live wherever the deployment keeps its environment (a secret
12
+ * manager, a .env the developer controls) and never in FeltDB, the activity log, an
13
+ * API response, or agent context. FeltKit can report whether a reference resolves
14
+ * (`describe`) without ever reading the value out.
15
+ */
16
+ import type { ScopedSecretsResolver } from "@appport/services";
17
+ /** The environment variable that holds the value for a credential id. */
18
+ export declare function credentialVariable(secretId: string): string;
19
+ export declare class EnvironmentCredentials implements ScopedSecretsResolver<string> {
20
+ #private;
21
+ constructor(env?: NodeJS.ProcessEnv);
22
+ withSecret<T>(input: {
23
+ reference: {
24
+ secretId: string;
25
+ tenantId: string;
26
+ };
27
+ context: {
28
+ purpose: string;
29
+ };
30
+ }, use: (secret: {
31
+ value: string;
32
+ secretId: string;
33
+ version: number;
34
+ kind?: string;
35
+ }) => T | Promise<T>): Promise<T>;
36
+ /** Whether a reference resolves, and from which variable. Never returns the value. */
37
+ describe(ref: string): {
38
+ ref: string;
39
+ variable: string | null;
40
+ present: boolean;
41
+ };
42
+ }
@@ -0,0 +1,32 @@
1
+ const ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$/;
2
+ /** The environment variable that holds the value for a credential id. */
3
+ export function credentialVariable(secretId) {
4
+ return `FELTKIT_CREDENTIAL_${secretId.replace(/[^A-Za-z0-9]/g, "_").toUpperCase()}`;
5
+ }
6
+ export class EnvironmentCredentials {
7
+ #env;
8
+ constructor(env = process.env) {
9
+ this.#env = env;
10
+ }
11
+ async withSecret(input, use) {
12
+ const id = input.reference.secretId;
13
+ if (!ID.test(id))
14
+ throw Object.assign(new Error(`Invalid credential id "${id}"`), { code: "INVALID_REQUEST" });
15
+ const variable = credentialVariable(id);
16
+ const value = this.#env[variable];
17
+ if (!value) {
18
+ // Names the variable, never a value.
19
+ throw Object.assign(new Error(`Credential "${id}" is not set: define ${variable} in the environment.`), { code: "CREDENTIAL_UNAVAILABLE" });
20
+ }
21
+ return use({ value, secretId: id, version: 1, kind: "environment" });
22
+ }
23
+ /** Whether a reference resolves, and from which variable. Never returns the value. */
24
+ describe(ref) {
25
+ const id = ref.startsWith("credential-ref:") ? ref.slice("credential-ref:".length) : ref;
26
+ if (!ID.test(id))
27
+ return { ref, variable: null, present: false };
28
+ const variable = credentialVariable(id);
29
+ return { ref, variable, present: Boolean(this.#env[variable]) };
30
+ }
31
+ }
32
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/runtime/credentials.ts"],"names":[],"mappings":"AAiBA,MAAM,EAAE,GAAG,qCAAqC,CAAC;AAEjD,yEAAyE;AACzE,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,OAAO,sBAAsB,QAAQ,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;AACtF,CAAC;AAED,MAAM,OAAO,sBAAsB;IACxB,IAAI,CAAoB;IAEjC,YAAY,MAAyB,OAAO,CAAC,GAAG;QAC9C,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,UAAU,CACd,KAA0F,EAC1F,GAAoG;QAEpG,MAAM,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC;QACpC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,0BAA0B,EAAE,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC,CAAC;QAC/G,MAAM,QAAQ,GAAG,kBAAkB,CAAC,EAAE,CAAC,CAAC;QACxC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,qCAAqC;YACrC,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,eAAe,EAAE,wBAAwB,QAAQ,sBAAsB,CAAC,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC,CAAC;QAC9I,CAAC;QACD,OAAO,GAAG,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,sFAAsF;IACtF,QAAQ,CAAC,GAAW;QAClB,MAAM,EAAE,GAAG,GAAG,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACzF,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QACjE,MAAM,QAAQ,GAAG,kBAAkB,CAAC,EAAE,CAAC,CAAC;QACxC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;IAClE,CAAC;CACF"}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * `ctx.db`: the thinnest correct layer over FeltDB.
3
+ *
4
+ * Reads map one-to-one onto FeltDB:
5
+ * get → collection.get(id)
6
+ * find → collection.find(equalityFilter, { orderBy, limit })
7
+ * query → db.query({ collection, where, orderBy, limit, cursor }) (bounded page)
8
+ * count → collection.find(filter).length
9
+ *
10
+ * Writes in a mutation are buffered and committed as ONE FeltDB atomic transaction
11
+ * when the handler returns:
12
+ * - inserts are `requireAbsent` creates,
13
+ * - updates and deletes carry `ifVersion` = the version this mutation observed,
14
+ * - records the mutation read with `get` but did not write become preconditions.
15
+ * If anything the mutation read by id changed before commit, FeltDB rejects the whole
16
+ * transaction and nothing is written (CONFLICT). If the handler throws, nothing is
17
+ * written. Reads inside a mutation see the mutation's own pending writes.
18
+ *
19
+ * Reads through `find`/`query`/`count` are fenced with FeltDB read bases: the basis
20
+ * for the read's equality predicate is captured before the read and re-checked at
21
+ * commit, so a concurrent insert, update, or delete of any record matching it (a
22
+ * phantom included) fails the commit with CONFLICT. Range clauses widen the fence to
23
+ * their equality-only superset: extra conflicts, never missed ones. A read with no
24
+ * equality clause fences the collection's change marker (see COLLECTION_MARKERS),
25
+ * which detects every commit made through a Writer, but not writes made through the
26
+ * `ctx.unsafe.feltdb` escape hatch.
27
+ *
28
+ * Not provided: a consistent snapshot across reads within one call. A mutation that
29
+ * only reads commits nothing, so nothing is checked; queries are not fenced.
30
+ */
31
+ import { type StateFirstDB } from "@feltdb/core";
32
+ import type { CollectionDefinition } from "../app.js";
33
+ import { type Doc, type InferShape, type ShapeInput, type Simplify } from "../schema.js";
34
+ type AnyDoc = Record<string, unknown> & {
35
+ id: string;
36
+ __version: number;
37
+ };
38
+ export type CollectionRef<S extends ShapeInput = ShapeInput> = CollectionDefinition<S> | string;
39
+ type DocOf<C> = C extends CollectionDefinition<infer S> ? Doc<S> : AnyDoc;
40
+ type FieldsOf<C> = C extends CollectionDefinition<infer S> ? Simplify<InferShape<S>> : Record<string, unknown>;
41
+ export interface OrderBy {
42
+ field: string;
43
+ direction: "asc" | "desc";
44
+ }
45
+ export interface WhereClause {
46
+ field: string;
47
+ eq?: unknown;
48
+ neq?: unknown;
49
+ lt?: unknown;
50
+ lte?: unknown;
51
+ gt?: unknown;
52
+ gte?: unknown;
53
+ }
54
+ export interface FindOptions {
55
+ orderBy?: OrderBy[];
56
+ limit?: number;
57
+ }
58
+ export interface QueryRequest {
59
+ where?: WhereClause[];
60
+ orderBy?: OrderBy[];
61
+ limit: number;
62
+ cursor?: string;
63
+ }
64
+ export interface QueryPage<T> {
65
+ records: T[];
66
+ nextCursor?: string;
67
+ exhausted: boolean;
68
+ }
69
+ export interface DatabaseReader {
70
+ get<C extends CollectionRef>(collection: C, id: string): Promise<DocOf<C> | null>;
71
+ find<C extends CollectionRef>(collection: C, filter?: Partial<FieldsOf<C> & {
72
+ id: string;
73
+ }>, options?: FindOptions): Promise<DocOf<C>[]>;
74
+ query<C extends CollectionRef>(collection: C, request: QueryRequest): Promise<QueryPage<DocOf<C>>>;
75
+ count<C extends CollectionRef>(collection: C, filter?: Partial<FieldsOf<C>>): Promise<number>;
76
+ }
77
+ export interface DatabaseWriter extends DatabaseReader {
78
+ /** Create a record. Returns its id. */
79
+ insert<C extends CollectionRef>(collection: C, value: FieldsOf<C>): Promise<string>;
80
+ /** Merge fields into an existing record. Returns the record as it will be committed. */
81
+ patch<C extends CollectionRef>(collection: C, id: string, fields: Partial<FieldsOf<C>>): Promise<DocOf<C>>;
82
+ /** Replace an existing record's fields. */
83
+ replace<C extends CollectionRef>(collection: C, id: string, value: FieldsOf<C>): Promise<DocOf<C>>;
84
+ delete<C extends CollectionRef>(collection: C, id: string): Promise<void>;
85
+ }
86
+ export interface CommittedWrite {
87
+ collection: string;
88
+ id: string;
89
+ op: "insert" | "update" | "delete";
90
+ /** Version the write was conditioned on (updates and deletes). */
91
+ expectedVersion?: number;
92
+ }
93
+ export interface CommitResult {
94
+ transactionId: string;
95
+ writes: CommittedWrite[];
96
+ commitRevision?: number;
97
+ revisionId?: string;
98
+ operationIds: string[];
99
+ }
100
+ /**
101
+ * Per-collection change markers. Every commit through a Writer touches the marker of
102
+ * each collection it writes (unguarded, so concurrent writers never conflict on it).
103
+ * A read with no equality clause fences the marker, because FeltDB fences only
104
+ * predicates that name at least one field.
105
+ */
106
+ export declare const COLLECTION_MARKERS = "_feltkit_collections";
107
+ export declare class CollectionResolver {
108
+ private readonly collections;
109
+ constructor(collections: ReadonlyMap<string, CollectionDefinition>);
110
+ resolve(ref: CollectionRef): CollectionDefinition;
111
+ }
112
+ export declare function newId(): string;
113
+ /** Read-only access. Every collection read is recorded so subscribers can be invalidated. */
114
+ export declare class Reader implements DatabaseReader {
115
+ protected readonly db: StateFirstDB;
116
+ protected readonly resolver: CollectionResolver;
117
+ readonly reads: Set<string>;
118
+ constructor(db: StateFirstDB, resolver: CollectionResolver);
119
+ protected track(ref: CollectionRef): CollectionDefinition;
120
+ get(ref: CollectionRef, id: string): Promise<any>;
121
+ find(ref: CollectionRef, filter?: Record<string, unknown>, options?: FindOptions): Promise<any[]>;
122
+ query(ref: CollectionRef, request: QueryRequest): Promise<QueryPage<any>>;
123
+ count(ref: CollectionRef, filter?: Record<string, unknown>): Promise<number>;
124
+ }
125
+ /** Mutation access: reads see pending writes; writes commit together. */
126
+ export declare class Writer extends Reader implements DatabaseWriter {
127
+ #private;
128
+ get pendingCount(): number;
129
+ get(ref: CollectionRef, id: string): Promise<any>;
130
+ find(ref: CollectionRef, filter?: Record<string, unknown>, options?: FindOptions): Promise<any[]>;
131
+ query(ref: CollectionRef, request: QueryRequest): Promise<QueryPage<any>>;
132
+ insert(ref: CollectionRef, value: Record<string, unknown>): Promise<string>;
133
+ patch(ref: CollectionRef, id: string, fields: Record<string, unknown>): Promise<any>;
134
+ replace(ref: CollectionRef, id: string, value: Record<string, unknown>): Promise<any>;
135
+ delete(ref: CollectionRef, id: string): Promise<void>;
136
+ /** Commit every pending write in one FeltDB transaction. */
137
+ /**
138
+ * `keyed`: the transaction id was derived from the caller's idempotency key, so FeltDB's
139
+ * IDEMPOTENCY_CONFLICT means an earlier attempt under that key already committed.
140
+ */
141
+ commit(transactionId: string, options?: {
142
+ keyed?: boolean;
143
+ }): Promise<CommitResult>;
144
+ }
145
+ export {};