@barekey/cli 0.5.9 → 0.7.0
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/barekey.schema.json +85 -0
- package/dist/commands/init.js +1 -0
- package/dist/commands/typegen.js +3 -0
- package/dist/contracts/index.d.ts +3 -0
- package/dist/contracts/index.js +3 -0
- package/dist/runtime-config.d.ts +2 -0
- package/dist/runtime-config.js +2 -0
- package/dist/typegen/core.d.ts +3 -1
- package/dist/typegen/core.js +9 -3
- package/package.json +2 -2
- package/schemas/barekey.schema.json +85 -0
- package/scripts/copy-barekey-schema.mjs +12 -0
- package/src/commands/init.ts +5 -4
- package/src/commands/typegen.ts +4 -0
- package/src/contracts/index.ts +3 -0
- package/src/runtime-config.ts +5 -0
- package/src/typegen/core.ts +17 -2
- package/test/runtime-config.test.ts +61 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://barekey.dev/schemas/barekey.schema.json",
|
|
4
|
+
"title": "Barekey Runtime Config",
|
|
5
|
+
"description": "Configuration file for Barekey CLI and SDK repo-scoped targeting and type generation.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"properties": {
|
|
9
|
+
"$schema": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "Optional JSON Schema reference for editor tooling."
|
|
12
|
+
},
|
|
13
|
+
"organization": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"minLength": 1,
|
|
16
|
+
"description": "Canonical organization slug."
|
|
17
|
+
},
|
|
18
|
+
"org": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"minLength": 1,
|
|
21
|
+
"description": "Legacy alias for organization."
|
|
22
|
+
},
|
|
23
|
+
"project": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"minLength": 1,
|
|
26
|
+
"description": "Project slug."
|
|
27
|
+
},
|
|
28
|
+
"environment": {
|
|
29
|
+
"type": "string",
|
|
30
|
+
"minLength": 1,
|
|
31
|
+
"description": "Canonical stage slug."
|
|
32
|
+
},
|
|
33
|
+
"stage": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"minLength": 1,
|
|
36
|
+
"description": "Legacy alias for environment."
|
|
37
|
+
},
|
|
38
|
+
"typegen": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"enum": ["semantic", "minimal"],
|
|
41
|
+
"description": "Legacy top-level typegen mode."
|
|
42
|
+
},
|
|
43
|
+
"config": {
|
|
44
|
+
"type": "object",
|
|
45
|
+
"additionalProperties": false,
|
|
46
|
+
"properties": {
|
|
47
|
+
"mode": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"enum": ["centralized", "standalone"],
|
|
50
|
+
"default": "centralized",
|
|
51
|
+
"description": "Runtime mode for the SDK and CLI."
|
|
52
|
+
},
|
|
53
|
+
"typegen": {
|
|
54
|
+
"type": "string",
|
|
55
|
+
"enum": ["semantic", "minimal"],
|
|
56
|
+
"default": "semantic",
|
|
57
|
+
"description": "Generated type style."
|
|
58
|
+
},
|
|
59
|
+
"disallow_ambigious_keys": {
|
|
60
|
+
"type": "boolean",
|
|
61
|
+
"default": true,
|
|
62
|
+
"description": "When true, keys missing from generated types are treated as TypeScript errors."
|
|
63
|
+
},
|
|
64
|
+
"strictGeneratedKeys": {
|
|
65
|
+
"type": "boolean",
|
|
66
|
+
"deprecated": true,
|
|
67
|
+
"description": "Legacy name for disallow_ambigious_keys."
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"examples": [
|
|
73
|
+
{
|
|
74
|
+
"$schema": "./node_modules/@barekey/sdk/dist/barekey.schema.json",
|
|
75
|
+
"organization": "acme",
|
|
76
|
+
"project": "web",
|
|
77
|
+
"environment": "development",
|
|
78
|
+
"config": {
|
|
79
|
+
"mode": "centralized",
|
|
80
|
+
"typegen": "semantic",
|
|
81
|
+
"disallow_ambigious_keys": true
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
package/dist/commands/init.js
CHANGED
package/dist/commands/typegen.js
CHANGED
|
@@ -55,6 +55,7 @@ async function resolveTypegenContext(options) {
|
|
|
55
55
|
environment: target.stageSlug.trim().length > 0 ? target.stageSlug : "local",
|
|
56
56
|
runtimeMode: runtime?.config.config?.mode ?? "centralized",
|
|
57
57
|
typegenMode: runtime?.config.config?.typegen ?? "semantic",
|
|
58
|
+
disallowAmbigiousKeys: runtime?.config.config?.disallowAmbigiousKeys ?? true,
|
|
58
59
|
localEnvRoot: runtime?.path ?? null,
|
|
59
60
|
};
|
|
60
61
|
}
|
|
@@ -87,6 +88,7 @@ async function runTypegen(options) {
|
|
|
87
88
|
projectSlug: context.project,
|
|
88
89
|
stageSlug: context.environment,
|
|
89
90
|
typegenMode: context.typegenMode,
|
|
91
|
+
disallowAmbigiousKeys: context.disallowAmbigiousKeys,
|
|
90
92
|
runtimeMode: context.runtimeMode,
|
|
91
93
|
localEnvRoot: context.localEnvRoot,
|
|
92
94
|
});
|
|
@@ -117,6 +119,7 @@ async function runTypegenWatch(options) {
|
|
|
117
119
|
projectSlug: nextContext.project,
|
|
118
120
|
stageSlug: nextContext.environment,
|
|
119
121
|
typegenMode: nextContext.typegenMode,
|
|
122
|
+
disallowAmbigiousKeys: nextContext.disallowAmbigiousKeys,
|
|
120
123
|
runtimeMode: nextContext.runtimeMode,
|
|
121
124
|
localEnvRoot: nextContext.localEnvRoot,
|
|
122
125
|
});
|
|
@@ -5,6 +5,7 @@ export declare const RolloutFunctionSchema: Schema.Literal<["linear", "step", "e
|
|
|
5
5
|
export declare const RuntimeModeSchema: Schema.Literal<["centralized", "standalone"]>;
|
|
6
6
|
export declare const TypegenModeSchema: Schema.Literal<["semantic", "minimal"]>;
|
|
7
7
|
export declare const RuntimeConfigSchema: Schema.Struct<{
|
|
8
|
+
$schema: Schema.optional<Schema.NullOr<typeof Schema.String>>;
|
|
8
9
|
organization: Schema.optional<Schema.NullOr<typeof Schema.String>>;
|
|
9
10
|
org: Schema.optional<Schema.NullOr<typeof Schema.String>>;
|
|
10
11
|
project: Schema.optional<Schema.NullOr<typeof Schema.String>>;
|
|
@@ -13,6 +14,8 @@ export declare const RuntimeConfigSchema: Schema.Struct<{
|
|
|
13
14
|
typegen: Schema.optional<Schema.NullOr<Schema.Literal<["semantic", "minimal"]>>>;
|
|
14
15
|
config: Schema.optional<Schema.Struct<{
|
|
15
16
|
typegen: Schema.optional<Schema.Literal<["semantic", "minimal"]>>;
|
|
17
|
+
disallow_ambigious_keys: Schema.optional<typeof Schema.Boolean>;
|
|
18
|
+
strictGeneratedKeys: Schema.optional<typeof Schema.Boolean>;
|
|
16
19
|
mode: Schema.optional<Schema.Literal<["centralized", "standalone"]>>;
|
|
17
20
|
}>>;
|
|
18
21
|
}>;
|
package/dist/contracts/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export const TypegenModeSchema = Schema.Literal("semantic", "minimal");
|
|
|
7
7
|
const TrimmedStringSchema = Schema.String;
|
|
8
8
|
const NonEmptyStringSchema = Schema.String.pipe(Schema.minLength(1));
|
|
9
9
|
export const RuntimeConfigSchema = Schema.Struct({
|
|
10
|
+
$schema: Schema.optional(Schema.NullOr(TrimmedStringSchema)),
|
|
10
11
|
organization: Schema.optional(Schema.NullOr(TrimmedStringSchema)),
|
|
11
12
|
org: Schema.optional(Schema.NullOr(TrimmedStringSchema)),
|
|
12
13
|
project: Schema.optional(Schema.NullOr(TrimmedStringSchema)),
|
|
@@ -15,6 +16,8 @@ export const RuntimeConfigSchema = Schema.Struct({
|
|
|
15
16
|
typegen: Schema.optional(Schema.NullOr(TypegenModeSchema)),
|
|
16
17
|
config: Schema.optional(Schema.Struct({
|
|
17
18
|
typegen: Schema.optional(TypegenModeSchema),
|
|
19
|
+
disallow_ambigious_keys: Schema.optional(Schema.Boolean),
|
|
20
|
+
strictGeneratedKeys: Schema.optional(Schema.Boolean),
|
|
18
21
|
mode: Schema.optional(RuntimeModeSchema),
|
|
19
22
|
})),
|
|
20
23
|
});
|
package/dist/runtime-config.d.ts
CHANGED
package/dist/runtime-config.js
CHANGED
|
@@ -39,6 +39,7 @@ export async function loadRuntimeConfig() {
|
|
|
39
39
|
const config = decoded.right.config;
|
|
40
40
|
const mode = config?.mode ?? "centralized";
|
|
41
41
|
const typegen = mode === "standalone" ? "minimal" : (config?.typegen ?? decoded.right.typegen ?? "semantic");
|
|
42
|
+
const disallowAmbigiousKeys = config?.disallow_ambigious_keys ?? config?.strictGeneratedKeys ?? true;
|
|
42
43
|
return {
|
|
43
44
|
path: configPath,
|
|
44
45
|
config: {
|
|
@@ -48,6 +49,7 @@ export async function loadRuntimeConfig() {
|
|
|
48
49
|
config: {
|
|
49
50
|
mode,
|
|
50
51
|
typegen,
|
|
52
|
+
disallowAmbigiousKeys,
|
|
51
53
|
},
|
|
52
54
|
},
|
|
53
55
|
};
|
package/dist/typegen/core.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type TypegenManifest } from "../contracts/index.js";
|
|
2
2
|
export type CliTypegenMode = "semantic" | "minimal";
|
|
3
3
|
export type CliRuntimeMode = "centralized" | "standalone";
|
|
4
|
+
export type CliDisallowAmbigiousKeys = boolean;
|
|
4
5
|
export type CliTypegenResult = {
|
|
5
6
|
written: boolean;
|
|
6
7
|
path: string;
|
|
@@ -14,6 +15,7 @@ type TypegenIdentity = {
|
|
|
14
15
|
projectSlug: string;
|
|
15
16
|
stageSlug: string;
|
|
16
17
|
typegenMode: CliTypegenMode;
|
|
18
|
+
disallowAmbigiousKeys: CliDisallowAmbigiousKeys;
|
|
17
19
|
runtimeMode: CliRuntimeMode;
|
|
18
20
|
localEnvRoot: string | null;
|
|
19
21
|
};
|
|
@@ -27,7 +29,7 @@ type TypegenIdentity = {
|
|
|
27
29
|
* @lastModified 2026-03-19
|
|
28
30
|
* @author GPT-5.4
|
|
29
31
|
*/
|
|
30
|
-
export declare function renderGeneratedTypesForManifest(manifest: TypegenManifest, mode: CliTypegenMode): {
|
|
32
|
+
export declare function renderGeneratedTypesForManifest(manifest: TypegenManifest, mode: CliTypegenMode, disallowAmbigiousKeys?: boolean): {
|
|
31
33
|
serverContents: string;
|
|
32
34
|
publicContents: string;
|
|
33
35
|
};
|
package/dist/typegen/core.js
CHANGED
|
@@ -12,6 +12,7 @@ const TypegenMetadataSchema = Schema.Struct({
|
|
|
12
12
|
projectSlug: Schema.NullOr(Schema.String),
|
|
13
13
|
stageSlug: Schema.NullOr(Schema.String),
|
|
14
14
|
typegenMode: Schema.NullOr(Schema.Literal("semantic", "minimal")),
|
|
15
|
+
disallowAmbigiousKeys: Schema.Boolean,
|
|
15
16
|
runtimeMode: Schema.NullOr(Schema.Literal("centralized", "standalone")),
|
|
16
17
|
localEnvRoot: Schema.NullOr(Schema.String),
|
|
17
18
|
});
|
|
@@ -50,7 +51,7 @@ function buildGeneratedTypesContents(manifest, input) {
|
|
|
50
51
|
const importLine = input.mode === "semantic"
|
|
51
52
|
? `import type { EaseInOut, Env, Linear, Step } from "${input.typeModulePath}";\n\n`
|
|
52
53
|
: "";
|
|
53
|
-
return `/* eslint-disable */\n/* This file is generated by barekey typegen. */\n/* barekey-manifest-version: ${manifest.manifestVersion} */\n\n${importLine}declare module "${input.declaredModulePath}" {\n interface ${input.interfaceName} {\n${mapLines.length > 0 ? mapLines : ""}\n }\n}\n\nexport {};\n`;
|
|
54
|
+
return `/* eslint-disable */\n/* This file is generated by barekey typegen. */\n/* barekey-manifest-version: ${manifest.manifestVersion} */\n\n${importLine}declare module "${input.declaredModulePath}" {\n interface ${input.interfaceName} {\n${mapLines.length > 0 ? mapLines : ""}\n }\n\n interface ${input.configInterfaceName} {\n allowUnknownKeys: ${input.disallowAmbigiousKeys ? "false" : "true"};\n }\n}\n\nexport {};\n`;
|
|
54
55
|
}
|
|
55
56
|
function readManifestVersion(contents) {
|
|
56
57
|
return contents?.match(MANIFEST_VERSION_PATTERN)?.[1]?.trim() ?? null;
|
|
@@ -132,6 +133,7 @@ function buildTypegenMetadataContents(lastGeneratedAt, identity) {
|
|
|
132
133
|
projectSlug: identity.projectSlug,
|
|
133
134
|
stageSlug: identity.stageSlug,
|
|
134
135
|
typegenMode: identity.typegenMode,
|
|
136
|
+
disallowAmbigiousKeys: identity.disallowAmbigiousKeys,
|
|
135
137
|
runtimeMode: identity.runtimeMode,
|
|
136
138
|
localEnvRoot: identity.localEnvRoot,
|
|
137
139
|
}, null, 2)}\n`;
|
|
@@ -146,21 +148,25 @@ function buildTypegenMetadataContents(lastGeneratedAt, identity) {
|
|
|
146
148
|
* @lastModified 2026-03-19
|
|
147
149
|
* @author GPT-5.4
|
|
148
150
|
*/
|
|
149
|
-
export function renderGeneratedTypesForManifest(manifest, mode) {
|
|
151
|
+
export function renderGeneratedTypesForManifest(manifest, mode, disallowAmbigiousKeys = true) {
|
|
150
152
|
const decodedManifest = Schema.decodeUnknownSync(TypegenManifestSchema)(manifest);
|
|
151
153
|
return {
|
|
152
154
|
serverContents: buildGeneratedTypesContents(decodedManifest, {
|
|
153
155
|
mode,
|
|
156
|
+
disallowAmbigiousKeys,
|
|
154
157
|
typeModulePath: "./dist/types.js",
|
|
155
158
|
declaredModulePath: "./dist/types.js",
|
|
156
159
|
interfaceName: "BarekeyGeneratedTypeMap",
|
|
160
|
+
configInterfaceName: "BarekeyGeneratedTypeConfig",
|
|
157
161
|
include: () => true,
|
|
158
162
|
}),
|
|
159
163
|
publicContents: buildGeneratedTypesContents(decodedManifest, {
|
|
160
164
|
mode,
|
|
165
|
+
disallowAmbigiousKeys,
|
|
161
166
|
typeModulePath: "./dist/public-types.js",
|
|
162
167
|
declaredModulePath: "./dist/public-types.js",
|
|
163
168
|
interfaceName: "BarekeyPublicGeneratedTypeMap",
|
|
169
|
+
configInterfaceName: "BarekeyPublicGeneratedTypeConfig",
|
|
164
170
|
include: (row) => row.visibility === "public",
|
|
165
171
|
}),
|
|
166
172
|
};
|
|
@@ -190,7 +196,7 @@ export async function writeInstalledSdkGeneratedTypes(manifest, identity) {
|
|
|
190
196
|
readTextFile(target.serverGeneratedTypesPath),
|
|
191
197
|
readTextFile(target.publicGeneratedTypesPath),
|
|
192
198
|
]);
|
|
193
|
-
const rendered = renderGeneratedTypesForManifest(manifest, identity.typegenMode);
|
|
199
|
+
const rendered = renderGeneratedTypesForManifest(manifest, identity.typegenMode, identity.disallowAmbigiousKeys);
|
|
194
200
|
if (existingServerContents === rendered.serverContents &&
|
|
195
201
|
existingPublicContents === rendered.publicContents &&
|
|
196
202
|
readManifestVersion(existingServerContents) === manifest.manifestVersion &&
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barekey/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Barekey command line interface",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"barekey": "./dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "tsc -p tsconfig.json",
|
|
10
|
+
"build": "tsc -p tsconfig.json && node scripts/copy-barekey-schema.mjs",
|
|
11
11
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
12
12
|
"test": "bun test test",
|
|
13
13
|
"start": "node dist/index.js"
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://barekey.dev/schemas/barekey.schema.json",
|
|
4
|
+
"title": "Barekey Runtime Config",
|
|
5
|
+
"description": "Configuration file for Barekey CLI and SDK repo-scoped targeting and type generation.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"properties": {
|
|
9
|
+
"$schema": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "Optional JSON Schema reference for editor tooling."
|
|
12
|
+
},
|
|
13
|
+
"organization": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"minLength": 1,
|
|
16
|
+
"description": "Canonical organization slug."
|
|
17
|
+
},
|
|
18
|
+
"org": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"minLength": 1,
|
|
21
|
+
"description": "Legacy alias for organization."
|
|
22
|
+
},
|
|
23
|
+
"project": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"minLength": 1,
|
|
26
|
+
"description": "Project slug."
|
|
27
|
+
},
|
|
28
|
+
"environment": {
|
|
29
|
+
"type": "string",
|
|
30
|
+
"minLength": 1,
|
|
31
|
+
"description": "Canonical stage slug."
|
|
32
|
+
},
|
|
33
|
+
"stage": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"minLength": 1,
|
|
36
|
+
"description": "Legacy alias for environment."
|
|
37
|
+
},
|
|
38
|
+
"typegen": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"enum": ["semantic", "minimal"],
|
|
41
|
+
"description": "Legacy top-level typegen mode."
|
|
42
|
+
},
|
|
43
|
+
"config": {
|
|
44
|
+
"type": "object",
|
|
45
|
+
"additionalProperties": false,
|
|
46
|
+
"properties": {
|
|
47
|
+
"mode": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"enum": ["centralized", "standalone"],
|
|
50
|
+
"default": "centralized",
|
|
51
|
+
"description": "Runtime mode for the SDK and CLI."
|
|
52
|
+
},
|
|
53
|
+
"typegen": {
|
|
54
|
+
"type": "string",
|
|
55
|
+
"enum": ["semantic", "minimal"],
|
|
56
|
+
"default": "semantic",
|
|
57
|
+
"description": "Generated type style."
|
|
58
|
+
},
|
|
59
|
+
"disallow_ambigious_keys": {
|
|
60
|
+
"type": "boolean",
|
|
61
|
+
"default": true,
|
|
62
|
+
"description": "When true, keys missing from generated types are treated as TypeScript errors."
|
|
63
|
+
},
|
|
64
|
+
"strictGeneratedKeys": {
|
|
65
|
+
"type": "boolean",
|
|
66
|
+
"deprecated": true,
|
|
67
|
+
"description": "Legacy name for disallow_ambigious_keys."
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"examples": [
|
|
73
|
+
{
|
|
74
|
+
"$schema": "./node_modules/@barekey/sdk/dist/barekey.schema.json",
|
|
75
|
+
"organization": "acme",
|
|
76
|
+
"project": "web",
|
|
77
|
+
"environment": "development",
|
|
78
|
+
"config": {
|
|
79
|
+
"mode": "centralized",
|
|
80
|
+
"typegen": "semantic",
|
|
81
|
+
"disallow_ambigious_keys": true
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { copyFile, mkdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const projectRoot = path.resolve(__dirname, "..");
|
|
7
|
+
const sourcePath = path.join(projectRoot, "schemas", "barekey.schema.json");
|
|
8
|
+
const distDirectory = path.join(projectRoot, "dist");
|
|
9
|
+
const destinationPath = path.join(distDirectory, "barekey.schema.json");
|
|
10
|
+
|
|
11
|
+
await mkdir(distDirectory, { recursive: true });
|
|
12
|
+
await copyFile(sourcePath, destinationPath);
|
package/src/commands/init.ts
CHANGED
|
@@ -21,10 +21,11 @@ async function runInit(options: EnvTargetOptions & { path?: string }) {
|
|
|
21
21
|
organization: orgSlug,
|
|
22
22
|
project: projectSlug,
|
|
23
23
|
environment: stageSlug,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
config: {
|
|
25
|
+
mode: "centralized",
|
|
26
|
+
typegen: "semantic",
|
|
27
|
+
disallow_ambigious_keys: true,
|
|
28
|
+
},
|
|
28
29
|
},
|
|
29
30
|
null,
|
|
30
31
|
2,
|
package/src/commands/typegen.ts
CHANGED
|
@@ -74,6 +74,7 @@ async function resolveTypegenContext(options: EnvTargetOptions): Promise<{
|
|
|
74
74
|
environment: string;
|
|
75
75
|
runtimeMode: "centralized" | "standalone";
|
|
76
76
|
typegenMode: "semantic" | "minimal";
|
|
77
|
+
disallowAmbigiousKeys: boolean;
|
|
77
78
|
localEnvRoot: string | null;
|
|
78
79
|
}> {
|
|
79
80
|
const runtime = await loadRuntimeConfig();
|
|
@@ -89,6 +90,7 @@ async function resolveTypegenContext(options: EnvTargetOptions): Promise<{
|
|
|
89
90
|
environment: target.stageSlug.trim().length > 0 ? target.stageSlug : "local",
|
|
90
91
|
runtimeMode: runtime?.config.config?.mode ?? "centralized",
|
|
91
92
|
typegenMode: runtime?.config.config?.typegen ?? "semantic",
|
|
93
|
+
disallowAmbigiousKeys: runtime?.config.config?.disallowAmbigiousKeys ?? true,
|
|
92
94
|
localEnvRoot: runtime?.path ?? null,
|
|
93
95
|
};
|
|
94
96
|
}
|
|
@@ -126,6 +128,7 @@ async function runTypegen(options: EnvTargetOptions): Promise<void> {
|
|
|
126
128
|
projectSlug: context.project,
|
|
127
129
|
stageSlug: context.environment,
|
|
128
130
|
typegenMode: context.typegenMode,
|
|
131
|
+
disallowAmbigiousKeys: context.disallowAmbigiousKeys,
|
|
129
132
|
runtimeMode: context.runtimeMode,
|
|
130
133
|
localEnvRoot: context.localEnvRoot,
|
|
131
134
|
});
|
|
@@ -167,6 +170,7 @@ async function runTypegenWatch(
|
|
|
167
170
|
projectSlug: nextContext.project,
|
|
168
171
|
stageSlug: nextContext.environment,
|
|
169
172
|
typegenMode: nextContext.typegenMode,
|
|
173
|
+
disallowAmbigiousKeys: nextContext.disallowAmbigiousKeys,
|
|
170
174
|
runtimeMode: nextContext.runtimeMode,
|
|
171
175
|
localEnvRoot: nextContext.localEnvRoot,
|
|
172
176
|
});
|
package/src/contracts/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ const TrimmedStringSchema = Schema.String;
|
|
|
17
17
|
const NonEmptyStringSchema = Schema.String.pipe(Schema.minLength(1));
|
|
18
18
|
|
|
19
19
|
export const RuntimeConfigSchema = Schema.Struct({
|
|
20
|
+
$schema: Schema.optional(Schema.NullOr(TrimmedStringSchema)),
|
|
20
21
|
organization: Schema.optional(Schema.NullOr(TrimmedStringSchema)),
|
|
21
22
|
org: Schema.optional(Schema.NullOr(TrimmedStringSchema)),
|
|
22
23
|
project: Schema.optional(Schema.NullOr(TrimmedStringSchema)),
|
|
@@ -26,6 +27,8 @@ export const RuntimeConfigSchema = Schema.Struct({
|
|
|
26
27
|
config: Schema.optional(
|
|
27
28
|
Schema.Struct({
|
|
28
29
|
typegen: Schema.optional(TypegenModeSchema),
|
|
30
|
+
disallow_ambigious_keys: Schema.optional(Schema.Boolean),
|
|
31
|
+
strictGeneratedKeys: Schema.optional(Schema.Boolean),
|
|
29
32
|
mode: Schema.optional(RuntimeModeSchema),
|
|
30
33
|
}),
|
|
31
34
|
),
|
package/src/runtime-config.ts
CHANGED
|
@@ -5,11 +5,13 @@ import { Either, Schema } from "effect";
|
|
|
5
5
|
import { RuntimeConfigSchema } from "./contracts/index.js";
|
|
6
6
|
|
|
7
7
|
export type BarekeyRuntimeConfig = {
|
|
8
|
+
$schema?: string;
|
|
8
9
|
org?: string;
|
|
9
10
|
project?: string;
|
|
10
11
|
environment?: string;
|
|
11
12
|
config?: {
|
|
12
13
|
typegen?: "semantic" | "minimal";
|
|
14
|
+
disallowAmbigiousKeys?: boolean;
|
|
13
15
|
mode?: "centralized" | "standalone";
|
|
14
16
|
};
|
|
15
17
|
};
|
|
@@ -61,6 +63,8 @@ export async function loadRuntimeConfig(): Promise<BarekeyRuntimeConfigResult |
|
|
|
61
63
|
const mode = config?.mode ?? "centralized";
|
|
62
64
|
const typegen =
|
|
63
65
|
mode === "standalone" ? "minimal" : (config?.typegen ?? decoded.right.typegen ?? "semantic");
|
|
66
|
+
const disallowAmbigiousKeys =
|
|
67
|
+
config?.disallow_ambigious_keys ?? config?.strictGeneratedKeys ?? true;
|
|
64
68
|
|
|
65
69
|
return {
|
|
66
70
|
path: configPath,
|
|
@@ -71,6 +75,7 @@ export async function loadRuntimeConfig(): Promise<BarekeyRuntimeConfigResult |
|
|
|
71
75
|
config: {
|
|
72
76
|
mode,
|
|
73
77
|
typegen,
|
|
78
|
+
disallowAmbigiousKeys,
|
|
74
79
|
},
|
|
75
80
|
},
|
|
76
81
|
};
|
package/src/typegen/core.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { TypegenManifestSchema, type TypegenManifest } from "../contracts/index.
|
|
|
8
8
|
|
|
9
9
|
export type CliTypegenMode = "semantic" | "minimal";
|
|
10
10
|
export type CliRuntimeMode = "centralized" | "standalone";
|
|
11
|
+
export type CliDisallowAmbigiousKeys = boolean;
|
|
11
12
|
|
|
12
13
|
export type CliTypegenResult = {
|
|
13
14
|
written: boolean;
|
|
@@ -23,6 +24,7 @@ type TypegenIdentity = {
|
|
|
23
24
|
projectSlug: string;
|
|
24
25
|
stageSlug: string;
|
|
25
26
|
typegenMode: CliTypegenMode;
|
|
27
|
+
disallowAmbigiousKeys: CliDisallowAmbigiousKeys;
|
|
26
28
|
runtimeMode: CliRuntimeMode;
|
|
27
29
|
localEnvRoot: string | null;
|
|
28
30
|
};
|
|
@@ -37,6 +39,7 @@ const TypegenMetadataSchema = Schema.Struct({
|
|
|
37
39
|
projectSlug: Schema.NullOr(Schema.String),
|
|
38
40
|
stageSlug: Schema.NullOr(Schema.String),
|
|
39
41
|
typegenMode: Schema.NullOr(Schema.Literal("semantic", "minimal")),
|
|
42
|
+
disallowAmbigiousKeys: Schema.Boolean,
|
|
40
43
|
runtimeMode: Schema.NullOr(Schema.Literal("centralized", "standalone")),
|
|
41
44
|
localEnvRoot: Schema.NullOr(Schema.String),
|
|
42
45
|
});
|
|
@@ -93,9 +96,11 @@ function buildGeneratedTypesContents(
|
|
|
93
96
|
manifest: TypegenManifest,
|
|
94
97
|
input: {
|
|
95
98
|
mode: CliTypegenMode;
|
|
99
|
+
disallowAmbigiousKeys: CliDisallowAmbigiousKeys;
|
|
96
100
|
typeModulePath: "./dist/types.js" | "./dist/public-types.js";
|
|
97
101
|
declaredModulePath: "./dist/types.js" | "./dist/public-types.js";
|
|
98
102
|
interfaceName: "BarekeyGeneratedTypeMap" | "BarekeyPublicGeneratedTypeMap";
|
|
103
|
+
configInterfaceName: "BarekeyGeneratedTypeConfig" | "BarekeyPublicGeneratedTypeConfig";
|
|
99
104
|
include: (row: TypegenManifest["variables"][number]) => boolean;
|
|
100
105
|
},
|
|
101
106
|
): string {
|
|
@@ -111,7 +116,7 @@ function buildGeneratedTypesContents(
|
|
|
111
116
|
? `import type { EaseInOut, Env, Linear, Step } from "${input.typeModulePath}";\n\n`
|
|
112
117
|
: "";
|
|
113
118
|
|
|
114
|
-
return `/* eslint-disable */\n/* This file is generated by barekey typegen. */\n/* barekey-manifest-version: ${manifest.manifestVersion} */\n\n${importLine}declare module "${input.declaredModulePath}" {\n interface ${input.interfaceName} {\n${mapLines.length > 0 ? mapLines : ""}\n }\n}\n\nexport {};\n`;
|
|
119
|
+
return `/* eslint-disable */\n/* This file is generated by barekey typegen. */\n/* barekey-manifest-version: ${manifest.manifestVersion} */\n\n${importLine}declare module "${input.declaredModulePath}" {\n interface ${input.interfaceName} {\n${mapLines.length > 0 ? mapLines : ""}\n }\n\n interface ${input.configInterfaceName} {\n allowUnknownKeys: ${input.disallowAmbigiousKeys ? "false" : "true"};\n }\n}\n\nexport {};\n`;
|
|
115
120
|
}
|
|
116
121
|
|
|
117
122
|
function readManifestVersion(contents: string | null): string | null {
|
|
@@ -197,6 +202,7 @@ function buildTypegenMetadataContents(lastGeneratedAt: Date, identity: TypegenId
|
|
|
197
202
|
projectSlug: identity.projectSlug,
|
|
198
203
|
stageSlug: identity.stageSlug,
|
|
199
204
|
typegenMode: identity.typegenMode,
|
|
205
|
+
disallowAmbigiousKeys: identity.disallowAmbigiousKeys,
|
|
200
206
|
runtimeMode: identity.runtimeMode,
|
|
201
207
|
localEnvRoot: identity.localEnvRoot,
|
|
202
208
|
},
|
|
@@ -218,6 +224,7 @@ function buildTypegenMetadataContents(lastGeneratedAt: Date, identity: TypegenId
|
|
|
218
224
|
export function renderGeneratedTypesForManifest(
|
|
219
225
|
manifest: TypegenManifest,
|
|
220
226
|
mode: CliTypegenMode,
|
|
227
|
+
disallowAmbigiousKeys = true,
|
|
221
228
|
): {
|
|
222
229
|
serverContents: string;
|
|
223
230
|
publicContents: string;
|
|
@@ -227,16 +234,20 @@ export function renderGeneratedTypesForManifest(
|
|
|
227
234
|
return {
|
|
228
235
|
serverContents: buildGeneratedTypesContents(decodedManifest, {
|
|
229
236
|
mode,
|
|
237
|
+
disallowAmbigiousKeys,
|
|
230
238
|
typeModulePath: "./dist/types.js",
|
|
231
239
|
declaredModulePath: "./dist/types.js",
|
|
232
240
|
interfaceName: "BarekeyGeneratedTypeMap",
|
|
241
|
+
configInterfaceName: "BarekeyGeneratedTypeConfig",
|
|
233
242
|
include: () => true,
|
|
234
243
|
}),
|
|
235
244
|
publicContents: buildGeneratedTypesContents(decodedManifest, {
|
|
236
245
|
mode,
|
|
246
|
+
disallowAmbigiousKeys,
|
|
237
247
|
typeModulePath: "./dist/public-types.js",
|
|
238
248
|
declaredModulePath: "./dist/public-types.js",
|
|
239
249
|
interfaceName: "BarekeyPublicGeneratedTypeMap",
|
|
250
|
+
configInterfaceName: "BarekeyPublicGeneratedTypeConfig",
|
|
240
251
|
include: (row) => row.visibility === "public",
|
|
241
252
|
}),
|
|
242
253
|
};
|
|
@@ -271,7 +282,11 @@ export async function writeInstalledSdkGeneratedTypes(
|
|
|
271
282
|
readTextFile(target.serverGeneratedTypesPath),
|
|
272
283
|
readTextFile(target.publicGeneratedTypesPath),
|
|
273
284
|
]);
|
|
274
|
-
const rendered = renderGeneratedTypesForManifest(
|
|
285
|
+
const rendered = renderGeneratedTypesForManifest(
|
|
286
|
+
manifest,
|
|
287
|
+
identity.typegenMode,
|
|
288
|
+
identity.disallowAmbigiousKeys,
|
|
289
|
+
);
|
|
275
290
|
|
|
276
291
|
if (
|
|
277
292
|
existingServerContents === rendered.serverContents &&
|
|
@@ -86,6 +86,67 @@ describe("loadRuntimeConfig", () => {
|
|
|
86
86
|
config: {
|
|
87
87
|
mode: "centralized",
|
|
88
88
|
typegen: "semantic",
|
|
89
|
+
disallowAmbigiousKeys: true,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("reads config.disallow_ambigious_keys when present", async () => {
|
|
97
|
+
const tempDir = await createTempDir();
|
|
98
|
+
await writeFile(
|
|
99
|
+
path.join(tempDir, "barekey.json"),
|
|
100
|
+
JSON.stringify(
|
|
101
|
+
{
|
|
102
|
+
organization: "acme",
|
|
103
|
+
project: "api",
|
|
104
|
+
environment: "development",
|
|
105
|
+
config: {
|
|
106
|
+
disallow_ambigious_keys: false,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
null,
|
|
110
|
+
2,
|
|
111
|
+
),
|
|
112
|
+
"utf8",
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
await withWorkingDirectory(tempDir, async () => {
|
|
116
|
+
await expect(loadRuntimeConfig()).resolves.toMatchObject({
|
|
117
|
+
config: {
|
|
118
|
+
config: {
|
|
119
|
+
disallowAmbigiousKeys: false,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("keeps reading legacy config.strictGeneratedKeys for compatibility", async () => {
|
|
127
|
+
const tempDir = await createTempDir();
|
|
128
|
+
await writeFile(
|
|
129
|
+
path.join(tempDir, "barekey.json"),
|
|
130
|
+
JSON.stringify(
|
|
131
|
+
{
|
|
132
|
+
organization: "acme",
|
|
133
|
+
project: "api",
|
|
134
|
+
environment: "development",
|
|
135
|
+
config: {
|
|
136
|
+
strictGeneratedKeys: false,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
null,
|
|
140
|
+
2,
|
|
141
|
+
),
|
|
142
|
+
"utf8",
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
await withWorkingDirectory(tempDir, async () => {
|
|
146
|
+
await expect(loadRuntimeConfig()).resolves.toMatchObject({
|
|
147
|
+
config: {
|
|
148
|
+
config: {
|
|
149
|
+
disallowAmbigiousKeys: false,
|
|
89
150
|
},
|
|
90
151
|
},
|
|
91
152
|
});
|