arkormx 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-DbtnN_Yb.d.mts → index-BD0RC4Si.d.cts} +342 -89
- package/dist/{index-nSC0udqX.d.cts → index-Wg5flH28.d.mts} +342 -89
- package/dist/index.cjs +172 -44
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +172 -44
- 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-CRlJHS90.cjs → relationship-Cku0y1Mt.cjs} +274 -1
- package/dist/{relationship-CJaPnw92.mjs → relationship-DcvK5Xn-.mjs} +274 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as deletePersistedColumnMappingsState, $t as supportsDatabaseCreation, A as isDelegateLike, At as buildModelBlock, B as getRegisteredSeeders, Bt as findModelBlock, C as getRuntimeAdapter, Cn as resolveMigrationStateFilePath, Ct as applyMigrationToPrismaSchema, D as getRuntimePaginationURLDriverFactory, Dn as RuntimeModuleLoader, Dt as buildIndexLine, E as getRuntimePaginationCurrentPageResolver, En as writeAppliedMigrationsStateToStore, Et as buildFieldLine, F as runArkormTransaction, Ft as deriveRelationAlias, G as registerFactories, Gt as getMigrationPlan, H as loadMigrationsFrom, Ht as formatEnumDefaultValue, I as getRegisteredFactories, It as deriveRelationFieldName, J as registerPaths, Jt as resolveMigrationClassName, K as registerMigrations, Kt as pad, L as getRegisteredMigrations, Lt as deriveSingularFieldName, M as isTransactionCapableClient, Mn as ArkormCollection, Mt as createMigrationTimestamp, N as loadArkormConfig, Nn as ArkormException, Nt as deriveCollectionFieldName, O as getRuntimePrismaClient, On as UnsupportedAdapterFeatureException, Ot as buildInverseRelationLine, P as resetArkormRuntimeForTests, Pt as deriveInverseRelationAlias, Q as createEmptyPersistedColumnMappingsState, Qt as stripPrismaSchemaModelsAndEnums, R as getRegisteredModels, Rt as escapeRegex, S as getDefaultStubsPath, Sn as removeAppliedMigration, St as applyMigrationToDatabase, T as getRuntimeDebugHandler, Tn as writeAppliedMigrationsState, Tt as buildEnumBlock, U as loadModelsFrom, Ut as formatRelationAction, V as loadFactoriesFrom, Vt as formatDefaultValue, W as loadSeedersFrom, Wt as generateMigrationFile, X as resetRuntimeRegistryForTests, Xt as runMigrationWithPrisma, Y as registerSeeders, Yt as resolvePrismaType, Z as applyOperationsToPersistedColumnMappingsState, Zt as runPrismaCommand, _ as defineConfig, _n as isMigrationApplied, _t as applyAlterTableOperation, a as HasOneRelation, an as EnumBuilder, at as getPersistedTimestampColumns, b as getActiveTransactionAdapter, bn as readAppliedMigrationsState, bt as applyMigrationRollbackToDatabase, c as BelongsToRelation, cn as PrimaryKeyGenerationPlanner, ct as resetPersistedColumnMappingsCache, d as Relation, dn as computeMigrationChecksum, dt as syncPersistedColumnMappingsFromState, en as supportsDatabaseMigrationExecution, et as getPersistedColumnMap, f as LengthAwarePaginator, fn as createEmptyAppliedMigrationsState, ft as validatePersistedMetadataFeaturesForMigrations, g as configureArkormRuntime, gn as getLatestAppliedMigrations, gt as PRISMA_MODEL_REGEX, h as bindAdapterToModels, hn as getLastMigrationRun, ht as PRISMA_ENUM_REGEX, i as HasOneThroughRelation, in as SchemaBuilder, it as getPersistedTableMetadata, j as isQuerySchemaLike, jn as RelationResolutionException, jt as buildRelationLine, k as getUserConfig, kn as SetBasedEagerLoader, kt as buildMigrationSource, ln as buildMigrationIdentity, lt as resolveColumnMappingsFilePath, m as URLDriver, mn as findAppliedMigration, mt as PRISMA_ENUM_MEMBER_REGEX, n as MorphOneRelation, nn as toMigrationFileSlug, nt as getPersistedEnumTsType, o as HasManyThroughRelation, on as TableBuilder, ot as readPersistedColumnMappingsState, p as Paginator, pn as deleteAppliedMigrationsStateFromStore, pt as writePersistedColumnMappingsState, q as registerModels, qt as resolveEnumName, r as MorphManyRelation, rn as toModelName, rt as getPersistedPrimaryKeyGeneration, s as HasManyRelation, sn as ForeignKeyBuilder, st as rebuildPersistedColumnMappingsState, t as MorphToManyRelation, tn as supportsDatabaseReset, tt as getPersistedEnumMap, u as BelongsToManyRelation, un as buildMigrationRunId, ut as resolvePersistedMetadataFeatures, v as emitRuntimeDebugEvent, vn as markMigrationApplied, vt as applyCreateTableOperation, w as getRuntimeClient, wn as supportsDatabaseMigrationState, wt as applyOperationsToPrismaSchema, x as getActiveTransactionClient, xn as readAppliedMigrationsStateFromStore, xt as applyMigrationRollbackToPrismaSchema, y as ensureArkormConfigLoading, yn as markMigrationRun, yt as applyDropTableOperation, z as getRegisteredPaths, zt as findEnumBlock } from "./relationship-
|
|
1
|
+
import { $ as deletePersistedColumnMappingsState, $t as supportsDatabaseCreation, A as isDelegateLike, At as buildModelBlock, B as getRegisteredSeeders, Bt as findModelBlock, C as getRuntimeAdapter, Cn as resolveMigrationStateFilePath, Ct as applyMigrationToPrismaSchema, D as getRuntimePaginationURLDriverFactory, Dn as RuntimeModuleLoader, Dt as buildIndexLine, E as getRuntimePaginationCurrentPageResolver, En as writeAppliedMigrationsStateToStore, Et as buildFieldLine, F as runArkormTransaction, Ft as deriveRelationAlias, G as registerFactories, Gt as getMigrationPlan, H as loadMigrationsFrom, Ht as formatEnumDefaultValue, I as getRegisteredFactories, It as deriveRelationFieldName, J as registerPaths, Jt as resolveMigrationClassName, K as registerMigrations, Kt as pad, L as getRegisteredMigrations, Lt as deriveSingularFieldName, M as isTransactionCapableClient, Mn as ArkormCollection, Mt as createMigrationTimestamp, N as loadArkormConfig, Nn as ArkormException, Nt as deriveCollectionFieldName, O as getRuntimePrismaClient, On as UnsupportedAdapterFeatureException, Ot as buildInverseRelationLine, P as resetArkormRuntimeForTests, Pt as deriveInverseRelationAlias, Q as createEmptyPersistedColumnMappingsState, Qt as stripPrismaSchemaModelsAndEnums, R as getRegisteredModels, Rt as escapeRegex, S as getDefaultStubsPath, Sn as removeAppliedMigration, St as applyMigrationToDatabase, T as getRuntimeDebugHandler, Tn as writeAppliedMigrationsState, Tt as buildEnumBlock, U as loadModelsFrom, Ut as formatRelationAction, V as loadFactoriesFrom, Vt as formatDefaultValue, W as loadSeedersFrom, Wt as generateMigrationFile, X as resetRuntimeRegistryForTests, Xt as runMigrationWithPrisma, Y as registerSeeders, Yt as resolvePrismaType, Z as applyOperationsToPersistedColumnMappingsState, Zt as runPrismaCommand, _ as defineConfig, _n as isMigrationApplied, _t as applyAlterTableOperation, a as HasOneRelation, an as EnumBuilder, at as getPersistedTimestampColumns, b as getActiveTransactionAdapter, bn as readAppliedMigrationsState, bt as applyMigrationRollbackToDatabase, c as BelongsToRelation, cn as PrimaryKeyGenerationPlanner, ct as resetPersistedColumnMappingsCache, d as Relation, dn as computeMigrationChecksum, dt as syncPersistedColumnMappingsFromState, en as supportsDatabaseMigrationExecution, et as getPersistedColumnMap, f as LengthAwarePaginator, fn as createEmptyAppliedMigrationsState, ft as validatePersistedMetadataFeaturesForMigrations, g as configureArkormRuntime, gn as getLatestAppliedMigrations, gt as PRISMA_MODEL_REGEX, h as bindAdapterToModels, hn as getLastMigrationRun, ht as PRISMA_ENUM_REGEX, i as HasOneThroughRelation, in as SchemaBuilder, it as getPersistedTableMetadata, j as isQuerySchemaLike, jn as RelationResolutionException, jt as buildRelationLine, k as getUserConfig, kn as SetBasedEagerLoader, kt as buildMigrationSource, ln as buildMigrationIdentity, lt as resolveColumnMappingsFilePath, m as URLDriver, mn as findAppliedMigration, mt as PRISMA_ENUM_MEMBER_REGEX, n as MorphOneRelation, nn as toMigrationFileSlug, nt as getPersistedEnumTsType, o as HasManyThroughRelation, on as TableBuilder, ot as readPersistedColumnMappingsState, p as Paginator, pn as deleteAppliedMigrationsStateFromStore, pt as writePersistedColumnMappingsState, q as registerModels, qt as resolveEnumName, r as MorphManyRelation, rn as toModelName, rt as getPersistedPrimaryKeyGeneration, s as HasManyRelation, sn as ForeignKeyBuilder, st as rebuildPersistedColumnMappingsState, t as MorphToManyRelation, tn as supportsDatabaseReset, tt as getPersistedEnumMap, u as BelongsToManyRelation, un as buildMigrationRunId, ut as resolvePersistedMetadataFeatures, v as emitRuntimeDebugEvent, vn as markMigrationApplied, vt as applyCreateTableOperation, w as getRuntimeClient, wn as supportsDatabaseMigrationState, wt as applyOperationsToPrismaSchema, x as getActiveTransactionClient, xn as readAppliedMigrationsStateFromStore, xt as applyMigrationRollbackToPrismaSchema, y as ensureArkormConfigLoading, yn as markMigrationRun, yt as applyDropTableOperation, z as getRegisteredPaths, zt as findEnumBlock } from "./relationship-DcvK5Xn-.mjs";
|
|
2
2
|
import { Pool } from "pg";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import { createRequire } from "module";
|
|
@@ -4306,6 +4306,34 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4306
4306
|
return this.whereHas(relation, callback, "<", 1);
|
|
4307
4307
|
}
|
|
4308
4308
|
/**
|
|
4309
|
+
* Add a constrained polymorphic relationship has clause.
|
|
4310
|
+
*
|
|
4311
|
+
* The current relationship metadata does not expose morph-to targets yet, so
|
|
4312
|
+
* this method delegates to whereHas while preserving the forward-compatible
|
|
4313
|
+
* API shape.
|
|
4314
|
+
*
|
|
4315
|
+
* @param relation
|
|
4316
|
+
* @param types
|
|
4317
|
+
* @param callback
|
|
4318
|
+
* @param operator
|
|
4319
|
+
* @param count
|
|
4320
|
+
* @returns
|
|
4321
|
+
*/
|
|
4322
|
+
whereHasMorph(relation, types, callback, operator = ">=", count = 1) {
|
|
4323
|
+
return this.whereHas(relation, callback, operator, count);
|
|
4324
|
+
}
|
|
4325
|
+
/**
|
|
4326
|
+
* Add a constrained polymorphic relationship does-not-have clause.
|
|
4327
|
+
*
|
|
4328
|
+
* @param relation
|
|
4329
|
+
* @param types
|
|
4330
|
+
* @param callback
|
|
4331
|
+
* @returns
|
|
4332
|
+
*/
|
|
4333
|
+
whereDoesntHaveMorph(relation, types, callback) {
|
|
4334
|
+
return this.whereDoesntHave(relation, callback);
|
|
4335
|
+
}
|
|
4336
|
+
/**
|
|
4309
4337
|
* Add an OR constrained relationship does-not-have clause.
|
|
4310
4338
|
*
|
|
4311
4339
|
* @param relation
|
|
@@ -4322,13 +4350,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4322
4350
|
* @returns
|
|
4323
4351
|
*/
|
|
4324
4352
|
withCount(relations) {
|
|
4325
|
-
|
|
4326
|
-
this.relationAggregates.push({
|
|
4327
|
-
type: "count",
|
|
4328
|
-
relation
|
|
4329
|
-
});
|
|
4330
|
-
});
|
|
4331
|
-
return this;
|
|
4353
|
+
return this.withRelationAggregate("count", relations);
|
|
4332
4354
|
}
|
|
4333
4355
|
/**
|
|
4334
4356
|
* Add relationship existence aggregate attributes.
|
|
@@ -4337,13 +4359,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4337
4359
|
* @returns
|
|
4338
4360
|
*/
|
|
4339
4361
|
withExists(relations) {
|
|
4340
|
-
|
|
4341
|
-
this.relationAggregates.push({
|
|
4342
|
-
type: "exists",
|
|
4343
|
-
relation
|
|
4344
|
-
});
|
|
4345
|
-
});
|
|
4346
|
-
return this;
|
|
4362
|
+
return this.withRelationAggregate("exists", relations);
|
|
4347
4363
|
}
|
|
4348
4364
|
/**
|
|
4349
4365
|
* Add relationship sum aggregate attribute.
|
|
@@ -4353,12 +4369,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4353
4369
|
* @returns
|
|
4354
4370
|
*/
|
|
4355
4371
|
withSum(relation, column) {
|
|
4356
|
-
this.
|
|
4357
|
-
type: "sum",
|
|
4358
|
-
relation,
|
|
4359
|
-
column
|
|
4360
|
-
});
|
|
4361
|
-
return this;
|
|
4372
|
+
return this.withRelationAggregate("sum", relation, column);
|
|
4362
4373
|
}
|
|
4363
4374
|
/**
|
|
4364
4375
|
* Add relationship average aggregate attribute.
|
|
@@ -4368,12 +4379,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4368
4379
|
* @returns
|
|
4369
4380
|
*/
|
|
4370
4381
|
withAvg(relation, column) {
|
|
4371
|
-
this.
|
|
4372
|
-
type: "avg",
|
|
4373
|
-
relation,
|
|
4374
|
-
column
|
|
4375
|
-
});
|
|
4376
|
-
return this;
|
|
4382
|
+
return this.withRelationAggregate("avg", relation, column);
|
|
4377
4383
|
}
|
|
4378
4384
|
/**
|
|
4379
4385
|
* Add relationship minimum aggregate attribute.
|
|
@@ -4383,12 +4389,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4383
4389
|
* @returns
|
|
4384
4390
|
*/
|
|
4385
4391
|
withMin(relation, column) {
|
|
4386
|
-
this.
|
|
4387
|
-
type: "min",
|
|
4388
|
-
relation,
|
|
4389
|
-
column
|
|
4390
|
-
});
|
|
4391
|
-
return this;
|
|
4392
|
+
return this.withRelationAggregate("min", relation, column);
|
|
4392
4393
|
}
|
|
4393
4394
|
/**
|
|
4394
4395
|
* Add relationship maximum aggregate attribute.
|
|
@@ -4398,12 +4399,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
4398
4399
|
* @returns
|
|
4399
4400
|
*/
|
|
4400
4401
|
withMax(relation, column) {
|
|
4401
|
-
this.
|
|
4402
|
-
type: "max",
|
|
4403
|
-
relation,
|
|
4404
|
-
column
|
|
4405
|
-
});
|
|
4406
|
-
return this;
|
|
4402
|
+
return this.withRelationAggregate("max", relation, column);
|
|
4407
4403
|
}
|
|
4408
4404
|
/**
|
|
4409
4405
|
* Includes soft-deleted records in the query results.
|
|
@@ -5277,7 +5273,39 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5277
5273
|
accumulator[relation] = void 0;
|
|
5278
5274
|
return accumulator;
|
|
5279
5275
|
}, {});
|
|
5280
|
-
return relations
|
|
5276
|
+
return Object.entries(relations).reduce((normalized, [relation, constraint]) => {
|
|
5277
|
+
normalized[relation] = constraint === true ? void 0 : constraint;
|
|
5278
|
+
return normalized;
|
|
5279
|
+
}, {});
|
|
5280
|
+
}
|
|
5281
|
+
withRelationAggregate(type, relations, column) {
|
|
5282
|
+
this.normalizeRelationAggregateInput(relations).forEach((aggregate) => {
|
|
5283
|
+
this.relationAggregates.push({
|
|
5284
|
+
type,
|
|
5285
|
+
column,
|
|
5286
|
+
...aggregate
|
|
5287
|
+
});
|
|
5288
|
+
});
|
|
5289
|
+
return this;
|
|
5290
|
+
}
|
|
5291
|
+
normalizeRelationAggregateInput(relations) {
|
|
5292
|
+
if (typeof relations === "string") return [this.parseRelationAggregateName(relations)];
|
|
5293
|
+
if (Array.isArray(relations)) return relations.map((relation) => this.parseRelationAggregateName(relation));
|
|
5294
|
+
return Object.entries(relations).reduce((normalized, [name, value]) => {
|
|
5295
|
+
if (value === false || value === void 0) return normalized;
|
|
5296
|
+
const aggregate = this.parseRelationAggregateName(name);
|
|
5297
|
+
if (typeof value === "function") aggregate.callback = value;
|
|
5298
|
+
normalized.push(aggregate);
|
|
5299
|
+
return normalized;
|
|
5300
|
+
}, []);
|
|
5301
|
+
}
|
|
5302
|
+
parseRelationAggregateName(name) {
|
|
5303
|
+
const match = name.match(/^(.+?)\s+as\s+(.+)$/i);
|
|
5304
|
+
if (!match) return { relation: name };
|
|
5305
|
+
return {
|
|
5306
|
+
relation: match[1].trim(),
|
|
5307
|
+
alias: match[2].trim()
|
|
5308
|
+
};
|
|
5281
5309
|
}
|
|
5282
5310
|
buildQueryTarget() {
|
|
5283
5311
|
const metadata = this.model.getModelMetadata();
|
|
@@ -5989,7 +6017,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
5989
6017
|
return this.relationAggregates.some((aggregate) => {
|
|
5990
6018
|
const metadata = this.model.getRelationMetadata(aggregate.relation);
|
|
5991
6019
|
if (!this.isSqlRelationFeatureMetadata(metadata)) return false;
|
|
5992
|
-
return this.tryBuildRelationConstraintWhere(aggregate.relation) === null;
|
|
6020
|
+
return this.tryBuildRelationConstraintWhere(aggregate.relation, aggregate.callback) === null;
|
|
5993
6021
|
});
|
|
5994
6022
|
}
|
|
5995
6023
|
tryBuildRelationFilterSpecs() {
|
|
@@ -6014,7 +6042,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6014
6042
|
if (!specs) return null;
|
|
6015
6043
|
const metadata = this.model.getRelationMetadata(aggregate.relation);
|
|
6016
6044
|
if (!this.isSqlRelationFeatureMetadata(metadata)) return null;
|
|
6017
|
-
const where = this.tryBuildRelationConstraintWhere(aggregate.relation);
|
|
6045
|
+
const where = this.tryBuildRelationConstraintWhere(aggregate.relation, aggregate.callback);
|
|
6018
6046
|
if (where === null) return null;
|
|
6019
6047
|
specs.push({
|
|
6020
6048
|
relation: aggregate.relation,
|
|
@@ -6075,7 +6103,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6075
6103
|
const cache = relationCache ?? /* @__PURE__ */ new WeakMap();
|
|
6076
6104
|
await Promise.all(models.map(async (model) => {
|
|
6077
6105
|
for (const aggregate of this.relationAggregates) {
|
|
6078
|
-
const results = await this.resolveRelatedResults(model, aggregate.relation, cache);
|
|
6106
|
+
const results = await this.resolveRelatedResults(model, aggregate.relation, cache, aggregate.callback);
|
|
6079
6107
|
const list = Array.isArray(results) ? results : results ? [results] : [];
|
|
6080
6108
|
const attributeKey = this.buildAggregateAttributeKey(aggregate);
|
|
6081
6109
|
if (aggregate.type === "count") {
|
|
@@ -6170,6 +6198,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6170
6198
|
return left < right;
|
|
6171
6199
|
}
|
|
6172
6200
|
buildAggregateAttributeKey(aggregate) {
|
|
6201
|
+
if (aggregate.alias) return aggregate.alias;
|
|
6173
6202
|
const relationName = aggregate.relation;
|
|
6174
6203
|
if (aggregate.type === "count") return `${relationName}Count`;
|
|
6175
6204
|
if (aggregate.type === "exists") return `${relationName}Exists`;
|
|
@@ -7005,6 +7034,59 @@ var Model = class Model {
|
|
|
7005
7034
|
await this.constructor.query().with(relationMap).loadIntoModels([this]);
|
|
7006
7035
|
return this;
|
|
7007
7036
|
}
|
|
7037
|
+
/**
|
|
7038
|
+
* Load relationship count aggregates onto the current model instance.
|
|
7039
|
+
*
|
|
7040
|
+
* @param relations
|
|
7041
|
+
* @returns
|
|
7042
|
+
*/
|
|
7043
|
+
async loadCount(relations) {
|
|
7044
|
+
return this.loadAggregate("count", relations);
|
|
7045
|
+
}
|
|
7046
|
+
/**
|
|
7047
|
+
* Load relationship sum aggregates onto the current model instance.
|
|
7048
|
+
*
|
|
7049
|
+
* @param relations
|
|
7050
|
+
* @param column
|
|
7051
|
+
* @returns
|
|
7052
|
+
*/
|
|
7053
|
+
async loadSum(relations, column) {
|
|
7054
|
+
return this.loadAggregate("sum", relations, column);
|
|
7055
|
+
}
|
|
7056
|
+
/**
|
|
7057
|
+
* Load relations only when they are not already present on the model.
|
|
7058
|
+
*
|
|
7059
|
+
* @param relations
|
|
7060
|
+
* @returns
|
|
7061
|
+
*/
|
|
7062
|
+
async loadMissing(relations) {
|
|
7063
|
+
const relationMap = this.normalizeRelationMap(relations);
|
|
7064
|
+
const missing = Object.entries(relationMap).reduce((all, [relation, constraint]) => {
|
|
7065
|
+
const root = relation.split(".")[0];
|
|
7066
|
+
if (!Object.prototype.hasOwnProperty.call(this.attributes, root)) all[relation] = constraint;
|
|
7067
|
+
return all;
|
|
7068
|
+
}, {});
|
|
7069
|
+
if (Object.keys(missing).length === 0) return this;
|
|
7070
|
+
return this.load(missing);
|
|
7071
|
+
}
|
|
7072
|
+
/**
|
|
7073
|
+
* Load nested relations on a polymorphic relation result by model class name.
|
|
7074
|
+
*
|
|
7075
|
+
* @param relation
|
|
7076
|
+
* @param relationsByType
|
|
7077
|
+
* @returns
|
|
7078
|
+
*/
|
|
7079
|
+
async loadMorph(relation, relationsByType) {
|
|
7080
|
+
await this.loadMissing(relation);
|
|
7081
|
+
const value = this.getAttribute(relation);
|
|
7082
|
+
const related = value instanceof ArkormCollection ? value.all() : Array.isArray(value) ? value : value ? [value] : [];
|
|
7083
|
+
await Promise.all(related.map(async (model) => {
|
|
7084
|
+
if (!(model instanceof Model)) return;
|
|
7085
|
+
const relations = relationsByType[model.constructor.name];
|
|
7086
|
+
if (relations) await model.load(relations);
|
|
7087
|
+
}));
|
|
7088
|
+
return this;
|
|
7089
|
+
}
|
|
7008
7090
|
setLoadedRelation(name, value) {
|
|
7009
7091
|
this.attributes[name] = value;
|
|
7010
7092
|
return this;
|
|
@@ -7359,6 +7441,49 @@ var Model = class Model {
|
|
|
7359
7441
|
}
|
|
7360
7442
|
return false;
|
|
7361
7443
|
}
|
|
7444
|
+
static buildRelationAggregateAttributeKey(type, relation, column) {
|
|
7445
|
+
const { relation: relationName, alias } = Model.parseRelationAggregateName(relation);
|
|
7446
|
+
if (alias) return alias;
|
|
7447
|
+
if (type === "count") return `${relationName}Count`;
|
|
7448
|
+
if (type === "exists") return `${relationName}Exists`;
|
|
7449
|
+
const columnName = column ? `${column.charAt(0).toUpperCase()}${column.slice(1)}` : "";
|
|
7450
|
+
return `${relationName}${`${type.charAt(0).toUpperCase()}${type.slice(1)}`}${columnName}`;
|
|
7451
|
+
}
|
|
7452
|
+
static parseRelationAggregateName(name) {
|
|
7453
|
+
const match = name.match(/^(.+?)\s+as\s+(.+)$/i);
|
|
7454
|
+
if (!match) return { relation: name };
|
|
7455
|
+
return {
|
|
7456
|
+
relation: match[1].trim(),
|
|
7457
|
+
alias: match[2].trim()
|
|
7458
|
+
};
|
|
7459
|
+
}
|
|
7460
|
+
async loadAggregate(type, relations, column) {
|
|
7461
|
+
const normalized = this.normalizeRelationAggregateInput(relations);
|
|
7462
|
+
if (normalized.length === 0) return this;
|
|
7463
|
+
const constructor = this.constructor;
|
|
7464
|
+
const primaryKey = constructor.getPrimaryKey();
|
|
7465
|
+
const identifier = this.getAttribute(primaryKey);
|
|
7466
|
+
if (identifier == null) throw new ArkormException(primaryKey === "id" ? "Cannot load aggregates for a model without an id." : `Cannot load aggregates for a model without a [${primaryKey}] value.`);
|
|
7467
|
+
const query = constructor.query().where({ [primaryKey]: identifier });
|
|
7468
|
+
if (type === "count") query.withCount(relations);
|
|
7469
|
+
else query.withSum(relations, column);
|
|
7470
|
+
const aggregated = await query.first();
|
|
7471
|
+
if (!aggregated) return this;
|
|
7472
|
+
normalized.forEach((relation) => {
|
|
7473
|
+
const attribute = Model.buildRelationAggregateAttributeKey(type, relation, column);
|
|
7474
|
+
this.setAttribute(attribute, aggregated.getAttribute(attribute) ?? (type === "count" ? 0 : null));
|
|
7475
|
+
});
|
|
7476
|
+
return this;
|
|
7477
|
+
}
|
|
7478
|
+
normalizeRelationAggregateInput(relations) {
|
|
7479
|
+
if (typeof relations === "string") return [relations];
|
|
7480
|
+
if (Array.isArray(relations)) return relations;
|
|
7481
|
+
return Object.entries(relations).reduce((all, [relation, enabled]) => {
|
|
7482
|
+
if (enabled === false || enabled === void 0) return all;
|
|
7483
|
+
all.push(relation);
|
|
7484
|
+
return all;
|
|
7485
|
+
}, []);
|
|
7486
|
+
}
|
|
7362
7487
|
/**
|
|
7363
7488
|
* Sync the original snapshot to the model's current raw attributes.
|
|
7364
7489
|
*/
|
|
@@ -7483,7 +7608,10 @@ var Model = class Model {
|
|
|
7483
7608
|
accumulator[relation] = void 0;
|
|
7484
7609
|
return accumulator;
|
|
7485
7610
|
}, {});
|
|
7486
|
-
return relations
|
|
7611
|
+
return Object.entries(relations).reduce((all, [relation, constraint]) => {
|
|
7612
|
+
all[relation] = constraint === true ? void 0 : constraint;
|
|
7613
|
+
return all;
|
|
7614
|
+
}, {});
|
|
7487
7615
|
}
|
|
7488
7616
|
};
|
|
7489
7617
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_relationship = require('../relationship-
|
|
2
|
+
const require_relationship = require('../relationship-Cku0y1Mt.cjs');
|
|
3
3
|
|
|
4
4
|
exports.BelongsToManyRelation = require_relationship.BelongsToManyRelation;
|
|
5
5
|
exports.BelongsToRelation = require_relationship.BelongsToRelation;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $a as MorphToManyRelation, Qa as SetBasedEagerLoader, ao as HasManyRelation, co as BelongsToManyRelation, eo as MorphOneRelation, io as HasManyThroughRelation, lo as Relation, no as HasOneThroughRelation, oo as BelongsToRelation, ro as HasOneRelation, so as SingleResultRelation, to as MorphManyRelation, uo as RelationTableLoader } from "../index-BD0RC4Si.cjs";
|
|
2
2
|
export { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasManyThroughRelation, HasOneRelation, HasOneThroughRelation, MorphManyRelation, MorphOneRelation, MorphToManyRelation, Relation, RelationTableLoader, SetBasedEagerLoader, SingleResultRelation };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $a as MorphToManyRelation, Qa as SetBasedEagerLoader, ao as HasManyRelation, co as BelongsToManyRelation, eo as MorphOneRelation, io as HasManyThroughRelation, lo as Relation, no as HasOneThroughRelation, oo as BelongsToRelation, ro as HasOneRelation, so as SingleResultRelation, to as MorphManyRelation, uo as RelationTableLoader } from "../index-Wg5flH28.mjs";
|
|
2
2
|
export { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasManyThroughRelation, HasOneRelation, HasOneThroughRelation, MorphManyRelation, MorphOneRelation, MorphToManyRelation, Relation, RelationTableLoader, SetBasedEagerLoader, SingleResultRelation };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { An as RelationTableLoader, a as HasOneRelation, c as BelongsToRelation, d as Relation, i as HasOneThroughRelation, kn as SetBasedEagerLoader, l as SingleResultRelation, n as MorphOneRelation, o as HasManyThroughRelation, r as MorphManyRelation, s as HasManyRelation, t as MorphToManyRelation, u as BelongsToManyRelation } from "../relationship-
|
|
1
|
+
import { An as RelationTableLoader, a as HasOneRelation, c as BelongsToRelation, d as Relation, i as HasOneThroughRelation, kn as SetBasedEagerLoader, l as SingleResultRelation, n as MorphOneRelation, o as HasManyThroughRelation, r as MorphManyRelation, s as HasManyRelation, t as MorphToManyRelation, u as BelongsToManyRelation } from "../relationship-DcvK5Xn-.mjs";
|
|
2
2
|
|
|
3
3
|
export { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasManyThroughRelation, HasOneRelation, HasOneThroughRelation, MorphManyRelation, MorphOneRelation, MorphToManyRelation, Relation, RelationTableLoader, SetBasedEagerLoader, SingleResultRelation };
|