arkormx 2.0.0-next.4 → 2.0.0-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +73 -18
- package/dist/index.cjs +113 -22
- package/dist/index.d.cts +28 -3
- package/dist/index.d.mts +28 -3
- package/dist/index.mjs +113 -24
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
4
|
import { dirname, extname, join, resolve } from "node:path";
|
|
4
5
|
import { spawnSync } from "node:child_process";
|
|
5
6
|
import { str } from "@h3ravel/support";
|
|
6
|
-
import { createHash } from "node:crypto";
|
|
7
7
|
import path, { dirname as dirname$1, extname as extname$1, join as join$1, relative } from "path";
|
|
8
8
|
import { copyFileSync, existsSync as existsSync$1, mkdirSync as mkdirSync$1, readFileSync as readFileSync$1, readdirSync as readdirSync$1, rmSync as rmSync$1, writeFileSync as writeFileSync$1 } from "fs";
|
|
9
9
|
import { AsyncLocalStorage } from "async_hooks";
|
|
@@ -55,6 +55,23 @@ var ArkormException = class extends Error {
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/helpers/PrimaryKeyGenerationPlanner.ts
|
|
60
|
+
var PrimaryKeyGenerationPlanner = class {
|
|
61
|
+
static plan(column) {
|
|
62
|
+
if (!column.primary || column.default !== void 0) return void 0;
|
|
63
|
+
if (column.type === "uuid" || column.type === "string") return {
|
|
64
|
+
strategy: "uuid",
|
|
65
|
+
prismaDefault: "@default(uuid())",
|
|
66
|
+
databaseDefault: column.type === "uuid" ? "gen_random_uuid()" : "gen_random_uuid()::text",
|
|
67
|
+
runtimeFactory: "uuid"
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
static generate(generation) {
|
|
71
|
+
if (generation?.runtimeFactory === "uuid") return randomUUID();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
58
75
|
//#endregion
|
|
59
76
|
//#region src/database/ForeignKeyBuilder.ts
|
|
60
77
|
/**
|
|
@@ -248,6 +265,7 @@ var TableBuilder = class {
|
|
|
248
265
|
column.primary = true;
|
|
249
266
|
if (typeof config.autoIncrement === "boolean") column.autoIncrement = config.autoIncrement;
|
|
250
267
|
if (Object.prototype.hasOwnProperty.call(config, "default")) column.default = config.default;
|
|
268
|
+
column.primaryKeyGeneration = PrimaryKeyGenerationPlanner.plan(column);
|
|
251
269
|
return this;
|
|
252
270
|
}
|
|
253
271
|
/**
|
|
@@ -611,8 +629,11 @@ var TableBuilder = class {
|
|
|
611
629
|
autoIncrement: options.autoIncrement,
|
|
612
630
|
after: options.after,
|
|
613
631
|
default: options.default,
|
|
614
|
-
updatedAt: options.updatedAt
|
|
632
|
+
updatedAt: options.updatedAt,
|
|
633
|
+
primaryKeyGeneration: options.primaryKeyGeneration
|
|
615
634
|
});
|
|
635
|
+
const column = this.columns[this.columns.length - 1];
|
|
636
|
+
column.primaryKeyGeneration = PrimaryKeyGenerationPlanner.plan(column);
|
|
616
637
|
this.latestColumnName = name;
|
|
617
638
|
return this;
|
|
618
639
|
}
|
|
@@ -867,7 +888,7 @@ const buildFieldLine = (column) => {
|
|
|
867
888
|
const primary = column.primary ? " @id" : "";
|
|
868
889
|
const mapped = typeof column.map === "string" && column.map.trim().length > 0 ? ` @map("${column.map.replace(/"/g, "\\\"")}")` : "";
|
|
869
890
|
const updatedAt = column.updatedAt ? " @updatedAt" : "";
|
|
870
|
-
const defaultValue = column.type === "enum" ? formatEnumDefaultValue(column.default) :
|
|
891
|
+
const defaultValue = column.type === "enum" ? formatEnumDefaultValue(column.default) : column.primaryKeyGeneration?.prismaDefault ?? formatDefaultValue(column.default);
|
|
871
892
|
const defaultSuffix = defaultValue ? ` ${defaultValue}` : "";
|
|
872
893
|
return ` ${column.name} ${scalar}${nullable}${primary}${unique}${defaultSuffix}${updatedAt}${mapped}`;
|
|
873
894
|
};
|
|
@@ -1603,7 +1624,20 @@ const normalizePersistedTableMetadata = (table) => {
|
|
|
1603
1624
|
const normalizedValues = normalizePersistedEnumValues(values);
|
|
1604
1625
|
if (normalizedValues.length > 0) all[columnName] = normalizedValues;
|
|
1605
1626
|
return all;
|
|
1606
|
-
}, {})
|
|
1627
|
+
}, {}),
|
|
1628
|
+
primaryKeyGeneration: normalizePersistedPrimaryKeyGeneration(candidate.primaryKeyGeneration)
|
|
1629
|
+
};
|
|
1630
|
+
};
|
|
1631
|
+
const normalizePersistedPrimaryKeyGeneration = (value) => {
|
|
1632
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
1633
|
+
const candidate = value;
|
|
1634
|
+
if (candidate.strategy !== "uuid" || typeof candidate.column !== "string" || candidate.column.trim().length === 0) return void 0;
|
|
1635
|
+
return {
|
|
1636
|
+
column: candidate.column,
|
|
1637
|
+
strategy: "uuid",
|
|
1638
|
+
prismaDefault: typeof candidate.prismaDefault === "string" && candidate.prismaDefault.trim().length > 0 ? candidate.prismaDefault : void 0,
|
|
1639
|
+
databaseDefault: typeof candidate.databaseDefault === "string" && candidate.databaseDefault.trim().length > 0 ? candidate.databaseDefault : void 0,
|
|
1640
|
+
runtimeFactory: candidate.runtimeFactory === "uuid" ? "uuid" : void 0
|
|
1607
1641
|
};
|
|
1608
1642
|
};
|
|
1609
1643
|
const normalizePersistedColumnMappingsState = (state) => {
|
|
@@ -1612,7 +1646,7 @@ const normalizePersistedColumnMappingsState = (state) => {
|
|
|
1612
1646
|
tables: Object.entries(state?.tables ?? {}).reduce((all, [tableName, tableMetadata]) => {
|
|
1613
1647
|
if (tableName.trim().length === 0) return all;
|
|
1614
1648
|
const normalized = normalizePersistedTableMetadata(tableMetadata);
|
|
1615
|
-
if (Object.keys(normalized.columns).length > 0 || Object.keys(normalized.enums).length > 0) all[tableName] = normalized;
|
|
1649
|
+
if (Object.keys(normalized.columns).length > 0 || Object.keys(normalized.enums).length > 0 || normalized.primaryKeyGeneration) all[tableName] = normalized;
|
|
1616
1650
|
return all;
|
|
1617
1651
|
}, {})
|
|
1618
1652
|
};
|
|
@@ -1683,12 +1717,10 @@ const getPersistedTableMetadata = (table, options = {}) => {
|
|
|
1683
1717
|
enums: Object.entries(metadata.enums).reduce((all, [columnName, values]) => {
|
|
1684
1718
|
all[columnName] = [...values];
|
|
1685
1719
|
return all;
|
|
1686
|
-
}, {})
|
|
1720
|
+
}, {}),
|
|
1721
|
+
primaryKeyGeneration: metadata.primaryKeyGeneration ? { ...metadata.primaryKeyGeneration } : void 0
|
|
1687
1722
|
};
|
|
1688
1723
|
};
|
|
1689
|
-
const getPersistedEnumMap = (table, options = {}) => {
|
|
1690
|
-
return getPersistedTableMetadata(table, options).enums;
|
|
1691
|
-
};
|
|
1692
1724
|
const applyMappedColumn = (tableColumns, column, features, table) => {
|
|
1693
1725
|
if (typeof column.map === "string" && column.map.trim().length > 0 && column.map !== column.name) {
|
|
1694
1726
|
if (!features.persistedColumnMappings) throw buildPersistedFeatureDisabledError("persistedColumnMappings", table);
|
|
@@ -1712,6 +1744,17 @@ const removePersistedColumnMetadata = (tableMetadata, columnName) => {
|
|
|
1712
1744
|
Object.entries(tableMetadata.columns).forEach(([attribute, mappedColumn]) => {
|
|
1713
1745
|
if (mappedColumn === columnName) delete tableMetadata.columns[attribute];
|
|
1714
1746
|
});
|
|
1747
|
+
if (tableMetadata.primaryKeyGeneration?.column === columnName) delete tableMetadata.primaryKeyGeneration;
|
|
1748
|
+
};
|
|
1749
|
+
const applyPrimaryKeyGeneration = (tableMetadata, column) => {
|
|
1750
|
+
if (!column.primary || !column.primaryKeyGeneration) {
|
|
1751
|
+
if (tableMetadata.primaryKeyGeneration?.column === column.name) delete tableMetadata.primaryKeyGeneration;
|
|
1752
|
+
return;
|
|
1753
|
+
}
|
|
1754
|
+
tableMetadata.primaryKeyGeneration = {
|
|
1755
|
+
column: column.name,
|
|
1756
|
+
...column.primaryKeyGeneration
|
|
1757
|
+
};
|
|
1715
1758
|
};
|
|
1716
1759
|
const applyOperationsToPersistedColumnMappingsState = (state, operations, features = resolvePersistedMetadataFeatures()) => {
|
|
1717
1760
|
const nextTables = Object.entries(state.tables).reduce((all, [table, metadata]) => {
|
|
@@ -1720,7 +1763,8 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
|
|
|
1720
1763
|
enums: Object.entries(metadata.enums).reduce((nextEnums, [columnName, values]) => {
|
|
1721
1764
|
nextEnums[columnName] = [...values];
|
|
1722
1765
|
return nextEnums;
|
|
1723
|
-
}, {})
|
|
1766
|
+
}, {}),
|
|
1767
|
+
primaryKeyGeneration: metadata.primaryKeyGeneration ? { ...metadata.primaryKeyGeneration } : void 0
|
|
1724
1768
|
};
|
|
1725
1769
|
return all;
|
|
1726
1770
|
}, {});
|
|
@@ -1733,8 +1777,9 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
|
|
|
1733
1777
|
operation.columns.forEach((column) => {
|
|
1734
1778
|
applyMappedColumn(tableMetadata.columns, column, features, operation.table);
|
|
1735
1779
|
applyEnumColumn(tableMetadata.enums, column, features, operation.table);
|
|
1780
|
+
applyPrimaryKeyGeneration(tableMetadata, column);
|
|
1736
1781
|
});
|
|
1737
|
-
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0) nextTables[operation.table] = tableMetadata;
|
|
1782
|
+
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0 || tableMetadata.primaryKeyGeneration) nextTables[operation.table] = tableMetadata;
|
|
1738
1783
|
else delete nextTables[operation.table];
|
|
1739
1784
|
return;
|
|
1740
1785
|
}
|
|
@@ -1746,11 +1791,12 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
|
|
|
1746
1791
|
operation.addColumns.forEach((column) => {
|
|
1747
1792
|
applyMappedColumn(tableMetadata.columns, column, features, operation.table);
|
|
1748
1793
|
applyEnumColumn(tableMetadata.enums, column, features, operation.table);
|
|
1794
|
+
applyPrimaryKeyGeneration(tableMetadata, column);
|
|
1749
1795
|
});
|
|
1750
1796
|
operation.dropColumns.forEach((columnName) => {
|
|
1751
1797
|
removePersistedColumnMetadata(tableMetadata, columnName);
|
|
1752
1798
|
});
|
|
1753
|
-
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0) nextTables[operation.table] = tableMetadata;
|
|
1799
|
+
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0 || tableMetadata.primaryKeyGeneration) nextTables[operation.table] = tableMetadata;
|
|
1754
1800
|
else delete nextTables[operation.table];
|
|
1755
1801
|
return;
|
|
1756
1802
|
}
|
|
@@ -2544,21 +2590,30 @@ var CliApp = class {
|
|
|
2544
2590
|
skipped
|
|
2545
2591
|
};
|
|
2546
2592
|
}
|
|
2547
|
-
|
|
2548
|
-
const
|
|
2593
|
+
applyPersistedFieldMetadata(structure) {
|
|
2594
|
+
const persistedMetadata = getPersistedTableMetadata(structure.table, {
|
|
2549
2595
|
features: resolvePersistedMetadataFeatures(this.getConfig("features")),
|
|
2550
2596
|
strict: true
|
|
2551
2597
|
});
|
|
2552
|
-
if (Object.keys(
|
|
2598
|
+
if (Object.keys(persistedMetadata.columns).length === 0 && Object.keys(persistedMetadata.enums).length === 0) return structure;
|
|
2599
|
+
const attributesByColumn = Object.entries(persistedMetadata.columns).reduce((all, [attribute, column]) => {
|
|
2600
|
+
all[column] = attribute;
|
|
2601
|
+
return all;
|
|
2602
|
+
}, {});
|
|
2553
2603
|
return {
|
|
2554
2604
|
...structure,
|
|
2555
2605
|
fields: structure.fields.map((field) => {
|
|
2556
|
-
const
|
|
2557
|
-
|
|
2606
|
+
const logicalName = attributesByColumn[field.name] ?? field.name;
|
|
2607
|
+
const enumValues = persistedMetadata.enums[logicalName] ?? persistedMetadata.enums[field.name];
|
|
2608
|
+
if (!enumValues || enumValues.length === 0) return {
|
|
2609
|
+
...field,
|
|
2610
|
+
name: logicalName
|
|
2611
|
+
};
|
|
2558
2612
|
const enumType = getPersistedEnumTsType(enumValues);
|
|
2559
2613
|
const isArray = /^Array<.+>$/.test(field.type);
|
|
2560
2614
|
return {
|
|
2561
2615
|
...field,
|
|
2616
|
+
name: logicalName,
|
|
2562
2617
|
type: isArray ? `Array<${enumType}>` : enumType
|
|
2563
2618
|
};
|
|
2564
2619
|
})
|
|
@@ -2723,7 +2778,7 @@ var CliApp = class {
|
|
|
2723
2778
|
}, /* @__PURE__ */ new Map());
|
|
2724
2779
|
const discovered = await adapter.introspectModels({ tables: [...new Set([...sources.values()].map((source) => source.table))] });
|
|
2725
2780
|
const structuresByTable = new Map(discovered.map((model) => {
|
|
2726
|
-
const enriched = this.
|
|
2781
|
+
const enriched = this.applyPersistedFieldMetadata(model);
|
|
2727
2782
|
return [enriched.table, enriched];
|
|
2728
2783
|
}));
|
|
2729
2784
|
const result = this.syncModelFiles(modelFiles, (filePath) => {
|
package/dist/index.cjs
CHANGED
|
@@ -164,6 +164,7 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
164
164
|
return "timestamptz";
|
|
165
165
|
}
|
|
166
166
|
resolveSchemaColumnDefault(column) {
|
|
167
|
+
if (column.primaryKeyGeneration?.databaseDefault) return column.primaryKeyGeneration.databaseDefault;
|
|
167
168
|
const value = column.default ?? (column.updatedAt ? "now()" : void 0);
|
|
168
169
|
if (value === void 0) return null;
|
|
169
170
|
if (value === "now()") return "now()";
|
|
@@ -1147,6 +1148,23 @@ const getLatestAppliedMigrations = (state, steps) => {
|
|
|
1147
1148
|
}).slice(0, Math.max(0, steps)).map((entry) => entry.migration);
|
|
1148
1149
|
};
|
|
1149
1150
|
|
|
1151
|
+
//#endregion
|
|
1152
|
+
//#region src/helpers/PrimaryKeyGenerationPlanner.ts
|
|
1153
|
+
var PrimaryKeyGenerationPlanner = class {
|
|
1154
|
+
static plan(column) {
|
|
1155
|
+
if (!column.primary || column.default !== void 0) return void 0;
|
|
1156
|
+
if (column.type === "uuid" || column.type === "string") return {
|
|
1157
|
+
strategy: "uuid",
|
|
1158
|
+
prismaDefault: "@default(uuid())",
|
|
1159
|
+
databaseDefault: column.type === "uuid" ? "gen_random_uuid()" : "gen_random_uuid()::text",
|
|
1160
|
+
runtimeFactory: "uuid"
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
static generate(generation) {
|
|
1164
|
+
if (generation?.runtimeFactory === "uuid") return (0, node_crypto.randomUUID)();
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
|
|
1150
1168
|
//#endregion
|
|
1151
1169
|
//#region src/database/ForeignKeyBuilder.ts
|
|
1152
1170
|
/**
|
|
@@ -1340,6 +1358,7 @@ var TableBuilder = class {
|
|
|
1340
1358
|
column.primary = true;
|
|
1341
1359
|
if (typeof config.autoIncrement === "boolean") column.autoIncrement = config.autoIncrement;
|
|
1342
1360
|
if (Object.prototype.hasOwnProperty.call(config, "default")) column.default = config.default;
|
|
1361
|
+
column.primaryKeyGeneration = PrimaryKeyGenerationPlanner.plan(column);
|
|
1343
1362
|
return this;
|
|
1344
1363
|
}
|
|
1345
1364
|
/**
|
|
@@ -1703,8 +1722,11 @@ var TableBuilder = class {
|
|
|
1703
1722
|
autoIncrement: options.autoIncrement,
|
|
1704
1723
|
after: options.after,
|
|
1705
1724
|
default: options.default,
|
|
1706
|
-
updatedAt: options.updatedAt
|
|
1725
|
+
updatedAt: options.updatedAt,
|
|
1726
|
+
primaryKeyGeneration: options.primaryKeyGeneration
|
|
1707
1727
|
});
|
|
1728
|
+
const column = this.columns[this.columns.length - 1];
|
|
1729
|
+
column.primaryKeyGeneration = PrimaryKeyGenerationPlanner.plan(column);
|
|
1708
1730
|
this.latestColumnName = name;
|
|
1709
1731
|
return this;
|
|
1710
1732
|
}
|
|
@@ -1959,7 +1981,7 @@ const buildFieldLine = (column) => {
|
|
|
1959
1981
|
const primary = column.primary ? " @id" : "";
|
|
1960
1982
|
const mapped = typeof column.map === "string" && column.map.trim().length > 0 ? ` @map("${column.map.replace(/"/g, "\\\"")}")` : "";
|
|
1961
1983
|
const updatedAt = column.updatedAt ? " @updatedAt" : "";
|
|
1962
|
-
const defaultValue = column.type === "enum" ? formatEnumDefaultValue(column.default) :
|
|
1984
|
+
const defaultValue = column.type === "enum" ? formatEnumDefaultValue(column.default) : column.primaryKeyGeneration?.prismaDefault ?? formatDefaultValue(column.default);
|
|
1963
1985
|
const defaultSuffix = defaultValue ? ` ${defaultValue}` : "";
|
|
1964
1986
|
return ` ${column.name} ${scalar}${nullable}${primary}${unique}${defaultSuffix}${updatedAt}${mapped}`;
|
|
1965
1987
|
};
|
|
@@ -2607,7 +2629,20 @@ const normalizePersistedTableMetadata = (table) => {
|
|
|
2607
2629
|
const normalizedValues = normalizePersistedEnumValues(values);
|
|
2608
2630
|
if (normalizedValues.length > 0) all[columnName] = normalizedValues;
|
|
2609
2631
|
return all;
|
|
2610
|
-
}, {})
|
|
2632
|
+
}, {}),
|
|
2633
|
+
primaryKeyGeneration: normalizePersistedPrimaryKeyGeneration(candidate.primaryKeyGeneration)
|
|
2634
|
+
};
|
|
2635
|
+
};
|
|
2636
|
+
const normalizePersistedPrimaryKeyGeneration = (value) => {
|
|
2637
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
2638
|
+
const candidate = value;
|
|
2639
|
+
if (candidate.strategy !== "uuid" || typeof candidate.column !== "string" || candidate.column.trim().length === 0) return void 0;
|
|
2640
|
+
return {
|
|
2641
|
+
column: candidate.column,
|
|
2642
|
+
strategy: "uuid",
|
|
2643
|
+
prismaDefault: typeof candidate.prismaDefault === "string" && candidate.prismaDefault.trim().length > 0 ? candidate.prismaDefault : void 0,
|
|
2644
|
+
databaseDefault: typeof candidate.databaseDefault === "string" && candidate.databaseDefault.trim().length > 0 ? candidate.databaseDefault : void 0,
|
|
2645
|
+
runtimeFactory: candidate.runtimeFactory === "uuid" ? "uuid" : void 0
|
|
2611
2646
|
};
|
|
2612
2647
|
};
|
|
2613
2648
|
const normalizePersistedColumnMappingsState = (state) => {
|
|
@@ -2616,7 +2651,7 @@ const normalizePersistedColumnMappingsState = (state) => {
|
|
|
2616
2651
|
tables: Object.entries(state?.tables ?? {}).reduce((all, [tableName, tableMetadata]) => {
|
|
2617
2652
|
if (tableName.trim().length === 0) return all;
|
|
2618
2653
|
const normalized = normalizePersistedTableMetadata(tableMetadata);
|
|
2619
|
-
if (Object.keys(normalized.columns).length > 0 || Object.keys(normalized.enums).length > 0) all[tableName] = normalized;
|
|
2654
|
+
if (Object.keys(normalized.columns).length > 0 || Object.keys(normalized.enums).length > 0 || normalized.primaryKeyGeneration) all[tableName] = normalized;
|
|
2620
2655
|
return all;
|
|
2621
2656
|
}, {})
|
|
2622
2657
|
};
|
|
@@ -2687,7 +2722,8 @@ const getPersistedTableMetadata = (table, options = {}) => {
|
|
|
2687
2722
|
enums: Object.entries(metadata.enums).reduce((all, [columnName, values]) => {
|
|
2688
2723
|
all[columnName] = [...values];
|
|
2689
2724
|
return all;
|
|
2690
|
-
}, {})
|
|
2725
|
+
}, {}),
|
|
2726
|
+
primaryKeyGeneration: metadata.primaryKeyGeneration ? { ...metadata.primaryKeyGeneration } : void 0
|
|
2691
2727
|
};
|
|
2692
2728
|
};
|
|
2693
2729
|
const getPersistedColumnMap = (table, options = {}) => {
|
|
@@ -2696,6 +2732,9 @@ const getPersistedColumnMap = (table, options = {}) => {
|
|
|
2696
2732
|
const getPersistedEnumMap = (table, options = {}) => {
|
|
2697
2733
|
return getPersistedTableMetadata(table, options).enums;
|
|
2698
2734
|
};
|
|
2735
|
+
const getPersistedPrimaryKeyGeneration = (table, options = {}) => {
|
|
2736
|
+
return getPersistedTableMetadata(table, options).primaryKeyGeneration;
|
|
2737
|
+
};
|
|
2699
2738
|
const applyMappedColumn = (tableColumns, column, features, table) => {
|
|
2700
2739
|
if (typeof column.map === "string" && column.map.trim().length > 0 && column.map !== column.name) {
|
|
2701
2740
|
if (!features.persistedColumnMappings) throw buildPersistedFeatureDisabledError("persistedColumnMappings", table);
|
|
@@ -2719,6 +2758,17 @@ const removePersistedColumnMetadata = (tableMetadata, columnName) => {
|
|
|
2719
2758
|
Object.entries(tableMetadata.columns).forEach(([attribute, mappedColumn]) => {
|
|
2720
2759
|
if (mappedColumn === columnName) delete tableMetadata.columns[attribute];
|
|
2721
2760
|
});
|
|
2761
|
+
if (tableMetadata.primaryKeyGeneration?.column === columnName) delete tableMetadata.primaryKeyGeneration;
|
|
2762
|
+
};
|
|
2763
|
+
const applyPrimaryKeyGeneration = (tableMetadata, column) => {
|
|
2764
|
+
if (!column.primary || !column.primaryKeyGeneration) {
|
|
2765
|
+
if (tableMetadata.primaryKeyGeneration?.column === column.name) delete tableMetadata.primaryKeyGeneration;
|
|
2766
|
+
return;
|
|
2767
|
+
}
|
|
2768
|
+
tableMetadata.primaryKeyGeneration = {
|
|
2769
|
+
column: column.name,
|
|
2770
|
+
...column.primaryKeyGeneration
|
|
2771
|
+
};
|
|
2722
2772
|
};
|
|
2723
2773
|
const applyOperationsToPersistedColumnMappingsState = (state, operations, features = resolvePersistedMetadataFeatures()) => {
|
|
2724
2774
|
const nextTables = Object.entries(state.tables).reduce((all, [table, metadata]) => {
|
|
@@ -2727,7 +2777,8 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
|
|
|
2727
2777
|
enums: Object.entries(metadata.enums).reduce((nextEnums, [columnName, values]) => {
|
|
2728
2778
|
nextEnums[columnName] = [...values];
|
|
2729
2779
|
return nextEnums;
|
|
2730
|
-
}, {})
|
|
2780
|
+
}, {}),
|
|
2781
|
+
primaryKeyGeneration: metadata.primaryKeyGeneration ? { ...metadata.primaryKeyGeneration } : void 0
|
|
2731
2782
|
};
|
|
2732
2783
|
return all;
|
|
2733
2784
|
}, {});
|
|
@@ -2740,8 +2791,9 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
|
|
|
2740
2791
|
operation.columns.forEach((column) => {
|
|
2741
2792
|
applyMappedColumn(tableMetadata.columns, column, features, operation.table);
|
|
2742
2793
|
applyEnumColumn(tableMetadata.enums, column, features, operation.table);
|
|
2794
|
+
applyPrimaryKeyGeneration(tableMetadata, column);
|
|
2743
2795
|
});
|
|
2744
|
-
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0) nextTables[operation.table] = tableMetadata;
|
|
2796
|
+
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0 || tableMetadata.primaryKeyGeneration) nextTables[operation.table] = tableMetadata;
|
|
2745
2797
|
else delete nextTables[operation.table];
|
|
2746
2798
|
return;
|
|
2747
2799
|
}
|
|
@@ -2753,11 +2805,12 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
|
|
|
2753
2805
|
operation.addColumns.forEach((column) => {
|
|
2754
2806
|
applyMappedColumn(tableMetadata.columns, column, features, operation.table);
|
|
2755
2807
|
applyEnumColumn(tableMetadata.enums, column, features, operation.table);
|
|
2808
|
+
applyPrimaryKeyGeneration(tableMetadata, column);
|
|
2756
2809
|
});
|
|
2757
2810
|
operation.dropColumns.forEach((columnName) => {
|
|
2758
2811
|
removePersistedColumnMetadata(tableMetadata, columnName);
|
|
2759
2812
|
});
|
|
2760
|
-
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0) nextTables[operation.table] = tableMetadata;
|
|
2813
|
+
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0 || tableMetadata.primaryKeyGeneration) nextTables[operation.table] = tableMetadata;
|
|
2761
2814
|
else delete nextTables[operation.table];
|
|
2762
2815
|
return;
|
|
2763
2816
|
}
|
|
@@ -4193,21 +4246,30 @@ var CliApp = class {
|
|
|
4193
4246
|
skipped
|
|
4194
4247
|
};
|
|
4195
4248
|
}
|
|
4196
|
-
|
|
4197
|
-
const
|
|
4249
|
+
applyPersistedFieldMetadata(structure) {
|
|
4250
|
+
const persistedMetadata = getPersistedTableMetadata(structure.table, {
|
|
4198
4251
|
features: resolvePersistedMetadataFeatures(this.getConfig("features")),
|
|
4199
4252
|
strict: true
|
|
4200
4253
|
});
|
|
4201
|
-
if (Object.keys(
|
|
4254
|
+
if (Object.keys(persistedMetadata.columns).length === 0 && Object.keys(persistedMetadata.enums).length === 0) return structure;
|
|
4255
|
+
const attributesByColumn = Object.entries(persistedMetadata.columns).reduce((all, [attribute, column]) => {
|
|
4256
|
+
all[column] = attribute;
|
|
4257
|
+
return all;
|
|
4258
|
+
}, {});
|
|
4202
4259
|
return {
|
|
4203
4260
|
...structure,
|
|
4204
4261
|
fields: structure.fields.map((field) => {
|
|
4205
|
-
const
|
|
4206
|
-
|
|
4262
|
+
const logicalName = attributesByColumn[field.name] ?? field.name;
|
|
4263
|
+
const enumValues = persistedMetadata.enums[logicalName] ?? persistedMetadata.enums[field.name];
|
|
4264
|
+
if (!enumValues || enumValues.length === 0) return {
|
|
4265
|
+
...field,
|
|
4266
|
+
name: logicalName
|
|
4267
|
+
};
|
|
4207
4268
|
const enumType = getPersistedEnumTsType(enumValues);
|
|
4208
4269
|
const isArray = /^Array<.+>$/.test(field.type);
|
|
4209
4270
|
return {
|
|
4210
4271
|
...field,
|
|
4272
|
+
name: logicalName,
|
|
4211
4273
|
type: isArray ? `Array<${enumType}>` : enumType
|
|
4212
4274
|
};
|
|
4213
4275
|
})
|
|
@@ -4372,7 +4434,7 @@ var CliApp = class {
|
|
|
4372
4434
|
}, /* @__PURE__ */ new Map());
|
|
4373
4435
|
const discovered = await adapter.introspectModels({ tables: [...new Set([...sources.values()].map((source) => source.table))] });
|
|
4374
4436
|
const structuresByTable = new Map(discovered.map((model) => {
|
|
4375
|
-
const enriched = this.
|
|
4437
|
+
const enriched = this.applyPersistedFieldMetadata(model);
|
|
4376
4438
|
return [enriched.table, enriched];
|
|
4377
4439
|
}));
|
|
4378
4440
|
const result = this.syncModelFiles(modelFiles, (filePath) => {
|
|
@@ -7657,7 +7719,8 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7657
7719
|
* @returns
|
|
7658
7720
|
*/
|
|
7659
7721
|
async create(data) {
|
|
7660
|
-
const
|
|
7722
|
+
const [payload] = this.normalizeInsertPayloads(data);
|
|
7723
|
+
const created = await this.executeInsertRow(payload);
|
|
7661
7724
|
return this.model.hydrate(created);
|
|
7662
7725
|
}
|
|
7663
7726
|
/**
|
|
@@ -7668,7 +7731,8 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7668
7731
|
*/
|
|
7669
7732
|
async createMany(values) {
|
|
7670
7733
|
if (values.length === 0) return [];
|
|
7671
|
-
|
|
7734
|
+
const payloads = this.normalizeInsertPayloads(values);
|
|
7735
|
+
return await Promise.all(payloads.map(async (value) => await this.create(value)));
|
|
7672
7736
|
}
|
|
7673
7737
|
/**
|
|
7674
7738
|
* Insert one or more records.
|
|
@@ -7932,8 +7996,17 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7932
7996
|
return !await this.exists();
|
|
7933
7997
|
}
|
|
7934
7998
|
normalizeInsertPayloads(values) {
|
|
7935
|
-
|
|
7936
|
-
|
|
7999
|
+
const payloads = Array.isArray(values) ? values : [values];
|
|
8000
|
+
const metadata = this.model.getModelMetadata();
|
|
8001
|
+
return payloads.map((payload) => {
|
|
8002
|
+
const nextPayload = { ...payload };
|
|
8003
|
+
const primaryKeyValue = nextPayload[metadata.primaryKey];
|
|
8004
|
+
if (primaryKeyValue !== void 0 && primaryKeyValue !== null) return nextPayload;
|
|
8005
|
+
const generated = PrimaryKeyGenerationPlanner.generate(metadata.primaryKeyGeneration);
|
|
8006
|
+
if (generated === void 0) return nextPayload;
|
|
8007
|
+
nextPayload[metadata.primaryKey] = generated;
|
|
8008
|
+
return nextPayload;
|
|
8009
|
+
});
|
|
7937
8010
|
}
|
|
7938
8011
|
resolveAffectedCount(result, fallback) {
|
|
7939
8012
|
if (typeof result === "number") return result;
|
|
@@ -8176,6 +8249,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
8176
8249
|
modelName: this.model.name,
|
|
8177
8250
|
table: metadata.table,
|
|
8178
8251
|
primaryKey: metadata.primaryKey,
|
|
8252
|
+
primaryKeyGeneration: metadata.primaryKeyGeneration,
|
|
8179
8253
|
columns: metadata.columns,
|
|
8180
8254
|
softDelete: metadata.softDelete
|
|
8181
8255
|
};
|
|
@@ -8988,10 +9062,10 @@ var Model = class Model {
|
|
|
8988
9062
|
const adapter = this.getAdapter();
|
|
8989
9063
|
const shouldStrictlyValidatePersistedMappings = Boolean(adapter) && !(adapter instanceof PrismaDatabaseAdapter);
|
|
8990
9064
|
return {
|
|
8991
|
-
...
|
|
9065
|
+
...getPersistedTableMetadata(this.getTable(), {
|
|
8992
9066
|
features: resolvePersistedMetadataFeatures(getUserConfig("features")),
|
|
8993
9067
|
strict: shouldStrictlyValidatePersistedMappings
|
|
8994
|
-
}),
|
|
9068
|
+
}).columns,
|
|
8995
9069
|
...this.columns
|
|
8996
9070
|
};
|
|
8997
9071
|
}
|
|
@@ -8999,11 +9073,26 @@ var Model = class Model {
|
|
|
8999
9073
|
return this.getColumnMap()[attribute] ?? attribute;
|
|
9000
9074
|
}
|
|
9001
9075
|
static getModelMetadata() {
|
|
9076
|
+
const adapter = this.getAdapter();
|
|
9077
|
+
const shouldStrictlyValidatePersistedMappings = Boolean(adapter) && !(adapter instanceof PrismaDatabaseAdapter);
|
|
9078
|
+
const persistedMetadata = getPersistedTableMetadata(this.getTable(), {
|
|
9079
|
+
features: resolvePersistedMetadataFeatures(getUserConfig("features")),
|
|
9080
|
+
strict: shouldStrictlyValidatePersistedMappings
|
|
9081
|
+
});
|
|
9002
9082
|
return {
|
|
9003
9083
|
table: this.getTable(),
|
|
9004
9084
|
primaryKey: this.getPrimaryKey(),
|
|
9005
|
-
columns:
|
|
9006
|
-
|
|
9085
|
+
columns: {
|
|
9086
|
+
...persistedMetadata.columns,
|
|
9087
|
+
...this.columns
|
|
9088
|
+
},
|
|
9089
|
+
softDelete: this.getSoftDeleteConfig(),
|
|
9090
|
+
primaryKeyGeneration: persistedMetadata.primaryKeyGeneration?.column === this.getPrimaryKey() ? {
|
|
9091
|
+
strategy: persistedMetadata.primaryKeyGeneration.strategy,
|
|
9092
|
+
prismaDefault: persistedMetadata.primaryKeyGeneration.prismaDefault,
|
|
9093
|
+
databaseDefault: persistedMetadata.primaryKeyGeneration.databaseDefault,
|
|
9094
|
+
runtimeFactory: persistedMetadata.primaryKeyGeneration.runtimeFactory
|
|
9095
|
+
} : void 0
|
|
9007
9096
|
};
|
|
9008
9097
|
}
|
|
9009
9098
|
static getRelationMetadata(name) {
|
|
@@ -10034,6 +10123,7 @@ exports.PRISMA_ENUM_MEMBER_REGEX = PRISMA_ENUM_MEMBER_REGEX;
|
|
|
10034
10123
|
exports.PRISMA_ENUM_REGEX = PRISMA_ENUM_REGEX;
|
|
10035
10124
|
exports.PRISMA_MODEL_REGEX = PRISMA_MODEL_REGEX;
|
|
10036
10125
|
exports.Paginator = Paginator;
|
|
10126
|
+
exports.PrimaryKeyGenerationPlanner = PrimaryKeyGenerationPlanner;
|
|
10037
10127
|
exports.PrismaDatabaseAdapter = PrismaDatabaseAdapter;
|
|
10038
10128
|
exports.QueryBuilder = QueryBuilder;
|
|
10039
10129
|
exports.QueryConstraintException = QueryConstraintException;
|
|
@@ -10103,6 +10193,7 @@ exports.getMigrationPlan = getMigrationPlan;
|
|
|
10103
10193
|
exports.getPersistedColumnMap = getPersistedColumnMap;
|
|
10104
10194
|
exports.getPersistedEnumMap = getPersistedEnumMap;
|
|
10105
10195
|
exports.getPersistedEnumTsType = getPersistedEnumTsType;
|
|
10196
|
+
exports.getPersistedPrimaryKeyGeneration = getPersistedPrimaryKeyGeneration;
|
|
10106
10197
|
exports.getPersistedTableMetadata = getPersistedTableMetadata;
|
|
10107
10198
|
exports.getRuntimeAdapter = getRuntimeAdapter;
|
|
10108
10199
|
exports.getRuntimePaginationCurrentPageResolver = getRuntimePaginationCurrentPageResolver;
|
package/dist/index.d.cts
CHANGED
|
@@ -5,6 +5,12 @@ import { Command } from "@h3ravel/musket";
|
|
|
5
5
|
|
|
6
6
|
//#region src/types/migrations.d.ts
|
|
7
7
|
type SchemaColumnType = 'id' | 'uuid' | 'enum' | 'string' | 'text' | 'integer' | 'bigInteger' | 'float' | 'boolean' | 'json' | 'date' | 'timestamp';
|
|
8
|
+
interface PrimaryKeyGeneration {
|
|
9
|
+
strategy: 'uuid';
|
|
10
|
+
prismaDefault?: string;
|
|
11
|
+
databaseDefault?: string;
|
|
12
|
+
runtimeFactory?: 'uuid';
|
|
13
|
+
}
|
|
8
14
|
interface SchemaColumn {
|
|
9
15
|
name: string;
|
|
10
16
|
type: SchemaColumnType;
|
|
@@ -18,6 +24,7 @@ interface SchemaColumn {
|
|
|
18
24
|
after?: string;
|
|
19
25
|
default?: unknown;
|
|
20
26
|
updatedAt?: boolean;
|
|
27
|
+
primaryKeyGeneration?: PrimaryKeyGeneration;
|
|
21
28
|
}
|
|
22
29
|
interface SchemaIndex {
|
|
23
30
|
columns: string[];
|
|
@@ -325,6 +332,7 @@ interface ModelMetadata {
|
|
|
325
332
|
primaryKey: string;
|
|
326
333
|
columns: ColumnMap;
|
|
327
334
|
softDelete: SoftDeleteConfig;
|
|
335
|
+
primaryKeyGeneration?: PrimaryKeyGeneration;
|
|
328
336
|
}
|
|
329
337
|
type RelationMetadataType = 'hasOne' | 'hasMany' | 'belongsTo' | 'belongsToMany' | 'hasOneThrough' | 'hasManyThrough' | 'morphOne' | 'morphMany' | 'morphToMany';
|
|
330
338
|
interface BaseRelationMetadata {
|
|
@@ -2628,6 +2636,7 @@ interface QueryTarget<TModel = unknown> {
|
|
|
2628
2636
|
modelName?: string;
|
|
2629
2637
|
table?: string;
|
|
2630
2638
|
primaryKey?: string;
|
|
2639
|
+
primaryKeyGeneration?: PrimaryKeyGeneration;
|
|
2631
2640
|
columns?: Record<string, string>;
|
|
2632
2641
|
softDelete?: SoftDeleteConfig;
|
|
2633
2642
|
alias?: string;
|
|
@@ -3324,13 +3333,13 @@ declare class CliApp {
|
|
|
3324
3333
|
private syncPrismaEnumImports;
|
|
3325
3334
|
private parseModelSyncSource;
|
|
3326
3335
|
private syncModelFiles;
|
|
3327
|
-
private
|
|
3336
|
+
private applyPersistedFieldMetadata;
|
|
3328
3337
|
/**
|
|
3329
3338
|
* Parse Prisma enum definitions from a schema and return their member names.
|
|
3330
3339
|
*
|
|
3331
3340
|
* @param schema The Prisma schema source.
|
|
3332
3341
|
* @returns A map of enum names to their declared member names.
|
|
3333
|
-
|
|
3342
|
+
*/
|
|
3334
3343
|
private parsePrismaEnums;
|
|
3335
3344
|
/**
|
|
3336
3345
|
* Resolve the generated TypeScript declaration type for a Prisma field.
|
|
@@ -4175,6 +4184,10 @@ interface PersistedMetadataFeatures {
|
|
|
4175
4184
|
interface PersistedTableMetadata {
|
|
4176
4185
|
columns: Record<string, string>;
|
|
4177
4186
|
enums: Record<string, string[]>;
|
|
4187
|
+
primaryKeyGeneration?: PersistedPrimaryKeyGeneration;
|
|
4188
|
+
}
|
|
4189
|
+
interface PersistedPrimaryKeyGeneration extends PrimaryKeyGeneration {
|
|
4190
|
+
column: string;
|
|
4178
4191
|
}
|
|
4179
4192
|
interface PersistedColumnMappingsState {
|
|
4180
4193
|
version: 1;
|
|
@@ -4205,6 +4218,12 @@ declare const getPersistedEnumMap: (table: string, options?: {
|
|
|
4205
4218
|
features?: PersistedMetadataFeatures;
|
|
4206
4219
|
strict?: boolean;
|
|
4207
4220
|
}) => Record<string, string[]>;
|
|
4221
|
+
declare const getPersistedPrimaryKeyGeneration: (table: string, options?: {
|
|
4222
|
+
cwd?: string;
|
|
4223
|
+
configuredPath?: string;
|
|
4224
|
+
features?: PersistedMetadataFeatures;
|
|
4225
|
+
strict?: boolean;
|
|
4226
|
+
}) => PersistedPrimaryKeyGeneration | undefined;
|
|
4208
4227
|
declare const applyOperationsToPersistedColumnMappingsState: (state: PersistedColumnMappingsState, operations: SchemaOperation[], features?: PersistedMetadataFeatures) => PersistedColumnMappingsState;
|
|
4209
4228
|
declare const rebuildPersistedColumnMappingsState: (state: AppliedMigrationsState, availableMigrations: [MigrationClass, string][], features?: PersistedMetadataFeatures) => Promise<PersistedColumnMappingsState>;
|
|
4210
4229
|
declare const syncPersistedColumnMappingsFromState: (cwd: string, state: AppliedMigrationsState, availableMigrations: [MigrationClass, string][], features?: PersistedMetadataFeatures) => Promise<void>;
|
|
@@ -4525,6 +4544,12 @@ declare const runMigrationWithPrisma: (migration: Migration | (new () => Migrati
|
|
|
4525
4544
|
operations: SchemaOperation[];
|
|
4526
4545
|
}>;
|
|
4527
4546
|
//#endregion
|
|
4547
|
+
//#region src/helpers/PrimaryKeyGenerationPlanner.d.ts
|
|
4548
|
+
declare class PrimaryKeyGenerationPlanner {
|
|
4549
|
+
static plan(column: Pick<SchemaColumn, 'type' | 'primary' | 'default'>): PrimaryKeyGeneration | undefined;
|
|
4550
|
+
static generate(generation: PrimaryKeyGeneration | undefined): unknown;
|
|
4551
|
+
}
|
|
4552
|
+
//#endregion
|
|
4528
4553
|
//#region src/helpers/runtime-config.d.ts
|
|
4529
4554
|
/**
|
|
4530
4555
|
* Define the ArkORM runtime configuration. This function can be used to provide.
|
|
@@ -4656,4 +4681,4 @@ declare class URLDriver {
|
|
|
4656
4681
|
url(page: number): string;
|
|
4657
4682
|
}
|
|
4658
4683
|
//#endregion
|
|
4659
|
-
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedTableMetadata, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedTableMetadata, getRuntimeAdapter, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
|
4684
|
+
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getRuntimeAdapter, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
package/dist/index.d.mts
CHANGED
|
@@ -5,6 +5,12 @@ import { PrismaClient } from "@prisma/client";
|
|
|
5
5
|
|
|
6
6
|
//#region src/types/migrations.d.ts
|
|
7
7
|
type SchemaColumnType = 'id' | 'uuid' | 'enum' | 'string' | 'text' | 'integer' | 'bigInteger' | 'float' | 'boolean' | 'json' | 'date' | 'timestamp';
|
|
8
|
+
interface PrimaryKeyGeneration {
|
|
9
|
+
strategy: 'uuid';
|
|
10
|
+
prismaDefault?: string;
|
|
11
|
+
databaseDefault?: string;
|
|
12
|
+
runtimeFactory?: 'uuid';
|
|
13
|
+
}
|
|
8
14
|
interface SchemaColumn {
|
|
9
15
|
name: string;
|
|
10
16
|
type: SchemaColumnType;
|
|
@@ -18,6 +24,7 @@ interface SchemaColumn {
|
|
|
18
24
|
after?: string;
|
|
19
25
|
default?: unknown;
|
|
20
26
|
updatedAt?: boolean;
|
|
27
|
+
primaryKeyGeneration?: PrimaryKeyGeneration;
|
|
21
28
|
}
|
|
22
29
|
interface SchemaIndex {
|
|
23
30
|
columns: string[];
|
|
@@ -325,6 +332,7 @@ interface ModelMetadata {
|
|
|
325
332
|
primaryKey: string;
|
|
326
333
|
columns: ColumnMap;
|
|
327
334
|
softDelete: SoftDeleteConfig;
|
|
335
|
+
primaryKeyGeneration?: PrimaryKeyGeneration;
|
|
328
336
|
}
|
|
329
337
|
type RelationMetadataType = 'hasOne' | 'hasMany' | 'belongsTo' | 'belongsToMany' | 'hasOneThrough' | 'hasManyThrough' | 'morphOne' | 'morphMany' | 'morphToMany';
|
|
330
338
|
interface BaseRelationMetadata {
|
|
@@ -2628,6 +2636,7 @@ interface QueryTarget<TModel = unknown> {
|
|
|
2628
2636
|
modelName?: string;
|
|
2629
2637
|
table?: string;
|
|
2630
2638
|
primaryKey?: string;
|
|
2639
|
+
primaryKeyGeneration?: PrimaryKeyGeneration;
|
|
2631
2640
|
columns?: Record<string, string>;
|
|
2632
2641
|
softDelete?: SoftDeleteConfig;
|
|
2633
2642
|
alias?: string;
|
|
@@ -3324,13 +3333,13 @@ declare class CliApp {
|
|
|
3324
3333
|
private syncPrismaEnumImports;
|
|
3325
3334
|
private parseModelSyncSource;
|
|
3326
3335
|
private syncModelFiles;
|
|
3327
|
-
private
|
|
3336
|
+
private applyPersistedFieldMetadata;
|
|
3328
3337
|
/**
|
|
3329
3338
|
* Parse Prisma enum definitions from a schema and return their member names.
|
|
3330
3339
|
*
|
|
3331
3340
|
* @param schema The Prisma schema source.
|
|
3332
3341
|
* @returns A map of enum names to their declared member names.
|
|
3333
|
-
|
|
3342
|
+
*/
|
|
3334
3343
|
private parsePrismaEnums;
|
|
3335
3344
|
/**
|
|
3336
3345
|
* Resolve the generated TypeScript declaration type for a Prisma field.
|
|
@@ -4175,6 +4184,10 @@ interface PersistedMetadataFeatures {
|
|
|
4175
4184
|
interface PersistedTableMetadata {
|
|
4176
4185
|
columns: Record<string, string>;
|
|
4177
4186
|
enums: Record<string, string[]>;
|
|
4187
|
+
primaryKeyGeneration?: PersistedPrimaryKeyGeneration;
|
|
4188
|
+
}
|
|
4189
|
+
interface PersistedPrimaryKeyGeneration extends PrimaryKeyGeneration {
|
|
4190
|
+
column: string;
|
|
4178
4191
|
}
|
|
4179
4192
|
interface PersistedColumnMappingsState {
|
|
4180
4193
|
version: 1;
|
|
@@ -4205,6 +4218,12 @@ declare const getPersistedEnumMap: (table: string, options?: {
|
|
|
4205
4218
|
features?: PersistedMetadataFeatures;
|
|
4206
4219
|
strict?: boolean;
|
|
4207
4220
|
}) => Record<string, string[]>;
|
|
4221
|
+
declare const getPersistedPrimaryKeyGeneration: (table: string, options?: {
|
|
4222
|
+
cwd?: string;
|
|
4223
|
+
configuredPath?: string;
|
|
4224
|
+
features?: PersistedMetadataFeatures;
|
|
4225
|
+
strict?: boolean;
|
|
4226
|
+
}) => PersistedPrimaryKeyGeneration | undefined;
|
|
4208
4227
|
declare const applyOperationsToPersistedColumnMappingsState: (state: PersistedColumnMappingsState, operations: SchemaOperation[], features?: PersistedMetadataFeatures) => PersistedColumnMappingsState;
|
|
4209
4228
|
declare const rebuildPersistedColumnMappingsState: (state: AppliedMigrationsState, availableMigrations: [MigrationClass, string][], features?: PersistedMetadataFeatures) => Promise<PersistedColumnMappingsState>;
|
|
4210
4229
|
declare const syncPersistedColumnMappingsFromState: (cwd: string, state: AppliedMigrationsState, availableMigrations: [MigrationClass, string][], features?: PersistedMetadataFeatures) => Promise<void>;
|
|
@@ -4525,6 +4544,12 @@ declare const runMigrationWithPrisma: (migration: Migration | (new () => Migrati
|
|
|
4525
4544
|
operations: SchemaOperation[];
|
|
4526
4545
|
}>;
|
|
4527
4546
|
//#endregion
|
|
4547
|
+
//#region src/helpers/PrimaryKeyGenerationPlanner.d.ts
|
|
4548
|
+
declare class PrimaryKeyGenerationPlanner {
|
|
4549
|
+
static plan(column: Pick<SchemaColumn, 'type' | 'primary' | 'default'>): PrimaryKeyGeneration | undefined;
|
|
4550
|
+
static generate(generation: PrimaryKeyGeneration | undefined): unknown;
|
|
4551
|
+
}
|
|
4552
|
+
//#endregion
|
|
4528
4553
|
//#region src/helpers/runtime-config.d.ts
|
|
4529
4554
|
/**
|
|
4530
4555
|
* Define the ArkORM runtime configuration. This function can be used to provide.
|
|
@@ -4656,4 +4681,4 @@ declare class URLDriver {
|
|
|
4656
4681
|
url(page: number): string;
|
|
4657
4682
|
}
|
|
4658
4683
|
//#endregion
|
|
4659
|
-
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedTableMetadata, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedTableMetadata, getRuntimeAdapter, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
|
4684
|
+
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getRuntimeAdapter, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { str } from "@h3ravel/support";
|
|
|
3
3
|
import { AsyncLocalStorage } from "async_hooks";
|
|
4
4
|
import { dirname, extname, join, resolve } from "node:path";
|
|
5
5
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
6
|
-
import { createHash } from "node:crypto";
|
|
6
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
7
7
|
import { spawnSync } from "node:child_process";
|
|
8
8
|
import { createJiti } from "@rexxars/jiti";
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
@@ -135,6 +135,7 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
135
135
|
return "timestamptz";
|
|
136
136
|
}
|
|
137
137
|
resolveSchemaColumnDefault(column) {
|
|
138
|
+
if (column.primaryKeyGeneration?.databaseDefault) return column.primaryKeyGeneration.databaseDefault;
|
|
138
139
|
const value = column.default ?? (column.updatedAt ? "now()" : void 0);
|
|
139
140
|
if (value === void 0) return null;
|
|
140
141
|
if (value === "now()") return "now()";
|
|
@@ -1118,6 +1119,23 @@ const getLatestAppliedMigrations = (state, steps) => {
|
|
|
1118
1119
|
}).slice(0, Math.max(0, steps)).map((entry) => entry.migration);
|
|
1119
1120
|
};
|
|
1120
1121
|
|
|
1122
|
+
//#endregion
|
|
1123
|
+
//#region src/helpers/PrimaryKeyGenerationPlanner.ts
|
|
1124
|
+
var PrimaryKeyGenerationPlanner = class {
|
|
1125
|
+
static plan(column) {
|
|
1126
|
+
if (!column.primary || column.default !== void 0) return void 0;
|
|
1127
|
+
if (column.type === "uuid" || column.type === "string") return {
|
|
1128
|
+
strategy: "uuid",
|
|
1129
|
+
prismaDefault: "@default(uuid())",
|
|
1130
|
+
databaseDefault: column.type === "uuid" ? "gen_random_uuid()" : "gen_random_uuid()::text",
|
|
1131
|
+
runtimeFactory: "uuid"
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
static generate(generation) {
|
|
1135
|
+
if (generation?.runtimeFactory === "uuid") return randomUUID();
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1121
1139
|
//#endregion
|
|
1122
1140
|
//#region src/database/ForeignKeyBuilder.ts
|
|
1123
1141
|
/**
|
|
@@ -1311,6 +1329,7 @@ var TableBuilder = class {
|
|
|
1311
1329
|
column.primary = true;
|
|
1312
1330
|
if (typeof config.autoIncrement === "boolean") column.autoIncrement = config.autoIncrement;
|
|
1313
1331
|
if (Object.prototype.hasOwnProperty.call(config, "default")) column.default = config.default;
|
|
1332
|
+
column.primaryKeyGeneration = PrimaryKeyGenerationPlanner.plan(column);
|
|
1314
1333
|
return this;
|
|
1315
1334
|
}
|
|
1316
1335
|
/**
|
|
@@ -1674,8 +1693,11 @@ var TableBuilder = class {
|
|
|
1674
1693
|
autoIncrement: options.autoIncrement,
|
|
1675
1694
|
after: options.after,
|
|
1676
1695
|
default: options.default,
|
|
1677
|
-
updatedAt: options.updatedAt
|
|
1696
|
+
updatedAt: options.updatedAt,
|
|
1697
|
+
primaryKeyGeneration: options.primaryKeyGeneration
|
|
1678
1698
|
});
|
|
1699
|
+
const column = this.columns[this.columns.length - 1];
|
|
1700
|
+
column.primaryKeyGeneration = PrimaryKeyGenerationPlanner.plan(column);
|
|
1679
1701
|
this.latestColumnName = name;
|
|
1680
1702
|
return this;
|
|
1681
1703
|
}
|
|
@@ -1930,7 +1952,7 @@ const buildFieldLine = (column) => {
|
|
|
1930
1952
|
const primary = column.primary ? " @id" : "";
|
|
1931
1953
|
const mapped = typeof column.map === "string" && column.map.trim().length > 0 ? ` @map("${column.map.replace(/"/g, "\\\"")}")` : "";
|
|
1932
1954
|
const updatedAt = column.updatedAt ? " @updatedAt" : "";
|
|
1933
|
-
const defaultValue = column.type === "enum" ? formatEnumDefaultValue(column.default) :
|
|
1955
|
+
const defaultValue = column.type === "enum" ? formatEnumDefaultValue(column.default) : column.primaryKeyGeneration?.prismaDefault ?? formatDefaultValue(column.default);
|
|
1934
1956
|
const defaultSuffix = defaultValue ? ` ${defaultValue}` : "";
|
|
1935
1957
|
return ` ${column.name} ${scalar}${nullable}${primary}${unique}${defaultSuffix}${updatedAt}${mapped}`;
|
|
1936
1958
|
};
|
|
@@ -2578,7 +2600,20 @@ const normalizePersistedTableMetadata = (table) => {
|
|
|
2578
2600
|
const normalizedValues = normalizePersistedEnumValues(values);
|
|
2579
2601
|
if (normalizedValues.length > 0) all[columnName] = normalizedValues;
|
|
2580
2602
|
return all;
|
|
2581
|
-
}, {})
|
|
2603
|
+
}, {}),
|
|
2604
|
+
primaryKeyGeneration: normalizePersistedPrimaryKeyGeneration(candidate.primaryKeyGeneration)
|
|
2605
|
+
};
|
|
2606
|
+
};
|
|
2607
|
+
const normalizePersistedPrimaryKeyGeneration = (value) => {
|
|
2608
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
2609
|
+
const candidate = value;
|
|
2610
|
+
if (candidate.strategy !== "uuid" || typeof candidate.column !== "string" || candidate.column.trim().length === 0) return void 0;
|
|
2611
|
+
return {
|
|
2612
|
+
column: candidate.column,
|
|
2613
|
+
strategy: "uuid",
|
|
2614
|
+
prismaDefault: typeof candidate.prismaDefault === "string" && candidate.prismaDefault.trim().length > 0 ? candidate.prismaDefault : void 0,
|
|
2615
|
+
databaseDefault: typeof candidate.databaseDefault === "string" && candidate.databaseDefault.trim().length > 0 ? candidate.databaseDefault : void 0,
|
|
2616
|
+
runtimeFactory: candidate.runtimeFactory === "uuid" ? "uuid" : void 0
|
|
2582
2617
|
};
|
|
2583
2618
|
};
|
|
2584
2619
|
const normalizePersistedColumnMappingsState = (state) => {
|
|
@@ -2587,7 +2622,7 @@ const normalizePersistedColumnMappingsState = (state) => {
|
|
|
2587
2622
|
tables: Object.entries(state?.tables ?? {}).reduce((all, [tableName, tableMetadata]) => {
|
|
2588
2623
|
if (tableName.trim().length === 0) return all;
|
|
2589
2624
|
const normalized = normalizePersistedTableMetadata(tableMetadata);
|
|
2590
|
-
if (Object.keys(normalized.columns).length > 0 || Object.keys(normalized.enums).length > 0) all[tableName] = normalized;
|
|
2625
|
+
if (Object.keys(normalized.columns).length > 0 || Object.keys(normalized.enums).length > 0 || normalized.primaryKeyGeneration) all[tableName] = normalized;
|
|
2591
2626
|
return all;
|
|
2592
2627
|
}, {})
|
|
2593
2628
|
};
|
|
@@ -2658,7 +2693,8 @@ const getPersistedTableMetadata = (table, options = {}) => {
|
|
|
2658
2693
|
enums: Object.entries(metadata.enums).reduce((all, [columnName, values]) => {
|
|
2659
2694
|
all[columnName] = [...values];
|
|
2660
2695
|
return all;
|
|
2661
|
-
}, {})
|
|
2696
|
+
}, {}),
|
|
2697
|
+
primaryKeyGeneration: metadata.primaryKeyGeneration ? { ...metadata.primaryKeyGeneration } : void 0
|
|
2662
2698
|
};
|
|
2663
2699
|
};
|
|
2664
2700
|
const getPersistedColumnMap = (table, options = {}) => {
|
|
@@ -2667,6 +2703,9 @@ const getPersistedColumnMap = (table, options = {}) => {
|
|
|
2667
2703
|
const getPersistedEnumMap = (table, options = {}) => {
|
|
2668
2704
|
return getPersistedTableMetadata(table, options).enums;
|
|
2669
2705
|
};
|
|
2706
|
+
const getPersistedPrimaryKeyGeneration = (table, options = {}) => {
|
|
2707
|
+
return getPersistedTableMetadata(table, options).primaryKeyGeneration;
|
|
2708
|
+
};
|
|
2670
2709
|
const applyMappedColumn = (tableColumns, column, features, table) => {
|
|
2671
2710
|
if (typeof column.map === "string" && column.map.trim().length > 0 && column.map !== column.name) {
|
|
2672
2711
|
if (!features.persistedColumnMappings) throw buildPersistedFeatureDisabledError("persistedColumnMappings", table);
|
|
@@ -2690,6 +2729,17 @@ const removePersistedColumnMetadata = (tableMetadata, columnName) => {
|
|
|
2690
2729
|
Object.entries(tableMetadata.columns).forEach(([attribute, mappedColumn]) => {
|
|
2691
2730
|
if (mappedColumn === columnName) delete tableMetadata.columns[attribute];
|
|
2692
2731
|
});
|
|
2732
|
+
if (tableMetadata.primaryKeyGeneration?.column === columnName) delete tableMetadata.primaryKeyGeneration;
|
|
2733
|
+
};
|
|
2734
|
+
const applyPrimaryKeyGeneration = (tableMetadata, column) => {
|
|
2735
|
+
if (!column.primary || !column.primaryKeyGeneration) {
|
|
2736
|
+
if (tableMetadata.primaryKeyGeneration?.column === column.name) delete tableMetadata.primaryKeyGeneration;
|
|
2737
|
+
return;
|
|
2738
|
+
}
|
|
2739
|
+
tableMetadata.primaryKeyGeneration = {
|
|
2740
|
+
column: column.name,
|
|
2741
|
+
...column.primaryKeyGeneration
|
|
2742
|
+
};
|
|
2693
2743
|
};
|
|
2694
2744
|
const applyOperationsToPersistedColumnMappingsState = (state, operations, features = resolvePersistedMetadataFeatures()) => {
|
|
2695
2745
|
const nextTables = Object.entries(state.tables).reduce((all, [table, metadata]) => {
|
|
@@ -2698,7 +2748,8 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
|
|
|
2698
2748
|
enums: Object.entries(metadata.enums).reduce((nextEnums, [columnName, values]) => {
|
|
2699
2749
|
nextEnums[columnName] = [...values];
|
|
2700
2750
|
return nextEnums;
|
|
2701
|
-
}, {})
|
|
2751
|
+
}, {}),
|
|
2752
|
+
primaryKeyGeneration: metadata.primaryKeyGeneration ? { ...metadata.primaryKeyGeneration } : void 0
|
|
2702
2753
|
};
|
|
2703
2754
|
return all;
|
|
2704
2755
|
}, {});
|
|
@@ -2711,8 +2762,9 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
|
|
|
2711
2762
|
operation.columns.forEach((column) => {
|
|
2712
2763
|
applyMappedColumn(tableMetadata.columns, column, features, operation.table);
|
|
2713
2764
|
applyEnumColumn(tableMetadata.enums, column, features, operation.table);
|
|
2765
|
+
applyPrimaryKeyGeneration(tableMetadata, column);
|
|
2714
2766
|
});
|
|
2715
|
-
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0) nextTables[operation.table] = tableMetadata;
|
|
2767
|
+
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0 || tableMetadata.primaryKeyGeneration) nextTables[operation.table] = tableMetadata;
|
|
2716
2768
|
else delete nextTables[operation.table];
|
|
2717
2769
|
return;
|
|
2718
2770
|
}
|
|
@@ -2724,11 +2776,12 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
|
|
|
2724
2776
|
operation.addColumns.forEach((column) => {
|
|
2725
2777
|
applyMappedColumn(tableMetadata.columns, column, features, operation.table);
|
|
2726
2778
|
applyEnumColumn(tableMetadata.enums, column, features, operation.table);
|
|
2779
|
+
applyPrimaryKeyGeneration(tableMetadata, column);
|
|
2727
2780
|
});
|
|
2728
2781
|
operation.dropColumns.forEach((columnName) => {
|
|
2729
2782
|
removePersistedColumnMetadata(tableMetadata, columnName);
|
|
2730
2783
|
});
|
|
2731
|
-
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0) nextTables[operation.table] = tableMetadata;
|
|
2784
|
+
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0 || tableMetadata.primaryKeyGeneration) nextTables[operation.table] = tableMetadata;
|
|
2732
2785
|
else delete nextTables[operation.table];
|
|
2733
2786
|
return;
|
|
2734
2787
|
}
|
|
@@ -4164,21 +4217,30 @@ var CliApp = class {
|
|
|
4164
4217
|
skipped
|
|
4165
4218
|
};
|
|
4166
4219
|
}
|
|
4167
|
-
|
|
4168
|
-
const
|
|
4220
|
+
applyPersistedFieldMetadata(structure) {
|
|
4221
|
+
const persistedMetadata = getPersistedTableMetadata(structure.table, {
|
|
4169
4222
|
features: resolvePersistedMetadataFeatures(this.getConfig("features")),
|
|
4170
4223
|
strict: true
|
|
4171
4224
|
});
|
|
4172
|
-
if (Object.keys(
|
|
4225
|
+
if (Object.keys(persistedMetadata.columns).length === 0 && Object.keys(persistedMetadata.enums).length === 0) return structure;
|
|
4226
|
+
const attributesByColumn = Object.entries(persistedMetadata.columns).reduce((all, [attribute, column]) => {
|
|
4227
|
+
all[column] = attribute;
|
|
4228
|
+
return all;
|
|
4229
|
+
}, {});
|
|
4173
4230
|
return {
|
|
4174
4231
|
...structure,
|
|
4175
4232
|
fields: structure.fields.map((field) => {
|
|
4176
|
-
const
|
|
4177
|
-
|
|
4233
|
+
const logicalName = attributesByColumn[field.name] ?? field.name;
|
|
4234
|
+
const enumValues = persistedMetadata.enums[logicalName] ?? persistedMetadata.enums[field.name];
|
|
4235
|
+
if (!enumValues || enumValues.length === 0) return {
|
|
4236
|
+
...field,
|
|
4237
|
+
name: logicalName
|
|
4238
|
+
};
|
|
4178
4239
|
const enumType = getPersistedEnumTsType(enumValues);
|
|
4179
4240
|
const isArray = /^Array<.+>$/.test(field.type);
|
|
4180
4241
|
return {
|
|
4181
4242
|
...field,
|
|
4243
|
+
name: logicalName,
|
|
4182
4244
|
type: isArray ? `Array<${enumType}>` : enumType
|
|
4183
4245
|
};
|
|
4184
4246
|
})
|
|
@@ -4343,7 +4405,7 @@ var CliApp = class {
|
|
|
4343
4405
|
}, /* @__PURE__ */ new Map());
|
|
4344
4406
|
const discovered = await adapter.introspectModels({ tables: [...new Set([...sources.values()].map((source) => source.table))] });
|
|
4345
4407
|
const structuresByTable = new Map(discovered.map((model) => {
|
|
4346
|
-
const enriched = this.
|
|
4408
|
+
const enriched = this.applyPersistedFieldMetadata(model);
|
|
4347
4409
|
return [enriched.table, enriched];
|
|
4348
4410
|
}));
|
|
4349
4411
|
const result = this.syncModelFiles(modelFiles, (filePath) => {
|
|
@@ -7628,7 +7690,8 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7628
7690
|
* @returns
|
|
7629
7691
|
*/
|
|
7630
7692
|
async create(data) {
|
|
7631
|
-
const
|
|
7693
|
+
const [payload] = this.normalizeInsertPayloads(data);
|
|
7694
|
+
const created = await this.executeInsertRow(payload);
|
|
7632
7695
|
return this.model.hydrate(created);
|
|
7633
7696
|
}
|
|
7634
7697
|
/**
|
|
@@ -7639,7 +7702,8 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7639
7702
|
*/
|
|
7640
7703
|
async createMany(values) {
|
|
7641
7704
|
if (values.length === 0) return [];
|
|
7642
|
-
|
|
7705
|
+
const payloads = this.normalizeInsertPayloads(values);
|
|
7706
|
+
return await Promise.all(payloads.map(async (value) => await this.create(value)));
|
|
7643
7707
|
}
|
|
7644
7708
|
/**
|
|
7645
7709
|
* Insert one or more records.
|
|
@@ -7903,8 +7967,17 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7903
7967
|
return !await this.exists();
|
|
7904
7968
|
}
|
|
7905
7969
|
normalizeInsertPayloads(values) {
|
|
7906
|
-
|
|
7907
|
-
|
|
7970
|
+
const payloads = Array.isArray(values) ? values : [values];
|
|
7971
|
+
const metadata = this.model.getModelMetadata();
|
|
7972
|
+
return payloads.map((payload) => {
|
|
7973
|
+
const nextPayload = { ...payload };
|
|
7974
|
+
const primaryKeyValue = nextPayload[metadata.primaryKey];
|
|
7975
|
+
if (primaryKeyValue !== void 0 && primaryKeyValue !== null) return nextPayload;
|
|
7976
|
+
const generated = PrimaryKeyGenerationPlanner.generate(metadata.primaryKeyGeneration);
|
|
7977
|
+
if (generated === void 0) return nextPayload;
|
|
7978
|
+
nextPayload[metadata.primaryKey] = generated;
|
|
7979
|
+
return nextPayload;
|
|
7980
|
+
});
|
|
7908
7981
|
}
|
|
7909
7982
|
resolveAffectedCount(result, fallback) {
|
|
7910
7983
|
if (typeof result === "number") return result;
|
|
@@ -8147,6 +8220,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
8147
8220
|
modelName: this.model.name,
|
|
8148
8221
|
table: metadata.table,
|
|
8149
8222
|
primaryKey: metadata.primaryKey,
|
|
8223
|
+
primaryKeyGeneration: metadata.primaryKeyGeneration,
|
|
8150
8224
|
columns: metadata.columns,
|
|
8151
8225
|
softDelete: metadata.softDelete
|
|
8152
8226
|
};
|
|
@@ -8959,10 +9033,10 @@ var Model = class Model {
|
|
|
8959
9033
|
const adapter = this.getAdapter();
|
|
8960
9034
|
const shouldStrictlyValidatePersistedMappings = Boolean(adapter) && !(adapter instanceof PrismaDatabaseAdapter);
|
|
8961
9035
|
return {
|
|
8962
|
-
...
|
|
9036
|
+
...getPersistedTableMetadata(this.getTable(), {
|
|
8963
9037
|
features: resolvePersistedMetadataFeatures(getUserConfig("features")),
|
|
8964
9038
|
strict: shouldStrictlyValidatePersistedMappings
|
|
8965
|
-
}),
|
|
9039
|
+
}).columns,
|
|
8966
9040
|
...this.columns
|
|
8967
9041
|
};
|
|
8968
9042
|
}
|
|
@@ -8970,11 +9044,26 @@ var Model = class Model {
|
|
|
8970
9044
|
return this.getColumnMap()[attribute] ?? attribute;
|
|
8971
9045
|
}
|
|
8972
9046
|
static getModelMetadata() {
|
|
9047
|
+
const adapter = this.getAdapter();
|
|
9048
|
+
const shouldStrictlyValidatePersistedMappings = Boolean(adapter) && !(adapter instanceof PrismaDatabaseAdapter);
|
|
9049
|
+
const persistedMetadata = getPersistedTableMetadata(this.getTable(), {
|
|
9050
|
+
features: resolvePersistedMetadataFeatures(getUserConfig("features")),
|
|
9051
|
+
strict: shouldStrictlyValidatePersistedMappings
|
|
9052
|
+
});
|
|
8973
9053
|
return {
|
|
8974
9054
|
table: this.getTable(),
|
|
8975
9055
|
primaryKey: this.getPrimaryKey(),
|
|
8976
|
-
columns:
|
|
8977
|
-
|
|
9056
|
+
columns: {
|
|
9057
|
+
...persistedMetadata.columns,
|
|
9058
|
+
...this.columns
|
|
9059
|
+
},
|
|
9060
|
+
softDelete: this.getSoftDeleteConfig(),
|
|
9061
|
+
primaryKeyGeneration: persistedMetadata.primaryKeyGeneration?.column === this.getPrimaryKey() ? {
|
|
9062
|
+
strategy: persistedMetadata.primaryKeyGeneration.strategy,
|
|
9063
|
+
prismaDefault: persistedMetadata.primaryKeyGeneration.prismaDefault,
|
|
9064
|
+
databaseDefault: persistedMetadata.primaryKeyGeneration.databaseDefault,
|
|
9065
|
+
runtimeFactory: persistedMetadata.primaryKeyGeneration.runtimeFactory
|
|
9066
|
+
} : void 0
|
|
8978
9067
|
};
|
|
8979
9068
|
}
|
|
8980
9069
|
static getRelationMetadata(name) {
|
|
@@ -9976,4 +10065,4 @@ var Model = class Model {
|
|
|
9976
10065
|
};
|
|
9977
10066
|
|
|
9978
10067
|
//#endregion
|
|
9979
|
-
export { ArkormCollection, ArkormException, Attribute, CliApp, EnumBuilder, ForeignKeyBuilder, InitCommand, InlineFactory, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationHistoryCommand, MissingDelegateException, Model, ModelFactory, ModelNotFoundException, ModelsSyncCommand, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, Paginator, PrismaDatabaseAdapter, QueryBuilder, QueryConstraintException, RelationResolutionException, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, ScopeNotDefinedException, SeedCommand, Seeder, TableBuilder, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedTableMetadata, getRuntimeAdapter, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
|
10068
|
+
export { ArkormCollection, ArkormException, Attribute, CliApp, EnumBuilder, ForeignKeyBuilder, InitCommand, InlineFactory, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationHistoryCommand, MissingDelegateException, Model, ModelFactory, ModelNotFoundException, ModelsSyncCommand, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, Paginator, PrimaryKeyGenerationPlanner, PrismaDatabaseAdapter, QueryBuilder, QueryConstraintException, RelationResolutionException, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, ScopeNotDefinedException, SeedCommand, Seeder, TableBuilder, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getRuntimeAdapter, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|