@feltdb/core 0.9.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands.js +151 -22
- package/dist/cli/development-session.js +16 -0
- package/dist/cli/index.js +1 -1
- package/dist/cli/studio-artifact.js +33 -0
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +6 -4
- package/dist/create/package-versions.js +1 -1
- package/dist/create/server-source/crates/feltdb/src/acceptance_tests.rs +8 -1
- package/dist/create/server-source/crates/feltdb/src/application.rs +16 -0
- package/dist/create/server-source/crates/feltdb/src/bin/feltdb_node.rs +21 -22
- package/dist/create/server-source/crates/feltdb/src/lib.rs +556 -45
- package/dist/create/server-source/crates/feltdb/src/state_contract.rs +48 -3
- package/dist/create/server-source/crates/feltdb/src/state_model.rs +569 -4
- package/dist/create/server-source/crates/feltdb/src/state_trigger.rs +1 -0
- package/dist/create/server-source/crates/feltdb/src/versioned_object_substrate.rs +708 -0
- package/dist/create/server-source/crates/feltdb/src/worker_mesh.rs +1 -0
- package/dist/create/server-source/crates/feltdb/src/workload.rs +480 -44
- package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_evidence.rs +123 -0
- package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_substrate_completion.rs +281 -0
- package/dist/create/server-source/crates/feltdb/tests/local_process_ownership.rs +69 -0
- package/dist/create/server-source/crates/feltdb/tests/production_readiness_contract.rs +15 -3
- package/dist/create/server-source/crates/feltdb/tests/revision_retention_boundary_evidence.rs +49 -24
- package/dist/create/server-source/crates/feltdb/tests/storage_independent_versioned_object_substrate.rs +328 -0
- package/dist/create/server-source/crates/feltdb/tests/workload_envelope_contract.rs +20 -3
- package/dist/create/server-source/crates/feltdb-server/src/app_state.rs +14 -4
- package/dist/create/server-source/crates/feltdb-server/src/backup.rs +0 -4
- package/dist/create/server-source/crates/feltdb-server/src/canonical_principals.rs +1093 -0
- package/dist/create/server-source/crates/feltdb-server/src/causal.rs +905 -144
- package/dist/create/server-source/crates/feltdb-server/src/connections.rs +9 -6
- package/dist/create/server-source/crates/feltdb-server/src/control_plane.rs +90 -0
- package/dist/create/server-source/crates/feltdb-server/src/lib.rs +1 -0
- package/dist/create/server-source/crates/feltdb-server/src/main.rs +418 -82
- package/dist/create/server-source/crates/feltdb-server/src/principals.rs +9 -501
- package/dist/create/server-source/crates/feltdb-server/src/tenancy.rs +22 -0
- package/dist/create/server-source/crates/feltdb-server/tests/principal_tenant_migration.rs +247 -0
- package/dist/db.d.ts +6 -5
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +18 -24
- package/dist/deployment.d.ts.map +1 -1
- package/dist/deployment.js +4 -2
- package/dist/embedded-transaction.d.ts.map +1 -1
- package/dist/embedded-transaction.js +4 -0
- package/dist/error-codes.d.ts +12 -0
- package/dist/error-codes.d.ts.map +1 -1
- package/dist/error-codes.js +20 -2
- package/dist/feltdb.d.ts +4 -0
- package/dist/feltdb.d.ts.map +1 -1
- package/dist/file-db.d.ts +12 -0
- package/dist/file-db.d.ts.map +1 -1
- package/dist/file-db.js +66 -6
- package/dist/http-db.d.ts +4 -0
- package/dist/http-db.d.ts.map +1 -1
- package/dist/http-db.js +73 -12
- package/dist/index-core.d.ts +1 -0
- package/dist/index-core.d.ts.map +1 -1
- package/dist/index-core.js +1 -0
- package/dist/memory-db.d.ts +1 -0
- package/dist/memory-db.d.ts.map +1 -1
- package/dist/memory-db.js +1 -1
- package/dist/public-contract.d.ts +112 -0
- package/dist/public-contract.d.ts.map +1 -0
- package/dist/public-contract.js +125 -0
- package/dist/studio/app.d.ts +23 -0
- package/dist/studio/app.d.ts.map +1 -1
- package/dist/studio/components/ContractInspector.d.ts +5 -0
- package/dist/studio/components/ContractInspector.d.ts.map +1 -1
- package/dist/studio/components/SettingsPanel.d.ts +4 -1
- package/dist/studio/components/SettingsPanel.d.ts.map +1 -1
- package/dist/studio/components/index.js +4 -4
- package/dist/studio/{components-CehkcX_k.js → components-BHTKlUgT.js} +323 -304
- package/dist/studio/control-plane/Data.d.ts.map +1 -1
- package/dist/studio/control-plane/Instance.d.ts +10 -0
- package/dist/studio/control-plane/Instance.d.ts.map +1 -1
- package/dist/studio/control-plane/Operations.d.ts +3 -0
- package/dist/studio/control-plane/Operations.d.ts.map +1 -1
- package/dist/studio/control-plane/State.d.ts.map +1 -1
- package/dist/studio/control-plane/index.d.ts +4 -2
- package/dist/studio/control-plane/index.d.ts.map +1 -1
- package/dist/studio/control-plane/index.js +2 -2
- package/dist/studio/control-plane-DP8ljTDO.js +3207 -0
- package/dist/studio/index.js +96 -75
- package/dist/studio/utils/api.d.ts +1 -1
- package/dist/studio/utils/api.d.ts.map +1 -1
- package/dist/studio/utils/control-plane-api.d.ts +12 -1
- package/dist/studio/utils/control-plane-api.d.ts.map +1 -1
- package/dist/studio/utils/control-plane-api.js +1 -1
- package/dist/studio/utils/index.js +16 -16
- package/dist/studio/utils/service-api.d.ts +8 -0
- package/dist/studio/utils/service-api.d.ts.map +1 -1
- package/dist/studio/utils/service-api.js +15 -12
- package/dist/studio-app/assets/{feltdb_wasm-DksXDnLa.js → feltdb_wasm-Dlr_kLlk.js} +1 -1
- package/dist/studio-app/assets/feltdb_wasm_bg-CkozAQKb.wasm +0 -0
- package/dist/studio-app/assets/index-H_L5pjur.js +30 -0
- package/dist/studio-app/feltdb-studio.json +6 -0
- package/dist/studio-app/index.html +1 -1
- package/dist/transaction.d.ts +9 -1
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +6 -2
- package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
- package/dist/workspace/local-development-authority.d.ts +8 -0
- package/dist/workspace/local-development-authority.d.ts.map +1 -1
- package/dist/workspace/local-development-authority.js +136 -1
- package/package.json +2 -2
- package/dist/studio/control-plane-D6TT2fCQ.js +0 -3064
- package/dist/studio-app/assets/feltdb_wasm_bg-Yy4QRHJT.wasm +0 -0
- package/dist/studio-app/assets/index-CZ55nLgp.js +0 -30
package/dist/file-db.js
CHANGED
|
@@ -53,6 +53,7 @@ export class FileJsDb {
|
|
|
53
53
|
}
|
|
54
54
|
loadState() {
|
|
55
55
|
const nodeFs = getFsSync();
|
|
56
|
+
const backupPath = `${this.statePath}.backup`;
|
|
56
57
|
// Load atomic snapshot if it exists
|
|
57
58
|
if (nodeFs.existsSync(this.statePath)) {
|
|
58
59
|
try {
|
|
@@ -60,8 +61,15 @@ export class FileJsDb {
|
|
|
60
61
|
const snapshot = JSON.parse(content);
|
|
61
62
|
// Validate snapshot structure
|
|
62
63
|
if (snapshot.version !== 1 || !snapshot.meta || !snapshot.rows || !snapshot.events) {
|
|
63
|
-
console.warn(`Invalid snapshot structure at ${this.statePath},
|
|
64
|
-
return this.
|
|
64
|
+
console.warn(`Invalid snapshot structure at ${this.statePath}, attempting backup recovery`);
|
|
65
|
+
return this.loadStateFromBackup();
|
|
66
|
+
}
|
|
67
|
+
// Successfully loaded valid state, preserve it as backup
|
|
68
|
+
try {
|
|
69
|
+
nodeFs.copyFileSync(this.statePath, backupPath);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Backup failure is non-fatal
|
|
65
73
|
}
|
|
66
74
|
return {
|
|
67
75
|
version: snapshot.version,
|
|
@@ -75,12 +83,41 @@ export class FileJsDb {
|
|
|
75
83
|
};
|
|
76
84
|
}
|
|
77
85
|
catch (error) {
|
|
78
|
-
console.warn(`Failed to load snapshot from ${this.statePath}
|
|
79
|
-
|
|
86
|
+
console.warn(`Failed to load snapshot from ${this.statePath}: ${error}`);
|
|
87
|
+
console.warn(`Attempting to recover from backup...`);
|
|
88
|
+
return this.loadStateFromBackup();
|
|
80
89
|
}
|
|
81
90
|
}
|
|
82
91
|
return this.initializeState();
|
|
83
92
|
}
|
|
93
|
+
loadStateFromBackup() {
|
|
94
|
+
const nodeFs = getFsSync();
|
|
95
|
+
const backupPath = `${this.statePath}.backup`;
|
|
96
|
+
if (nodeFs.existsSync(backupPath)) {
|
|
97
|
+
try {
|
|
98
|
+
const content = nodeFs.readFileSync(backupPath, 'utf-8');
|
|
99
|
+
const snapshot = JSON.parse(content);
|
|
100
|
+
if (snapshot.version === 1 && snapshot.meta && snapshot.rows && snapshot.events) {
|
|
101
|
+
console.warn(`Recovered state from backup at ${backupPath}`);
|
|
102
|
+
return {
|
|
103
|
+
version: snapshot.version,
|
|
104
|
+
instance_id: this.origin,
|
|
105
|
+
sequence: snapshot.meta.sequence,
|
|
106
|
+
rows: snapshot.rows,
|
|
107
|
+
events: snapshot.events,
|
|
108
|
+
peers: snapshot.meta.peers ?? [],
|
|
109
|
+
sequences: snapshot.meta.sequences ?? {},
|
|
110
|
+
applied_transactions: snapshot.applied_transactions ?? []
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Backup is also corrupted or invalid
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
console.warn(`Backup recovery failed, reinitializing state`);
|
|
119
|
+
return this.initializeState();
|
|
120
|
+
}
|
|
84
121
|
initializeState() {
|
|
85
122
|
return {
|
|
86
123
|
version: 1,
|
|
@@ -333,7 +370,11 @@ export class FileJsDb {
|
|
|
333
370
|
if (plan.kind === 'reject')
|
|
334
371
|
throw new EmbeddedTransactionRejected(plan.reason, plan.failure);
|
|
335
372
|
// Build the post-transaction state without touching the live one.
|
|
336
|
-
|
|
373
|
+
// Critical: Deep-copy rows to prevent stale references after refresh
|
|
374
|
+
const rows = {};
|
|
375
|
+
for (const [key, value] of Object.entries(this.state.rows)) {
|
|
376
|
+
rows[key] = value;
|
|
377
|
+
}
|
|
337
378
|
const events = [...this.state.events];
|
|
338
379
|
let sequence = this.state.sequence;
|
|
339
380
|
const timestamp = Date.now();
|
|
@@ -502,6 +543,24 @@ export class FileJsDb {
|
|
|
502
543
|
this.refresh();
|
|
503
544
|
return [...this.state.events];
|
|
504
545
|
}
|
|
546
|
+
/** Read-only projection of the materialized authority state. */
|
|
547
|
+
authorityStateSummary() {
|
|
548
|
+
this.refresh();
|
|
549
|
+
const cardinalities = new Map();
|
|
550
|
+
for (const key of Object.keys(this.state.rows)) {
|
|
551
|
+
const separator = key.indexOf(':');
|
|
552
|
+
const collection = separator === -1 ? key : key.slice(0, separator);
|
|
553
|
+
cardinalities.set(collection, (cardinalities.get(collection) ?? 0) + 1);
|
|
554
|
+
}
|
|
555
|
+
return {
|
|
556
|
+
current_sequence: this.state.sequence,
|
|
557
|
+
records: Object.keys(this.state.rows).length,
|
|
558
|
+
events: this.state.events.length,
|
|
559
|
+
collections: [...cardinalities]
|
|
560
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
561
|
+
.map(([collection, records]) => ({ collection, records })),
|
|
562
|
+
};
|
|
563
|
+
}
|
|
505
564
|
export_operations(sinceSequence) {
|
|
506
565
|
this.refresh();
|
|
507
566
|
return this.state.events.filter(event => event.sequence > sinceSequence);
|
|
@@ -812,7 +871,8 @@ export class FileJsDb {
|
|
|
812
871
|
return {
|
|
813
872
|
updated: true,
|
|
814
873
|
currentVersion: params.expectedVersion + 1,
|
|
815
|
-
currentEpoch
|
|
874
|
+
currentEpoch,
|
|
875
|
+
item: newValue
|
|
816
876
|
};
|
|
817
877
|
}
|
|
818
878
|
catch (error) {
|
package/dist/http-db.d.ts
CHANGED
|
@@ -175,6 +175,8 @@ export declare class HttpJsDb implements JsDb {
|
|
|
175
175
|
operations: number;
|
|
176
176
|
stateBefore: number;
|
|
177
177
|
stateAfter: number;
|
|
178
|
+
revisionId: string;
|
|
179
|
+
operationIds: string[];
|
|
178
180
|
}>;
|
|
179
181
|
/**
|
|
180
182
|
* Atomically create a record only if the key is free.
|
|
@@ -244,6 +246,8 @@ export declare class HttpJsDb implements JsDb {
|
|
|
244
246
|
acquireContent(hash: string): Promise<Uint8Array | null>;
|
|
245
247
|
command(path: string, body: unknown): Promise<any>;
|
|
246
248
|
application_request<T>(path: string, init?: RequestInit): Promise<T>;
|
|
249
|
+
/** Canonical HTTP adapter used by the typed public substrate contract. */
|
|
250
|
+
public_request<T>(path: string, init?: RequestInit): Promise<T>;
|
|
247
251
|
/**
|
|
248
252
|
* Subscribe to change notifications.
|
|
249
253
|
*
|
package/dist/http-db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-db.d.ts","sourceRoot":"","sources":["../src/http-db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAEkD,KAAK,mBAAmB,EAChF,MAAM,uBAAuB,CAAC;AAE/B,UAAU,QAAQ;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,kBAAkB;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,MAAM,CAAA;KAAE,CAAC;IACpF;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAGD,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,OAAO,CAAC;QAAC,GAAG,CAAC,E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B,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI;YAavD,aAAa;YAsFb,OAAO;IASrB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAC7D,UAAU,IAAI,QAAQ;IACtB,SAAS,IAAI,QAAQ;IACrB,QAAQ,IAAI,QAAQ;IACpB,aAAa,IAAI,QAAQ;IACzB,gBAAgB,IAAI,QAAQ;IAC5B,oBAAoB,IAAI,QAAQ;IAChC,2BAA2B,IAAI,QAAQ;IACvC,WAAW,IAAI,MAAM;IAErB;;;;;;;;OAQG;IACH,YAAY,IAAI,MAAM;IAEtB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,eAAe,CAAC,CAAS;IAE3B,SAAS,IAAI,OAAO,CAAC,mBAAmB,CAAC;IA0BzC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;YAKrB,IAAI;IAOlB,OAAO,CAAC,MAAM;CAIf"}
|
package/dist/http-db.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FeltDBServiceError } from './error-codes.js';
|
|
1
|
+
import { FeltDBErrorCode, FeltDBServiceError } from './error-codes.js';
|
|
2
2
|
import { conditionalRefusal } from './transaction.js';
|
|
3
3
|
import { BoundedBackoff, SingleFlightValue, cancellableDelay, describeFailure, } from './managed-recovery.js';
|
|
4
4
|
/**
|
|
@@ -15,6 +15,20 @@ function conditionalTransactionId(purpose) {
|
|
|
15
15
|
: `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
16
16
|
return `${purpose}-${unique}`;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The canonical state API exposes storage projection metadata as `_id` and
|
|
20
|
+
* `_version`. The collection SDK has its own document contract (`id` and
|
|
21
|
+
* `__version`), so those projection-only fields must not leak into remote
|
|
22
|
+
* collection values or make managed results differ from embedded results.
|
|
23
|
+
*/
|
|
24
|
+
function managedCollectionRecord(value) {
|
|
25
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
26
|
+
return value;
|
|
27
|
+
const record = { ...value };
|
|
28
|
+
delete record._id;
|
|
29
|
+
delete record._version;
|
|
30
|
+
return record;
|
|
31
|
+
}
|
|
18
32
|
/** Network adapter implementing the same collection runtime contract as WASM. */
|
|
19
33
|
export class HttpJsDb {
|
|
20
34
|
url;
|
|
@@ -204,7 +218,7 @@ export class HttpJsDb {
|
|
|
204
218
|
const [collection, id] = this.splitKey(key);
|
|
205
219
|
if (this.applicationId) {
|
|
206
220
|
const result = await this.canonical('/query', { query: { collection, filter: { operator: 'eq', field: 'id', value: id }, limit: 1 } });
|
|
207
|
-
return { success: true, data: result.records.length ? JSON.stringify(result.records[0]) : undefined };
|
|
221
|
+
return { success: true, data: result.records.length ? JSON.stringify(managedCollectionRecord(result.records[0])) : undefined };
|
|
208
222
|
}
|
|
209
223
|
const response = await fetch(`${this.url}/collections/${encodeURIComponent(collection)}/${encodeURIComponent(id)}`, {
|
|
210
224
|
headers: this.headers(),
|
|
@@ -229,7 +243,7 @@ export class HttpJsDb {
|
|
|
229
243
|
const page = await this.canonical('/query', {
|
|
230
244
|
query: { collection, limit: 100, ...(cursor ? { cursor } : {}) },
|
|
231
245
|
});
|
|
232
|
-
records.push(...page.records);
|
|
246
|
+
records.push(...page.records.map(managedCollectionRecord));
|
|
233
247
|
cursor = page.next_cursor;
|
|
234
248
|
} while (cursor);
|
|
235
249
|
return { success: true, data: JSON.stringify(records) };
|
|
@@ -259,7 +273,7 @@ export class HttpJsDb {
|
|
|
259
273
|
order_by: query.orderBy?.map(value => ({ field: value.field, direction: value.direction })),
|
|
260
274
|
limit: query.limit, cursor: query.cursor,
|
|
261
275
|
} });
|
|
262
|
-
return { records: result.records, nextCursor: result.next_cursor, exhausted: !result.next_cursor, plan: result.plan };
|
|
276
|
+
return { records: result.records.map(managedCollectionRecord), nextCursor: result.next_cursor, exhausted: !result.next_cursor, plan: result.plan };
|
|
263
277
|
}
|
|
264
278
|
const response = await fetch(`${this.url}/query`, {
|
|
265
279
|
method: 'POST', headers: this.headers(true), body: JSON.stringify(query),
|
|
@@ -324,7 +338,11 @@ export class HttpJsDb {
|
|
|
324
338
|
if (this.applicationId) {
|
|
325
339
|
const operations = request.operations.map(operation => ({
|
|
326
340
|
kind: operation.value === undefined ? 'delete' : operation.requireAbsent ? 'insert' : 'update',
|
|
327
|
-
collection: operation.collection,
|
|
341
|
+
collection: operation.collection,
|
|
342
|
+
id: operation.id,
|
|
343
|
+
value: operation.value && typeof operation.value === 'object' && !Array.isArray(operation.value)
|
|
344
|
+
? { ...operation.value, id: operation.id }
|
|
345
|
+
: operation.value,
|
|
328
346
|
}));
|
|
329
347
|
// Every record-level guard travels as a `record` precondition, which the
|
|
330
348
|
// authority evaluates inside the same lock as the writes and against the
|
|
@@ -348,13 +366,21 @@ export class HttpJsDb {
|
|
|
348
366
|
expected_lease_id: guard.expectedLeaseId,
|
|
349
367
|
}));
|
|
350
368
|
const result = await this.canonicalTransaction(operations, request.transactionId, guards);
|
|
351
|
-
return { transactionId: result.transaction_id, baseRevision: result.base_revision, commitRevision: result.commit_revision, status: result.status, duplicate: result.duplicate, operations: operations.length, stateBefore: result.state_before, stateAfter: result.state_after };
|
|
369
|
+
return { transactionId: result.transaction_id, baseRevision: result.base_revision, commitRevision: result.commit_revision, revisionId: result.revision_id, operationIds: result.operation_ids, status: result.status, duplicate: result.duplicate, operations: operations.length, stateBefore: result.state_before, stateAfter: result.state_after };
|
|
370
|
+
}
|
|
371
|
+
let response;
|
|
372
|
+
try {
|
|
373
|
+
response = await fetch(`${this.url}/transactions`, {
|
|
374
|
+
method: 'POST',
|
|
375
|
+
headers: this.headers(true),
|
|
376
|
+
body: JSON.stringify(request),
|
|
377
|
+
signal: AbortSignal.timeout(this.requestTimeoutMs),
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
this.recordFailure(error);
|
|
382
|
+
throw new FeltDBServiceError(error instanceof Error ? error.message : String(error), FeltDBErrorCode.COMMIT_OUTCOME_UNKNOWN);
|
|
352
383
|
}
|
|
353
|
-
const response = await fetch(`${this.url}/transactions`, {
|
|
354
|
-
method: 'POST',
|
|
355
|
-
headers: this.headers(true),
|
|
356
|
-
body: JSON.stringify(request),
|
|
357
|
-
});
|
|
358
384
|
if (!response.ok) {
|
|
359
385
|
// The authority answers a refused transaction with a structured
|
|
360
386
|
// document. Flattening it to a message here is what would force a
|
|
@@ -618,7 +644,8 @@ export class HttpJsDb {
|
|
|
618
644
|
}
|
|
619
645
|
catch (error) {
|
|
620
646
|
this.recordFailure(error);
|
|
621
|
-
|
|
647
|
+
const mutating = !['GET', 'HEAD', 'OPTIONS'].includes((init.method ?? 'GET').toUpperCase());
|
|
648
|
+
throw new FeltDBServiceError(error instanceof Error ? error.message : String(error), mutating ? FeltDBErrorCode.COMMIT_OUTCOME_UNKNOWN : FeltDBErrorCode.SERVICE_UNAVAILABLE);
|
|
622
649
|
}
|
|
623
650
|
const text = await response.text();
|
|
624
651
|
let body;
|
|
@@ -636,6 +663,40 @@ export class HttpJsDb {
|
|
|
636
663
|
this.recordSuccess();
|
|
637
664
|
return body;
|
|
638
665
|
}
|
|
666
|
+
/** Canonical HTTP adapter used by the typed public substrate contract. */
|
|
667
|
+
async public_request(path, init = {}) {
|
|
668
|
+
let response;
|
|
669
|
+
try {
|
|
670
|
+
response = await fetch(`${this.url}${path}`, {
|
|
671
|
+
...init,
|
|
672
|
+
signal: init.signal ?? AbortSignal.timeout(this.requestTimeoutMs),
|
|
673
|
+
headers: { ...this.headers(init.body !== undefined), ...(init.headers || {}) },
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
catch (error) {
|
|
677
|
+
this.recordFailure(error);
|
|
678
|
+
const mutating = !['GET', 'HEAD', 'OPTIONS'].includes((init.method ?? 'GET').toUpperCase());
|
|
679
|
+
throw new FeltDBServiceError(error instanceof Error ? error.message : String(error), mutating ? FeltDBErrorCode.COMMIT_OUTCOME_UNKNOWN : FeltDBErrorCode.SERVICE_UNAVAILABLE);
|
|
680
|
+
}
|
|
681
|
+
const text = await response.text();
|
|
682
|
+
let body;
|
|
683
|
+
try {
|
|
684
|
+
body = text ? JSON.parse(text) : undefined;
|
|
685
|
+
}
|
|
686
|
+
catch {
|
|
687
|
+
body = { message: text };
|
|
688
|
+
}
|
|
689
|
+
if (!response.ok) {
|
|
690
|
+
const error = new FeltDBServiceError(body?.message || body?.error || `FeltDB request failed: HTTP ${response.status}`, body?.code || (response.status === 401 ? FeltDBErrorCode.UNAUTHORIZED
|
|
691
|
+
: response.status === 403 ? FeltDBErrorCode.FORBIDDEN
|
|
692
|
+
: response.status === 404 ? FeltDBErrorCode.NOT_FOUND
|
|
693
|
+
: 'INVALID_REQUEST'), body?.request_id, response.status);
|
|
694
|
+
this.recordFailure(error);
|
|
695
|
+
throw error;
|
|
696
|
+
}
|
|
697
|
+
this.recordSuccess();
|
|
698
|
+
return body;
|
|
699
|
+
}
|
|
639
700
|
/**
|
|
640
701
|
* Subscribe to change notifications.
|
|
641
702
|
*
|
package/dist/index-core.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export * from './operation-admission.js';
|
|
|
43
43
|
export * from './error-codes.js';
|
|
44
44
|
export * from './authority-scope.js';
|
|
45
45
|
export * from './managed-recovery.js';
|
|
46
|
+
export * from './public-contract.js';
|
|
46
47
|
export * from './authorization.js';
|
|
47
48
|
export * from './sync-contract.js';
|
|
48
49
|
export * from './workload.js';
|
package/dist/index-core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-core.d.ts","sourceRoot":"","sources":["../src/index-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAA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e,CAAC;AAEvB;;GAEG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AAEnC;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACnE,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEzE;;GAEG;AACH,YAAY,EACV,eAAe,EACf,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC"}
|
package/dist/index-core.js
CHANGED
|
@@ -42,6 +42,7 @@ export * from './operation-admission.js';
|
|
|
42
42
|
export * from './error-codes.js';
|
|
43
43
|
export * from './authority-scope.js';
|
|
44
44
|
export * from './managed-recovery.js';
|
|
45
|
+
export * from './public-contract.js';
|
|
45
46
|
export * from './authorization.js';
|
|
46
47
|
export * from './sync-contract.js';
|
|
47
48
|
export * from './workload.js';
|
package/dist/memory-db.d.ts
CHANGED
package/dist/memory-db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-db.d.ts","sourceRoot":"","sources":["../src/memory-db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAA8B,KAAK,mBAAmB,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACrG,OAAO,KAAK,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAO1F,UAAU,QAAQ;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAA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AC1C,2BAA2B,IAAI,QAAQ;IACvC,oBAAoB,IAAI,QAAQ;IAChC,WAAW,IAAI,MAAM;IACrB,YAAY,IAAI,MAAM;IAEtB;;;;;;;OAOG;IACH,SAAS,IAAI,mBAAmB;IAiB1B,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;IAQnC,YAAY;IACZ,iBAAiB,CAAC,aAAa,EAAE,MAAM;IACvC,uBAAuB,CAAC,UAAU,EAAE,aAAa,EAAE;;;;CAmBpD"}
|
package/dist/memory-db.js
CHANGED
|
@@ -137,7 +137,7 @@ export class MemoryJsDb {
|
|
|
137
137
|
const updated = { ...parsed, __version: newVersion };
|
|
138
138
|
this.rows.set(params.key, updated);
|
|
139
139
|
this.event(params.key.split(':')[0], params.key, 'put', updated);
|
|
140
|
-
return Promise.resolve({ updated: true, currentVersion: newVersion, currentEpoch });
|
|
140
|
+
return Promise.resolve({ updated: true, currentVersion: newVersion, currentEpoch, item: updated });
|
|
141
141
|
}
|
|
142
142
|
query(capability) {
|
|
143
143
|
const prefix = `${capability}:`;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { AuthorityScope } from './authority-scope.js';
|
|
2
|
+
import type { Collection } from './collection.js';
|
|
3
|
+
import type { StateFirstDB } from './db.js';
|
|
4
|
+
import type { AtomicTransactionDocument, AtomicTransactionOptions, AtomicTransactionResult, AtomicTransactionScope } from './transaction.js';
|
|
5
|
+
import type { CreateWorkloadInput, Workload } from './workload.js';
|
|
6
|
+
import type { CausalEvent } from './observe.js';
|
|
7
|
+
export declare const FELTDB_PUBLIC_CONTRACT_VERSION: "1.0";
|
|
8
|
+
declare const cursorBrand: unique symbol;
|
|
9
|
+
/** Opaque resume token. No parsing, comparison, or arithmetic is public. */
|
|
10
|
+
export type FeltDBEventCursor = string & {
|
|
11
|
+
readonly [cursorBrand]: true;
|
|
12
|
+
};
|
|
13
|
+
export interface PublicTransactionResult extends AtomicTransactionResult {
|
|
14
|
+
baseRevision: number;
|
|
15
|
+
commitRevision: number;
|
|
16
|
+
revisionId: string;
|
|
17
|
+
operationIds: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface PublicEvent extends CausalEvent {
|
|
20
|
+
revision_id: string;
|
|
21
|
+
operation_ids: string[];
|
|
22
|
+
metadata: CausalEvent['metadata'] & {
|
|
23
|
+
cursor: FeltDBEventCursor;
|
|
24
|
+
transaction_id: string;
|
|
25
|
+
revision_id: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface EventReplayPage {
|
|
29
|
+
contract_version: typeof FELTDB_PUBLIC_CONTRACT_VERSION;
|
|
30
|
+
cursor_format: 'fh1';
|
|
31
|
+
application_id: string;
|
|
32
|
+
environment: string;
|
|
33
|
+
events: PublicEvent[];
|
|
34
|
+
next_cursor: FeltDBEventCursor;
|
|
35
|
+
}
|
|
36
|
+
export interface PublicPrincipal {
|
|
37
|
+
id: string;
|
|
38
|
+
tenant_id: string;
|
|
39
|
+
application_id: string;
|
|
40
|
+
kind: string;
|
|
41
|
+
name: string;
|
|
42
|
+
status: string;
|
|
43
|
+
capabilities: string[];
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
}
|
|
46
|
+
export interface PublicCapabilityDeclaration {
|
|
47
|
+
contract: 'feltdb.public.substrate';
|
|
48
|
+
contract_version: typeof FELTDB_PUBLIC_CONTRACT_VERSION;
|
|
49
|
+
cursor_format_version: 'fh1';
|
|
50
|
+
stored_state_schema_version: number;
|
|
51
|
+
migration_version: string;
|
|
52
|
+
capabilities: Array<{
|
|
53
|
+
capability: string;
|
|
54
|
+
contract_version: string;
|
|
55
|
+
support: 'supported' | 'unsupported' | 'conditionally_supported';
|
|
56
|
+
supported_transport: string[];
|
|
57
|
+
scope_requirements: string;
|
|
58
|
+
durability_semantics: string;
|
|
59
|
+
authority_owner: 'canonical_feltdb';
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
type PublicRequest = <T>(path: string, init?: RequestInit) => Promise<T>;
|
|
63
|
+
/**
|
|
64
|
+
* One typed public adapter over the canonical FeltDB authority.
|
|
65
|
+
*
|
|
66
|
+
* This class owns no records, versions, cursors, work, provenance, or retry
|
|
67
|
+
* log. Its fields are routing adapters; destroying this object loses no
|
|
68
|
+
* durable information.
|
|
69
|
+
*/
|
|
70
|
+
export declare class FeltDBPublicContract {
|
|
71
|
+
private readonly db;
|
|
72
|
+
private readonly scope;
|
|
73
|
+
private readonly applicationId;
|
|
74
|
+
private readonly environment;
|
|
75
|
+
private readonly request?;
|
|
76
|
+
readonly version: "1.0";
|
|
77
|
+
constructor(db: StateFirstDB, scope: AuthorityScope | undefined, applicationId: string | undefined, environment: string, request?: PublicRequest | undefined);
|
|
78
|
+
private requireApplicationScope;
|
|
79
|
+
private authority;
|
|
80
|
+
readonly state: {
|
|
81
|
+
collection: <T>(name: string) => Collection<T>;
|
|
82
|
+
transaction: (build: ((transaction: AtomicTransactionScope) => void | Promise<void>) | AtomicTransactionDocument, options?: AtomicTransactionOptions) => Promise<PublicTransactionResult>;
|
|
83
|
+
};
|
|
84
|
+
readonly principals: {
|
|
85
|
+
list: () => Promise<PublicPrincipal[]>;
|
|
86
|
+
create: (input: {
|
|
87
|
+
kind: string;
|
|
88
|
+
name: string;
|
|
89
|
+
}) => Promise<PublicPrincipal>;
|
|
90
|
+
grant: (principalId: string, capability: string) => Promise<PublicPrincipal>;
|
|
91
|
+
};
|
|
92
|
+
readonly work: {
|
|
93
|
+
create: (input: CreateWorkloadInput) => Promise<Workload>;
|
|
94
|
+
inspect: (workId: string) => Promise<Workload>;
|
|
95
|
+
history: (workId: string) => Promise<unknown>;
|
|
96
|
+
};
|
|
97
|
+
readonly events: {
|
|
98
|
+
replay: (after?: FeltDBEventCursor, options?: {
|
|
99
|
+
limit?: number;
|
|
100
|
+
}) => Promise<EventReplayPage>;
|
|
101
|
+
subscribe: (after: FeltDBEventCursor | undefined, listener: (event: PublicEvent) => void | Promise<void>, options?: {
|
|
102
|
+
pollIntervalMs?: number;
|
|
103
|
+
signal?: AbortSignal;
|
|
104
|
+
}) => (() => void);
|
|
105
|
+
};
|
|
106
|
+
readonly provenance: {
|
|
107
|
+
record: (collection: string, id: string) => Promise<unknown>;
|
|
108
|
+
};
|
|
109
|
+
capabilities(): Promise<PublicCapabilityDeclaration>;
|
|
110
|
+
}
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=public-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-contract.d.ts","sourceRoot":"","sources":["../src/public-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EACV,yBAAyB,EACzB,wBAAwB,EACxB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,eAAO,MAAM,8BAA8B,EAAG,KAAc,CAAC;AAE7D,OAAO,CAAC,MAAM,WAAW,EAAE,OAAO,MAAM,CAAC;AACzC,4EAA4E;AAC5E,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,WAAW,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAE1E,MAAM,WAAW,uBAAwB,SAAQ,uBAAuB;IACtE,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE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AQ,CAAC,MAAM;yBAEH,iBAAiB,YAChB;YAAE,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,KAC1B,OAAO,CAAC,eAAe,CAAC;2BAWlB,iBAAiB,GAAG,SAAS,YAC1B,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,YAC7C;YAAE,cAAc,CAAC,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,WAAW,CAAA;SAAE,KACzD,CAAC,MAAM,IAAI,CAAC;MAyBf;IAEF,QAAQ,CAAC,UAAU;6BACU,MAAM,MAAM,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;MAUhE;IAEI,YAAY,IAAI,OAAO,CAAC,2BAA2B,CAAC;CAM3D"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { FeltDBErrorCode, FeltDBServiceError } from './error-codes.js';
|
|
2
|
+
export const FELTDB_PUBLIC_CONTRACT_VERSION = '1.0';
|
|
3
|
+
/**
|
|
4
|
+
* One typed public adapter over the canonical FeltDB authority.
|
|
5
|
+
*
|
|
6
|
+
* This class owns no records, versions, cursors, work, provenance, or retry
|
|
7
|
+
* log. Its fields are routing adapters; destroying this object loses no
|
|
8
|
+
* durable information.
|
|
9
|
+
*/
|
|
10
|
+
export class FeltDBPublicContract {
|
|
11
|
+
db;
|
|
12
|
+
scope;
|
|
13
|
+
applicationId;
|
|
14
|
+
environment;
|
|
15
|
+
request;
|
|
16
|
+
version = FELTDB_PUBLIC_CONTRACT_VERSION;
|
|
17
|
+
constructor(db, scope, applicationId, environment, request) {
|
|
18
|
+
this.db = db;
|
|
19
|
+
this.scope = scope;
|
|
20
|
+
this.applicationId = applicationId;
|
|
21
|
+
this.environment = environment;
|
|
22
|
+
this.request = request;
|
|
23
|
+
}
|
|
24
|
+
requireApplicationScope() {
|
|
25
|
+
if (this.scope?.kind !== 'tenant' || !this.applicationId) {
|
|
26
|
+
throw new FeltDBServiceError('The public durable contract requires explicit tenant and application scope', FeltDBErrorCode.AUTHORITY_SCOPE_REQUIRED);
|
|
27
|
+
}
|
|
28
|
+
return { tenantId: this.scope.tenantId, applicationId: this.applicationId };
|
|
29
|
+
}
|
|
30
|
+
authority() {
|
|
31
|
+
this.requireApplicationScope();
|
|
32
|
+
if (!this.request) {
|
|
33
|
+
throw new FeltDBServiceError('This capability requires a connected FeltDB authority', FeltDBErrorCode.CONTRACT_UNSUPPORTED);
|
|
34
|
+
}
|
|
35
|
+
return this.request;
|
|
36
|
+
}
|
|
37
|
+
state = {
|
|
38
|
+
collection: (name) => {
|
|
39
|
+
this.requireApplicationScope();
|
|
40
|
+
return this.db.collection(name);
|
|
41
|
+
},
|
|
42
|
+
transaction: (build, options = {}) => {
|
|
43
|
+
this.requireApplicationScope();
|
|
44
|
+
return this.db.transaction(build, options);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
principals = {
|
|
48
|
+
list: async () => {
|
|
49
|
+
const { applicationId } = this.requireApplicationScope();
|
|
50
|
+
return this.authority()(`/api/applications/${encodeURIComponent(applicationId)}/principals`);
|
|
51
|
+
},
|
|
52
|
+
create: async (input) => {
|
|
53
|
+
const { applicationId } = this.requireApplicationScope();
|
|
54
|
+
return this.authority()(`/api/applications/${encodeURIComponent(applicationId)}/principals`, { method: 'POST', body: JSON.stringify(input) });
|
|
55
|
+
},
|
|
56
|
+
grant: async (principalId, capability) => this.authority()(`/api/principals/${encodeURIComponent(principalId)}/capabilities`, { method: 'POST', body: JSON.stringify({ capability }) }),
|
|
57
|
+
};
|
|
58
|
+
work = {
|
|
59
|
+
create: async (input) => {
|
|
60
|
+
const { tenantId, applicationId } = this.requireApplicationScope();
|
|
61
|
+
if (input.tenant_id !== tenantId || input.application_id !== applicationId) {
|
|
62
|
+
throw new FeltDBServiceError('Durable Work scope does not match the bound public contract', FeltDBErrorCode.SCOPE_VIOLATION);
|
|
63
|
+
}
|
|
64
|
+
return this.authority()('/v1/workloads', {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
body: JSON.stringify({ ...input, created_at: input.created_at ?? Math.floor(Date.now() / 1000) }),
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
inspect: (workId) => this.authority()(`/v1/workloads/${encodeURIComponent(workId)}`),
|
|
70
|
+
history: (workId) => this.authority()(`/v1/workloads/${encodeURIComponent(workId)}/history`),
|
|
71
|
+
};
|
|
72
|
+
events = {
|
|
73
|
+
replay: async (after, options = {}) => {
|
|
74
|
+
const { applicationId } = this.requireApplicationScope();
|
|
75
|
+
const query = new URLSearchParams({
|
|
76
|
+
application_id: applicationId,
|
|
77
|
+
environment: this.environment,
|
|
78
|
+
limit: String(options.limit ?? 100),
|
|
79
|
+
});
|
|
80
|
+
if (after)
|
|
81
|
+
query.set('cursor', after);
|
|
82
|
+
return this.authority()(`/v1/public/events/replay?${query}`);
|
|
83
|
+
},
|
|
84
|
+
subscribe: (after, listener, options = {}) => {
|
|
85
|
+
const controller = new AbortController();
|
|
86
|
+
const cancel = () => controller.abort();
|
|
87
|
+
options.signal?.addEventListener('abort', cancel, { once: true });
|
|
88
|
+
void (async () => {
|
|
89
|
+
let cursor = after;
|
|
90
|
+
while (!controller.signal.aborted) {
|
|
91
|
+
const page = await this.events.replay(cursor);
|
|
92
|
+
for (const event of page.events)
|
|
93
|
+
await listener(event);
|
|
94
|
+
cursor = page.next_cursor;
|
|
95
|
+
await new Promise(resolve => {
|
|
96
|
+
const timer = setTimeout(resolve, options.pollIntervalMs ?? 250);
|
|
97
|
+
controller.signal.addEventListener('abort', () => {
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
resolve();
|
|
100
|
+
}, { once: true });
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
})().catch(() => {
|
|
104
|
+
// Delivery failure ends this discardable subscriber. Replay remains
|
|
105
|
+
// available from the caller's last acknowledged opaque cursor.
|
|
106
|
+
controller.abort();
|
|
107
|
+
});
|
|
108
|
+
return cancel;
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
provenance = {
|
|
112
|
+
record: async (collection, id) => {
|
|
113
|
+
const { applicationId } = this.requireApplicationScope();
|
|
114
|
+
const query = new URLSearchParams({
|
|
115
|
+
application_id: applicationId,
|
|
116
|
+
environment: this.environment,
|
|
117
|
+
});
|
|
118
|
+
return this.authority()(`/v1/control-plane/provenance/${encodeURIComponent(collection)}/${encodeURIComponent(id)}?${query}`);
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
async capabilities() {
|
|
122
|
+
const declaration = await this.authority()('/v1/control-plane/capabilities');
|
|
123
|
+
return declaration.public_contract;
|
|
124
|
+
}
|
|
125
|
+
}
|
package/dist/studio/app.d.ts
CHANGED
|
@@ -16,6 +16,29 @@ export interface StudioAppProps {
|
|
|
16
16
|
sourceSync?: SourceSyncConfiguration;
|
|
17
17
|
onConnect?: (url: string, token: string) => void;
|
|
18
18
|
}
|
|
19
|
+
export interface ApplicationConnectionNoticeProps {
|
|
20
|
+
registration?: {
|
|
21
|
+
namespace?: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export type StudioConnectionResolution = {
|
|
25
|
+
source: 'explicit-authority' | 'configured-authority';
|
|
26
|
+
authorityUrl: string;
|
|
27
|
+
} | {
|
|
28
|
+
source: 'injected';
|
|
29
|
+
authorityUrl: '';
|
|
30
|
+
} | {
|
|
31
|
+
source: 'browser';
|
|
32
|
+
authorityUrl: '';
|
|
33
|
+
};
|
|
34
|
+
export declare function resolveStudioConnection(input: {
|
|
35
|
+
explicitAuthority?: string | null;
|
|
36
|
+
configuredAuthority?: string | null;
|
|
37
|
+
injected?: boolean;
|
|
38
|
+
}): StudioConnectionResolution;
|
|
39
|
+
/** A registration proves the application is connected; it does not identify
|
|
40
|
+
* the JavaScript environment in which the application itself executes. */
|
|
41
|
+
export declare function ApplicationConnectionNotice({ registration }: ApplicationConnectionNoticeProps): React.JSX.Element;
|
|
19
42
|
export declare function StudioApp({ db, remoteUrl, token, namespace, deploymentRuntime, applicationUrl, applicationId, environment, developmentSession, managedPublish, sourceSync, onConnect }: StudioAppProps): React.JSX.Element;
|
|
20
43
|
export default StudioApp;
|
|
21
44
|
//# sourceMappingURL=app.d.ts.map
|