@barekey/cli 0.6.0 → 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 -1
- package/dist/commands/typegen.js +3 -3
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.js +2 -0
- package/dist/runtime-config.d.ts +2 -1
- package/dist/runtime-config.js +2 -2
- package/dist/typegen/core.d.ts +3 -3
- package/dist/typegen/core.js +7 -7
- 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 +1 -1
- package/src/commands/typegen.ts +4 -4
- package/src/contracts/index.ts +2 -0
- package/src/runtime-config.ts +5 -3
- package/src/typegen/core.ts +10 -10
- package/test/runtime-config.test.ts +34 -4
|
@@ -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,7 +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
|
-
|
|
58
|
+
disallowAmbigiousKeys: runtime?.config.config?.disallowAmbigiousKeys ?? true,
|
|
59
59
|
localEnvRoot: runtime?.path ?? null,
|
|
60
60
|
};
|
|
61
61
|
}
|
|
@@ -88,7 +88,7 @@ async function runTypegen(options) {
|
|
|
88
88
|
projectSlug: context.project,
|
|
89
89
|
stageSlug: context.environment,
|
|
90
90
|
typegenMode: context.typegenMode,
|
|
91
|
-
|
|
91
|
+
disallowAmbigiousKeys: context.disallowAmbigiousKeys,
|
|
92
92
|
runtimeMode: context.runtimeMode,
|
|
93
93
|
localEnvRoot: context.localEnvRoot,
|
|
94
94
|
});
|
|
@@ -119,7 +119,7 @@ async function runTypegenWatch(options) {
|
|
|
119
119
|
projectSlug: nextContext.project,
|
|
120
120
|
stageSlug: nextContext.environment,
|
|
121
121
|
typegenMode: nextContext.typegenMode,
|
|
122
|
-
|
|
122
|
+
disallowAmbigiousKeys: nextContext.disallowAmbigiousKeys,
|
|
123
123
|
runtimeMode: nextContext.runtimeMode,
|
|
124
124
|
localEnvRoot: nextContext.localEnvRoot,
|
|
125
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,7 @@ 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>;
|
|
16
18
|
strictGeneratedKeys: Schema.optional<typeof Schema.Boolean>;
|
|
17
19
|
mode: Schema.optional<Schema.Literal<["centralized", "standalone"]>>;
|
|
18
20
|
}>>;
|
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,7 @@ 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),
|
|
18
20
|
strictGeneratedKeys: Schema.optional(Schema.Boolean),
|
|
19
21
|
mode: Schema.optional(RuntimeModeSchema),
|
|
20
22
|
})),
|
package/dist/runtime-config.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export type BarekeyRuntimeConfig = {
|
|
2
|
+
$schema?: string;
|
|
2
3
|
org?: string;
|
|
3
4
|
project?: string;
|
|
4
5
|
environment?: string;
|
|
5
6
|
config?: {
|
|
6
7
|
typegen?: "semantic" | "minimal";
|
|
7
|
-
|
|
8
|
+
disallowAmbigiousKeys?: boolean;
|
|
8
9
|
mode?: "centralized" | "standalone";
|
|
9
10
|
};
|
|
10
11
|
};
|
package/dist/runtime-config.js
CHANGED
|
@@ -39,7 +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
|
|
42
|
+
const disallowAmbigiousKeys = config?.disallow_ambigious_keys ?? config?.strictGeneratedKeys ?? true;
|
|
43
43
|
return {
|
|
44
44
|
path: configPath,
|
|
45
45
|
config: {
|
|
@@ -49,7 +49,7 @@ export async function loadRuntimeConfig() {
|
|
|
49
49
|
config: {
|
|
50
50
|
mode,
|
|
51
51
|
typegen,
|
|
52
|
-
|
|
52
|
+
disallowAmbigiousKeys,
|
|
53
53
|
},
|
|
54
54
|
},
|
|
55
55
|
};
|
package/dist/typegen/core.d.ts
CHANGED
|
@@ -1,7 +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
|
|
4
|
+
export type CliDisallowAmbigiousKeys = boolean;
|
|
5
5
|
export type CliTypegenResult = {
|
|
6
6
|
written: boolean;
|
|
7
7
|
path: string;
|
|
@@ -15,7 +15,7 @@ type TypegenIdentity = {
|
|
|
15
15
|
projectSlug: string;
|
|
16
16
|
stageSlug: string;
|
|
17
17
|
typegenMode: CliTypegenMode;
|
|
18
|
-
|
|
18
|
+
disallowAmbigiousKeys: CliDisallowAmbigiousKeys;
|
|
19
19
|
runtimeMode: CliRuntimeMode;
|
|
20
20
|
localEnvRoot: string | null;
|
|
21
21
|
};
|
|
@@ -29,7 +29,7 @@ type TypegenIdentity = {
|
|
|
29
29
|
* @lastModified 2026-03-19
|
|
30
30
|
* @author GPT-5.4
|
|
31
31
|
*/
|
|
32
|
-
export declare function renderGeneratedTypesForManifest(manifest: TypegenManifest, mode: CliTypegenMode,
|
|
32
|
+
export declare function renderGeneratedTypesForManifest(manifest: TypegenManifest, mode: CliTypegenMode, disallowAmbigiousKeys?: boolean): {
|
|
33
33
|
serverContents: string;
|
|
34
34
|
publicContents: string;
|
|
35
35
|
};
|
package/dist/typegen/core.js
CHANGED
|
@@ -12,7 +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
|
-
|
|
15
|
+
disallowAmbigiousKeys: Schema.Boolean,
|
|
16
16
|
runtimeMode: Schema.NullOr(Schema.Literal("centralized", "standalone")),
|
|
17
17
|
localEnvRoot: Schema.NullOr(Schema.String),
|
|
18
18
|
});
|
|
@@ -51,7 +51,7 @@ function buildGeneratedTypesContents(manifest, input) {
|
|
|
51
51
|
const importLine = input.mode === "semantic"
|
|
52
52
|
? `import type { EaseInOut, Env, Linear, Step } from "${input.typeModulePath}";\n\n`
|
|
53
53
|
: "";
|
|
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.
|
|
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`;
|
|
55
55
|
}
|
|
56
56
|
function readManifestVersion(contents) {
|
|
57
57
|
return contents?.match(MANIFEST_VERSION_PATTERN)?.[1]?.trim() ?? null;
|
|
@@ -133,7 +133,7 @@ function buildTypegenMetadataContents(lastGeneratedAt, identity) {
|
|
|
133
133
|
projectSlug: identity.projectSlug,
|
|
134
134
|
stageSlug: identity.stageSlug,
|
|
135
135
|
typegenMode: identity.typegenMode,
|
|
136
|
-
|
|
136
|
+
disallowAmbigiousKeys: identity.disallowAmbigiousKeys,
|
|
137
137
|
runtimeMode: identity.runtimeMode,
|
|
138
138
|
localEnvRoot: identity.localEnvRoot,
|
|
139
139
|
}, null, 2)}\n`;
|
|
@@ -148,12 +148,12 @@ function buildTypegenMetadataContents(lastGeneratedAt, identity) {
|
|
|
148
148
|
* @lastModified 2026-03-19
|
|
149
149
|
* @author GPT-5.4
|
|
150
150
|
*/
|
|
151
|
-
export function renderGeneratedTypesForManifest(manifest, mode,
|
|
151
|
+
export function renderGeneratedTypesForManifest(manifest, mode, disallowAmbigiousKeys = true) {
|
|
152
152
|
const decodedManifest = Schema.decodeUnknownSync(TypegenManifestSchema)(manifest);
|
|
153
153
|
return {
|
|
154
154
|
serverContents: buildGeneratedTypesContents(decodedManifest, {
|
|
155
155
|
mode,
|
|
156
|
-
|
|
156
|
+
disallowAmbigiousKeys,
|
|
157
157
|
typeModulePath: "./dist/types.js",
|
|
158
158
|
declaredModulePath: "./dist/types.js",
|
|
159
159
|
interfaceName: "BarekeyGeneratedTypeMap",
|
|
@@ -162,7 +162,7 @@ export function renderGeneratedTypesForManifest(manifest, mode, strictGeneratedK
|
|
|
162
162
|
}),
|
|
163
163
|
publicContents: buildGeneratedTypesContents(decodedManifest, {
|
|
164
164
|
mode,
|
|
165
|
-
|
|
165
|
+
disallowAmbigiousKeys,
|
|
166
166
|
typeModulePath: "./dist/public-types.js",
|
|
167
167
|
declaredModulePath: "./dist/public-types.js",
|
|
168
168
|
interfaceName: "BarekeyPublicGeneratedTypeMap",
|
|
@@ -196,7 +196,7 @@ export async function writeInstalledSdkGeneratedTypes(manifest, identity) {
|
|
|
196
196
|
readTextFile(target.serverGeneratedTypesPath),
|
|
197
197
|
readTextFile(target.publicGeneratedTypesPath),
|
|
198
198
|
]);
|
|
199
|
-
const rendered = renderGeneratedTypesForManifest(manifest, identity.typegenMode, identity.
|
|
199
|
+
const rendered = renderGeneratedTypesForManifest(manifest, identity.typegenMode, identity.disallowAmbigiousKeys);
|
|
200
200
|
if (existingServerContents === rendered.serverContents &&
|
|
201
201
|
existingPublicContents === rendered.publicContents &&
|
|
202
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
package/src/commands/typegen.ts
CHANGED
|
@@ -74,7 +74,7 @@ async function resolveTypegenContext(options: EnvTargetOptions): Promise<{
|
|
|
74
74
|
environment: string;
|
|
75
75
|
runtimeMode: "centralized" | "standalone";
|
|
76
76
|
typegenMode: "semantic" | "minimal";
|
|
77
|
-
|
|
77
|
+
disallowAmbigiousKeys: boolean;
|
|
78
78
|
localEnvRoot: string | null;
|
|
79
79
|
}> {
|
|
80
80
|
const runtime = await loadRuntimeConfig();
|
|
@@ -90,7 +90,7 @@ async function resolveTypegenContext(options: EnvTargetOptions): Promise<{
|
|
|
90
90
|
environment: target.stageSlug.trim().length > 0 ? target.stageSlug : "local",
|
|
91
91
|
runtimeMode: runtime?.config.config?.mode ?? "centralized",
|
|
92
92
|
typegenMode: runtime?.config.config?.typegen ?? "semantic",
|
|
93
|
-
|
|
93
|
+
disallowAmbigiousKeys: runtime?.config.config?.disallowAmbigiousKeys ?? true,
|
|
94
94
|
localEnvRoot: runtime?.path ?? null,
|
|
95
95
|
};
|
|
96
96
|
}
|
|
@@ -128,7 +128,7 @@ async function runTypegen(options: EnvTargetOptions): Promise<void> {
|
|
|
128
128
|
projectSlug: context.project,
|
|
129
129
|
stageSlug: context.environment,
|
|
130
130
|
typegenMode: context.typegenMode,
|
|
131
|
-
|
|
131
|
+
disallowAmbigiousKeys: context.disallowAmbigiousKeys,
|
|
132
132
|
runtimeMode: context.runtimeMode,
|
|
133
133
|
localEnvRoot: context.localEnvRoot,
|
|
134
134
|
});
|
|
@@ -170,7 +170,7 @@ async function runTypegenWatch(
|
|
|
170
170
|
projectSlug: nextContext.project,
|
|
171
171
|
stageSlug: nextContext.environment,
|
|
172
172
|
typegenMode: nextContext.typegenMode,
|
|
173
|
-
|
|
173
|
+
disallowAmbigiousKeys: nextContext.disallowAmbigiousKeys,
|
|
174
174
|
runtimeMode: nextContext.runtimeMode,
|
|
175
175
|
localEnvRoot: nextContext.localEnvRoot,
|
|
176
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,7 @@ 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),
|
|
29
31
|
strictGeneratedKeys: Schema.optional(Schema.Boolean),
|
|
30
32
|
mode: Schema.optional(RuntimeModeSchema),
|
|
31
33
|
}),
|
package/src/runtime-config.ts
CHANGED
|
@@ -5,12 +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";
|
|
13
|
-
|
|
14
|
+
disallowAmbigiousKeys?: boolean;
|
|
14
15
|
mode?: "centralized" | "standalone";
|
|
15
16
|
};
|
|
16
17
|
};
|
|
@@ -62,7 +63,8 @@ export async function loadRuntimeConfig(): Promise<BarekeyRuntimeConfigResult |
|
|
|
62
63
|
const mode = config?.mode ?? "centralized";
|
|
63
64
|
const typegen =
|
|
64
65
|
mode === "standalone" ? "minimal" : (config?.typegen ?? decoded.right.typegen ?? "semantic");
|
|
65
|
-
const
|
|
66
|
+
const disallowAmbigiousKeys =
|
|
67
|
+
config?.disallow_ambigious_keys ?? config?.strictGeneratedKeys ?? true;
|
|
66
68
|
|
|
67
69
|
return {
|
|
68
70
|
path: configPath,
|
|
@@ -73,7 +75,7 @@ export async function loadRuntimeConfig(): Promise<BarekeyRuntimeConfigResult |
|
|
|
73
75
|
config: {
|
|
74
76
|
mode,
|
|
75
77
|
typegen,
|
|
76
|
-
|
|
78
|
+
disallowAmbigiousKeys,
|
|
77
79
|
},
|
|
78
80
|
},
|
|
79
81
|
};
|
package/src/typegen/core.ts
CHANGED
|
@@ -8,7 +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
|
|
11
|
+
export type CliDisallowAmbigiousKeys = boolean;
|
|
12
12
|
|
|
13
13
|
export type CliTypegenResult = {
|
|
14
14
|
written: boolean;
|
|
@@ -24,7 +24,7 @@ type TypegenIdentity = {
|
|
|
24
24
|
projectSlug: string;
|
|
25
25
|
stageSlug: string;
|
|
26
26
|
typegenMode: CliTypegenMode;
|
|
27
|
-
|
|
27
|
+
disallowAmbigiousKeys: CliDisallowAmbigiousKeys;
|
|
28
28
|
runtimeMode: CliRuntimeMode;
|
|
29
29
|
localEnvRoot: string | null;
|
|
30
30
|
};
|
|
@@ -39,7 +39,7 @@ const TypegenMetadataSchema = Schema.Struct({
|
|
|
39
39
|
projectSlug: Schema.NullOr(Schema.String),
|
|
40
40
|
stageSlug: Schema.NullOr(Schema.String),
|
|
41
41
|
typegenMode: Schema.NullOr(Schema.Literal("semantic", "minimal")),
|
|
42
|
-
|
|
42
|
+
disallowAmbigiousKeys: Schema.Boolean,
|
|
43
43
|
runtimeMode: Schema.NullOr(Schema.Literal("centralized", "standalone")),
|
|
44
44
|
localEnvRoot: Schema.NullOr(Schema.String),
|
|
45
45
|
});
|
|
@@ -96,7 +96,7 @@ function buildGeneratedTypesContents(
|
|
|
96
96
|
manifest: TypegenManifest,
|
|
97
97
|
input: {
|
|
98
98
|
mode: CliTypegenMode;
|
|
99
|
-
|
|
99
|
+
disallowAmbigiousKeys: CliDisallowAmbigiousKeys;
|
|
100
100
|
typeModulePath: "./dist/types.js" | "./dist/public-types.js";
|
|
101
101
|
declaredModulePath: "./dist/types.js" | "./dist/public-types.js";
|
|
102
102
|
interfaceName: "BarekeyGeneratedTypeMap" | "BarekeyPublicGeneratedTypeMap";
|
|
@@ -116,7 +116,7 @@ function buildGeneratedTypesContents(
|
|
|
116
116
|
? `import type { EaseInOut, Env, Linear, Step } from "${input.typeModulePath}";\n\n`
|
|
117
117
|
: "";
|
|
118
118
|
|
|
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.
|
|
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`;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
function readManifestVersion(contents: string | null): string | null {
|
|
@@ -202,7 +202,7 @@ function buildTypegenMetadataContents(lastGeneratedAt: Date, identity: TypegenId
|
|
|
202
202
|
projectSlug: identity.projectSlug,
|
|
203
203
|
stageSlug: identity.stageSlug,
|
|
204
204
|
typegenMode: identity.typegenMode,
|
|
205
|
-
|
|
205
|
+
disallowAmbigiousKeys: identity.disallowAmbigiousKeys,
|
|
206
206
|
runtimeMode: identity.runtimeMode,
|
|
207
207
|
localEnvRoot: identity.localEnvRoot,
|
|
208
208
|
},
|
|
@@ -224,7 +224,7 @@ function buildTypegenMetadataContents(lastGeneratedAt: Date, identity: TypegenId
|
|
|
224
224
|
export function renderGeneratedTypesForManifest(
|
|
225
225
|
manifest: TypegenManifest,
|
|
226
226
|
mode: CliTypegenMode,
|
|
227
|
-
|
|
227
|
+
disallowAmbigiousKeys = true,
|
|
228
228
|
): {
|
|
229
229
|
serverContents: string;
|
|
230
230
|
publicContents: string;
|
|
@@ -234,7 +234,7 @@ export function renderGeneratedTypesForManifest(
|
|
|
234
234
|
return {
|
|
235
235
|
serverContents: buildGeneratedTypesContents(decodedManifest, {
|
|
236
236
|
mode,
|
|
237
|
-
|
|
237
|
+
disallowAmbigiousKeys,
|
|
238
238
|
typeModulePath: "./dist/types.js",
|
|
239
239
|
declaredModulePath: "./dist/types.js",
|
|
240
240
|
interfaceName: "BarekeyGeneratedTypeMap",
|
|
@@ -243,7 +243,7 @@ export function renderGeneratedTypesForManifest(
|
|
|
243
243
|
}),
|
|
244
244
|
publicContents: buildGeneratedTypesContents(decodedManifest, {
|
|
245
245
|
mode,
|
|
246
|
-
|
|
246
|
+
disallowAmbigiousKeys,
|
|
247
247
|
typeModulePath: "./dist/public-types.js",
|
|
248
248
|
declaredModulePath: "./dist/public-types.js",
|
|
249
249
|
interfaceName: "BarekeyPublicGeneratedTypeMap",
|
|
@@ -285,7 +285,7 @@ export async function writeInstalledSdkGeneratedTypes(
|
|
|
285
285
|
const rendered = renderGeneratedTypesForManifest(
|
|
286
286
|
manifest,
|
|
287
287
|
identity.typegenMode,
|
|
288
|
-
identity.
|
|
288
|
+
identity.disallowAmbigiousKeys,
|
|
289
289
|
);
|
|
290
290
|
|
|
291
291
|
if (
|
|
@@ -86,14 +86,14 @@ describe("loadRuntimeConfig", () => {
|
|
|
86
86
|
config: {
|
|
87
87
|
mode: "centralized",
|
|
88
88
|
typegen: "semantic",
|
|
89
|
-
|
|
89
|
+
disallowAmbigiousKeys: true,
|
|
90
90
|
},
|
|
91
91
|
},
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
-
test("reads config.
|
|
96
|
+
test("reads config.disallow_ambigious_keys when present", async () => {
|
|
97
97
|
const tempDir = await createTempDir();
|
|
98
98
|
await writeFile(
|
|
99
99
|
path.join(tempDir, "barekey.json"),
|
|
@@ -103,7 +103,37 @@ describe("loadRuntimeConfig", () => {
|
|
|
103
103
|
project: "api",
|
|
104
104
|
environment: "development",
|
|
105
105
|
config: {
|
|
106
|
-
|
|
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,
|
|
107
137
|
},
|
|
108
138
|
},
|
|
109
139
|
null,
|
|
@@ -116,7 +146,7 @@ describe("loadRuntimeConfig", () => {
|
|
|
116
146
|
await expect(loadRuntimeConfig()).resolves.toMatchObject({
|
|
117
147
|
config: {
|
|
118
148
|
config: {
|
|
119
|
-
|
|
149
|
+
disallowAmbigiousKeys: false,
|
|
120
150
|
},
|
|
121
151
|
},
|
|
122
152
|
});
|