primitive-admin 1.1.0-alpha.4 → 1.1.0-alpha.41
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 +325 -31
- package/assets/skill/skills/primitive-platform/SKILL.md +281 -0
- package/dist/bin/primitive.d.ts +2 -0
- package/dist/bin/primitive.js +268 -16
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/admins.d.ts +2 -0
- package/dist/src/commands/admins.js +123 -18
- package/dist/src/commands/admins.js.map +1 -1
- package/dist/src/commands/analytics.d.ts +2 -0
- package/dist/src/commands/analytics.js +464 -55
- package/dist/src/commands/analytics.js.map +1 -1
- package/dist/src/commands/apps.d.ts +2 -0
- package/dist/src/commands/apps.js +55 -13
- package/dist/src/commands/apps.js.map +1 -1
- package/dist/src/commands/auth.d.ts +2 -0
- package/dist/src/commands/auth.js +177 -7
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/blob-buckets.d.ts +2 -0
- package/dist/src/commands/blob-buckets.js +422 -0
- package/dist/src/commands/blob-buckets.js.map +1 -0
- package/dist/src/commands/catalog.d.ts +2 -0
- package/dist/src/commands/catalog.js +34 -35
- package/dist/src/commands/catalog.js.map +1 -1
- package/dist/src/commands/collection-type-configs.d.ts +2 -0
- package/dist/src/commands/collection-type-configs.js +178 -0
- package/dist/src/commands/collection-type-configs.js.map +1 -0
- package/dist/src/commands/collections.d.ts +2 -0
- package/dist/src/commands/collections.js +515 -0
- package/dist/src/commands/collections.js.map +1 -0
- package/dist/src/commands/comparisons.d.ts +2 -0
- package/dist/src/commands/comparisons.js +6 -6
- package/dist/src/commands/comparisons.js.map +1 -1
- package/dist/src/commands/cron-triggers.d.ts +2 -0
- package/dist/src/commands/cron-triggers.js +357 -0
- package/dist/src/commands/cron-triggers.js.map +1 -0
- package/dist/src/commands/database-types.d.ts +2 -0
- package/dist/src/commands/database-types.js +471 -0
- package/dist/src/commands/database-types.js.map +1 -0
- package/dist/src/commands/databases.d.ts +2 -0
- package/dist/src/commands/databases.js +1462 -83
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/documents.d.ts +2 -0
- package/dist/src/commands/documents.js +518 -11
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/email-templates.d.ts +2 -0
- package/dist/src/commands/email-templates.js +281 -0
- package/dist/src/commands/email-templates.js.map +1 -0
- package/dist/src/commands/env.d.ts +12 -0
- package/dist/src/commands/env.js +260 -0
- package/dist/src/commands/env.js.map +1 -0
- package/dist/src/commands/group-type-configs.d.ts +2 -0
- package/dist/src/commands/group-type-configs.js +181 -0
- package/dist/src/commands/group-type-configs.js.map +1 -0
- package/dist/src/commands/groups.d.ts +2 -0
- package/dist/src/commands/groups.js +48 -45
- package/dist/src/commands/groups.js.map +1 -1
- package/dist/src/commands/guides.d.ts +159 -0
- package/dist/src/commands/guides.js +449 -35
- package/dist/src/commands/guides.js.map +1 -1
- package/dist/src/commands/init.d.ts +17 -0
- package/dist/src/commands/init.js +811 -201
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/integrations.d.ts +2 -0
- package/dist/src/commands/integrations.js +533 -46
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/llm.d.ts +2 -0
- package/dist/src/commands/llm.js +4 -2
- package/dist/src/commands/llm.js.map +1 -1
- package/dist/src/commands/metadata.d.ts +2 -0
- package/dist/src/commands/metadata.js +194 -0
- package/dist/src/commands/metadata.js.map +1 -0
- package/dist/src/commands/prompts.d.ts +2 -0
- package/dist/src/commands/prompts.js +50 -52
- package/dist/src/commands/prompts.js.map +1 -1
- package/dist/src/commands/rule-sets.d.ts +3 -0
- package/dist/src/commands/rule-sets.js +388 -0
- package/dist/src/commands/rule-sets.js.map +1 -0
- package/dist/src/commands/scripts.d.ts +2 -0
- package/dist/src/commands/scripts.js +667 -0
- package/dist/src/commands/scripts.js.map +1 -0
- package/dist/src/commands/secrets.d.ts +2 -0
- package/dist/src/commands/secrets.js +108 -0
- package/dist/src/commands/secrets.js.map +1 -0
- package/dist/src/commands/skill.d.ts +2 -0
- package/dist/src/commands/skill.js +29 -0
- package/dist/src/commands/skill.js.map +1 -0
- package/dist/src/commands/sync.d.ts +175 -0
- package/dist/src/commands/sync.js +4412 -233
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/tokens.d.ts +2 -0
- package/dist/src/commands/tokens.js +122 -19
- package/dist/src/commands/tokens.js.map +1 -1
- package/dist/src/commands/users.d.ts +2 -0
- package/dist/src/commands/users.js +440 -22
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/commands/waitlist.d.ts +2 -0
- package/dist/src/commands/waitlist.js +10 -10
- package/dist/src/commands/waitlist.js.map +1 -1
- package/dist/src/commands/webhooks.d.ts +2 -0
- package/dist/src/commands/webhooks.js +391 -0
- package/dist/src/commands/webhooks.js.map +1 -0
- package/dist/src/commands/workflows.d.ts +49 -0
- package/dist/src/commands/workflows.js +1009 -123
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/api-client.d.ts +1283 -0
- package/dist/src/lib/api-client.js +1129 -83
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/auth-flow.d.ts +8 -0
- package/dist/src/lib/block-layout.d.ts +160 -0
- package/dist/src/lib/block-layout.js +451 -0
- package/dist/src/lib/block-layout.js.map +1 -0
- package/dist/src/lib/cli-manifest.d.ts +60 -0
- package/dist/src/lib/cli-manifest.js +70 -0
- package/dist/src/lib/cli-manifest.js.map +1 -0
- package/dist/src/lib/config.d.ts +53 -0
- package/dist/src/lib/config.js +92 -53
- package/dist/src/lib/config.js.map +1 -1
- package/dist/src/lib/confirm-prompt.d.ts +83 -0
- package/dist/src/lib/confirm-prompt.js +110 -0
- package/dist/src/lib/confirm-prompt.js.map +1 -0
- package/dist/src/lib/constants.d.ts +2 -0
- package/dist/src/lib/constants.js +3 -0
- package/dist/src/lib/constants.js.map +1 -0
- package/dist/src/lib/crash-handlers.d.ts +20 -0
- package/dist/src/lib/crash-handlers.js +49 -0
- package/dist/src/lib/crash-handlers.js.map +1 -0
- package/dist/src/lib/credentials-store.d.ts +79 -0
- package/dist/src/lib/credentials-store.js +307 -0
- package/dist/src/lib/credentials-store.js.map +1 -0
- package/dist/src/lib/csv.d.ts +48 -0
- package/dist/src/lib/csv.js +177 -0
- package/dist/src/lib/csv.js.map +1 -0
- package/dist/src/lib/db-codegen/dbFingerprint.d.ts +10 -0
- package/dist/src/lib/db-codegen/dbFingerprint.js +17 -0
- package/dist/src/lib/db-codegen/dbFingerprint.js.map +1 -0
- package/dist/src/lib/db-codegen/dbGenerator.d.ts +111 -0
- package/dist/src/lib/db-codegen/dbGenerator.js +371 -0
- package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -0
- package/dist/src/lib/db-codegen/dbNaming.d.ts +45 -0
- package/dist/src/lib/db-codegen/dbNaming.js +104 -0
- package/dist/src/lib/db-codegen/dbNaming.js.map +1 -0
- package/dist/src/lib/db-codegen/dbTemplates.d.ts +97 -0
- package/dist/src/lib/db-codegen/dbTemplates.js +159 -0
- package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -0
- package/dist/src/lib/db-codegen/dbTsTypes.d.ts +78 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js +112 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -0
- package/dist/src/lib/env-resolver.d.ts +62 -0
- package/dist/src/lib/env-resolver.js +121 -0
- package/dist/src/lib/env-resolver.js.map +1 -0
- package/dist/src/lib/fetch.d.ts +5 -0
- package/dist/src/lib/generated-allowlist.d.ts +28 -0
- package/dist/src/lib/generated-allowlist.js +220 -0
- package/dist/src/lib/generated-allowlist.js.map +1 -0
- package/dist/src/lib/init-config.d.ts +59 -0
- package/dist/src/lib/init-config.js +113 -0
- package/dist/src/lib/init-config.js.map +1 -0
- package/dist/src/lib/migration-nag.d.ts +49 -0
- package/dist/src/lib/migration-nag.js +163 -0
- package/dist/src/lib/migration-nag.js.map +1 -0
- package/dist/src/lib/output.d.ts +86 -0
- package/dist/src/lib/output.js +150 -8
- package/dist/src/lib/output.js.map +1 -1
- package/dist/src/lib/paginate.d.ts +33 -0
- package/dist/src/lib/paginate.js +42 -0
- package/dist/src/lib/paginate.js.map +1 -0
- package/dist/src/lib/project-config.d.ts +97 -0
- package/dist/src/lib/project-config.js +209 -0
- package/dist/src/lib/project-config.js.map +1 -0
- package/dist/src/lib/query-operators.d.ts +43 -0
- package/dist/src/lib/query-operators.js +80 -0
- package/dist/src/lib/query-operators.js.map +1 -0
- package/dist/src/lib/refresh-admin-credentials.d.ts +65 -0
- package/dist/src/lib/refresh-admin-credentials.js +103 -0
- package/dist/src/lib/refresh-admin-credentials.js.map +1 -0
- package/dist/src/lib/resolve-platform.d.ts +45 -0
- package/dist/src/lib/resolve-platform.js +43 -0
- package/dist/src/lib/resolve-platform.js.map +1 -0
- package/dist/src/lib/skill-installer.d.ts +23 -0
- package/dist/src/lib/skill-installer.js +135 -0
- package/dist/src/lib/skill-installer.js.map +1 -0
- package/dist/src/lib/snapshots.d.ts +99 -0
- package/dist/src/lib/snapshots.js +357 -0
- package/dist/src/lib/snapshots.js.map +1 -0
- package/dist/src/lib/sync-paths.d.ts +72 -0
- package/dist/src/lib/sync-paths.js +130 -0
- package/dist/src/lib/sync-paths.js.map +1 -0
- package/dist/src/lib/template.d.ts +97 -0
- package/dist/src/lib/template.js +336 -62
- package/dist/src/lib/template.js.map +1 -1
- package/dist/src/lib/token-inject.d.ts +56 -0
- package/dist/src/lib/token-inject.js +204 -0
- package/dist/src/lib/token-inject.js.map +1 -0
- package/dist/src/lib/toml-database-config.d.ts +152 -0
- package/dist/src/lib/toml-database-config.js +600 -0
- package/dist/src/lib/toml-database-config.js.map +1 -0
- package/dist/src/lib/toml-metadata-config.d.ts +139 -0
- package/dist/src/lib/toml-metadata-config.js +427 -0
- package/dist/src/lib/toml-metadata-config.js.map +1 -0
- package/dist/src/lib/toml-params-validator.d.ts +129 -0
- package/dist/src/lib/toml-params-validator.js +298 -0
- package/dist/src/lib/toml-params-validator.js.map +1 -0
- package/dist/src/lib/version-check.d.ts +10 -0
- package/dist/src/lib/version-check.js +172 -0
- package/dist/src/lib/version-check.js.map +1 -0
- package/dist/src/lib/workflow-apply.d.ts +66 -0
- package/dist/src/lib/workflow-apply.js +117 -0
- package/dist/src/lib/workflow-apply.js.map +1 -0
- package/dist/src/lib/workflow-fragments.d.ts +41 -0
- package/dist/src/lib/workflow-fragments.js +121 -0
- package/dist/src/lib/workflow-fragments.js.map +1 -0
- package/dist/src/lib/workflow-toml-validator.d.ts +95 -0
- package/dist/src/lib/workflow-toml-validator.js +323 -0
- package/dist/src/lib/workflow-toml-validator.js.map +1 -0
- package/dist/src/types/index.d.ts +520 -0
- package/dist/src/validators.d.ts +64 -0
- package/dist/src/validators.js +63 -0
- package/dist/src/validators.js.map +1 -0
- package/package.json +18 -4
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure string templates for the `databases codegen` generator (issue #814).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the codegen-v2 template style
|
|
5
|
+
* (`packages/js-bao/src/cli/v2/templates.ts`): total functions (no I/O, no
|
|
6
|
+
* hidden state), an auto-generated banner + fingerprint header, and
|
|
7
|
+
* deterministic ordering so `--check` can compare byte-for-byte.
|
|
8
|
+
*
|
|
9
|
+
* Diverges from codegen-v2 in two ways:
|
|
10
|
+
* 1. Database-DO records are schemaless documents, NOT `BaseModel` ORM
|
|
11
|
+
* classes — so we emit plain `export interface` types with no class
|
|
12
|
+
* shell, no barrel registration, and `import type` only.
|
|
13
|
+
* 2. We add an OPERATIONS half codegen-v2 has no analog for: per-op
|
|
14
|
+
* input-params interfaces + per-op result aliases keyed off `op.type`.
|
|
15
|
+
*/
|
|
16
|
+
/** A field on a record interface (read shape). */
|
|
17
|
+
export interface RecordField {
|
|
18
|
+
name: string;
|
|
19
|
+
/** TOML field type (`string|number|boolean|date|id|stringset`). */
|
|
20
|
+
type: string;
|
|
21
|
+
/** Required props render as `name: T`; otherwise `name?: T`. */
|
|
22
|
+
required: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Allowed-value set for a `string` field (#843). When non-empty, the field
|
|
25
|
+
* renders a TS string-literal union (`"a" | "b"`) instead of bare `string`.
|
|
26
|
+
*/
|
|
27
|
+
enum?: string[];
|
|
28
|
+
}
|
|
29
|
+
export interface RenderRecordInterfaceInput {
|
|
30
|
+
/** PascalCase interface name (e.g. `Account`). */
|
|
31
|
+
interfaceName: string;
|
|
32
|
+
/** TOML model name (e.g. `accounts`). */
|
|
33
|
+
modelName: string;
|
|
34
|
+
fields: RecordField[];
|
|
35
|
+
/**
|
|
36
|
+
* Server-stamped field names (timestamps + auto-populated fields) that
|
|
37
|
+
* appear on the READ record interface as OPTIONAL props, and only if not
|
|
38
|
+
* already declared in `fields`.
|
|
39
|
+
*/
|
|
40
|
+
stampedFields: string[];
|
|
41
|
+
}
|
|
42
|
+
/** One declared param on an op-input interface (write shape). */
|
|
43
|
+
export interface ParamField {
|
|
44
|
+
name: string;
|
|
45
|
+
/** TOML param type (`string|number|boolean|object`). */
|
|
46
|
+
type: string;
|
|
47
|
+
required: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Allowed-value set for a `string` param → string-literal union (#861).
|
|
50
|
+
* Validated server-side (`validateParams`) at config-push time; the emitter
|
|
51
|
+
* renders the union when present and falls back to the base type otherwise.
|
|
52
|
+
*/
|
|
53
|
+
enum?: string[];
|
|
54
|
+
}
|
|
55
|
+
export interface RenderOpParamsInterfaceInput {
|
|
56
|
+
/** PascalCase params interface name (e.g. `SaveAccountParams`). */
|
|
57
|
+
interfaceName: string;
|
|
58
|
+
/** Operation name (e.g. `saveAccount`). */
|
|
59
|
+
opName: string;
|
|
60
|
+
params: ParamField[];
|
|
61
|
+
}
|
|
62
|
+
export interface RenderOpResultAliasInput {
|
|
63
|
+
/** Per-op result alias name (e.g. `SaveAccountResult`). */
|
|
64
|
+
aliasName: string;
|
|
65
|
+
/** Operation name (e.g. `saveAccount`). */
|
|
66
|
+
opName: string;
|
|
67
|
+
/** Operation type (`query|mutation|count|aggregate|pipeline|applyToQuery`). */
|
|
68
|
+
opType: string;
|
|
69
|
+
/**
|
|
70
|
+
* For `query` ops, the record interface name the result is generic over
|
|
71
|
+
* (`QueryResult<Account>`). Null when the op's model has no record
|
|
72
|
+
* interface (e.g. pipeline) — falls back to `QueryResult<Record<string, unknown>>`.
|
|
73
|
+
*/
|
|
74
|
+
recordInterfaceName: string | null;
|
|
75
|
+
}
|
|
76
|
+
/** The shared generic result aliases, keyed off `op.type`. */
|
|
77
|
+
export declare const RESULT_ALIASES_BLOCK = "// Generic per-op result shapes, keyed off the operation type. The op\n// return contract is NOT stored in the TOML \u2014 these mirror the runtime\n// result shapes produced by the database-operations controller.\n\n/** `query` ops return a page of records. */\nexport interface QueryResult<T = Record<string, unknown>> {\n data: T[];\n hasMore?: boolean;\n nextCursor?: string;\n}\n\n/** `mutation` ops return per-step results. */\nexport interface MutationResult {\n results: unknown[];\n}\n\n/** `count` ops return a single count. */\nexport interface CountResult {\n count: number;\n}\n\n/** `aggregate` ops return a single result object. */\nexport interface AggregateResult {\n result: Record<string, unknown>;\n}\n\n/** `applyToQuery` ops return match/affect/fail counts. */\nexport interface ApplyToQueryResult {\n matched: number;\n affected: number;\n failed: number;\n sample?: unknown[];\n}\n\n/** `pipeline` ops return per-step results keyed by step name. */\nexport interface PipelineResult {\n steps: Record<string, unknown>;\n}\n";
|
|
78
|
+
/**
|
|
79
|
+
* Render the header (banner + regen hint + fingerprint).
|
|
80
|
+
*/
|
|
81
|
+
export declare function renderHeader(fingerprint: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* Render a single record interface (read shape). Stamped fields
|
|
84
|
+
* (`createdAt`, `modifiedAt`, `ownerId`, …) are appended as OPTIONAL props
|
|
85
|
+
* if not already present in `fields`.
|
|
86
|
+
*/
|
|
87
|
+
export declare function renderRecordInterface(input: RenderRecordInterfaceInput): string;
|
|
88
|
+
/**
|
|
89
|
+
* Render a single op-input-params interface (write shape). `required: true`
|
|
90
|
+
* params are non-optional; others are optional. `object` params render as
|
|
91
|
+
* `Record<string, any>`.
|
|
92
|
+
*/
|
|
93
|
+
export declare function renderOpParamsInterface(input: RenderOpParamsInterfaceInput): string;
|
|
94
|
+
/**
|
|
95
|
+
* Render a per-op result alias keyed off `op.type`.
|
|
96
|
+
*/
|
|
97
|
+
export declare function renderOpResultAlias(input: RenderOpResultAliasInput): string;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure string templates for the `databases codegen` generator (issue #814).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the codegen-v2 template style
|
|
5
|
+
* (`packages/js-bao/src/cli/v2/templates.ts`): total functions (no I/O, no
|
|
6
|
+
* hidden state), an auto-generated banner + fingerprint header, and
|
|
7
|
+
* deterministic ordering so `--check` can compare byte-for-byte.
|
|
8
|
+
*
|
|
9
|
+
* Diverges from codegen-v2 in two ways:
|
|
10
|
+
* 1. Database-DO records are schemaless documents, NOT `BaseModel` ORM
|
|
11
|
+
* classes — so we emit plain `export interface` types with no class
|
|
12
|
+
* shell, no barrel registration, and `import type` only.
|
|
13
|
+
* 2. We add an OPERATIONS half codegen-v2 has no analog for: per-op
|
|
14
|
+
* input-params interfaces + per-op result aliases keyed off `op.type`.
|
|
15
|
+
*/
|
|
16
|
+
import { tsTypeForDbField, tsTypeForDbParamType } from "./dbTsTypes.js";
|
|
17
|
+
const HEADER_BANNER = "// AUTO-GENERATED FROM database-types TOML — DO NOT EDIT.";
|
|
18
|
+
const REGEN_INSTRUCTION = "// Run `primitive databases codegen <database-type>` to regenerate.";
|
|
19
|
+
/** The shared generic result aliases, keyed off `op.type`. */
|
|
20
|
+
export const RESULT_ALIASES_BLOCK = `// Generic per-op result shapes, keyed off the operation type. The op
|
|
21
|
+
// return contract is NOT stored in the TOML — these mirror the runtime
|
|
22
|
+
// result shapes produced by the database-operations controller.
|
|
23
|
+
|
|
24
|
+
/** \`query\` ops return a page of records. */
|
|
25
|
+
export interface QueryResult<T = Record<string, unknown>> {
|
|
26
|
+
data: T[];
|
|
27
|
+
hasMore?: boolean;
|
|
28
|
+
nextCursor?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** \`mutation\` ops return per-step results. */
|
|
32
|
+
export interface MutationResult {
|
|
33
|
+
results: unknown[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** \`count\` ops return a single count. */
|
|
37
|
+
export interface CountResult {
|
|
38
|
+
count: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** \`aggregate\` ops return a single result object. */
|
|
42
|
+
export interface AggregateResult {
|
|
43
|
+
result: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** \`applyToQuery\` ops return match/affect/fail counts. */
|
|
47
|
+
export interface ApplyToQueryResult {
|
|
48
|
+
matched: number;
|
|
49
|
+
affected: number;
|
|
50
|
+
failed: number;
|
|
51
|
+
sample?: unknown[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** \`pipeline\` ops return per-step results keyed by step name. */
|
|
55
|
+
export interface PipelineResult {
|
|
56
|
+
steps: Record<string, unknown>;
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
/**
|
|
60
|
+
* Render the header (banner + regen hint + fingerprint).
|
|
61
|
+
*/
|
|
62
|
+
export function renderHeader(fingerprint) {
|
|
63
|
+
return [
|
|
64
|
+
HEADER_BANNER,
|
|
65
|
+
REGEN_INSTRUCTION,
|
|
66
|
+
`// fingerprint: ${fingerprint}`,
|
|
67
|
+
].join("\n");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Render a single record interface (read shape). Stamped fields
|
|
71
|
+
* (`createdAt`, `modifiedAt`, `ownerId`, …) are appended as OPTIONAL props
|
|
72
|
+
* if not already present in `fields`.
|
|
73
|
+
*/
|
|
74
|
+
export function renderRecordInterface(input) {
|
|
75
|
+
const { interfaceName, fields, stampedFields } = input;
|
|
76
|
+
const memberLines = [];
|
|
77
|
+
const declared = new Set();
|
|
78
|
+
for (const f of fields) {
|
|
79
|
+
declared.add(f.name);
|
|
80
|
+
const optional = f.required ? "" : "?";
|
|
81
|
+
memberLines.push(` ${f.name}${optional}: ${tsTypeForDbField(f.type, f.enum)};`);
|
|
82
|
+
}
|
|
83
|
+
// Server-stamped fields appear on the read interface as optional —
|
|
84
|
+
// the runtime populates them, but a freshly-built object may not have
|
|
85
|
+
// them yet, so claiming them as required would be a type lie.
|
|
86
|
+
for (const stamped of stampedFields) {
|
|
87
|
+
if (declared.has(stamped))
|
|
88
|
+
continue;
|
|
89
|
+
declared.add(stamped);
|
|
90
|
+
memberLines.push(` ${stamped}?: string;`);
|
|
91
|
+
}
|
|
92
|
+
// A record with no fields and no stamped fields would render an empty
|
|
93
|
+
// `interface X {}`, which trips `@typescript-eslint/no-empty-object-type`.
|
|
94
|
+
// Emit a `Record<string, unknown>` type alias instead. Database-DO records
|
|
95
|
+
// are SCHEMALESS — arbitrary runtime keys can exist — so the empty-schema
|
|
96
|
+
// shape must stay OPEN (`Record<string, unknown>`), NOT `Record<string,
|
|
97
|
+
// never>`. `Record<string, never>` forbids every key, which would make real
|
|
98
|
+
// returned records unassignable to `QueryResult<X>` and unusable in TS.
|
|
99
|
+
// (Contrast with the no-param-op case in `renderOpParamsInterface`, where
|
|
100
|
+
// `Record<string, never>` is correct: it means "no params allowed".)
|
|
101
|
+
if (memberLines.length === 0) {
|
|
102
|
+
return `export type ${interfaceName} = Record<string, unknown>;`;
|
|
103
|
+
}
|
|
104
|
+
const lines = [];
|
|
105
|
+
lines.push(`export interface ${interfaceName} {`);
|
|
106
|
+
lines.push(...memberLines);
|
|
107
|
+
lines.push(`}`);
|
|
108
|
+
return lines.join("\n");
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Render a single op-input-params interface (write shape). `required: true`
|
|
112
|
+
* params are non-optional; others are optional. `object` params render as
|
|
113
|
+
* `Record<string, any>`.
|
|
114
|
+
*/
|
|
115
|
+
export function renderOpParamsInterface(input) {
|
|
116
|
+
const { interfaceName, params } = input;
|
|
117
|
+
// An op with no declared params has no input shape. Emitting an empty
|
|
118
|
+
// `interface X {}` trips `@typescript-eslint/no-empty-object-type`, so
|
|
119
|
+
// render a `Record<string, never>` type alias instead — it types "no
|
|
120
|
+
// params allowed" and stays call-site compatible (`op({})`).
|
|
121
|
+
if (params.length === 0) {
|
|
122
|
+
return `export type ${interfaceName} = Record<string, never>;`;
|
|
123
|
+
}
|
|
124
|
+
const lines = [];
|
|
125
|
+
lines.push(`export interface ${interfaceName} {`);
|
|
126
|
+
for (const p of params) {
|
|
127
|
+
const optional = p.required ? "" : "?";
|
|
128
|
+
lines.push(` ${p.name}${optional}: ${tsTypeForDbParamType(p.type, p.enum)};`);
|
|
129
|
+
}
|
|
130
|
+
lines.push(`}`);
|
|
131
|
+
return lines.join("\n");
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Render a per-op result alias keyed off `op.type`.
|
|
135
|
+
*/
|
|
136
|
+
export function renderOpResultAlias(input) {
|
|
137
|
+
const { aliasName, opType, recordInterfaceName } = input;
|
|
138
|
+
switch (opType) {
|
|
139
|
+
case "query": {
|
|
140
|
+
const generic = recordInterfaceName ?? "Record<string, unknown>";
|
|
141
|
+
return `export type ${aliasName} = QueryResult<${generic}>;`;
|
|
142
|
+
}
|
|
143
|
+
case "mutation":
|
|
144
|
+
return `export type ${aliasName} = MutationResult;`;
|
|
145
|
+
case "count":
|
|
146
|
+
return `export type ${aliasName} = CountResult;`;
|
|
147
|
+
case "aggregate":
|
|
148
|
+
return `export type ${aliasName} = AggregateResult;`;
|
|
149
|
+
case "applyToQuery":
|
|
150
|
+
return `export type ${aliasName} = ApplyToQueryResult;`;
|
|
151
|
+
case "pipeline":
|
|
152
|
+
return `export type ${aliasName} = PipelineResult;`;
|
|
153
|
+
default:
|
|
154
|
+
// Unknown op type — emit a permissive alias rather than throwing,
|
|
155
|
+
// so one stray op doesn't block codegen for the whole file.
|
|
156
|
+
return `export type ${aliasName} = unknown;`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=dbTemplates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbTemplates.js","sourceRoot":"","sources":["../../../../src/lib/db-codegen/dbTemplates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAExE,MAAM,aAAa,GACjB,2DAA2D,CAAC;AAC9D,MAAM,iBAAiB,GACrB,qEAAqE,CAAC;AAmExE,8DAA8D;AAC9D,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCnC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,WAAmB;IAC9C,OAAO;QACL,aAAa;QACb,iBAAiB;QACjB,mBAAmB,WAAW,EAAE;KACjC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAiC;IAEjC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;IACvD,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACrB,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QACvC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,GAAG,QAAQ,KAAK,gBAAgB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ue #814).
|
|
4
|
+
*
|
|
5
|
+
* The record-interface half reuses the SAME `FieldType` vocabulary that
|
|
6
|
+
* powers the document-model codegen-v2 generator
|
|
7
|
+
* (`packages/js-bao/src/cli/v2/tsTypes.ts`): the database-type
|
|
8
|
+
* `[models.<m>.fields.<f>]` blocks round-trip through the same
|
|
9
|
+
* `loadSchemaFromTomlString` loader, so the field→TS mapping is identical
|
|
10
|
+
* (`string|id|date → string`, `number → number`, `boolean → boolean`,
|
|
11
|
+
* `stringset → StringSet`).
|
|
12
|
+
*
|
|
13
|
+
* The op-params half maps the operation `params.{type}` vocabulary
|
|
14
|
+
* (`string|number|boolean|object`, validated server-side in
|
|
15
|
+
* `database-type-operations-controller.ts`). `object` has no field-type
|
|
16
|
+
* analog and carries no nested schema, so it renders as `Record<string, unknown>`.
|
|
17
|
+
*
|
|
18
|
+
* NOTE (#842 — infer required record fields from operation params): when that
|
|
19
|
+
* issue is scheduled, the op-params analysis it needs (which fields a `$params.X`
|
|
20
|
+
* binding writes, and whether the param is `required`) already exists in
|
|
21
|
+
* `inferParamFieldTypes(op)` in
|
|
22
|
+
* `src/app-api/controllers/database-type-config-controller.ts` (issue #845 /
|
|
23
|
+
* #812 Phase 2). Its return shape was deliberately made growable (it can carry
|
|
24
|
+
* a `requiredInThisOp` flag) so it can be lifted into a shared `analyzeOpParams`
|
|
25
|
+
* pass consumed by BOTH the scaffold (#845, field *type*) and codegen (#842,
|
|
26
|
+
* field *required-ness*). Lift it rather than re-walking the ops here.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Field types accepted in a database-type `[models.*]` schema. Mirrors
|
|
30
|
+
* `FieldType` in `packages/js-bao/src/types/ormTypes.ts`. Declared locally
|
|
31
|
+
* (rather than imported from `js-bao`) because `FieldType` is not part of
|
|
32
|
+
* the published `js-bao` entry point and the CLI does not depend on the
|
|
33
|
+
* library's internal type paths.
|
|
34
|
+
*/
|
|
35
|
+
export type DbFieldType = "string" | "number" | "boolean" | "date" | "id" | "stringset";
|
|
36
|
+
/** Param types accepted in an `[[operations]]` `params` block. */
|
|
37
|
+
export type DbParamType = "string" | "number" | "boolean" | "object";
|
|
38
|
+
/**
|
|
39
|
+
* Returns the TS type expression for a record field type. Unknown types
|
|
40
|
+
* fall back to `unknown` rather than throwing: the database-type TOML is
|
|
41
|
+
* author-curated and may legitimately carry a field type the CLI's vendored
|
|
42
|
+
* vocabulary predates, and a hard throw would block codegen for the whole
|
|
43
|
+
* file over one unrecognized field.
|
|
44
|
+
*/
|
|
45
|
+
export declare function tsTypeForDbFieldType(fieldType: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Render a TypeScript string-literal union from an `enum` allowed-value set
|
|
48
|
+
* (e.g. `["a", "b"]` → `"a" | "b"`). Each value is emitted via
|
|
49
|
+
* `JSON.stringify` so quotes, backslashes, and other special characters are
|
|
50
|
+
* properly escaped into a valid TS string literal.
|
|
51
|
+
*
|
|
52
|
+
* Shared enum vocabulary with the doc-model v2 codegen
|
|
53
|
+
* (`packages/js-bao/src/cli/v2/tsTypes.ts`). The `enum` array is validated
|
|
54
|
+
* upstream by the TOML loader (`parseFieldOptions`): non-empty, all-string,
|
|
55
|
+
* string-field-only. This renderer assumes that contract has held.
|
|
56
|
+
*/
|
|
57
|
+
export declare function tsUnionFromEnum(values: string[]): string;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the TS type expression for a record field, honoring an optional
|
|
60
|
+
* string `enum` allowed-value set (#843). A non-empty `enum` on a `string`
|
|
61
|
+
* field renders a string-literal union; otherwise falls back to the base
|
|
62
|
+
* `tsTypeForDbFieldType` mapping.
|
|
63
|
+
*/
|
|
64
|
+
export declare function tsTypeForDbField(fieldType: string, enumValues?: string[]): string;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the TS type expression for an op param, honoring an optional string
|
|
67
|
+
* `enum` allowed-value set (#861). A non-empty `enum` on a `string` param
|
|
68
|
+
* renders a string-literal union (`"a" | "b"`); otherwise falls back to the
|
|
69
|
+
* base param-type mapping below. Mirrors `tsTypeForDbField` (the record-field
|
|
70
|
+
* sibling) and reuses `tsUnionFromEnum` for a single escaping implementation.
|
|
71
|
+
*
|
|
72
|
+
* Unlike the record-field path (validated upstream by `parseFieldOptions`,
|
|
73
|
+
* which throws), op-param enum *shape* is validated server-side in
|
|
74
|
+
* `validateParams` at config-push time. So this renderer just falls back to
|
|
75
|
+
* the base type for a non-string param or an empty enum rather than throwing —
|
|
76
|
+
* the server is the source of truth for rejecting a malformed param `enum`.
|
|
77
|
+
*/
|
|
78
|
+
export declare function tsTypeForDbParamType(paramType: string, enumValues?: string[]): string;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map database-type TOML field/param types → TypeScript types for the
|
|
3
|
+
* `databases codegen` generator (issue #814).
|
|
4
|
+
*
|
|
5
|
+
* The record-interface half reuses the SAME `FieldType` vocabulary that
|
|
6
|
+
* powers the document-model codegen-v2 generator
|
|
7
|
+
* (`packages/js-bao/src/cli/v2/tsTypes.ts`): the database-type
|
|
8
|
+
* `[models.<m>.fields.<f>]` blocks round-trip through the same
|
|
9
|
+
* `loadSchemaFromTomlString` loader, so the field→TS mapping is identical
|
|
10
|
+
* (`string|id|date → string`, `number → number`, `boolean → boolean`,
|
|
11
|
+
* `stringset → StringSet`).
|
|
12
|
+
*
|
|
13
|
+
* The op-params half maps the operation `params.{type}` vocabulary
|
|
14
|
+
* (`string|number|boolean|object`, validated server-side in
|
|
15
|
+
* `database-type-operations-controller.ts`). `object` has no field-type
|
|
16
|
+
* analog and carries no nested schema, so it renders as `Record<string, unknown>`.
|
|
17
|
+
*
|
|
18
|
+
* NOTE (#842 — infer required record fields from operation params): when that
|
|
19
|
+
* issue is scheduled, the op-params analysis it needs (which fields a `$params.X`
|
|
20
|
+
* binding writes, and whether the param is `required`) already exists in
|
|
21
|
+
* `inferParamFieldTypes(op)` in
|
|
22
|
+
* `src/app-api/controllers/database-type-config-controller.ts` (issue #845 /
|
|
23
|
+
* #812 Phase 2). Its return shape was deliberately made growable (it can carry
|
|
24
|
+
* a `requiredInThisOp` flag) so it can be lifted into a shared `analyzeOpParams`
|
|
25
|
+
* pass consumed by BOTH the scaffold (#845, field *type*) and codegen (#842,
|
|
26
|
+
* field *required-ness*). Lift it rather than re-walking the ops here.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Returns the TS type expression for a record field type. Unknown types
|
|
30
|
+
* fall back to `unknown` rather than throwing: the database-type TOML is
|
|
31
|
+
* author-curated and may legitimately carry a field type the CLI's vendored
|
|
32
|
+
* vocabulary predates, and a hard throw would block codegen for the whole
|
|
33
|
+
* file over one unrecognized field.
|
|
34
|
+
*/
|
|
35
|
+
export function tsTypeForDbFieldType(fieldType) {
|
|
36
|
+
switch (fieldType) {
|
|
37
|
+
case "string":
|
|
38
|
+
case "id":
|
|
39
|
+
case "date":
|
|
40
|
+
return "string";
|
|
41
|
+
case "number":
|
|
42
|
+
return "number";
|
|
43
|
+
case "boolean":
|
|
44
|
+
return "boolean";
|
|
45
|
+
case "stringset":
|
|
46
|
+
// StringSet serializes to a string array on the wire.
|
|
47
|
+
return "string[]";
|
|
48
|
+
default:
|
|
49
|
+
return "unknown";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Render a TypeScript string-literal union from an `enum` allowed-value set
|
|
54
|
+
* (e.g. `["a", "b"]` → `"a" | "b"`). Each value is emitted via
|
|
55
|
+
* `JSON.stringify` so quotes, backslashes, and other special characters are
|
|
56
|
+
* properly escaped into a valid TS string literal.
|
|
57
|
+
*
|
|
58
|
+
* Shared enum vocabulary with the doc-model v2 codegen
|
|
59
|
+
* (`packages/js-bao/src/cli/v2/tsTypes.ts`). The `enum` array is validated
|
|
60
|
+
* upstream by the TOML loader (`parseFieldOptions`): non-empty, all-string,
|
|
61
|
+
* string-field-only. This renderer assumes that contract has held.
|
|
62
|
+
*/
|
|
63
|
+
export function tsUnionFromEnum(values) {
|
|
64
|
+
return values.map((v) => JSON.stringify(v)).join(" | ");
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns the TS type expression for a record field, honoring an optional
|
|
68
|
+
* string `enum` allowed-value set (#843). A non-empty `enum` on a `string`
|
|
69
|
+
* field renders a string-literal union; otherwise falls back to the base
|
|
70
|
+
* `tsTypeForDbFieldType` mapping.
|
|
71
|
+
*/
|
|
72
|
+
export function tsTypeForDbField(fieldType, enumValues) {
|
|
73
|
+
if (fieldType === "string" &&
|
|
74
|
+
Array.isArray(enumValues) &&
|
|
75
|
+
enumValues.length > 0) {
|
|
76
|
+
return tsUnionFromEnum(enumValues);
|
|
77
|
+
}
|
|
78
|
+
return tsTypeForDbFieldType(fieldType);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns the TS type expression for an op param, honoring an optional string
|
|
82
|
+
* `enum` allowed-value set (#861). A non-empty `enum` on a `string` param
|
|
83
|
+
* renders a string-literal union (`"a" | "b"`); otherwise falls back to the
|
|
84
|
+
* base param-type mapping below. Mirrors `tsTypeForDbField` (the record-field
|
|
85
|
+
* sibling) and reuses `tsUnionFromEnum` for a single escaping implementation.
|
|
86
|
+
*
|
|
87
|
+
* Unlike the record-field path (validated upstream by `parseFieldOptions`,
|
|
88
|
+
* which throws), op-param enum *shape* is validated server-side in
|
|
89
|
+
* `validateParams` at config-push time. So this renderer just falls back to
|
|
90
|
+
* the base type for a non-string param or an empty enum rather than throwing —
|
|
91
|
+
* the server is the source of truth for rejecting a malformed param `enum`.
|
|
92
|
+
*/
|
|
93
|
+
export function tsTypeForDbParamType(paramType, enumValues) {
|
|
94
|
+
if (paramType === "string" &&
|
|
95
|
+
Array.isArray(enumValues) &&
|
|
96
|
+
enumValues.length > 0) {
|
|
97
|
+
return tsUnionFromEnum(enumValues);
|
|
98
|
+
}
|
|
99
|
+
switch (paramType) {
|
|
100
|
+
case "string":
|
|
101
|
+
return "string";
|
|
102
|
+
case "number":
|
|
103
|
+
return "number";
|
|
104
|
+
case "boolean":
|
|
105
|
+
return "boolean";
|
|
106
|
+
case "object":
|
|
107
|
+
return "Record<string, unknown>";
|
|
108
|
+
default:
|
|
109
|
+
return "unknown";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=dbTsTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbTsTypes.js","sourceRoot":"","sources":["../../../../src/lib/db-codegen/dbTsTypes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAoBH;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAAiB;IACpD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,QAAQ,CAAC;QACd,KAAK,IAAI,CAAC;QACV,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,WAAW;YACd,sDAAsD;YACtD,OAAO,UAAU,CAAC;QACpB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,MAAgB;IAC9C,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,SAAiB,EACjB,UAAqB;IAErB,IACE,SAAS,KAAK,QAAQ;QACtB,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QACzB,UAAU,CAAC,MAAM,GAAG,CAAC,EACrB,CAAC;QACD,OAAO,eAAe,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,oBAAoB,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAiB,EACjB,UAAqB;IAErB,IACE,SAAS,KAAK,QAAQ;QACtB,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QACzB,UAAU,CAAC,MAAM,GAAG,CAAC,EACrB,CAAC;QACD,OAAO,eAAe,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IACD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,yBAAyB,CAAC;QACnC;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment resolution.
|
|
3
|
+
*
|
|
4
|
+
* Decides which named environment the CLI is currently targeting. The
|
|
5
|
+
* resolution order is:
|
|
6
|
+
*
|
|
7
|
+
* 1. Explicit --env <name> flag (set via setCurrentEnvName from bin/primitive.ts)
|
|
8
|
+
* 2. PRIMITIVE_ENV environment variable
|
|
9
|
+
* 3. The project config's defaultEnvironment
|
|
10
|
+
* 4. If the project has exactly one environment, that one
|
|
11
|
+
* 5. null (legacy mode — fall back to ~/.primitive/credentials.json)
|
|
12
|
+
*
|
|
13
|
+
* Commands read the resolved environment once via getCurrentEnvironment().
|
|
14
|
+
* The resolution is cached for the lifetime of the process.
|
|
15
|
+
*/
|
|
16
|
+
import { type ProjectConfig, type ProjectEnvironment } from "./project-config.js";
|
|
17
|
+
export interface ResolvedEnvironment {
|
|
18
|
+
/** The environment name (e.g. "dev", "prod"). */
|
|
19
|
+
name: string;
|
|
20
|
+
/** The config entry for this environment. */
|
|
21
|
+
config: ProjectEnvironment;
|
|
22
|
+
/** Absolute path to .primitive/config.json. */
|
|
23
|
+
projectConfigPath: string;
|
|
24
|
+
/** Absolute path to the project root (the parent of .primitive/). */
|
|
25
|
+
projectRoot: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Called by bin/primitive.ts when the user passes --env <name> on the command
|
|
29
|
+
* line. Must be called before any command code runs so subsequent calls to
|
|
30
|
+
* getCurrentEnvironment() see the override.
|
|
31
|
+
*/
|
|
32
|
+
export declare function setCurrentEnvName(name: string | null): void;
|
|
33
|
+
/**
|
|
34
|
+
* Forces the resolver to re-read the project config on the next call.
|
|
35
|
+
* Used by tests and by commands that mutate the project config.
|
|
36
|
+
*/
|
|
37
|
+
export declare function resetEnvResolver(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Loads and caches the project config. Returns null if no
|
|
40
|
+
* .primitive/config.json is present. Throws ProjectConfigError on a broken config.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getProjectConfig(): ProjectConfig | null;
|
|
43
|
+
/**
|
|
44
|
+
* Resolves the current environment, or returns null if we're running in
|
|
45
|
+
* legacy mode (no .primitive/config.json present).
|
|
46
|
+
*
|
|
47
|
+
* This never throws for a missing project config — that's legitimate
|
|
48
|
+
* "legacy mode" usage. It DOES throw if the project config exists but the
|
|
49
|
+
* requested environment doesn't.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getCurrentEnvironment(): ResolvedEnvironment | null;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the current environment name for display purposes (e.g. in status
|
|
54
|
+
* headers). Returns null in legacy mode. Swallows resolution errors so the
|
|
55
|
+
* header never crashes the CLI.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getCurrentEnvNameSafe(): string | null;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the explicit name set via setCurrentEnvName(), for commands that
|
|
60
|
+
* need to know whether the user passed --env vs. relying on defaults.
|
|
61
|
+
*/
|
|
62
|
+
export declare function getExplicitEnvName(): string | null;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment resolution.
|
|
3
|
+
*
|
|
4
|
+
* Decides which named environment the CLI is currently targeting. The
|
|
5
|
+
* resolution order is:
|
|
6
|
+
*
|
|
7
|
+
* 1. Explicit --env <name> flag (set via setCurrentEnvName from bin/primitive.ts)
|
|
8
|
+
* 2. PRIMITIVE_ENV environment variable
|
|
9
|
+
* 3. The project config's defaultEnvironment
|
|
10
|
+
* 4. If the project has exactly one environment, that one
|
|
11
|
+
* 5. null (legacy mode — fall back to ~/.primitive/credentials.json)
|
|
12
|
+
*
|
|
13
|
+
* Commands read the resolved environment once via getCurrentEnvironment().
|
|
14
|
+
* The resolution is cached for the lifetime of the process.
|
|
15
|
+
*/
|
|
16
|
+
import { loadProjectConfig, findProjectConfigPath, findProjectRoot, PROJECT_CONFIG_DISPLAY_NAME, } from "./project-config.js";
|
|
17
|
+
/** Process-lifetime cache for resolution results. */
|
|
18
|
+
let cachedResolution;
|
|
19
|
+
let explicitEnvName = null;
|
|
20
|
+
let cachedProjectConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Called by bin/primitive.ts when the user passes --env <name> on the command
|
|
23
|
+
* line. Must be called before any command code runs so subsequent calls to
|
|
24
|
+
* getCurrentEnvironment() see the override.
|
|
25
|
+
*/
|
|
26
|
+
export function setCurrentEnvName(name) {
|
|
27
|
+
explicitEnvName = name;
|
|
28
|
+
// Invalidate any cached resolution so the next getCurrentEnvironment()
|
|
29
|
+
// picks up the new override.
|
|
30
|
+
cachedResolution = undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Forces the resolver to re-read the project config on the next call.
|
|
34
|
+
* Used by tests and by commands that mutate the project config.
|
|
35
|
+
*/
|
|
36
|
+
export function resetEnvResolver() {
|
|
37
|
+
cachedResolution = undefined;
|
|
38
|
+
cachedProjectConfig = undefined;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Loads and caches the project config. Returns null if no
|
|
42
|
+
* .primitive/config.json is present. Throws ProjectConfigError on a broken config.
|
|
43
|
+
*/
|
|
44
|
+
export function getProjectConfig() {
|
|
45
|
+
if (cachedProjectConfig === undefined) {
|
|
46
|
+
cachedProjectConfig = loadProjectConfig();
|
|
47
|
+
}
|
|
48
|
+
return cachedProjectConfig ?? null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Resolves the current environment, or returns null if we're running in
|
|
52
|
+
* legacy mode (no .primitive/config.json present).
|
|
53
|
+
*
|
|
54
|
+
* This never throws for a missing project config — that's legitimate
|
|
55
|
+
* "legacy mode" usage. It DOES throw if the project config exists but the
|
|
56
|
+
* requested environment doesn't.
|
|
57
|
+
*/
|
|
58
|
+
export function getCurrentEnvironment() {
|
|
59
|
+
if (cachedResolution !== undefined)
|
|
60
|
+
return cachedResolution;
|
|
61
|
+
const project = getProjectConfig();
|
|
62
|
+
if (!project) {
|
|
63
|
+
cachedResolution = null;
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const configPath = findProjectConfigPath();
|
|
67
|
+
const projectRoot = findProjectRoot();
|
|
68
|
+
// Determine the environment name.
|
|
69
|
+
const requested = explicitEnvName ??
|
|
70
|
+
process.env.PRIMITIVE_ENV ??
|
|
71
|
+
project.defaultEnvironment ??
|
|
72
|
+
null;
|
|
73
|
+
let name;
|
|
74
|
+
if (requested) {
|
|
75
|
+
if (!project.environments[requested]) {
|
|
76
|
+
const available = Object.keys(project.environments).join(", ") || "(none)";
|
|
77
|
+
throw new Error(`Environment "${requested}" is not defined in ${PROJECT_CONFIG_DISPLAY_NAME}. Available: ${available}`);
|
|
78
|
+
}
|
|
79
|
+
name = requested;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const names = Object.keys(project.environments);
|
|
83
|
+
if (names.length === 1) {
|
|
84
|
+
name = names[0];
|
|
85
|
+
}
|
|
86
|
+
else if (names.length === 0) {
|
|
87
|
+
throw new Error(`${PROJECT_CONFIG_DISPLAY_NAME} has no environments defined. Run 'primitive env add <name>' or 'primitive init'.`);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
throw new Error(`No environment selected. Set "defaultEnvironment" in ${PROJECT_CONFIG_DISPLAY_NAME}, pass --env <name>, or export PRIMITIVE_ENV. Available: ${names.join(", ")}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
cachedResolution = {
|
|
94
|
+
name,
|
|
95
|
+
config: project.environments[name],
|
|
96
|
+
projectConfigPath: configPath,
|
|
97
|
+
projectRoot,
|
|
98
|
+
};
|
|
99
|
+
return cachedResolution;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns the current environment name for display purposes (e.g. in status
|
|
103
|
+
* headers). Returns null in legacy mode. Swallows resolution errors so the
|
|
104
|
+
* header never crashes the CLI.
|
|
105
|
+
*/
|
|
106
|
+
export function getCurrentEnvNameSafe() {
|
|
107
|
+
try {
|
|
108
|
+
return getCurrentEnvironment()?.name ?? null;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Returns the explicit name set via setCurrentEnvName(), for commands that
|
|
116
|
+
* need to know whether the user passed --env vs. relying on defaults.
|
|
117
|
+
*/
|
|
118
|
+
export function getExplicitEnvName() {
|
|
119
|
+
return explicitEnvName;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=env-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-resolver.js","sourceRoot":"","sources":["../../../src/lib/env-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,2BAA2B,GAG5B,MAAM,qBAAqB,CAAC;AAa7B,qDAAqD;AACrD,IAAI,gBAAwD,CAAC;AAC7D,IAAI,eAAe,GAAkB,IAAI,CAAC;AAC1C,IAAI,mBAAqD,CAAC;AAE1D;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAmB;IACn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