arkormx 2.0.0-next.25 → 2.0.0-next.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +11 -7
- package/dist/index.cjs +154 -92
- package/dist/index.d.cts +133 -81
- package/dist/index.d.mts +133 -81
- package/dist/index.mjs +149 -93
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1991,6 +1991,7 @@ let runtimePaginationURLDriverFactory;
|
|
|
1991
1991
|
let runtimePaginationCurrentPageResolver;
|
|
1992
1992
|
let runtimeDebugHandler;
|
|
1993
1993
|
const transactionClientStorage = new AsyncLocalStorage();
|
|
1994
|
+
const transactionAdapterStorage = new AsyncLocalStorage();
|
|
1994
1995
|
const defaultDebugHandler = (event) => {
|
|
1995
1996
|
const prefix = `[arkorm:${event.adapter}] ${event.operation}${event.target ? ` [${event.target}]` : ""}`;
|
|
1996
1997
|
const payload = {
|
|
@@ -2048,11 +2049,10 @@ const getUserConfig = (key) => {
|
|
|
2048
2049
|
return userConfig;
|
|
2049
2050
|
};
|
|
2050
2051
|
/**
|
|
2051
|
-
* Configure the ArkORM runtime with the provided
|
|
2052
|
-
*
|
|
2052
|
+
* Configure the ArkORM runtime with the provided runtime client resolver and
|
|
2053
|
+
* adapter-first options.
|
|
2053
2054
|
*
|
|
2054
2055
|
* @param prisma
|
|
2055
|
-
* @param mapping
|
|
2056
2056
|
*/
|
|
2057
2057
|
const configureArkormRuntime = (prisma, options = {}) => {
|
|
2058
2058
|
const nextConfig = {
|
|
@@ -2078,7 +2078,7 @@ const configureArkormRuntime = (prisma, options = {}) => {
|
|
|
2078
2078
|
});
|
|
2079
2079
|
};
|
|
2080
2080
|
/**
|
|
2081
|
-
* Resolve a
|
|
2081
|
+
* Resolve a runtime client instance from the provided resolver, which can be either
|
|
2082
2082
|
* a direct client instance or a function that returns a client instance.
|
|
2083
2083
|
*
|
|
2084
2084
|
* @param resolver
|
|
@@ -2171,13 +2171,13 @@ const emitRuntimeDebugEvent = (event) => {
|
|
|
2171
2171
|
getRuntimeDebugHandler()?.(event);
|
|
2172
2172
|
};
|
|
2173
2173
|
/**
|
|
2174
|
-
* Check if a given value
|
|
2174
|
+
* Check if a given value matches Arkorm's query-schema contract
|
|
2175
2175
|
* by verifying the presence of common delegate methods.
|
|
2176
2176
|
*
|
|
2177
2177
|
* @param value The value to check.
|
|
2178
|
-
* @returns True if the value
|
|
2178
|
+
* @returns True if the value matches the query-schema contract, false otherwise.
|
|
2179
2179
|
*/
|
|
2180
|
-
const
|
|
2180
|
+
const isQuerySchemaLike = (value) => {
|
|
2181
2181
|
if (!value || typeof value !== "object") return false;
|
|
2182
2182
|
const candidate = value;
|
|
2183
2183
|
return [
|
|
@@ -2189,6 +2189,10 @@ const isDelegateLike = (value) => {
|
|
|
2189
2189
|
"count"
|
|
2190
2190
|
].every((method) => typeof candidate[method] === "function");
|
|
2191
2191
|
};
|
|
2192
|
+
/**
|
|
2193
|
+
* @deprecated Use isQuerySchemaLike instead.
|
|
2194
|
+
*/
|
|
2195
|
+
const isDelegateLike = isQuerySchemaLike;
|
|
2192
2196
|
loadArkormConfig();
|
|
2193
2197
|
|
|
2194
2198
|
//#endregion
|
package/dist/index.cjs
CHANGED
|
@@ -2062,6 +2062,7 @@ let runtimePaginationURLDriverFactory;
|
|
|
2062
2062
|
let runtimePaginationCurrentPageResolver;
|
|
2063
2063
|
let runtimeDebugHandler;
|
|
2064
2064
|
const transactionClientStorage = new async_hooks.AsyncLocalStorage();
|
|
2065
|
+
const transactionAdapterStorage = new async_hooks.AsyncLocalStorage();
|
|
2065
2066
|
const defaultDebugHandler = (event) => {
|
|
2066
2067
|
const prefix = `[arkorm:${event.adapter}] ${event.operation}${event.target ? ` [${event.target}]` : ""}`;
|
|
2067
2068
|
const payload = {
|
|
@@ -2128,11 +2129,10 @@ const getUserConfig = (key) => {
|
|
|
2128
2129
|
return userConfig;
|
|
2129
2130
|
};
|
|
2130
2131
|
/**
|
|
2131
|
-
* Configure the ArkORM runtime with the provided
|
|
2132
|
-
*
|
|
2132
|
+
* Configure the ArkORM runtime with the provided runtime client resolver and
|
|
2133
|
+
* adapter-first options.
|
|
2133
2134
|
*
|
|
2134
2135
|
* @param prisma
|
|
2135
|
-
* @param mapping
|
|
2136
2136
|
*/
|
|
2137
2137
|
const configureArkormRuntime = (prisma, options = {}) => {
|
|
2138
2138
|
const nextConfig = {
|
|
@@ -2177,7 +2177,7 @@ const resetArkormRuntimeForTests = () => {
|
|
|
2177
2177
|
resetPersistedColumnMappingsCache();
|
|
2178
2178
|
};
|
|
2179
2179
|
/**
|
|
2180
|
-
* Resolve a
|
|
2180
|
+
* Resolve a runtime client instance from the provided resolver, which can be either
|
|
2181
2181
|
* a direct client instance or a function that returns a client instance.
|
|
2182
2182
|
*
|
|
2183
2183
|
* @param resolver
|
|
@@ -2274,33 +2274,55 @@ const getDefaultStubsPath = () => {
|
|
|
2274
2274
|
return resolveDefaultStubsPath();
|
|
2275
2275
|
};
|
|
2276
2276
|
/**
|
|
2277
|
-
* Get the runtime
|
|
2277
|
+
* Get the runtime compatibility client.
|
|
2278
2278
|
* This function will trigger the loading of the ArkORM configuration if
|
|
2279
2279
|
* it hasn't already been loaded.
|
|
2280
2280
|
*
|
|
2281
2281
|
* @returns
|
|
2282
2282
|
*/
|
|
2283
|
-
const
|
|
2283
|
+
const getRuntimeClient = () => {
|
|
2284
2284
|
const activeTransactionClient = transactionClientStorage.getStore();
|
|
2285
2285
|
if (activeTransactionClient) return activeTransactionClient;
|
|
2286
2286
|
if (!runtimeConfigLoaded) loadRuntimeConfigSync();
|
|
2287
2287
|
return resolveClient(runtimeClientResolver);
|
|
2288
2288
|
};
|
|
2289
|
+
/**
|
|
2290
|
+
* @deprecated Use getRuntimeClient instead.
|
|
2291
|
+
*/
|
|
2292
|
+
const getRuntimePrismaClient = getRuntimeClient;
|
|
2289
2293
|
const getRuntimeAdapter = () => {
|
|
2294
|
+
const activeTransactionAdapter = transactionAdapterStorage.getStore();
|
|
2295
|
+
if (activeTransactionAdapter) return activeTransactionAdapter;
|
|
2290
2296
|
if (!runtimeConfigLoaded) loadRuntimeConfigSync();
|
|
2291
2297
|
return runtimeAdapter;
|
|
2292
2298
|
};
|
|
2293
2299
|
const getActiveTransactionClient = () => {
|
|
2294
2300
|
return transactionClientStorage.getStore();
|
|
2295
2301
|
};
|
|
2302
|
+
const getActiveTransactionAdapter = () => {
|
|
2303
|
+
return transactionAdapterStorage.getStore();
|
|
2304
|
+
};
|
|
2296
2305
|
const isTransactionCapableClient = (value) => {
|
|
2297
2306
|
if (!value || typeof value !== "object") return false;
|
|
2298
2307
|
return typeof value.$transaction === "function";
|
|
2299
2308
|
};
|
|
2300
|
-
const runArkormTransaction = async (callback, options = {}) => {
|
|
2309
|
+
const runArkormTransaction = async (callback, options = {}, preferredAdapter) => {
|
|
2310
|
+
const activeTransactionAdapter = transactionAdapterStorage.getStore();
|
|
2301
2311
|
const activeTransactionClient = transactionClientStorage.getStore();
|
|
2302
|
-
if (activeTransactionClient) return await callback(
|
|
2303
|
-
|
|
2312
|
+
if (activeTransactionAdapter || activeTransactionClient) return await callback({
|
|
2313
|
+
adapter: activeTransactionAdapter,
|
|
2314
|
+
client: activeTransactionClient
|
|
2315
|
+
});
|
|
2316
|
+
const adapter = preferredAdapter ?? getRuntimeAdapter();
|
|
2317
|
+
if (adapter) return await adapter.transaction(async (transactionAdapter) => {
|
|
2318
|
+
return await transactionAdapterStorage.run(transactionAdapter, async () => {
|
|
2319
|
+
return await callback({
|
|
2320
|
+
adapter: transactionAdapter,
|
|
2321
|
+
client: transactionClientStorage.getStore()
|
|
2322
|
+
});
|
|
2323
|
+
});
|
|
2324
|
+
}, options);
|
|
2325
|
+
const client = getRuntimeClient();
|
|
2304
2326
|
if (!client) throw new ArkormException("Cannot start a transaction without a configured Prisma client.", {
|
|
2305
2327
|
code: "CLIENT_NOT_CONFIGURED",
|
|
2306
2328
|
operation: "transaction"
|
|
@@ -2311,7 +2333,7 @@ const runArkormTransaction = async (callback, options = {}) => {
|
|
|
2311
2333
|
});
|
|
2312
2334
|
return await client.$transaction(async (transactionClient) => {
|
|
2313
2335
|
return await transactionClientStorage.run(transactionClient, async () => {
|
|
2314
|
-
return await callback(transactionClient);
|
|
2336
|
+
return await callback({ client: transactionClient });
|
|
2315
2337
|
});
|
|
2316
2338
|
}, options);
|
|
2317
2339
|
};
|
|
@@ -2341,13 +2363,13 @@ const emitRuntimeDebugEvent = (event) => {
|
|
|
2341
2363
|
getRuntimeDebugHandler()?.(event);
|
|
2342
2364
|
};
|
|
2343
2365
|
/**
|
|
2344
|
-
* Check if a given value
|
|
2366
|
+
* Check if a given value matches Arkorm's query-schema contract
|
|
2345
2367
|
* by verifying the presence of common delegate methods.
|
|
2346
2368
|
*
|
|
2347
2369
|
* @param value The value to check.
|
|
2348
|
-
* @returns True if the value
|
|
2370
|
+
* @returns True if the value matches the query-schema contract, false otherwise.
|
|
2349
2371
|
*/
|
|
2350
|
-
const
|
|
2372
|
+
const isQuerySchemaLike = (value) => {
|
|
2351
2373
|
if (!value || typeof value !== "object") return false;
|
|
2352
2374
|
const candidate = value;
|
|
2353
2375
|
return [
|
|
@@ -2359,6 +2381,10 @@ const isDelegateLike = (value) => {
|
|
|
2359
2381
|
"count"
|
|
2360
2382
|
].every((method) => typeof candidate[method] === "function");
|
|
2361
2383
|
};
|
|
2384
|
+
/**
|
|
2385
|
+
* @deprecated Use isQuerySchemaLike instead.
|
|
2386
|
+
*/
|
|
2387
|
+
const isDelegateLike = isQuerySchemaLike;
|
|
2362
2388
|
loadArkormConfig();
|
|
2363
2389
|
|
|
2364
2390
|
//#endregion
|
|
@@ -3420,31 +3446,31 @@ var MissingDelegateException = class extends ArkormException {
|
|
|
3420
3446
|
//#endregion
|
|
3421
3447
|
//#region src/helpers/prisma.ts
|
|
3422
3448
|
/**
|
|
3423
|
-
*
|
|
3424
|
-
*
|
|
3449
|
+
* Compatibility-only helper that exposes Prisma query schemas as a plain object map.
|
|
3450
|
+
* It is retained for migration support and tests, not as a supported runtime bootstrap path.
|
|
3425
3451
|
*
|
|
3426
3452
|
* @deprecated Prefer createPrismaDatabaseAdapter(prisma) for runtime usage.
|
|
3427
3453
|
*
|
|
3428
3454
|
* @param prisma The Prisma client instance to adapt.
|
|
3429
3455
|
* @param mapping An optional mapping of Prisma delegate names to ArkORM delegate names.
|
|
3430
|
-
* @returns A record of adapted Prisma
|
|
3456
|
+
* @returns A record of adapted Prisma compatibility query schemas.
|
|
3431
3457
|
*/
|
|
3432
3458
|
function createPrismaAdapter(prisma) {
|
|
3433
3459
|
return Object.entries(prisma).reduce((accumulator, [key, value]) => {
|
|
3434
|
-
if (!
|
|
3460
|
+
if (!isQuerySchemaLike(value)) return accumulator;
|
|
3435
3461
|
accumulator[key] = value;
|
|
3436
3462
|
return accumulator;
|
|
3437
3463
|
}, {});
|
|
3438
3464
|
}
|
|
3439
3465
|
/**
|
|
3440
|
-
*
|
|
3466
|
+
* Compatibility-only helper for legacy delegate-map bootstrapping during migration.
|
|
3441
3467
|
*
|
|
3442
|
-
* @deprecated Prefer createPrismaDatabaseAdapter(prisma, mapping)
|
|
3443
|
-
*
|
|
3468
|
+
* @deprecated Prefer createPrismaDatabaseAdapter(prisma, mapping). Direct delegate-map
|
|
3469
|
+
* bootstrapping is no longer part of the supported runtime path.
|
|
3444
3470
|
*
|
|
3445
3471
|
* @param prisma The Prisma client instance.
|
|
3446
3472
|
* @param mapping Optional mapping of Arkormˣ delegate names to Prisma delegate names.
|
|
3447
|
-
* @returns A
|
|
3473
|
+
* @returns A compatibility map keyed by Arkormˣ query-schema names.
|
|
3448
3474
|
*/
|
|
3449
3475
|
function createPrismaDelegateMap(prisma, mapping = {}) {
|
|
3450
3476
|
const delegates = createPrismaAdapter(prisma);
|
|
@@ -5712,6 +5738,45 @@ const defineFactory = (model, definition) => {
|
|
|
5712
5738
|
return new InlineFactory(model, definition);
|
|
5713
5739
|
};
|
|
5714
5740
|
|
|
5741
|
+
//#endregion
|
|
5742
|
+
//#region src/helpers/runtime-compatibility.ts
|
|
5743
|
+
const isObjectLike = (value) => {
|
|
5744
|
+
return Boolean(value) && typeof value === "object";
|
|
5745
|
+
};
|
|
5746
|
+
const isCompatibilityClient = (value) => {
|
|
5747
|
+
return Boolean(value) && typeof value === "object";
|
|
5748
|
+
};
|
|
5749
|
+
const getCompatibilitySources = (preferredClient) => {
|
|
5750
|
+
const activeTransactionClient = getActiveTransactionClient();
|
|
5751
|
+
const runtimeClient = getRuntimeClient();
|
|
5752
|
+
return activeTransactionClient ? [
|
|
5753
|
+
activeTransactionClient,
|
|
5754
|
+
preferredClient,
|
|
5755
|
+
runtimeClient
|
|
5756
|
+
] : [preferredClient, runtimeClient];
|
|
5757
|
+
};
|
|
5758
|
+
const getRuntimeCompatibilityAdapter = (preferredClient) => {
|
|
5759
|
+
const client = getCompatibilitySources(preferredClient).find((source) => isCompatibilityClient(source));
|
|
5760
|
+
if (!client) return void 0;
|
|
5761
|
+
return createPrismaCompatibilityAdapter(client);
|
|
5762
|
+
};
|
|
5763
|
+
const resolveRuntimeCompatibilityQuerySchema = (candidates, preferredClient) => {
|
|
5764
|
+
return getCompatibilitySources(preferredClient).flatMap((source) => {
|
|
5765
|
+
if (!isObjectLike(source)) return [];
|
|
5766
|
+
return candidates.map((candidate) => source[candidate]);
|
|
5767
|
+
}).find((candidate) => isQuerySchemaLike(candidate));
|
|
5768
|
+
};
|
|
5769
|
+
const resolveRuntimeCompatibilityQuerySchemaOrThrow = (key, candidates, modelName, preferredClient) => {
|
|
5770
|
+
const resolved = resolveRuntimeCompatibilityQuerySchema(candidates, preferredClient);
|
|
5771
|
+
if (!resolved) throw new MissingDelegateException(`Database delegate [${key}] is not configured.`, {
|
|
5772
|
+
operation: "getDelegate",
|
|
5773
|
+
model: modelName,
|
|
5774
|
+
delegate: key,
|
|
5775
|
+
meta: { candidates }
|
|
5776
|
+
});
|
|
5777
|
+
return resolved;
|
|
5778
|
+
};
|
|
5779
|
+
|
|
5715
5780
|
//#endregion
|
|
5716
5781
|
//#region src/URLDriver.ts
|
|
5717
5782
|
/**
|
|
@@ -8764,14 +8829,6 @@ var QueryBuilder = class QueryBuilder {
|
|
|
8764
8829
|
|
|
8765
8830
|
//#endregion
|
|
8766
8831
|
//#region src/DB.ts
|
|
8767
|
-
const noopDelegate = {
|
|
8768
|
-
findMany: async () => [],
|
|
8769
|
-
findFirst: async () => null,
|
|
8770
|
-
create: async () => ({}),
|
|
8771
|
-
update: async () => ({}),
|
|
8772
|
-
delete: async () => ({}),
|
|
8773
|
-
count: async () => 0
|
|
8774
|
-
};
|
|
8775
8832
|
const defaultSoftDeleteConfig = {
|
|
8776
8833
|
enabled: false,
|
|
8777
8834
|
column: "deletedAt"
|
|
@@ -8786,12 +8843,10 @@ var DB = class DB {
|
|
|
8786
8843
|
this.adapter = adapter;
|
|
8787
8844
|
}
|
|
8788
8845
|
static getAdapter() {
|
|
8789
|
-
if (this.adapter) return this.adapter;
|
|
8790
8846
|
const runtimeAdapter = getRuntimeAdapter();
|
|
8791
8847
|
if (runtimeAdapter) return runtimeAdapter;
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
return createPrismaCompatibilityAdapter(client);
|
|
8848
|
+
if (this.adapter) return this.adapter;
|
|
8849
|
+
return getRuntimeCompatibilityAdapter();
|
|
8795
8850
|
}
|
|
8796
8851
|
getAdapter() {
|
|
8797
8852
|
return this.scopedAdapter ?? DB.getAdapter();
|
|
@@ -8850,7 +8905,6 @@ var DB = class DB {
|
|
|
8850
8905
|
getAdapter: () => resolvedAdapter,
|
|
8851
8906
|
getColumnMap: () => ({ ...columns }),
|
|
8852
8907
|
getColumnName: (attribute) => columns[attribute] ?? attribute,
|
|
8853
|
-
getDelegate: () => noopDelegate,
|
|
8854
8908
|
getModelMetadata: () => buildMetadata(),
|
|
8855
8909
|
getPrimaryKey: () => primaryKey,
|
|
8856
8910
|
getRelationMetadata: () => null,
|
|
@@ -9133,11 +9187,11 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
9133
9187
|
pivotWhere;
|
|
9134
9188
|
pivotModel;
|
|
9135
9189
|
shouldAttachPivot = false;
|
|
9136
|
-
constructor(parent, related,
|
|
9190
|
+
constructor(parent, related, throughTable, foreignPivotKey, relatedPivotKey, parentKey, relatedKey) {
|
|
9137
9191
|
super();
|
|
9138
9192
|
this.parent = parent;
|
|
9139
9193
|
this.related = related;
|
|
9140
|
-
this.
|
|
9194
|
+
this.throughTable = throughTable;
|
|
9141
9195
|
this.foreignPivotKey = foreignPivotKey;
|
|
9142
9196
|
this.relatedPivotKey = relatedPivotKey;
|
|
9143
9197
|
this.parentKey = parentKey;
|
|
@@ -9305,7 +9359,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
9305
9359
|
}
|
|
9306
9360
|
buildPivotTarget() {
|
|
9307
9361
|
return {
|
|
9308
|
-
table: this.
|
|
9362
|
+
table: this.throughTable,
|
|
9309
9363
|
primaryKey: this.relatedPivotKey
|
|
9310
9364
|
};
|
|
9311
9365
|
}
|
|
@@ -9661,7 +9715,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
9661
9715
|
async loadPivotRowsForParent() {
|
|
9662
9716
|
const parentValue = this.resolveParentPivotValue();
|
|
9663
9717
|
return await this.createRelationTableLoader().selectRows({
|
|
9664
|
-
table: this.
|
|
9718
|
+
table: this.throughTable,
|
|
9665
9719
|
where: this.buildPivotWhere(parentValue),
|
|
9666
9720
|
columns: this.getPivotColumnSelection().map((column) => ({ column }))
|
|
9667
9721
|
});
|
|
@@ -9681,7 +9735,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
9681
9735
|
return {
|
|
9682
9736
|
type: "belongsToMany",
|
|
9683
9737
|
relatedModel: this.related,
|
|
9684
|
-
throughTable: this.
|
|
9738
|
+
throughTable: this.throughTable,
|
|
9685
9739
|
foreignPivotKey: this.foreignPivotKey,
|
|
9686
9740
|
relatedPivotKey: this.relatedPivotKey,
|
|
9687
9741
|
parentKey: this.parentKey,
|
|
@@ -9831,11 +9885,11 @@ var HasManyRelation = class extends Relation {
|
|
|
9831
9885
|
* @since 0.1.0
|
|
9832
9886
|
*/
|
|
9833
9887
|
var HasManyThroughRelation = class extends Relation {
|
|
9834
|
-
constructor(parent, related,
|
|
9888
|
+
constructor(parent, related, throughTable, firstKey, secondKey, localKey, secondLocalKey) {
|
|
9835
9889
|
super();
|
|
9836
9890
|
this.parent = parent;
|
|
9837
9891
|
this.related = related;
|
|
9838
|
-
this.
|
|
9892
|
+
this.throughTable = throughTable;
|
|
9839
9893
|
this.firstKey = firstKey;
|
|
9840
9894
|
this.secondKey = secondKey;
|
|
9841
9895
|
this.localKey = localKey;
|
|
@@ -9850,7 +9904,7 @@ var HasManyThroughRelation = class extends Relation {
|
|
|
9850
9904
|
const localValue = this.parent.getAttribute(this.localKey);
|
|
9851
9905
|
const keys = await this.createRelationTableLoader().selectColumnValues({
|
|
9852
9906
|
lookup: {
|
|
9853
|
-
table: this.
|
|
9907
|
+
table: this.throughTable,
|
|
9854
9908
|
where: {
|
|
9855
9909
|
type: "comparison",
|
|
9856
9910
|
column: this.firstKey,
|
|
@@ -9866,7 +9920,7 @@ var HasManyThroughRelation = class extends Relation {
|
|
|
9866
9920
|
return {
|
|
9867
9921
|
type: "hasManyThrough",
|
|
9868
9922
|
relatedModel: this.related,
|
|
9869
|
-
throughTable: this.
|
|
9923
|
+
throughTable: this.throughTable,
|
|
9870
9924
|
firstKey: this.firstKey,
|
|
9871
9925
|
secondKey: this.secondKey,
|
|
9872
9926
|
localKey: this.localKey,
|
|
@@ -9934,9 +9988,9 @@ var HasOneRelation = class extends SingleResultRelation {
|
|
|
9934
9988
|
* @since 0.1.0
|
|
9935
9989
|
*/
|
|
9936
9990
|
var HasOneThroughRelation = class extends SingleResultRelation {
|
|
9937
|
-
constructor(parent, related,
|
|
9991
|
+
constructor(parent, related, throughTable, firstKey, secondKey, localKey, secondLocalKey) {
|
|
9938
9992
|
super(parent, related);
|
|
9939
|
-
this.
|
|
9993
|
+
this.throughTable = throughTable;
|
|
9940
9994
|
this.firstKey = firstKey;
|
|
9941
9995
|
this.secondKey = secondKey;
|
|
9942
9996
|
this.localKey = localKey;
|
|
@@ -9951,7 +10005,7 @@ var HasOneThroughRelation = class extends SingleResultRelation {
|
|
|
9951
10005
|
const localValue = this.parent.getAttribute(this.localKey);
|
|
9952
10006
|
const intermediateKey = await this.createRelationTableLoader().selectColumnValue({
|
|
9953
10007
|
lookup: {
|
|
9954
|
-
table: this.
|
|
10008
|
+
table: this.throughTable,
|
|
9955
10009
|
where: {
|
|
9956
10010
|
type: "comparison",
|
|
9957
10011
|
column: this.firstKey,
|
|
@@ -9968,7 +10022,7 @@ var HasOneThroughRelation = class extends SingleResultRelation {
|
|
|
9968
10022
|
return {
|
|
9969
10023
|
type: "hasOneThrough",
|
|
9970
10024
|
relatedModel: this.related,
|
|
9971
|
-
throughTable: this.
|
|
10025
|
+
throughTable: this.throughTable,
|
|
9972
10026
|
firstKey: this.firstKey,
|
|
9973
10027
|
secondKey: this.secondKey,
|
|
9974
10028
|
localKey: this.localKey,
|
|
@@ -10090,11 +10144,11 @@ var MorphOneRelation = class extends SingleResultRelation {
|
|
|
10090
10144
|
* @since 0.1.0
|
|
10091
10145
|
*/
|
|
10092
10146
|
var MorphToManyRelation = class extends Relation {
|
|
10093
|
-
constructor(parent, related,
|
|
10147
|
+
constructor(parent, related, throughTable, morphName, relatedPivotKey, parentKey, relatedKey) {
|
|
10094
10148
|
super();
|
|
10095
10149
|
this.parent = parent;
|
|
10096
10150
|
this.related = related;
|
|
10097
|
-
this.
|
|
10151
|
+
this.throughTable = throughTable;
|
|
10098
10152
|
this.morphName = morphName;
|
|
10099
10153
|
this.relatedPivotKey = relatedPivotKey;
|
|
10100
10154
|
this.parentKey = parentKey;
|
|
@@ -10110,7 +10164,7 @@ var MorphToManyRelation = class extends Relation {
|
|
|
10110
10164
|
const morphType = this.parent.constructor.name;
|
|
10111
10165
|
const ids = await this.createRelationTableLoader().selectColumnValues({
|
|
10112
10166
|
lookup: {
|
|
10113
|
-
table: this.
|
|
10167
|
+
table: this.throughTable,
|
|
10114
10168
|
where: {
|
|
10115
10169
|
type: "group",
|
|
10116
10170
|
operator: "and",
|
|
@@ -10135,7 +10189,7 @@ var MorphToManyRelation = class extends Relation {
|
|
|
10135
10189
|
return {
|
|
10136
10190
|
type: "morphToMany",
|
|
10137
10191
|
relatedModel: this.related,
|
|
10138
|
-
throughTable: this.
|
|
10192
|
+
throughTable: this.throughTable,
|
|
10139
10193
|
morphName: this.morphName,
|
|
10140
10194
|
morphIdColumn: `${this.morphName}Id`,
|
|
10141
10195
|
morphTypeColumn: `${this.morphName}Type`,
|
|
@@ -10170,7 +10224,14 @@ var Model = class Model {
|
|
|
10170
10224
|
static eventsSuppressed = 0;
|
|
10171
10225
|
static factoryClass;
|
|
10172
10226
|
static adapter;
|
|
10227
|
+
/**
|
|
10228
|
+
* Compatibility-only runtime state retained for 2.x transition window.
|
|
10229
|
+
* New setups should use adapter-first setup via `setAdapter(...)` or runtime config.
|
|
10230
|
+
*/
|
|
10173
10231
|
static client;
|
|
10232
|
+
/**
|
|
10233
|
+
* @deprecated Use `table` instead. This remains as a compatibility alias during the transition.
|
|
10234
|
+
*/
|
|
10174
10235
|
static delegate;
|
|
10175
10236
|
static table;
|
|
10176
10237
|
static primaryKey = "id";
|
|
@@ -10219,7 +10280,8 @@ var Model = class Model {
|
|
|
10219
10280
|
});
|
|
10220
10281
|
}
|
|
10221
10282
|
/**
|
|
10222
|
-
*
|
|
10283
|
+
* Compatibility-only runtime API retained for the 2.x transition window.
|
|
10284
|
+
* This is no longer part of the supported runtime bootstrap path.
|
|
10223
10285
|
*
|
|
10224
10286
|
* @deprecated Use Model.setAdapter(createPrismaDatabaseAdapter(...)) or another
|
|
10225
10287
|
* adapter-first bootstrap path instead.
|
|
@@ -10230,11 +10292,19 @@ var Model = class Model {
|
|
|
10230
10292
|
Model.emitDeprecationWarning("ARKORM_SET_CLIENT_DEPRECATED", "Model.setClient() is deprecated and will be removed in Arkorm 3.0. Use Model.setAdapter(createPrismaDatabaseAdapter(...)) or another adapter-first setup path instead.");
|
|
10231
10293
|
this.client = client;
|
|
10232
10294
|
}
|
|
10295
|
+
/**
|
|
10296
|
+
* Primary runtime API: bind an adapter directly to the model class.
|
|
10297
|
+
*/
|
|
10233
10298
|
static setAdapter(adapter) {
|
|
10234
10299
|
this.adapter = adapter;
|
|
10235
10300
|
}
|
|
10236
10301
|
static getTable() {
|
|
10237
|
-
|
|
10302
|
+
if (this.table) return this.table;
|
|
10303
|
+
if (this.delegate) {
|
|
10304
|
+
Model.emitDeprecationWarning("ARKORM_MODEL_DELEGATE_DEPRECATED", "Model.delegate is deprecated and will be removed in Arkorm 3.0. Use Model.table instead.");
|
|
10305
|
+
return this.delegate;
|
|
10306
|
+
}
|
|
10307
|
+
return `${(0, _h3ravel_support.str)(this.name).camel().plural()}`;
|
|
10238
10308
|
}
|
|
10239
10309
|
static getPrimaryKey() {
|
|
10240
10310
|
return this.primaryKey || "id";
|
|
@@ -10443,52 +10513,38 @@ var Model = class Model {
|
|
|
10443
10513
|
*/
|
|
10444
10514
|
static async transaction(callback, options = {}) {
|
|
10445
10515
|
ensureArkormConfigLoading();
|
|
10446
|
-
return await runArkormTransaction(async (
|
|
10447
|
-
return await callback(
|
|
10448
|
-
}, options);
|
|
10516
|
+
return await runArkormTransaction(async (context) => {
|
|
10517
|
+
return await callback(context);
|
|
10518
|
+
}, options, this.getAdapter());
|
|
10449
10519
|
}
|
|
10450
10520
|
/**
|
|
10451
|
-
*
|
|
10452
|
-
*
|
|
10453
|
-
*
|
|
10521
|
+
* Compatibility-only runtime API retained for 2.x migration support.
|
|
10522
|
+
* New runtime code should prefer `getAdapter()` and adapter-backed execution.
|
|
10523
|
+
*
|
|
10524
|
+
* If a delegate name is provided, it will attempt to resolve that delegate.
|
|
10525
|
+
* Otherwise, it will attempt to resolve a compatibility schema based on the model's name or
|
|
10454
10526
|
* the static `delegate` property.
|
|
10455
10527
|
*
|
|
10456
10528
|
* @param delegate
|
|
10457
10529
|
* @returns
|
|
10458
10530
|
*/
|
|
10459
10531
|
static getDelegate(delegate) {
|
|
10532
|
+
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.");
|
|
10460
10533
|
ensureArkormConfigLoading();
|
|
10461
10534
|
const key = delegate || this.delegate || this.getTable();
|
|
10462
|
-
|
|
10535
|
+
return resolveRuntimeCompatibilityQuerySchemaOrThrow(key, [
|
|
10463
10536
|
key,
|
|
10464
10537
|
`${(0, _h3ravel_support.str)(key).camel()}`,
|
|
10465
10538
|
`${(0, _h3ravel_support.str)(key).singular()}`,
|
|
10466
10539
|
`${(0, _h3ravel_support.str)(key).camel().singular()}`
|
|
10467
|
-
];
|
|
10468
|
-
const activeTransactionClient = getActiveTransactionClient();
|
|
10469
|
-
const runtimeClient = getRuntimePrismaClient();
|
|
10470
|
-
const sources = activeTransactionClient ? [
|
|
10471
|
-
activeTransactionClient,
|
|
10472
|
-
this.client,
|
|
10473
|
-
runtimeClient
|
|
10474
|
-
] : [this.client, runtimeClient];
|
|
10475
|
-
const resolved = candidates.flatMap((name) => sources.map((source) => source?.[name])).find((candidate) => isDelegateLike(candidate));
|
|
10476
|
-
if (!resolved) throw new MissingDelegateException(`Database delegate [${key}] is not configured.`, {
|
|
10477
|
-
operation: "getDelegate",
|
|
10478
|
-
model: this.name,
|
|
10479
|
-
delegate: key,
|
|
10480
|
-
meta: { candidates }
|
|
10481
|
-
});
|
|
10482
|
-
return resolved;
|
|
10540
|
+
], this.name, this.client);
|
|
10483
10541
|
}
|
|
10484
10542
|
static getAdapter() {
|
|
10485
10543
|
ensureArkormConfigLoading();
|
|
10486
|
-
if (this.adapter) return this.adapter;
|
|
10487
10544
|
const runtimeAdapter = getRuntimeAdapter();
|
|
10488
10545
|
if (runtimeAdapter) return runtimeAdapter;
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
return createPrismaCompatibilityAdapter(client);
|
|
10546
|
+
if (this.adapter) return this.adapter;
|
|
10547
|
+
return getRuntimeCompatibilityAdapter(this.client);
|
|
10492
10548
|
}
|
|
10493
10549
|
/**
|
|
10494
10550
|
* Get a new query builder instance for the model.
|
|
@@ -10948,46 +11004,46 @@ var Model = class Model {
|
|
|
10948
11004
|
* Define a belongs to many relationship.
|
|
10949
11005
|
*
|
|
10950
11006
|
* @param related
|
|
10951
|
-
* @param
|
|
11007
|
+
* @param throughTable
|
|
10952
11008
|
* @param foreignPivotKey
|
|
10953
11009
|
* @param relatedPivotKey
|
|
10954
11010
|
* @param parentKey
|
|
10955
11011
|
* @param relatedKey
|
|
10956
11012
|
* @returns
|
|
10957
11013
|
*/
|
|
10958
|
-
belongsToMany(related,
|
|
11014
|
+
belongsToMany(related, throughTable, foreignPivotKey, relatedPivotKey, parentKey, relatedKey) {
|
|
10959
11015
|
const constructor = this.constructor;
|
|
10960
|
-
return new BelongsToManyRelation(this, related,
|
|
11016
|
+
return new BelongsToManyRelation(this, related, throughTable, foreignPivotKey, relatedPivotKey, parentKey ?? constructor.getPrimaryKey(), relatedKey ?? related.getPrimaryKey());
|
|
10961
11017
|
}
|
|
10962
11018
|
/**
|
|
10963
11019
|
* Define a has one through relationship.
|
|
10964
11020
|
*
|
|
10965
11021
|
* @param related
|
|
10966
|
-
* @param
|
|
11022
|
+
* @param throughTable
|
|
10967
11023
|
* @param firstKey
|
|
10968
11024
|
* @param secondKey
|
|
10969
11025
|
* @param localKey
|
|
10970
11026
|
* @param secondLocalKey
|
|
10971
11027
|
* @returns
|
|
10972
11028
|
*/
|
|
10973
|
-
hasOneThrough(related,
|
|
11029
|
+
hasOneThrough(related, throughTable, firstKey, secondKey, localKey, secondLocalKey = "id") {
|
|
10974
11030
|
const constructor = this.constructor;
|
|
10975
|
-
return new HasOneThroughRelation(this, related,
|
|
11031
|
+
return new HasOneThroughRelation(this, related, throughTable, firstKey, secondKey, localKey ?? constructor.getPrimaryKey(), secondLocalKey);
|
|
10976
11032
|
}
|
|
10977
11033
|
/**
|
|
10978
11034
|
* Define a has many through relationship.
|
|
10979
11035
|
*
|
|
10980
11036
|
* @param related
|
|
10981
|
-
* @param
|
|
11037
|
+
* @param throughTable
|
|
10982
11038
|
* @param firstKey
|
|
10983
11039
|
* @param secondKey
|
|
10984
11040
|
* @param localKey
|
|
10985
11041
|
* @param secondLocalKey
|
|
10986
11042
|
* @returns
|
|
10987
11043
|
*/
|
|
10988
|
-
hasManyThrough(related,
|
|
11044
|
+
hasManyThrough(related, throughTable, firstKey, secondKey, localKey, secondLocalKey = "id") {
|
|
10989
11045
|
const constructor = this.constructor;
|
|
10990
|
-
return new HasManyThroughRelation(this, related,
|
|
11046
|
+
return new HasManyThroughRelation(this, related, throughTable, firstKey, secondKey, localKey ?? constructor.getPrimaryKey(), secondLocalKey);
|
|
10991
11047
|
}
|
|
10992
11048
|
/**
|
|
10993
11049
|
* Define a polymorphic one to one relationship.
|
|
@@ -11017,16 +11073,16 @@ var Model = class Model {
|
|
|
11017
11073
|
* Define a polymorphic many to many relationship.
|
|
11018
11074
|
*
|
|
11019
11075
|
* @param related
|
|
11020
|
-
* @param
|
|
11076
|
+
* @param throughTable
|
|
11021
11077
|
* @param morphName
|
|
11022
11078
|
* @param relatedPivotKey
|
|
11023
11079
|
* @param parentKey
|
|
11024
11080
|
* @param relatedKey
|
|
11025
11081
|
* @returns
|
|
11026
11082
|
*/
|
|
11027
|
-
morphToMany(related,
|
|
11083
|
+
morphToMany(related, throughTable, morphName, relatedPivotKey, parentKey, relatedKey) {
|
|
11028
11084
|
const constructor = this.constructor;
|
|
11029
|
-
return new MorphToManyRelation(this, related,
|
|
11085
|
+
return new MorphToManyRelation(this, related, throughTable, morphName, relatedPivotKey, parentKey ?? constructor.getPrimaryKey(), relatedKey ?? related.getPrimaryKey());
|
|
11030
11086
|
}
|
|
11031
11087
|
/**
|
|
11032
11088
|
* Resolve a get mutator method for a given attribute key, if it exists.
|
|
@@ -11388,6 +11444,7 @@ exports.formatDefaultValue = formatDefaultValue;
|
|
|
11388
11444
|
exports.formatEnumDefaultValue = formatEnumDefaultValue;
|
|
11389
11445
|
exports.formatRelationAction = formatRelationAction;
|
|
11390
11446
|
exports.generateMigrationFile = generateMigrationFile;
|
|
11447
|
+
exports.getActiveTransactionAdapter = getActiveTransactionAdapter;
|
|
11391
11448
|
exports.getActiveTransactionClient = getActiveTransactionClient;
|
|
11392
11449
|
exports.getDefaultStubsPath = getDefaultStubsPath;
|
|
11393
11450
|
exports.getLastMigrationRun = getLastMigrationRun;
|
|
@@ -11400,6 +11457,8 @@ exports.getPersistedPrimaryKeyGeneration = getPersistedPrimaryKeyGeneration;
|
|
|
11400
11457
|
exports.getPersistedTableMetadata = getPersistedTableMetadata;
|
|
11401
11458
|
exports.getPersistedTimestampColumns = getPersistedTimestampColumns;
|
|
11402
11459
|
exports.getRuntimeAdapter = getRuntimeAdapter;
|
|
11460
|
+
exports.getRuntimeClient = getRuntimeClient;
|
|
11461
|
+
exports.getRuntimeCompatibilityAdapter = getRuntimeCompatibilityAdapter;
|
|
11403
11462
|
exports.getRuntimeDebugHandler = getRuntimeDebugHandler;
|
|
11404
11463
|
exports.getRuntimePaginationCurrentPageResolver = getRuntimePaginationCurrentPageResolver;
|
|
11405
11464
|
exports.getRuntimePaginationURLDriverFactory = getRuntimePaginationURLDriverFactory;
|
|
@@ -11408,6 +11467,7 @@ exports.getUserConfig = getUserConfig;
|
|
|
11408
11467
|
exports.inferDelegateName = inferDelegateName;
|
|
11409
11468
|
exports.isDelegateLike = isDelegateLike;
|
|
11410
11469
|
exports.isMigrationApplied = isMigrationApplied;
|
|
11470
|
+
exports.isQuerySchemaLike = isQuerySchemaLike;
|
|
11411
11471
|
exports.isTransactionCapableClient = isTransactionCapableClient;
|
|
11412
11472
|
exports.loadArkormConfig = loadArkormConfig;
|
|
11413
11473
|
exports.markMigrationApplied = markMigrationApplied;
|
|
@@ -11427,6 +11487,8 @@ exports.resolveMigrationClassName = resolveMigrationClassName;
|
|
|
11427
11487
|
exports.resolveMigrationStateFilePath = resolveMigrationStateFilePath;
|
|
11428
11488
|
exports.resolvePersistedMetadataFeatures = resolvePersistedMetadataFeatures;
|
|
11429
11489
|
exports.resolvePrismaType = resolvePrismaType;
|
|
11490
|
+
exports.resolveRuntimeCompatibilityQuerySchema = resolveRuntimeCompatibilityQuerySchema;
|
|
11491
|
+
exports.resolveRuntimeCompatibilityQuerySchemaOrThrow = resolveRuntimeCompatibilityQuerySchemaOrThrow;
|
|
11430
11492
|
exports.runArkormTransaction = runArkormTransaction;
|
|
11431
11493
|
exports.runMigrationWithPrisma = runMigrationWithPrisma;
|
|
11432
11494
|
exports.runPrismaCommand = runPrismaCommand;
|