@askdb/config 0.3.0-beta.1
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/LICENSE +201 -0
- package/NOTICE +10 -0
- package/README.md +97 -0
- package/dist/bootstrap.d.ts +31 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +108 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/constants.d.ts +20 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +22 -0
- package/dist/constants.js.map +1 -0
- package/dist/defaults.d.ts +20 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +46 -0
- package/dist/defaults.js.map +1 -0
- package/dist/discover.d.ts +15 -0
- package/dist/discover.d.ts.map +1 -0
- package/dist/discover.js +29 -0
- package/dist/discover.js.map +1 -0
- package/dist/env.d.ts +11 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +24 -0
- package/dist/env.js.map +1 -0
- package/dist/flatten.d.ts +7 -0
- package/dist/flatten.d.ts.map +1 -0
- package/dist/flatten.js +228 -0
- package/dist/flatten.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/load-merge.d.ts +18 -0
- package/dist/load-merge.d.ts.map +1 -0
- package/dist/load-merge.js +52 -0
- package/dist/load-merge.js.map +1 -0
- package/dist/projection.d.ts +22 -0
- package/dist/projection.d.ts.map +1 -0
- package/dist/projection.js +32 -0
- package/dist/projection.js.map +1 -0
- package/dist/runtime-config.d.ts +59 -0
- package/dist/runtime-config.d.ts.map +1 -0
- package/dist/runtime-config.js +60 -0
- package/dist/runtime-config.js.map +1 -0
- package/dist/runtime-store.d.ts +21 -0
- package/dist/runtime-store.d.ts.map +1 -0
- package/dist/runtime-store.js +40 -0
- package/dist/runtime-store.js.map +1 -0
- package/dist/types.d.ts +169 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may accept and charge a
|
|
167
|
+
fee for, the acceptance of support, warranty, indemnity, or
|
|
168
|
+
other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Yahya Gilany
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
AskDB
|
|
2
|
+
Copyright 2026 Yahya Gilany
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Yahya Gilany and contributors.
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License.
|
|
8
|
+
You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# `@askdb/config`
|
|
2
|
+
|
|
3
|
+
Prisma-style helpers for AskDB: `env()`, `defineConfig()`, plus discovery and loading of `askdb.config.*` / `.config/askdb.*` files used by first-party apps (`askdb` CLI, `@askdb/http-api`, `@askdb/studio`).
|
|
4
|
+
|
|
5
|
+
**`@askdb/config` is the single package that reads `process.env` directly** (during dotenv load, while `askdb.config.*` evaluates, and for a tiny bootstrap-time overlay allowlist). All other packages obtain configuration through **`getAskDbRuntimeConfig()`**.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @askdb/config
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Config file discovery
|
|
14
|
+
|
|
15
|
+
AskDB searches the working directory (`cwd`, usually `process.cwd()`) in this order:
|
|
16
|
+
|
|
17
|
+
1. `askdb.config.<ext>` — extension precedence: `ts` → `mts` → `cts` → `js` → `mjs` → `cjs` (first existing file wins).
|
|
18
|
+
2. `.config/askdb.<ext>` — same extension precedence.
|
|
19
|
+
|
|
20
|
+
This mirrors the layout described in [Prisma's config reference](https://www.prisma.io/docs/orm/reference/prisma-config-reference), but uses **`.config/askdb.*`** so it does not collide with Prisma's own `.config/prisma.*` files.
|
|
21
|
+
|
|
22
|
+
## Example `askdb.config.ts`
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import "dotenv/config";
|
|
26
|
+
import { defineConfig, env, type AskDbConfig } from "@askdb/config";
|
|
27
|
+
|
|
28
|
+
export default defineConfig({
|
|
29
|
+
ai: {
|
|
30
|
+
provider: "openai",
|
|
31
|
+
providerConfig: {
|
|
32
|
+
openai: {
|
|
33
|
+
apiKey: env("MY_OPENAI_API_KEY"),
|
|
34
|
+
model: env("MY_CHAT_MODEL"),
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
database: {
|
|
39
|
+
provider: "postgres",
|
|
40
|
+
providerConfig: { postgres: { databaseUrl: env("MY_DATABASE_URL") } },
|
|
41
|
+
},
|
|
42
|
+
introspection: {
|
|
43
|
+
provider: "postgres",
|
|
44
|
+
providerConfig: { postgres: {} },
|
|
45
|
+
outputDir: env("MY_INTROSPECT_OUTPUT_DIR"),
|
|
46
|
+
},
|
|
47
|
+
rag: {
|
|
48
|
+
embedder: "mock",
|
|
49
|
+
embedderConfig: {},
|
|
50
|
+
store: "memory",
|
|
51
|
+
storeConfig: { memory: {} },
|
|
52
|
+
},
|
|
53
|
+
} satisfies AskDbConfig);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Your `.env` can use friendly names (`MY_OPENAI_API_KEY`, …). `defineConfig` runs `flattenAskDbConfig`, which maps the nested object onto the canonical environment variable names used in the **runtime flat map** (and in `aiEnv` for `@askdb/core`). **Unset optional fields get defaults inside `flattenAskDbConfig`** (chat model, introspection output dir, database URL fallbacks, RAG embedding dimensions, file-store base path, pgvector index strategy, etc. — see `packages/config/src/defaults.ts`).
|
|
57
|
+
|
|
58
|
+
## Architectural rule — `@askdb/config` is the sole `process.env` reader
|
|
59
|
+
|
|
60
|
+
**Only `@askdb/config` reads `process.env` directly.** All AskDB library packages obtain their
|
|
61
|
+
configuration through a single typed gateway:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { getAskDbRuntimeConfig } from "@askdb/config";
|
|
65
|
+
|
|
66
|
+
const config = getAskDbRuntimeConfig();
|
|
67
|
+
const apiKey = opts.apiKey ?? config.rag.embedder.apiKey;
|
|
68
|
+
const level = config.logging.level;
|
|
69
|
+
// For @askdb/core functions that accept an env-map argument:
|
|
70
|
+
const model = await createAskDbLanguageModelFromEnv(config.ai.aiEnv, { ... });
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Rules:**
|
|
74
|
+
|
|
75
|
+
- Library packages (`@askdb/rag`, `@askdb/tui`, …) must call `getAskDbRuntimeConfig()` and use the returned typed fields. They must **not** call `env()`, `requiredEnv()`, or access `process.env` directly.
|
|
76
|
+
- `env(name)` is only for use inside `askdb.config.*` files authored by end users — it maps friendly `.env` names onto values that become part of the structured config and flat map.
|
|
77
|
+
- First-party app entry points call `bootstrapAskDbEnv()` at start-up. That loads dotenv, evaluates `askdb.config.*`, and installs an **in-memory runtime snapshot** (structured config + flat map + derived `aiEnv`). It does **not** copy AskDB settings into `process.env`.
|
|
78
|
+
|
|
79
|
+
## Migration from legacy flat config
|
|
80
|
+
|
|
81
|
+
`export default { OPENAI_API_KEY: "…" }` is **no longer supported**. Use nested `defineConfig({ ... satisfies AskDbConfig })` and `export default defineConfig({ … })`.
|
|
82
|
+
|
|
83
|
+
## API
|
|
84
|
+
|
|
85
|
+
- `getAskDbRuntimeConfig()` — **primary API for library packages**. Returns a typed `AskDbRuntimeConfig` from the bootstrapped snapshot (`structured`, `flat`-derived fields, and `ai.aiEnv` for `@askdb/core`).
|
|
86
|
+
- `env(name)` / `requiredEnv(name)` — read `process.env` while authoring `askdb.config.*` only.
|
|
87
|
+
- `defineConfig(config)` — returns an `AskDbEnvProjection` with `config` (structured) and `entries` (flattened canonical map).
|
|
88
|
+
- `flattenAskDbConfig(config)` — nested config → flat canonical map (applies defaults for optional values).
|
|
89
|
+
- `bootstrapAskDbEnv(options?)` / `bootstrapAskDbRuntime` — load dotenv, load config, install the runtime snapshot.
|
|
90
|
+
- `loadAskDbConfigProjection(cwd)` / `loadAskDbConfigProjectionSync(cwd)` — load projection without installing the singleton (advanced / tests).
|
|
91
|
+
- `discoverAskDbConfigPath(cwd)` — returns the resolved config path, if any.
|
|
92
|
+
- `mergeAskDbFlatIntoEnvMap(base, flat)` — merge AskDB flat entries into an env map for **child processes** (does not read `process.env` itself). Use `getAskDbRuntimeConfig().flat` as `flat` after bootstrap.
|
|
93
|
+
- `setAskDbRuntimeForTests` / `resetAskDbRuntimeForTests` — test helpers for the runtime snapshot.
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
Apache-2.0. See [LICENSE](./LICENSE) and [NOTICE](./NOTICE).
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type BootstrapAskDbEnvOptions = {
|
|
2
|
+
/** Working directory for `.env` default path and config discovery. Defaults to `process.cwd()`. */
|
|
3
|
+
cwd?: string;
|
|
4
|
+
/**
|
|
5
|
+
* Explicit `.env` file paths to try in order. First existing file wins.
|
|
6
|
+
* When omitted, loads `${cwd}/.env` only.
|
|
7
|
+
*/
|
|
8
|
+
dotenvCandidatePaths?: readonly string[];
|
|
9
|
+
/**
|
|
10
|
+
* When `true` (default), non-ENOENT dotenv issues are logged to stderr and `process.exitCode`
|
|
11
|
+
* is set to `1`, matching legacy `askdb` CLI / `@askdb/http-api` behavior. Set `false` to throw instead.
|
|
12
|
+
*/
|
|
13
|
+
dotenvNonFatal?: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Loads dotenv (optional `.env` candidates), then loads `askdb.config.*` / `.config/askdb.*`
|
|
17
|
+
* and installs the AskDB runtime snapshot (structured config + flattened canonical keys).
|
|
18
|
+
*
|
|
19
|
+
* Does **not** merge AskDB settings into `process.env`. Use {@link getAskDbRuntimeConfig} to read configuration.
|
|
20
|
+
*
|
|
21
|
+
* A small allowlist of shell variables (e.g. `ASKDB_MOCK_SQL`, `ASKDB_CORRELATION_ID`,
|
|
22
|
+
* `ASKDB_PRISMA_SCHEMA`, `ASKDB_INTROSPECT_OUT`, `DATABASE_URL`, `PORT`, `HOST`) may override flattened entries
|
|
23
|
+
* so CI/subprocesses can inject values such as `ASKDB_MOCK_SQL` without editing the config file.
|
|
24
|
+
*/
|
|
25
|
+
export declare function bootstrapAskDbEnv(options?: BootstrapAskDbEnvOptions): {
|
|
26
|
+
dotenvPath?: string;
|
|
27
|
+
configPath?: string;
|
|
28
|
+
};
|
|
29
|
+
/** Alias for {@link bootstrapAskDbEnv} (explicit naming). */
|
|
30
|
+
export declare const bootstrapAskDbRuntime: typeof bootstrapAskDbEnv;
|
|
31
|
+
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AA+BA,MAAM,MAAM,wBAAwB,GAAG;IACrC,mGAAmG;IACnG,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,oBAAoB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAeF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAqDA;AAED,6DAA6D;AAC7D,eAAO,MAAM,qBAAqB,0BAAoB,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import dotenv from "dotenv";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { loadAskDbConfigProjectionSync } from "./load-merge.js";
|
|
5
|
+
import { setAskDbRuntime } from "./runtime-store.js";
|
|
6
|
+
/**
|
|
7
|
+
* After loading `askdb.config.*`, non-empty values for these keys in `process.env`
|
|
8
|
+
* override the flattened snapshot (tests, subprocess env, platform-assigned `PORT`, …).
|
|
9
|
+
* Scoped to `@askdb/config` bootstrap only — library code still uses `getAskDbRuntimeConfig()`.
|
|
10
|
+
*/
|
|
11
|
+
const RUNTIME_SHELL_FLAT_OVERRIDES = [
|
|
12
|
+
"ASKDB_MOCK_SQL",
|
|
13
|
+
"ASKDB_CORRELATION_ID",
|
|
14
|
+
"ASKDB_PRISMA_SCHEMA",
|
|
15
|
+
"ASKDB_INTROSPECT_OUT",
|
|
16
|
+
"DATABASE_URL",
|
|
17
|
+
"PORT",
|
|
18
|
+
"HOST",
|
|
19
|
+
];
|
|
20
|
+
function mergeShellOverridesOntoFlat(flat) {
|
|
21
|
+
for (const key of RUNTIME_SHELL_FLAT_OVERRIDES) {
|
|
22
|
+
const raw = process.env[key];
|
|
23
|
+
if (raw === undefined)
|
|
24
|
+
continue;
|
|
25
|
+
const trimmed = raw.trim();
|
|
26
|
+
if (trimmed === "")
|
|
27
|
+
continue;
|
|
28
|
+
flat[key] = trimmed;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function handleDotenvError(error, nonFatal) {
|
|
32
|
+
const err = error;
|
|
33
|
+
const code = typeof err.code === "string" ? err.code : undefined;
|
|
34
|
+
const message = typeof err.message === "string" ? err.message : String(error);
|
|
35
|
+
if (code === "ENOENT")
|
|
36
|
+
return;
|
|
37
|
+
if (nonFatal) {
|
|
38
|
+
console.error(`Failed to load .env: ${message}`);
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`Failed to load .env: ${message}`);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Loads dotenv (optional `.env` candidates), then loads `askdb.config.*` / `.config/askdb.*`
|
|
46
|
+
* and installs the AskDB runtime snapshot (structured config + flattened canonical keys).
|
|
47
|
+
*
|
|
48
|
+
* Does **not** merge AskDB settings into `process.env`. Use {@link getAskDbRuntimeConfig} to read configuration.
|
|
49
|
+
*
|
|
50
|
+
* A small allowlist of shell variables (e.g. `ASKDB_MOCK_SQL`, `ASKDB_CORRELATION_ID`,
|
|
51
|
+
* `ASKDB_PRISMA_SCHEMA`, `ASKDB_INTROSPECT_OUT`, `DATABASE_URL`, `PORT`, `HOST`) may override flattened entries
|
|
52
|
+
* so CI/subprocesses can inject values such as `ASKDB_MOCK_SQL` without editing the config file.
|
|
53
|
+
*/
|
|
54
|
+
export function bootstrapAskDbEnv(options = {}) {
|
|
55
|
+
const cwd = options.cwd ?? process.cwd();
|
|
56
|
+
const nonFatal = options.dotenvNonFatal ?? true;
|
|
57
|
+
let dotenvPath;
|
|
58
|
+
if (options.dotenvCandidatePaths && options.dotenvCandidatePaths.length > 0) {
|
|
59
|
+
let loaded = false;
|
|
60
|
+
for (const path of options.dotenvCandidatePaths) {
|
|
61
|
+
if (!existsSync(path))
|
|
62
|
+
continue;
|
|
63
|
+
const { error } = dotenv.config({ path });
|
|
64
|
+
if (!error) {
|
|
65
|
+
loaded = true;
|
|
66
|
+
dotenvPath = path;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!loaded) {
|
|
71
|
+
const { error } = dotenv.config();
|
|
72
|
+
if (error)
|
|
73
|
+
handleDotenvError(error, nonFatal);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const path = join(cwd, ".env");
|
|
78
|
+
const { error } = dotenv.config({ path });
|
|
79
|
+
if (error) {
|
|
80
|
+
const err = error;
|
|
81
|
+
const code = typeof err.code === "string" ? err.code : undefined;
|
|
82
|
+
if (code === "ENOENT") {
|
|
83
|
+
// Missing `.env` is normal.
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
handleDotenvError(error, nonFatal);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
dotenvPath = path;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const { path: configPath, projection } = loadAskDbConfigProjectionSync(cwd);
|
|
94
|
+
if (!configPath || !projection) {
|
|
95
|
+
throw new Error(`No askdb.config.* or .config/askdb.* found under ${cwd}. ` +
|
|
96
|
+
`Create one with \`askdb init\` or add defineConfig({ ... }) at the project root.`);
|
|
97
|
+
}
|
|
98
|
+
const flat = { ...projection.entries };
|
|
99
|
+
mergeShellOverridesOntoFlat(flat);
|
|
100
|
+
setAskDbRuntime({
|
|
101
|
+
structured: projection.config,
|
|
102
|
+
flat,
|
|
103
|
+
});
|
|
104
|
+
return { dotenvPath, configPath };
|
|
105
|
+
}
|
|
106
|
+
/** Alias for {@link bootstrapAskDbEnv} (explicit naming). */
|
|
107
|
+
export const bootstrapAskDbRuntime = bootstrapAskDbEnv;
|
|
108
|
+
//# sourceMappingURL=bootstrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep aligned with `ASKDB_MODES_V1` in `@askdb/core` (`packages/core/src/modes/types.ts`).
|
|
3
|
+
*/
|
|
4
|
+
export declare const ASKDB_MODES_V1: readonly ["schema_only", "bounded_results"];
|
|
5
|
+
export type AskDbModeV1 = (typeof ASKDB_MODES_V1)[number];
|
|
6
|
+
/**
|
|
7
|
+
* Keep aligned with Pino levels + `silent` (`@askdb/core` `SUPPORTED_ASKDB_LOG_LEVELS`).
|
|
8
|
+
*/
|
|
9
|
+
export declare const ASKDB_LOG_LEVELS: readonly ["fatal", "error", "warn", "info", "debug", "trace", "silent"];
|
|
10
|
+
export type AskDbLogLevel = (typeof ASKDB_LOG_LEVELS)[number];
|
|
11
|
+
/** RAG embedder modes used by Studio / docs (CLI RAG currently supports mock + openai). */
|
|
12
|
+
export declare const ASKDB_RAG_EMBEDDERS: readonly ["mock", "openai", "ai-sdk"];
|
|
13
|
+
export type AskDbRagEmbedder = (typeof ASKDB_RAG_EMBEDDERS)[number];
|
|
14
|
+
export declare const ASKDB_RAG_STORES: readonly ["file", "memory", "pgvector"];
|
|
15
|
+
export type AskDbRagStore = (typeof ASKDB_RAG_STORES)[number];
|
|
16
|
+
export declare const ASKDB_AI_PROVIDERS: readonly ["openai", "azure", "foundry"];
|
|
17
|
+
export type AskDbAiProviderId = (typeof ASKDB_AI_PROVIDERS)[number];
|
|
18
|
+
export declare const ASKDB_INTROSPECTION_PROVIDERS: readonly ["postgres", "prisma"];
|
|
19
|
+
export type AskDbIntrospectionProvider = (typeof ASKDB_INTROSPECTION_PROVIDERS)[number];
|
|
20
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,cAAc,6CAA8C,CAAC;AAC1E,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,gBAAgB,yEAQnB,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9D,2FAA2F;AAC3F,eAAO,MAAM,mBAAmB,uCAAwC,CAAC;AACzE,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE,eAAO,MAAM,gBAAgB,yCAA0C,CAAC;AACxE,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9D,eAAO,MAAM,kBAAkB,yCAA0C,CAAC;AAC1E,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE,eAAO,MAAM,6BAA6B,iCAAkC,CAAC;AAC7E,MAAM,MAAM,0BAA0B,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep aligned with `ASKDB_MODES_V1` in `@askdb/core` (`packages/core/src/modes/types.ts`).
|
|
3
|
+
*/
|
|
4
|
+
export const ASKDB_MODES_V1 = ["schema_only", "bounded_results"];
|
|
5
|
+
/**
|
|
6
|
+
* Keep aligned with Pino levels + `silent` (`@askdb/core` `SUPPORTED_ASKDB_LOG_LEVELS`).
|
|
7
|
+
*/
|
|
8
|
+
export const ASKDB_LOG_LEVELS = [
|
|
9
|
+
"fatal",
|
|
10
|
+
"error",
|
|
11
|
+
"warn",
|
|
12
|
+
"info",
|
|
13
|
+
"debug",
|
|
14
|
+
"trace",
|
|
15
|
+
"silent",
|
|
16
|
+
];
|
|
17
|
+
/** RAG embedder modes used by Studio / docs (CLI RAG currently supports mock + openai). */
|
|
18
|
+
export const ASKDB_RAG_EMBEDDERS = ["mock", "openai", "ai-sdk"];
|
|
19
|
+
export const ASKDB_RAG_STORES = ["file", "memory", "pgvector"];
|
|
20
|
+
export const ASKDB_AI_PROVIDERS = ["openai", "azure", "foundry"];
|
|
21
|
+
export const ASKDB_INTROSPECTION_PROVIDERS = ["postgres", "prisma"];
|
|
22
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,aAAa,EAAE,iBAAiB,CAAU,CAAC;AAG1E;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;CACA,CAAC;AAGX,2FAA2F;AAC3F,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAC;AAGzE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAU,CAAC;AAGxE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAU,CAAC;AAG1E,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAU,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical defaults applied in {@link flattenAskDbConfig} when optional env-backed
|
|
3
|
+
* fields are unset (missing, blank, or invalid after trim).
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_OPENAI_CHAT_MODEL = "gpt-4o-mini";
|
|
6
|
+
export declare const DEFAULT_AZURE_OPENAI_DEPLOYMENT = "gpt-4o-mini";
|
|
7
|
+
export declare const DEFAULT_INTROSPECT_OUTPUT_DIR = "./askdb/";
|
|
8
|
+
export declare const DEFAULT_LOCAL_POSTGRES_URL = "postgres://postgres:postgres@127.0.0.1:5432/postgres";
|
|
9
|
+
export declare const DEFAULT_RAG_EMBEDDING_MODEL = "text-embedding-3-small";
|
|
10
|
+
/** Under the same visible tree as {@link DEFAULT_INTROSPECT_OUTPUT_DIR} (`./askdb/…`). */
|
|
11
|
+
export declare const DEFAULT_RAG_FILE_BASE_PATH = "./askdb/rag";
|
|
12
|
+
export declare const DEFAULT_MOCK_RAG_EMBEDDING_DIMENSIONS = 64;
|
|
13
|
+
export declare const DEFAULT_PGVECTOR_INDEX_STRATEGY: "hnsw";
|
|
14
|
+
export declare const PGVECTOR_INDEX_STRATEGIES: readonly ["ivfflat", "hnsw", "none"];
|
|
15
|
+
export type PgvectorIndexStrategyId = (typeof PGVECTOR_INDEX_STRATEGIES)[number];
|
|
16
|
+
/** Same heuristics as Studio / `@askdb/rag` CLI for common OpenAI embedding models. */
|
|
17
|
+
export declare function defaultRagEmbeddingDimensions(model: string): number;
|
|
18
|
+
export declare function parsePositiveInteger(value: string | number | undefined): number | undefined;
|
|
19
|
+
export declare function normalizePgvectorIndexStrategy(raw: string | undefined): PgvectorIndexStrategyId;
|
|
20
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,yBAAyB,gBAAgB,CAAC;AACvD,eAAO,MAAM,+BAA+B,gBAAgB,CAAC;AAC7D,eAAO,MAAM,6BAA6B,aAAa,CAAC;AACxD,eAAO,MAAM,0BAA0B,yDAAyD,CAAC;AACjG,eAAO,MAAM,2BAA2B,2BAA2B,CAAC;AACpE,0FAA0F;AAC1F,eAAO,MAAM,0BAA0B,gBAAgB,CAAC;AACxD,eAAO,MAAM,qCAAqC,KAAK,CAAC;AACxD,eAAO,MAAM,+BAA+B,EAAG,MAAe,CAAC;AAE/D,eAAO,MAAM,yBAAyB,sCAAuC,CAAC;AAC9E,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,yBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjF,uFAAuF;AACvF,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKnE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAU3F;AAED,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,uBAAuB,CAK/F"}
|
package/dist/defaults.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical defaults applied in {@link flattenAskDbConfig} when optional env-backed
|
|
3
|
+
* fields are unset (missing, blank, or invalid after trim).
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_OPENAI_CHAT_MODEL = "gpt-4o-mini";
|
|
6
|
+
export const DEFAULT_AZURE_OPENAI_DEPLOYMENT = "gpt-4o-mini";
|
|
7
|
+
export const DEFAULT_INTROSPECT_OUTPUT_DIR = "./askdb/";
|
|
8
|
+
export const DEFAULT_LOCAL_POSTGRES_URL = "postgres://postgres:postgres@127.0.0.1:5432/postgres";
|
|
9
|
+
export const DEFAULT_RAG_EMBEDDING_MODEL = "text-embedding-3-small";
|
|
10
|
+
/** Under the same visible tree as {@link DEFAULT_INTROSPECT_OUTPUT_DIR} (`./askdb/…`). */
|
|
11
|
+
export const DEFAULT_RAG_FILE_BASE_PATH = "./askdb/rag";
|
|
12
|
+
export const DEFAULT_MOCK_RAG_EMBEDDING_DIMENSIONS = 64;
|
|
13
|
+
export const DEFAULT_PGVECTOR_INDEX_STRATEGY = "hnsw";
|
|
14
|
+
export const PGVECTOR_INDEX_STRATEGIES = ["ivfflat", "hnsw", "none"];
|
|
15
|
+
/** Same heuristics as Studio / `@askdb/rag` CLI for common OpenAI embedding models. */
|
|
16
|
+
export function defaultRagEmbeddingDimensions(model) {
|
|
17
|
+
const m = model.trim();
|
|
18
|
+
if (m === "text-embedding-3-large")
|
|
19
|
+
return 3072;
|
|
20
|
+
if (m === "text-embedding-ada-002")
|
|
21
|
+
return 1536;
|
|
22
|
+
return 1536;
|
|
23
|
+
}
|
|
24
|
+
export function parsePositiveInteger(value) {
|
|
25
|
+
if (value === undefined)
|
|
26
|
+
return undefined;
|
|
27
|
+
if (typeof value === "number") {
|
|
28
|
+
return Number.isInteger(value) && value > 0 ? value : undefined;
|
|
29
|
+
}
|
|
30
|
+
const t = value.trim();
|
|
31
|
+
if (t === "")
|
|
32
|
+
return undefined;
|
|
33
|
+
const n = Number(t);
|
|
34
|
+
if (!Number.isInteger(n) || n <= 0)
|
|
35
|
+
return undefined;
|
|
36
|
+
return n;
|
|
37
|
+
}
|
|
38
|
+
export function normalizePgvectorIndexStrategy(raw) {
|
|
39
|
+
if (raw === undefined || raw.trim() === "")
|
|
40
|
+
return DEFAULT_PGVECTOR_INDEX_STRATEGY;
|
|
41
|
+
const v = raw.trim().toLowerCase();
|
|
42
|
+
if (v === "ivfflat" || v === "hnsw" || v === "none")
|
|
43
|
+
return v;
|
|
44
|
+
throw new Error(`Invalid pgvector indexStrategy "${raw}" (expected ivfflat | hnsw | none).`);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,aAAa,CAAC;AACvD,MAAM,CAAC,MAAM,+BAA+B,GAAG,aAAa,CAAC;AAC7D,MAAM,CAAC,MAAM,6BAA6B,GAAG,UAAU,CAAC;AACxD,MAAM,CAAC,MAAM,0BAA0B,GAAG,sDAAsD,CAAC;AACjG,MAAM,CAAC,MAAM,2BAA2B,GAAG,wBAAwB,CAAC;AACpE,0FAA0F;AAC1F,MAAM,CAAC,MAAM,0BAA0B,GAAG,aAAa,CAAC;AACxD,MAAM,CAAC,MAAM,qCAAqC,GAAG,EAAE,CAAC;AACxD,MAAM,CAAC,MAAM,+BAA+B,GAAG,MAAe,CAAC;AAE/D,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAG9E,uFAAuF;AACvF,MAAM,UAAU,6BAA6B,CAAC,KAAa;IACzD,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IACvB,IAAI,CAAC,KAAK,wBAAwB;QAAE,OAAO,IAAI,CAAC;IAChD,IAAI,CAAC,KAAK,wBAAwB;QAAE,OAAO,IAAI,CAAC;IAChD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAkC;IACrE,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAClE,CAAC;IACD,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IACvB,IAAI,CAAC,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IAC/B,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IACrD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,GAAuB;IACpE,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,+BAA+B,CAAC;IACnF,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACnC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,MAAM,IAAI,CAAC,KAAK,MAAM;QAAE,OAAO,CAAC,CAAC;IAC9D,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,qCAAqC,CAAC,CAAC;AAC/F,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When multiple config files exist, the first extension in this list wins
|
|
3
|
+
* (per-family: `askdb.config.*` vs `.config/askdb.*`).
|
|
4
|
+
*/
|
|
5
|
+
export declare const ASKDB_CONFIG_EXTENSION_PRECEDENCE: readonly ["ts", "mts", "cts", "js", "mjs", "cjs"];
|
|
6
|
+
export type AskDbConfigExtension = (typeof ASKDB_CONFIG_EXTENSION_PRECEDENCE)[number];
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the path to an AskDB config file in `cwd`, or `undefined` if none exists.
|
|
9
|
+
*
|
|
10
|
+
* Discovery order:
|
|
11
|
+
* 1. `askdb.config.<ext>` in cwd (extension precedence: ts → mts → cts → js → mjs → cjs)
|
|
12
|
+
* 2. `.config/askdb.<ext>` in cwd (same extension precedence)
|
|
13
|
+
*/
|
|
14
|
+
export declare function discoverAskDbConfigPath(cwd: string): string | undefined;
|
|
15
|
+
//# sourceMappingURL=discover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../src/discover.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,iCAAiC,mDAAoD,CAAC;AAEnG,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,iCAAiC,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtF;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAavE"}
|
package/dist/discover.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* When multiple config files exist, the first extension in this list wins
|
|
5
|
+
* (per-family: `askdb.config.*` vs `.config/askdb.*`).
|
|
6
|
+
*/
|
|
7
|
+
export const ASKDB_CONFIG_EXTENSION_PRECEDENCE = ["ts", "mts", "cts", "js", "mjs", "cjs"];
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the path to an AskDB config file in `cwd`, or `undefined` if none exists.
|
|
10
|
+
*
|
|
11
|
+
* Discovery order:
|
|
12
|
+
* 1. `askdb.config.<ext>` in cwd (extension precedence: ts → mts → cts → js → mjs → cjs)
|
|
13
|
+
* 2. `.config/askdb.<ext>` in cwd (same extension precedence)
|
|
14
|
+
*/
|
|
15
|
+
export function discoverAskDbConfigPath(cwd) {
|
|
16
|
+
const families = [
|
|
17
|
+
(ext) => join(cwd, `askdb.config.${ext}`),
|
|
18
|
+
(ext) => join(cwd, ".config", `askdb.${ext}`),
|
|
19
|
+
];
|
|
20
|
+
for (const makePath of families) {
|
|
21
|
+
for (const ext of ASKDB_CONFIG_EXTENSION_PRECEDENCE) {
|
|
22
|
+
const candidate = makePath(ext);
|
|
23
|
+
if (existsSync(candidate))
|
|
24
|
+
return candidate;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=discover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.js","sourceRoot":"","sources":["../src/discover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;GAGG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAU,CAAC;AAInG;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAW;IACjD,MAAM,QAAQ,GAAG;QACf,CAAC,GAAyB,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB,GAAG,EAAE,CAAC;QAC/D,CAAC,GAAyB,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAG,EAAE,CAAC;KAC3D,CAAC;IAEX,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAAE,CAAC;QAChC,KAAK,MAAM,GAAG,IAAI,iCAAiC,EAAE,CAAC;YACpD,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;YAChC,IAAI,UAAU,CAAC,SAAS,CAAC;gBAAE,OAAO,SAAS,CAAC;QAC9C,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|