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
|
@@ -65,9 +65,9 @@ var RelationResolutionException = class extends ArkormException {
|
|
|
65
65
|
//#endregion
|
|
66
66
|
//#region src/relationship/RelationTableLoader.ts
|
|
67
67
|
/**
|
|
68
|
-
* Utility class responsible for loading data from relation tables, which are used to
|
|
69
|
-
* manage relationships between models in Arkorm.
|
|
70
|
-
*
|
|
68
|
+
* Utility class responsible for loading data from relation tables, which are used to
|
|
69
|
+
* manage relationships between models in Arkorm.
|
|
70
|
+
*
|
|
71
71
|
* @author Legacy (3m1n3nc3)
|
|
72
72
|
* @since 2.0.0-next.0
|
|
73
73
|
*/
|
|
@@ -113,9 +113,9 @@ var RelationTableLoader = class {
|
|
|
113
113
|
//#endregion
|
|
114
114
|
//#region src/relationship/SetBasedEagerLoader.ts
|
|
115
115
|
/**
|
|
116
|
-
* Utility class responsible for performing set-based eager loading of relationships for
|
|
116
|
+
* Utility class responsible for performing set-based eager loading of relationships for
|
|
117
117
|
* a collection of models.
|
|
118
|
-
*
|
|
118
|
+
*
|
|
119
119
|
* @author Legacy (3m1n3nc3)
|
|
120
120
|
* @since 2.0.0-next.2
|
|
121
121
|
*/
|
|
@@ -125,9 +125,9 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
125
125
|
this.relations = relations;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
|
-
* Performs eager loading of all specified relationships for the set of models.
|
|
129
|
-
*
|
|
130
|
-
* @returns
|
|
128
|
+
* Performs eager loading of all specified relationships for the set of models.
|
|
129
|
+
*
|
|
130
|
+
* @returns
|
|
131
131
|
*/
|
|
132
132
|
async load() {
|
|
133
133
|
if (this.models.length === 0) return;
|
|
@@ -144,9 +144,9 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
144
144
|
await new SetBasedEagerLoader(relatedModels, this.relationTreeToMap(node.children)).load();
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
|
-
* Loads a specific relationship for the set of models based on the relationship name
|
|
147
|
+
* Loads a specific relationship for the set of models based on the relationship name
|
|
148
148
|
* and an optional constraint.
|
|
149
|
-
*
|
|
149
|
+
*
|
|
150
150
|
* @param name The name of the relationship to load.
|
|
151
151
|
* @param constraint An optional constraint to apply to the query.
|
|
152
152
|
* @returns A promise that resolves when the relationship is loaded.
|
|
@@ -187,9 +187,9 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
190
|
-
* Resolves the relation resolver function for a given relationship name by inspecting
|
|
190
|
+
* Resolves the relation resolver function for a given relationship name by inspecting
|
|
191
191
|
* the first model in the set.
|
|
192
|
-
*
|
|
192
|
+
*
|
|
193
193
|
* @param name The name of the relationship to resolve.
|
|
194
194
|
* @returns The relation resolver function or null if not found.
|
|
195
195
|
*/
|
|
@@ -249,7 +249,7 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
249
249
|
}
|
|
250
250
|
/**
|
|
251
251
|
* Loads a "belongs to" relationship for the set of models.
|
|
252
|
-
*
|
|
252
|
+
*
|
|
253
253
|
* @param name The name of the relationship to load.
|
|
254
254
|
* @param resolver The relation resolver function.
|
|
255
255
|
* @param metadata The metadata for the relationship.
|
|
@@ -281,12 +281,12 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
281
281
|
});
|
|
282
282
|
}
|
|
283
283
|
/**
|
|
284
|
-
* Loads a "has many" relationship for the set of models.
|
|
285
|
-
*
|
|
286
|
-
* @param name
|
|
287
|
-
* @param metadata
|
|
288
|
-
* @param constraint
|
|
289
|
-
* @returns
|
|
284
|
+
* Loads a "has many" relationship for the set of models.
|
|
285
|
+
*
|
|
286
|
+
* @param name
|
|
287
|
+
* @param metadata
|
|
288
|
+
* @param constraint
|
|
289
|
+
* @returns
|
|
290
290
|
*/
|
|
291
291
|
async loadHasMany(name, metadata, constraint) {
|
|
292
292
|
const keys = this.collectUniqueKeys((model) => model.getAttribute(metadata.localKey));
|
|
@@ -315,12 +315,12 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
315
315
|
});
|
|
316
316
|
}
|
|
317
317
|
/**
|
|
318
|
-
* Loads a "belongs to many" relationship for the set of models.
|
|
319
|
-
*
|
|
320
|
-
* @param name
|
|
321
|
-
* @param metadata
|
|
322
|
-
* @param constraint
|
|
323
|
-
* @returns
|
|
318
|
+
* Loads a "belongs to many" relationship for the set of models.
|
|
319
|
+
*
|
|
320
|
+
* @param name
|
|
321
|
+
* @param metadata
|
|
322
|
+
* @param constraint
|
|
323
|
+
* @returns
|
|
324
324
|
*/
|
|
325
325
|
async loadBelongsToMany(name, metadata, constraint) {
|
|
326
326
|
const parentKeys = this.collectUniqueKeys((model) => model.getAttribute(metadata.parentKey));
|
|
@@ -415,12 +415,12 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
415
415
|
}
|
|
416
416
|
/**
|
|
417
417
|
* Loads a "belongs to many" relationship for the set of models.
|
|
418
|
-
*
|
|
419
|
-
* @param name
|
|
420
|
-
* @param resolver
|
|
421
|
-
* @param metadata
|
|
422
|
-
* @param constraint
|
|
423
|
-
* @returns
|
|
418
|
+
*
|
|
419
|
+
* @param name
|
|
420
|
+
* @param resolver
|
|
421
|
+
* @param metadata
|
|
422
|
+
* @param constraint
|
|
423
|
+
* @returns
|
|
424
424
|
*/
|
|
425
425
|
async loadHasOne(name, resolver, metadata, constraint) {
|
|
426
426
|
const keys = this.collectUniqueKeys((model) => model.getAttribute(metadata.localKey));
|
|
@@ -448,11 +448,11 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
448
448
|
}
|
|
449
449
|
/**
|
|
450
450
|
* Loads a "has many through" relationship for the set of models.
|
|
451
|
-
*
|
|
452
|
-
* @param name
|
|
453
|
-
* @param metadata
|
|
454
|
-
* @param constraint
|
|
455
|
-
* @returns
|
|
451
|
+
*
|
|
452
|
+
* @param name
|
|
453
|
+
* @param metadata
|
|
454
|
+
* @param constraint
|
|
455
|
+
* @returns
|
|
456
456
|
*/
|
|
457
457
|
async loadHasManyThrough(name, metadata, constraint) {
|
|
458
458
|
const parentKeys = this.collectUniqueKeys((model) => model.getAttribute(metadata.localKey));
|
|
@@ -506,12 +506,12 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
506
506
|
}
|
|
507
507
|
/**
|
|
508
508
|
* Loads a "has one through" relationship for the set of models.
|
|
509
|
-
*
|
|
510
|
-
* @param name
|
|
511
|
-
* @param resolver
|
|
512
|
-
* @param metadata
|
|
513
|
-
* @param constraint
|
|
514
|
-
* @returns
|
|
509
|
+
*
|
|
510
|
+
* @param name
|
|
511
|
+
* @param resolver
|
|
512
|
+
* @param metadata
|
|
513
|
+
* @param constraint
|
|
514
|
+
* @returns
|
|
515
515
|
*/
|
|
516
516
|
async loadHasOneThrough(name, resolver, metadata, constraint) {
|
|
517
517
|
const parentKeys = this.collectUniqueKeys((model) => model.getAttribute(metadata.localKey));
|
|
@@ -705,19 +705,19 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
705
705
|
}
|
|
706
706
|
/**
|
|
707
707
|
* Applies an eager load constraint to a query if provided.
|
|
708
|
-
*
|
|
709
|
-
* @param query
|
|
710
|
-
* @param constraint
|
|
711
|
-
* @returns
|
|
708
|
+
*
|
|
709
|
+
* @param query
|
|
710
|
+
* @param constraint
|
|
711
|
+
* @returns
|
|
712
712
|
*/
|
|
713
713
|
applyConstraint(query, constraint) {
|
|
714
714
|
if (!constraint) return query;
|
|
715
715
|
return constraint(query) ?? query;
|
|
716
716
|
}
|
|
717
717
|
/**
|
|
718
|
-
* Collects unique values from the set of models based on a resolver function, which
|
|
718
|
+
* Collects unique values from the set of models based on a resolver function, which
|
|
719
719
|
* is used to extract the value from each model.
|
|
720
|
-
*
|
|
720
|
+
*
|
|
721
721
|
* @param resolve A function that takes a model and returns the value to be collected.
|
|
722
722
|
* @returns An array of unique values.
|
|
723
723
|
*/
|
|
@@ -735,9 +735,9 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
735
735
|
return values;
|
|
736
736
|
}
|
|
737
737
|
/**
|
|
738
|
-
* Collects unique values from an array of database rows based on a specified key, which
|
|
738
|
+
* Collects unique values from an array of database rows based on a specified key, which
|
|
739
739
|
* is used to extract the value from each row.
|
|
740
|
-
*
|
|
740
|
+
*
|
|
741
741
|
* @param rows An array of database rows.
|
|
742
742
|
* @param key The key to extract values from each row.
|
|
743
743
|
* @returns An array of unique values.
|
|
@@ -757,16 +757,16 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
757
757
|
}
|
|
758
758
|
/**
|
|
759
759
|
* Loads a "belongs to many" relationship for the set of models.
|
|
760
|
-
*
|
|
761
|
-
* @returns
|
|
760
|
+
*
|
|
761
|
+
* @returns
|
|
762
762
|
*/
|
|
763
763
|
createRelationTableLoader() {
|
|
764
764
|
return new RelationTableLoader(this.resolveAdapter());
|
|
765
765
|
}
|
|
766
766
|
/**
|
|
767
767
|
* Loads a "belongs to many" relationship for the set of models.
|
|
768
|
-
*
|
|
769
|
-
* @returns
|
|
768
|
+
*
|
|
769
|
+
* @returns
|
|
770
770
|
*/
|
|
771
771
|
resolveAdapter() {
|
|
772
772
|
const adapter = this.models[0].constructor.getAdapter?.();
|
|
@@ -774,30 +774,30 @@ var SetBasedEagerLoader = class SetBasedEagerLoader {
|
|
|
774
774
|
return adapter;
|
|
775
775
|
}
|
|
776
776
|
/**
|
|
777
|
-
* Reads an attribute value from a model using the getAttribute method, which is used
|
|
777
|
+
* Reads an attribute value from a model using the getAttribute method, which is used
|
|
778
778
|
* to access model attributes in a way that is compatible with Arkorm's internal model structure.
|
|
779
|
-
*
|
|
779
|
+
*
|
|
780
780
|
* @param model The model to read the attribute from.
|
|
781
781
|
* @param key The name of the attribute to read.
|
|
782
|
-
* @returns
|
|
782
|
+
* @returns
|
|
783
783
|
*/
|
|
784
784
|
readModelAttribute(model, key) {
|
|
785
785
|
return model.getAttribute?.(key);
|
|
786
786
|
}
|
|
787
787
|
/**
|
|
788
|
-
* Resolves the default result for a relationship when no related models are found.
|
|
789
|
-
*
|
|
790
|
-
* @param resolver
|
|
791
|
-
* @param model
|
|
792
|
-
* @returns
|
|
788
|
+
* Resolves the default result for a relationship when no related models are found.
|
|
789
|
+
*
|
|
790
|
+
* @param resolver
|
|
791
|
+
* @param model
|
|
792
|
+
* @returns
|
|
793
793
|
*/
|
|
794
794
|
resolveSingleDefault(resolver, model) {
|
|
795
795
|
return resolver.call(model).resolveDefaultResult?.() ?? null;
|
|
796
796
|
}
|
|
797
797
|
/**
|
|
798
|
-
* Generates a unique lookup key for a given value, which is used to store and retrieve
|
|
798
|
+
* Generates a unique lookup key for a given value, which is used to store and retrieve
|
|
799
799
|
* values in maps during the eager loading process.
|
|
800
|
-
*
|
|
800
|
+
*
|
|
801
801
|
* @param value The value to generate a lookup key for.
|
|
802
802
|
* @returns A unique string representing the value.
|
|
803
803
|
*/
|
|
@@ -843,10 +843,10 @@ var RuntimeModuleLoader = class {
|
|
|
843
843
|
*
|
|
844
844
|
* Each returned entry carries either the loaded module or the last error,
|
|
845
845
|
* so callers can surface genuine failures instead of silently dropping them.
|
|
846
|
-
*
|
|
847
|
-
* @param filePaths
|
|
848
|
-
* @param useDefault
|
|
849
|
-
* @returns
|
|
846
|
+
*
|
|
847
|
+
* @param filePaths
|
|
848
|
+
* @param useDefault
|
|
849
|
+
* @returns
|
|
850
850
|
*/
|
|
851
851
|
static async loadAll(filePaths, useDefault = false) {
|
|
852
852
|
const jiti = createJiti(`${pathToFileURL(resolve(".")).href}/`, {
|
|
@@ -1012,9 +1012,9 @@ const getLatestAppliedMigrations = (state, steps) => {
|
|
|
1012
1012
|
//#endregion
|
|
1013
1013
|
//#region src/database/ForeignKeyBuilder.ts
|
|
1014
1014
|
/**
|
|
1015
|
-
* The ForeignKeyBuilder class provides a fluent interface for defining
|
|
1016
|
-
* foreign key constraints in a migration. It allows you to specify
|
|
1017
|
-
* the referenced table and column, as well as actions to take on
|
|
1015
|
+
* The ForeignKeyBuilder class provides a fluent interface for defining
|
|
1016
|
+
* foreign key constraints in a migration. It allows you to specify
|
|
1017
|
+
* the referenced table and column, as well as actions to take on
|
|
1018
1018
|
* delete and aliases for the relation.
|
|
1019
1019
|
*
|
|
1020
1020
|
* @author Legacy (3m1n3nc3)
|
|
@@ -1026,10 +1026,10 @@ var ForeignKeyBuilder = class {
|
|
|
1026
1026
|
}
|
|
1027
1027
|
/**
|
|
1028
1028
|
* Defines the referenced table and column for this foreign key constraint.
|
|
1029
|
-
*
|
|
1030
|
-
* @param table
|
|
1031
|
-
* @param column
|
|
1032
|
-
* @returns
|
|
1029
|
+
*
|
|
1030
|
+
* @param table
|
|
1031
|
+
* @param column
|
|
1032
|
+
* @returns
|
|
1033
1033
|
*/
|
|
1034
1034
|
references(table, column) {
|
|
1035
1035
|
this.foreignKey.referencesTable = table;
|
|
@@ -1037,22 +1037,22 @@ var ForeignKeyBuilder = class {
|
|
|
1037
1037
|
return this;
|
|
1038
1038
|
}
|
|
1039
1039
|
/**
|
|
1040
|
-
* Defines the action to take when a referenced record is deleted, such
|
|
1040
|
+
* Defines the action to take when a referenced record is deleted, such
|
|
1041
1041
|
* as "CASCADE", "SET NULL", or "RESTRICT".
|
|
1042
|
-
*
|
|
1043
|
-
* @param action
|
|
1044
|
-
* @returns
|
|
1042
|
+
*
|
|
1043
|
+
* @param action
|
|
1044
|
+
* @returns
|
|
1045
1045
|
*/
|
|
1046
1046
|
onDelete(action) {
|
|
1047
1047
|
this.foreignKey.onDelete = action;
|
|
1048
1048
|
return this;
|
|
1049
1049
|
}
|
|
1050
1050
|
/**
|
|
1051
|
-
* Defines an alias for the relation represented by this foreign key, which
|
|
1051
|
+
* Defines an alias for the relation represented by this foreign key, which
|
|
1052
1052
|
* can be used in the ORM for more intuitive access to related models.
|
|
1053
|
-
*
|
|
1054
|
-
* @param name
|
|
1055
|
-
* @returns
|
|
1053
|
+
*
|
|
1054
|
+
* @param name
|
|
1055
|
+
* @returns
|
|
1056
1056
|
*/
|
|
1057
1057
|
alias(name) {
|
|
1058
1058
|
this.foreignKey.relationAlias = name;
|
|
@@ -1060,20 +1060,20 @@ var ForeignKeyBuilder = class {
|
|
|
1060
1060
|
}
|
|
1061
1061
|
/**
|
|
1062
1062
|
* Defines an alias for the inverse relation represented by this foreign key.
|
|
1063
|
-
*
|
|
1064
|
-
* @param name
|
|
1065
|
-
* @returns
|
|
1063
|
+
*
|
|
1064
|
+
* @param name
|
|
1065
|
+
* @returns
|
|
1066
1066
|
*/
|
|
1067
1067
|
inverseAlias(name) {
|
|
1068
1068
|
this.foreignKey.inverseRelationAlias = name;
|
|
1069
1069
|
return this;
|
|
1070
1070
|
}
|
|
1071
1071
|
/**
|
|
1072
|
-
* Defines an alias for the foreign key field itself, which can be
|
|
1072
|
+
* Defines an alias for the foreign key field itself, which can be
|
|
1073
1073
|
* used in the ORM for more intuitive access to the foreign key value.
|
|
1074
|
-
*
|
|
1075
|
-
* @param fieldName
|
|
1076
|
-
* @returns
|
|
1074
|
+
*
|
|
1075
|
+
* @param fieldName
|
|
1076
|
+
* @returns
|
|
1077
1077
|
*/
|
|
1078
1078
|
as(fieldName) {
|
|
1079
1079
|
this.foreignKey.fieldAlias = fieldName;
|
|
@@ -1192,7 +1192,7 @@ var EnumBuilder = class {
|
|
|
1192
1192
|
}
|
|
1193
1193
|
};
|
|
1194
1194
|
/**
|
|
1195
|
-
* The TableBuilder class provides a fluent interface for defining
|
|
1195
|
+
* The TableBuilder class provides a fluent interface for defining
|
|
1196
1196
|
* the structure of a database table in a migration, including columns to add or drop.
|
|
1197
1197
|
*
|
|
1198
1198
|
* @author Legacy (3m1n3nc3)
|
|
@@ -1229,7 +1229,7 @@ var TableBuilder = class {
|
|
|
1229
1229
|
}
|
|
1230
1230
|
/**
|
|
1231
1231
|
* Defines an auto-incrementing primary key column.
|
|
1232
|
-
*
|
|
1232
|
+
*
|
|
1233
1233
|
* @param name The name of the primary key column.
|
|
1234
1234
|
* @default 'id'
|
|
1235
1235
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1239,7 +1239,7 @@ var TableBuilder = class {
|
|
|
1239
1239
|
}
|
|
1240
1240
|
/**
|
|
1241
1241
|
* Defines a UUID column in the table.
|
|
1242
|
-
*
|
|
1242
|
+
*
|
|
1243
1243
|
* @param name The name of the UUID column.
|
|
1244
1244
|
* @param options Additional options for the UUID column.
|
|
1245
1245
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1270,7 +1270,7 @@ var TableBuilder = class {
|
|
|
1270
1270
|
}
|
|
1271
1271
|
/**
|
|
1272
1272
|
* Defines a string column in the table.
|
|
1273
|
-
*
|
|
1273
|
+
*
|
|
1274
1274
|
* @param name The name of the string column.
|
|
1275
1275
|
* @param options Additional options for the string column.
|
|
1276
1276
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1280,7 +1280,7 @@ var TableBuilder = class {
|
|
|
1280
1280
|
}
|
|
1281
1281
|
/**
|
|
1282
1282
|
* Defines a text column in the table.
|
|
1283
|
-
*
|
|
1283
|
+
*
|
|
1284
1284
|
* @param name The name of the text column.
|
|
1285
1285
|
* @param options Additional options for the text column.
|
|
1286
1286
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1290,7 +1290,7 @@ var TableBuilder = class {
|
|
|
1290
1290
|
}
|
|
1291
1291
|
/**
|
|
1292
1292
|
* Defines an integer column in the table.
|
|
1293
|
-
*
|
|
1293
|
+
*
|
|
1294
1294
|
* @param name The name of the integer column.
|
|
1295
1295
|
* @param options Additional options for the integer column.
|
|
1296
1296
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1300,7 +1300,7 @@ var TableBuilder = class {
|
|
|
1300
1300
|
}
|
|
1301
1301
|
/**
|
|
1302
1302
|
* Defines a big integer column in the table.
|
|
1303
|
-
*
|
|
1303
|
+
*
|
|
1304
1304
|
* @param name The name of the big integer column.
|
|
1305
1305
|
* @param options Additional options for the big integer column.
|
|
1306
1306
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1310,7 +1310,7 @@ var TableBuilder = class {
|
|
|
1310
1310
|
}
|
|
1311
1311
|
/**
|
|
1312
1312
|
* Defines a float column in the table.
|
|
1313
|
-
*
|
|
1313
|
+
*
|
|
1314
1314
|
* @param name The name of the float column.
|
|
1315
1315
|
* @param options Additional options for the float column.
|
|
1316
1316
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1318,6 +1318,22 @@ var TableBuilder = class {
|
|
|
1318
1318
|
float(name, options = {}) {
|
|
1319
1319
|
return this.column(name, "float", options);
|
|
1320
1320
|
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Defines a fixed-precision decimal column in the table.
|
|
1323
|
+
*
|
|
1324
|
+
* @param name The name of the decimal column.
|
|
1325
|
+
* @param precision The total number of digits. Defaults to 8.
|
|
1326
|
+
* @param scale The number of digits to the right of the point. Defaults to 2.
|
|
1327
|
+
* @param options Additional options for the decimal column.
|
|
1328
|
+
* @returns The current TableBuilder instance for chaining.
|
|
1329
|
+
*/
|
|
1330
|
+
decimal(name, precision = 8, scale = 2, options = {}) {
|
|
1331
|
+
return this.column(name, "decimal", {
|
|
1332
|
+
precision,
|
|
1333
|
+
scale,
|
|
1334
|
+
...options
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1321
1337
|
unique(columnsOrName, name) {
|
|
1322
1338
|
if (Array.isArray(columnsOrName)) {
|
|
1323
1339
|
const columns = this.normalizeCompositeColumns(columnsOrName, "unique constraint");
|
|
@@ -1336,8 +1352,8 @@ var TableBuilder = class {
|
|
|
1336
1352
|
}
|
|
1337
1353
|
/**
|
|
1338
1354
|
* Defines a boolean column in the table.
|
|
1339
|
-
*
|
|
1340
|
-
* @param name The name of the boolean column.
|
|
1355
|
+
*
|
|
1356
|
+
* @param name The name of the boolean column.
|
|
1341
1357
|
* @param options Additional options for the boolean column.
|
|
1342
1358
|
* @returns The current TableBuilder instance for chaining.
|
|
1343
1359
|
*/
|
|
@@ -1346,29 +1362,39 @@ var TableBuilder = class {
|
|
|
1346
1362
|
}
|
|
1347
1363
|
/**
|
|
1348
1364
|
* Defines a JSON column in the table.
|
|
1349
|
-
*
|
|
1365
|
+
*
|
|
1350
1366
|
* @param name The name of the JSON column.
|
|
1351
1367
|
* @param options Additional options for the JSON column.
|
|
1352
|
-
* @returns
|
|
1368
|
+
* @returns
|
|
1353
1369
|
*/
|
|
1354
1370
|
json(name, options = {}) {
|
|
1355
1371
|
return this.column(name, "json", options);
|
|
1356
1372
|
}
|
|
1357
1373
|
/**
|
|
1358
1374
|
* Defines a date column in the table.
|
|
1359
|
-
*
|
|
1375
|
+
*
|
|
1360
1376
|
* @param name The name of the date column.
|
|
1361
1377
|
* @param options Additional options for the date column.
|
|
1362
|
-
* @returns
|
|
1378
|
+
* @returns
|
|
1363
1379
|
*/
|
|
1364
1380
|
date(name, options = {}) {
|
|
1365
1381
|
return this.column(name, "date", options);
|
|
1366
1382
|
}
|
|
1367
1383
|
/**
|
|
1384
|
+
* Defines a date-time column in the table (timestamp without time zone).
|
|
1385
|
+
*
|
|
1386
|
+
* @param name The name of the date-time column.
|
|
1387
|
+
* @param options Additional options for the date-time column.
|
|
1388
|
+
* @returns The current TableBuilder instance for chaining.
|
|
1389
|
+
*/
|
|
1390
|
+
dateTime(name, options = {}) {
|
|
1391
|
+
return this.column(name, "dateTime", options);
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1368
1394
|
* Defines colonns for a polymorphic relationship in the table.
|
|
1369
|
-
*
|
|
1395
|
+
*
|
|
1370
1396
|
* @param name The base name for the polymorphic relationship columns.
|
|
1371
|
-
* @returns
|
|
1397
|
+
* @returns
|
|
1372
1398
|
*/
|
|
1373
1399
|
morphs(name, nullable = false) {
|
|
1374
1400
|
this.string(`${name}Type`, { nullable });
|
|
@@ -1377,9 +1403,9 @@ var TableBuilder = class {
|
|
|
1377
1403
|
}
|
|
1378
1404
|
/**
|
|
1379
1405
|
* Defines columns for a polymorphic relationship in the table with UUID ID.
|
|
1380
|
-
*
|
|
1406
|
+
*
|
|
1381
1407
|
* @param name The base name for the polymorphic relationship columns.
|
|
1382
|
-
* @returns
|
|
1408
|
+
* @returns
|
|
1383
1409
|
*/
|
|
1384
1410
|
uuidMorphs(name, nullable = false) {
|
|
1385
1411
|
this.string(`${name}Type`, { nullable });
|
|
@@ -1388,28 +1414,28 @@ var TableBuilder = class {
|
|
|
1388
1414
|
}
|
|
1389
1415
|
/**
|
|
1390
1416
|
* Defines nullable columns for a polymorphic relationship in the table.
|
|
1391
|
-
*
|
|
1417
|
+
*
|
|
1392
1418
|
* @param name The base name for the polymorphic relationship columns.
|
|
1393
|
-
* @returns
|
|
1419
|
+
* @returns
|
|
1394
1420
|
*/
|
|
1395
1421
|
nullableMorphs(name) {
|
|
1396
1422
|
return this.morphs(name, true);
|
|
1397
1423
|
}
|
|
1398
1424
|
/**
|
|
1399
1425
|
* Defines nullable columns for a polymorphic relationship in the table with UUID ID.
|
|
1400
|
-
*
|
|
1426
|
+
*
|
|
1401
1427
|
* @param name The base name for the polymorphic relationship columns.
|
|
1402
|
-
* @returns
|
|
1428
|
+
* @returns
|
|
1403
1429
|
*/
|
|
1404
1430
|
nullableUuidMorphs(name) {
|
|
1405
1431
|
return this.uuidMorphs(name, true);
|
|
1406
1432
|
}
|
|
1407
1433
|
/**
|
|
1408
1434
|
* Defines a timestamp column in the table.
|
|
1409
|
-
*
|
|
1435
|
+
*
|
|
1410
1436
|
* @param name The name of the timestamp column.
|
|
1411
1437
|
* @param options Additional options for the timestamp column.
|
|
1412
|
-
* @returns
|
|
1438
|
+
* @returns
|
|
1413
1439
|
*/
|
|
1414
1440
|
timestamp(name, options = {}) {
|
|
1415
1441
|
return this.column(name, "timestamp", options);
|
|
@@ -1470,9 +1496,9 @@ var TableBuilder = class {
|
|
|
1470
1496
|
}
|
|
1471
1497
|
/**
|
|
1472
1498
|
* Defines a soft delete timestamp column in the table.
|
|
1473
|
-
*
|
|
1499
|
+
*
|
|
1474
1500
|
* @param column The name of the soft delete column.
|
|
1475
|
-
* @returns
|
|
1501
|
+
* @returns
|
|
1476
1502
|
*/
|
|
1477
1503
|
softDeletes(column = "deletedAt") {
|
|
1478
1504
|
this.timestamp(column, { nullable: true });
|
|
@@ -1480,9 +1506,9 @@ var TableBuilder = class {
|
|
|
1480
1506
|
}
|
|
1481
1507
|
/**
|
|
1482
1508
|
* Defines a column to be dropped from the table in an alterTable operation.
|
|
1483
|
-
*
|
|
1509
|
+
*
|
|
1484
1510
|
* @param name The name of the column to drop.
|
|
1485
|
-
* @returns
|
|
1511
|
+
* @returns
|
|
1486
1512
|
*/
|
|
1487
1513
|
dropColumn(name) {
|
|
1488
1514
|
this.dropColumnNames.push(name);
|
|
@@ -1490,7 +1516,7 @@ var TableBuilder = class {
|
|
|
1490
1516
|
}
|
|
1491
1517
|
/**
|
|
1492
1518
|
* Marks a column as nullable.
|
|
1493
|
-
*
|
|
1519
|
+
*
|
|
1494
1520
|
* @param columnName Optional explicit column name. When omitted, applies to the latest defined column.
|
|
1495
1521
|
* @returns The current TableBuilder instance for chaining.
|
|
1496
1522
|
*/
|
|
@@ -1528,7 +1554,7 @@ var TableBuilder = class {
|
|
|
1528
1554
|
}
|
|
1529
1555
|
/**
|
|
1530
1556
|
* Sets the column position to appear after another column when possible.
|
|
1531
|
-
*
|
|
1557
|
+
*
|
|
1532
1558
|
* @param referenceColumn The column that the target column should be placed after.
|
|
1533
1559
|
* @param columnName Optional explicit target column name. When omitted, applies to the latest defined column.
|
|
1534
1560
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1540,7 +1566,7 @@ var TableBuilder = class {
|
|
|
1540
1566
|
}
|
|
1541
1567
|
/**
|
|
1542
1568
|
* Maps the column to a custom database column name.
|
|
1543
|
-
*
|
|
1569
|
+
*
|
|
1544
1570
|
* @param name The custom database column name.
|
|
1545
1571
|
* @param columnName Optional explicit target column name. When omitted, applies to the latest defined column.
|
|
1546
1572
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1552,7 +1578,7 @@ var TableBuilder = class {
|
|
|
1552
1578
|
}
|
|
1553
1579
|
/**
|
|
1554
1580
|
* Defines an index on one or more columns.
|
|
1555
|
-
*
|
|
1581
|
+
*
|
|
1556
1582
|
* @param columns Optional target columns. When omitted, applies to the latest defined column.
|
|
1557
1583
|
* @param name Optional index name.
|
|
1558
1584
|
* @returns The current TableBuilder instance for chaining.
|
|
@@ -1581,11 +1607,11 @@ var TableBuilder = class {
|
|
|
1581
1607
|
return new ForeignKeyBuilder(entry);
|
|
1582
1608
|
}
|
|
1583
1609
|
/**
|
|
1584
|
-
* Defines a foreign key relation for a column, using a
|
|
1610
|
+
* Defines a foreign key relation for a column, using a
|
|
1585
1611
|
* conventional naming pattern.
|
|
1586
|
-
*
|
|
1587
|
-
* @param column
|
|
1588
|
-
* @returns
|
|
1612
|
+
*
|
|
1613
|
+
* @param column
|
|
1614
|
+
* @returns
|
|
1589
1615
|
*/
|
|
1590
1616
|
foreign(column) {
|
|
1591
1617
|
const columnName = this.resolveColumn(column).name;
|
|
@@ -1593,8 +1619,8 @@ var TableBuilder = class {
|
|
|
1593
1619
|
}
|
|
1594
1620
|
/**
|
|
1595
1621
|
* Returns a deep copy of the defined columns for the table.
|
|
1596
|
-
*
|
|
1597
|
-
* @returns
|
|
1622
|
+
*
|
|
1623
|
+
* @returns
|
|
1598
1624
|
*/
|
|
1599
1625
|
getColumns() {
|
|
1600
1626
|
return this.columns.map((column) => ({
|
|
@@ -1604,15 +1630,15 @@ var TableBuilder = class {
|
|
|
1604
1630
|
}
|
|
1605
1631
|
/**
|
|
1606
1632
|
* Returns a copy of the defined column names to be dropped from the table.
|
|
1607
|
-
*
|
|
1608
|
-
* @returns
|
|
1633
|
+
*
|
|
1634
|
+
* @returns
|
|
1609
1635
|
*/
|
|
1610
1636
|
getDropColumns() {
|
|
1611
1637
|
return [...this.dropColumnNames];
|
|
1612
1638
|
}
|
|
1613
1639
|
/**
|
|
1614
1640
|
* Returns a deep copy of the defined indexes for the table.
|
|
1615
|
-
*
|
|
1641
|
+
*
|
|
1616
1642
|
* @returns
|
|
1617
1643
|
*/
|
|
1618
1644
|
getIndexes() {
|
|
@@ -1649,11 +1675,11 @@ var TableBuilder = class {
|
|
|
1649
1675
|
}
|
|
1650
1676
|
/**
|
|
1651
1677
|
* Defines a column in the table with the given name.
|
|
1652
|
-
*
|
|
1678
|
+
*
|
|
1653
1679
|
* @param name The name of the column.
|
|
1654
1680
|
* @param type The type of the column.
|
|
1655
1681
|
* @param options Additional options for the column.
|
|
1656
|
-
* @returns
|
|
1682
|
+
* @returns
|
|
1657
1683
|
*/
|
|
1658
1684
|
column(name, type, options) {
|
|
1659
1685
|
this.columns.push({
|
|
@@ -1669,6 +1695,8 @@ var TableBuilder = class {
|
|
|
1669
1695
|
after: options.after,
|
|
1670
1696
|
default: options.default,
|
|
1671
1697
|
updatedAt: options.updatedAt,
|
|
1698
|
+
precision: options.precision,
|
|
1699
|
+
scale: options.scale,
|
|
1672
1700
|
primaryKeyGeneration: options.primaryKeyGeneration
|
|
1673
1701
|
});
|
|
1674
1702
|
const column = this.columns[this.columns.length - 1];
|
|
@@ -1678,9 +1706,9 @@ var TableBuilder = class {
|
|
|
1678
1706
|
}
|
|
1679
1707
|
/**
|
|
1680
1708
|
* Resolve a target column by name or fallback to the latest defined column.
|
|
1681
|
-
*
|
|
1682
|
-
* @param columnName
|
|
1683
|
-
* @returns
|
|
1709
|
+
*
|
|
1710
|
+
* @param columnName
|
|
1711
|
+
* @returns
|
|
1684
1712
|
*/
|
|
1685
1713
|
resolveColumn(columnName) {
|
|
1686
1714
|
const targetName = columnName ?? this.latestColumnName;
|
|
@@ -1701,19 +1729,84 @@ var TableBuilder = class {
|
|
|
1701
1729
|
//#endregion
|
|
1702
1730
|
//#region src/database/SchemaBuilder.ts
|
|
1703
1731
|
/**
|
|
1704
|
-
* The SchemaBuilder class provides methods for defining the operations to be
|
|
1705
|
-
* performed in a migration, such as creating, altering, or dropping tables.
|
|
1732
|
+
* The SchemaBuilder class provides methods for defining the operations to be
|
|
1733
|
+
* performed in a migration, such as creating, altering, or dropping tables.
|
|
1706
1734
|
*
|
|
1707
1735
|
* @author Legacy (3m1n3nc3)
|
|
1708
1736
|
* @since 0.1.0
|
|
1709
1737
|
*/
|
|
1710
|
-
var SchemaBuilder = class {
|
|
1738
|
+
var SchemaBuilder = class SchemaBuilder {
|
|
1711
1739
|
constructor() {
|
|
1712
1740
|
this.operations = [];
|
|
1713
1741
|
}
|
|
1714
1742
|
/**
|
|
1743
|
+
* Disable foreign-key constraint enforcement on the active PostgreSQL
|
|
1744
|
+
* connection by switching the session into replication mode, which
|
|
1745
|
+
* suppresses the internal triggers that enforce foreign keys.
|
|
1746
|
+
*
|
|
1747
|
+
* The setting is connection-scoped, so the disable, the work that depends
|
|
1748
|
+
* on it, and the matching {@link SchemaBuilder.enableForeignKeyConstraints}
|
|
1749
|
+
* must run on the same connection. Prefer
|
|
1750
|
+
* {@link SchemaBuilder.withoutForeignKeyConstraints}, which guarantees this
|
|
1751
|
+
* by wrapping the work in a transaction. Requires a SQL-backed adapter and
|
|
1752
|
+
* a database role permitted to set `session_replication_role`.
|
|
1753
|
+
*
|
|
1754
|
+
* @returns
|
|
1755
|
+
*/
|
|
1756
|
+
static async disableForeignKeyConstraints() {
|
|
1757
|
+
await SchemaBuilder.setSessionReplicationRole("replica");
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* Re-enable foreign-key constraint enforcement on the active PostgreSQL
|
|
1761
|
+
* connection by restoring the default session replication role.
|
|
1762
|
+
*
|
|
1763
|
+
* @returns
|
|
1764
|
+
*/
|
|
1765
|
+
static async enableForeignKeyConstraints() {
|
|
1766
|
+
await SchemaBuilder.setSessionReplicationRole("origin");
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
* Run the given callback with foreign-key constraints disabled, then
|
|
1770
|
+
* restore them. The whole unit runs inside a transaction so the disable,
|
|
1771
|
+
* the callback, and the re-enable share a single connection (required for
|
|
1772
|
+
* the connection-scoped replication role to take effect) and roll back
|
|
1773
|
+
* together on failure.
|
|
1774
|
+
*
|
|
1775
|
+
* @example
|
|
1776
|
+
* await SchemaBuilder.withoutForeignKeyConstraints(async () => {
|
|
1777
|
+
* await User.factory()
|
|
1778
|
+
* .hasAttached(Tenant.factory().has(Project.factory(3)), { status: 'active' }, 'tenantMemberships')
|
|
1779
|
+
* .create()
|
|
1780
|
+
* })
|
|
1781
|
+
*
|
|
1782
|
+
* @param callback
|
|
1783
|
+
* @returns
|
|
1784
|
+
*/
|
|
1785
|
+
static async withoutForeignKeyConstraints(callback) {
|
|
1786
|
+
return await runArkormTransaction(async () => {
|
|
1787
|
+
await SchemaBuilder.disableForeignKeyConstraints();
|
|
1788
|
+
try {
|
|
1789
|
+
return await callback();
|
|
1790
|
+
} finally {
|
|
1791
|
+
await SchemaBuilder.enableForeignKeyConstraints();
|
|
1792
|
+
}
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
static async setSessionReplicationRole(role) {
|
|
1796
|
+
const adapter = getRuntimeAdapter();
|
|
1797
|
+
if (!adapter) throw new ArkormException("Toggling foreign-key constraints requires a configured database adapter.", {
|
|
1798
|
+
code: "ADAPTER_NOT_CONFIGURED",
|
|
1799
|
+
operation: "schema.foreignKeyConstraints"
|
|
1800
|
+
});
|
|
1801
|
+
if (!adapter.rawQuery) throw new UnsupportedAdapterFeatureException("Toggling foreign-key constraints requires an adapter that supports raw queries.", {
|
|
1802
|
+
operation: "schema.foreignKeyConstraints",
|
|
1803
|
+
meta: { feature: "rawQuery" }
|
|
1804
|
+
});
|
|
1805
|
+
await adapter.rawQuery({ sql: `SET session_replication_role = '${role}'` });
|
|
1806
|
+
}
|
|
1807
|
+
/**
|
|
1715
1808
|
* Defines a new table to be created in the migration.
|
|
1716
|
-
*
|
|
1809
|
+
*
|
|
1717
1810
|
* @param table The name of the table to create.
|
|
1718
1811
|
* @param callback A callback function to define the table's columns and structure.
|
|
1719
1812
|
* @returns The current SchemaBuilder instance for chaining.
|
|
@@ -1737,7 +1830,7 @@ var SchemaBuilder = class {
|
|
|
1737
1830
|
}
|
|
1738
1831
|
/**
|
|
1739
1832
|
* Defines alterations to an existing table in the migration.
|
|
1740
|
-
*
|
|
1833
|
+
*
|
|
1741
1834
|
* @param table The name of the table to alter.
|
|
1742
1835
|
* @param callback A callback function to define the alterations to the table's columns and structure.
|
|
1743
1836
|
* @returns The current SchemaBuilder instance for chaining.
|
|
@@ -1762,7 +1855,7 @@ var SchemaBuilder = class {
|
|
|
1762
1855
|
}
|
|
1763
1856
|
/**
|
|
1764
1857
|
* Defines a table to be dropped in the migration.
|
|
1765
|
-
*
|
|
1858
|
+
*
|
|
1766
1859
|
* @param table The name of the table to drop.
|
|
1767
1860
|
* @returns The current SchemaBuilder instance for chaining.
|
|
1768
1861
|
*/
|
|
@@ -1775,7 +1868,7 @@ var SchemaBuilder = class {
|
|
|
1775
1868
|
}
|
|
1776
1869
|
/**
|
|
1777
1870
|
* Returns a deep copy of the defined schema operations for the migration/
|
|
1778
|
-
*
|
|
1871
|
+
*
|
|
1779
1872
|
* @returns An array of schema operations for the migration.
|
|
1780
1873
|
*/
|
|
1781
1874
|
getOperations() {
|
|
@@ -1851,7 +1944,7 @@ const PRISMA_ENUM_REGEX = /enum\s+(\w+)\s*\{[\s\S]*?\n\}/g;
|
|
|
1851
1944
|
const PRISMA_ENUM_MEMBER_REGEX = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
1852
1945
|
/**
|
|
1853
1946
|
* Convert a table name to a PascalCase model name, with basic singularization.
|
|
1854
|
-
*
|
|
1947
|
+
*
|
|
1855
1948
|
* @param tableName The name of the table to convert.
|
|
1856
1949
|
* @returns The corresponding PascalCase model name.
|
|
1857
1950
|
*/
|
|
@@ -1863,16 +1956,16 @@ const toModelName = (tableName) => {
|
|
|
1863
1956
|
};
|
|
1864
1957
|
/**
|
|
1865
1958
|
* Escape special characters in a string for use in a regular expression.
|
|
1866
|
-
*
|
|
1867
|
-
* @param value
|
|
1868
|
-
* @returns
|
|
1959
|
+
*
|
|
1960
|
+
* @param value
|
|
1961
|
+
* @returns
|
|
1869
1962
|
*/
|
|
1870
1963
|
const escapeRegex = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1871
1964
|
/**
|
|
1872
1965
|
* Convert a SchemaColumn definition to a Prisma field type string, including modifiers.
|
|
1873
|
-
*
|
|
1874
|
-
* @param column
|
|
1875
|
-
* @returns
|
|
1966
|
+
*
|
|
1967
|
+
* @param column
|
|
1968
|
+
* @returns
|
|
1876
1969
|
*/
|
|
1877
1970
|
const resolvePrismaType = (column) => {
|
|
1878
1971
|
if (column.type === "id") return "Int";
|
|
@@ -1882,6 +1975,7 @@ const resolvePrismaType = (column) => {
|
|
|
1882
1975
|
if (column.type === "integer") return "Int";
|
|
1883
1976
|
if (column.type === "bigInteger") return "BigInt";
|
|
1884
1977
|
if (column.type === "float") return "Float";
|
|
1978
|
+
if (column.type === "decimal") return "Decimal";
|
|
1885
1979
|
if (column.type === "boolean") return "Boolean";
|
|
1886
1980
|
if (column.type === "json") return "Json";
|
|
1887
1981
|
return "DateTime";
|
|
@@ -1891,11 +1985,11 @@ const resolveEnumName = (column) => {
|
|
|
1891
1985
|
if (column.enumName && column.enumName.trim().length > 0) return column.enumName.trim();
|
|
1892
1986
|
throw new ArkormException(`Enum column [${column.name}] must define an enum name.`);
|
|
1893
1987
|
};
|
|
1894
|
-
/**
|
|
1988
|
+
/**
|
|
1895
1989
|
* Format a default value for inclusion in a Prisma schema field definition, based on its type.
|
|
1896
|
-
*
|
|
1897
|
-
* @param value
|
|
1898
|
-
* @returns
|
|
1990
|
+
*
|
|
1991
|
+
* @param value
|
|
1992
|
+
* @returns
|
|
1899
1993
|
*/
|
|
1900
1994
|
const formatDefaultValue = (value) => {
|
|
1901
1995
|
if (value == null) return void 0;
|
|
@@ -1906,9 +2000,9 @@ const formatDefaultValue = (value) => {
|
|
|
1906
2000
|
};
|
|
1907
2001
|
/**
|
|
1908
2002
|
* Format a default value for an enum column as a Prisma @default attribute, validating that it is a non-empty string.
|
|
1909
|
-
*
|
|
1910
|
-
* @param value
|
|
1911
|
-
* @returns
|
|
2003
|
+
*
|
|
2004
|
+
* @param value
|
|
2005
|
+
* @returns
|
|
1912
2006
|
*/
|
|
1913
2007
|
const formatEnumDefaultValue = (value) => {
|
|
1914
2008
|
if (value == null) return void 0;
|
|
@@ -1917,9 +2011,9 @@ const formatEnumDefaultValue = (value) => {
|
|
|
1917
2011
|
};
|
|
1918
2012
|
/**
|
|
1919
2013
|
* Normalize an enum value by ensuring it is a non-empty string and trimming whitespace.
|
|
1920
|
-
*
|
|
1921
|
-
* @param value
|
|
1922
|
-
* @returns
|
|
2014
|
+
*
|
|
2015
|
+
* @param value
|
|
2016
|
+
* @returns
|
|
1923
2017
|
*/
|
|
1924
2018
|
const normalizeEnumValue = (value) => {
|
|
1925
2019
|
if (typeof value !== "string" || value.trim().length === 0) throw new ArkormException("Enum values must be provided as non-empty strings.");
|
|
@@ -1929,9 +2023,9 @@ const normalizeEnumValue = (value) => {
|
|
|
1929
2023
|
};
|
|
1930
2024
|
/**
|
|
1931
2025
|
* Extract the enum values from a Prisma enum block string.
|
|
1932
|
-
*
|
|
1933
|
-
* @param block
|
|
1934
|
-
* @returns
|
|
2026
|
+
*
|
|
2027
|
+
* @param block
|
|
2028
|
+
* @returns
|
|
1935
2029
|
*/
|
|
1936
2030
|
const extractEnumBlockValues = (block) => {
|
|
1937
2031
|
return block.split("\n").slice(1, -1).map((line) => line.trim()).filter(Boolean);
|
|
@@ -1947,11 +2041,11 @@ const validateEnumValues = (column, enumName, enumValues) => {
|
|
|
1947
2041
|
};
|
|
1948
2042
|
/**
|
|
1949
2043
|
* Validate that a default value for an enum column is included in the defined enum values.
|
|
1950
|
-
*
|
|
1951
|
-
* @param column
|
|
1952
|
-
* @param enumName
|
|
1953
|
-
* @param enumValues
|
|
1954
|
-
* @returns
|
|
2044
|
+
*
|
|
2045
|
+
* @param column
|
|
2046
|
+
* @param enumName
|
|
2047
|
+
* @param enumValues
|
|
2048
|
+
* @returns
|
|
1955
2049
|
*/
|
|
1956
2050
|
const validateEnumDefaultValue = (column, enumName, enumValues) => {
|
|
1957
2051
|
if (column.default == null) return;
|
|
@@ -1961,9 +2055,9 @@ const validateEnumDefaultValue = (column, enumName, enumValues) => {
|
|
|
1961
2055
|
};
|
|
1962
2056
|
/**
|
|
1963
2057
|
* Build a single line of a Prisma model field definition based on a SchemaColumn, including type and modifiers.
|
|
1964
|
-
*
|
|
1965
|
-
* @param column
|
|
1966
|
-
* @returns
|
|
2058
|
+
*
|
|
2059
|
+
* @param column
|
|
2060
|
+
* @returns
|
|
1967
2061
|
*/
|
|
1968
2062
|
const buildFieldLine = (column) => {
|
|
1969
2063
|
if (column.type === "id") {
|
|
@@ -1980,14 +2074,15 @@ const buildFieldLine = (column) => {
|
|
|
1980
2074
|
const primary = column.primary ? " @id" : "";
|
|
1981
2075
|
const mapped = typeof column.map === "string" && column.map.trim().length > 0 ? ` @map("${column.map.replace(/"/g, "\\\"")}")` : "";
|
|
1982
2076
|
const updatedAt = column.updatedAt ? " @updatedAt" : "";
|
|
2077
|
+
const nativeType = column.type === "decimal" ? ` @db.Decimal(${column.precision ?? 8}, ${column.scale ?? 2})` : "";
|
|
1983
2078
|
const defaultValue = column.type === "enum" ? formatEnumDefaultValue(column.default) : column.primaryKeyGeneration?.prismaDefault ?? formatDefaultValue(column.default);
|
|
1984
2079
|
const defaultSuffix = defaultValue ? ` ${defaultValue}` : "";
|
|
1985
|
-
return ` ${column.name} ${scalar}${nullable}${primary}${unique}${defaultSuffix}${updatedAt}${mapped}`;
|
|
2080
|
+
return ` ${column.name} ${scalar}${nullable}${primary}${unique}${defaultSuffix}${updatedAt}${mapped}${nativeType}`;
|
|
1986
2081
|
};
|
|
1987
2082
|
/**
|
|
1988
|
-
* Build a Prisma enum block string based on an enum name and its values, validating that
|
|
2083
|
+
* Build a Prisma enum block string based on an enum name and its values, validating that
|
|
1989
2084
|
* at least one value is provided.
|
|
1990
|
-
*
|
|
2085
|
+
*
|
|
1991
2086
|
* @param enumName The name of the enum to create.
|
|
1992
2087
|
* @param values The array of values for the enum.
|
|
1993
2088
|
* @returns The Prisma enum block string.
|
|
@@ -1997,12 +2092,12 @@ const buildEnumBlock = (enumName, values) => {
|
|
|
1997
2092
|
return `enum ${enumName} {\n${values.map((value) => ` ${value}`).join("\n")}\n}`;
|
|
1998
2093
|
};
|
|
1999
2094
|
/**
|
|
2000
|
-
* Find the Prisma enum block in a schema string that corresponds to a given enum
|
|
2095
|
+
* Find the Prisma enum block in a schema string that corresponds to a given enum
|
|
2001
2096
|
* name, returning its details if found.
|
|
2002
|
-
*
|
|
2097
|
+
*
|
|
2003
2098
|
* @param schema The Prisma schema string to search for the enum block.
|
|
2004
2099
|
* @param enumName The name of the enum to find in the schema.
|
|
2005
|
-
* @returns
|
|
2100
|
+
* @returns
|
|
2006
2101
|
*/
|
|
2007
2102
|
const findEnumBlock = (schema, enumName) => {
|
|
2008
2103
|
const candidates = [...schema.matchAll(PRISMA_ENUM_REGEX)];
|
|
@@ -2021,13 +2116,13 @@ const findEnumBlock = (schema, enumName) => {
|
|
|
2021
2116
|
return null;
|
|
2022
2117
|
};
|
|
2023
2118
|
/**
|
|
2024
|
-
* Ensure that Prisma enum blocks exist in the schema for any enum columns defined in a
|
|
2025
|
-
* create or alter table operation, adding them if necessary and validating against
|
|
2119
|
+
* Ensure that Prisma enum blocks exist in the schema for any enum columns defined in a
|
|
2120
|
+
* create or alter table operation, adding them if necessary and validating against
|
|
2026
2121
|
* existing blocks.
|
|
2027
|
-
*
|
|
2122
|
+
*
|
|
2028
2123
|
* @param schema The current Prisma schema string to check and modify.
|
|
2029
2124
|
* @param columns The array of schema column definitions to check for enum types and ensure corresponding blocks exist for.
|
|
2030
|
-
* @returns
|
|
2125
|
+
* @returns
|
|
2031
2126
|
*/
|
|
2032
2127
|
const ensureEnumBlocks = (schema, columns) => {
|
|
2033
2128
|
let nextSchema = schema;
|
|
@@ -2057,9 +2152,9 @@ const ensureEnumBlocks = (schema, columns) => {
|
|
|
2057
2152
|
};
|
|
2058
2153
|
/**
|
|
2059
2154
|
* Build a Prisma model-level @@index definition line.
|
|
2060
|
-
*
|
|
2155
|
+
*
|
|
2061
2156
|
* @param index The schema index definition to convert to a Prisma \@\@index line.
|
|
2062
|
-
* @returns
|
|
2157
|
+
* @returns
|
|
2063
2158
|
*/
|
|
2064
2159
|
const buildIndexLine = (index) => {
|
|
2065
2160
|
return ` @@index([${index.columns.join(", ")}]${typeof index.name === "string" && index.name.trim().length > 0 ? `, name: "${index.name.replace(/"/g, "\\\"")}"` : ""})`;
|
|
@@ -2083,9 +2178,9 @@ const buildUniqueConstraintLine = (constraint) => {
|
|
|
2083
2178
|
return ` @@unique([${constraint.columns.join(", ")}]${typeof constraint.name === "string" && constraint.name.trim().length > 0 ? `, name: "${constraint.name.replace(/"/g, "\\\"")}"` : ""})`;
|
|
2084
2179
|
};
|
|
2085
2180
|
/**
|
|
2086
|
-
* Derive a relation field name from a foreign key column name by applying
|
|
2181
|
+
* Derive a relation field name from a foreign key column name by applying
|
|
2087
2182
|
* common conventions, such as removing "Id" suffixes and converting to camelCase.
|
|
2088
|
-
*
|
|
2183
|
+
*
|
|
2089
2184
|
* @param columnName The name of the foreign key column.
|
|
2090
2185
|
* @returns The derived relation field name.
|
|
2091
2186
|
*/
|
|
@@ -2100,10 +2195,10 @@ const deriveRelationFieldName = (columnName) => {
|
|
|
2100
2195
|
return `${trimmed.charAt(0).toLowerCase()}${trimmed.slice(1)}`;
|
|
2101
2196
|
};
|
|
2102
2197
|
/**
|
|
2103
|
-
* Derive a relation name for both sides of a relation based on the
|
|
2104
|
-
* source and target model names, using an explicit alias if provided or a
|
|
2198
|
+
* Derive a relation name for both sides of a relation based on the
|
|
2199
|
+
* source and target model names, using an explicit alias if provided or a
|
|
2105
2200
|
* convention of combining the full source model name with the target model name.
|
|
2106
|
-
*
|
|
2201
|
+
*
|
|
2107
2202
|
* @param sourceModelName The name of the source model in the relation.
|
|
2108
2203
|
* @param targetModelName The name of the target model in the relation.
|
|
2109
2204
|
* @param explicitAlias An optional explicit alias for the relation.
|
|
@@ -2130,9 +2225,9 @@ const resolveForeignKeyColumn = (columns, foreignKey) => {
|
|
|
2130
2225
|
const isOneToOneForeignKey = (column) => {
|
|
2131
2226
|
return Boolean(column?.unique || column?.primary);
|
|
2132
2227
|
};
|
|
2133
|
-
/**
|
|
2228
|
+
/**
|
|
2134
2229
|
* Format a SchemaForeignKeyAction value as a Prisma onDelete action string.
|
|
2135
|
-
*
|
|
2230
|
+
*
|
|
2136
2231
|
* @param action The foreign key action to format.
|
|
2137
2232
|
* @returns The corresponding Prisma onDelete action string.
|
|
2138
2233
|
*/
|
|
@@ -2144,9 +2239,9 @@ const formatRelationAction = (action) => {
|
|
|
2144
2239
|
return "NoAction";
|
|
2145
2240
|
};
|
|
2146
2241
|
/**
|
|
2147
|
-
* Build a Prisma relation field line based on a SchemaForeignKey
|
|
2242
|
+
* Build a Prisma relation field line based on a SchemaForeignKey
|
|
2148
2243
|
* definition, including relation name and onDelete action.
|
|
2149
|
-
*
|
|
2244
|
+
*
|
|
2150
2245
|
* @param foreignKey The foreign key definition to convert to a relation line.
|
|
2151
2246
|
* @returns The corresponding Prisma schema line for the relation field.
|
|
2152
2247
|
*/
|
|
@@ -2162,10 +2257,10 @@ const buildRelationLine = (sourceModelName, foreignKey, columns = []) => {
|
|
|
2162
2257
|
return ` ${fieldName} ${targetModel}${optional} @relation("${relationName.replace(/"/g, "\\\"")}", fields: [${foreignKey.column}], references: [${foreignKey.referencesColumn}]${onDelete})`;
|
|
2163
2258
|
};
|
|
2164
2259
|
/**
|
|
2165
|
-
* Build a Prisma relation field line for the inverse side of a relation, based
|
|
2166
|
-
* on the source and target model names and the foreign key definition, using
|
|
2260
|
+
* Build a Prisma relation field line for the inverse side of a relation, based
|
|
2261
|
+
* on the source and target model names and the foreign key definition, using
|
|
2167
2262
|
* naming conventions and any explicit inverse alias provided.
|
|
2168
|
-
*
|
|
2263
|
+
*
|
|
2169
2264
|
* @param sourceModelName The name of the source model in the relation.
|
|
2170
2265
|
* @param targetModelName The name of the target model in the relation.
|
|
2171
2266
|
* @param foreignKey The foreign key definition for the relation.
|
|
@@ -2178,14 +2273,14 @@ const buildInverseRelationLine = (sourceModelName, targetModelName, foreignKey,
|
|
|
2178
2273
|
return ` ${fieldName} ${isOneToOneForeignKey(sourceColumn) ? `${sourceModelName}?` : `${sourceModelName}[]`} @relation("${relationName.replace(/"/g, "\\\"")}")`;
|
|
2179
2274
|
};
|
|
2180
2275
|
/**
|
|
2181
|
-
* Inject a line into the body of a Prisma model block if it does not already
|
|
2182
|
-
* exist, using a provided existence check function to determine if the line
|
|
2276
|
+
* Inject a line into the body of a Prisma model block if it does not already
|
|
2277
|
+
* exist, using a provided existence check function to determine if the line
|
|
2183
2278
|
* is already present.
|
|
2184
|
-
*
|
|
2279
|
+
*
|
|
2185
2280
|
* @param bodyLines The lines of the model block body to modify.
|
|
2186
2281
|
* @param line The line to inject if it does not already exist.
|
|
2187
2282
|
* @param exists A function that checks if a given line already exists in the body.
|
|
2188
|
-
* @returns
|
|
2283
|
+
* @returns
|
|
2189
2284
|
*/
|
|
2190
2285
|
const injectLineIntoModelBody = (bodyLines, line, exists) => {
|
|
2191
2286
|
if (bodyLines.some(exists)) return bodyLines;
|
|
@@ -2194,10 +2289,10 @@ const injectLineIntoModelBody = (bodyLines, line, exists) => {
|
|
|
2194
2289
|
return bodyLines;
|
|
2195
2290
|
};
|
|
2196
2291
|
/**
|
|
2197
|
-
* Apply inverse relation definitions to a Prisma schema string based on the
|
|
2198
|
-
* foreign keys defined in a create or alter table operation, ensuring that
|
|
2292
|
+
* Apply inverse relation definitions to a Prisma schema string based on the
|
|
2293
|
+
* foreign keys defined in a create or alter table operation, ensuring that
|
|
2199
2294
|
* related models have corresponding relation fields for bi-directional navigation.
|
|
2200
|
-
*
|
|
2295
|
+
*
|
|
2201
2296
|
* @param schema The Prisma schema string to modify.
|
|
2202
2297
|
* @param sourceModelName The name of the source model in the relation.
|
|
2203
2298
|
* @param foreignKeys An array of foreign key definitions to process.
|
|
@@ -2220,9 +2315,9 @@ const applyInverseRelations = (schema, sourceModelName, foreignKeys, columns = [
|
|
|
2220
2315
|
return nextSchema;
|
|
2221
2316
|
};
|
|
2222
2317
|
/**
|
|
2223
|
-
* Build a Prisma model block string based on a SchemaTableCreateOperation, including
|
|
2318
|
+
* Build a Prisma model block string based on a SchemaTableCreateOperation, including
|
|
2224
2319
|
* all fields and any necessary mapping.
|
|
2225
|
-
*
|
|
2320
|
+
*
|
|
2226
2321
|
* @param operation The schema table create operation to convert.
|
|
2227
2322
|
* @returns The corresponding Prisma model block string.
|
|
2228
2323
|
*/
|
|
@@ -2247,12 +2342,12 @@ const buildModelBlock = (operation) => {
|
|
|
2247
2342
|
] : [...fields, ...relations]).join("\n")}\n}`;
|
|
2248
2343
|
};
|
|
2249
2344
|
/**
|
|
2250
|
-
* Find the Prisma model block in a schema string that corresponds to a given
|
|
2345
|
+
* Find the Prisma model block in a schema string that corresponds to a given
|
|
2251
2346
|
* table name, using both explicit mapping and naming conventions.
|
|
2252
|
-
*
|
|
2253
|
-
* @param schema
|
|
2254
|
-
* @param table
|
|
2255
|
-
* @returns
|
|
2347
|
+
*
|
|
2348
|
+
* @param schema
|
|
2349
|
+
* @param table
|
|
2350
|
+
* @returns
|
|
2256
2351
|
*/
|
|
2257
2352
|
const findModelBlock = (schema, table) => {
|
|
2258
2353
|
const candidates = [...schema.matchAll(PRISMA_MODEL_REGEX)];
|
|
@@ -2284,9 +2379,9 @@ const findModelBlock = (schema, table) => {
|
|
|
2284
2379
|
return null;
|
|
2285
2380
|
};
|
|
2286
2381
|
/**
|
|
2287
|
-
* Apply a create table operation to a Prisma schema string, adding a new model
|
|
2382
|
+
* Apply a create table operation to a Prisma schema string, adding a new model
|
|
2288
2383
|
* block for the specified table and fields.
|
|
2289
|
-
*
|
|
2384
|
+
*
|
|
2290
2385
|
* @param schema The current Prisma schema string.
|
|
2291
2386
|
* @param operation The schema table create operation to apply.
|
|
2292
2387
|
* @returns The updated Prisma schema string with the new model block.
|
|
@@ -2298,9 +2393,9 @@ const applyCreateTableOperation = (schema, operation) => {
|
|
|
2298
2393
|
return applyInverseRelations(`${schemaWithEnums.trimEnd()}\n\n${block}\n`, toModelName(operation.table), operation.foreignKeys ?? [], operation.columns);
|
|
2299
2394
|
};
|
|
2300
2395
|
/**
|
|
2301
|
-
* Apply an alter table operation to a Prisma schema string, modifying the model
|
|
2396
|
+
* Apply an alter table operation to a Prisma schema string, modifying the model
|
|
2302
2397
|
* block for the specified table by adding and removing fields as needed.
|
|
2303
|
-
*
|
|
2398
|
+
*
|
|
2304
2399
|
* @param schema The current Prisma schema string.
|
|
2305
2400
|
* @param operation The schema table alter operation to apply.
|
|
2306
2401
|
* @returns The updated Prisma schema string with the modified model block.
|
|
@@ -2367,10 +2462,10 @@ const applyDropTableOperation = (schema, operation) => {
|
|
|
2367
2462
|
return `${before}${before && after ? "\n\n" : ""}${after}`;
|
|
2368
2463
|
};
|
|
2369
2464
|
/**
|
|
2370
|
-
* The SchemaBuilder class provides a fluent interface for defining
|
|
2371
|
-
* database schema operations in a migration, such as creating, altering, and
|
|
2465
|
+
* The SchemaBuilder class provides a fluent interface for defining
|
|
2466
|
+
* database schema operations in a migration, such as creating, altering, and
|
|
2372
2467
|
* dropping tables.
|
|
2373
|
-
*
|
|
2468
|
+
*
|
|
2374
2469
|
* @param schema The current Prisma schema string.
|
|
2375
2470
|
* @param operations The list of schema operations to apply.
|
|
2376
2471
|
* @returns The updated Prisma schema string after applying all operations.
|
|
@@ -2384,7 +2479,7 @@ const applyOperationsToPrismaSchema = (schema, operations) => {
|
|
|
2384
2479
|
};
|
|
2385
2480
|
/**
|
|
2386
2481
|
* Run a Prisma CLI command using npx, capturing and throwing any errors that occur.
|
|
2387
|
-
*
|
|
2482
|
+
*
|
|
2388
2483
|
* @param args The arguments to pass to the Prisma CLI command.
|
|
2389
2484
|
* @param cwd The current working directory to run the command in.
|
|
2390
2485
|
* @returns void
|
|
@@ -2399,11 +2494,11 @@ const runPrismaCommand = (args, cwd) => {
|
|
|
2399
2494
|
throw new ArkormException(errorOutput ? `Prisma command failed: prisma ${args.join(" ")}\n${errorOutput}` : `Prisma command failed: prisma ${args.join(" ")}`);
|
|
2400
2495
|
};
|
|
2401
2496
|
/**
|
|
2402
|
-
* Generate a new migration file with a given name and options, including
|
|
2497
|
+
* Generate a new migration file with a given name and options, including
|
|
2403
2498
|
* writing the file to disk if specified.
|
|
2404
|
-
*
|
|
2405
|
-
* @param name
|
|
2406
|
-
* @returns
|
|
2499
|
+
*
|
|
2500
|
+
* @param name
|
|
2501
|
+
* @returns
|
|
2407
2502
|
*/
|
|
2408
2503
|
const resolveMigrationClassName = (name) => {
|
|
2409
2504
|
const cleaned = name.replace(/[^a-zA-Z0-9]+/g, " ").trim();
|
|
@@ -2411,39 +2506,39 @@ const resolveMigrationClassName = (name) => {
|
|
|
2411
2506
|
return `${cleaned.split(/\s+/g).map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("")}Migration`;
|
|
2412
2507
|
};
|
|
2413
2508
|
/**
|
|
2414
|
-
* Pad a number with leading zeros to ensure it is at least two digits, for
|
|
2509
|
+
* Pad a number with leading zeros to ensure it is at least two digits, for
|
|
2415
2510
|
* use in migration timestamps.
|
|
2416
|
-
*
|
|
2417
|
-
* @param value
|
|
2418
|
-
* @returns
|
|
2511
|
+
*
|
|
2512
|
+
* @param value
|
|
2513
|
+
* @returns
|
|
2419
2514
|
*/
|
|
2420
2515
|
const pad = (value) => String(value).padStart(2, "0");
|
|
2421
2516
|
/**
|
|
2422
|
-
* Create a timestamp string in the format YYYYMMDDHHMMSS for use in migration
|
|
2517
|
+
* Create a timestamp string in the format YYYYMMDDHHMMSS for use in migration
|
|
2423
2518
|
* file names, based on the current date and time or a provided date.
|
|
2424
|
-
*
|
|
2425
|
-
* @param date
|
|
2426
|
-
* @returns
|
|
2519
|
+
*
|
|
2520
|
+
* @param date
|
|
2521
|
+
* @returns
|
|
2427
2522
|
*/
|
|
2428
2523
|
const createMigrationTimestamp = (date = /* @__PURE__ */ new Date()) => {
|
|
2429
2524
|
return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`;
|
|
2430
2525
|
};
|
|
2431
2526
|
/**
|
|
2432
|
-
* Convert a migration name to a slug suitable for use in a file name, by
|
|
2527
|
+
* Convert a migration name to a slug suitable for use in a file name, by
|
|
2433
2528
|
* lowercasing and replacing non-alphanumeric characters with underscores.
|
|
2434
|
-
*
|
|
2435
|
-
* @param name
|
|
2436
|
-
* @returns
|
|
2529
|
+
*
|
|
2530
|
+
* @param name
|
|
2531
|
+
* @returns
|
|
2437
2532
|
*/
|
|
2438
2533
|
const toMigrationFileSlug = (name) => {
|
|
2439
2534
|
return name.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "migration";
|
|
2440
2535
|
};
|
|
2441
2536
|
/**
|
|
2442
|
-
* Build the source code for a new migration file based on a given class
|
|
2537
|
+
* Build the source code for a new migration file based on a given class
|
|
2443
2538
|
* name, using a template with empty up and down methods.
|
|
2444
|
-
*
|
|
2445
|
-
* @param className
|
|
2446
|
-
* @returns
|
|
2539
|
+
*
|
|
2540
|
+
* @param className
|
|
2541
|
+
* @returns
|
|
2447
2542
|
*/
|
|
2448
2543
|
const buildMigrationSource = (className, extension = "ts") => {
|
|
2449
2544
|
if (extension === "js") return [
|
|
@@ -2480,12 +2575,12 @@ const buildMigrationSource = (className, extension = "ts") => {
|
|
|
2480
2575
|
].join("\n");
|
|
2481
2576
|
};
|
|
2482
2577
|
/**
|
|
2483
|
-
* Generate a new migration file with a given name and options, including
|
|
2578
|
+
* Generate a new migration file with a given name and options, including
|
|
2484
2579
|
* writing the file to disk if specified, and return the details of the generated file.
|
|
2485
|
-
*
|
|
2486
|
-
* @param name
|
|
2487
|
-
* @param options
|
|
2488
|
-
* @returns
|
|
2580
|
+
*
|
|
2581
|
+
* @param name
|
|
2582
|
+
* @param options
|
|
2583
|
+
* @returns
|
|
2489
2584
|
*/
|
|
2490
2585
|
const generateMigrationFile = (name, options = {}) => {
|
|
2491
2586
|
const timestamp = createMigrationTimestamp(/* @__PURE__ */ new Date());
|
|
@@ -2510,10 +2605,10 @@ const generateMigrationFile = (name, options = {}) => {
|
|
|
2510
2605
|
};
|
|
2511
2606
|
/**
|
|
2512
2607
|
* 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.
|
|
2513
|
-
*
|
|
2608
|
+
*
|
|
2514
2609
|
* @param migration The migration class or instance to analyze.
|
|
2515
2610
|
* @param direction The direction of the migration to plan for ('up' or 'down').
|
|
2516
|
-
* @returns A promise that resolves to an array of schema operations that would be performed.
|
|
2611
|
+
* @returns A promise that resolves to an array of schema operations that would be performed.
|
|
2517
2612
|
*/
|
|
2518
2613
|
const getMigrationPlan = async (migration, direction = "up") => {
|
|
2519
2614
|
const instance = typeof migration === "function" ? new migration() : migration;
|
|
@@ -2548,10 +2643,10 @@ const applyMigrationRollbackToDatabase = async (adapter, migration) => {
|
|
|
2548
2643
|
return { operations };
|
|
2549
2644
|
};
|
|
2550
2645
|
/**
|
|
2551
|
-
* Apply the schema operations defined in a migration to a Prisma schema
|
|
2552
|
-
* file, updating the file on disk if specified, and return the updated
|
|
2646
|
+
* Apply the schema operations defined in a migration to a Prisma schema
|
|
2647
|
+
* file, updating the file on disk if specified, and return the updated
|
|
2553
2648
|
* schema and list of operations applied.
|
|
2554
|
-
*
|
|
2649
|
+
*
|
|
2555
2650
|
* @param migration The migration class or instance to apply.
|
|
2556
2651
|
* @param options Options for applying the migration, including schema path and write flag.
|
|
2557
2652
|
* @returns A promise that resolves to an object containing the updated schema, schema path, and list of operations applied.
|
|
@@ -2590,10 +2685,10 @@ const applyMigrationRollbackToPrismaSchema = async (migration, options = {}) =>
|
|
|
2590
2685
|
};
|
|
2591
2686
|
};
|
|
2592
2687
|
/**
|
|
2593
|
-
* Run a migration by applying its schema operations to a Prisma schema
|
|
2594
|
-
* file, optionally generating Prisma client code and running migrations after
|
|
2688
|
+
* Run a migration by applying its schema operations to a Prisma schema
|
|
2689
|
+
* file, optionally generating Prisma client code and running migrations after
|
|
2595
2690
|
* applying the schema changes.
|
|
2596
|
-
*
|
|
2691
|
+
*
|
|
2597
2692
|
* @param migration The migration class or instance to run.
|
|
2598
2693
|
* @param options Options for running the migration, including schema path, write flag, and Prisma commands.
|
|
2599
2694
|
* @returns A promise that resolves to an object containing the schema path and list of operations applied.
|
|
@@ -2975,8 +3070,8 @@ const normalizePathInput = (paths) => {
|
|
|
2975
3070
|
const normalizeConstructors = (items) => items.flatMap((item) => Array.isArray(item) ? item : [item]).filter(Boolean);
|
|
2976
3071
|
/**
|
|
2977
3072
|
* Register additional runtime discovery paths without replacing configured paths.
|
|
2978
|
-
*
|
|
2979
|
-
* @param paths
|
|
3073
|
+
*
|
|
3074
|
+
* @param paths
|
|
2980
3075
|
*/
|
|
2981
3076
|
const registerPaths = (paths) => {
|
|
2982
3077
|
Object.entries(paths).forEach(([key, value]) => {
|
|
@@ -2985,69 +3080,69 @@ const registerPaths = (paths) => {
|
|
|
2985
3080
|
};
|
|
2986
3081
|
/**
|
|
2987
3082
|
* Register additional runtime discovery paths for migrations without replacing configured paths.
|
|
2988
|
-
*
|
|
2989
|
-
* @param paths
|
|
2990
|
-
* @returns
|
|
3083
|
+
*
|
|
3084
|
+
* @param paths
|
|
3085
|
+
* @returns
|
|
2991
3086
|
*/
|
|
2992
3087
|
const loadMigrationsFrom = (paths) => registerPaths({ migrations: paths });
|
|
2993
3088
|
/**
|
|
2994
3089
|
* Register additional runtime discovery paths for seeders without replacing configured paths.
|
|
2995
|
-
*
|
|
2996
|
-
* @param paths
|
|
2997
|
-
* @returns
|
|
3090
|
+
*
|
|
3091
|
+
* @param paths
|
|
3092
|
+
* @returns
|
|
2998
3093
|
*/
|
|
2999
3094
|
const loadSeedersFrom = (paths) => registerPaths({ seeders: paths });
|
|
3000
3095
|
/**
|
|
3001
3096
|
* Register additional runtime discovery paths for models without replacing configured paths.
|
|
3002
|
-
*
|
|
3003
|
-
* @param paths
|
|
3004
|
-
* @returns
|
|
3097
|
+
*
|
|
3098
|
+
* @param paths
|
|
3099
|
+
* @returns
|
|
3005
3100
|
*/
|
|
3006
3101
|
const loadModelsFrom = (paths) => registerPaths({ models: paths });
|
|
3007
3102
|
/**
|
|
3008
3103
|
* Register additional runtime discovery paths for factories without replacing configured paths.
|
|
3009
|
-
*
|
|
3010
|
-
* @param paths
|
|
3011
|
-
* @returns
|
|
3104
|
+
*
|
|
3105
|
+
* @param paths
|
|
3106
|
+
* @returns
|
|
3012
3107
|
*/
|
|
3013
3108
|
const loadFactoriesFrom = (paths) => registerPaths({ factories: paths });
|
|
3014
3109
|
/**
|
|
3015
3110
|
* Register migration constructors directly without relying on runtime discovery.
|
|
3016
|
-
*
|
|
3017
|
-
* @param migrations
|
|
3111
|
+
*
|
|
3112
|
+
* @param migrations
|
|
3018
3113
|
*/
|
|
3019
3114
|
const registerMigrations = (...migrations) => {
|
|
3020
3115
|
pushUnique(registry.migrations, normalizeConstructors(migrations));
|
|
3021
3116
|
};
|
|
3022
3117
|
/**
|
|
3023
3118
|
* Register seeder constructors directly without relying on runtime discovery.
|
|
3024
|
-
*
|
|
3025
|
-
* @param seeders
|
|
3119
|
+
*
|
|
3120
|
+
* @param seeders
|
|
3026
3121
|
*/
|
|
3027
3122
|
const registerSeeders = (...seeders) => {
|
|
3028
3123
|
pushUnique(registry.seeders, normalizeConstructors(seeders));
|
|
3029
3124
|
};
|
|
3030
3125
|
/**
|
|
3031
3126
|
* Register model constructors directly without relying on runtime discovery.
|
|
3032
|
-
*
|
|
3033
|
-
* @param models
|
|
3127
|
+
*
|
|
3128
|
+
* @param models
|
|
3034
3129
|
*/
|
|
3035
3130
|
const registerModels = (...models) => {
|
|
3036
3131
|
pushUnique(registry.models, normalizeConstructors(models));
|
|
3037
3132
|
};
|
|
3038
3133
|
/**
|
|
3039
3134
|
* Register factory constructors or instances directly without relying on runtime discovery.
|
|
3040
|
-
*
|
|
3041
|
-
* @param factories
|
|
3135
|
+
*
|
|
3136
|
+
* @param factories
|
|
3042
3137
|
*/
|
|
3043
3138
|
const registerFactories = (...factories) => {
|
|
3044
3139
|
pushUnique(registry.factories, normalizeConstructors(factories));
|
|
3045
3140
|
};
|
|
3046
3141
|
/**
|
|
3047
3142
|
* Get registered runtime discovery paths or registered constructors for a specific type.
|
|
3048
|
-
*
|
|
3049
|
-
* @param key
|
|
3050
|
-
* @returns
|
|
3143
|
+
*
|
|
3144
|
+
* @param key
|
|
3145
|
+
* @returns
|
|
3051
3146
|
*/
|
|
3052
3147
|
const getRegisteredPaths = (key) => {
|
|
3053
3148
|
if (key) return [...registry.paths[key]];
|
|
@@ -3060,26 +3155,26 @@ const getRegisteredPaths = (key) => {
|
|
|
3060
3155
|
};
|
|
3061
3156
|
/**
|
|
3062
3157
|
* Get registered migration constructors instances.
|
|
3063
|
-
*
|
|
3064
|
-
* @returns
|
|
3158
|
+
*
|
|
3159
|
+
* @returns
|
|
3065
3160
|
*/
|
|
3066
3161
|
const getRegisteredMigrations = () => [...registry.migrations];
|
|
3067
3162
|
/**
|
|
3068
3163
|
* Get registered seeder constructors instances.
|
|
3069
|
-
*
|
|
3070
|
-
* @returns
|
|
3164
|
+
*
|
|
3165
|
+
* @returns
|
|
3071
3166
|
*/
|
|
3072
3167
|
const getRegisteredSeeders = () => [...registry.seeders];
|
|
3073
3168
|
/**
|
|
3074
3169
|
* Get registered model constructors instances.
|
|
3075
|
-
*
|
|
3076
|
-
* @returns
|
|
3170
|
+
*
|
|
3171
|
+
* @returns
|
|
3077
3172
|
*/
|
|
3078
3173
|
const getRegisteredModels = () => [...registry.models];
|
|
3079
3174
|
/**
|
|
3080
3175
|
* Get registered factory constructors or instances.
|
|
3081
|
-
*
|
|
3082
|
-
* @returns
|
|
3176
|
+
*
|
|
3177
|
+
* @returns
|
|
3083
3178
|
*/
|
|
3084
3179
|
const getRegisteredFactories = () => [...registry.factories];
|
|
3085
3180
|
const resetRuntimeRegistryForTests = () => {
|
|
@@ -3183,9 +3278,9 @@ const mergePathConfig = (paths) => {
|
|
|
3183
3278
|
};
|
|
3184
3279
|
/**
|
|
3185
3280
|
* Merge the feature configuration from the base defaults, user configuration, and provided options.
|
|
3186
|
-
*
|
|
3187
|
-
* @param features
|
|
3188
|
-
* @returns
|
|
3281
|
+
*
|
|
3282
|
+
* @param features
|
|
3283
|
+
* @returns
|
|
3189
3284
|
*/
|
|
3190
3285
|
const mergeFeatureConfig = (features) => {
|
|
3191
3286
|
const defaults = baseConfig.features ?? {};
|
|
@@ -3241,7 +3336,7 @@ const awaitConfiguredModelsRegistration = async () => {
|
|
|
3241
3336
|
};
|
|
3242
3337
|
/**
|
|
3243
3338
|
* Define the ArkORM runtime configuration. This function can be used to provide.
|
|
3244
|
-
*
|
|
3339
|
+
*
|
|
3245
3340
|
* @param config The ArkORM configuration object.
|
|
3246
3341
|
* @returns The same configuration object.
|
|
3247
3342
|
*/
|
|
@@ -3250,10 +3345,10 @@ const defineConfig = (config) => {
|
|
|
3250
3345
|
};
|
|
3251
3346
|
/**
|
|
3252
3347
|
* Bind a database adapter instance to an array of models that support adapter binding.
|
|
3253
|
-
*
|
|
3254
|
-
* @param adapter
|
|
3255
|
-
* @param models
|
|
3256
|
-
* @returns
|
|
3348
|
+
*
|
|
3349
|
+
* @param adapter
|
|
3350
|
+
* @param models
|
|
3351
|
+
* @returns
|
|
3257
3352
|
*/
|
|
3258
3353
|
const bindAdapterToModels = (adapter, models) => {
|
|
3259
3354
|
models.forEach((model) => {
|
|
@@ -3262,10 +3357,10 @@ const bindAdapterToModels = (adapter, models) => {
|
|
|
3262
3357
|
return adapter;
|
|
3263
3358
|
};
|
|
3264
3359
|
/**
|
|
3265
|
-
* Get the user-provided ArkORM configuration.
|
|
3266
|
-
*
|
|
3360
|
+
* Get the user-provided ArkORM configuration.
|
|
3361
|
+
*
|
|
3267
3362
|
* @param key Optional specific configuration key to retrieve. If omitted, the entire configuration object is returned.
|
|
3268
|
-
* @returns The user-provided ArkORM configuration object.
|
|
3363
|
+
* @returns The user-provided ArkORM configuration object.
|
|
3269
3364
|
*/
|
|
3270
3365
|
const getUserConfig = (key) => {
|
|
3271
3366
|
if (key) return userConfig[key];
|
|
@@ -3274,8 +3369,8 @@ const getUserConfig = (key) => {
|
|
|
3274
3369
|
/**
|
|
3275
3370
|
* Configure the ArkORM runtime with the provided runtime client resolver and
|
|
3276
3371
|
* adapter-first options.
|
|
3277
|
-
*
|
|
3278
|
-
* @param client
|
|
3372
|
+
*
|
|
3373
|
+
* @param client
|
|
3279
3374
|
* @param options
|
|
3280
3375
|
*/
|
|
3281
3376
|
const configureArkormRuntime = (client, options = {}) => {
|
|
@@ -3308,7 +3403,7 @@ const configureArkormRuntime = (client, options = {}) => {
|
|
|
3308
3403
|
});
|
|
3309
3404
|
};
|
|
3310
3405
|
/**
|
|
3311
|
-
* Reset the ArkORM runtime configuration.
|
|
3406
|
+
* Reset the ArkORM runtime configuration.
|
|
3312
3407
|
* This is primarily intended for testing purposes.
|
|
3313
3408
|
*/
|
|
3314
3409
|
const resetArkormRuntimeForTests = () => {
|
|
@@ -3333,9 +3428,9 @@ const resetArkormRuntimeForTests = () => {
|
|
|
3333
3428
|
/**
|
|
3334
3429
|
* Resolve a runtime client instance from the provided resolver, which can be either
|
|
3335
3430
|
* a direct client instance or a function that returns a client instance.
|
|
3336
|
-
*
|
|
3337
|
-
* @param resolver
|
|
3338
|
-
* @returns
|
|
3431
|
+
*
|
|
3432
|
+
* @param resolver
|
|
3433
|
+
* @returns
|
|
3339
3434
|
*/
|
|
3340
3435
|
const resolveClient = (resolver) => {
|
|
3341
3436
|
if (!resolver) return void 0;
|
|
@@ -3344,12 +3439,12 @@ const resolveClient = (resolver) => {
|
|
|
3344
3439
|
return client;
|
|
3345
3440
|
};
|
|
3346
3441
|
/**
|
|
3347
|
-
* Resolve and apply the ArkORM configuration from an imported module.
|
|
3442
|
+
* Resolve and apply the ArkORM configuration from an imported module.
|
|
3348
3443
|
* This function checks for a default export and falls back to the module itself, then validates
|
|
3349
3444
|
* the configuration object and applies it to the runtime if valid.
|
|
3350
|
-
*
|
|
3351
|
-
* @param imported
|
|
3352
|
-
* @returns
|
|
3445
|
+
*
|
|
3446
|
+
* @param imported
|
|
3447
|
+
* @returns
|
|
3353
3448
|
*/
|
|
3354
3449
|
const resolveAndApplyConfig = (imported) => {
|
|
3355
3450
|
const config = imported?.default ?? imported;
|
|
@@ -3369,11 +3464,11 @@ const resolveAndApplyConfig = (imported) => {
|
|
|
3369
3464
|
runtimeConfigLoaded = true;
|
|
3370
3465
|
};
|
|
3371
3466
|
/**
|
|
3372
|
-
* Dynamically import a configuration file.
|
|
3467
|
+
* Dynamically import a configuration file.
|
|
3373
3468
|
* A cache-busting query parameter is appended to ensure the latest version is loaded.
|
|
3374
|
-
*
|
|
3375
|
-
* @param configPath
|
|
3376
|
-
* @returns A promise that resolves to the imported configuration module.
|
|
3469
|
+
*
|
|
3470
|
+
* @param configPath
|
|
3471
|
+
* @returns A promise that resolves to the imported configuration module.
|
|
3377
3472
|
*/
|
|
3378
3473
|
const importConfigFile = (configPath) => {
|
|
3379
3474
|
return RuntimeModuleLoader.load(configPath);
|
|
@@ -3393,9 +3488,9 @@ const loadRuntimeConfigSync = () => {
|
|
|
3393
3488
|
return false;
|
|
3394
3489
|
};
|
|
3395
3490
|
/**
|
|
3396
|
-
* Load the ArkORM configuration by searching for configuration files in the
|
|
3491
|
+
* Load the ArkORM configuration by searching for configuration files in the
|
|
3397
3492
|
* current working directory.
|
|
3398
|
-
* @returns
|
|
3493
|
+
* @returns
|
|
3399
3494
|
*/
|
|
3400
3495
|
const loadArkormConfig = async () => {
|
|
3401
3496
|
if (runtimeConfigLoaded) {
|
|
@@ -3426,11 +3521,11 @@ const loadArkormConfig = async () => {
|
|
|
3426
3521
|
await runtimeConfigLoadingPromise;
|
|
3427
3522
|
};
|
|
3428
3523
|
/**
|
|
3429
|
-
* Ensure that the ArkORM configuration is loaded.
|
|
3524
|
+
* Ensure that the ArkORM configuration is loaded.
|
|
3430
3525
|
* This function can be called to trigger the loading process if it hasn't already been initiated.
|
|
3431
3526
|
* If the configuration is already loaded, it will return immediately.
|
|
3432
|
-
*
|
|
3433
|
-
* @returns
|
|
3527
|
+
*
|
|
3528
|
+
* @returns
|
|
3434
3529
|
*/
|
|
3435
3530
|
const ensureArkormConfigLoading = () => {
|
|
3436
3531
|
if (runtimeConfigLoaded) return;
|
|
@@ -3441,10 +3536,10 @@ const getDefaultStubsPath = () => {
|
|
|
3441
3536
|
};
|
|
3442
3537
|
/**
|
|
3443
3538
|
* Get the runtime compatibility client.
|
|
3444
|
-
* This function will trigger the loading of the ArkORM configuration if
|
|
3539
|
+
* This function will trigger the loading of the ArkORM configuration if
|
|
3445
3540
|
* it hasn't already been loaded.
|
|
3446
|
-
*
|
|
3447
|
-
* @returns
|
|
3541
|
+
*
|
|
3542
|
+
* @returns
|
|
3448
3543
|
*/
|
|
3449
3544
|
const getRuntimeClient = () => {
|
|
3450
3545
|
const activeTransactionClient = transactionClientStorage.getStore();
|
|
@@ -3458,8 +3553,8 @@ const getRuntimeClient = () => {
|
|
|
3458
3553
|
const getRuntimePrismaClient = getRuntimeClient;
|
|
3459
3554
|
/**
|
|
3460
3555
|
* Get the currently configured runtime adapter, if any.
|
|
3461
|
-
*
|
|
3462
|
-
* @returns
|
|
3556
|
+
*
|
|
3557
|
+
* @returns
|
|
3463
3558
|
*/
|
|
3464
3559
|
const getRuntimeAdapter = () => {
|
|
3465
3560
|
const activeTransactionAdapter = transactionAdapterStorage.getStore();
|
|
@@ -3536,7 +3631,7 @@ const emitRuntimeDebugEvent = (event) => {
|
|
|
3536
3631
|
/**
|
|
3537
3632
|
* Check if a given value matches Arkorm's query-schema contract
|
|
3538
3633
|
* by verifying the presence of common delegate methods.
|
|
3539
|
-
*
|
|
3634
|
+
*
|
|
3540
3635
|
* @param value The value to check.
|
|
3541
3636
|
* @returns True if the value matches the query-schema contract, false otherwise.
|
|
3542
3637
|
*/
|
|
@@ -3562,7 +3657,7 @@ loadArkormConfig();
|
|
|
3562
3657
|
//#region src/URLDriver.ts
|
|
3563
3658
|
/**
|
|
3564
3659
|
* URLDriver builds pagination URLs from paginator options.
|
|
3565
|
-
*
|
|
3660
|
+
*
|
|
3566
3661
|
* @author Legacy (3m1n3nc3)
|
|
3567
3662
|
* @since 0.1.0
|
|
3568
3663
|
*/
|
|
@@ -3605,7 +3700,7 @@ var URLDriver = class URLDriver {
|
|
|
3605
3700
|
/**
|
|
3606
3701
|
* The LengthAwarePaginator class encapsulates paginated results with full
|
|
3607
3702
|
* metadata including the total result count and last page.
|
|
3608
|
-
*
|
|
3703
|
+
*
|
|
3609
3704
|
* @template T The type of the data being paginated.
|
|
3610
3705
|
* @author Legacy (3m1n3nc3)
|
|
3611
3706
|
* @since 0.1.0
|
|
@@ -3613,7 +3708,7 @@ var URLDriver = class URLDriver {
|
|
|
3613
3708
|
var LengthAwarePaginator = class {
|
|
3614
3709
|
/**
|
|
3615
3710
|
* Creates a new LengthAwarePaginator instance.
|
|
3616
|
-
*
|
|
3711
|
+
*
|
|
3617
3712
|
* @param data The collection of data being paginated.
|
|
3618
3713
|
* @param total The total number of items.
|
|
3619
3714
|
* @param perPage The number of items per page.
|
|
@@ -3658,8 +3753,8 @@ var LengthAwarePaginator = class {
|
|
|
3658
3753
|
}
|
|
3659
3754
|
/**
|
|
3660
3755
|
* Converts the paginator instance to a JSON-serializable object.
|
|
3661
|
-
*
|
|
3662
|
-
* @returns
|
|
3756
|
+
*
|
|
3757
|
+
* @returns
|
|
3663
3758
|
*/
|
|
3664
3759
|
toJSON() {
|
|
3665
3760
|
return {
|
|
@@ -3734,7 +3829,7 @@ var Paginator = class {
|
|
|
3734
3829
|
//#region src/relationship/Relation.ts
|
|
3735
3830
|
/**
|
|
3736
3831
|
* Base class for all relationship types. Not meant to be used directly.
|
|
3737
|
-
*
|
|
3832
|
+
*
|
|
3738
3833
|
* @author Legacy (3m1n3nc3)
|
|
3739
3834
|
* @since 0.1.0
|
|
3740
3835
|
*/
|
|
@@ -3780,7 +3875,7 @@ var Relation = class {
|
|
|
3780
3875
|
}
|
|
3781
3876
|
/**
|
|
3782
3877
|
* Apply a constraint to the relationship query.
|
|
3783
|
-
*
|
|
3878
|
+
*
|
|
3784
3879
|
* @param constraint The constraint function to apply to the query.
|
|
3785
3880
|
* @returns The current relation instance.
|
|
3786
3881
|
*/
|
|
@@ -3884,81 +3979,81 @@ var Relation = class {
|
|
|
3884
3979
|
}
|
|
3885
3980
|
/**
|
|
3886
3981
|
* Adds clause to determine if a column's value is in the past
|
|
3887
|
-
*
|
|
3888
|
-
* @param key
|
|
3889
|
-
* @returns
|
|
3982
|
+
*
|
|
3983
|
+
* @param key
|
|
3984
|
+
* @returns
|
|
3890
3985
|
*/
|
|
3891
3986
|
wherePast(key) {
|
|
3892
3987
|
return this.constrain((query) => query.wherePast(key));
|
|
3893
3988
|
}
|
|
3894
3989
|
/**
|
|
3895
3990
|
* Adds clause to determine if a column's value is in the future
|
|
3896
|
-
*
|
|
3897
|
-
* @param key
|
|
3898
|
-
* @returns
|
|
3991
|
+
*
|
|
3992
|
+
* @param key
|
|
3993
|
+
* @returns
|
|
3899
3994
|
*/
|
|
3900
3995
|
whereFuture(key) {
|
|
3901
3996
|
return this.constrain((query) => query.whereFuture(key));
|
|
3902
3997
|
}
|
|
3903
3998
|
/**
|
|
3904
3999
|
* Adds clause to determine if a column's value is in the past, inclusive of the current date and time
|
|
3905
|
-
*
|
|
3906
|
-
* @param key
|
|
3907
|
-
* @returns
|
|
4000
|
+
*
|
|
4001
|
+
* @param key
|
|
4002
|
+
* @returns
|
|
3908
4003
|
*/
|
|
3909
4004
|
whereNowOrPast(key) {
|
|
3910
4005
|
return this.constrain((query) => query.whereNowOrPast(key));
|
|
3911
4006
|
}
|
|
3912
4007
|
/**
|
|
3913
4008
|
* Adds clause to determine if a column's value is in the future, inclusive of the current date and time
|
|
3914
|
-
*
|
|
3915
|
-
* @param key
|
|
3916
|
-
* @returns
|
|
4009
|
+
*
|
|
4010
|
+
* @param key
|
|
4011
|
+
* @returns
|
|
3917
4012
|
*/
|
|
3918
4013
|
whereNowOrFuture(key) {
|
|
3919
4014
|
return this.constrain((query) => query.whereNowOrFuture(key));
|
|
3920
4015
|
}
|
|
3921
4016
|
/**
|
|
3922
4017
|
* Adds clause to determine if a column's value is today
|
|
3923
|
-
*
|
|
3924
|
-
* @param key
|
|
3925
|
-
* @returns
|
|
4018
|
+
*
|
|
4019
|
+
* @param key
|
|
4020
|
+
* @returns
|
|
3926
4021
|
*/
|
|
3927
4022
|
whereToday(key) {
|
|
3928
4023
|
return this.constrain((query) => query.whereToday(key));
|
|
3929
4024
|
}
|
|
3930
4025
|
/**
|
|
3931
4026
|
* Adds clause to determine if a column's value is before today
|
|
3932
|
-
*
|
|
3933
|
-
* @param key
|
|
3934
|
-
* @returns
|
|
4027
|
+
*
|
|
4028
|
+
* @param key
|
|
4029
|
+
* @returns
|
|
3935
4030
|
*/
|
|
3936
4031
|
whereBeforeToday(key) {
|
|
3937
4032
|
return this.constrain((query) => query.whereBeforeToday(key));
|
|
3938
4033
|
}
|
|
3939
4034
|
/**
|
|
3940
4035
|
* Adds clause to determine if a column's value is after today
|
|
3941
|
-
*
|
|
3942
|
-
* @param key
|
|
3943
|
-
* @returns
|
|
4036
|
+
*
|
|
4037
|
+
* @param key
|
|
4038
|
+
* @returns
|
|
3944
4039
|
*/
|
|
3945
4040
|
whereAfterToday(key) {
|
|
3946
4041
|
return this.constrain((query) => query.whereAfterToday(key));
|
|
3947
4042
|
}
|
|
3948
4043
|
/**
|
|
3949
4044
|
* Adds clause to determine if a column's value is today or before today
|
|
3950
|
-
*
|
|
3951
|
-
* @param key
|
|
3952
|
-
* @returns
|
|
4045
|
+
*
|
|
4046
|
+
* @param key
|
|
4047
|
+
* @returns
|
|
3953
4048
|
*/
|
|
3954
4049
|
whereTodayOrBefore(key) {
|
|
3955
4050
|
return this.constrain((query) => query.whereTodayOrBefore(key));
|
|
3956
4051
|
}
|
|
3957
4052
|
/**
|
|
3958
4053
|
* Adds clause to determine if a column's value is today or after today
|
|
3959
|
-
*
|
|
3960
|
-
* @param key
|
|
3961
|
-
* @returns
|
|
4054
|
+
*
|
|
4055
|
+
* @param key
|
|
4056
|
+
* @returns
|
|
3962
4057
|
*/
|
|
3963
4058
|
whereTodayOrAfter(key) {
|
|
3964
4059
|
return this.constrain((query) => query.whereTodayOrAfter(key));
|
|
@@ -3968,9 +4063,9 @@ var Relation = class {
|
|
|
3968
4063
|
}
|
|
3969
4064
|
/**
|
|
3970
4065
|
* Adds "where exists" SQL clauses.
|
|
3971
|
-
*
|
|
3972
|
-
* @param queryOrCallback
|
|
3973
|
-
* @returns
|
|
4066
|
+
*
|
|
4067
|
+
* @param queryOrCallback
|
|
4068
|
+
* @returns
|
|
3974
4069
|
*/
|
|
3975
4070
|
whereExists(queryOrCallback) {
|
|
3976
4071
|
return this.constrain((query) => query.whereExists(queryOrCallback));
|
|
@@ -4069,107 +4164,107 @@ var Relation = class {
|
|
|
4069
4164
|
}
|
|
4070
4165
|
/**
|
|
4071
4166
|
* Add an OR string contains clause to the relationship query.
|
|
4072
|
-
*
|
|
4073
|
-
* @param key
|
|
4074
|
-
* @param value
|
|
4075
|
-
* @returns
|
|
4167
|
+
*
|
|
4168
|
+
* @param key
|
|
4169
|
+
* @param value
|
|
4170
|
+
* @returns
|
|
4076
4171
|
*/
|
|
4077
4172
|
orWhereLike(key, value) {
|
|
4078
4173
|
return this.constrain((query) => query.orWhereLike(key, value));
|
|
4079
4174
|
}
|
|
4080
4175
|
/**
|
|
4081
4176
|
* Add a negated string contains (NOT LIKE) clause to the relationship query.
|
|
4082
|
-
*
|
|
4083
|
-
* @param key
|
|
4084
|
-
* @param value
|
|
4085
|
-
* @returns
|
|
4177
|
+
*
|
|
4178
|
+
* @param key
|
|
4179
|
+
* @param value
|
|
4180
|
+
* @returns
|
|
4086
4181
|
*/
|
|
4087
4182
|
whereNotLike(key, value) {
|
|
4088
4183
|
return this.constrain((query) => query.whereNotLike(key, value));
|
|
4089
4184
|
}
|
|
4090
4185
|
/**
|
|
4091
4186
|
* Add an OR negated string contains (NOT LIKE) clause to the relationship query.
|
|
4092
|
-
*
|
|
4093
|
-
* @param key
|
|
4094
|
-
* @param value
|
|
4095
|
-
* @returns
|
|
4187
|
+
*
|
|
4188
|
+
* @param key
|
|
4189
|
+
* @param value
|
|
4190
|
+
* @returns
|
|
4096
4191
|
*/
|
|
4097
4192
|
orWhereNotLike(key, value) {
|
|
4098
4193
|
return this.constrain((query) => query.orWhereNotLike(key, value));
|
|
4099
4194
|
}
|
|
4100
4195
|
/**
|
|
4101
4196
|
* Add a JSON containment clause to the relationship query.
|
|
4102
|
-
*
|
|
4103
|
-
* @param key
|
|
4104
|
-
* @param value
|
|
4105
|
-
* @returns
|
|
4197
|
+
*
|
|
4198
|
+
* @param key
|
|
4199
|
+
* @param value
|
|
4200
|
+
* @returns
|
|
4106
4201
|
*/
|
|
4107
4202
|
whereJsonContains(column, value) {
|
|
4108
4203
|
return this.constrain((query) => query.whereJsonContains(column, value));
|
|
4109
4204
|
}
|
|
4110
4205
|
/**
|
|
4111
4206
|
* OR variant of whereJsonContains().
|
|
4112
|
-
*
|
|
4113
|
-
* @param column
|
|
4114
|
-
* @param value
|
|
4115
|
-
* @returns
|
|
4207
|
+
*
|
|
4208
|
+
* @param column
|
|
4209
|
+
* @param value
|
|
4210
|
+
* @returns
|
|
4116
4211
|
*/
|
|
4117
4212
|
orWhereJsonContains(column, value) {
|
|
4118
4213
|
return this.constrain((query) => query.orWhereJsonContains(column, value));
|
|
4119
4214
|
}
|
|
4120
4215
|
/**
|
|
4121
4216
|
* Add a negated JSON containment clause to the relationship query.
|
|
4122
|
-
*
|
|
4123
|
-
* @param column
|
|
4124
|
-
* @param value
|
|
4125
|
-
* @returns
|
|
4217
|
+
*
|
|
4218
|
+
* @param column
|
|
4219
|
+
* @param value
|
|
4220
|
+
* @returns
|
|
4126
4221
|
*/
|
|
4127
4222
|
whereJsonDoesntContain(column, value) {
|
|
4128
4223
|
return this.constrain((query) => query.whereJsonDoesntContain(column, value));
|
|
4129
4224
|
}
|
|
4130
4225
|
/**
|
|
4131
4226
|
* OR variant of whereJsonDoesntContain().
|
|
4132
|
-
*
|
|
4133
|
-
* @param column
|
|
4134
|
-
* @param value
|
|
4135
|
-
* @returns
|
|
4227
|
+
*
|
|
4228
|
+
* @param column
|
|
4229
|
+
* @param value
|
|
4230
|
+
* @returns
|
|
4136
4231
|
*/
|
|
4137
4232
|
orWhereJsonDoesntContain(column, value) {
|
|
4138
4233
|
return this.constrain((query) => query.orWhereJsonDoesntContain(column, value));
|
|
4139
4234
|
}
|
|
4140
4235
|
/**
|
|
4141
4236
|
* Add a JSON key-existence clause to the relationship query.
|
|
4142
|
-
*
|
|
4143
|
-
* @param column
|
|
4144
|
-
* @param value
|
|
4145
|
-
* @returns
|
|
4237
|
+
*
|
|
4238
|
+
* @param column
|
|
4239
|
+
* @param value
|
|
4240
|
+
* @returns
|
|
4146
4241
|
*/
|
|
4147
4242
|
whereJsonContainsKey(column) {
|
|
4148
4243
|
return this.constrain((query) => query.whereJsonContainsKey(column));
|
|
4149
4244
|
}
|
|
4150
4245
|
/**
|
|
4151
4246
|
* OR variant of whereJsonContainsKey().
|
|
4152
|
-
*
|
|
4153
|
-
* @param column
|
|
4154
|
-
* @returns
|
|
4247
|
+
*
|
|
4248
|
+
* @param column
|
|
4249
|
+
* @returns
|
|
4155
4250
|
*/
|
|
4156
4251
|
orWhereJsonContainsKey(column) {
|
|
4157
4252
|
return this.constrain((query) => query.orWhereJsonContainsKey(column));
|
|
4158
4253
|
}
|
|
4159
4254
|
/**
|
|
4160
4255
|
* Add a negated JSON key-existence clause to the relationship query.
|
|
4161
|
-
*
|
|
4162
|
-
* @param column
|
|
4163
|
-
* @returns
|
|
4256
|
+
*
|
|
4257
|
+
* @param column
|
|
4258
|
+
* @returns
|
|
4164
4259
|
*/
|
|
4165
4260
|
whereJsonDoesntContainKey(column) {
|
|
4166
4261
|
return this.constrain((query) => query.whereJsonDoesntContainKey(column));
|
|
4167
4262
|
}
|
|
4168
4263
|
/**
|
|
4169
4264
|
* OR variant of whereJsonDoesntContainKey().
|
|
4170
|
-
*
|
|
4171
|
-
* @param column
|
|
4172
|
-
* @returns
|
|
4265
|
+
*
|
|
4266
|
+
* @param column
|
|
4267
|
+
* @returns
|
|
4173
4268
|
*/
|
|
4174
4269
|
orWhereJsonDoesntContainKey(column) {
|
|
4175
4270
|
return this.constrain((query) => query.orWhereJsonDoesntContainKey(column));
|
|
@@ -4182,18 +4277,18 @@ var Relation = class {
|
|
|
4182
4277
|
}
|
|
4183
4278
|
/**
|
|
4184
4279
|
* Add a JSON array overlap clause to the relationship query.
|
|
4185
|
-
*
|
|
4186
|
-
* @param column
|
|
4187
|
-
* @param value
|
|
4280
|
+
*
|
|
4281
|
+
* @param column
|
|
4282
|
+
* @param value
|
|
4188
4283
|
*/
|
|
4189
4284
|
whereJsonOverlaps(column, value) {
|
|
4190
4285
|
return this.constrain((query) => query.whereJsonOverlaps(column, value));
|
|
4191
4286
|
}
|
|
4192
4287
|
/**
|
|
4193
4288
|
* OR variant of whereJsonOverlaps().
|
|
4194
|
-
*
|
|
4195
|
-
* @param column
|
|
4196
|
-
* @param value
|
|
4289
|
+
*
|
|
4290
|
+
* @param column
|
|
4291
|
+
* @param value
|
|
4197
4292
|
*/
|
|
4198
4293
|
orWhereJsonOverlaps(column, value) {
|
|
4199
4294
|
return this.constrain((query) => query.orWhereJsonOverlaps(column, value));
|
|
@@ -4420,9 +4515,9 @@ var Relation = class {
|
|
|
4420
4515
|
}
|
|
4421
4516
|
/**
|
|
4422
4517
|
* Apply the defined constraint to the given query, if any.
|
|
4423
|
-
*
|
|
4518
|
+
*
|
|
4424
4519
|
* @param query The query builder instance to apply the constraint to.
|
|
4425
|
-
*
|
|
4520
|
+
*
|
|
4426
4521
|
* @returns The query builder instance with the constraint applied, if any.
|
|
4427
4522
|
*/
|
|
4428
4523
|
applyConstraint(query) {
|
|
@@ -4449,18 +4544,18 @@ var Relation = class {
|
|
|
4449
4544
|
}
|
|
4450
4545
|
/**
|
|
4451
4546
|
* Execute the relationship query and return the first related model or throw an error if not found.
|
|
4452
|
-
*
|
|
4453
|
-
* @returns
|
|
4547
|
+
*
|
|
4548
|
+
* @returns
|
|
4454
4549
|
*/
|
|
4455
4550
|
async firstOrFail() {
|
|
4456
4551
|
return (await this.getQuery()).firstOrFail();
|
|
4457
4552
|
}
|
|
4458
4553
|
/**
|
|
4459
|
-
* Execute the relationship query and return the first related model or the result of
|
|
4554
|
+
* Execute the relationship query and return the first related model or the result of
|
|
4460
4555
|
* the callback if not found.
|
|
4461
|
-
*
|
|
4462
|
-
* @param callback
|
|
4463
|
-
* @returns
|
|
4556
|
+
*
|
|
4557
|
+
* @param callback
|
|
4558
|
+
* @returns
|
|
4464
4559
|
*/
|
|
4465
4560
|
async firstOr(callback) {
|
|
4466
4561
|
const result = await this.first();
|
|
@@ -4496,11 +4591,11 @@ var Relation = class {
|
|
|
4496
4591
|
return !await this.exists();
|
|
4497
4592
|
}
|
|
4498
4593
|
/**
|
|
4499
|
-
* Create a new instance of the related model with the given attributes and
|
|
4594
|
+
* Create a new instance of the related model with the given attributes and
|
|
4500
4595
|
* relationship creation attributes applied, but do not save it.
|
|
4501
|
-
*
|
|
4502
|
-
* @param attributes
|
|
4503
|
-
* @returns
|
|
4596
|
+
*
|
|
4597
|
+
* @param attributes
|
|
4598
|
+
* @returns
|
|
4504
4599
|
*/
|
|
4505
4600
|
make(attributes = {}) {
|
|
4506
4601
|
const model = this.getRelatedModelConstructor().hydrate(this.mergeCreationAttributes(attributes));
|
|
@@ -4508,31 +4603,31 @@ var Relation = class {
|
|
|
4508
4603
|
return model;
|
|
4509
4604
|
}
|
|
4510
4605
|
/**
|
|
4511
|
-
* Create new instances of the related model with the given attributes and relationship
|
|
4606
|
+
* Create new instances of the related model with the given attributes and relationship
|
|
4512
4607
|
* creation attributes applied, but do not save them.
|
|
4513
|
-
*
|
|
4514
|
-
* @param attributes
|
|
4515
|
-
* @returns
|
|
4608
|
+
*
|
|
4609
|
+
* @param attributes
|
|
4610
|
+
* @returns
|
|
4516
4611
|
*/
|
|
4517
4612
|
makeMany(attributes = []) {
|
|
4518
4613
|
return attributes.map((item) => this.make(item));
|
|
4519
4614
|
}
|
|
4520
4615
|
/**
|
|
4521
|
-
* Create a new instance of the related model with the given attributes and relationship
|
|
4616
|
+
* Create a new instance of the related model with the given attributes and relationship
|
|
4522
4617
|
* creation attributes applied, and save it to the database.
|
|
4523
|
-
*
|
|
4524
|
-
* @param attributes
|
|
4525
|
-
* @returns
|
|
4618
|
+
*
|
|
4619
|
+
* @param attributes
|
|
4620
|
+
* @returns
|
|
4526
4621
|
*/
|
|
4527
4622
|
async create(attributes = {}) {
|
|
4528
4623
|
return await this.getRelatedModelConstructor().query().create(this.mergeCreationAttributes(attributes));
|
|
4529
4624
|
}
|
|
4530
4625
|
/**
|
|
4531
|
-
* Create new instances of the related model with the given attributes and relationship
|
|
4626
|
+
* Create new instances of the related model with the given attributes and relationship
|
|
4532
4627
|
* creation attributes applied, and save them to the database.
|
|
4533
|
-
*
|
|
4534
|
-
* @param values
|
|
4535
|
-
* @returns
|
|
4628
|
+
*
|
|
4629
|
+
* @param values
|
|
4630
|
+
* @returns
|
|
4536
4631
|
*/
|
|
4537
4632
|
async createMany(values = []) {
|
|
4538
4633
|
if (values.length === 0) return [];
|
|
@@ -4540,9 +4635,9 @@ var Relation = class {
|
|
|
4540
4635
|
}
|
|
4541
4636
|
/**
|
|
4542
4637
|
* Save the given model instance by applying relationship creation attributes and calling save() on it.
|
|
4543
|
-
*
|
|
4544
|
-
* @param model
|
|
4545
|
-
* @returns
|
|
4638
|
+
*
|
|
4639
|
+
* @param model
|
|
4640
|
+
* @returns
|
|
4546
4641
|
*/
|
|
4547
4642
|
async save(model) {
|
|
4548
4643
|
const saveable = this.applyCreationAttributesToModel(model);
|
|
@@ -4556,11 +4651,11 @@ var Relation = class {
|
|
|
4556
4651
|
}
|
|
4557
4652
|
}
|
|
4558
4653
|
/**
|
|
4559
|
-
* Save the given model instance by applying relationship creation attributes and
|
|
4654
|
+
* Save the given model instance by applying relationship creation attributes and
|
|
4560
4655
|
* calling saveQuietly() on it if supported, otherwise falling back to save().
|
|
4561
|
-
*
|
|
4562
|
-
* @param model
|
|
4563
|
-
* @returns
|
|
4656
|
+
*
|
|
4657
|
+
* @param model
|
|
4658
|
+
* @returns
|
|
4564
4659
|
*/
|
|
4565
4660
|
async saveQuietly(model) {
|
|
4566
4661
|
const saveable = this.applyCreationAttributesToModel(model);
|
|
@@ -4578,21 +4673,21 @@ var Relation = class {
|
|
|
4578
4673
|
return error instanceof Error && (error.name === "ModelNotFoundException" || error.message.includes("Record not found"));
|
|
4579
4674
|
}
|
|
4580
4675
|
/**
|
|
4581
|
-
* Create new instances of the related model with the given attributes and
|
|
4676
|
+
* Create new instances of the related model with the given attributes and
|
|
4582
4677
|
* relationship * creation attributes applied, and save them to the database.
|
|
4583
|
-
*
|
|
4584
|
-
* @param models
|
|
4585
|
-
* @returns
|
|
4678
|
+
*
|
|
4679
|
+
* @param models
|
|
4680
|
+
* @returns
|
|
4586
4681
|
*/
|
|
4587
4682
|
async saveMany(models = []) {
|
|
4588
4683
|
return await Promise.all(models.map(async (model) => await this.save(model)));
|
|
4589
4684
|
}
|
|
4590
4685
|
/**
|
|
4591
|
-
* Create new instances of the related model with the given attributes and relationship
|
|
4686
|
+
* Create new instances of the related model with the given attributes and relationship
|
|
4592
4687
|
* creation attributes applied, and save them to the database.
|
|
4593
|
-
*
|
|
4594
|
-
* @param models
|
|
4595
|
-
* @returns
|
|
4688
|
+
*
|
|
4689
|
+
* @param models
|
|
4690
|
+
* @returns
|
|
4596
4691
|
*/
|
|
4597
4692
|
async saveManyQuietly(models = []) {
|
|
4598
4693
|
return await Promise.all(models.map(async (model) => await this.saveQuietly(model)));
|
|
@@ -4616,10 +4711,10 @@ var Relation = class {
|
|
|
4616
4711
|
}
|
|
4617
4712
|
/**
|
|
4618
4713
|
* Find the first related model by a specific key and value, or create a new instance if not found.
|
|
4619
|
-
*
|
|
4620
|
-
* @param attributes
|
|
4621
|
-
* @param values
|
|
4622
|
-
* @returns
|
|
4714
|
+
*
|
|
4715
|
+
* @param attributes
|
|
4716
|
+
* @param values
|
|
4717
|
+
* @returns
|
|
4623
4718
|
*/
|
|
4624
4719
|
async firstOrNew(attributes, values = {}) {
|
|
4625
4720
|
const found = await (await this.getQuery()).clone().where(attributes).first();
|
|
@@ -4630,12 +4725,12 @@ var Relation = class {
|
|
|
4630
4725
|
});
|
|
4631
4726
|
}
|
|
4632
4727
|
/**
|
|
4633
|
-
* Find the first related model by a specific key and value, or create and save a new instance
|
|
4728
|
+
* Find the first related model by a specific key and value, or create and save a new instance
|
|
4634
4729
|
* if not found.
|
|
4635
|
-
*
|
|
4636
|
-
* @param attributes
|
|
4637
|
-
* @param values
|
|
4638
|
-
* @returns
|
|
4730
|
+
*
|
|
4731
|
+
* @param attributes
|
|
4732
|
+
* @param values
|
|
4733
|
+
* @returns
|
|
4639
4734
|
*/
|
|
4640
4735
|
async firstOrCreate(attributes, values = {}) {
|
|
4641
4736
|
const found = await (await this.getQuery()).clone().where(attributes).first();
|
|
@@ -4646,12 +4741,12 @@ var Relation = class {
|
|
|
4646
4741
|
});
|
|
4647
4742
|
}
|
|
4648
4743
|
/**
|
|
4649
|
-
* Find the first related model by a specific key and value, update the first matching record with
|
|
4744
|
+
* Find the first related model by a specific key and value, update the first matching record with
|
|
4650
4745
|
* the given values, or create and save a new instance if no matching record is found.
|
|
4651
|
-
*
|
|
4652
|
-
* @param attributes
|
|
4653
|
-
* @param values
|
|
4654
|
-
* @returns
|
|
4746
|
+
*
|
|
4747
|
+
* @param attributes
|
|
4748
|
+
* @param values
|
|
4749
|
+
* @returns
|
|
4655
4750
|
*/
|
|
4656
4751
|
async updateOrCreate(attributes, values = {}) {
|
|
4657
4752
|
const query = await this.getQuery();
|
|
@@ -4665,35 +4760,35 @@ var Relation = class {
|
|
|
4665
4760
|
return await query.clone().where(attributes).update(values);
|
|
4666
4761
|
}
|
|
4667
4762
|
/**
|
|
4668
|
-
* Find related models by specific attributes, update matching records with the given values, or
|
|
4763
|
+
* Find related models by specific attributes, update matching records with the given values, or
|
|
4669
4764
|
* create and save new instances if no matching records are found.
|
|
4670
|
-
*
|
|
4671
|
-
* @param values
|
|
4672
|
-
* @param uniqueBy
|
|
4673
|
-
* @param update
|
|
4674
|
-
* @returns
|
|
4765
|
+
*
|
|
4766
|
+
* @param values
|
|
4767
|
+
* @param uniqueBy
|
|
4768
|
+
* @param update
|
|
4769
|
+
* @returns
|
|
4675
4770
|
*/
|
|
4676
4771
|
async upsert(values, uniqueBy, update = null) {
|
|
4677
4772
|
return await (await this.getQuery()).upsert(values.map((value) => this.mergeCreationAttributes(value)), uniqueBy, update);
|
|
4678
4773
|
}
|
|
4679
4774
|
/**
|
|
4680
4775
|
* Paginate the relationship query results.
|
|
4681
|
-
*
|
|
4682
|
-
* @param perPage
|
|
4683
|
-
* @param page
|
|
4684
|
-
* @param options
|
|
4685
|
-
* @returns
|
|
4776
|
+
*
|
|
4777
|
+
* @param perPage
|
|
4778
|
+
* @param page
|
|
4779
|
+
* @param options
|
|
4780
|
+
* @returns
|
|
4686
4781
|
*/
|
|
4687
4782
|
async paginate(perPage = 15, page, options = {}) {
|
|
4688
4783
|
return (await this.getQuery()).paginate(perPage, page, options);
|
|
4689
4784
|
}
|
|
4690
4785
|
/**
|
|
4691
4786
|
* Paginate the relationship query results without total count optimization.
|
|
4692
|
-
*
|
|
4693
|
-
* @param perPage
|
|
4694
|
-
* @param page
|
|
4695
|
-
* @param options
|
|
4696
|
-
* @returns
|
|
4787
|
+
*
|
|
4788
|
+
* @param perPage
|
|
4789
|
+
* @param page
|
|
4790
|
+
* @param options
|
|
4791
|
+
* @returns
|
|
4697
4792
|
*/
|
|
4698
4793
|
async simplePaginate(perPage = 15, page, options = {}) {
|
|
4699
4794
|
return (await this.getQuery()).simplePaginate(perPage, page, options);
|
|
@@ -4704,7 +4799,7 @@ var Relation = class {
|
|
|
4704
4799
|
//#region src/relationship/BelongsToManyRelation.ts
|
|
4705
4800
|
/**
|
|
4706
4801
|
* Defines a many-to-many relationship.
|
|
4707
|
-
*
|
|
4802
|
+
*
|
|
4708
4803
|
* @author Legacy (3m1n3nc3)
|
|
4709
4804
|
* @since 0.1.0
|
|
4710
4805
|
*/
|
|
@@ -4727,9 +4822,9 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4727
4822
|
}
|
|
4728
4823
|
/**
|
|
4729
4824
|
* Specifies additional pivot columns to include on the related models.
|
|
4730
|
-
*
|
|
4731
|
-
* @param columns The pivot columns to include on the related models.
|
|
4732
|
-
* @returns
|
|
4825
|
+
*
|
|
4826
|
+
* @param columns The pivot columns to include on the related models.
|
|
4827
|
+
* @returns
|
|
4733
4828
|
*/
|
|
4734
4829
|
withPivot(...columns) {
|
|
4735
4830
|
columns.flat().forEach((column) => {
|
|
@@ -4740,9 +4835,9 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4740
4835
|
return this;
|
|
4741
4836
|
}
|
|
4742
4837
|
/**
|
|
4743
|
-
* Specifies that the pivot table contains timestamp columns and optionally
|
|
4838
|
+
* Specifies that the pivot table contains timestamp columns and optionally
|
|
4744
4839
|
* allows customizing the names of those columns.
|
|
4745
|
-
*
|
|
4840
|
+
*
|
|
4746
4841
|
* @param createdAtColumn The name of the "created at" timestamp column.
|
|
4747
4842
|
* @param updatedAtColumn The name of the "updated at" timestamp column.
|
|
4748
4843
|
* @returns The current instance of the relationship.
|
|
@@ -4753,10 +4848,10 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4753
4848
|
return this.withPivot(createdAtColumn, updatedAtColumn);
|
|
4754
4849
|
}
|
|
4755
4850
|
/**
|
|
4756
|
-
* Specifies a custom accessor name for the pivot attributes on the related models.
|
|
4757
|
-
* By default, pivot attributes are accessible via the `pivot` property on the
|
|
4851
|
+
* Specifies a custom accessor name for the pivot attributes on the related models.
|
|
4852
|
+
* By default, pivot attributes are accessible via the `pivot` property on the
|
|
4758
4853
|
* related models.
|
|
4759
|
-
*
|
|
4854
|
+
*
|
|
4760
4855
|
* @param accessor The custom accessor name for the pivot attributes.
|
|
4761
4856
|
* @returns The current instance of the relationship.
|
|
4762
4857
|
*/
|
|
@@ -4768,10 +4863,10 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4768
4863
|
return this;
|
|
4769
4864
|
}
|
|
4770
4865
|
/**
|
|
4771
|
-
* Specifies a custom pivot model to use for the pivot records. The pivot model can
|
|
4772
|
-
* be used to define custom behavior or methods on the pivot records, as well as to
|
|
4866
|
+
* Specifies a custom pivot model to use for the pivot records. The pivot model can
|
|
4867
|
+
* be used to define custom behavior or methods on the pivot records, as well as to
|
|
4773
4868
|
* specify a custom hydration method for the pivot records.
|
|
4774
|
-
*
|
|
4869
|
+
*
|
|
4775
4870
|
* @param pivotModel The custom pivot model to use.
|
|
4776
4871
|
* @returns The current instance of the relationship.
|
|
4777
4872
|
*/
|
|
@@ -4788,20 +4883,20 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4788
4883
|
}
|
|
4789
4884
|
/**
|
|
4790
4885
|
* Adds a "pivot column in" condition to the relationship query.
|
|
4791
|
-
*
|
|
4792
|
-
* @param column
|
|
4793
|
-
* @param values
|
|
4794
|
-
* @returns
|
|
4886
|
+
*
|
|
4887
|
+
* @param column
|
|
4888
|
+
* @param values
|
|
4889
|
+
* @returns
|
|
4795
4890
|
*/
|
|
4796
4891
|
wherePivotNotIn(column, values) {
|
|
4797
4892
|
return this.addPivotWhere(this.makePivotComparison(column, "not-in", values));
|
|
4798
4893
|
}
|
|
4799
4894
|
/**
|
|
4800
4895
|
* Adds a "pivot column between" condition to the relationship query.
|
|
4801
|
-
*
|
|
4802
|
-
* @param column
|
|
4803
|
-
* @param range
|
|
4804
|
-
* @returns
|
|
4896
|
+
*
|
|
4897
|
+
* @param column
|
|
4898
|
+
* @param range
|
|
4899
|
+
* @returns
|
|
4805
4900
|
*/
|
|
4806
4901
|
wherePivotBetween(column, range) {
|
|
4807
4902
|
return this.addPivotWhere({
|
|
@@ -4812,10 +4907,10 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4812
4907
|
}
|
|
4813
4908
|
/**
|
|
4814
4909
|
* Adds a "pivot column not between" condition to the relationship query.
|
|
4815
|
-
*
|
|
4816
|
-
* @param column
|
|
4817
|
-
* @param range
|
|
4818
|
-
* @returns
|
|
4910
|
+
*
|
|
4911
|
+
* @param column
|
|
4912
|
+
* @param range
|
|
4913
|
+
* @returns
|
|
4819
4914
|
*/
|
|
4820
4915
|
wherePivotNotBetween(column, range) {
|
|
4821
4916
|
return this.addPivotWhere({
|
|
@@ -4829,18 +4924,18 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
4829
4924
|
}
|
|
4830
4925
|
/**
|
|
4831
4926
|
* Adds a "pivot column is null" condition to the relationship query.
|
|
4832
|
-
*
|
|
4833
|
-
* @param column
|
|
4834
|
-
* @returns
|
|
4927
|
+
*
|
|
4928
|
+
* @param column
|
|
4929
|
+
* @returns
|
|
4835
4930
|
*/
|
|
4836
4931
|
wherePivotNull(column) {
|
|
4837
4932
|
return this.addPivotWhere(this.makePivotComparison(column, "is-null"));
|
|
4838
4933
|
}
|
|
4839
4934
|
/**
|
|
4840
4935
|
* Adds a "pivot column is not null" condition to the relationship query.
|
|
4841
|
-
*
|
|
4842
|
-
* @param column
|
|
4843
|
-
* @returns
|
|
4936
|
+
*
|
|
4937
|
+
* @param column
|
|
4938
|
+
* @returns
|
|
4844
4939
|
*/
|
|
4845
4940
|
wherePivotNotNull(column) {
|
|
4846
4941
|
return this.addPivotWhere(this.makePivotComparison(column, "is-not-null"));
|
|
@@ -5040,9 +5135,9 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5040
5135
|
return rows.length;
|
|
5041
5136
|
}
|
|
5042
5137
|
/**
|
|
5043
|
-
* Creates a new instance of the related model with the given attributes and attaches
|
|
5138
|
+
* Creates a new instance of the related model with the given attributes and attaches
|
|
5044
5139
|
* pivot attributes if pivot attributes should be included.
|
|
5045
|
-
*
|
|
5140
|
+
*
|
|
5046
5141
|
* @param attributes The attributes to initialize the related model with.
|
|
5047
5142
|
* @returns A new instance of the related model.
|
|
5048
5143
|
*/
|
|
@@ -5050,10 +5145,10 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5050
5145
|
return this.related.hydrate(attributes);
|
|
5051
5146
|
}
|
|
5052
5147
|
/**
|
|
5053
|
-
* Creates a new related model record with the given attributes, creates a pivot record
|
|
5054
|
-
* with the given pivot attributes, and attaches pivot attributes if pivot attributes
|
|
5148
|
+
* Creates a new related model record with the given attributes, creates a pivot record
|
|
5149
|
+
* with the given pivot attributes, and attaches pivot attributes if pivot attributes
|
|
5055
5150
|
* should be included.
|
|
5056
|
-
*
|
|
5151
|
+
*
|
|
5057
5152
|
* @param attributes The attributes to initialize the related model with.
|
|
5058
5153
|
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
5059
5154
|
* @returns A new instance of the related model with pivot attributes attached.
|
|
@@ -5065,10 +5160,10 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5065
5160
|
return this.attachPivotToSingleResult(related, pivotRow);
|
|
5066
5161
|
}
|
|
5067
5162
|
/**
|
|
5068
|
-
* Saves a related model record, creates a pivot record with the given pivot attributes
|
|
5069
|
-
* if the related model was not previously persisted, and attaches pivot attributes if
|
|
5163
|
+
* Saves a related model record, creates a pivot record with the given pivot attributes
|
|
5164
|
+
* if the related model was not previously persisted, and attaches pivot attributes if
|
|
5070
5165
|
* pivot attributes should be included.
|
|
5071
|
-
*
|
|
5166
|
+
*
|
|
5072
5167
|
* @param related The related model instance to save.
|
|
5073
5168
|
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
5074
5169
|
* @returns A new instance of the related model with pivot attributes attached.
|
|
@@ -5088,9 +5183,9 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5088
5183
|
return this.attachPivotToSingleResult(persisted, pivotRow);
|
|
5089
5184
|
}
|
|
5090
5185
|
/**
|
|
5091
|
-
* Attaches one or more related model records to the parent model by creating pivot
|
|
5186
|
+
* Attaches one or more related model records to the parent model by creating pivot
|
|
5092
5187
|
* records with the given pivot attributes if pivot attributes should be included.
|
|
5093
|
-
*
|
|
5188
|
+
*
|
|
5094
5189
|
* @param related The related model instance(s) to attach.
|
|
5095
5190
|
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
5096
5191
|
* @returns The number of related model records attached.
|
|
@@ -5173,7 +5268,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5173
5268
|
}
|
|
5174
5269
|
/**
|
|
5175
5270
|
* Creates a pivot record from a row of data.
|
|
5176
|
-
*
|
|
5271
|
+
*
|
|
5177
5272
|
* @param row The row of data containing pivot attributes.
|
|
5178
5273
|
* @returns The pivot record.
|
|
5179
5274
|
*/
|
|
@@ -5188,10 +5283,10 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5188
5283
|
}
|
|
5189
5284
|
/**
|
|
5190
5285
|
* Attaches pivot attributes to the related models if pivot attributes should be included.
|
|
5191
|
-
*
|
|
5192
|
-
* @param results
|
|
5193
|
-
* @param pivotRows
|
|
5194
|
-
* @returns
|
|
5286
|
+
*
|
|
5287
|
+
* @param results
|
|
5288
|
+
* @param pivotRows
|
|
5289
|
+
* @returns
|
|
5195
5290
|
*/
|
|
5196
5291
|
attachPivotToResults(results, pivotRows) {
|
|
5197
5292
|
if (!this.shouldAttachPivotAttributes()) return results;
|
|
@@ -5283,8 +5378,8 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5283
5378
|
}
|
|
5284
5379
|
/**
|
|
5285
5380
|
* Fetches the related models for this relationship.
|
|
5286
|
-
*
|
|
5287
|
-
* @returns
|
|
5381
|
+
*
|
|
5382
|
+
* @returns
|
|
5288
5383
|
*/
|
|
5289
5384
|
async getResults() {
|
|
5290
5385
|
return (await this.getQuery()).get();
|
|
@@ -5295,7 +5390,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
5295
5390
|
//#region src/relationship/SingleResultRelation.ts
|
|
5296
5391
|
/**
|
|
5297
5392
|
* Base class for relationships that resolve to a single related model.
|
|
5298
|
-
*
|
|
5393
|
+
*
|
|
5299
5394
|
* @author Legacy (3m1n3nc3)
|
|
5300
5395
|
* @since 1.3.0
|
|
5301
5396
|
*/
|
|
@@ -5307,7 +5402,7 @@ var SingleResultRelation = class extends Relation {
|
|
|
5307
5402
|
}
|
|
5308
5403
|
/**
|
|
5309
5404
|
* Defines a default value to return when the relationship does not find a related model.
|
|
5310
|
-
*
|
|
5405
|
+
*
|
|
5311
5406
|
* @param value The default value or a callback that returns the default value.
|
|
5312
5407
|
* @returns The current instance for method chaining.
|
|
5313
5408
|
*/
|
|
@@ -5327,7 +5422,7 @@ var SingleResultRelation = class extends Relation {
|
|
|
5327
5422
|
//#region src/relationship/BelongsToRelation.ts
|
|
5328
5423
|
/**
|
|
5329
5424
|
* Defines an inverse one-to-one or many relationship.
|
|
5330
|
-
*
|
|
5425
|
+
*
|
|
5331
5426
|
* @author Legacy (3m1n3nc3)
|
|
5332
5427
|
* @since 0.1.0
|
|
5333
5428
|
*/
|
|
@@ -5356,8 +5451,8 @@ var BelongsToRelation = class extends SingleResultRelation {
|
|
|
5356
5451
|
}
|
|
5357
5452
|
/**
|
|
5358
5453
|
* Fetches the related models for this relationship.
|
|
5359
|
-
*
|
|
5360
|
-
* @returns
|
|
5454
|
+
*
|
|
5455
|
+
* @returns
|
|
5361
5456
|
*/
|
|
5362
5457
|
async getResults() {
|
|
5363
5458
|
return await (await this.getQuery()).first() ?? this.resolveDefaultResult();
|
|
@@ -5368,7 +5463,7 @@ var BelongsToRelation = class extends SingleResultRelation {
|
|
|
5368
5463
|
//#region src/relationship/HasManyRelation.ts
|
|
5369
5464
|
/**
|
|
5370
5465
|
* Defines a one-to-many relationship.
|
|
5371
|
-
*
|
|
5466
|
+
*
|
|
5372
5467
|
* @author Legacy (3m1n3nc3)
|
|
5373
5468
|
* @since 0.1.0
|
|
5374
5469
|
*/
|
|
@@ -5402,8 +5497,8 @@ var HasManyRelation = class extends Relation {
|
|
|
5402
5497
|
}
|
|
5403
5498
|
/**
|
|
5404
5499
|
* Fetches the related models for this relationship.
|
|
5405
|
-
*
|
|
5406
|
-
* @returns
|
|
5500
|
+
*
|
|
5501
|
+
* @returns
|
|
5407
5502
|
*/
|
|
5408
5503
|
async getResults() {
|
|
5409
5504
|
return (await this.getQuery()).get();
|
|
@@ -5413,9 +5508,9 @@ var HasManyRelation = class extends Relation {
|
|
|
5413
5508
|
//#endregion
|
|
5414
5509
|
//#region src/relationship/HasManyThroughRelation.ts
|
|
5415
5510
|
/**
|
|
5416
|
-
* Defines a has-many-through relationship, which provides a convenient way to access
|
|
5417
|
-
* distant relations via an intermediate relation.
|
|
5418
|
-
*
|
|
5511
|
+
* Defines a has-many-through relationship, which provides a convenient way to access
|
|
5512
|
+
* distant relations via an intermediate relation.
|
|
5513
|
+
*
|
|
5419
5514
|
* @author Legacy (3m1n3nc3)
|
|
5420
5515
|
* @since 0.1.0
|
|
5421
5516
|
*/
|
|
@@ -5464,8 +5559,8 @@ var HasManyThroughRelation = class extends Relation {
|
|
|
5464
5559
|
}
|
|
5465
5560
|
/**
|
|
5466
5561
|
* Fetches the related models for this relationship.
|
|
5467
|
-
*
|
|
5468
|
-
* @returns
|
|
5562
|
+
*
|
|
5563
|
+
* @returns
|
|
5469
5564
|
*/
|
|
5470
5565
|
async getResults() {
|
|
5471
5566
|
return (await this.getQuery()).get();
|
|
@@ -5476,7 +5571,7 @@ var HasManyThroughRelation = class extends Relation {
|
|
|
5476
5571
|
//#region src/relationship/HasOneRelation.ts
|
|
5477
5572
|
/**
|
|
5478
5573
|
* Represents a "has one" relationship between two models.
|
|
5479
|
-
*
|
|
5574
|
+
*
|
|
5480
5575
|
* @author Legacy (3m1n3nc3)
|
|
5481
5576
|
* @since 0.1.0
|
|
5482
5577
|
*/
|
|
@@ -5508,8 +5603,8 @@ var HasOneRelation = class extends SingleResultRelation {
|
|
|
5508
5603
|
}
|
|
5509
5604
|
/**
|
|
5510
5605
|
* Fetches the related models for this relationship.
|
|
5511
|
-
*
|
|
5512
|
-
* @returns
|
|
5606
|
+
*
|
|
5607
|
+
* @returns
|
|
5513
5608
|
*/
|
|
5514
5609
|
async getResults() {
|
|
5515
5610
|
return await (await this.getQuery()).first() ?? this.resolveDefaultResult();
|
|
@@ -5519,9 +5614,9 @@ var HasOneRelation = class extends SingleResultRelation {
|
|
|
5519
5614
|
//#endregion
|
|
5520
5615
|
//#region src/relationship/HasOneThroughRelation.ts
|
|
5521
5616
|
/**
|
|
5522
|
-
* Represents a "has one through" relationship, where the parent model is related
|
|
5617
|
+
* Represents a "has one through" relationship, where the parent model is related
|
|
5523
5618
|
* to exactly one instance of the related model through an intermediate model.
|
|
5524
|
-
*
|
|
5619
|
+
*
|
|
5525
5620
|
* @author Legacy (3m1n3nc3)
|
|
5526
5621
|
* @since 0.1.0
|
|
5527
5622
|
*/
|
|
@@ -5569,8 +5664,8 @@ var HasOneThroughRelation = class extends SingleResultRelation {
|
|
|
5569
5664
|
}
|
|
5570
5665
|
/**
|
|
5571
5666
|
* Fetches the related models for this relationship.
|
|
5572
|
-
*
|
|
5573
|
-
* @returns
|
|
5667
|
+
*
|
|
5668
|
+
* @returns
|
|
5574
5669
|
*/
|
|
5575
5670
|
async getResults() {
|
|
5576
5671
|
return await (await this.getQuery()).first() ?? this.resolveDefaultResult();
|
|
@@ -5580,8 +5675,8 @@ var HasOneThroughRelation = class extends SingleResultRelation {
|
|
|
5580
5675
|
//#endregion
|
|
5581
5676
|
//#region src/relationship/MorphManyRelation.ts
|
|
5582
5677
|
/**
|
|
5583
|
-
* Defines a polymorphic one-to-many relationship.
|
|
5584
|
-
*
|
|
5678
|
+
* Defines a polymorphic one-to-many relationship.
|
|
5679
|
+
*
|
|
5585
5680
|
* @author Legacy (3m1n3nc3)
|
|
5586
5681
|
* @since 0.1.0
|
|
5587
5682
|
*/
|
|
@@ -5626,8 +5721,8 @@ var MorphManyRelation = class extends Relation {
|
|
|
5626
5721
|
}
|
|
5627
5722
|
/**
|
|
5628
5723
|
* Fetches the related models for this relationship.
|
|
5629
|
-
*
|
|
5630
|
-
* @returns
|
|
5724
|
+
*
|
|
5725
|
+
* @returns
|
|
5631
5726
|
*/
|
|
5632
5727
|
async getResults() {
|
|
5633
5728
|
return (await this.getQuery()).get();
|
|
@@ -5638,7 +5733,7 @@ var MorphManyRelation = class extends Relation {
|
|
|
5638
5733
|
//#region src/relationship/MorphOneRelation.ts
|
|
5639
5734
|
/**
|
|
5640
5735
|
* Defines a polymorphic one-to-one relationship.
|
|
5641
|
-
*
|
|
5736
|
+
*
|
|
5642
5737
|
* @author Legacy (3m1n3nc3)
|
|
5643
5738
|
* @since 0.1.0
|
|
5644
5739
|
*/
|
|
@@ -5681,8 +5776,8 @@ var MorphOneRelation = class extends SingleResultRelation {
|
|
|
5681
5776
|
}
|
|
5682
5777
|
/**
|
|
5683
5778
|
* Fetches the related models for this relationship.
|
|
5684
|
-
*
|
|
5685
|
-
* @returns
|
|
5779
|
+
*
|
|
5780
|
+
* @returns
|
|
5686
5781
|
*/
|
|
5687
5782
|
async getResults() {
|
|
5688
5783
|
return await (await this.getQuery()).first() ?? this.resolveDefaultResult();
|
|
@@ -5692,8 +5787,8 @@ var MorphOneRelation = class extends SingleResultRelation {
|
|
|
5692
5787
|
//#endregion
|
|
5693
5788
|
//#region src/relationship/MorphToManyRelation.ts
|
|
5694
5789
|
/**
|
|
5695
|
-
* Defines a polymorphic many-to-many relationship.
|
|
5696
|
-
*
|
|
5790
|
+
* Defines a polymorphic many-to-many relationship.
|
|
5791
|
+
*
|
|
5697
5792
|
* @author Legacy (3m1n3nc3)
|
|
5698
5793
|
* @since 0.1.0
|
|
5699
5794
|
*/
|
|
@@ -5756,8 +5851,8 @@ var MorphToManyRelation = class extends Relation {
|
|
|
5756
5851
|
}
|
|
5757
5852
|
/**
|
|
5758
5853
|
* Fetches the related models for this relationship.
|
|
5759
|
-
*
|
|
5760
|
-
* @returns
|
|
5854
|
+
*
|
|
5855
|
+
* @returns
|
|
5761
5856
|
*/
|
|
5762
5857
|
async getResults() {
|
|
5763
5858
|
return (await this.getQuery()).get();
|