arkormx 2.9.1 → 2.9.3
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 +461 -337
- package/dist/{index-18M5gEFk.d.cts → index-BFNEyqme.d.cts} +77 -13
- package/dist/{index-CFXreeV7.d.mts → index-EVK8EOKN.d.mts} +77 -13
- package/dist/index.cjs +550 -516
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +550 -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-BD04hN72.mjs} +614 -549
- package/dist/{relationship-BVYP9lU2.cjs → relationship-DhdzLnKH.cjs} +614 -549
- package/package.json +6 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as applyOperationsToPersistedColumnMappingsState, $t as resolvePrismaType, A as getRuntimePrismaClient, An as writeAppliedMigrationsStateToStore, At as buildInverseRelationLine, B as getRegisteredModels, Bt as deriveRelationFieldName, C as getActiveTransactionClient, Cn as markMigrationRun, Ct as applyMigrationRollbackToPrismaSchema, D as getRuntimeDebugHandler, Dn as resolveMigrationStateFilePath, Dt as buildEnumBlock, E as getRuntimeClient, En as removeAppliedMigration, Et as applyOperationsToPrismaSchema, F as loadArkormConfig, Fn as RelationResolutionException, Ft as buildUniqueConstraintLine, G as loadModelsFrom, Gt as formatDefaultValue, H as getRegisteredSeeders, Ht as escapeRegex, I as resetArkormRuntimeForTests, In as ArkormCollection, It as createMigrationTimestamp, J as registerMigrations, Jt as generateMigrationFile, K as loadSeedersFrom, Kt as formatEnumDefaultValue, L as runArkormTransaction, Ln as ArkormException, Lt as deriveCollectionFieldName, M as isDelegateLike, Mn as UnsupportedAdapterFeatureException, Mt as buildModelBlock, N as isQuerySchemaLike, Nn as SetBasedEagerLoader, Nt as buildPrimaryKeyLine, O as getRuntimePaginationCurrentPageResolver, On as supportsDatabaseMigrationState, Ot as buildFieldLine, P as isTransactionCapableClient, Pt as buildRelationLine, Q as resetRuntimeRegistryForTests, Qt as resolveMigrationClassName, R as getRegisteredFactories, Rt as deriveInverseRelationAlias, S as getActiveTransactionAdapter, Sn as markMigrationApplied, St as applyMigrationRollbackToDatabase, T as getRuntimeAdapter, Tn as readAppliedMigrationsStateFromStore, Tt as applyMigrationToPrismaSchema, U as loadFactoriesFrom, Ut as findEnumBlock, V as getRegisteredPaths, Vt as deriveSingularFieldName, W as loadMigrationsFrom, Wt as findModelBlock, X as registerPaths, Xt as pad, Y as registerModels, Yt as getMigrationPlan, Z as registerSeeders, Zt as resolveEnumName, _ as bindAdapterToModels, _n as deleteAppliedMigrationsStateFromStore, _t as PRISMA_ENUM_REGEX, a as HasOneThroughRelation, an as supportsDatabaseReset, at as getPersistedPrimaryKeyGeneration, b as emitRuntimeDebugEvent, bn as getLatestAppliedMigrations, bt as applyCreateTableOperation, c as HasManyRelation, cn as SchemaBuilder, ct as readPersistedColumnMappingsState, d as BelongsToManyRelation, dn as PrimaryKeyGenerationPlanner, dt as resolveColumnMappingsFilePath, en as runMigrationWithPrisma, et as createEmptyPersistedColumnMappingsState, f as Relation, fn as ForeignKeyBuilder, ft as resolvePersistedMetadataFeatures, g as awaitConfiguredModelsRegistration, gn as createEmptyAppliedMigrationsState, gt as PRISMA_ENUM_MEMBER_REGEX, h as URLDriver, hn as computeMigrationChecksum, ht as writePersistedColumnMappingsState, i as MorphManyRelation, in as supportsDatabaseMigrationExecution, it as getPersistedEnumTsType, j as getUserConfig, jn as RuntimeModuleLoader, jt as buildMigrationSource, k as getRuntimePaginationURLDriverFactory, kn as writeAppliedMigrationsState, kt as buildIndexLine, l as BelongsToRelation, ln as EnumBuilder, lt as rebuildPersistedColumnMappingsState, m as Paginator, mn as buildMigrationRunId, mt as validatePersistedMetadataFeaturesForMigrations, n as MorphToManyRelation, nn as stripPrismaSchemaModelsAndEnums, nt as getPersistedColumnMap, o as HasOneRelation, on as toMigrationFileSlug, ot as getPersistedTableMetadata, p as LengthAwarePaginator, pn as buildMigrationIdentity, pt as syncPersistedColumnMappingsFromState, q as registerFactories, qt as formatRelationAction, r as MorphOneRelation, rn as supportsDatabaseCreation, rt as getPersistedEnumMap, s as HasManyThroughRelation, sn as toModelName, st as getPersistedTimestampColumns, t as MorphToRelation, tn as runPrismaCommand, tt as deletePersistedColumnMappingsState, un as TableBuilder, ut as resetPersistedColumnMappingsCache, v as configureArkormRuntime, vn as findAppliedMigration, vt as PRISMA_MODEL_REGEX, w as getDefaultStubsPath, wn as readAppliedMigrationsState, wt as applyMigrationToDatabase, x as ensureArkormConfigLoading, xn as isMigrationApplied, xt as applyDropTableOperation, y as defineConfig, yn as getLastMigrationRun, yt as applyAlterTableOperation, z as getRegisteredMigrations, zt as deriveRelationAlias } from "./relationship-
|
|
1
|
+
import { $ as applyOperationsToPersistedColumnMappingsState, $t as resolvePrismaType, A as getRuntimePrismaClient, An as writeAppliedMigrationsStateToStore, At as buildInverseRelationLine, B as getRegisteredModels, Bt as deriveRelationFieldName, C as getActiveTransactionClient, Cn as markMigrationRun, Ct as applyMigrationRollbackToPrismaSchema, D as getRuntimeDebugHandler, Dn as resolveMigrationStateFilePath, Dt as buildEnumBlock, E as getRuntimeClient, En as removeAppliedMigration, Et as applyOperationsToPrismaSchema, F as loadArkormConfig, Fn as RelationResolutionException, Ft as buildUniqueConstraintLine, G as loadModelsFrom, Gt as formatDefaultValue, H as getRegisteredSeeders, Ht as escapeRegex, I as resetArkormRuntimeForTests, In as ArkormCollection, It as createMigrationTimestamp, J as registerMigrations, Jt as generateMigrationFile, K as loadSeedersFrom, Kt as formatEnumDefaultValue, L as runArkormTransaction, Ln as ArkormException, Lt as deriveCollectionFieldName, M as isDelegateLike, Mn as UnsupportedAdapterFeatureException, Mt as buildModelBlock, N as isQuerySchemaLike, Nn as SetBasedEagerLoader, Nt as buildPrimaryKeyLine, O as getRuntimePaginationCurrentPageResolver, On as supportsDatabaseMigrationState, Ot as buildFieldLine, P as isTransactionCapableClient, Pt as buildRelationLine, Q as resetRuntimeRegistryForTests, Qt as resolveMigrationClassName, R as getRegisteredFactories, Rt as deriveInverseRelationAlias, S as getActiveTransactionAdapter, Sn as markMigrationApplied, St as applyMigrationRollbackToDatabase, T as getRuntimeAdapter, Tn as readAppliedMigrationsStateFromStore, Tt as applyMigrationToPrismaSchema, U as loadFactoriesFrom, Ut as findEnumBlock, V as getRegisteredPaths, Vt as deriveSingularFieldName, W as loadMigrationsFrom, Wt as findModelBlock, X as registerPaths, Xt as pad, Y as registerModels, Yt as getMigrationPlan, Z as registerSeeders, Zt as resolveEnumName, _ as bindAdapterToModels, _n as deleteAppliedMigrationsStateFromStore, _t as PRISMA_ENUM_REGEX, a as HasOneThroughRelation, an as supportsDatabaseReset, at as getPersistedPrimaryKeyGeneration, b as emitRuntimeDebugEvent, bn as getLatestAppliedMigrations, bt as applyCreateTableOperation, c as HasManyRelation, cn as SchemaBuilder, ct as readPersistedColumnMappingsState, d as BelongsToManyRelation, dn as PrimaryKeyGenerationPlanner, dt as resolveColumnMappingsFilePath, en as runMigrationWithPrisma, et as createEmptyPersistedColumnMappingsState, f as Relation, fn as ForeignKeyBuilder, ft as resolvePersistedMetadataFeatures, g as awaitConfiguredModelsRegistration, gn as createEmptyAppliedMigrationsState, gt as PRISMA_ENUM_MEMBER_REGEX, h as URLDriver, hn as computeMigrationChecksum, ht as writePersistedColumnMappingsState, i as MorphManyRelation, in as supportsDatabaseMigrationExecution, it as getPersistedEnumTsType, j as getUserConfig, jn as RuntimeModuleLoader, jt as buildMigrationSource, k as getRuntimePaginationURLDriverFactory, kn as writeAppliedMigrationsState, kt as buildIndexLine, l as BelongsToRelation, ln as EnumBuilder, lt as rebuildPersistedColumnMappingsState, m as Paginator, mn as buildMigrationRunId, mt as validatePersistedMetadataFeaturesForMigrations, n as MorphToManyRelation, nn as stripPrismaSchemaModelsAndEnums, nt as getPersistedColumnMap, o as HasOneRelation, on as toMigrationFileSlug, ot as getPersistedTableMetadata, p as LengthAwarePaginator, pn as buildMigrationIdentity, pt as syncPersistedColumnMappingsFromState, q as registerFactories, qt as formatRelationAction, r as MorphOneRelation, rn as supportsDatabaseCreation, rt as getPersistedEnumMap, s as HasManyThroughRelation, sn as toModelName, st as getPersistedTimestampColumns, t as MorphToRelation, tn as runPrismaCommand, tt as deletePersistedColumnMappingsState, un as TableBuilder, ut as resetPersistedColumnMappingsCache, v as configureArkormRuntime, vn as findAppliedMigration, vt as PRISMA_MODEL_REGEX, w as getDefaultStubsPath, wn as readAppliedMigrationsState, wt as applyMigrationToDatabase, x as ensureArkormConfigLoading, xn as isMigrationApplied, xt as applyDropTableOperation, y as defineConfig, yn as getLastMigrationRun, yt as applyAlterTableOperation, z as getRegisteredMigrations, zt as deriveRelationAlias } from "./relationship-BD04hN72.mjs";
|
|
2
2
|
import { Pool } from "pg";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import { createRequire } from "module";
|
|
@@ -33,9 +33,9 @@ var QueryExecutionException = class extends ArkormException {
|
|
|
33
33
|
//#endregion
|
|
34
34
|
//#region src/adapters/KyselyDatabaseAdapter.ts
|
|
35
35
|
/**
|
|
36
|
-
* Database adapter implementation for Kysely, allowing Arkorm to execute queries using Kysely
|
|
36
|
+
* Database adapter implementation for Kysely, allowing Arkorm to execute queries using Kysely
|
|
37
37
|
* as the underlying query builder and executor.
|
|
38
|
-
*
|
|
38
|
+
*
|
|
39
39
|
* @author Legacy (3m1n3nc3)
|
|
40
40
|
* @since 2.0.0-next.0
|
|
41
41
|
*/
|
|
@@ -1083,9 +1083,9 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1083
1083
|
}
|
|
1084
1084
|
}
|
|
1085
1085
|
/**
|
|
1086
|
-
* Selects records from the database matching the specified criteria and returns
|
|
1086
|
+
* Selects records from the database matching the specified criteria and returns
|
|
1087
1087
|
* them as an array of database rows.
|
|
1088
|
-
*
|
|
1088
|
+
*
|
|
1089
1089
|
* @param spec The specification defining the selection criteria.
|
|
1090
1090
|
* @returns A promise that resolves to an array of database rows.
|
|
1091
1091
|
*/
|
|
@@ -1103,10 +1103,10 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1103
1103
|
});
|
|
1104
1104
|
}
|
|
1105
1105
|
/**
|
|
1106
|
-
* Selects a single record from the database matching the specified criteria and returns it as
|
|
1107
|
-
* a database row. If multiple records match the criteria, only the first one is returned.
|
|
1106
|
+
* Selects a single record from the database matching the specified criteria and returns it as
|
|
1107
|
+
* a database row. If multiple records match the criteria, only the first one is returned.
|
|
1108
1108
|
* If no records match, null is returned.
|
|
1109
|
-
*
|
|
1109
|
+
*
|
|
1110
1110
|
* @param spec The specification defining the selection criteria.
|
|
1111
1111
|
* @returns A promise that resolves to a database row or null if no records match.
|
|
1112
1112
|
*/
|
|
@@ -1117,11 +1117,11 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1117
1117
|
}))[0] ?? null;
|
|
1118
1118
|
}
|
|
1119
1119
|
/**
|
|
1120
|
-
* Inserts a new record into the database with the specified values and returns the
|
|
1120
|
+
* Inserts a new record into the database with the specified values and returns the
|
|
1121
1121
|
* inserted record as a database row.
|
|
1122
|
-
*
|
|
1123
|
-
* @param spec
|
|
1124
|
-
* @returns
|
|
1122
|
+
*
|
|
1123
|
+
* @param spec
|
|
1124
|
+
* @returns
|
|
1125
1125
|
*/
|
|
1126
1126
|
async insert(spec) {
|
|
1127
1127
|
const values = this.mapValues(spec.target, spec.values);
|
|
@@ -1140,9 +1140,9 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1140
1140
|
}, { values: spec.values });
|
|
1141
1141
|
}
|
|
1142
1142
|
/**
|
|
1143
|
-
* Inserts multiple records into the database with the specified values and returns the number
|
|
1144
|
-
* of records successfully inserted.
|
|
1145
|
-
*
|
|
1143
|
+
* Inserts multiple records into the database with the specified values and returns the number
|
|
1144
|
+
* of records successfully inserted.
|
|
1145
|
+
*
|
|
1146
1146
|
* @param spec The specification defining the values to be inserted.
|
|
1147
1147
|
* @returns A promise that resolves to the number of records successfully inserted.
|
|
1148
1148
|
*/
|
|
@@ -1213,11 +1213,11 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1213
1213
|
return spec.values.length;
|
|
1214
1214
|
}
|
|
1215
1215
|
/**
|
|
1216
|
-
* Updates records in the database matching the specified criteria with the given values
|
|
1217
|
-
* and returns the updated record as a database row.
|
|
1218
|
-
*
|
|
1216
|
+
* Updates records in the database matching the specified criteria with the given values
|
|
1217
|
+
* and returns the updated record as a database row.
|
|
1218
|
+
*
|
|
1219
1219
|
* @param spec The specification defining the update criteria and values.
|
|
1220
|
-
* @returns A promise that resolves to the updated record as a database row, or null if no records match the criteria.
|
|
1220
|
+
* @returns A promise that resolves to the updated record as a database row, or null if no records match the criteria.
|
|
1221
1221
|
*/
|
|
1222
1222
|
async update(spec) {
|
|
1223
1223
|
const values = this.mapValues(spec.target, spec.values);
|
|
@@ -1244,9 +1244,9 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1244
1244
|
}
|
|
1245
1245
|
/**
|
|
1246
1246
|
* Updates a single record in the database matching the specified criteria with the given values.
|
|
1247
|
-
*
|
|
1248
|
-
* @param spec
|
|
1249
|
-
* @returns
|
|
1247
|
+
*
|
|
1248
|
+
* @param spec
|
|
1249
|
+
* @returns
|
|
1250
1250
|
*/
|
|
1251
1251
|
async updateFirst(spec) {
|
|
1252
1252
|
const values = this.mapValues(spec.target, spec.values);
|
|
@@ -1276,9 +1276,9 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1276
1276
|
});
|
|
1277
1277
|
}
|
|
1278
1278
|
/**
|
|
1279
|
-
* Updates multiple records in the database matching the specified criteria with the
|
|
1279
|
+
* Updates multiple records in the database matching the specified criteria with the
|
|
1280
1280
|
* given values and returns the number of records successfully updated.
|
|
1281
|
-
*
|
|
1281
|
+
*
|
|
1282
1282
|
* @param spec The specification defining the update criteria and values.
|
|
1283
1283
|
* @returns A promise that resolves to the number of records successfully updated.
|
|
1284
1284
|
*/
|
|
@@ -1300,9 +1300,9 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1300
1300
|
});
|
|
1301
1301
|
}
|
|
1302
1302
|
/**
|
|
1303
|
-
* Deletes records from the database matching the specified criteria and returns the
|
|
1303
|
+
* Deletes records from the database matching the specified criteria and returns the
|
|
1304
1304
|
* deleted record as a database row.
|
|
1305
|
-
*
|
|
1305
|
+
*
|
|
1306
1306
|
* @param spec The specification defining the delete criteria.
|
|
1307
1307
|
* @returns A promise that resolves to the deleted record as a database row, or null if no records match the criteria.
|
|
1308
1308
|
*/
|
|
@@ -1318,9 +1318,9 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1318
1318
|
}
|
|
1319
1319
|
/**
|
|
1320
1320
|
* Deletes a single record from the database matching the specified criteria and returns it as a database row.
|
|
1321
|
-
*
|
|
1322
|
-
* @param spec
|
|
1323
|
-
* @returns
|
|
1321
|
+
*
|
|
1322
|
+
* @param spec
|
|
1323
|
+
* @returns
|
|
1324
1324
|
*/
|
|
1325
1325
|
async deleteFirst(spec) {
|
|
1326
1326
|
const primaryKey = this.resolvePrimaryKey(spec.target);
|
|
@@ -1337,9 +1337,9 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1337
1337
|
}, { where: spec.where });
|
|
1338
1338
|
}
|
|
1339
1339
|
/**
|
|
1340
|
-
* Deletes multiple records from the database matching the specified criteria and
|
|
1340
|
+
* Deletes multiple records from the database matching the specified criteria and
|
|
1341
1341
|
* returns the number of records successfully deleted.
|
|
1342
|
-
*
|
|
1342
|
+
*
|
|
1343
1343
|
* @param spec The specification defining the delete criteria.
|
|
1344
1344
|
* @returns A promise that resolves to the number of records successfully deleted.
|
|
1345
1345
|
*/
|
|
@@ -1352,9 +1352,9 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1352
1352
|
return await this.executeWithDebug("deleteMany", spec.target, statement, (rows) => rows.length, { where: spec.where });
|
|
1353
1353
|
}
|
|
1354
1354
|
/**
|
|
1355
|
-
* Counts the number of records in the database matching the specified criteria and returns
|
|
1355
|
+
* Counts the number of records in the database matching the specified criteria and returns
|
|
1356
1356
|
* the count as a number.
|
|
1357
|
-
*
|
|
1357
|
+
*
|
|
1358
1358
|
* @param spec The specification defining the count criteria.
|
|
1359
1359
|
* @returns A promise that resolves to the number of records matching the criteria.
|
|
1360
1360
|
*/
|
|
@@ -1368,7 +1368,7 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1368
1368
|
}
|
|
1369
1369
|
/**
|
|
1370
1370
|
* Checks for the existence of records matching the specified criteria.
|
|
1371
|
-
*
|
|
1371
|
+
*
|
|
1372
1372
|
* @param spec The specification defining the existence criteria.
|
|
1373
1373
|
* @returns A promise that resolves to a boolean indicating whether any records match the criteria.
|
|
1374
1374
|
*/
|
|
@@ -1382,9 +1382,9 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1382
1382
|
}
|
|
1383
1383
|
/**
|
|
1384
1384
|
* Loads relations for the given models based on the specified relation load plans.
|
|
1385
|
-
*
|
|
1385
|
+
*
|
|
1386
1386
|
* @param spec The specification defining the models and their relations to be loaded.
|
|
1387
|
-
* @returns
|
|
1387
|
+
* @returns
|
|
1388
1388
|
*/
|
|
1389
1389
|
async loadRelations(spec) {
|
|
1390
1390
|
if (spec.models.length === 0 || spec.relations.length === 0) return;
|
|
@@ -1520,10 +1520,10 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1520
1520
|
});
|
|
1521
1521
|
}
|
|
1522
1522
|
/**
|
|
1523
|
-
* Executes a series of database operations within a transaction.
|
|
1524
|
-
* The provided callback function is called with a new instance of the
|
|
1523
|
+
* Executes a series of database operations within a transaction.
|
|
1524
|
+
* The provided callback function is called with a new instance of the
|
|
1525
1525
|
* KyselyDatabaseAdapter that is bound to the transaction context.
|
|
1526
|
-
*
|
|
1526
|
+
*
|
|
1527
1527
|
* @param callback The callback function containing the database operations to be executed within the transaction.
|
|
1528
1528
|
* @param context The transaction context specifying options such as read-only mode and isolation level.
|
|
1529
1529
|
* @returns A promise that resolves to the result of the callback function.
|
|
@@ -1538,12 +1538,12 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
1538
1538
|
}
|
|
1539
1539
|
};
|
|
1540
1540
|
/**
|
|
1541
|
-
* Factory function to create a KyselyDatabaseAdapter instance with the given Kysely executor
|
|
1541
|
+
* Factory function to create a KyselyDatabaseAdapter instance with the given Kysely executor
|
|
1542
1542
|
* and optional table name mapping.
|
|
1543
|
-
*
|
|
1543
|
+
*
|
|
1544
1544
|
* @param db The Kysely executor to be used by the adapter.
|
|
1545
1545
|
* @param mapping Optional table name mapping for the adapter.
|
|
1546
|
-
* @returns A new instance of KyselyDatabaseAdapter.
|
|
1546
|
+
* @returns A new instance of KyselyDatabaseAdapter.
|
|
1547
1547
|
*/
|
|
1548
1548
|
const createKyselyAdapter = (db, mapping = {}) => {
|
|
1549
1549
|
return new KyselyDatabaseAdapter(db, mapping);
|
|
@@ -1602,7 +1602,7 @@ function createPrismaDelegateMap(prisma, mapping = {}) {
|
|
|
1602
1602
|
}
|
|
1603
1603
|
/**
|
|
1604
1604
|
* Infer the Prisma delegate name for a given model name using a simple convention.
|
|
1605
|
-
*
|
|
1605
|
+
*
|
|
1606
1606
|
* @param modelName The name of the model to infer the delegate name for.
|
|
1607
1607
|
* @returns The inferred Prisma delegate name.
|
|
1608
1608
|
*/
|
|
@@ -1613,9 +1613,9 @@ function inferDelegateName(modelName) {
|
|
|
1613
1613
|
//#endregion
|
|
1614
1614
|
//#region src/adapters/PrismaDatabaseAdapter.ts
|
|
1615
1615
|
/**
|
|
1616
|
-
* Database adapter implementation for Prisma, allowing Arkorm to execute queries using Prisma
|
|
1616
|
+
* Database adapter implementation for Prisma, allowing Arkorm to execute queries using Prisma
|
|
1617
1617
|
* as the underlying query builder and executor.
|
|
1618
|
-
*
|
|
1618
|
+
*
|
|
1619
1619
|
* @author Legacy (3m1n3nc3)
|
|
1620
1620
|
* @since 2.0.0-next.0
|
|
1621
1621
|
*/
|
|
@@ -1884,9 +1884,9 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
1884
1884
|
* Prisma include/select arguments, but the adapter does not advertise the
|
|
1885
1885
|
* adapter-owned batch relation load seam. QueryBuilder eager loads therefore stay
|
|
1886
1886
|
* on Arkorm's generic relation loader on the Prisma compatibility path.
|
|
1887
|
-
*
|
|
1888
|
-
* @param spec
|
|
1889
|
-
* @returns
|
|
1887
|
+
*
|
|
1888
|
+
* @param spec
|
|
1889
|
+
* @returns
|
|
1890
1890
|
*/
|
|
1891
1891
|
async select(spec) {
|
|
1892
1892
|
const delegate = this.resolveDelegate(spec.target);
|
|
@@ -1896,10 +1896,10 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
1896
1896
|
}, { args });
|
|
1897
1897
|
}
|
|
1898
1898
|
/**
|
|
1899
|
-
* Selects a single record matching the specified criteria.
|
|
1900
|
-
*
|
|
1901
|
-
* @param spec
|
|
1902
|
-
* @returns
|
|
1899
|
+
* Selects a single record matching the specified criteria.
|
|
1900
|
+
*
|
|
1901
|
+
* @param spec
|
|
1902
|
+
* @returns
|
|
1903
1903
|
*/
|
|
1904
1904
|
async selectOne(spec) {
|
|
1905
1905
|
const delegate = this.resolveDelegate(spec.target);
|
|
@@ -1910,9 +1910,9 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
1910
1910
|
}
|
|
1911
1911
|
/**
|
|
1912
1912
|
* Inserts a single record into the database and returns the created record.
|
|
1913
|
-
*
|
|
1914
|
-
* @param spec
|
|
1915
|
-
* @returns
|
|
1913
|
+
*
|
|
1914
|
+
* @param spec
|
|
1915
|
+
* @returns
|
|
1916
1916
|
*/
|
|
1917
1917
|
async insert(spec) {
|
|
1918
1918
|
const delegate = this.resolveDelegate(spec.target);
|
|
@@ -1921,10 +1921,10 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
1921
1921
|
}, { values: spec.values });
|
|
1922
1922
|
}
|
|
1923
1923
|
/**
|
|
1924
|
-
* Inserts multiple records into the database.
|
|
1925
|
-
*
|
|
1926
|
-
* @param spec
|
|
1927
|
-
* @returns
|
|
1924
|
+
* Inserts multiple records into the database.
|
|
1925
|
+
*
|
|
1926
|
+
* @param spec
|
|
1927
|
+
* @returns
|
|
1928
1928
|
*/
|
|
1929
1929
|
async insertMany(spec) {
|
|
1930
1930
|
const delegate = this.resolveDelegate(spec.target);
|
|
@@ -1953,9 +1953,9 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
1953
1953
|
}
|
|
1954
1954
|
/**
|
|
1955
1955
|
* Updates a single record matching the specified criteria and returns the updated record.
|
|
1956
|
-
*
|
|
1957
|
-
* @param spec
|
|
1958
|
-
* @returns
|
|
1956
|
+
*
|
|
1957
|
+
* @param spec
|
|
1958
|
+
* @returns
|
|
1959
1959
|
*/
|
|
1960
1960
|
async update(spec) {
|
|
1961
1961
|
const delegate = this.resolveDelegate(spec.target);
|
|
@@ -1972,10 +1972,10 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
1972
1972
|
});
|
|
1973
1973
|
}
|
|
1974
1974
|
/**
|
|
1975
|
-
* Updates multiple records matching the specified criteria.
|
|
1976
|
-
*
|
|
1977
|
-
* @param spec
|
|
1978
|
-
* @returns
|
|
1975
|
+
* Updates multiple records matching the specified criteria.
|
|
1976
|
+
*
|
|
1977
|
+
* @param spec
|
|
1978
|
+
* @returns
|
|
1979
1979
|
*/
|
|
1980
1980
|
async updateMany(spec) {
|
|
1981
1981
|
const delegate = this.resolveDelegate(spec.target);
|
|
@@ -2005,9 +2005,9 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
2005
2005
|
}
|
|
2006
2006
|
/**
|
|
2007
2007
|
* Deletes a single record matching the specified criteria and returns the deleted record.
|
|
2008
|
-
*
|
|
2009
|
-
* @param spec
|
|
2010
|
-
* @returns
|
|
2008
|
+
*
|
|
2009
|
+
* @param spec
|
|
2010
|
+
* @returns
|
|
2011
2011
|
*/
|
|
2012
2012
|
async delete(spec) {
|
|
2013
2013
|
const delegate = this.resolveDelegate(spec.target);
|
|
@@ -2018,10 +2018,10 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
2018
2018
|
}, { where });
|
|
2019
2019
|
}
|
|
2020
2020
|
/**
|
|
2021
|
-
* Deletes multiple records matching the specified criteria.
|
|
2022
|
-
*
|
|
2023
|
-
* @param spec
|
|
2024
|
-
* @returns
|
|
2021
|
+
* Deletes multiple records matching the specified criteria.
|
|
2022
|
+
*
|
|
2023
|
+
* @param spec
|
|
2024
|
+
* @returns
|
|
2025
2025
|
*/
|
|
2026
2026
|
async deleteMany(spec) {
|
|
2027
2027
|
const delegate = this.resolveDelegate(spec.target);
|
|
@@ -2036,9 +2036,9 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
2036
2036
|
}
|
|
2037
2037
|
/**
|
|
2038
2038
|
* Counts the number of records matching the specified criteria.
|
|
2039
|
-
*
|
|
2040
|
-
* @param spec
|
|
2041
|
-
* @returns
|
|
2039
|
+
*
|
|
2040
|
+
* @param spec
|
|
2041
|
+
* @returns
|
|
2042
2042
|
*/
|
|
2043
2043
|
async count(spec) {
|
|
2044
2044
|
const delegate = this.resolveDelegate(spec.target);
|
|
@@ -2049,9 +2049,9 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
2049
2049
|
}
|
|
2050
2050
|
/**
|
|
2051
2051
|
* Checks for the existence of records matching the specified criteria.
|
|
2052
|
-
*
|
|
2053
|
-
* @param spec
|
|
2054
|
-
* @returns
|
|
2052
|
+
*
|
|
2053
|
+
* @param spec
|
|
2054
|
+
* @returns
|
|
2055
2055
|
*/
|
|
2056
2056
|
async exists(spec) {
|
|
2057
2057
|
return await this.selectOne({
|
|
@@ -2061,8 +2061,8 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
2061
2061
|
}
|
|
2062
2062
|
/**
|
|
2063
2063
|
* Loads related models for a batch of parent records based on the specified relation load plans.
|
|
2064
|
-
*
|
|
2065
|
-
* @param _spec
|
|
2064
|
+
*
|
|
2065
|
+
* @param _spec
|
|
2066
2066
|
*/
|
|
2067
2067
|
async loadRelations(_spec) {
|
|
2068
2068
|
throw new UnsupportedAdapterFeatureException("Adapter-owned relation batch loading is intentionally unavailable on the Prisma compatibility adapter; eager loading stays on Arkorm's generic loader for this path.", {
|
|
@@ -2071,12 +2071,12 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
2071
2071
|
});
|
|
2072
2072
|
}
|
|
2073
2073
|
/**
|
|
2074
|
-
* Executes a series of database operations within a transaction.
|
|
2074
|
+
* Executes a series of database operations within a transaction.
|
|
2075
2075
|
* If the underlying Prisma client does not support transactions, an exception is thrown.
|
|
2076
|
-
*
|
|
2077
|
-
* @param callback
|
|
2078
|
-
* @param context
|
|
2079
|
-
* @returns
|
|
2076
|
+
*
|
|
2077
|
+
* @param callback
|
|
2078
|
+
* @param context
|
|
2079
|
+
* @returns
|
|
2080
2080
|
*/
|
|
2081
2081
|
async transaction(callback, context = {}) {
|
|
2082
2082
|
if (!this.hasTransactionSupport(this.prisma)) throw new UnsupportedAdapterFeatureException("Transactions are not supported by the Prisma compatibility adapter.", {
|
|
@@ -2093,9 +2093,9 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
2093
2093
|
}
|
|
2094
2094
|
};
|
|
2095
2095
|
/**
|
|
2096
|
-
* Factory function to create a PrismaDatabaseAdapter instance with the given
|
|
2096
|
+
* Factory function to create a PrismaDatabaseAdapter instance with the given
|
|
2097
2097
|
* Prisma client and optional delegate name mapping.
|
|
2098
|
-
*
|
|
2098
|
+
*
|
|
2099
2099
|
* @param prisma The Prisma client instance to be used by the adapter.
|
|
2100
2100
|
* @param mapping Optional mapping of delegate names.
|
|
2101
2101
|
* @returns A new instance of PrismaDatabaseAdapter.
|
|
@@ -2104,9 +2104,9 @@ const createPrismaDatabaseAdapter = (prisma, mapping = {}) => {
|
|
|
2104
2104
|
return new PrismaDatabaseAdapter(prisma, mapping);
|
|
2105
2105
|
};
|
|
2106
2106
|
/**
|
|
2107
|
-
* Alias for createPrismaDatabaseAdapter to maintain backward compatibility with
|
|
2107
|
+
* Alias for createPrismaDatabaseAdapter to maintain backward compatibility with
|
|
2108
2108
|
* previous versions of Arkorm that exported the adapter factory under a different name.
|
|
2109
|
-
*
|
|
2109
|
+
*
|
|
2110
2110
|
* @param prisma The Prisma client instance to be used by the adapter.
|
|
2111
2111
|
* @param mapping Optional mapping of delegate names.
|
|
2112
2112
|
* @returns A new instance of PrismaDatabaseAdapter.
|
|
@@ -2136,10 +2136,10 @@ var Arkorm = class Arkorm {
|
|
|
2136
2136
|
}
|
|
2137
2137
|
/**
|
|
2138
2138
|
* Configure the ArkORM runtime with the provided runtime client resolver and adapter-first options.
|
|
2139
|
-
*
|
|
2140
|
-
* @param client
|
|
2141
|
-
* @param options
|
|
2142
|
-
* @returns
|
|
2139
|
+
*
|
|
2140
|
+
* @param client
|
|
2141
|
+
* @param options
|
|
2142
|
+
* @returns
|
|
2143
2143
|
*/
|
|
2144
2144
|
static configure(options, client) {
|
|
2145
2145
|
return configureArkormRuntime(client, options);
|
|
@@ -2156,113 +2156,113 @@ var Arkorm = class Arkorm {
|
|
|
2156
2156
|
}
|
|
2157
2157
|
/**
|
|
2158
2158
|
* Register migration constructors directly without relying on runtime discovery.
|
|
2159
|
-
*
|
|
2160
|
-
* @param migrations
|
|
2161
|
-
* @returns
|
|
2159
|
+
*
|
|
2160
|
+
* @param migrations
|
|
2161
|
+
* @returns
|
|
2162
2162
|
*/
|
|
2163
2163
|
static registerMigrations(...migrations) {
|
|
2164
2164
|
return registerMigrations(...migrations);
|
|
2165
2165
|
}
|
|
2166
2166
|
/**
|
|
2167
2167
|
* Register seeder constructors directly without relying on runtime discovery.
|
|
2168
|
-
*
|
|
2169
|
-
* @param seeders
|
|
2170
|
-
* @returns
|
|
2168
|
+
*
|
|
2169
|
+
* @param seeders
|
|
2170
|
+
* @returns
|
|
2171
2171
|
*/
|
|
2172
2172
|
static registerSeeders(...seeders) {
|
|
2173
2173
|
return registerSeeders(...seeders);
|
|
2174
2174
|
}
|
|
2175
2175
|
/**
|
|
2176
2176
|
* Register model constructors directly without relying on runtime discovery.
|
|
2177
|
-
*
|
|
2178
|
-
* @param models
|
|
2179
|
-
* @returns
|
|
2177
|
+
*
|
|
2178
|
+
* @param models
|
|
2179
|
+
* @returns
|
|
2180
2180
|
*/
|
|
2181
2181
|
static registerModels(...models) {
|
|
2182
2182
|
return registerModels(...models);
|
|
2183
2183
|
}
|
|
2184
2184
|
/**
|
|
2185
2185
|
* Register factory constructors or instances directly without relying on runtime discovery.
|
|
2186
|
-
*
|
|
2187
|
-
* @param factories
|
|
2188
|
-
* @returns
|
|
2186
|
+
*
|
|
2187
|
+
* @param factories
|
|
2188
|
+
* @returns
|
|
2189
2189
|
*/
|
|
2190
2190
|
static registerFactories(...factories) {
|
|
2191
2191
|
return registerFactories(...factories);
|
|
2192
2192
|
}
|
|
2193
2193
|
/**
|
|
2194
2194
|
* Register additional runtime discovery paths for models without replacing configured paths.
|
|
2195
|
-
*
|
|
2196
|
-
* @param paths
|
|
2197
|
-
* @returns
|
|
2195
|
+
*
|
|
2196
|
+
* @param paths
|
|
2197
|
+
* @returns
|
|
2198
2198
|
*/
|
|
2199
2199
|
static loadModelsFrom(paths) {
|
|
2200
2200
|
return loadModelsFrom(paths);
|
|
2201
2201
|
}
|
|
2202
2202
|
/**
|
|
2203
2203
|
* Register additional runtime discovery paths for seeders without replacing configured paths.
|
|
2204
|
-
*
|
|
2205
|
-
* @param paths
|
|
2206
|
-
* @returns
|
|
2204
|
+
*
|
|
2205
|
+
* @param paths
|
|
2206
|
+
* @returns
|
|
2207
2207
|
*/
|
|
2208
2208
|
static loadSeedersFrom(paths) {
|
|
2209
2209
|
return loadSeedersFrom(paths);
|
|
2210
2210
|
}
|
|
2211
2211
|
/**
|
|
2212
2212
|
* Register additional runtime discovery paths for migrations without replacing configured paths.
|
|
2213
|
-
*
|
|
2214
|
-
* @param paths
|
|
2215
|
-
* @returns
|
|
2213
|
+
*
|
|
2214
|
+
* @param paths
|
|
2215
|
+
* @returns
|
|
2216
2216
|
*/
|
|
2217
2217
|
static loadMigrationsFrom(paths) {
|
|
2218
2218
|
return loadMigrationsFrom(paths);
|
|
2219
2219
|
}
|
|
2220
2220
|
/**
|
|
2221
2221
|
* Register additional runtime discovery paths for factories without replacing configured paths.
|
|
2222
|
-
*
|
|
2223
|
-
* @param paths
|
|
2224
|
-
* @returns
|
|
2222
|
+
*
|
|
2223
|
+
* @param paths
|
|
2224
|
+
* @returns
|
|
2225
2225
|
*/
|
|
2226
2226
|
static loadFactoriesFrom(paths) {
|
|
2227
2227
|
return loadFactoriesFrom(paths);
|
|
2228
2228
|
}
|
|
2229
2229
|
/**
|
|
2230
2230
|
* Get registered runtime discovery paths or registered constructors for a specific type.
|
|
2231
|
-
*
|
|
2232
|
-
* @param key
|
|
2233
|
-
* @returns
|
|
2231
|
+
*
|
|
2232
|
+
* @param key
|
|
2233
|
+
* @returns
|
|
2234
2234
|
*/
|
|
2235
2235
|
static getRegisteredPaths(key) {
|
|
2236
2236
|
return getRegisteredPaths(key);
|
|
2237
2237
|
}
|
|
2238
2238
|
/**
|
|
2239
2239
|
* Get registered migration constructors instances
|
|
2240
|
-
*
|
|
2241
|
-
* @returns
|
|
2240
|
+
*
|
|
2241
|
+
* @returns
|
|
2242
2242
|
*/
|
|
2243
2243
|
static getRegisteredMigrations() {
|
|
2244
2244
|
return getRegisteredMigrations();
|
|
2245
2245
|
}
|
|
2246
2246
|
/**
|
|
2247
2247
|
* Get registered seeder constructors instances.
|
|
2248
|
-
*
|
|
2249
|
-
* @returns
|
|
2248
|
+
*
|
|
2249
|
+
* @returns
|
|
2250
2250
|
*/
|
|
2251
2251
|
static getRegisteredSeeders() {
|
|
2252
2252
|
return getRegisteredSeeders();
|
|
2253
2253
|
}
|
|
2254
2254
|
/**
|
|
2255
2255
|
* Get registered model constructors instances.
|
|
2256
|
-
*
|
|
2257
|
-
* @returns
|
|
2256
|
+
*
|
|
2257
|
+
* @returns
|
|
2258
2258
|
*/
|
|
2259
2259
|
static getRegisteredModels() {
|
|
2260
2260
|
return getRegisteredModels();
|
|
2261
2261
|
}
|
|
2262
2262
|
/**
|
|
2263
2263
|
* Get registered factory constructors or instances.
|
|
2264
|
-
*
|
|
2265
|
-
* @returns
|
|
2264
|
+
*
|
|
2265
|
+
* @returns
|
|
2266
2266
|
*/
|
|
2267
2267
|
static getRegisteredFactories() {
|
|
2268
2268
|
return getRegisteredFactories();
|
|
@@ -2390,12 +2390,12 @@ var CliApp = class {
|
|
|
2390
2390
|
return relPath;
|
|
2391
2391
|
}
|
|
2392
2392
|
/**
|
|
2393
|
-
* Utility to format a value for logging, converting absolute paths under current
|
|
2393
|
+
* Utility to format a value for logging, converting absolute paths under current
|
|
2394
2394
|
* working directory into relative display paths.
|
|
2395
|
-
*
|
|
2396
|
-
* @param name
|
|
2397
|
-
* @param value
|
|
2398
|
-
* @returns
|
|
2395
|
+
*
|
|
2396
|
+
* @param name
|
|
2397
|
+
* @param value
|
|
2398
|
+
* @returns
|
|
2399
2399
|
*/
|
|
2400
2400
|
splitLogger(name, value) {
|
|
2401
2401
|
value = value.includes(process.cwd()) ? this.formatPathForLog(value) : value;
|
|
@@ -2484,7 +2484,7 @@ var CliApp = class {
|
|
|
2484
2484
|
}
|
|
2485
2485
|
/**
|
|
2486
2486
|
* Resolve a configuration path with a fallback default
|
|
2487
|
-
*
|
|
2487
|
+
*
|
|
2488
2488
|
* @param key The configuration key to resolve
|
|
2489
2489
|
* @param fallback The fallback value if the configuration key is not set
|
|
2490
2490
|
* @returns The resolved configuration path
|
|
@@ -2496,19 +2496,19 @@ var CliApp = class {
|
|
|
2496
2496
|
}
|
|
2497
2497
|
/**
|
|
2498
2498
|
* Resolve the path to a stub file based on configuration
|
|
2499
|
-
*
|
|
2500
|
-
* @param stubName
|
|
2501
|
-
* @returns
|
|
2499
|
+
*
|
|
2500
|
+
* @param stubName
|
|
2501
|
+
* @returns
|
|
2502
2502
|
*/
|
|
2503
2503
|
resolveStubPath(stubName) {
|
|
2504
2504
|
return join$1(this.resolveConfigPath("stubs", getDefaultStubsPath()), stubName);
|
|
2505
2505
|
}
|
|
2506
2506
|
/**
|
|
2507
2507
|
* Generate a factory file for a given model name.
|
|
2508
|
-
*
|
|
2509
|
-
* @param name
|
|
2510
|
-
* @param options
|
|
2511
|
-
* @returns
|
|
2508
|
+
*
|
|
2509
|
+
* @param name
|
|
2510
|
+
* @param options
|
|
2511
|
+
* @returns
|
|
2512
2512
|
*/
|
|
2513
2513
|
makeFactory(name, options = {}) {
|
|
2514
2514
|
const baseName = str(name.replace(/Factory$/, "")).pascal();
|
|
@@ -2530,10 +2530,10 @@ var CliApp = class {
|
|
|
2530
2530
|
}
|
|
2531
2531
|
/**
|
|
2532
2532
|
* Generate a seeder file for a given name.
|
|
2533
|
-
*
|
|
2534
|
-
* @param name
|
|
2535
|
-
* @param options
|
|
2536
|
-
* @returns
|
|
2533
|
+
*
|
|
2534
|
+
* @param name
|
|
2535
|
+
* @param options
|
|
2536
|
+
* @returns
|
|
2537
2537
|
*/
|
|
2538
2538
|
makeSeeder(name, options = {}) {
|
|
2539
2539
|
const seederName = `${str(name.replace(/Seeder$/, "")).pascal()}Seeder`;
|
|
@@ -2547,7 +2547,7 @@ var CliApp = class {
|
|
|
2547
2547
|
}
|
|
2548
2548
|
/**
|
|
2549
2549
|
* Generate a migration file for a given name.
|
|
2550
|
-
*
|
|
2550
|
+
*
|
|
2551
2551
|
* @param name The name of the migration.
|
|
2552
2552
|
* @returns An object containing the name and path of the generated migration file.
|
|
2553
2553
|
*/
|
|
@@ -2563,10 +2563,10 @@ var CliApp = class {
|
|
|
2563
2563
|
}
|
|
2564
2564
|
/**
|
|
2565
2565
|
* Generate a model file along with optional factory, seeder, and migration files.
|
|
2566
|
-
*
|
|
2567
|
-
* @param name
|
|
2568
|
-
* @param options
|
|
2569
|
-
* @returns
|
|
2566
|
+
*
|
|
2567
|
+
* @param name
|
|
2568
|
+
* @param options
|
|
2569
|
+
* @returns
|
|
2570
2570
|
*/
|
|
2571
2571
|
makeModel(name, options = {}) {
|
|
2572
2572
|
const baseName = str(name.replace(/Model$/, "")).pascal().toString();
|
|
@@ -2610,10 +2610,10 @@ var CliApp = class {
|
|
|
2610
2610
|
return created;
|
|
2611
2611
|
}
|
|
2612
2612
|
/**
|
|
2613
|
-
* Ensure that the Prisma schema has a model entry for the given model
|
|
2613
|
+
* Ensure that the Prisma schema has a model entry for the given model
|
|
2614
2614
|
* and table names.
|
|
2615
2615
|
* If the entry does not exist, it will be created with a default `id` field.
|
|
2616
|
-
*
|
|
2616
|
+
*
|
|
2617
2617
|
* @param modelName The name of the model to ensure in the Prisma schema.
|
|
2618
2618
|
* @param tableName The table name to ensure in the Prisma schema.
|
|
2619
2619
|
*/
|
|
@@ -2645,7 +2645,7 @@ var CliApp = class {
|
|
|
2645
2645
|
}
|
|
2646
2646
|
/**
|
|
2647
2647
|
* Convert a Prisma scalar type to its corresponding TypeScript type.
|
|
2648
|
-
*
|
|
2648
|
+
*
|
|
2649
2649
|
* @param value The Prisma scalar type.
|
|
2650
2650
|
* @returns The corresponding TypeScript type.
|
|
2651
2651
|
*/
|
|
@@ -2938,9 +2938,9 @@ var CliApp = class {
|
|
|
2938
2938
|
return isList ? `Array<${baseType}>` : baseType;
|
|
2939
2939
|
}
|
|
2940
2940
|
/**
|
|
2941
|
-
* Parse the Prisma schema to extract model definitions and their fields, focusing
|
|
2941
|
+
* Parse the Prisma schema to extract model definitions and their fields, focusing
|
|
2942
2942
|
* on scalar types.
|
|
2943
|
-
*
|
|
2943
|
+
*
|
|
2944
2944
|
* @param schema The Prisma schema as a string.
|
|
2945
2945
|
* @returns An array of model definitions with their fields.
|
|
2946
2946
|
*/
|
|
@@ -2988,11 +2988,11 @@ var CliApp = class {
|
|
|
2988
2988
|
return models;
|
|
2989
2989
|
}
|
|
2990
2990
|
/**
|
|
2991
|
-
* Sync model attribute declarations in a model file based on the
|
|
2991
|
+
* Sync model attribute declarations in a model file based on the
|
|
2992
2992
|
* provided declarations.
|
|
2993
|
-
* This method takes the source code of a model file and a list of
|
|
2993
|
+
* This method takes the source code of a model file and a list of
|
|
2994
2994
|
* attribute declarations,
|
|
2995
|
-
*
|
|
2995
|
+
*
|
|
2996
2996
|
* @param modelSource The source code of the model file.
|
|
2997
2997
|
* @param declarations A list of attribute declarations to sync.
|
|
2998
2998
|
* @returns An object containing the updated content and a flag indicating if it was updated.
|
|
@@ -3088,12 +3088,12 @@ var CliApp = class {
|
|
|
3088
3088
|
}
|
|
3089
3089
|
/**
|
|
3090
3090
|
* Sync model attribute declarations in model files based on the Prisma schema.
|
|
3091
|
-
* This method reads the Prisma schema to extract model definitions and their
|
|
3092
|
-
* scalar fields, then updates the corresponding model files to include `declare`
|
|
3091
|
+
* This method reads the Prisma schema to extract model definitions and their
|
|
3092
|
+
* scalar fields, then updates the corresponding model files to include `declare`
|
|
3093
3093
|
* statements for these fields. It returns an object containing the paths of the
|
|
3094
|
-
* schema and models, the total number of model files processed, and lists of
|
|
3094
|
+
* schema and models, the total number of model files processed, and lists of
|
|
3095
3095
|
* updated and skipped files.
|
|
3096
|
-
*
|
|
3096
|
+
*
|
|
3097
3097
|
* @param options Optional parameters to specify custom paths for the Prisma schema and models directory.
|
|
3098
3098
|
* @returns An object with details about the synchronization process, including updated and skipped files.
|
|
3099
3099
|
*/
|
|
@@ -3124,7 +3124,7 @@ var CliApp = class {
|
|
|
3124
3124
|
//#endregion
|
|
3125
3125
|
//#region src/cli/commands/InitCommand.ts
|
|
3126
3126
|
/**
|
|
3127
|
-
* The InitCommand class implements the CLI command for initializing Arkormˣ by creating
|
|
3127
|
+
* The InitCommand class implements the CLI command for initializing Arkormˣ by creating
|
|
3128
3128
|
* a default config file in the current directory.
|
|
3129
3129
|
*
|
|
3130
3130
|
* @author Legacy (3m1n3nc3)
|
|
@@ -3183,8 +3183,8 @@ var MakeFactoryCommand = class extends Command {
|
|
|
3183
3183
|
}
|
|
3184
3184
|
/**
|
|
3185
3185
|
* Command handler for the make:factory command.
|
|
3186
|
-
*
|
|
3187
|
-
* @returns
|
|
3186
|
+
*
|
|
3187
|
+
* @returns
|
|
3188
3188
|
*/
|
|
3189
3189
|
async handle() {
|
|
3190
3190
|
this.app.command = this;
|
|
@@ -3213,8 +3213,8 @@ var MakeMigrationCommand = class extends Command {
|
|
|
3213
3213
|
}
|
|
3214
3214
|
/**
|
|
3215
3215
|
* Command handler for the make:migration command.
|
|
3216
|
-
*
|
|
3217
|
-
* @returns
|
|
3216
|
+
*
|
|
3217
|
+
* @returns
|
|
3218
3218
|
*/
|
|
3219
3219
|
async handle() {
|
|
3220
3220
|
this.app.command = this;
|
|
@@ -3228,7 +3228,7 @@ var MakeMigrationCommand = class extends Command {
|
|
|
3228
3228
|
//#endregion
|
|
3229
3229
|
//#region src/cli/commands/MakeModelCommand.ts
|
|
3230
3230
|
/**
|
|
3231
|
-
* The MakeModelCommand class implements the CLI command for creating new model
|
|
3231
|
+
* The MakeModelCommand class implements the CLI command for creating new model
|
|
3232
3232
|
* classes along with optional linked resources such as factories, seeders, and migrations.
|
|
3233
3233
|
*
|
|
3234
3234
|
* @author Legacy (3m1n3nc3)
|
|
@@ -3250,8 +3250,8 @@ var MakeModelCommand = class extends Command {
|
|
|
3250
3250
|
}
|
|
3251
3251
|
/**
|
|
3252
3252
|
* Command handler for the make:model command.
|
|
3253
|
-
*
|
|
3254
|
-
* @returns
|
|
3253
|
+
*
|
|
3254
|
+
* @returns
|
|
3255
3255
|
*/
|
|
3256
3256
|
async handle() {
|
|
3257
3257
|
this.app.command = this;
|
|
@@ -3301,8 +3301,8 @@ var MakeSeederCommand = class extends Command {
|
|
|
3301
3301
|
//#region src/database/Migration.ts
|
|
3302
3302
|
const MIGRATION_BRAND = Symbol.for("arkormx.migration");
|
|
3303
3303
|
/**
|
|
3304
|
-
* The Migration class serves as a base for defining database migrations, requiring
|
|
3305
|
-
* the implementation of `up` and `down` methods to specify the changes to be
|
|
3304
|
+
* The Migration class serves as a base for defining database migrations, requiring
|
|
3305
|
+
* the implementation of `up` and `down` methods to specify the changes to be
|
|
3306
3306
|
* applied or reverted in the database schema.
|
|
3307
3307
|
*
|
|
3308
3308
|
* @author Legacy (3m1n3nc3)
|
|
@@ -3317,7 +3317,7 @@ var Migration = class {
|
|
|
3317
3317
|
//#endregion
|
|
3318
3318
|
//#region src/cli/commands/MigrateCommand.ts
|
|
3319
3319
|
/**
|
|
3320
|
-
* The MigrateCommand class implements the CLI command for applying migration
|
|
3320
|
+
* The MigrateCommand class implements the CLI command for applying migration
|
|
3321
3321
|
* classes to the Prisma schema and running the Prisma workflow.
|
|
3322
3322
|
*
|
|
3323
3323
|
* @author Legacy (3m1n3nc3)
|
|
@@ -3341,12 +3341,12 @@ var MigrateCommand = class extends Command {
|
|
|
3341
3341
|
}
|
|
3342
3342
|
/**
|
|
3343
3343
|
* Command handler for the migrate command.
|
|
3344
|
-
* This method is responsible for orchestrating the migration
|
|
3345
|
-
* process, including loading migration classes, applying them to
|
|
3346
|
-
* the Prisma schema, and running the appropriate Prisma commands
|
|
3344
|
+
* This method is responsible for orchestrating the migration
|
|
3345
|
+
* process, including loading migration classes, applying them to
|
|
3346
|
+
* the Prisma schema, and running the appropriate Prisma commands
|
|
3347
3347
|
* based on the provided options.
|
|
3348
|
-
*
|
|
3349
|
-
* @returns
|
|
3348
|
+
*
|
|
3349
|
+
* @returns
|
|
3350
3350
|
*/
|
|
3351
3351
|
async handle() {
|
|
3352
3352
|
this.app.command = this;
|
|
@@ -3461,10 +3461,10 @@ var MigrateCommand = class extends Command {
|
|
|
3461
3461
|
}
|
|
3462
3462
|
/**
|
|
3463
3463
|
* Load migration classes from a specific file or by class name.
|
|
3464
|
-
*
|
|
3465
|
-
* @param migrationsDir
|
|
3466
|
-
* @param name
|
|
3467
|
-
* @returns
|
|
3464
|
+
*
|
|
3465
|
+
* @param migrationsDir
|
|
3466
|
+
* @param name
|
|
3467
|
+
* @returns
|
|
3468
3468
|
*/
|
|
3469
3469
|
async loadNamedMigration(migrationsDirs, name) {
|
|
3470
3470
|
if (!name) return [[void 0, ""]];
|
|
@@ -3487,9 +3487,9 @@ var MigrateCommand = class extends Command {
|
|
|
3487
3487
|
}
|
|
3488
3488
|
/**
|
|
3489
3489
|
* Load migration classes from a given file path.
|
|
3490
|
-
*
|
|
3491
|
-
* @param filePath
|
|
3492
|
-
* @returns
|
|
3490
|
+
*
|
|
3491
|
+
* @param filePath
|
|
3492
|
+
* @returns
|
|
3493
3493
|
*/
|
|
3494
3494
|
async loadMigrationClassesFromFile(filePath) {
|
|
3495
3495
|
const imported = await RuntimeModuleLoader.load(filePath);
|
|
@@ -3908,7 +3908,7 @@ var ModelsSyncCommand = class extends Command {
|
|
|
3908
3908
|
//#region src/database/Seeder.ts
|
|
3909
3909
|
const SEEDER_BRAND = Symbol.for("arkormx.seeder");
|
|
3910
3910
|
/**
|
|
3911
|
-
* The Seeder class serves as a base for defining database seeders, which are
|
|
3911
|
+
* The Seeder class serves as a base for defining database seeders, which are
|
|
3912
3912
|
* used to populate the database with initial or test data.
|
|
3913
3913
|
*
|
|
3914
3914
|
* @author Legacy (3m1n3nc3)
|
|
@@ -3923,7 +3923,7 @@ var Seeder = class Seeder {
|
|
|
3923
3923
|
}
|
|
3924
3924
|
/**
|
|
3925
3925
|
* Runs one or more seeders.
|
|
3926
|
-
*
|
|
3926
|
+
*
|
|
3927
3927
|
* @param seeders The seeders to be run.
|
|
3928
3928
|
*/
|
|
3929
3929
|
async call(...seeders) {
|
|
@@ -3931,9 +3931,9 @@ var Seeder = class Seeder {
|
|
|
3931
3931
|
}
|
|
3932
3932
|
/**
|
|
3933
3933
|
* Run seeders and return every seeder class executed, including nested calls.
|
|
3934
|
-
*
|
|
3935
|
-
* @param seeders
|
|
3936
|
-
* @returns
|
|
3934
|
+
*
|
|
3935
|
+
* @param seeders
|
|
3936
|
+
* @returns
|
|
3937
3937
|
*/
|
|
3938
3938
|
static async runWithReport(...seeders) {
|
|
3939
3939
|
const report = [];
|
|
@@ -3943,8 +3943,8 @@ var Seeder = class Seeder {
|
|
|
3943
3943
|
return report;
|
|
3944
3944
|
}
|
|
3945
3945
|
/**
|
|
3946
|
-
* Converts a SeederInput into a Seeder instance.
|
|
3947
|
-
*
|
|
3946
|
+
* Converts a SeederInput into a Seeder instance.
|
|
3947
|
+
*
|
|
3948
3948
|
* @param input The SeederInput to convert.
|
|
3949
3949
|
* @returns A Seeder instance.
|
|
3950
3950
|
*/
|
|
@@ -3957,7 +3957,7 @@ var Seeder = class Seeder {
|
|
|
3957
3957
|
}
|
|
3958
3958
|
/**
|
|
3959
3959
|
* Runs the given seeders in sequence.
|
|
3960
|
-
*
|
|
3960
|
+
*
|
|
3961
3961
|
* @param seeders The seeders to be run.
|
|
3962
3962
|
*/
|
|
3963
3963
|
static async runSeeders(...seeders) {
|
|
@@ -3977,7 +3977,7 @@ var Seeder = class Seeder {
|
|
|
3977
3977
|
//#endregion
|
|
3978
3978
|
//#region src/cli/commands/SeedCommand.ts
|
|
3979
3979
|
/**
|
|
3980
|
-
* The SeedCommand class implements the CLI command for running seeder classes.
|
|
3980
|
+
* The SeedCommand class implements the CLI command for running seeder classes.
|
|
3981
3981
|
*
|
|
3982
3982
|
* @author Legacy (3m1n3nc3)
|
|
3983
3983
|
* @since 0.1.0
|
|
@@ -3993,8 +3993,8 @@ var SeedCommand = class extends Command {
|
|
|
3993
3993
|
}
|
|
3994
3994
|
/**
|
|
3995
3995
|
* Command handler for the seed command.
|
|
3996
|
-
*
|
|
3997
|
-
* @returns
|
|
3996
|
+
*
|
|
3997
|
+
* @returns
|
|
3998
3998
|
*/
|
|
3999
3999
|
async handle() {
|
|
4000
4000
|
this.app.command = this;
|
|
@@ -4010,9 +4010,9 @@ var SeedCommand = class extends Command {
|
|
|
4010
4010
|
}
|
|
4011
4011
|
/**
|
|
4012
4012
|
* Load all seeder classes from the specified directory.
|
|
4013
|
-
*
|
|
4014
|
-
* @param seedersDir
|
|
4015
|
-
* @returns
|
|
4013
|
+
*
|
|
4014
|
+
* @param seedersDir
|
|
4015
|
+
* @returns
|
|
4016
4016
|
*/
|
|
4017
4017
|
resolveSeederDirectories(configuredSeedersDir) {
|
|
4018
4018
|
return [this.app.resolveRuntimeDirectoryPath(configuredSeedersDir), ...getRegisteredPaths("seeders").map((directory) => this.app.resolveRuntimeDirectoryPath(directory))].filter((directory, index, all) => existsSync$1(directory) && all.indexOf(directory) === index);
|
|
@@ -4023,10 +4023,10 @@ var SeedCommand = class extends Command {
|
|
|
4023
4023
|
}
|
|
4024
4024
|
/**
|
|
4025
4025
|
* Load seeder classes from a specific file or by class name.
|
|
4026
|
-
*
|
|
4027
|
-
* @param seedersDir
|
|
4028
|
-
* @param name
|
|
4029
|
-
* @returns
|
|
4026
|
+
*
|
|
4027
|
+
* @param seedersDir
|
|
4028
|
+
* @param name
|
|
4029
|
+
* @returns
|
|
4030
4030
|
*/
|
|
4031
4031
|
async loadNamedSeeder(seedersDirs, name) {
|
|
4032
4032
|
const base = name.replace(/Seeder$/, "");
|
|
@@ -4048,7 +4048,7 @@ var SeedCommand = class extends Command {
|
|
|
4048
4048
|
}
|
|
4049
4049
|
/**
|
|
4050
4050
|
* Load seeder classes from a given file path.
|
|
4051
|
-
*
|
|
4051
|
+
*
|
|
4052
4052
|
* @param filePath The path to the file containing seeder classes.
|
|
4053
4053
|
* @returns An array of seeder classes.
|
|
4054
4054
|
*/
|
|
@@ -4314,9 +4314,9 @@ var JoinClause = class JoinClause {
|
|
|
4314
4314
|
//#endregion
|
|
4315
4315
|
//#region src/Exceptions/ModelNotFoundException.ts
|
|
4316
4316
|
/**
|
|
4317
|
-
* The ModelNotFoundException class is a custom error type for handling
|
|
4318
|
-
* cases where a requested model instance cannot be found in the database.
|
|
4319
|
-
*
|
|
4317
|
+
* The ModelNotFoundException class is a custom error type for handling
|
|
4318
|
+
* cases where a requested model instance cannot be found in the database.
|
|
4319
|
+
*
|
|
4320
4320
|
* @author Legacy (3m1n3nc3)
|
|
4321
4321
|
* @since 0.1.0
|
|
4322
4322
|
*/
|
|
@@ -4374,9 +4374,9 @@ var UniqueConstraintResolutionException = class extends ArkormException {
|
|
|
4374
4374
|
//#endregion
|
|
4375
4375
|
//#region src/QueryBuilder.ts
|
|
4376
4376
|
/**
|
|
4377
|
-
* The QueryBuilder class provides a fluent interface for building and
|
|
4377
|
+
* The QueryBuilder class provides a fluent interface for building and
|
|
4378
4378
|
* executing database queries.
|
|
4379
|
-
*
|
|
4379
|
+
*
|
|
4380
4380
|
* @template TModel The type of the model being queried.
|
|
4381
4381
|
* @author Legacy (3m1n3nc3)
|
|
4382
4382
|
* @since 0.1.0
|
|
@@ -4384,8 +4384,8 @@ var UniqueConstraintResolutionException = class extends ArkormException {
|
|
|
4384
4384
|
var QueryBuilder = class QueryBuilder {
|
|
4385
4385
|
/**
|
|
4386
4386
|
* Creates a new QueryBuilder instance.
|
|
4387
|
-
*
|
|
4388
|
-
* @param model
|
|
4387
|
+
*
|
|
4388
|
+
* @param model
|
|
4389
4389
|
*/
|
|
4390
4390
|
constructor(model, adapter) {
|
|
4391
4391
|
this.model = model;
|
|
@@ -4563,45 +4563,45 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4563
4563
|
}
|
|
4564
4564
|
/**
|
|
4565
4565
|
* Adds clause to determine if a column's value is in the past
|
|
4566
|
-
*
|
|
4567
|
-
* @param key
|
|
4568
|
-
* @returns
|
|
4566
|
+
*
|
|
4567
|
+
* @param key
|
|
4568
|
+
* @returns
|
|
4569
4569
|
*/
|
|
4570
4570
|
wherePast(key) {
|
|
4571
4571
|
return this.where({ [key]: { lt: /* @__PURE__ */ new Date() } });
|
|
4572
4572
|
}
|
|
4573
4573
|
/**
|
|
4574
4574
|
* Adds clause to determine if a column's value is in the future
|
|
4575
|
-
*
|
|
4576
|
-
* @param key
|
|
4577
|
-
* @returns
|
|
4575
|
+
*
|
|
4576
|
+
* @param key
|
|
4577
|
+
* @returns
|
|
4578
4578
|
*/
|
|
4579
4579
|
whereFuture(key) {
|
|
4580
4580
|
return this.where({ [key]: { gt: /* @__PURE__ */ new Date() } });
|
|
4581
4581
|
}
|
|
4582
4582
|
/**
|
|
4583
4583
|
* Adds clause to determine if a column's value is in the past, inclusive of the current date and time
|
|
4584
|
-
*
|
|
4585
|
-
* @param key
|
|
4586
|
-
* @returns
|
|
4584
|
+
*
|
|
4585
|
+
* @param key
|
|
4586
|
+
* @returns
|
|
4587
4587
|
*/
|
|
4588
4588
|
whereNowOrPast(key) {
|
|
4589
4589
|
return this.where({ [key]: { lte: /* @__PURE__ */ new Date() } });
|
|
4590
4590
|
}
|
|
4591
4591
|
/**
|
|
4592
4592
|
* Adds clause to determine if a column's value is in the future, inclusive of the current date and time
|
|
4593
|
-
*
|
|
4594
|
-
* @param key
|
|
4595
|
-
* @returns
|
|
4593
|
+
*
|
|
4594
|
+
* @param key
|
|
4595
|
+
* @returns
|
|
4596
4596
|
*/
|
|
4597
4597
|
whereNowOrFuture(key) {
|
|
4598
4598
|
return this.where({ [key]: { gte: /* @__PURE__ */ new Date() } });
|
|
4599
4599
|
}
|
|
4600
4600
|
/**
|
|
4601
4601
|
* Adds clause to determine if a column's value is today
|
|
4602
|
-
*
|
|
4603
|
-
* @param key
|
|
4604
|
-
* @returns
|
|
4602
|
+
*
|
|
4603
|
+
* @param key
|
|
4604
|
+
* @returns
|
|
4605
4605
|
*/
|
|
4606
4606
|
whereToday(key) {
|
|
4607
4607
|
const [start, end] = this.getUtcDayBounds();
|
|
@@ -4612,9 +4612,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4612
4612
|
}
|
|
4613
4613
|
/**
|
|
4614
4614
|
* Adds clause to determine if a column's value is before today
|
|
4615
|
-
*
|
|
4616
|
-
* @param key
|
|
4617
|
-
* @returns
|
|
4615
|
+
*
|
|
4616
|
+
* @param key
|
|
4617
|
+
* @returns
|
|
4618
4618
|
*/
|
|
4619
4619
|
whereBeforeToday(key) {
|
|
4620
4620
|
const [start] = this.getUtcDayBounds();
|
|
@@ -4622,9 +4622,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4622
4622
|
}
|
|
4623
4623
|
/**
|
|
4624
4624
|
* Adds clause to determine if a column's value is after today
|
|
4625
|
-
*
|
|
4626
|
-
* @param key
|
|
4627
|
-
* @returns
|
|
4625
|
+
*
|
|
4626
|
+
* @param key
|
|
4627
|
+
* @returns
|
|
4628
4628
|
*/
|
|
4629
4629
|
whereAfterToday(key) {
|
|
4630
4630
|
const [, end] = this.getUtcDayBounds();
|
|
@@ -4632,9 +4632,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4632
4632
|
}
|
|
4633
4633
|
/**
|
|
4634
4634
|
* Adds clause to determine if a column's value is today or before today
|
|
4635
|
-
*
|
|
4636
|
-
* @param key
|
|
4637
|
-
* @returns
|
|
4635
|
+
*
|
|
4636
|
+
* @param key
|
|
4637
|
+
* @returns
|
|
4638
4638
|
*/
|
|
4639
4639
|
whereTodayOrBefore(key) {
|
|
4640
4640
|
const [, end] = this.getUtcDayBounds();
|
|
@@ -4642,9 +4642,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4642
4642
|
}
|
|
4643
4643
|
/**
|
|
4644
4644
|
* Adds clause to determine if a column's value is today or after today
|
|
4645
|
-
*
|
|
4646
|
-
* @param key
|
|
4647
|
-
* @returns
|
|
4645
|
+
*
|
|
4646
|
+
* @param key
|
|
4647
|
+
* @returns
|
|
4648
4648
|
*/
|
|
4649
4649
|
whereTodayOrAfter(key) {
|
|
4650
4650
|
const [start] = this.getUtcDayBounds();
|
|
@@ -4661,9 +4661,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4661
4661
|
}
|
|
4662
4662
|
/**
|
|
4663
4663
|
* Adds "where exists" SQL clauses.
|
|
4664
|
-
*
|
|
4665
|
-
* @param queryOrCallback
|
|
4666
|
-
* @returns
|
|
4664
|
+
*
|
|
4665
|
+
* @param queryOrCallback
|
|
4666
|
+
* @returns
|
|
4667
4667
|
*/
|
|
4668
4668
|
whereExists(queryOrCallback) {
|
|
4669
4669
|
const baseQuery = new QueryBuilder(this.model, this.adapter);
|
|
@@ -4803,12 +4803,12 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4803
4803
|
/**
|
|
4804
4804
|
* Append a structured JSON predicate, splitting a `column->path->key`
|
|
4805
4805
|
* expression into its base column and nested path segments.
|
|
4806
|
-
*
|
|
4807
|
-
* @param boolean
|
|
4808
|
-
* @param kind
|
|
4809
|
-
* @param column
|
|
4810
|
-
* @param options
|
|
4811
|
-
* @returns
|
|
4806
|
+
*
|
|
4807
|
+
* @param boolean
|
|
4808
|
+
* @param kind
|
|
4809
|
+
* @param column
|
|
4810
|
+
* @param options
|
|
4811
|
+
* @returns
|
|
4812
4812
|
*/
|
|
4813
4813
|
appendJsonCondition(boolean, kind, column, options = {}) {
|
|
4814
4814
|
const [base, ...path] = column.split("->").map((segment) => segment.trim());
|
|
@@ -4837,10 +4837,10 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4837
4837
|
}
|
|
4838
4838
|
/**
|
|
4839
4839
|
* OR variant of whereJsonContains().
|
|
4840
|
-
*
|
|
4841
|
-
* @param column
|
|
4842
|
-
* @param value
|
|
4843
|
-
* @returns
|
|
4840
|
+
*
|
|
4841
|
+
* @param column
|
|
4842
|
+
* @param value
|
|
4843
|
+
* @returns
|
|
4844
4844
|
*/
|
|
4845
4845
|
orWhereJsonContains(column, value) {
|
|
4846
4846
|
return this.appendJsonCondition("OR", "contains", column, { value });
|
|
@@ -4860,10 +4860,10 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4860
4860
|
}
|
|
4861
4861
|
/**
|
|
4862
4862
|
* OR variant of whereJsonDoesntContain().
|
|
4863
|
-
*
|
|
4864
|
-
* @param column
|
|
4865
|
-
* @param value
|
|
4866
|
-
* @returns
|
|
4863
|
+
*
|
|
4864
|
+
* @param column
|
|
4865
|
+
* @param value
|
|
4866
|
+
* @returns
|
|
4867
4867
|
*/
|
|
4868
4868
|
orWhereJsonDoesntContain(column, value) {
|
|
4869
4869
|
return this.appendJsonCondition("OR", "contains", column, {
|
|
@@ -4882,9 +4882,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4882
4882
|
}
|
|
4883
4883
|
/**
|
|
4884
4884
|
* OR variant of whereJsonContainsKey().
|
|
4885
|
-
*
|
|
4886
|
-
* @param column
|
|
4887
|
-
* @returns
|
|
4885
|
+
*
|
|
4886
|
+
* @param column
|
|
4887
|
+
* @returns
|
|
4888
4888
|
*/
|
|
4889
4889
|
orWhereJsonContainsKey(column) {
|
|
4890
4890
|
return this.appendJsonCondition("OR", "contains-key", column);
|
|
@@ -4900,9 +4900,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4900
4900
|
}
|
|
4901
4901
|
/**
|
|
4902
4902
|
* OR variant of whereJsonDoesntContainKey().
|
|
4903
|
-
*
|
|
4904
|
-
* @param column
|
|
4905
|
-
* @returns
|
|
4903
|
+
*
|
|
4904
|
+
* @param column
|
|
4905
|
+
* @returns
|
|
4906
4906
|
*/
|
|
4907
4907
|
orWhereJsonDoesntContainKey(column) {
|
|
4908
4908
|
return this.appendJsonCondition("OR", "contains-key", column, { not: true });
|
|
@@ -4944,10 +4944,10 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4944
4944
|
}
|
|
4945
4945
|
/**
|
|
4946
4946
|
* OR variant of whereJsonOverlaps().
|
|
4947
|
-
*
|
|
4948
|
-
* @param column
|
|
4949
|
-
* @param value
|
|
4950
|
-
* @returns
|
|
4947
|
+
*
|
|
4948
|
+
* @param column
|
|
4949
|
+
* @param value
|
|
4950
|
+
* @returns
|
|
4951
4951
|
*/
|
|
4952
4952
|
orWhereJsonOverlaps(column, value) {
|
|
4953
4953
|
return this.appendJsonCondition("OR", "overlaps", column, { value });
|
|
@@ -5065,9 +5065,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5065
5065
|
}
|
|
5066
5066
|
/**
|
|
5067
5067
|
* Adds an orderBy clause to the query. This will overwrite any existing orderBy clause.
|
|
5068
|
-
*
|
|
5069
|
-
* @param orderBy
|
|
5070
|
-
* @returns
|
|
5068
|
+
*
|
|
5069
|
+
* @param orderBy
|
|
5070
|
+
* @returns
|
|
5071
5071
|
*/
|
|
5072
5072
|
orderBy(orderBy) {
|
|
5073
5073
|
this.randomOrderEnabled = false;
|
|
@@ -5121,9 +5121,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5121
5121
|
}
|
|
5122
5122
|
/**
|
|
5123
5123
|
* Adds an include clause to the query. This will overwrite any existing include clause.
|
|
5124
|
-
*
|
|
5125
|
-
* @param include
|
|
5126
|
-
* @returns
|
|
5124
|
+
*
|
|
5125
|
+
* @param include
|
|
5126
|
+
* @returns
|
|
5127
5127
|
*/
|
|
5128
5128
|
include(include) {
|
|
5129
5129
|
const normalized = this.normalizeRelationLoads(include);
|
|
@@ -5136,11 +5136,11 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5136
5136
|
return this;
|
|
5137
5137
|
}
|
|
5138
5138
|
/**
|
|
5139
|
-
* Adds eager loading for the specified relations.
|
|
5139
|
+
* Adds eager loading for the specified relations.
|
|
5140
5140
|
* This will merge with any existing include clause.
|
|
5141
|
-
*
|
|
5142
|
-
* @param relations
|
|
5143
|
-
* @returns
|
|
5141
|
+
*
|
|
5142
|
+
* @param relations
|
|
5143
|
+
* @returns
|
|
5144
5144
|
*/
|
|
5145
5145
|
with(relations) {
|
|
5146
5146
|
const relationMap = this.normalizeWith(relations);
|
|
@@ -5342,10 +5342,10 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5342
5342
|
return this.withRelationAggregate("max", relation, column);
|
|
5343
5343
|
}
|
|
5344
5344
|
/**
|
|
5345
|
-
* Includes soft-deleted records in the query results.
|
|
5345
|
+
* Includes soft-deleted records in the query results.
|
|
5346
5346
|
* This method is only applicable if the model has soft delete enabled.
|
|
5347
|
-
*
|
|
5348
|
-
* @returns
|
|
5347
|
+
*
|
|
5348
|
+
* @returns
|
|
5349
5349
|
*/
|
|
5350
5350
|
withTrashed() {
|
|
5351
5351
|
this.includeTrashed = true;
|
|
@@ -5353,10 +5353,10 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5353
5353
|
return this;
|
|
5354
5354
|
}
|
|
5355
5355
|
/**
|
|
5356
|
-
* Limits the query results to only soft-deleted records.
|
|
5356
|
+
* Limits the query results to only soft-deleted records.
|
|
5357
5357
|
* This method is only applicable if the model has soft delete enabled.
|
|
5358
|
-
*
|
|
5359
|
-
* @returns
|
|
5358
|
+
*
|
|
5359
|
+
* @returns
|
|
5360
5360
|
*/
|
|
5361
5361
|
onlyTrashed() {
|
|
5362
5362
|
this.onlyTrashedRecords = true;
|
|
@@ -5364,11 +5364,11 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5364
5364
|
return this;
|
|
5365
5365
|
}
|
|
5366
5366
|
/**
|
|
5367
|
-
* Excludes soft-deleted records from the query results.
|
|
5368
|
-
* This is the default behavior, but this method can be used to explicitly
|
|
5367
|
+
* Excludes soft-deleted records from the query results.
|
|
5368
|
+
* This is the default behavior, but this method can be used to explicitly
|
|
5369
5369
|
* enforce it after using withTrashed or onlyTrashed.
|
|
5370
|
-
*
|
|
5371
|
-
* @returns
|
|
5370
|
+
*
|
|
5371
|
+
* @returns
|
|
5372
5372
|
*/
|
|
5373
5373
|
withoutTrashed() {
|
|
5374
5374
|
this.includeTrashed = false;
|
|
@@ -5377,14 +5377,14 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5377
5377
|
}
|
|
5378
5378
|
/**
|
|
5379
5379
|
* Applies a named scope to the query. A scope is a reusable query constraint
|
|
5380
|
-
* defined as a static method on the model. The scope method will look for a
|
|
5381
|
-
* method with the name `scope{Name}` on the model's prototype.
|
|
5382
|
-
* If found, it will call that method with the current query builder
|
|
5380
|
+
* defined as a static method on the model. The scope method will look for a
|
|
5381
|
+
* method with the name `scope{Name}` on the model's prototype.
|
|
5382
|
+
* If found, it will call that method with the current query builder
|
|
5383
5383
|
* instance and any additional arguments provided.
|
|
5384
|
-
*
|
|
5385
|
-
* @param name
|
|
5386
|
-
* @param args
|
|
5387
|
-
* @returns
|
|
5384
|
+
*
|
|
5385
|
+
* @param name
|
|
5386
|
+
* @param args
|
|
5387
|
+
* @returns
|
|
5388
5388
|
*/
|
|
5389
5389
|
scope(name, ...args) {
|
|
5390
5390
|
const methodName = `scope${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
@@ -5447,9 +5447,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5447
5447
|
}
|
|
5448
5448
|
/**
|
|
5449
5449
|
* Adds a select clause to the query. This will overwrite any existing select clause.
|
|
5450
|
-
*
|
|
5451
|
-
* @param select
|
|
5452
|
-
* @returns
|
|
5450
|
+
*
|
|
5451
|
+
* @param select
|
|
5452
|
+
* @returns
|
|
5453
5453
|
*/
|
|
5454
5454
|
select(select) {
|
|
5455
5455
|
const normalized = this.normalizeQuerySelect(select);
|
|
@@ -5800,9 +5800,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5800
5800
|
/**
|
|
5801
5801
|
* Adds a skip clause to the query for pagination.
|
|
5802
5802
|
* This will overwrite any existing skip clause.
|
|
5803
|
-
*
|
|
5804
|
-
* @param skip
|
|
5805
|
-
* @returns
|
|
5803
|
+
*
|
|
5804
|
+
* @param skip
|
|
5805
|
+
* @returns
|
|
5806
5806
|
*/
|
|
5807
5807
|
skip(skip) {
|
|
5808
5808
|
this.offsetValue = skip;
|
|
@@ -5819,9 +5819,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5819
5819
|
}
|
|
5820
5820
|
/**
|
|
5821
5821
|
* Adds a take clause to the query for pagination.
|
|
5822
|
-
*
|
|
5823
|
-
* @param take
|
|
5824
|
-
* @returns
|
|
5822
|
+
*
|
|
5823
|
+
* @param take
|
|
5824
|
+
* @returns
|
|
5825
5825
|
*/
|
|
5826
5826
|
take(take) {
|
|
5827
5827
|
this.limitValue = take;
|
|
@@ -5838,9 +5838,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5838
5838
|
}
|
|
5839
5839
|
/**
|
|
5840
5840
|
* Returns a representation of the query that can be used for debugging or logging purposes.
|
|
5841
|
-
*
|
|
5842
|
-
* @param operation
|
|
5843
|
-
* @returns
|
|
5841
|
+
*
|
|
5842
|
+
* @param operation
|
|
5843
|
+
* @returns
|
|
5844
5844
|
*/
|
|
5845
5845
|
inspect(operation = "select") {
|
|
5846
5846
|
const adapter = this.requireAdapter();
|
|
@@ -5887,8 +5887,8 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5887
5887
|
}
|
|
5888
5888
|
/**
|
|
5889
5889
|
* Executes the query and returns the results as a collection of model instances.
|
|
5890
|
-
*
|
|
5891
|
-
* @returns
|
|
5890
|
+
*
|
|
5891
|
+
* @returns
|
|
5892
5892
|
*/
|
|
5893
5893
|
async get() {
|
|
5894
5894
|
const useAdapterRelationFeatures = this.canExecuteRelationFeaturesInAdapter();
|
|
@@ -5909,10 +5909,10 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5909
5909
|
return new ArkormCollection(filteredModels);
|
|
5910
5910
|
}
|
|
5911
5911
|
/**
|
|
5912
|
-
* Executes the query and returns the first result as a model
|
|
5912
|
+
* Executes the query and returns the first result as a model
|
|
5913
5913
|
* instance, or null if no results are found.
|
|
5914
|
-
*
|
|
5915
|
-
* @returns
|
|
5914
|
+
*
|
|
5915
|
+
* @returns
|
|
5916
5916
|
*/
|
|
5917
5917
|
async first() {
|
|
5918
5918
|
if (this.shouldUseCompatibilityRelationFallback()) return (await this.get()).all()[0] ?? null;
|
|
@@ -5933,8 +5933,8 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5933
5933
|
}
|
|
5934
5934
|
/**
|
|
5935
5935
|
* Executes the query and returns the first result as a model instance.
|
|
5936
|
-
*
|
|
5937
|
-
* @returns
|
|
5936
|
+
*
|
|
5937
|
+
* @returns
|
|
5938
5938
|
*/
|
|
5939
5939
|
async firstOrFail() {
|
|
5940
5940
|
const model = await this.first();
|
|
@@ -6047,9 +6047,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6047
6047
|
}
|
|
6048
6048
|
/**
|
|
6049
6049
|
* Creates a new record with the specified data and returns it as a model instance.
|
|
6050
|
-
*
|
|
6051
|
-
* @param data
|
|
6052
|
-
* @returns
|
|
6050
|
+
*
|
|
6051
|
+
* @param data
|
|
6052
|
+
* @returns
|
|
6053
6053
|
*/
|
|
6054
6054
|
async create(data) {
|
|
6055
6055
|
const created = await this.executeInsertRow(data);
|
|
@@ -6135,11 +6135,11 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6135
6135
|
return this.insertOrIgnore(rows);
|
|
6136
6136
|
}
|
|
6137
6137
|
/**
|
|
6138
|
-
* Updates records matching the current query constraints with the
|
|
6138
|
+
* Updates records matching the current query constraints with the
|
|
6139
6139
|
* specified data and returns the updated record(s) as model instance(s).
|
|
6140
|
-
*
|
|
6141
|
-
* @param data
|
|
6142
|
-
* @returns
|
|
6140
|
+
*
|
|
6141
|
+
* @param data
|
|
6142
|
+
* @returns
|
|
6143
6143
|
*/
|
|
6144
6144
|
async update(data) {
|
|
6145
6145
|
const where = this.buildWhere();
|
|
@@ -6254,8 +6254,8 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6254
6254
|
/**
|
|
6255
6255
|
* Deletes the first record matching the current query constraints and returns
|
|
6256
6256
|
* it as a hydrated model instance. Returns null when no record matches.
|
|
6257
|
-
*
|
|
6258
|
-
* @returns
|
|
6257
|
+
*
|
|
6258
|
+
* @returns
|
|
6259
6259
|
*/
|
|
6260
6260
|
async delete() {
|
|
6261
6261
|
const where = this.buildWhere();
|
|
@@ -6353,8 +6353,8 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6353
6353
|
}
|
|
6354
6354
|
/**
|
|
6355
6355
|
* Counts the number of records matching the current query constraints.
|
|
6356
|
-
*
|
|
6357
|
-
* @returns
|
|
6356
|
+
*
|
|
6357
|
+
* @returns
|
|
6358
6358
|
*/
|
|
6359
6359
|
async count() {
|
|
6360
6360
|
if (this.hasRelationFilters() && this.shouldUseCompatibilityRelationFallback()) return (await this.get()).all().length;
|
|
@@ -6392,15 +6392,24 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6392
6392
|
if (nextPayload[column.column] !== void 0 && nextPayload[column.column] !== null) continue;
|
|
6393
6393
|
if (column.default === "now()" || column.updatedAt) nextPayload[column.column] = now;
|
|
6394
6394
|
}
|
|
6395
|
-
return nextPayload;
|
|
6395
|
+
return this.castForPersistence(nextPayload);
|
|
6396
6396
|
});
|
|
6397
6397
|
}
|
|
6398
|
+
/**
|
|
6399
|
+
* Apply the model's persistence casts when a real model backs the query.
|
|
6400
|
+
*
|
|
6401
|
+
* @param payload
|
|
6402
|
+
* @returns
|
|
6403
|
+
*/
|
|
6404
|
+
castForPersistence(payload) {
|
|
6405
|
+
return typeof this.model.castAttributesForPersistence === "function" ? this.model.castAttributesForPersistence(payload) : payload;
|
|
6406
|
+
}
|
|
6398
6407
|
normalizeUpdatePayload(values) {
|
|
6399
6408
|
const metadata = this.model.getModelMetadata();
|
|
6400
6409
|
const nextPayload = { ...values };
|
|
6401
6410
|
const now = /* @__PURE__ */ new Date();
|
|
6402
6411
|
for (const column of metadata.timestampColumns ?? []) if (column.updatedAt) nextPayload[column.column] = now;
|
|
6403
|
-
return nextPayload;
|
|
6412
|
+
return this.castForPersistence(nextPayload);
|
|
6404
6413
|
}
|
|
6405
6414
|
resolveAffectedCount(result, fallback) {
|
|
6406
6415
|
if (typeof result === "number") return result;
|
|
@@ -6552,13 +6561,13 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6552
6561
|
return this;
|
|
6553
6562
|
}
|
|
6554
6563
|
/**
|
|
6555
|
-
* Paginates the query results and returns a LengthAwarePaginator instance
|
|
6564
|
+
* Paginates the query results and returns a LengthAwarePaginator instance
|
|
6556
6565
|
* containing data and total-aware pagination metadata.
|
|
6557
|
-
*
|
|
6558
|
-
* @param page
|
|
6559
|
-
* @param perPage
|
|
6566
|
+
*
|
|
6567
|
+
* @param page
|
|
6568
|
+
* @param perPage
|
|
6560
6569
|
* @param options
|
|
6561
|
-
* @returns
|
|
6570
|
+
* @returns
|
|
6562
6571
|
*/
|
|
6563
6572
|
async paginate(perPage = 15, page = void 0, options = {}) {
|
|
6564
6573
|
const currentPage = this.resolvePaginationPage(page, options);
|
|
@@ -6596,8 +6605,8 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6596
6605
|
}
|
|
6597
6606
|
/**
|
|
6598
6607
|
* Creates a clone of the current query builder instance with the same state.
|
|
6599
|
-
*
|
|
6600
|
-
* @returns
|
|
6608
|
+
*
|
|
6609
|
+
* @returns
|
|
6601
6610
|
*/
|
|
6602
6611
|
clone() {
|
|
6603
6612
|
const builder = new QueryBuilder(this.model, this.adapter);
|
|
@@ -6627,9 +6636,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6627
6636
|
}
|
|
6628
6637
|
/**
|
|
6629
6638
|
* Normalizes the input for eager loading relations into a consistent format.
|
|
6630
|
-
*
|
|
6631
|
-
* @param relations
|
|
6632
|
-
* @returns
|
|
6639
|
+
*
|
|
6640
|
+
* @param relations
|
|
6641
|
+
* @returns
|
|
6633
6642
|
*/
|
|
6634
6643
|
normalizeWith(relations) {
|
|
6635
6644
|
if (typeof relations === "string") return { [relations]: void 0 };
|
|
@@ -6818,7 +6827,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6818
6827
|
}
|
|
6819
6828
|
/**
|
|
6820
6829
|
* Attempts to build relation load plans for the adapter based on the eager loads specified in the query builder.
|
|
6821
|
-
*
|
|
6830
|
+
*
|
|
6822
6831
|
* @returns an array of RelationLoadPlan if successful, or null if the eager loads contain constraints that cannot be represented in a way compatible with adapter-based loading.
|
|
6823
6832
|
*/
|
|
6824
6833
|
tryBuildAdapterRelationLoadPlans() {
|
|
@@ -7286,10 +7295,10 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7286
7295
|
return deleted;
|
|
7287
7296
|
}
|
|
7288
7297
|
/**
|
|
7289
|
-
* Builds the where clause for the query, taking into account soft delete
|
|
7298
|
+
* Builds the where clause for the query, taking into account soft delete
|
|
7290
7299
|
* settings if applicable.
|
|
7291
|
-
*
|
|
7292
|
-
* @returns
|
|
7300
|
+
*
|
|
7301
|
+
* @returns
|
|
7293
7302
|
*/
|
|
7294
7303
|
buildWhere() {
|
|
7295
7304
|
const baseWhere = this.legacyWhere ?? this.toQuerySchemaWhere(this.queryWhere);
|
|
@@ -7302,14 +7311,14 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7302
7311
|
}
|
|
7303
7312
|
/**
|
|
7304
7313
|
* Builds the arguments for the findMany delegate method, including the where clause.
|
|
7305
|
-
*
|
|
7306
|
-
* @returns
|
|
7314
|
+
*
|
|
7315
|
+
* @returns
|
|
7307
7316
|
*/
|
|
7308
7317
|
/**
|
|
7309
|
-
* Resolves a unique where clause for update and delete operations.
|
|
7310
|
-
*
|
|
7311
|
-
* @param where
|
|
7312
|
-
* @returns
|
|
7318
|
+
* Resolves a unique where clause for update and delete operations.
|
|
7319
|
+
*
|
|
7320
|
+
* @param where
|
|
7321
|
+
* @returns
|
|
7313
7322
|
*/
|
|
7314
7323
|
async resolveUniqueWhere(where, failIfMissing = true) {
|
|
7315
7324
|
if (this.isUniqueWhere(where)) return where;
|
|
@@ -7340,11 +7349,11 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7340
7349
|
return { [primaryKey]: row[primaryKey] };
|
|
7341
7350
|
}
|
|
7342
7351
|
/**
|
|
7343
|
-
* Checks if the provided where clause is already a unique
|
|
7352
|
+
* Checks if the provided where clause is already a unique
|
|
7344
7353
|
* identifier (i.e., contains only an 'id' field).
|
|
7345
|
-
*
|
|
7346
|
-
* @param where
|
|
7347
|
-
* @returns
|
|
7354
|
+
*
|
|
7355
|
+
* @param where
|
|
7356
|
+
* @returns
|
|
7348
7357
|
*/
|
|
7349
7358
|
isUniqueWhere(where) {
|
|
7350
7359
|
const primaryKey = this.model.getPrimaryKey();
|
|
@@ -7614,10 +7623,10 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7614
7623
|
//#endregion
|
|
7615
7624
|
//#region src/Model.ts
|
|
7616
7625
|
/**
|
|
7617
|
-
* Base model class that all models should extend.
|
|
7618
|
-
*
|
|
7626
|
+
* Base model class that all models should extend.
|
|
7627
|
+
*
|
|
7619
7628
|
* @template TModel The type of the model extending this base class.
|
|
7620
|
-
*
|
|
7629
|
+
*
|
|
7621
7630
|
* @author Legacy (3m1n3nc3)
|
|
7622
7631
|
* @since 0.1.0
|
|
7623
7632
|
*/
|
|
@@ -7625,6 +7634,9 @@ var Model = class Model {
|
|
|
7625
7634
|
static {
|
|
7626
7635
|
this.lifecycleStates = /* @__PURE__ */ new WeakMap();
|
|
7627
7636
|
}
|
|
7637
|
+
static {
|
|
7638
|
+
this.castMapCache = /* @__PURE__ */ new WeakMap();
|
|
7639
|
+
}
|
|
7628
7640
|
static {
|
|
7629
7641
|
this.emittedDeprecationWarnings = /* @__PURE__ */ new Set();
|
|
7630
7642
|
}
|
|
@@ -7763,6 +7775,31 @@ var Model = class Model {
|
|
|
7763
7775
|
timestampColumns: persistedMetadata.timestampColumns?.map((column) => ({ ...column }))
|
|
7764
7776
|
};
|
|
7765
7777
|
}
|
|
7778
|
+
/**
|
|
7779
|
+
* The model's cast map. Resolved from a throwaway instance (casts are an
|
|
7780
|
+
* instance field) and cached per model class.
|
|
7781
|
+
*/
|
|
7782
|
+
static getCasts() {
|
|
7783
|
+
const cached = Model.castMapCache.get(this);
|
|
7784
|
+
if (cached) return cached;
|
|
7785
|
+
const casts = { ...new this({}).casts };
|
|
7786
|
+
Model.castMapCache.set(this, casts);
|
|
7787
|
+
return casts;
|
|
7788
|
+
}
|
|
7789
|
+
/**
|
|
7790
|
+
* Apply built-in persistence casts (currently `json` serialisation) to a raw
|
|
7791
|
+
* attribute payload, without re-running arbitrary custom setters. Used by
|
|
7792
|
+
* both instance `save()` and the query-builder insert/update paths so a JS
|
|
7793
|
+
* object/array destined for a `json`/`jsonb` column is serialised to a string
|
|
7794
|
+
* rather than bound as a Postgres array.
|
|
7795
|
+
*/
|
|
7796
|
+
static castAttributesForPersistence(attributes) {
|
|
7797
|
+
const casts = this.getCasts();
|
|
7798
|
+
return Object.entries(attributes).reduce((normalized, [key, value]) => {
|
|
7799
|
+
normalized[key] = casts[key] === "json" ? resolveCast("json").set(value) : value;
|
|
7800
|
+
return normalized;
|
|
7801
|
+
}, {});
|
|
7802
|
+
}
|
|
7766
7803
|
static getRelationMetadata(name) {
|
|
7767
7804
|
const resolver = this.prototype[name];
|
|
7768
7805
|
if (typeof resolver !== "function") return null;
|
|
@@ -7940,9 +7977,9 @@ var Model = class Model {
|
|
|
7940
7977
|
* If a delegate name is provided, it will attempt to resolve that delegate.
|
|
7941
7978
|
* Otherwise, it will attempt to resolve a compatibility schema based on the model's name or
|
|
7942
7979
|
* the static `delegate` property.
|
|
7943
|
-
*
|
|
7944
|
-
* @param delegate
|
|
7945
|
-
* @returns
|
|
7980
|
+
*
|
|
7981
|
+
* @param delegate
|
|
7982
|
+
* @returns
|
|
7946
7983
|
*/
|
|
7947
7984
|
static getDelegate(delegate) {
|
|
7948
7985
|
Model.emitDeprecationWarning("ARKORM_GET_DELEGATE_DEPRECATED", "Model.getDelegate() is deprecated and will be removed in Arkorm 3.0. Use Model.getAdapter() and adapter-backed execution instead.");
|
|
@@ -7964,9 +8001,9 @@ var Model = class Model {
|
|
|
7964
8001
|
}
|
|
7965
8002
|
/**
|
|
7966
8003
|
* Get a new query builder instance for the model.
|
|
7967
|
-
*
|
|
7968
|
-
* @param this
|
|
7969
|
-
* @returns
|
|
8004
|
+
*
|
|
8005
|
+
* @param this
|
|
8006
|
+
* @returns
|
|
7970
8007
|
*/
|
|
7971
8008
|
static query() {
|
|
7972
8009
|
Model.ensureModelBooted(this);
|
|
@@ -7992,31 +8029,31 @@ var Model = class Model {
|
|
|
7992
8029
|
static booted() {}
|
|
7993
8030
|
/**
|
|
7994
8031
|
* Get a query builder instance that includes soft-deleted records.
|
|
7995
|
-
*
|
|
7996
|
-
* @param this
|
|
7997
|
-
* @returns
|
|
8032
|
+
*
|
|
8033
|
+
* @param this
|
|
8034
|
+
* @returns
|
|
7998
8035
|
*/
|
|
7999
8036
|
static withTrashed() {
|
|
8000
8037
|
return this.query().withTrashed();
|
|
8001
8038
|
}
|
|
8002
8039
|
/**
|
|
8003
8040
|
* Get a query builder instance that only includes soft-deleted records.
|
|
8004
|
-
*
|
|
8005
|
-
* @param this
|
|
8006
|
-
* @returns
|
|
8041
|
+
*
|
|
8042
|
+
* @param this
|
|
8043
|
+
* @returns
|
|
8007
8044
|
*/
|
|
8008
8045
|
static onlyTrashed() {
|
|
8009
8046
|
return this.query().onlyTrashed();
|
|
8010
8047
|
}
|
|
8011
8048
|
/**
|
|
8012
|
-
* Get a query builder instance that excludes soft-deleted records.
|
|
8013
|
-
* This is the default behavior of the query builder, but this method can be used
|
|
8049
|
+
* Get a query builder instance that excludes soft-deleted records.
|
|
8050
|
+
* This is the default behavior of the query builder, but this method can be used
|
|
8014
8051
|
* to explicitly specify it after using `withTrashed` or `onlyTrashed`.
|
|
8015
|
-
*
|
|
8016
|
-
* @param this
|
|
8017
|
-
* @param name
|
|
8018
|
-
* @param args
|
|
8019
|
-
* @returns
|
|
8052
|
+
*
|
|
8053
|
+
* @param this
|
|
8054
|
+
* @param name
|
|
8055
|
+
* @param args
|
|
8056
|
+
* @returns
|
|
8020
8057
|
*/
|
|
8021
8058
|
static scope(name, ...args) {
|
|
8022
8059
|
return this.query().scope(name, ...args);
|
|
@@ -8084,10 +8121,10 @@ var Model = class Model {
|
|
|
8084
8121
|
return deleted;
|
|
8085
8122
|
}
|
|
8086
8123
|
/**
|
|
8087
|
-
* Get the soft delete configuration for the model, including whether
|
|
8124
|
+
* Get the soft delete configuration for the model, including whether
|
|
8088
8125
|
* soft deletes are enabled and the name of the deleted at column.
|
|
8089
|
-
*
|
|
8090
|
-
* @returns
|
|
8126
|
+
*
|
|
8127
|
+
* @returns
|
|
8091
8128
|
*/
|
|
8092
8129
|
static getSoftDeleteConfig() {
|
|
8093
8130
|
return {
|
|
@@ -8096,11 +8133,11 @@ var Model = class Model {
|
|
|
8096
8133
|
};
|
|
8097
8134
|
}
|
|
8098
8135
|
/**
|
|
8099
|
-
* Hydrate a model instance from a plain object of attributes.
|
|
8100
|
-
*
|
|
8101
|
-
* @param this
|
|
8102
|
-
* @param attributes
|
|
8103
|
-
* @returns
|
|
8136
|
+
* Hydrate a model instance from a plain object of attributes.
|
|
8137
|
+
*
|
|
8138
|
+
* @param this
|
|
8139
|
+
* @param attributes
|
|
8140
|
+
* @returns
|
|
8104
8141
|
*/
|
|
8105
8142
|
static hydrate(attributes) {
|
|
8106
8143
|
const model = new this(attributes);
|
|
@@ -8111,10 +8148,10 @@ var Model = class Model {
|
|
|
8111
8148
|
}
|
|
8112
8149
|
/**
|
|
8113
8150
|
* Hydrate multiple model instances from an array of plain objects of attributes.
|
|
8114
|
-
*
|
|
8115
|
-
* @param this
|
|
8116
|
-
* @param attributes
|
|
8117
|
-
* @returns
|
|
8151
|
+
*
|
|
8152
|
+
* @param this
|
|
8153
|
+
* @param attributes
|
|
8154
|
+
* @returns
|
|
8118
8155
|
*/
|
|
8119
8156
|
static hydrateMany(attributes) {
|
|
8120
8157
|
const constructor = this;
|
|
@@ -8254,12 +8291,12 @@ var Model = class Model {
|
|
|
8254
8291
|
return await this.constructor.transaction(async () => await this.save());
|
|
8255
8292
|
}
|
|
8256
8293
|
/**
|
|
8257
|
-
* Delete the model from the database.
|
|
8258
|
-
* If soft deletes are enabled, it will perform a soft delete by
|
|
8259
|
-
* setting the deleted at column to the current date.
|
|
8294
|
+
* Delete the model from the database.
|
|
8295
|
+
* If soft deletes are enabled, it will perform a soft delete by
|
|
8296
|
+
* setting the deleted at column to the current date.
|
|
8260
8297
|
* Otherwise, it will perform a hard delete.
|
|
8261
|
-
*
|
|
8262
|
-
* @returns
|
|
8298
|
+
*
|
|
8299
|
+
* @returns
|
|
8263
8300
|
*/
|
|
8264
8301
|
async delete() {
|
|
8265
8302
|
const constructor = this.constructor;
|
|
@@ -8303,10 +8340,10 @@ var Model = class Model {
|
|
|
8303
8340
|
return await this.constructor.transaction(async () => await this.delete());
|
|
8304
8341
|
}
|
|
8305
8342
|
/**
|
|
8306
|
-
* Permanently delete the model from the database, regardless of whether soft
|
|
8343
|
+
* Permanently delete the model from the database, regardless of whether soft
|
|
8307
8344
|
* deletes are enabled.
|
|
8308
|
-
*
|
|
8309
|
-
* @returns
|
|
8345
|
+
*
|
|
8346
|
+
* @returns
|
|
8310
8347
|
*/
|
|
8311
8348
|
async forceDelete() {
|
|
8312
8349
|
const constructor = this.constructor;
|
|
@@ -8335,8 +8372,8 @@ var Model = class Model {
|
|
|
8335
8372
|
}
|
|
8336
8373
|
/**
|
|
8337
8374
|
* Restore a soft-deleted model by setting the deleted at column to null.
|
|
8338
|
-
*
|
|
8339
|
-
* @returns
|
|
8375
|
+
*
|
|
8376
|
+
* @returns
|
|
8340
8377
|
*/
|
|
8341
8378
|
async restore() {
|
|
8342
8379
|
const constructor = this.constructor;
|
|
@@ -8364,9 +8401,9 @@ var Model = class Model {
|
|
|
8364
8401
|
}
|
|
8365
8402
|
/**
|
|
8366
8403
|
* Load related models onto the current model instance.
|
|
8367
|
-
*
|
|
8368
|
-
* @param relations
|
|
8369
|
-
* @returns
|
|
8404
|
+
*
|
|
8405
|
+
* @param relations
|
|
8406
|
+
* @returns
|
|
8370
8407
|
*/
|
|
8371
8408
|
async load(relations) {
|
|
8372
8409
|
const relationMap = this.normalizeRelationMap(relations);
|
|
@@ -8432,8 +8469,8 @@ var Model = class Model {
|
|
|
8432
8469
|
}
|
|
8433
8470
|
/**
|
|
8434
8471
|
* Get the raw attributes of the model without applying any mutators or casts.
|
|
8435
|
-
*
|
|
8436
|
-
* @returns
|
|
8472
|
+
*
|
|
8473
|
+
* @returns
|
|
8437
8474
|
*/
|
|
8438
8475
|
getRawAttributes() {
|
|
8439
8476
|
return { ...this.attributes };
|
|
@@ -8494,10 +8531,10 @@ var Model = class Model {
|
|
|
8494
8531
|
}, {});
|
|
8495
8532
|
}
|
|
8496
8533
|
/**
|
|
8497
|
-
* Convert the model instance to a plain object, applying visibility
|
|
8534
|
+
* Convert the model instance to a plain object, applying visibility
|
|
8498
8535
|
* rules, appends, and mutators.
|
|
8499
|
-
*
|
|
8500
|
-
* @returns
|
|
8536
|
+
*
|
|
8537
|
+
* @returns
|
|
8501
8538
|
*/
|
|
8502
8539
|
toObject() {
|
|
8503
8540
|
const object = (this.visible.length > 0 ? this.visible : Object.keys(this.attributes).filter((key) => !this.hidden.includes(key))).reduce((accumulator, key) => {
|
|
@@ -8513,8 +8550,8 @@ var Model = class Model {
|
|
|
8513
8550
|
}
|
|
8514
8551
|
/**
|
|
8515
8552
|
* Convert the model instance to JSON by first converting it to a plain object.
|
|
8516
|
-
*
|
|
8517
|
-
* @returns
|
|
8553
|
+
*
|
|
8554
|
+
* @returns
|
|
8518
8555
|
*/
|
|
8519
8556
|
toJSON() {
|
|
8520
8557
|
return this.toObject();
|
|
@@ -8563,11 +8600,11 @@ var Model = class Model {
|
|
|
8563
8600
|
}
|
|
8564
8601
|
/**
|
|
8565
8602
|
* Define a has one relationship.
|
|
8566
|
-
*
|
|
8567
|
-
* @param related
|
|
8568
|
-
* @param foreignKey
|
|
8569
|
-
* @param localKey
|
|
8570
|
-
* @returns
|
|
8603
|
+
*
|
|
8604
|
+
* @param related
|
|
8605
|
+
* @param foreignKey
|
|
8606
|
+
* @param localKey
|
|
8607
|
+
* @returns
|
|
8571
8608
|
*/
|
|
8572
8609
|
hasOne(related, foreignKey, localKey) {
|
|
8573
8610
|
const constructor = this.constructor;
|
|
@@ -8575,11 +8612,11 @@ var Model = class Model {
|
|
|
8575
8612
|
}
|
|
8576
8613
|
/**
|
|
8577
8614
|
* Define a has many relationship.
|
|
8578
|
-
*
|
|
8579
|
-
* @param related
|
|
8580
|
-
* @param foreignKey
|
|
8581
|
-
* @param localKey
|
|
8582
|
-
* @returns
|
|
8615
|
+
*
|
|
8616
|
+
* @param related
|
|
8617
|
+
* @param foreignKey
|
|
8618
|
+
* @param localKey
|
|
8619
|
+
* @returns
|
|
8583
8620
|
*/
|
|
8584
8621
|
hasMany(related, foreignKey, localKey) {
|
|
8585
8622
|
const constructor = this.constructor;
|
|
@@ -8587,25 +8624,25 @@ var Model = class Model {
|
|
|
8587
8624
|
}
|
|
8588
8625
|
/**
|
|
8589
8626
|
* Define a belongs to relationship.
|
|
8590
|
-
*
|
|
8591
|
-
* @param related
|
|
8592
|
-
* @param foreignKey
|
|
8593
|
-
* @param ownerKey
|
|
8594
|
-
* @returns
|
|
8627
|
+
*
|
|
8628
|
+
* @param related
|
|
8629
|
+
* @param foreignKey
|
|
8630
|
+
* @param ownerKey
|
|
8631
|
+
* @returns
|
|
8595
8632
|
*/
|
|
8596
8633
|
belongsTo(related, foreignKey, ownerKey) {
|
|
8597
8634
|
return new BelongsToRelation(this, related, foreignKey, ownerKey ?? related.getPrimaryKey());
|
|
8598
8635
|
}
|
|
8599
8636
|
/**
|
|
8600
8637
|
* Define a belongs to many relationship.
|
|
8601
|
-
*
|
|
8602
|
-
* @param related
|
|
8638
|
+
*
|
|
8639
|
+
* @param related
|
|
8603
8640
|
* @param throughTable
|
|
8604
|
-
* @param foreignPivotKey
|
|
8605
|
-
* @param relatedPivotKey
|
|
8606
|
-
* @param parentKey
|
|
8607
|
-
* @param relatedKey
|
|
8608
|
-
* @returns
|
|
8641
|
+
* @param foreignPivotKey
|
|
8642
|
+
* @param relatedPivotKey
|
|
8643
|
+
* @param parentKey
|
|
8644
|
+
* @param relatedKey
|
|
8645
|
+
* @returns
|
|
8609
8646
|
*/
|
|
8610
8647
|
belongsToMany(related, throughTable, foreignPivotKey, relatedPivotKey, parentKey, relatedKey) {
|
|
8611
8648
|
const constructor = this.constructor;
|
|
@@ -8613,14 +8650,14 @@ var Model = class Model {
|
|
|
8613
8650
|
}
|
|
8614
8651
|
/**
|
|
8615
8652
|
* Define a has one through relationship.
|
|
8616
|
-
*
|
|
8617
|
-
* @param related
|
|
8653
|
+
*
|
|
8654
|
+
* @param related
|
|
8618
8655
|
* @param throughTable
|
|
8619
|
-
* @param firstKey
|
|
8620
|
-
* @param secondKey
|
|
8621
|
-
* @param localKey
|
|
8622
|
-
* @param secondLocalKey
|
|
8623
|
-
* @returns
|
|
8656
|
+
* @param firstKey
|
|
8657
|
+
* @param secondKey
|
|
8658
|
+
* @param localKey
|
|
8659
|
+
* @param secondLocalKey
|
|
8660
|
+
* @returns
|
|
8624
8661
|
*/
|
|
8625
8662
|
hasOneThrough(related, throughTable, firstKey, secondKey, localKey, secondLocalKey = "id") {
|
|
8626
8663
|
const constructor = this.constructor;
|
|
@@ -8628,14 +8665,14 @@ var Model = class Model {
|
|
|
8628
8665
|
}
|
|
8629
8666
|
/**
|
|
8630
8667
|
* Define a has many through relationship.
|
|
8631
|
-
*
|
|
8632
|
-
* @param related
|
|
8668
|
+
*
|
|
8669
|
+
* @param related
|
|
8633
8670
|
* @param throughTable
|
|
8634
|
-
* @param firstKey
|
|
8635
|
-
* @param secondKey
|
|
8636
|
-
* @param localKey
|
|
8637
|
-
* @param secondLocalKey
|
|
8638
|
-
* @returns
|
|
8671
|
+
* @param firstKey
|
|
8672
|
+
* @param secondKey
|
|
8673
|
+
* @param localKey
|
|
8674
|
+
* @param secondLocalKey
|
|
8675
|
+
* @returns
|
|
8639
8676
|
*/
|
|
8640
8677
|
hasManyThrough(related, throughTable, firstKey, secondKey, localKey, secondLocalKey = "id") {
|
|
8641
8678
|
const constructor = this.constructor;
|
|
@@ -8643,13 +8680,13 @@ var Model = class Model {
|
|
|
8643
8680
|
}
|
|
8644
8681
|
/**
|
|
8645
8682
|
* Define a polymorphic one to one relationship.
|
|
8646
|
-
*
|
|
8647
|
-
* @param related
|
|
8683
|
+
*
|
|
8684
|
+
* @param related
|
|
8648
8685
|
* @param morphName
|
|
8649
8686
|
* @param idColumn
|
|
8650
8687
|
* @param typeColumn
|
|
8651
8688
|
* @param localKey
|
|
8652
|
-
* @returns
|
|
8689
|
+
* @returns
|
|
8653
8690
|
*/
|
|
8654
8691
|
morphOne(related, morphName, idColumn, typeColumn, localKey) {
|
|
8655
8692
|
const constructor = this.constructor;
|
|
@@ -8658,13 +8695,13 @@ var Model = class Model {
|
|
|
8658
8695
|
}
|
|
8659
8696
|
/**
|
|
8660
8697
|
* Define a polymorphic one to many relationship.
|
|
8661
|
-
*
|
|
8662
|
-
* @param related
|
|
8698
|
+
*
|
|
8699
|
+
* @param related
|
|
8663
8700
|
* @param morphName
|
|
8664
8701
|
* @param idColumn
|
|
8665
8702
|
* @param typeColumn
|
|
8666
8703
|
* @param localKey
|
|
8667
|
-
* @returns
|
|
8704
|
+
* @returns
|
|
8668
8705
|
*/
|
|
8669
8706
|
morphMany(related, morphName, idColumn, typeColumn, localKey) {
|
|
8670
8707
|
const constructor = this.constructor;
|
|
@@ -8679,7 +8716,7 @@ var Model = class Model {
|
|
|
8679
8716
|
}
|
|
8680
8717
|
/**
|
|
8681
8718
|
* Define a polymorphic many to many relationship.
|
|
8682
|
-
*
|
|
8719
|
+
*
|
|
8683
8720
|
* @param related
|
|
8684
8721
|
* @param morphName
|
|
8685
8722
|
* @param throughTable
|
|
@@ -8688,7 +8725,7 @@ var Model = class Model {
|
|
|
8688
8725
|
* @param relatedPivotKey
|
|
8689
8726
|
* @param parentKey
|
|
8690
8727
|
* @param relatedKey
|
|
8691
|
-
* @returns
|
|
8728
|
+
* @returns
|
|
8692
8729
|
*/
|
|
8693
8730
|
morphToMany(related, morphName, throughTable, foreignPivotKey, morphTypeColumn, relatedPivotKey, parentKey, relatedKey) {
|
|
8694
8731
|
const constructor = this.constructor;
|
|
@@ -8716,9 +8753,9 @@ var Model = class Model {
|
|
|
8716
8753
|
}
|
|
8717
8754
|
/**
|
|
8718
8755
|
* Resolve a get mutator method for a given attribute key, if it exists.
|
|
8719
|
-
*
|
|
8720
|
-
* @param key
|
|
8721
|
-
* @returns
|
|
8756
|
+
*
|
|
8757
|
+
* @param key
|
|
8758
|
+
* @returns
|
|
8722
8759
|
*/
|
|
8723
8760
|
resolveGetMutator(key) {
|
|
8724
8761
|
const methodName = `get${str(key).studly()}Attribute`;
|
|
@@ -8750,10 +8787,7 @@ var Model = class Model {
|
|
|
8750
8787
|
* @returns
|
|
8751
8788
|
*/
|
|
8752
8789
|
normalizePersistenceAttributes(attributes) {
|
|
8753
|
-
return
|
|
8754
|
-
normalized[key] = this.casts[key] === "json" ? resolveCast("json").set(value) : value;
|
|
8755
|
-
return normalized;
|
|
8756
|
-
}, {});
|
|
8790
|
+
return this.constructor.castAttributesForPersistence(attributes);
|
|
8757
8791
|
}
|
|
8758
8792
|
/**
|
|
8759
8793
|
* Normalize a key or key list for dirty/change lookups.
|
|
@@ -8785,9 +8819,9 @@ var Model = class Model {
|
|
|
8785
8819
|
}
|
|
8786
8820
|
/**
|
|
8787
8821
|
* Resolve a set mutator method for a given attribute key, if it exists.
|
|
8788
|
-
*
|
|
8789
|
-
* @param key
|
|
8790
|
-
* @returns
|
|
8822
|
+
*
|
|
8823
|
+
* @param key
|
|
8824
|
+
* @returns
|
|
8791
8825
|
*/
|
|
8792
8826
|
resolveSetMutator(key) {
|
|
8793
8827
|
const methodName = `set${str(key).studly()}Attribute`;
|
|
@@ -9014,9 +9048,9 @@ var Model = class Model {
|
|
|
9014
9048
|
}
|
|
9015
9049
|
/**
|
|
9016
9050
|
* Normalize the relation map for eager loading.
|
|
9017
|
-
*
|
|
9018
|
-
* @param relations
|
|
9019
|
-
* @returns
|
|
9051
|
+
*
|
|
9052
|
+
* @param relations
|
|
9053
|
+
* @returns
|
|
9020
9054
|
*/
|
|
9021
9055
|
normalizeRelationMap(relations) {
|
|
9022
9056
|
if (typeof relations === "string") return { [relations]: void 0 };
|
|
@@ -9034,9 +9068,9 @@ var Model = class Model {
|
|
|
9034
9068
|
//#endregion
|
|
9035
9069
|
//#region src/database/factories.ts
|
|
9036
9070
|
/**
|
|
9037
|
-
* Base class for defining model factories.
|
|
9071
|
+
* Base class for defining model factories.
|
|
9038
9072
|
* Not meant to be used directly.
|
|
9039
|
-
*
|
|
9073
|
+
*
|
|
9040
9074
|
* @template TModel The type of model the factory creates.
|
|
9041
9075
|
* @template TAttributes The type of attributes used to create the model.
|
|
9042
9076
|
* @author Legacy (3m1n3nc3)
|
|
@@ -9062,9 +9096,9 @@ var ModelFactory = class ModelFactory {
|
|
|
9062
9096
|
configure() {}
|
|
9063
9097
|
/**
|
|
9064
9098
|
* Set the number of models to create.
|
|
9065
|
-
*
|
|
9066
|
-
* @param amount
|
|
9067
|
-
* @returns
|
|
9099
|
+
*
|
|
9100
|
+
* @param amount
|
|
9101
|
+
* @returns
|
|
9068
9102
|
*/
|
|
9069
9103
|
count(amount) {
|
|
9070
9104
|
this.ensureConfigured();
|
|
@@ -9072,9 +9106,9 @@ var ModelFactory = class ModelFactory {
|
|
|
9072
9106
|
return this;
|
|
9073
9107
|
}
|
|
9074
9108
|
/**
|
|
9075
|
-
* Define a state transformation for the factory.
|
|
9109
|
+
* Define a state transformation for the factory.
|
|
9076
9110
|
* States are applied in the order they were defined.
|
|
9077
|
-
*
|
|
9111
|
+
*
|
|
9078
9112
|
* @param resolver A function that takes the current attributes and sequence number, and returns the transformed attributes.
|
|
9079
9113
|
* @returns The factory instance for chaining.
|
|
9080
9114
|
*/
|
|
@@ -9085,9 +9119,9 @@ var ModelFactory = class ModelFactory {
|
|
|
9085
9119
|
}
|
|
9086
9120
|
/**
|
|
9087
9121
|
* Register a callback that runs after a model is made.
|
|
9088
|
-
*
|
|
9089
|
-
* @param callback
|
|
9090
|
-
* @returns
|
|
9122
|
+
*
|
|
9123
|
+
* @param callback
|
|
9124
|
+
* @returns
|
|
9091
9125
|
*/
|
|
9092
9126
|
afterMaking(callback) {
|
|
9093
9127
|
this.ensureConfigured();
|
|
@@ -9096,9 +9130,9 @@ var ModelFactory = class ModelFactory {
|
|
|
9096
9130
|
}
|
|
9097
9131
|
/**
|
|
9098
9132
|
* Register a callback that runs after a model is persisted.
|
|
9099
|
-
*
|
|
9100
|
-
* @param callback
|
|
9101
|
-
* @returns
|
|
9133
|
+
*
|
|
9134
|
+
* @param callback
|
|
9135
|
+
* @returns
|
|
9102
9136
|
*/
|
|
9103
9137
|
afterCreating(callback) {
|
|
9104
9138
|
this.ensureConfigured();
|
|
@@ -9107,9 +9141,9 @@ var ModelFactory = class ModelFactory {
|
|
|
9107
9141
|
}
|
|
9108
9142
|
/**
|
|
9109
9143
|
* Create a new model instance without saving it to the database.
|
|
9110
|
-
*
|
|
9111
|
-
* @param overrides
|
|
9112
|
-
* @returns
|
|
9144
|
+
*
|
|
9145
|
+
* @param overrides
|
|
9146
|
+
* @returns
|
|
9113
9147
|
*/
|
|
9114
9148
|
make(overrides = {}) {
|
|
9115
9149
|
this.ensureConfigured();
|
|
@@ -9134,10 +9168,10 @@ var ModelFactory = class ModelFactory {
|
|
|
9134
9168
|
}
|
|
9135
9169
|
/**
|
|
9136
9170
|
* Create multiple model instances without saving them to the database.
|
|
9137
|
-
*
|
|
9138
|
-
* @param amount
|
|
9139
|
-
* @param overrides
|
|
9140
|
-
* @returns
|
|
9171
|
+
*
|
|
9172
|
+
* @param amount
|
|
9173
|
+
* @param overrides
|
|
9174
|
+
* @returns
|
|
9141
9175
|
*/
|
|
9142
9176
|
makeMany(amount = this.amount, overrides = {}) {
|
|
9143
9177
|
const total = Math.max(1, Math.floor(amount));
|
|
@@ -9159,19 +9193,19 @@ var ModelFactory = class ModelFactory {
|
|
|
9159
9193
|
}
|
|
9160
9194
|
/**
|
|
9161
9195
|
* Create a new model instance and save it to the database.
|
|
9162
|
-
*
|
|
9163
|
-
* @param overrides
|
|
9164
|
-
* @returns
|
|
9196
|
+
*
|
|
9197
|
+
* @param overrides
|
|
9198
|
+
* @returns
|
|
9165
9199
|
*/
|
|
9166
9200
|
async create(overrides = {}) {
|
|
9167
9201
|
return await this.createPersisted(overrides);
|
|
9168
9202
|
}
|
|
9169
9203
|
/**
|
|
9170
9204
|
* Create multiple model instances and save them to the database.
|
|
9171
|
-
*
|
|
9172
|
-
* @param amount
|
|
9173
|
-
* @param overrides
|
|
9174
|
-
* @returns
|
|
9205
|
+
*
|
|
9206
|
+
* @param amount
|
|
9207
|
+
* @param overrides
|
|
9208
|
+
* @returns
|
|
9175
9209
|
*/
|
|
9176
9210
|
async createMany(amount = this.amount, overrides = {}) {
|
|
9177
9211
|
this.ensureConfigured();
|
|
@@ -9182,10 +9216,10 @@ var ModelFactory = class ModelFactory {
|
|
|
9182
9216
|
}
|
|
9183
9217
|
/**
|
|
9184
9218
|
* Create related models through a has-one or has-many relationship.
|
|
9185
|
-
*
|
|
9186
|
-
* @param factory
|
|
9187
|
-
* @param relationship
|
|
9188
|
-
* @returns
|
|
9219
|
+
*
|
|
9220
|
+
* @param factory
|
|
9221
|
+
* @param relationship
|
|
9222
|
+
* @returns
|
|
9189
9223
|
*/
|
|
9190
9224
|
has(factory, relationship) {
|
|
9191
9225
|
this.ensureConfigured();
|
|
@@ -9197,10 +9231,10 @@ var ModelFactory = class ModelFactory {
|
|
|
9197
9231
|
}
|
|
9198
9232
|
/**
|
|
9199
9233
|
* Associate the created model with a parent model or factory.
|
|
9200
|
-
*
|
|
9201
|
-
* @param related
|
|
9202
|
-
* @param relationship
|
|
9203
|
-
* @returns
|
|
9234
|
+
*
|
|
9235
|
+
* @param related
|
|
9236
|
+
* @param relationship
|
|
9237
|
+
* @returns
|
|
9204
9238
|
*/
|
|
9205
9239
|
for(related, relationship) {
|
|
9206
9240
|
this.ensureConfigured();
|
|
@@ -9212,11 +9246,11 @@ var ModelFactory = class ModelFactory {
|
|
|
9212
9246
|
}
|
|
9213
9247
|
/**
|
|
9214
9248
|
* Create or reuse related models and attach them through a many-to-many relationship.
|
|
9215
|
-
*
|
|
9216
|
-
* @param related
|
|
9217
|
-
* @param pivot
|
|
9218
|
-
* @param relationship
|
|
9219
|
-
* @returns
|
|
9249
|
+
*
|
|
9250
|
+
* @param related
|
|
9251
|
+
* @param pivot
|
|
9252
|
+
* @param relationship
|
|
9253
|
+
* @returns
|
|
9220
9254
|
*/
|
|
9221
9255
|
hasAttached(related, pivot = {}, relationship) {
|
|
9222
9256
|
this.ensureConfigured();
|
|
@@ -9229,9 +9263,9 @@ var ModelFactory = class ModelFactory {
|
|
|
9229
9263
|
}
|
|
9230
9264
|
/**
|
|
9231
9265
|
* Reuse existing models when resolving factory-backed relationships.
|
|
9232
|
-
*
|
|
9233
|
-
* @param models
|
|
9234
|
-
* @returns
|
|
9266
|
+
*
|
|
9267
|
+
* @param models
|
|
9268
|
+
* @returns
|
|
9235
9269
|
*/
|
|
9236
9270
|
recycle(models) {
|
|
9237
9271
|
this.ensureConfigured();
|
|
@@ -9245,18 +9279,18 @@ var ModelFactory = class ModelFactory {
|
|
|
9245
9279
|
}
|
|
9246
9280
|
/**
|
|
9247
9281
|
* Get the model contgructor
|
|
9248
|
-
*
|
|
9249
|
-
* @returns
|
|
9282
|
+
*
|
|
9283
|
+
* @returns
|
|
9250
9284
|
*/
|
|
9251
9285
|
getModelConstructor() {
|
|
9252
9286
|
return this.model;
|
|
9253
9287
|
}
|
|
9254
9288
|
/**
|
|
9255
|
-
* Build the attributes for a model instance, applying the factory
|
|
9289
|
+
* Build the attributes for a model instance, applying the factory
|
|
9256
9290
|
* definition and any defined states, and merging in any overrides.
|
|
9257
|
-
*
|
|
9258
|
-
* @param overrides
|
|
9259
|
-
* @returns
|
|
9291
|
+
*
|
|
9292
|
+
* @param overrides
|
|
9293
|
+
* @returns
|
|
9260
9294
|
*/
|
|
9261
9295
|
buildAttributes(overrides) {
|
|
9262
9296
|
const sequence = this.sequence;
|
|
@@ -9427,11 +9461,11 @@ var ModelFactory = class ModelFactory {
|
|
|
9427
9461
|
}
|
|
9428
9462
|
};
|
|
9429
9463
|
/**
|
|
9430
|
-
* A helper class for defining factories using an inline definition
|
|
9464
|
+
* A helper class for defining factories using an inline definition
|
|
9431
9465
|
* function, without needing to create a separate factory class.
|
|
9432
|
-
*
|
|
9466
|
+
*
|
|
9433
9467
|
* @template TModel
|
|
9434
|
-
* @template TAttributes
|
|
9468
|
+
* @template TAttributes
|
|
9435
9469
|
* @author Legacy (3m1n3nc3)
|
|
9436
9470
|
* @since 0.1.0
|
|
9437
9471
|
*/
|
|
@@ -9447,7 +9481,7 @@ var InlineFactory = class extends ModelFactory {
|
|
|
9447
9481
|
};
|
|
9448
9482
|
/**
|
|
9449
9483
|
* Define a factory for a given model using an inline definition function.
|
|
9450
|
-
*
|
|
9484
|
+
*
|
|
9451
9485
|
* @template TModel The type of model the factory creates.
|
|
9452
9486
|
* @template TAttributes The type of attributes used to create the model.
|
|
9453
9487
|
* @param model The model constructor.
|
|
@@ -9580,10 +9614,10 @@ var DB = class DB {
|
|
|
9580
9614
|
//#endregion
|
|
9581
9615
|
//#region src/PivotModel.ts
|
|
9582
9616
|
/**
|
|
9583
|
-
* Base pivot class that all pivot models should extend.
|
|
9584
|
-
*
|
|
9617
|
+
* Base pivot class that all pivot models should extend.
|
|
9618
|
+
*
|
|
9585
9619
|
* @template TModel The type of the model extending this base class.
|
|
9586
|
-
*
|
|
9620
|
+
*
|
|
9587
9621
|
* @author Legacy (3m1n3nc3)
|
|
9588
9622
|
* @since 2.0.0-next.18
|
|
9589
9623
|
*/
|