@strapi/database 5.56.0 → 5.57.0

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 (196) hide show
  1. package/dist/dialects/dialect.d.ts +28 -0
  2. package/dist/dialects/dialect.d.ts.map +1 -1
  3. package/dist/dialects/dialect.js +29 -0
  4. package/dist/dialects/dialect.js.map +1 -1
  5. package/dist/dialects/dialect.mjs +29 -0
  6. package/dist/dialects/dialect.mjs.map +1 -1
  7. package/dist/dialects/mysql/index.d.ts +9 -0
  8. package/dist/dialects/mysql/index.d.ts.map +1 -1
  9. package/dist/dialects/mysql/index.js +37 -0
  10. package/dist/dialects/mysql/index.js.map +1 -1
  11. package/dist/dialects/mysql/index.mjs +37 -0
  12. package/dist/dialects/mysql/index.mjs.map +1 -1
  13. package/dist/dialects/postgresql/index.d.ts +7 -0
  14. package/dist/dialects/postgresql/index.d.ts.map +1 -1
  15. package/dist/dialects/postgresql/index.js +50 -0
  16. package/dist/dialects/postgresql/index.js.map +1 -1
  17. package/dist/dialects/postgresql/index.mjs +50 -0
  18. package/dist/dialects/postgresql/index.mjs.map +1 -1
  19. package/dist/dialects/sqlite/index.d.ts +9 -0
  20. package/dist/dialects/sqlite/index.d.ts.map +1 -1
  21. package/dist/dialects/sqlite/index.js +16 -0
  22. package/dist/dialects/sqlite/index.js.map +1 -1
  23. package/dist/dialects/sqlite/index.mjs +16 -0
  24. package/dist/dialects/sqlite/index.mjs.map +1 -1
  25. package/dist/entity-manager/entity-repository.js +1 -1
  26. package/dist/entity-manager/entity-repository.js.map +1 -1
  27. package/dist/entity-manager/entity-repository.mjs +1 -1
  28. package/dist/entity-manager/entity-repository.mjs.map +1 -1
  29. package/dist/entity-manager/index.d.ts.map +1 -1
  30. package/dist/entity-manager/index.js +38 -36
  31. package/dist/entity-manager/index.js.map +1 -1
  32. package/dist/entity-manager/index.mjs +38 -36
  33. package/dist/entity-manager/index.mjs.map +1 -1
  34. package/dist/entity-manager/morph-relations.d.ts.map +1 -1
  35. package/dist/entity-manager/morph-relations.js +3 -5
  36. package/dist/entity-manager/morph-relations.js.map +1 -1
  37. package/dist/entity-manager/morph-relations.mjs +3 -5
  38. package/dist/entity-manager/morph-relations.mjs.map +1 -1
  39. package/dist/entity-manager/regular-relations.js +3 -3
  40. package/dist/entity-manager/regular-relations.js.map +1 -1
  41. package/dist/entity-manager/regular-relations.mjs +3 -3
  42. package/dist/entity-manager/regular-relations.mjs.map +1 -1
  43. package/dist/entity-manager/relations-orderer.d.ts.map +1 -1
  44. package/dist/entity-manager/relations-orderer.js +4 -5
  45. package/dist/entity-manager/relations-orderer.js.map +1 -1
  46. package/dist/entity-manager/relations-orderer.mjs +2 -3
  47. package/dist/entity-manager/relations-orderer.mjs.map +1 -1
  48. package/dist/fields/biginteger.js +1 -1
  49. package/dist/fields/biginteger.js.map +1 -1
  50. package/dist/fields/biginteger.mjs +1 -1
  51. package/dist/fields/biginteger.mjs.map +1 -1
  52. package/dist/fields/boolean.js +1 -1
  53. package/dist/fields/boolean.js.map +1 -1
  54. package/dist/fields/boolean.mjs +1 -1
  55. package/dist/fields/boolean.mjs.map +1 -1
  56. package/dist/fields/number.js +1 -1
  57. package/dist/fields/number.js.map +1 -1
  58. package/dist/fields/number.mjs +1 -1
  59. package/dist/fields/number.mjs.map +1 -1
  60. package/dist/fields/shared/parsers.js +2 -2
  61. package/dist/fields/shared/parsers.js.map +1 -1
  62. package/dist/fields/shared/parsers.mjs +2 -2
  63. package/dist/fields/shared/parsers.mjs.map +1 -1
  64. package/dist/fields/string.js +1 -1
  65. package/dist/fields/string.js.map +1 -1
  66. package/dist/fields/string.mjs +1 -1
  67. package/dist/fields/string.mjs.map +1 -1
  68. package/dist/index.d.ts +9 -5
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +2 -0
  71. package/dist/index.js.map +1 -1
  72. package/dist/index.mjs +1 -0
  73. package/dist/index.mjs.map +1 -1
  74. package/dist/metadata/attribute-naming.d.ts +31 -0
  75. package/dist/metadata/attribute-naming.d.ts.map +1 -0
  76. package/dist/metadata/attribute-naming.js +39 -0
  77. package/dist/metadata/attribute-naming.js.map +1 -0
  78. package/dist/metadata/attribute-naming.mjs +37 -0
  79. package/dist/metadata/attribute-naming.mjs.map +1 -0
  80. package/dist/metadata/index.d.ts +5 -2
  81. package/dist/metadata/index.d.ts.map +1 -1
  82. package/dist/metadata/index.js +3 -0
  83. package/dist/metadata/index.js.map +1 -1
  84. package/dist/metadata/index.mjs +3 -1
  85. package/dist/metadata/index.mjs.map +1 -1
  86. package/dist/metadata/metadata.d.ts +10 -0
  87. package/dist/metadata/metadata.d.ts.map +1 -1
  88. package/dist/metadata/metadata.js +10 -2
  89. package/dist/metadata/metadata.js.map +1 -1
  90. package/dist/metadata/metadata.mjs +10 -2
  91. package/dist/metadata/metadata.mjs.map +1 -1
  92. package/dist/metadata/relations.d.ts.map +1 -1
  93. package/dist/metadata/relations.js +6 -5
  94. package/dist/metadata/relations.js.map +1 -1
  95. package/dist/metadata/relations.mjs +6 -5
  96. package/dist/metadata/relations.mjs.map +1 -1
  97. package/dist/migrations/common.d.ts +2 -0
  98. package/dist/migrations/common.d.ts.map +1 -1
  99. package/dist/migrations/common.js.map +1 -1
  100. package/dist/migrations/common.mjs.map +1 -1
  101. package/dist/migrations/file-builder.d.ts +97 -0
  102. package/dist/migrations/file-builder.d.ts.map +1 -0
  103. package/dist/migrations/file-builder.js +251 -0
  104. package/dist/migrations/file-builder.js.map +1 -0
  105. package/dist/migrations/file-builder.mjs +240 -0
  106. package/dist/migrations/file-builder.mjs.map +1 -0
  107. package/dist/migrations/index.d.ts +3 -2
  108. package/dist/migrations/index.d.ts.map +1 -1
  109. package/dist/migrations/index.js +6 -0
  110. package/dist/migrations/index.js.map +1 -1
  111. package/dist/migrations/index.mjs +6 -0
  112. package/dist/migrations/index.mjs.map +1 -1
  113. package/dist/migrations/internal-migrations/5.0.0-02-document-id.js +1 -1
  114. package/dist/migrations/internal-migrations/5.0.0-02-document-id.js.map +1 -1
  115. package/dist/migrations/internal-migrations/5.0.0-02-document-id.mjs +1 -1
  116. package/dist/migrations/internal-migrations/5.0.0-02-document-id.mjs.map +1 -1
  117. package/dist/migrations/resolver.d.ts.map +1 -1
  118. package/dist/migrations/resolver.js +4 -1
  119. package/dist/migrations/resolver.js.map +1 -1
  120. package/dist/migrations/resolver.mjs +4 -1
  121. package/dist/migrations/resolver.mjs.map +1 -1
  122. package/dist/query/helpers/order-by.d.ts.map +1 -1
  123. package/dist/query/helpers/order-by.js +3 -4
  124. package/dist/query/helpers/order-by.js.map +1 -1
  125. package/dist/query/helpers/order-by.mjs +3 -4
  126. package/dist/query/helpers/order-by.mjs.map +1 -1
  127. package/dist/query/helpers/populate/apply.d.ts.map +1 -1
  128. package/dist/query/helpers/populate/apply.js +46 -30
  129. package/dist/query/helpers/populate/apply.js.map +1 -1
  130. package/dist/query/helpers/populate/apply.mjs +46 -30
  131. package/dist/query/helpers/populate/apply.mjs.map +1 -1
  132. package/dist/query/helpers/populate/process.js +3 -3
  133. package/dist/query/helpers/populate/process.js.map +1 -1
  134. package/dist/query/helpers/populate/process.mjs +3 -3
  135. package/dist/query/helpers/populate/process.mjs.map +1 -1
  136. package/dist/query/helpers/search.js +2 -2
  137. package/dist/query/helpers/search.js.map +1 -1
  138. package/dist/query/helpers/search.mjs +2 -2
  139. package/dist/query/helpers/search.mjs.map +1 -1
  140. package/dist/query/helpers/streams/readable.js +3 -3
  141. package/dist/query/helpers/streams/readable.js.map +1 -1
  142. package/dist/query/helpers/streams/readable.mjs +3 -3
  143. package/dist/query/helpers/streams/readable.mjs.map +1 -1
  144. package/dist/query/helpers/transform.d.ts.map +1 -1
  145. package/dist/query/helpers/transform.js +6 -13
  146. package/dist/query/helpers/transform.js.map +1 -1
  147. package/dist/query/helpers/transform.mjs +6 -9
  148. package/dist/query/helpers/transform.mjs.map +1 -1
  149. package/dist/query/helpers/where.js +13 -9
  150. package/dist/query/helpers/where.js.map +1 -1
  151. package/dist/query/helpers/where.mjs +13 -9
  152. package/dist/query/helpers/where.mjs.map +1 -1
  153. package/dist/query/query-builder.d.ts.map +1 -1
  154. package/dist/query/query-builder.js +35 -29
  155. package/dist/query/query-builder.js.map +1 -1
  156. package/dist/query/query-builder.mjs +35 -29
  157. package/dist/query/query-builder.mjs.map +1 -1
  158. package/dist/schema/builder.js +5 -5
  159. package/dist/schema/builder.js.map +1 -1
  160. package/dist/schema/builder.mjs +5 -5
  161. package/dist/schema/builder.mjs.map +1 -1
  162. package/dist/schema/diff.js +12 -12
  163. package/dist/schema/diff.js.map +1 -1
  164. package/dist/schema/diff.mjs +12 -12
  165. package/dist/schema/diff.mjs.map +1 -1
  166. package/dist/schema/index.d.ts +3 -1
  167. package/dist/schema/index.d.ts.map +1 -1
  168. package/dist/schema/index.js +6 -0
  169. package/dist/schema/index.js.map +1 -1
  170. package/dist/schema/index.mjs +6 -0
  171. package/dist/schema/index.mjs.map +1 -1
  172. package/dist/schema/rename-helpers.d.ts +78 -0
  173. package/dist/schema/rename-helpers.d.ts.map +1 -0
  174. package/dist/schema/rename-helpers.js +235 -0
  175. package/dist/schema/rename-helpers.js.map +1 -0
  176. package/dist/schema/rename-helpers.mjs +233 -0
  177. package/dist/schema/rename-helpers.mjs.map +1 -0
  178. package/dist/utils/async-curry.d.ts.map +1 -1
  179. package/dist/utils/async-curry.js +1 -2
  180. package/dist/utils/async-curry.js.map +1 -1
  181. package/dist/utils/async-curry.mjs +1 -2
  182. package/dist/utils/async-curry.mjs.map +1 -1
  183. package/dist/utils/identifiers/hash.d.ts.map +1 -1
  184. package/dist/utils/identifiers/hash.js +1 -2
  185. package/dist/utils/identifiers/hash.js.map +1 -1
  186. package/dist/utils/identifiers/hash.mjs +1 -2
  187. package/dist/utils/identifiers/hash.mjs.map +1 -1
  188. package/dist/utils/identifiers/index.js +8 -10
  189. package/dist/utils/identifiers/index.js.map +1 -1
  190. package/dist/utils/identifiers/index.mjs +8 -6
  191. package/dist/utils/identifiers/index.mjs.map +1 -1
  192. package/dist/validations/relations/bidirectional.js +1 -1
  193. package/dist/validations/relations/bidirectional.js.map +1 -1
  194. package/dist/validations/relations/bidirectional.mjs +1 -1
  195. package/dist/validations/relations/bidirectional.mjs.map +1 -1
  196. package/package.json +6 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rename-helpers.js","sources":["../../src/schema/rename-helpers.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport { getOperationComment } from '../migrations/file-builder';\n\nimport type { Database } from '..';\nimport type {\n AttributeRenamesOperation,\n RenameColumnOperation,\n RenameTableOperation,\n UpdateRowsOperation,\n} from '../migrations/file-builder';\n\n/**\n * Runtime helpers used by generated rename migrations (see\n * `migrations/file-builder.ts`). Keeping the guards, logging and dialect\n * specifics here instead of in the generated file means a fix in the database\n * package applies to migrations users already generated.\n *\n * Every helper:\n * - runs on the transaction it is given (never on `db.connection`, which may\n * be exhausted by that very transaction on single-connection pools);\n * - checks the source exists and the target does not before doing anything,\n * so it is a safe no-op on a fresh database (schema sync creates the tables\n * afterwards) or on one that already moved on. For `updateRows` the source\n * is the rows matching `where`: with none, nothing is deleted or updated, so\n * re-running a partly applied migration (MySQL commits DDL implicitly)\n * cannot mistake the rows it already renamed for orphans;\n * - logs when it skips: `info` when the source is missing (expected on a fresh\n * database), `warn` when the target already exists (the environment drifted\n * and the rename could not be applied — schema sync will then drop the old\n * artifact, so this is worth a look);\n * - renames the indexes/constraints whose names embed the renamed identifier\n * where the dialect supports it (Postgres), so schema sync sees no diff\n * afterwards. On other dialects it drops them instead and schema sync\n * re-creates them under the new name. Leaving them under the old name is not\n * an option: sync only drops indexes it tracked on a table of the same name,\n * so re-adding the old table/column later would collide with them.\n */\n\nexport type RenameSkipReason = 'source-missing' | 'target-exists';\n\n/**\n * Attribute renames of one save, composed per model: `uid -> { origin: final }`.\n */\nexport interface AttributeRenames {\n renames: Record<string, Record<string, string>>;\n comment?: string;\n}\n\n/**\n * Updates a store keyed by attribute name (e.g. admin field permissions) for\n * the given renames. Runs inside the migration transaction `trx`.\n */\nexport type AttributeRenameHandler = (\n trx: Knex,\n renames: AttributeRenames['renames']\n) => Promise<void>;\n\ninterface RenameHelpersDeps {\n db: Database;\n}\n\nexport const createRenameHelpers = ({ db }: RenameHelpersDeps) => {\n const { identifiers } = db.metadata;\n\n const logSkip = (comment: string, detail: string, reason: RenameSkipReason): void => {\n const message = `[rename migration] skipped: ${comment} (${detail})`;\n if (reason === 'target-exists') {\n db.logger.warn(message);\n } else {\n db.logger.info(message);\n }\n };\n\n const logApplied = (comment: string): void => {\n db.logger.info(`[rename migration] applied: ${comment}`);\n };\n\n // A knex SchemaBuilder accumulates statements, so build a fresh one per call.\n const schemaOf = (trx: Knex) => db.getSchemaConnection(trx);\n const hasTable = (trx: Knex, table: string) => schemaOf(trx).hasTable(table);\n const hasColumn = (trx: Knex, table: string, column: string) =>\n schemaOf(trx).hasColumn(table, column);\n const tableOf = (trx: Knex, table: string) => {\n const schemaName = db.getSchemaName();\n return schemaName ? trx(table).withSchema(schemaName) : trx(table);\n };\n\n /**\n * Brings every index / constraint from the `pairs` list that exists on\n * `table` in line with a rename: renamed in place when the dialect can do so,\n * dropped otherwise (schema sync then re-creates it under the new name).\n */\n const syncSchemaObjectNames = async (\n trx: Knex,\n table: string,\n pairs: Array<{ from: string; to: string }>\n ): Promise<void> => {\n const canRename = db.dialect.canRenameSchemaObjects();\n\n for (const { from, to } of pairs) {\n if (from === to) {\n continue;\n }\n\n if (canRename) {\n await db.dialect.renameSchemaObject(trx, { table, from, to });\n } else {\n await db.dialect.dropSchemaObject(trx, { table, name: from });\n }\n }\n };\n\n const attributeRenameHandlers = new Set<AttributeRenameHandler>();\n\n return {\n /**\n * Renames a column, then the index / unique / foreign-key constraints named\n * after it (`<table>_<column>_index|unique|fk`) where supported.\n */\n async renameColumn(trx: Knex, op: RenameColumnOperation): Promise<boolean> {\n const comment = getOperationComment({ kind: 'renameColumn', ...op });\n\n if (!(await hasTable(trx, op.table))) {\n logSkip(comment, `table \"${op.table}\" does not exist`, 'source-missing');\n return false;\n }\n\n if (!(await hasColumn(trx, op.table, op.from))) {\n logSkip(comment, `column \"${op.table}.${op.from}\" does not exist`, 'source-missing');\n return false;\n }\n\n if (await hasColumn(trx, op.table, op.to)) {\n logSkip(comment, `column \"${op.table}.${op.to}\" already exists`, 'target-exists');\n return false;\n }\n\n await schemaOf(trx).alterTable(op.table, (table) => {\n table.renameColumn(op.from, op.to);\n });\n\n await syncSchemaObjectNames(trx, op.table, [\n {\n from: identifiers.getIndexName([op.table, op.from]),\n to: identifiers.getIndexName([op.table, op.to]),\n },\n {\n from: identifiers.getUniqueIndexName([op.table, op.from]),\n to: identifiers.getUniqueIndexName([op.table, op.to]),\n },\n {\n from: identifiers.getFkIndexName([op.table, op.from]),\n to: identifiers.getFkIndexName([op.table, op.to]),\n },\n ]);\n\n logApplied(comment);\n return true;\n },\n\n /**\n * Renames a table (typically a relation join table), then the indexes and\n * constraints named after it where supported.\n */\n async renameTable(trx: Knex, op: RenameTableOperation): Promise<boolean> {\n const comment = getOperationComment({ kind: 'renameTable', ...op });\n\n if (!(await hasTable(trx, op.from))) {\n logSkip(comment, `table \"${op.from}\" does not exist`, 'source-missing');\n return false;\n }\n\n if (await hasTable(trx, op.to)) {\n logSkip(comment, `table \"${op.to}\" already exists`, 'target-exists');\n return false;\n }\n\n await schemaOf(trx).renameTable(op.from, op.to);\n\n // Every name a join table's metadata derives from the table name (see\n // `createJoinTable` in metadata/relations.ts and the component link\n // tables in core's transform-content-types-to-models).\n const derived: Array<(name: string) => string> = [\n (name) => identifiers.getFkIndexName(name),\n (name) => identifiers.getInverseFkIndexName(name),\n (name) => identifiers.getUniqueIndexName(name),\n (name) => identifiers.getOrderFkIndexName(name),\n (name) => identifiers.getOrderInverseFkIndexName(name),\n (name) => identifiers.getOrderIndexName(name),\n (name) => identifiers.getIdColumnIndexName(name),\n ];\n\n await syncSchemaObjectNames(\n trx,\n op.to,\n derived.map((derive) => ({ from: derive(op.from), to: derive(op.to) }))\n );\n\n logApplied(comment);\n return true;\n },\n\n /**\n * Rewrites a stored value (e.g. the `field` or `component_type` column of a\n * component link table). Guarded on the table and `guardColumn` (defaults\n * to the first updated column) existing, and on rows matching `where`.\n */\n async updateRows(trx: Knex, op: UpdateRowsOperation): Promise<boolean> {\n const comment = getOperationComment({ kind: 'updateRows', ...op });\n const [firstSetColumn] = Object.keys(op.set);\n const guardColumn = op.guardColumn ?? firstSetColumn;\n\n if (!(await hasTable(trx, op.table))) {\n logSkip(comment, `table \"${op.table}\" does not exist`, 'source-missing');\n return false;\n }\n\n if (!(await hasColumn(trx, op.table, guardColumn))) {\n logSkip(comment, `column \"${op.table}.${guardColumn}\" does not exist`, 'source-missing');\n return false;\n }\n\n // Scope: every `where` key except the renamed column(s).\n const scope = Object.fromEntries(\n Object.entries(op.where).filter(([key]) => !(key in op.set))\n );\n const countRows = async (where: Record<string, unknown>): Promise<number> => {\n const [row] = await tableOf(trx, op.table).where(where).count({ count: '*' });\n return Number(row?.count ?? 0);\n };\n\n // Without source rows there is nothing to rename. Rows carrying the\n // target value may then be the ones a previous run already renamed, so\n // they must not be taken for orphans.\n if ((await countRows(op.where)) === 0) {\n if ((await countRows({ ...scope, ...op.set })) > 0) {\n logSkip(\n comment,\n `no row matches ${JSON.stringify(op.where)} in \"${op.table}\"; rows already matching ${JSON.stringify(op.set)} were left untouched, the rename may already have run`,\n 'target-exists'\n );\n } else {\n logSkip(\n comment,\n `no row matches ${JSON.stringify(op.where)} in \"${op.table}\"`,\n 'source-missing'\n );\n }\n return false;\n }\n\n // Rows already carrying the target value are orphans (left behind when\n // an attribute with the target name was deleted earlier). Updating would\n // merge them into the renamed field and resurrect deleted content, so\n // they go first.\n const removed = await tableOf(trx, op.table)\n .where({ ...scope, ...op.set })\n .delete();\n if (removed > 0) {\n db.logger.info(\n `[rename migration] removed ${removed} orphan row(s) already matching ${JSON.stringify(op.set)} in \"${op.table}\" before: ${comment}`\n );\n }\n\n await tableOf(trx, op.table).where(op.where).update(op.set);\n\n logApplied(comment);\n return true;\n },\n\n /**\n * Registers a handler for `applyAttributeRenames`. Plugins that keep data\n * keyed by attribute name register one during their register phase, before\n * user migrations run. Returns a function that unregisters it.\n */\n registerAttributeRenameHandler(handler: AttributeRenameHandler): () => void {\n attributeRenameHandlers.add(handler);\n return () => {\n attributeRenameHandlers.delete(handler);\n };\n },\n\n /**\n * Dispatches one save's attribute renames to every registered handler, in\n * registration order, inside `trx`. The database package itself stores\n * nothing keyed by attribute name, so with no handler this is a no-op.\n */\n async applyAttributeRenames(trx: Knex, op: AttributeRenamesOperation): Promise<boolean> {\n const comment = getOperationComment({ kind: 'attributeRenames', ...op });\n\n if (attributeRenameHandlers.size === 0) {\n db.logger.debug(`[rename migration] skipped: ${comment} (no handler registered)`);\n return false;\n }\n\n for (const handler of attributeRenameHandlers) {\n await handler(trx, op.renames);\n }\n\n logApplied(comment);\n return true;\n },\n };\n};\n\nexport type RenameHelpers = ReturnType<typeof createRenameHelpers>;\n"],"names":["createRenameHelpers","db","identifiers","metadata","logSkip","comment","detail","reason","message","logger","warn","info","logApplied","schemaOf","trx","getSchemaConnection","hasTable","table","hasColumn","column","tableOf","schemaName","getSchemaName","withSchema","syncSchemaObjectNames","pairs","canRename","dialect","canRenameSchemaObjects","from","to","renameSchemaObject","dropSchemaObject","name","attributeRenameHandlers","Set","renameColumn","op","getOperationComment","kind","alterTable","getIndexName","getUniqueIndexName","getFkIndexName","renameTable","derived","getInverseFkIndexName","getOrderFkIndexName","getOrderInverseFkIndexName","getOrderIndexName","getIdColumnIndexName","map","derive","updateRows","firstSetColumn","Object","keys","set","guardColumn","scope","fromEntries","entries","where","filter","key","countRows","row","count","Number","JSON","stringify","removed","delete","update","registerAttributeRenameHandler","handler","add","applyAttributeRenames","size","debug","renames"],"mappings":";;;;AA8DO,MAAMA,mBAAAA,GAAsB,CAAC,EAAEC,EAAE,EAAqB,GAAA;AAC3D,IAAA,MAAM,EA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K,CAAA,CAAEW,MAAM,CAACpC,GAAGoB,GAAG,CAAA;YAE1D7C,UAAAA,CAAWP,OAAAA,CAAAA;YACX,OAAO,IAAA;AACT,QAAA,CAAA;AAEA;;;;AAIC,QACDqE,gCAA+BC,OAA+B,EAAA;AAC5DzC,YAAAA,uBAAAA,CAAwB0C,GAAG,CAACD,OAAAA,CAAAA;YAC5B,OAAO,IAAA;AACLzC,gBAAAA,uBAAAA,CAAwBsC,MAAM,CAACG,OAAAA,CAAAA;AACjC,YAAA,CAAA;AACF,QAAA,CAAA;AAEA;;;;AAIC,QACD,MAAME,qBAAAA,CAAAA,CAAsB/D,GAAS,EAAEuB,EAA6B,EAAA;AAClE,YAAA,MAAMhC,UAAUiC,+BAAAA,CAAoB;gBAAEC,IAAAA,EAAM,kBAAA;AAAoB,gBAAA,GAAGF;AAAG,aAAA,CAAA;YAEtE,IAAIH,uBAAAA,CAAwB4C,IAAI,KAAK,CAAA,EAAG;gBACtC7E,EAAAA,CAAGQ,MAAM,CAACsE,KAAK,CAAC,CAAC,4BAA4B,EAAE1E,OAAAA,CAAQ,wBAAwB,CAAC,CAAA;gBAChF,OAAO,KAAA;AACT,YAAA;YAEA,KAAK,MAAMsE,WAAWzC,uBAAAA,CAAyB;gBAC7C,MAAMyC,OAAAA,CAAQ7D,GAAAA,EAAKuB,EAAAA,CAAG2C,OAAO,CAAA;AAC/B,YAAA;YAEApE,UAAAA,CAAWP,OAAAA,CAAAA;YACX,OAAO,IAAA;AACT,QAAA;AACF,KAAA;AACF;;;;"}
@@ -0,0 +1,233 @@
1
+ import { getOperationComment } from '../migrations/file-builder.mjs';
2
+
3
+ const createRenameHelpers = ({ db })=>{
4
+ const { identifiers } = db.metadata;
5
+ const logSkip = (comment, detail, reason)=>{
6
+ const message = `[rename migration] skipped: ${comment} (${detail})`;
7
+ if (reason === 'target-exists') {
8
+ db.logger.warn(message);
9
+ } else {
10
+ db.logger.info(message);
11
+ }
12
+ };
13
+ const logApplied = (comment)=>{
14
+ db.logger.info(`[rename migration] applied: ${comment}`);
15
+ };
16
+ // A knex SchemaBuilder accumulates statements, so build a fresh one per call.
17
+ const schemaOf = (trx)=>db.getSchemaConnection(trx);
18
+ const hasTable = (trx, table)=>schemaOf(trx).hasTable(table);
19
+ const hasColumn = (trx, table, column)=>schemaOf(trx).hasColumn(table, column);
20
+ const tableOf = (trx, table)=>{
21
+ const schemaName = db.getSchemaName();
22
+ return schemaName ? trx(table).withSchema(schemaName) : trx(table);
23
+ };
24
+ /**
25
+ * Brings every index / constraint from the `pairs` list that exists on
26
+ * `table` in line with a rename: renamed in place when the dialect can do so,
27
+ * dropped otherwise (schema sync then re-creates it under the new name).
28
+ */ const syncSchemaObjectNames = async (trx, table, pairs)=>{
29
+ const canRename = db.dialect.canRenameSchemaObjects();
30
+ for (const { from, to } of pairs){
31
+ if (from === to) {
32
+ continue;
33
+ }
34
+ if (canRename) {
35
+ await db.dialect.renameSchemaObject(trx, {
36
+ table,
37
+ from,
38
+ to
39
+ });
40
+ } else {
41
+ await db.dialect.dropSchemaObject(trx, {
42
+ table,
43
+ name: from
44
+ });
45
+ }
46
+ }
47
+ };
48
+ const attributeRenameHandlers = new Set();
49
+ return {
50
+ /**
51
+ * Renames a column, then the index / unique / foreign-key constraints named
52
+ * after it (`<table>_<column>_index|unique|fk`) where supported.
53
+ */ async renameColumn (trx, op) {
54
+ const comment = getOperationComment({
55
+ kind: 'renameColumn',
56
+ ...op
57
+ });
58
+ if (!await hasTable(trx, op.table)) {
59
+ logSkip(comment, `table "${op.table}" does not exist`, 'source-missing');
60
+ return false;
61
+ }
62
+ if (!await hasColumn(trx, op.table, op.from)) {
63
+ logSkip(comment, `column "${op.table}.${op.from}" does not exist`, 'source-missing');
64
+ return false;
65
+ }
66
+ if (await hasColumn(trx, op.table, op.to)) {
67
+ logSkip(comment, `column "${op.table}.${op.to}" already exists`, 'target-exists');
68
+ return false;
69
+ }
70
+ await schemaOf(trx).alterTable(op.table, (table)=>{
71
+ table.renameColumn(op.from, op.to);
72
+ });
73
+ await syncSchemaObjectNames(trx, op.table, [
74
+ {
75
+ from: identifiers.getIndexName([
76
+ op.table,
77
+ op.from
78
+ ]),
79
+ to: identifiers.getIndexName([
80
+ op.table,
81
+ op.to
82
+ ])
83
+ },
84
+ {
85
+ from: identifiers.getUniqueIndexName([
86
+ op.table,
87
+ op.from
88
+ ]),
89
+ to: identifiers.getUniqueIndexName([
90
+ op.table,
91
+ op.to
92
+ ])
93
+ },
94
+ {
95
+ from: identifiers.getFkIndexName([
96
+ op.table,
97
+ op.from
98
+ ]),
99
+ to: identifiers.getFkIndexName([
100
+ op.table,
101
+ op.to
102
+ ])
103
+ }
104
+ ]);
105
+ logApplied(comment);
106
+ return true;
107
+ },
108
+ /**
109
+ * Renames a table (typically a relation join table), then the indexes and
110
+ * constraints named after it where supported.
111
+ */ async renameTable (trx, op) {
112
+ const comment = getOperationComment({
113
+ kind: 'renameTable',
114
+ ...op
115
+ });
116
+ if (!await hasTable(trx, op.from)) {
117
+ logSkip(comment, `table "${op.from}" does not exist`, 'source-missing');
118
+ return false;
119
+ }
120
+ if (await hasTable(trx, op.to)) {
121
+ logSkip(comment, `table "${op.to}" already exists`, 'target-exists');
122
+ return false;
123
+ }
124
+ await schemaOf(trx).renameTable(op.from, op.to);
125
+ // Every name a join table's metadata derives from the table name (see
126
+ // `createJoinTable` in metadata/relations.ts and the component link
127
+ // tables in core's transform-content-types-to-models).
128
+ const derived = [
129
+ (name)=>identifiers.getFkIndexName(name),
130
+ (name)=>identifiers.getInverseFkIndexName(name),
131
+ (name)=>identifiers.getUniqueIndexName(name),
132
+ (name)=>identifiers.getOrderFkIndexName(name),
133
+ (name)=>identifiers.getOrderInverseFkIndexName(name),
134
+ (name)=>identifiers.getOrderIndexName(name),
135
+ (name)=>identifiers.getIdColumnIndexName(name)
136
+ ];
137
+ await syncSchemaObjectNames(trx, op.to, derived.map((derive)=>({
138
+ from: derive(op.from),
139
+ to: derive(op.to)
140
+ })));
141
+ logApplied(comment);
142
+ return true;
143
+ },
144
+ /**
145
+ * Rewrites a stored value (e.g. the `field` or `component_type` column of a
146
+ * component link table). Guarded on the table and `guardColumn` (defaults
147
+ * to the first updated column) existing, and on rows matching `where`.
148
+ */ async updateRows (trx, op) {
149
+ const comment = getOperationComment({
150
+ kind: 'updateRows',
151
+ ...op
152
+ });
153
+ const [firstSetColumn] = Object.keys(op.set);
154
+ const guardColumn = op.guardColumn ?? firstSetColumn;
155
+ if (!await hasTable(trx, op.table)) {
156
+ logSkip(comment, `table "${op.table}" does not exist`, 'source-missing');
157
+ return false;
158
+ }
159
+ if (!await hasColumn(trx, op.table, guardColumn)) {
160
+ logSkip(comment, `column "${op.table}.${guardColumn}" does not exist`, 'source-missing');
161
+ return false;
162
+ }
163
+ // Scope: every `where` key except the renamed column(s).
164
+ const scope = Object.fromEntries(Object.entries(op.where).filter(([key])=>!(key in op.set)));
165
+ const countRows = async (where)=>{
166
+ const [row] = await tableOf(trx, op.table).where(where).count({
167
+ count: '*'
168
+ });
169
+ return Number(row?.count ?? 0);
170
+ };
171
+ // Without source rows there is nothing to rename. Rows carrying the
172
+ // target value may then be the ones a previous run already renamed, so
173
+ // they must not be taken for orphans.
174
+ if (await countRows(op.where) === 0) {
175
+ if (await countRows({
176
+ ...scope,
177
+ ...op.set
178
+ }) > 0) {
179
+ logSkip(comment, `no row matches ${JSON.stringify(op.where)} in "${op.table}"; rows already matching ${JSON.stringify(op.set)} were left untouched, the rename may already have run`, 'target-exists');
180
+ } else {
181
+ logSkip(comment, `no row matches ${JSON.stringify(op.where)} in "${op.table}"`, 'source-missing');
182
+ }
183
+ return false;
184
+ }
185
+ // Rows already carrying the target value are orphans (left behind when
186
+ // an attribute with the target name was deleted earlier). Updating would
187
+ // merge them into the renamed field and resurrect deleted content, so
188
+ // they go first.
189
+ const removed = await tableOf(trx, op.table).where({
190
+ ...scope,
191
+ ...op.set
192
+ }).delete();
193
+ if (removed > 0) {
194
+ db.logger.info(`[rename migration] removed ${removed} orphan row(s) already matching ${JSON.stringify(op.set)} in "${op.table}" before: ${comment}`);
195
+ }
196
+ await tableOf(trx, op.table).where(op.where).update(op.set);
197
+ logApplied(comment);
198
+ return true;
199
+ },
200
+ /**
201
+ * Registers a handler for `applyAttributeRenames`. Plugins that keep data
202
+ * keyed by attribute name register one during their register phase, before
203
+ * user migrations run. Returns a function that unregisters it.
204
+ */ registerAttributeRenameHandler (handler) {
205
+ attributeRenameHandlers.add(handler);
206
+ return ()=>{
207
+ attributeRenameHandlers.delete(handler);
208
+ };
209
+ },
210
+ /**
211
+ * Dispatches one save's attribute renames to every registered handler, in
212
+ * registration order, inside `trx`. The database package itself stores
213
+ * nothing keyed by attribute name, so with no handler this is a no-op.
214
+ */ async applyAttributeRenames (trx, op) {
215
+ const comment = getOperationComment({
216
+ kind: 'attributeRenames',
217
+ ...op
218
+ });
219
+ if (attributeRenameHandlers.size === 0) {
220
+ db.logger.debug(`[rename migration] skipped: ${comment} (no handler registered)`);
221
+ return false;
222
+ }
223
+ for (const handler of attributeRenameHandlers){
224
+ await handler(trx, op.renames);
225
+ }
226
+ logApplied(comment);
227
+ return true;
228
+ }
229
+ };
230
+ };
231
+
232
+ export { createRenameHelpers };
233
+ //# sourceMappingURL=rename-helpers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rename-helpers.mjs","sources":["../../src/schema/rename-helpers.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport { getOperationComment } from '../migrations/file-builder';\n\nimport type { Database } from '..';\nimport type {\n AttributeRenamesOperation,\n RenameColumnOperation,\n RenameTableOperation,\n UpdateRowsOperation,\n} from '../migrations/file-builder';\n\n/**\n * Runtime helpers used by generated rename migrations (see\n * `migrations/file-builder.ts`). Keeping the guards, logging and dialect\n * specifics here instead of in the generated file means a fix in the database\n * package applies to migrations users already generated.\n *\n * Every helper:\n * - runs on the transaction it is given (never on `db.connection`, which may\n * be exhausted by that very transaction on single-connection pools);\n * - checks the source exists and the target does not before doing anything,\n * so it is a safe no-op on a fresh database (schema sync creates the tables\n * afterwards) or on one that already moved on. For `updateRows` the source\n * is the rows matching `where`: with none, nothing is deleted or updated, so\n * re-running a partly applied migration (MySQL commits DDL implicitly)\n * cannot mistake the rows it already renamed for orphans;\n * - logs when it skips: `info` when the source is missing (expected on a fresh\n * database), `warn` when the target already exists (the environment drifted\n * and the rename could not be applied — schema sync will then drop the old\n * artifact, so this is worth a look);\n * - renames the indexes/constraints whose names embed the renamed identifier\n * where the dialect supports it (Postgres), so schema sync sees no diff\n * afterwards. On other dialects it drops them instead and schema sync\n * re-creates them under the new name. Leaving them under the old name is not\n * an option: sync only drops indexes it tracked on a table of the same name,\n * so re-adding the old table/column later would collide with them.\n */\n\nexport type RenameSkipReason = 'source-missing' | 'target-exists';\n\n/**\n * Attribute renames of one save, composed per model: `uid -> { origin: final }`.\n */\nexport interface AttributeRenames {\n renames: Record<string, Record<string, string>>;\n comment?: string;\n}\n\n/**\n * Updates a store keyed by attribute name (e.g. admin field permissions) for\n * the given renames. Runs inside the migration transaction `trx`.\n */\nexport type AttributeRenameHandler = (\n trx: Knex,\n renames: AttributeRenames['renames']\n) => Promise<void>;\n\ninterface RenameHelpersDeps {\n db: Database;\n}\n\nexport const createRenameHelpers = ({ db }: RenameHelpersDeps) => {\n const { identifiers } = db.metadata;\n\n const logSkip = (comment: string, detail: string, reason: RenameSkipReason): void => {\n const message = `[rename migration] skipped: ${comment} (${detail})`;\n if (reason === 'target-exists') {\n db.logger.warn(message);\n } else {\n db.logger.info(message);\n }\n };\n\n const logApplied = (comment: string): void => {\n db.logger.info(`[rename migration] applied: ${comment}`);\n };\n\n // A knex SchemaBuilder accumulates statements, so build a fresh one per call.\n const schemaOf = (trx: Knex) => db.getSchemaConnection(trx);\n const hasTable = (trx: Knex, table: string) => schemaOf(trx).hasTable(table);\n const hasColumn = (trx: Knex, table: string, column: string) =>\n schemaOf(trx).hasColumn(table, column);\n const tableOf = (trx: Knex, table: string) => {\n const schemaName = db.getSchemaName();\n return schemaName ? trx(table).withSchema(schemaName) : trx(table);\n };\n\n /**\n * Brings every index / constraint from the `pairs` list that exists on\n * `table` in line with a rename: renamed in place when the dialect can do so,\n * dropped otherwise (schema sync then re-creates it under the new name).\n */\n const syncSchemaObjectNames = async (\n trx: Knex,\n table: string,\n pairs: Array<{ from: string; to: string }>\n ): Promise<void> => {\n const canRename = db.dialect.canRenameSchemaObjects();\n\n for (const { from, to } of pairs) {\n if (from === to) {\n continue;\n }\n\n if (canRename) {\n await db.dialect.renameSchemaObject(trx, { table, from, to });\n } else {\n await db.dialect.dropSchemaObject(trx, { table, name: from });\n }\n }\n };\n\n const attributeRenameHandlers = new Set<AttributeRenameHandler>();\n\n return {\n /**\n * Renames a column, then the index / unique / foreign-key constraints named\n * after it (`<table>_<column>_index|unique|fk`) where supported.\n */\n async renameColumn(trx: Knex, op: RenameColumnOperation): Promise<boolean> {\n const comment = getOperationComment({ kind: 'renameColumn', ...op });\n\n if (!(await hasTable(trx, op.table))) {\n logSkip(comment, `table \"${op.table}\" does not exist`, 'source-missing');\n return false;\n }\n\n if (!(await hasColumn(trx, op.table, op.from))) {\n logSkip(comment, `column \"${op.table}.${op.from}\" does not exist`, 'source-missing');\n return false;\n }\n\n if (await hasColumn(trx, op.table, op.to)) {\n logSkip(comment, `column \"${op.table}.${op.to}\" already exists`, 'target-exists');\n return false;\n }\n\n await schemaOf(trx).alterTable(op.table, (table) => {\n table.renameColumn(op.from, op.to);\n });\n\n await syncSchemaObjectNames(trx, op.table, [\n {\n from: identifiers.getIndexName([op.table, op.from]),\n to: identifiers.getIndexName([op.table, op.to]),\n },\n {\n from: identifiers.getUniqueIndexName([op.table, op.from]),\n to: identifiers.getUniqueIndexName([op.table, op.to]),\n },\n {\n from: identifiers.getFkIndexName([op.table, op.from]),\n to: identifiers.getFkIndexName([op.table, op.to]),\n },\n ]);\n\n logApplied(comment);\n return true;\n },\n\n /**\n * Renames a table (typically a relation join table), then the indexes and\n * constraints named after it where supported.\n */\n async renameTable(trx: Knex, op: RenameTableOperation): Promise<boolean> {\n const comment = getOperationComment({ kind: 'renameTable', ...op });\n\n if (!(await hasTable(trx, op.from))) {\n logSkip(comment, `table \"${op.from}\" does not exist`, 'source-missing');\n return false;\n }\n\n if (await hasTable(trx, op.to)) {\n logSkip(comment, `table \"${op.to}\" already exists`, 'target-exists');\n return false;\n }\n\n await schemaOf(trx).renameTable(op.from, op.to);\n\n // Every name a join table's metadata derives from the table name (see\n // `createJoinTable` in metadata/relations.ts and the component link\n // tables in core's transform-content-types-to-models).\n const derived: Array<(name: string) => string> = [\n (name) => identifiers.getFkIndexName(name),\n (name) => identifiers.getInverseFkIndexName(name),\n (name) => identifiers.getUniqueIndexName(name),\n (name) => identifiers.getOrderFkIndexName(name),\n (name) => identifiers.getOrderInverseFkIndexName(name),\n (name) => identifiers.getOrderIndexName(name),\n (name) => identifiers.getIdColumnIndexName(name),\n ];\n\n await syncSchemaObjectNames(\n trx,\n op.to,\n derived.map((derive) => ({ from: derive(op.from), to: derive(op.to) }))\n );\n\n logApplied(comment);\n return true;\n },\n\n /**\n * Rewrites a stored value (e.g. the `field` or `component_type` column of a\n * component link table). Guarded on the table and `guardColumn` (defaults\n * to the first updated column) existing, and on rows matching `where`.\n */\n async updateRows(trx: Knex, op: UpdateRowsOperation): Promise<boolean> {\n const comment = getOperationComment({ kind: 'updateRows', ...op });\n const [firstSetColumn] = Object.keys(op.set);\n const guardColumn = op.guardColumn ?? firstSetColumn;\n\n if (!(await hasTable(trx, op.table))) {\n logSkip(comment, `table \"${op.table}\" does not exist`, 'source-missing');\n return false;\n }\n\n if (!(await hasColumn(trx, op.table, guardColumn))) {\n logSkip(comment, `column \"${op.table}.${guardColumn}\" does not exist`, 'source-missing');\n return false;\n }\n\n // Scope: every `where` key except the renamed column(s).\n const scope = Object.fromEntries(\n Object.entries(op.where).filter(([key]) => !(key in op.set))\n );\n const countRows = async (where: Record<string, unknown>): Promise<number> => {\n const [row] = await tableOf(trx, op.table).where(where).count({ count: '*' });\n return Number(row?.count ?? 0);\n };\n\n // Without source rows there is nothing to rename. Rows carrying the\n // target value may then be the ones a previous run already renamed, so\n // they must not be taken for orphans.\n if ((await countRows(op.where)) === 0) {\n if ((await countRows({ ...scope, ...op.set })) > 0) {\n logSkip(\n comment,\n `no row matches ${JSON.stringify(op.where)} in \"${op.table}\"; rows already matching ${JSON.stringify(op.set)} were left untouched, the rename may already have run`,\n 'target-exists'\n );\n } else {\n logSkip(\n comment,\n `no row matches ${JSON.stringify(op.where)} in \"${op.table}\"`,\n 'source-missing'\n );\n }\n return false;\n }\n\n // Rows already carrying the target value are orphans (left behind when\n // an attribute with the target name was deleted earlier). Updating would\n // merge them into the renamed field and resurrect deleted content, so\n // they go first.\n const removed = await tableOf(trx, op.table)\n .where({ ...scope, ...op.set })\n .delete();\n if (removed > 0) {\n db.logger.info(\n `[rename migration] removed ${removed} orphan row(s) already matching ${JSON.stringify(op.set)} in \"${op.table}\" before: ${comment}`\n );\n }\n\n await tableOf(trx, op.table).where(op.where).update(op.set);\n\n logApplied(comment);\n return true;\n },\n\n /**\n * Registers a handler for `applyAttributeRenames`. Plugins that keep data\n * keyed by attribute name register one during their register phase, before\n * user migrations run. Returns a function that unregisters it.\n */\n registerAttributeRenameHandler(handler: AttributeRenameHandler): () => void {\n attributeRenameHandlers.add(handler);\n return () => {\n attributeRenameHandlers.delete(handler);\n };\n },\n\n /**\n * Dispatches one save's attribute renames to every registered handler, in\n * registration order, inside `trx`. The database package itself stores\n * nothing keyed by attribute name, so with no handler this is a no-op.\n */\n async applyAttributeRenames(trx: Knex, op: AttributeRenamesOperation): Promise<boolean> {\n const comment = getOperationComment({ kind: 'attributeRenames', ...op });\n\n if (attributeRenameHandlers.size === 0) {\n db.logger.debug(`[rename migration] skipped: ${comment} (no handler registered)`);\n return false;\n }\n\n for (const handler of attributeRenameHandlers) {\n await handler(trx, op.renames);\n }\n\n logApplied(comment);\n return true;\n },\n };\n};\n\nexport type RenameHelpers = ReturnType<typeof createRenameHelpers>;\n"],"names":["createRenameHelpers","db","identifiers","metadata","logSkip","comment","detail","reason","message","logger","warn","info","logApplied","schemaOf","trx","getSchemaConnection","hasTable","table","hasColumn","column","tableOf","schemaName","getSchemaName","withSchema","syncSchemaObjectNames","pairs","canRename","dialect","canRenameSchemaObjects","from","to","renameSchemaObject","dropSchemaObject","name","attributeRenameHandlers","Set","renameColumn","op","getOperationComment","kind","alterTable","getIndexName","getUniqueIndexName","getFkIndexName","renameTable","derived","getInverseFkIndexName","getOrderFkIndexName","getOrderInverseFkIndexName","getOrderIndexName","getIdColumnIndexName","map","derive","updateRows","firstSetColumn","Object","keys","set","guardColumn","scope","fromEntries","entries","where","filter","key","countRows","row","count","Number","JSON","stringify","removed","delete","update","registerAttributeRenameHandler","handler","add","applyAttributeRenames","size","debug","renames"],"mappings":";;AA8DO,MAAMA,mBAAAA,GAAsB,CAAC,EAAEC,EAAE,EAAqB,GAAA;AAC3D,IAAA,MAAM,EAAEC,WAAW,EAAE,GAAGD,GAAGE,QAAQ;IAEnC,MAAMC,OAAAA,GAAU,CAACC,OAAAA,EAAiBC,MAAAA,EAAgBC,MAAAA,GAAAA;QAChD,MAAMC,OAAAA,GAAU,CAAC,4BAA4B,EAAEH,QAAQ,EAAE,EAAEC,MAAAA,CAAO,CAAC,CAAC;AACpE,QAAA,IAAIC,WAAW,eAAA,EAAiB;YAC9BN,EAAAA,CAAGQ,MAAM,CAACC,IAAI,CAACF,OAAAA,CAAAA;QACjB,CAAA,MAAO;YACLP,EAAAA,CAAGQ,MAAM,CAACE,IAAI,CAACH,OAAAA,CAAAA;AACjB,QAAA;AACF,IAAA,CAAA;AAEA,IAAA,MAAMI,aAAa,CAACP,OAAAA,GAAAA;AAClBJ,QAAAA,EAAAA,CAAGQ,MAAM,CAACE,IAAI,CAAC,CAAC,4BAA4B,EAAEN,OAAAA,CAAAA,CAAS,CAAA;AACzD,IAAA,CAAA;;AAGA,IAAA,MAAMQ,QAAAA,GAAW,C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CAACsE,KAAK,CAAC,CAAC,4BAA4B,EAAE1E,OAAAA,CAAQ,wBAAwB,CAAC,CAAA;gBAChF,OAAO,KAAA;AACT,YAAA;YAEA,KAAK,MAAMsE,WAAWzC,uBAAAA,CAAyB;gBAC7C,MAAMyC,OAAAA,CAAQ7D,GAAAA,EAAKuB,EAAAA,CAAG2C,OAAO,CAAA;AAC/B,YAAA;YAEApE,UAAAA,CAAWP,OAAAA,CAAAA;YACX,OAAO,IAAA;AACT,QAAA;AACF,KAAA;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"async-curry.d.ts","sourceRoot":"","sources":["../../src/utils/async-curry.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,IAAI,SAAS,GAAG,EAAE,EAAE,CAAC,EAC9C,IAAI,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAChC,oBAAoB,CAAC,IAAI,EAAE,CAAC,CAS9B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,IAAI,SAAS,GAAG,EAAE,EAAE,CAAC,IAAI,IAAI,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAC/F,IAAI,SAAS,EAAE,GACb,CAAC,GAAG,EAAE,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,GAC1B,CAAC,GAAG,EAAE,KAAK,KAAK,oBAAoB,CAAC,IAAI,EAAE,CAAC,CAAC,GAC/C,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"async-curry.d.ts","sourceRoot":"","sources":["../../src/utils/async-curry.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,IAAI,SAAS,GAAG,EAAE,EAAE,CAAC,EAC9C,IAAI,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAChC,oBAAoB,CAAC,IAAI,EAAE,CAAC,CAS9B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,IAAI,SAAS,GAAG,EAAE,EAAE,CAAC,IAAI,IAAI,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAC/F,IAAI,SAAS,EAAE,GACb,CAAC,GAAG,EAAE,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,GAC1B,CAAC,GAAG,EAAE,KAAK,KAAK,oBAAoB,CAAC,IAAI,EAAE,CAAC,CAAC,GAC/C,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC"}
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // lodash/fp curry does not handle async functions properly, and creates very "ugly" types,
4
- // so we will use our own version to ensure curried functions are typed correctly
3
+ // Keep asynchronous return values in the types of partially applied functions.
5
4
  // TODO: Export this from root @strapi/utils so we don't have copies of it between packages
6
5
  /**
7
6
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"async-curry.js","sources":["../../src/utils/async-curry.ts"],"sourcesContent":["// lodash/fp curry does not handle async functions properly, and creates very \"ugly\" types,\n// so we will use our own version to ensure curried functions are typed correctly\n// TODO: Export this from root @strapi/utils so we don't have copies of it between packages\n\n/**\n * @internal\n */\nexport const asyncCurry = <Args extends any[], R>(\n fn: (...args: Args) => Promise<R>\n): CurriedAsyncFunction<Args, R> => {\n const curried = (...args: any[]): any => {\n if (args.length >= fn.length) {\n return fn(...(args as Args));\n }\n return (...moreArgs: any[]) => curried(...args, ...moreArgs);\n };\n\n return curried as CurriedAsyncFunction<Args, R>;\n};\n\n/**\n * @internal\n */\nexport type CurriedAsyncFunction<Args extends any[], R> = Args extends [infer First, ...infer Rest]\n ? Rest extends []\n ? (arg: First) => Promise<R>\n : (arg: First) => CurriedAsyncFunction<Rest, R>\n : () => Promise<R>;\n"],"names":["asyncCurry","fn","curried","args","length","moreArgs"],"mappings":";;AAAA;AACA;AACA;AAEA;;IAGO,MAAMA,UAAAA,GAAa,CACxBC,EAAAA,GAAAA;IAEA,MAAMC,OAAAA,GAAU,CAAC,GAAGC,IAAAA,GAAAA;AAClB,QAAA,IAAIA,IAAAA,CAAKC,MAAM,IAAIH,EAAAA,CAAGG,MAAM,EAAE;AAC5B,YAAA,OAAOH,EAAAA,CAAAA,GAAOE,IAAAA,CAAAA;AAChB,QAAA;AACA,QAAA,OAAO,CAAC,GAAGE,QAAAA,GAAoBH,OAAAA,CAAAA,GAAWC,IAAAA,EAAAA,GAASE,QAAAA,CAAAA;AACrD,IAAA,CAAA;IAEA,OAAOH,OAAAA;AACT;;;;"}
1
+ {"version":3,"file":"async-curry.js","sources":["../../src/utils/async-curry.ts"],"sourcesContent":["// Keep asynchronous return values in the types of partially applied functions.\n// TODO: Export this from root @strapi/utils so we don't have copies of it between packages\n\n/**\n * @internal\n */\nexport const asyncCurry = <Args extends any[], R>(\n fn: (...args: Args) => Promise<R>\n): CurriedAsyncFunction<Args, R> => {\n const curried = (...args: any[]): any => {\n if (args.length >= fn.length) {\n return fn(...(args as Args));\n }\n return (...moreArgs: any[]) => curried(...args, ...moreArgs);\n };\n\n return curried as CurriedAsyncFunction<Args, R>;\n};\n\n/**\n * @internal\n */\nexport type CurriedAsyncFunction<Args extends any[], R> = Args extends [infer First, ...infer Rest]\n ? Rest extends []\n ? (arg: First) => Promise<R>\n : (arg: First) => CurriedAsyncFunction<Rest, R>\n : () => Promise<R>;\n"],"names":["asyncCurry","fn","curried","args","length","moreArgs"],"mappings":";;AAAA;AACA;AAEA;;IAGO,MAAMA,UAAAA,GAAa,CACxBC,EAAAA,GAAAA;IAEA,MAAMC,OAAAA,GAAU,CAAC,GAAGC,IAAAA,GAAAA;AAClB,QAAA,IAAIA,IAAAA,CAAKC,MAAM,IAAIH,EAAAA,CAAGG,MAAM,EAAE;AAC5B,YAAA,OAAOH,EAAAA,CAAAA,GAAOE,IAAAA,CAAAA;AAChB,QAAA;AACA,QAAA,OAAO,CAAC,GAAGE,QAAAA,GAAoBH,OAAAA,CAAAA,GAAWC,IAAAA,EAAAA,GAASE,QAAAA,CAAAA;AACrD,IAAA,CAAA;IAEA,OAAOH,OAAAA;AACT;;;;"}
@@ -1,5 +1,4 @@
1
- // lodash/fp curry does not handle async functions properly, and creates very "ugly" types,
2
- // so we will use our own version to ensure curried functions are typed correctly
1
+ // Keep asynchronous return values in the types of partially applied functions.
3
2
  // TODO: Export this from root @strapi/utils so we don't have copies of it between packages
4
3
  /**
5
4
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"async-curry.mjs","sources":["../../src/utils/async-curry.ts"],"sourcesContent":["// lodash/fp curry does not handle async functions properly, and creates very \"ugly\" types,\n// so we will use our own version to ensure curried functions are typed correctly\n// TODO: Export this from root @strapi/utils so we don't have copies of it between packages\n\n/**\n * @internal\n */\nexport const asyncCurry = <Args extends any[], R>(\n fn: (...args: Args) => Promise<R>\n): CurriedAsyncFunction<Args, R> => {\n const curried = (...args: any[]): any => {\n if (args.length >= fn.length) {\n return fn(...(args as Args));\n }\n return (...moreArgs: any[]) => curried(...args, ...moreArgs);\n };\n\n return curried as CurriedAsyncFunction<Args, R>;\n};\n\n/**\n * @internal\n */\nexport type CurriedAsyncFunction<Args extends any[], R> = Args extends [infer First, ...infer Rest]\n ? Rest extends []\n ? (arg: First) => Promise<R>\n : (arg: First) => CurriedAsyncFunction<Rest, R>\n : () => Promise<R>;\n"],"names":["asyncCurry","fn","curried","args","length","moreArgs"],"mappings":"AAAA;AACA;AACA;AAEA;;IAGO,MAAMA,UAAAA,GAAa,CACxBC,EAAAA,GAAAA;IAEA,MAAMC,OAAAA,GAAU,CAAC,GAAGC,IAAAA,GAAAA;AAClB,QAAA,IAAIA,IAAAA,CAAKC,MAAM,IAAIH,EAAAA,CAAGG,MAAM,EAAE;AAC5B,YAAA,OAAOH,EAAAA,CAAAA,GAAOE,IAAAA,CAAAA;AAChB,QAAA;AACA,QAAA,OAAO,CAAC,GAAGE,QAAAA,GAAoBH,OAAAA,CAAAA,GAAWC,IAAAA,EAAAA,GAASE,QAAAA,CAAAA;AACrD,IAAA,CAAA;IAEA,OAAOH,OAAAA;AACT;;;;"}
1
+ {"version":3,"file":"async-curry.mjs","sources":["../../src/utils/async-curry.ts"],"sourcesContent":["// Keep asynchronous return values in the types of partially applied functions.\n// TODO: Export this from root @strapi/utils so we don't have copies of it between packages\n\n/**\n * @internal\n */\nexport const asyncCurry = <Args extends any[], R>(\n fn: (...args: Args) => Promise<R>\n): CurriedAsyncFunction<Args, R> => {\n const curried = (...args: any[]): any => {\n if (args.length >= fn.length) {\n return fn(...(args as Args));\n }\n return (...moreArgs: any[]) => curried(...args, ...moreArgs);\n };\n\n return curried as CurriedAsyncFunction<Args, R>;\n};\n\n/**\n * @internal\n */\nexport type CurriedAsyncFunction<Args extends any[], R> = Args extends [infer First, ...infer Rest]\n ? Rest extends []\n ? (arg: First) => Promise<R>\n : (arg: First) => CurriedAsyncFunction<Rest, R>\n : () => Promise<R>;\n"],"names":["asyncCurry","fn","curried","args","length","moreArgs"],"mappings":"AAAA;AACA;AAEA;;IAGO,MAAMA,UAAAA,GAAa,CACxBC,EAAAA,GAAAA;IAEA,MAAMC,OAAAA,GAAU,CAAC,GAAGC,IAAAA,GAAAA;AAClB,QAAA,IAAIA,IAAAA,CAAKC,MAAM,IAAIH,EAAAA,CAAGG,MAAM,EAAE;AAC5B,YAAA,OAAOH,EAAAA,CAAAA,GAAOE,IAAAA,CAAAA;AAChB,QAAA;AACA,QAAA,OAAO,CAAC,GAAGE,QAAAA,GAAoBH,OAAAA,CAAAA,GAAWC,IAAAA,EAAAA,GAASE,QAAAA,CAAAA;AACrD,IAAA,CAAA;IAEA,OAAOH,OAAAA;AACT;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/utils/identifiers/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAO5D"}
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/utils/identifiers/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAO5D"}
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var crypto = require('node:crypto');
4
- var _ = require('lodash/fp');
5
4
 
6
5
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
6
 
@@ -21,7 +20,7 @@ var crypto__default = /*#__PURE__*/_interopDefault(crypto);
21
20
  * @throws Error if the length is not a positive integer
22
21
  * @internal
23
22
  */ function createHash(data, len) {
24
- if (!_.isInteger(len) || len <= 0) {
23
+ if (!Number.isInteger(len) || len <= 0) {
25
24
  throw new Error(`createHash length must be a positive integer, received ${len}`);
26
25
  }
27
26
  const hash = crypto__default.default.createHash('shake256', {
@@ -1 +1 @@
1
- {"version":3,"file":"hash.js","sources":["../../../src/utils/identifiers/hash.ts"],"sourcesContent":["/**\n * @fileoverview This file contains utility functions for shortening identifiers for use in a database schema.\n * The functions in this file are used to generate shorter names for database tables and columns\n * to avoid breaking the constraints of databases.\n *\n * IMPORTANT\n * Any changes here that result in a different output string from any of the naming methods will\n * cause the schema creation to delete data it doesn't recognize because the name\n * is different.\n *\n * If there are any test failures after updating this code, it means there is a breaking change that\n * will cause data loss, so beware; do not update the test to match your changes\n *\n * @internal\n */\n\nimport crypto from 'node:crypto';\nimport { isInteger } from 'lodash/fp';\n\n/**\n * Creates a hash of the given data with the specified string length as a string of hex characters\n *\n * @example\n * createHash(\"myData\", 5); // \"03f85\"\n * createHash(\"myData\", 2); // \"03\"\n * createHash(\"myData\", 1); // \"0\"\n *\n * @param data - The data to be hashed\n * @param len - The length of the hash\n * @returns The generated hash\n * @throws Error if the length is not a positive integer\n * @internal\n */\nexport function createHash(data: string, len: number): string {\n if (!isInteger(len) || len <= 0) {\n throw new Error(`createHash length must be a positive integer, received ${len}`);\n }\n\n const hash = crypto.createHash('shake256', { outputLength: Math.ceil(len / 2) }).update(data);\n return hash.digest('hex').substring(0, len);\n}\n"],"names":["createHash","data","len","isInteger","Error","hash","crypto","outputLength","Math","ceil","update","digest","substring"],"mappings":";;;;;;;;;AAmBA;;;;;;;;;;;;;AAaC,IACM,SAASA,UAAAA,CAAWC,IAAY,EAAEC,GAAW,EAAA;AAClD,IAAA,IAAI,CAACC,WAAAA,CAAUD,GAAAA,CAAAA,IAAQA,GAAAA,IAAO,CAAA,EAAG;AAC/B,QAAA,MAAM,IAAIE,KAAAA,CAAM,CAAC,uDAAuD,EAAEF,GAAAA,CAAAA,CAAK,CAAA;AACjF,IAAA;AAEA,IAAA,MAAMG,IAAAA,GAAOC,uBAAAA,CAAON,UAAU,CAAC,UAAA,EAAY;QAAEO,YAAAA,EAAcC,IAAAA,CAAKC,IAAI,CAACP,GAAAA,GAAM,CAAA;AAAG,KAAA,CAAA,CAAGQ,MAAM,CAACT,IAAAA,CAAAA;AACxF,IAAA,OAAOI,KAAKM,MAAM,CAAC,KAAA,CAAA,CAAOC,SAAS,CAAC,CAAA,EAAGV,GAAAA,CAAAA;AACzC;;;;"}
1
+ {"version":3,"file":"hash.js","sources":["../../../src/utils/identifiers/hash.ts"],"sourcesContent":["/**\n * @fileoverview This file contains utility functions for shortening identifiers for use in a database schema.\n * The functions in this file are used to generate shorter names for database tables and columns\n * to avoid breaking the constraints of databases.\n *\n * IMPORTANT\n * Any changes here that result in a different output string from any of the naming methods will\n * cause the schema creation to delete data it doesn't recognize because the name\n * is different.\n *\n * If there are any test failures after updating this code, it means there is a breaking change that\n * will cause data loss, so beware; do not update the test to match your changes\n *\n * @internal\n */\n\nimport crypto from 'node:crypto';\n\n/**\n * Creates a hash of the given data with the specified string length as a string of hex characters\n *\n * @example\n * createHash(\"myData\", 5); // \"03f85\"\n * createHash(\"myData\", 2); // \"03\"\n * createHash(\"myData\", 1); // \"0\"\n *\n * @param data - The data to be hashed\n * @param len - The length of the hash\n * @returns The generated hash\n * @throws Error if the length is not a positive integer\n * @internal\n */\nexport function createHash(data: string, len: number): string {\n if (!Number.isInteger(len) || len <= 0) {\n throw new Error(`createHash length must be a positive integer, received ${len}`);\n }\n\n const hash = crypto.createHash('shake256', { outputLength: Math.ceil(len / 2) }).update(data);\n return hash.digest('hex').substring(0, len);\n}\n"],"names":["createHash","data","len","Number","isInteger","Error","hash","crypto","outputLength","Math","ceil","update","digest","substring"],"mappings":";;;;;;;;AAkBA;;;;;;;;;;;;;AAaC,IACM,SAASA,UAAAA,CAAWC,IAAY,EAAEC,GAAW,EAAA;AAClD,IAAA,IAAI,CAACC,MAAAA,CAAOC,SAAS,CAACF,GAAAA,CAAAA,IAAQA,OAAO,CAAA,EAAG;AACtC,QAAA,MAAM,IAAIG,KAAAA,CAAM,CAAC,uDAAuD,EAAEH,GAAAA,CAAAA,CAAK,CAAA;AACjF,IAAA;AAEA,IAAA,MAAMI,IAAAA,GAAOC,uBAAAA,CAAOP,UAAU,CAAC,UAAA,EAAY;QAAEQ,YAAAA,EAAcC,IAAAA,CAAKC,IAAI,CAACR,GAAAA,GAAM,CAAA;AAAG,KAAA,CAAA,CAAGS,MAAM,CAACV,IAAAA,CAAAA;AACxF,IAAA,OAAOK,KAAKM,MAAM,CAAC,KAAA,CAAA,CAAOC,SAAS,CAAC,CAAA,EAAGX,GAAAA,CAAAA;AACzC;;;;"}
@@ -1,5 +1,4 @@
1
1
  import crypto from 'node:crypto';
2
- import { isInteger } from 'lodash/fp';
3
2
 
4
3
  /**
5
4
  * Creates a hash of the given data with the specified string length as a string of hex characters
@@ -15,7 +14,7 @@ import { isInteger } from 'lodash/fp';
15
14
  * @throws Error if the length is not a positive integer
16
15
  * @internal
17
16
  */ function createHash(data, len) {
18
- if (!isInteger(len) || len <= 0) {
17
+ if (!Number.isInteger(len) || len <= 0) {
19
18
  throw new Error(`createHash length must be a positive integer, received ${len}`);
20
19
  }
21
20
  const hash = crypto.createHash('shake256', {
@@ -1 +1 @@
1
- {"version":3,"file":"hash.mjs","sources":["../../../src/utils/identifiers/hash.ts"],"sourcesContent":["/**\n * @fileoverview This file contains utility functions for shortening identifiers for use in a database schema.\n * The functions in this file are used to generate shorter names for database tables and columns\n * to avoid breaking the constraints of databases.\n *\n * IMPORTANT\n * Any changes here that result in a different output string from any of the naming methods will\n * cause the schema creation to delete data it doesn't recognize because the name\n * is different.\n *\n * If there are any test failures after updating this code, it means there is a breaking change that\n * will cause data loss, so beware; do not update the test to match your changes\n *\n * @internal\n */\n\nimport crypto from 'node:crypto';\nimport { isInteger } from 'lodash/fp';\n\n/**\n * Creates a hash of the given data with the specified string length as a string of hex characters\n *\n * @example\n * createHash(\"myData\", 5); // \"03f85\"\n * createHash(\"myData\", 2); // \"03\"\n * createHash(\"myData\", 1); // \"0\"\n *\n * @param data - The data to be hashed\n * @param len - The length of the hash\n * @returns The generated hash\n * @throws Error if the length is not a positive integer\n * @internal\n */\nexport function createHash(data: string, len: number): string {\n if (!isInteger(len) || len <= 0) {\n throw new Error(`createHash length must be a positive integer, received ${len}`);\n }\n\n const hash = crypto.createHash('shake256', { outputLength: Math.ceil(len / 2) }).update(data);\n return hash.digest('hex').substring(0, len);\n}\n"],"names":["createHash","data","len","isInteger","Error","hash","crypto","outputLength","Math","ceil","update","digest","substring"],"mappings":";;;AAmBA;;;;;;;;;;;;;AAaC,IACM,SAASA,UAAAA,CAAWC,IAAY,EAAEC,GAAW,EAAA;AAClD,IAAA,IAAI,CAACC,SAAAA,CAAUD,GAAAA,CAAAA,IAAQA,GAAAA,IAAO,CAAA,EAAG;AAC/B,QAAA,MAAM,IAAIE,KAAAA,CAAM,CAAC,uDAAuD,EAAEF,GAAAA,CAAAA,CAAK,CAAA;AACjF,IAAA;AAEA,IAAA,MAAMG,IAAAA,GAAOC,MAAAA,CAAON,UAAU,CAAC,UAAA,EAAY;QAAEO,YAAAA,EAAcC,IAAAA,CAAKC,IAAI,CAACP,GAAAA,GAAM,CAAA;AAAG,KAAA,CAAA,CAAGQ,MAAM,CAACT,IAAAA,CAAAA;AACxF,IAAA,OAAOI,KAAKM,MAAM,CAAC,KAAA,CAAA,CAAOC,SAAS,CAAC,CAAA,EAAGV,GAAAA,CAAAA;AACzC;;;;"}
1
+ {"version":3,"file":"hash.mjs","sources":["../../../src/utils/identifiers/hash.ts"],"sourcesContent":["/**\n * @fileoverview This file contains utility functions for shortening identifiers for use in a database schema.\n * The functions in this file are used to generate shorter names for database tables and columns\n * to avoid breaking the constraints of databases.\n *\n * IMPORTANT\n * Any changes here that result in a different output string from any of the naming methods will\n * cause the schema creation to delete data it doesn't recognize because the name\n * is different.\n *\n * If there are any test failures after updating this code, it means there is a breaking change that\n * will cause data loss, so beware; do not update the test to match your changes\n *\n * @internal\n */\n\nimport crypto from 'node:crypto';\n\n/**\n * Creates a hash of the given data with the specified string length as a string of hex characters\n *\n * @example\n * createHash(\"myData\", 5); // \"03f85\"\n * createHash(\"myData\", 2); // \"03\"\n * createHash(\"myData\", 1); // \"0\"\n *\n * @param data - The data to be hashed\n * @param len - The length of the hash\n * @returns The generated hash\n * @throws Error if the length is not a positive integer\n * @internal\n */\nexport function createHash(data: string, len: number): string {\n if (!Number.isInteger(len) || len <= 0) {\n throw new Error(`createHash length must be a positive integer, received ${len}`);\n }\n\n const hash = crypto.createHash('shake256', { outputLength: Math.ceil(len / 2) }).update(data);\n return hash.digest('hex').substring(0, len);\n}\n"],"names":["createHash","data","len","Number","isInteger","Error","hash","crypto","outputLength","Math","ceil","update","digest","substring"],"mappings":";;AAkBA;;;;;;;;;;;;;AAaC,IACM,SAASA,UAAAA,CAAWC,IAAY,EAAEC,GAAW,EAAA;AAClD,IAAA,IAAI,CAACC,MAAAA,CAAOC,SAAS,CAACF,GAAAA,CAAAA,IAAQA,OAAO,CAAA,EAAG;AACtC,QAAA,MAAM,IAAIG,KAAAA,CAAM,CAAC,uDAAuD,EAAEH,GAAAA,CAAAA,CAAK,CAAA;AACjF,IAAA;AAEA,IAAA,MAAMI,IAAAA,GAAOC,MAAAA,CAAOP,UAAU,CAAC,UAAA,EAAY;QAAEQ,YAAAA,EAAcC,IAAAA,CAAKC,IAAI,CAACR,GAAAA,GAAM,CAAA;AAAG,KAAA,CAAA,CAAGS,MAAM,CAACV,IAAAA,CAAAA;AACxF,IAAA,OAAOK,KAAKM,MAAM,CAAC,KAAA,CAAA,CAAOC,SAAS,CAAC,CAAA,EAAGX,GAAAA,CAAAA;AACzC;;;;"}
@@ -1,12 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var _ = require('lodash/fp');
3
+ var _ = require('lodash');
4
4
  var hash = require('./hash.js');
5
5
 
6
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
-
8
- var ___default = /*#__PURE__*/_interopDefault(_);
9
-
10
6
  /**
11
7
  * This file contains utility functions for generating names used in the database.
12
8
  * These names include table names, column names, join table names, index names, and more.
@@ -78,7 +74,9 @@ class Identifiers {
78
74
  * we get names 'myModel' and 'my_model' they would be converted to the same
79
75
  * final string my_model which generally works but is not entirely safe
80
76
  * */ this.getName = (names, options)=>{
81
- const tokens = ___default.default.castArray(names).map((name)=>{
77
+ const tokens = (Array.isArray(names) ? names : [
78
+ names
79
+ ]).map((name)=>{
82
80
  return {
83
81
  name,
84
82
  compressible: true
@@ -256,7 +254,7 @@ class Identifiers {
256
254
  * @throws Error if the length is not a positive integer, or if the length is too short for the token.
257
255
  * @internal
258
256
  */ this.getShortenedName = (name, len)=>{
259
- if (!_.isInteger(len) || len <= 0) {
257
+ if (!Number.isInteger(len) || len <= 0) {
260
258
  throw new Error(`tokenWithHash length must be a positive integer, received ${len}`);
261
259
  }
262
260
  if (name.length <= len) {
@@ -280,7 +278,7 @@ class Identifiers {
280
278
  * @internal
281
279
  */ this.getNameFromTokens = (nameTokens)=>{
282
280
  const { maxLength } = this.options;
283
- if (!_.isInteger(maxLength) || maxLength < 0) {
281
+ if (!Number.isInteger(maxLength) || maxLength < 0) {
284
282
  throw new Error('maxLength must be a positive integer or 0 (for unlimited length)');
285
283
  }
286
284
  const unshortenedName = nameTokens.map((token)=>{
@@ -303,8 +301,8 @@ class Identifiers {
303
301
  return fullLengthName;
304
302
  }
305
303
  // Split tokens by compressibility
306
- const [compressible, incompressible] = _.partition((token)=>token.compressible, nameTokens);
307
- const totalIncompressibleLength = _.sumBy((token)=>token.compressible === false && token.shortName !== undefined ? token.shortName.length : token.name.length)(incompressible);
304
+ const [compressible, incompressible] = _.partition(nameTokens, (token)=>token.compressible);
305
+ const totalIncompressibleLength = _.sumBy(incompressible, (token)=>token.compressible === false && token.shortName !== undefined ? token.shortName.length : token.name.length);
308
306
  const totalSeparatorsLength = nameTokens.length * this.IDENTIFIER_SEPARATOR.length - 1;
309
307
  const available = maxLength - totalIncompressibleLength - totalSeparatorsLength;
310
308
  const availablePerToken = Math.floor(available / compressible.length);