simetra 0.3.0-next.1 → 0.3.0-next.10
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/compiler/index.d.ts +52 -12
- package/dist/compiler/index.js +2578 -939
- package/dist/data/index.js +495 -159
- package/dist/model/index.d.ts +366 -12
- package/dist/model/index.js +171 -13
- package/dist/schema/index.d.ts +29 -7
- package/dist/schema/index.js +58 -15
- package/dist/server/index.d.ts +71 -26
- package/dist/server/index.js +418 -91
- package/dist/shell/index.d.ts +12 -0
- package/dist/shell/index.js +12 -1
- package/dist/ui/index.js +25 -2
- package/package.json +2 -1
- package/schemas/catalogs.schema.json +3 -26
- package/schemas/documents.schema.json +3 -26
- package/schemas/project.schema.json +195 -0
- package/schemas/rights-sets.schema.json +17 -1
- package/schemas/roles.schema.json +19 -2
package/dist/schema/index.js
CHANGED
|
@@ -3893,7 +3893,7 @@ async function readSessionSearchPath(tx) {
|
|
|
3893
3893
|
* тримає тест, а не читання маніфесту під час виконання: ярус не звертається
|
|
3894
3894
|
* до файлової системи.
|
|
3895
3895
|
*/
|
|
3896
|
-
const PLATFORM_VERSION = "0.3.0-next.
|
|
3896
|
+
const PLATFORM_VERSION = "0.3.0-next.10";
|
|
3897
3897
|
// src/schema/apply/state.ts
|
|
3898
3898
|
/**
|
|
3899
3899
|
* Форма стану застосування (платформна спека §6.1). Читач приймає лише її:
|
|
@@ -9225,7 +9225,10 @@ const PLPGSQL_CHECK_MODES = [
|
|
|
9225
9225
|
"transient",
|
|
9226
9226
|
"unavailable"
|
|
9227
9227
|
];
|
|
9228
|
-
/**
|
|
9228
|
+
/**
|
|
9229
|
+
* The extension that checks function bodies when it is there; `roles` of the
|
|
9230
|
+
* postgres profile installs it (spec of the profile §3.5).
|
|
9231
|
+
*/
|
|
9229
9232
|
const PLPGSQL_CHECK = "plpgsql_check";
|
|
9230
9233
|
/** Схема тимчасового розширення й точка збереження, у якій воно живе. */
|
|
9231
9234
|
const CHECK_SCHEMA = "simetra_plpgsql_check";
|
|
@@ -9258,14 +9261,18 @@ async function readPlpgsqlCheckFacts(tx) {
|
|
|
9258
9261
|
*/
|
|
9259
9262
|
function modeOf(f, installable) {
|
|
9260
9263
|
if (f.installed) return f.schemaUsage && f.functionExecute ? "installed" : "unavailable";
|
|
9261
|
-
return f.available && f.createOnDatabase && (f.trusted || f.superuser || installable.includes(
|
|
9264
|
+
return f.available && f.createOnDatabase && (f.trusted || f.superuser || installable.includes("plpgsql_check")) ? "transient" : "unavailable";
|
|
9262
9265
|
}
|
|
9263
9266
|
/**
|
|
9264
|
-
*
|
|
9265
|
-
*
|
|
9267
|
+
* Наявність розширення незалежно від прав ролі на нього: звірка цілі з планом
|
|
9268
|
+
* питає лише, чи воно є в базі й чи сервер його пропонує.
|
|
9266
9269
|
*/
|
|
9267
|
-
async function
|
|
9268
|
-
|
|
9270
|
+
async function readPlpgsqlCheckPresence(tx) {
|
|
9271
|
+
const { installed, available } = await readPlpgsqlCheckFacts(tx);
|
|
9272
|
+
return {
|
|
9273
|
+
installed,
|
|
9274
|
+
available
|
|
9275
|
+
};
|
|
9269
9276
|
}
|
|
9270
9277
|
/** Режим `plpgsql_check` цієї бази; `installable` — перелік пресету провайдера. */
|
|
9271
9278
|
async function readPlpgsqlCheckMode(tx, installable) {
|
|
@@ -11471,7 +11478,11 @@ async function runAttempt(raw, plan, o, timeouts, applyId, parse, report) {
|
|
|
11471
11478
|
const live = await readLiveForeignKeys(tx, plan.foreignKeys.subjects);
|
|
11472
11479
|
if (canonicalize(live) !== canonicalize(plan.foreignKeys.live)) throw stop("refused", "apply.target-changed", { sections: "foreignKeys" });
|
|
11473
11480
|
}
|
|
11474
|
-
if (o.mode !== "proof" && plan.plpgsqlCheck
|
|
11481
|
+
if (o.mode !== "proof" && plan.plpgsqlCheck !== "unavailable") {
|
|
11482
|
+
const presence = await readPlpgsqlCheckPresence(tx);
|
|
11483
|
+
if (!presence.installed && !presence.available) throw stop("refused", "apply.extension-unavailable", { extension: PLPGSQL_CHECK });
|
|
11484
|
+
if (plan.plpgsqlCheck === "installed" && !presence.installed) throw stop("refused", "apply.target-changed", { sections: "plpgsqlCheck" });
|
|
11485
|
+
}
|
|
11475
11486
|
let identity;
|
|
11476
11487
|
if (o.mode !== "proof") {
|
|
11477
11488
|
const copy = o.mode === "rehearse";
|
|
@@ -13155,7 +13166,7 @@ function templateState(found) {
|
|
|
13155
13166
|
}
|
|
13156
13167
|
const EXTENSIONS_SCHEMA = "extensions";
|
|
13157
13168
|
const AUTH_SCHEMA = PROVIDER_IDENTITY_SOURCES.postgres.table.schema;
|
|
13158
|
-
const CHECK_EXTENSION =
|
|
13169
|
+
const CHECK_EXTENSION = PLPGSQL_CHECK;
|
|
13159
13170
|
/**
|
|
13160
13171
|
* The session timeouts that every transaction or session of the schema engine
|
|
13161
13172
|
* resets to 0 (off) before its own work: the target database or role may set
|
|
@@ -13211,6 +13222,26 @@ async function enterSession(tx) {
|
|
|
13211
13222
|
}
|
|
13212
13223
|
const q$1 = quoteIdent;
|
|
13213
13224
|
const literal$1 = (value) => `'${value.replaceAll("'", "''")}'`;
|
|
13225
|
+
/**
|
|
13226
|
+
* `ALTER ROLE … PASSWORD` з рядком `E'…'`, де кожен зворотний слеш і лапку
|
|
13227
|
+
* подвоєно: текст той самий за будь-якого `standard_conforming_strings`
|
|
13228
|
+
* (прелюдія його не закріплює, а звичайний рядок зі слешем він тлумачив би
|
|
13229
|
+
* по-різному).
|
|
13230
|
+
* Параметр запиту тут неможливий: `ALTER ROLE` — утиліта без параметрів.
|
|
13231
|
+
*/
|
|
13232
|
+
function rolePasswordSql(role, password) {
|
|
13233
|
+
const escaped = password.replaceAll("\\", "\\\\").replaceAll("'", "''");
|
|
13234
|
+
return `ALTER ROLE ${q$1(role)} PASSWORD E'${escaped}'`;
|
|
13235
|
+
}
|
|
13236
|
+
/**
|
|
13237
|
+
* Whether the server offers the extension `name` in `pg_available_extensions`
|
|
13238
|
+
* (its control file is on the server). The view is the same in every database
|
|
13239
|
+
* of the cluster, so the maintenance session reads it.
|
|
13240
|
+
*/
|
|
13241
|
+
async function readExtensionAvailable(tx, name) {
|
|
13242
|
+
const [row] = await tx.query(["SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_available_extensions a", " WHERE a.name = $1::text) AS available"].join("\n"), [name]);
|
|
13243
|
+
return row?.available === true;
|
|
13244
|
+
}
|
|
13214
13245
|
const CREATE_DATABASE_OPTIONS = [
|
|
13215
13246
|
`TEMPLATE ${q$1("template0")}`,
|
|
13216
13247
|
`LOCALE_PROVIDER ${DATABASE_LOCALE.provider}`,
|
|
@@ -13512,6 +13543,7 @@ async function readPhase(dbs, conns, set, maintenance) {
|
|
|
13512
13543
|
};
|
|
13513
13544
|
}
|
|
13514
13545
|
}
|
|
13546
|
+
if ((target?.checkInstalled !== true || template.state !== "sealed" && templateFacts?.checkInstalled !== true) && !await readExtensionAvailable(maintenance, CHECK_EXTENSION)) refusal.push(applyDiagnostic("roles.extension-unavailable", "error", { extension: CHECK_EXTENSION }));
|
|
13515
13547
|
if (refusal.length > 0) return {
|
|
13516
13548
|
ok: false,
|
|
13517
13549
|
error: refusal
|
|
@@ -13560,11 +13592,12 @@ async function write(dbs, conn, fn) {
|
|
|
13560
13592
|
* наступного кроку, що від нього залежить, бо інше з'єднання незакомічених
|
|
13561
13593
|
* ролей і баз не бачить.
|
|
13562
13594
|
*/
|
|
13563
|
-
async function writePhase(dbs, conns, set, snapshot) {
|
|
13595
|
+
async function writePhase(dbs, conns, set, snapshot, passwords) {
|
|
13564
13596
|
const created = [];
|
|
13565
13597
|
const present = [];
|
|
13566
13598
|
const skipped = [];
|
|
13567
13599
|
const added = [];
|
|
13600
|
+
const passworded = [];
|
|
13568
13601
|
const planned = plannedRoles(set);
|
|
13569
13602
|
const missing = planned.filter((r) => !snapshot.roles.has(r.name));
|
|
13570
13603
|
for (const r of planned) if (snapshot.roles.has(r.name)) present.push(r.name);
|
|
@@ -13572,6 +13605,11 @@ async function writePhase(dbs, conns, set, snapshot) {
|
|
|
13572
13605
|
await tx.query("SET LOCAL createrole_self_grant = ''");
|
|
13573
13606
|
for (const r of missing) {
|
|
13574
13607
|
for (const sql of r.create) await tx.query(sql);
|
|
13608
|
+
const password = passwords.get(r.name);
|
|
13609
|
+
if (password !== void 0) {
|
|
13610
|
+
await tx.query(rolePasswordSql(r.name, password));
|
|
13611
|
+
passworded.push(r.name);
|
|
13612
|
+
}
|
|
13575
13613
|
created.push(r.name);
|
|
13576
13614
|
}
|
|
13577
13615
|
for (const l of set.roles.login) {
|
|
@@ -13635,7 +13673,8 @@ async function writePhase(dbs, conns, set, snapshot) {
|
|
|
13635
13673
|
created,
|
|
13636
13674
|
present,
|
|
13637
13675
|
skipped,
|
|
13638
|
-
...added.length > 0 ? { added } : {}
|
|
13676
|
+
...added.length > 0 ? { added } : {},
|
|
13677
|
+
...passworded.length > 0 ? { passwords: passworded } : {}
|
|
13639
13678
|
};
|
|
13640
13679
|
}
|
|
13641
13680
|
/**
|
|
@@ -13645,9 +13684,13 @@ async function writePhase(dbs, conns, set, snapshot) {
|
|
|
13645
13684
|
* Фаза читання нічого не пише й збирає всі відмови; фаза запису не відмовляє
|
|
13646
13685
|
* вибірково (окрім повторної перевірки `extensions` перед
|
|
13647
13686
|
* `CREATE EXTENSION`) і діє за знімком читання. Повторний виклик нічого не
|
|
13648
|
-
* створює.
|
|
13687
|
+
* створює. Розширення, якого сервер не пропонує, — відмова фази читання
|
|
13688
|
+
* `roles.extension-unavailable`, а не сира помилка `CREATE EXTENSION`.
|
|
13649
13689
|
*/
|
|
13650
|
-
async function ensurePostgresCluster(dbs, conns, set) {
|
|
13690
|
+
async function ensurePostgresCluster(dbs, conns, set, options = {}) {
|
|
13691
|
+
const passwords = options.passwords ?? /* @__PURE__ */ new Map();
|
|
13692
|
+
const logins = new Set(simetraLogins(set).concat(set.owner));
|
|
13693
|
+
for (const role of passwords.keys()) if (!logins.has(role)) throw new Error(`a password is given for ${role}, not a login role of the set`);
|
|
13651
13694
|
try {
|
|
13652
13695
|
return await dbs.transaction(conns.maintenance, "rollback", async (maintenance) => {
|
|
13653
13696
|
const denied = await enterSession(maintenance);
|
|
@@ -13665,7 +13708,7 @@ async function ensurePostgresCluster(dbs, conns, set) {
|
|
|
13665
13708
|
if (!read.ok) return read;
|
|
13666
13709
|
return {
|
|
13667
13710
|
ok: true,
|
|
13668
|
-
value: await writePhase(dbs, conns, set, read.snapshot)
|
|
13711
|
+
value: await writePhase(dbs, conns, set, read.snapshot, passwords)
|
|
13669
13712
|
};
|
|
13670
13713
|
});
|
|
13671
13714
|
} catch (error) {
|
|
@@ -16503,4 +16546,4 @@ function cloneMismatch(engine, scope, live, copy) {
|
|
|
16503
16546
|
if (sections.length > 0) out.push(mismatch("fingerprint", sections.join(", ")));
|
|
16504
16547
|
return out;
|
|
16505
16548
|
}
|
|
16506
|
-
export { ALL_PRIVILEGES, APPLY_ADVISORY_LOCK, APPLY_STATE_FORMAT, ApplyConnectionLost, ApplyDbError, BACKFILL_SETTINGS, CANONICAL_NAME_KINDS, CLUSTER_ADVISORY_LOCK, CheckNameTaken, DATA_SETTINGS, DATA_TRIGGER_MODES, DEFAULT_APPLY_TIMEOUTS, DEFAULT_PRIVILEGE_OBJTYPES, DRIFT_PERMISSION, DRIFT_REASONS, ENGINE_ACTION_VERBS, ENGINE_PREAMBLE_ALLOWED, ENGINE_SESSION_TIMEOUTS, ENGINE_TRANSACTIONALITIES, FINGERPRINT_SECTIONS, FINGERPRINT_VERSION, FUNCTION_ERROR_LIMIT, FUNCTION_SCOPE_SQL, GUARD_PAIR_SQLSTATES, LOCK_MODE_SQL, PLAN_FORMAT, PLATFORM_VERSION, PLPGSQL_CHECK_MODES, PROVIDER_ASSUMED_SCHEMAS, PROVIDER_BASE_EXTENSIONS, PROVIDER_EVENT_TRIGGERS, PROVIDER_EXPECTED_BLIND_FUNCTIONS, PROVIDER_IDENTITY_TRIGGER_LOCKED, PROVIDER_INSTALLABLE_EXTENSIONS, PROVIDER_LOCKS, PROVIDER_LOCK_STATEMENTS, PROVIDER_PUBLIC_SCHEMA_GRANTS, PROVIDER_SHADOW_TEMPLATES, PROVIDER_SURFACES, PROVIDER_SYSTEM_ROLES, PROVIDER_UNMANAGED_EXTENSIONS, PlpgsqlCheckUnavailable, REHEARSAL_FORMAT, REHEARSAL_PHASES, RETRYABLE_SQLSTATES, STEP_CLASSES, TABLE_LOCK_MODES, UNAPPLIED_FUNCTION_SETTINGS, accessChanges, adoptedReplacements, appliedCatalog, applyStateOf, applyStateOwnership, backfillAction, backfillStepRefusals, backfillTargetKey, backfillTargets, backfillTriggers, backfillWriteTables, buildPlan, canonicalRenames, carrierBackfillSteps, castGuardForms, castProbeQuery, censusDiagnostics, checkGuardCasts, checkOwnerAttributes, checkOwnerMembership, checkPermissions, checkPlatformRoles, classifyRemovals, classifySteps, columnKey, compareFingerprints, comparePermissionItems, compareWithDesired, conditionalToPlain, copiesShadowFromTemplate, countOf, coversMode, createdByPlan, dataComputeSql, dataCountSql, dataFactRefusals, dataGuardSql, dataPlan, dataStepRefusals, dataTableStep, dataWriteSql, defaultsBeforeNotNull, desiredForApply, driftGate, engineScope, ensurePlatformRoles, ensurePostgresCluster, environmentMismatch, environmentSteps, executePlan, findApply, folderReference, footprintSubjects, footprintTables, foreignChanges, foreignSequenceRefusals, functionChangeRefusals, hasIdentityTriggers, identityTableRefusal, identityTriggerLocks, intentStep, isPlatformTrigger, isRetryable, joinModes, lintSteps, lockPrivileges, lockRightsSql, newFunctionErrors, notNullColumns, numberingNotGenerated, ownerRefusal, parsePlan, parseRehearsal, pendingCarrierCopies, planArtifactSchema, planBackfills, planChange, planFileName, planFootprint, planFunctionChecks, planLocks, planPlatformFunctions, platformReplacements, platformRoleGate, platformRoleRefusals, platformRoleSet,
|
|
16549
|
+
export { ALL_PRIVILEGES, APPLY_ADVISORY_LOCK, APPLY_STATE_FORMAT, ApplyConnectionLost, ApplyDbError, BACKFILL_SETTINGS, CANONICAL_NAME_KINDS, CLUSTER_ADVISORY_LOCK, CheckNameTaken, DATA_SETTINGS, DATA_TRIGGER_MODES, DEFAULT_APPLY_TIMEOUTS, DEFAULT_PRIVILEGE_OBJTYPES, DRIFT_PERMISSION, DRIFT_REASONS, ENGINE_ACTION_VERBS, ENGINE_PREAMBLE_ALLOWED, ENGINE_SESSION_TIMEOUTS, ENGINE_TRANSACTIONALITIES, FINGERPRINT_SECTIONS, FINGERPRINT_VERSION, FUNCTION_ERROR_LIMIT, FUNCTION_SCOPE_SQL, GUARD_PAIR_SQLSTATES, LOCK_MODE_SQL, PLAN_FORMAT, PLATFORM_VERSION, PLPGSQL_CHECK_MODES, PROVIDER_ASSUMED_SCHEMAS, PROVIDER_BASE_EXTENSIONS, PROVIDER_EVENT_TRIGGERS, PROVIDER_EXPECTED_BLIND_FUNCTIONS, PROVIDER_IDENTITY_TRIGGER_LOCKED, PROVIDER_INSTALLABLE_EXTENSIONS, PROVIDER_LOCKS, PROVIDER_LOCK_STATEMENTS, PROVIDER_PUBLIC_SCHEMA_GRANTS, PROVIDER_SHADOW_TEMPLATES, PROVIDER_SURFACES, PROVIDER_SYSTEM_ROLES, PROVIDER_UNMANAGED_EXTENSIONS, PlpgsqlCheckUnavailable, REHEARSAL_FORMAT, REHEARSAL_PHASES, RETRYABLE_SQLSTATES, STEP_CLASSES, TABLE_LOCK_MODES, UNAPPLIED_FUNCTION_SETTINGS, accessChanges, adoptedReplacements, appliedCatalog, applyStateOf, applyStateOwnership, backfillAction, backfillStepRefusals, backfillTargetKey, backfillTargets, backfillTriggers, backfillWriteTables, buildPlan, canonicalRenames, carrierBackfillSteps, castGuardForms, castProbeQuery, censusDiagnostics, checkGuardCasts, checkOwnerAttributes, checkOwnerMembership, checkPermissions, checkPlatformRoles, classifyRemovals, classifySteps, columnKey, compareFingerprints, comparePermissionItems, compareWithDesired, conditionalToPlain, copiesShadowFromTemplate, countOf, coversMode, createdByPlan, dataComputeSql, dataCountSql, dataFactRefusals, dataGuardSql, dataPlan, dataStepRefusals, dataTableStep, dataWriteSql, defaultsBeforeNotNull, desiredForApply, driftGate, engineScope, ensurePlatformRoles, ensurePostgresCluster, environmentMismatch, environmentSteps, executePlan, findApply, folderReference, footprintSubjects, footprintTables, foreignChanges, foreignSequenceRefusals, functionChangeRefusals, hasIdentityTriggers, identityTableRefusal, identityTriggerLocks, intentStep, isPlatformTrigger, isRetryable, joinModes, lintSteps, lockPrivileges, lockRightsSql, newFunctionErrors, notNullColumns, numberingNotGenerated, ownerRefusal, parsePlan, parseRehearsal, pendingCarrierCopies, planArtifactSchema, planBackfills, planChange, planFileName, planFootprint, planFunctionChecks, planLocks, planPlatformFunctions, platformReplacements, platformRoleGate, platformRoleRefusals, platformRoleSet, postgresClusterSet, predefinedSeedSql, predefinedSeedSteps, preservationPlan, preservationQuery, preservationTypeRefusals, preservationTypeStepRefusals, promotionPermissionItems, promotionTransition, propertyReproductions, providerStatement, providerStatements, providerTableNames, providerTriggerConflicts, providerTriggerInBoundarySql, providerTriggerKey, readAccessDependents, readAppliedPromotions, readApplyState, readBackfillCounts, readBlindFunctions, readDataFacts, readEquivalenceObjects, readFingerprint, readGlobalDefaultPrivileges, readLedgerHead, readLiveForeignKeys, readLiveTriggers, readLockRights, readPlatformRoles, readPlpgsqlCheckMode, readPlpgsqlCheckPresence, readPlpgsqlErrors, readProviderLocks, readSeedTargetRows, readServerFacts, readServiceAccess, readSessionSearchPath, readShadowEnvironment, readTypeChangeDependents, readTypePresence, readUserTriggers, readValidatorErrors, readWriteFacts, readWritePath, reconcileCensus, rehearsalFileName, rehearsalHash, rehearsalRefusals, rehearsalReport, rehearsalReportSchema, renameIntent, renderApplyState, renderComments, renderDesiredState, renderEnumType, renderForeignKeys, renderGlobalDefaultPrivileges, renderIndexes, renderProviderSeed, renderRowLevelSecurity, renderTable, requiredPermissions, requiredPlatformRoles, revalidationSettings, reverseGenerate, runRightsMaintenance, sameDefault, seedVerdict, serializePlan, serializeRehearsal, stampPlan, statementSubjects, statementTimeoutFromReport, stepConversions, stepFootprint, tableKey, triggerReplacements, triggerSql, typeChangeRefusals, typeGuards, typeIdentity, unclassifiedRemovals, unmodeledClasses, unrealizedRenames, updateOfNarrowings, valueElementColumns, verifyPlanHash, withLocalSettings, withNotNullChecks, withShownTriggers, withTempNames, withTriggers, writeApplyStateStatements, writeFactRefusals };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -154,6 +154,27 @@ interface ReconcileReport {
|
|
|
154
154
|
/** Attach records of finished transactions removed from the database. */
|
|
155
155
|
pendingSwept: number;
|
|
156
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Facts about the request origin that the host passes to the data handler.
|
|
159
|
+
* An HTTP call carries the `Sec-Fetch-Site` and `Origin` header values (absent
|
|
160
|
+
* header = absent field) and the origin the host serves from; a call inside
|
|
161
|
+
* the server process (SSR) is `{ inProcess: true }`.
|
|
162
|
+
*/
|
|
163
|
+
type RequestOrigin = {
|
|
164
|
+
secFetchSite?: string;
|
|
165
|
+
origin?: string;
|
|
166
|
+
expectedOrigin: string;
|
|
167
|
+
} | {
|
|
168
|
+
inProcess: true;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Step 0 of the data handler: refuses a request that could be forged by
|
|
172
|
+
* another site. Runs before the envelope is parsed, so it touches nothing but
|
|
173
|
+
* the origin facts (and, for `inProcess`, the raw request type).
|
|
174
|
+
*
|
|
175
|
+
* @returns the refusal, or `undefined` when the request may proceed.
|
|
176
|
+
*/
|
|
177
|
+
export declare function checkRequestOrigin(origin: RequestOrigin, rawRequest: unknown): CommandError | undefined;
|
|
157
178
|
/**
|
|
158
179
|
* One connection taken from a pool: bound text parameters only, unnamed
|
|
159
180
|
* statements (P4 spec Рт19).
|
|
@@ -481,6 +502,50 @@ interface CommandRuntime {
|
|
|
481
502
|
* Rejects with `command.nested` from inside a hook.
|
|
482
503
|
*/
|
|
483
504
|
rebindFileStore(store: FileStore): Promise<void>;
|
|
505
|
+
/**
|
|
506
|
+
* Accepts an invitation by its secret (invitations spec §5) in a command
|
|
507
|
+
* transaction of its own. The origin is checked first: a foreign origin
|
|
508
|
+
* and `inProcess` alike are `command.forbidden` `reason: "origin"`, before
|
|
509
|
+
* the database. Rejects with `CommandFailure` before the database:
|
|
510
|
+
* `command.invalid` in a catalog without invitations, `command.forbidden`
|
|
511
|
+
* for a session without a user (invalid, no `sub`), an anonymous one or
|
|
512
|
+
* one with the `act` claim,
|
|
513
|
+
* `invitation.invalid` for a secret that is not 43 base64url characters.
|
|
514
|
+
* The database answer is committed whatever it is, then mapped: an unknown,
|
|
515
|
+
* expired, used or changed secret alike — `invitation.invalid`;
|
|
516
|
+
* `invitation.already-member`; `invitation.rate-limited`;
|
|
517
|
+
* `command.forbidden` when the database sees no actor.
|
|
518
|
+
*/
|
|
519
|
+
acceptInvitation(session: SessionClaims, secret: string, origin: RequestOrigin): Promise<AcceptedInvitation>;
|
|
520
|
+
/**
|
|
521
|
+
* The scopes the session's user is a member of (invitations spec §7):
|
|
522
|
+
* `rights_my_scopes()` and the root row of each scope, read in one
|
|
523
|
+
* `REPEATABLE READ READ ONLY` transaction under the request role; a root
|
|
524
|
+
* the user cannot read is `null`. `inProcess` is allowed, as for reads. An
|
|
525
|
+
* anonymous session gets `[]` without a database call. Rejects with
|
|
526
|
+
* `CommandFailure`: `command.forbidden` `reason: "origin"`,
|
|
527
|
+
* `command.invalid` in a catalog without invitations,
|
|
528
|
+
* `command.unauthenticated` for an invalid session.
|
|
529
|
+
*/
|
|
530
|
+
workspaces(session: SessionClaims, origin: RequestOrigin): Promise<Workspace[]>;
|
|
531
|
+
}
|
|
532
|
+
/** The membership an accepted invitation created. */
|
|
533
|
+
interface AcceptedInvitation {
|
|
534
|
+
/** The scope kind id. */
|
|
535
|
+
scopeKind: string;
|
|
536
|
+
scope: string;
|
|
537
|
+
/** The member row id. */
|
|
538
|
+
member: string;
|
|
539
|
+
}
|
|
540
|
+
/** One scope of {@link CommandRuntime.workspaces}. */
|
|
541
|
+
interface Workspace {
|
|
542
|
+
/** The scope kind id. */
|
|
543
|
+
scopeKind: string;
|
|
544
|
+
scope: string;
|
|
545
|
+
/** The user's member row id. */
|
|
546
|
+
member: string;
|
|
547
|
+
/** The root row of the scope by logical names; `null` — not readable. */
|
|
548
|
+
root: Record<string, unknown> | null;
|
|
484
549
|
}
|
|
485
550
|
/**
|
|
486
551
|
* The request role of `purpose` the server reads under for a provider
|
|
@@ -506,27 +571,6 @@ export declare function sessionKind(provider: DatabaseProvider, claims: SessionC
|
|
|
506
571
|
* catalog or module map throws before any database call.
|
|
507
572
|
*/
|
|
508
573
|
export declare function createCommandRuntime(options: CommandRuntimeOptions): Promise<CommandRuntime>;
|
|
509
|
-
/**
|
|
510
|
-
* Facts about the request origin that the host passes to the data handler.
|
|
511
|
-
* An HTTP call carries the `Sec-Fetch-Site` and `Origin` header values (absent
|
|
512
|
-
* header = absent field) and the origin the host serves from; a call inside
|
|
513
|
-
* the server process (SSR) is `{ inProcess: true }`.
|
|
514
|
-
*/
|
|
515
|
-
type RequestOrigin = {
|
|
516
|
-
secFetchSite?: string;
|
|
517
|
-
origin?: string;
|
|
518
|
-
expectedOrigin: string;
|
|
519
|
-
} | {
|
|
520
|
-
inProcess: true;
|
|
521
|
-
};
|
|
522
|
-
/**
|
|
523
|
-
* Step 0 of the data handler: refuses a request that could be forged by
|
|
524
|
-
* another site. Runs before the envelope is parsed, so it touches nothing but
|
|
525
|
-
* the origin facts (and, for `inProcess`, the raw request type).
|
|
526
|
-
*
|
|
527
|
-
* @returns the refusal, or `undefined` when the request may proceed.
|
|
528
|
-
*/
|
|
529
|
-
export declare function checkRequestOrigin(origin: RequestOrigin, rawRequest: unknown): CommandError | undefined;
|
|
530
574
|
/**
|
|
531
575
|
* Creates the data handler of the transport (P4-B spec §4.5): checks the
|
|
532
576
|
* request origin, the envelope, the session and the compatibility with the
|
|
@@ -631,7 +675,7 @@ interface AgentCore {
|
|
|
631
675
|
}
|
|
632
676
|
export declare function createAgentCore(options: AgentCoreOptions): AgentCore;
|
|
633
677
|
/** The closed set of codes an agent tool result may carry. */
|
|
634
|
-
export declare const AGENT_ERROR_CODES: readonly ["command.forbidden", "command.conflict", "command.invalid", "command.constraint", "command.context", "command.unauthenticated", "command.rejected", "command.nested", "command.depth", "command.retry-exhausted", "command.model-mismatch", "command.read-role-missing", "command.privileged-login", "command.unavailable", "command.timeout", "command.busy", "command.stale-client", "command.internal", "catalog.invalid-input", "catalog.unknown-tool", "catalog.unknown-object", "catalog.rights-write-refused", "catalog.result-too-large"];
|
|
678
|
+
export declare const AGENT_ERROR_CODES: readonly ["command.forbidden", "command.conflict", "command.invalid", "command.constraint", "command.context", "command.unauthenticated", "command.rejected", "command.nested", "command.depth", "command.retry-exhausted", "command.model-mismatch", "command.read-role-missing", "command.privileged-login", "command.unavailable", "command.timeout", "command.busy", "command.stale-client", "command.internal", "invitation.invalid", "invitation.already-member", "invitation.rate-limited", "invitation.not-pending", "catalog.invalid-input", "catalog.unknown-tool", "catalog.unknown-object", "catalog.rights-write-refused", "catalog.result-too-large"];
|
|
635
679
|
type AgentErrorCode = (typeof AGENT_ERROR_CODES)[number];
|
|
636
680
|
/**
|
|
637
681
|
* The next step for an agent: `retry` — the same call may work later;
|
|
@@ -719,9 +763,10 @@ export declare class AgentWriteRefused extends Error {
|
|
|
719
763
|
* The rights-write guard: a pure function over the runtime catalog and a batch,
|
|
720
764
|
* so an adapter can call it before opening a pool. It refuses when any
|
|
721
765
|
* operation of the batch (not only the first) touches a rights system catalog
|
|
722
|
-
* (its operations have the `administerRights` context)
|
|
723
|
-
* with a creator. An object outside the catalog is
|
|
724
|
-
* rejects it. Without `rightsWrite` the refusal
|
|
766
|
+
* (its operations have the `administerRights` context), creates a scope root
|
|
767
|
+
* with a creator or issues an invitation. An object outside the catalog is
|
|
768
|
+
* skipped: the runtime schema rejects it. Without `rightsWrite` the refusal
|
|
769
|
+
* comes before the database.
|
|
725
770
|
*/
|
|
726
771
|
export declare function agentWriteRefusal(catalog: RuntimeCatalog, batch: Batch, permissions: {
|
|
727
772
|
rightsWrite: boolean;
|
|
@@ -744,4 +789,4 @@ interface AgentToolCatalog extends AgentCore {
|
|
|
744
789
|
call(session: SessionClaims, name: string, input: unknown): Promise<AgentToolResult>;
|
|
745
790
|
}
|
|
746
791
|
export declare function createAgentToolCatalog(options: AgentToolCatalogOptions): AgentToolCatalog;
|
|
747
|
-
export type { AgentAttributeDescription, AgentCore, AgentCoreOptions, AgentCorePermissions, AgentErrorCode, AgentMcpResult, AgentObjectDescription, AgentObjectSummary, AgentOutcome, AgentTool, AgentToolAnnotations, AgentToolCatalog, AgentToolCatalogOptions, AgentToolError, AgentToolResult, AgentToolState, AgentToolSuccess, AgentVerb, AttachFileInput, CheckUploadInput, CommandDatabase, CommandRunOptions, CommandRuntime, CommandRuntimeOptions, DatabaseClient, FileStore, LogEntry, PgPoolLike, ReadPartOutcome, ReadPartsOptions, ReadPartsResult, ReconcileLogEntry, ReconcileOptions, ReconcileRefusal, ReconcileReport, RequestOrigin, S3ClientLike, UploadLimits };
|
|
792
|
+
export type { AcceptedInvitation, AgentAttributeDescription, AgentCore, AgentCoreOptions, AgentCorePermissions, AgentErrorCode, AgentMcpResult, AgentObjectDescription, AgentObjectSummary, AgentOutcome, AgentTool, AgentToolAnnotations, AgentToolCatalog, AgentToolCatalogOptions, AgentToolError, AgentToolResult, AgentToolState, AgentToolSuccess, AgentVerb, AttachFileInput, CheckUploadInput, CommandDatabase, CommandRunOptions, CommandRuntime, CommandRuntimeOptions, DatabaseClient, FileStore, LogEntry, PgPoolLike, ReadPartOutcome, ReadPartsOptions, ReadPartsResult, ReconcileLogEntry, ReconcileOptions, ReconcileRefusal, ReconcileReport, RequestOrigin, S3ClientLike, UploadLimits, Workspace };
|