@jini-ai/core 0.7.2 → 0.7.3-next.2
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/README.md +40 -12
- package/dist/admin-runtime/admin-api-error.d.ts +68 -0
- package/dist/admin-runtime/admin-api-error.js +72 -0
- package/dist/admin-runtime/admin-config-error.d.ts +8 -0
- package/dist/admin-runtime/admin-config-error.js +11 -0
- package/dist/admin-runtime/controller-store.d.ts +20 -0
- package/dist/admin-runtime/controller-store.js +32 -0
- package/dist/admin-runtime/index.d.ts +13 -0
- package/dist/admin-runtime/index.js +12 -0
- package/dist/admin-runtime/panel-access.d.ts +88 -0
- package/dist/admin-runtime/panel-access.js +76 -0
- package/dist/admin-runtime/query-suffix.d.ts +5 -0
- package/dist/admin-runtime/query-suffix.js +5 -0
- package/dist/agent-handles/element-handles.d.ts +134 -0
- package/dist/agent-handles/element-handles.js +45 -0
- package/dist/agent-handles/field-descriptor.d.ts +28 -0
- package/dist/agent-handles/field-descriptor.js +3 -0
- package/dist/agent-handles/handle.d.ts +109 -0
- package/dist/agent-handles/handle.js +109 -0
- package/dist/agent-handles/index.d.ts +9 -0
- package/dist/agent-handles/index.js +6 -0
- package/dist/agent-handles/list-handles.d.ts +46 -0
- package/dist/agent-handles/list-handles.js +67 -0
- package/dist/agent-handles/secret-attrs.d.ts +14 -0
- package/dist/agent-handles/secret-attrs.js +13 -0
- package/dist/approval-batch-chain.d.ts +45 -0
- package/dist/approval-batch-chain.js +75 -0
- package/dist/approval.d.ts +33 -14
- package/dist/approval.js +57 -43
- package/dist/batch-tool-inputs.js +24 -20
- package/dist/contracts/admin-module.d.ts +166 -0
- package/dist/contracts/admin-module.js +14 -0
- package/dist/contracts/agents/definition.d.ts +459 -0
- package/dist/contracts/agents/definition.js +2 -0
- package/dist/contracts/agents/index.d.ts +7 -0
- package/dist/contracts/agents/index.js +2 -0
- package/dist/contracts/agents/launch.d.ts +64 -0
- package/dist/contracts/agents/launch.js +2 -0
- package/dist/contracts/agents/model-catalog.d.ts +213 -0
- package/dist/contracts/agents/model-catalog.js +4 -0
- package/dist/contracts/agents/native-tool-policy.d.ts +42 -0
- package/dist/contracts/agents/native-tool-policy.js +2 -0
- package/dist/contracts/ai-trace/capture.d.ts +17 -0
- package/dist/contracts/ai-trace/capture.js +43 -0
- package/dist/contracts/ai-trace/classify.d.ts +12 -0
- package/dist/contracts/ai-trace/classify.js +16 -0
- package/dist/contracts/ai-trace/index.d.ts +13 -0
- package/dist/contracts/ai-trace/index.js +6 -0
- package/dist/contracts/ai-trace/recorder.d.ts +64 -0
- package/dist/contracts/ai-trace/recorder.js +283 -0
- package/dist/contracts/ai-trace/sinks.d.ts +51 -0
- package/dist/contracts/ai-trace/sinks.js +153 -0
- package/dist/contracts/ai-trace/types.d.ts +123 -0
- package/dist/contracts/ai-trace/types.js +17 -0
- package/dist/contracts/ai-trace/usage.d.ts +16 -0
- package/dist/contracts/ai-trace/usage.js +45 -0
- package/dist/contracts/blob.d.ts +31 -0
- package/dist/contracts/blob.js +10 -0
- package/dist/contracts/capabilities.d.ts +95 -0
- package/dist/contracts/capabilities.js +111 -0
- package/dist/contracts/charts.d.ts +75 -0
- package/dist/contracts/charts.js +4 -0
- package/dist/contracts/env.d.ts +96 -0
- package/dist/contracts/env.js +6 -0
- package/dist/contracts/events/change-set.d.ts +106 -0
- package/dist/contracts/events/change-set.js +2 -0
- package/dist/contracts/events/command.d.ts +118 -0
- package/dist/contracts/events/command.js +2 -0
- package/dist/contracts/events/ports.d.ts +172 -0
- package/dist/contracts/events/ports.js +2 -0
- package/dist/contracts/events.d.ts +5 -0
- package/dist/contracts/events.js +2 -0
- package/dist/contracts/forms.d.ts +110 -0
- package/dist/contracts/forms.js +4 -0
- package/dist/contracts/hosted-mcp/config.d.ts +19 -0
- package/dist/contracts/hosted-mcp/record.d.ts +61 -4
- package/dist/contracts/mail/email-sender.d.ts +118 -0
- package/dist/contracts/mail/email-sender.js +20 -0
- package/dist/contracts/mail/smtp-payload.d.ts +32 -0
- package/dist/contracts/mail/smtp-payload.js +2 -0
- package/dist/contracts/mail.d.ts +2 -0
- package/dist/contracts/mail.js +1 -1
- package/dist/contracts/observability.d.ts +235 -0
- package/dist/contracts/observability.js +28 -0
- package/dist/contracts/plugin-sdk.d.ts +186 -0
- package/dist/contracts/plugin-sdk.js +39 -0
- package/dist/contracts/runtime/command.d.ts +41 -0
- package/dist/contracts/runtime/command.js +60 -0
- package/dist/contracts/runtime/environment.d.ts +18 -0
- package/dist/contracts/runtime/environment.js +26 -0
- package/dist/contracts/runtime/file-lock.d.ts +94 -0
- package/dist/contracts/runtime/file-lock.js +25 -0
- package/dist/contracts/runtime/fs.d.ts +33 -0
- package/dist/contracts/runtime/fs.js +2 -0
- package/dist/contracts/runtime/http.d.ts +89 -0
- package/dist/contracts/runtime/http.js +2 -0
- package/dist/contracts/runtime/platform.d.ts +3 -0
- package/dist/contracts/runtime/platform.js +2 -0
- package/dist/contracts/runtime/process.d.ts +40 -0
- package/dist/contracts/runtime/process.js +31 -0
- package/dist/contracts/runtime/reader.d.ts +11 -0
- package/dist/contracts/runtime/reader.js +2 -0
- package/dist/contracts/runtime/terminal.d.ts +99 -0
- package/dist/contracts/runtime/terminal.js +2 -0
- package/dist/contracts/runtime/testing.d.ts +84 -0
- package/dist/contracts/runtime/testing.js +116 -0
- package/dist/contracts/runtime.d.ts +10 -0
- package/dist/contracts/runtime.js +10 -0
- package/dist/contracts/server/api-error.d.ts +43 -0
- package/dist/contracts/server/api-error.js +49 -0
- package/dist/contracts/server/auth.d.ts +20 -0
- package/dist/contracts/server/auth.js +21 -0
- package/dist/contracts/server/conformance.d.ts +25 -0
- package/dist/contracts/server/conformance.js +50 -0
- package/dist/contracts/server/json-route.d.ts +176 -0
- package/dist/contracts/server/json-route.js +155 -0
- package/dist/contracts/server/middleware.d.ts +35 -0
- package/dist/contracts/server/middleware.js +56 -0
- package/dist/contracts/server/origin.d.ts +44 -0
- package/dist/contracts/server/origin.js +32 -0
- package/dist/contracts/server/query.d.ts +16 -0
- package/dist/contracts/server/query.js +69 -0
- package/dist/contracts/server/rate-limit.d.ts +20 -0
- package/dist/contracts/server/rate-limit.js +8 -0
- package/dist/contracts/server/request-body.d.ts +26 -0
- package/dist/contracts/server/request-body.js +82 -0
- package/dist/contracts/server/result.d.ts +17 -0
- package/dist/contracts/server/result.js +5 -0
- package/dist/contracts/server/route-table.d.ts +54 -0
- package/dist/contracts/server/route-table.js +119 -0
- package/dist/contracts/server/same-origin-write.d.ts +18 -0
- package/dist/contracts/server/same-origin-write.js +31 -0
- package/dist/contracts/server/security-headers.d.ts +30 -0
- package/dist/contracts/server/security-headers.js +35 -0
- package/dist/contracts/server/sse.d.ts +82 -0
- package/dist/contracts/server/sse.js +103 -0
- package/dist/contracts/server/testing.d.ts +59 -0
- package/dist/contracts/server/testing.js +68 -0
- package/dist/contracts/server/verified-origin/configured-origin.d.ts +37 -0
- package/dist/contracts/server/verified-origin/configured-origin.js +103 -0
- package/dist/contracts/server/verified-origin/index.d.ts +7 -0
- package/dist/contracts/server/verified-origin/index.js +6 -0
- package/dist/contracts/server/verified-origin/loopback-host.d.ts +9 -0
- package/dist/contracts/server/verified-origin/loopback-host.js +17 -0
- package/dist/contracts/server/verified-origin/origin.d.ts +64 -0
- package/dist/contracts/server/verified-origin/origin.js +162 -0
- package/dist/contracts/server/verified-origin/ports.d.ts +38 -0
- package/dist/contracts/server/verified-origin/ports.js +2 -0
- package/dist/contracts/server/verified-origin/repo.memory.d.ts +32 -0
- package/dist/contracts/server/verified-origin/repo.memory.js +34 -0
- package/dist/contracts/server/verified-origin/site-path.d.ts +113 -0
- package/dist/contracts/server/verified-origin/site-path.js +188 -0
- package/dist/contracts/server/verified-origin/types.d.ts +33 -0
- package/dist/contracts/server/verified-origin/types.js +30 -0
- package/dist/contracts/server.d.ts +46 -2
- package/dist/contracts/server.js +17 -3
- package/dist/contracts/storage/kernel.d.ts +86 -0
- package/dist/contracts/storage/kernel.js +38 -0
- package/dist/contracts/storage/migration.d.ts +32 -0
- package/dist/contracts/storage/migration.js +2 -0
- package/dist/contracts/storage/rows.d.ts +33 -0
- package/dist/contracts/storage/rows.js +42 -0
- package/dist/contracts/storage/sqlite.d.ts +113 -0
- package/dist/contracts/storage/sqlite.js +8 -0
- package/dist/contracts/storage/values.d.ts +25 -0
- package/dist/contracts/storage/values.js +25 -0
- package/dist/contracts/storage.d.ts +8 -0
- package/dist/contracts/storage.js +6 -0
- package/dist/contracts/vault/invariants.d.ts +26 -0
- package/dist/contracts/vault/invariants.js +49 -0
- package/dist/contracts/vault.d.ts +1 -0
- package/dist/contracts/vault.js +1 -1
- package/dist/env/coercers.d.ts +21 -0
- package/dist/env/coercers.js +68 -0
- package/dist/env/describe-env-for-diagnostics.d.ts +16 -0
- package/dist/env/describe-env-for-diagnostics.js +23 -0
- package/dist/env/format-env-issue.d.ts +13 -0
- package/dist/env/format-env-issue.js +22 -0
- package/dist/env/parse-env.d.ts +24 -0
- package/dist/env/parse-env.js +102 -0
- package/dist/env/value-echo.d.ts +17 -0
- package/dist/env/value-echo.js +42 -0
- package/dist/errors/approved-cause.d.ts +36 -0
- package/dist/errors/approved-cause.js +17 -0
- package/dist/errors/bindings.d.ts +61 -0
- package/dist/errors/bindings.js +57 -0
- package/dist/errors/catalog.d.ts +84 -0
- package/dist/errors/catalog.js +151 -0
- package/dist/errors/disclosure.d.ts +48 -0
- package/dist/errors/disclosure.js +27 -0
- package/dist/errors/error-id.d.ts +26 -0
- package/dist/errors/error-id.js +23 -0
- package/dist/errors/idioms.d.ts +73 -0
- package/dist/errors/idioms.js +85 -0
- package/dist/errors/incident-text.d.ts +16 -0
- package/dist/errors/incident-text.js +77 -0
- package/dist/errors/reporter.d.ts +94 -0
- package/dist/errors/reporter.js +152 -0
- package/dist/errors/sentences.d.ts +68 -0
- package/dist/errors/sentences.js +93 -0
- package/dist/errors/testing.d.ts +50 -0
- package/dist/errors/testing.js +44 -0
- package/dist/fetch/cache.d.ts +12 -5
- package/dist/fetch/cache.js +46 -47
- package/dist/fetch/index.d.ts +1 -1
- package/dist/fetch/loader-read.d.ts +6 -2
- package/dist/fetch/loader-read.js +4 -4
- package/dist/format-error-for-log.d.ts +15 -0
- package/dist/format-error-for-log.js +55 -0
- package/dist/gated-mutations/gateway.d.ts +2 -0
- package/dist/gated-mutations/gateway.js +4 -1
- package/dist/host-read-vocabulary.d.ts +47 -0
- package/dist/host-read-vocabulary.js +44 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -0
- package/dist/list-page.d.ts +93 -0
- package/dist/list-page.js +154 -0
- package/dist/model-facing-tool-errors.d.ts +67 -5
- package/dist/model-facing-tool-errors.js +155 -19
- package/dist/net/endpoint-policy.d.ts +39 -0
- package/dist/net/endpoint-policy.js +218 -0
- package/dist/net/fetch-timeouts.d.ts +38 -0
- package/dist/net/fetch-timeouts.js +31 -0
- package/dist/net/index.d.ts +4 -0
- package/dist/net/index.js +4 -0
- package/dist/net/loopback.d.ts +13 -0
- package/dist/net/loopback.js +39 -0
- package/dist/optimistic-concurrency.d.ts +183 -0
- package/dist/optimistic-concurrency.js +222 -0
- package/dist/primitives/errors.d.ts +9 -0
- package/dist/primitives/errors.js +12 -0
- package/dist/primitives/ids.d.ts +0 -2
- package/dist/primitives/ids.js +1 -4
- package/dist/primitives/index.d.ts +3 -0
- package/dist/primitives/index.js +2 -0
- package/dist/primitives/logger.d.ts +36 -1
- package/dist/primitives/logger.js +125 -9
- package/dist/primitives/node-shape.d.ts +24 -0
- package/dist/primitives/node-shape.js +21 -0
- package/dist/primitives/time.d.ts +9 -2
- package/dist/primitives/time.js +4 -3
- package/dist/provider-registry.js +26 -20
- package/dist/records.d.ts +40 -7
- package/dist/records.js +37 -3
- package/dist/redact.d.ts +1 -84
- package/dist/redact.js +2 -826
- package/dist/redaction-collectors.d.ts +7 -0
- package/dist/redaction-collectors.js +152 -0
- package/dist/redaction-exact-secrets.d.ts +14 -0
- package/dist/redaction-exact-secrets.js +115 -0
- package/dist/redaction-labels.d.ts +14 -0
- package/dist/redaction-labels.js +156 -0
- package/dist/redaction-patterns.d.ts +54 -0
- package/dist/redaction-patterns.js +178 -0
- package/dist/redaction-spans.d.ts +31 -0
- package/dist/redaction-spans.js +83 -0
- package/dist/registration-kit.d.ts +1 -1
- package/dist/revision-conflict-error.d.ts +18 -0
- package/dist/revision-conflict-error.js +20 -0
- package/dist/secret-shapes.d.ts +50 -0
- package/dist/secret-shapes.js +105 -0
- package/dist/settings/agent-tools.js +22 -8
- package/dist/settings/agent-value-write-tools.d.ts +4 -1
- package/dist/settings/agent-value-write-tools.js +7 -6
- package/dist/settings/agent-writable-preferences.d.ts +3 -1
- package/dist/settings/agent-writable-preferences.js +1 -1
- package/dist/settings/agent-write-denylist.d.ts +7 -4
- package/dist/settings/agent-write-denylist.js +1 -1
- package/dist/settings/{express/cms-adapter.d.ts → cms-adapter.d.ts} +3 -2
- package/dist/settings/{express/cms-adapter.js → cms-adapter.js} +21 -11
- package/dist/settings/definitions-dispatch.js +3 -1
- package/dist/settings/ensure-definitions.js +3 -1
- package/dist/settings/errors.d.ts +1 -13
- package/dist/settings/errors.js +2 -15
- package/dist/settings/index.d.ts +11 -2
- package/dist/settings/index.js +10 -2
- package/dist/settings/purge-service.js +63 -86
- package/dist/settings/{express/contracts.d.ts → route-policy.d.ts} +53 -47
- package/dist/settings/{express/shared.js → route-policy.js} +1 -16
- package/dist/settings/settings.d.ts +19 -11
- package/dist/settings/settings.js +9 -11
- package/dist/settings/tool-registrations.d.ts +3 -3
- package/dist/settings/tool-registrations.js +130 -125
- package/dist/settings/types.d.ts +1 -1
- package/dist/settings/write-definition-rename.d.ts +37 -0
- package/dist/settings/write-definition-rename.js +119 -0
- package/dist/settings/write-definition-retype.d.ts +61 -0
- package/dist/settings/write-definition-retype.js +109 -0
- package/dist/settings/write-definition-status.d.ts +81 -0
- package/dist/settings/write-definition-status.js +121 -0
- package/dist/settings/write-reset.d.ts +34 -0
- package/dist/settings/write-reset.js +73 -0
- package/dist/settings/write-service.d.ts +16 -287
- package/dist/settings/write-service.js +49 -681
- package/dist/settings/write-value-revisions.d.ts +68 -0
- package/dist/settings/write-value-revisions.js +124 -0
- package/dist/settings/write-values.d.ts +96 -0
- package/dist/settings/write-values.js +83 -0
- package/dist/surface-exchanges.d.ts +2 -2
- package/dist/text/dictionary-translator.d.ts +19 -0
- package/dist/text/dictionary-translator.js +14 -0
- package/dist/text/format-byte-size.d.ts +25 -0
- package/dist/text/format-byte-size.js +25 -0
- package/dist/text/format-timestamp.d.ts +22 -0
- package/dist/text/format-timestamp.js +57 -0
- package/dist/text/index.d.ts +12 -0
- package/dist/text/index.js +9 -0
- package/dist/text/is-abort-error.d.ts +5 -0
- package/dist/text/is-abort-error.js +5 -0
- package/dist/text/mime.d.ts +5 -0
- package/dist/text/mime.js +21 -0
- package/dist/text/redact-urls.d.ts +7 -0
- package/dist/text/redact-urls.js +5 -0
- package/dist/text/resolve-active-tab-id.d.ts +13 -0
- package/dist/text/resolve-active-tab-id.js +15 -0
- package/dist/text/sanitize-untrusted-text.d.ts +1 -1
- package/dist/text/sanitize-untrusted-text.js +2 -1
- package/dist/text/tagged-text-suppression.d.ts +103 -0
- package/dist/text/tagged-text-suppression.js +143 -0
- package/dist/text/template-i18n.d.ts +37 -0
- package/dist/text/template-i18n.js +48 -0
- package/dist/tool-call-text.d.ts +59 -0
- package/dist/tool-call-text.js +62 -0
- package/dist/tool-input-envelope.js +8 -4
- package/dist/tool-input-normalization.js +8 -1
- package/dist/tool-input-repairs.d.ts +58 -0
- package/dist/tool-input-repairs.js +154 -0
- package/dist/tool-tokens.js +1 -1
- package/dist/user-facing-error.d.ts +1 -1
- package/dist/user-facing-error.js +3 -1
- package/package.json +235 -14
- package/plugin-directory.d.ts +2 -2
- package/plugin-directory.js +16 -10
- package/dist/settings/express/contracts.js +0 -2
- package/dist/settings/express/http-request.d.ts +0 -33
- package/dist/settings/express/http-request.js +0 -50
- package/dist/settings/express/http.d.ts +0 -10
- package/dist/settings/express/http.js +0 -196
- package/dist/settings/express/index.d.ts +0 -5
- package/dist/settings/express/index.js +0 -4
- package/dist/settings/express/shared.d.ts +0 -68
- package/dist/settings/express/stream.d.ts +0 -24
- package/dist/settings/express/stream.js +0 -171
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { nowIso as kernelNowIso } from "../primitives/index.js";
|
|
2
|
+
import { DefinitionInvalidError, RenameRetypeConflictError } from "./errors.js";
|
|
3
|
+
import { invalidateDefinitionNamespaceCache } from "./settings.js";
|
|
4
|
+
import { SCOPE_BIT } from "./types.js";
|
|
5
|
+
import { authorizeDefinitionsManage, resolveActiveDefinitionOrThrow } from './write-service.js';
|
|
6
|
+
/** One transaction body: deprecate the prior active version, insert the new one, ledger the retype. */
|
|
7
|
+
async function writeRetypedVersion({ deps, input, current }) {
|
|
8
|
+
const now = kernelNowIso({ clock: deps.clock });
|
|
9
|
+
const newVersion = current.version + 1;
|
|
10
|
+
// Step 1: deprecate the prior active version first.
|
|
11
|
+
await deps.repo.saveDefinition({ ...current, status: "deprecated", updatedAt: now });
|
|
12
|
+
// Step 2: insert the new version as active -- same setting_id/namespace/key.
|
|
13
|
+
await deps.repo.saveDefinition({
|
|
14
|
+
settingId: current.settingId,
|
|
15
|
+
version: newVersion,
|
|
16
|
+
workspaceId: current.workspaceId,
|
|
17
|
+
namespace: current.namespace,
|
|
18
|
+
key: current.key,
|
|
19
|
+
ownerKind: current.ownerKind,
|
|
20
|
+
ownerId: current.ownerId,
|
|
21
|
+
schema: input.schema,
|
|
22
|
+
defaultValue: input.defaultValue,
|
|
23
|
+
scopes: current.scopes,
|
|
24
|
+
secret: current.secret,
|
|
25
|
+
status: "active",
|
|
26
|
+
aliasOfNamespace: null,
|
|
27
|
+
aliasOfKey: null,
|
|
28
|
+
coercionTag: input.coercionTag,
|
|
29
|
+
createdAt: now,
|
|
30
|
+
updatedAt: now,
|
|
31
|
+
});
|
|
32
|
+
await deps.repo.appendRevision({
|
|
33
|
+
entityKind: "definition",
|
|
34
|
+
settingId: current.settingId,
|
|
35
|
+
scope: null,
|
|
36
|
+
workspaceId: current.workspaceId,
|
|
37
|
+
principalId: null,
|
|
38
|
+
op: "retype",
|
|
39
|
+
beforeJson: null,
|
|
40
|
+
afterJson: null,
|
|
41
|
+
defVersion: newVersion,
|
|
42
|
+
actor: input.callerPrincipalId,
|
|
43
|
+
originPluginId: null,
|
|
44
|
+
changeSetId: null,
|
|
45
|
+
createdAt: now,
|
|
46
|
+
});
|
|
47
|
+
return { settingId: current.settingId, version: newVersion };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The retype mechanism : a same-tx pair --
|
|
51
|
+
* (1) UPDATE the prior active version's `status` to `deprecated` FIRST (else
|
|
52
|
+
* the insert in step 2 collides with the one-active-row-per-slot
|
|
53
|
+
* invariant); (2) INSERT the new `version+1` row as `active`, same
|
|
54
|
+
* `setting_id`/`namespace`/`key`. Rejected unless every prior version
|
|
55
|
+
* (2..N) already carries a total coercer -- `coercionTag` is `null` only for
|
|
56
|
+
* version 1 by construction (`types.ts`), so this walks 2..N and requires
|
|
57
|
+
* each to be non-null.
|
|
58
|
+
* See docs/decisions/DR-003-settings-ledger-invariants.md.
|
|
59
|
+
*/
|
|
60
|
+
export async function retypeDefinition(required) {
|
|
61
|
+
const { deps, input } = required;
|
|
62
|
+
await authorizeDefinitionsManage(deps, input.callerPrincipalId, input.authWorkspaceId);
|
|
63
|
+
const current = await resolveActiveDefinitionOrThrow(deps, input, "retype");
|
|
64
|
+
const namespaceOrKeyChanged = (input.newNamespace !== undefined && input.newNamespace !== current.namespace) ||
|
|
65
|
+
(input.newKey !== undefined && input.newKey !== current.key);
|
|
66
|
+
const schemaChanged = JSON.stringify(input.schema) !== JSON.stringify(current.schema);
|
|
67
|
+
if (namespaceOrKeyChanged && schemaChanged) {
|
|
68
|
+
throw new RenameRetypeConflictError(`cannot rename and retype '${input.namespace}.${input.key}' in the same operation; submit the rename and the retype as two separate chokepoint calls`);
|
|
69
|
+
}
|
|
70
|
+
for (let version = 2; version <= current.version; version++) {
|
|
71
|
+
const priorVersion = await deps.repo.findDefinitionBySettingId({ settingId: current.settingId, version });
|
|
72
|
+
if (!priorVersion || priorVersion.coercionTag == null) {
|
|
73
|
+
throw new DefinitionInvalidError(`retype of '${input.namespace}.${input.key}' rejected: version ${version} does not carry a total coercer`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const result = await deps.repo.transaction(() => writeRetypedVersion({ deps, input, current }));
|
|
77
|
+
invalidateDefinitionNamespaceCache({ repo: deps.repo, namespace: input.namespace });
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
/** Add source-declared scopes to a core definition without moving or rewriting existing values.
|
|
81
|
+
* Boot uses this when a workspace preference gains a personal override. Scope removal is a
|
|
82
|
+
* separate migration decision: this operation only adds bits and preserves definition identity.
|
|
83
|
+
* @throws DefinitionInvalidError for operator-owned definitions or invalid scope bits.
|
|
84
|
+
* @complexity O(1), one definition transaction and cache invalidation.
|
|
85
|
+
* @example await extendDefinitionScopes({ deps, input: { namespace, key, workspaceId: null,
|
|
86
|
+
* scopes: SCOPE_BIT.user, callerPrincipalId, authWorkspaceId } });
|
|
87
|
+
*/
|
|
88
|
+
export async function extendDefinitionScopes({ deps, input }, _options = {}) {
|
|
89
|
+
await authorizeDefinitionsManage(deps, input.callerPrincipalId, input.authWorkspaceId);
|
|
90
|
+
const current = await resolveActiveDefinitionOrThrow(deps, input, "extend the scopes of");
|
|
91
|
+
const validBits = SCOPE_BIT.global | SCOPE_BIT.workspace | SCOPE_BIT.user;
|
|
92
|
+
if (current.ownerKind !== "core" || !Number.isInteger(input.scopes) || input.scopes <= 0 || input.scopes > validBits) {
|
|
93
|
+
throw new DefinitionInvalidError("Only core definitions can gain valid source-declared scope bits");
|
|
94
|
+
}
|
|
95
|
+
const scopes = current.scopes | input.scopes;
|
|
96
|
+
if (scopes === current.scopes)
|
|
97
|
+
return;
|
|
98
|
+
await deps.repo.transaction(async () => {
|
|
99
|
+
const now = kernelNowIso({ clock: deps.clock });
|
|
100
|
+
await deps.repo.saveDefinition({ ...current, scopes, updatedAt: now });
|
|
101
|
+
// Re-registration of metadata, not a value/schema change; retain the existing revision vocabulary.
|
|
102
|
+
await deps.repo.appendRevision({ entityKind: "definition", settingId: current.settingId,
|
|
103
|
+
scope: null, workspaceId: current.workspaceId, principalId: null, op: "register",
|
|
104
|
+
beforeJson: { scopes: current.scopes }, afterJson: { scopes }, defVersion: current.version,
|
|
105
|
+
actor: input.callerPrincipalId, originPluginId: null, changeSetId: null, createdAt: now });
|
|
106
|
+
});
|
|
107
|
+
invalidateDefinitionNamespaceCache({ repo: deps.repo, namespace: input.namespace });
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=write-definition-retype.js.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { JsonValue, UUID } from "../primitives/index.js";
|
|
2
|
+
import { type SettingsWriteServiceDeps } from './write-service.js';
|
|
3
|
+
export interface ReconcileDefinitionDefaultRequired {
|
|
4
|
+
deps: SettingsWriteServiceDeps;
|
|
5
|
+
input: {
|
|
6
|
+
namespace: string;
|
|
7
|
+
key: string;
|
|
8
|
+
workspaceId: UUID | null;
|
|
9
|
+
/** The default the SOURCE declares. Wins over a differing stored default. */
|
|
10
|
+
defaultValue: JsonValue;
|
|
11
|
+
callerPrincipalId: UUID;
|
|
12
|
+
authWorkspaceId: UUID;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Reconciles a stored `default_json` that has drifted from the default its
|
|
17
|
+
* source declares. Idempotent and a no-op when they already agree.
|
|
18
|
+
*
|
|
19
|
+
* Why this exists — the bug it closes:
|
|
20
|
+
* `ensure-definitions.ts` registers each definition once and then skips it
|
|
21
|
+
* forever (`if (existing) continue;`). That makes a changed `defaultValue` in
|
|
22
|
+
* SOURCE unreachable in any install that has already booted, for every
|
|
23
|
+
* settings-dialog tab a host registers this way. It can surface as a stored
|
|
24
|
+
* default staying "system" in the database while source says "light",
|
|
25
|
+
* rendering a settings panel with the wrong initial state — a visibly wrong
|
|
26
|
+
* value produced by entirely correct-looking source. The next occurrence
|
|
27
|
+
* could be a silently wrong default with no visual tell at all.
|
|
28
|
+
*
|
|
29
|
+
* Why `core`-only:
|
|
30
|
+
* `ownerKind` already encodes who owns a definition. `core` definitions
|
|
31
|
+
* configure a platform capability and are code-owned, so code is the authority
|
|
32
|
+
* on their default and may overwrite a drifted stored one. `site` and `theme`
|
|
33
|
+
* definitions are operator-owned — silently overwriting those would destroy a
|
|
34
|
+
* deliberate choice, so they are rejected rather than reconciled.
|
|
35
|
+
*
|
|
36
|
+
* Why this is NOT a `retype`:
|
|
37
|
+
* `retype` deprecates the active row and inserts `version+1` because a changed
|
|
38
|
+
* SCHEMA means every stored value needs a total coercer. A changed DEFAULT
|
|
39
|
+
* needs none — the schema is untouched, so every stored value stays valid and
|
|
40
|
+
* only the resolution of UNSET values moves. The row is therefore updated in
|
|
41
|
+
* place at the same version, and the paired revision carries the old and new
|
|
42
|
+
* default in `beforeJson`/`afterJson` so the change is auditable.
|
|
43
|
+
*
|
|
44
|
+
* @complexity O(1) — one definition lookup plus at most one row update and one
|
|
45
|
+
* revision append, in a single transaction.
|
|
46
|
+
*/
|
|
47
|
+
export declare function reconcileDefinitionDefault(required: ReconcileDefinitionDefaultRequired): Promise<{
|
|
48
|
+
settingId: string;
|
|
49
|
+
changed: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
export interface DeprecateDefinitionRequired {
|
|
52
|
+
deps: SettingsWriteServiceDeps;
|
|
53
|
+
input: {
|
|
54
|
+
namespace: string;
|
|
55
|
+
key: string;
|
|
56
|
+
workspaceId: UUID | null;
|
|
57
|
+
callerPrincipalId: UUID;
|
|
58
|
+
authWorkspaceId: UUID;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface TombstoneDefinitionRequired {
|
|
62
|
+
deps: SettingsWriteServiceDeps;
|
|
63
|
+
input: {
|
|
64
|
+
namespace: string;
|
|
65
|
+
key: string;
|
|
66
|
+
workspaceId: UUID | null;
|
|
67
|
+
callerPrincipalId: UUID;
|
|
68
|
+
authWorkspaceId: UUID;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Flips the active definition's status to `deprecated`, ledgered `op='deprecate'` -- same-tx, chokepoint-gated. */
|
|
72
|
+
export declare function deprecateDefinition(required: DeprecateDefinitionRequired): Promise<{
|
|
73
|
+
settingId: string;
|
|
74
|
+
version: number;
|
|
75
|
+
}>;
|
|
76
|
+
/** Flips the active definition's status to `tombstone` (kills a core key), ledgered `op='tombstone'` -- same-tx, chokepoint-gated. */
|
|
77
|
+
export declare function tombstoneDefinition(required: TombstoneDefinitionRequired): Promise<{
|
|
78
|
+
settingId: string;
|
|
79
|
+
version: number;
|
|
80
|
+
}>;
|
|
81
|
+
//# sourceMappingURL=write-definition-status.d.ts.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { nowIso as kernelNowIso } from "../primitives/index.js";
|
|
2
|
+
import { DefinitionInvalidError, ValueValidationFailedError } from "./errors.js";
|
|
3
|
+
import { invalidateDefinitionNamespaceCache, validateValueAgainstSchema } from "./settings.js";
|
|
4
|
+
import { authorizeDefinitionsManage, resolveActiveDefinitionOrThrow } from './write-service.js';
|
|
5
|
+
/**
|
|
6
|
+
* Reconciles a stored `default_json` that has drifted from the default its
|
|
7
|
+
* source declares. Idempotent and a no-op when they already agree.
|
|
8
|
+
*
|
|
9
|
+
* Why this exists — the bug it closes:
|
|
10
|
+
* `ensure-definitions.ts` registers each definition once and then skips it
|
|
11
|
+
* forever (`if (existing) continue;`). That makes a changed `defaultValue` in
|
|
12
|
+
* SOURCE unreachable in any install that has already booted, for every
|
|
13
|
+
* settings-dialog tab a host registers this way. It can surface as a stored
|
|
14
|
+
* default staying "system" in the database while source says "light",
|
|
15
|
+
* rendering a settings panel with the wrong initial state — a visibly wrong
|
|
16
|
+
* value produced by entirely correct-looking source. The next occurrence
|
|
17
|
+
* could be a silently wrong default with no visual tell at all.
|
|
18
|
+
*
|
|
19
|
+
* Why `core`-only:
|
|
20
|
+
* `ownerKind` already encodes who owns a definition. `core` definitions
|
|
21
|
+
* configure a platform capability and are code-owned, so code is the authority
|
|
22
|
+
* on their default and may overwrite a drifted stored one. `site` and `theme`
|
|
23
|
+
* definitions are operator-owned — silently overwriting those would destroy a
|
|
24
|
+
* deliberate choice, so they are rejected rather than reconciled.
|
|
25
|
+
*
|
|
26
|
+
* Why this is NOT a `retype`:
|
|
27
|
+
* `retype` deprecates the active row and inserts `version+1` because a changed
|
|
28
|
+
* SCHEMA means every stored value needs a total coercer. A changed DEFAULT
|
|
29
|
+
* needs none — the schema is untouched, so every stored value stays valid and
|
|
30
|
+
* only the resolution of UNSET values moves. The row is therefore updated in
|
|
31
|
+
* place at the same version, and the paired revision carries the old and new
|
|
32
|
+
* default in `beforeJson`/`afterJson` so the change is auditable.
|
|
33
|
+
*
|
|
34
|
+
* @complexity O(1) — one definition lookup plus at most one row update and one
|
|
35
|
+
* revision append, in a single transaction.
|
|
36
|
+
*/
|
|
37
|
+
export async function reconcileDefinitionDefault(required) {
|
|
38
|
+
const { deps, input } = required;
|
|
39
|
+
await authorizeDefinitionsManage(deps, input.callerPrincipalId, input.authWorkspaceId);
|
|
40
|
+
const current = await resolveActiveDefinitionOrThrow(deps, input, "reconcile the default of");
|
|
41
|
+
if (current.ownerKind !== "core") {
|
|
42
|
+
throw new DefinitionInvalidError(`cannot reconcile the default of '${input.namespace}.${input.key}': only 'core' definitions are code-owned, and this one is '${current.ownerKind}' (operator-owned)`);
|
|
43
|
+
}
|
|
44
|
+
// Structural compare — `defaultValue` is a `JsonValue`, so `===` would miss a
|
|
45
|
+
// changed object/array default.
|
|
46
|
+
if (JSON.stringify(current.defaultValue) === JSON.stringify(input.defaultValue)) {
|
|
47
|
+
return { settingId: current.settingId, changed: false };
|
|
48
|
+
}
|
|
49
|
+
if (!validateValueAgainstSchema({ schema: current.schema, value: input.defaultValue })) {
|
|
50
|
+
throw new ValueValidationFailedError(`cannot reconcile the default of '${input.namespace}.${input.key}': the source default does not satisfy the definition's own schema (type '${current.schema.type}')`);
|
|
51
|
+
}
|
|
52
|
+
await deps.repo.transaction(async () => {
|
|
53
|
+
const now = kernelNowIso({ clock: deps.clock });
|
|
54
|
+
await deps.repo.saveDefinition({ ...current, defaultValue: input.defaultValue, updatedAt: now });
|
|
55
|
+
await deps.repo.appendRevision({
|
|
56
|
+
entityKind: "definition",
|
|
57
|
+
settingId: current.settingId,
|
|
58
|
+
scope: null,
|
|
59
|
+
workspaceId: current.workspaceId,
|
|
60
|
+
principalId: null,
|
|
61
|
+
op: "redefault",
|
|
62
|
+
beforeJson: current.defaultValue,
|
|
63
|
+
afterJson: input.defaultValue,
|
|
64
|
+
// Unchanged, deliberately — see the retype contrast above.
|
|
65
|
+
defVersion: current.version,
|
|
66
|
+
actor: input.callerPrincipalId,
|
|
67
|
+
originPluginId: null,
|
|
68
|
+
changeSetId: null,
|
|
69
|
+
createdAt: now,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
invalidateDefinitionNamespaceCache({ repo: deps.repo, namespace: input.namespace });
|
|
73
|
+
return { settingId: current.settingId, changed: true };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* `deprecateDefinition`/`tombstoneDefinition` were a jaccard-1.0
|
|
77
|
+
* duplicate pair (same authorize -> resolve -> same-tx status flip + revision
|
|
78
|
+
* shape, differing only in the target status string). This is that shape,
|
|
79
|
+
* written once; both thin exports below just name their target status.
|
|
80
|
+
*/
|
|
81
|
+
async function transitionDefinitionStatus(deps, input, target) {
|
|
82
|
+
await authorizeDefinitionsManage(deps, input.callerPrincipalId, input.authWorkspaceId);
|
|
83
|
+
const current = await resolveActiveDefinitionOrThrow(deps, input, target.revisionOp);
|
|
84
|
+
const result = await deps.repo.transaction(async () => {
|
|
85
|
+
const now = kernelNowIso({ clock: deps.clock });
|
|
86
|
+
await deps.repo.saveDefinition({ ...current, status: target.status, updatedAt: now });
|
|
87
|
+
await deps.repo.appendRevision({
|
|
88
|
+
entityKind: "definition",
|
|
89
|
+
settingId: current.settingId,
|
|
90
|
+
scope: null,
|
|
91
|
+
workspaceId: current.workspaceId,
|
|
92
|
+
principalId: null,
|
|
93
|
+
op: target.revisionOp,
|
|
94
|
+
beforeJson: null,
|
|
95
|
+
afterJson: null,
|
|
96
|
+
defVersion: current.version,
|
|
97
|
+
actor: input.callerPrincipalId,
|
|
98
|
+
originPluginId: null,
|
|
99
|
+
changeSetId: null,
|
|
100
|
+
createdAt: now,
|
|
101
|
+
});
|
|
102
|
+
return { settingId: current.settingId, version: current.version };
|
|
103
|
+
});
|
|
104
|
+
invalidateDefinitionNamespaceCache({ repo: deps.repo, namespace: input.namespace });
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
/** Flips the active definition's status to `deprecated`, ledgered `op='deprecate'` -- same-tx, chokepoint-gated. */
|
|
108
|
+
export async function deprecateDefinition(required) {
|
|
109
|
+
return transitionDefinitionStatus(required.deps, required.input, {
|
|
110
|
+
status: "deprecated",
|
|
111
|
+
revisionOp: "deprecate",
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/** Flips the active definition's status to `tombstone` (kills a core key), ledgered `op='tombstone'` -- same-tx, chokepoint-gated. */
|
|
115
|
+
export async function tombstoneDefinition(required) {
|
|
116
|
+
return transitionDefinitionStatus(required.deps, required.input, {
|
|
117
|
+
status: "tombstone",
|
|
118
|
+
revisionOp: "tombstone",
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=write-definition-status.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { UUID } from "../primitives/index.js";
|
|
2
|
+
import { type SettingScope } from "./types.js";
|
|
3
|
+
import { type SettingsWriteServiceDeps } from './write-service.js';
|
|
4
|
+
export interface ResetNamespaceRequired {
|
|
5
|
+
deps: SettingsWriteServiceDeps;
|
|
6
|
+
input: {
|
|
7
|
+
namespace: string;
|
|
8
|
+
scope: Exclude<SettingScope, never>;
|
|
9
|
+
workspaceId?: UUID | undefined;
|
|
10
|
+
principalId?: UUID | undefined;
|
|
11
|
+
callerPrincipalId: UUID;
|
|
12
|
+
/** See `SetValueRequired.input.authWorkspaceId`'s doc. Optional/additive. */
|
|
13
|
+
authWorkspaceId?: UUID | undefined;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* — an explicit, human-invoked orchestrator: authorize
|
|
18
|
+
* the matching `settings.reset.*` permission once, then loop `clear` for
|
|
19
|
+
* every setting in the namespace in the reset-authorized internal context
|
|
20
|
+
* (`skipAuthorize: true`) — the outer reset permission is sufficient on its
|
|
21
|
+
* own; each inner clear still emits its own `op='clear'` revision.
|
|
22
|
+
*
|
|
23
|
+
* `revisionSeqs` collects each inner `clear` call's own `revisionSeq` so a
|
|
24
|
+
* host's admin HTTP route can surface the full contract without a second
|
|
25
|
+
* read. Existing callers that only read `.clearedCount` are unaffected.
|
|
26
|
+
* See docs/decisions/DR-003-settings-ledger-invariants.md.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resetNamespace({ keysInNamespace, ...required }: ResetNamespaceRequired & {
|
|
29
|
+
keysInNamespace: string[];
|
|
30
|
+
}, _optional?: Record<string, never>): Promise<{
|
|
31
|
+
clearedCount: number;
|
|
32
|
+
revisionSeqs: number[];
|
|
33
|
+
}>;
|
|
34
|
+
//# sourceMappingURL=write-reset.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ForbiddenError } from "./errors.js";
|
|
2
|
+
import {} from "./types.js";
|
|
3
|
+
import {} from './write-service.js';
|
|
4
|
+
import { clear } from './write-values.js';
|
|
5
|
+
import { assertTargetWorkspaceMatchesAuth } from './write-value-revisions.js';
|
|
6
|
+
/**
|
|
7
|
+
* — an explicit, human-invoked orchestrator: authorize
|
|
8
|
+
* the matching `settings.reset.*` permission once, then loop `clear` for
|
|
9
|
+
* every setting in the namespace in the reset-authorized internal context
|
|
10
|
+
* (`skipAuthorize: true`) — the outer reset permission is sufficient on its
|
|
11
|
+
* own; each inner clear still emits its own `op='clear'` revision.
|
|
12
|
+
*
|
|
13
|
+
* `revisionSeqs` collects each inner `clear` call's own `revisionSeq` so a
|
|
14
|
+
* host's admin HTTP route can surface the full contract without a second
|
|
15
|
+
* read. Existing callers that only read `.clearedCount` are unaffected.
|
|
16
|
+
* See docs/decisions/DR-003-settings-ledger-invariants.md.
|
|
17
|
+
*/
|
|
18
|
+
export async function resetNamespace({ keysInNamespace, ...required }, _optional = {}) {
|
|
19
|
+
const { deps, input } = required;
|
|
20
|
+
const resetPermission = `settings.reset.${input.scope}`;
|
|
21
|
+
const authWorkspaceId = input.authWorkspaceId ?? input.workspaceId ?? input.callerPrincipalId;
|
|
22
|
+
// Asserted once here rather than per inner `clear()`: those run with `skipAuthorize: true`, which
|
|
23
|
+
// short-circuits the same check inside `clear()`. This is the only gate for the whole loop.
|
|
24
|
+
assertTargetWorkspaceMatchesAuth({ ...input, authWorkspaceId });
|
|
25
|
+
const authResult = await deps.authorize({
|
|
26
|
+
principalId: input.callerPrincipalId,
|
|
27
|
+
permission: resetPermission,
|
|
28
|
+
workspaceId: authWorkspaceId,
|
|
29
|
+
entityType: "setting-namespace",
|
|
30
|
+
});
|
|
31
|
+
if (!authResult.allowed) {
|
|
32
|
+
throw new ForbiddenError(`principal '${input.callerPrincipalId}' is not authorized for '${resetPermission}' (${authResult.reason})`);
|
|
33
|
+
}
|
|
34
|
+
// One transaction around the whole loop, so a reset is all-or-nothing.
|
|
35
|
+
//
|
|
36
|
+
// Each `clear()` opens its own transaction and commits on its own, so a
|
|
37
|
+
// failure partway through used to leave the namespace HALF reset — some keys
|
|
38
|
+
// durably cleared, the rest untouched — while the caller received an error and
|
|
39
|
+
// could reasonably assume nothing had happened. "Reset this namespace" is not
|
|
40
|
+
// a meaningful operation if it can apply to an arbitrary prefix of the keys.
|
|
41
|
+
//
|
|
42
|
+
// This works because each inner `clear()` is passed `skipTransaction: true`
|
|
43
|
+
// and so writes into THIS frame instead of opening its own. That is explicit
|
|
44
|
+
// at the call site by design: an earlier version made `transaction` reentrant
|
|
45
|
+
// via an instance-level depth counter, which could not tell a genuine nested
|
|
46
|
+
// call from an unrelated concurrent one and silently merged the two.
|
|
47
|
+
//
|
|
48
|
+
// Both adapters honour the rollback: a SQLite adapter via ROLLBACK, and
|
|
49
|
+
// `repo.memory.ts` via a snapshot/restore journal.
|
|
50
|
+
return deps.repo.transaction(async () => {
|
|
51
|
+
let clearedCount = 0;
|
|
52
|
+
const revisionSeqs = [];
|
|
53
|
+
for (const key of keysInNamespace) {
|
|
54
|
+
const result = await clear({
|
|
55
|
+
deps,
|
|
56
|
+
input: {
|
|
57
|
+
namespace: input.namespace,
|
|
58
|
+
key,
|
|
59
|
+
scope: input.scope,
|
|
60
|
+
workspaceId: input.workspaceId,
|
|
61
|
+
principalId: input.principalId,
|
|
62
|
+
callerPrincipalId: input.callerPrincipalId,
|
|
63
|
+
skipAuthorize: true,
|
|
64
|
+
skipTransaction: true,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
revisionSeqs.push(result.revisionSeq);
|
|
68
|
+
clearedCount++;
|
|
69
|
+
}
|
|
70
|
+
return { clearedCount, revisionSeqs };
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=write-reset.js.map
|