@pkgverse/prismock 2.0.5-beta.0 → 2.0.5-beta.1
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/lib/client.d.ts +3 -0
- package/dist/lib/delegate.d.ts +2 -2
- package/dist/lib/extensions/index.d.ts +3 -1
- package/dist/lib/extensions/result.d.ts +5 -3
- package/dist/lib/globals.d.ts +6 -0
- package/dist/lib/operations/create.d.ts +1 -1
- package/dist/lib/operations/find/find.d.ts +1 -1
- package/dist/lib/prismock.d.ts +4 -4
- package/dist/lib/types/Find.d.ts +1 -1
- package/dist/lib/types/GroupBy.d.ts +1 -1
- package/dist/v6/index.cjs +68 -39
- package/dist/v6/index.mjs +2720 -41
- package/dist/v7/index.cjs +70 -39
- package/dist/v7/index.mjs +2786 -41
- package/package.json +5 -1
package/dist/lib/client.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Data } from "./prismock";
|
|
|
5
5
|
import { type ExtensionsDefinition } from "./extensions";
|
|
6
6
|
import type { PGlite } from "@electric-sql/pglite";
|
|
7
7
|
import type { PrismaPGlite } from "pglite-prisma-adapter";
|
|
8
|
+
import { type PrismaDMMF } from "./globals";
|
|
8
9
|
type GetData = () => Promise<Data>;
|
|
9
10
|
type SetData = (data: Data) => Promise<void>;
|
|
10
11
|
export interface PrismockData {
|
|
@@ -20,6 +21,8 @@ export type PrismockOptions = {
|
|
|
20
21
|
};
|
|
21
22
|
export declare class Prismock {
|
|
22
23
|
schemaPath: string;
|
|
24
|
+
datamodel?: DMMF.Document;
|
|
25
|
+
PrismaDMMF?: PrismaDMMF;
|
|
23
26
|
private genPromise;
|
|
24
27
|
protected constructor(schemaPath: string);
|
|
25
28
|
static create<PC = PrismaClient>(schemaPath: string): Promise<PrismockClientType<PC>>;
|
package/dist/lib/delegate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DMMF } from '@prisma/generator-helper';
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
2
|
import { CreateArgs, CreateManyArgs, FindArgs, GroupByArgs, UpsertArgs } from './types';
|
|
3
3
|
import { DeleteArgs, UpdateArgs } from './operations';
|
|
4
4
|
import { Data, Delegates, Properties } from './prismock';
|
|
@@ -39,4 +39,4 @@ export type DelegateContext = {
|
|
|
39
39
|
data: Data;
|
|
40
40
|
properties: Record<string, DelegateProperties>;
|
|
41
41
|
};
|
|
42
|
-
export declare function generateDelegate(model: DMMF.Model, data: Data, name: string, properties: Properties, delegates: Delegates, onChange: (items: Item[]) => void): Delegate
|
|
42
|
+
export declare function generateDelegate(model: DMMF.Model, data: Data, name: string, properties: Properties, delegates: Delegates, onChange: (items: Item[]) => void): Promise<Delegate>;
|
|
@@ -3,6 +3,8 @@ import { applyModelExtensions } from './model';
|
|
|
3
3
|
import { applyQueryExtensions } from './query';
|
|
4
4
|
import { applyResultExtensions } from './result';
|
|
5
5
|
import type { ExtendsHook, DefaultArgs } from '@prisma/client/runtime/library';
|
|
6
|
+
import type { DMMF } from '@prisma/generator-helper-v7';
|
|
7
|
+
import type { PrismaDMMF } from '../globals';
|
|
6
8
|
export { applyModelExtensions, applyQueryExtensions, applyResultExtensions };
|
|
7
9
|
export type ExtensionsDefinition = Parameters<ExtendsHook<"define", Prisma.TypeMapCb, DefaultArgs>>[0];
|
|
8
|
-
export declare function applyExtensions(client: PrismaClient, extensions: ExtensionsDefinition): PrismaClient<Prisma.PrismaClientOptions, never, DefaultArgs>;
|
|
10
|
+
export declare function applyExtensions(client: PrismaClient, extensions: ExtensionsDefinition, datamodel: DMMF.Document, PrismaDMMF: PrismaDMMF): PrismaClient<Prisma.PrismaClientOptions, never, DefaultArgs>;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import { Prisma,
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { Prisma, PrismaClient } from "@prisma/client";
|
|
2
|
+
import type { DefaultArgs, ExtendsHook } from "@prisma/client/runtime/library";
|
|
3
|
+
import type { DMMF } from "@prisma/generator-helper-v7";
|
|
4
|
+
import type { PrismaDMMF } from "../globals";
|
|
5
|
+
export declare function applyResultExtensions(client: PrismaClient, extensions: Parameters<ExtendsHook<"define", Prisma.TypeMapCb, DefaultArgs>>[0], datamodel: DMMF.Document, PrismaDMMF: PrismaDMMF): PrismaClient;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type PrismaDMMF = Awaited<ReturnType<typeof getGlobals>>["DMMF"];
|
|
2
|
+
export declare function getGlobals(): Promise<{
|
|
3
|
+
PrismaClientKnownRequestError: typeof import("@prisma/client-runtime-utils").PrismaClientKnownRequestError;
|
|
4
|
+
Decimal: typeof import("@prisma/client-runtime-utils").Decimal;
|
|
5
|
+
DMMF: typeof import("@prisma/dmmf-v7") | typeof import("@prisma/dmmf-v6");
|
|
6
|
+
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DMMF } from '@prisma/generator-helper';
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
2
|
import { FindArgs, GroupByFieldArg, Order, OrderedValue } from '../../types';
|
|
3
3
|
import { Delegate, DelegateProperties, Item } from '../../delegate';
|
|
4
4
|
import { Delegates } from '../../prismock';
|
package/dist/lib/prismock.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ActiveConnectorType } from
|
|
2
|
-
import { Delegate, DelegateProperties, Item } from
|
|
1
|
+
import type { ActiveConnectorType } from "@prisma/generator-helper";
|
|
2
|
+
import { Delegate, DelegateProperties, Item } from "./delegate";
|
|
3
3
|
import type { Model } from "@prisma/dmmf";
|
|
4
4
|
type OptionsSync = {
|
|
5
5
|
models: Model[];
|
|
@@ -8,9 +8,9 @@ export type Data = Record<string, Item[]>;
|
|
|
8
8
|
export type Properties = Record<string, DelegateProperties>;
|
|
9
9
|
export type Delegates = Record<string, Delegate>;
|
|
10
10
|
export declare function fetchProvider(schemaPath?: string): Promise<ActiveConnectorType>;
|
|
11
|
-
export declare function generateDelegates(options: OptionsSync): {
|
|
11
|
+
export declare function generateDelegates(options: OptionsSync): Promise<{
|
|
12
12
|
delegates: Delegates;
|
|
13
13
|
getData: () => Promise<Data>;
|
|
14
14
|
setData: (d: Data) => Promise<void>;
|
|
15
|
-
}
|
|
15
|
+
}>;
|
|
16
16
|
export {};
|
package/dist/lib/types/Find.d.ts
CHANGED
package/dist/v6/index.cjs
CHANGED
|
@@ -1290,9 +1290,6 @@ function mergeAggregateArg(aggregation, aggregate2, value) {
|
|
|
1290
1290
|
[aggregation]: Object.fromEntries(Object.keys(valueToProcess).map((k) => [k, true]))
|
|
1291
1291
|
};
|
|
1292
1292
|
}
|
|
1293
|
-
// src/lib/operations/create.ts
|
|
1294
|
-
var import_library = require("@prisma/client/runtime/library");
|
|
1295
|
-
|
|
1296
1293
|
// node_modules/bson/lib/bson.node.mjs
|
|
1297
1294
|
var import_crypto = require("crypto");
|
|
1298
1295
|
var TypedArrayPrototypeGetSymbolToStringTag = (() => {
|
|
@@ -4416,6 +4413,7 @@ var buffer = ByteUtils.allocate(MAXSIZE);
|
|
|
4416
4413
|
|
|
4417
4414
|
// src/lib/operations/create.ts
|
|
4418
4415
|
var import_cuid2 = __toESM(require_cuid2());
|
|
4416
|
+
var import_client_runtime_utils = require("@prisma/client-runtime-utils");
|
|
4419
4417
|
var isAutoIncrement = (field) => {
|
|
4420
4418
|
return field.default?.name === "autoincrement";
|
|
4421
4419
|
};
|
|
@@ -4468,7 +4466,7 @@ function calculateDefaultFieldValue(field, properties) {
|
|
|
4468
4466
|
if (field.type === "Json" && typeof field.default === "string")
|
|
4469
4467
|
return JSON.parse(field.default);
|
|
4470
4468
|
if (field.type === "Decimal" && typeof field.default === "number")
|
|
4471
|
-
return new
|
|
4469
|
+
return new import_client_runtime_utils.Decimal(field.default);
|
|
4472
4470
|
if (["string", "number", "boolean"].includes(typeof field.default))
|
|
4473
4471
|
return field.default;
|
|
4474
4472
|
return;
|
|
@@ -4802,15 +4800,29 @@ function updateMany(args, current, delegates, onChange) {
|
|
|
4802
4800
|
// node_modules/@prisma/client/package.json
|
|
4803
4801
|
var version = "6.12.0";
|
|
4804
4802
|
|
|
4803
|
+
// src/lib/globals.ts
|
|
4804
|
+
async function getGlobals() {
|
|
4805
|
+
const { PrismaClientKnownRequestError, Decimal: Decimal2 } = await import("@prisma/client-runtime-utils");
|
|
4806
|
+
const DMMF = await (async () => {
|
|
4807
|
+
if (false) {}
|
|
4808
|
+
return await import("@prisma/dmmf-v6");
|
|
4809
|
+
})();
|
|
4810
|
+
return {
|
|
4811
|
+
PrismaClientKnownRequestError,
|
|
4812
|
+
Decimal: Decimal2,
|
|
4813
|
+
DMMF
|
|
4814
|
+
};
|
|
4815
|
+
}
|
|
4816
|
+
|
|
4805
4817
|
// src/lib/delegate.ts
|
|
4806
|
-
|
|
4807
|
-
|
|
4818
|
+
async function generateDelegate(model, data, name, properties, delegates, onChange) {
|
|
4819
|
+
const { PrismaClientKnownRequestError } = await getGlobals();
|
|
4808
4820
|
const delegate = {};
|
|
4809
4821
|
Object.assign(delegate, {
|
|
4810
4822
|
delete: (args = {}) => {
|
|
4811
4823
|
const deleted = deleteMany(args, delegate, delegates, onChange);
|
|
4812
4824
|
if (deleted.length === 0)
|
|
4813
|
-
return Promise.reject(new
|
|
4825
|
+
return Promise.reject(new PrismaClientKnownRequestError(`No record was found for a delete on ${delegate.model.name}`, {
|
|
4814
4826
|
code: "P2025",
|
|
4815
4827
|
clientVersion: version,
|
|
4816
4828
|
meta: {
|
|
@@ -4827,7 +4839,7 @@ function generateDelegate(model, data, name, properties, delegates, onChange) {
|
|
|
4827
4839
|
update: (args) => {
|
|
4828
4840
|
const updated = updateMany(args, delegate, delegates, onChange);
|
|
4829
4841
|
const [update3] = updated;
|
|
4830
|
-
return update3 ? Promise.resolve(update3) : Promise.reject(new
|
|
4842
|
+
return update3 ? Promise.resolve(update3) : Promise.reject(new PrismaClientKnownRequestError(`No record was found for an update on ${delegate.model.name}`, {
|
|
4831
4843
|
code: "P2025",
|
|
4832
4844
|
clientVersion: version,
|
|
4833
4845
|
meta: {
|
|
@@ -4873,7 +4885,7 @@ function generateDelegate(model, data, name, properties, delegates, onChange) {
|
|
|
4873
4885
|
findUniqueOrThrow: (args = {}) => {
|
|
4874
4886
|
const found = findOne(args, delegate, delegates);
|
|
4875
4887
|
if (!found)
|
|
4876
|
-
return Promise.reject(new
|
|
4888
|
+
return Promise.reject(new PrismaClientKnownRequestError(`No record was found for a query on ${delegate.model.name}`, {
|
|
4877
4889
|
code: "P2025",
|
|
4878
4890
|
clientVersion: version
|
|
4879
4891
|
}));
|
|
@@ -4882,7 +4894,7 @@ function generateDelegate(model, data, name, properties, delegates, onChange) {
|
|
|
4882
4894
|
findFirstOrThrow: (args = {}) => {
|
|
4883
4895
|
const found = findOne(args, delegate, delegates);
|
|
4884
4896
|
if (!found)
|
|
4885
|
-
return Promise.reject(new
|
|
4897
|
+
return Promise.reject(new PrismaClientKnownRequestError(`No record was found for a query on ${delegate.model.name}`, {
|
|
4886
4898
|
code: "P2025",
|
|
4887
4899
|
clientVersion: version
|
|
4888
4900
|
}));
|
|
@@ -4934,7 +4946,7 @@ async function generateDMMF(schemaPath) {
|
|
|
4934
4946
|
}
|
|
4935
4947
|
|
|
4936
4948
|
// src/lib/prismock.ts
|
|
4937
|
-
function generateDelegates(options) {
|
|
4949
|
+
async function generateDelegates(options) {
|
|
4938
4950
|
const models = options.models ?? [];
|
|
4939
4951
|
const data = {};
|
|
4940
4952
|
const properties = {};
|
|
@@ -4960,18 +4972,19 @@ function generateDelegates(options) {
|
|
|
4960
4972
|
};
|
|
4961
4973
|
}, {}));
|
|
4962
4974
|
}
|
|
4963
|
-
models.
|
|
4975
|
+
await Promise.all(models.map(async (model) => {
|
|
4964
4976
|
const name = camelize(model.name);
|
|
4965
4977
|
data[name] = [];
|
|
4966
4978
|
properties[name] = {
|
|
4967
4979
|
increment: {}
|
|
4968
4980
|
};
|
|
4981
|
+
const delegate = await generateDelegate(model, data, name, properties, delegates, (items) => {
|
|
4982
|
+
Object.assign(data, { [name]: items });
|
|
4983
|
+
});
|
|
4969
4984
|
Object.assign(delegates, {
|
|
4970
|
-
[name]:
|
|
4971
|
-
Object.assign(data, { [name]: items });
|
|
4972
|
-
})
|
|
4985
|
+
[name]: delegate
|
|
4973
4986
|
});
|
|
4974
|
-
}, {});
|
|
4987
|
+
}, {}));
|
|
4975
4988
|
const clientDelegates = Object.entries(delegates).reduce((accumulator, [delegateKey, delegateValue]) => {
|
|
4976
4989
|
return {
|
|
4977
4990
|
...accumulator,
|
|
@@ -5119,25 +5132,23 @@ function applyQueryExtensions(client, extensions) {
|
|
|
5119
5132
|
}
|
|
5120
5133
|
|
|
5121
5134
|
// src/lib/extensions/result.ts
|
|
5122
|
-
|
|
5123
|
-
var import_library3 = require("@prisma/client/runtime/library");
|
|
5124
|
-
function buildResultExtendedModel(client, proxiedModels, modelExtensions, modelName) {
|
|
5135
|
+
function buildResultExtendedModel(client, proxiedModels, modelExtensions, modelName, PrismaDMMF) {
|
|
5125
5136
|
const model = proxiedModels[modelName] ?? client[modelName];
|
|
5126
5137
|
if (Object.keys(modelExtensions).length === 0) {
|
|
5127
5138
|
return model;
|
|
5128
5139
|
}
|
|
5129
5140
|
const singleResultActions = [
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5141
|
+
PrismaDMMF.ModelAction.findFirst,
|
|
5142
|
+
PrismaDMMF.ModelAction.findFirstOrThrow,
|
|
5143
|
+
PrismaDMMF.ModelAction.findUnique,
|
|
5144
|
+
PrismaDMMF.ModelAction.findUniqueOrThrow,
|
|
5145
|
+
PrismaDMMF.ModelAction.create,
|
|
5146
|
+
PrismaDMMF.ModelAction.update,
|
|
5147
|
+
PrismaDMMF.ModelAction.upsert
|
|
5137
5148
|
];
|
|
5138
5149
|
const multipleResultActions = [
|
|
5139
|
-
|
|
5140
|
-
|
|
5150
|
+
PrismaDMMF.ModelAction.findMany,
|
|
5151
|
+
PrismaDMMF.ModelAction.createManyAndReturn
|
|
5141
5152
|
];
|
|
5142
5153
|
const allResultActions = [...singleResultActions, ...multipleResultActions];
|
|
5143
5154
|
const proxyMethod = (actionName) => {
|
|
@@ -5212,7 +5223,7 @@ function buildResultExtendedModel(client, proxiedModels, modelExtensions, modelN
|
|
|
5212
5223
|
});
|
|
5213
5224
|
return proxiedModel;
|
|
5214
5225
|
}
|
|
5215
|
-
function applyResultExtensions(client, extensions) {
|
|
5226
|
+
function applyResultExtensions(client, extensions, datamodel, PrismaDMMF) {
|
|
5216
5227
|
if (typeof extensions === "function") {
|
|
5217
5228
|
const extendedClient = extensions(client);
|
|
5218
5229
|
return extendedClient;
|
|
@@ -5226,7 +5237,7 @@ function applyResultExtensions(client, extensions) {
|
|
|
5226
5237
|
if (!originalModel) {
|
|
5227
5238
|
return;
|
|
5228
5239
|
}
|
|
5229
|
-
const proxiedModel = buildResultExtendedModel(client, proxiedModels, resultExtendedModelMap[modelName], modelName);
|
|
5240
|
+
const proxiedModel = buildResultExtendedModel(client, proxiedModels, resultExtendedModelMap[modelName], modelName, PrismaDMMF);
|
|
5230
5241
|
proxiedModels[modelName] = proxiedModel;
|
|
5231
5242
|
return proxiedModel;
|
|
5232
5243
|
}
|
|
@@ -5240,12 +5251,12 @@ function applyResultExtensions(client, extensions) {
|
|
|
5240
5251
|
proxyModel(modelName);
|
|
5241
5252
|
}
|
|
5242
5253
|
if (hasAllModelsExtension && resultExtendedModelMap["$allModels"]) {
|
|
5243
|
-
for (const model of
|
|
5254
|
+
for (const model of datamodel.datamodel.models) {
|
|
5244
5255
|
const modelName = model.name;
|
|
5245
5256
|
if (!(modelName in client)) {
|
|
5246
5257
|
continue;
|
|
5247
5258
|
}
|
|
5248
|
-
const proxiedModel = buildResultExtendedModel(client, proxiedModels, resultExtendedModelMap["$allModels"], modelName);
|
|
5259
|
+
const proxiedModel = buildResultExtendedModel(client, proxiedModels, resultExtendedModelMap["$allModels"], modelName, PrismaDMMF);
|
|
5249
5260
|
proxiedModels[modelName] = proxiedModel;
|
|
5250
5261
|
}
|
|
5251
5262
|
}
|
|
@@ -5260,8 +5271,8 @@ function applyResultExtensions(client, extensions) {
|
|
|
5260
5271
|
}
|
|
5261
5272
|
|
|
5262
5273
|
// src/lib/extensions/index.ts
|
|
5263
|
-
function applyExtensions(client, extensions) {
|
|
5264
|
-
const resultExtended = applyResultExtensions(client, extensions);
|
|
5274
|
+
function applyExtensions(client, extensions, datamodel, PrismaDMMF) {
|
|
5275
|
+
const resultExtended = applyResultExtensions(client, extensions, datamodel, PrismaDMMF);
|
|
5265
5276
|
const queryExtended = applyQueryExtensions(resultExtended, extensions);
|
|
5266
5277
|
const modelExtended = applyModelExtensions(queryExtended, extensions);
|
|
5267
5278
|
return modelExtended;
|
|
@@ -5270,19 +5281,29 @@ function applyExtensions(client, extensions) {
|
|
|
5270
5281
|
// src/lib/client.ts
|
|
5271
5282
|
class Prismock {
|
|
5272
5283
|
schemaPath;
|
|
5284
|
+
datamodel;
|
|
5285
|
+
PrismaDMMF;
|
|
5273
5286
|
genPromise;
|
|
5274
5287
|
constructor(schemaPath) {
|
|
5275
5288
|
this.schemaPath = schemaPath;
|
|
5276
|
-
this.genPromise = this.generate()
|
|
5289
|
+
this.genPromise = this.generate().then(({ datamodel, PrismaDMMF }) => {
|
|
5290
|
+
this.datamodel = datamodel;
|
|
5291
|
+
this.PrismaDMMF = PrismaDMMF;
|
|
5292
|
+
return { datamodel, PrismaDMMF };
|
|
5293
|
+
});
|
|
5277
5294
|
}
|
|
5278
5295
|
static async create(schemaPath) {
|
|
5279
5296
|
const p = new Prismock(schemaPath);
|
|
5280
|
-
await p.genPromise;
|
|
5297
|
+
const { datamodel, PrismaDMMF } = await p.genPromise;
|
|
5298
|
+
p.datamodel = datamodel;
|
|
5299
|
+
p.PrismaDMMF = PrismaDMMF;
|
|
5281
5300
|
return p;
|
|
5282
5301
|
}
|
|
5283
5302
|
static async createDefault(schemaPath) {
|
|
5284
5303
|
const p = new Prismock(schemaPath);
|
|
5285
|
-
await p.genPromise;
|
|
5304
|
+
const { datamodel, PrismaDMMF } = await p.genPromise;
|
|
5305
|
+
p.datamodel = datamodel;
|
|
5306
|
+
p.PrismaDMMF = PrismaDMMF;
|
|
5286
5307
|
return p;
|
|
5287
5308
|
}
|
|
5288
5309
|
async reset() {
|
|
@@ -5290,7 +5311,7 @@ class Prismock {
|
|
|
5290
5311
|
}
|
|
5291
5312
|
async generate() {
|
|
5292
5313
|
const datamodel = await generateDMMF(this.schemaPath);
|
|
5293
|
-
const { delegates, setData, getData } = generateDelegates({
|
|
5314
|
+
const { delegates, setData, getData } = await generateDelegates({
|
|
5294
5315
|
models: [
|
|
5295
5316
|
...datamodel.datamodel.models
|
|
5296
5317
|
]
|
|
@@ -5301,6 +5322,8 @@ class Prismock {
|
|
|
5301
5322
|
else
|
|
5302
5323
|
Object.assign(this, { [key]: value });
|
|
5303
5324
|
});
|
|
5325
|
+
const { DMMF: PrismaDMMF } = await getGlobals();
|
|
5326
|
+
return { datamodel, PrismaDMMF };
|
|
5304
5327
|
}
|
|
5305
5328
|
async $connect() {
|
|
5306
5329
|
await this.genPromise;
|
|
@@ -5326,7 +5349,13 @@ class Prismock {
|
|
|
5326
5349
|
return Promise.resolve([]);
|
|
5327
5350
|
}
|
|
5328
5351
|
$extends(extensionDefs) {
|
|
5329
|
-
|
|
5352
|
+
if (!this.datamodel) {
|
|
5353
|
+
throw new Error("Datamodel not loaded");
|
|
5354
|
+
}
|
|
5355
|
+
if (!this.PrismaDMMF) {
|
|
5356
|
+
throw new Error("PrismaDMMF not loaded");
|
|
5357
|
+
}
|
|
5358
|
+
return applyExtensions(this, extensionDefs, this.datamodel, this.PrismaDMMF);
|
|
5330
5359
|
}
|
|
5331
5360
|
async $transaction(args) {
|
|
5332
5361
|
if (Array.isArray(args)) {
|