primitive-admin 1.2.0-alpha.14 → 1.2.0-alpha.15
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 +102 -78
- package/assets/skill/skills/primitive-platform/SKILL.md +87 -23
- package/dist/bin/primitive.js +11 -82
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/admins.js +79 -17
- package/dist/src/commands/admins.js.map +1 -1
- package/dist/src/commands/agent-sessions.js +2 -0
- package/dist/src/commands/agent-sessions.js.map +1 -1
- package/dist/src/commands/analytics.js +183 -12
- package/dist/src/commands/analytics.js.map +1 -1
- package/dist/src/commands/apps-children.js +2 -0
- package/dist/src/commands/apps-children.js.map +1 -1
- package/dist/src/commands/apps.js +19 -2
- package/dist/src/commands/apps.js.map +1 -1
- package/dist/src/commands/auth.js +11 -1
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/collections.js +13 -0
- package/dist/src/commands/collections.js.map +1 -1
- package/dist/src/commands/config.d.ts +1 -1
- package/dist/src/commands/config.js +40 -9
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/connections.js +2 -0
- package/dist/src/commands/connections.js.map +1 -1
- package/dist/src/commands/database-type-configs.js +5 -3
- package/dist/src/commands/database-type-configs.js.map +1 -1
- package/dist/src/commands/databases.js +6 -4
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/db3-types.js +2 -0
- package/dist/src/commands/db3-types.js.map +1 -1
- package/dist/src/commands/db3.d.ts +12 -0
- package/dist/src/commands/db3.js +343 -24
- package/dist/src/commands/db3.js.map +1 -1
- package/dist/src/commands/documents.d.ts +52 -12
- package/dist/src/commands/documents.js +120 -29
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/email-templates.js +72 -0
- package/dist/src/commands/email-templates.js.map +1 -1
- package/dist/src/commands/functions.js +47 -10
- package/dist/src/commands/functions.js.map +1 -1
- package/dist/src/commands/groups.js +18 -3
- package/dist/src/commands/groups.js.map +1 -1
- package/dist/src/commands/init.js +7 -1
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/integrations.js +80 -47
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/metadata-category-configs.js +2 -0
- package/dist/src/commands/metadata-category-configs.js.map +1 -1
- package/dist/src/commands/metadata.js +41 -0
- package/dist/src/commands/metadata.js.map +1 -1
- package/dist/src/commands/prompts.js +73 -47
- package/dist/src/commands/prompts.js.map +1 -1
- package/dist/src/commands/rule-sets.js +2 -0
- package/dist/src/commands/rule-sets.js.map +1 -1
- package/dist/src/commands/schemas.d.ts +15 -0
- package/dist/src/commands/schemas.js +122 -0
- package/dist/src/commands/schemas.js.map +1 -0
- package/dist/src/commands/secrets.js +45 -3
- package/dist/src/commands/secrets.js.map +1 -1
- package/dist/src/commands/sessions.js +2 -0
- package/dist/src/commands/sessions.js.map +1 -1
- package/dist/src/commands/sync-schemas.d.ts +202 -0
- package/dist/src/commands/sync-schemas.js +629 -0
- package/dist/src/commands/sync-schemas.js.map +1 -0
- package/dist/src/commands/sync-user-properties.d.ts +118 -0
- package/dist/src/commands/sync-user-properties.js +276 -0
- package/dist/src/commands/sync-user-properties.js.map +1 -0
- package/dist/src/commands/sync.d.ts +243 -12
- package/dist/src/commands/sync.js +1474 -314
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/user-properties.d.ts +14 -0
- package/dist/src/commands/user-properties.js +79 -0
- package/dist/src/commands/user-properties.js.map +1 -0
- package/dist/src/commands/users.js +879 -16
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/commands/waitlist.js +39 -4
- package/dist/src/commands/waitlist.js.map +1 -1
- package/dist/src/lib/analytics-query.d.ts +58 -0
- package/dist/src/lib/analytics-query.js +134 -0
- package/dist/src/lib/analytics-query.js.map +1 -0
- package/dist/src/lib/api-client.d.ts +748 -95
- package/dist/src/lib/api-client.js +356 -158
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/block-selector.d.ts +9 -15
- package/dist/src/lib/block-selector.js +9 -20
- package/dist/src/lib/block-selector.js.map +1 -1
- package/dist/src/lib/cli-manifest.d.ts +8 -0
- package/dist/src/lib/cli-manifest.js +10 -1
- package/dist/src/lib/cli-manifest.js.map +1 -1
- package/dist/src/lib/cli-version.d.ts +14 -0
- package/dist/src/lib/cli-version.js +38 -0
- package/dist/src/lib/cli-version.js.map +1 -0
- package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
- package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
- package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
- package/dist/src/lib/command-status.d.ts +110 -0
- package/dist/src/lib/command-status.js +184 -0
- package/dist/src/lib/command-status.js.map +1 -0
- package/dist/src/lib/config-object-descriptor.d.ts +6 -0
- package/dist/src/lib/config-object-descriptor.js +71 -0
- package/dist/src/lib/config-object-descriptor.js.map +1 -1
- package/dist/src/lib/config-toml.d.ts +11 -2
- package/dist/src/lib/config-toml.js +25 -2
- package/dist/src/lib/config-toml.js.map +1 -1
- package/dist/src/lib/data-input.d.ts +1 -1
- package/dist/src/lib/data-input.js +1 -1
- package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
- package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTypeIR.d.ts +11 -1
- package/dist/src/lib/db-codegen/dbTypeIR.js +11 -5
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
- package/dist/src/lib/db-type-records.d.ts +95 -0
- package/dist/src/lib/db-type-records.js +219 -0
- package/dist/src/lib/db-type-records.js.map +1 -0
- package/dist/src/lib/db3-export.d.ts +51 -14
- package/dist/src/lib/db3-export.js +135 -27
- package/dist/src/lib/db3-export.js.map +1 -1
- package/dist/src/lib/db3-index-output.d.ts +68 -3
- package/dist/src/lib/db3-index-output.js +139 -3
- package/dist/src/lib/db3-index-output.js.map +1 -1
- package/dist/src/lib/db3-type-models.d.ts +39 -7
- package/dist/src/lib/db3-type-models.js +138 -27
- package/dist/src/lib/db3-type-models.js.map +1 -1
- package/dist/src/lib/deprecation.d.ts +2 -2
- package/dist/src/lib/deprecation.js +2 -2
- package/dist/src/lib/experimental-apis.d.ts +36 -0
- package/dist/src/lib/experimental-apis.js +46 -0
- package/dist/src/lib/experimental-apis.js.map +1 -0
- package/dist/src/lib/file-attachment.d.ts +24 -0
- package/dist/src/lib/file-attachment.js +31 -0
- package/dist/src/lib/file-attachment.js.map +1 -0
- package/dist/src/lib/function-authorize-check.d.ts +1 -1
- package/dist/src/lib/function-authorize-check.js +2 -1
- package/dist/src/lib/function-authorize-check.js.map +1 -1
- package/dist/src/lib/function-authorize-view.js +4 -0
- package/dist/src/lib/function-authorize-view.js.map +1 -1
- package/dist/src/lib/function-bundle.d.ts +27 -5
- package/dist/src/lib/function-bundle.js +106 -7
- package/dist/src/lib/function-bundle.js.map +1 -1
- package/dist/src/lib/function-collect.d.ts +2 -0
- package/dist/src/lib/function-collect.js +36 -7
- package/dist/src/lib/function-collect.js.map +1 -1
- package/dist/src/lib/function-db-types.d.ts +57 -40
- package/dist/src/lib/function-db-types.js +246 -285
- package/dist/src/lib/function-db-types.js.map +1 -1
- package/dist/src/lib/function-document-types.d.ts +19 -7
- package/dist/src/lib/function-document-types.js +24 -12
- package/dist/src/lib/function-document-types.js.map +1 -1
- package/dist/src/lib/function-run.d.ts +1 -1
- package/dist/src/lib/function-run.js +1 -1
- package/dist/src/lib/function-run.js.map +1 -1
- package/dist/src/lib/function-schema-codegen.d.ts +58 -18
- package/dist/src/lib/function-schema-codegen.js +85 -74
- package/dist/src/lib/function-schema-codegen.js.map +1 -1
- package/dist/src/lib/function-schema-refs.d.ts +98 -0
- package/dist/src/lib/function-schema-refs.js +177 -0
- package/dist/src/lib/function-schema-refs.js.map +1 -0
- package/dist/src/lib/function-sync.d.ts +38 -4
- package/dist/src/lib/function-sync.js +83 -14
- package/dist/src/lib/function-sync.js.map +1 -1
- package/dist/src/lib/function-typecheck.d.ts +52 -0
- package/dist/src/lib/function-typecheck.js +171 -54
- package/dist/src/lib/function-typecheck.js.map +1 -1
- package/dist/src/lib/generated-build-flags.d.ts +13 -0
- package/dist/src/lib/generated-build-flags.js +14 -0
- package/dist/src/lib/generated-build-flags.js.map +1 -0
- package/dist/src/lib/generated-config-surfaces.d.ts +211 -11
- package/dist/src/lib/generated-config-surfaces.js +579 -69
- 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/integration-test-request.d.ts +54 -0
- package/dist/src/lib/integration-test-request.js +207 -0
- package/dist/src/lib/integration-test-request.js.map +1 -0
- package/dist/src/lib/metadata-report.d.ts +85 -0
- package/dist/src/lib/metadata-report.js +81 -0
- package/dist/src/lib/metadata-report.js.map +1 -0
- package/dist/src/lib/output.d.ts +1 -1
- package/dist/src/lib/output.js +1 -1
- package/dist/src/lib/platform-owned.js +5 -0
- package/dist/src/lib/platform-owned.js.map +1 -1
- package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
- package/dist/src/lib/primitive-declaration-names.js +22 -0
- package/dist/src/lib/primitive-declaration-names.js.map +1 -0
- package/dist/src/lib/primitive-declaration.d.ts +143 -0
- package/dist/src/lib/primitive-declaration.js +658 -0
- package/dist/src/lib/primitive-declaration.js.map +1 -0
- package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
- package/dist/src/lib/prompt-schema-codegen.js +82 -98
- package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
- package/dist/src/lib/prompt-schema-document.d.ts +35 -0
- package/dist/src/lib/prompt-schema-document.js +92 -0
- package/dist/src/lib/prompt-schema-document.js.map +1 -0
- package/dist/src/lib/prompt-schema-refs.d.ts +164 -0
- package/dist/src/lib/prompt-schema-refs.js +452 -0
- package/dist/src/lib/prompt-schema-refs.js.map +1 -0
- package/dist/src/lib/records-verbs.d.ts +12 -2
- package/dist/src/lib/records-verbs.js +7 -2
- package/dist/src/lib/records-verbs.js.map +1 -1
- package/dist/src/lib/register-commands.d.ts +28 -0
- package/dist/src/lib/register-commands.js +101 -0
- package/dist/src/lib/register-commands.js.map +1 -0
- package/dist/src/lib/retired-imports.d.ts +53 -0
- package/dist/src/lib/retired-imports.js +120 -0
- package/dist/src/lib/retired-imports.js.map +1 -0
- package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
- package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
- package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
- package/dist/src/lib/schema-codegen/generated-db3-bridge.js +221 -0
- package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
- package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
- package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +209 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.js +379 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
- package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
- package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
- package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
- package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +129 -0
- package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +154 -1
- package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -1
- package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
- package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
- package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
- package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
- package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
- package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
- package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
- package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
- package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
- package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
- package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
- package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
- package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
- package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
- package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
- package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaToTs.d.ts +40 -13
- package/dist/src/lib/schema-codegen/schemaToTs.js +124 -160
- package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -1
- package/dist/src/lib/schema-codegen/valuesLists.d.ts +35 -0
- package/dist/src/lib/schema-codegen/valuesLists.js +128 -0
- package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
- package/dist/src/lib/schema-family-index.d.ts +228 -0
- package/dist/src/lib/schema-family-index.js +813 -0
- package/dist/src/lib/schema-family-index.js.map +1 -0
- package/dist/src/lib/schema-pins.d.ts +82 -0
- package/dist/src/lib/schema-pins.js +198 -0
- package/dist/src/lib/schema-pins.js.map +1 -0
- package/dist/src/lib/schema-preview.d.ts +244 -0
- package/dist/src/lib/schema-preview.js +498 -0
- package/dist/src/lib/schema-preview.js.map +1 -0
- package/dist/src/lib/skill-installer.d.ts +2 -2
- package/dist/src/lib/skill-installer.js +2 -21
- package/dist/src/lib/skill-installer.js.map +1 -1
- package/dist/src/lib/step-run-table.d.ts +1 -2
- package/dist/src/lib/step-run-table.js +1 -2
- package/dist/src/lib/step-run-table.js.map +1 -1
- package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
- package/dist/src/lib/swift-codegen/agentGenerator.js +24 -22
- package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
- package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
- package/dist/src/lib/swift-codegen/banners.js +12 -0
- package/dist/src/lib/swift-codegen/banners.js.map +1 -1
- package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
- package/dist/src/lib/swift-codegen/functionGenerator.js +167 -50
- package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
- package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +31 -7
- package/dist/src/lib/swift-codegen/schemaToSwift.js +213 -177
- package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
- package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js +120 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
- package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
- package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
- package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
- package/dist/src/lib/sync-resource-types.d.ts +37 -5
- package/dist/src/lib/sync-resource-types.js +53 -5
- package/dist/src/lib/sync-resource-types.js.map +1 -1
- package/dist/src/lib/sync-selectors.d.ts +7 -0
- package/dist/src/lib/sync-selectors.js +22 -2
- package/dist/src/lib/sync-selectors.js.map +1 -1
- package/dist/src/lib/test-runs.d.ts +45 -0
- package/dist/src/lib/test-runs.js +150 -0
- package/dist/src/lib/test-runs.js.map +1 -0
- package/dist/src/lib/toml-database-config.d.ts +2 -1
- package/dist/src/lib/toml-database-config.js +4 -3
- package/dist/src/lib/toml-database-config.js.map +1 -1
- package/dist/src/lib/toml-scalar-edit.js +6 -4
- package/dist/src/lib/toml-scalar-edit.js.map +1 -1
- package/dist/src/lib/user-index.d.ts +80 -0
- package/dist/src/lib/user-index.js +166 -0
- package/dist/src/lib/user-index.js.map +1 -0
- package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
- package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
- package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
- package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
- package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
- package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
- package/dist/src/lib/user-walk.d.ts +31 -0
- package/dist/src/lib/user-walk.js +102 -0
- package/dist/src/lib/user-walk.js.map +1 -0
- package/dist/src/lib/worker-perf-format.d.ts +22 -0
- package/dist/src/lib/worker-perf-format.js +27 -0
- package/dist/src/lib/worker-perf-format.js.map +1 -0
- package/dist/src/types/index.d.ts +13 -34
- package/package.json +5 -3
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `schemas/<file>.toml` in `config push`, `pull` and `diff` (#5532, project
|
|
3
|
+
* `unified-schemas` phase 3).
|
|
4
|
+
*
|
|
5
|
+
* A `schemas/` file holds shared shapes, one `[defs.<Name>]` table each. It is
|
|
6
|
+
* read and compiled with the server's own module (the vendored
|
|
7
|
+
* `generated-schema-file.ts`), so the preflight refuses exactly what the push
|
|
8
|
+
* route would, and a push sends the compile beside the source for the server
|
|
9
|
+
* to recompile and compare. Each push of a changed file is a new immutable
|
|
10
|
+
* version; an identical file is skipped, a file changed only on the server is
|
|
11
|
+
* declined (`config pull` takes it, `--force` overwrites it), and one changed
|
|
12
|
+
* on both sides is a conflict. A selection carries the `schemas/` files its
|
|
13
|
+
* refs reach, in any spelling, pushed dependencies first.
|
|
14
|
+
*
|
|
15
|
+
* #5533 — a file's defs may ref another file's defs; the tree's family index
|
|
16
|
+
* (`loadSchemaFamilyIndex`) compiles the files in dependency order and
|
|
17
|
+
* refuses a cycle of files. A push carries each def's provenance, and a file
|
|
18
|
+
* whose source is unchanged is pushed again when its compile changed because
|
|
19
|
+
* a file it refs did.
|
|
20
|
+
*/
|
|
21
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync } from "fs";
|
|
22
|
+
import { join } from "path";
|
|
23
|
+
import { createHash } from "crypto";
|
|
24
|
+
import { parseConfigToml } from "../lib/config-toml.js";
|
|
25
|
+
import { schemaFileProvenanceOf } from "../lib/schema-codegen/generated-schema-file.js";
|
|
26
|
+
import { schemaFamilyRefsIn } from "../lib/schema-codegen/generated-schema-refs.js";
|
|
27
|
+
import { canonicalJsonEquals } from "../lib/schema-codegen/generated-schema-provenance.js";
|
|
28
|
+
import { loadPromptFamilyIndex, loadSchemaFamilyIndex, overrideTreeDb3Types, remoteDb3Entry, rememberRemoteDb3Types, rememberRemoteSchemaFiles, } from "../lib/schema-family-index.js";
|
|
29
|
+
import { promptSchemaDocumentOf, promptSchemaLocations } from "../lib/prompt-schema-document.js";
|
|
30
|
+
import { createSchemaPinJudge, schemaFileReader, schemaPinHint } from "../lib/schema-pins.js";
|
|
31
|
+
import { schemaFilePreview } from "../lib/schema-preview.js";
|
|
32
|
+
import { previewNamesOf } from "../lib/primitive-declaration.js";
|
|
33
|
+
import { writePulledFile } from "../lib/pull-write.js";
|
|
34
|
+
import { filterFilesBySelection, selectionIncludesKey } from "../lib/sync-selectors.js";
|
|
35
|
+
import { info, warn } from "../lib/output.js";
|
|
36
|
+
/** The directory of the shared shapes in a tree. */
|
|
37
|
+
export const SCHEMAS_DIR = "schemas";
|
|
38
|
+
/** The type label push, pull and diff report a file under. */
|
|
39
|
+
export const SCHEMA_LABEL = "schema";
|
|
40
|
+
/** The `.toml` files of `dir` in a tree, by name; none when the directory is absent. */
|
|
41
|
+
function tomlFilesIn(configDir, dir) {
|
|
42
|
+
const path = join(configDir, dir);
|
|
43
|
+
if (!existsSync(path))
|
|
44
|
+
return [];
|
|
45
|
+
return readdirSync(path)
|
|
46
|
+
.filter((name) => name.endsWith(".toml"))
|
|
47
|
+
.sort();
|
|
48
|
+
}
|
|
49
|
+
/** A tree file's parsed TOML, or null when it does not parse (the preflight reports it). */
|
|
50
|
+
function parsedOrNull(path) {
|
|
51
|
+
try {
|
|
52
|
+
return parseConfigToml(readFileSync(path, "utf-8"));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* `document` with every string that holds a JSON object read as that object,
|
|
60
|
+
* the way the push reads a schema written as a JSON string (a function's
|
|
61
|
+
* `inputSchema`, a prompt's `outputSchema` or `agent`), so its refs are seen.
|
|
62
|
+
*/
|
|
63
|
+
function withJsonStringsDecoded(document) {
|
|
64
|
+
if (typeof document === "string") {
|
|
65
|
+
if (!document.trimStart().startsWith("{"))
|
|
66
|
+
return document;
|
|
67
|
+
try {
|
|
68
|
+
const parsed = JSON.parse(document);
|
|
69
|
+
return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? withJsonStringsDecoded(parsed) : document;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return document;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(document))
|
|
76
|
+
return document.map(withJsonStringsDecoded);
|
|
77
|
+
if (document === null || typeof document !== "object")
|
|
78
|
+
return document;
|
|
79
|
+
const out = {};
|
|
80
|
+
for (const [key, value] of Object.entries(document)) {
|
|
81
|
+
Object.defineProperty(out, key, { value: withJsonStringsDecoded(value), enumerable: true, writable: true, configurable: true });
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The `schemas/` files a push of `selection` must carry: every file a ref to a
|
|
87
|
+
* shared def reaches (`schemas:<file>#/$defs/<Name>`, `ref = "schemas.<file>.<Name>"`,
|
|
88
|
+
* or a short form the tree resolves) from the selected functions, prompts
|
|
89
|
+
* (agent tables included) and `schemas/` files, and the files those reach in
|
|
90
|
+
* turn, to a fixpoint. A ref to a file the tree does not have is listed under
|
|
91
|
+
* `missing`. With no selection, every file is a start.
|
|
92
|
+
*/
|
|
93
|
+
export function schemaDependenciesOf(configDir, selection) {
|
|
94
|
+
const index = loadSchemaFamilyIndex(configDir);
|
|
95
|
+
const queue = [];
|
|
96
|
+
const files = new Set();
|
|
97
|
+
for (const dir of ["functions", "prompts"]) {
|
|
98
|
+
const label = dir === "functions" ? "function" : "prompt";
|
|
99
|
+
for (const name of filterFilesBySelection(selection, label, join(configDir, dir), tomlFilesIn(configDir, dir))) {
|
|
100
|
+
queue.push({ from: `${dir}/${name}`, document: withJsonStringsDecoded(parsedOrNull(join(configDir, dir, name))) });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (const name of tomlFilesIn(configDir, SCHEMAS_DIR)) {
|
|
104
|
+
const file = name.slice(0, -".toml".length);
|
|
105
|
+
if (!selectionIncludesKey(selection, SCHEMA_LABEL, file))
|
|
106
|
+
continue;
|
|
107
|
+
files.add(file);
|
|
108
|
+
queue.push({ from: `${SCHEMAS_DIR}/${name}`, document: parsedOrNull(join(configDir, SCHEMAS_DIR, name)) });
|
|
109
|
+
}
|
|
110
|
+
const missing = [];
|
|
111
|
+
const reported = new Set();
|
|
112
|
+
while (queue.length > 0) {
|
|
113
|
+
const { from, document } = queue.shift();
|
|
114
|
+
for (const { ref, file } of schemaFamilyRefsIn(document, index).edges) {
|
|
115
|
+
if (files.has(file))
|
|
116
|
+
continue;
|
|
117
|
+
const path = join(configDir, SCHEMAS_DIR, `${file}.toml`);
|
|
118
|
+
if (!existsSync(path)) {
|
|
119
|
+
const key = `${from}\u0000${ref}`;
|
|
120
|
+
if (!reported.has(key)) {
|
|
121
|
+
reported.add(key);
|
|
122
|
+
missing.push({ from, ref, file });
|
|
123
|
+
}
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
files.add(file);
|
|
127
|
+
queue.push({ from: `${SCHEMAS_DIR}/${file}.toml`, document: parsedOrNull(path) });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return { files: [...files].sort(), missing };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* `files` in the order a push stores them: a file after the files its refs
|
|
134
|
+
* name (any spelling), so a dependency in the same push is stored first. The
|
|
135
|
+
* files of a cycle go in name order (the preflight refuses a cycle).
|
|
136
|
+
*/
|
|
137
|
+
export function schemaPushOrder(configDir, files) {
|
|
138
|
+
const members = new Set(files);
|
|
139
|
+
const names = [...members].sort();
|
|
140
|
+
const locals = new Map(loadSchemaFamilyIndex(configDir).locals.map((local) => [local.file, local]));
|
|
141
|
+
const edges = new Map();
|
|
142
|
+
for (const file of names) {
|
|
143
|
+
const targets = new Set((locals.get(file)?.edges ?? []).map((edge) => edge.file).filter((target) => members.has(target) && target !== file));
|
|
144
|
+
edges.set(file, [...targets].sort());
|
|
145
|
+
}
|
|
146
|
+
// Tarjan's strongly connected components, which come out dependencies first.
|
|
147
|
+
const order = [];
|
|
148
|
+
const index = new Map();
|
|
149
|
+
const low = new Map();
|
|
150
|
+
const onStack = new Set();
|
|
151
|
+
const stack = [];
|
|
152
|
+
let next = 0;
|
|
153
|
+
for (const root of names) {
|
|
154
|
+
if (index.has(root))
|
|
155
|
+
continue;
|
|
156
|
+
const frames = [{ file: root, edge: 0 }];
|
|
157
|
+
index.set(root, next);
|
|
158
|
+
low.set(root, next++);
|
|
159
|
+
stack.push(root);
|
|
160
|
+
onStack.add(root);
|
|
161
|
+
while (frames.length > 0) {
|
|
162
|
+
const frame = frames[frames.length - 1];
|
|
163
|
+
const targets = edges.get(frame.file);
|
|
164
|
+
if (frame.edge < targets.length) {
|
|
165
|
+
const target = targets[frame.edge++];
|
|
166
|
+
if (!index.has(target)) {
|
|
167
|
+
index.set(target, next);
|
|
168
|
+
low.set(target, next++);
|
|
169
|
+
stack.push(target);
|
|
170
|
+
onStack.add(target);
|
|
171
|
+
frames.push({ file: target, edge: 0 });
|
|
172
|
+
}
|
|
173
|
+
else if (onStack.has(target)) {
|
|
174
|
+
low.set(frame.file, Math.min(low.get(frame.file), index.get(target)));
|
|
175
|
+
}
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
frames.pop();
|
|
179
|
+
if (frames.length > 0) {
|
|
180
|
+
const parent = frames[frames.length - 1].file;
|
|
181
|
+
low.set(parent, Math.min(low.get(parent), low.get(frame.file)));
|
|
182
|
+
}
|
|
183
|
+
if (low.get(frame.file) === index.get(frame.file)) {
|
|
184
|
+
const component = [];
|
|
185
|
+
let member;
|
|
186
|
+
do {
|
|
187
|
+
member = stack.pop();
|
|
188
|
+
onStack.delete(member);
|
|
189
|
+
component.push(member);
|
|
190
|
+
} while (member !== frame.file);
|
|
191
|
+
order.push(...component.sort());
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return order;
|
|
196
|
+
}
|
|
197
|
+
const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
198
|
+
/**
|
|
199
|
+
* Read and check every `schemas/*.toml` of a tree, by name: each compiled
|
|
200
|
+
* against the files it refs (#5533), with a file's own error, a refused cycle
|
|
201
|
+
* of files, or a dependency's error that its refs meet.
|
|
202
|
+
*/
|
|
203
|
+
/**
|
|
204
|
+
* The db3 types a push applies (#5540), each with its tree file: every type
|
|
205
|
+
* of the tree the push selects whose stored row would bridge differently, or
|
|
206
|
+
* that the server does not hold. `serverRows` is the server's listing by
|
|
207
|
+
* name; without it (the listing is unavailable) every selected type counts.
|
|
208
|
+
* A type the push leaves as stored changes no compile, so the files that ref
|
|
209
|
+
* it keep their place.
|
|
210
|
+
*/
|
|
211
|
+
export function appliedDb3Types(configDir, selection, serverRows) {
|
|
212
|
+
const selected = new Set([
|
|
213
|
+
...filterFilesBySelection(selection, "db3-type", join(configDir, "db3-types"), tomlFilesIn(configDir, "db3-types")).map((name) => `db3-types/${name}`),
|
|
214
|
+
...filterFilesBySelection(selection, "database-type-config", join(configDir, "database-type-configs"), tomlFilesIn(configDir, "database-type-configs")).map((name) => `database-type-configs/${name}`),
|
|
215
|
+
]);
|
|
216
|
+
const applied = new Map();
|
|
217
|
+
for (const type of [...loadSchemaFamilyIndex(configDir).db3Locals].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))) {
|
|
218
|
+
if (!selected.has(type.relative))
|
|
219
|
+
continue;
|
|
220
|
+
const row = serverRows ? serverRows.get(type.name) : undefined;
|
|
221
|
+
if (serverRows && row && JSON.stringify(remoteDb3Entry(row)) === JSON.stringify(type.entry))
|
|
222
|
+
continue;
|
|
223
|
+
applied.set(type.name, type.relative);
|
|
224
|
+
}
|
|
225
|
+
return applied;
|
|
226
|
+
}
|
|
227
|
+
/** The schemas a function file declares, JSON-string spellings parsed. */
|
|
228
|
+
function functionFileSchemas(document) {
|
|
229
|
+
return ["inputSchema", "outputSchema"].map((field) => {
|
|
230
|
+
const value = document?.function?.[field];
|
|
231
|
+
if (typeof value !== "string")
|
|
232
|
+
return value;
|
|
233
|
+
try {
|
|
234
|
+
return JSON.parse(value);
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Before a push compiles (#5540): when a function, prompt or `schemas/` file
|
|
243
|
+
* of the tree writes a db3 ref (or a `<key>.<part>` short form, which a
|
|
244
|
+
* server type could answer), read the server's db3 types once and tell the
|
|
245
|
+
* tree's index, so a type the tree lacks resolves against its stored row and
|
|
246
|
+
* its name counts for the short forms. Under `--only`, the files the push
|
|
247
|
+
* carries compile against the server's row for a type of the tree it does not
|
|
248
|
+
* select, as the server will. Reads nothing for a tree with no such ref.
|
|
249
|
+
* Answers one error per such type the server does not hold either.
|
|
250
|
+
*/
|
|
251
|
+
export async function prepareDb3SchemaRefs(input) {
|
|
252
|
+
const { configDir, selection } = input;
|
|
253
|
+
const read = (dir, name) => parsedOrNull(join(configDir, dir, name));
|
|
254
|
+
const documents = [
|
|
255
|
+
...tomlFilesIn(configDir, "functions").flatMap((name) => functionFileSchemas(read("functions", name))),
|
|
256
|
+
...tomlFilesIn(configDir, SCHEMAS_DIR).map((name) => read(SCHEMAS_DIR, name)),
|
|
257
|
+
...tomlFilesIn(configDir, "prompts").flatMap((name) => {
|
|
258
|
+
const parsed = read("prompts", name);
|
|
259
|
+
return parsed ? promptSchemaLocations(promptSchemaDocumentOf(parsed)).map((location) => location.document) : [];
|
|
260
|
+
}),
|
|
261
|
+
];
|
|
262
|
+
const wanted = documents.some((document) => {
|
|
263
|
+
const scan = schemaFamilyRefsIn(document);
|
|
264
|
+
return scan.db3.length > 0 || scan.shortKeys.length > 0;
|
|
265
|
+
});
|
|
266
|
+
if (!wanted)
|
|
267
|
+
return [];
|
|
268
|
+
let rows;
|
|
269
|
+
try {
|
|
270
|
+
const listed = await input.client.listDatabaseTypeConfigs();
|
|
271
|
+
rows = Array.isArray(listed) ? listed : [];
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return []; // The compile reports a type it cannot find.
|
|
275
|
+
}
|
|
276
|
+
rememberRemoteDb3Types(configDir, rows.filter((row) => row?.databaseType));
|
|
277
|
+
overrideTreeDb3Types(configDir, []);
|
|
278
|
+
if (!selection)
|
|
279
|
+
return [];
|
|
280
|
+
// The types the files this push carries name: the selected functions, prompts and schemas/ files, and the files they reach.
|
|
281
|
+
const index = loadPromptFamilyIndex(configDir);
|
|
282
|
+
const carried = new Set(schemaDependenciesOf(configDir, selection).files);
|
|
283
|
+
const named = new Set();
|
|
284
|
+
for (const local of index.locals)
|
|
285
|
+
if (carried.has(local.file))
|
|
286
|
+
for (const edge of local.db3Edges)
|
|
287
|
+
named.add(edge.type);
|
|
288
|
+
const selectedPrompts = new Set(filterFilesBySelection(selection, "prompt", join(configDir, "prompts"), tomlFilesIn(configDir, "prompts")));
|
|
289
|
+
for (const local of index.promptLocals)
|
|
290
|
+
if (selectedPrompts.has(local.file))
|
|
291
|
+
for (const edge of local.db3Edges)
|
|
292
|
+
named.add(edge.type);
|
|
293
|
+
for (const name of filterFilesBySelection(selection, "function", join(configDir, "functions"), tomlFilesIn(configDir, "functions"))) {
|
|
294
|
+
for (const schema of functionFileSchemas(read("functions", name)))
|
|
295
|
+
for (const edge of schemaFamilyRefsIn(schema, index).db3)
|
|
296
|
+
named.add(edge.type);
|
|
297
|
+
}
|
|
298
|
+
const selectedTypes = new Set(appliedDb3Types(configDir, selection, null).keys());
|
|
299
|
+
const byName = new Map(rows.filter((row) => row?.databaseType).map((row) => [String(row.databaseType), row]));
|
|
300
|
+
const overrides = [];
|
|
301
|
+
const errors = [];
|
|
302
|
+
for (const type of index.db3Locals) {
|
|
303
|
+
if (!named.has(type.name) || selectedTypes.has(type.name))
|
|
304
|
+
continue;
|
|
305
|
+
const row = byName.get(type.name);
|
|
306
|
+
if (row) {
|
|
307
|
+
overrides.push(row);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
const label = type.relative.startsWith("db3-types/") ? "db3-type" : "database-type-config";
|
|
311
|
+
errors.push(`${type.relative}: the selected files ref db3 type ${type.name}, which this push does not select and the server does not have. ` +
|
|
312
|
+
`Add ${label}/${type.name} to --only, or push it first.`);
|
|
313
|
+
}
|
|
314
|
+
overrideTreeDb3Types(configDir, overrides);
|
|
315
|
+
return errors;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* `config push`'s two schemas legs (#5540): a file whose closure (through
|
|
319
|
+
* the other `files`) reaches a db3 type in `applied` goes after the db3 legs,
|
|
320
|
+
* so the type is stored before the server compiles the file; every other
|
|
321
|
+
* file keeps its place before every family. Each leg is in dependency order;
|
|
322
|
+
* `reasons` names, for each deferred file, the type files it waits for.
|
|
323
|
+
*/
|
|
324
|
+
export function partitionSchemaFilesForPush(configDir, files, applied) {
|
|
325
|
+
const members = new Set(files);
|
|
326
|
+
const locals = new Map(loadSchemaFamilyIndex(configDir).locals.map((local) => [local.file, local]));
|
|
327
|
+
const reasons = new Map();
|
|
328
|
+
for (const file of files) {
|
|
329
|
+
const reached = new Set([file]);
|
|
330
|
+
const queue = [file];
|
|
331
|
+
const waits = new Set();
|
|
332
|
+
while (queue.length > 0) {
|
|
333
|
+
const at = locals.get(queue.shift());
|
|
334
|
+
for (const edge of at?.db3Edges ?? []) {
|
|
335
|
+
const typeFile = applied.get(edge.type);
|
|
336
|
+
if (typeFile)
|
|
337
|
+
waits.add(typeFile);
|
|
338
|
+
}
|
|
339
|
+
for (const edge of at?.edges ?? []) {
|
|
340
|
+
if (!members.has(edge.file) || reached.has(edge.file))
|
|
341
|
+
continue;
|
|
342
|
+
reached.add(edge.file);
|
|
343
|
+
queue.push(edge.file);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (waits.size > 0)
|
|
347
|
+
reasons.set(file, [...waits].sort());
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
first: schemaPushOrder(configDir, files.filter((file) => !reasons.has(file))),
|
|
351
|
+
afterDb3: schemaPushOrder(configDir, files.filter((file) => reasons.has(file))),
|
|
352
|
+
reasons,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
export function readLocalSchemaFiles(configDir) {
|
|
356
|
+
return loadSchemaFamilyIndex(configDir).locals;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* The preflight for `schemas/`: an error line for each selected file the push
|
|
360
|
+
* route would refuse. A function's, a prompt's (#5534) or a file's ref to a
|
|
361
|
+
* missing file is its own compile error (#5533), so nothing is left to warn
|
|
362
|
+
* about; `warnings` stays for callers that print them.
|
|
363
|
+
*/
|
|
364
|
+
export function collectSchemaPreflight(configDir, selection) {
|
|
365
|
+
const errors = readLocalSchemaFiles(configDir)
|
|
366
|
+
.filter((local) => local.error && selectionIncludesKey(selection, SCHEMA_LABEL, local.file))
|
|
367
|
+
.map((local) => ` ${local.relative}: ${local.error}`);
|
|
368
|
+
return { errors, warnings: [] };
|
|
369
|
+
}
|
|
370
|
+
/** A local file's compile as it is pushed: the compiled defs and each def's provenance. */
|
|
371
|
+
async function compiledPayloadOf(local) {
|
|
372
|
+
const compile = local.compile;
|
|
373
|
+
return { defs: compile.defs, provenance: await schemaFileProvenanceOf(compile) };
|
|
374
|
+
}
|
|
375
|
+
/** A file's state entry, from a version both sides now agree on. */
|
|
376
|
+
function entryFor(version, contentHash) {
|
|
377
|
+
return {
|
|
378
|
+
version: version.version,
|
|
379
|
+
modifiedAt: version.createdAt,
|
|
380
|
+
contentHash,
|
|
381
|
+
...(version.sourceHash ? { sourceHash: version.sourceHash } : {}),
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
const defCount = (n) => `${n} def${n === 1 ? "" : "s"}`;
|
|
385
|
+
/**
|
|
386
|
+
* `config push`'s schemas leg, which runs before every family that may
|
|
387
|
+
* reference a shape: each selected file pushed when it changed, in
|
|
388
|
+
* dependency order. A file is judged against the live current version and
|
|
389
|
+
* the recorded baseline: unchanged is skipped, a version moved on the server
|
|
390
|
+
* with the file unchanged since the baseline is declined (drift), and one
|
|
391
|
+
* moved with the file edited too is a conflict, unless `--force`. A push is
|
|
392
|
+
* pinned to the live version it was judged against.
|
|
393
|
+
*/
|
|
394
|
+
export async function pushSchemaFiles(ctx) {
|
|
395
|
+
const locals = new Map(readLocalSchemaFiles(ctx.configDir)
|
|
396
|
+
.filter((local) => selectionIncludesKey(ctx.selection, SCHEMA_LABEL, local.file) && !local.error && (!ctx.files || ctx.files.includes(local.file)))
|
|
397
|
+
.map((local) => [local.file, local]));
|
|
398
|
+
if (locals.size === 0)
|
|
399
|
+
return;
|
|
400
|
+
const baseline = ctx.syncState?.entities?.schemas ?? {};
|
|
401
|
+
let live = null;
|
|
402
|
+
try {
|
|
403
|
+
const listed = await ctx.client.listSchemaFiles(ctx.appId, { includeTombstoned: true });
|
|
404
|
+
live = new Map(listed.items.map((item) => [item.file, item]));
|
|
405
|
+
}
|
|
406
|
+
catch (err) {
|
|
407
|
+
warn(` schemas: live state unavailable (${err?.message ?? err}) — falling back to the last-sync content hashes`);
|
|
408
|
+
}
|
|
409
|
+
for (const file of schemaPushOrder(ctx.configDir, [...locals.keys()])) {
|
|
410
|
+
const local = locals.get(file);
|
|
411
|
+
const entry = baseline[file];
|
|
412
|
+
const current = live?.get(file) ?? null;
|
|
413
|
+
const liveSource = current && !current.tombstone ? current : null;
|
|
414
|
+
if (!live) {
|
|
415
|
+
if (entry?.contentHash && entry.contentHash === local.contentHash) {
|
|
416
|
+
ctx.skipped();
|
|
417
|
+
info(` Skipped schema ${file} (unchanged)`);
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
if (!ctx.force) {
|
|
421
|
+
ctx.fail(file, "live state could not be read and the file changed since the last sync, so push cannot tell which side moved. Nothing was written. Run `config pull`, or `config push --force`.");
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
const payload = await compiledPayloadOf(local);
|
|
426
|
+
// #5533 — the same source compiles differently once a file it refs moved:
|
|
427
|
+
// that is a new version (the server never re-pins a stored one), so a file
|
|
428
|
+
// whose compile records provenance (any ref inlined, local or to another
|
|
429
|
+
// file) is unchanged only when its stored compile is too. A version stored
|
|
430
|
+
// before provenance existed holds none, and a function importing its defs
|
|
431
|
+
// would never verify against it until it is pushed again.
|
|
432
|
+
if (liveSource && liveSource.sourceHash === local.sourceHash && (!recordsProvenance(payload) || (await storedCompileEquals(ctx, file, payload)))) {
|
|
433
|
+
ctx.skipped();
|
|
434
|
+
info(` Skipped schema ${file} (unchanged)`);
|
|
435
|
+
if (ctx.syncState && !ctx.dryRun) {
|
|
436
|
+
ctx.syncState.entities.schemas = { ...(ctx.syncState.entities.schemas ?? {}), [file]: entryFor(liveSource, local.contentHash) };
|
|
437
|
+
}
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
const recompiled = !!liveSource && liveSource.sourceHash === local.sourceHash;
|
|
441
|
+
if (live && current && !ctx.force && !ctx.isCrossAppPush && !recompiled) {
|
|
442
|
+
const remoteHash = current.sourceHash ?? "tombstone";
|
|
443
|
+
if (!entry) {
|
|
444
|
+
if (liveSource) {
|
|
445
|
+
ctx.conflict(file, "unknown-direction", local.sourceHash, remoteHash, current.createdAt, `schemas/${file}.toml is on the server at version ${current.version}, which this tree never pulled: run 'primitive config pull' and merge, or 'config push --force' to push over it`);
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
else if (current.version !== entry.version) {
|
|
450
|
+
if (local.contentHash === entry.contentHash) {
|
|
451
|
+
warn(` Declined schema ${file}: server drifted (version ${current.version}) — run 'primitive config pull' to take the server's version, or 'config push --force' to overwrite it.`);
|
|
452
|
+
ctx.drift(file, local.sourceHash, remoteHash);
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
ctx.conflict(file, "both-changed", local.sourceHash, remoteHash, current.createdAt, `schemas/${file}.toml changed on both sides (the server is at version ${current.version}): run 'primitive config pull' and merge, or 'config push --force' to overwrite the server's version`);
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
const compile = local.compile;
|
|
460
|
+
ctx.changes.push({ type: SCHEMA_LABEL, action: liveSource ? "update" : "create", key: file });
|
|
461
|
+
for (const warning of compile.warnings)
|
|
462
|
+
warn(` ${local.relative}: ${warning.message}`);
|
|
463
|
+
if (ctx.dryRun) {
|
|
464
|
+
info(` Would push schema ${file}`);
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
let answer;
|
|
468
|
+
try {
|
|
469
|
+
answer = await ctx.client.pushSchemaFile(ctx.appId, file, {
|
|
470
|
+
source: local.text,
|
|
471
|
+
compiled: payload,
|
|
472
|
+
...(ctx.force || !live ? {} : { expectedVersion: current?.version ?? 0 }),
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
catch (err) {
|
|
476
|
+
if (err?.statusCode === 409) {
|
|
477
|
+
const version = err?.details?.version;
|
|
478
|
+
ctx.conflict(file, "unknown-direction", local.sourceHash, "unknown", undefined, `schemas/${file}.toml changed on the server during the push${typeof version === "number" ? ` (now version ${version})` : ""}: run 'primitive config pull' and push again`);
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
ctx.fail(file, `schemas/${file}.toml was refused: ${err?.message ?? String(err)}`);
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
if (answer.outcome === "unchanged") {
|
|
485
|
+
ctx.skipped();
|
|
486
|
+
info(` Skipped schema ${file} (unchanged)`);
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
info(` ${liveSource ? "Updated" : "Created"} schema ${file} (version ${answer.version}, ${defCount(answer.defs.length)})`);
|
|
490
|
+
}
|
|
491
|
+
if (ctx.syncState) {
|
|
492
|
+
ctx.syncState.entities.schemas = { ...(ctx.syncState.entities.schemas ?? {}), [file]: entryFor(answer, local.contentHash) };
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
/** Does any def of a compile record an inlined ref? A ref-free file's stored compile cannot differ for the same source. */
|
|
497
|
+
function recordsProvenance(payload) {
|
|
498
|
+
return Object.values(payload.provenance).some((entries) => entries !== null && typeof entries === "object" && Object.keys(entries).length > 0);
|
|
499
|
+
}
|
|
500
|
+
/** Does the server's current version of `file` hold `payload` as its compile? A read that fails says no. */
|
|
501
|
+
async function storedCompileEquals(ctx, file, payload) {
|
|
502
|
+
try {
|
|
503
|
+
const stored = await ctx.client.getSchemaFile(ctx.appId, file);
|
|
504
|
+
return canonicalJsonEquals(stored.compiled ?? null, payload);
|
|
505
|
+
}
|
|
506
|
+
catch {
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* `config pull`'s schemas leg: every live file's source, the selected ones
|
|
512
|
+
* written to `schemas/<file>.toml` byte for byte. Answers the state entries
|
|
513
|
+
* of the files written and every live file's name, for the prune that
|
|
514
|
+
* removes a managed file the server tombstoned or no longer has.
|
|
515
|
+
*/
|
|
516
|
+
export async function pullSchemaFilesLeg(input) {
|
|
517
|
+
const answer = await input.client.pullSchemaFiles(input.appId);
|
|
518
|
+
const entities = {};
|
|
519
|
+
const chosen = answer.items.filter((item) => input.selected(item.file));
|
|
520
|
+
if (chosen.length > 0)
|
|
521
|
+
mkdirSync(join(input.configDir, SCHEMAS_DIR), { recursive: true });
|
|
522
|
+
for (const item of chosen) {
|
|
523
|
+
const path = join(input.configDir, SCHEMAS_DIR, `${item.file}.toml`);
|
|
524
|
+
if (writePulledFile(path, item.source, input.tally))
|
|
525
|
+
info(` Wrote ${SCHEMAS_DIR}/${item.file}.toml`);
|
|
526
|
+
// An own property, so a file named `__proto__` keeps its entry.
|
|
527
|
+
Object.defineProperty(entities, item.file, {
|
|
528
|
+
value: entryFor(item, sha256(readFileSync(path))),
|
|
529
|
+
enumerable: true,
|
|
530
|
+
writable: true,
|
|
531
|
+
configurable: true,
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
return { entities, serverKeys: answer.items.map((item) => item.file) };
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Whether `config diff` reads a local file's stored current version: when the
|
|
538
|
+
* file refs other files (#5533) or db3 models (#5543), whose current state its
|
|
539
|
+
* pins are judged against, or when its source differs (the stored version may
|
|
540
|
+
* ref what the local one no longer does). An unchanged file with no such refs
|
|
541
|
+
* reads nothing.
|
|
542
|
+
*/
|
|
543
|
+
export function schemaFileReadsPins(local, remote) {
|
|
544
|
+
return local.edges.length > 0 || local.db3Edges.length > 0 || remote.sourceHash !== local.sourceHash;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* `config diff`'s rows for `schemas/`: each local file against the live
|
|
548
|
+
* current version (by source hash, classified by which side moved since the
|
|
549
|
+
* last sync), and each live file with no local file.
|
|
550
|
+
*/
|
|
551
|
+
export async function diffSchemaRows(input) {
|
|
552
|
+
const listed = await input.client.listSchemaFiles(input.appId, { includeTombstoned: true });
|
|
553
|
+
// A file the tree lacks but the server tombstoned reads as deleted in a dependant's compile.
|
|
554
|
+
rememberRemoteSchemaFiles(input.configDir, listed.items);
|
|
555
|
+
const locals = readLocalSchemaFiles(input.configDir);
|
|
556
|
+
const live = new Map(listed.items.filter((item) => !item.tombstone).map((item) => [item.file, item]));
|
|
557
|
+
const judge = input.pins ?? createSchemaPinJudge(schemaFileReader(input.client, input.appId));
|
|
558
|
+
// #5544 — each def's declaration named and referenced as primitive.d.ts has it.
|
|
559
|
+
const previewNames = previewNamesOf(input.configDir);
|
|
560
|
+
const baseline = input.syncState?.entities?.schemas ?? {};
|
|
561
|
+
const rows = [];
|
|
562
|
+
/** `file`'s stored current version and its pins; neither when the read fails. */
|
|
563
|
+
const stored = async (file) => {
|
|
564
|
+
try {
|
|
565
|
+
const version = await input.client.getSchemaFile(input.appId, file);
|
|
566
|
+
return { version, pins: await judge(version.compiled?.provenance ?? null) };
|
|
567
|
+
}
|
|
568
|
+
catch {
|
|
569
|
+
return { version: null, pins: [] };
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
/** #5543 — each def against the stored version's, when the compile is one the push takes. */
|
|
573
|
+
const previews = (local, version) => {
|
|
574
|
+
if (!local.compile || !local.compile.ok)
|
|
575
|
+
return {};
|
|
576
|
+
const compile = local.compile;
|
|
577
|
+
// An unchanged file that refs no other file or db3 model compiles as its
|
|
578
|
+
// stored version did, so its own compile stands for the stored one.
|
|
579
|
+
const stored = version === "unchanged" ? { compiled: { defs: compile.defs } } : version;
|
|
580
|
+
const schemas = schemaFilePreview({ local: compile, stored, file: local.file, names: previewNames });
|
|
581
|
+
return schemas.length > 0 ? { schemas } : {};
|
|
582
|
+
};
|
|
583
|
+
for (const local of locals) {
|
|
584
|
+
if (local.error) {
|
|
585
|
+
rows.push({ key: local.file, status: input.statuses.invalid, hint: local.error });
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
const remote = live.get(local.file);
|
|
589
|
+
if (!remote) {
|
|
590
|
+
rows.push({ key: local.file, status: input.statuses.localOnly(local.file), ...previews(local, null) });
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
// #5533 — the defs the stored version inlined from other files (and,
|
|
594
|
+
// #5543, db3 models), judged against them now.
|
|
595
|
+
const readsPins = schemaFileReadsPins(local, remote);
|
|
596
|
+
const read = readsPins ? await stored(local.file) : null;
|
|
597
|
+
const pins = read?.pins ?? [];
|
|
598
|
+
const pinHint = schemaPinHint(pins);
|
|
599
|
+
const defs = read?.version ? previews(local, read.version) : readsPins ? {} : previews(local, "unchanged");
|
|
600
|
+
if (remote.sourceHash === local.sourceHash) {
|
|
601
|
+
rows.push({
|
|
602
|
+
key: local.file,
|
|
603
|
+
status: pinHint ? input.statuses.modified : input.statuses.synced,
|
|
604
|
+
...(pinHint ? { hint: pinHint } : {}),
|
|
605
|
+
...(readsPins ? { pins } : {}),
|
|
606
|
+
...defs,
|
|
607
|
+
});
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
610
|
+
const entry = baseline[local.file];
|
|
611
|
+
const hint = entry && remote.version === entry.version
|
|
612
|
+
? "local edited"
|
|
613
|
+
: entry && local.contentHash === entry.contentHash
|
|
614
|
+
? "server drifted"
|
|
615
|
+
: "both changed";
|
|
616
|
+
rows.push({ key: local.file, status: input.statuses.modified, hint: pinHint ? `${hint}; ${pinHint}` : hint, pins, ...defs });
|
|
617
|
+
}
|
|
618
|
+
const localNames = new Set(locals.map((local) => local.file));
|
|
619
|
+
for (const file of live.keys()) {
|
|
620
|
+
if (localNames.has(file))
|
|
621
|
+
continue;
|
|
622
|
+
// A file only the server holds lists its pins too, as a remote-only function does.
|
|
623
|
+
const { pins } = await stored(file);
|
|
624
|
+
const pinHint = schemaPinHint(pins);
|
|
625
|
+
rows.push({ key: file, status: input.statuses.remoteOnly(file), ...(pinHint ? { hint: pinHint } : {}), pins });
|
|
626
|
+
}
|
|
627
|
+
return rows;
|
|
628
|
+
}
|
|
629
|
+
//# sourceMappingURL=sync-schemas.js.map
|