primitive-admin 1.1.0-alpha.44 → 1.1.0-alpha.46
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/dist/bin/primitive.js +2 -0
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/blob-buckets.js +20 -7
- package/dist/src/commands/blob-buckets.js.map +1 -1
- package/dist/src/commands/collections.js +11 -0
- package/dist/src/commands/collections.js.map +1 -1
- package/dist/src/commands/databases.js +34 -49
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/sync.js +116 -28
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/vars.d.ts +8 -0
- package/dist/src/commands/vars.js +110 -0
- package/dist/src/commands/vars.js.map +1 -0
- package/dist/src/commands/workflows.js +126 -20
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/api-client.d.ts +10 -0
- package/dist/src/lib/api-client.js +19 -0
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/codegen-shared/generatedFiles.d.ts +61 -0
- package/dist/src/lib/codegen-shared/generatedFiles.js +127 -0
- package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +68 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +168 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -0
- package/dist/src/lib/db-codegen/dbGenerator.d.ts +30 -5
- package/dist/src/lib/db-codegen/dbGenerator.js +227 -165
- package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTemplates.d.ts +11 -23
- package/dist/src/lib/db-codegen/dbTemplates.js +21 -41
- package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTsTypes.d.ts +7 -3
- package/dist/src/lib/db-codegen/dbTsTypes.js +23 -1
- package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
- package/dist/src/lib/generated-allowlist.js +15 -0
- package/dist/src/lib/generated-allowlist.js.map +1 -1
- package/dist/src/lib/toml-metadata-config.d.ts +10 -2
- package/dist/src/lib/toml-metadata-config.js +51 -15
- package/dist/src/lib/toml-metadata-config.js.map +1 -1
- package/dist/src/lib/workflow-codegen/generated-schema-descriptor.d.ts +129 -0
- package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js +269 -0
- package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js.map +1 -0
- package/dist/src/lib/workflow-codegen/generator.d.ts +74 -0
- package/dist/src/lib/workflow-codegen/generator.js +215 -0
- package/dist/src/lib/workflow-codegen/generator.js.map +1 -0
- package/dist/src/lib/workflow-codegen/naming.d.ts +33 -0
- package/dist/src/lib/workflow-codegen/naming.js +81 -0
- package/dist/src/lib/workflow-codegen/naming.js.map +1 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.d.ts +64 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.js +282 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.js.map +1 -0
- package/package.json +4 -2
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared source-directory resolution for the CLI codegen commands
|
|
3
|
+
* (`workflows codegen` #1442 and `databases codegen` #814, issue #1510).
|
|
4
|
+
*
|
|
5
|
+
* Both commands read a set of `*.toml` schemas out of a synced sub-directory
|
|
6
|
+
* (`workflows/` or `database-types/`) and render `*.generated.ts` beside them.
|
|
7
|
+
* Historically each command located that source directory by scanning EVERY
|
|
8
|
+
* `.primitive/sync/<env>/<appId>/<subdir>` slot and either hard-erroring on
|
|
9
|
+
* more than one (`workflows`) or silently merging across environments
|
|
10
|
+
* (`databases`, via a `seenTypes` dedup). Neither did any environment
|
|
11
|
+
* resolution, so `PRIMITIVE_ENV=dev workflows codegen` would happily generate
|
|
12
|
+
* from the `alpha` TOML while `databases codegen` followed a different env —
|
|
13
|
+
* the two generated-type trees could come from different environments in one
|
|
14
|
+
* run.
|
|
15
|
+
*
|
|
16
|
+
* This helper resolves the source directory the same way every other CLI
|
|
17
|
+
* command targets an environment: `--env` → `PRIMITIVE_ENV` →
|
|
18
|
+
* `defaultEnvironment` → single-env → error. `--sync-dir` and `--app` remain
|
|
19
|
+
* explicit overrides. It returns ONLY the resolved source directory; TOML
|
|
20
|
+
* collection, type filtering/dedup, and output-dir defaulting stay in each
|
|
21
|
+
* command.
|
|
22
|
+
*
|
|
23
|
+
* Design notes (binding, from the plan of record for #1510):
|
|
24
|
+
* - Call `getCurrentEnvironment()` DIRECTLY when no `--sync-dir` is given.
|
|
25
|
+
* `resolveSyncDir()`'s internal `safeEnv()` swallows the resolver's
|
|
26
|
+
* ambiguity error and falls back to `./config`, so genuine ambiguity must
|
|
27
|
+
* be surfaced here, not through `resolveSyncDir()`.
|
|
28
|
+
* - Throw plain `Error`s; the calling commands keep their existing
|
|
29
|
+
* `error(); process.exit(1)` convention (they catch at the boundary).
|
|
30
|
+
* - Do NOT use `resolveAppId()` — it is auth-oriented and exits the process,
|
|
31
|
+
* which is wrong for an offline codegen path.
|
|
32
|
+
* - Preserve the `--app`-alone legacy fallback: when `--app` is given, NO
|
|
33
|
+
* environment was explicitly requested, and env resolution fails (or there
|
|
34
|
+
* is no project config / legacy bare-dir mode), scan
|
|
35
|
+
* `.primitive/sync/<env>/<app>/<subdir>` for that specific app, resolving
|
|
36
|
+
* when it appears under exactly one env and erroring (naming the candidate
|
|
37
|
+
* envs) when it appears under more than one. This keeps the existing
|
|
38
|
+
* integration contract
|
|
39
|
+
* (`cli/tests/integration/workflows-codegen.test.ts`) intact.
|
|
40
|
+
* - Do NOT fall through to that scan when an environment WAS explicitly named
|
|
41
|
+
* (`--env` or `PRIMITIVE_ENV`) but is invalid/unknown: surface the
|
|
42
|
+
* resolver's error instead, so an explicit env selection never silently
|
|
43
|
+
* generates code from a different synced environment.
|
|
44
|
+
*/
|
|
45
|
+
import { existsSync, readdirSync } from "fs";
|
|
46
|
+
import { basename, dirname, join } from "path";
|
|
47
|
+
import { getCurrentEnvironment, getExplicitEnvName } from "../env-resolver.js";
|
|
48
|
+
import { getCurrentAppId } from "../config.js";
|
|
49
|
+
import { resolveSyncDir, assertSafePathComponent } from "../sync-paths.js";
|
|
50
|
+
/**
|
|
51
|
+
* Resolves the single source directory a codegen command should read its
|
|
52
|
+
* `*.toml` schemas from. Throws a plain `Error` (with a user-facing message)
|
|
53
|
+
* when the directory can't be resolved unambiguously or doesn't exist.
|
|
54
|
+
*/
|
|
55
|
+
export function resolveCodegenSourceDir(args) {
|
|
56
|
+
const { subdir, options } = args;
|
|
57
|
+
const cwd = args.cwd ?? process.cwd();
|
|
58
|
+
// 1. --sync-dir is an explicit override: use <sync-dir>/<subdir> verbatim.
|
|
59
|
+
if (options.syncDir) {
|
|
60
|
+
return requireExisting(join(options.syncDir, subdir), subdir, undefined);
|
|
61
|
+
}
|
|
62
|
+
// 2. Resolve the active environment. Call getCurrentEnvironment() directly
|
|
63
|
+
// (not via resolveSyncDir/safeEnv) so a genuinely ambiguous project
|
|
64
|
+
// surfaces the resolver's "No environment selected… Available: …" error
|
|
65
|
+
// with a non-zero exit — unless the caller narrowed the target with
|
|
66
|
+
// --app AND did not name an environment, in which case we fall back to the
|
|
67
|
+
// legacy per-app scan.
|
|
68
|
+
//
|
|
69
|
+
// The `--app`-alone fallback only applies when NO environment was
|
|
70
|
+
// explicitly requested (neither `--env` nor `PRIMITIVE_ENV`). When the
|
|
71
|
+
// user DID name an env but it's invalid/unknown, getCurrentEnvironment()
|
|
72
|
+
// throws; we must surface that error (non-zero exit) rather than silently
|
|
73
|
+
// scanning the app under some OTHER synced environment — that would
|
|
74
|
+
// generate code from the wrong env instead of honoring the explicit
|
|
75
|
+
// selection.
|
|
76
|
+
const explicitEnvRequested = getExplicitEnvName() !== null || !!process.env.PRIMITIVE_ENV;
|
|
77
|
+
let env;
|
|
78
|
+
try {
|
|
79
|
+
env = getCurrentEnvironment();
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
if (options.app && !explicitEnvRequested) {
|
|
83
|
+
return scanSyncTree({ subdir, appId: options.app, cwd });
|
|
84
|
+
}
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
// 3. Project mode: resolve the app id and build the env/app-scoped path.
|
|
88
|
+
if (env) {
|
|
89
|
+
const appId = options.app ?? env.config.appId ?? getCurrentAppId();
|
|
90
|
+
if (!appId) {
|
|
91
|
+
throw new Error(`No app configured for environment "${env.name}" in .primitive/config.json ` +
|
|
92
|
+
`and no --app given. Add "appId" to the environment or pass --app <app-id>.`);
|
|
93
|
+
}
|
|
94
|
+
// resolveSyncDir re-reads the (cached) resolved env and guards appId via
|
|
95
|
+
// assertSafePathComponent, so an unsafe --app is rejected here.
|
|
96
|
+
const dir = join(resolveSyncDir({ appId }), subdir);
|
|
97
|
+
return requireExisting(dir, subdir, appId);
|
|
98
|
+
}
|
|
99
|
+
// 4. Legacy / bare-dir mode (no .primitive/config.json): scan the sync tree,
|
|
100
|
+
// filtered to --app when given. This preserves the pre-#1510 behavior.
|
|
101
|
+
return scanSyncTree({ subdir, appId: options.app, cwd });
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Legacy fallback: scan `<cwd>/.primitive/sync/<env>/<app>/<subdir>` for a
|
|
105
|
+
* source directory. When `appId` is given, only that app's slots are
|
|
106
|
+
* considered. Resolves to the single match; errors clearly on zero or on
|
|
107
|
+
* ambiguity (naming the candidate apps or envs).
|
|
108
|
+
*/
|
|
109
|
+
function scanSyncTree(args) {
|
|
110
|
+
const { subdir, appId, cwd } = args;
|
|
111
|
+
// Defence-in-depth: an --app value flows into a file-system path below, so
|
|
112
|
+
// reject separators / `..` before using it.
|
|
113
|
+
if (appId)
|
|
114
|
+
assertSafePathComponent(appId, "appId");
|
|
115
|
+
const root = join(cwd, ".primitive", "sync");
|
|
116
|
+
const found = [];
|
|
117
|
+
if (existsSync(root)) {
|
|
118
|
+
for (const envName of readdirSync(root)) {
|
|
119
|
+
const envDir = join(root, envName);
|
|
120
|
+
try {
|
|
121
|
+
for (const app of readdirSync(envDir)) {
|
|
122
|
+
if (appId && app !== appId)
|
|
123
|
+
continue;
|
|
124
|
+
const candidate = join(envDir, app, subdir);
|
|
125
|
+
if (existsSync(candidate))
|
|
126
|
+
found.push(candidate);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Not a directory (or unreadable) — skip.
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (found.length === 0) {
|
|
135
|
+
throw new Error(notFoundMessage(subdir, appId));
|
|
136
|
+
}
|
|
137
|
+
if (found.length > 1) {
|
|
138
|
+
if (appId) {
|
|
139
|
+
const envs = [
|
|
140
|
+
...new Set(found.map((d) => basename(dirname(dirname(d))))),
|
|
141
|
+
];
|
|
142
|
+
throw new Error(`App "${appId}" has a ${subdir}/ directory under multiple environments: ` +
|
|
143
|
+
`${envs.join(", ")}.\n` +
|
|
144
|
+
found.map((d) => ` ${d}`).join("\n") +
|
|
145
|
+
`\nPass --env <name> or --sync-dir to select one.`);
|
|
146
|
+
}
|
|
147
|
+
const apps = [...new Set(found.map((d) => basename(dirname(d))))];
|
|
148
|
+
throw new Error(`Found ${subdir}/ directories for more than one app/env:\n` +
|
|
149
|
+
found.map((d) => ` ${d}`).join("\n") +
|
|
150
|
+
`\nCodegen writes into one output dir, so it must run against one app. ` +
|
|
151
|
+
`Pass --app <app-id> (found: ${apps.join(", ")}) or --sync-dir to select one.`);
|
|
152
|
+
}
|
|
153
|
+
return found[0];
|
|
154
|
+
}
|
|
155
|
+
/** Verifies `dir` exists, throwing the standard "no source dir" error otherwise. */
|
|
156
|
+
function requireExisting(dir, subdir, appId) {
|
|
157
|
+
if (!existsSync(dir)) {
|
|
158
|
+
throw new Error(notFoundMessage(subdir, appId));
|
|
159
|
+
}
|
|
160
|
+
return dir;
|
|
161
|
+
}
|
|
162
|
+
function notFoundMessage(subdir, appId) {
|
|
163
|
+
return appId
|
|
164
|
+
? `No ${subdir}/ directory found for app "${appId}" under .primitive/sync/. ` +
|
|
165
|
+
`Check the --app id, pass --sync-dir, or run \`primitive sync pull\` first.`
|
|
166
|
+
: `No ${subdir}/ directory found. Pass --sync-dir or run \`primitive sync pull\` first.`;
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=resolveCodegenSourceDir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveCodegenSourceDir.js","sourceRoot":"","sources":["../../../../src/lib/codegen-shared/resolveCodegenSourceDir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAsB3E;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAiC;IACvE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAEtC,2EAA2E;IAC3E,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAC3E,CAAC;IAED,2EAA2E;IAC3E,uEAAuE;IACvE,2EAA2E;IAC3E,uEAAuE;IACvE,8EAA8E;IAC9E,0BA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0EAA0E,CAAC;AAC7F,CAAC"}
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* `return` step (#1437). This file resolves those into the small descriptors
|
|
20
20
|
* the templates consume; the templates stay pure string-emitters.
|
|
21
21
|
*/
|
|
22
|
+
import { type GeneratedFileMismatch } from "../codegen-shared/generatedFiles.js";
|
|
22
23
|
export interface DbCodegenInput {
|
|
23
24
|
/** Database type name (drives the output filename). */
|
|
24
25
|
databaseType: string;
|
|
@@ -56,15 +57,37 @@ export interface DbCodegenResult {
|
|
|
56
57
|
/** Only populated under `--check`: files whose on-disk content is out of date. */
|
|
57
58
|
mismatches: DbCheckMismatch[];
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Re-exported from the shared generated-file module so existing importers keep
|
|
62
|
+
* a stable type. The write/`--check`/cleanup lifecycle now lives in
|
|
63
|
+
* `codegen-shared/generatedFiles.ts` (shared with `workflows codegen`).
|
|
64
|
+
*/
|
|
65
|
+
export type DbCheckMismatch = GeneratedFileMismatch;
|
|
63
66
|
/**
|
|
64
67
|
* Render the in-memory `.generated.ts` content for a single database-type
|
|
65
68
|
* TOML. Exported so tests can assert on the rendered string directly.
|
|
66
69
|
*/
|
|
67
70
|
export declare function renderDbTypeFile(input: DbCodegenInput): string;
|
|
71
|
+
/**
|
|
72
|
+
* Infer the scalar element TS type for op params consumed by a `$in`/`$nin`
|
|
73
|
+
* filter operator (#1488, Phase 1). Codegen-only: a param compared with
|
|
74
|
+
* `$in`/`$nin` against a model field is definitionally an array, so the
|
|
75
|
+
* typed-ops factory (#1441) should emit `<elem>[]` rather than widening an
|
|
76
|
+
* untyped/object param to `Record<string, unknown>` (which `string[]` is not
|
|
77
|
+
* assignable to).
|
|
78
|
+
*
|
|
79
|
+
* Kept a small local helper next to {@link inferRequiredRecordFields} rather
|
|
80
|
+
* than a shared cross-runtime analysis pass (sponsor decision on #1488).
|
|
81
|
+
*
|
|
82
|
+
* Returns a map of param name → element TS type. The `"unknown"` sentinel means
|
|
83
|
+
* "emit `unknown[]`" — used when the compared field is missing from the model
|
|
84
|
+
* schema (or the op has no resolvable model), when the same param is bound to
|
|
85
|
+
* fields of differing element types, or when the param is also used as a scalar
|
|
86
|
+
* elsewhere (conservative widen, mirroring #845's disagreement rule / #1488
|
|
87
|
+
* Fork 4). A param absent from the map is not consumed by any array operator
|
|
88
|
+
* and keeps its declared-type mapping (inference never widens such a param).
|
|
89
|
+
*/
|
|
90
|
+
export declare function inferArrayParamElementTypes(op: any, fieldTypesByModel: Map<string, Map<string, string>>): Map<string, string>;
|
|
68
91
|
/**
|
|
69
92
|
* Per-model result of {@link inferRequiredRecordFields}. Shaped as an object
|
|
70
93
|
* (rather than a bare `Set`) so it can grow additional inferred metadata later
|
|
@@ -109,6 +132,8 @@ export interface InferredRecordModelInfo {
|
|
|
109
132
|
*/
|
|
110
133
|
export declare function inferRequiredRecordFields(operations: any[]): Map<string, InferredRecordModelInfo>;
|
|
111
134
|
/**
|
|
112
|
-
* Run codegen end-to-end across one or more database-type TOML inputs.
|
|
135
|
+
* Run codegen end-to-end across one or more database-type TOML inputs. The
|
|
136
|
+
* disk lifecycle (write / `--check` / stale cleanup) is delegated to the
|
|
137
|
+
* shared `writeOrCheckGeneratedFiles` (shared with `workflows codegen`).
|
|
113
138
|
*/
|
|
114
139
|
export declare function generateDbTypes(options: GenerateDbTypesOptions): Promise<DbCodegenResult>;
|