primitive-admin 1.3.0-alpha.0 → 1.3.0-alpha.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 +45 -0
- package/dist/src/commands/admins.js +91 -0
- package/dist/src/commands/admins.js.map +1 -1
- package/dist/src/commands/auth-passkeys.d.ts +7 -0
- package/dist/src/commands/auth-passkeys.js +99 -0
- package/dist/src/commands/auth-passkeys.js.map +1 -0
- package/dist/src/commands/auth-sessions.js +7 -28
- package/dist/src/commands/auth-sessions.js.map +1 -1
- package/dist/src/commands/auth.js +32 -6
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/db3-types.d.ts +27 -0
- package/dist/src/commands/db3-types.js +288 -2
- package/dist/src/commands/db3-types.js.map +1 -1
- package/dist/src/commands/db3.d.ts +16 -2
- package/dist/src/commands/db3.js +614 -5
- package/dist/src/commands/db3.js.map +1 -1
- package/dist/src/commands/documents.js +7 -0
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/functions.js +8 -3
- package/dist/src/commands/functions.js.map +1 -1
- package/dist/src/commands/hosting.js +177 -14
- package/dist/src/commands/hosting.js.map +1 -1
- package/dist/src/commands/metadata.js +14 -6
- package/dist/src/commands/metadata.js.map +1 -1
- package/dist/src/commands/secrets.d.ts +38 -0
- package/dist/src/commands/secrets.js +102 -4
- package/dist/src/commands/secrets.js.map +1 -1
- package/dist/src/commands/spent-tokens.d.ts +19 -0
- package/dist/src/commands/spent-tokens.js +79 -0
- package/dist/src/commands/spent-tokens.js.map +1 -0
- package/dist/src/commands/sync-app-settings.d.ts +145 -0
- package/dist/src/commands/sync-app-settings.js +341 -8
- package/dist/src/commands/sync-app-settings.js.map +1 -1
- package/dist/src/commands/sync.d.ts +62 -15
- package/dist/src/commands/sync.js +437 -48
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/usage.d.ts +24 -0
- package/dist/src/commands/usage.js +54 -0
- package/dist/src/commands/usage.js.map +1 -1
- package/dist/src/commands/users.js +41 -1
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/lib/admin-login-tables.d.ts +31 -0
- package/dist/src/lib/admin-login-tables.js +75 -0
- package/dist/src/lib/admin-login-tables.js.map +1 -0
- package/dist/src/lib/api-client.d.ts +241 -0
- package/dist/src/lib/api-client.js +203 -10
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/app-settings-descriptor.d.ts +42 -3
- package/dist/src/lib/app-settings-descriptor.js +114 -1
- package/dist/src/lib/app-settings-descriptor.js.map +1 -1
- package/dist/src/lib/auth-flow.d.ts +13 -0
- package/dist/src/lib/auth-flow.js +23 -2
- package/dist/src/lib/auth-flow.js.map +1 -1
- package/dist/src/lib/command-groups.js +2 -0
- package/dist/src/lib/command-groups.js.map +1 -1
- package/dist/src/lib/config-object-descriptor.js +6 -1
- package/dist/src/lib/config-object-descriptor.js.map +1 -1
- package/dist/src/lib/credentials-store.d.ts +19 -0
- package/dist/src/lib/credentials-store.js +66 -2
- package/dist/src/lib/credentials-store.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTypeIR.d.ts +2 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js +3 -1
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
- package/dist/src/lib/db-type-records.d.ts +20 -1
- package/dist/src/lib/db-type-records.js +17 -4
- package/dist/src/lib/db-type-records.js.map +1 -1
- package/dist/src/lib/db3-export.d.ts +43 -8
- package/dist/src/lib/db3-export.js +133 -13
- package/dist/src/lib/db3-export.js.map +1 -1
- package/dist/src/lib/db3-json-fields.d.ts +49 -0
- package/dist/src/lib/db3-json-fields.js +195 -0
- package/dist/src/lib/db3-json-fields.js.map +1 -0
- package/dist/src/lib/db3-type-archive.d.ts +59 -0
- package/dist/src/lib/db3-type-archive.js +95 -0
- package/dist/src/lib/db3-type-archive.js.map +1 -0
- package/dist/src/lib/db3-type-models.d.ts +15 -1
- package/dist/src/lib/db3-type-models.js +147 -16
- package/dist/src/lib/db3-type-models.js.map +1 -1
- package/dist/src/lib/document-export-record-log.d.ts +7 -0
- package/dist/src/lib/document-export-record-log.js +9 -0
- package/dist/src/lib/document-export-record-log.js.map +1 -1
- package/dist/src/lib/document-ingest-artifact.d.ts +6 -0
- package/dist/src/lib/document-ingest-artifact.js +20 -1
- package/dist/src/lib/document-ingest-artifact.js.map +1 -1
- package/dist/src/lib/function-authorize-check.js +5 -0
- package/dist/src/lib/function-authorize-check.js.map +1 -1
- package/dist/src/lib/function-authorize-view.d.ts +9 -0
- package/dist/src/lib/function-authorize-view.js +27 -4
- package/dist/src/lib/function-authorize-view.js.map +1 -1
- package/dist/src/lib/function-collect.d.ts +28 -0
- package/dist/src/lib/function-collect.js +129 -2
- package/dist/src/lib/function-collect.js.map +1 -1
- package/dist/src/lib/function-db-types.js +31 -2
- package/dist/src/lib/function-db-types.js.map +1 -1
- package/dist/src/lib/function-grants-preflight.d.ts +99 -0
- package/dist/src/lib/function-grants-preflight.js +154 -2
- package/dist/src/lib/function-grants-preflight.js.map +1 -1
- package/dist/src/lib/function-lint.d.ts +29 -1
- package/dist/src/lib/function-lint.js +208 -0
- package/dist/src/lib/function-lint.js.map +1 -1
- package/dist/src/lib/function-sync.d.ts +73 -0
- package/dist/src/lib/function-sync.js +107 -2
- package/dist/src/lib/function-sync.js.map +1 -1
- package/dist/src/lib/generated-command-status.js +46 -8
- package/dist/src/lib/generated-command-status.js.map +1 -1
- package/dist/src/lib/generated-config-surfaces.d.ts +351 -9
- package/dist/src/lib/generated-config-surfaces.js +1009 -24
- package/dist/src/lib/generated-config-surfaces.js.map +1 -1
- package/dist/src/lib/generated-sdk-types.d.ts +1 -1
- package/dist/src/lib/generated-sdk-types.js +1 -1
- package/dist/src/lib/generated-sdk-types.js.map +1 -1
- package/dist/src/lib/hosting-trust-step.d.ts +67 -0
- package/dist/src/lib/hosting-trust-step.js +279 -0
- package/dist/src/lib/hosting-trust-step.js.map +1 -0
- package/dist/src/lib/hosting-trust.d.ts +77 -0
- package/dist/src/lib/hosting-trust.js +194 -0
- package/dist/src/lib/hosting-trust.js.map +1 -0
- package/dist/src/lib/primitive-declaration.js +89 -10
- package/dist/src/lib/primitive-declaration.js.map +1 -1
- package/dist/src/lib/refresh-admin-credentials.d.ts +34 -4
- package/dist/src/lib/refresh-admin-credentials.js +85 -29
- package/dist/src/lib/refresh-admin-credentials.js.map +1 -1
- package/dist/src/lib/refresh-stored-login.d.ts +85 -0
- package/dist/src/lib/refresh-stored-login.js +233 -0
- package/dist/src/lib/refresh-stored-login.js.map +1 -0
- package/dist/src/lib/row-field-rename.d.ts +18 -0
- package/dist/src/lib/row-field-rename.js +32 -0
- package/dist/src/lib/row-field-rename.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +13 -2
- package/dist/src/lib/schema-codegen/generated-field-grammar.js +24 -1
- package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -1
- package/dist/src/lib/schema-defs-module.d.ts +29 -0
- package/dist/src/lib/schema-defs-module.js +103 -0
- package/dist/src/lib/schema-defs-module.js.map +1 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +6 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js +74 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -1
- package/dist/src/lib/toml-list-edit.d.ts +33 -0
- package/dist/src/lib/toml-list-edit.js +481 -0
- package/dist/src/lib/toml-list-edit.js.map +1 -0
- package/dist/src/lib/toml-scalar-edit.d.ts +9 -0
- package/dist/src/lib/toml-scalar-edit.js +67 -1
- package/dist/src/lib/toml-scalar-edit.js.map +1 -1
- package/dist/src/lib/usage-meters.d.ts +16 -0
- package/dist/src/lib/usage-meters.js +52 -0
- package/dist/src/lib/usage-meters.js.map +1 -0
- package/dist/src/types/index.d.ts +9 -0
- package/package.json +2 -2
|
@@ -13,20 +13,22 @@ import { serializeJsonField } from "../lib/config-json-field.js";
|
|
|
13
13
|
import { parseMetadataCategoryToml, validateMetadataCategoryConfig, serializeMetadataCategoryConfig, parseDeclaredAccessManifestToml, validateDeclaredAccessManifest, } from "../lib/toml-metadata-config.js";
|
|
14
14
|
import { getCurrentAppId, getServerUrl, loadCredentials } from "../lib/config.js";
|
|
15
15
|
import { sessionHoldsScope, tokenReachesScope, } from "../lib/session-scope.js";
|
|
16
|
-
import { requireCurrentEnvironment } from "../lib/env-resolver.js";
|
|
16
|
+
import { getProjectConfig, requireCurrentEnvironment } from "../lib/env-resolver.js";
|
|
17
17
|
import { ensureFileIgnored } from "../lib/local-state.js";
|
|
18
18
|
import { PROJECT_TREE_DIR } from "../lib/env-resolver-core.js";
|
|
19
19
|
import { cachedVarsNote, layerVars, planVarsOverridePull, varsOverridePath as resolveVarsOverridePath, varsOverrideSummaryLine, VARS_OVERRIDE_GITIGNORE_PATTERN, } from "../lib/vars-override.js";
|
|
20
20
|
import { resolveSyncDir, resolveSnapshotsRoot, resolveSyncStateReadPath, resolveSyncStateWritePath, SYNC_STATE_FILENAME, checkLegacyDatabaseTypesDir, } from "../lib/sync-paths.js";
|
|
21
21
|
import { createSnapshot, listSnapshots, resolveSnapshot, restoreSnapshot, pruneSnapshots, } from "../lib/snapshots.js";
|
|
22
22
|
import { FieldTableError, parseConfigToml, parseRawToml, stringifyConfigToml } from "../lib/config-toml.js";
|
|
23
|
-
import { cloneTomlValue, planDb3TypePull, readDb3TypeContext, readDb3TypesDir, resolveDb3TypeModels } from "../lib/db3-type-models.js";
|
|
23
|
+
import { cloneTomlValue, databaseTypeConfigJsonRefusals, planDb3TypePull, readDb3TypeContext, readDb3TypesDir, resolveDb3TypeModels, } from "../lib/db3-type-models.js";
|
|
24
|
+
import { db3JsonDefRefusals } from "../lib/db3-json-fields.js";
|
|
24
25
|
import { canonicalizeIntegrationRequestConfig } from "../lib/integration-request-config.js";
|
|
25
26
|
import { canonicalizeServerTextFields } from "../lib/server-text-normalization.js";
|
|
26
27
|
import { canonicalJsonStringify } from "../lib/canonical-json.js";
|
|
27
28
|
import { newPullWriteTally, writePulledFile, } from "../lib/pull-write.js";
|
|
28
29
|
import { serializeSection, parseTomlToAppSettings, buildAppSettingsPayload, settingsProtectionLevel, } from "../lib/app-settings-descriptor.js";
|
|
29
|
-
import { collectAppSettingsPushErrors, writePulledAppSettings, diffAppSettings, appSettingsFieldDiffs, appSettingsNameExcluded, appSettingsNameExcludedForState, hashAppSettingsForDiff, } from "./sync-app-settings.js";
|
|
30
|
+
import { collectAppSettingsPushErrors, writePulledAppSettings, diffAppSettings, appSettingsFieldDiffs, appSettingsNameExcluded, appSettingsNameExcludedForState, hashAppSettingsForDiff, appSettingsLoweredMinimums, appSettingsWriteBody, clientVersionsWriteFailure, confirmClientVersionLowering, appSettingsBackendOverridesExcluded, appSettingsBackendOverridesExcludedForState, backendOverridesNotSentLine, backendOverrideTargetLines, confirmReleasedBackendOverrides, countBackendOverrides, } from "./sync-app-settings.js";
|
|
31
|
+
import { releasedBackendOverrides } from "../lib/generated-config-surfaces.js";
|
|
30
32
|
// #2644 — the one definition per configuration object, vendored from the server.
|
|
31
33
|
import { BLOB_BUCKET_TABLE, DATABASE_TYPE_TABLE, DB3_TYPE_TABLE, EMAIL_TEMPLATE_TABLE, INTEGRATION_TABLE, METADATA_CATEGORY_CONFIG_TABLE, PROMPT_CONFIG_TABLE, PROMPT_TABLE, RULE_SET_TABLE, SERVER_FUNCTION_TABLE, TEST_CASE_SURFACE, TEST_CASE_TABLE, configDeclaredTypeErrors, deprecatedConfigKey, fieldServerDefault, findMisshapenTables, findUnknownDocumentKeys, findUnknownGroupedTomlKeys, findUnknownTomlKeys, misshapenTableMessage, retiredTomlKey, retiredDocumentKey, spellsDecimalNumber, unrecognizedPushKeysMessage, unrecognizedPushTablesMessage, warnUnrecognizedServerKeys, } from "../lib/config-surface.js";
|
|
32
34
|
import { buildPayloadFromToml, projectEntityToPayload, projectRecordToToml, tomlOwned, } from "../lib/config-payload.js";
|
|
@@ -53,7 +55,7 @@ import { agentFunctionChangeRefusals, agentFunctionUses, } from "../lib/generate
|
|
|
53
55
|
import { resolvePromptStrictOutput } from "../lib/generated-config-surfaces.js";
|
|
54
56
|
// #3179 — the function's two halves: the header payloads and the envelope
|
|
55
57
|
// `config push` sends, and the bytes `config pull` writes back.
|
|
56
|
-
import { applyFunctionPull, buildFunctionConfigPush, buildFunctionConfigPushDetailed, createDocumentSchemaDropWarner, documentSchemaRetentionFailure, buildFunctionCreatePayload, buildFunctionUpdatePayload, functionDiffEntity, functionTomlPreflightErrors, functionPushPreRefusal, functionVersionRefusalMessage, unchangedAccessWarning, planDocumentSchemaPull, planFunctionPull, serializeFunction, } from "../lib/function-sync.js";
|
|
58
|
+
import { applyFunctionPull, buildFunctionConfigPush, buildFunctionConfigPushDetailed, createDocumentSchemaDropWarner, documentSchemaRetentionFailure, buildFunctionCreatePayload, buildFunctionUpdatePayload, functionDiffEntity, functionTomlPreflightErrors, functionVersionPushWarnings, functionPushPreRefusal, functionVersionRefusalMessage, recheckUnchangedFunctionVersion, unchangedAccessWarning, unchangedVersionNeedsInputRecheck, planDocumentSchemaPull, planFunctionPull, serializeFunction, } from "../lib/function-sync.js";
|
|
57
59
|
import { compileFunctionToml, functionFileLabel } from "../lib/function-schema-refs.js";
|
|
58
60
|
import { compilePromptToml, promptSchemaCycleError, promptSchemaKeywordRefusals, preparePromptSchemaRefs, promptConfigSchemaPayload, promptDependenciesOf, promptPlacementErrors, promptPushDependencies, promptSchemaPayload, withSchemaPayload, } from "../lib/prompt-schema-refs.js";
|
|
59
61
|
import { promptFamilyIndexLoader, rememberRemoteFunctions, rememberRemotePrompts } from "../lib/schema-family-index.js";
|
|
@@ -67,7 +69,7 @@ import { FunctionBuildError } from "../lib/function-bundle.js";
|
|
|
67
69
|
import { previewNamesOf } from "../lib/primitive-declaration.js";
|
|
68
70
|
// #3182 — the local half of capability validation. The grammar is the vendored
|
|
69
71
|
// module the server also imports; this is where an author's own file is read.
|
|
70
|
-
import { configObjectKeysFromTree, functionGrantErrors, mergeKnownGrantTargets, } from "../lib/function-grants-preflight.js";
|
|
72
|
+
import { configObjectKeysFromTree, functionGrantErrors, functionReservedSecretPreflight, mergeKnownGrantTargets, } from "../lib/function-grants-preflight.js";
|
|
71
73
|
// #3182 — the typed handle's generated declarations and the compiler wiring
|
|
72
74
|
// that makes an editor load them.
|
|
73
75
|
import { functionTypeWiringProblems, applyFunctionTypeArtifacts, functionTypeRemovalLine, staleFunctionTypeArtifacts, } from "../lib/function-db-types.js";
|
|
@@ -2118,6 +2120,15 @@ export async function runConfigPushPreflight(input) {
|
|
|
2118
2120
|
// #4564 — the protection level follows the name on a machine-local
|
|
2119
2121
|
// environment: out of the body, so out of what is validated.
|
|
2120
2122
|
excludeProtection: localEnvironment,
|
|
2123
|
+
// #6183 — a push to an app other than the tree's own sends no
|
|
2124
|
+
// backend overrides, so none is validated; the app being written is
|
|
2125
|
+
// the one an override may not name.
|
|
2126
|
+
excludeBackendOverrides: appSettingsBackendOverridesExcluded({
|
|
2127
|
+
localEnvironment,
|
|
2128
|
+
isCrossAppPush: !!isCrossAppPush,
|
|
2129
|
+
recorded: syncState?.backendOverridesExcluded === true,
|
|
2130
|
+
}).excluded,
|
|
2131
|
+
ownAppId: resolvedAppId,
|
|
2121
2132
|
});
|
|
2122
2133
|
for (const e of appErrors) {
|
|
2123
2134
|
preflightValidationErrors.push(` app.toml: ${e}`);
|
|
@@ -2225,6 +2236,20 @@ export async function runConfigPushPreflight(input) {
|
|
|
2225
2236
|
// the integrations the server already has. If the live listing cannot
|
|
2226
2237
|
// be fetched and the tree declares none, the target check is skipped
|
|
2227
2238
|
// and the server — which is authoritative — has the last word.
|
|
2239
|
+
// The app's functions, listed at most once for the #6119, #3798 and #4441 checks.
|
|
2240
|
+
// `null` when the listing failed.
|
|
2241
|
+
let liveFunctionRows;
|
|
2242
|
+
const liveFunctionListing = async () => {
|
|
2243
|
+
if (liveFunctionRows === undefined) {
|
|
2244
|
+
try {
|
|
2245
|
+
liveFunctionRows = (await client.listFunctions(resolvedAppId)).items;
|
|
2246
|
+
}
|
|
2247
|
+
catch {
|
|
2248
|
+
liveFunctionRows = null;
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
return liveFunctionRows;
|
|
2252
|
+
};
|
|
2228
2253
|
const preflightFunctionsDir = join(configDir, "functions");
|
|
2229
2254
|
if (existsSync(preflightFunctionsDir)) {
|
|
2230
2255
|
const functionFiles = selectFiles("function", preflightFunctionsDir, readdirSync(preflightFunctionsDir).filter(isFunctionDeclarationFile));
|
|
@@ -2264,6 +2289,7 @@ export async function runConfigPushPreflight(input) {
|
|
|
2264
2289
|
configDir,
|
|
2265
2290
|
functionFiles: functionFiles.map((file) => join(preflightFunctionsDir, file)),
|
|
2266
2291
|
});
|
|
2292
|
+
const reservedSecretFiles = [];
|
|
2267
2293
|
for (const file of functionFiles) {
|
|
2268
2294
|
const filePath = join(preflightFunctionsDir, file);
|
|
2269
2295
|
let tomlData;
|
|
@@ -2295,6 +2321,7 @@ export async function runConfigPushPreflight(input) {
|
|
|
2295
2321
|
// Bounded by the same `selectFiles` above, so `--only` keeps its
|
|
2296
2322
|
// posture (#2645).
|
|
2297
2323
|
const functionKey = tomlData?.function?.key || basename(file, ".toml");
|
|
2324
|
+
reservedSecretFiles.push({ filePath, functionKey, tomlData });
|
|
2298
2325
|
for (const message of functionTomlPreflightErrors({
|
|
2299
2326
|
filePath,
|
|
2300
2327
|
functionKey,
|
|
@@ -2306,6 +2333,21 @@ export async function runConfigPushPreflight(input) {
|
|
|
2306
2333
|
: ` ${filePath}: ${message}`);
|
|
2307
2334
|
}
|
|
2308
2335
|
}
|
|
2336
|
+
// #6119 — a `secret:` capability naming a reserved app secret the
|
|
2337
|
+
// function's active version does not already hold is refused here, with
|
|
2338
|
+
// the server's sentence. Reads nothing unless a selected file names one;
|
|
2339
|
+
// a listing or envelope that cannot be read skips the check with a
|
|
2340
|
+
// warning, and the server still refuses.
|
|
2341
|
+
const reservedSecrets = await functionReservedSecretPreflight({
|
|
2342
|
+
files: reservedSecretFiles,
|
|
2343
|
+
listFunctions: liveFunctionListing,
|
|
2344
|
+
getEnvelope: (functionId, configId) => client.getFunctionConfigEnvelope(resolvedAppId, functionId, configId),
|
|
2345
|
+
});
|
|
2346
|
+
for (const message of reservedSecrets.warnings)
|
|
2347
|
+
warn(` ${message}`);
|
|
2348
|
+
for (const message of reservedSecrets.errors) {
|
|
2349
|
+
preflightValidationErrors.push(` ${message}`);
|
|
2350
|
+
}
|
|
2309
2351
|
}
|
|
2310
2352
|
}
|
|
2311
2353
|
// #5534 — the prompt files are compiled with the server's own module, by
|
|
@@ -2369,20 +2411,6 @@ export async function runConfigPushPreflight(input) {
|
|
|
2369
2411
|
// #3798 — the functions an agent's references are checked against, read
|
|
2370
2412
|
// once and only when a selected prompt is an agent that names one.
|
|
2371
2413
|
let agentFunctions = null;
|
|
2372
|
-
// The app's functions, listed at most once for the #3798 and #4441 checks.
|
|
2373
|
-
// `null` when the listing failed.
|
|
2374
|
-
let liveFunctionRows;
|
|
2375
|
-
const liveFunctionListing = async () => {
|
|
2376
|
-
if (liveFunctionRows === undefined) {
|
|
2377
|
-
try {
|
|
2378
|
-
liveFunctionRows = (await client.listFunctions(resolvedAppId)).items;
|
|
2379
|
-
}
|
|
2380
|
-
catch {
|
|
2381
|
-
liveFunctionRows = null;
|
|
2382
|
-
}
|
|
2383
|
-
}
|
|
2384
|
-
return liveFunctionRows;
|
|
2385
|
-
};
|
|
2386
2414
|
if (existsSync(preflightPromptsDir)) {
|
|
2387
2415
|
for (const file of selectFiles("prompt", preflightPromptsDir, readdirSync(preflightPromptsDir).filter((f) => f.endsWith(".toml")))) {
|
|
2388
2416
|
const filePath = join(preflightPromptsDir, file);
|
|
@@ -3336,6 +3364,16 @@ export function configFileValidationMessages(filePath, tomlData, surface, tables
|
|
|
3336
3364
|
if (surface.label === "prompt") {
|
|
3337
3365
|
messages.push(...promptKindFileErrors(filePath, tomlData));
|
|
3338
3366
|
}
|
|
3367
|
+
// #6020 — `archived` is a key, not a field, so the declared-type check above does not see it.
|
|
3368
|
+
if (surface.label === "db3-type") {
|
|
3369
|
+
const archivedError = db3TypeArchivedKeyError(filePath, tomlData);
|
|
3370
|
+
if (archivedError)
|
|
3371
|
+
messages.push(archivedError);
|
|
3372
|
+
// #5998 — `create` is a key too.
|
|
3373
|
+
const createError = db3TypeCreateKeyError(filePath, tomlData);
|
|
3374
|
+
if (createError)
|
|
3375
|
+
messages.push(createError);
|
|
3376
|
+
}
|
|
3339
3377
|
return messages;
|
|
3340
3378
|
}
|
|
3341
3379
|
/**
|
|
@@ -3407,8 +3445,15 @@ export function collectConfigFileValidationErrors(configDir, experimental = EXPE
|
|
|
3407
3445
|
// #5025 — a db3 type naming a model declared in another file of the
|
|
3408
3446
|
// directory: an undeclared or self reference, or two files declaring one
|
|
3409
3447
|
// model differently, refuses every file it is about.
|
|
3410
|
-
|
|
3411
|
-
|
|
3448
|
+
// #5899 — a JSON field's def may use only the keywords the client validators implement, and a JSON field belongs to
|
|
3449
|
+
// a db3 type in db3-types/.
|
|
3450
|
+
const treeRefusals = dir === "db3-types"
|
|
3451
|
+
? [...resolveDb3TypeModels(typeDir).refusals, ...db3JsonDefRefusals(configDir).map(({ file, message }) => ({ files: [file], message }))]
|
|
3452
|
+
: dir === "database-type-configs"
|
|
3453
|
+
? databaseTypeConfigJsonRefusals(configDir)
|
|
3454
|
+
: null;
|
|
3455
|
+
if (treeRefusals) {
|
|
3456
|
+
for (const refusal of treeRefusals) {
|
|
3412
3457
|
for (const file of refusal.files) {
|
|
3413
3458
|
const filePath = join(typeDir, file);
|
|
3414
3459
|
let tomlData;
|
|
@@ -3611,14 +3656,51 @@ export function serializeDatabaseType(typeConfig, ruleSetIdToName, options = {})
|
|
|
3611
3656
|
*/
|
|
3612
3657
|
export function serializeDb3Type(typeConfig, ruleSetIdToName, options = {}) {
|
|
3613
3658
|
warnUnrecognizedServerKeys(typeConfig, DB3_TYPE_TABLE, `db3-types/${typeConfig?.databaseType}.toml`, options.logger);
|
|
3614
|
-
|
|
3659
|
+
const data = buildDatabaseTypeTomlData(typeConfig, ruleSetIdToName, DB3_TYPE_TABLE);
|
|
3660
|
+
// #6020 — only an archived type's file carries the key, so every other
|
|
3661
|
+
// type's pulled file is as it was.
|
|
3662
|
+
if (typeConfig?.archived === true)
|
|
3663
|
+
data.type = { ...data.type, archived: true };
|
|
3664
|
+
// #5998 — likewise only a restricted type's file carries `create`.
|
|
3665
|
+
if (typeConfig?.create === "admins")
|
|
3666
|
+
data.type = { ...data.type, create: "admins" };
|
|
3667
|
+
return stringifyConfigToml(data);
|
|
3615
3668
|
}
|
|
3616
3669
|
/**
|
|
3617
3670
|
* #4802 — a `db3-types/<name>.toml` file as the payload `PUT db3-types/:name`
|
|
3618
3671
|
* takes: the database type file's, its type read from `[type] name`.
|
|
3672
|
+
* #6020 — `[type] archived = true` reads as `archived: true`; `false` and an
|
|
3673
|
+
* absent key both read as active (no key), the spelling a pull writes.
|
|
3619
3674
|
*/
|
|
3620
3675
|
export function parseDb3TypeToml(tomlData) {
|
|
3621
|
-
|
|
3676
|
+
const parsed = parseDatabaseTypeToml(tomlData, DB3_TYPE_TABLE);
|
|
3677
|
+
if (tomlData?.type?.archived === true)
|
|
3678
|
+
parsed.typeConfig.archived = true;
|
|
3679
|
+
// #5998 — `[type] create = "admins"` reads as `create: "admins"`; `"members"`
|
|
3680
|
+
// and an absent key both read as open (no key), the spelling a pull writes.
|
|
3681
|
+
if (tomlData?.type?.create === "admins")
|
|
3682
|
+
parsed.typeConfig.create = "admins";
|
|
3683
|
+
return parsed;
|
|
3684
|
+
}
|
|
3685
|
+
/**
|
|
3686
|
+
* #5998 — the preflight refusal of a `db3-types/` file whose `[type] create`
|
|
3687
|
+
* is not `"admins"` or `"members"`, or `null` when it is one or absent.
|
|
3688
|
+
*/
|
|
3689
|
+
export function db3TypeCreateKeyError(filePath, tomlData) {
|
|
3690
|
+
const value = tomlData?.type?.create;
|
|
3691
|
+
if (value === undefined || value === "admins" || value === "members")
|
|
3692
|
+
return null;
|
|
3693
|
+
return `${filePath}: [type] create must be "admins" or "members", not ${JSON.stringify(value)}`;
|
|
3694
|
+
}
|
|
3695
|
+
/**
|
|
3696
|
+
* #6020 — the preflight refusal of a `db3-types/` file whose `[type]
|
|
3697
|
+
* archived` is not a boolean, or `null` when it is one or absent.
|
|
3698
|
+
*/
|
|
3699
|
+
export function db3TypeArchivedKeyError(filePath, tomlData) {
|
|
3700
|
+
const value = tomlData?.type?.archived;
|
|
3701
|
+
if (value === undefined || typeof value === "boolean")
|
|
3702
|
+
return null;
|
|
3703
|
+
return `${filePath}: [type] archived must be a boolean (true or false), not ${JSON.stringify(value)}`;
|
|
3622
3704
|
}
|
|
3623
3705
|
/**
|
|
3624
3706
|
* Flatten an email-template detail response onto its field surface.
|
|
@@ -4688,6 +4770,11 @@ export const DB3_TYPE_DIFF_SPEC = {
|
|
|
4688
4770
|
schema: entity.schema ?? null,
|
|
4689
4771
|
triggers: entity.triggers ?? null,
|
|
4690
4772
|
metadataManifest: entity.metadataManifest ?? null,
|
|
4773
|
+
// #6020 — only when archived, so a type never archived projects (and
|
|
4774
|
+
// hashes) exactly as before, and an absent key reads as `false`.
|
|
4775
|
+
...(entity.archived === true ? { archived: true } : {}),
|
|
4776
|
+
// #5998 — likewise only when restricted, so `create = "members"` is no drift.
|
|
4777
|
+
...(entity.create === "admins" ? { create: "admins" } : {}),
|
|
4691
4778
|
}),
|
|
4692
4779
|
describe: (entity) => `db3 type "${entity?.databaseType}"`,
|
|
4693
4780
|
};
|
|
@@ -4754,6 +4841,10 @@ export function buildDb3TypePushBody(typeConfig, options) {
|
|
|
4754
4841
|
...buildOwnedScalarUpdate(typeConfig, DB3_TYPE_OWNED_SCALARS),
|
|
4755
4842
|
triggers: typeConfig.triggers ?? null,
|
|
4756
4843
|
metadataManifest: typeConfig.metadataManifest ?? null,
|
|
4844
|
+
// #6020 — the file owns the archived state: a file without the key unarchives.
|
|
4845
|
+
archived: typeConfig.archived === true,
|
|
4846
|
+
// #5998 — the file owns the create setting: a file without the key opens the type.
|
|
4847
|
+
create: typeConfig.create === "admins" ? "admins" : "members",
|
|
4757
4848
|
};
|
|
4758
4849
|
if (typeof typeConfig.schema === "string" && typeConfig.schema.trim().length > 0)
|
|
4759
4850
|
body.schema = typeConfig.schema;
|
|
@@ -4765,6 +4856,34 @@ export function buildDb3TypePushBody(typeConfig, options) {
|
|
|
4765
4856
|
export function appendOnlyReasonLines(type, reasons) {
|
|
4766
4857
|
return reasons.map((r) => `${type}: ${r.path}: ${r.reason}`);
|
|
4767
4858
|
}
|
|
4859
|
+
/**
|
|
4860
|
+
* What a type write's answer says about the type's field lifecycle, as
|
|
4861
|
+
* `config push` prints it: `deprecatedFields` as a reminder, and
|
|
4862
|
+
* `unclearedFields` as a warning that the return is partial.
|
|
4863
|
+
*/
|
|
4864
|
+
export function fieldLifecycleLines(type, answer) {
|
|
4865
|
+
const info = [];
|
|
4866
|
+
const warn = [];
|
|
4867
|
+
const deprecated = Array.isArray(answer?.deprecatedFields) ? answer.deprecatedFields : [];
|
|
4868
|
+
if (deprecated.length) {
|
|
4869
|
+
info.push(`${type}: ${deprecated.length} deprecated field${deprecated.length === 1 ? "" : "s"} still present: ${deprecated.join(", ")}`);
|
|
4870
|
+
}
|
|
4871
|
+
const uncleared = Array.isArray(answer?.unclearedFields) ? answer.unclearedFields : [];
|
|
4872
|
+
if (uncleared.length) {
|
|
4873
|
+
warn.push(`${type}: un-cleared ${uncleared.join(", ")}. The return is partial: every server read returns each value not yet dropped, ` +
|
|
4874
|
+
`values a db3 already dropped stay unset, and registered indexes the clear dropped are not restored. ` +
|
|
4875
|
+
`On devices, a device keeps its local copy until it next downloads the db3 whole.`);
|
|
4876
|
+
}
|
|
4877
|
+
return { info, warn };
|
|
4878
|
+
}
|
|
4879
|
+
/** Print {@link fieldLifecycleLines} for one type's write. */
|
|
4880
|
+
function printFieldLifecycle(type, answer) {
|
|
4881
|
+
const { info: notes, warn: warnings } = fieldLifecycleLines(type, answer);
|
|
4882
|
+
for (const line of notes)
|
|
4883
|
+
info(` ${line}`);
|
|
4884
|
+
for (const line of warnings)
|
|
4885
|
+
warn(` ${line}`);
|
|
4886
|
+
}
|
|
4768
4887
|
/** The reasons of a `409 DB3_TYPE_NOT_APPEND_ONLY`, or `null` for any other error. */
|
|
4769
4888
|
export function appendOnlyReasonsOf(err) {
|
|
4770
4889
|
if (!(err instanceof ApiError) || err.code !== "DB3_TYPE_NOT_APPEND_ONLY")
|
|
@@ -4971,6 +5090,79 @@ export function db3TypeWriteBaseline(answerType, name, maps) {
|
|
|
4971
5090
|
returned: { ...row, databaseType: row.databaseType ?? typeName ?? name },
|
|
4972
5091
|
});
|
|
4973
5092
|
}
|
|
5093
|
+
/**
|
|
5094
|
+
* #6020 — the environment variable naming the file `config push`'s db3 type
|
|
5095
|
+
* step writes each type's outcome to. Set only by `db3-types archive` and
|
|
5096
|
+
* `unarchive`, which run `config push --only db3-type/<type>` and must tell a
|
|
5097
|
+
* refusal from a write whose answer was lost.
|
|
5098
|
+
*/
|
|
5099
|
+
export const DB3_TYPE_PUSH_REPORT_ENV = "PRIMITIVE_INTERNAL_DB3_TYPE_PUSH_REPORT";
|
|
5100
|
+
/** Write `report` for `name` to the report file, when one is named; never fails the push. */
|
|
5101
|
+
function reportDb3TypePush(name, report) {
|
|
5102
|
+
const path = process.env[DB3_TYPE_PUSH_REPORT_ENV];
|
|
5103
|
+
if (!path)
|
|
5104
|
+
return;
|
|
5105
|
+
try {
|
|
5106
|
+
let all = {};
|
|
5107
|
+
if (existsSync(path)) {
|
|
5108
|
+
try {
|
|
5109
|
+
all = JSON.parse(readFileSync(path, "utf-8")) ?? {};
|
|
5110
|
+
}
|
|
5111
|
+
catch {
|
|
5112
|
+
all = {};
|
|
5113
|
+
}
|
|
5114
|
+
}
|
|
5115
|
+
all[name] = report;
|
|
5116
|
+
writeFileSync(path, JSON.stringify(all));
|
|
5117
|
+
}
|
|
5118
|
+
catch {
|
|
5119
|
+
// The report is advisory; the push's own output and exit code stand.
|
|
5120
|
+
}
|
|
5121
|
+
}
|
|
5122
|
+
/** The failure a thrown push error is reported as: its status and code when it has them. */
|
|
5123
|
+
function db3TypePushFailureOf(err) {
|
|
5124
|
+
const e = err;
|
|
5125
|
+
return {
|
|
5126
|
+
...(typeof e?.name === "string" ? { name: e.name } : {}),
|
|
5127
|
+
message: e instanceof Error ? e.message : String(err),
|
|
5128
|
+
...(typeof e?.statusCode === "number" ? { statusCode: e.statusCode } : {}),
|
|
5129
|
+
...(typeof e?.code === "string" ? { code: e.code } : {}),
|
|
5130
|
+
};
|
|
5131
|
+
}
|
|
5132
|
+
/**
|
|
5133
|
+
* The sync baseline of one `db3-types/` file: the row's `modifiedAt`, the
|
|
5134
|
+
* file's bytes, the semantic hash of the row and whether it holds a schema.
|
|
5135
|
+
* The legacy twin's baseline moves with the row, so its prune and its next
|
|
5136
|
+
* push read no drift. Shared by `config push` and `db3-types archive` (#6020).
|
|
5137
|
+
*/
|
|
5138
|
+
export function recordDb3TypeBaseline(syncState, name, filePath, modifiedAt, semanticHash, hasSchema) {
|
|
5139
|
+
if (!syncState.entities.db3Types)
|
|
5140
|
+
syncState.entities.db3Types = {};
|
|
5141
|
+
syncState.entities.db3Types[name] = {
|
|
5142
|
+
name,
|
|
5143
|
+
modifiedAt,
|
|
5144
|
+
contentHash: computeFileHash(filePath),
|
|
5145
|
+
...(semanticHash ? { semanticHash } : {}),
|
|
5146
|
+
...(hasSchema !== undefined ? { hasSchema } : {}),
|
|
5147
|
+
};
|
|
5148
|
+
const legacy = syncState.entities.databaseTypes?.[name];
|
|
5149
|
+
if (legacy)
|
|
5150
|
+
legacy.modifiedAt = modifiedAt;
|
|
5151
|
+
}
|
|
5152
|
+
/**
|
|
5153
|
+
* #6020 — stamp the sync baseline of one `db3-types/` file from a type read
|
|
5154
|
+
* back from `GET db3-types/:name` (the db3 type answer), as a push's answer
|
|
5155
|
+
* stamps it: used when the push's own answer was lost and the read confirmed
|
|
5156
|
+
* the write. Writes nothing when this tree has no sync state for the app.
|
|
5157
|
+
*/
|
|
5158
|
+
export function stampDb3TypeBaselineFromRead(name, filePath, type) {
|
|
5159
|
+
const state = loadSyncState();
|
|
5160
|
+
if (!state)
|
|
5161
|
+
return;
|
|
5162
|
+
const maps = { ruleSetIdToName: new Map(), ruleSetNameToId: new Map() };
|
|
5163
|
+
recordDb3TypeBaseline(state, name, filePath, type?.modifiedAt || new Date().toISOString(), db3TypeWriteBaseline(type, name, maps), typeof type?.schema === "string" && type.schema.length > 0);
|
|
5164
|
+
saveSyncState(state);
|
|
5165
|
+
}
|
|
4974
5166
|
/**
|
|
4975
5167
|
* #5025 — the hint a declined `db3-types/` push carries: the conflict hint
|
|
4976
5168
|
* when the row is live but this tree holds no baseline for it, none otherwise.
|
|
@@ -5022,7 +5214,9 @@ export function classifyDb3TypeTwins(configDir, maps = { ruleSetIdToName: new Ma
|
|
|
5022
5214
|
continue;
|
|
5023
5215
|
let same = false;
|
|
5024
5216
|
try {
|
|
5025
|
-
|
|
5217
|
+
// #6020 — a legacy file cannot carry `archived`, so the db3 side's is left out.
|
|
5218
|
+
// #5998 — nor `create`.
|
|
5219
|
+
const { archived: _archived, create: _create, ...db3Side } = projectLocalConfig(DB3_TYPE_DIFF_SPEC, parsed, maps);
|
|
5026
5220
|
// #5993 — a db3 type takes no rule set, so the legacy file's is left
|
|
5027
5221
|
// out, resolved (`ruleSetId`) or not (`_unresolvedRuleSetName`).
|
|
5028
5222
|
const { ruleSetId: _ruleSetId, _unresolvedRuleSetName: _unresolved, ...legacySide } = projectLocalConfig(configDiffSpec("database-type-config"), twin.parsed, maps);
|
|
@@ -6004,6 +6198,19 @@ export function sameTomlAs(serverContent) {
|
|
|
6004
6198
|
* already builds) makes those guards hold from the first run, so the
|
|
6005
6199
|
* end-of-push and catch-path saves persist what the push actually did.
|
|
6006
6200
|
*/
|
|
6201
|
+
/**
|
|
6202
|
+
* The committed environments of `primitive/config.json` (#6183), which a
|
|
6203
|
+
* push's backend-override summary matches each override's target against.
|
|
6204
|
+
* Empty when the project has no config.
|
|
6205
|
+
*/
|
|
6206
|
+
function committedEnvironmentsForSummary() {
|
|
6207
|
+
try {
|
|
6208
|
+
return getProjectConfig()?.environments ?? {};
|
|
6209
|
+
}
|
|
6210
|
+
catch {
|
|
6211
|
+
return {};
|
|
6212
|
+
}
|
|
6213
|
+
}
|
|
6007
6214
|
export function ensurePushSyncState(existing, appId, serverUrl) {
|
|
6008
6215
|
if (existing)
|
|
6009
6216
|
return existing;
|
|
@@ -8369,10 +8576,19 @@ export function registerConfigSyncCommands(sync, options = {}) {
|
|
|
8369
8576
|
ensureDir(join(configDir, "metadata-category-configs"));
|
|
8370
8577
|
}
|
|
8371
8578
|
ensureDir(join(configDir, "email-templates"));
|
|
8579
|
+
// #6183 — an environment whose sync state named another app, or
|
|
8580
|
+
// recorded that it did, keeps leaving the tree's backend overrides
|
|
8581
|
+
// alone after a re-init.
|
|
8582
|
+
const priorInitState = loadSyncState();
|
|
8583
|
+
const keepsOverridesExcluded = !requireCurrentEnvironment().local &&
|
|
8584
|
+
!!priorInitState &&
|
|
8585
|
+
(priorInitState.appId !== resolvedAppId ||
|
|
8586
|
+
priorInitState.backendOverridesExcluded === true);
|
|
8372
8587
|
const state = {
|
|
8373
8588
|
appId: resolvedAppId,
|
|
8374
8589
|
serverUrl: getServerUrl(),
|
|
8375
8590
|
lastSyncedAt: new Date().toISOString(),
|
|
8591
|
+
...(keepsOverridesExcluded ? { backendOverridesExcluded: true } : {}),
|
|
8376
8592
|
entities: {},
|
|
8377
8593
|
};
|
|
8378
8594
|
saveSyncState(state);
|
|
@@ -8585,6 +8801,14 @@ export function registerConfigSyncCommands(sync, options = {}) {
|
|
|
8585
8801
|
// files themselves are about to be rewritten.
|
|
8586
8802
|
const priorState = loadSyncState();
|
|
8587
8803
|
const priorEntities = priorState?.entities ?? {};
|
|
8804
|
+
// #6183 — the backend-override rule, as push reads it: a
|
|
8805
|
+
// machine-local environment, a sync state naming another app, or one
|
|
8806
|
+
// that recorded such a push or pull.
|
|
8807
|
+
const pullExcludesBackendOverrides = appSettingsBackendOverridesExcluded({
|
|
8808
|
+
localEnvironment: pullsLocalEnvironment,
|
|
8809
|
+
isCrossAppPush: !!(priorState && priorState.appId !== resolvedAppId),
|
|
8810
|
+
recorded: priorState?.backendOverridesExcluded === true,
|
|
8811
|
+
}).excluded;
|
|
8588
8812
|
// #3190 — the slots of the retired object types (workflows, scripts,
|
|
8589
8813
|
// webhooks, cron triggers) are not carried into the state this pull
|
|
8590
8814
|
// writes; say so once, so the shrinking file is not a surprise.
|
|
@@ -8622,6 +8846,9 @@ export function registerConfigSyncCommands(sync, options = {}) {
|
|
|
8622
8846
|
// tree's, and a pull never writes the child's over it (#4117).
|
|
8623
8847
|
const written = writePulledAppSettings(configDir, settings, {
|
|
8624
8848
|
keepStatedName: pullsLocalEnvironment,
|
|
8849
|
+
// #6183 — a pull from an app other than the tree's own keeps the
|
|
8850
|
+
// backend overrides the file states and writes none of that app's.
|
|
8851
|
+
keepStatedBackendOverrides: pullExcludesBackendOverrides,
|
|
8625
8852
|
tally: pullWrites,
|
|
8626
8853
|
});
|
|
8627
8854
|
if (written.written)
|
|
@@ -9383,6 +9610,11 @@ export function registerConfigSyncCommands(sync, options = {}) {
|
|
|
9383
9610
|
appId: resolvedAppId,
|
|
9384
9611
|
serverUrl: getServerUrl(),
|
|
9385
9612
|
lastSyncedAt: new Date().toISOString(),
|
|
9613
|
+
// #6183 — carried, never ended: a committed environment once
|
|
9614
|
+
// pointed at another app keeps leaving the tree's overrides alone.
|
|
9615
|
+
...(pullExcludesBackendOverrides && !pullsLocalEnvironment
|
|
9616
|
+
? { backendOverridesExcluded: true }
|
|
9617
|
+
: {}),
|
|
9386
9618
|
entities: {
|
|
9387
9619
|
app: settings && pullsApp
|
|
9388
9620
|
? {
|
|
@@ -9477,9 +9709,9 @@ export function registerConfigSyncCommands(sync, options = {}) {
|
|
|
9477
9709
|
// `--only`, so `--only workflow/a --only prompt/b` would silently apply
|
|
9478
9710
|
// just the prompt and report success.
|
|
9479
9711
|
(value, previous) => [...(previous ?? []), value], [])
|
|
9480
|
-
.option("--prune", "Delete remote entities whose local TOML was removed since the last sync
|
|
9481
|
-
.option("-y, --yes", "Skip the interactive confirmation before pruning (for CI / automation)")
|
|
9482
|
-
.option("--accept-warnings", "Commit schema diffs that have operations with dynamic refs
|
|
9712
|
+
.option("--prune", "Delete remote entities whose local TOML was removed since the last sync")
|
|
9713
|
+
.option("-y, --yes", "Skip the interactive confirmation before pruning or before lowering or removing a client version minimum in app.toml (for CI / automation)")
|
|
9714
|
+
.option("--accept-warnings", "Commit schema diffs that have operations with dynamic refs, via the SCHEMA_HAS_UNCHECKABLE_OPS escape hatch")
|
|
9483
9715
|
.option("--allow-field-removal", "Push db3 type changes that would make stored records unreadable (removed fields or models, changed types). Needs `[app] allowFieldRemoval = true` already stored by an earlier push")
|
|
9484
9716
|
// #3320 — what this command actually guarantees, said where it is run.
|
|
9485
9717
|
// Two stages, and only the first is all-or-nothing.
|
|
@@ -9502,7 +9734,7 @@ What a push guarantees (two stages):
|
|
|
9502
9734
|
secret exists, whether a scheme's config is valid under this environment's
|
|
9503
9735
|
policy, per-app caps, key collisions. Those surface during apply.
|
|
9504
9736
|
`)
|
|
9505
|
-
.option("--no-typecheck", "Ship function code without typechecking it against the declarations this push generates
|
|
9737
|
+
.option("--no-typecheck", "Ship function code without typechecking it against the declarations this push generates")
|
|
9506
9738
|
.action(async (options) => {
|
|
9507
9739
|
const resolvedAppId = getCurrentAppId();
|
|
9508
9740
|
const configDir = resolveSyncDir();
|
|
@@ -9569,6 +9801,13 @@ What a push guarantees (two stages):
|
|
|
9569
9801
|
serverUrl: syncState.serverUrl,
|
|
9570
9802
|
lastSyncedAt: new Date().toISOString(),
|
|
9571
9803
|
entities: {},
|
|
9804
|
+
// #6183 — this committed environment now names an app other than
|
|
9805
|
+
// the tree's own: from here on its pushes send no backend overrides
|
|
9806
|
+
// and its pulls keep the file's. Recorded whatever `app.toml` holds
|
|
9807
|
+
// and whatever `--only` selects, and never removed, so no later edit
|
|
9808
|
+
// or branch switch sends the tree's overrides to this app. A
|
|
9809
|
+
// machine-local environment needs no record: it is always excluded.
|
|
9810
|
+
...(localEnvironment ? {} : { backendOverridesExcluded: true }),
|
|
9572
9811
|
};
|
|
9573
9812
|
}
|
|
9574
9813
|
// A `--only` selector that would apply nothing is refused before push
|
|
@@ -10286,16 +10525,47 @@ What a push guarantees (two stages):
|
|
|
10286
10525
|
// The whole-truth body. Errors (an unrecognized or retired key, a
|
|
10287
10526
|
// type mismatch, a missing required key) already aborted the push in
|
|
10288
10527
|
// the preflight pass above, so only warnings remain here.
|
|
10528
|
+
// #6183 — a push to an app other than the tree's own (a
|
|
10529
|
+
// machine-local environment, a cross-app push, or a sync state
|
|
10530
|
+
// that recorded one) sends no backend overrides.
|
|
10531
|
+
const overridesExclusion = appSettingsBackendOverridesExcluded({
|
|
10532
|
+
localEnvironment,
|
|
10533
|
+
isCrossAppPush: !!isCrossAppPush,
|
|
10534
|
+
recorded: syncState?.backendOverridesExcluded === true,
|
|
10535
|
+
});
|
|
10289
10536
|
const { settings: appPayload, warnings: appWarnings } = buildAppSettingsPayload(tomlData, {
|
|
10290
10537
|
excludeName: payloadExcludesName,
|
|
10291
10538
|
nameOptional: localEnvironment,
|
|
10292
10539
|
// #4564 — on a machine-local environment the level is the
|
|
10293
10540
|
// shared tree's, like the name, and never this child's.
|
|
10294
10541
|
excludeProtection: localEnvironment,
|
|
10542
|
+
excludeBackendOverrides: overridesExclusion.excluded,
|
|
10543
|
+
ownAppId: resolvedAppId,
|
|
10295
10544
|
});
|
|
10296
10545
|
for (const w of appWarnings) {
|
|
10297
10546
|
warn(` ${w}`);
|
|
10298
10547
|
}
|
|
10548
|
+
// Said before the comparison, so an unchanged push says it too:
|
|
10549
|
+
// the overrides left out, or where each one sent points.
|
|
10550
|
+
if (overridesExclusion.excluded) {
|
|
10551
|
+
const notSent = countBackendOverrides(tomlData?.clients);
|
|
10552
|
+
if (notSent > 0) {
|
|
10553
|
+
info(` ${backendOverridesNotSentLine(notSent, overridesExclusion.reason, requireCurrentEnvironment().name)}`);
|
|
10554
|
+
}
|
|
10555
|
+
}
|
|
10556
|
+
else {
|
|
10557
|
+
const targetLines = backendOverrideTargetLines({
|
|
10558
|
+
clients: appPayload.clientVersions,
|
|
10559
|
+
environments: committedEnvironmentsForSummary(),
|
|
10560
|
+
currentApiUrl: requireCurrentEnvironment().config.apiUrl,
|
|
10561
|
+
});
|
|
10562
|
+
for (const line of targetLines) {
|
|
10563
|
+
if (line.level === "warn")
|
|
10564
|
+
warn(` ${line.text}`);
|
|
10565
|
+
else
|
|
10566
|
+
info(` ${line.text}`);
|
|
10567
|
+
}
|
|
10568
|
+
}
|
|
10299
10569
|
let appLiveOk = true;
|
|
10300
10570
|
let liveSettings;
|
|
10301
10571
|
try {
|
|
@@ -10372,7 +10642,7 @@ What a push guarantees (two stages):
|
|
|
10372
10642
|
},
|
|
10373
10643
|
});
|
|
10374
10644
|
const fields = appSettingsFieldDiffs(appPayload, liveSettings ?? {}, compareOptions).map((d) => ({
|
|
10375
|
-
field:
|
|
10645
|
+
field: d.label,
|
|
10376
10646
|
local: d.local,
|
|
10377
10647
|
server: d.remote,
|
|
10378
10648
|
}));
|
|
@@ -10420,10 +10690,77 @@ What a push guarantees (two stages):
|
|
|
10420
10690
|
applyAppSettings = false;
|
|
10421
10691
|
}
|
|
10422
10692
|
}
|
|
10693
|
+
// #6034 — a push that lowers or removes a stored client version
|
|
10694
|
+
// minimum names each change and proceeds only on confirmation
|
|
10695
|
+
// (`--yes`, or the prompt); with no terminal it is an apply failure
|
|
10696
|
+
// and app.toml is not sent. Compared against the TARGET app's live
|
|
10697
|
+
// policy, whichever app the tree came from.
|
|
10698
|
+
if (applyAppSettings) {
|
|
10699
|
+
const lowering = await confirmClientVersionLowering({
|
|
10700
|
+
lowered: appLiveOk
|
|
10701
|
+
? appSettingsLoweredMinimums(liveSettings, appPayload)
|
|
10702
|
+
: [],
|
|
10703
|
+
compared: appLiveOk,
|
|
10704
|
+
dryRun: !!options.dryRun,
|
|
10705
|
+
yes: !!options.yes,
|
|
10706
|
+
confirm: (message) => confirmPrompt(message),
|
|
10707
|
+
print: (line) => warn(line),
|
|
10708
|
+
});
|
|
10709
|
+
if (lowering.proceed === false) {
|
|
10710
|
+
applyFailures.push({
|
|
10711
|
+
type: "app-settings",
|
|
10712
|
+
key: "app.toml",
|
|
10713
|
+
message: lowering.failure,
|
|
10714
|
+
});
|
|
10715
|
+
applyAppSettings = false;
|
|
10716
|
+
}
|
|
10717
|
+
}
|
|
10718
|
+
// #6183 — a backend override at or below its platform's `latest`
|
|
10719
|
+
// moves copies already released: named, and stored only on a yes.
|
|
10720
|
+
// Judged from the file alone, so asked whether or not the live
|
|
10721
|
+
// settings could be read.
|
|
10423
10722
|
if (applyAppSettings) {
|
|
10424
|
-
|
|
10723
|
+
const released = await confirmReleasedBackendOverrides({
|
|
10724
|
+
released: releasedBackendOverrides(appPayload.clientVersions ?? null),
|
|
10725
|
+
dryRun: !!options.dryRun,
|
|
10726
|
+
yes: !!options.yes,
|
|
10727
|
+
confirm: (message) => confirmPrompt(message),
|
|
10728
|
+
print: (line) => warn(line),
|
|
10729
|
+
});
|
|
10730
|
+
if (released.proceed === false) {
|
|
10731
|
+
applyFailures.push({
|
|
10732
|
+
type: "app-settings",
|
|
10733
|
+
key: "app.toml",
|
|
10734
|
+
message: released.failure,
|
|
10735
|
+
});
|
|
10736
|
+
applyAppSettings = false;
|
|
10737
|
+
}
|
|
10738
|
+
}
|
|
10739
|
+
if (applyAppSettings) {
|
|
10740
|
+
let updated;
|
|
10741
|
+
let appWriteRefused = false;
|
|
10425
10742
|
if (!options.dryRun) {
|
|
10426
|
-
|
|
10743
|
+
// The body carries the policy the push compared against
|
|
10744
|
+
// (#6034): the server writes only if it is still the stored one.
|
|
10745
|
+
try {
|
|
10746
|
+
updated = await client.updateAppSettings(resolvedAppId, appSettingsWriteBody(appPayload, {
|
|
10747
|
+
liveRead: appLiveOk,
|
|
10748
|
+
liveSettings,
|
|
10749
|
+
force: !!options.force,
|
|
10750
|
+
}));
|
|
10751
|
+
}
|
|
10752
|
+
catch (err) {
|
|
10753
|
+
const failure = clientVersionsWriteFailure(err);
|
|
10754
|
+
if (!failure)
|
|
10755
|
+
throw err;
|
|
10756
|
+
applyFailures.push(failure);
|
|
10757
|
+
appWriteRefused = true;
|
|
10758
|
+
}
|
|
10759
|
+
}
|
|
10760
|
+
if (!appWriteRefused) {
|
|
10761
|
+
changes.push({ type: "app", action: "update", key: "settings" });
|
|
10762
|
+
}
|
|
10763
|
+
if (!options.dryRun && !appWriteRefused) {
|
|
10427
10764
|
info(" Updated app settings");
|
|
10428
10765
|
// Stamped from what the server RETURNED, not from the body sent:
|
|
10429
10766
|
// `PUT /settings` normalizes (a trailing slash off `baseUrl`, a
|
|
@@ -12278,6 +12615,9 @@ What a push guarantees (two stages):
|
|
|
12278
12615
|
}
|
|
12279
12616
|
}
|
|
12280
12617
|
const db3TwinNames = new Set();
|
|
12618
|
+
// The row each db3 type push in this run left (its modifiedAt), so a
|
|
12619
|
+
// legacy twin pushed after it can read that write as its baseline.
|
|
12620
|
+
const db3WrittenThisRun = new Map();
|
|
12281
12621
|
const db3TypesDir = join(configDir, "db3-types");
|
|
12282
12622
|
if (existsSync(db3TypesDir)) {
|
|
12283
12623
|
const files = selectFiles("db3-type", db3TypesDir, readdirSync(db3TypesDir).filter((f) => f.endsWith(".toml")));
|
|
@@ -12314,20 +12654,7 @@ What a push guarantees (two stages):
|
|
|
12314
12654
|
const record = (modifiedAt, semanticHash, hasSchema) => {
|
|
12315
12655
|
if (!syncState || options.dryRun)
|
|
12316
12656
|
return;
|
|
12317
|
-
|
|
12318
|
-
syncState.entities.db3Types = {};
|
|
12319
|
-
syncState.entities.db3Types[name] = {
|
|
12320
|
-
name,
|
|
12321
|
-
modifiedAt,
|
|
12322
|
-
contentHash: computeFileHash(filePath),
|
|
12323
|
-
...(semanticHash ? { semanticHash } : {}),
|
|
12324
|
-
...(hasSchema !== undefined ? { hasSchema } : {}),
|
|
12325
|
-
};
|
|
12326
|
-
// The legacy twin's baseline moves with the row, so its prune
|
|
12327
|
-
// and its next push read no drift.
|
|
12328
|
-
const legacy = syncState.entities.databaseTypes?.[name];
|
|
12329
|
-
if (legacy)
|
|
12330
|
-
legacy.modifiedAt = modifiedAt;
|
|
12657
|
+
recordDb3TypeBaseline(syncState, name, filePath, modifiedAt, semanticHash, hasSchema);
|
|
12331
12658
|
};
|
|
12332
12659
|
let gate;
|
|
12333
12660
|
if (db3TypesLiveOk && !live) {
|
|
@@ -12345,10 +12672,12 @@ What a push guarantees (two stages):
|
|
|
12345
12672
|
if (gate.action === "skip") {
|
|
12346
12673
|
skippedCount++;
|
|
12347
12674
|
record(live.modifiedAt || entry?.modifiedAt || new Date().toISOString(), gate.remoteHash, typeof live.schema === "string" && live.schema.trim().length > 0);
|
|
12675
|
+
reportDb3TypePush(name, { outcome: "skipped" });
|
|
12348
12676
|
continue;
|
|
12349
12677
|
}
|
|
12350
12678
|
if (gate.action === "drift" || gate.action === "conflict" || gate.action === "immutable") {
|
|
12351
12679
|
recordDeclined("db3-type", name, gate, entry?.modifiedAt, db3TypeDeclineHint(name, gate));
|
|
12680
|
+
reportDb3TypePush(name, { outcome: "declined", action: gate.action });
|
|
12352
12681
|
continue;
|
|
12353
12682
|
}
|
|
12354
12683
|
}
|
|
@@ -12360,10 +12689,12 @@ What a push guarantees (two stages):
|
|
|
12360
12689
|
});
|
|
12361
12690
|
if (degraded.action === "skip") {
|
|
12362
12691
|
skippedCount++;
|
|
12692
|
+
reportDb3TypePush(name, { outcome: "skipped" });
|
|
12363
12693
|
continue;
|
|
12364
12694
|
}
|
|
12365
12695
|
if (degraded.action === "decline") {
|
|
12366
12696
|
recordDeclined("db3-type", name, { action: "live-unavailable" }, entry?.modifiedAt);
|
|
12697
|
+
reportDb3TypePush(name, { outcome: "declined", action: "live-unavailable" });
|
|
12367
12698
|
continue;
|
|
12368
12699
|
}
|
|
12369
12700
|
}
|
|
@@ -12380,7 +12711,10 @@ What a push guarantees (two stages):
|
|
|
12380
12711
|
if (options.dryRun)
|
|
12381
12712
|
continue;
|
|
12382
12713
|
info(` ${answer.created ? "Created" : "Updated"} db3 type: ${name}`);
|
|
12714
|
+
if (typeof answer.type?.modifiedAt === "string")
|
|
12715
|
+
db3WrittenThisRun.set(name, answer.type.modifiedAt);
|
|
12383
12716
|
printAppendOnlyOverride(name, answer);
|
|
12717
|
+
printFieldLifecycle(name, answer);
|
|
12384
12718
|
printStaleInstanceWarning(answer);
|
|
12385
12719
|
if (answer.push?.runId) {
|
|
12386
12720
|
info(` Pushing revision ${answer.revision.generation} to the db3s of ${name}: run ${answer.push.runId} — ` +
|
|
@@ -12390,8 +12724,10 @@ What a push guarantees (two stages):
|
|
|
12390
12724
|
warn(` The push to the db3s of ${name} did not start: ${answer.push.error}`);
|
|
12391
12725
|
}
|
|
12392
12726
|
record(answer.type?.modifiedAt || new Date().toISOString(), db3TypeWriteBaseline(answer.type, name, pushDiffMaps), typeof answer.type?.schema === "string" && answer.type.schema.length > 0);
|
|
12727
|
+
reportDb3TypePush(name, { outcome: "applied", answer });
|
|
12393
12728
|
}
|
|
12394
12729
|
catch (err) {
|
|
12730
|
+
reportDb3TypePush(name, { outcome: "failed", failure: db3TypePushFailureOf(err) });
|
|
12395
12731
|
if (err instanceof ConflictError) {
|
|
12396
12732
|
conflicts.push({
|
|
12397
12733
|
type: "db3-type",
|
|
@@ -12504,6 +12840,18 @@ What a push guarantees (two stages):
|
|
|
12504
12840
|
dbTypeGate = { action: "create" };
|
|
12505
12841
|
}
|
|
12506
12842
|
else if (databaseTypesLiveOk && liveDatabaseType) {
|
|
12843
|
+
// A legacy twin with no baseline (a cross-app push resets them)
|
|
12844
|
+
// whose row this run's db3 push just wrote, and nobody has moved
|
|
12845
|
+
// since: that write is the baseline, so its rule set is an edit
|
|
12846
|
+
// over it, not a change of unknown direction (#5993).
|
|
12847
|
+
const writtenAt = db3WrittenThisRun.get(dbType);
|
|
12848
|
+
const gateEntry = !existingEntry && writtenAt !== undefined && liveDatabaseType.modifiedAt === writtenAt
|
|
12849
|
+
? {
|
|
12850
|
+
databaseType: dbType,
|
|
12851
|
+
modifiedAt: writtenAt,
|
|
12852
|
+
semanticHash: hashRemoteConfigForDiff(databaseTypeSpec, liveDatabaseType, pushDiffMaps),
|
|
12853
|
+
}
|
|
12854
|
+
: existingEntry;
|
|
12507
12855
|
dbTypeGate = decidePushForConfig({
|
|
12508
12856
|
spec: databaseTypeSpec,
|
|
12509
12857
|
maps: pushDiffMaps,
|
|
@@ -12513,7 +12861,7 @@ What a push guarantees (two stages):
|
|
|
12513
12861
|
extra: {},
|
|
12514
12862
|
modifiedAt: liveDatabaseType.modifiedAt,
|
|
12515
12863
|
},
|
|
12516
|
-
entry:
|
|
12864
|
+
entry: gateEntry,
|
|
12517
12865
|
localFileHash: computeFileHash(filePath),
|
|
12518
12866
|
force: options.force,
|
|
12519
12867
|
});
|
|
@@ -12798,6 +13146,7 @@ What a push guarantees (two stages):
|
|
|
12798
13146
|
});
|
|
12799
13147
|
info(` Updated database type: ${dbType}`);
|
|
12800
13148
|
printAppendOnlyOverride(dbType, updated);
|
|
13149
|
+
printFieldLifecycle(dbType, updated);
|
|
12801
13150
|
// Issue #1567: name each owned scalar this push cleared, so
|
|
12802
13151
|
// removing a rule (triggers, autoPopulatedFields) is never
|
|
12803
13152
|
// silent.
|
|
@@ -12875,6 +13224,7 @@ What a push guarantees (two stages):
|
|
|
12875
13224
|
try {
|
|
12876
13225
|
const created = await client.createDatabaseTypeConfig(resolvedAppId, createData);
|
|
12877
13226
|
info(` Created database type: ${dbType}`);
|
|
13227
|
+
printFieldLifecycle(dbType, created);
|
|
12878
13228
|
if (syncState) {
|
|
12879
13229
|
if (!syncState.entities.databaseTypes) {
|
|
12880
13230
|
syncState.entities.databaseTypes = {};
|
|
@@ -13004,6 +13354,7 @@ What a push guarantees (two stages):
|
|
|
13004
13354
|
});
|
|
13005
13355
|
printStaleInstanceWarning(reconciled);
|
|
13006
13356
|
printAppendOnlyOverride(dbType, reconciled);
|
|
13357
|
+
printFieldLifecycle(dbType, reconciled);
|
|
13007
13358
|
if (syncState?.entities?.databaseTypes?.[dbType] &&
|
|
13008
13359
|
reconciled?.modifiedAt) {
|
|
13009
13360
|
syncState.entities.databaseTypes[dbType].modifiedAt =
|
|
@@ -13374,7 +13725,36 @@ What a push guarantees (two stages):
|
|
|
13374
13725
|
if (codeUnchanged && localAuthorize && tomlCarriesAccess) {
|
|
13375
13726
|
warn(` ${unchangedAccessWarning(key)}`);
|
|
13376
13727
|
}
|
|
13377
|
-
|
|
13728
|
+
// #6170 — an unchanged function whose active version runs
|
|
13729
|
+
// `authorize` with no recorded input list is sent anyway (never on
|
|
13730
|
+
// a dry run): the server records a list the source declares, or
|
|
13731
|
+
// answers its warning or refusal again. It still counts as
|
|
13732
|
+
// unchanged, unless the server made a new version after all.
|
|
13733
|
+
let recheckedCreated = false;
|
|
13734
|
+
if (headerAction === "skip" &&
|
|
13735
|
+
codeUnchanged &&
|
|
13736
|
+
!options.dryRun &&
|
|
13737
|
+
liveFunction?.functionId &&
|
|
13738
|
+
unchangedVersionNeedsInputRecheck({ localAuthorize, activeVersion })) {
|
|
13739
|
+
const recheck = await recheckUnchangedFunctionVersion({
|
|
13740
|
+
client,
|
|
13741
|
+
appId: resolvedAppId,
|
|
13742
|
+
functionId: String(liveFunction.functionId),
|
|
13743
|
+
functionKey: key,
|
|
13744
|
+
push,
|
|
13745
|
+
});
|
|
13746
|
+
if (recheck.kind === "refused") {
|
|
13747
|
+
applyFailures.push({ type: "function", key, message: recheck.message });
|
|
13748
|
+
markUnapplied();
|
|
13749
|
+
continue;
|
|
13750
|
+
}
|
|
13751
|
+
for (const line of recheck.warnings)
|
|
13752
|
+
warn(` ${line}`);
|
|
13753
|
+
recheckedCreated = recheck.created;
|
|
13754
|
+
if (!recheckedCreated)
|
|
13755
|
+
info(` Function ${key}: code unchanged (no new version)`);
|
|
13756
|
+
}
|
|
13757
|
+
if (headerAction === "skip" && codeUnchanged && !recheckedCreated) {
|
|
13378
13758
|
skippedCount++;
|
|
13379
13759
|
if (syncState && liveFunction?.functionId) {
|
|
13380
13760
|
if (!syncState.entities.functions)
|
|
@@ -13483,6 +13863,11 @@ What a push guarantees (two stages):
|
|
|
13483
13863
|
await warnIfDroppingDocumentSchema(String(functionId), liveFunction?.activeConfigId
|
|
13484
13864
|
? String(liveFunction.activeConfigId)
|
|
13485
13865
|
: undefined);
|
|
13866
|
+
// #6118 — the server's lines about this version (a Turnstile
|
|
13867
|
+
// function whose app lacks its site key or secret). The push has
|
|
13868
|
+
// landed; they change neither the exit code nor the sync state.
|
|
13869
|
+
for (const line of functionVersionPushWarnings(pushedVersion))
|
|
13870
|
+
warn(` ${line}`);
|
|
13486
13871
|
if (pushedVersion?.created === false) {
|
|
13487
13872
|
info(` Function ${key}: code unchanged (no new version)`);
|
|
13488
13873
|
}
|
|
@@ -15359,6 +15744,10 @@ What a push guarantees (two stages):
|
|
|
15359
15744
|
excludeName,
|
|
15360
15745
|
nameOptional: diffsLocalEnvironment,
|
|
15361
15746
|
excludeProtection: diffsLocalEnvironment,
|
|
15747
|
+
// #6183 — the overrides push would leave out, and the app an
|
|
15748
|
+
// override may not name, exactly as push reads them.
|
|
15749
|
+
excludeBackendOverrides: appSettingsBackendOverridesExcludedForState(syncState, resolvedAppId, diffsLocalEnvironment).excluded,
|
|
15750
|
+
ownAppId: resolvedAppId,
|
|
15362
15751
|
});
|
|
15363
15752
|
if (appErrors.length > 0) {
|
|
15364
15753
|
appRow(VALIDATION_ERROR, appErrors.join("; "));
|
|
@@ -15380,7 +15769,7 @@ What a push guarantees (two stages):
|
|
|
15380
15769
|
else {
|
|
15381
15770
|
appRow("modified", `${fieldDiffs.length} field(s) differ: ` +
|
|
15382
15771
|
fieldDiffs
|
|
15383
|
-
.map((d) =>
|
|
15772
|
+
.map((d) => d.label)
|
|
15384
15773
|
.join(", ") +
|
|
15385
15774
|
" — `config diff --only app` shows the values");
|
|
15386
15775
|
}
|