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
package/dist/src/commands/db3.js
CHANGED
|
@@ -1,18 +1,40 @@
|
|
|
1
|
+
import { commandStatus } from "../lib/command-status.js";
|
|
1
2
|
import { ApiClient } from "../lib/api-client.js";
|
|
2
3
|
import { resolveAppId } from "../lib/config.js";
|
|
3
4
|
import { error, flushOutput, formatDate, formatTable, info, json, result as printResult, success } from "../lib/output.js";
|
|
4
5
|
import { confirmPrompt } from "../lib/confirm-prompt.js";
|
|
5
6
|
import { normalizeCliListEnvelope, wholeListEnvelope } from "../lib/paginate.js";
|
|
6
7
|
import { parseDataOption } from "../lib/data-input.js";
|
|
7
|
-
import {
|
|
8
|
+
import { parseFilterOptions } from "../lib/record-filter.js";
|
|
9
|
+
import { DB3_BATCH_OPERATION_CAP, DB3_ROUTES } from "../lib/records-verbs.js";
|
|
8
10
|
import { DB3_LOAD_ROUTES } from "../lib/load-routes.js";
|
|
9
11
|
import { declarationOfSchemaAnswer, declaredModelNames, exportDb3, loadDb3Rows, pendingRegistrations, planDb3Import, readDb3Manifest, readExportedBlobs, resolvedTypeName, } from "../lib/db3-export.js";
|
|
10
12
|
import fs from "fs";
|
|
11
13
|
import path from "path";
|
|
12
|
-
import { db3IndexRefusalLines, db3IndexTableRows } from "../lib/db3-index-output.js";
|
|
14
|
+
import { DB3_INDEX_KINDS, DB3_INDEX_PLACEMENTS, VECTOR_DISTANCES, VECTOR_INDEX_MODES, VECTOR_QUANTIZERS, db3IndexRefusalLines, db3IndexTableRows, listsVectorIndex, db3TextOptionsOf, vectorIndexOptions, } from "../lib/db3-index-output.js";
|
|
13
15
|
import { parseCustodianOrExit } from "../lib/custodian.js";
|
|
14
16
|
import { pageCursorOption, pageLimitOption, parsePageLimit, printEmptyPage, printPageHint } from "../lib/list-options.js";
|
|
15
|
-
import {
|
|
17
|
+
import { aggregateReadOf, aggregateRecordsAction, batchReadRecordsAction, batchRecordsAction, countRecordsAction, deleteRecordAction, describeAction, describeRecordsFailure, displayTags, inspectAction, modelsAction, patchRecordAction, queryReadOf, queryRecordsAction, saveRecordAction, schemaAction, statsAction, ingestAction, listIngestsAction, getIngestAction, abortIngestAction, listSnapshotsAction, getSnapshotAction, buildSnapshotAction, } from "./documents.js";
|
|
18
|
+
/**
|
|
19
|
+
* The `--data-file` help of `db3 records batch`: the db3 operation shapes,
|
|
20
|
+
* reads among them (#5243), the cap, and the command for a larger load.
|
|
21
|
+
*/
|
|
22
|
+
export const DB3_BATCH_DATA_FILE_HELP = "JSON file with { operations: [...] } or a bare operations array, " +
|
|
23
|
+
`at most ${DB3_BATCH_OPERATION_CAP} operations per call (atomic): all apply or none do, in order. ` +
|
|
24
|
+
"Each write is one of { model, action: create, data, id? } (the database assigns " +
|
|
25
|
+
"the id when none is given), { model, action: patch, id, data }, " +
|
|
26
|
+
"{ model, action: increment, id, fields } (each field's delta), " +
|
|
27
|
+
"{ model, action: delete, id } or { model, action: upsert, constraint, data, id? } " +
|
|
28
|
+
"(merged into the record holding that unique constraint's key, or created). " +
|
|
29
|
+
"Any write takes a condition, a query filter the record must match or the batch is refused. " +
|
|
30
|
+
"A read { model, action: query, filter?, sort?, limit?, cursor?, include? }, " +
|
|
31
|
+
"{ model, action: count, filter? } or { model, action: aggregate, options } is answered " +
|
|
32
|
+
"against the writes before it. For larger loads use `primitive db3 ingest`";
|
|
33
|
+
/** The `--data-file` help of `db3 records batch-read` (#5243): the read shapes and the cap. */
|
|
34
|
+
export const DB3_BATCH_READ_DATA_FILE_HELP = "JSON file with { operations: [...] } or a bare array of reads, " +
|
|
35
|
+
`at most ${DB3_BATCH_OPERATION_CAP} per call, all answered from one state of the db3. ` +
|
|
36
|
+
"Each read is { model, action: query, filter?, sort?, limit?, cursor?, include? }, " +
|
|
37
|
+
"{ model, action: count, filter? } or { model, action: aggregate, options }";
|
|
16
38
|
/**
|
|
17
39
|
* A refused index call: the server's sentence, its code and status, then one
|
|
18
40
|
* line per detail the code names (the duplicate keys, the origins keeping
|
|
@@ -29,6 +51,83 @@ function fail(err) {
|
|
|
29
51
|
error(describeRecordsFailure(err));
|
|
30
52
|
process.exit(1);
|
|
31
53
|
}
|
|
54
|
+
/** `--explain` on a records read verb (#5240). */
|
|
55
|
+
const EXPLAIN_FLAG = "Explain the read on the server instead of answering it: the indexes it used, what it scanned and the rows it read";
|
|
56
|
+
/** `--index` on a records read verb (#5240). */
|
|
57
|
+
const INDEX_FLAG = "Explain the read forced onto this index of the model, or 'none' to read with no index (implies --explain)";
|
|
58
|
+
/** Whether a records read verb was asked to explain: `--explain`, or `--index`, which implies it. */
|
|
59
|
+
const explaining = (options) => options.explain === true || options.index !== undefined;
|
|
60
|
+
/**
|
|
61
|
+
* A records read explained (#5240): sends `read` through `client`, with
|
|
62
|
+
* `--index` as its force, to `POST db3/:id/records/:model/explain` and prints the answer,
|
|
63
|
+
* or `--json` it. A refusal prints the server's sentence, code and status,
|
|
64
|
+
* and a force's reason.
|
|
65
|
+
*/
|
|
66
|
+
async function explainReadAction(client, appId, db3Id, modelName, options, read) {
|
|
67
|
+
try {
|
|
68
|
+
const answer = await client.explainDb3Read(appId, db3Id, modelName, {
|
|
69
|
+
...read,
|
|
70
|
+
...(options.index !== undefined ? { index: options.index } : {}),
|
|
71
|
+
});
|
|
72
|
+
if (options.json) {
|
|
73
|
+
json(answer);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
printExplain(answer);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
refuse(err);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** An explain's answer: the read and its force, what it used, scanned, read and answered, then each statement's plan. */
|
|
83
|
+
function printExplain(answer) {
|
|
84
|
+
const forced = answer.index === null ? "no" : answer.index === "none" ? "none (no index)" : answer.index;
|
|
85
|
+
printResult("Read", `${answer.op} ${answer.model}`);
|
|
86
|
+
printResult("Forced", forced);
|
|
87
|
+
printResult("Indexes", answer.indexes.length > 0 ? answer.indexes.join(", ") : "none");
|
|
88
|
+
printResult("Scanned", answer.scanned.length > 0 ? answer.scanned.join(", ") : "none");
|
|
89
|
+
printResult("Rows read", answer.cost?.rowsRead ?? "not reported");
|
|
90
|
+
printResult("Answered", answer.answered);
|
|
91
|
+
for (const statement of answer.statements) {
|
|
92
|
+
console.log("");
|
|
93
|
+
console.log(statement.runs > 1 ? `${statement.model} (${statement.runs} runs)` : statement.model);
|
|
94
|
+
if (statement.plan === null)
|
|
95
|
+
console.log(` (no plan: ${statement.planError ?? "refused"})`);
|
|
96
|
+
else
|
|
97
|
+
for (const line of statement.plan)
|
|
98
|
+
console.log(` ${line}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Print `message` and exit 1, before any request. */
|
|
102
|
+
function refuseList(message) {
|
|
103
|
+
error(message);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
/** The ways `db3 list --user-id` reads, in listing order. */
|
|
107
|
+
const DB3_VIAS = ["held", "shared", "app"];
|
|
108
|
+
/**
|
|
109
|
+
* The columns of `db3 list --user-id`, in order: each a field of the client's
|
|
110
|
+
* `Db3Row` or `Db3ListEntry` (`src/client/api/db3Api.ts`).
|
|
111
|
+
*/
|
|
112
|
+
export const USER_DB3_TABLE_FIELDS = ["id", "title", "via", "permission", "custodian", "sync", "type", "grantedAt"];
|
|
113
|
+
const USER_DB3_TABLE_HEADERS = {
|
|
114
|
+
id: "ID",
|
|
115
|
+
title: "TITLE",
|
|
116
|
+
via: "VIA",
|
|
117
|
+
permission: "PERMISSION",
|
|
118
|
+
custodian: "CUSTODIAN",
|
|
119
|
+
sync: "SYNC",
|
|
120
|
+
type: "TYPE",
|
|
121
|
+
grantedAt: "GRANTED",
|
|
122
|
+
};
|
|
123
|
+
/** `--via` as a list of ways, or exit 1 before any request when it names anything else. */
|
|
124
|
+
function parseVia(value) {
|
|
125
|
+
const ways = value.split(",");
|
|
126
|
+
if (!value || ways.some((way) => !DB3_VIAS.includes(way))) {
|
|
127
|
+
refuseList("--via lists some of held, shared and app, comma-separated.");
|
|
128
|
+
}
|
|
129
|
+
return ways;
|
|
130
|
+
}
|
|
32
131
|
/** `on` or `off` as a boolean, or exit 1 naming `label` before any request. */
|
|
33
132
|
function parseOnOff(value, label) {
|
|
34
133
|
if (value === "on")
|
|
@@ -60,6 +159,7 @@ export function registerDb3Commands(program) {
|
|
|
60
159
|
const db3 = program
|
|
61
160
|
.command("db3")
|
|
62
161
|
.description("Work with db3s: create, read, list and delete them, their sync, app access and custody, indexes, records, schema and room");
|
|
162
|
+
commandStatus(db3, { stability: "beta" });
|
|
63
163
|
// ---- Indexes ----
|
|
64
164
|
const indexes = db3.command("indexes").description("List, register and drop a db3's indexes");
|
|
65
165
|
indexes
|
|
@@ -87,6 +187,10 @@ export function registerDb3Commands(program) {
|
|
|
87
187
|
{ header: "FIELDS", key: "fields" },
|
|
88
188
|
{ header: "UNIQUE", key: "unique" },
|
|
89
189
|
{ header: "ORIGINS", key: "origins" },
|
|
190
|
+
{ header: "KIND", key: "kind" },
|
|
191
|
+
{ header: "ON", key: "on" },
|
|
192
|
+
// #5229 — a vector index's shared model; a list with no vector index prints as before.
|
|
193
|
+
...(listsVectorIndex(list) ? [{ header: "ANN MODEL", key: "annModel" }] : []),
|
|
90
194
|
]));
|
|
91
195
|
}
|
|
92
196
|
catch (err) {
|
|
@@ -101,31 +205,70 @@ export function registerDb3Commands(program) {
|
|
|
101
205
|
.requiredOption("--field <field>", "Field to index (repeat it for a composite unique index, which also needs --unique and --name)", (value, previous = []) => previous.concat(value))
|
|
102
206
|
.option("--unique", "Enforce that no two records share the key")
|
|
103
207
|
.option("--name <name>", "Name the index (idx_named_<model>_<name>)")
|
|
104
|
-
.option("--members", "Index a string-set field's members (idx_members_<model>_<field>) for $contains, any-of and facets; one --field, no --unique or --name")
|
|
208
|
+
.option("--members", "Index a string-set field's members (idx_members_<model>_<field>) for $contains, any-of and facets; one --field, no --unique or --name (the same as --kind members)")
|
|
209
|
+
.option("--kind <kind>", `What the index is: ${DB3_INDEX_KINDS.join(", ")} (default scalar, members with --members)`)
|
|
210
|
+
.option("--on <placement>", `Where the index lives: ${DB3_INDEX_PLACEMENTS.join(", ")} (default both, server for a member index, device for a vector index); change it by dropping and registering again`)
|
|
211
|
+
.option("--distance <distance>", `A vector index's distance: ${VECTOR_DISTANCES.join(", ")} (with --kind vector)`)
|
|
212
|
+
.option("--index <mode>", `A vector index's search: ${VECTOR_INDEX_MODES.join(", ")} (with --kind vector; default exact)`)
|
|
213
|
+
.option("--nbucket <n>", "An ann vector index's bucket count (with --index ann)")
|
|
214
|
+
.option("--codesize <n>", "An ann vector index's bytes per quantized vector (with --index ann)")
|
|
215
|
+
.option("--quantizer <quantizer>", `An ann vector index's quantizer: ${VECTOR_QUANTIZERS.join(", ")} (with --index ann)`)
|
|
216
|
+
.option("--tokenizer <tokenizer>", "A text index's tokenizer: unicode61 (the default, diacritics folded) or porter (English stems)")
|
|
217
|
+
.option("--prefix <lengths>", "A text index's prefix lengths to index, comma-separated (e.g. 2,3)")
|
|
218
|
+
.option("--weight <field=weight>", "A text index's weight for one of its fields (repeatable; 1 by default)", (value, previous = []) => previous.concat(value))
|
|
105
219
|
.option("--app <app-id>", "App ID")
|
|
106
220
|
.option("--json", "Output as JSON")
|
|
107
221
|
.action(async (db3Id, options) => {
|
|
108
222
|
const resolvedAppId = resolveAppId(undefined, options);
|
|
109
223
|
const fields = options.field;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
: options.name !== undefined
|
|
116
|
-
? "--members takes no --name: a member index is named idx_members_<model>_<field>"
|
|
117
|
-
: null;
|
|
118
|
-
if (conflict) {
|
|
119
|
-
error(conflict);
|
|
120
|
-
process.exit(1);
|
|
121
|
-
}
|
|
224
|
+
const kind = options.kind;
|
|
225
|
+
const vector = vectorIndexOptions(options, kind);
|
|
226
|
+
if ("problem" in vector) {
|
|
227
|
+
error(vector.problem);
|
|
228
|
+
process.exit(1);
|
|
122
229
|
}
|
|
230
|
+
const members = options.members === true || kind === "members";
|
|
231
|
+
const flag = options.members ? "--members" : "--kind members";
|
|
232
|
+
const textOptions = options.tokenizer !== undefined || options.prefix !== undefined || options.weight !== undefined;
|
|
233
|
+
const text = kind === "text" ? db3TextOptionsOf(options) : null;
|
|
234
|
+
const conflict = kind !== undefined && !DB3_INDEX_KINDS.includes(kind)
|
|
235
|
+
? `--kind must be one of ${DB3_INDEX_KINDS.join(", ")}`
|
|
236
|
+
: options.on !== undefined && !DB3_INDEX_PLACEMENTS.includes(options.on)
|
|
237
|
+
? `--on must be one of ${DB3_INDEX_PLACEMENTS.join(", ")}`
|
|
238
|
+
: options.members && kind !== undefined && kind !== "members"
|
|
239
|
+
? `--members is --kind members: give --kind ${kind} without --members, or --kind members`
|
|
240
|
+
: textOptions && kind !== "text"
|
|
241
|
+
? `--tokenizer, --prefix and --weight apply to --kind text`
|
|
242
|
+
: text && "refusal" in text
|
|
243
|
+
? text.refusal
|
|
244
|
+
: kind === "text" && options.unique
|
|
245
|
+
? `--kind text takes no --unique: a text index enforces nothing`
|
|
246
|
+
: kind === "text" && options.name !== undefined
|
|
247
|
+
? `--kind text takes no --name: a model's text index is named idx_text_<model>`
|
|
248
|
+
: !members
|
|
249
|
+
? null
|
|
250
|
+
: fields.length > 1
|
|
251
|
+
? `${flag} takes one --field: a member index covers one string-set field`
|
|
252
|
+
: options.unique
|
|
253
|
+
? `${flag} takes no --unique: a member index enforces nothing`
|
|
254
|
+
: options.name !== undefined
|
|
255
|
+
? `${flag} takes no --name: a member index is named idx_members_<model>_<field>`
|
|
256
|
+
: null;
|
|
257
|
+
if (conflict) {
|
|
258
|
+
error(conflict);
|
|
259
|
+
process.exit(1);
|
|
260
|
+
}
|
|
261
|
+
const textBody = text && "text" in text && Object.keys(text.text).length > 0 ? { text: text.text } : {};
|
|
123
262
|
const body = {
|
|
124
263
|
model: options.model,
|
|
125
264
|
...(fields.length === 1 ? { field: fields[0] } : { fields }),
|
|
126
265
|
...(options.unique ? { unique: true } : {}),
|
|
127
266
|
...(options.name !== undefined ? { name: options.name } : {}),
|
|
128
267
|
...(options.members ? { members: true } : {}),
|
|
268
|
+
...(kind !== undefined ? { kind: kind } : {}),
|
|
269
|
+
...(options.on !== undefined ? { on: options.on } : {}),
|
|
270
|
+
...(vector.options ? { vector: vector.options } : {}),
|
|
271
|
+
...textBody,
|
|
129
272
|
};
|
|
130
273
|
const client = new ApiClient();
|
|
131
274
|
try {
|
|
@@ -134,7 +277,7 @@ export function registerDb3Commands(program) {
|
|
|
134
277
|
json(index);
|
|
135
278
|
return;
|
|
136
279
|
}
|
|
137
|
-
success(`Registered ${index.name} on ${index.model} (${index.fields.join(", ")}${index.unique ? ", unique" : ""}${index.members ? ", members" : ""}).`);
|
|
280
|
+
success(`Registered ${index.name} on ${index.model} (${index.fields.join(", ")}${index.unique ? ", unique" : ""}${index.members ? ", members" : ""}${index.kind === "text" ? ", text" : ""}).`);
|
|
138
281
|
}
|
|
139
282
|
catch (err) {
|
|
140
283
|
refuse(err);
|
|
@@ -177,6 +320,80 @@ export function registerDb3Commands(program) {
|
|
|
177
320
|
refuse(err);
|
|
178
321
|
}
|
|
179
322
|
});
|
|
323
|
+
// ---- A vector index's shared ANN model (#5229) ----
|
|
324
|
+
const model = indexes.command("model").description("Fetch or delete an ann vector index's shared model");
|
|
325
|
+
model
|
|
326
|
+
.command("get")
|
|
327
|
+
.description("Write an ann vector index's shared model to a file, as a device uploaded it")
|
|
328
|
+
.argument("<db3-id>", "db3 ID")
|
|
329
|
+
.argument("<name>", "Vector index name, as `db3 indexes list` prints it")
|
|
330
|
+
.option("--out <file>", "Where to write the model (default <name>-<generation>-<revision>.pvm1)")
|
|
331
|
+
.option("--app <app-id>", "App ID")
|
|
332
|
+
.option("--json", "Output as JSON")
|
|
333
|
+
.action(async (db3Id, name, options) => {
|
|
334
|
+
const resolvedAppId = resolveAppId(undefined, options);
|
|
335
|
+
const client = new ApiClient();
|
|
336
|
+
try {
|
|
337
|
+
const fetched = await client.fetchDb3IndexModel(resolvedAppId, db3Id, name);
|
|
338
|
+
const out = path.resolve(options.out ?? `${name}-${fetched.generation}-${fetched.revision}.pvm1`);
|
|
339
|
+
fs.writeFileSync(out, fetched.data);
|
|
340
|
+
const summary = {
|
|
341
|
+
name,
|
|
342
|
+
file: out,
|
|
343
|
+
bytes: fetched.data.byteLength,
|
|
344
|
+
generation: fetched.generation,
|
|
345
|
+
revision: fetched.revision,
|
|
346
|
+
rows: fetched.rows,
|
|
347
|
+
trainedAt: fetched.trainedAt,
|
|
348
|
+
format: fetched.format,
|
|
349
|
+
};
|
|
350
|
+
if (options.json) {
|
|
351
|
+
json(summary);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
success(`Wrote ${name}'s model (revision ${fetched.revision}, ${fetched.rows} rows, trained ${fetched.trainedAt}) to ${out}: ${fetched.data.byteLength} bytes.`);
|
|
355
|
+
}
|
|
356
|
+
catch (err) {
|
|
357
|
+
refuse(err);
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
model
|
|
361
|
+
.command("delete")
|
|
362
|
+
.description("Delete an ann vector index's shared model so a device trains it again (the db3's owner)")
|
|
363
|
+
.argument("<db3-id>", "db3 ID")
|
|
364
|
+
.argument("<name>", "Vector index name, as `db3 indexes list` prints it")
|
|
365
|
+
.option("--app <app-id>", "App ID")
|
|
366
|
+
.option("-y, --yes", "Skip confirmation prompt")
|
|
367
|
+
.option("--json", "Output as JSON")
|
|
368
|
+
.action(async (db3Id, name, options) => {
|
|
369
|
+
const resolvedAppId = resolveAppId(undefined, options);
|
|
370
|
+
if (!options.yes) {
|
|
371
|
+
let confirmed;
|
|
372
|
+
try {
|
|
373
|
+
confirmed = await confirmPrompt(`Delete ${name}'s shared model on db3 ${db3Id}? Every device answers exactly until one trains it again.`);
|
|
374
|
+
}
|
|
375
|
+
catch (err) {
|
|
376
|
+
error(err.message);
|
|
377
|
+
process.exit(1);
|
|
378
|
+
}
|
|
379
|
+
if (!confirmed) {
|
|
380
|
+
info("Cancelled.");
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const client = new ApiClient();
|
|
385
|
+
try {
|
|
386
|
+
const answer = await client.deleteDb3IndexModel(resolvedAppId, db3Id, name);
|
|
387
|
+
if (options.json) {
|
|
388
|
+
json(answer);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
success(`Deleted ${answer.name}'s model; its revision is now ${answer.revision}.`);
|
|
392
|
+
}
|
|
393
|
+
catch (err) {
|
|
394
|
+
refuse(err);
|
|
395
|
+
}
|
|
396
|
+
});
|
|
180
397
|
// ---- Records: the `documents records` verbs' twins ----
|
|
181
398
|
const records = db3.command("records").description("Query and write a db3's records");
|
|
182
399
|
records
|
|
@@ -191,9 +408,26 @@ export function registerDb3Commands(program) {
|
|
|
191
408
|
.option("--limit <n>", "Records per page (default 100, max 10000)")
|
|
192
409
|
.option("--cursor <cursor>", "Pagination cursor from a previous query (valid only with the same --sort)")
|
|
193
410
|
.option("--include <json>", "Related records as a JSON array of include specs, e.g. '[{\"model\":\"customer\",\"type\":\"refersTo\",\"sourceField\":\"customerId\"}]'; answered as _related")
|
|
411
|
+
.option("--explain", EXPLAIN_FLAG)
|
|
412
|
+
.option("--index <name>", INDEX_FLAG)
|
|
194
413
|
.option("--json", "Output as JSON")
|
|
195
414
|
.action(async (db3Id, modelName, options) => {
|
|
196
415
|
const resolvedAppId = resolveAppId(undefined, options);
|
|
416
|
+
if (explaining(options)) {
|
|
417
|
+
const { filter, sort, include } = queryReadOf(options);
|
|
418
|
+
const limit = options.limit === undefined ? undefined : /^\d+$/.test(options.limit) ? Number(options.limit) : options.limit;
|
|
419
|
+
await explainReadAction(new ApiClient(), resolvedAppId, db3Id, modelName, options, {
|
|
420
|
+
op: "query",
|
|
421
|
+
...(filter ? { filter } : {}),
|
|
422
|
+
options: {
|
|
423
|
+
...(sort !== undefined ? { sort } : {}),
|
|
424
|
+
...(limit !== undefined ? { limit } : {}),
|
|
425
|
+
...(options.cursor !== undefined ? { cursor: options.cursor } : {}),
|
|
426
|
+
...(include !== undefined ? { include } : {}),
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
197
431
|
await queryRecordsAction(DB3_ROUTES, resolvedAppId, db3Id, modelName, options);
|
|
198
432
|
});
|
|
199
433
|
records
|
|
@@ -204,9 +438,16 @@ export function registerDb3Commands(program) {
|
|
|
204
438
|
.option("--app <app-id>", "App ID")
|
|
205
439
|
.option("--filter <json>", "Filter as JSON (e.g. '{\"status\":\"open\"}')")
|
|
206
440
|
.option("--filter-file <path>", "Read filter from a JSON or TOML file")
|
|
441
|
+
.option("--explain", EXPLAIN_FLAG)
|
|
442
|
+
.option("--index <name>", INDEX_FLAG)
|
|
207
443
|
.option("--json", "Output as JSON")
|
|
208
444
|
.action(async (db3Id, modelName, options) => {
|
|
209
445
|
const resolvedAppId = resolveAppId(undefined, options);
|
|
446
|
+
if (explaining(options)) {
|
|
447
|
+
const filter = parseFilterOptions(options);
|
|
448
|
+
await explainReadAction(new ApiClient(), resolvedAppId, db3Id, modelName, options, { op: "count", ...(filter ? { filter } : {}) });
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
210
451
|
await countRecordsAction(DB3_ROUTES, resolvedAppId, db3Id, modelName, options);
|
|
211
452
|
});
|
|
212
453
|
records
|
|
@@ -220,9 +461,19 @@ export function registerDb3Commands(program) {
|
|
|
220
461
|
.option("--group-by <field>", "Group results by this field (repeatable)", (value, previous = []) => previous.concat(value), [])
|
|
221
462
|
.option("--filter <json>", "Filter as JSON")
|
|
222
463
|
.option("--filter-file <path>", "Read filter from a JSON or TOML file")
|
|
464
|
+
.option("--explain", EXPLAIN_FLAG)
|
|
465
|
+
.option("--index <name>", INDEX_FLAG)
|
|
223
466
|
.option("--json", "Output as JSON")
|
|
224
467
|
.action(async (db3Id, modelName, options) => {
|
|
225
468
|
const resolvedAppId = resolveAppId(undefined, options);
|
|
469
|
+
if (explaining(options)) {
|
|
470
|
+
const { operations, groupBy, filter } = aggregateReadOf(options);
|
|
471
|
+
await explainReadAction(new ApiClient(), resolvedAppId, db3Id, modelName, options, {
|
|
472
|
+
op: "aggregate",
|
|
473
|
+
aggregate: { operations, groupBy, ...(filter ? { filter } : {}) },
|
|
474
|
+
});
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
226
477
|
await aggregateRecordsAction(DB3_ROUTES, resolvedAppId, db3Id, modelName, options);
|
|
227
478
|
});
|
|
228
479
|
records
|
|
@@ -270,15 +521,29 @@ export function registerDb3Commands(program) {
|
|
|
270
521
|
await deleteRecordAction(DB3_ROUTES, resolvedAppId, db3Id, modelName, recordId, options);
|
|
271
522
|
});
|
|
272
523
|
records
|
|
273
|
-
.command("
|
|
274
|
-
.description(
|
|
524
|
+
.command("batch")
|
|
525
|
+
.description(`Apply create/patch/increment/delete/upsert operations to a db3, with reads among them, at most ${DB3_BATCH_OPERATION_CAP} ` +
|
|
526
|
+
"operations per call (atomic); use `primitive db3 ingest` for larger loads")
|
|
275
527
|
.argument("<db3-id>", "db3 ID")
|
|
276
|
-
.requiredOption("--data-file <file>",
|
|
528
|
+
.requiredOption("--data-file <file>", DB3_BATCH_DATA_FILE_HELP)
|
|
277
529
|
.option("--app <app-id>", "App ID")
|
|
278
530
|
.option("-y, --yes", "Skip confirmation prompt")
|
|
279
531
|
.option("--json", "Output as JSON")
|
|
280
532
|
.action(async (db3Id, options) => {
|
|
281
|
-
await
|
|
533
|
+
await batchRecordsAction(DB3_ROUTES, db3Id, options);
|
|
534
|
+
});
|
|
535
|
+
records
|
|
536
|
+
.command("batch-read")
|
|
537
|
+
.description(`Run several queries, counts and aggregates on a db3 in one request, at most ${DB3_BATCH_OPERATION_CAP} ` +
|
|
538
|
+
"per call, answered from one state of the db3")
|
|
539
|
+
.argument("<db3-id>", "db3 ID")
|
|
540
|
+
.requiredOption("--data-file <file>", DB3_BATCH_READ_DATA_FILE_HELP)
|
|
541
|
+
.option("--partial", "Answer a refused read in its place instead of refusing the request")
|
|
542
|
+
.option("--app <app-id>", "App ID")
|
|
543
|
+
.option("--json", "Output as JSON")
|
|
544
|
+
.action(async (db3Id, options) => {
|
|
545
|
+
const client = new ApiClient();
|
|
546
|
+
await batchReadRecordsAction(client, db3Id, options);
|
|
282
547
|
});
|
|
283
548
|
records
|
|
284
549
|
.command("models")
|
|
@@ -631,14 +896,68 @@ Custody:
|
|
|
631
896
|
});
|
|
632
897
|
db3
|
|
633
898
|
.command("list")
|
|
634
|
-
.description("List one custodian's db3s, oldest first")
|
|
635
|
-
.
|
|
899
|
+
.description("List one custodian's db3s, oldest first, or every db3 a user reaches: held, shared with them, then app access")
|
|
900
|
+
.option("--custodian <custodian>", '"app" or "user:<user-id>"')
|
|
901
|
+
.option("--user-id <user-id>", "List every db3 this user reaches, one row per way, sync-off db3s included")
|
|
902
|
+
.option("--via <ways>", "With --user-id: some of held, shared and app, comma-separated")
|
|
636
903
|
.option("--app <app-id>", "App ID")
|
|
637
904
|
.addOption(pageLimitOption())
|
|
638
905
|
.addOption(pageCursorOption())
|
|
639
906
|
.option("--json", "Output as JSON")
|
|
640
907
|
.allowExcessArguments(false)
|
|
641
908
|
.action(async (options) => {
|
|
909
|
+
if ((options.custodian === undefined) === (options.userId === undefined)) {
|
|
910
|
+
refuseList("db3 list takes exactly one of --custodian and --user-id.");
|
|
911
|
+
}
|
|
912
|
+
if (options.userId === undefined) {
|
|
913
|
+
if (options.via !== undefined)
|
|
914
|
+
refuseList("--via is valid only with --user-id.");
|
|
915
|
+
return listByCustodian(options);
|
|
916
|
+
}
|
|
917
|
+
const userId = options.userId;
|
|
918
|
+
if (!userId.trim() || userId.startsWith("user:"))
|
|
919
|
+
refuseList("--user-id needs a bare user id.");
|
|
920
|
+
const via = options.via === undefined ? undefined : parseVia(options.via);
|
|
921
|
+
const limit = parsePageLimit(options.limit);
|
|
922
|
+
const resolvedAppId = resolveAppId(undefined, options);
|
|
923
|
+
try {
|
|
924
|
+
const page = normalizeCliListEnvelope(await new ApiClient().listDb3ForUser(resolvedAppId, userId, {
|
|
925
|
+
...(via ? { via } : {}),
|
|
926
|
+
...(limit !== undefined ? { limit } : {}),
|
|
927
|
+
...(options.cursor ? { cursor: options.cursor } : {}),
|
|
928
|
+
}));
|
|
929
|
+
if (options.json) {
|
|
930
|
+
json(page);
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
if (page.items.length === 0) {
|
|
934
|
+
printEmptyPage(page, "db3s");
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
const rows = page.items.map((row) => ({
|
|
938
|
+
id: row.id,
|
|
939
|
+
title: row.title ?? "",
|
|
940
|
+
via: row.via,
|
|
941
|
+
permission: row.permission ?? "none",
|
|
942
|
+
custodian: row.custodian ?? "none",
|
|
943
|
+
sync: row.sync === false ? "off" : "on",
|
|
944
|
+
type: row.type ?? "none",
|
|
945
|
+
grantedAt: row.grantedAt,
|
|
946
|
+
}));
|
|
947
|
+
console.log(formatTable(rows, USER_DB3_TABLE_FIELDS.map((key) => ({
|
|
948
|
+
header: USER_DB3_TABLE_HEADERS[key],
|
|
949
|
+
key,
|
|
950
|
+
...(key === "title" ? { flex: true } : {}),
|
|
951
|
+
...(key === "grantedAt" ? { format: (value) => (value ? formatDate(value) : "—") } : {}),
|
|
952
|
+
}))));
|
|
953
|
+
printPageHint(page);
|
|
954
|
+
}
|
|
955
|
+
catch (err) {
|
|
956
|
+
fail(err);
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
/** `db3 list --custodian`: one custodian's db3s from the admin API (#4800). */
|
|
960
|
+
async function listByCustodian(options) {
|
|
642
961
|
const limit = parsePageLimit(options.limit);
|
|
643
962
|
const custodian = parseCustodianOrExit(options.custodian, "--custodian");
|
|
644
963
|
const resolvedAppId = resolveAppId(undefined, options);
|
|
@@ -676,7 +995,7 @@ Custody:
|
|
|
676
995
|
catch (err) {
|
|
677
996
|
fail(err);
|
|
678
997
|
}
|
|
679
|
-
}
|
|
998
|
+
}
|
|
680
999
|
db3
|
|
681
1000
|
.command("delete")
|
|
682
1001
|
.description("Delete a db3 and all its data (records, blobs, aliases, permissions)")
|