@feltdb/feltkit 0.3.17 → 0.3.19
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 +246 -13
- package/dist/app.js +215 -6
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.d.ts +70 -0
- package/dist/appboundry/build.js +62 -2
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest.js +57 -3
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/appboundry/host.js +7 -0
- package/dist/appboundry/host.js.map +1 -1
- package/dist/authorize.js +1 -0
- package/dist/authorize.js.map +1 -1
- package/dist/cli/compose.d.ts +31 -0
- package/dist/cli/compose.js +274 -0
- package/dist/cli/compose.js.map +1 -0
- package/dist/cli/create.d.ts +201 -0
- package/dist/cli/create.js +1139 -0
- package/dist/cli/create.js.map +1 -0
- 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/deploy.d.ts +1 -0
- package/dist/cli/deploy.js +66 -6
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/domain.d.ts +174 -0
- package/dist/cli/domain.js +1119 -0
- package/dist/cli/domain.js.map +1 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +141 -7
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/shell.d.ts +7 -0
- package/dist/cli/shell.js +59 -0
- package/dist/cli/shell.js.map +1 -0
- package/dist/client/index.d.ts +192 -5
- package/dist/client/index.js +301 -28
- package/dist/client/index.js.map +1 -1
- package/dist/component.d.ts +174 -0
- package/dist/component.js +77 -0
- package/dist/component.js.map +1 -0
- package/dist/composition/catalog.d.ts +3 -0
- package/dist/composition/catalog.js +217 -0
- package/dist/composition/catalog.js.map +1 -0
- package/dist/composition/contract.d.ts +165 -0
- package/dist/composition/contract.js +12 -0
- package/dist/composition/contract.js.map +1 -0
- package/dist/composition/execute.d.ts +110 -0
- package/dist/composition/execute.js +350 -0
- package/dist/composition/execute.js.map +1 -0
- package/dist/composition/generate.d.ts +105 -0
- package/dist/composition/generate.js +274 -0
- package/dist/composition/generate.js.map +1 -0
- package/dist/composition/plan.d.ts +131 -0
- package/dist/composition/plan.js +558 -0
- package/dist/composition/plan.js.map +1 -0
- package/dist/composition/profiles.d.ts +20 -0
- package/dist/composition/profiles.js +81 -0
- package/dist/composition/profiles.js.map +1 -0
- package/dist/composition/reconcile.d.ts +153 -0
- package/dist/composition/reconcile.js +282 -0
- package/dist/composition/reconcile.js.map +1 -0
- package/dist/composition/recover.d.ts +89 -0
- package/dist/composition/recover.js +407 -0
- package/dist/composition/recover.js.map +1 -0
- package/dist/composition/resolve.d.ts +2 -0
- package/dist/composition/resolve.js +208 -0
- package/dist/composition/resolve.js.map +1 -0
- package/dist/dashboard/assets/{index-DnIOVGF-.js → index-BrC1AtZ1.js} +5 -5
- package/dist/dashboard/index.html +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +2 -0
- package/dist/docs.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.js +2 -0
- 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 +3 -18
- package/dist/react/index.js +5 -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/activity.d.ts +8 -1
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/audit.d.ts +43 -0
- package/dist/runtime/audit.js +52 -0
- package/dist/runtime/audit.js.map +1 -0
- package/dist/runtime/authority.d.ts +8 -1
- package/dist/runtime/authority.js +11 -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/claims.d.ts +76 -0
- package/dist/runtime/claims.js +100 -0
- package/dist/runtime/claims.js.map +1 -0
- package/dist/runtime/context.d.ts +47 -5
- package/dist/runtime/contract.js +17 -3
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/data.d.ts +50 -4
- package/dist/runtime/data.js +113 -35
- package/dist/runtime/data.js.map +1 -1
- package/dist/runtime/escape-hatch.d.ts +37 -0
- package/dist/runtime/escape-hatch.js +76 -0
- package/dist/runtime/escape-hatch.js.map +1 -0
- package/dist/runtime/instance.js +2 -1
- package/dist/runtime/instance.js.map +1 -1
- 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 +6 -0
- package/dist/runtime/outbox.js.map +1 -1
- package/dist/runtime/runtime.d.ts +103 -5
- package/dist/runtime/runtime.js +411 -41
- 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-rules.d.ts +12 -0
- package/dist/runtime/services-rules.js +8 -0
- package/dist/runtime/services-rules.js.map +1 -0
- package/dist/runtime/services.js +5 -3
- 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 +198 -0
- package/dist/runtime/tenancy.js +397 -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 +83 -3
- package/dist/runtime/transactions.js +53 -11
- package/dist/runtime/transactions.js.map +1 -1
- package/dist/server/admin.js +52 -0
- package/dist/server/admin.js.map +1 -1
- package/dist/server/components.d.ts +44 -0
- package/dist/server/components.js +212 -0
- package/dist/server/components.js.map +1 -0
- package/dist/server/index.d.ts +4 -1
- package/dist/server/index.js +324 -63
- 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/project.d.ts +27 -0
- package/dist/server/project.js +63 -0
- package/dist/server/project.js.map +1 -1
- package/dist/server/public.d.ts +2 -0
- package/dist/server/public.js +2 -0
- package/dist/server/public.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 +19 -0
- package/dist/testing/index.js +22 -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 +5 -3
- package/docs/AUTH.md +267 -0
- package/docs/COMPONENTS.md +91 -0
- package/docs/GUARANTEES.md +74 -7
- package/docs/README.md +4 -2
- package/docs/RESOLVER.md +4 -2
- package/docs/SECURITY.md +5 -4
- package/docs/TRANSACTIONS.md +98 -1
- package/docs/UPSTREAM-GAPS.md +2 -0
- package/package.json +15 -12
- 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/skills/feltkit-services/SKILL.md +1 -1
- 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/changes.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { COLLECTION_MARKERS, readAll } from "./data.js";
|
|
2
|
+
/** How long a description waits for its journal operation before it is dropped. */
|
|
3
|
+
const DESCRIPTION_TTL_MS = 60_000;
|
|
2
4
|
export class ChangeFeed {
|
|
3
5
|
#db;
|
|
4
6
|
#listeners = new Set();
|
|
@@ -10,6 +12,8 @@ export class ChangeFeed {
|
|
|
10
12
|
#remote;
|
|
11
13
|
/** Remote mode: each collection marker's last seen stamp; null until the first read. */
|
|
12
14
|
#stamps = null;
|
|
15
|
+
/** Descriptions of committed writes awaiting their journal operation, by collection, id and version. */
|
|
16
|
+
#described = new Map();
|
|
13
17
|
lastError = null;
|
|
14
18
|
constructor(db, options = {}) {
|
|
15
19
|
this.#db = db;
|
|
@@ -35,6 +39,23 @@ export class ChangeFeed {
|
|
|
35
39
|
clearInterval(this.#timer);
|
|
36
40
|
this.#timer = undefined;
|
|
37
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Describe writes FeltKit just committed (runtime/live.ts). Called right after the commit, before
|
|
44
|
+
* `check()`. A journal operation read before its description arrived is reported without details.
|
|
45
|
+
*/
|
|
46
|
+
describe(writes) {
|
|
47
|
+
if (this.#remote || !writes?.length)
|
|
48
|
+
return;
|
|
49
|
+
const now = Date.now();
|
|
50
|
+
for (const [key, entry] of this.#described)
|
|
51
|
+
if (now - entry.at > DESCRIPTION_TTL_MS)
|
|
52
|
+
this.#described.delete(key);
|
|
53
|
+
for (const write of writes) {
|
|
54
|
+
const key = describedKey(write.collection, write.id, write.op === "delete" ? "delete" : write.version);
|
|
55
|
+
if (key)
|
|
56
|
+
this.#described.set(key, { record: { id: write.id, ...(write.before ? { before: write.before } : {}), ...(write.after ? { after: write.after } : {}) }, at: now });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
38
59
|
subscribe(listener) {
|
|
39
60
|
this.#listeners.add(listener);
|
|
40
61
|
return () => this.#listeners.delete(listener);
|
|
@@ -62,9 +83,11 @@ export class ChangeFeed {
|
|
|
62
83
|
return;
|
|
63
84
|
const since = this.#position;
|
|
64
85
|
let collections;
|
|
86
|
+
let details;
|
|
65
87
|
try {
|
|
66
|
-
const operations = await this.#db.exportOperations(since);
|
|
67
|
-
collections = [...new Set(operations.
|
|
88
|
+
const operations = (await this.#db.exportOperations(since)).filter((op) => op.sequence > since);
|
|
89
|
+
collections = [...new Set(operations.map((op) => op.collection))];
|
|
90
|
+
details = this.#details(operations);
|
|
68
91
|
this.lastError = null;
|
|
69
92
|
}
|
|
70
93
|
catch (error) {
|
|
@@ -74,7 +97,29 @@ export class ChangeFeed {
|
|
|
74
97
|
collections = ["*"];
|
|
75
98
|
}
|
|
76
99
|
this.#position = sequence;
|
|
77
|
-
this.#emit({ sequence, collections, at: new Date().toISOString() });
|
|
100
|
+
this.#emit({ sequence, collections, at: new Date().toISOString(), ...(details && Object.keys(details).length ? { details } : {}) });
|
|
101
|
+
}
|
|
102
|
+
/** Each collection all of whose operations here have a description, with those records. */
|
|
103
|
+
#details(operations) {
|
|
104
|
+
const out = {};
|
|
105
|
+
const undescribed = new Set();
|
|
106
|
+
for (const op of operations) {
|
|
107
|
+
if (undescribed.has(op.collection))
|
|
108
|
+
continue;
|
|
109
|
+
const prefix = `${op.collection}:`;
|
|
110
|
+
const id = op.key.startsWith(prefix) ? op.key.slice(prefix.length) : op.key;
|
|
111
|
+
const version = op.type === "delete" ? "delete" : op.value?.__version;
|
|
112
|
+
const key = describedKey(op.collection, id, typeof version === "number" || version === "delete" ? version : undefined);
|
|
113
|
+
const entry = key ? this.#described.get(key) : undefined;
|
|
114
|
+
if (!entry) {
|
|
115
|
+
undescribed.add(op.collection);
|
|
116
|
+
delete out[op.collection];
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
this.#described.delete(key);
|
|
120
|
+
(out[op.collection] ??= []).push(entry.record);
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
78
123
|
}
|
|
79
124
|
/** Remote mode: report every collection whose change marker was stamped since the last read. */
|
|
80
125
|
async #checkMarkers() {
|
|
@@ -118,6 +163,9 @@ export class ChangeFeed {
|
|
|
118
163
|
}
|
|
119
164
|
}
|
|
120
165
|
}
|
|
166
|
+
function describedKey(collection, id, version) {
|
|
167
|
+
return version === undefined ? null : `${collection}\u0000${id}\u0000${version}`;
|
|
168
|
+
}
|
|
121
169
|
function safeSequence(db) {
|
|
122
170
|
try {
|
|
123
171
|
return db.getSequence();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changes.js","sourceRoot":"","sources":["../../src/runtime/changes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"changes.js","sourceRoot":"","sources":["../../src/runtime/changes.ts"],"names":[],"mappings":"AAuCA,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAuB,MAAM,WAAW,CAAC;AAgB7E,mFAAmF;AACnF,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAIlC,MAAM,OAAO,UAAU;IACZ,GAAG,CAAe;IAClB,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,WAAW,CAAS;IAC7B,SAAS,CAAS;IAClB,MAAM,CAA6B;IACnC,QAAQ,GAAyB,IAAI,CAAC;IACtC,QAAQ,GAAG,KAAK,CAAC;IACR,OAAO,CAAU;IAC1B,wFAAwF;IACxF,OAAO,GAA+B,IAAI,CAAC;IAC3C,wGAAwG;IAC/F,UAAU,GAAG,IAAI,GAAG,EAAiD,CAAC;IAC/E,SAAS,GAAkB,IAAI,CAAC;IAEhC,YAAY,EAAgB,EAAE,UAAqD,EAAE;QACnF,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC;QACvC,oEAAoE;QACpE,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,C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M;YAAE,OAAO;QAChC,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACtF,CAAC;IAED,KAAK,CAAC,KAAkB;QACtB,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,UAAkB,EAAE,EAAU,EAAE,OAAsC;IAC1F,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,UAAU,SAAS,EAAE,SAAS,OAAO,EAAE,CAAC;AACnF,CAAC;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,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Membership claims (`auth.tenant.claims`): typed values a membership carries beside its role, set only through the
|
|
3
|
+
* server (a member manager, or an invitation) and never read from a request.
|
|
4
|
+
*
|
|
5
|
+
* A claim is declared either as a schema (`s.enum([...])`, application code) or as a **claim spec**: plain data that a
|
|
6
|
+
* composition record can hold (`{ type: "enum", values: ["free", "pro"] }`), which is what `feltkit create --claim`
|
|
7
|
+
* writes and `workspace.tenancy.claims` records. Both compile to the same schema, so validation is one rule.
|
|
8
|
+
*
|
|
9
|
+
* At the authentication boundary (`Tenancy.context`, on every call) each declared claim is classified from what the
|
|
10
|
+
* membership record holds:
|
|
11
|
+
*
|
|
12
|
+
* verified the stored value validates under the declaration now; set by `by` at `at`, through `via`
|
|
13
|
+
* default nothing is stored; the declaration gives a default, and that is the value
|
|
14
|
+
* unavailable nothing is stored and there is no default; the claim is absent
|
|
15
|
+
* invalid a stored value no longer validates (the declaration changed since it was set); it is withheld
|
|
16
|
+
*
|
|
17
|
+
* Only `verified` and `default` values appear in `claims`; `invalid` and `unavailable` ones are absent, and a rule that
|
|
18
|
+
* needs them refuses (`app.requireClaim`). A stored claim the declaration no longer names is dropped. Nothing here
|
|
19
|
+
* upgrades a status: a client cannot assert a claim, and a stale value is never served as current.
|
|
20
|
+
*/
|
|
21
|
+
import type { Schema } from "@appport/sdk";
|
|
22
|
+
export type ClaimSpec = {
|
|
23
|
+
readonly type: "enum";
|
|
24
|
+
readonly values: readonly string[];
|
|
25
|
+
readonly default?: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: "string";
|
|
28
|
+
readonly default?: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "boolean";
|
|
31
|
+
readonly default?: boolean;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "number";
|
|
34
|
+
readonly default?: number;
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: "integer";
|
|
37
|
+
readonly default?: number;
|
|
38
|
+
};
|
|
39
|
+
export declare const CLAIM_TYPES: readonly ["enum", "string", "boolean", "number", "integer"];
|
|
40
|
+
/** A schema (application code) or a claim spec (plain data). */
|
|
41
|
+
export type ClaimDeclaration = Schema | ClaimSpec;
|
|
42
|
+
export type ClaimStatus = "verified" | "default" | "unavailable" | "invalid";
|
|
43
|
+
/** How a claim's value came to be on the membership, as the boundary classified it for this call. */
|
|
44
|
+
export interface ClaimProvenance {
|
|
45
|
+
readonly status: ClaimStatus;
|
|
46
|
+
/** Who set the stored value (a principal id), when, and how. Only with a stored value (verified or invalid). */
|
|
47
|
+
readonly by?: string;
|
|
48
|
+
readonly at?: string;
|
|
49
|
+
readonly via?: "invitation" | "manager" | "self";
|
|
50
|
+
}
|
|
51
|
+
/** What a membership record keeps about each stored claim: who set it, when, how. */
|
|
52
|
+
export interface StoredClaimProvenance {
|
|
53
|
+
by: string;
|
|
54
|
+
at: string;
|
|
55
|
+
via: "invitation" | "manager" | "self";
|
|
56
|
+
}
|
|
57
|
+
/** Whether a value has the shape of a claim spec (a `type` among CLAIM_TYPES). Its validity is `claimSpecProblem`. */
|
|
58
|
+
export declare function isClaimSpec(v: unknown): v is ClaimSpec;
|
|
59
|
+
/** Why a declared claim is not acceptable, or null. Deterministic: the same declaration always gives the same answer. */
|
|
60
|
+
export declare function claimSpecProblem(name: string, declaration: unknown): string | null;
|
|
61
|
+
/** The schema a claim spec compiles to. */
|
|
62
|
+
export declare function claimSchema(spec: ClaimSpec): Schema;
|
|
63
|
+
export interface CompiledClaims {
|
|
64
|
+
/** One schema per declared claim, whatever form it was declared in. */
|
|
65
|
+
readonly schemas: Readonly<Record<string, Schema>>;
|
|
66
|
+
/** Declared defaults (claim specs only). */
|
|
67
|
+
readonly defaults: Readonly<Record<string, unknown>>;
|
|
68
|
+
readonly names: readonly string[];
|
|
69
|
+
}
|
|
70
|
+
/** Compile `auth.tenant.claims` once. Throws TypeError on a declaration `claimSpecProblem` refuses. */
|
|
71
|
+
export declare function compileClaims(declared: Readonly<Record<string, ClaimDeclaration>> | undefined): CompiledClaims;
|
|
72
|
+
/** The claims a membership presents on a call, and each declared claim's provenance. Pure. */
|
|
73
|
+
export declare function classifyClaims(compiled: CompiledClaims, stored: Readonly<Record<string, unknown>>, storedProvenance?: Readonly<Record<string, StoredClaimProvenance>>): {
|
|
74
|
+
claims: Record<string, unknown>;
|
|
75
|
+
provenance: Record<string, ClaimProvenance>;
|
|
76
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { s } from "../schema.js";
|
|
2
|
+
export const CLAIM_TYPES = ["enum", "string", "boolean", "number", "integer"];
|
|
3
|
+
const isSchema = (v) => Boolean(v) && typeof v.validate === "function";
|
|
4
|
+
const plain = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && !isSchema(v);
|
|
5
|
+
/** Whether a value has the shape of a claim spec (a `type` among CLAIM_TYPES). Its validity is `claimSpecProblem`. */
|
|
6
|
+
export function isClaimSpec(v) {
|
|
7
|
+
return plain(v) && typeof v.type === "string" && CLAIM_TYPES.includes(v.type);
|
|
8
|
+
}
|
|
9
|
+
const IDENT = /^[a-z][a-zA-Z0-9]{0,40}$/;
|
|
10
|
+
/** Why a declared claim is not acceptable, or null. Deterministic: the same declaration always gives the same answer. */
|
|
11
|
+
export function claimSpecProblem(name, declaration) {
|
|
12
|
+
if (name === "role")
|
|
13
|
+
return "role is the membership's role (auth.tenant.roles); do not declare it as a claim";
|
|
14
|
+
if (!IDENT.test(name))
|
|
15
|
+
return `"${name}" is not a claim name (a lower-case identifier)`;
|
|
16
|
+
if (isSchema(declaration))
|
|
17
|
+
return null;
|
|
18
|
+
if (!plain(declaration))
|
|
19
|
+
return "must be a schema (s.enum, s.string, …) or a claim spec ({ type: \"enum\", values: [...] })";
|
|
20
|
+
if (!isClaimSpec(declaration))
|
|
21
|
+
return `type must be one of ${CLAIM_TYPES.join(", ")}, got ${JSON.stringify(declaration.type)}`;
|
|
22
|
+
const known = new Set(["type", "values", "default"]);
|
|
23
|
+
const extra = Object.keys(declaration).filter((k) => !known.has(k));
|
|
24
|
+
if (extra.length)
|
|
25
|
+
return `unknown member ${extra.map((k) => JSON.stringify(k)).join(", ")} (a claim spec has type, values and default)`;
|
|
26
|
+
if (declaration.type === "enum") {
|
|
27
|
+
const values = declaration.values;
|
|
28
|
+
if (!Array.isArray(values) || !values.length || !values.every((v) => typeof v === "string" && v.length > 0))
|
|
29
|
+
return "an enum claim needs values: a non-empty list of strings";
|
|
30
|
+
if (new Set(values).size !== values.length)
|
|
31
|
+
return "an enum claim lists a value twice";
|
|
32
|
+
}
|
|
33
|
+
else if ("values" in declaration)
|
|
34
|
+
return `only an enum claim has values`;
|
|
35
|
+
if ("default" in declaration && declaration.default !== undefined) {
|
|
36
|
+
const result = claimSchema(declaration).validate(declaration.default);
|
|
37
|
+
if (!result.ok)
|
|
38
|
+
return `the default does not validate: ${result.issues?.[0]?.message ?? "invalid"}`;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
/** The schema a claim spec compiles to. */
|
|
43
|
+
export function claimSchema(spec) {
|
|
44
|
+
switch (spec.type) {
|
|
45
|
+
case "enum":
|
|
46
|
+
return s.enum([...spec.values]);
|
|
47
|
+
case "string":
|
|
48
|
+
return s.string();
|
|
49
|
+
case "boolean":
|
|
50
|
+
return s.boolean();
|
|
51
|
+
case "number":
|
|
52
|
+
return s.number();
|
|
53
|
+
case "integer":
|
|
54
|
+
return s.integer();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Compile `auth.tenant.claims` once. Throws TypeError on a declaration `claimSpecProblem` refuses. */
|
|
58
|
+
export function compileClaims(declared) {
|
|
59
|
+
const schemas = {};
|
|
60
|
+
const defaults = {};
|
|
61
|
+
for (const [name, declaration] of Object.entries(declared ?? {})) {
|
|
62
|
+
const problem = claimSpecProblem(name, declaration);
|
|
63
|
+
if (problem)
|
|
64
|
+
throw new TypeError(`auth.tenant.claims.${name}: ${problem}.`);
|
|
65
|
+
if (isSchema(declaration))
|
|
66
|
+
schemas[name] = declaration;
|
|
67
|
+
else {
|
|
68
|
+
schemas[name] = claimSchema(declaration);
|
|
69
|
+
if (declaration.default !== undefined)
|
|
70
|
+
defaults[name] = declaration.default;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { schemas, defaults, names: Object.keys(schemas).sort() };
|
|
74
|
+
}
|
|
75
|
+
/** The claims a membership presents on a call, and each declared claim's provenance. Pure. */
|
|
76
|
+
export function classifyClaims(compiled, stored, storedProvenance = {}) {
|
|
77
|
+
const claims = {};
|
|
78
|
+
const provenance = {};
|
|
79
|
+
for (const name of compiled.names) {
|
|
80
|
+
const origin = storedProvenance[name];
|
|
81
|
+
const who = origin ? { by: origin.by, at: origin.at, via: origin.via } : {};
|
|
82
|
+
if (name in stored && stored[name] !== undefined) {
|
|
83
|
+
const result = compiled.schemas[name].validate(stored[name]);
|
|
84
|
+
if (result.ok) {
|
|
85
|
+
claims[name] = "value" in result ? result.value : stored[name];
|
|
86
|
+
provenance[name] = { status: "verified", ...who };
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
provenance[name] = { status: "invalid", ...who };
|
|
90
|
+
}
|
|
91
|
+
else if (name in compiled.defaults) {
|
|
92
|
+
claims[name] = compiled.defaults[name];
|
|
93
|
+
provenance[name] = { status: "default" };
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
provenance[name] = { status: "unavailable" };
|
|
97
|
+
}
|
|
98
|
+
return { claims, provenance };
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=claims.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claims.js","sourceRoot":"","sources":["../../src/runtime/claims.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AASjC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAU,CAAC;AAuBvF,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAe,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,OAAQ,CAA4B,CAAC,QAAQ,KAAK,UAAU,CAAC;AACzH,MAAM,KAAK,GAAG,CAAC,CAAU,EAAgC,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAErI,sHAAsH;AACtH,MAAM,UAAU,WAAW,CAAC,CAAU;IACpC,OAAO,KAAK,CAAC,CAAC,CAAC,IAA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E,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,IAAI,IAAI,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YACjD,MAAM,MAAM,GAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,CAA2E,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;YACxI,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;gBACd,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBAC/D,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,EAAE,CAAC;YACpD,CAAC;;gBAAM,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,GAAG,EAAE,CAAC;QAC1D,CAAC;aAAM,IAAI,IAAI,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACrC,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACvC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC3C,CAAC;;YAAM,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;IACtD,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -9,7 +9,6 @@ export interface EventsWriter {
|
|
|
9
9
|
scope?: string;
|
|
10
10
|
}): void;
|
|
11
11
|
}
|
|
12
|
-
import type { StateFirstDB } from "@feltdb/core";
|
|
13
12
|
import type { AuthContext } from "./authority.js";
|
|
14
13
|
import type { DatabaseReader, DatabaseWriter } from "./data.js";
|
|
15
14
|
import type { ConfigurationReader, ConfigurationWriter, FilesReader, FilesWriter, NotificationsReader, NotificationsWriter, JobsWriter, WebhooksWriter } from "./services.js";
|
|
@@ -28,10 +27,27 @@ export interface EnvironmentInfo {
|
|
|
28
27
|
durable: boolean;
|
|
29
28
|
};
|
|
30
29
|
}
|
|
30
|
+
/** The current tenant's members, read-only (`auth.tenant`). Managing members is the tenancy routes' job. */
|
|
31
|
+
export interface TenancyReader {
|
|
32
|
+
/**
|
|
33
|
+
* The active members of the tenant this call works in (none without a tenant). Live queries that
|
|
34
|
+
* call it re-run when memberships change.
|
|
35
|
+
*/
|
|
36
|
+
members(): Promise<Array<{
|
|
37
|
+
principalId: string;
|
|
38
|
+
type: string;
|
|
39
|
+
role: string;
|
|
40
|
+
claims: Record<string, unknown>;
|
|
41
|
+
displayName?: string;
|
|
42
|
+
email?: string;
|
|
43
|
+
}>>;
|
|
44
|
+
}
|
|
31
45
|
export interface QueryCtx {
|
|
32
46
|
/** Read-only. Queries cannot write. */
|
|
33
47
|
readonly db: DatabaseReader;
|
|
34
48
|
readonly auth: AuthContext;
|
|
49
|
+
/** The current tenant's members (`auth.tenant`). */
|
|
50
|
+
readonly tenancy: TenancyReader;
|
|
35
51
|
readonly services: {
|
|
36
52
|
readonly files: FilesReader;
|
|
37
53
|
readonly notifications: NotificationsReader;
|
|
@@ -47,6 +63,8 @@ export interface MutationCtx {
|
|
|
47
63
|
/** Writes are buffered and commit atomically when the handler returns. */
|
|
48
64
|
readonly db: DatabaseWriter;
|
|
49
65
|
readonly auth: AuthContext;
|
|
66
|
+
/** The current tenant's members (`auth.tenant`). */
|
|
67
|
+
readonly tenancy: TenancyReader;
|
|
50
68
|
/** Service effects commit on their own; they are not part of the mutation's transaction. */
|
|
51
69
|
readonly services: {
|
|
52
70
|
readonly files: FilesWriter;
|
|
@@ -74,13 +92,37 @@ export interface MutationCtx {
|
|
|
74
92
|
/** The FeltKit agent, as the caller. */
|
|
75
93
|
readonly agent: AgentWriter;
|
|
76
94
|
/**
|
|
77
|
-
* Escape hatch: this
|
|
78
|
-
* validated, not part of the mutation's transaction, and not shown as the
|
|
79
|
-
*
|
|
95
|
+
* Escape hatch: FeltDB access to this application's own collections. Writes made here are not
|
|
96
|
+
* validated, not part of the mutation's transaction, and not shown as the mutation's writes in
|
|
97
|
+
* the activity log. It reaches only collections the application declares that do not belong to
|
|
98
|
+
* a workspace; platform collections (sessions, accounts, memberships, activity, API keys,
|
|
99
|
+
* configuration) and workspace collections are refused with FORBIDDEN. Prefer ctx.db.
|
|
80
100
|
*/
|
|
81
101
|
readonly unsafe: {
|
|
82
|
-
readonly feltdb:
|
|
102
|
+
readonly feltdb: import("./escape-hatch.js").EscapeHatch;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** What an application agent's handler (`app.agent`) receives: a mutation's context, as the agent, plus its trigger. */
|
|
106
|
+
export interface AgentCtx extends MutationCtx {
|
|
107
|
+
readonly trigger: AgentTrigger;
|
|
108
|
+
}
|
|
109
|
+
export interface AgentTrigger {
|
|
110
|
+
/** The agent's name. */
|
|
111
|
+
readonly agent: string;
|
|
112
|
+
/** 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. */
|
|
113
|
+
readonly idempotencyKey: string;
|
|
114
|
+
/** 1 on the first attempt. */
|
|
115
|
+
readonly attempt: number;
|
|
116
|
+
/** Who triggered it, for reference only: the agent never holds their authority. */
|
|
117
|
+
readonly by: {
|
|
118
|
+
readonly principalId: string;
|
|
119
|
+
readonly function: string;
|
|
120
|
+
readonly requestId: string;
|
|
83
121
|
};
|
|
122
|
+
/** The event that triggered it (`on`), if one did. */
|
|
123
|
+
readonly event?: string;
|
|
124
|
+
/** The tenant the triggering call worked in, whether or not the agent may work there (`ctx.auth.tenant` says where it does). */
|
|
125
|
+
readonly requestedTenantId?: string;
|
|
84
126
|
}
|
|
85
127
|
/** Start agent work from a mutation. Nothing happens unless the mutation commits. */
|
|
86
128
|
export interface AgentWriter {
|
package/dist/runtime/contract.js
CHANGED
|
@@ -36,13 +36,16 @@ 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 {
|
|
39
|
+
import { AUDIT_COLLECTION } from "./audit.js";
|
|
40
|
+
import { ACCOUNTS_COLLECTION, ACCOUNT_EMAILS_COLLECTION } from "./accounts.js";
|
|
41
|
+
import { CHALLENGES_COLLECTION } from "./challenges.js";
|
|
42
|
+
import { INVITATIONS_COLLECTION, MEMBERSHIPS_COLLECTION, TENANTS_COLLECTION } from "./tenancy.js";
|
|
40
43
|
import { COLLECTION_MARKERS, MIGRATIONS_COLLECTION, SEQUENCES_COLLECTION } from "./data.js";
|
|
41
44
|
import { IDEMPOTENCY_COLLECTION } from "./idempotency.js";
|
|
42
45
|
import { INTEGRATION_CALLS } from "./integrations.js";
|
|
43
46
|
import { SAVED_MODELS } from "./decisions.js";
|
|
44
47
|
import { SESSIONS_COLLECTION } from "./sessions.js";
|
|
45
|
-
import { FILE_CONTENT_COLLECTION } from "./content.js";
|
|
48
|
+
import { FILE_CONTENT_COLLECTION, FILE_LINK_COLLECTION } from "./content.js";
|
|
46
49
|
import { OUTBOX_COLLECTION } from "./outbox.js";
|
|
47
50
|
import { compileStateContract } from "./state-contract.js";
|
|
48
51
|
/**
|
|
@@ -55,6 +58,8 @@ const PLATFORM_COLLECTIONS = {
|
|
|
55
58
|
[COLLECTION_MARKERS]: ["transactionId", "changedAt"],
|
|
56
59
|
[SEQUENCES_COLLECTION]: ["name", "value", "transactionId"],
|
|
57
60
|
[MIGRATIONS_COLLECTION]: ["kind", "from", "to", "changes", "migrations", "writes", "appliedAt", "by", "environment"],
|
|
61
|
+
// The audit trail (runtime/audit.ts): one record per committed mutation, in its transaction.
|
|
62
|
+
[AUDIT_COLLECTION]: ["at", "transactionId", "function", "via", "requestId", "principal", "tenantId", "authority", "writes", "effects"],
|
|
58
63
|
[OUTBOX_COLLECTION]: ["requestId", "function", "principalId", "effect", "state", "createdAt", "updatedAt", "attempts", "error", "result", "retriedBy"],
|
|
59
64
|
[ACTIVITY_COLLECTION]: [
|
|
60
65
|
"at", "kind", "name", "capability", "via", "requestId", "principal", "authority", "outcome", "error",
|
|
@@ -62,7 +67,14 @@ const PLATFORM_COLLECTIONS = {
|
|
|
62
67
|
],
|
|
63
68
|
[SESSIONS_COLLECTION]: ["principal", "permissions", "applicationId", "createdAt", "expiresAt", "attributes"],
|
|
64
69
|
// Built-in accounts (auth.accounts): only a scrypt hash of the password is stored.
|
|
65
|
-
[ACCOUNTS_COLLECTION]: ["email", "name", "passwordHash", "roles", "createdAt", "emailVerifiedAt", "identities"],
|
|
70
|
+
[ACCOUNTS_COLLECTION]: ["email", "name", "passwordHash", "roles", "createdAt", "emailVerifiedAt", "identities", "disabledAt"],
|
|
71
|
+
[ACCOUNT_EMAILS_COLLECTION]: ["accountId"],
|
|
72
|
+
// Account e-mail challenges: a nonce and digests only; the link and code are derived with the auth secret.
|
|
73
|
+
[CHALLENGES_COLLECTION]: ["kind", "purpose", "subject", "nonce", "codeDigest", "expiresAt", "attempts", "data", "current", "issued"],
|
|
74
|
+
// Tenancy (auth.tenant). Invitations hold a nonce; the token is derived with the auth secret.
|
|
75
|
+
[TENANTS_COLLECTION]: ["name", "createdBy", "createdAt", "updatedAt"],
|
|
76
|
+
[MEMBERSHIPS_COLLECTION]: ["tenantId", "principalId", "principalType", "role", "claims", "claimsProvenance", "status", "displayName", "email", "invitedBy", "createdAt", "updatedAt", "lastUsedAt"],
|
|
77
|
+
[INVITATIONS_COLLECTION]: ["tenantId", "email", "role", "claims", "nonce", "invitedBy", "inviterName", "createdAt", "expiresAt", "status", "acceptedBy", "acceptedAt"],
|
|
66
78
|
[IDEMPOTENCY_COLLECTION]: [
|
|
67
79
|
"key", "capability", "version", "requestId", "requestDigest", "sessionId", "principalId", "response",
|
|
68
80
|
"status", "claimedAt", "storedAt", "expiresAt",
|
|
@@ -116,6 +128,8 @@ export function feltdbContract(app) {
|
|
|
116
128
|
}
|
|
117
129
|
if (services.includes("files")) {
|
|
118
130
|
collections.push({ name: FILE_CONTENT_COLLECTION, fields: [ID, ...["data", "size", "checksum"].map((field) => ({ name: field, type: "json", required: false, nullable: true }))] });
|
|
131
|
+
// File links (files.link / uploadLink): keyed by the token's digest.
|
|
132
|
+
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
133
|
}
|
|
120
134
|
collections.push(...FELTDB_AGENT_STATE_CONTRACT.collections);
|
|
121
135
|
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,mBAA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e;YACrB,KAAK,EAAE,eAAe;YACtB,YAAY,EAAE,CAAC,YAAY,EAAE,aAAa,CAAC;SAC5C,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,eAAe,CAAC,GAAe;IAC7C,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IACzG,MAAM,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAE,aAAmC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1F,IAAI,OAAO,CAAC,MAAM;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[];
|
|
@@ -161,15 +190,16 @@ export declare function newId(): string;
|
|
|
161
190
|
export declare function equalityWhere(filter: Record<string, unknown> | undefined): WhereClause[];
|
|
162
191
|
/** Read-only access. Every collection read is recorded so subscribers can be invalidated. */
|
|
163
192
|
export declare class Reader implements DatabaseReader {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
readonly reads: Set<string>;
|
|
193
|
+
/** Collections read (a Set of names), with the equality predicates of reads limited to them. */
|
|
194
|
+
readonly reads: ReadSet;
|
|
167
195
|
constructor(db: StateFirstDB, resolver: CollectionResolver);
|
|
168
|
-
|
|
196
|
+
/** Record a read of `ref`: limited to the equality `clauses` when given, else the whole collection. */
|
|
197
|
+
protected track(ref: CollectionRef, clauses?: WhereClause[]): CollectionDefinition;
|
|
169
198
|
get(ref: CollectionRef, id: string): Promise<any>;
|
|
170
199
|
find(ref: CollectionRef, filter?: Record<string, unknown>, options?: FindOptions): Promise<any[]>;
|
|
171
200
|
query(ref: CollectionRef, request: QueryRequest): Promise<QueryPage<any>>;
|
|
172
201
|
count(ref: CollectionRef, filter?: Record<string, unknown>): Promise<number>;
|
|
202
|
+
search(ref: CollectionRef, request: SearchRequest): Promise<any[]>;
|
|
173
203
|
}
|
|
174
204
|
/** Mutation access: reads see pending writes; writes commit together. */
|
|
175
205
|
export declare class Writer extends Reader implements DatabaseWriter {
|
|
@@ -189,11 +219,19 @@ export declare class Writer extends Reader implements DatabaseWriter {
|
|
|
189
219
|
/** Whether this mutation drew from a sequence. */
|
|
190
220
|
get usedSequences(): boolean;
|
|
191
221
|
get pendingCount(): number;
|
|
222
|
+
/** What this mutation will write: collection, id and operation (no values). For the audit record; not on `ctx.db`. */
|
|
223
|
+
pendingWrites(): Array<{
|
|
224
|
+
collection: string;
|
|
225
|
+
id: string;
|
|
226
|
+
op: "insert" | "update" | "delete";
|
|
227
|
+
}>;
|
|
192
228
|
get(ref: CollectionRef, id: string): Promise<any>;
|
|
193
229
|
find(ref: CollectionRef, filter?: Record<string, unknown>, options?: FindOptions): Promise<any[]>;
|
|
194
230
|
/** As `find(...).length`, with the same fence and this mutation's own writes; counted in pages when there are none. */
|
|
195
231
|
count(ref: CollectionRef, filter?: Record<string, unknown>): Promise<number>;
|
|
196
232
|
query(ref: CollectionRef, request: QueryRequest): Promise<QueryPage<any>>;
|
|
233
|
+
/** As `find` with the same fence: this mutation's own pending writes are searched too. */
|
|
234
|
+
search(ref: CollectionRef, request: SearchRequest): Promise<any[]>;
|
|
197
235
|
insert(ref: CollectionRef, value: Record<string, unknown>): Promise<string>;
|
|
198
236
|
patch(ref: CollectionRef, id: string, fields: Record<string, unknown>): Promise<any>;
|
|
199
237
|
replace(ref: CollectionRef, id: string, value: Record<string, unknown>): Promise<any>;
|
|
@@ -217,3 +255,11 @@ export declare const CONTRACT_CHANGED_HINT = "The request was built for the prev
|
|
|
217
255
|
* stays out of the answer.
|
|
218
256
|
*/
|
|
219
257
|
export declare function feltdbRefusalJSON(error: unknown): FeltKitErrorJSON | null;
|
|
258
|
+
/**
|
|
259
|
+
* What application code holds as `ctx.db`: the documented reader or writer methods, bound to
|
|
260
|
+
* FeltKit's own Reader/Writer, and nothing else. The Writer also carries the runtime's commit
|
|
261
|
+
* machinery (`stageSystem`, `staged`, `commit`): handed to application code, `stageSystem` alone
|
|
262
|
+
* would let a function have FeltKit commit any record into any collection, a session included
|
|
263
|
+
* (test/escape-hatch.test.ts).
|
|
264
|
+
*/
|
|
265
|
+
export declare function applicationView(db: Reader): DatabaseReader | DatabaseWriter;
|