@mikro-orm/core 7.1.0-dev.3 → 7.1.0-dev.30

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 (54) hide show
  1. package/EntityManager.d.ts +44 -11
  2. package/EntityManager.js +139 -31
  3. package/drivers/IDatabaseDriver.d.ts +39 -1
  4. package/entity/BaseEntity.d.ts +68 -1
  5. package/entity/BaseEntity.js +18 -0
  6. package/entity/Collection.d.ts +6 -3
  7. package/entity/Collection.js +15 -4
  8. package/entity/EntityFactory.js +20 -1
  9. package/entity/EntityLoader.d.ts +3 -1
  10. package/entity/EntityLoader.js +39 -16
  11. package/entity/EntityRepository.d.ts +27 -9
  12. package/entity/EntityRepository.js +12 -0
  13. package/entity/Reference.d.ts +42 -1
  14. package/entity/Reference.js +9 -0
  15. package/entity/defineEntity.d.ts +105 -23
  16. package/entity/defineEntity.js +17 -6
  17. package/entity/utils.js +4 -5
  18. package/errors.d.ts +2 -0
  19. package/errors.js +4 -0
  20. package/index.d.ts +2 -2
  21. package/index.js +1 -1
  22. package/metadata/EntitySchema.js +3 -0
  23. package/metadata/MetadataDiscovery.d.ts +12 -0
  24. package/metadata/MetadataDiscovery.js +185 -16
  25. package/metadata/MetadataValidator.d.ts +24 -0
  26. package/metadata/MetadataValidator.js +202 -1
  27. package/metadata/types.d.ts +77 -4
  28. package/naming-strategy/AbstractNamingStrategy.d.ts +1 -1
  29. package/naming-strategy/NamingStrategy.d.ts +1 -1
  30. package/package.json +1 -1
  31. package/platforms/Platform.d.ts +8 -1
  32. package/platforms/Platform.js +40 -4
  33. package/serialization/EntitySerializer.js +2 -1
  34. package/typings.d.ts +176 -18
  35. package/typings.js +22 -5
  36. package/unit-of-work/UnitOfWork.js +3 -0
  37. package/utils/AbstractMigrator.d.ts +20 -5
  38. package/utils/AbstractMigrator.js +263 -28
  39. package/utils/AbstractSchemaGenerator.d.ts +1 -1
  40. package/utils/AbstractSchemaGenerator.js +4 -1
  41. package/utils/Configuration.d.ts +25 -0
  42. package/utils/Configuration.js +1 -0
  43. package/utils/DataloaderUtils.d.ts +10 -1
  44. package/utils/DataloaderUtils.js +78 -0
  45. package/utils/EntityComparator.js +1 -1
  46. package/utils/QueryHelper.d.ts +16 -0
  47. package/utils/QueryHelper.js +15 -0
  48. package/utils/Utils.js +1 -1
  49. package/utils/fs-utils.d.ts +2 -0
  50. package/utils/fs-utils.js +7 -1
  51. package/utils/index.d.ts +1 -0
  52. package/utils/index.js +1 -0
  53. package/utils/partition-utils.d.ts +17 -0
  54. package/utils/partition-utils.js +79 -0
package/utils/index.js CHANGED
@@ -10,3 +10,4 @@ export * from './EntityComparator.js';
10
10
  export * from './RawQueryFragment.js';
11
11
  export * from './env-vars.js';
12
12
  export * from './upsert-utils.js';
13
+ export * from './partition-utils.js';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Normalize a partition name for collision detection. Mirrors PostgreSQL identifier
3
+ * resolution: unquoted segments fold to lower case, quoted segments preserve case and
4
+ * un-escape embedded `""`. Returns a canonical `schema.name` form so both schema-qualified
5
+ * and bare names compare consistently (`.name` vs `schema.name` stay distinguishable).
6
+ *
7
+ * `Part_1`, `part_1`, and `"part_1"` all normalize to the same value, catching collisions
8
+ * that would otherwise only surface as runtime PG "relation already exists" errors.
9
+ */
10
+ export declare function normalizePartitionNameForComparison(name: string): string;
11
+ /**
12
+ * Split a comma-list of identifiers, respecting double-quoted identifiers (which may contain
13
+ * commas and use `""` to escape embedded quotes). Returns `null` when the input is not a clean
14
+ * comma-list of identifiers (e.g. contains function calls or literals), so callers treat it
15
+ * as an opaque expression.
16
+ */
17
+ export declare function splitCommaSeparatedIdentifiers(value: string): string[] | null;
@@ -0,0 +1,79 @@
1
+ function normalizeIdentifierSegment(segment) {
2
+ const trimmed = segment.trim();
3
+ if (trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
4
+ return trimmed.slice(1, -1).replaceAll('""', '"');
5
+ }
6
+ return trimmed.toLowerCase();
7
+ }
8
+ /**
9
+ * Normalize a partition name for collision detection. Mirrors PostgreSQL identifier
10
+ * resolution: unquoted segments fold to lower case, quoted segments preserve case and
11
+ * un-escape embedded `""`. Returns a canonical `schema.name` form so both schema-qualified
12
+ * and bare names compare consistently (`.name` vs `schema.name` stay distinguishable).
13
+ *
14
+ * `Part_1`, `part_1`, and `"part_1"` all normalize to the same value, catching collisions
15
+ * that would otherwise only surface as runtime PG "relation already exists" errors.
16
+ */
17
+ export function normalizePartitionNameForComparison(name) {
18
+ const trimmed = name.trim();
19
+ let depth = 0;
20
+ for (let i = 0; i < trimmed.length; i++) {
21
+ const ch = trimmed[i];
22
+ if (ch === '"') {
23
+ if (trimmed[i + 1] === '"') {
24
+ i++;
25
+ continue;
26
+ }
27
+ depth = depth === 0 ? 1 : 0;
28
+ continue;
29
+ }
30
+ if (ch === '.' && depth === 0) {
31
+ return `${normalizeIdentifierSegment(trimmed.slice(0, i))}.${normalizeIdentifierSegment(trimmed.slice(i + 1))}`;
32
+ }
33
+ }
34
+ return `.${normalizeIdentifierSegment(trimmed)}`;
35
+ }
36
+ /**
37
+ * Split a comma-list of identifiers, respecting double-quoted identifiers (which may contain
38
+ * commas and use `""` to escape embedded quotes). Returns `null` when the input is not a clean
39
+ * comma-list of identifiers (e.g. contains function calls or literals), so callers treat it
40
+ * as an opaque expression.
41
+ */
42
+ export function splitCommaSeparatedIdentifiers(value) {
43
+ const segments = [];
44
+ let buffer = '';
45
+ let inQuote = false;
46
+ for (let i = 0; i < value.length; i++) {
47
+ const ch = value[i];
48
+ if (ch === '"') {
49
+ if (inQuote && value[i + 1] === '"') {
50
+ buffer += '""';
51
+ i++;
52
+ continue;
53
+ }
54
+ inQuote = !inQuote;
55
+ buffer += ch;
56
+ continue;
57
+ }
58
+ if (!inQuote) {
59
+ if (ch === ',') {
60
+ segments.push(buffer);
61
+ buffer = '';
62
+ continue;
63
+ }
64
+ if (!/[\w.\s]/.test(ch)) {
65
+ return null;
66
+ }
67
+ }
68
+ buffer += ch;
69
+ }
70
+ if (inQuote) {
71
+ return null;
72
+ }
73
+ segments.push(buffer);
74
+ const trimmed = segments.map(s => s.trim());
75
+ if (trimmed.some(s => s === '')) {
76
+ return null;
77
+ }
78
+ return trimmed;
79
+ }