@payloadcms/drizzle 4.0.0-beta.10 → 4.0.0-beta.12

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 (66) hide show
  1. package/dist/exports/postgres.d.ts +1 -0
  2. package/dist/exports/postgres.d.ts.map +1 -1
  3. package/dist/exports/postgres.js +1 -0
  4. package/dist/exports/postgres.js.map +1 -1
  5. package/dist/find/buildPolymorphicJoinWhere.js +1 -1
  6. package/dist/find/buildPolymorphicJoinWhere.js.map +1 -1
  7. package/dist/postgres/predefinedMigrations/localize-status/getGeneratedColumnType.d.ts +26 -0
  8. package/dist/postgres/predefinedMigrations/localize-status/getGeneratedColumnType.d.ts.map +1 -0
  9. package/dist/postgres/predefinedMigrations/localize-status/getGeneratedColumnType.js +61 -0
  10. package/dist/postgres/predefinedMigrations/localize-status/getGeneratedColumnType.js.map +1 -0
  11. package/dist/postgres/predefinedMigrations/localize-status/getMigrationDB.d.ts +13 -0
  12. package/dist/postgres/predefinedMigrations/localize-status/getMigrationDB.d.ts.map +1 -0
  13. package/dist/postgres/predefinedMigrations/localize-status/getMigrationDB.js +17 -0
  14. package/dist/postgres/predefinedMigrations/localize-status/getMigrationDB.js.map +1 -0
  15. package/dist/postgres/predefinedMigrations/localize-status/index.d.ts.map +1 -1
  16. package/dist/postgres/predefinedMigrations/localize-status/index.js +73 -10
  17. package/dist/postgres/predefinedMigrations/localize-status/index.js.map +1 -1
  18. package/dist/queries/parseParams.d.ts.map +1 -1
  19. package/dist/queries/parseParams.js +54 -2
  20. package/dist/queries/parseParams.js.map +1 -1
  21. package/dist/schema/build.d.ts.map +1 -1
  22. package/dist/schema/build.js +51 -2
  23. package/dist/schema/build.js.map +1 -1
  24. package/dist/schema/traverseFields.d.ts.map +1 -1
  25. package/dist/schema/traverseFields.js +71 -14
  26. package/dist/schema/traverseFields.js.map +1 -1
  27. package/dist/transform/write/addBlockTablesToDelete.d.ts +20 -0
  28. package/dist/transform/write/addBlockTablesToDelete.d.ts.map +1 -0
  29. package/dist/transform/write/addBlockTablesToDelete.js +54 -0
  30. package/dist/transform/write/addBlockTablesToDelete.js.map +1 -0
  31. package/dist/transform/write/array.d.ts +3 -2
  32. package/dist/transform/write/array.d.ts.map +1 -1
  33. package/dist/transform/write/array.js +2 -1
  34. package/dist/transform/write/array.js.map +1 -1
  35. package/dist/transform/write/blocks.d.ts +3 -2
  36. package/dist/transform/write/blocks.d.ts.map +1 -1
  37. package/dist/transform/write/blocks.js +2 -1
  38. package/dist/transform/write/blocks.js.map +1 -1
  39. package/dist/transform/write/index.d.ts.map +1 -1
  40. package/dist/transform/write/index.js +2 -0
  41. package/dist/transform/write/index.js.map +1 -1
  42. package/dist/transform/write/traverseFields.d.ts +2 -1
  43. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  44. package/dist/transform/write/traverseFields.js +36 -5
  45. package/dist/transform/write/traverseFields.js.map +1 -1
  46. package/dist/transform/write/types.d.ts +10 -0
  47. package/dist/transform/write/types.d.ts.map +1 -1
  48. package/dist/transform/write/types.js.map +1 -1
  49. package/dist/upsertRow/deleteExistingRowsByPath.d.ts +6 -1
  50. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
  51. package/dist/upsertRow/deleteExistingRowsByPath.js +21 -3
  52. package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
  53. package/dist/upsertRow/index.d.ts.map +1 -1
  54. package/dist/upsertRow/index.js +3 -0
  55. package/dist/upsertRow/index.js.map +1 -1
  56. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  57. package/dist/upsertRow/insertArrays.js +2 -3
  58. package/dist/upsertRow/insertArrays.js.map +1 -1
  59. package/dist/utilities/createSchemaGenerator.d.ts.map +1 -1
  60. package/dist/utilities/createSchemaGenerator.js +17 -1
  61. package/dist/utilities/createSchemaGenerator.js.map +1 -1
  62. package/dist/utilities/fitIdentifierLength.d.ts +25 -0
  63. package/dist/utilities/fitIdentifierLength.d.ts.map +1 -0
  64. package/dist/utilities/fitIdentifierLength.js +35 -0
  65. package/dist/utilities/fitIdentifierLength.js.map +1 -0
  66. package/package.json +3 -3
@@ -0,0 +1,35 @@
1
+ import { maxIdentifierLength } from './validateIdentifierLength.js';
2
+ /**
3
+ * Returns `<name><suffix>` for a generated index or foreign key name, shortened only when
4
+ * Postgres would otherwise truncate it.
5
+ *
6
+ * Postgres keeps at most 63 characters of an identifier, so a longer name never matches what
7
+ * push reads back from the database and the constraint is dropped and re-added on every run.
8
+ *
9
+ * - Other adapters (SQLite, D1) have no such limit and always get the name unchanged.
10
+ * - Names that already fit are unchanged, so existing databases keep their current names.
11
+ * - Longer names are cut and end with a hash of the full name. The result depends only on
12
+ * `name` and `suffix`, never on which other names exist in the config, so adding or
13
+ * reordering fields doesn't rename constraints on other tables.
14
+ */ export const fitIdentifierLength = ({ name, adapter, suffix })=>{
15
+ const identifier = `${name}${suffix}`;
16
+ if (!exceedsIdentifierLength({
17
+ adapter,
18
+ identifier
19
+ })) {
20
+ return identifier;
21
+ }
22
+ const tail = `_${hashIdentifier(identifier)}${suffix}`;
23
+ return `${name.slice(0, maxIdentifierLength - tail.length)}${tail}`;
24
+ };
25
+ /** Whether Postgres would truncate `identifier`. Always `false` for non-Postgres adapters. */ export const exceedsIdentifierLength = ({ adapter, identifier })=>adapter.name === 'postgres' && identifier.length > maxIdentifierLength;
26
+ /** 32-bit FNV-1a hash as 8 hex characters. Avoids `crypto` so it also runs on edge runtimes. */ const hashIdentifier = (value)=>{
27
+ let hash = 0x811c9dc5;
28
+ for(let i = 0; i < value.length; i++){
29
+ hash ^= value.charCodeAt(i);
30
+ hash = Math.imul(hash, 0x01000193);
31
+ }
32
+ return (hash >>> 0).toString(16).padStart(8, '0');
33
+ };
34
+
35
+ //# sourceMappingURL=fitIdentifierLength.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/fitIdentifierLength.ts"],"sourcesContent":["import type { DrizzleAdapter } from '../types.js'\n\nimport { maxIdentifierLength } from './validateIdentifierLength.js'\n\n/**\n * Returns `<name><suffix>` for a generated index or foreign key name, shortened only when\n * Postgres would otherwise truncate it.\n *\n * Postgres keeps at most 63 characters of an identifier, so a longer name never matches what\n * push reads back from the database and the constraint is dropped and re-added on every run.\n *\n * - Other adapters (SQLite, D1) have no such limit and always get the name unchanged.\n * - Names that already fit are unchanged, so existing databases keep their current names.\n * - Longer names are cut and end with a hash of the full name. The result depends only on\n * `name` and `suffix`, never on which other names exist in the config, so adding or\n * reordering fields doesn't rename constraints on other tables.\n */\nexport const fitIdentifierLength = ({\n name,\n adapter,\n suffix,\n}: {\n adapter: Pick<DrizzleAdapter, 'name'>\n name: string\n suffix: string\n}): string => {\n const identifier = `${name}${suffix}`\n\n if (!exceedsIdentifierLength({ adapter, identifier })) {\n return identifier\n }\n\n const tail = `_${hashIdentifier(identifier)}${suffix}`\n\n return `${name.slice(0, maxIdentifierLength - tail.length)}${tail}`\n}\n\n/** Whether Postgres would truncate `identifier`. Always `false` for non-Postgres adapters. */\nexport const exceedsIdentifierLength = ({\n adapter,\n identifier,\n}: {\n adapter: Pick<DrizzleAdapter, 'name'>\n identifier: string\n}): boolean => adapter.name === 'postgres' && identifier.length > maxIdentifierLength\n\n/** 32-bit FNV-1a hash as 8 hex characters. Avoids `crypto` so it also runs on edge runtimes. */\nconst hashIdentifier = (value: string): string => {\n let hash = 0x811c9dc5\n\n for (let i = 0; i < value.length; i++) {\n hash ^= value.charCodeAt(i)\n hash = Math.imul(hash, 0x01000193)\n }\n\n return (hash >>> 0).toString(16).padStart(8, '0')\n}\n"],"names":["maxIdentifierLength","fitIdentifierLength","name","adapter","suffix","identifier","exceedsIdentifierLength","tail","hashIdentifier","slice","length","value","hash","i","charCodeAt","Math","imul","toString","padStart"],"mappings":"AAEA,SAASA,mBAAmB,QAAQ,gCAA+B;AAEnE;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,IAAI,EACJC,OAAO,EACPC,MAAM,EAKP;IACC,MAAMC,aAAa,GAAGH,OAAOE,QAAQ;IAErC,IAAI,CAACE,wBAAwB;QAAEH;QAASE;IAAW,IAAI;QACrD,OAAOA;IACT;IAEA,MAAME,OAAO,CAAC,CAAC,EAAEC,eAAeH,cAAcD,QAAQ;IAEtD,OAAO,GAAGF,KAAKO,KAAK,CAAC,GAAGT,sBAAsBO,KAAKG,MAAM,IAAIH,MAAM;AACrE,EAAC;AAED,4FAA4F,GAC5F,OAAO,MAAMD,0BAA0B,CAAC,EACtCH,OAAO,EACPE,UAAU,EAIX,GAAcF,QAAQD,IAAI,KAAK,cAAcG,WAAWK,MAAM,GAAGV,oBAAmB;AAErF,8FAA8F,GAC9F,MAAMQ,iBAAiB,CAACG;IACtB,IAAIC,OAAO;IAEX,IAAK,IAAIC,IAAI,GAAGA,IAAIF,MAAMD,MAAM,EAAEG,IAAK;QACrCD,QAAQD,MAAMG,UAAU,CAACD;QACzBD,OAAOG,KAAKC,IAAI,CAACJ,MAAM;IACzB;IAEA,OAAO,AAACA,CAAAA,SAAS,CAAA,EAAGK,QAAQ,CAAC,IAAIC,QAAQ,CAAC,GAAG;AAC/C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/drizzle",
3
- "version": "4.0.0-beta.10",
3
+ "version": "4.0.0-beta.12",
4
4
  "description": "A library of shared functions used by different payload database adapters",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "license": "MIT",
@@ -55,10 +55,10 @@
55
55
  "@types/pg": "8.20.0",
56
56
  "@types/to-snake-case": "1.0.0",
57
57
  "esbuild": "0.27.1",
58
- "payload": "4.0.0-beta.10"
58
+ "payload": "4.0.0-beta.12"
59
59
  },
60
60
  "peerDependencies": {
61
- "payload": "4.0.0-beta.10"
61
+ "payload": "4.0.0-beta.12"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "pnpm build:swc && pnpm build:types",