arkormx 2.9.2 → 2.9.4
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/README.md +18 -24
- package/dist/cli.mjs +492 -338
- package/dist/{index-BDnvZR_9.d.cts → index-CJ7yJR43.d.mts} +80 -17
- package/dist/{index-CmVlF-_5.d.mts → index-CgzhC61F.d.cts} +80 -17
- package/dist/index.cjs +528 -515
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +529 -516
- package/dist/relationship/index.cjs +1 -1
- package/dist/relationship/index.d.cts +1 -1
- package/dist/relationship/index.d.mts +1 -1
- package/dist/relationship/index.mjs +1 -1
- package/dist/{relationship-DtNgcxxv.mjs → relationship-CmhzOlEo.mjs} +645 -550
- package/dist/{relationship-BVYP9lU2.cjs → relationship-DGOpcWA0.cjs} +645 -550
- package/package.json +6 -2
|
@@ -93,9 +93,9 @@ var RelationResolutionException = class extends ArkormException {
|
|
|
93
93
|
//#endregion
|
|
94
94
|
//#region src/relationship/RelationTableLoader.ts
|
|
95
95
|
/**
|
|
96
|
-
* Utility class responsible for loading data from relation tables, which are used to
|
|
97
|
-
* manage relationships between models in Arkorm.
|
|
98
|
-
*
|
|
96
|
+
* Utility class responsible for loading data from relation tables, which are used to
|
|
97
|
+
* manage relationships between models in Arkorm.
|
|
98
|
+
*
|
|
99
99
|
* @author Legacy (3m1n3nc3)
|
|
100
100
|
* @since 2.0.0-next.0
|
|
101
101
|
*/
|
|
@@ -141,9 +141,9 @@ var RelationTableLoader = class {
|
|
|
141
141
|
//#endregion
|
|
142
142
|
//#region src/relationship/SetBasedEagerLoader.ts
|
|
143
143
|
/**
|
|
144
|
-
* Utility class responsible for performing set-based eager loading of relationships for
|
|
144
|
+
* Utility class responsible for performing set-based eager loading of relationships for
|
|
145
145
|
* a collection of models.
|
|
146
|
-
*
|
|
146
|
+
*
|
|
147
147
|
* @author Legacy (3m1n3nc3)
|
|
148
148
|
* @since 2.0.0-next.2
|
|
149
149
|
*/
|
|
@@ -153,9 +153,9 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
153
153
|
this.relations = relations;
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
|
-
* Performs eager loading of all specified relationships for the set of models.
|
|
157
|
-
*
|
|
158
|
-
* @returns
|
|
156
|
+
* Performs eager loading of all specified relationships for the set of models.
|
|
157
|
+
*
|
|
158
|
+
* @returns
|
|
159
159
|
*/
|
|
160
160
|
async load() {
|
|
161
161
|
if (this.models.length === 0) return;
|
|
@@ -172,9 +172,9 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
172
172
|
await new SetBasedEagerLoader(relatedModels, this.relationTreeToMap(node.children)).load();
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
|
-
* Loads a specific relationship for the set of models based on the relationship name
|
|
175
|
+
* Loads a specific relationship for the set of models based on the relationship name
|
|
176
176
|
* and an optional constraint.
|
|
177
|
-
*
|
|
177
|
+
*
|
|
178
178
|
* @param name The name of the relationship to load.
|
|
179
179
|
* @param constraint An optional constraint to apply to the query.
|
|
180
180
|
* @returns A promise that resolves when the relationship is loaded.
|
|
@@ -215,9 +215,9 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
|
-
* Resolves the relation resolver function for a given relationship name by inspecting
|
|
218
|
+
* Resolves the relation resolver function for a given relationship name by inspecting
|
|
219
219
|
* the first model in the set.
|
|
220
|
-
*
|
|
220
|
+
*
|
|
221
221
|
* @param name The name of the relationship to resolve.
|
|
222
222
|
* @returns The relation resolver function or null if not found.
|
|
223
223
|
*/
|
|
@@ -277,7 +277,7 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
277
277
|
}
|
|
278
278
|
/**
|
|
279
279
|
* Loads a "belongs to" relationship for the set of models.
|
|
280
|
-
*
|
|
280
|
+
*
|
|
281
281
|
* @param name The name of the relationship to load.
|
|
282
282
|
* @param resolver The relation resolver function.
|
|
283
283
|
* @param metadata The metadata for the relationship.
|
|
@@ -309,12 +309,12 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
309
309
|
});
|
|
310
310
|
}
|
|
311
311
|
/**
|
|
312
|
-
* Loads a "has many" relationship for the set of models.
|
|
313
|
-
*
|
|
314
|
-
* @param name
|
|
315
|
-
* @param metadata
|
|
316
|
-
* @param constraint
|
|
317
|
-
* @returns
|
|
312
|
+
* Loads a "has many" relationship for the set of models.
|
|
313
|
+
*
|
|
314
|
+
* @param name
|
|
315
|
+
* @param metadata
|
|
316
|
+
* @param constraint
|
|
317
|
+
* @returns
|
|
318
318
|
*/
|
|
319
319
|
async loadHasMany(name, metadata, constraint) {
|
|
320
320
|
const keys = this.collectUniqueKeys((model) => model.getAttribute(metadata.localKey));
|
|
@@ -343,12 +343,12 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
343
343
|
});
|
|
344
344
|
}
|
|
345
345
|
/**
|
|
346
|
-
* Loads a "belongs to many" relationship for the set of models.
|
|
347
|
-
*
|
|
348
|
-
* @param name
|
|
349
|
-
* @param metadata
|
|
350
|
-
* @param constraint
|
|
351
|
-
* @returns
|
|
346
|
+
* Loads a "belongs to many" relationship for the set of models.
|
|
347
|
+
*
|
|
348
|
+
* @param name
|
|
349
|
+
* @param metadata
|
|
350
|
+
* @param constraint
|
|
351
|
+
* @returns
|
|
352
352
|
*/
|
|
353
353
|
async loadBelongsToMany(name, metadata, constraint) {
|
|
354
354
|
const parentKeys = this.collectUniqueKeys((model) => model.getAttribute(metadata.parentKey));
|
|
@@ -443,12 +443,12 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
443
443
|
}
|
|
444
444
|
/**
|
|
445
445
|
* Loads a "belongs to many" relationship for the set of models.
|
|
446
|
-
*
|
|
447
|
-
* @param name
|
|
448
|
-
* @param resolver
|
|
449
|
-
* @param metadata
|
|
450
|
-
* @param constraint
|
|
451
|
-
* @returns
|
|
446
|
+
*
|
|
447
|
+
* @param name
|
|
448
|
+
* @param resolver
|
|
449
|
+
* @param metadata
|
|
450
|
+
* @param constraint
|
|
451
|
+
* @returns
|
|
452
452
|
*/
|
|
453
453
|
async loadHasOne(name, resolver, metadata, constraint) {
|
|
454
454
|
const keys = this.collectUniqueKeys((model) => model.getAttribute(metadata.localKey));
|
|
@@ -476,11 +476,11 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
476
476
|
}
|
|
477
477
|
/**
|
|
478
478
|
* Loads a "has many through" relationship for the set of models.
|
|
479
|
-
*
|
|
480
|
-
* @param name
|
|
481
|
-
* @param metadata
|
|
482
|
-
* @param constraint
|
|
483
|
-
* @returns
|
|
479
|
+
*
|
|
480
|
+
* @param name
|
|
481
|
+
* @param metadata
|
|
482
|
+
* @param constraint
|
|
483
|
+
* @returns
|
|
484
484
|
*/
|
|
485
485
|
async loadHasManyThrough(name, metadata, constraint) {
|
|
486
486
|
const parentKeys = this.collectUniqueKeys((model) => model.getAttribute(metadata.localKey));
|
|
@@ -534,12 +534,12 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
534
534
|
}
|
|
535
535
|
/**
|
|
536
536
|
* Loads a "has one through" relationship for the set of models.
|
|
537
|
-
*
|
|
538
|
-
* @param name
|
|
539
|
-
* @param resolver
|
|
540
|
-
* @param metadata
|
|
541
|
-
* @param constraint
|
|
542
|
-
* @returns
|
|
537
|
+
*
|
|
538
|
+
* @param name
|
|
539
|
+
* @param resolver
|
|
540
|
+
* @param metadata
|
|
541
|
+
* @param constraint
|
|
542
|
+
* @returns
|
|
543
543
|
*/
|
|
544
544
|
async loadHasOneThrough(name, resolver, metadata, constraint) {
|
|
545
545
|
const parentKeys = this.collectUniqueKeys((model) => model.getAttribute(metadata.localKey));
|
|
@@ -733,19 +733,19 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
733
733
|
}
|
|
734
734
|
/**
|
|
735
735
|
* Applies an eager load constraint to a query if provided.
|
|
736
|
-
*
|
|
737
|
-
* @param query
|
|
738
|
-
* @param constraint
|
|
739
|
-
* @returns
|
|
736
|
+
*
|
|
737
|
+
* @param query
|
|
738
|
+
* @param constraint
|
|
739
|
+
* @returns
|
|
740
740
|
*/
|
|
741
741
|
applyConstraint(query, constraint) {
|
|
742
742
|
if (!constraint) return query;
|
|
743
743
|
return constraint(query) ?? query;
|
|
744
744
|
}
|
|
745
745
|
/**
|
|
746
|
-
* Collects unique values from the set of models based on a resolver function, which
|
|
746
|
+
* Collects unique values from the set of models based on a resolver function, which
|
|
747
747
|
* is used to extract the value from each model.
|
|
748
|
-
*
|
|
748
|
+
*
|
|
749
749
|
* @param resolve A function that takes a model and returns the value to be collected.
|
|
750
750
|
* @returns An array of unique values.
|
|
751
751
|
*/
|
|
@@ -763,9 +763,9 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
763
763
|
return values;
|
|
764
764
|
}
|
|
765
765
|
/**
|
|
766
|
-
* Collects unique values from an array of database rows based on a specified key, which
|
|
766
|
+
* Collects unique values from an array of database rows based on a specified key, which
|
|
767
767
|
* is used to extract the value from each row.
|
|
768
|
-
*
|
|
768
|
+
*
|
|
769
769
|
* @param rows An array of database rows.
|
|
770
770
|
* @param key The key to extract values from each row.
|
|
771
771
|
* @returns An array of unique values.
|
|
@@ -785,16 +785,16 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
785
785
|
}
|
|
786
786
|
/**
|
|
787
787
|
* Loads a "belongs to many" relationship for the set of models.
|
|
788
|
-
*
|
|
789
|
-
* @returns
|
|
788
|
+
*
|
|
789
|
+
* @returns
|
|
790
790
|
*/
|
|
791
791
|
createRelationTableLoader() {
|
|
792
792
|
return new RelationTableLoader(this.resolveAdapter());
|
|
793
793
|
}
|
|
794
794
|
/**
|
|
795
795
|
* Loads a "belongs to many" relationship for the set of models.
|
|
796
|
-
*
|
|
797
|
-
* @returns
|
|
796
|
+
*
|
|
797
|
+
* @returns
|
|
798
798
|
*/
|
|
799
799
|
resolveAdapter() {
|
|
800
800
|
const adapter = this.models[0].constructor.getAdapter?.();
|
|
@@ -802,30 +802,30 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
802
802
|
return adapter;
|
|
803
803
|
}
|
|
804
804
|
/**
|
|
805
|
-
* Reads an attribute value from a model using the getAttribute method, which is used
|
|
805
|
+
* Reads an attribute value from a model using the getAttribute method, which is used
|
|
806
806
|
* to access model attributes in a way that is compatible with Arkorm's internal model structure.
|
|
807
|
-
*
|
|
807
|
+
*
|
|
808
808
|
* @param model The model to read the attribute from.
|
|
809
809
|
* @param key The name of the attribute to read.
|
|
810
|
-
* @returns
|
|
810
|
+
* @returns
|
|
811
811
|
*/
|
|
812
812
|
readModelAttribute(model, key) {
|
|
813
813
|
return model.getAttribute?.(key);
|
|
814
814
|
}
|
|
815
815
|
/**
|
|
816
|
-
* Resolves the default result for a relationship when no related models are found.
|
|
817
|
-
*
|
|
818
|
-
* @param resolver
|
|
819
|
-
* @param model
|
|
820
|
-
* @returns
|
|
816
|
+
* Resolves the default result for a relationship when no related models are found.
|
|
817
|
+
*
|
|
818
|
+
* @param resolver
|
|
819
|
+
* @param model
|
|
820
|
+
* @returns
|
|
821
821
|
*/
|
|
822
822
|
resolveSingleDefault(resolver, model) {
|
|
823
823
|
return resolver.call(model).resolveDefaultResult?.() ?? null;
|
|
824
824
|
}
|
|
825
825
|
/**
|
|
826
|
-
* Generates a unique lookup key for a given value, which is used to store and retrieve
|
|
826
|
+
* Generates a unique lookup key for a given value, which is used to store and retrieve
|
|
827
827
|
* values in maps during the eager loading process.
|
|
828
|
-
*
|
|
828
|
+
*
|
|
829
829
|
* @param value The value to generate a lookup key for.
|
|
830
830
|
* @returns A unique string representing the value.
|
|
831
831
|
*/
|
|
@@ -871,10 +871,10 @@ var RuntimeModuleLoader = class {
|
|
|
871
871
|
*
|
|
872
872
|
* Each returned entry carries either the loaded module or the last error,
|
|
873
873
|
* so callers can surface genuine failures instead of silently dropping them.
|
|
874
|
-
*
|
|
875
|
-
* @param filePaths
|
|
876
|
-
* @param useDefault
|
|
877
|
-
* @returns
|
|
874
|
+
*
|
|
875
|
+
* @param filePaths
|
|
876
|
+
* @param useDefault
|
|
877
|
+
* @returns
|
|
878
878
|
*/
|
|
879
879
|
static async loadAll(filePaths, useDefault = false) {
|
|
880
880
|
const jiti$1 = (0, jiti.createJiti)(`${(0, node_url.pathToFileURL)((0, node_path.resolve)(".")).href}/`, {
|
|
@@ -1040,9 +1040,9 @@ const getLatestAppliedMigrations = (state, steps) => {
|
|
|
1040
1040
|
//#endregion
|
|
1041
1041
|
//#region src/database/ForeignKeyBuilder.ts
|
|
1042
1042
|
/**
|
|
1043
|
-
* The ForeignKeyBuilder class provides a fluent interface for defining
|
|
1044
|
-
* foreign key constraints in a migration. It allows you to specify
|
|
1045
|
-
* the referenced table and column, as well as actions to take on
|
|
1043
|
+
* The ForeignKeyBuilder class provides a fluent interface for defining
|
|
1044
|
+
* foreign key constraints in a migration. It allows you to specify
|
|
1045
|
+
* the referenced table and column, as well as actions to take on
|
|
1046
1046
|
* delete and aliases for the relation.
|
|
1047
1047
|
*
|
|
1048
1048
|
* @author Legacy (3m1n3nc3)
|
|
@@ -1054,10 +1054,10 @@ var ForeignKeyBuilder = class {
|
|
|
1054
1054
|
}
|
|
1055
1055
|
/**
|
|
1056
1056
|
* Defines the referenced table and column for this foreign key constraint.
|
|
1057
|
-
*
|
|
1058
|
-
* @param table
|
|
1059
|
-
* @param column
|
|
1060
|
-
* @returns
|
|
1057
|
+
*
|
|
1058
|
+
* @param table
|
|
1059
|
+
* @param column
|
|
1060
|
+
* @returns
|
|
1061
1061
|
*/
|
|
1062
1062
|
references(table, column) {
|
|
1063
1063
|
this.foreignKey.referencesTable = table;
|
|
@@ -1065,22 +1065,22 @@ var ForeignKeyBuilder = class {
|
|
|
1065
1065
|
return this;
|
|
1066
1066
|
}
|
|
1067
1067
|
/**
|
|
1068
|
-
* Defines the action to take when a referenced record is deleted, such
|
|
1068
|
+
* Defines the action to take when a referenced record is deleted, such
|
|
1069
1069
|
* as "CASCADE", "SET NULL", or "RESTRICT".
|
|
1070
|
-
*
|
|
1071
|
-
* @param action
|
|
1072
|
-
* @returns
|
|
1070
|
+
*
|
|
1071
|
+
* @param action
|
|
1072
|
+
* @returns
|
|
1073
1073
|
*/
|
|
1074
1074
|
onDelete(action) {
|
|
1075
1075
|
this.foreignKey.onDelete = action;
|
|
1076
1076
|
return this;
|
|
1077
1077
|
}
|
|
1078
1078
|
/**
|
|
1079
|
-
* Defines an alias for the relation represented by this foreign key, which
|
|
1079
|
+
* Defines an alias for the relation represented by this foreign key, which
|
|
1080
1080
|
* can be used in the ORM for more intuitive access to related models.
|
|
1081
|
-
*
|
|
1082
|
-
* @param name
|
|
1083
|
-
* @returns
|
|
1081
|
+
*
|
|
1082
|
+
* @param name
|
|
1083
|
+
* @returns
|
|
1084
1084
|
*/
|
|
1085
1085
|
alias(name) {
|
|
1086
1086
|
this.foreignKey.relationAlias = name;
|
|
@@ -1088,20 +1088,20 @@ var ForeignKeyBuilder = class {
|
|
|
1088
1088
|
}
|
|
1089
1089
|
/**
|
|
1090
1090
|
* Defines an alias for the inverse relation represented by this foreign key.
|
|
1091
|
-
*
|
|
1092
|
-
* @param name
|
|
1093
|
-
* @returns
|
|
1091
|
+
*
|
|
1092
|
+
* @param name
|
|
1093
|
+
* @returns
|
|
1094
1094
|
*/
|
|
1095
1095
|
inverseAlias(name) {
|
|
1096
1096
|
this.foreignKey.inverseRelationAlias = name;
|
|
1097
1097
|
return this;
|
|
1098
1098
|
}
|
|
1099
1099
|
/**
|
|
1100
|
-
* Defines an alias for the foreign key field itself, which can be
|
|
1100
|
+
* Defines an alias for the foreign key field itself, which can be
|
|
1101
1101
|
* used in the ORM for more intuitive access to the foreign key value.
|
|
1102
|
-
*
|
|
1103
|
-
* @param fieldName
|
|
1104
|
-
* @returns
|
|
1102
|
+
*
|
|
1103
|
+
* @param fieldName
|
|
1104
|
+
* @returns
|
|
1105
1105
|
*/
|
|
1106
1106
|
as(fieldName) {
|
|
1107
1107
|
this.foreignKey.fieldAlias = fieldName;
|
|
@@ -1220,7 +1220,7 @@ var EnumBuilder = class {
|
|
|
1220
1220
|
}
|
|
1221
1221
|
};
|
|
1222
1222
|
/**
|
|
1223
|
-
* The TableBuilder class provides a fluent interface for defining
|
|
1223
|
+
* The TableBuilder class provides a fluent interface for defining
|
|
1224
1224
|
* the structure of a database table in a migration, including columns to add or drop.
|
|
1225
1225
|
*
|
|
1226
1226
|
* @author Legacy (3m1n3nc3)
|
|
@@ -1257,7 +1257,7 @@ var TableBuilder = class {
|
|
|
1257
1257
|
}
|
|
1258
1258
|
/**
|
|
1259
1259
|
* Defines an auto-incrementing primary key column.
|
|
1260
|
-
*
|
|
1260
|
+
*
|
|
1261
1261
|
* @param name The name of the primary key column.
|
|
1262
1262
|
* @default 'id'
|
|
1263
1263
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1267,7 +1267,7 @@ var TableBuilder = class {
|
|
|
1267
1267
|
}
|
|
1268
1268
|
/**
|
|
1269
1269
|
* Defines a UUID column in the table.
|
|
1270
|
-
*
|
|
1270
|
+
*
|
|
1271
1271
|
* @param name The name of the UUID column.
|
|
1272
1272
|
* @param options Additional options for the UUID column.
|
|
1273
1273
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1298,7 +1298,7 @@ var TableBuilder = class {
|
|
|
1298
1298
|
}
|
|
1299
1299
|
/**
|
|
1300
1300
|
* Defines a string column in the table.
|
|
1301
|
-
*
|
|
1301
|
+
*
|
|
1302
1302
|
* @param name The name of the string column.
|
|
1303
1303
|
* @param options Additional options for the string column.
|
|
1304
1304
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1308,7 +1308,7 @@ var TableBuilder = class {
|
|
|
1308
1308
|
}
|
|
1309
1309
|
/**
|
|
1310
1310
|
* Defines a text column in the table.
|
|
1311
|
-
*
|
|
1311
|
+
*
|
|
1312
1312
|
* @param name The name of the text column.
|
|
1313
1313
|
* @param options Additional options for the text column.
|
|
1314
1314
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1318,7 +1318,7 @@ var TableBuilder = class {
|
|
|
1318
1318
|
}
|
|
1319
1319
|
/**
|
|
1320
1320
|
* Defines an integer column in the table.
|
|
1321
|
-
*
|
|
1321
|
+
*
|
|
1322
1322
|
* @param name The name of the integer column.
|
|
1323
1323
|
* @param options Additional options for the integer column.
|
|
1324
1324
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1328,7 +1328,7 @@ var TableBuilder = class {
|
|
|
1328
1328
|
}
|
|
1329
1329
|
/**
|
|
1330
1330
|
* Defines a big integer column in the table.
|
|
1331
|
-
*
|
|
1331
|
+
*
|
|
1332
1332
|
* @param name The name of the big integer column.
|
|
1333
1333
|
* @param options Additional options for the big integer column.
|
|
1334
1334
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1338,7 +1338,7 @@ var TableBuilder = class {
|
|
|
1338
1338
|
}
|
|
1339
1339
|
/**
|
|
1340
1340
|
* Defines a float column in the table.
|
|
1341
|
-
*
|
|
1341
|
+
*
|
|
1342
1342
|
* @param name The name of the float column.
|
|
1343
1343
|
* @param options Additional options for the float column.
|
|
1344
1344
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1346,6 +1346,22 @@ var TableBuilder = class {
|
|
|
1346
1346
|
float(name, options = {}) {
|
|
1347
1347
|
return this.column(name, "float", options);
|
|
1348
1348
|
}
|
|
1349
|
+
/**
|
|
1350
|
+
* Defines a fixed-precision decimal column in the table.
|
|
1351
|
+
*
|
|
1352
|
+
* @param name The name of the decimal column.
|
|
1353
|
+
* @param precision The total number of digits. Defaults to 8.
|
|
1354
|
+
* @param scale The number of digits to the right of the point. Defaults to 2.
|
|
1355
|
+
* @param options Additional options for the decimal column.
|
|
1356
|
+
* @returns The current TableBuilder instance for chaining.
|
|
1357
|
+
*/
|
|
1358
|
+
decimal(name, precision = 8, scale = 2, options = {}) {
|
|
1359
|
+
return this.column(name, "decimal", {
|
|
1360
|
+
precision,
|
|
1361
|
+
scale,
|
|
1362
|
+
...options
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1349
1365
|
unique(columnsOrName, name) {
|
|
1350
1366
|
if (Array.isArray(columnsOrName)) {
|
|
1351
1367
|
const columns = this.normalizeCompositeColumns(columnsOrName, "unique constraint");
|
|
@@ -1364,8 +1380,8 @@ var TableBuilder = class {
|
|
|
1364
1380
|
}
|
|
1365
1381
|
/**
|
|
1366
1382
|
* Defines a boolean column in the table.
|
|
1367
|
-
*
|
|
1368
|
-
* @param name The name of the boolean column.
|
|
1383
|
+
*
|
|
1384
|
+
* @param name The name of the boolean column.
|
|
1369
1385
|
* @param options Additional options for the boolean column.
|
|
1370
1386
|
* @returns The current TableBuilder instance for chaining.
|
|
1371
1387
|
*/
|
|
@@ -1374,29 +1390,39 @@ var TableBuilder = class {
|
|
|
1374
1390
|
}
|
|
1375
1391
|
/**
|
|
1376
1392
|
* Defines a JSON column in the table.
|
|
1377
|
-
*
|
|
1393
|
+
*
|
|
1378
1394
|
* @param name The name of the JSON column.
|
|
1379
1395
|
* @param options Additional options for the JSON column.
|
|
1380
|
-
* @returns
|
|
1396
|
+
* @returns
|
|
1381
1397
|
*/
|
|
1382
1398
|
json(name, options = {}) {
|
|
1383
1399
|
return this.column(name, "json", options);
|
|
1384
1400
|
}
|
|
1385
1401
|
/**
|
|
1386
1402
|
* Defines a date column in the table.
|
|
1387
|
-
*
|
|
1403
|
+
*
|
|
1388
1404
|
* @param name The name of the date column.
|
|
1389
1405
|
* @param options Additional options for the date column.
|
|
1390
|
-
* @returns
|
|
1406
|
+
* @returns
|
|
1391
1407
|
*/
|
|
1392
1408
|
date(name, options = {}) {
|
|
1393
1409
|
return this.column(name, "date", options);
|
|
1394
1410
|
}
|
|
1395
1411
|
/**
|
|
1412
|
+
* Defines a date-time column in the table (timestamp without time zone).
|
|
1413
|
+
*
|
|
1414
|
+
* @param name The name of the date-time column.
|
|
1415
|
+
* @param options Additional options for the date-time column.
|
|
1416
|
+
* @returns The current TableBuilder instance for chaining.
|
|
1417
|
+
*/
|
|
1418
|
+
dateTime(name, options = {}) {
|
|
1419
|
+
return this.column(name, "dateTime", options);
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1396
1422
|
* Defines colonns for a polymorphic relationship in the table.
|
|
1397
|
-
*
|
|
1423
|
+
*
|
|
1398
1424
|
* @param name The base name for the polymorphic relationship columns.
|
|
1399
|
-
* @returns
|
|
1425
|
+
* @returns
|
|
1400
1426
|
*/
|
|
1401
1427
|
morphs(name, nullable = false) {
|
|
1402
1428
|
this.string(`${name}Type`, { nullable });
|
|
@@ -1405,9 +1431,9 @@ var TableBuilder = class {
|
|
|
1405
1431
|
}
|
|
1406
1432
|
/**
|
|
1407
1433
|
* Defines columns for a polymorphic relationship in the table with UUID ID.
|
|
1408
|
-
*
|
|
1434
|
+
*
|
|
1409
1435
|
* @param name The base name for the polymorphic relationship columns.
|
|
1410
|
-
* @returns
|
|
1436
|
+
* @returns
|
|
1411
1437
|
*/
|
|
1412
1438
|
uuidMorphs(name, nullable = false) {
|
|
1413
1439
|
this.string(`${name}Type`, { nullable });
|
|
@@ -1416,28 +1442,28 @@ var TableBuilder = class {
|
|
|
1416
1442
|
}
|
|
1417
1443
|
/**
|
|
1418
1444
|
* Defines nullable columns for a polymorphic relationship in the table.
|
|
1419
|
-
*
|
|
1445
|
+
*
|
|
1420
1446
|
* @param name The base name for the polymorphic relationship columns.
|
|
1421
|
-
* @returns
|
|
1447
|
+
* @returns
|
|
1422
1448
|
*/
|
|
1423
1449
|
nullableMorphs(name) {
|
|
1424
1450
|
return this.morphs(name, true);
|
|
1425
1451
|
}
|
|
1426
1452
|
/**
|
|
1427
1453
|
* Defines nullable columns for a polymorphic relationship in the table with UUID ID.
|
|
1428
|
-
*
|
|
1454
|
+
*
|
|
1429
1455
|
* @param name The base name for the polymorphic relationship columns.
|
|
1430
|
-
* @returns
|
|
1456
|
+
* @returns
|
|
1431
1457
|
*/
|
|
1432
1458
|
nullableUuidMorphs(name) {
|
|
1433
1459
|
return this.uuidMorphs(name, true);
|
|
1434
1460
|
}
|
|
1435
1461
|
/**
|
|
1436
1462
|
* Defines a timestamp column in the table.
|
|
1437
|
-
*
|
|
1463
|
+
*
|
|
1438
1464
|
* @param name The name of the timestamp column.
|
|
1439
1465
|
* @param options Additional options for the timestamp column.
|
|
1440
|
-
* @returns
|
|
1466
|
+
* @returns
|
|
1441
1467
|
*/
|
|
1442
1468
|
timestamp(name, options = {}) {
|
|
1443
1469
|
return this.column(name, "timestamp", options);
|
|
@@ -1498,9 +1524,9 @@ var TableBuilder = class {
|
|
|
1498
1524
|
}
|
|
1499
1525
|
/**
|
|
1500
1526
|
* Defines a soft delete timestamp column in the table.
|
|
1501
|
-
*
|
|
1527
|
+
*
|
|
1502
1528
|
* @param column The name of the soft delete column.
|
|
1503
|
-
* @returns
|
|
1529
|
+
* @returns
|
|
1504
1530
|
*/
|
|
1505
1531
|
softDeletes(column = "deletedAt") {
|
|
1506
1532
|
this.timestamp(column, { nullable: true });
|
|
@@ -1508,9 +1534,9 @@ var TableBuilder = class {
|
|
|
1508
1534
|
}
|
|
1509
1535
|
/**
|
|
1510
1536
|
* Defines a column to be dropped from the table in an alterTable operation.
|
|
1511
|
-
*
|
|
1537
|
+
*
|
|
1512
1538
|
* @param name The name of the column to drop.
|
|
1513
|
-
* @returns
|
|
1539
|
+
* @returns
|
|
1514
1540
|
*/
|
|
1515
1541
|
dropColumn(name) {
|
|
1516
1542
|
this.dropColumnNames.push(name);
|
|
@@ -1518,7 +1544,7 @@ var TableBuilder = class {
|
|
|
1518
1544
|
}
|
|
1519
1545
|
/**
|
|
1520
1546
|
* Marks a column as nullable.
|
|
1521
|
-
*
|
|
1547
|
+
*
|
|
1522
1548
|
* @param columnName Optional explicit column name. When omitted, applies to the latest defined column.
|
|
1523
1549
|
* @returns The current TableBuilder instance for chaining.
|
|
1524
1550
|
*/
|
|
@@ -1556,7 +1582,7 @@ var TableBuilder = class {
|
|
|
1556
1582
|
}
|
|
1557
1583
|
/**
|
|
1558
1584
|
* Sets the column position to appear after another column when possible.
|
|
1559
|
-
*
|
|
1585
|
+
*
|
|
1560
1586
|
* @param referenceColumn The column that the target column should be placed after.
|
|
1561
1587
|
* @param columnName Optional explicit target column name. When omitted, applies to the latest defined column.
|
|
1562
1588
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1568,7 +1594,7 @@ var TableBuilder = class {
|
|
|
1568
1594
|
}
|
|
1569
1595
|
/**
|
|
1570
1596
|
* Maps the column to a custom database column name.
|
|
1571
|
-
*
|
|
1597
|
+
*
|
|
1572
1598
|
* @param name The custom database column name.
|
|
1573
1599
|
* @param columnName Optional explicit target column name. When omitted, applies to the latest defined column.
|
|
1574
1600
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1580,7 +1606,7 @@ var TableBuilder = class {
|
|
|
1580
1606
|
}
|
|
1581
1607
|
/**
|
|
1582
1608
|
* Defines an index on one or more columns.
|
|
1583
|
-
*
|
|
1609
|
+
*
|
|
1584
1610
|
* @param columns Optional target columns. When omitted, applies to the latest defined column.
|
|
1585
1611
|
* @param name Optional index name.
|
|
1586
1612
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1609,11 +1635,11 @@ var TableBuilder = class {
|
|
|
1609
1635
|
return new ForeignKeyBuilder(entry);
|
|
1610
1636
|
}
|
|
1611
1637
|
/**
|
|
1612
|
-
* Defines a foreign key relation for a column, using a
|
|
1638
|
+
* Defines a foreign key relation for a column, using a
|
|
1613
1639
|
* conventional naming pattern.
|
|
1614
|
-
*
|
|
1615
|
-
* @param column
|
|
1616
|
-
* @returns
|
|
1640
|
+
*
|
|
1641
|
+
* @param column
|
|
1642
|
+
* @returns
|
|
1617
1643
|
*/
|
|
1618
1644
|
foreign(column) {
|
|
1619
1645
|
const columnName = this.resolveColumn(column).name;
|
|
@@ -1621,8 +1647,8 @@ var TableBuilder = class {
|
|
|
1621
1647
|
}
|
|
1622
1648
|
/**
|
|
1623
1649
|
* Returns a deep copy of the defined columns for the table.
|
|
1624
|
-
*
|
|
1625
|
-
* @returns
|
|
1650
|
+
*
|
|
1651
|
+
* @returns
|
|
1626
1652
|
*/
|
|
1627
1653
|
getColumns() {
|
|
1628
1654
|
return this.columns.map((column) => ({
|
|
@@ -1632,15 +1658,15 @@ var TableBuilder = class {
|
|
|
1632
1658
|
}
|
|
1633
1659
|
/**
|
|
1634
1660
|
* Returns a copy of the defined column names to be dropped from the table.
|
|
1635
|
-
*
|
|
1636
|
-
* @returns
|
|
1661
|
+
*
|
|
1662
|
+
* @returns
|
|
1637
1663
|
*/
|
|
1638
1664
|
getDropColumns() {
|
|
1639
1665
|
return [...this.dropColumnNames];
|
|
1640
1666
|
}
|
|
1641
1667
|
/**
|
|
1642
1668
|
* Returns a deep copy of the defined indexes for the table.
|
|
1643
|
-
*
|
|
1669
|
+
*
|
|
1644
1670
|
* @returns
|
|
1645
1671
|
*/
|
|
1646
1672
|
getIndexes() {
|
|
@@ -1677,11 +1703,11 @@ var TableBuilder = class {
|
|
|
1677
1703
|
}
|
|
1678
1704
|
/**
|
|
1679
1705
|
* Defines a column in the table with the given name.
|
|
1680
|
-
*
|
|
1706
|
+
*
|
|
1681
1707
|
* @param name The name of the column.
|
|
1682
1708
|
* @param type The type of the column.
|
|
1683
1709
|
* @param options Additional options for the column.
|
|
1684
|
-
* @returns
|
|
1710
|
+
* @returns
|
|
1685
1711
|
*/
|
|
1686
1712
|
column(name, type, options) {
|
|
1687
1713
|
this.columns.push({
|
|
@@ -1697,6 +1723,8 @@ var TableBuilder = class {
|
|
|
1697
1723
|
after: options.after,
|
|
1698
1724
|
default: options.default,
|
|
1699
1725
|
updatedAt: options.updatedAt,
|
|
1726
|
+
precision: options.precision,
|
|
1727
|
+
scale: options.scale,
|
|
1700
1728
|
primaryKeyGeneration: options.primaryKeyGeneration
|
|
1701
1729
|
});
|
|
1702
1730
|
const column = this.columns[this.columns.length - 1];
|
|
@@ -1706,9 +1734,9 @@ var TableBuilder = class {
|
|
|
1706
1734
|
}
|
|
1707
1735
|
/**
|
|
1708
1736
|
* Resolve a target column by name or fallback to the latest defined column.
|
|
1709
|
-
*
|
|
1710
|
-
* @param columnName
|
|
1711
|
-
* @returns
|
|
1737
|
+
*
|
|
1738
|
+
* @param columnName
|
|
1739
|
+
* @returns
|
|
1712
1740
|
*/
|
|
1713
1741
|
resolveColumn(columnName) {
|
|
1714
1742
|
const targetName = columnName ?? this.latestColumnName;
|
|
@@ -1729,19 +1757,84 @@ var TableBuilder = class {
|
|
|
1729
1757
|
//#endregion
|
|
1730
1758
|
//#region src/database/SchemaBuilder.ts
|
|
1731
1759
|
/**
|
|
1732
|
-
* The SchemaBuilder class provides methods for defining the operations to be
|
|
1733
|
-
* performed in a migration, such as creating, altering, or dropping tables.
|
|
1760
|
+
* The SchemaBuilder class provides methods for defining the operations to be
|
|
1761
|
+
* performed in a migration, such as creating, altering, or dropping tables.
|
|
1734
1762
|
*
|
|
1735
1763
|
* @author Legacy (3m1n3nc3)
|
|
1736
1764
|
* @since 0.1.0
|
|
1737
1765
|
*/
|
|
1738
|
-
var SchemaBuilder = class {
|
|
1766
|
+
var SchemaBuilder = class SchemaBuilder {
|
|
1739
1767
|
constructor() {
|
|
1740
1768
|
this.operations = [];
|
|
1741
1769
|
}
|
|
1742
1770
|
/**
|
|
1771
|
+
* Disable foreign-key constraint enforcement on the active PostgreSQL
|
|
1772
|
+
* connection by switching the session into replication mode, which
|
|
1773
|
+
* suppresses the internal triggers that enforce foreign keys.
|
|
1774
|
+
*
|
|
1775
|
+
* The setting is connection-scoped, so the disable, the work that depends
|
|
1776
|
+
* on it, and the matching {@link SchemaBuilder.enableForeignKeyConstraints}
|
|
1777
|
+
* must run on the same connection. Prefer
|
|
1778
|
+
* {@link SchemaBuilder.withoutForeignKeyConstraints}, which guarantees this
|
|
1779
|
+
* by wrapping the work in a transaction. Requires a SQL-backed adapter and
|
|
1780
|
+
* a database role permitted to set `session_replication_role`.
|
|
1781
|
+
*
|
|
1782
|
+
* @returns
|
|
1783
|
+
*/
|
|
1784
|
+
static async disableForeignKeyConstraints() {
|
|
1785
|
+
await SchemaBuilder.setSessionReplicationRole("replica");
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* Re-enable foreign-key constraint enforcement on the active PostgreSQL
|
|
1789
|
+
* connection by restoring the default session replication role.
|
|
1790
|
+
*
|
|
1791
|
+
* @returns
|
|
1792
|
+
*/
|
|
1793
|
+
static async enableForeignKeyConstraints() {
|
|
1794
|
+
await SchemaBuilder.setSessionReplicationRole("origin");
|
|
1795
|
+
}
|
|
1796
|
+
/**
|
|
1797
|
+
* Run the given callback with foreign-key constraints disabled, then
|
|
1798
|
+
* restore them. The whole unit runs inside a transaction so the disable,
|
|
1799
|
+
* the callback, and the re-enable share a single connection (required for
|
|
1800
|
+
* the connection-scoped replication role to take effect) and roll back
|
|
1801
|
+
* together on failure.
|
|
1802
|
+
*
|
|
1803
|
+
* @example
|
|
1804
|
+
* await SchemaBuilder.withoutForeignKeyConstraints(async () => {
|
|
1805
|
+
* await User.factory()
|
|
1806
|
+
* .hasAttached(Tenant.factory().has(Project.factory(3)), { status: 'active' }, 'tenantMemberships')
|
|
1807
|
+
* .create()
|
|
1808
|
+
* })
|
|
1809
|
+
*
|
|
1810
|
+
* @param callback
|
|
1811
|
+
* @returns
|
|
1812
|
+
*/
|
|
1813
|
+
static async withoutForeignKeyConstraints(callback) {
|
|
1814
|
+
return await runArkormTransaction(async () => {
|
|
1815
|
+
await SchemaBuilder.disableForeignKeyConstraints();
|
|
1816
|
+
try {
|
|
1817
|
+
return await callback();
|
|
1818
|
+
} finally {
|
|
1819
|
+
await SchemaBuilder.enableForeignKeyConstraints();
|
|
1820
|
+
}
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
static async setSessionReplicationRole(role) {
|
|
1824
|
+
const adapter = getRuntimeAdapter();
|
|
1825
|
+
if (!adapter) throw new ArkormException("Toggling foreign-key constraints requires a configured database adapter.", {
|
|
1826
|
+
code: "ADAPTER_NOT_CONFIGURED",
|
|
1827
|
+
operation: "schema.foreignKeyConstraints"
|
|
1828
|
+
});
|
|
1829
|
+
if (!adapter.rawQuery) throw new UnsupportedAdapterFeatureException("Toggling foreign-key constraints requires an adapter that supports raw queries.", {
|
|
1830
|
+
operation: "schema.foreignKeyConstraints",
|
|
1831
|
+
meta: { feature: "rawQuery" }
|
|
1832
|
+
});
|
|
1833
|
+
await adapter.rawQuery({ sql: `SET session_replication_role = '${role}'` });
|
|
1834
|
+
}
|
|
1835
|
+
/**
|
|
1743
1836
|
* Defines a new table to be created in the migration.
|
|
1744
|
-
*
|
|
1837
|
+
*
|
|
1745
1838
|
* @param table The name of the table to create.
|
|
1746
1839
|
* @param callback A callback function to define the table's columns and structure.
|
|
1747
1840
|
* @returns The current SchemaBuilder instance for chaining.
|
|
@@ -1765,7 +1858,7 @@ var SchemaBuilder = class {
|
|
|
1765
1858
|
}
|
|
1766
1859
|
/**
|
|
1767
1860
|
* Defines alterations to an existing table in the migration.
|
|
1768
|
-
*
|
|
1861
|
+
*
|
|
1769
1862
|
* @param table The name of the table to alter.
|
|
1770
1863
|
* @param callback A callback function to define the alterations to the table's columns and structure.
|
|
1771
1864
|
* @returns The current SchemaBuilder instance for chaining.
|
|
@@ -1790,7 +1883,7 @@ var SchemaBuilder = class {
|
|
|
1790
1883
|
}
|
|
1791
1884
|
/**
|
|
1792
1885
|
* Defines a table to be dropped in the migration.
|
|
1793
|
-
*
|
|
1886
|
+
*
|
|
1794
1887
|
* @param table The name of the table to drop.
|
|
1795
1888
|
* @returns The current SchemaBuilder instance for chaining.
|
|
1796
1889
|
*/
|
|
@@ -1803,7 +1896,7 @@ var SchemaBuilder = class {
|
|
|
1803
1896
|
}
|
|
1804
1897
|
/**
|
|
1805
1898
|
* Returns a deep copy of the defined schema operations for the migration/
|
|
1806
|
-
*
|
|
1899
|
+
*
|
|
1807
1900
|
* @returns An array of schema operations for the migration.
|
|
1808
1901
|
*/
|
|
1809
1902
|
getOperations() {
|
|
@@ -1879,7 +1972,7 @@ const PRISMA_ENUM_REGEX = /enum\s+(\w+)\s*\{[\s\S]*?\n\}/g;
|
|
|
1879
1972
|
const PRISMA_ENUM_MEMBER_REGEX = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
1880
1973
|
/**
|
|
1881
1974
|
* Convert a table name to a PascalCase model name, with basic singularization.
|
|
1882
|
-
*
|
|
1975
|
+
*
|
|
1883
1976
|
* @param tableName The name of the table to convert.
|
|
1884
1977
|
* @returns The corresponding PascalCase model name.
|
|
1885
1978
|
*/
|
|
@@ -1891,16 +1984,16 @@ const toModelName = (tableName) => {
|
|
|
1891
1984
|
};
|
|
1892
1985
|
/**
|
|
1893
1986
|
* Escape special characters in a string for use in a regular expression.
|
|
1894
|
-
*
|
|
1895
|
-
* @param value
|
|
1896
|
-
* @returns
|
|
1987
|
+
*
|
|
1988
|
+
* @param value
|
|
1989
|
+
* @returns
|
|
1897
1990
|
*/
|
|
1898
1991
|
const escapeRegex = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1899
1992
|
/**
|
|
1900
1993
|
* Convert a SchemaColumn definition to a Prisma field type string, including modifiers.
|
|
1901
|
-
*
|
|
1902
|
-
* @param column
|
|
1903
|
-
* @returns
|
|
1994
|
+
*
|
|
1995
|
+
* @param column
|
|
1996
|
+
* @returns
|
|
1904
1997
|
*/
|
|
1905
1998
|
const resolvePrismaType = (column) => {
|
|
1906
1999
|
if (column.type === "id") return "Int";
|
|
@@ -1910,6 +2003,7 @@ const resolvePrismaType = (column) => {
|
|
|
1910
2003
|
if (column.type === "integer") return "Int";
|
|
1911
2004
|
if (column.type === "bigInteger") return "BigInt";
|
|
1912
2005
|
if (column.type === "float") return "Float";
|
|
2006
|
+
if (column.type === "decimal") return "Decimal";
|
|
1913
2007
|
if (column.type === "boolean") return "Boolean";
|
|
1914
2008
|
if (column.type === "json") return "Json";
|
|
1915
2009
|
return "DateTime";
|
|
@@ -1919,11 +2013,11 @@ const resolveEnumName = (column) => {
|
|
|
1919
2013
|
if (column.enumName && column.enumName.trim().length > 0) return column.enumName.trim();
|
|
1920
2014
|
throw new ArkormException(`Enum column [${column.name}] must define an enum name.`);
|
|
1921
2015
|
};
|
|
1922
|
-
/**
|
|
2016
|
+
/**
|
|
1923
2017
|
* Format a default value for inclusion in a Prisma schema field definition, based on its type.
|
|
1924
|
-
*
|
|
1925
|
-
* @param value
|
|
1926
|
-
* @returns
|
|
2018
|
+
*
|
|
2019
|
+
* @param value
|
|
2020
|
+
* @returns
|
|
1927
2021
|
*/
|
|
1928
2022
|
const formatDefaultValue = (value) => {
|
|
1929
2023
|
if (value == null) return void 0;
|
|
@@ -1934,9 +2028,9 @@ const formatDefaultValue = (value) => {
|
|
|
1934
2028
|
};
|
|
1935
2029
|
/**
|
|
1936
2030
|
* Format a default value for an enum column as a Prisma @default attribute, validating that it is a non-empty string.
|
|
1937
|
-
*
|
|
1938
|
-
* @param value
|
|
1939
|
-
* @returns
|
|
2031
|
+
*
|
|
2032
|
+
* @param value
|
|
2033
|
+
* @returns
|
|
1940
2034
|
*/
|
|
1941
2035
|
const formatEnumDefaultValue = (value) => {
|
|
1942
2036
|
if (value == null) return void 0;
|
|
@@ -1945,9 +2039,9 @@ const formatEnumDefaultValue = (value) => {
|
|
|
1945
2039
|
};
|
|
1946
2040
|
/**
|
|
1947
2041
|
* Normalize an enum value by ensuring it is a non-empty string and trimming whitespace.
|
|
1948
|
-
*
|
|
1949
|
-
* @param value
|
|
1950
|
-
* @returns
|
|
2042
|
+
*
|
|
2043
|
+
* @param value
|
|
2044
|
+
* @returns
|
|
1951
2045
|
*/
|
|
1952
2046
|
const normalizeEnumValue = (value) => {
|
|
1953
2047
|
if (typeof value !== "string" || value.trim().length === 0) throw new ArkormException("Enum values must be provided as non-empty strings.");
|
|
@@ -1957,9 +2051,9 @@ const normalizeEnumValue = (value) => {
|
|
|
1957
2051
|
};
|
|
1958
2052
|
/**
|
|
1959
2053
|
* Extract the enum values from a Prisma enum block string.
|
|
1960
|
-
*
|
|
1961
|
-
* @param block
|
|
1962
|
-
* @returns
|
|
2054
|
+
*
|
|
2055
|
+
* @param block
|
|
2056
|
+
* @returns
|
|
1963
2057
|
*/
|
|
1964
2058
|
const extractEnumBlockValues = (block) => {
|
|
1965
2059
|
return block.split("\n").slice(1, -1).map((line) => line.trim()).filter(Boolean);
|
|
@@ -1975,11 +2069,11 @@ const validateEnumValues = (column, enumName, enumValues) => {
|
|
|
1975
2069
|
};
|
|
1976
2070
|
/**
|
|
1977
2071
|
* Validate that a default value for an enum column is included in the defined enum values.
|
|
1978
|
-
*
|
|
1979
|
-
* @param column
|
|
1980
|
-
* @param enumName
|
|
1981
|
-
* @param enumValues
|
|
1982
|
-
* @returns
|
|
2072
|
+
*
|
|
2073
|
+
* @param column
|
|
2074
|
+
* @param enumName
|
|
2075
|
+
* @param enumValues
|
|
2076
|
+
* @returns
|
|
1983
2077
|
*/
|
|
1984
2078
|
const validateEnumDefaultValue = (column, enumName, enumValues) => {
|
|
1985
2079
|
if (column.default == null) return;
|
|
@@ -1989,9 +2083,9 @@ const validateEnumDefaultValue = (column, enumName, enumValues) => {
|
|
|
1989
2083
|
};
|
|
1990
2084
|
/**
|
|
1991
2085
|
* Build a single line of a Prisma model field definition based on a SchemaColumn, including type and modifiers.
|
|
1992
|
-
*
|
|
1993
|
-
* @param column
|
|
1994
|
-
* @returns
|
|
2086
|
+
*
|
|
2087
|
+
* @param column
|
|
2088
|
+
* @returns
|
|
1995
2089
|
*/
|
|
1996
2090
|
const buildFieldLine = (column) => {
|
|
1997
2091
|
if (column.type === "id") {
|
|
@@ -2008,14 +2102,15 @@ const buildFieldLine = (column) => {
|
|
|
2008
2102
|
const primary = column.primary ? " @id" : "";
|
|
2009
2103
|
const mapped = typeof column.map === "string" && column.map.trim().length > 0 ? ` @map("${column.map.replace(/"/g, "\\\"")}")` : "";
|
|
2010
2104
|
const updatedAt = column.updatedAt ? " @updatedAt" : "";
|
|
2105
|
+
const nativeType = column.type === "decimal" ? ` @db.Decimal(${column.precision ?? 8}, ${column.scale ?? 2})` : "";
|
|
2011
2106
|
const defaultValue = column.type === "enum" ? formatEnumDefaultValue(column.default) : column.primaryKeyGeneration?.prismaDefault ?? formatDefaultValue(column.default);
|
|
2012
2107
|
const defaultSuffix = defaultValue ? ` ${defaultValue}` : "";
|
|
2013
|
-
return ` ${column.name} ${scalar}${nullable}${primary}${unique}${defaultSuffix}${updatedAt}${mapped}`;
|
|
2108
|
+
return ` ${column.name} ${scalar}${nullable}${primary}${unique}${defaultSuffix}${updatedAt}${mapped}${nativeType}`;
|
|
2014
2109
|
};
|
|
2015
2110
|
/**
|
|
2016
|
-
* Build a Prisma enum block string based on an enum name and its values, validating that
|
|
2111
|
+
* Build a Prisma enum block string based on an enum name and its values, validating that
|
|
2017
2112
|
* at least one value is provided.
|
|
2018
|
-
*
|
|
2113
|
+
*
|
|
2019
2114
|
* @param enumName The name of the enum to create.
|
|
2020
2115
|
* @param values The array of values for the enum.
|
|
2021
2116
|
* @returns The Prisma enum block string.
|
|
@@ -2025,12 +2120,12 @@ const buildEnumBlock = (enumName, values) => {
|
|
|
2025
2120
|
return `enum ${enumName} {\n${values.map((value) => ` ${value}`).join("\n")}\n}`;
|
|
2026
2121
|
};
|
|
2027
2122
|
/**
|
|
2028
|
-
* Find the Prisma enum block in a schema string that corresponds to a given enum
|
|
2123
|
+
* Find the Prisma enum block in a schema string that corresponds to a given enum
|
|
2029
2124
|
* name, returning its details if found.
|
|
2030
|
-
*
|
|
2125
|
+
*
|
|
2031
2126
|
* @param schema The Prisma schema string to search for the enum block.
|
|
2032
2127
|
* @param enumName The name of the enum to find in the schema.
|
|
2033
|
-
* @returns
|
|
2128
|
+
* @returns
|
|
2034
2129
|
*/
|
|
2035
2130
|
const findEnumBlock = (schema, enumName) => {
|
|
2036
2131
|
const candidates = [...schema.matchAll(PRISMA_ENUM_REGEX)];
|
|
@@ -2049,13 +2144,13 @@ const findEnumBlock = (schema, enumName) => {
|
|
|
2049
2144
|
return null;
|
|
2050
2145
|
};
|
|
2051
2146
|
/**
|
|
2052
|
-
* Ensure that Prisma enum blocks exist in the schema for any enum columns defined in a
|
|
2053
|
-
* create or alter table operation, adding them if necessary and validating against
|
|
2147
|
+
* Ensure that Prisma enum blocks exist in the schema for any enum columns defined in a
|
|
2148
|
+
* create or alter table operation, adding them if necessary and validating against
|
|
2054
2149
|
* existing blocks.
|
|
2055
|
-
*
|
|
2150
|
+
*
|
|
2056
2151
|
* @param schema The current Prisma schema string to check and modify.
|
|
2057
2152
|
* @param columns The array of schema column definitions to check for enum types and ensure corresponding blocks exist for.
|
|
2058
|
-
* @returns
|
|
2153
|
+
* @returns
|
|
2059
2154
|
*/
|
|
2060
2155
|
const ensureEnumBlocks = (schema, columns) => {
|
|
2061
2156
|
let nextSchema = schema;
|
|
@@ -2085,9 +2180,9 @@ const ensureEnumBlocks = (schema, columns) => {
|
|
|
2085
2180
|
};
|
|
2086
2181
|
/**
|
|
2087
2182
|
* Build a Prisma model-level @@index definition line.
|
|
2088
|
-
*
|
|
2183
|
+
*
|
|
2089
2184
|
* @param index The schema index definition to convert to a Prisma \@\@index line.
|
|
2090
|
-
* @returns
|
|
2185
|
+
* @returns
|
|
2091
2186
|
*/
|
|
2092
2187
|
const buildIndexLine = (index) => {
|
|
2093
2188
|
return ` @@index([${index.columns.join(", ")}]${typeof index.name === "string" && index.name.trim().length > 0 ? `, name: "${index.name.replace(/"/g, "\\\"")}"` : ""})`;
|
|
@@ -2111,9 +2206,9 @@ const buildUniqueConstraintLine = (constraint) => {
|
|
|
2111
2206
|
return ` @@unique([${constraint.columns.join(", ")}]${typeof constraint.name === "string" && constraint.name.trim().length > 0 ? `, name: "${constraint.name.replace(/"/g, "\\\"")}"` : ""})`;
|
|
2112
2207
|
};
|
|
2113
2208
|
/**
|
|
2114
|
-
* Derive a relation field name from a foreign key column name by applying
|
|
2209
|
+
* Derive a relation field name from a foreign key column name by applying
|
|
2115
2210
|
* common conventions, such as removing "Id" suffixes and converting to camelCase.
|
|
2116
|
-
*
|
|
2211
|
+
*
|
|
2117
2212
|
* @param columnName The name of the foreign key column.
|
|
2118
2213
|
* @returns The derived relation field name.
|
|
2119
2214
|
*/
|
|
@@ -2128,10 +2223,10 @@ const deriveRelationFieldName = (columnName) => {
|
|
|
2128
2223
|
return `${trimmed.charAt(0).toLowerCase()}${trimmed.slice(1)}`;
|
|
2129
2224
|
};
|
|
2130
2225
|
/**
|
|
2131
|
-
* Derive a relation name for both sides of a relation based on the
|
|
2132
|
-
* source and target model names, using an explicit alias if provided or a
|
|
2226
|
+
* Derive a relation name for both sides of a relation based on the
|
|
2227
|
+
* source and target model names, using an explicit alias if provided or a
|
|
2133
2228
|
* convention of combining the full source model name with the target model name.
|
|
2134
|
-
*
|
|
2229
|
+
*
|
|
2135
2230
|
* @param sourceModelName The name of the source model in the relation.
|
|
2136
2231
|
* @param targetModelName The name of the target model in the relation.
|
|
2137
2232
|
* @param explicitAlias An optional explicit alias for the relation.
|
|
@@ -2158,9 +2253,9 @@ const resolveForeignKeyColumn = (columns, foreignKey) => {
|
|
|
2158
2253
|
const isOneToOneForeignKey = (column) => {
|
|
2159
2254
|
return Boolean(column?.unique || column?.primary);
|
|
2160
2255
|
};
|
|
2161
|
-
/**
|
|
2256
|
+
/**
|
|
2162
2257
|
* Format a SchemaForeignKeyAction value as a Prisma onDelete action string.
|
|
2163
|
-
*
|
|
2258
|
+
*
|
|
2164
2259
|
* @param action The foreign key action to format.
|
|
2165
2260
|
* @returns The corresponding Prisma onDelete action string.
|
|
2166
2261
|
*/
|
|
@@ -2172,9 +2267,9 @@ const formatRelationAction = (action) => {
|
|
|
2172
2267
|
return "NoAction";
|
|
2173
2268
|
};
|
|
2174
2269
|
/**
|
|
2175
|
-
* Build a Prisma relation field line based on a SchemaForeignKey
|
|
2270
|
+
* Build a Prisma relation field line based on a SchemaForeignKey
|
|
2176
2271
|
* definition, including relation name and onDelete action.
|
|
2177
|
-
*
|
|
2272
|
+
*
|
|
2178
2273
|
* @param foreignKey The foreign key definition to convert to a relation line.
|
|
2179
2274
|
* @returns The corresponding Prisma schema line for the relation field.
|
|
2180
2275
|
*/
|
|
@@ -2190,10 +2285,10 @@ const buildRelationLine = (sourceModelName, foreignKey, columns = []) => {
|
|
|
2190
2285
|
return ` ${fieldName} ${targetModel}${optional} @relation("${relationName.replace(/"/g, "\\\"")}", fields: [${foreignKey.column}], references: [${foreignKey.referencesColumn}]${onDelete})`;
|
|
2191
2286
|
};
|
|
2192
2287
|
/**
|
|
2193
|
-
* Build a Prisma relation field line for the inverse side of a relation, based
|
|
2194
|
-
* on the source and target model names and the foreign key definition, using
|
|
2288
|
+
* Build a Prisma relation field line for the inverse side of a relation, based
|
|
2289
|
+
* on the source and target model names and the foreign key definition, using
|
|
2195
2290
|
* naming conventions and any explicit inverse alias provided.
|
|
2196
|
-
*
|
|
2291
|
+
*
|
|
2197
2292
|
* @param sourceModelName The name of the source model in the relation.
|
|
2198
2293
|
* @param targetModelName The name of the target model in the relation.
|
|
2199
2294
|
* @param foreignKey The foreign key definition for the relation.
|
|
@@ -2206,14 +2301,14 @@ const buildInverseRelationLine = (sourceModelName, targetModelName, foreignKey,
|
|
|
2206
2301
|
return ` ${fieldName} ${isOneToOneForeignKey(sourceColumn) ? `${sourceModelName}?` : `${sourceModelName}[]`} @relation("${relationName.replace(/"/g, "\\\"")}")`;
|
|
2207
2302
|
};
|
|
2208
2303
|
/**
|
|
2209
|
-
* Inject a line into the body of a Prisma model block if it does not already
|
|
2210
|
-
* exist, using a provided existence check function to determine if the line
|
|
2304
|
+
* Inject a line into the body of a Prisma model block if it does not already
|
|
2305
|
+
* exist, using a provided existence check function to determine if the line
|
|
2211
2306
|
* is already present.
|
|
2212
|
-
*
|
|
2307
|
+
*
|
|
2213
2308
|
* @param bodyLines The lines of the model block body to modify.
|
|
2214
2309
|
* @param line The line to inject if it does not already exist.
|
|
2215
2310
|
* @param exists A function that checks if a given line already exists in the body.
|
|
2216
|
-
* @returns
|
|
2311
|
+
* @returns
|
|
2217
2312
|
*/
|
|
2218
2313
|
const injectLineIntoModelBody = (bodyLines, line, exists) => {
|
|
2219
2314
|
if (bodyLines.some(exists)) return bodyLines;
|
|
@@ -2222,10 +2317,10 @@ const injectLineIntoModelBody = (bodyLines, line, exists) => {
|
|
|
2222
2317
|
return bodyLines;
|
|
2223
2318
|
};
|
|
2224
2319
|
/**
|
|
2225
|
-
* Apply inverse relation definitions to a Prisma schema string based on the
|
|
2226
|
-
* foreign keys defined in a create or alter table operation, ensuring that
|
|
2320
|
+
* Apply inverse relation definitions to a Prisma schema string based on the
|
|
2321
|
+
* foreign keys defined in a create or alter table operation, ensuring that
|
|
2227
2322
|
* related models have corresponding relation fields for bi-directional navigation.
|
|
2228
|
-
*
|
|
2323
|
+
*
|
|
2229
2324
|
* @param schema The Prisma schema string to modify.
|
|
2230
2325
|
* @param sourceModelName The name of the source model in the relation.
|
|
2231
2326
|
* @param foreignKeys An array of foreign key definitions to process.
|
|
@@ -2248,9 +2343,9 @@ const applyInverseRelations = (schema, sourceModelName, foreignKeys, columns = [
|
|
|
2248
2343
|
return nextSchema;
|
|
2249
2344
|
};
|
|
2250
2345
|
/**
|
|
2251
|
-
* Build a Prisma model block string based on a SchemaTableCreateOperation, including
|
|
2346
|
+
* Build a Prisma model block string based on a SchemaTableCreateOperation, including
|
|
2252
2347
|
* all fields and any necessary mapping.
|
|
2253
|
-
*
|
|
2348
|
+
*
|
|
2254
2349
|
* @param operation The schema table create operation to convert.
|
|
2255
2350
|
* @returns The corresponding Prisma model block string.
|
|
2256
2351
|
*/
|
|
@@ -2275,12 +2370,12 @@ const buildModelBlock = (operation) => {
|
|
|
2275
2370
|
] : [...fields, ...relations]).join("\n")}\n}`;
|
|
2276
2371
|
};
|
|
2277
2372
|
/**
|
|
2278
|
-
* Find the Prisma model block in a schema string that corresponds to a given
|
|
2373
|
+
* Find the Prisma model block in a schema string that corresponds to a given
|
|
2279
2374
|
* table name, using both explicit mapping and naming conventions.
|
|
2280
|
-
*
|
|
2281
|
-
* @param schema
|
|
2282
|
-
* @param table
|
|
2283
|
-
* @returns
|
|
2375
|
+
*
|
|
2376
|
+
* @param schema
|
|
2377
|
+
* @param table
|
|
2378
|
+
* @returns
|
|
2284
2379
|
*/
|
|
2285
2380
|
const findModelBlock = (schema, table) => {
|
|
2286
2381
|
const candidates = [...schema.matchAll(PRISMA_MODEL_REGEX)];
|
|
@@ -2312,9 +2407,9 @@ const findModelBlock = (schema, table) => {
|
|
|
2312
2407
|
return null;
|
|
2313
2408
|
};
|
|
2314
2409
|
/**
|
|
2315
|
-
* Apply a create table operation to a Prisma schema string, adding a new model
|
|
2410
|
+
* Apply a create table operation to a Prisma schema string, adding a new model
|
|
2316
2411
|
* block for the specified table and fields.
|
|
2317
|
-
*
|
|
2412
|
+
*
|
|
2318
2413
|
* @param schema The current Prisma schema string.
|
|
2319
2414
|
* @param operation The schema table create operation to apply.
|
|
2320
2415
|
* @returns The updated Prisma schema string with the new model block.
|
|
@@ -2326,9 +2421,9 @@ const applyCreateTableOperation = (schema, operation) => {
|
|
|
2326
2421
|
return applyInverseRelations(`${schemaWithEnums.trimEnd()}\n\n${block}\n`, toModelName(operation.table), operation.foreignKeys ?? [], operation.columns);
|
|
2327
2422
|
};
|
|
2328
2423
|
/**
|
|
2329
|
-
* Apply an alter table operation to a Prisma schema string, modifying the model
|
|
2424
|
+
* Apply an alter table operation to a Prisma schema string, modifying the model
|
|
2330
2425
|
* block for the specified table by adding and removing fields as needed.
|
|
2331
|
-
*
|
|
2426
|
+
*
|
|
2332
2427
|
* @param schema The current Prisma schema string.
|
|
2333
2428
|
* @param operation The schema table alter operation to apply.
|
|
2334
2429
|
* @returns The updated Prisma schema string with the modified model block.
|
|
@@ -2395,10 +2490,10 @@ const applyDropTableOperation = (schema, operation) => {
|
|
|
2395
2490
|
return `${before}${before && after ? "\n\n" : ""}${after}`;
|
|
2396
2491
|
};
|
|
2397
2492
|
/**
|
|
2398
|
-
* The SchemaBuilder class provides a fluent interface for defining
|
|
2399
|
-
* database schema operations in a migration, such as creating, altering, and
|
|
2493
|
+
* The SchemaBuilder class provides a fluent interface for defining
|
|
2494
|
+
* database schema operations in a migration, such as creating, altering, and
|
|
2400
2495
|
* dropping tables.
|
|
2401
|
-
*
|
|
2496
|
+
*
|
|
2402
2497
|
* @param schema The current Prisma schema string.
|
|
2403
2498
|
* @param operations The list of schema operations to apply.
|
|
2404
2499
|
* @returns The updated Prisma schema string after applying all operations.
|
|
@@ -2412,7 +2507,7 @@ const applyOperationsToPrismaSchema = (schema, operations) => {
|
|
|
2412
2507
|
};
|
|
2413
2508
|
/**
|
|
2414
2509
|
* Run a Prisma CLI command using npx, capturing and throwing any errors that occur.
|
|
2415
|
-
*
|
|
2510
|
+
*
|
|
2416
2511
|
* @param args The arguments to pass to the Prisma CLI command.
|
|
2417
2512
|
* @param cwd The current working directory to run the command in.
|
|
2418
2513
|
* @returns void
|
|
@@ -2427,11 +2522,11 @@ const runPrismaCommand = (args, cwd) => {
|
|
|
2427
2522
|
throw new ArkormException(errorOutput ? `Prisma command failed: prisma ${args.join(" ")}\n${errorOutput}` : `Prisma command failed: prisma ${args.join(" ")}`);
|
|
2428
2523
|
};
|
|
2429
2524
|
/**
|
|
2430
|
-
* Generate a new migration file with a given name and options, including
|
|
2525
|
+
* Generate a new migration file with a given name and options, including
|
|
2431
2526
|
* writing the file to disk if specified.
|
|
2432
|
-
*
|
|
2433
|
-
* @param name
|
|
2434
|
-
* @returns
|
|
2527
|
+
*
|
|
2528
|
+
* @param name
|
|
2529
|
+
* @returns
|
|
2435
2530
|
*/
|
|
2436
2531
|
const resolveMigrationClassName = (name) => {
|
|
2437
2532
|
const cleaned = name.replace(/[^a-zA-Z0-9]+/g, " ").trim();
|
|
@@ -2439,39 +2534,39 @@ const resolveMigrationClassName = (name) => {
|
|
|
2439
2534
|
return `${cleaned.split(/\s+/g).map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("")}Migration`;
|
|
2440
2535
|
};
|
|
2441
2536
|
/**
|
|
2442
|
-
* Pad a number with leading zeros to ensure it is at least two digits, for
|
|
2537
|
+
* Pad a number with leading zeros to ensure it is at least two digits, for
|
|
2443
2538
|
* use in migration timestamps.
|
|
2444
|
-
*
|
|
2445
|
-
* @param value
|
|
2446
|
-
* @returns
|
|
2539
|
+
*
|
|
2540
|
+
* @param value
|
|
2541
|
+
* @returns
|
|
2447
2542
|
*/
|
|
2448
2543
|
const pad = (value) => String(value).padStart(2, "0");
|
|
2449
2544
|
/**
|
|
2450
|
-
* Create a timestamp string in the format YYYYMMDDHHMMSS for use in migration
|
|
2545
|
+
* Create a timestamp string in the format YYYYMMDDHHMMSS for use in migration
|
|
2451
2546
|
* file names, based on the current date and time or a provided date.
|
|
2452
|
-
*
|
|
2453
|
-
* @param date
|
|
2454
|
-
* @returns
|
|
2547
|
+
*
|
|
2548
|
+
* @param date
|
|
2549
|
+
* @returns
|
|
2455
2550
|
*/
|
|
2456
2551
|
const createMigrationTimestamp = (date = /* @__PURE__ */ new Date()) => {
|
|
2457
2552
|
return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`;
|
|
2458
2553
|
};
|
|
2459
2554
|
/**
|
|
2460
|
-
* Convert a migration name to a slug suitable for use in a file name, by
|
|
2555
|
+
* Convert a migration name to a slug suitable for use in a file name, by
|
|
2461
2556
|
* lowercasing and replacing non-alphanumeric characters with underscores.
|
|
2462
|
-
*
|
|
2463
|
-
* @param name
|
|
2464
|
-
* @returns
|
|
2557
|
+
*
|
|
2558
|
+
* @param name
|
|
2559
|
+
* @returns
|
|
2465
2560
|
*/
|
|
2466
2561
|
const toMigrationFileSlug = (name) => {
|
|
2467
2562
|
return name.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "migration";
|
|
2468
2563
|
};
|
|
2469
2564
|
/**
|
|
2470
|
-
* Build the source code for a new migration file based on a given class
|
|
2565
|
+
* Build the source code for a new migration file based on a given class
|
|
2471
2566
|
* name, using a template with empty up and down methods.
|
|
2472
|
-
*
|
|
2473
|
-
* @param className
|
|
2474
|
-
* @returns
|
|
2567
|
+
*
|
|
2568
|
+
* @param className
|
|
2569
|
+
* @returns
|
|
2475
2570
|
*/
|
|
2476
2571
|
const buildMigrationSource = (className, extension = "ts") => {
|
|
2477
2572
|
if (extension === "js") return [
|
|
@@ -2508,12 +2603,12 @@ const buildMigrationSource = (className, extension = "ts") => {
|
|
|
2508
2603
|
].join("\n");
|
|
2509
2604
|
};
|
|
2510
2605
|
/**
|
|
2511
|
-
* Generate a new migration file with a given name and options, including
|
|
2606
|
+
* Generate a new migration file with a given name and options, including
|
|
2512
2607
|
* writing the file to disk if specified, and return the details of the generated file.
|
|
2513
|
-
*
|
|
2514
|
-
* @param name
|
|
2515
|
-
* @param options
|
|
2516
|
-
* @returns
|
|
2608
|
+
*
|
|
2609
|
+
* @param name
|
|
2610
|
+
* @param options
|
|
2611
|
+
* @returns
|
|
2517
2612
|
*/
|
|
2518
2613
|
const generateMigrationFile = (name, options = {}) => {
|
|
2519
2614
|
const timestamp = createMigrationTimestamp(/* @__PURE__ */ new Date());
|
|
@@ -2538,10 +2633,10 @@ const generateMigrationFile = (name, options = {}) => {
|
|
|
2538
2633
|
};
|
|
2539
2634
|
/**
|
|
2540
2635
|
* Get the list of schema operations that would be performed by a given migration class when run in a specified direction (up or down), without actually applying them.
|
|
2541
|
-
*
|
|
2636
|
+
*
|
|
2542
2637
|
* @param migration The migration class or instance to analyze.
|
|
2543
2638
|
* @param direction The direction of the migration to plan for ('up' or 'down').
|
|
2544
|
-
* @returns A promise that resolves to an array of schema operations that would be performed.
|
|
2639
|
+
* @returns A promise that resolves to an array of schema operations that would be performed.
|
|
2545
2640
|
*/
|
|
2546
2641
|
const getMigrationPlan = async (migration, direction = "up") => {
|
|
2547
2642
|
const instance = typeof migration === "function" ? new migration() : migration;
|
|
@@ -2576,10 +2671,10 @@ const applyMigrationRollbackToDatabase = async (adapter, migration) => {
|
|
|
2576
2671
|
return { operations };
|
|
2577
2672
|
};
|
|
2578
2673
|
/**
|
|
2579
|
-
* Apply the schema operations defined in a migration to a Prisma schema
|
|
2580
|
-
* file, updating the file on disk if specified, and return the updated
|
|
2674
|
+
* Apply the schema operations defined in a migration to a Prisma schema
|
|
2675
|
+
* file, updating the file on disk if specified, and return the updated
|
|
2581
2676
|
* schema and list of operations applied.
|
|
2582
|
-
*
|
|
2677
|
+
*
|
|
2583
2678
|
* @param migration The migration class or instance to apply.
|
|
2584
2679
|
* @param options Options for applying the migration, including schema path and write flag.
|
|
2585
2680
|
* @returns A promise that resolves to an object containing the updated schema, schema path, and list of operations applied.
|
|
@@ -2618,10 +2713,10 @@ const applyMigrationRollbackToPrismaSchema = async (migration, options = {}) =>
|
|
|
2618
2713
|
};
|
|
2619
2714
|
};
|
|
2620
2715
|
/**
|
|
2621
|
-
* Run a migration by applying its schema operations to a Prisma schema
|
|
2622
|
-
* file, optionally generating Prisma client code and running migrations after
|
|
2716
|
+
* Run a migration by applying its schema operations to a Prisma schema
|
|
2717
|
+
* file, optionally generating Prisma client code and running migrations after
|
|
2623
2718
|
* applying the schema changes.
|
|
2624
|
-
*
|
|
2719
|
+
*
|
|
2625
2720
|
* @param migration The migration class or instance to run.
|
|
2626
2721
|
* @param options Options for running the migration, including schema path, write flag, and Prisma commands.
|
|
2627
2722
|
* @returns A promise that resolves to an object containing the schema path and list of operations applied.
|
|
@@ -3003,8 +3098,8 @@ const normalizePathInput = (paths) => {
|
|
|
3003
3098
|
const normalizeConstructors = (items) => items.flatMap((item) => Array.isArray(item) ? item : [item]).filter(Boolean);
|
|
3004
3099
|
/**
|
|
3005
3100
|
* Register additional runtime discovery paths without replacing configured paths.
|
|
3006
|
-
*
|
|
3007
|
-
* @param paths
|
|
3101
|
+
*
|
|
3102
|
+
* @param paths
|
|
3008
3103
|
*/
|
|
3009
3104
|
const registerPaths = (paths) => {
|
|
3010
3105
|
Object.entries(paths).forEach(([key, value]) => {
|
|
@@ -3013,69 +3108,69 @@ const registerPaths = (paths) => {
|
|
|
3013
3108
|
};
|
|
3014
3109
|
/**
|
|
3015
3110
|
* Register additional runtime discovery paths for migrations without replacing configured paths.
|
|
3016
|
-
*
|
|
3017
|
-
* @param paths
|
|
3018
|
-
* @returns
|
|
3111
|
+
*
|
|
3112
|
+
* @param paths
|
|
3113
|
+
* @returns
|
|
3019
3114
|
*/
|
|
3020
3115
|
const loadMigrationsFrom = (paths) => registerPaths({ migrations: paths });
|
|
3021
3116
|
/**
|
|
3022
3117
|
* Register additional runtime discovery paths for seeders without replacing configured paths.
|
|
3023
|
-
*
|
|
3024
|
-
* @param paths
|
|
3025
|
-
* @returns
|
|
3118
|
+
*
|
|
3119
|
+
* @param paths
|
|
3120
|
+
* @returns
|
|
3026
3121
|
*/
|
|
3027
3122
|
const loadSeedersFrom = (paths) => registerPaths({ seeders: paths });
|
|
3028
3123
|
/**
|
|
3029
3124
|
* Register additional runtime discovery paths for models without replacing configured paths.
|
|
3030
|
-
*
|
|
3031
|
-
* @param paths
|
|
3032
|
-
* @returns
|
|
3125
|
+
*
|
|
3126
|
+
* @param paths
|
|
3127
|
+
* @returns
|
|
3033
3128
|
*/
|
|
3034
3129
|
const loadModelsFrom = (paths) => registerPaths({ models: paths });
|
|
3035
3130
|
/**
|
|
3036
3131
|
* Register additional runtime discovery paths for factories without replacing configured paths.
|
|
3037
|
-
*
|
|
3038
|
-
* @param paths
|
|
3039
|
-
* @returns
|
|
3132
|
+
*
|
|
3133
|
+
* @param paths
|
|
3134
|
+
* @returns
|
|
3040
3135
|
*/
|
|
3041
3136
|
const loadFactoriesFrom = (paths) => registerPaths({ factories: paths });
|
|
3042
3137
|
/**
|
|
3043
3138
|
* Register migration constructors directly without relying on runtime discovery.
|
|
3044
|
-
*
|
|
3045
|
-
* @param migrations
|
|
3139
|
+
*
|
|
3140
|
+
* @param migrations
|
|
3046
3141
|
*/
|
|
3047
3142
|
const registerMigrations = (...migrations) => {
|
|
3048
3143
|
pushUnique(registry.migrations, normalizeConstructors(migrations));
|
|
3049
3144
|
};
|
|
3050
3145
|
/**
|
|
3051
3146
|
* Register seeder constructors directly without relying on runtime discovery.
|
|
3052
|
-
*
|
|
3053
|
-
* @param seeders
|
|
3147
|
+
*
|
|
3148
|
+
* @param seeders
|
|
3054
3149
|
*/
|
|
3055
3150
|
const registerSeeders = (...seeders) => {
|
|
3056
3151
|
pushUnique(registry.seeders, normalizeConstructors(seeders));
|
|
3057
3152
|
};
|
|
3058
3153
|
/**
|
|
3059
3154
|
* Register model constructors directly without relying on runtime discovery.
|
|
3060
|
-
*
|
|
3061
|
-
* @param models
|
|
3155
|
+
*
|
|
3156
|
+
* @param models
|
|
3062
3157
|
*/
|
|
3063
3158
|
const registerModels = (...models) => {
|
|
3064
3159
|
pushUnique(registry.models, normalizeConstructors(models));
|
|
3065
3160
|
};
|
|
3066
3161
|
/**
|
|
3067
3162
|
* Register factory constructors or instances directly without relying on runtime discovery.
|
|
3068
|
-
*
|
|
3069
|
-
* @param factories
|
|
3163
|
+
*
|
|
3164
|
+
* @param factories
|
|
3070
3165
|
*/
|
|
3071
3166
|
const registerFactories = (...factories) => {
|
|
3072
3167
|
pushUnique(registry.factories, normalizeConstructors(factories));
|
|
3073
3168
|
};
|
|
3074
3169
|
/**
|
|
3075
3170
|
* Get registered runtime discovery paths or registered constructors for a specific type.
|
|
3076
|
-
*
|
|
3077
|
-
* @param key
|
|
3078
|
-
* @returns
|
|
3171
|
+
*
|
|
3172
|
+
* @param key
|
|
3173
|
+
* @returns
|
|
3079
3174
|
*/
|
|
3080
3175
|
const getRegisteredPaths = (key) => {
|
|
3081
3176
|
if (key) return [...registry.paths[key]];
|
|
@@ -3088,26 +3183,26 @@ const getRegisteredPaths = (key) => {
|
|
|
3088
3183
|
};
|
|
3089
3184
|
/**
|
|
3090
3185
|
* Get registered migration constructors instances.
|
|
3091
|
-
*
|
|
3092
|
-
* @returns
|
|
3186
|
+
*
|
|
3187
|
+
* @returns
|
|
3093
3188
|
*/
|
|
3094
3189
|
const getRegisteredMigrations = () => [...registry.migrations];
|
|
3095
3190
|
/**
|
|
3096
3191
|
* Get registered seeder constructors instances.
|
|
3097
|
-
*
|
|
3098
|
-
* @returns
|
|
3192
|
+
*
|
|
3193
|
+
* @returns
|
|
3099
3194
|
*/
|
|
3100
3195
|
const getRegisteredSeeders = () => [...registry.seeders];
|
|
3101
3196
|
/**
|
|
3102
3197
|
* Get registered model constructors instances.
|
|
3103
|
-
*
|
|
3104
|
-
* @returns
|
|
3198
|
+
*
|
|
3199
|
+
* @returns
|
|
3105
3200
|
*/
|
|
3106
3201
|
const getRegisteredModels = () => [...registry.models];
|
|
3107
3202
|
/**
|
|
3108
3203
|
* Get registered factory constructors or instances.
|
|
3109
|
-
*
|
|
3110
|
-
* @returns
|
|
3204
|
+
*
|
|
3205
|
+
* @returns
|
|
3111
3206
|
*/
|
|
3112
3207
|
const getRegisteredFactories = () => [...registry.factories];
|
|
3113
3208
|
const resetRuntimeRegistryForTests = () => {
|
|
@@ -3211,9 +3306,9 @@ const mergePathConfig = (paths) => {
|
|
|
3211
3306
|
};
|
|
3212
3307
|
/**
|
|
3213
3308
|
* Merge the feature configuration from the base defaults, user configuration, and provided options.
|
|
3214
|
-
*
|
|
3215
|
-
* @param features
|
|
3216
|
-
* @returns
|
|
3309
|
+
*
|
|
3310
|
+
* @param features
|
|
3311
|
+
* @returns
|
|
3217
3312
|
*/
|
|
3218
3313
|
const mergeFeatureConfig = (features) => {
|
|
3219
3314
|
const defaults = baseConfig.features ?? {};
|
|
@@ -3269,7 +3364,7 @@ const awaitConfiguredModelsRegistration = async () => {
|
|
|
3269
3364
|
};
|
|
3270
3365
|
/**
|
|
3271
3366
|
* Define the ArkORM runtime configuration. This function can be used to provide.
|
|
3272
|
-
*
|
|
3367
|
+
*
|
|
3273
3368
|
* @param config The ArkORM configuration object.
|
|
3274
3369
|
* @returns The same configuration object.
|
|
3275
3370
|
*/
|
|
@@ -3278,10 +3373,10 @@ const defineConfig = (config) => {
|
|
|
3278
3373
|
};
|
|
3279
3374
|
/**
|
|
3280
3375
|
* Bind a database adapter instance to an array of models that support adapter binding.
|
|
3281
|
-
*
|
|
3282
|
-
* @param adapter
|
|
3283
|
-
* @param models
|
|
3284
|
-
* @returns
|
|
3376
|
+
*
|
|
3377
|
+
* @param adapter
|
|
3378
|
+
* @param models
|
|
3379
|
+
* @returns
|
|
3285
3380
|
*/
|
|
3286
3381
|
const bindAdapterToModels = (adapter, models) => {
|
|
3287
3382
|
models.forEach((model) => {
|
|
@@ -3290,10 +3385,10 @@ const bindAdapterToModels = (adapter, models) => {
|
|
|
3290
3385
|
return adapter;
|
|
3291
3386
|
};
|
|
3292
3387
|
/**
|
|
3293
|
-
* Get the user-provided ArkORM configuration.
|
|
3294
|
-
*
|
|
3388
|
+
* Get the user-provided ArkORM configuration.
|
|
3389
|
+
*
|
|
3295
3390
|
* @param key Optional specific configuration key to retrieve. If omitted, the entire configuration object is returned.
|
|
3296
|
-
* @returns The user-provided ArkORM configuration object.
|
|
3391
|
+
* @returns The user-provided ArkORM configuration object.
|
|
3297
3392
|
*/
|
|
3298
3393
|
const getUserConfig = (key) => {
|
|
3299
3394
|
if (key) return userConfig[key];
|
|
@@ -3302,8 +3397,8 @@ const getUserConfig = (key) => {
|
|
|
3302
3397
|
/**
|
|
3303
3398
|
* Configure the ArkORM runtime with the provided runtime client resolver and
|
|
3304
3399
|
* adapter-first options.
|
|
3305
|
-
*
|
|
3306
|
-
* @param client
|
|
3400
|
+
*
|
|
3401
|
+
* @param client
|
|
3307
3402
|
* @param options
|
|
3308
3403
|
*/
|
|
3309
3404
|
const configureArkormRuntime = (client, options = {}) => {
|
|
@@ -3336,7 +3431,7 @@ const configureArkormRuntime = (client, options = {}) => {
|
|
|
3336
3431
|
});
|
|
3337
3432
|
};
|
|
3338
3433
|
/**
|
|
3339
|
-
* Reset the ArkORM runtime configuration.
|
|
3434
|
+
* Reset the ArkORM runtime configuration.
|
|
3340
3435
|
* This is primarily intended for testing purposes.
|
|
3341
3436
|
*/
|
|
3342
3437
|
const resetArkormRuntimeForTests = () => {
|
|
@@ -3361,9 +3456,9 @@ const resetArkormRuntimeForTests = () => {
|
|
|
3361
3456
|
/**
|
|
3362
3457
|
* Resolve a runtime client instance from the provided resolver, which can be either
|
|
3363
3458
|
* a direct client instance or a function that returns a client instance.
|
|
3364
|
-
*
|
|
3365
|
-
* @param resolver
|
|
3366
|
-
* @returns
|
|
3459
|
+
*
|
|
3460
|
+
* @param resolver
|
|
3461
|
+
* @returns
|
|
3367
3462
|
*/
|
|
3368
3463
|
const resolveClient = (resolver) => {
|
|
3369
3464
|
if (!resolver) return void 0;
|
|
@@ -3372,12 +3467,12 @@ const resolveClient = (resolver) => {
|
|
|
3372
3467
|
return client;
|
|
3373
3468
|
};
|
|
3374
3469
|
/**
|
|
3375
|
-
* Resolve and apply the ArkORM configuration from an imported module.
|
|
3470
|
+
* Resolve and apply the ArkORM configuration from an imported module.
|
|
3376
3471
|
* This function checks for a default export and falls back to the module itself, then validates
|
|
3377
3472
|
* the configuration object and applies it to the runtime if valid.
|
|
3378
|
-
*
|
|
3379
|
-
* @param imported
|
|
3380
|
-
* @returns
|
|
3473
|
+
*
|
|
3474
|
+
* @param imported
|
|
3475
|
+
* @returns
|
|
3381
3476
|
*/
|
|
3382
3477
|
const resolveAndApplyConfig = (imported) => {
|
|
3383
3478
|
const config = imported?.default ?? imported;
|
|
@@ -3397,11 +3492,11 @@ const resolveAndApplyConfig = (imported) => {
|
|
|
3397
3492
|
runtimeConfigLoaded = true;
|
|
3398
3493
|
};
|
|
3399
3494
|
/**
|
|
3400
|
-
* Dynamically import a configuration file.
|
|
3495
|
+
* Dynamically import a configuration file.
|
|
3401
3496
|
* A cache-busting query parameter is appended to ensure the latest version is loaded.
|
|
3402
|
-
*
|
|
3403
|
-
* @param configPath
|
|
3404
|
-
* @returns A promise that resolves to the imported configuration module.
|
|
3497
|
+
*
|
|
3498
|
+
* @param configPath
|
|
3499
|
+
* @returns A promise that resolves to the imported configuration module.
|
|
3405
3500
|
*/
|
|
3406
3501
|
const importConfigFile = (configPath) => {
|
|
3407
3502
|
return RuntimeModuleLoader.load(configPath);
|
|
@@ -3421,9 +3516,9 @@ const loadRuntimeConfigSync = () => {
|
|
|
3421
3516
|
return false;
|
|
3422
3517
|
};
|
|
3423
3518
|
/**
|
|
3424
|
-
* Load the ArkORM configuration by searching for configuration files in the
|
|
3519
|
+
* Load the ArkORM configuration by searching for configuration files in the
|
|
3425
3520
|
* current working directory.
|
|
3426
|
-
* @returns
|
|
3521
|
+
* @returns
|
|
3427
3522
|
*/
|
|
3428
3523
|
const loadArkormConfig = async () => {
|
|
3429
3524
|
if (runtimeConfigLoaded) {
|
|
@@ -3454,11 +3549,11 @@ const loadArkormConfig = async () => {
|
|
|
3454
3549
|
await runtimeConfigLoadingPromise;
|
|
3455
3550
|
};
|
|
3456
3551
|
/**
|
|
3457
|
-
* Ensure that the ArkORM configuration is loaded.
|
|
3552
|
+
* Ensure that the ArkORM configuration is loaded.
|
|
3458
3553
|
* This function can be called to trigger the loading process if it hasn't already been initiated.
|
|
3459
3554
|
* If the configuration is already loaded, it will return immediately.
|
|
3460
|
-
*
|
|
3461
|
-
* @returns
|
|
3555
|
+
*
|
|
3556
|
+
* @returns
|
|
3462
3557
|
*/
|
|
3463
3558
|
const ensureArkormConfigLoading = () => {
|
|
3464
3559
|
if (runtimeConfigLoaded) return;
|
|
@@ -3469,10 +3564,10 @@ const getDefaultStubsPath = () => {
|
|
|
3469
3564
|
};
|
|
3470
3565
|
/**
|
|
3471
3566
|
* Get the runtime compatibility client.
|
|
3472
|
-
* This function will trigger the loading of the ArkORM configuration if
|
|
3567
|
+
* This function will trigger the loading of the ArkORM configuration if
|
|
3473
3568
|
* it hasn't already been loaded.
|
|
3474
|
-
*
|
|
3475
|
-
* @returns
|
|
3569
|
+
*
|
|
3570
|
+
* @returns
|
|
3476
3571
|
*/
|
|
3477
3572
|
const getRuntimeClient = () => {
|
|
3478
3573
|
const activeTransactionClient = transactionClientStorage.getStore();
|
|
@@ -3486,8 +3581,8 @@ const getRuntimeClient = () => {
|
|
|
3486
3581
|
const getRuntimePrismaClient = getRuntimeClient;
|
|
3487
3582
|
/**
|
|
3488
3583
|
* Get the currently configured runtime adapter, if any.
|
|
3489
|
-
*
|
|
3490
|
-
* @returns
|
|
3584
|
+
*
|
|
3585
|
+
* @returns
|
|
3491
3586
|
*/
|
|
3492
3587
|
const getRuntimeAdapter = () => {
|
|
3493
3588
|
const activeTransactionAdapter = transactionAdapterStorage.getStore();
|
|
@@ -3564,7 +3659,7 @@ const emitRuntimeDebugEvent = (event) => {
|
|
|
3564
3659
|
/**
|
|
3565
3660
|
* Check if a given value matches Arkorm's query-schema contract
|
|
3566
3661
|
* by verifying the presence of common delegate methods.
|
|
3567
|
-
*
|
|
3662
|
+
*
|
|
3568
3663
|
* @param value The value to check.
|
|
3569
3664
|
* @returns True if the value matches the query-schema contract, false otherwise.
|
|
3570
3665
|
*/
|
|
@@ -3590,7 +3685,7 @@ loadArkormConfig();
|
|
|
3590
3685
|
//#region src/URLDriver.ts
|
|
3591
3686
|
/**
|
|
3592
3687
|
* URLDriver builds pagination URLs from paginator options.
|
|
3593
|
-
*
|
|
3688
|
+
*
|
|
3594
3689
|
* @author Legacy (3m1n3nc3)
|
|
3595
3690
|
* @since 0.1.0
|
|
3596
3691
|
*/
|
|
@@ -3633,7 +3728,7 @@ var URLDriver = class URLDriver {
|
|
|
3633
3728
|
/**
|
|
3634
3729
|
* The LengthAwarePaginator class encapsulates paginated results with full
|
|
3635
3730
|
* metadata including the total result count and last page.
|
|
3636
|
-
*
|
|
3731
|
+
*
|
|
3637
3732
|
* @template T The type of the data being paginated.
|
|
3638
3733
|
* @author Legacy (3m1n3nc3)
|
|
3639
3734
|
* @since 0.1.0
|
|
@@ -3641,7 +3736,7 @@ var URLDriver = class URLDriver {
|
|
|
3641
3736
|
var LengthAwarePaginator = class {
|
|
3642
3737
|
/**
|
|
3643
3738
|
* Creates a new LengthAwarePaginator instance.
|
|
3644
|
-
*
|
|
3739
|
+
*
|
|
3645
3740
|
* @param data The collection of data being paginated.
|
|
3646
3741
|
* @param total The total number of items.
|
|
3647
3742
|
* @param perPage The number of items per page.
|
|
@@ -3686,8 +3781,8 @@ var LengthAwarePaginator = class {
|
|
|
3686
3781
|
}
|
|
3687
3782
|
/**
|
|
3688
3783
|
* Converts the paginator instance to a JSON-serializable object.
|
|
3689
|
-
*
|
|
3690
|
-
* @returns
|
|
3784
|
+
*
|
|
3785
|
+
* @returns
|
|
3691
3786
|
*/
|
|
3692
3787
|
toJSON() {
|
|
3693
3788
|
return {
|
|
@@ -3762,7 +3857,7 @@ var Paginator = class {
|
|
|
3762
3857
|
//#region src/relationship/Relation.ts
|
|
3763
3858
|
/**
|
|
3764
3859
|
* Base class for all relationship types. Not meant to be used directly.
|
|
3765
|
-
*
|
|
3860
|
+
*
|
|
3766
3861
|
* @author Legacy (3m1n3nc3)
|
|
3767
3862
|
* @since 0.1.0
|
|
3768
3863
|
*/
|
|
@@ -3808,7 +3903,7 @@ var Relation = class {
|
|
|
3808
3903
|
}
|
|
3809
3904
|
/**
|
|
3810
3905
|
* Apply a constraint to the relationship query.
|
|
3811
|
-
*
|
|
3906
|
+
*
|
|
3812
3907
|
* @param constraint The constraint function to apply to the query.
|
|
3813
3908
|
* @returns The current relation instance.
|
|
3814
3909
|
*/
|
|
@@ -3912,81 +4007,81 @@ var Relation = class {
|
|
|
3912
4007
|
}
|
|
3913
4008
|
/**
|
|
3914
4009
|
* Adds clause to determine if a column's value is in the past
|
|
3915
|
-
*
|
|
3916
|
-
* @param key
|
|
3917
|
-
* @returns
|
|
4010
|
+
*
|
|
4011
|
+
* @param key
|
|
4012
|
+
* @returns
|
|
3918
4013
|
*/
|
|
3919
4014
|
wherePast(key) {
|
|
3920
4015
|
return this.constrain((query) => query.wherePast(key));
|
|
3921
4016
|
}
|
|
3922
4017
|
/**
|
|
3923
4018
|
* Adds clause to determine if a column's value is in the future
|
|
3924
|
-
*
|
|
3925
|
-
* @param key
|
|
3926
|
-
* @returns
|
|
4019
|
+
*
|
|
4020
|
+
* @param key
|
|
4021
|
+
* @returns
|
|
3927
4022
|
*/
|
|
3928
4023
|
whereFuture(key) {
|
|
3929
4024
|
return this.constrain((query) => query.whereFuture(key));
|
|
3930
4025
|
}
|
|
3931
4026
|
/**
|
|
3932
4027
|
* Adds clause to determine if a column's value is in the past, inclusive of the current date and time
|
|
3933
|
-
*
|
|
3934
|
-
* @param key
|
|
3935
|
-
* @returns
|
|
4028
|
+
*
|
|
4029
|
+
* @param key
|
|
4030
|
+
* @returns
|
|
3936
4031
|
*/
|
|
3937
4032
|
whereNowOrPast(key) {
|
|
3938
4033
|
return this.constrain((query) => query.whereNowOrPast(key));
|
|
3939
4034
|
}
|
|
3940
4035
|
/**
|
|
3941
4036
|
* Adds clause to determine if a column's value is in the future, inclusive of the current date and time
|
|
3942
|
-
*
|
|
3943
|
-
* @param key
|
|
3944
|
-
* @returns
|
|
4037
|
+
*
|
|
4038
|
+
* @param key
|
|
4039
|
+
* @returns
|
|
3945
4040
|
*/
|
|
3946
4041
|
whereNowOrFuture(key) {
|
|
3947
4042
|
return this.constrain((query) => query.whereNowOrFuture(key));
|
|
3948
4043
|
}
|
|
3949
4044
|
/**
|
|
3950
4045
|
* Adds clause to determine if a column's value is today
|
|
3951
|
-
*
|
|
3952
|
-
* @param key
|
|
3953
|
-
* @returns
|
|
4046
|
+
*
|
|
4047
|
+
* @param key
|
|
4048
|
+
* @returns
|
|
3954
4049
|
*/
|
|
3955
4050
|
whereToday(key) {
|
|
3956
4051
|
return this.constrain((query) => query.whereToday(key));
|
|
3957
4052
|
}
|
|
3958
4053
|
/**
|
|
3959
4054
|
* Adds clause to determine if a column's value is before today
|
|
3960
|
-
*
|
|
3961
|
-
* @param key
|
|
3962
|
-
* @returns
|
|
4055
|
+
*
|
|
4056
|
+
* @param key
|
|
4057
|
+
* @returns
|
|
3963
4058
|
*/
|
|
3964
4059
|
whereBeforeToday(key) {
|
|
3965
4060
|
return this.constrain((query) => query.whereBeforeToday(key));
|
|
3966
4061
|
}
|
|
3967
4062
|
/**
|
|
3968
4063
|
* Adds clause to determine if a column's value is after today
|
|
3969
|
-
*
|
|
3970
|
-
* @param key
|
|
3971
|
-
* @returns
|
|
4064
|
+
*
|
|
4065
|
+
* @param key
|
|
4066
|
+
* @returns
|
|
3972
4067
|
*/
|
|
3973
4068
|
whereAfterToday(key) {
|
|
3974
4069
|
return this.constrain((query) => query.whereAfterToday(key));
|
|
3975
4070
|
}
|
|
3976
4071
|
/**
|
|
3977
4072
|
* Adds clause to determine if a column's value is today or before today
|
|
3978
|
-
*
|
|
3979
|
-
* @param key
|
|
3980
|
-
* @returns
|
|
4073
|
+
*
|
|
4074
|
+
* @param key
|
|
4075
|
+
* @returns
|
|
3981
4076
|
*/
|
|
3982
4077
|
whereTodayOrBefore(key) {
|
|
3983
4078
|
return this.constrain((query) => query.whereTodayOrBefore(key));
|
|
3984
4079
|
}
|
|
3985
4080
|
/**
|
|
3986
4081
|
* Adds clause to determine if a column's value is today or after today
|
|
3987
|
-
*
|
|
3988
|
-
* @param key
|
|
3989
|
-
* @returns
|
|
4082
|
+
*
|
|
4083
|
+
* @param key
|
|
4084
|
+
* @returns
|
|
3990
4085
|
*/
|
|
3991
4086
|
whereTodayOrAfter(key) {
|
|
3992
4087
|
return this.constrain((query) => query.whereTodayOrAfter(key));
|
|
@@ -3996,9 +4091,9 @@ var Relation = class {
|
|
|
3996
4091
|
}
|
|
3997
4092
|
/**
|
|
3998
4093
|
* Adds "where exists" SQL clauses.
|
|
3999
|
-
*
|
|
4000
|
-
* @param queryOrCallback
|
|
4001
|
-
* @returns
|
|
4094
|
+
*
|
|
4095
|
+
* @param queryOrCallback
|
|
4096
|
+
* @returns
|
|
4002
4097
|
*/
|
|
4003
4098
|
whereExists(queryOrCallback) {
|
|
4004
4099
|
return this.constrain((query) => query.whereExists(queryOrCallback));
|
|
@@ -4097,107 +4192,107 @@ var Relation = class {
|
|
|
4097
4192
|
}
|
|
4098
4193
|
/**
|
|
4099
4194
|
* Add an OR string contains clause to the relationship query.
|
|
4100
|
-
*
|
|
4101
|
-
* @param key
|
|
4102
|
-
* @param value
|
|
4103
|
-
* @returns
|
|
4195
|
+
*
|
|
4196
|
+
* @param key
|
|
4197
|
+
* @param value
|
|
4198
|
+
* @returns
|
|
4104
4199
|
*/
|
|
4105
4200
|
orWhereLike(key, value) {
|
|
4106
4201
|
return this.constrain((query) => query.orWhereLike(key, value));
|
|
4107
4202
|
}
|
|
4108
4203
|
/**
|
|
4109
4204
|
* Add a negated string contains (NOT LIKE) clause to the relationship query.
|
|
4110
|
-
*
|
|
4111
|
-
* @param key
|
|
4112
|
-
* @param value
|
|
4113
|
-
* @returns
|
|
4205
|
+
*
|
|
4206
|
+
* @param key
|
|
4207
|
+
* @param value
|
|
4208
|
+
* @returns
|
|
4114
4209
|
*/
|
|
4115
4210
|
whereNotLike(key, value) {
|
|
4116
4211
|
return this.constrain((query) => query.whereNotLike(key, value));
|
|
4117
4212
|
}
|
|
4118
4213
|
/**
|
|
4119
4214
|
* Add an OR negated string contains (NOT LIKE) clause to the relationship query.
|
|
4120
|
-
*
|
|
4121
|
-
* @param key
|
|
4122
|
-
* @param value
|
|
4123
|
-
* @returns
|
|
4215
|
+
*
|
|
4216
|
+
* @param key
|
|
4217
|
+
* @param value
|
|
4218
|
+
* @returns
|
|
4124
4219
|
*/
|
|
4125
4220
|
orWhereNotLike(key, value) {
|
|
4126
4221
|
return this.constrain((query) => query.orWhereNotLike(key, value));
|
|
4127
4222
|
}
|
|
4128
4223
|
/**
|
|
4129
4224
|
* Add a JSON containment clause to the relationship query.
|
|
4130
|
-
*
|
|
4131
|
-
* @param key
|
|
4132
|
-
* @param value
|
|
4133
|
-
* @returns
|
|
4225
|
+
*
|
|
4226
|
+
* @param key
|
|
4227
|
+
* @param value
|
|
4228
|
+
* @returns
|
|
4134
4229
|
*/
|
|
4135
4230
|
whereJsonContains(column, value) {
|
|
4136
4231
|
return this.constrain((query) => query.whereJsonContains(column, value));
|
|
4137
4232
|
}
|
|
4138
4233
|
/**
|
|
4139
4234
|
* OR variant of whereJsonContains().
|
|
4140
|
-
*
|
|
4141
|
-
* @param column
|
|
4142
|
-
* @param value
|
|
4143
|
-
* @returns
|
|
4235
|
+
*
|
|
4236
|
+
* @param column
|
|
4237
|
+
* @param value
|
|
4238
|
+
* @returns
|
|
4144
4239
|
*/
|
|
4145
4240
|
orWhereJsonContains(column, value) {
|
|
4146
4241
|
return this.constrain((query) => query.orWhereJsonContains(column, value));
|
|
4147
4242
|
}
|
|
4148
4243
|
/**
|
|
4149
4244
|
* Add a negated JSON containment clause to the relationship query.
|
|
4150
|
-
*
|
|
4151
|
-
* @param column
|
|
4152
|
-
* @param value
|
|
4153
|
-
* @returns
|
|
4245
|
+
*
|
|
4246
|
+
* @param column
|
|
4247
|
+
* @param value
|
|
4248
|
+
* @returns
|
|
4154
4249
|
*/
|
|
4155
4250
|
whereJsonDoesntContain(column, value) {
|
|
4156
4251
|
return this.constrain((query) => query.whereJsonDoesntContain(column, value));
|
|
4157
4252
|
}
|
|
4158
4253
|
/**
|
|
4159
4254
|
* OR variant of whereJsonDoesntContain().
|
|
4160
|
-
*
|
|
4161
|
-
* @param column
|
|
4162
|
-
* @param value
|
|
4163
|
-
* @returns
|
|
4255
|
+
*
|
|
4256
|
+
* @param column
|
|
4257
|
+
* @param value
|
|
4258
|
+
* @returns
|
|
4164
4259
|
*/
|
|
4165
4260
|
orWhereJsonDoesntContain(column, value) {
|
|
4166
4261
|
return this.constrain((query) => query.orWhereJsonDoesntContain(column, value));
|
|
4167
4262
|
}
|
|
4168
4263
|
/**
|
|
4169
4264
|
* Add a JSON key-existence clause to the relationship query.
|
|
4170
|
-
*
|
|
4171
|
-
* @param column
|
|
4172
|
-
* @param value
|
|
4173
|
-
* @returns
|
|
4265
|
+
*
|
|
4266
|
+
* @param column
|
|
4267
|
+
* @param value
|
|
4268
|
+
* @returns
|
|
4174
4269
|
*/
|
|
4175
4270
|
whereJsonContainsKey(column) {
|
|
4176
4271
|
return this.constrain((query) => query.whereJsonContainsKey(column));
|
|
4177
4272
|
}
|
|
4178
4273
|
/**
|
|
4179
4274
|
* OR variant of whereJsonContainsKey().
|
|
4180
|
-
*
|
|
4181
|
-
* @param column
|
|
4182
|
-
* @returns
|
|
4275
|
+
*
|
|
4276
|
+
* @param column
|
|
4277
|
+
* @returns
|
|
4183
4278
|
*/
|
|
4184
4279
|
orWhereJsonContainsKey(column) {
|
|
4185
4280
|
return this.constrain((query) => query.orWhereJsonContainsKey(column));
|
|
4186
4281
|
}
|
|
4187
4282
|
/**
|
|
4188
4283
|
* Add a negated JSON key-existence clause to the relationship query.
|
|
4189
|
-
*
|
|
4190
|
-
* @param column
|
|
4191
|
-
* @returns
|
|
4284
|
+
*
|
|
4285
|
+
* @param column
|
|
4286
|
+
* @returns
|
|
4192
4287
|
*/
|
|
4193
4288
|
whereJsonDoesntContainKey(column) {
|
|
4194
4289
|
return this.constrain((query) => query.whereJsonDoesntContainKey(column));
|
|
4195
4290
|
}
|
|
4196
4291
|
/**
|
|
4197
4292
|
* OR variant of whereJsonDoesntContainKey().
|
|
4198
|
-
*
|
|
4199
|
-
* @param column
|
|
4200
|
-
* @returns
|
|
4293
|
+
*
|
|
4294
|
+
* @param column
|
|
4295
|
+
* @returns
|
|
4201
4296
|
*/
|
|
4202
4297
|
orWhereJsonDoesntContainKey(column) {
|
|
4203
4298
|
return this.constrain((query) => query.orWhereJsonDoesntContainKey(column));
|
|
@@ -4210,18 +4305,18 @@ var Relation = class {
|
|
|
4210
4305
|
}
|
|
4211
4306
|
/**
|
|
4212
4307
|
* Add a JSON array overlap clause to the relationship query.
|
|
4213
|
-
*
|
|
4214
|
-
* @param column
|
|
4215
|
-
* @param value
|
|
4308
|
+
*
|
|
4309
|
+
* @param column
|
|
4310
|
+
* @param value
|
|
4216
4311
|
*/
|
|
4217
4312
|
whereJsonOverlaps(column, value) {
|
|
4218
4313
|
return this.constrain((query) => query.whereJsonOverlaps(column, value));
|
|
4219
4314
|
}
|
|
4220
4315
|
/**
|
|
4221
4316
|
* OR variant of whereJsonOverlaps().
|
|
4222
|
-
*
|
|
4223
|
-
* @param column
|
|
4224
|
-
* @param value
|
|
4317
|
+
*
|
|
4318
|
+
* @param column
|
|
4319
|
+
* @param value
|
|
4225
4320
|
*/
|
|
4226
4321
|
orWhereJsonOverlaps(column, value) {
|
|
4227
4322
|
return this.constrain((query) => query.orWhereJsonOverlaps(column, value));
|
|
@@ -4448,9 +4543,9 @@ var Relation = class {
|
|
|
4448
4543
|
}
|
|
4449
4544
|
/**
|
|
4450
4545
|
* Apply the defined constraint to the given query, if any.
|
|
4451
|
-
*
|
|
4546
|
+
*
|
|
4452
4547
|
* @param query The query builder instance to apply the constraint to.
|
|
4453
|
-
*
|
|
4548
|
+
*
|
|
4454
4549
|
* @returns The query builder instance with the constraint applied, if any.
|
|
4455
4550
|
*/
|
|
4456
4551
|
applyConstraint(query) {
|
|
@@ -4477,18 +4572,18 @@ var Relation = class {
|
|
|
4477
4572
|
}
|
|
4478
4573
|
/**
|
|
4479
4574
|
* Execute the relationship query and return the first related model or throw an error if not found.
|
|
4480
|
-
*
|
|
4481
|
-
* @returns
|
|
4575
|
+
*
|
|
4576
|
+
* @returns
|
|
4482
4577
|
*/
|
|
4483
4578
|
async firstOrFail() {
|
|
4484
4579
|
return (await this.getQuery()).firstOrFail();
|
|
4485
4580
|
}
|
|
4486
4581
|
/**
|
|
4487
|
-
* Execute the relationship query and return the first related model or the result of
|
|
4582
|
+
* Execute the relationship query and return the first related model or the result of
|
|
4488
4583
|
* the callback if not found.
|
|
4489
|
-
*
|
|
4490
|
-
* @param callback
|
|
4491
|
-
* @returns
|
|
4584
|
+
*
|
|
4585
|
+
* @param callback
|
|
4586
|
+
* @returns
|
|
4492
4587
|
*/
|
|
4493
4588
|
async firstOr(callback) {
|
|
4494
4589
|
const result = await this.first();
|
|
@@ -4524,11 +4619,11 @@ var Relation = class {
|
|
|
4524
4619
|
return !await this.exists();
|
|
4525
4620
|
}
|
|
4526
4621
|
/**
|
|
4527
|
-
* Create a new instance of the related model with the given attributes and
|
|
4622
|
+
* Create a new instance of the related model with the given attributes and
|
|
4528
4623
|
* relationship creation attributes applied, but do not save it.
|
|
4529
|
-
*
|
|
4530
|
-
* @param attributes
|
|
4531
|
-
* @returns
|
|
4624
|
+
*
|
|
4625
|
+
* @param attributes
|
|
4626
|
+
* @returns
|
|
4532
4627
|
*/
|
|
4533
4628
|
make(attributes = {}) {
|
|
4534
4629
|
const model = this.getRelatedModelConstructor().hydrate(this.mergeCreationAttributes(attributes));
|
|
@@ -4536,31 +4631,31 @@ var Relation = class {
|
|
|
4536
4631
|
return model;
|
|
4537
4632
|
}
|
|
4538
4633
|
/**
|
|
4539
|
-
* Create new instances of the related model with the given attributes and relationship
|
|
4634
|
+
* Create new instances of the related model with the given attributes and relationship
|
|
4540
4635
|
* creation attributes applied, but do not save them.
|
|
4541
|
-
*
|
|
4542
|
-
* @param attributes
|
|
4543
|
-
* @returns
|
|
4636
|
+
*
|
|
4637
|
+
* @param attributes
|
|
4638
|
+
* @returns
|
|
4544
4639
|
*/
|
|
4545
4640
|
makeMany(attributes = []) {
|
|
4546
4641
|
return attributes.map((item) => this.make(item));
|
|
4547
4642
|
}
|
|
4548
4643
|
/**
|
|
4549
|
-
* Create a new instance of the related model with the given attributes and relationship
|
|
4644
|
+
* Create a new instance of the related model with the given attributes and relationship
|
|
4550
4645
|
* creation attributes applied, and save it to the database.
|
|
4551
|
-
*
|
|
4552
|
-
* @param attributes
|
|
4553
|
-
* @returns
|
|
4646
|
+
*
|
|
4647
|
+
* @param attributes
|
|
4648
|
+
* @returns
|
|
4554
4649
|
*/
|
|
4555
4650
|
async create(attributes = {}) {
|
|
4556
4651
|
return await this.getRelatedModelConstructor().query().create(this.mergeCreationAttributes(attributes));
|
|
4557
4652
|
}
|
|
4558
4653
|
/**
|
|
4559
|
-
* Create new instances of the related model with the given attributes and relationship
|
|
4654
|
+
* Create new instances of the related model with the given attributes and relationship
|
|
4560
4655
|
* creation attributes applied, and save them to the database.
|
|
4561
|
-
*
|
|
4562
|
-
* @param values
|
|
4563
|
-
* @returns
|
|
4656
|
+
*
|
|
4657
|
+
* @param values
|
|
4658
|
+
* @returns
|
|
4564
4659
|
*/
|
|
4565
4660
|
async createMany(values = []) {
|
|
4566
4661
|
if (values.length === 0) return [];
|
|
@@ -4568,9 +4663,9 @@ var Relation = class {
|
|
|
4568
4663
|
}
|
|
4569
4664
|
/**
|
|
4570
4665
|
* Save the given model instance by applying relationship creation attributes and calling save() on it.
|
|
4571
|
-
*
|
|
4572
|
-
* @param model
|
|
4573
|
-
* @returns
|
|
4666
|
+
*
|
|
4667
|
+
* @param model
|
|
4668
|
+
* @returns
|
|
4574
4669
|
*/
|
|
4575
4670
|
async save(model) {
|
|
4576
4671
|
const saveable = this.applyCreationAttributesToModel(model);
|
|
@@ -4584,11 +4679,11 @@ var Relation = class {
|
|
|
4584
4679
|
}
|
|
4585
4680
|
}
|
|
4586
4681
|
/**
|
|
4587
|
-
* Save the given model instance by applying relationship creation attributes and
|
|
4682
|
+
* Save the given model instance by applying relationship creation attributes and
|
|
4588
4683
|
* calling saveQuietly() on it if supported, otherwise falling back to save().
|
|
4589
|
-
*
|
|
4590
|
-
* @param model
|
|
4591
|
-
* @returns
|
|
4684
|
+
*
|
|
4685
|
+
* @param model
|
|
4686
|
+
* @returns
|
|
4592
4687
|
*/
|
|
4593
4688
|
async saveQuietly(model) {
|
|
4594
4689
|
const saveable = this.applyCreationAttributesToModel(model);
|
|
@@ -4606,21 +4701,21 @@ var Relation = class {
|
|
|
4606
4701
|
return error instanceof Error && (error.name === "ModelNotFoundException" || error.message.includes("Record not found"));
|
|
4607
4702
|
}
|
|
4608
4703
|
/**
|
|
4609
|
-
* Create new instances of the related model with the given attributes and
|
|
4704
|
+
* Create new instances of the related model with the given attributes and
|
|
4610
4705
|
* relationship * creation attributes applied, and save them to the database.
|
|
4611
|
-
*
|
|
4612
|
-
* @param models
|
|
4613
|
-
* @returns
|
|
4706
|
+
*
|
|
4707
|
+
* @param models
|
|
4708
|
+
* @returns
|
|
4614
4709
|
*/
|
|
4615
4710
|
async saveMany(models = []) {
|
|
4616
4711
|
return await Promise.all(models.map(async (model) => await this.save(model)));
|
|
4617
4712
|
}
|
|
4618
4713
|
/**
|
|
4619
|
-
* Create new instances of the related model with the given attributes and relationship
|
|
4714
|
+
* Create new instances of the related model with the given attributes and relationship
|
|
4620
4715
|
* creation attributes applied, and save them to the database.
|
|
4621
|
-
*
|
|
4622
|
-
* @param models
|
|
4623
|
-
* @returns
|
|
4716
|
+
*
|
|
4717
|
+
* @param models
|
|
4718
|
+
* @returns
|
|
4624
4719
|
*/
|
|
4625
4720
|
async saveManyQuietly(models = []) {
|
|
4626
4721
|
return await Promise.all(models.map(async (model) => await this.saveQuietly(model)));
|
|
@@ -4644,10 +4739,10 @@ var Relation = class {
|
|
|
4644
4739
|
}
|
|
4645
4740
|
/**
|
|
4646
4741
|
* Find the first related model by a specific key and value, or create a new instance if not found.
|
|
4647
|
-
*
|
|
4648
|
-
* @param attributes
|
|
4649
|
-
* @param values
|
|
4650
|
-
* @returns
|
|
4742
|
+
*
|
|
4743
|
+
* @param attributes
|
|
4744
|
+
* @param values
|
|
4745
|
+
* @returns
|
|
4651
4746
|
*/
|
|
4652
4747
|
async firstOrNew(attributes, values = {}) {
|
|
4653
4748
|
const found = await (await this.getQuery()).clone().where(attributes).first();
|
|
@@ -4658,12 +4753,12 @@ var Relation = class {
|
|
|
4658
4753
|
});
|
|
4659
4754
|
}
|
|
4660
4755
|
/**
|
|
4661
|
-
* Find the first related model by a specific key and value, or create and save a new instance
|
|
4756
|
+
* Find the first related model by a specific key and value, or create and save a new instance
|
|
4662
4757
|
* if not found.
|
|
4663
|
-
*
|
|
4664
|
-
* @param attributes
|
|
4665
|
-
* @param values
|
|
4666
|
-
* @returns
|
|
4758
|
+
*
|
|
4759
|
+
* @param attributes
|
|
4760
|
+
* @param values
|
|
4761
|
+
* @returns
|
|
4667
4762
|
*/
|
|
4668
4763
|
async firstOrCreate(attributes, values = {}) {
|
|
4669
4764
|
const found = await (await this.getQuery()).clone().where(attributes).first();
|
|
@@ -4674,12 +4769,12 @@ var Relation = class {
|
|
|
4674
4769
|
});
|
|
4675
4770
|
}
|
|
4676
4771
|
/**
|
|
4677
|
-
* Find the first related model by a specific key and value, update the first matching record with
|
|
4772
|
+
* Find the first related model by a specific key and value, update the first matching record with
|
|
4678
4773
|
* the given values, or create and save a new instance if no matching record is found.
|
|
4679
|
-
*
|
|
4680
|
-
* @param attributes
|
|
4681
|
-
* @param values
|
|
4682
|
-
* @returns
|
|
4774
|
+
*
|
|
4775
|
+
* @param attributes
|
|
4776
|
+
* @param values
|
|
4777
|
+
* @returns
|
|
4683
4778
|
*/
|
|
4684
4779
|
async updateOrCreate(attributes, values = {}) {
|
|
4685
4780
|
const query = await this.getQuery();
|
|
@@ -4693,35 +4788,35 @@ var Relation = class {
|
|
|
4693
4788
|
return await query.clone().where(attributes).update(values);
|
|
4694
4789
|
}
|
|
4695
4790
|
/**
|
|
4696
|
-
* Find related models by specific attributes, update matching records with the given values, or
|
|
4791
|
+
* Find related models by specific attributes, update matching records with the given values, or
|
|
4697
4792
|
* create and save new instances if no matching records are found.
|
|
4698
|
-
*
|
|
4699
|
-
* @param values
|
|
4700
|
-
* @param uniqueBy
|
|
4701
|
-
* @param update
|
|
4702
|
-
* @returns
|
|
4793
|
+
*
|
|
4794
|
+
* @param values
|
|
4795
|
+
* @param uniqueBy
|
|
4796
|
+
* @param update
|
|
4797
|
+
* @returns
|
|
4703
4798
|
*/
|
|
4704
4799
|
async upsert(values, uniqueBy, update = null) {
|
|
4705
4800
|
return await (await this.getQuery()).upsert(values.map((value) => this.mergeCreationAttributes(value)), uniqueBy, update);
|
|
4706
4801
|
}
|
|
4707
4802
|
/**
|
|
4708
4803
|
* Paginate the relationship query results.
|
|
4709
|
-
*
|
|
4710
|
-
* @param perPage
|
|
4711
|
-
* @param page
|
|
4712
|
-
* @param options
|
|
4713
|
-
* @returns
|
|
4804
|
+
*
|
|
4805
|
+
* @param perPage
|
|
4806
|
+
* @param page
|
|
4807
|
+
* @param options
|
|
4808
|
+
* @returns
|
|
4714
4809
|
*/
|
|
4715
4810
|
async paginate(perPage = 15, page, options = {}) {
|
|
4716
4811
|
return (await this.getQuery()).paginate(perPage, page, options);
|
|
4717
4812
|
}
|
|
4718
4813
|
/**
|
|
4719
4814
|
* Paginate the relationship query results without total count optimization.
|
|
4720
|
-
*
|
|
4721
|
-
* @param perPage
|
|
4722
|
-
* @param page
|
|
4723
|
-
* @param options
|
|
4724
|
-
* @returns
|
|
4815
|
+
*
|
|
4816
|
+
* @param perPage
|
|
4817
|
+
* @param page
|
|
4818
|
+
* @param options
|
|
4819
|
+
* @returns
|
|
4725
4820
|
*/
|
|
4726
4821
|
async simplePaginate(perPage = 15, page, options = {}) {
|
|
4727
4822
|
return (await this.getQuery()).simplePaginate(perPage, page, options);
|
|
@@ -4732,7 +4827,7 @@ var Relation = class {
|
|
|
4732
4827
|
//#region src/relationship/BelongsToManyRelation.ts
|
|
4733
4828
|
/**
|
|
4734
4829
|
* Defines a many-to-many relationship.
|
|
4735
|
-
*
|
|
4830
|
+
*
|
|
4736
4831
|
* @author Legacy (3m1n3nc3)
|
|
4737
4832
|
* @since 0.1.0
|
|
4738
4833
|
*/
|
|
@@ -4755,9 +4850,9 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4755
4850
|
}
|
|
4756
4851
|
/**
|
|
4757
4852
|
* Specifies additional pivot columns to include on the related models.
|
|
4758
|
-
*
|
|
4759
|
-
* @param columns The pivot columns to include on the related models.
|
|
4760
|
-
* @returns
|
|
4853
|
+
*
|
|
4854
|
+
* @param columns The pivot columns to include on the related models.
|
|
4855
|
+
* @returns
|
|
4761
4856
|
*/
|
|
4762
4857
|
withPivot(...columns) {
|
|
4763
4858
|
columns.flat().forEach((column) => {
|
|
@@ -4768,9 +4863,9 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4768
4863
|
return this;
|
|
4769
4864
|
}
|
|
4770
4865
|
/**
|
|
4771
|
-
* Specifies that the pivot table contains timestamp columns and optionally
|
|
4866
|
+
* Specifies that the pivot table contains timestamp columns and optionally
|
|
4772
4867
|
* allows customizing the names of those columns.
|
|
4773
|
-
*
|
|
4868
|
+
*
|
|
4774
4869
|
* @param createdAtColumn The name of the "created at" timestamp column.
|
|
4775
4870
|
* @param updatedAtColumn The name of the "updated at" timestamp column.
|
|
4776
4871
|
* @returns The current instance of the relationship.
|
|
@@ -4781,10 +4876,10 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4781
4876
|
return this.withPivot(createdAtColumn, updatedAtColumn);
|
|
4782
4877
|
}
|
|
4783
4878
|
/**
|
|
4784
|
-
* Specifies a custom accessor name for the pivot attributes on the related models.
|
|
4785
|
-
* By default, pivot attributes are accessible via the `pivot` property on the
|
|
4879
|
+
* Specifies a custom accessor name for the pivot attributes on the related models.
|
|
4880
|
+
* By default, pivot attributes are accessible via the `pivot` property on the
|
|
4786
4881
|
* related models.
|
|
4787
|
-
*
|
|
4882
|
+
*
|
|
4788
4883
|
* @param accessor The custom accessor name for the pivot attributes.
|
|
4789
4884
|
* @returns The current instance of the relationship.
|
|
4790
4885
|
*/
|
|
@@ -4796,10 +4891,10 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4796
4891
|
return this;
|
|
4797
4892
|
}
|
|
4798
4893
|
/**
|
|
4799
|
-
* Specifies a custom pivot model to use for the pivot records. The pivot model can
|
|
4800
|
-
* be used to define custom behavior or methods on the pivot records, as well as to
|
|
4894
|
+
* Specifies a custom pivot model to use for the pivot records. The pivot model can
|
|
4895
|
+
* be used to define custom behavior or methods on the pivot records, as well as to
|
|
4801
4896
|
* specify a custom hydration method for the pivot records.
|
|
4802
|
-
*
|
|
4897
|
+
*
|
|
4803
4898
|
* @param pivotModel The custom pivot model to use.
|
|
4804
4899
|
* @returns The current instance of the relationship.
|
|
4805
4900
|
*/
|
|
@@ -4816,20 +4911,20 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4816
4911
|
}
|
|
4817
4912
|
/**
|
|
4818
4913
|
* Adds a "pivot column in" condition to the relationship query.
|
|
4819
|
-
*
|
|
4820
|
-
* @param column
|
|
4821
|
-
* @param values
|
|
4822
|
-
* @returns
|
|
4914
|
+
*
|
|
4915
|
+
* @param column
|
|
4916
|
+
* @param values
|
|
4917
|
+
* @returns
|
|
4823
4918
|
*/
|
|
4824
4919
|
wherePivotNotIn(column, values) {
|
|
4825
4920
|
return this.addPivotWhere(this.makePivotComparison(column, "not-in", values));
|
|
4826
4921
|
}
|
|
4827
4922
|
/**
|
|
4828
4923
|
* Adds a "pivot column between" condition to the relationship query.
|
|
4829
|
-
*
|
|
4830
|
-
* @param column
|
|
4831
|
-
* @param range
|
|
4832
|
-
* @returns
|
|
4924
|
+
*
|
|
4925
|
+
* @param column
|
|
4926
|
+
* @param range
|
|
4927
|
+
* @returns
|
|
4833
4928
|
*/
|
|
4834
4929
|
wherePivotBetween(column, range) {
|
|
4835
4930
|
return this.addPivotWhere({
|
|
@@ -4840,10 +4935,10 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4840
4935
|
}
|
|
4841
4936
|
/**
|
|
4842
4937
|
* Adds a "pivot column not between" condition to the relationship query.
|
|
4843
|
-
*
|
|
4844
|
-
* @param column
|
|
4845
|
-
* @param range
|
|
4846
|
-
* @returns
|
|
4938
|
+
*
|
|
4939
|
+
* @param column
|
|
4940
|
+
* @param range
|
|
4941
|
+
* @returns
|
|
4847
4942
|
*/
|
|
4848
4943
|
wherePivotNotBetween(column, range) {
|
|
4849
4944
|
return this.addPivotWhere({
|
|
@@ -4857,18 +4952,18 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4857
4952
|
}
|
|
4858
4953
|
/**
|
|
4859
4954
|
* Adds a "pivot column is null" condition to the relationship query.
|
|
4860
|
-
*
|
|
4861
|
-
* @param column
|
|
4862
|
-
* @returns
|
|
4955
|
+
*
|
|
4956
|
+
* @param column
|
|
4957
|
+
* @returns
|
|
4863
4958
|
*/
|
|
4864
4959
|
wherePivotNull(column) {
|
|
4865
4960
|
return this.addPivotWhere(this.makePivotComparison(column, "is-null"));
|
|
4866
4961
|
}
|
|
4867
4962
|
/**
|
|
4868
4963
|
* Adds a "pivot column is not null" condition to the relationship query.
|
|
4869
|
-
*
|
|
4870
|
-
* @param column
|
|
4871
|
-
* @returns
|
|
4964
|
+
*
|
|
4965
|
+
* @param column
|
|
4966
|
+
* @returns
|
|
4872
4967
|
*/
|
|
4873
4968
|
wherePivotNotNull(column) {
|
|
4874
4969
|
return this.addPivotWhere(this.makePivotComparison(column, "is-not-null"));
|
|
@@ -5068,9 +5163,9 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5068
5163
|
return rows.length;
|
|
5069
5164
|
}
|
|
5070
5165
|
/**
|
|
5071
|
-
* Creates a new instance of the related model with the given attributes and attaches
|
|
5166
|
+
* Creates a new instance of the related model with the given attributes and attaches
|
|
5072
5167
|
* pivot attributes if pivot attributes should be included.
|
|
5073
|
-
*
|
|
5168
|
+
*
|
|
5074
5169
|
* @param attributes The attributes to initialize the related model with.
|
|
5075
5170
|
* @returns A new instance of the related model.
|
|
5076
5171
|
*/
|
|
@@ -5078,10 +5173,10 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5078
5173
|
return this.related.hydrate(attributes);
|
|
5079
5174
|
}
|
|
5080
5175
|
/**
|
|
5081
|
-
* Creates a new related model record with the given attributes, creates a pivot record
|
|
5082
|
-
* with the given pivot attributes, and attaches pivot attributes if pivot attributes
|
|
5176
|
+
* Creates a new related model record with the given attributes, creates a pivot record
|
|
5177
|
+
* with the given pivot attributes, and attaches pivot attributes if pivot attributes
|
|
5083
5178
|
* should be included.
|
|
5084
|
-
*
|
|
5179
|
+
*
|
|
5085
5180
|
* @param attributes The attributes to initialize the related model with.
|
|
5086
5181
|
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
5087
5182
|
* @returns A new instance of the related model with pivot attributes attached.
|
|
@@ -5093,10 +5188,10 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5093
5188
|
return this.attachPivotToSingleResult(related, pivotRow);
|
|
5094
5189
|
}
|
|
5095
5190
|
/**
|
|
5096
|
-
* Saves a related model record, creates a pivot record with the given pivot attributes
|
|
5097
|
-
* if the related model was not previously persisted, and attaches pivot attributes if
|
|
5191
|
+
* Saves a related model record, creates a pivot record with the given pivot attributes
|
|
5192
|
+
* if the related model was not previously persisted, and attaches pivot attributes if
|
|
5098
5193
|
* pivot attributes should be included.
|
|
5099
|
-
*
|
|
5194
|
+
*
|
|
5100
5195
|
* @param related The related model instance to save.
|
|
5101
5196
|
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
5102
5197
|
* @returns A new instance of the related model with pivot attributes attached.
|
|
@@ -5116,9 +5211,9 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5116
5211
|
return this.attachPivotToSingleResult(persisted, pivotRow);
|
|
5117
5212
|
}
|
|
5118
5213
|
/**
|
|
5119
|
-
* Attaches one or more related model records to the parent model by creating pivot
|
|
5214
|
+
* Attaches one or more related model records to the parent model by creating pivot
|
|
5120
5215
|
* records with the given pivot attributes if pivot attributes should be included.
|
|
5121
|
-
*
|
|
5216
|
+
*
|
|
5122
5217
|
* @param related The related model instance(s) to attach.
|
|
5123
5218
|
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
5124
5219
|
* @returns The number of related model records attached.
|
|
@@ -5201,7 +5296,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5201
5296
|
}
|
|
5202
5297
|
/**
|
|
5203
5298
|
* Creates a pivot record from a row of data.
|
|
5204
|
-
*
|
|
5299
|
+
*
|
|
5205
5300
|
* @param row The row of data containing pivot attributes.
|
|
5206
5301
|
* @returns The pivot record.
|
|
5207
5302
|
*/
|
|
@@ -5216,10 +5311,10 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5216
5311
|
}
|
|
5217
5312
|
/**
|
|
5218
5313
|
* Attaches pivot attributes to the related models if pivot attributes should be included.
|
|
5219
|
-
*
|
|
5220
|
-
* @param results
|
|
5221
|
-
* @param pivotRows
|
|
5222
|
-
* @returns
|
|
5314
|
+
*
|
|
5315
|
+
* @param results
|
|
5316
|
+
* @param pivotRows
|
|
5317
|
+
* @returns
|
|
5223
5318
|
*/
|
|
5224
5319
|
attachPivotToResults(results, pivotRows) {
|
|
5225
5320
|
if (!this.shouldAttachPivotAttributes()) return results;
|
|
@@ -5311,8 +5406,8 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5311
5406
|
}
|
|
5312
5407
|
/**
|
|
5313
5408
|
* Fetches the related models for this relationship.
|
|
5314
|
-
*
|
|
5315
|
-
* @returns
|
|
5409
|
+
*
|
|
5410
|
+
* @returns
|
|
5316
5411
|
*/
|
|
5317
5412
|
async getResults() {
|
|
5318
5413
|
return (await this.getQuery()).get();
|
|
@@ -5323,7 +5418,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5323
5418
|
//#region src/relationship/SingleResultRelation.ts
|
|
5324
5419
|
/**
|
|
5325
5420
|
* Base class for relationships that resolve to a single related model.
|
|
5326
|
-
*
|
|
5421
|
+
*
|
|
5327
5422
|
* @author Legacy (3m1n3nc3)
|
|
5328
5423
|
* @since 1.3.0
|
|
5329
5424
|
*/
|
|
@@ -5335,7 +5430,7 @@ var SingleResultRelation = class extends Relation {
|
|
|
5335
5430
|
}
|
|
5336
5431
|
/**
|
|
5337
5432
|
* Defines a default value to return when the relationship does not find a related model.
|
|
5338
|
-
*
|
|
5433
|
+
*
|
|
5339
5434
|
* @param value The default value or a callback that returns the default value.
|
|
5340
5435
|
* @returns The current instance for method chaining.
|
|
5341
5436
|
*/
|
|
@@ -5355,7 +5450,7 @@ var SingleResultRelation = class extends Relation {
|
|
|
5355
5450
|
//#region src/relationship/BelongsToRelation.ts
|
|
5356
5451
|
/**
|
|
5357
5452
|
* Defines an inverse one-to-one or many relationship.
|
|
5358
|
-
*
|
|
5453
|
+
*
|
|
5359
5454
|
* @author Legacy (3m1n3nc3)
|
|
5360
5455
|
* @since 0.1.0
|
|
5361
5456
|
*/
|
|
@@ -5384,8 +5479,8 @@ var BelongsToRelation = class extends SingleResultRelation {
|
|
|
5384
5479
|
}
|
|
5385
5480
|
/**
|
|
5386
5481
|
* Fetches the related models for this relationship.
|
|
5387
|
-
*
|
|
5388
|
-
* @returns
|
|
5482
|
+
*
|
|
5483
|
+
* @returns
|
|
5389
5484
|
*/
|
|
5390
5485
|
async getResults() {
|
|
5391
5486
|
return await (await this.getQuery()).first() ?? this.resolveDefaultResult();
|
|
@@ -5396,7 +5491,7 @@ var BelongsToRelation = class extends SingleResultRelation {
|
|
|
5396
5491
|
//#region src/relationship/HasManyRelation.ts
|
|
5397
5492
|
/**
|
|
5398
5493
|
* Defines a one-to-many relationship.
|
|
5399
|
-
*
|
|
5494
|
+
*
|
|
5400
5495
|
* @author Legacy (3m1n3nc3)
|
|
5401
5496
|
* @since 0.1.0
|
|
5402
5497
|
*/
|
|
@@ -5430,8 +5525,8 @@ var HasManyRelation = class extends Relation {
|
|
|
5430
5525
|
}
|
|
5431
5526
|
/**
|
|
5432
5527
|
* Fetches the related models for this relationship.
|
|
5433
|
-
*
|
|
5434
|
-
* @returns
|
|
5528
|
+
*
|
|
5529
|
+
* @returns
|
|
5435
5530
|
*/
|
|
5436
5531
|
async getResults() {
|
|
5437
5532
|
return (await this.getQuery()).get();
|
|
@@ -5441,9 +5536,9 @@ var HasManyRelation = class extends Relation {
|
|
|
5441
5536
|
//#endregion
|
|
5442
5537
|
//#region src/relationship/HasManyThroughRelation.ts
|
|
5443
5538
|
/**
|
|
5444
|
-
* Defines a has-many-through relationship, which provides a convenient way to access
|
|
5445
|
-
* distant relations via an intermediate relation.
|
|
5446
|
-
*
|
|
5539
|
+
* Defines a has-many-through relationship, which provides a convenient way to access
|
|
5540
|
+
* distant relations via an intermediate relation.
|
|
5541
|
+
*
|
|
5447
5542
|
* @author Legacy (3m1n3nc3)
|
|
5448
5543
|
* @since 0.1.0
|
|
5449
5544
|
*/
|
|
@@ -5492,8 +5587,8 @@ var HasManyThroughRelation = class extends Relation {
|
|
|
5492
5587
|
}
|
|
5493
5588
|
/**
|
|
5494
5589
|
* Fetches the related models for this relationship.
|
|
5495
|
-
*
|
|
5496
|
-
* @returns
|
|
5590
|
+
*
|
|
5591
|
+
* @returns
|
|
5497
5592
|
*/
|
|
5498
5593
|
async getResults() {
|
|
5499
5594
|
return (await this.getQuery()).get();
|
|
@@ -5504,7 +5599,7 @@ var HasManyThroughRelation = class extends Relation {
|
|
|
5504
5599
|
//#region src/relationship/HasOneRelation.ts
|
|
5505
5600
|
/**
|
|
5506
5601
|
* Represents a "has one" relationship between two models.
|
|
5507
|
-
*
|
|
5602
|
+
*
|
|
5508
5603
|
* @author Legacy (3m1n3nc3)
|
|
5509
5604
|
* @since 0.1.0
|
|
5510
5605
|
*/
|
|
@@ -5536,8 +5631,8 @@ var HasOneRelation = class extends SingleResultRelation {
|
|
|
5536
5631
|
}
|
|
5537
5632
|
/**
|
|
5538
5633
|
* Fetches the related models for this relationship.
|
|
5539
|
-
*
|
|
5540
|
-
* @returns
|
|
5634
|
+
*
|
|
5635
|
+
* @returns
|
|
5541
5636
|
*/
|
|
5542
5637
|
async getResults() {
|
|
5543
5638
|
return await (await this.getQuery()).first() ?? this.resolveDefaultResult();
|
|
@@ -5547,9 +5642,9 @@ var HasOneRelation = class extends SingleResultRelation {
|
|
|
5547
5642
|
//#endregion
|
|
5548
5643
|
//#region src/relationship/HasOneThroughRelation.ts
|
|
5549
5644
|
/**
|
|
5550
|
-
* Represents a "has one through" relationship, where the parent model is related
|
|
5645
|
+
* Represents a "has one through" relationship, where the parent model is related
|
|
5551
5646
|
* to exactly one instance of the related model through an intermediate model.
|
|
5552
|
-
*
|
|
5647
|
+
*
|
|
5553
5648
|
* @author Legacy (3m1n3nc3)
|
|
5554
5649
|
* @since 0.1.0
|
|
5555
5650
|
*/
|
|
@@ -5597,8 +5692,8 @@ var HasOneThroughRelation = class extends SingleResultRelation {
|
|
|
5597
5692
|
}
|
|
5598
5693
|
/**
|
|
5599
5694
|
* Fetches the related models for this relationship.
|
|
5600
|
-
*
|
|
5601
|
-
* @returns
|
|
5695
|
+
*
|
|
5696
|
+
* @returns
|
|
5602
5697
|
*/
|
|
5603
5698
|
async getResults() {
|
|
5604
5699
|
return await (await this.getQuery()).first() ?? this.resolveDefaultResult();
|
|
@@ -5608,8 +5703,8 @@ var HasOneThroughRelation = class extends SingleResultRelation {
|
|
|
5608
5703
|
//#endregion
|
|
5609
5704
|
//#region src/relationship/MorphManyRelation.ts
|
|
5610
5705
|
/**
|
|
5611
|
-
* Defines a polymorphic one-to-many relationship.
|
|
5612
|
-
*
|
|
5706
|
+
* Defines a polymorphic one-to-many relationship.
|
|
5707
|
+
*
|
|
5613
5708
|
* @author Legacy (3m1n3nc3)
|
|
5614
5709
|
* @since 0.1.0
|
|
5615
5710
|
*/
|
|
@@ -5654,8 +5749,8 @@ var MorphManyRelation = class extends Relation {
|
|
|
5654
5749
|
}
|
|
5655
5750
|
/**
|
|
5656
5751
|
* Fetches the related models for this relationship.
|
|
5657
|
-
*
|
|
5658
|
-
* @returns
|
|
5752
|
+
*
|
|
5753
|
+
* @returns
|
|
5659
5754
|
*/
|
|
5660
5755
|
async getResults() {
|
|
5661
5756
|
return (await this.getQuery()).get();
|
|
@@ -5666,7 +5761,7 @@ var MorphManyRelation = class extends Relation {
|
|
|
5666
5761
|
//#region src/relationship/MorphOneRelation.ts
|
|
5667
5762
|
/**
|
|
5668
5763
|
* Defines a polymorphic one-to-one relationship.
|
|
5669
|
-
*
|
|
5764
|
+
*
|
|
5670
5765
|
* @author Legacy (3m1n3nc3)
|
|
5671
5766
|
* @since 0.1.0
|
|
5672
5767
|
*/
|
|
@@ -5709,8 +5804,8 @@ var MorphOneRelation = class extends SingleResultRelation {
|
|
|
5709
5804
|
}
|
|
5710
5805
|
/**
|
|
5711
5806
|
* Fetches the related models for this relationship.
|
|
5712
|
-
*
|
|
5713
|
-
* @returns
|
|
5807
|
+
*
|
|
5808
|
+
* @returns
|
|
5714
5809
|
*/
|
|
5715
5810
|
async getResults() {
|
|
5716
5811
|
return await (await this.getQuery()).first() ?? this.resolveDefaultResult();
|
|
@@ -5720,8 +5815,8 @@ var MorphOneRelation = class extends SingleResultRelation {
|
|
|
5720
5815
|
//#endregion
|
|
5721
5816
|
//#region src/relationship/MorphToManyRelation.ts
|
|
5722
5817
|
/**
|
|
5723
|
-
* Defines a polymorphic many-to-many relationship.
|
|
5724
|
-
*
|
|
5818
|
+
* Defines a polymorphic many-to-many relationship.
|
|
5819
|
+
*
|
|
5725
5820
|
* @author Legacy (3m1n3nc3)
|
|
5726
5821
|
* @since 0.1.0
|
|
5727
5822
|
*/
|
|
@@ -5784,8 +5879,8 @@ var MorphToManyRelation = class extends Relation {
|
|
|
5784
5879
|
}
|
|
5785
5880
|
/**
|
|
5786
5881
|
* Fetches the related models for this relationship.
|
|
5787
|
-
*
|
|
5788
|
-
* @returns
|
|
5882
|
+
*
|
|
5883
|
+
* @returns
|
|
5789
5884
|
*/
|
|
5790
5885
|
async getResults() {
|
|
5791
5886
|
return (await this.getQuery()).get();
|