@dbx-tools/core 0.6.88 → 0.6.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -14
- package/index.ts +1 -2
- package/lib/index.d.ts +1 -2
- package/lib/index.js +2 -2
- package/lib/src/config.d.ts +26 -51
- package/lib/src/config.js +123 -274
- package/lib/src/project.d.ts +1 -1
- package/lib/src/project.js +8 -8
- package/package.json +2 -11
- package/src/config.ts +149 -279
- package/src/project.ts +8 -8
package/README.md
CHANGED
|
@@ -107,17 +107,11 @@ targets, resources, and paths, so reading one as a process setting resolves name
|
|
|
107
107
|
the deployed App never sees. Reference a variable from `config.env` to make it
|
|
108
108
|
one.
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
says which of several apps a process is. Finally AppKit's execution context
|
|
116
|
-
confirms the process really is that app; that context does not exist until AppKit
|
|
117
|
-
boots, so only the affirmative is remembered and a lookup during boot still
|
|
118
|
-
resolves from the bundle instead of being permanently denied. Setting
|
|
119
|
-
`DBX_TOOLS_CONFIG_BUNDLE=true` skips this gate for a tool that wants the bundle
|
|
120
|
-
without being the App.
|
|
110
|
+
Bundle lookup is not coupled to AppKit installation or execution context. If
|
|
111
|
+
earlier sources miss during local development, the configured working directory
|
|
112
|
+
contains a bundle, and bundle reads are enabled, validation runs. This keeps
|
|
113
|
+
pre-boot callers such as `@dbx-tools/appkit` auto-configuration on the same
|
|
114
|
+
deterministic path as CLIs and ordinary Node consumers.
|
|
121
115
|
|
|
122
116
|
Deployed Apps skip dotenv and bundle lookup after `isDatabricksAppEnv()`
|
|
123
117
|
recognizes the required App name, HTTP(S) host, and valid port. Set
|
|
@@ -132,9 +126,10 @@ the default: read files outside an App and skip them inside one. Bundle reads
|
|
|
132
126
|
also default off when `NODE_ENV=production`; set
|
|
133
127
|
`DBX_TOOLS_CONFIG_BUNDLE=true` to opt into bundle validation there.
|
|
134
128
|
|
|
135
|
-
Use `config.string()`, `boolean()`, `positiveNumber()`, `positiveInt()`,
|
|
136
|
-
`list()` to normalize typed options and text-based configuration
|
|
137
|
-
rule. `config.
|
|
129
|
+
Use `config.string()`, `boolean()`, `positiveNumber()`, `positiveInt()`,
|
|
130
|
+
`port()`, and `list()` to normalize typed options and text-based configuration
|
|
131
|
+
through one rule. `config.port()` accepts only TCP ports from 1 through 65535;
|
|
132
|
+
`config.ENV_ONLY` disables file fallbacks for exact environment reads.
|
|
138
133
|
|
|
139
134
|
## Run Commands
|
|
140
135
|
|
package/index.ts
CHANGED
|
@@ -13,8 +13,7 @@ export * as project from "./src/project.ts";
|
|
|
13
13
|
export type { BinContext, BinSelectionContext, BinSelector, BinVersionOutput, BinVersionParser, BinOptions, BinUrl } from "./src/bin.ts";
|
|
14
14
|
export { BrandContextSchema, defaultBrandContext, parseBrandContext, brandContextJsonSchema, brandContextPrompt } from "./src/brand.ts";
|
|
15
15
|
export type { BrandContext, BrandContextInput } from "./src/brand.ts";
|
|
16
|
-
export { MAX_TCP_PORT,
|
|
17
|
-
export type { ConfigKey, ConfigSource, ConfigOptions, ConfigFile } from "./src/config.ts";
|
|
16
|
+
export { MAX_TCP_PORT, ENV_ONLY, valueSchema, bundleResourceSchema, bundleEnvEntrySchema, bundleAppSchema } from "./src/config.ts";
|
|
18
17
|
export { COMMAND_NOT_FOUND_EXIT_CODE } from "./src/exec.ts";
|
|
19
18
|
export type { ExecStdio, LineHandler, StdioOption, ExecResult, ChildProcessResult, ExecOptions, SyncExecStdio, SyncExecOptions, SpawnArgs } from "./src/exec.ts";
|
|
20
19
|
export type { FileLockBackend, FileLockAcquisition, FileLockOptions } from "./src/file-lock.ts";
|
package/lib/index.d.ts
CHANGED
|
@@ -9,8 +9,7 @@ export * as project from "./src/project.ts";
|
|
|
9
9
|
export type { BinContext, BinSelectionContext, BinSelector, BinVersionOutput, BinVersionParser, BinOptions, BinUrl } from "./src/bin.ts";
|
|
10
10
|
export { BrandContextSchema, defaultBrandContext, parseBrandContext, brandContextJsonSchema, brandContextPrompt } from "./src/brand.ts";
|
|
11
11
|
export type { BrandContext, BrandContextInput } from "./src/brand.ts";
|
|
12
|
-
export { MAX_TCP_PORT,
|
|
13
|
-
export type { ConfigKey, ConfigSource, ConfigOptions, ConfigFile } from "./src/config.ts";
|
|
12
|
+
export { MAX_TCP_PORT, ENV_ONLY, valueSchema, bundleResourceSchema, bundleEnvEntrySchema, bundleAppSchema } from "./src/config.ts";
|
|
14
13
|
export { COMMAND_NOT_FOUND_EXIT_CODE } from "./src/exec.ts";
|
|
15
14
|
export type { ExecStdio, LineHandler, StdioOption, ExecResult, ChildProcessResult, ExecOptions, SyncExecStdio, SyncExecOptions, SpawnArgs } from "./src/exec.ts";
|
|
16
15
|
export type { FileLockBackend, FileLockAcquisition, FileLockOptions } from "./src/file-lock.ts";
|
package/lib/index.js
CHANGED
|
@@ -10,6 +10,6 @@ export * as fileLock from "./src/file-lock.js";
|
|
|
10
10
|
export * as processLock from "./src/process-lock.js";
|
|
11
11
|
export * as project from "./src/project.js";
|
|
12
12
|
export { BrandContextSchema, defaultBrandContext, parseBrandContext, brandContextJsonSchema, brandContextPrompt } from "./src/brand.js";
|
|
13
|
-
export { MAX_TCP_PORT,
|
|
13
|
+
export { MAX_TCP_PORT, ENV_ONLY, valueSchema, bundleResourceSchema, bundleEnvEntrySchema, bundleAppSchema } from "./src/config.js";
|
|
14
14
|
export { COMMAND_NOT_FOUND_EXIT_CODE } from "./src/exec.js";
|
|
15
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSwyQ0FBMkM7QUFDM0MsbURBQW1EO0FBQ25ELHdFQUF3RTtBQUV4RSxPQUFP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Rk9VTkRfRVhJVF9DT0RFIH0gZnJvbSBcIi4vc3JjL2V4ZWMudHNcIjtcbmV4cG9ydCB0eXBlIHsgRXhlY1N0ZGlvLCBMaW5lSGFuZGxlciwgU3RkaW9PcHRpb24sIEV4ZWNSZXN1bHQsIENoaWxkUHJvY2Vzc1Jlc3VsdCwgRXhlY09wdGlvbnMsIFN5bmNFeGVjU3RkaW8sIFN5bmNFeGVjT3B0aW9ucywgU3Bhd25BcmdzIH0gZnJvbSBcIi4vc3JjL2V4ZWMudHNcIjtcbmV4cG9ydCB0eXBlIHsgRmlsZUxvY2tCYWNrZW5kLCBGaWxlTG9ja0FjcXVpc2l0aW9uLCBGaWxlTG9ja09wdGlvbnMgfSBmcm9tIFwiLi9zcmMvZmlsZS1sb2NrLnRzXCI7XG5leHBvcnQgdHlwZSB7IFByb2plY3RDb250ZXh0IH0gZnJvbSBcIi4vc3JjL3Byb2plY3QudHNcIjtcbiJdfQ==
|
package/lib/src/config.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Every package resolves settings the same way: take the caller's value, else
|
|
5
5
|
* an environment variable, else a default. Local development adds two fallback
|
|
6
|
-
* locations: `.env` files and `resources.apps.<app>.config.env`
|
|
7
|
-
* `
|
|
6
|
+
* locations: `.env` files and one App's `resources.apps.<app>.config.env` in
|
|
7
|
+
* `databricks.yml`.
|
|
8
8
|
*
|
|
9
9
|
* Two things make it cheap to call from a hot path:
|
|
10
10
|
*
|
|
@@ -20,24 +20,6 @@
|
|
|
20
20
|
* CLI is not on the image. Boolean environment overrides can force either file
|
|
21
21
|
* source on or off when a tool needs different behavior.
|
|
22
22
|
*
|
|
23
|
-
* The bundle is gated on this being an AppKit project at all. `databricks bundle
|
|
24
|
-
* validate` is a process spawn measured in seconds, and a plain library or CLI
|
|
25
|
-
* consumer has no bundle to find, so the gate runs in three steps before the
|
|
26
|
-
* spawn is allowed - see {@link bundleFile}:
|
|
27
|
-
*
|
|
28
|
-
* 1. `@databricks/appkit` is resolved WITHOUT evaluating it. It is an optional
|
|
29
|
-
* peer, so a consumer that never installed it is not an AppKit project and
|
|
30
|
-
* the bundle is never loaded. The probe is cached, so this costs one
|
|
31
|
-
* resolution for the life of the process.
|
|
32
|
-
* 2. The bundle is read (once per context) and must describe EXACTLY ONE app
|
|
33
|
-
* with `config.env`. Nothing here says which of several apps this process
|
|
34
|
-
* is, so an ambiguous bundle contributes nothing rather than a guess.
|
|
35
|
-
* 3. AppKit's execution context confirms this process really is that app. The
|
|
36
|
-
* context does not exist until AppKit boots and `getExecutionContext()`
|
|
37
|
-
* THROWS until then, so the probe is caught and only the affirmative is
|
|
38
|
-
* remembered - a lookup before boot still resolves, and re-confirms later
|
|
39
|
-
* once the context is available.
|
|
40
|
-
*
|
|
41
23
|
* Only the single app's `config.env` is consulted. Root bundle `variables` are
|
|
42
24
|
* not: they are authoring inputs for the bundle itself (interpolated into
|
|
43
25
|
* targets, resources, and paths), so treating one as a process setting resolves
|
|
@@ -48,40 +30,34 @@
|
|
|
48
30
|
* @module
|
|
49
31
|
*/
|
|
50
32
|
import { z } from "zod";
|
|
51
|
-
|
|
33
|
+
type ConfigKey = string | readonly string[];
|
|
52
34
|
/** Where a value may come from, consulted in the order given. */
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
type ConfigSource = "env" | "dotenv" | "bundle";
|
|
36
|
+
interface ConfigOptions {
|
|
55
37
|
/**
|
|
56
38
|
* Outermost namespaces tried before each key. Defaults to `DBX_TOOLS`.
|
|
57
39
|
*/
|
|
58
40
|
scope?: string | readonly string[];
|
|
59
41
|
/** Capability namespaces inserted after the scope and before each key. */
|
|
60
42
|
prefix?: string | readonly string[];
|
|
61
|
-
/** Directory to resolve `.env` and the bundle from. Default: `process.cwd()`. */
|
|
62
|
-
cwd?: string;
|
|
63
43
|
/** Sources in precedence order. Default: `env`, `dotenv`, `bundle`. */
|
|
64
44
|
sources?: ConfigSource | readonly ConfigSource[];
|
|
45
|
+
/** Directory to resolve `.env` and the bundle from. Default: `process.cwd()`. */
|
|
46
|
+
cwd?: string;
|
|
65
47
|
}
|
|
66
48
|
/** A config file found on disk, with its parsed contents. */
|
|
67
|
-
|
|
49
|
+
interface ConfigFile {
|
|
68
50
|
path: string;
|
|
69
51
|
data: Record<string, unknown>;
|
|
70
52
|
}
|
|
71
53
|
/** Highest valid TCP port number. */
|
|
72
54
|
export declare const MAX_TCP_PORT = 65535;
|
|
73
|
-
/** Boolean environment override for {@link isDatabricksAppEnv}. */
|
|
74
|
-
export declare const DATABRICKS_APP_ENV_KEY = "DBX_TOOLS_DATABRICKS_APP_ENV";
|
|
75
|
-
/** Boolean environment override for project `.env` reads. */
|
|
76
|
-
export declare const CONFIG_DOTENV_KEY = "DBX_TOOLS_CONFIG_DOTENV";
|
|
77
|
-
/** Boolean environment override for Databricks bundle reads. */
|
|
78
|
-
export declare const CONFIG_BUNDLE_KEY = "DBX_TOOLS_CONFIG_BUNDLE";
|
|
79
55
|
/** Exact process-environment lookup for callers that do not read local config files. */
|
|
80
56
|
export declare const ENV_ONLY: {
|
|
81
57
|
scope: readonly [];
|
|
82
58
|
sources: "env";
|
|
83
59
|
};
|
|
84
|
-
export declare const
|
|
60
|
+
export declare const valueSchema: z.ZodString;
|
|
85
61
|
/**
|
|
86
62
|
* The GENERIC shape of a bundle resource: a name, and whatever else the resource
|
|
87
63
|
* type carries. Deliberately unopinionated and `passthrough()` - the concrete
|
|
@@ -90,25 +66,24 @@ export declare const bundleValue: z.ZodPipe<z.ZodString, z.ZodTransform<string,
|
|
|
90
66
|
* node-appkit `.extend()`s this rather than this module knowing about them.
|
|
91
67
|
*/
|
|
92
68
|
export declare const bundleResourceSchema: z.ZodObject<{
|
|
93
|
-
name: z.ZodOptional<z.
|
|
69
|
+
name: z.ZodOptional<z.ZodString>;
|
|
94
70
|
}, z.core.$loose>;
|
|
95
71
|
export declare const bundleEnvEntrySchema: z.ZodObject<{
|
|
96
|
-
name: z.ZodOptional<z.
|
|
72
|
+
name: z.ZodOptional<z.ZodString>;
|
|
97
73
|
value: z.ZodOptional<z.ZodString>;
|
|
98
|
-
value_from: z.ZodOptional<z.
|
|
74
|
+
value_from: z.ZodOptional<z.ZodString>;
|
|
99
75
|
}, z.core.$strip>;
|
|
100
76
|
export declare const bundleAppSchema: z.ZodObject<{
|
|
101
|
-
name: z.ZodOptional<z.
|
|
102
|
-
source_code_path: z.ZodOptional<z.ZodString>;
|
|
77
|
+
name: z.ZodOptional<z.ZodString>;
|
|
103
78
|
config: z.ZodOptional<z.ZodObject<{
|
|
104
79
|
env: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
105
|
-
name: z.ZodOptional<z.
|
|
80
|
+
name: z.ZodOptional<z.ZodString>;
|
|
106
81
|
value: z.ZodOptional<z.ZodString>;
|
|
107
|
-
value_from: z.ZodOptional<z.
|
|
82
|
+
value_from: z.ZodOptional<z.ZodString>;
|
|
108
83
|
}, z.core.$strip>>>;
|
|
109
84
|
}, z.core.$strip>>;
|
|
110
85
|
resources: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
111
|
-
name: z.ZodOptional<z.
|
|
86
|
+
name: z.ZodOptional<z.ZodString>;
|
|
112
87
|
}, z.core.$loose>>>;
|
|
113
88
|
}, z.core.$strip>;
|
|
114
89
|
/**
|
|
@@ -162,6 +137,12 @@ export declare function positiveNumber(configured: unknown, input: ConfigKey, fa
|
|
|
162
137
|
* these are ceilings where a sane default beats a boot failure.
|
|
163
138
|
*/
|
|
164
139
|
export declare function positiveInt(configured: unknown, input: ConfigKey, fallback: number, options?: ConfigOptions): number;
|
|
140
|
+
/**
|
|
141
|
+
* Resolve a TCP port between 1 and {@link MAX_TCP_PORT}. Invalid configured or
|
|
142
|
+
* sourced values fall back to the caller's default, which may be a sentinel
|
|
143
|
+
* such as `0` when the caller uses one.
|
|
144
|
+
*/
|
|
145
|
+
export declare function port(configured: unknown, input: ConfigKey, fallback: number, options?: ConfigOptions): number;
|
|
165
146
|
/**
|
|
166
147
|
* Resolve a list through `string.parseList`, so an array from typed config and a
|
|
167
148
|
* `"a, b c"` string normalize identically. `[]` when neither source has entries.
|
|
@@ -171,16 +152,9 @@ export declare function list(configured: string | readonly string[] | undefined
|
|
|
171
152
|
* The Databricks bundle output for `cwd` - `databricks bundle validate --output
|
|
172
153
|
* json` run from the directory holding `databricks.yml`, with the config file's
|
|
173
154
|
* path. A non-zero validation may still return partial JSON with usable App
|
|
174
|
-
* config. `undefined` when bundle reads are disabled,
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* The spawn is guarded because it is expensive and usually pointless. In order:
|
|
179
|
-
* `@databricks/appkit` must be RESOLVABLE (no AppKit, no bundle - and the probe
|
|
180
|
-
* never evaluates the module); the bundle must describe exactly ONE app carrying
|
|
181
|
-
* `config.env`; and AppKit's execution context must confirm this process is that
|
|
182
|
-
* app. Only the confirmation is remembered, so a lookup during boot - before any
|
|
183
|
-
* context exists - still resolves from the bundle and re-confirms later.
|
|
155
|
+
* config. `undefined` when bundle reads are disabled, the process is production
|
|
156
|
+
* or a deployed App without an explicit override, there is no bundle, or the
|
|
157
|
+
* CLI produces no JSON.
|
|
184
158
|
*
|
|
185
159
|
* Cached once per resolved working-directory context and
|
|
186
160
|
* `DATABRICKS_CONFIG_PROFILE` through {@link context.cached}, so repeated
|
|
@@ -188,3 +162,4 @@ export declare function list(configured: string | readonly string[] | undefined
|
|
|
188
162
|
* context's bundle.
|
|
189
163
|
*/
|
|
190
164
|
export declare function bundleFile(cwd?: string | null): ConfigFile | undefined;
|
|
165
|
+
export {};
|