@feltdb/feltkit 0.3.16 → 0.3.18
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/app.d.ts +222 -5
- package/dist/app.js +178 -3
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.d.ts +57 -0
- package/dist/appboundry/build.js +54 -2
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest.js +73 -1
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/appboundry/host.d.ts +15 -0
- package/dist/appboundry/host.js +45 -1
- package/dist/appboundry/host.js.map +1 -1
- package/dist/authorize.d.ts +3 -2
- package/dist/authorize.js +5 -3
- package/dist/authorize.js.map +1 -1
- package/dist/cli/deploy-appboundry-self-hosted.d.ts +2 -0
- package/dist/cli/deploy-appboundry-self-hosted.js +1 -1
- package/dist/cli/deploy-appboundry-self-hosted.js.map +1 -1
- package/dist/cli/deploy-appboundry.js +3 -0
- package/dist/cli/deploy-appboundry.js.map +1 -1
- package/dist/cli/main.js +6 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/client/index.d.ts +242 -5
- package/dist/client/index.js +413 -29
- package/dist/client/index.js.map +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +1 -0
- package/dist/docs.js.map +1 -1
- package/dist/event-stage.d.ts +13 -0
- package/dist/event-stage.js +15 -0
- package/dist/event-stage.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js.map +1 -1
- package/dist/react/auth.d.ts +131 -0
- package/dist/react/auth.js +830 -0
- package/dist/react/auth.js.map +1 -0
- package/dist/react/context.d.ts +8 -0
- package/dist/react/context.js +14 -0
- package/dist/react/context.js.map +1 -0
- package/dist/react/index.d.ts +17 -18
- package/dist/react/index.js +21 -13
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/accounts.d.ts +33 -2
- package/dist/runtime/accounts.js +167 -27
- package/dist/runtime/accounts.js.map +1 -1
- package/dist/runtime/authority.d.ts +9 -1
- package/dist/runtime/authority.js +14 -2
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/challenges.d.ts +51 -0
- package/dist/runtime/challenges.js +121 -0
- package/dist/runtime/challenges.js.map +1 -0
- package/dist/runtime/changes.d.ts +22 -0
- package/dist/runtime/changes.js +51 -3
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/content.d.ts +32 -0
- package/dist/runtime/content.js +42 -1
- package/dist/runtime/content.js.map +1 -1
- package/dist/runtime/context.d.ts +50 -0
- package/dist/runtime/contract.js +14 -3
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/data.d.ts +36 -2
- package/dist/runtime/data.js +56 -17
- package/dist/runtime/data.js.map +1 -1
- package/dist/runtime/events.d.ts +21 -0
- package/dist/runtime/events.js +65 -0
- package/dist/runtime/events.js.map +1 -0
- package/dist/runtime/live.d.ts +48 -0
- package/dist/runtime/live.js +154 -0
- package/dist/runtime/live.js.map +1 -0
- package/dist/runtime/outbox.js +3 -0
- package/dist/runtime/outbox.js.map +1 -1
- package/dist/runtime/runtime.d.ts +70 -5
- package/dist/runtime/runtime.js +307 -36
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/search.d.ts +54 -0
- package/dist/runtime/search.js +66 -0
- package/dist/runtime/search.js.map +1 -0
- package/dist/runtime/services.d.ts +45 -0
- package/dist/runtime/services.js +90 -0
- package/dist/runtime/services.js.map +1 -1
- package/dist/runtime/sessions.d.ts +16 -2
- package/dist/runtime/sessions.js +40 -4
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/runtime/tenancy.d.ts +189 -0
- package/dist/runtime/tenancy.js +376 -0
- package/dist/runtime/tenancy.js.map +1 -0
- package/dist/runtime/tenant-scope.d.ts +9 -0
- package/dist/runtime/tenant-scope.js +127 -0
- package/dist/runtime/tenant-scope.js.map +1 -0
- package/dist/runtime/transactions.d.ts +45 -2
- package/dist/runtime/transactions.js +36 -9
- package/dist/runtime/transactions.js.map +1 -1
- package/dist/schema.d.ts +2 -1
- package/dist/schema.js +1 -1
- package/dist/schema.js.map +1 -1
- package/dist/server/http.d.ts +1 -0
- package/dist/server/http.js +14 -0
- package/dist/server/http.js.map +1 -1
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +325 -59
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp.js +6 -3
- package/dist/server/mcp.js.map +1 -1
- package/dist/server/session-http.d.ts +48 -0
- package/dist/server/session-http.js +116 -0
- package/dist/server/session-http.js.map +1 -0
- package/dist/server/tenancy.d.ts +40 -0
- package/dist/server/tenancy.js +191 -0
- package/dist/server/tenancy.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.js +7 -2
- package/dist/testing/index.js.map +1 -1
- package/docs/AGENT-OPERATIONS.md +1 -0
- package/docs/APPBOUNDRY.md +11 -1
- package/docs/ARCHITECTURE.md +4 -2
- package/docs/AUTH.md +262 -0
- package/docs/GUARANTEES.md +58 -4
- package/docs/README.md +3 -2
- package/docs/SECURITY.md +3 -2
- package/docs/TRANSACTIONS.md +98 -1
- package/docs/UPSTREAM-GAPS.md +3 -0
- package/package.json +11 -9
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-data/SKILL.md +6 -0
- package/dist/runtime/account-links.d.ts +0 -19
- package/dist/runtime/account-links.js +0 -45
- package/dist/runtime/account-links.js.map +0 -1
package/dist/runtime/content.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
1
|
+
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
2
2
|
import { FeltKitError } from "../errors.js";
|
|
3
|
+
/** Outstanding file links (download and upload), keyed by the SHA-256 of their token. */
|
|
4
|
+
export const FILE_LINK_COLLECTION = "_feltkit_file_links";
|
|
5
|
+
const LINK_PREFIX = "fkf_";
|
|
6
|
+
const digestOf = (token) => createHash("sha256").update(token).digest("hex");
|
|
3
7
|
/** Where file bytes are kept, one row per file. */
|
|
4
8
|
export const FILE_CONTENT_COLLECTION = "_feltkit_file_content";
|
|
5
9
|
const PREFIX = "feltkit-content:";
|
|
@@ -42,5 +46,42 @@ export class FileContent {
|
|
|
42
46
|
if (row)
|
|
43
47
|
await this.#db.transaction({ operations: [{ collection: FILE_CONTENT_COLLECTION, id, ifVersion: row.__version }] });
|
|
44
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Issue an opaque link token for `grant`. Only its SHA-256 is stored, so the stored row cannot
|
|
51
|
+
* be replayed as a link. The function that issues it has already authorized the caller.
|
|
52
|
+
*/
|
|
53
|
+
async issueLink(grant) {
|
|
54
|
+
const token = LINK_PREFIX + randomBytes(32).toString("base64url");
|
|
55
|
+
const id = digestOf(token);
|
|
56
|
+
await this.#db.transaction({ operations: [{ collection: FILE_LINK_COLLECTION, id, requireAbsent: true, value: { id, ...grant } }] });
|
|
57
|
+
return token;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Resolve a link token. Unknown, expired and (for upload links) already-used tokens are all
|
|
61
|
+
* NOT_FOUND. An upload link is consumed here, before its bytes are read: it works once.
|
|
62
|
+
*/
|
|
63
|
+
async redeemLink(token, kind, now = Date.now()) {
|
|
64
|
+
const missing = () => new FeltKitError("NOT_FOUND", "This file link is invalid, expired or already used.");
|
|
65
|
+
if (typeof token !== "string" || !token.startsWith(LINK_PREFIX) || token.length > 100)
|
|
66
|
+
throw missing();
|
|
67
|
+
const id = digestOf(token);
|
|
68
|
+
const row = await this.#db.collection(FILE_LINK_COLLECTION).get(id);
|
|
69
|
+
if (!row || row.kind !== kind)
|
|
70
|
+
throw missing();
|
|
71
|
+
if (row.expiresAt <= now || kind === "upload") {
|
|
72
|
+
// Expired links are removed when seen; an upload link is removed as it is used (once).
|
|
73
|
+
try {
|
|
74
|
+
await this.#db.transaction({ operations: [{ collection: FILE_LINK_COLLECTION, id, ifVersion: row.__version }] });
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
throw missing(); // a concurrent redemption used it first
|
|
78
|
+
}
|
|
79
|
+
if (row.expiresAt <= now)
|
|
80
|
+
throw missing();
|
|
81
|
+
}
|
|
82
|
+
const { __version: _version, ...grant } = row;
|
|
83
|
+
delete grant.id;
|
|
84
|
+
return grant;
|
|
85
|
+
}
|
|
45
86
|
}
|
|
46
87
|
//# sourceMappingURL=content.js.map
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/runtime/content.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,yFAAyF;AACzF,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AAC1D,MAAM,WAAW,GAAG,MAAM,CAAC;AAO3B,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAErF,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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"}
|
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
* What a query or mutation handler receives.
|
|
3
3
|
*/
|
|
4
4
|
import type { CryptoContext } from "./crypto-token.js";
|
|
5
|
+
import type { EventDefinition } from "../app.js";
|
|
6
|
+
export interface EventsWriter {
|
|
7
|
+
/** Publish after this mutation commits (not if it fails). `scope` names the resource (e.g. "workspace:ws_1"): only subscribers to that scope receive it. */
|
|
8
|
+
publish<P>(event: EventDefinition<P>, payload: P, options?: {
|
|
9
|
+
scope?: string;
|
|
10
|
+
}): void;
|
|
11
|
+
}
|
|
5
12
|
import type { StateFirstDB } from "@feltdb/core";
|
|
6
13
|
import type { AuthContext } from "./authority.js";
|
|
7
14
|
import type { DatabaseReader, DatabaseWriter } from "./data.js";
|
|
@@ -21,10 +28,27 @@ export interface EnvironmentInfo {
|
|
|
21
28
|
durable: boolean;
|
|
22
29
|
};
|
|
23
30
|
}
|
|
31
|
+
/** The current tenant's members, read-only (`auth.tenant`). Managing members is the tenancy routes' job. */
|
|
32
|
+
export interface TenancyReader {
|
|
33
|
+
/**
|
|
34
|
+
* The active members of the tenant this call works in (none without a tenant). Live queries that
|
|
35
|
+
* call it re-run when memberships change.
|
|
36
|
+
*/
|
|
37
|
+
members(): Promise<Array<{
|
|
38
|
+
principalId: string;
|
|
39
|
+
type: string;
|
|
40
|
+
role: string;
|
|
41
|
+
claims: Record<string, unknown>;
|
|
42
|
+
displayName?: string;
|
|
43
|
+
email?: string;
|
|
44
|
+
}>>;
|
|
45
|
+
}
|
|
24
46
|
export interface QueryCtx {
|
|
25
47
|
/** Read-only. Queries cannot write. */
|
|
26
48
|
readonly db: DatabaseReader;
|
|
27
49
|
readonly auth: AuthContext;
|
|
50
|
+
/** The current tenant's members (`auth.tenant`). */
|
|
51
|
+
readonly tenancy: TenancyReader;
|
|
28
52
|
readonly services: {
|
|
29
53
|
readonly files: FilesReader;
|
|
30
54
|
readonly notifications: NotificationsReader;
|
|
@@ -40,6 +64,8 @@ export interface MutationCtx {
|
|
|
40
64
|
/** Writes are buffered and commit atomically when the handler returns. */
|
|
41
65
|
readonly db: DatabaseWriter;
|
|
42
66
|
readonly auth: AuthContext;
|
|
67
|
+
/** The current tenant's members (`auth.tenant`). */
|
|
68
|
+
readonly tenancy: TenancyReader;
|
|
43
69
|
/** Service effects commit on their own; they are not part of the mutation's transaction. */
|
|
44
70
|
readonly services: {
|
|
45
71
|
readonly files: FilesWriter;
|
|
@@ -55,6 +81,8 @@ export interface MutationCtx {
|
|
|
55
81
|
readonly log: Logger;
|
|
56
82
|
/** Secure random tokens (`await ctx.crypto.token()`), on every runtime. */
|
|
57
83
|
readonly crypto: CryptoContext;
|
|
84
|
+
/** Ephemeral events (`app.event`), published to their subscribers only if this mutation commits. Never stored. */
|
|
85
|
+
readonly events: EventsWriter;
|
|
58
86
|
/**
|
|
59
87
|
* Notifications, webhook events and jobs that happen only if this mutation commits: each is
|
|
60
88
|
* recorded in the mutation's transaction and performed after it, as the caller (at least once;
|
|
@@ -73,6 +101,28 @@ export interface MutationCtx {
|
|
|
73
101
|
readonly feltdb: StateFirstDB;
|
|
74
102
|
};
|
|
75
103
|
}
|
|
104
|
+
/** What an application agent's handler (`app.agent`) receives: a mutation's context, as the agent, plus its trigger. */
|
|
105
|
+
export interface AgentCtx extends MutationCtx {
|
|
106
|
+
readonly trigger: AgentTrigger;
|
|
107
|
+
}
|
|
108
|
+
export interface AgentTrigger {
|
|
109
|
+
/** The agent's name. */
|
|
110
|
+
readonly agent: string;
|
|
111
|
+
/** Stable for every attempt of this run (the outbox id): dedupe effects outside FeltKit with it. FeltKit already commits the run's writes at most once. */
|
|
112
|
+
readonly idempotencyKey: string;
|
|
113
|
+
/** 1 on the first attempt. */
|
|
114
|
+
readonly attempt: number;
|
|
115
|
+
/** Who triggered it, for reference only: the agent never holds their authority. */
|
|
116
|
+
readonly by: {
|
|
117
|
+
readonly principalId: string;
|
|
118
|
+
readonly function: string;
|
|
119
|
+
readonly requestId: string;
|
|
120
|
+
};
|
|
121
|
+
/** The event that triggered it (`on`), if one did. */
|
|
122
|
+
readonly event?: string;
|
|
123
|
+
/** The tenant the triggering call worked in, whether or not the agent may work there (`ctx.auth.tenant` says where it does). */
|
|
124
|
+
readonly requestedTenantId?: string;
|
|
125
|
+
}
|
|
76
126
|
/** Start agent work from a mutation. Nothing happens unless the mutation commits. */
|
|
77
127
|
export interface AgentWriter {
|
|
78
128
|
/**
|
package/dist/runtime/contract.js
CHANGED
|
@@ -36,13 +36,15 @@ import { FELTDB_AGENT_STATE_CONTRACT } from "@feltdb/core";
|
|
|
36
36
|
import { SERVICE_NAMES, servicesContract } from "@appport/services";
|
|
37
37
|
import { FeltKitError } from "../errors.js";
|
|
38
38
|
import { ACTIVITY_COLLECTION } from "./activity.js";
|
|
39
|
-
import { ACCOUNTS_COLLECTION } from "./accounts.js";
|
|
39
|
+
import { ACCOUNTS_COLLECTION, ACCOUNT_EMAILS_COLLECTION } from "./accounts.js";
|
|
40
|
+
import { CHALLENGES_COLLECTION } from "./challenges.js";
|
|
41
|
+
import { INVITATIONS_COLLECTION, MEMBERSHIPS_COLLECTION, TENANTS_COLLECTION } from "./tenancy.js";
|
|
40
42
|
import { COLLECTION_MARKERS, MIGRATIONS_COLLECTION, SEQUENCES_COLLECTION } from "./data.js";
|
|
41
43
|
import { IDEMPOTENCY_COLLECTION } from "./idempotency.js";
|
|
42
44
|
import { INTEGRATION_CALLS } from "./integrations.js";
|
|
43
45
|
import { SAVED_MODELS } from "./decisions.js";
|
|
44
46
|
import { SESSIONS_COLLECTION } from "./sessions.js";
|
|
45
|
-
import { FILE_CONTENT_COLLECTION } from "./content.js";
|
|
47
|
+
import { FILE_CONTENT_COLLECTION, FILE_LINK_COLLECTION } from "./content.js";
|
|
46
48
|
import { OUTBOX_COLLECTION } from "./outbox.js";
|
|
47
49
|
import { compileStateContract } from "./state-contract.js";
|
|
48
50
|
/**
|
|
@@ -62,7 +64,14 @@ const PLATFORM_COLLECTIONS = {
|
|
|
62
64
|
],
|
|
63
65
|
[SESSIONS_COLLECTION]: ["principal", "permissions", "applicationId", "createdAt", "expiresAt", "attributes"],
|
|
64
66
|
// Built-in accounts (auth.accounts): only a scrypt hash of the password is stored.
|
|
65
|
-
[ACCOUNTS_COLLECTION]: ["email", "name", "passwordHash", "roles", "createdAt", "emailVerifiedAt", "identities"],
|
|
67
|
+
[ACCOUNTS_COLLECTION]: ["email", "name", "passwordHash", "roles", "createdAt", "emailVerifiedAt", "identities", "disabledAt"],
|
|
68
|
+
[ACCOUNT_EMAILS_COLLECTION]: ["accountId"],
|
|
69
|
+
// Account e-mail challenges: a nonce and digests only; the link and code are derived with the auth secret.
|
|
70
|
+
[CHALLENGES_COLLECTION]: ["kind", "purpose", "subject", "nonce", "codeDigest", "expiresAt", "attempts", "data", "current", "issued"],
|
|
71
|
+
// Tenancy (auth.tenant). Invitations hold a nonce; the token is derived with the auth secret.
|
|
72
|
+
[TENANTS_COLLECTION]: ["name", "createdBy", "createdAt", "updatedAt"],
|
|
73
|
+
[MEMBERSHIPS_COLLECTION]: ["tenantId", "principalId", "principalType", "role", "claims", "status", "displayName", "email", "invitedBy", "createdAt", "updatedAt", "lastUsedAt"],
|
|
74
|
+
[INVITATIONS_COLLECTION]: ["tenantId", "email", "role", "claims", "nonce", "invitedBy", "inviterName", "createdAt", "expiresAt", "status", "acceptedBy", "acceptedAt"],
|
|
66
75
|
[IDEMPOTENCY_COLLECTION]: [
|
|
67
76
|
"key", "capability", "version", "requestId", "requestDigest", "sessionId", "principalId", "response",
|
|
68
77
|
"status", "claimedAt", "storedAt", "expiresAt",
|
|
@@ -116,6 +125,8 @@ export function feltdbContract(app) {
|
|
|
116
125
|
}
|
|
117
126
|
if (services.includes("files")) {
|
|
118
127
|
collections.push({ name: FILE_CONTENT_COLLECTION, fields: [ID, ...["data", "size", "checksum"].map((field) => ({ name: field, type: "json", required: false, nullable: true }))] });
|
|
128
|
+
// File links (files.link / uploadLink): keyed by the token's digest.
|
|
129
|
+
collections.push({ name: FILE_LINK_COLLECTION, fields: [ID, ...["kind", "fileId", "expiresAt", "disposition", "principal", "name", "contentType", "maxBytes", "metadata"].map((field) => ({ name: field, type: "json", required: false, nullable: true }))] });
|
|
119
130
|
}
|
|
120
131
|
collections.push(...FELTDB_AGENT_STATE_CONTRACT.collections);
|
|
121
132
|
const indexes = compiled.indexes.map(manifestIndex);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/runtime/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,EAAE,2BAA2B,EAAwE,MAAM,cAAc,CAAC;AACjI,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAoB,MAAM,mBAAmB,CAAC;AAEtF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/runtime/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,EAAE,2BAA2B,EAAwE,MAAM,cAAc,CAAC;AACjI,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAoB,MAAM,mBAAmB,CAAC;AAEtF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAAE,qBA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M;QAAE,MAAM,IAAI,YAAY,CAAC,eAAe,EAAE,wDAAwD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,aAAa,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/L,OAAO,EAAmB,CAAC;AAC7B,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,cAAc,CAAC,QAAwB;IACrD,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC"}
|
package/dist/runtime/data.d.ts
CHANGED
|
@@ -33,6 +33,9 @@ import type { CollectionDefinition } from "../app.js";
|
|
|
33
33
|
import { type FeltKitErrorJSON } from "../errors.js";
|
|
34
34
|
import { CollectionResolver } from "./collections.js";
|
|
35
35
|
import { type Doc, type InferShape, type ShapeInput, type Simplify } from "../schema.js";
|
|
36
|
+
import { ReadSet, type ChangedRecord } from "./live.js";
|
|
37
|
+
import { type SearchRequest } from "./search.js";
|
|
38
|
+
export type { SearchRequest } from "./search.js";
|
|
36
39
|
type AnyDoc = Record<string, unknown> & {
|
|
37
40
|
id: string;
|
|
38
41
|
__version: number;
|
|
@@ -75,6 +78,20 @@ export interface DatabaseReader {
|
|
|
75
78
|
}>, options?: FindOptions): Promise<DocOf<C>[]>;
|
|
76
79
|
query<C extends CollectionRef>(collection: C, request: QueryRequest): Promise<QueryPage<DocOf<C>>>;
|
|
77
80
|
count<C extends CollectionRef>(collection: C, filter?: Partial<FieldsOf<C>>): Promise<number>;
|
|
81
|
+
/**
|
|
82
|
+
* Records whose `search` fields contain every word of `text` (case- and accent-insensitive),
|
|
83
|
+
* among those matching the equality `where`, newest first (or `orderBy`), at most `limit` (≤ 100).
|
|
84
|
+
* A bounded scan of the `where` matches (runtime/search.ts).
|
|
85
|
+
*/
|
|
86
|
+
search<C extends CollectionRef>(collection: C, request: {
|
|
87
|
+
text: string;
|
|
88
|
+
fields?: Array<keyof FieldsOf<C> & string>;
|
|
89
|
+
where?: Partial<FieldsOf<C> & {
|
|
90
|
+
id: string;
|
|
91
|
+
}>;
|
|
92
|
+
orderBy?: OrderBy[];
|
|
93
|
+
limit: number;
|
|
94
|
+
}): Promise<DocOf<C>[]>;
|
|
78
95
|
}
|
|
79
96
|
export interface DatabaseWriter extends DatabaseReader {
|
|
80
97
|
/** Create a record. Returns its id. */
|
|
@@ -102,9 +119,21 @@ export interface CommittedWrite {
|
|
|
102
119
|
/** Version the write was conditioned on (updates and deletes). */
|
|
103
120
|
expectedVersion?: number;
|
|
104
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* A committed write as the change feed describes it to live queries (runtime/live.ts): the keyed
|
|
124
|
+
* field values before and after. Server-side only: never logged, never sent as values.
|
|
125
|
+
*/
|
|
126
|
+
export interface DescribedWrite extends ChangedRecord {
|
|
127
|
+
collection: string;
|
|
128
|
+
op: "insert" | "update" | "delete";
|
|
129
|
+
/** The record's version after the write (inserts and updates). */
|
|
130
|
+
version?: number;
|
|
131
|
+
}
|
|
105
132
|
export interface CommitResult {
|
|
106
133
|
transactionId: string;
|
|
107
134
|
writes: CommittedWrite[];
|
|
135
|
+
/** The same writes with their keyed values (runtime/live.ts), for the change feed. */
|
|
136
|
+
described?: DescribedWrite[];
|
|
108
137
|
commitRevision?: number;
|
|
109
138
|
revisionId?: string;
|
|
110
139
|
operationIds: string[];
|
|
@@ -163,13 +192,16 @@ export declare function equalityWhere(filter: Record<string, unknown> | undefine
|
|
|
163
192
|
export declare class Reader implements DatabaseReader {
|
|
164
193
|
protected readonly db: StateFirstDB;
|
|
165
194
|
protected readonly resolver: CollectionResolver;
|
|
166
|
-
|
|
195
|
+
/** Collections read (a Set of names), with the equality predicates of reads limited to them. */
|
|
196
|
+
readonly reads: ReadSet;
|
|
167
197
|
constructor(db: StateFirstDB, resolver: CollectionResolver);
|
|
168
|
-
|
|
198
|
+
/** Record a read of `ref`: limited to the equality `clauses` when given, else the whole collection. */
|
|
199
|
+
protected track(ref: CollectionRef, clauses?: WhereClause[]): CollectionDefinition;
|
|
169
200
|
get(ref: CollectionRef, id: string): Promise<any>;
|
|
170
201
|
find(ref: CollectionRef, filter?: Record<string, unknown>, options?: FindOptions): Promise<any[]>;
|
|
171
202
|
query(ref: CollectionRef, request: QueryRequest): Promise<QueryPage<any>>;
|
|
172
203
|
count(ref: CollectionRef, filter?: Record<string, unknown>): Promise<number>;
|
|
204
|
+
search(ref: CollectionRef, request: SearchRequest): Promise<any[]>;
|
|
173
205
|
}
|
|
174
206
|
/** Mutation access: reads see pending writes; writes commit together. */
|
|
175
207
|
export declare class Writer extends Reader implements DatabaseWriter {
|
|
@@ -194,6 +226,8 @@ export declare class Writer extends Reader implements DatabaseWriter {
|
|
|
194
226
|
/** As `find(...).length`, with the same fence and this mutation's own writes; counted in pages when there are none. */
|
|
195
227
|
count(ref: CollectionRef, filter?: Record<string, unknown>): Promise<number>;
|
|
196
228
|
query(ref: CollectionRef, request: QueryRequest): Promise<QueryPage<any>>;
|
|
229
|
+
/** As `find` with the same fence: this mutation's own pending writes are searched too. */
|
|
230
|
+
search(ref: CollectionRef, request: SearchRequest): Promise<any[]>;
|
|
197
231
|
insert(ref: CollectionRef, value: Record<string, unknown>): Promise<string>;
|
|
198
232
|
patch(ref: CollectionRef, id: string, fields: Record<string, unknown>): Promise<any>;
|
|
199
233
|
replace(ref: CollectionRef, id: string, value: Record<string, unknown>): Promise<any>;
|
package/dist/runtime/data.js
CHANGED
|
@@ -34,6 +34,8 @@ import { FeltKitError } from "../errors.js";
|
|
|
34
34
|
import { CollectionResolver } from "./collections.js";
|
|
35
35
|
import { SequenceAllocations, SEQUENCES_COLLECTION } from "./transactions.js";
|
|
36
36
|
import { validate } from "../schema.js";
|
|
37
|
+
import { keyedValues, ReadSet, representative } from "./live.js";
|
|
38
|
+
import { collectMatches, prepareSearch } from "./search.js";
|
|
37
39
|
const MAX_FIND = 10_000;
|
|
38
40
|
/**
|
|
39
41
|
* The largest page FeltDB's `db.query` answers (it refuses a larger `limit`, on every runtime).
|
|
@@ -223,30 +225,32 @@ function checkPageLimit(limit) {
|
|
|
223
225
|
export class Reader {
|
|
224
226
|
db;
|
|
225
227
|
resolver;
|
|
226
|
-
|
|
228
|
+
/** Collections read (a Set of names), with the equality predicates of reads limited to them. */
|
|
229
|
+
reads = new ReadSet();
|
|
227
230
|
constructor(db, resolver) {
|
|
228
231
|
this.db = db;
|
|
229
232
|
this.resolver = resolver;
|
|
230
233
|
}
|
|
231
|
-
|
|
234
|
+
/** Record a read of `ref`: limited to the equality `clauses` when given, else the whole collection. */
|
|
235
|
+
track(ref, clauses) {
|
|
232
236
|
const definition = this.resolver.resolve(ref);
|
|
233
|
-
this.reads.
|
|
237
|
+
this.reads.record(definition.name, clauses ? representative(definition, clauses) : null);
|
|
234
238
|
return definition;
|
|
235
239
|
}
|
|
236
240
|
async get(ref, id) {
|
|
237
|
-
const definition = this.track(ref);
|
|
241
|
+
const definition = this.track(ref, [{ field: "id", eq: id }]);
|
|
238
242
|
if (typeof id !== "string" || !id)
|
|
239
243
|
throw new FeltKitError("INVALID_ARGUMENT", "get() needs a record id.");
|
|
240
244
|
return owned((await this.db.collection(definition.name).get(id)) ?? null);
|
|
241
245
|
}
|
|
242
246
|
async find(ref, filter, options = {}) {
|
|
243
|
-
const definition = this.track(ref);
|
|
247
|
+
const definition = this.track(ref, equalityWhere(filter));
|
|
244
248
|
checkLimit(options.limit, "find()");
|
|
245
249
|
// Every match unless the caller asked for at most `limit`: read in FeltDB pages (see queryPages).
|
|
246
250
|
return owned(await readAll(this.db, { collection: definition.name, where: equalityWhere(filter), ...(options.orderBy ? { orderBy: options.orderBy } : {}) }, options.limit));
|
|
247
251
|
}
|
|
248
252
|
async query(ref, request) {
|
|
249
|
-
const definition = this.track(ref);
|
|
253
|
+
const definition = this.track(ref, request?.where ?? []);
|
|
250
254
|
checkPageLimit(request?.limit);
|
|
251
255
|
if (!request?.limit)
|
|
252
256
|
throw new FeltKitError("INVALID_ARGUMENT", "query() needs a limit; FeltDB queries are bounded.");
|
|
@@ -260,9 +264,16 @@ export class Reader {
|
|
|
260
264
|
return { records: owned(page.records), exhausted: page.exhausted, ...(page.nextCursor ? { nextCursor: page.nextCursor } : {}) };
|
|
261
265
|
}
|
|
262
266
|
async count(ref, filter) {
|
|
263
|
-
const definition = this.track(ref);
|
|
267
|
+
const definition = this.track(ref, equalityWhere(filter));
|
|
264
268
|
return countAll(this.db, { collection: definition.name, where: equalityWhere(filter) });
|
|
265
269
|
}
|
|
270
|
+
async search(ref, request) {
|
|
271
|
+
const definition = this.resolver.resolve(ref);
|
|
272
|
+
const prepared = prepareSearch(definition, request);
|
|
273
|
+
this.track(ref, equalityWhere(prepared.where));
|
|
274
|
+
const pages = queryPages(this.db, { collection: definition.name, where: equalityWhere(prepared.where), orderBy: prepared.orderBy });
|
|
275
|
+
return owned(await collectMatches(pages, prepared, definition.name));
|
|
276
|
+
}
|
|
266
277
|
}
|
|
267
278
|
/** Mutation access: reads see pending writes; writes commit together. */
|
|
268
279
|
export class Writer extends Reader {
|
|
@@ -343,9 +354,10 @@ export class Writer extends Reader {
|
|
|
343
354
|
return { ...pending.value, id: pending.id, __version: committed?.__version ?? 0 };
|
|
344
355
|
}
|
|
345
356
|
async get(ref, id) {
|
|
346
|
-
const definition = this.
|
|
357
|
+
const definition = this.resolver.resolve(ref);
|
|
347
358
|
if (typeof id !== "string" || !id)
|
|
348
359
|
throw new FeltKitError("INVALID_ARGUMENT", "get() needs a record id.");
|
|
360
|
+
this.reads.record(definition.name, representative(definition, [{ field: "id", eq: id }]));
|
|
349
361
|
const pending = this.#pending.get(this.#key(definition.name, id));
|
|
350
362
|
if (pending?.op === "insert")
|
|
351
363
|
return owned(this.#overlayOne(pending, null));
|
|
@@ -375,7 +387,7 @@ export class Writer extends Reader {
|
|
|
375
387
|
await this.#fence(definition.name, equalityWhere(filter));
|
|
376
388
|
if (this.#pendingFor(definition.name).length === 0)
|
|
377
389
|
return super.find(ref, filter, options);
|
|
378
|
-
this.track(ref);
|
|
390
|
+
this.track(ref, equalityWhere(filter));
|
|
379
391
|
checkLimit(options.limit, "find()");
|
|
380
392
|
const matched = owned(sortRecords(await this.#overlayAll(definition.name, equalityWhere(filter)), options.orderBy));
|
|
381
393
|
return options.limit ? matched.slice(0, options.limit) : matched;
|
|
@@ -387,7 +399,7 @@ export class Writer extends Reader {
|
|
|
387
399
|
await this.#fence(definition.name, equalityWhere(filter));
|
|
388
400
|
if (this.#pendingFor(definition.name).length === 0)
|
|
389
401
|
return super.count(ref, filter);
|
|
390
|
-
this.track(ref);
|
|
402
|
+
this.track(ref, equalityWhere(filter));
|
|
391
403
|
return (await this.#overlayAll(definition.name, equalityWhere(filter))).length;
|
|
392
404
|
}
|
|
393
405
|
async query(ref, request) {
|
|
@@ -396,7 +408,7 @@ export class Writer extends Reader {
|
|
|
396
408
|
await this.#fence(definition.name, request?.where ?? []);
|
|
397
409
|
if (this.#pendingFor(definition.name).length === 0)
|
|
398
410
|
return super.query(ref, request);
|
|
399
|
-
this.track(ref);
|
|
411
|
+
this.track(ref, request?.where ?? []);
|
|
400
412
|
checkPageLimit(request?.limit);
|
|
401
413
|
if (request.cursor) {
|
|
402
414
|
throw new FeltKitError("INVALID_ARGUMENT", "query() cursors cannot be combined with this mutation's own pending writes to the same collection.", {
|
|
@@ -406,6 +418,19 @@ export class Writer extends Reader {
|
|
|
406
418
|
const matched = owned(sortRecords(await this.#overlayAll(definition.name, request.where ?? []), request.orderBy));
|
|
407
419
|
return { records: matched.slice(0, request.limit), exhausted: matched.length <= request.limit };
|
|
408
420
|
}
|
|
421
|
+
/** As `find` with the same fence: this mutation's own pending writes are searched too. */
|
|
422
|
+
async search(ref, request) {
|
|
423
|
+
const definition = this.resolver.resolve(ref);
|
|
424
|
+
this.#assertOpen();
|
|
425
|
+
const prepared = prepareSearch(definition, request);
|
|
426
|
+
const where = equalityWhere(prepared.where);
|
|
427
|
+
await this.#fence(definition.name, where);
|
|
428
|
+
if (this.#pendingFor(definition.name).length === 0)
|
|
429
|
+
return super.search(ref, request);
|
|
430
|
+
this.track(ref, where);
|
|
431
|
+
const all = sortRecords(await this.#overlayAll(definition.name, where), prepared.orderBy);
|
|
432
|
+
return owned(await collectMatches([all], prepared, definition.name));
|
|
433
|
+
}
|
|
409
434
|
#assertOpen() {
|
|
410
435
|
if (this.#committed)
|
|
411
436
|
throw new FeltKitError("INTERNAL", "This mutation has already committed; ctx.db cannot be used after the handler returns.");
|
|
@@ -429,7 +454,7 @@ export class Writer extends Reader {
|
|
|
429
454
|
if (pending?.op === "delete")
|
|
430
455
|
throw new FeltKitError("NOT_FOUND", `${definition.name}/${id} was deleted earlier in this mutation.`);
|
|
431
456
|
if (pending)
|
|
432
|
-
return { current: pending.value ?? {}, pending, ...(pending.baseVersion !== undefined ? { base: pending.baseVersion } : {}) };
|
|
457
|
+
return { current: pending.value ?? {}, pending, ...(pending.baseVersion !== undefined ? { base: pending.baseVersion } : {}), ...(pending.before ? { before: pending.before } : {}) };
|
|
433
458
|
const committed = await this.#committedGet(definition.name, id);
|
|
434
459
|
if (!committed)
|
|
435
460
|
throw new FeltKitError("NOT_FOUND", `${definition.name}/${id} does not exist.`, { details: { collection: definition.name, id } });
|
|
@@ -440,12 +465,12 @@ export class Writer extends Reader {
|
|
|
440
465
|
if (first === null) {
|
|
441
466
|
throw new FeltKitError("CONFLICT", `${definition.name}/${id} did not exist when this mutation read it and exists now. Nothing was written; it is safe to retry.`, { retryable: true, details: { collection: definition.name, id } });
|
|
442
467
|
}
|
|
443
|
-
return { current: stripSystem(committed), base: first ?? committed.__version };
|
|
468
|
+
return { current: stripSystem(committed), base: first ?? committed.__version, before: keyedValues(definition, committed) };
|
|
444
469
|
}
|
|
445
470
|
async patch(ref, id, fields) {
|
|
446
471
|
this.#assertOpen();
|
|
447
472
|
const definition = this.track(ref);
|
|
448
|
-
const { current, pending, base } = await this.#existing(definition, id);
|
|
473
|
+
const { current, pending, base, before } = await this.#existing(definition, id);
|
|
449
474
|
const merged = owned({ ...current, ...stripSystem(fields ?? {}) });
|
|
450
475
|
for (const [key, value] of Object.entries(fields ?? {}))
|
|
451
476
|
if (value === undefined)
|
|
@@ -457,13 +482,14 @@ export class Writer extends Reader {
|
|
|
457
482
|
op: pending?.op === "insert" ? "insert" : "update",
|
|
458
483
|
value: merged,
|
|
459
484
|
...(base !== undefined ? { baseVersion: base } : {}),
|
|
485
|
+
...(before ? { before } : {}),
|
|
460
486
|
});
|
|
461
487
|
return owned({ ...merged, id, __version: pending?.op === "insert" ? 1 : (base ?? 0) + 1 });
|
|
462
488
|
}
|
|
463
489
|
async replace(ref, id, value) {
|
|
464
490
|
this.#assertOpen();
|
|
465
491
|
const definition = this.track(ref);
|
|
466
|
-
const { pending, base } = await this.#existing(definition, id);
|
|
492
|
+
const { pending, base, before } = await this.#existing(definition, id);
|
|
467
493
|
const fields = owned(stripSystem(value ?? {}));
|
|
468
494
|
validateRecord(definition, fields);
|
|
469
495
|
this.#pending.set(this.#key(definition.name, id), {
|
|
@@ -472,19 +498,20 @@ export class Writer extends Reader {
|
|
|
472
498
|
op: pending?.op === "insert" ? "insert" : "update",
|
|
473
499
|
value: fields,
|
|
474
500
|
...(base !== undefined ? { baseVersion: base } : {}),
|
|
501
|
+
...(before ? { before } : {}),
|
|
475
502
|
});
|
|
476
503
|
return owned({ ...fields, id, __version: pending?.op === "insert" ? 1 : (base ?? 0) + 1 });
|
|
477
504
|
}
|
|
478
505
|
async delete(ref, id) {
|
|
479
506
|
this.#assertOpen();
|
|
480
507
|
const definition = this.track(ref);
|
|
481
|
-
const { pending, base } = await this.#existing(definition, id);
|
|
508
|
+
const { pending, base, before } = await this.#existing(definition, id);
|
|
482
509
|
const key = this.#key(definition.name, id);
|
|
483
510
|
if (pending?.op === "insert") {
|
|
484
511
|
this.#pending.delete(key);
|
|
485
512
|
return;
|
|
486
513
|
}
|
|
487
|
-
this.#pending.set(key, { collection: definition.name, id, op: "delete", ...(base !== undefined ? { baseVersion: base } : {}) });
|
|
514
|
+
this.#pending.set(key, { collection: definition.name, id, op: "delete", ...(base !== undefined ? { baseVersion: base } : {}), ...(before ? { before } : {}) });
|
|
488
515
|
}
|
|
489
516
|
/** Commit every pending write in one FeltDB transaction. */
|
|
490
517
|
/**
|
|
@@ -495,8 +522,19 @@ export class Writer extends Reader {
|
|
|
495
522
|
this.#assertOpen();
|
|
496
523
|
this.#committed = true;
|
|
497
524
|
const writes = [];
|
|
525
|
+
const described = [];
|
|
498
526
|
const operations = [];
|
|
499
527
|
for (const pending of this.#pending.values()) {
|
|
528
|
+
const definition = this.resolver.resolve(pending.collection);
|
|
529
|
+
const after = pending.op === "delete" ? undefined : keyedValues(definition, { ...pending.value, id: pending.id });
|
|
530
|
+
described.push({
|
|
531
|
+
collection: pending.collection,
|
|
532
|
+
id: pending.id,
|
|
533
|
+
op: pending.op,
|
|
534
|
+
...(pending.op === "insert" ? { version: 1 } : pending.op === "update" && pending.baseVersion !== undefined ? { version: pending.baseVersion + 1 } : {}),
|
|
535
|
+
...(pending.before ? { before: pending.before } : {}),
|
|
536
|
+
...(after ? { after } : {}),
|
|
537
|
+
});
|
|
500
538
|
if (pending.op === "insert") {
|
|
501
539
|
operations.push({ collection: pending.collection, id: pending.id, requireAbsent: true, value: { ...pending.value, id: pending.id } });
|
|
502
540
|
writes.push({ collection: pending.collection, id: pending.id, op: "insert" });
|
|
@@ -535,6 +573,7 @@ export class Writer extends Reader {
|
|
|
535
573
|
return {
|
|
536
574
|
transactionId: result.transactionId,
|
|
537
575
|
writes,
|
|
576
|
+
described,
|
|
538
577
|
operationIds: result.operationIds ?? [],
|
|
539
578
|
...(result.commitRevision !== undefined ? { commitRevision: result.commitRevision } : {}),
|
|
540
579
|
...(result.revisionId ? { revisionId: result.revisionId } : {}),
|