bun-query-builder 0.1.62 → 0.1.63

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/bin/cli.js CHANGED
@@ -11662,26 +11662,23 @@ function getPlaceholders(count, startIndex = 1) {
11662
11662
  return count === 1 ? "?" : `?${", ?".repeat(count - 1)}`;
11663
11663
  }
11664
11664
  async function getConfig() {
11665
- if (!_config) {
11666
- _config = await loadConfig6({
11665
+ if (!configState.fileLoaded) {
11666
+ configState.fileLoaded = true;
11667
+ const loaded = await loadConfig6({
11667
11668
  name: "query-builder",
11668
11669
  alias: "qb",
11669
11670
  defaultConfig: defaultConfig4
11670
11671
  });
11671
- setConfig(_config);
11672
+ const applicable = {};
11673
+ for (const [key, value] of Object.entries(loaded ?? {})) {
11674
+ if (!configState.explicit.has(key))
11675
+ applicable[key] = value;
11676
+ }
11677
+ applyConfig(applicable);
11672
11678
  }
11673
11679
  return config5;
11674
11680
  }
11675
- function setConfig(userConfig) {
11676
- if (userConfig.dialect && _lastConfiguredDialect && userConfig.dialect !== _lastConfiguredDialect) {
11677
- const key = `${_lastConfiguredDialect}->${userConfig.dialect}`;
11678
- if (!_warnedDialectConflicts.has(key)) {
11679
- _warnedDialectConflicts.add(key);
11680
- console.warn(`[query-builder] setConfig({ dialect: '${userConfig.dialect}' }) overrides a previous ` + `setConfig({ dialect: '${_lastConfiguredDialect}' }). ` + `Config is process-wide; in-flight queries from the previous configuration may break. ` + `Run conflicting connections in separate processes \u2014 see stacksjs/stacks#1862 #18.`);
11681
- }
11682
- }
11683
- if (userConfig.dialect)
11684
- _lastConfiguredDialect = userConfig.dialect;
11681
+ function applyConfig(userConfig) {
11685
11682
  Object.assign(config5, userConfig);
11686
11683
  if (userConfig.database) {
11687
11684
  config5.database = { ...config5.database, ...userConfig.database };
@@ -11695,11 +11692,22 @@ function setConfig(userConfig) {
11695
11692
  if (userConfig.softDeletes) {
11696
11693
  config5.softDeletes = { ...config5.softDeletes, ...userConfig.softDeletes };
11697
11694
  }
11698
- if (_config) {
11699
- Object.assign(_config, config5);
11695
+ }
11696
+ function setConfig(userConfig) {
11697
+ if (userConfig.dialect && _lastConfiguredDialect && userConfig.dialect !== _lastConfiguredDialect) {
11698
+ const key = `${_lastConfiguredDialect}->${userConfig.dialect}`;
11699
+ if (!_warnedDialectConflicts.has(key)) {
11700
+ _warnedDialectConflicts.add(key);
11701
+ console.warn(`[query-builder] setConfig({ dialect: '${userConfig.dialect}' }) overrides a previous ` + `setConfig({ dialect: '${_lastConfiguredDialect}' }). ` + `Config is process-wide; in-flight queries from the previous configuration may break. ` + `Run conflicting connections in separate processes \u2014 see stacksjs/stacks#1862 #18.`);
11702
+ }
11700
11703
  }
11704
+ if (userConfig.dialect)
11705
+ _lastConfiguredDialect = userConfig.dialect;
11706
+ for (const key of Object.keys(userConfig))
11707
+ configState.explicit.add(key);
11708
+ applyConfig(userConfig);
11701
11709
  }
11702
- var defaultConfig4, CONFIG_SINGLETON_KEY, config5, _config = null, _lastConfiguredDialect = null, _warnedDialectConflicts;
11710
+ var defaultConfig4, CONFIG_SINGLETON_KEY, config5, CONFIG_STATE_KEY, configState, _lastConfiguredDialect = null, _warnedDialectConflicts;
11703
11711
  var init_config = __esm(() => {
11704
11712
  init_dist();
11705
11713
  defaultConfig4 = {
@@ -11762,6 +11770,8 @@ var init_config = __esm(() => {
11762
11770
  };
11763
11771
  CONFIG_SINGLETON_KEY = Symbol.for("bun-query-builder.config");
11764
11772
  config5 = globalThis[CONFIG_SINGLETON_KEY] ??= { ...defaultConfig4 };
11773
+ CONFIG_STATE_KEY = Symbol.for("bun-query-builder.config-state");
11774
+ configState = globalThis[CONFIG_STATE_KEY] ??= { explicit: new Set, fileLoaded: false };
11765
11775
  _warnedDialectConflicts = new Set;
11766
11776
  });
11767
11777
 
@@ -27378,7 +27388,7 @@ function resolveKeyPattern(keyPatterns, data) {
27378
27388
  }
27379
27389
  return resolved;
27380
27390
  }
27381
- async function parseStacksModels(_config2) {
27391
+ async function parseStacksModels(_config) {
27382
27392
  return { models: new Map };
27383
27393
  }
27384
27394
  function toDynamoDBItem(item) {
@@ -31153,7 +31163,7 @@ function getPrefix() {
31153
31163
  }
31154
31164
  var prefix = getPrefix();
31155
31165
  // package.json
31156
- var version2 = "0.1.62";
31166
+ var version2 = "0.1.63";
31157
31167
 
31158
31168
  // bin/cli.ts
31159
31169
  init_actions();
package/dist/config.d.ts CHANGED
@@ -35,9 +35,23 @@ export declare function getPlaceholders(count: number, startIndex?: number): str
35
35
  * It is intentionally explicit/async: the builder otherwise runs purely off the
36
36
  * synchronous `config` singleton (defaults + any `setConfig`), which keeps
37
37
  * `bun --compile` and test behavior deterministic — auto-loading a file in the
38
- * background would make early queries race the load. Previously this wrote the
39
- * loaded config to a private `_config` variable that nothing else read, so a
40
- * config file silently never took effect; it now routes through `setConfig`.
38
+ * background would make early queries race the load.
39
+ *
40
+ * Precedence is `defaults < config file < setConfig()`. bunfig returns a fully
41
+ * populated object (defaults merged with the file and env), which is fine for
42
+ * every key the caller has not spoken for — re-applying a default on top of the
43
+ * singleton that already holds that default is a no-op. It is NOT fine for keys
44
+ * an embedder set through `setConfig()`: those came back as library defaults and
45
+ * silently overwrote the embedder's choice. `setConfig({ snapshotDir })`
46
+ * followed by a `generateMigration()` (which calls this) reverted the snapshot
47
+ * to `.qb` and wrote generated state into the project root.
48
+ *
49
+ * So the loaded object is applied with those keys filtered out — an explicit API
50
+ * call is a stronger signal than a file that may not know the embedder exists.
51
+ *
52
+ * Note the load MUST pass `defaultConfig`: bunfig derives the environment
53
+ * variable names it recognises (`QUERY_BUILDER_*`) from the shape of the
54
+ * defaults, so passing an empty object silently drops env-var support.
41
55
  */
42
56
  export declare function getConfig(): Promise<QueryBuilderConfig>;
43
57
  export declare function setConfig(userConfig: Partial<QueryBuilderConfig>): void;
package/dist/db.d.ts CHANGED
@@ -38,6 +38,12 @@ export declare function getOrCreateBunSql(forceNew?: boolean): SQL;
38
38
  export declare function resetConnection(): void;
39
39
  /**
40
40
  * Inject a custom SQL instance. Useful for tests or custom connection setups.
41
+ *
42
+ * The signature is stamped alongside it so `getOrCreateBunSql()` treats the
43
+ * injected instance as current: leaving it null would read as "config changed"
44
+ * on the very next call and the injection would be discarded before it was ever
45
+ * used. It also means a later `setConfig()` that changes the connection still
46
+ * invalidates the injected instance, which is the point of the signature.
41
47
  */
42
48
  export declare function setSqlInstance(sql: SQL): void;
43
49
  // Wrapper that catches "Connection closed" errors and retries with a fresh connection
package/dist/src/index.js CHANGED
@@ -11661,26 +11661,23 @@ function getPlaceholders(count, startIndex = 1) {
11661
11661
  return count === 1 ? "?" : `?${", ?".repeat(count - 1)}`;
11662
11662
  }
11663
11663
  async function getConfig() {
11664
- if (!_config) {
11665
- _config = await loadConfig6({
11664
+ if (!configState.fileLoaded) {
11665
+ configState.fileLoaded = true;
11666
+ const loaded = await loadConfig6({
11666
11667
  name: "query-builder",
11667
11668
  alias: "qb",
11668
11669
  defaultConfig: defaultConfig4
11669
11670
  });
11670
- setConfig(_config);
11671
+ const applicable = {};
11672
+ for (const [key, value] of Object.entries(loaded ?? {})) {
11673
+ if (!configState.explicit.has(key))
11674
+ applicable[key] = value;
11675
+ }
11676
+ applyConfig(applicable);
11671
11677
  }
11672
11678
  return config5;
11673
11679
  }
11674
- function setConfig(userConfig) {
11675
- if (userConfig.dialect && _lastConfiguredDialect && userConfig.dialect !== _lastConfiguredDialect) {
11676
- const key = `${_lastConfiguredDialect}->${userConfig.dialect}`;
11677
- if (!_warnedDialectConflicts.has(key)) {
11678
- _warnedDialectConflicts.add(key);
11679
- console.warn(`[query-builder] setConfig({ dialect: '${userConfig.dialect}' }) overrides a previous ` + `setConfig({ dialect: '${_lastConfiguredDialect}' }). ` + `Config is process-wide; in-flight queries from the previous configuration may break. ` + `Run conflicting connections in separate processes \u2014 see stacksjs/stacks#1862 #18.`);
11680
- }
11681
- }
11682
- if (userConfig.dialect)
11683
- _lastConfiguredDialect = userConfig.dialect;
11680
+ function applyConfig(userConfig) {
11684
11681
  Object.assign(config5, userConfig);
11685
11682
  if (userConfig.database) {
11686
11683
  config5.database = { ...config5.database, ...userConfig.database };
@@ -11694,11 +11691,22 @@ function setConfig(userConfig) {
11694
11691
  if (userConfig.softDeletes) {
11695
11692
  config5.softDeletes = { ...config5.softDeletes, ...userConfig.softDeletes };
11696
11693
  }
11697
- if (_config) {
11698
- Object.assign(_config, config5);
11694
+ }
11695
+ function setConfig(userConfig) {
11696
+ if (userConfig.dialect && _lastConfiguredDialect && userConfig.dialect !== _lastConfiguredDialect) {
11697
+ const key = `${_lastConfiguredDialect}->${userConfig.dialect}`;
11698
+ if (!_warnedDialectConflicts.has(key)) {
11699
+ _warnedDialectConflicts.add(key);
11700
+ console.warn(`[query-builder] setConfig({ dialect: '${userConfig.dialect}' }) overrides a previous ` + `setConfig({ dialect: '${_lastConfiguredDialect}' }). ` + `Config is process-wide; in-flight queries from the previous configuration may break. ` + `Run conflicting connections in separate processes \u2014 see stacksjs/stacks#1862 #18.`);
11701
+ }
11699
11702
  }
11703
+ if (userConfig.dialect)
11704
+ _lastConfiguredDialect = userConfig.dialect;
11705
+ for (const key of Object.keys(userConfig))
11706
+ configState.explicit.add(key);
11707
+ applyConfig(userConfig);
11700
11708
  }
11701
- var defaultConfig4, CONFIG_SINGLETON_KEY, config5, _config = null, _lastConfiguredDialect = null, _warnedDialectConflicts;
11709
+ var defaultConfig4, CONFIG_SINGLETON_KEY, config5, CONFIG_STATE_KEY, configState, _lastConfiguredDialect = null, _warnedDialectConflicts;
11702
11710
  var init_config = __esm(() => {
11703
11711
  init_dist();
11704
11712
  defaultConfig4 = {
@@ -11761,6 +11769,8 @@ var init_config = __esm(() => {
11761
11769
  };
11762
11770
  CONFIG_SINGLETON_KEY = Symbol.for("bun-query-builder.config");
11763
11771
  config5 = globalThis[CONFIG_SINGLETON_KEY] ??= { ...defaultConfig4 };
11772
+ CONFIG_STATE_KEY = Symbol.for("bun-query-builder.config-state");
11773
+ configState = globalThis[CONFIG_STATE_KEY] ??= { explicit: new Set, fileLoaded: false };
11764
11774
  _warnedDialectConflicts = new Set;
11765
11775
  });
11766
11776
 
@@ -27377,7 +27387,7 @@ function resolveKeyPattern(keyPatterns, data) {
27377
27387
  }
27378
27388
  return resolved;
27379
27389
  }
27380
- async function parseStacksModels(_config2) {
27390
+ async function parseStacksModels(_config) {
27381
27391
  return { models: new Map };
27382
27392
  }
27383
27393
  function toDynamoDBItem(item) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.1.62",
4
+ "version": "0.1.63",
5
5
  "description": "A simple yet performant query builder for TypeScript. Built with Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",