@strapi/database 5.48.0 → 5.49.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 (76) hide show
  1. package/dist/connection.js +5 -1
  2. package/dist/connection.js.map +1 -1
  3. package/dist/dialects/mysql/schema-inspector.d.ts +3 -0
  4. package/dist/dialects/mysql/schema-inspector.d.ts.map +1 -1
  5. package/dist/dialects/mysql/schema-inspector.js +145 -85
  6. package/dist/dialects/mysql/schema-inspector.js.map +1 -1
  7. package/dist/dialects/mysql/schema-inspector.mjs +145 -85
  8. package/dist/dialects/mysql/schema-inspector.mjs.map +1 -1
  9. package/dist/dialects/postgresql/schema-inspector.d.ts +3 -1
  10. package/dist/dialects/postgresql/schema-inspector.d.ts.map +1 -1
  11. package/dist/dialects/postgresql/schema-inspector.js +150 -109
  12. package/dist/dialects/postgresql/schema-inspector.js.map +1 -1
  13. package/dist/dialects/postgresql/schema-inspector.mjs +150 -109
  14. package/dist/dialects/postgresql/schema-inspector.mjs.map +1 -1
  15. package/dist/dialects/sqlite/index.js +8 -3
  16. package/dist/dialects/sqlite/index.js.map +1 -1
  17. package/dist/entity-manager/relations-orderer.js +5 -1
  18. package/dist/entity-manager/relations-orderer.js.map +1 -1
  19. package/dist/fields/datetime.js +3 -2
  20. package/dist/fields/datetime.js.map +1 -1
  21. package/dist/fields/index.js +5 -1
  22. package/dist/fields/index.js.map +1 -1
  23. package/dist/fields/shared/parsers.js +3 -2
  24. package/dist/fields/shared/parsers.js.map +1 -1
  25. package/dist/fields/timestamp.js +3 -2
  26. package/dist/fields/timestamp.js.map +1 -1
  27. package/dist/index.js +5 -1
  28. package/dist/index.js.map +1 -1
  29. package/dist/lifecycles/subscribers/timestamps.js +10 -6
  30. package/dist/lifecycles/subscribers/timestamps.js.map +1 -1
  31. package/dist/metadata/relations.js +6 -2
  32. package/dist/metadata/relations.js.map +1 -1
  33. package/dist/migrations/internal-migrations/5.0.0-01-convert-identifiers-long-than-max-length.js +5 -1
  34. package/dist/migrations/internal-migrations/5.0.0-01-convert-identifiers-long-than-max-length.js.map +1 -1
  35. package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.d.ts +5 -0
  36. package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.d.ts.map +1 -1
  37. package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.js +7 -58
  38. package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.js.map +1 -1
  39. package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.mjs +7 -58
  40. package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.mjs.map +1 -1
  41. package/dist/migrations/users.js +6 -2
  42. package/dist/migrations/users.js.map +1 -1
  43. package/dist/query/helpers/order-by.js +11 -7
  44. package/dist/query/helpers/order-by.js.map +1 -1
  45. package/dist/query/helpers/populate/apply.d.ts.map +1 -1
  46. package/dist/query/helpers/populate/apply.js +48 -47
  47. package/dist/query/helpers/populate/apply.js.map +1 -1
  48. package/dist/query/helpers/populate/apply.mjs +4 -7
  49. package/dist/query/helpers/populate/apply.mjs.map +1 -1
  50. package/dist/query/helpers/populate/process.js +7 -3
  51. package/dist/query/helpers/populate/process.js.map +1 -1
  52. package/dist/query/helpers/search.js +5 -1
  53. package/dist/query/helpers/search.js.map +1 -1
  54. package/dist/query/helpers/transform.js +10 -6
  55. package/dist/query/helpers/transform.js.map +1 -1
  56. package/dist/query/helpers/where.d.ts +1 -1
  57. package/dist/query/helpers/where.d.ts.map +1 -1
  58. package/dist/query/helpers/where.js.map +1 -1
  59. package/dist/query/helpers/where.mjs.map +1 -1
  60. package/dist/query/query-builder.js +30 -26
  61. package/dist/query/query-builder.js.map +1 -1
  62. package/dist/schema/builder.js +5 -1
  63. package/dist/schema/builder.js.map +1 -1
  64. package/dist/schema/diff.js +19 -15
  65. package/dist/schema/diff.js.map +1 -1
  66. package/dist/schema/index.js +5 -1
  67. package/dist/schema/index.js.map +1 -1
  68. package/dist/schema/storage.js +5 -1
  69. package/dist/schema/storage.js.map +1 -1
  70. package/dist/utils/identifiers/hash.js +5 -1
  71. package/dist/utils/identifiers/hash.js.map +1 -1
  72. package/dist/utils/identifiers/index.js +5 -1
  73. package/dist/utils/identifiers/index.js.map +1 -1
  74. package/dist/utils/knex.js +6 -1
  75. package/dist/utils/knex.js.map +1 -1
  76. package/package.json +5 -5
@@ -1,64 +1,13 @@
1
1
  'use strict';
2
2
 
3
- // Add an index if it does not already exist
4
- const createIndex = async (knex, tableName, columns, indexName)=>{
5
- try {
6
- // If the database can check for indexes, avoid duplicates
7
- const hasIndex = knex.schema.hasIndex;
8
- if (hasIndex) {
9
- const exists = await hasIndex.call(knex.schema, tableName, indexName);
10
- if (exists) {
11
- return;
12
- }
13
- }
14
- await knex.schema.alterTable(tableName, (table)=>{
15
- table.index(columns, indexName);
16
- });
17
- } catch (error) {
18
- // If the index exists (or cannot be created), move on
19
- }
20
- };
21
- const addIndexesForTable = async (knex, tableName)=>{
22
- // Only add indexes when the column is present
23
- const hasDocumentId = await knex.schema.hasColumn(tableName, 'document_id');
24
- if (!hasDocumentId) {
25
- return;
26
- }
27
- const hasLocale = await knex.schema.hasColumn(tableName, 'locale');
28
- const hasPublishedAt = await knex.schema.hasColumn(tableName, 'published_at');
29
- // Single column index for basic lookups
30
- await createIndex(knex, tableName, [
31
- 'document_id'
32
- ], `${tableName}_document_id_idx`);
33
- if (hasLocale && hasPublishedAt) {
34
- // Composite index for common filters
35
- await createIndex(knex, tableName, [
36
- 'document_id',
37
- 'locale',
38
- 'published_at'
39
- ], `${tableName}_document_id_locale_published_at_idx`);
40
- } else if (hasLocale) {
41
- await createIndex(knex, tableName, [
42
- 'document_id',
43
- 'locale'
44
- ], `${tableName}_document_id_locale_idx`);
45
- } else if (hasPublishedAt) {
46
- await createIndex(knex, tableName, [
47
- 'document_id',
48
- 'published_at'
49
- ], `${tableName}_document_id_published_at_idx`);
50
- }
51
- };
52
- const addDocumentIdIndexes = {
3
+ /**
4
+ * Previously created secondary indexes on `document_id` (and composites) via raw DDL.
5
+ * Those indexes are now owned by schema sync from model metadata (see transform-content-types-to-models).
6
+ * Keep this migration as a stable no-op so Umzug / `strapi_migrations_internal` stay consistent.
7
+ */ const addDocumentIdIndexes = {
53
8
  name: '5.0.0-06-add-document-id-indexes',
54
- async up (knex, db) {
55
- for (const meta of db.metadata.values()){
56
- const hasTable = await knex.schema.hasTable(meta.tableName);
57
- if (!hasTable) {
58
- continue;
59
- }
60
- await addIndexesForTable(knex, meta.tableName);
61
- }
9
+ async up () {
10
+ // No-op: the document_id indexes are now created by schema sync (see transform-content-types-to-models).
62
11
  },
63
12
  async down () {
64
13
  throw new Error('not implemented');
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-06-add-document-id-indexes.js","sources":["../../../src/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\n// Add an index if it does not already exist\nconst createIndex = async (knex: Knex, tableName: string, columns: string[], indexName: string) => {\n try {\n // If the database can check for indexes, avoid duplicates\n const hasIndex = (\n knex.schema as unknown as {\n hasIndex?: (tableName: string, indexName: string) => Promise<boolean>;\n }\n ).hasIndex;\n if (hasIndex) {\n const exists = await hasIndex.call(knex.schema, tableName, indexName);\n if (exists) {\n return;\n }\n }\n\n await knex.schema.alterTable(tableName, (table) => {\n table.index(columns, indexName);\n });\n } catch (error) {\n // If the index exists (or cannot be created), move on\n }\n};\n\nconst addIndexesForTable = async (knex: Knex, tableName: string) => {\n // Only add indexes when the column is present\n const hasDocumentId = await knex.schema.hasColumn(tableName, 'document_id');\n if (!hasDocumentId) {\n return;\n }\n\n const hasLocale = await knex.schema.hasColumn(tableName, 'locale');\n const hasPublishedAt = await knex.schema.hasColumn(tableName, 'published_at');\n\n // Single column index for basic lookups\n await createIndex(knex, tableName, ['document_id'], `${tableName}_document_id_idx`);\n\n if (hasLocale && hasPublishedAt) {\n // Composite index for common filters\n await createIndex(\n knex,\n tableName,\n ['document_id', 'locale', 'published_at'],\n `${tableName}_document_id_locale_published_at_idx`\n );\n } else if (hasLocale) {\n await createIndex(\n knex,\n tableName,\n ['document_id', 'locale'],\n `${tableName}_document_id_locale_idx`\n );\n } else if (hasPublishedAt) {\n await createIndex(\n knex,\n tableName,\n ['document_id', 'published_at'],\n `${tableName}_document_id_published_at_idx`\n );\n }\n};\n\nexport const addDocumentIdIndexes: Migration = {\n name: '5.0.0-06-add-document-id-indexes',\n async up(knex, db) {\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n if (!hasTable) {\n continue;\n }\n\n await addIndexesForTable(knex, meta.tableName);\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["createIndex","knex","tableName","columns","indexName","hasIndex","schema","exists","call","alterTable","table","index","error","addIndexesForTable","hasDocumentId","hasColumn","hasLocale","hasPublishedAt","addDocumentIdIndexes","name","up","db","meta","metadata","values","hasTable","down","Error"],"mappings":";;AAIA;AACA,MAAMA,WAAAA,GAAc,OAAOC,IAAAA,EAAYC,SAAAA,EAAmBC,OAAAA,EAAmBC,SAAAA,GAAAA;IAC3E,IAAI;;AAEF,QAAA,MAAMC,QAAAA,GACJJ,IAAAA,CAAKK,MAAM,CAGXD,QAAQ;AACV,QAAA,IAAIA,QAAAA,EAAU;YACZ,MAAME,MAAAA,GAAS,MAAMF,QAAAA,CAASG,IAAI,CAACP,IAAAA,CAAKK,MAAM,EAAEJ,SAAAA,EAAWE,SAAAA,CAAAA;AAC3D,YAAA,IAAIG,MAAAA,EAAQ;AACV,gBAAA;AACF,YAAA;AACF,QAAA;AAEA,QAAA,MAAMN,KAAKK,MAAM,CAACG,UAAU,CAACP,WAAW,CAACQ,KAAAA,GAAAA;YACvCA,KAAAA,CAAMC,KAAK,CAACR,OAAAA,EAASC,SAAAA,CAAAA;AACvB,QAAA,CAAA,CAAA;AACF,IAAA,CAAA,CAAE,OAAOQ,KAAAA,EAA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A,CAAGnB,IAAI,EAAEoB,EAAE,EAAA;AACf,QAAA,KAAK,MAAMC,IAAAA,IAAQD,EAAAA,CAAGE,QAAQ,CAACC,MAAM,EAAA,CAAI;YACvC,MAAMC,QAAAA,GAAW,MAAMxB,IAAAA,CAAKK,MAAM,CAACmB,QAAQ,CAACH,KAAKpB,SAAS,CAAA;AAC1D,YAAA,IAAI,CAACuB,QAAAA,EAAU;AACb,gBAAA;AACF,YAAA;YAEA,MAAMZ,kBAAAA,CAAmBZ,IAAAA,EAAMqB,IAAAA,CAAKpB,SAAS,CAAA;AAC/C,QAAA;AACF,IAAA,CAAA;IACA,MAAMwB,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
1
+ {"version":3,"file":"5.0.0-06-add-document-id-indexes.js","sources":["../../../src/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.ts"],"sourcesContent":["import type { Migration } from '../common';\n\n/**\n * Previously created secondary indexes on `document_id` (and composites) via raw DDL.\n * Those indexes are now owned by schema sync from model metadata (see transform-content-types-to-models).\n * Keep this migration as a stable no-op so Umzug / `strapi_migrations_internal` stay consistent.\n */\n\nexport const addDocumentIdIndexes: Migration = {\n name: '5.0.0-06-add-document-id-indexes',\n async up() {\n // No-op: the document_id indexes are now created by schema sync (see transform-content-types-to-models).\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["addDocumentIdIndexes","name","up","down","Error"],"mappings":";;AAEA;;;;UAMaA,oBAAAA,GAAkC;IAC7CC,IAAAA,EAAM,kCAAA;IACN,MAAMC,EAAAA,CAAAA,GAAAA;;AAEN,IAAA,CAAA;IACA,MAAMC,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
@@ -1,62 +1,11 @@
1
- // Add an index if it does not already exist
2
- const createIndex = async (knex, tableName, columns, indexName)=>{
3
- try {
4
- // If the database can check for indexes, avoid duplicates
5
- const hasIndex = knex.schema.hasIndex;
6
- if (hasIndex) {
7
- const exists = await hasIndex.call(knex.schema, tableName, indexName);
8
- if (exists) {
9
- return;
10
- }
11
- }
12
- await knex.schema.alterTable(tableName, (table)=>{
13
- table.index(columns, indexName);
14
- });
15
- } catch (error) {
16
- // If the index exists (or cannot be created), move on
17
- }
18
- };
19
- const addIndexesForTable = async (knex, tableName)=>{
20
- // Only add indexes when the column is present
21
- const hasDocumentId = await knex.schema.hasColumn(tableName, 'document_id');
22
- if (!hasDocumentId) {
23
- return;
24
- }
25
- const hasLocale = await knex.schema.hasColumn(tableName, 'locale');
26
- const hasPublishedAt = await knex.schema.hasColumn(tableName, 'published_at');
27
- // Single column index for basic lookups
28
- await createIndex(knex, tableName, [
29
- 'document_id'
30
- ], `${tableName}_document_id_idx`);
31
- if (hasLocale && hasPublishedAt) {
32
- // Composite index for common filters
33
- await createIndex(knex, tableName, [
34
- 'document_id',
35
- 'locale',
36
- 'published_at'
37
- ], `${tableName}_document_id_locale_published_at_idx`);
38
- } else if (hasLocale) {
39
- await createIndex(knex, tableName, [
40
- 'document_id',
41
- 'locale'
42
- ], `${tableName}_document_id_locale_idx`);
43
- } else if (hasPublishedAt) {
44
- await createIndex(knex, tableName, [
45
- 'document_id',
46
- 'published_at'
47
- ], `${tableName}_document_id_published_at_idx`);
48
- }
49
- };
50
- const addDocumentIdIndexes = {
1
+ /**
2
+ * Previously created secondary indexes on `document_id` (and composites) via raw DDL.
3
+ * Those indexes are now owned by schema sync from model metadata (see transform-content-types-to-models).
4
+ * Keep this migration as a stable no-op so Umzug / `strapi_migrations_internal` stay consistent.
5
+ */ const addDocumentIdIndexes = {
51
6
  name: '5.0.0-06-add-document-id-indexes',
52
- async up (knex, db) {
53
- for (const meta of db.metadata.values()){
54
- const hasTable = await knex.schema.hasTable(meta.tableName);
55
- if (!hasTable) {
56
- continue;
57
- }
58
- await addIndexesForTable(knex, meta.tableName);
59
- }
7
+ async up () {
8
+ // No-op: the document_id indexes are now created by schema sync (see transform-content-types-to-models).
60
9
  },
61
10
  async down () {
62
11
  throw new Error('not implemented');
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-06-add-document-id-indexes.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\n// Add an index if it does not already exist\nconst createIndex = async (knex: Knex, tableName: string, columns: string[], indexName: string) => {\n try {\n // If the database can check for indexes, avoid duplicates\n const hasIndex = (\n knex.schema as unknown as {\n hasIndex?: (tableName: string, indexName: string) => Promise<boolean>;\n }\n ).hasIndex;\n if (hasIndex) {\n const exists = await hasIndex.call(knex.schema, tableName, indexName);\n if (exists) {\n return;\n }\n }\n\n await knex.schema.alterTable(tableName, (table) => {\n table.index(columns, indexName);\n });\n } catch (error) {\n // If the index exists (or cannot be created), move on\n }\n};\n\nconst addIndexesForTable = async (knex: Knex, tableName: string) => {\n // Only add indexes when the column is present\n const hasDocumentId = await knex.schema.hasColumn(tableName, 'document_id');\n if (!hasDocumentId) {\n return;\n }\n\n const hasLocale = await knex.schema.hasColumn(tableName, 'locale');\n const hasPublishedAt = await knex.schema.hasColumn(tableName, 'published_at');\n\n // Single column index for basic lookups\n await createIndex(knex, tableName, ['document_id'], `${tableName}_document_id_idx`);\n\n if (hasLocale && hasPublishedAt) {\n // Composite index for common filters\n await createIndex(\n knex,\n tableName,\n ['document_id', 'locale', 'published_at'],\n `${tableName}_document_id_locale_published_at_idx`\n );\n } else if (hasLocale) {\n await createIndex(\n knex,\n tableName,\n ['document_id', 'locale'],\n `${tableName}_document_id_locale_idx`\n );\n } else if (hasPublishedAt) {\n await createIndex(\n knex,\n tableName,\n ['document_id', 'published_at'],\n `${tableName}_document_id_published_at_idx`\n );\n }\n};\n\nexport const addDocumentIdIndexes: Migration = {\n name: '5.0.0-06-add-document-id-indexes',\n async up(knex, db) {\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n if (!hasTable) {\n continue;\n }\n\n await addIndexesForTable(knex, meta.tableName);\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["createIndex","knex","tableName","columns","indexName","hasIndex","schema","exists","call","alterTable","table","index","error","addIndexesForTable","hasDocumentId","hasColumn","hasLocale","hasPublishedAt","addDocumentIdIndexes","name","up","db","meta","metadata","values","hasTable","down","Error"],"mappings":"AAIA;AACA,MAAMA,WAAAA,GAAc,OAAOC,IAAAA,EAAYC,SAAAA,EAAmBC,OAAAA,EAAmBC,SAAAA,GAAAA;IAC3E,IAAI;;AAEF,QAAA,MAAMC,QAAAA,GACJJ,IAAAA,CAAKK,MAAM,CAGXD,QAAQ;AACV,QAAA,IAAIA,QAAAA,EAAU;YACZ,MAAME,MAAAA,GAAS,MAAMF,QAAAA,CAASG,IAAI,CAACP,IAAAA,CAAKK,MAAM,EAAEJ,SAAAA,EAAWE,SAAAA,CAAAA;AAC3D,YAAA,IAAIG,MAAAA,EAAQ;AACV,gBAAA;AACF,YAAA;AACF,QAAA;AAEA,QAAA,MAAMN,KAAKK,MAAM,CAACG,UAAU,CAACP,WAAW,CAACQ,KAAAA,GAAAA;YACvCA,KAAAA,CAAMC,KAAK,CAACR,OAAAA,EAASC,SAAAA,CAAAA;AACvB,QAAA,CAAA,CAAA;AACF,IAAA,CAAA,CAAE,OAAOQ,KAAAA,EAAO;;AAEhB,IAAA;AACF,CAAA;AAEA,MAAMC,kBAAAA,GAAqB,OAAOZ,IAAAA,EAAYC,SAAAA,GAAAA;;AAE5C,IAAA,MAAMY,gBAAgB,MAAMb,IAAAA,CAAKK,MAAM,CAACS,SAAS,CAACb,SAAAA,EAAW,aAAA,CAAA;AAC7D,IAAA,IAAI,CAACY,aAAAA,EAAe;AAClB,QAAA;AACF,IAAA;AAEA,IAAA,MAAME,YAAY,MAAMf,IAAAA,CAAKK,MAAM,CAACS,SAAS,CAACb,SAAAA,EA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CAAKpB,SAAS,CAAA;AAC/C,QAAA;AACF,IAAA,CAAA;IACA,MAAMwB,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
1
+ {"version":3,"file":"5.0.0-06-add-document-id-indexes.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.ts"],"sourcesContent":["import type { Migration } from '../common';\n\n/**\n * Previously created secondary indexes on `document_id` (and composites) via raw DDL.\n * Those indexes are now owned by schema sync from model metadata (see transform-content-types-to-models).\n * Keep this migration as a stable no-op so Umzug / `strapi_migrations_internal` stay consistent.\n */\n\nexport const addDocumentIdIndexes: Migration = {\n name: '5.0.0-06-add-document-id-indexes',\n async up() {\n // No-op: the document_id indexes are now created by schema sync (see transform-content-types-to-models).\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["addDocumentIdIndexes","name","up","down","Error"],"mappings":"AAEA;;;;UAMaA,oBAAAA,GAAkC;IAC7CC,IAAAA,EAAM,kCAAA;IACN,MAAMC,EAAAA,CAAAA,GAAAA;;AAEN,IAAA,CAAA;IACA,MAAMC,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
@@ -5,6 +5,10 @@ var storage = require('./storage.js');
5
5
  var common = require('./common.js');
6
6
  var logger = require('./logger.js');
7
7
 
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var fse__default = /*#__PURE__*/_interopDefault(fse);
11
+
8
12
  // TODO: check multiple commands in one sql statement
9
13
  const migrationResolver = ({ name, path, context })=>{
10
14
  const { db } = context;
@@ -13,7 +17,7 @@ const migrationResolver = ({ name, path, context })=>{
13
17
  }
14
18
  // if sql file run with knex raw
15
19
  if (path.match(/\.sql$/)) {
16
- const sql = fse.readFileSync(path, 'utf8');
20
+ const sql = fse__default.default.readFileSync(path, 'utf8');
17
21
  return {
18
22
  name,
19
23
  up: common.wrapTransaction(db)((knex)=>knex.raw(sql)),
@@ -33,7 +37,7 @@ const migrationResolver = ({ name, path, context })=>{
33
37
  };
34
38
  const createUserMigrationProvider = (db)=>{
35
39
  const dir = db.config.settings.migrations.dir;
36
- fse.ensureDirSync(dir);
40
+ fse__default.default.ensureDirSync(dir);
37
41
  const context = {
38
42
  db
39
43
  };
@@ -1 +1 @@
1
- {"version":3,"file":"users.js","sources":["../../src/migrations/users.ts"],"sourcesContent":["import fse from 'fs-extra';\nimport type { Umzug } from 'umzug';\n\nimport { createStorage } from './storage';\nimport { wrapTransaction } from './common';\nimport { transformLogMessage } from './logger';\n\nimport type { MigrationResolver, UserMigrationProvider } from './common';\nimport type { Database } from '..';\n\n// TODO: check multiple commands in one sql statement\nconst migrationResolver: MigrationResolver = ({ name, path, context }) => {\n const { db } = context;\n\n if (!path) {\n throw new Error(`Migration ${name} has no path`);\n }\n\n // if sql file run with knex raw\n if (path.match(/\\.sql$/)) {\n const sql = fse.readFileSync(path, 'utf8');\n\n return {\n name,\n up: wrapTransaction(db)((knex) => knex.raw(sql)),\n async down() {\n throw new Error('Down migration is not supported for sql files');\n },\n };\n }\n\n // NOTE: we can add some ts register if we want to handle ts migration files at some point\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const migration = require(path);\n return {\n name,\n up: wrapTransaction(db)(migration.up),\n down: wrapTransaction(db)(migration.down),\n };\n};\n\nexport const createUserMigrationProvider = (db: Database): UserMigrationProvider => {\n const dir = db.config.settings.migrations.dir;\n\n fse.ensureDirSync(dir);\n\n const context = { db };\n\n // Lazy: defer `umzug` (and its inquirer / @rushstack chain) until first call\n let lazyProvider: Umzug<typeof context> | undefined;\n const provider = (): Umzug<typeof context> => {\n if (lazyProvider) return lazyProvider;\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { Umzug: UmzugCtor } = require('umzug') as typeof import('umzug');\n lazyProvider = new UmzugCtor({\n storage: createStorage({ db, tableName: 'strapi_migrations' }),\n logger: {\n info(message) {\n // NOTE: only log internal migration in debug mode\n db.logger.info(transformLogMessage('info', message));\n },\n warn(message) {\n db.logger.warn(transformLogMessage('warn', message));\n },\n error(message) {\n db.logger.error(transformLogMessage('error', message));\n },\n debug(message) {\n db.logger.debug(transformLogMessage('debug', message));\n },\n },\n context,\n migrations: {\n glob: ['*.{js,sql}', { cwd: dir }],\n resolve: migrationResolver,\n },\n });\n return lazyProvider;\n };\n\n return {\n async shouldRun() {\n const pendingMigrations = await provider().pending();\n return pendingMigrations.length > 0 && db.config?.settings?.runMigrations === true;\n },\n async up() {\n await provider().up();\n },\n async down() {\n await provider().down();\n },\n };\n};\n"],"names":["migrationResolver","name","path","context","db","Error","match","sql","fse","readFileSync","up","wrapTransaction","knex","raw","down","migration","require","createUserMigrationProvider","dir","config","settings","migrations","ensureDirSync","lazyProvider","provider","Umzug","UmzugCtor","storage","createStorage","tableName","logger","info","message","transformLogMessage","warn","error","debug","glob","cwd","resolve","shouldRun","pendingMigrations","pending","length","runMigrations"],"mappings":";;;;;;;AAUA;AACA,MAAMA,iBAAAA,GAAuC,CAAC,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAE,GAAA;IACnE,MAAM,EAAEC,EAAE,EAAE,GAAGD,OAAAA;AAEf,IAAA,IAAI,CAACD,IAAAA,EAAM;AACT,QAAA,MAAM,IAAIG,KAAAA,CAAM,CAAC,UAAU,EAAEJ,IAAAA,CAAK,YAAY,CAAC,CAAA;AACjD,IAAA;;IAGA,IAAIC,IAAAA,CAAKI,KAAK,CAAC,QAAA,CAAA,EAAW;AACxB,QAAA,MAAMC,GAAAA,GAAMC,GAAAA,CAAIC,YAAY,CAACP,IAAAA,EAAM,MAAA,CAAA;QAEnC,OAAO;AACLD,YAAAA,IAAAA;AACAS,YAAAA,EAAAA,EAAIC,uBAAgBP,EAAAA,CAAAA,CAAI,CAACQ,IAAAA,GAASA,IAAAA,CAAKC,GAAG,CAACN,GAAAA,CA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EAAA;AACV5B,oBAAAA,EAAAA,CAAG0B,MAAM,CAACI,IAAI,CAACD,2BAAoB,MAAA,EAAQD,OAAAA,CAAAA,CAAAA;AAC7C,gBAAA,CAAA;AACAG,gBAAAA,KAAAA,CAAAA,CAAMH,OAAO,EAAA;AACX5B,oBAAAA,EAAAA,CAAG0B,MAAM,CAACK,KAAK,CAACF,2BAAoB,OAAA,EAASD,OAAAA,CAAAA,CAAAA;AAC/C,gBAAA,CAAA;AACAI,gBAAAA,KAAAA,CAAAA,CAAMJ,OAAO,EAAA;AACX5B,oBAAAA,EAAAA,CAAG0B,MAAM,CAACM,KAAK,CAACH,2BAAoB,OAAA,EAASD,OAAAA,CAAAA,CAAAA;AAC/C,gBAAA;AACF,aAAA;AACA7B,YAAAA,OAAAA;YACAkB,UAAAA,EAAY;gBACVgB,IAAAA,EAAM;AAAC,oBAAA,YAAA;AAAc,oBAAA;wBAAEC,GAAAA,EAAKpB;AAAI;AAAE,iBAAA;gBAClCqB,OAAAA,EAASvC;AACX;AACF,SAAA,CAAA;QACA,OAAOuB,YAAAA;AACT,IAAA,CAAA;IAEA,OAAO;QACL,MAAMiB,SAAAA,CAAAA,GAAAA;YACJ,MAAMC,iBAAAA,GAAoB,MAAMjB,QAAAA,EAAAA,CAAWkB,OAAO,EAAA;YAClD,OAAOD,iBAAAA,CAAkBE,MAAM,GAAG,CAAA,IAAKvC,GAAGe,MAAM,EAAEC,UAAUwB,aAAAA,KAAkB,IAAA;AAChF,QAAA,CAAA;QACA,MAAMlC,EAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMc,WAAWd,EAAE,EAAA;AACrB,QAAA,CAAA;QACA,MAAMI,IAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMU,WAAWV,IAAI,EAAA;AACvB,QAAA;AACF,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"users.js","sources":["../../src/migrations/users.ts"],"sourcesContent":["import fse from 'fs-extra';\nimport type { Umzug } from 'umzug';\n\nimport { createStorage } from './storage';\nimport { wrapTransaction } from './common';\nimport { transformLogMessage } from './logger';\n\nimport type { MigrationResolver, UserMigrationProvider } from './common';\nimport type { Database } from '..';\n\n// TODO: check multiple commands in one sql statement\nconst migrationResolver: MigrationResolver = ({ name, path, context }) => {\n const { db } = context;\n\n if (!path) {\n throw new Error(`Migration ${name} has no path`);\n }\n\n // if sql file run with knex raw\n if (path.match(/\\.sql$/)) {\n const sql = fse.readFileSync(path, 'utf8');\n\n return {\n name,\n up: wrapTransaction(db)((knex) => knex.raw(sql)),\n async down() {\n throw new Error('Down migration is not supported for sql files');\n },\n };\n }\n\n // NOTE: we can add some ts register if we want to handle ts migration files at some point\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const migration = require(path);\n return {\n name,\n up: wrapTransaction(db)(migration.up),\n down: wrapTransaction(db)(migration.down),\n };\n};\n\nexport const createUserMigrationProvider = (db: Database): UserMigrationProvider => {\n const dir = db.config.settings.migrations.dir;\n\n fse.ensureDirSync(dir);\n\n const context = { db };\n\n // Lazy: defer `umzug` (and its inquirer / @rushstack chain) until first call\n let lazyProvider: Umzug<typeof context> | undefined;\n const provider = (): Umzug<typeof context> => {\n if (lazyProvider) return lazyProvider;\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { Umzug: UmzugCtor } = require('umzug') as typeof import('umzug');\n lazyProvider = new UmzugCtor({\n storage: createStorage({ db, tableName: 'strapi_migrations' }),\n logger: {\n info(message) {\n // NOTE: only log internal migration in debug mode\n db.logger.info(transformLogMessage('info', message));\n },\n warn(message) {\n db.logger.warn(transformLogMessage('warn', message));\n },\n error(message) {\n db.logger.error(transformLogMessage('error', message));\n },\n debug(message) {\n db.logger.debug(transformLogMessage('debug', message));\n },\n },\n context,\n migrations: {\n glob: ['*.{js,sql}', { cwd: dir }],\n resolve: migrationResolver,\n },\n });\n return lazyProvider;\n };\n\n return {\n async shouldRun() {\n const pendingMigrations = await provider().pending();\n return pendingMigrations.length > 0 && db.config?.settings?.runMigrations === true;\n },\n async up() {\n await provider().up();\n },\n async down() {\n await provider().down();\n },\n };\n};\n"],"names":["migrationResolver","name","path","context","db","Error","match","sql","fse","readFileSync","up","wrapTransaction","knex","raw","down","migration","require","createUserMigrationProvider","dir","config","settings","migrations","ensureDirSync","lazyProvider","provider","Umzug","UmzugCtor","storage","createStorage","tableName","logger","info","message","transformLogMessage","warn","error","debug","glob","cwd","resolve","shouldRun","pendingMigrations","pending","length","runMigrations"],"mappings":";;;;;;;;;;;AAUA;AACA,MAAMA,iBAAAA,GAAuC,CAAC,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAE,GAAA;IACnE,MAAM,EAAEC,EAAE,EAAE,GAAGD,OAAAA;AAEf,IAAA,IAAI,CAACD,IAAAA,EAAM;AACT,QAAA,MAAM,IAAIG,KAAAA,CAAM,CAAC,UAAU,EAAEJ,IAAAA,CAAK,YAAY,CAAC,CAAA;AACjD,IAAA;;IAGA,IAAIC,IAAAA,CAAKI,KAAK,CAAC,QAAA,CAAA,EAAW;AACxB,QAAA,MAAMC,GAAAA,GAAMC,oBAAAA,CAAIC,YAAY,CAACP,IAAAA,EAAM,MAAA,CAAA;QAEnC,OAAO;AACLD,YAAAA,IAAAA;AACAS,YAAAA,EAAAA,EAAIC,uBAAgBP,EAAAA,CAAAA,CAAI,CAACQ,IAAAA,GAASA,IAAAA,CAAKC,GAAG,CAACN,GAAAA,CAAAA,CAAAA;YAC3C,MAAMO,IAAAA,CAAAA,GAAAA;AACJ,gBAAA,MAAM,IAAIT,KAAAA,CAAM,+CAAA,CAAA;AAClB,YAAA;AACF,SAAA;AACF,IAAA;;;AAIA,IAAA,MAAMU,YAAYC,OAAAA,CAAQd,IAAAA,CAAAA;IAC1B,OAAO;AACLD,QAAAA,IAAAA;QACAS,EAAAA,EAAIC,sBAAAA,CAAgBP,EAAAA,CAAAA,CAAIW,SAAAA,CAAUL,EAAE,CAAA;QACpCI,IAAAA,EAAMH,sBAAAA,CAAgBP,EAAAA,CAAAA,CAAIW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B,MAAM,CAACM,KAAK,CAACH,2BAAoB,OAAA,EAASD,OAAAA,CAAAA,CAAAA;AAC/C,gBAAA;AACF,aAAA;AACA7B,YAAAA,OAAAA;YACAkB,UAAAA,EAAY;gBACVgB,IAAAA,EAAM;AAAC,oBAAA,YAAA;AAAc,oBAAA;wBAAEC,GAAAA,EAAKpB;AAAI;AAAE,iBAAA;gBAClCqB,OAAAA,EAASvC;AACX;AACF,SAAA,CAAA;QACA,OAAOuB,YAAAA;AACT,IAAA,CAAA;IAEA,OAAO;QACL,MAAMiB,SAAAA,CAAAA,GAAAA;YACJ,MAAMC,iBAAAA,GAAoB,MAAMjB,QAAAA,EAAAA,CAAWkB,OAAO,EAAA;YAClD,OAAOD,iBAAAA,CAAkBE,MAAM,GAAG,CAAA,IAAKvC,GAAGe,MAAM,EAAEC,UAAUwB,aAAAA,KAAkB,IAAA;AAChF,QAAA,CAAA;QACA,MAAMlC,EAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMc,WAAWd,EAAE,EAAA;AACrB,QAAA,CAAA;QACA,MAAMI,IAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMU,WAAWV,IAAI,EAAA;AACvB,QAAA;AACF,KAAA;AACF;;;;"}
@@ -5,6 +5,10 @@ var types = require('../../utils/types.js');
5
5
  var join = require('./join.js');
6
6
  var transform = require('./transform.js');
7
7
 
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var ___default = /*#__PURE__*/_interopDefault(_);
11
+
8
12
  const COL_STRAPI_ROW_NUMBER = '__strapi_row_number';
9
13
  const COL_STRAPI_ORDER_BY_PREFIX = '__strapi_order_by';
10
14
  /**
@@ -71,7 +75,7 @@ const processOrderBy = (orderBy, ctx)=>{
71
75
  if (Array.isArray(orderBy)) {
72
76
  return orderBy.flatMap((value)=>processOrderBy(value, ctx));
73
77
  }
74
- if (_.isPlainObject(orderBy)) {
78
+ if (___default.default.isPlainObject(orderBy)) {
75
79
  return Object.entries(orderBy).flatMap(([key, direction])=>{
76
80
  const value = orderBy[key];
77
81
  if (key === 'status') {
@@ -134,7 +138,7 @@ const getStrapiOrderColumnAlias = (column)=>{
134
138
  */ const { db, qb, uid } = ctx;
135
139
  const { tableName } = db.metadata.get(uid);
136
140
  // The orderBy is cloned to avoid unwanted mutations of the original object
137
- const orderBy = _.cloneDeep(qb.state.orderBy);
141
+ const orderBy = ___default.default.cloneDeep(qb.state.orderBy);
138
142
  // Separate column-based entries from raw-expression entries (e.g. status)
139
143
  const columnOrderBy = orderBy.filter((ob)=>'column' in ob);
140
144
  const rawExpressionOrderBy = orderBy.filter((ob)=>'rawExpression' in ob);
@@ -168,7 +172,7 @@ const getStrapiOrderColumnAlias = (column)=>{
168
172
  order: orderByClause.order
169
173
  }));
170
174
  // partitionedQuery select must contain every column used for sorting
171
- const orderByColumns = prefixedOrderBy.map(_.prop('column'));
175
+ const orderByColumns = prefixedOrderBy.map(___default.default.prop('column'));
172
176
  partitionedQuery.select(// Always select baseQuery.id
173
177
  prefix(baseQueryAlias, 'id'), // Sort columns
174
178
  ...orderByColumns)// The row number is used to assign an index to every row in every partition
@@ -183,8 +187,8 @@ const getStrapiOrderColumnAlias = (column)=>{
183
187
  // 3. Create the final resultQuery query, that select and sort the wanted data using T
184
188
  // Filter to string-only select items before diffing (Knex.Raw items are passed through as-is)
185
189
  const stringSelect = qb.state.select.filter((s)=>typeof s === 'string');
186
- const originalSelect = _.difference(stringSelect, // Remove column-based order by columns from the initial select (raw expressions are not in select)
187
- columnOrderBy.map(_.prop('column')))// Alias everything in resultQuery
190
+ const originalSelect = ___default.default.difference(stringSelect, // Remove column-based order by columns from the initial select (raw expressions are not in select)
191
+ columnOrderBy.map(___default.default.prop('column')))// Alias everything in resultQuery
188
192
  .map((col)=>`${resultQueryAlias}.${col}`);
189
193
  resultQuery.select(originalSelect)// Join T to resultQuery to access sorted data
190
194
  // Notes:
@@ -229,8 +233,8 @@ const getStrapiOrderColumnAlias = (column)=>{
229
233
  return resultQuery;
230
234
  };
231
235
  // Utils
232
- const alias = _.curry((alias, value)=>`${value} as ${alias}`);
233
- const prefix = _.curry((prefix, value)=>`${prefix}.${value}`);
236
+ const alias = ___default.default.curry((alias, value)=>`${value} as ${alias}`);
237
+ const prefix = ___default.default.curry((prefix, value)=>`${prefix}.${value}`);
234
238
 
235
239
  exports.buildStatusSortExpression = buildStatusSortExpression;
236
240
  exports.getStrapiOrderColumnAlias = getStrapiOrderColumnAlias;
@@ -1 +1 @@
1
- {"version":3,"file":"order-by.js","sources":["../../../src/query/helpers/order-by.ts"],"sourcesContent":["import _ from 'lodash/fp';\nimport knex from 'knex';\n\nimport * as types from '../../utils/types';\nimport { createJoin } from './join';\nimport { toColumnName } from './transform';\n\nimport type { Ctx } from '../types';\n\ntype OrderByCtx = Ctx & { alias?: string };\ntype OrderBy = string | { [key: string]: 'asc' | 'desc' } | OrderBy[];\ntype OrderByColumnValue = { column: string; order?: 'asc' | 'desc' };\ntype OrderByRawValue = { rawExpression: 'status'; isI18n?: boolean; order?: 'asc' | 'desc' };\nexport type OrderByValue = OrderByColumnValue | OrderByRawValue;\n\nconst COL_STRAPI_ROW_NUMBER = '__strapi_row_number';\nconst COL_STRAPI_ORDER_BY_PREFIX = '__strapi_order_by';\n\n/**\n * Builds a SQL CASE expression that maps each row to a numeric status rank:\n * 0 = draft/created (no published sibling with same documentId [+ locale])\n * 1 = modified (draft updated_at > published updated_at for same documentId [+ locale])\n * 2 = published\n *\n * @param db - Database instance (used to access knex raw)\n * @param tableName - Actual DB table name (used in correlated subqueries)\n * @param tableAlias - Alias of the table in the outer query (e.g. \"t0\")\n * @param isI18n - When true, adds a locale condition to avoid cross-locale contamination\n */\nexport const buildStatusSortExpression = (\n db: { connection: { raw: (sql: string, bindings?: unknown[]) => knex.Knex.Raw } },\n tableName: string,\n tableAlias: string,\n isI18n = false\n): knex.Knex.Raw => {\n const localeCondition = isI18n ? ` AND sub.locale = ${tableAlias}.locale` : '';\n\n return db.connection.raw(\n `CASE WHEN NOT EXISTS(SELECT 1 FROM ?? sub WHERE sub.document_id = ${tableAlias}.document_id AND sub.published_at IS NOT NULL${localeCondition}) THEN 0 WHEN ${tableAlias}.updated_at > (SELECT MAX(sub.updated_at) FROM ?? sub WHERE sub.document_id = ${tableAlias}.document_id AND sub.published_at IS NOT NULL${localeCondition}) THEN 1 ELSE 2 END`,\n [tableName, tableName]\n );\n};\n\n/** DB handle accepted by {@link buildStatusSortExpression}. */\ntype StatusSortDb = Parameters<typeof buildStatusSortExpression>[0];\n\n/**\n * Shape passed to Knex `orderBy` for compound ordering. Knex accepts `Knex.Raw` in the column\n * position at runtime; generated typings sometimes only list string.\n */\nexport type KnexOrderByColumnDescriptor = {\n column: string | knex.Knex.Raw;\n order?: 'asc' | 'desc';\n};\n\n/**\n * Maps processed {@link OrderByValue} entries to descriptors Knex can consume. Translates the\n * virtual `status` sort into a parameterized raw SQL expression.\n */\nexport const toKnexOrderByDescriptor = (\n db: StatusSortDb,\n tableName: string,\n rootTableAlias: string,\n entry: OrderByValue\n): KnexOrderByColumnDescriptor => {\n if ('rawExpression' in entry) {\n return {\n column: buildStatusSortExpression(db, tableName, rootTableAlias, entry.isI18n),\n order: entry.order,\n };\n }\n\n return { column: entry.column, order: entry.order };\n};\n\nexport const processOrderBy = (orderBy: OrderBy, ctx: OrderByCtx): OrderByValue[] => {\n const { db, uid, qb, alias } = ctx;\n const meta = db.metadata.get(uid);\n const { attributes } = meta;\n\n if (typeof orderBy === 'string') {\n if (orderBy === 'status') {\n if (!attributes.publishedAt || !attributes.documentId) {\n throw new Error(\n `Cannot order by status on model ${uid}: missing publishedAt or documentId`\n );\n }\n const isI18n = 'locale' in attributes;\n return [{ rawExpression: 'status' as const, isI18n, order: undefined }];\n }\n\n const attribute = attributes[orderBy];\n\n if (!attribute) {\n throw new Error(`Attribute ${orderBy} not found on model ${uid}`);\n }\n\n const columnName = toColumnName(meta, orderBy);\n\n return [{ column: qb.aliasColumn(columnName, alias) }];\n }\n\n if (Array.isArray(orderBy)) {\n return orderBy.flatMap((value) => processOrderBy(value, ctx));\n }\n\n if (_.isPlainObject(orderBy)) {\n return Object.entries(orderBy).flatMap(([key, direction]) => {\n const value = orderBy[key];\n\n if (key === 'status') {\n if (!attributes.publishedAt || !attributes.documentId) {\n throw new Error(\n `Cannot order by status on model ${uid}: missing publishedAt or documentId`\n );\n }\n const isI18n = 'locale' in attributes;\n return [{ rawExpression: 'status' as const, isI18n, order: direction as 'asc' | 'desc' }];\n }\n\n const attribute = attributes[key];\n\n if (!attribute) {\n throw new Error(`Attribute ${key} not found on model ${uid}`);\n }\n\n if (types.isScalar(attribute.type)) {\n const columnName = toColumnName(meta, key);\n\n return { column: qb.aliasColumn(columnName, alias), order: direction };\n }\n\n if (attribute.type === 'relation' && 'target' in attribute) {\n const subAlias = createJoin(ctx, {\n alias: alias || qb.alias,\n attributeName: key,\n attribute,\n });\n\n return processOrderBy(value, {\n db,\n qb,\n alias: subAlias,\n uid: attribute.target,\n });\n }\n\n throw new Error(`You cannot order on ${attribute.type} types`);\n });\n }\n\n throw new Error('Invalid orderBy syntax');\n};\n\nexport const getStrapiOrderColumnAlias = (column: string) => {\n const trimmedColumnName = column.replaceAll('.', '_');\n\n return `${COL_STRAPI_ORDER_BY_PREFIX}__${trimmedColumnName}`;\n};\n\n/**\n * Wraps the original Knex query with deep sorting functionality.\n *\n * The function takes an original query and an OrderByCtx object as parameters and returns a new Knex query with deep sorting applied.\n */\nexport const wrapWithDeepSort = (originalQuery: knex.Knex.QueryBuilder, ctx: OrderByCtx) => {\n /**\n * Notes:\n * - The generated query has the following flow: baseQuery (filtered unsorted data) -> T (partitioned/sorted data) --> resultQuery (distinct, paginated, sorted data)\n * - Pagination and selection are transferred from the original query to the outer one to avoid pruning rows too early\n * - Filtering (where) has to be done in the deepest sub query possible to avoid processing invalid rows and corrupting the final results\n * - We assume that all necessary joins are done in the original query (`originalQuery`), and every needed column is available with the right name and alias.\n */\n\n const { db, qb, uid } = ctx;\n\n const { tableName } = db.metadata.get(uid);\n\n // The orderBy is cloned to avoid unwanted mutations of the original object\n const orderBy = _.cloneDeep<OrderByValue[]>(qb.state.orderBy);\n\n // Separate column-based entries from raw-expression entries (e.g. status)\n const columnOrderBy = orderBy.filter((ob): ob is OrderByColumnValue => 'column' in ob);\n const rawExpressionOrderBy = orderBy.filter((ob): ob is OrderByRawValue => 'rawExpression' in ob);\n\n // 0. Init a new Knex query instance (referenced as resultQuery) using the DB connection\n // The connection reuse the original table name (aliased if needed)\n const resultQueryAlias = qb.getAlias();\n const aliasedTableName = qb.mustUseAlias() ? alias(resultQueryAlias, tableName) : tableName;\n\n const resultQuery = db.getConnection(aliasedTableName);\n\n // 1. Clone the original query to create the sub-query (referenced as baseQuery) and avoid any mutation on the initial object\n const baseQuery = originalQuery.clone();\n const baseQueryAlias = qb.getAlias();\n\n // Clear unwanted statements from the sub-query 'baseQuery'\n // Note: `first()` is cleared through the combination of `baseQuery.clear('limit')` and calling `baseQuery.select(...)` again\n // Note: Those statements will be re-applied when duplicates are removed from the final selection\n baseQuery\n // Columns selection\n .clear('select')\n // Pagination and sorting\n .clear('order')\n .clear('limit')\n .clear('offset');\n\n // Override the initial select and return only the columns needed for the partitioning.\n // Only column-based orderBy entries are included here; raw expressions are applied later.\n baseQuery.select(\n // Always select the row id for future manipulation\n prefix(qb.alias, 'id'),\n // Select every column used in an order by clause, but alias it for future reference\n // i.e. if t2.name is present in an order by clause:\n // Then, \"t2.name\" will become \"t2.name as __strapi_order_by__t2_name\"\n ...columnOrderBy.map((orderByClause) =>\n alias(getStrapiOrderColumnAlias(orderByClause.column), orderByClause.column)\n )\n );\n\n // 2. Create a sub-query callback to extract and sort the partitions using row number\n const partitionedQueryAlias = qb.getAlias();\n\n const selectRowsAsNumberedPartitions = (partitionedQuery: knex.Knex.QueryBuilder) => {\n // Transform order by clause to their alias to reference them from baseQuery\n const prefixedOrderBy = columnOrderBy.map((orderByClause) => ({\n column: prefix(baseQueryAlias, getStrapiOrderColumnAlias(orderByClause.column)),\n order: orderByClause.order,\n }));\n\n // partitionedQuery select must contain every column used for sorting\n const orderByColumns = prefixedOrderBy.map<string>(_.prop('column'));\n\n partitionedQuery\n .select(\n // Always select baseQuery.id\n prefix(baseQueryAlias, 'id'),\n // Sort columns\n ...orderByColumns\n )\n // The row number is used to assign an index to every row in every partition\n .rowNumber(COL_STRAPI_ROW_NUMBER, (subQuery) => {\n for (const orderByClause of prefixedOrderBy) {\n subQuery.orderBy(orderByClause.column, orderByClause.order, 'last');\n }\n\n // And each partition/group is created based on baseQuery.id\n subQuery.partitionBy(`${baseQueryAlias}.id`);\n })\n .from(baseQuery.as(baseQueryAlias))\n .as(partitionedQueryAlias);\n };\n\n // 3. Create the final resultQuery query, that select and sort the wanted data using T\n\n // Filter to string-only select items before diffing (Knex.Raw items are passed through as-is)\n const stringSelect = qb.state.select.filter((s): s is string => typeof s === 'string');\n const originalSelect = _.difference(\n stringSelect,\n // Remove column-based order by columns from the initial select (raw expressions are not in select)\n columnOrderBy.map(_.prop('column'))\n )\n // Alias everything in resultQuery\n .map((col) => `${resultQueryAlias}.${col}`);\n\n resultQuery\n .select(originalSelect)\n // Join T to resultQuery to access sorted data\n // Notes:\n // - Only select the first row for each partition\n // - Since we're applying the \"where\" statement directly on baseQuery (and not on resultQuery), we're using an inner join to avoid unwanted rows\n .innerJoin(selectRowsAsNumberedPartitions, function () {\n this\n // Only select rows that are returned by T\n .on(`${partitionedQueryAlias}.id`, `${resultQueryAlias}.id`)\n // By only selecting the rows number equal to 1, we make sure we don't have duplicate, and that\n // we're selecting rows in the correct order amongst the groups created by the \"partition by\"\n .andOnVal(`${partitionedQueryAlias}.${COL_STRAPI_ROW_NUMBER}`, '=', 1);\n });\n\n // Re-apply pagination params\n\n if (qb.state.limit) {\n resultQuery.limit(qb.state.limit);\n }\n\n if (qb.state.offset) {\n resultQuery.offset(qb.state.offset);\n }\n\n if (qb.state.first) {\n resultQuery.first();\n }\n\n // Re-apply the sort using T values (column-based), then append raw expression sorts.\n // Cast to any[] because Knex's TS types don't accept Knex.Raw in the column position,\n // even though Knex supports it at runtime.\n resultQuery.orderBy([\n // Transform column-based \"order by\" clause to their T alias and prefix them with T alias\n ...columnOrderBy.map((orderByClause) => ({\n column: prefix(partitionedQueryAlias, getStrapiOrderColumnAlias(orderByClause.column)),\n order: orderByClause.order,\n })),\n // Rebuild raw expression entries with the correct outer alias (resultQueryAlias)\n ...rawExpressionOrderBy.map((entry) => ({\n column: buildStatusSortExpression(db, tableName, resultQueryAlias, entry.isI18n),\n order: entry.order,\n })),\n // Add T.id to the order by clause to get consistent results in case several rows have the exact same order\n { column: `${partitionedQueryAlias}.id`, order: 'asc' },\n ] as any);\n\n return resultQuery;\n};\n\n// Utils\nconst alias = _.curry((alias: string, value: string) => `${value} as ${alias}`);\nconst prefix = _.curry((prefix: string, value: string) => `${prefix}.${value}`);\n"],"names":["COL_STRAPI_ROW_NUMBER","COL_STRAPI_ORDER_BY_PREFIX","buildStatusSortExpression","db","tableName","tableAlias","isI18n","localeCondition","connection","raw","toKnexOrderByDescriptor","rootTableAlias","entry","column","order","processOrderBy","orderBy","ctx","uid","qb","alias","meta","metadata","get","attributes","publishedAt","documentId","Error","rawExpression","undefined","attribute","columnName","toColumnName","aliasColumn","Array","isArray","flatMap","value","_","isPlainObject","Object","entries","key","direction","types","type","subAlias","createJoin","attributeName","target","getStrapiOrderColumnAlias","trimmedColumnName","replaceAll","wrapWithDeepSort","originalQuery","cloneDeep","state","columnOrderBy","filter","ob","rawExpressionOrderBy","resultQueryAlias","getAlias","aliasedTableName","mustUseAlias","resultQuery","getConnection","baseQuery","clone","baseQueryAlias","clear","select","prefix","map","orderByClause","partitionedQueryAlias","selectRowsAsNumberedPartitions","partitionedQuery","prefixedOrderBy","orderByColumns","prop","rowNumber","subQuery","partitionBy","from","as","stringSelect","s","originalSelect","difference","col","innerJoin","on","andOnVal","limit","offset","first","curry"],"mappings":";;;;;;;AAeA,MAAMA,qBAAAA,GAAw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AAAA,CAAAA,CAAO,CAAA;AAC9E,MAAMoD,MAAAA,GAASlC,CAAAA,CAAE2D,KAAK,CAAC,CAACzB,MAAAA,EAAgBnC,KAAAA,GAAkB,CAAA,EAAGmC,MAAAA,CAAO,CAAC,EAAEnC,KAAAA,CAAAA,CAAO,CAAA;;;;;;;;"}
1
+ {"version":3,"file":"order-by.js","sources":["../../../src/query/helpers/order-by.ts"],"sourcesContent":["import _ from 'lodash/fp';\nimport knex from 'knex';\n\nimport * as types from '../../utils/types';\nimport { createJoin } from './join';\nimport { toColumnName } from './transform';\n\nimport type { Ctx } from '../types';\n\ntype OrderByCtx = Ctx & { alias?: string };\ntype OrderBy = string | { [key: string]: 'asc' | 'desc' } | OrderBy[];\ntype OrderByColumnValue = { column: string; order?: 'asc' | 'desc' };\ntype OrderByRawValue = { rawExpression: 'status'; isI18n?: boolean; order?: 'asc' | 'desc' };\nexport type OrderByValue = OrderByColumnValue | OrderByRawValue;\n\nconst COL_STRAPI_ROW_NUMBER = '__strapi_row_number';\nconst COL_STRAPI_ORDER_BY_PREFIX = '__strapi_order_by';\n\n/**\n * Builds a SQL CASE expression that maps each row to a numeric status rank:\n * 0 = draft/created (no published sibling with same documentId [+ locale])\n * 1 = modified (draft updated_at > published updated_at for same documentId [+ locale])\n * 2 = published\n *\n * @param db - Database instance (used to access knex raw)\n * @param tableName - Actual DB table name (used in correlated subqueries)\n * @param tableAlias - Alias of the table in the outer query (e.g. \"t0\")\n * @param isI18n - When true, adds a locale condition to avoid cross-locale contamination\n */\nexport const buildStatusSortExpression = (\n db: { connection: { raw: (sql: string, bindings?: unknown[]) => knex.Knex.Raw } },\n tableName: string,\n tableAlias: string,\n isI18n = false\n): knex.Knex.Raw => {\n const localeCondition = isI18n ? ` AND sub.locale = ${tableAlias}.locale` : '';\n\n return db.connection.raw(\n `CASE WHEN NOT EXISTS(SELECT 1 FROM ?? sub WHERE sub.document_id = ${tableAlias}.document_id AND sub.published_at IS NOT NULL${localeCondition}) THEN 0 WHEN ${tableAlias}.updated_at > (SELECT MAX(sub.updated_at) FROM ?? sub WHERE sub.document_id = ${tableAlias}.document_id AND sub.published_at IS NOT NULL${localeCondition}) THEN 1 ELSE 2 END`,\n [tableName, tableName]\n );\n};\n\n/** DB handle accepted by {@link buildStatusSortExpression}. */\ntype StatusSortDb = Parameters<typeof buildStatusSortExpression>[0];\n\n/**\n * Shape passed to Knex `orderBy` for compound ordering. Knex accepts `Knex.Raw` in the column\n * position at runtime; generated typings sometimes only list string.\n */\nexport type KnexOrderByColumnDescriptor = {\n column: string | knex.Knex.Raw;\n order?: 'asc' | 'desc';\n};\n\n/**\n * Maps processed {@link OrderByValue} entries to descriptors Knex can consume. Translates the\n * virtual `status` sort into a parameterized raw SQL expression.\n */\nexport const toKnexOrderByDescriptor = (\n db: StatusSortDb,\n tableName: string,\n rootTableAlias: string,\n entry: OrderByValue\n): KnexOrderByColumnDescriptor => {\n if ('rawExpression' in entry) {\n return {\n column: buildStatusSortExpression(db, tableName, rootTableAlias, entry.isI18n),\n order: entry.order,\n };\n }\n\n return { column: entry.column, order: entry.order };\n};\n\nexport const processOrderBy = (orderBy: OrderBy, ctx: OrderByCtx): OrderByValue[] => {\n const { db, uid, qb, alias } = ctx;\n const meta = db.metadata.get(uid);\n const { attributes } = meta;\n\n if (typeof orderBy === 'string') {\n if (orderBy === 'status') {\n if (!attributes.publishedAt || !attributes.documentId) {\n throw new Error(\n `Cannot order by status on model ${uid}: missing publishedAt or documentId`\n );\n }\n const isI18n = 'locale' in attributes;\n return [{ rawExpression: 'status' as const, isI18n, order: undefined }];\n }\n\n const attribute = attributes[orderBy];\n\n if (!attribute) {\n throw new Error(`Attribute ${orderBy} not found on model ${uid}`);\n }\n\n const columnName = toColumnName(meta, orderBy);\n\n return [{ column: qb.aliasColumn(columnName, alias) }];\n }\n\n if (Array.isArray(orderBy)) {\n return orderBy.flatMap((value) => processOrderBy(value, ctx));\n }\n\n if (_.isPlainObject(orderBy)) {\n return Object.entries(orderBy).flatMap(([key, direction]) => {\n const value = orderBy[key];\n\n if (key === 'status') {\n if (!attributes.publishedAt || !attributes.documentId) {\n throw new Error(\n `Cannot order by status on model ${uid}: missing publishedAt or documentId`\n );\n }\n const isI18n = 'locale' in attributes;\n return [{ rawExpression: 'status' as const, isI18n, order: direction as 'asc' | 'desc' }];\n }\n\n const attribute = attributes[key];\n\n if (!attribute) {\n throw new Error(`Attribute ${key} not found on model ${uid}`);\n }\n\n if (types.isScalar(attribute.type)) {\n const columnName = toColumnName(meta, key);\n\n return { column: qb.aliasColumn(columnName, alias), order: direction };\n }\n\n if (attribute.type === 'relation' && 'target' in attribute) {\n const subAlias = createJoin(ctx, {\n alias: alias || qb.alias,\n attributeName: key,\n attribute,\n });\n\n return processOrderBy(value, {\n db,\n qb,\n alias: subAlias,\n uid: attribute.target,\n });\n }\n\n throw new Error(`You cannot order on ${attribute.type} types`);\n });\n }\n\n throw new Error('Invalid orderBy syntax');\n};\n\nexport const getStrapiOrderColumnAlias = (column: string) => {\n const trimmedColumnName = column.replaceAll('.', '_');\n\n return `${COL_STRAPI_ORDER_BY_PREFIX}__${trimmedColumnName}`;\n};\n\n/**\n * Wraps the original Knex query with deep sorting functionality.\n *\n * The function takes an original query and an OrderByCtx object as parameters and returns a new Knex query with deep sorting applied.\n */\nexport const wrapWithDeepSort = (originalQuery: knex.Knex.QueryBuilder, ctx: OrderByCtx) => {\n /**\n * Notes:\n * - The generated query has the following flow: baseQuery (filtered unsorted data) -> T (partitioned/sorted data) --> resultQuery (distinct, paginated, sorted data)\n * - Pagination and selection are transferred from the original query to the outer one to avoid pruning rows too early\n * - Filtering (where) has to be done in the deepest sub query possible to avoid processing invalid rows and corrupting the final results\n * - We assume that all necessary joins are done in the original query (`originalQuery`), and every needed column is available with the right name and alias.\n */\n\n const { db, qb, uid } = ctx;\n\n const { tableName } = db.metadata.get(uid);\n\n // The orderBy is cloned to avoid unwanted mutations of the original object\n const orderBy = _.cloneDeep<OrderByValue[]>(qb.state.orderBy);\n\n // Separate column-based entries from raw-expression entries (e.g. status)\n const columnOrderBy = orderBy.filter((ob): ob is OrderByColumnValue => 'column' in ob);\n const rawExpressionOrderBy = orderBy.filter((ob): ob is OrderByRawValue => 'rawExpression' in ob);\n\n // 0. Init a new Knex query instance (referenced as resultQuery) using the DB connection\n // The connection reuse the original table name (aliased if needed)\n const resultQueryAlias = qb.getAlias();\n const aliasedTableName = qb.mustUseAlias() ? alias(resultQueryAlias, tableName) : tableName;\n\n const resultQuery = db.getConnection(aliasedTableName);\n\n // 1. Clone the original query to create the sub-query (referenced as baseQuery) and avoid any mutation on the initial object\n const baseQuery = originalQuery.clone();\n const baseQueryAlias = qb.getAlias();\n\n // Clear unwanted statements from the sub-query 'baseQuery'\n // Note: `first()` is cleared through the combination of `baseQuery.clear('limit')` and calling `baseQuery.select(...)` again\n // Note: Those statements will be re-applied when duplicates are removed from the final selection\n baseQuery\n // Columns selection\n .clear('select')\n // Pagination and sorting\n .clear('order')\n .clear('limit')\n .clear('offset');\n\n // Override the initial select and return only the columns needed for the partitioning.\n // Only column-based orderBy entries are included here; raw expressions are applied later.\n baseQuery.select(\n // Always select the row id for future manipulation\n prefix(qb.alias, 'id'),\n // Select every column used in an order by clause, but alias it for future reference\n // i.e. if t2.name is present in an order by clause:\n // Then, \"t2.name\" will become \"t2.name as __strapi_order_by__t2_name\"\n ...columnOrderBy.map((orderByClause) =>\n alias(getStrapiOrderColumnAlias(orderByClause.column), orderByClause.column)\n )\n );\n\n // 2. Create a sub-query callback to extract and sort the partitions using row number\n const partitionedQueryAlias = qb.getAlias();\n\n const selectRowsAsNumberedPartitions = (partitionedQuery: knex.Knex.QueryBuilder) => {\n // Transform order by clause to their alias to reference them from baseQuery\n const prefixedOrderBy = columnOrderBy.map((orderByClause) => ({\n column: prefix(baseQueryAlias, getStrapiOrderColumnAlias(orderByClause.column)),\n order: orderByClause.order,\n }));\n\n // partitionedQuery select must contain every column used for sorting\n const orderByColumns = prefixedOrderBy.map<string>(_.prop('column'));\n\n partitionedQuery\n .select(\n // Always select baseQuery.id\n prefix(baseQueryAlias, 'id'),\n // Sort columns\n ...orderByColumns\n )\n // The row number is used to assign an index to every row in every partition\n .rowNumber(COL_STRAPI_ROW_NUMBER, (subQuery) => {\n for (const orderByClause of prefixedOrderBy) {\n subQuery.orderBy(orderByClause.column, orderByClause.order, 'last');\n }\n\n // And each partition/group is created based on baseQuery.id\n subQuery.partitionBy(`${baseQueryAlias}.id`);\n })\n .from(baseQuery.as(baseQueryAlias))\n .as(partitionedQueryAlias);\n };\n\n // 3. Create the final resultQuery query, that select and sort the wanted data using T\n\n // Filter to string-only select items before diffing (Knex.Raw items are passed through as-is)\n const stringSelect = qb.state.select.filter((s): s is string => typeof s === 'string');\n const originalSelect = _.difference(\n stringSelect,\n // Remove column-based order by columns from the initial select (raw expressions are not in select)\n columnOrderBy.map(_.prop('column'))\n )\n // Alias everything in resultQuery\n .map((col) => `${resultQueryAlias}.${col}`);\n\n resultQuery\n .select(originalSelect)\n // Join T to resultQuery to access sorted data\n // Notes:\n // - Only select the first row for each partition\n // - Since we're applying the \"where\" statement directly on baseQuery (and not on resultQuery), we're using an inner join to avoid unwanted rows\n .innerJoin(selectRowsAsNumberedPartitions, function () {\n this\n // Only select rows that are returned by T\n .on(`${partitionedQueryAlias}.id`, `${resultQueryAlias}.id`)\n // By only selecting the rows number equal to 1, we make sure we don't have duplicate, and that\n // we're selecting rows in the correct order amongst the groups created by the \"partition by\"\n .andOnVal(`${partitionedQueryAlias}.${COL_STRAPI_ROW_NUMBER}`, '=', 1);\n });\n\n // Re-apply pagination params\n\n if (qb.state.limit) {\n resultQuery.limit(qb.state.limit);\n }\n\n if (qb.state.offset) {\n resultQuery.offset(qb.state.offset);\n }\n\n if (qb.state.first) {\n resultQuery.first();\n }\n\n // Re-apply the sort using T values (column-based), then append raw expression sorts.\n // Cast to any[] because Knex's TS types don't accept Knex.Raw in the column position,\n // even though Knex supports it at runtime.\n resultQuery.orderBy([\n // Transform column-based \"order by\" clause to their T alias and prefix them with T alias\n ...columnOrderBy.map((orderByClause) => ({\n column: prefix(partitionedQueryAlias, getStrapiOrderColumnAlias(orderByClause.column)),\n order: orderByClause.order,\n })),\n // Rebuild raw expression entries with the correct outer alias (resultQueryAlias)\n ...rawExpressionOrderBy.map((entry) => ({\n column: buildStatusSortExpression(db, tableName, resultQueryAlias, entry.isI18n),\n order: entry.order,\n })),\n // Add T.id to the order by clause to get consistent results in case several rows have the exact same order\n { column: `${partitionedQueryAlias}.id`, order: 'asc' },\n ] as any);\n\n return resultQuery;\n};\n\n// Utils\nconst alias = _.curry((alias: string, value: string) => `${value} as ${alias}`);\nconst prefix = _.curry((prefix: string, value: string) => `${prefix}.${value}`);\n"],"names":["COL_STRAPI_ROW_NUMBER","COL_STRAPI_ORDER_BY_PREFIX","buildStatusSortExpression","db","tableName","tableAlias","isI18n","localeCondition","connection","raw","toKnexOrderByDescriptor","rootTableAlias","entry","column","order","processOrderBy","orderBy","ctx","uid","qb","alias","meta","metadata","get","attributes","publishedAt","documentId","Error","rawExpression","undefined","attribute","columnName","toColumnName","aliasColumn","Array","isArray","flatMap","value","_","isPlainObject","Object","entries","key","direction","types","type","subAlias","createJoin","attributeName","target","getStrapiOrderColumnAlias","trimmedColumnName","replaceAll","wrapWithDeepSort","originalQuery","cloneDeep","state","columnOrderBy","filter","ob","rawExpressionOrderBy","resultQueryAlias","getAlias","aliasedTableName","mustUseAlias","resultQuery","getConnection","baseQuery","clone","baseQueryAlias","clear","select","prefix","map","orderByClause","partitionedQueryAlias","selectRowsAsNumberedPartitions","partitionedQuery","prefixedOrderBy","orderByColumns","prop","rowNumber","subQuery","partitionBy","from","as","stringSelect","s","originalSelect","difference","col","innerJoin","on","andOnVal","limit","offset","first","curry"],"mappings":";;;;;;;;;;;AAeA,MAAMA,qBAAAA,GAAwB,qBAAA;AAC9B,MAAMC,0BAAAA,GAA6B,mBAAA;AAEnC;;;;;;;;;;UAWaC,yBAAAA,GAA4B,CACvCC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ACzB,MAAAA,EAAgBnC,KAAAA,GAAkB,CAAA,EAAGmC,MAAAA,CAAO,CAAC,EAAEnC,KAAAA,CAAAA,CAAO,CAAA;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../../src/query/helpers/populate/apply.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAyBzC,KAAK,OAAO,GAAG;IACb,EAAE,EAAE,QAAQ,CAAC;IACb,EAAE,EAAE,YAAY,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAoBF,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAopBnC,QAAA,MAAM,aAAa,YAAmB,GAAG,EAAE,YAAY,OAAO,MAAM,EAAE,GAAG,CAAC,OAAO,OAAO,+BA+DvF,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../../src/query/helpers/populate/apply.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAyBzC,KAAK,OAAO,GAAG;IACb,EAAE,EAAE,QAAQ,CAAC;IACb,EAAE,EAAE,YAAY,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAoBF,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAspBnC,QAAA,MAAM,aAAa,YAAmB,GAAG,EAAE,YAAY,OAAO,MAAM,EAAE,GAAG,CAAC,OAAO,OAAO,+BA+DvF,CAAC;AAEF,eAAe,aAAa,CAAC"}