@barekey/sdk 0.4.3 → 0.5.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.
Files changed (45) hide show
  1. package/dist/client.d.ts +4 -0
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +61 -15
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/internal/node-runtime.d.ts +11 -0
  7. package/dist/internal/node-runtime.d.ts.map +1 -1
  8. package/dist/internal/node-runtime.js +2 -1
  9. package/dist/internal/public-runtime.d.ts.map +1 -1
  10. package/dist/internal/public-runtime.js +38 -0
  11. package/dist/internal/runtime.d.ts +15 -2
  12. package/dist/internal/runtime.d.ts.map +1 -1
  13. package/dist/internal/runtime.js +71 -5
  14. package/dist/internal/singleton.d.ts.map +1 -1
  15. package/dist/internal/singleton.js +14 -0
  16. package/dist/internal/standalone.d.ts +10 -0
  17. package/dist/internal/standalone.d.ts.map +1 -0
  18. package/dist/internal/standalone.js +246 -0
  19. package/dist/internal/typegen.d.ts +6 -3
  20. package/dist/internal/typegen.d.ts.map +1 -1
  21. package/dist/internal/typegen.js +41 -9
  22. package/dist/public-client.d.ts +4 -0
  23. package/dist/public-client.d.ts.map +1 -1
  24. package/dist/public-types.d.ts +1 -1
  25. package/dist/public-types.d.ts.map +1 -1
  26. package/dist/public.d.ts +1 -1
  27. package/dist/public.d.ts.map +1 -1
  28. package/dist/server.d.ts +1 -1
  29. package/dist/server.d.ts.map +1 -1
  30. package/dist/types.d.ts +7 -3
  31. package/dist/types.d.ts.map +1 -1
  32. package/package.json +1 -1
  33. package/src/client.ts +86 -15
  34. package/src/index.ts +2 -0
  35. package/src/internal/node-runtime.ts +4 -2
  36. package/src/internal/public-runtime.ts +58 -1
  37. package/src/internal/runtime.ts +121 -5
  38. package/src/internal/singleton.ts +37 -4
  39. package/src/internal/standalone.ts +309 -0
  40. package/src/internal/typegen.ts +63 -10
  41. package/src/public-client.ts +4 -0
  42. package/src/public-types.ts +1 -0
  43. package/src/public.ts +2 -0
  44. package/src/server.ts +2 -0
  45. package/src/types.ts +14 -8
@@ -0,0 +1,309 @@
1
+ import {
2
+ FsNotAvailableError,
3
+ InvalidConfigurationProvidedError,
4
+ parseBigIntOrThrow,
5
+ parseBooleanOrThrow,
6
+ parseDateOrThrow,
7
+ parseFloatOrThrow,
8
+ } from "../errors.js";
9
+ import type {
10
+ BarekeyDeclaredType,
11
+ BarekeyVariableDefinition,
12
+ } from "../types.js";
13
+ import { loadNodeRuntime } from "./node-runtime.js";
14
+ import type { TypegenManifest, TypegenManifestVariable } from "./typegen.js";
15
+
16
+ type StandaloneVariable = {
17
+ name: string;
18
+ value: string;
19
+ };
20
+
21
+ type StandaloneSnapshot = {
22
+ variables: Array<StandaloneVariable>;
23
+ manifestVersion: string;
24
+ };
25
+
26
+ function isStandaloneEnvFile(fileName: string): boolean {
27
+ if (fileName === ".env") {
28
+ return true;
29
+ }
30
+
31
+ if (!fileName.startsWith(".env.")) {
32
+ return false;
33
+ }
34
+
35
+ const suffix = fileName.slice(".env.".length);
36
+ if (suffix.length === 0) {
37
+ return false;
38
+ }
39
+
40
+ return suffix.split(".")[0] !== "example";
41
+ }
42
+
43
+ function normalizeStandaloneKey(fileName: string, key: string): string {
44
+ const normalizedKey = key.trim().toUpperCase();
45
+ if (fileName === ".env") {
46
+ return normalizedKey;
47
+ }
48
+
49
+ const suffix = fileName.slice(".env.".length);
50
+ const prefix = suffix
51
+ .split(".")
52
+ .filter((token) => token.length > 0)
53
+ .map((token) => token.toUpperCase())
54
+ .join("_");
55
+
56
+ return prefix.length === 0 ? normalizedKey : `${prefix}_${normalizedKey}`;
57
+ }
58
+
59
+ function parseQuotedValue(value: string, quote: '"' | "'"): string {
60
+ let result = "";
61
+ let escaped = false;
62
+
63
+ for (let index = 1; index < value.length; index += 1) {
64
+ const character = value[index];
65
+ if (character === undefined) {
66
+ break;
67
+ }
68
+
69
+ if (quote === '"' && escaped) {
70
+ if (character === "n") {
71
+ result += "\n";
72
+ } else if (character === "r") {
73
+ result += "\r";
74
+ } else if (character === "t") {
75
+ result += "\t";
76
+ } else {
77
+ result += character;
78
+ }
79
+ escaped = false;
80
+ continue;
81
+ }
82
+
83
+ if (quote === '"' && character === "\\") {
84
+ escaped = true;
85
+ continue;
86
+ }
87
+
88
+ if (character === quote) {
89
+ return result;
90
+ }
91
+
92
+ result += character;
93
+ }
94
+
95
+ return result;
96
+ }
97
+
98
+ function parseEnvValue(rawValue: string): string {
99
+ const trimmed = rawValue.trim();
100
+ if (trimmed.length === 0) {
101
+ return "";
102
+ }
103
+
104
+ const firstCharacter = trimmed[0];
105
+ if (firstCharacter === '"' || firstCharacter === "'") {
106
+ return parseQuotedValue(trimmed, firstCharacter);
107
+ }
108
+
109
+ const commentStart = trimmed.search(/\s#/);
110
+ return (commentStart >= 0 ? trimmed.slice(0, commentStart) : trimmed).trim();
111
+ }
112
+
113
+ function parseStandaloneEnvContents(fileName: string, contents: string): Array<StandaloneVariable> {
114
+ const variables: Array<StandaloneVariable> = [];
115
+
116
+ for (const rawLine of contents.split(/\r?\n/)) {
117
+ const trimmedLine = rawLine.trimStart();
118
+ if (trimmedLine.length === 0 || trimmedLine.startsWith("#")) {
119
+ continue;
120
+ }
121
+
122
+ const line = trimmedLine.startsWith("export ")
123
+ ? trimmedLine.slice("export ".length).trimStart()
124
+ : trimmedLine;
125
+ const delimiterIndex = line.indexOf("=");
126
+ if (delimiterIndex <= 0) {
127
+ continue;
128
+ }
129
+
130
+ const rawKey = line.slice(0, delimiterIndex).trim();
131
+ if (rawKey.length === 0) {
132
+ continue;
133
+ }
134
+
135
+ variables.push({
136
+ name: normalizeStandaloneKey(fileName, rawKey),
137
+ value: parseEnvValue(line.slice(delimiterIndex + 1)),
138
+ });
139
+ }
140
+
141
+ return variables;
142
+ }
143
+
144
+ async function hashString(value: string): Promise<string> {
145
+ if (globalThis.crypto?.subtle !== undefined) {
146
+ const digest = await globalThis.crypto.subtle.digest(
147
+ "SHA-256",
148
+ new TextEncoder().encode(value),
149
+ );
150
+ return [...new Uint8Array(digest)]
151
+ .map((part) => part.toString(16).padStart(2, "0"))
152
+ .join("");
153
+ }
154
+
155
+ let hash = 0;
156
+ for (let index = 0; index < value.length; index += 1) {
157
+ hash = (hash * 31 + value.charCodeAt(index)) >>> 0;
158
+ }
159
+ return hash.toString(16).padStart(8, "0");
160
+ }
161
+
162
+ function inferStandaloneDeclaredType(value: string): BarekeyDeclaredType {
163
+ try {
164
+ parseBooleanOrThrow(value);
165
+ return "boolean";
166
+ } catch {}
167
+
168
+ try {
169
+ parseBigIntOrThrow(value);
170
+ return "int64";
171
+ } catch {}
172
+
173
+ try {
174
+ parseFloatOrThrow(value);
175
+ return "float";
176
+ } catch {}
177
+
178
+ try {
179
+ parseDateOrThrow(value);
180
+ return "date";
181
+ } catch {}
182
+
183
+ return "string";
184
+ }
185
+
186
+ function typeScriptTypeForDeclaredType(value: BarekeyDeclaredType): string {
187
+ if (value === "boolean") {
188
+ return "boolean";
189
+ }
190
+ if (value === "int64") {
191
+ return "bigint";
192
+ }
193
+ if (value === "float") {
194
+ return "number";
195
+ }
196
+ if (value === "date") {
197
+ return "Date";
198
+ }
199
+ return "string";
200
+ }
201
+
202
+ async function loadStandaloneSnapshot(rootDirectory: string): Promise<StandaloneSnapshot> {
203
+ const runtime = await loadNodeRuntime();
204
+ if (runtime === null) {
205
+ throw new FsNotAvailableError({
206
+ message: "Barekey standalone mode requires a local filesystem to read .env files.",
207
+ });
208
+ }
209
+
210
+ let fileNames: Array<string>;
211
+ try {
212
+ const entries = await runtime.fs.readdir(rootDirectory, {
213
+ withFileTypes: true,
214
+ });
215
+ fileNames = entries
216
+ .filter((entry) => entry.isFile() && isStandaloneEnvFile(entry.name))
217
+ .map((entry) => entry.name)
218
+ .sort((left, right) => {
219
+ if (left === ".env") {
220
+ return right === ".env" ? 0 : -1;
221
+ }
222
+ if (right === ".env") {
223
+ return 1;
224
+ }
225
+ return left.localeCompare(right);
226
+ });
227
+ } catch (error: unknown) {
228
+ throw new InvalidConfigurationProvidedError({
229
+ message: `Barekey standalone mode could not read env files from ${rootDirectory}.`,
230
+ cause: error,
231
+ });
232
+ }
233
+
234
+ const mergedVariables = new Map<string, string>();
235
+ const fingerprintParts: Array<string> = [];
236
+
237
+ for (const fileName of fileNames) {
238
+ const filePath = runtime.path.join(rootDirectory, fileName);
239
+ let contents: string;
240
+ try {
241
+ contents = await runtime.fs.readFile(filePath, "utf8");
242
+ } catch (error: unknown) {
243
+ throw new InvalidConfigurationProvidedError({
244
+ message: `Barekey standalone mode could not read ${filePath}.`,
245
+ cause: error,
246
+ });
247
+ }
248
+
249
+ fingerprintParts.push(`${fileName}\n${contents}`);
250
+ for (const variable of parseStandaloneEnvContents(fileName, contents)) {
251
+ mergedVariables.set(variable.name, variable.value);
252
+ }
253
+ }
254
+
255
+ return {
256
+ variables: [...mergedVariables.entries()]
257
+ .sort(([left], [right]) => left.localeCompare(right))
258
+ .map(([name, value]) => ({ name, value })),
259
+ manifestVersion: `standalone-${await hashString(fingerprintParts.join("\n---\n"))}`,
260
+ };
261
+ }
262
+
263
+ export async function loadStandaloneDefinitions(
264
+ rootDirectory: string,
265
+ ): Promise<Array<BarekeyVariableDefinition>> {
266
+ const snapshot = await loadStandaloneSnapshot(rootDirectory);
267
+ return snapshot.variables.map((variable) => ({
268
+ name: variable.name,
269
+ kind: "secret",
270
+ declaredType: inferStandaloneDeclaredType(variable.value),
271
+ visibility: "private",
272
+ value: variable.value,
273
+ }));
274
+ }
275
+
276
+ export async function buildStandaloneTypegenManifest(input: {
277
+ rootDirectory: string;
278
+ organization: string;
279
+ project: string;
280
+ environment: string;
281
+ }): Promise<TypegenManifest> {
282
+ const snapshot = await loadStandaloneSnapshot(input.rootDirectory);
283
+ const variables: Array<TypegenManifestVariable> = snapshot.variables.map((variable) => {
284
+ const declaredType = inferStandaloneDeclaredType(variable.value);
285
+ return {
286
+ name: variable.name,
287
+ visibility: "private",
288
+ kind: "secret",
289
+ declaredType,
290
+ required: true,
291
+ updatedAtMs: Date.now(),
292
+ typeScriptType: typeScriptTypeForDeclaredType(declaredType),
293
+ valueATypeScriptType: null,
294
+ valueBTypeScriptType: null,
295
+ rolloutFunction: null,
296
+ rolloutMilestones: null,
297
+ };
298
+ });
299
+
300
+ return {
301
+ orgId: `standalone:${input.organization}`,
302
+ orgSlug: input.organization,
303
+ projectSlug: input.project,
304
+ stageSlug: input.environment,
305
+ generatedAtMs: Date.now(),
306
+ manifestVersion: snapshot.manifestVersion,
307
+ variables,
308
+ };
309
+ }
@@ -4,8 +4,10 @@ import {
4
4
  writeTextFileAtomic,
5
5
  } from "./node-runtime.js";
6
6
  import type {
7
+ BarekeyMode,
7
8
  BarekeyRolloutFunction,
8
9
  BarekeyRolloutMilestone,
10
+ BarekeyTypegenMode,
9
11
  BarekeyTypegenResult,
10
12
  } from "../types.js";
11
13
 
@@ -43,13 +45,19 @@ type TypegenMetadata = {
43
45
  orgSlug: string | null;
44
46
  projectSlug: string | null;
45
47
  stageSlug: string | null;
48
+ typegenMode: BarekeyTypegenMode | null;
49
+ runtimeMode: BarekeyMode | null;
50
+ localEnvRoot: string | null;
46
51
  };
47
52
 
48
53
  type TypegenMetadataIdentity = {
49
- baseUrl: string;
54
+ baseUrl: string | null;
50
55
  orgSlug: string;
51
56
  projectSlug: string;
52
57
  stageSlug: string;
58
+ typegenMode: BarekeyTypegenMode;
59
+ runtimeMode: BarekeyMode;
60
+ localEnvRoot: string | null;
53
61
  };
54
62
 
55
63
  function renderLinearMilestones(milestones: Array<BarekeyRolloutMilestone>): string {
@@ -76,7 +84,14 @@ function renderRolloutMetadataType(row: TypegenManifestVariable): string {
76
84
  return `Linear<${renderedMilestones}>`;
77
85
  }
78
86
 
79
- function renderVariableType(row: TypegenManifestVariable): string {
87
+ function renderVariableType(
88
+ row: TypegenManifestVariable,
89
+ mode: BarekeyTypegenMode,
90
+ ): string {
91
+ if (mode === "minimal") {
92
+ return row.typeScriptType;
93
+ }
94
+
80
95
  const renderEnvDescriptor = (input: {
81
96
  mode: "Secret" | "AB";
82
97
  rollout: string;
@@ -100,6 +115,7 @@ function renderVariableType(row: TypegenManifestVariable): string {
100
115
  function buildGeneratedTypesContents(
101
116
  manifest: TypegenManifest,
102
117
  input: {
118
+ mode: BarekeyTypegenMode;
103
119
  typeModulePath: "./dist/types.js" | "./dist/public-types.js";
104
120
  declaredModulePath: "./dist/types.js" | "./dist/public-types.js";
105
121
  interfaceName: "BarekeyGeneratedTypeMap" | "BarekeyPublicGeneratedTypeMap";
@@ -110,16 +126,19 @@ function buildGeneratedTypesContents(
110
126
  .slice()
111
127
  .filter(input.include)
112
128
  .sort((left, right) => left.name.localeCompare(right.name))
113
- .map((row) => ` ${JSON.stringify(row.name)}: ${renderVariableType(row)};`)
129
+ .map((row) => ` ${JSON.stringify(row.name)}: ${renderVariableType(row, input.mode)};`)
114
130
  .join("\n");
115
131
 
132
+ const importLine =
133
+ input.mode === "semantic"
134
+ ? `import type { AB, EaseInOut, Env, Linear, Secret, Step } from "${input.typeModulePath}";\n\n`
135
+ : "";
136
+
116
137
  return `/* eslint-disable */
117
138
  /* This file is generated by barekey typegen. */
118
139
  /* barekey-manifest-version: ${manifest.manifestVersion} */
119
140
 
120
- import type { AB, EaseInOut, Env, Linear, Secret, Step } from "${input.typeModulePath}";
121
-
122
- declare module "${input.declaredModulePath}" {
141
+ ${importLine}declare module "${input.declaredModulePath}" {
123
142
  interface ${input.interfaceName} {
124
143
  ${mapLines.length > 0 ? mapLines : ""}
125
144
  }
@@ -156,6 +175,10 @@ function parseTypegenMetadata(contents: string | null): TypegenMetadata | null {
156
175
  orgSlug?: unknown;
157
176
  projectSlug?: unknown;
158
177
  stageSlug?: unknown;
178
+ typegenMode?: unknown;
179
+ runtimeMode?: unknown;
180
+ localEnvRoot?: unknown;
181
+ mode?: unknown;
159
182
  };
160
183
  if (
161
184
  candidate.version !== TYPEGEN_METADATA_VERSION ||
@@ -172,6 +195,21 @@ function parseTypegenMetadata(contents: string | null): TypegenMetadata | null {
172
195
  (candidate.stageSlug !== undefined &&
173
196
  candidate.stageSlug !== null &&
174
197
  typeof candidate.stageSlug !== "string") ||
198
+ (candidate.typegenMode !== undefined &&
199
+ candidate.typegenMode !== null &&
200
+ candidate.typegenMode !== "semantic" &&
201
+ candidate.typegenMode !== "minimal") ||
202
+ (candidate.mode !== undefined &&
203
+ candidate.mode !== null &&
204
+ candidate.mode !== "semantic" &&
205
+ candidate.mode !== "minimal") ||
206
+ (candidate.runtimeMode !== undefined &&
207
+ candidate.runtimeMode !== null &&
208
+ candidate.runtimeMode !== "centralized" &&
209
+ candidate.runtimeMode !== "standalone") ||
210
+ (candidate.localEnvRoot !== undefined &&
211
+ candidate.localEnvRoot !== null &&
212
+ typeof candidate.localEnvRoot !== "string") ||
175
213
  !Number.isFinite(Date.parse(candidate.last))
176
214
  ) {
177
215
  return null;
@@ -184,6 +222,9 @@ function parseTypegenMetadata(contents: string | null): TypegenMetadata | null {
184
222
  orgSlug: candidate.orgSlug ?? null,
185
223
  projectSlug: candidate.projectSlug ?? null,
186
224
  stageSlug: candidate.stageSlug ?? null,
225
+ typegenMode: candidate.typegenMode ?? candidate.mode ?? null,
226
+ runtimeMode: candidate.runtimeMode ?? "centralized",
227
+ localEnvRoot: candidate.localEnvRoot ?? null,
187
228
  };
188
229
  } catch {
189
230
  return null;
@@ -202,6 +243,9 @@ function buildTypegenMetadataContents(
202
243
  orgSlug: identity.orgSlug,
203
244
  projectSlug: identity.projectSlug,
204
245
  stageSlug: identity.stageSlug,
246
+ typegenMode: identity.typegenMode,
247
+ runtimeMode: identity.runtimeMode,
248
+ localEnvRoot: identity.localEnvRoot,
205
249
  },
206
250
  null,
207
251
  2,
@@ -213,18 +257,23 @@ export async function resolveInstalledSdkGeneratedTypesPath(): Promise<string |
213
257
  return target?.serverGeneratedTypesPath ?? null;
214
258
  }
215
259
 
216
- export function renderGeneratedTypesForManifest(manifest: TypegenManifest): {
260
+ export function renderGeneratedTypesForManifest(
261
+ manifest: TypegenManifest,
262
+ mode: BarekeyTypegenMode = "semantic",
263
+ ): {
217
264
  serverContents: string;
218
265
  publicContents: string;
219
266
  } {
220
267
  return {
221
268
  serverContents: buildGeneratedTypesContents(manifest, {
269
+ mode,
222
270
  typeModulePath: "./dist/types.js",
223
271
  declaredModulePath: "./dist/types.js",
224
272
  interfaceName: "BarekeyGeneratedTypeMap",
225
273
  include: () => true,
226
274
  }),
227
275
  publicContents: buildGeneratedTypesContents(manifest, {
276
+ mode,
228
277
  typeModulePath: "./dist/public-types.js",
229
278
  declaredModulePath: "./dist/public-types.js",
230
279
  interfaceName: "BarekeyPublicGeneratedTypeMap",
@@ -251,7 +300,10 @@ export async function hasFreshInstalledSdkTypegen(
251
300
  metadata.baseUrl !== identity.baseUrl ||
252
301
  metadata.orgSlug !== identity.orgSlug ||
253
302
  metadata.projectSlug !== identity.projectSlug ||
254
- metadata.stageSlug !== identity.stageSlug
303
+ metadata.stageSlug !== identity.stageSlug ||
304
+ metadata.typegenMode !== identity.typegenMode ||
305
+ metadata.runtimeMode !== identity.runtimeMode ||
306
+ metadata.localEnvRoot !== identity.localEnvRoot
255
307
  ) {
256
308
  return false;
257
309
  }
@@ -278,7 +330,10 @@ export async function writeInstalledSdkGeneratedTypes(
278
330
  readTextFile(target.serverGeneratedTypesPath),
279
331
  readTextFile(target.publicGeneratedTypesPath),
280
332
  ]);
333
+ const rendered = renderGeneratedTypesForManifest(manifest, identity.typegenMode);
281
334
  if (
335
+ existingServerContents === rendered.serverContents &&
336
+ existingPublicContents === rendered.publicContents &&
282
337
  readManifestVersion(existingServerContents) === manifest.manifestVersion &&
283
338
  readManifestVersion(existingPublicContents) === manifest.manifestVersion
284
339
  ) {
@@ -295,8 +350,6 @@ export async function writeInstalledSdkGeneratedTypes(
295
350
  };
296
351
  }
297
352
 
298
- const rendered = renderGeneratedTypesForManifest(manifest);
299
-
300
353
  await Promise.all([
301
354
  writeTextFileAtomic(
302
355
  target.serverGeneratedTypesPath,
@@ -70,6 +70,10 @@ export class PublicBarekeyClient {
70
70
  private requirementsPromise: Promise<void> | null = null;
71
71
 
72
72
  constructor();
73
+ constructor(options: {
74
+ requirements?: PublicBarekeyClientOptions["requirements"];
75
+ baseUrl?: string;
76
+ });
73
77
  constructor(options: {
74
78
  organization: string;
75
79
  project: string;
@@ -17,6 +17,7 @@ export type {
17
17
  BarekeyStandardSchemaV1,
18
18
  BarekeyTemporalInstant,
19
19
  BarekeyTemporalInstantLike,
20
+ BarekeyTypegenMode,
20
21
  BarekeyTtlInput,
21
22
  BarekeyTypegenResult,
22
23
  BarekeyVariableDefinition,
package/src/public.ts CHANGED
@@ -48,6 +48,7 @@ export type {
48
48
  BarekeyGetOptions,
49
49
  BarekeyJsonConfig,
50
50
  BarekeyLiteralString,
51
+ BarekeyMode,
51
52
  BarekeyResolvedRecord,
52
53
  BarekeyResolvedRecords,
53
54
  BarekeyResolvedKind,
@@ -57,6 +58,7 @@ export type {
57
58
  BarekeyStandardSchemaV1,
58
59
  BarekeyTemporalInstant,
59
60
  BarekeyTemporalInstantLike,
61
+ BarekeyTypegenMode,
60
62
  BarekeyTtlInput,
61
63
  BarekeyValueForGeneratedMap,
62
64
  BarekeyValuesForGeneratedMap,
package/src/server.ts CHANGED
@@ -51,6 +51,7 @@ export type {
51
51
  BarekeyJsonConfig,
52
52
  BarekeyKey,
53
53
  BarekeyLiteralString,
54
+ BarekeyMode,
54
55
  BarekeyKnownKey,
55
56
  BarekeyResolvedRecord,
56
57
  BarekeyResolvedRecords,
@@ -59,6 +60,7 @@ export type {
59
60
  BarekeyStandardSchemaV1,
60
61
  BarekeyTemporalInstant,
61
62
  BarekeyTemporalInstantLike,
63
+ BarekeyTypegenMode,
62
64
  BarekeyTtlInput,
63
65
  BarekeyTypegenResult,
64
66
  BarekeyValueForGeneratedMap,
package/src/types.ts CHANGED
@@ -3,6 +3,9 @@ export type BarekeyVisibility = "private" | "public";
3
3
 
4
4
  export type BarekeyDeclaredType = "string" | "boolean" | "int64" | "float" | "date" | "json";
5
5
 
6
+ export type BarekeyTypegenMode = "semantic" | "minimal";
7
+ export type BarekeyMode = "centralized" | "standalone";
8
+
6
9
  export type BarekeyTemporalInstant = {
7
10
  readonly epochMilliseconds: number;
8
11
  toJSON(): string;
@@ -68,12 +71,6 @@ type BarekeyEnvMarker<TMode, TVisibility, TRollout> = {
68
71
  };
69
72
  };
70
73
 
71
- type BarekeyEnvFromDescriptor<TDescriptor extends BarekeyAnyEnvDescriptor> = TDescriptor["Type"] &
72
- BarekeyEnvMarker<TDescriptor["Mode"], TDescriptor["Visibility"], TDescriptor["Rollout"]>;
73
-
74
- type BarekeyLegacyEnv<TMode, TValue, TRollout, TVisibility> = TValue &
75
- BarekeyEnvMarker<TMode, TVisibility, TRollout>;
76
-
77
74
  export type Env<
78
75
  TDescriptorOrMode,
79
76
  TValue = never,
@@ -81,9 +78,14 @@ export type Env<
81
78
  TVisibility = never,
82
79
  > = [TValue] extends [never]
83
80
  ? TDescriptorOrMode extends BarekeyAnyEnvDescriptor
84
- ? BarekeyEnvFromDescriptor<TDescriptorOrMode>
81
+ ? TDescriptorOrMode["Type"] &
82
+ BarekeyEnvMarker<
83
+ TDescriptorOrMode["Mode"],
84
+ TDescriptorOrMode["Visibility"],
85
+ TDescriptorOrMode["Rollout"]
86
+ >
85
87
  : never
86
- : BarekeyLegacyEnv<TDescriptorOrMode, TValue, TRollout, TVisibility>;
88
+ : TValue & BarekeyEnvMarker<TDescriptorOrMode, TVisibility, TRollout>;
87
89
 
88
90
  export type BarekeyCoerceTarget = "string" | "boolean" | "int64" | "float" | "date" | "json";
89
91
 
@@ -196,6 +198,10 @@ export type BarekeyJsonConfig = {
196
198
  environment?: string;
197
199
  org?: string;
198
200
  stage?: string;
201
+ config?: {
202
+ typegen?: BarekeyTypegenMode;
203
+ mode?: BarekeyMode;
204
+ };
199
205
  };
200
206
 
201
207
  export type BarekeyStandardSchemaResult =