bun-query-builder 0.2.4 → 0.2.5

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
@@ -18078,10 +18078,26 @@ export default model
18078
18078
  var init_make_model = () => {};
18079
18079
 
18080
18080
  // src/drivers/index-name.ts
18081
+ function fingerprint(value) {
18082
+ let hash = 2166136261;
18083
+ for (let i = 0;i < value.length; i++) {
18084
+ hash ^= value.charCodeAt(i);
18085
+ hash = Math.imul(hash, 16777619) >>> 0;
18086
+ }
18087
+ return hash.toString(36).padStart(7, "0").slice(-7);
18088
+ }
18089
+ function boundIdentifier(name, limit = MAX_IDENTIFIER_LENGTH) {
18090
+ if (name.length <= limit)
18091
+ return name;
18092
+ const suffix = `_${fingerprint(name)}`;
18093
+ return name.slice(0, limit - suffix.length) + suffix;
18094
+ }
18081
18095
  function qualifiedIndexName(tableName, indexName) {
18082
18096
  const prefix = `${tableName}_`;
18083
- return indexName.startsWith(prefix) ? indexName : `${prefix}${indexName}`;
18097
+ const qualified = indexName.startsWith(prefix) ? indexName : `${prefix}${indexName}`;
18098
+ return boundIdentifier(qualified);
18084
18099
  }
18100
+ var MAX_IDENTIFIER_LENGTH = 63;
18085
18101
 
18086
18102
  // src/drivers/mysql.ts
18087
18103
  class MySQLDriver {
@@ -31464,7 +31480,7 @@ function getPrefix() {
31464
31480
  }
31465
31481
  var prefix = getPrefix();
31466
31482
  // package.json
31467
- var version2 = "0.2.4";
31483
+ var version2 = "0.2.5";
31468
31484
 
31469
31485
  // bin/cli.ts
31470
31486
  init_actions();
@@ -1 +1,28 @@
1
+ /**
2
+ * Shorten a name to what the database will actually store.
3
+ *
4
+ * Truncating and appending the fingerprint of the full name keeps the result
5
+ * readable at the front - where the table and column names are - and unique at
6
+ * the back.
7
+ */
8
+ export declare function boundIdentifier(name: string, limit?: unknown): string;
9
+ /**
10
+ * The name an index has in the database.
11
+ *
12
+ * Qualified with its table when it is not already, then bounded. Both halves
13
+ * have to happen here rather than at the call sites, because the diff compares
14
+ * what the model declares against what the database reports, and those only
15
+ * agree if the same function produced both.
16
+ */
1
17
  export declare function qualifiedIndexName(tableName: string, indexName: string): string;
18
+ /**
19
+ * Postgres truncates any identifier over 63 bytes, silently, with a notice
20
+ * nobody reads. MySQL refuses one over 64 outright.
21
+ *
22
+ * A truncated index name is worse than a rejected one. The database ends up
23
+ * holding a name the model never declared, so the next diff looks for the
24
+ * declared name, does not find it, and proposes creating it - forever. That is
25
+ * exactly what "drop and recreate this index, unchanged, on every single run"
26
+ * looks like from the outside.
27
+ */
28
+ export declare const MAX_IDENTIFIER_LENGTH: 63;
package/dist/src/index.js CHANGED
@@ -18077,10 +18077,26 @@ export default model
18077
18077
  var init_make_model = () => {};
18078
18078
 
18079
18079
  // src/drivers/index-name.ts
18080
+ function fingerprint(value) {
18081
+ let hash = 2166136261;
18082
+ for (let i = 0;i < value.length; i++) {
18083
+ hash ^= value.charCodeAt(i);
18084
+ hash = Math.imul(hash, 16777619) >>> 0;
18085
+ }
18086
+ return hash.toString(36).padStart(7, "0").slice(-7);
18087
+ }
18088
+ function boundIdentifier(name, limit = MAX_IDENTIFIER_LENGTH) {
18089
+ if (name.length <= limit)
18090
+ return name;
18091
+ const suffix = `_${fingerprint(name)}`;
18092
+ return name.slice(0, limit - suffix.length) + suffix;
18093
+ }
18080
18094
  function qualifiedIndexName(tableName, indexName) {
18081
18095
  const prefix = `${tableName}_`;
18082
- return indexName.startsWith(prefix) ? indexName : `${prefix}${indexName}`;
18096
+ const qualified = indexName.startsWith(prefix) ? indexName : `${prefix}${indexName}`;
18097
+ return boundIdentifier(qualified);
18083
18098
  }
18099
+ var MAX_IDENTIFIER_LENGTH = 63;
18084
18100
 
18085
18101
  // src/drivers/mysql.ts
18086
18102
  class MySQLDriver {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.2.4",
4
+ "version": "0.2.5",
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",