@prisma/orm-family-sql 8.0.0-rc.18-dev.4 → 8.0.0-rc.18-dev.5
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/builder.d.mts +1 -1
- package/dist/builder__runtime.d.mts +3 -3
- package/dist/builder__runtime.mjs +1 -1
- package/dist/builder__types.d.mts +3 -2
- package/dist/collection-methods-BnR4UjcW-tiz3frtf.d.mts +77 -0
- package/dist/collection-methods-BnR4UjcW-tiz3frtf.d.mts.map +1 -0
- package/dist/collection-methods-DoBrRR69.d.mts +1 -0
- package/dist/{db-BmrN9nRS-DEogPltL.d.mts → db-BmrN9nRS-CDq1n2be.d.mts} +3 -2
- package/dist/db-BmrN9nRS-CDq1n2be.d.mts.map +1 -0
- package/dist/{index-qr6LA3dl.d.mts → index-CmKqLvvO.d.mts} +4 -4
- package/dist/{index-qr6LA3dl.d.mts.map → index-CmKqLvvO.d.mts.map} +1 -1
- package/dist/{index-reference-CflkzYSd.d.mts → index-reference-DJX-CNsb-D2qUlYq2.d.mts} +12 -3
- package/dist/index-reference-DJX-CNsb-D2qUlYq2.d.mts.map +1 -0
- package/dist/{index-reference-D693Lu-E.mjs → index-reference-DR62gjQS.mjs} +16 -3
- package/dist/index-reference-DR62gjQS.mjs.map +1 -0
- package/dist/index-reference-ZZrszBDq.d.mts +1 -0
- package/dist/orm-client.d.mts +55 -10
- package/dist/orm-client.d.mts.map +1 -1
- package/dist/orm-client.mjs +120 -2
- package/dist/orm-client.mjs.map +1 -1
- package/dist/{prepared-statement-Bs9TKj5u-CInk8vXF.d.mts → prepared-statement-BwHkxfuI-CKkkrS6r.d.mts} +9 -6
- package/dist/prepared-statement-BwHkxfuI-CKkkrS6r.d.mts.map +1 -0
- package/dist/{query-lane-context-C2AXsoFa-COSQOvZz.d.mts → query-lane-context-C42-u9L1-Bxa4DkI_.d.mts} +7 -2
- package/dist/query-lane-context-C42-u9L1-Bxa4DkI_.d.mts.map +1 -0
- package/dist/query-lane-context-DW5q2RAY.d.mts +1 -0
- package/dist/relational-core.d.mts +3 -3
- package/dist/relational-core__aggregate-descriptor-registry.d.mts +1 -1
- package/dist/relational-core__codec-descriptor-registry.d.mts +1 -1
- package/dist/relational-core__collection-methods.d.mts +3 -0
- package/dist/relational-core__collection-methods.mjs +1 -0
- package/dist/relational-core__index-reference.d.mts +3 -2
- package/dist/relational-core__index-reference.mjs +2 -2
- package/dist/relational-core__query-lane-context.d.mts +2 -2
- package/dist/relational-core__types.d.mts +2 -2
- package/dist/runtime.d.mts +3 -3
- package/dist/runtime.mjs +2 -1
- package/dist/runtime.mjs.map +1 -1
- package/dist/runtime__internal__prepared-query.d.mts +1 -1
- package/dist/types-BkA6tyT-.d.mts +1 -0
- package/dist/{types-D09NAayg-CNrpjo7Z.d.mts → types-Cl4MLNrS-lbf-K25i.d.mts} +3 -3
- package/dist/{types-D09NAayg-CNrpjo7Z.d.mts.map → types-Cl4MLNrS-lbf-K25i.d.mts.map} +1 -1
- package/package.json +19 -18
- package/dist/db-BmrN9nRS-DEogPltL.d.mts.map +0 -1
- package/dist/index-reference-CflkzYSd.d.mts.map +0 -1
- package/dist/index-reference-D693Lu-E.mjs.map +0 -1
- package/dist/prepared-statement-Bs9TKj5u-CInk8vXF.d.mts.map +0 -1
- package/dist/query-lane-context-BsZs5lvB.d.mts +0 -1
- package/dist/query-lane-context-C2AXsoFa-COSQOvZz.d.mts.map +0 -1
- package/dist/types-DAkmn9FV.d.mts +0 -1
package/dist/orm-client.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { C as lockStrengthCapabilities, S as lockOptionCapabilities, T as missin
|
|
|
6
6
|
import { a as isExpression, s as toExpr, t as ExpressionImpl } from "./expression-impl-B-XNINxr-vYwKVFeP.mjs";
|
|
7
7
|
import { n as codecRefForStorageColumn } from "./codec-descriptor-registry-CYK0Wzja.mjs";
|
|
8
8
|
import { t as createFunctions } from "./functions-0YWByawj.mjs";
|
|
9
|
-
import { t as createIndexReferences } from "./index-reference-
|
|
9
|
+
import { t as createIndexReferences } from "./index-reference-DR62gjQS.mjs";
|
|
10
10
|
import { o as settlementOf } from "./transaction-state-BfXhs7D7-3k10jZ8I.mjs";
|
|
11
11
|
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
12
12
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
@@ -2885,6 +2885,113 @@ function parseIncludePayload(value) {
|
|
|
2885
2885
|
return [];
|
|
2886
2886
|
}
|
|
2887
2887
|
}
|
|
2888
|
+
const tablesByContext = /* @__PURE__ */ new WeakMap();
|
|
2889
|
+
const NO_METHODS = Object.freeze({});
|
|
2890
|
+
function modelKey(namespaceId, modelName) {
|
|
2891
|
+
return JSON.stringify([namespaceId, modelName]);
|
|
2892
|
+
}
|
|
2893
|
+
function assertUniqueIds(contributions) {
|
|
2894
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2895
|
+
for (const { id } of contributions) {
|
|
2896
|
+
if (seen.has(id)) throw ormError("ORM.ARGUMENT_INVALID", `Two collection method contributions have the id "${id}".`, {
|
|
2897
|
+
why: "A contribution is registered under its id in CollectionMethodRegistry, so an id names one contribution.",
|
|
2898
|
+
fix: "List each extension once, or give one of the two contributions another id.",
|
|
2899
|
+
meta: { id }
|
|
2900
|
+
});
|
|
2901
|
+
seen.add(id);
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
function modelViews(context) {
|
|
2905
|
+
const { contract } = context;
|
|
2906
|
+
const views = [];
|
|
2907
|
+
for (const [namespaceId, namespace] of Object.entries(contract.domain.namespaces)) for (const [name, model] of Object.entries(namespace.models)) {
|
|
2908
|
+
const tableName = model.storage["table"];
|
|
2909
|
+
const resolved = typeof tableName === "string" ? resolveTableForContract(contract, namespaceId, tableName) : void 0;
|
|
2910
|
+
if (resolved === void 0) throw new InternalError(`Model "${name}" in namespace "${namespaceId}" has no storage table the contract declares.`);
|
|
2911
|
+
views.push([modelKey(namespaceId, name), {
|
|
2912
|
+
target: contract.target,
|
|
2913
|
+
name,
|
|
2914
|
+
fields: model.fields,
|
|
2915
|
+
relations: model.relations,
|
|
2916
|
+
table: resolved.table
|
|
2917
|
+
}]);
|
|
2918
|
+
}
|
|
2919
|
+
return views;
|
|
2920
|
+
}
|
|
2921
|
+
function methodsOf(contribution, view) {
|
|
2922
|
+
let methods;
|
|
2923
|
+
try {
|
|
2924
|
+
methods = contribution.methodsFor(view);
|
|
2925
|
+
} catch (cause) {
|
|
2926
|
+
throw ormError("ORM.ARGUMENT_INVALID", `Collection method contribution "${contribution.id}" failed for model "${view.name}".`, {
|
|
2927
|
+
why: "The ORM client asks every contribution for every model's methods when it is created.",
|
|
2928
|
+
fix: `Fix or remove the extension that contributes "${contribution.id}"; the cause is the contribution's own error.`,
|
|
2929
|
+
meta: {
|
|
2930
|
+
model: view.name,
|
|
2931
|
+
contribution: contribution.id
|
|
2932
|
+
},
|
|
2933
|
+
cause
|
|
2934
|
+
});
|
|
2935
|
+
}
|
|
2936
|
+
if (typeof methods !== "object" || methods === null) throw ormError("ORM.ARGUMENT_INVALID", `Collection method contribution "${contribution.id}" returned no object of methods for model "${view.name}".`, {
|
|
2937
|
+
why: "A contribution returns an object holding a model's methods by name, empty when it gives the model none.",
|
|
2938
|
+
fix: `Fix or remove the extension that contributes "${contribution.id}".`,
|
|
2939
|
+
meta: {
|
|
2940
|
+
model: view.name,
|
|
2941
|
+
contribution: contribution.id
|
|
2942
|
+
}
|
|
2943
|
+
});
|
|
2944
|
+
for (const [name, body] of Object.entries(methods)) if (typeof body !== "function") throw ormError("ORM.ARGUMENT_INVALID", `Collection method "${name}" that contribution "${contribution.id}" gives model "${view.name}" is not a function.`, {
|
|
2945
|
+
why: "A contribution returns each of a model's methods as a function of the collection and the caller's arguments.",
|
|
2946
|
+
fix: `Fix or remove the extension that contributes "${contribution.id}".`,
|
|
2947
|
+
meta: {
|
|
2948
|
+
model: view.name,
|
|
2949
|
+
method: name,
|
|
2950
|
+
contribution: contribution.id
|
|
2951
|
+
}
|
|
2952
|
+
});
|
|
2953
|
+
return blindCast(methods);
|
|
2954
|
+
}
|
|
2955
|
+
function mergedTable(view, contributions) {
|
|
2956
|
+
const methods = Object.create(null);
|
|
2957
|
+
const owners = /* @__PURE__ */ new Map();
|
|
2958
|
+
for (const contribution of contributions) for (const [name, body] of Object.entries(methodsOf(contribution, view))) {
|
|
2959
|
+
const owner = owners.get(name);
|
|
2960
|
+
if (owner !== void 0) throw ormError("ORM.ARGUMENT_INVALID", `Collection method "${name}" of model "${view.name}" is contributed by both "${owner}" and "${contribution.id}".`, {
|
|
2961
|
+
why: "A collection offers one method under each name in `using`.",
|
|
2962
|
+
fix: "Remove one of the extensions that contribute these methods.",
|
|
2963
|
+
meta: {
|
|
2964
|
+
model: view.name,
|
|
2965
|
+
method: name,
|
|
2966
|
+
contributions: [owner, contribution.id]
|
|
2967
|
+
}
|
|
2968
|
+
});
|
|
2969
|
+
owners.set(name, contribution.id);
|
|
2970
|
+
methods[name] = body;
|
|
2971
|
+
}
|
|
2972
|
+
return Object.freeze(methods);
|
|
2973
|
+
}
|
|
2974
|
+
/**
|
|
2975
|
+
* Asks each contribution for each model's methods, once per execution context. Throws `ORM.ARGUMENT_INVALID` when two contributions share an id, give one model two methods with the same name, fail, or return a method that is not a function.
|
|
2976
|
+
*/
|
|
2977
|
+
function collectionMethodTables(context) {
|
|
2978
|
+
const cached = tablesByContext.get(context);
|
|
2979
|
+
if (cached !== void 0) return cached;
|
|
2980
|
+
const contributions = context.collectionMethods ?? [];
|
|
2981
|
+
assertUniqueIds(contributions);
|
|
2982
|
+
const tables = /* @__PURE__ */ new Map();
|
|
2983
|
+
for (const [key, view] of modelViews(context)) tables.set(key, mergedTable(view, contributions));
|
|
2984
|
+
tablesByContext.set(context, tables);
|
|
2985
|
+
return tables;
|
|
2986
|
+
}
|
|
2987
|
+
/** The contributed methods of a model, by name. */
|
|
2988
|
+
function collectionMethodTable(context, namespaceId, modelName) {
|
|
2989
|
+
return collectionMethodTables(context).get(modelKey(namespaceId, modelName)) ?? NO_METHODS;
|
|
2990
|
+
}
|
|
2991
|
+
/** The run-time value of `collection.using`. */
|
|
2992
|
+
function createCollectionMethods(receiver, table) {
|
|
2993
|
+
return Object.freeze(Object.fromEntries(Object.entries(table).map(([name, body]) => [name, (...args) => body(receiver, ...args)])));
|
|
2994
|
+
}
|
|
2888
2995
|
/** The filter expression of a condition: a condition from `fns` becomes its AST. */
|
|
2889
2996
|
function conditionExpr(condition) {
|
|
2890
2997
|
return isFunctionCondition(condition) ? condition.buildAst() : condition;
|
|
@@ -3152,6 +3259,7 @@ function defineDeclaredFieldsFragment(declarations, body) {
|
|
|
3152
3259
|
});
|
|
3153
3260
|
}
|
|
3154
3261
|
const NO_INDEXES = Object.freeze({});
|
|
3262
|
+
const NO_COLLECTION_METHODS = Object.freeze({});
|
|
3155
3263
|
const collectionsBehindViews = /* @__PURE__ */ new WeakMap();
|
|
3156
3264
|
const BODY_CHAIN_METHODS = {
|
|
3157
3265
|
where: true,
|
|
@@ -3160,10 +3268,11 @@ const BODY_CHAIN_METHODS = {
|
|
|
3160
3268
|
offset: true
|
|
3161
3269
|
};
|
|
3162
3270
|
/**
|
|
3163
|
-
* The collection as the body of a fragment for any model sees it: a `where` or `orderBy` callback receives `fns` and an `indexes` with no members, as the body does not know its model.
|
|
3271
|
+
* The collection as the body of a fragment for any model sees it: a `where` or `orderBy` callback receives `fns` and an `indexes` with no members, and `using` has no members, as the body does not know its model.
|
|
3164
3272
|
*/
|
|
3165
3273
|
function withoutIndexes(collection) {
|
|
3166
3274
|
const view = new Proxy(collection, { get(target, prop) {
|
|
3275
|
+
if (prop === "using") return NO_COLLECTION_METHODS;
|
|
3167
3276
|
const member = Reflect.get(target, prop, target);
|
|
3168
3277
|
if (typeof member !== "function") return member;
|
|
3169
3278
|
if (!Object.hasOwn(BODY_CHAIN_METHODS, prop)) return member.bind(target);
|
|
@@ -5124,6 +5233,7 @@ var CollectionBase = class CollectionBase {
|
|
|
5124
5233
|
registry;
|
|
5125
5234
|
/** @internal */
|
|
5126
5235
|
includeRefinementMode;
|
|
5236
|
+
#using;
|
|
5127
5237
|
constructor(ctx, modelName, options) {
|
|
5128
5238
|
this.ctx = ctx;
|
|
5129
5239
|
this.contract = ctx.context.contract;
|
|
@@ -5189,6 +5299,13 @@ var CollectionBase = class CollectionBase {
|
|
|
5189
5299
|
filters: [...this.state.filters, filter]
|
|
5190
5300
|
});
|
|
5191
5301
|
}
|
|
5302
|
+
/**
|
|
5303
|
+
* The collection methods packages contribute for this model. Each contribution reads the model and names its methods. Each method returns this collection with the method's filter and order added.
|
|
5304
|
+
*/
|
|
5305
|
+
get using() {
|
|
5306
|
+
this.#using ??= createCollectionMethods(blindCast(this), collectionMethodTable(this.ctx.context, this.namespaceId, this.modelName));
|
|
5307
|
+
return blindCast(this.#using);
|
|
5308
|
+
}
|
|
5192
5309
|
whereUnique(criterion) {
|
|
5193
5310
|
if (this.includeRefinementMode) throw ormError("ORM.INCLUDE_INVALID", "whereUnique() is not available inside include() refinement callbacks", { meta: { action: "whereUnique()" } });
|
|
5194
5311
|
if (!hasCompleteUniqueKey(this.contract, this.namespaceId, this.modelName, criterion)) throw ormError("ORM.ARGUMENT_INVALID", `whereUnique() for model "${this.modelName}" needs a value for every field of the primary key or of one unique constraint`, { meta: {
|
|
@@ -5938,6 +6055,7 @@ function assertAggregateOperationsNotReserved(registry) {
|
|
|
5938
6055
|
function orm(options) {
|
|
5939
6056
|
const { runtime, collections, context } = options;
|
|
5940
6057
|
assertAggregateOperationsNotReserved(context.aggregateDescriptors);
|
|
6058
|
+
collectionMethodTables(context);
|
|
5941
6059
|
const contract = context.contract;
|
|
5942
6060
|
const ctx = {
|
|
5943
6061
|
runtime,
|