🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@zenstackhq/runtime

Package Overview
Dependencies
Maintainers
2
Versions
296
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zenstackhq/runtime - npm Package Compare versions

Comparing version

to
2.16.0

local-helpers/index.d.ts

44

cross/index.js

@@ -82,4 +82,27 @@ "use strict";

// src/local-helpers/is-plain-object.ts
function isObject(o) {
return Object.prototype.toString.call(o) === "[object Object]";
}
function isPlainObject(o) {
if (isObject(o) === false) return false;
const ctor = o.constructor;
if (ctor === void 0) return true;
const prot = ctor.prototype;
if (isObject(prot) === false) return false;
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
return false;
}
return true;
}
// src/local-helpers/lower-case-first.ts
function lowerCaseFirst(input) {
return input.charAt(0).toLowerCase() + input.slice(1);
}
// src/local-helpers/tiny-invariant.ts
var isProduction = process.env.NODE_ENV === "production";
// src/cross/clone.ts
var import_is_plain_object = require("is-plain-object");
function clone(value) {

@@ -90,3 +113,3 @@ if (Array.isArray(value)) {

if (typeof value === "object") {
if (!value || !(0, import_is_plain_object.isPlainObject)(value)) {
if (!value || !isPlainObject(value)) {
return value;

@@ -135,7 +158,6 @@ }

// src/cross/model-meta.ts
var import_lower_case_first = require("lower-case-first");
function resolveField(modelMeta, modelOrTypeDef, field, isTypeDef = false) {
var _a, _b;
const container = isTypeDef ? modelMeta.typeDefs : modelMeta.models;
return (_b = (_a = container == null ? void 0 : container[(0, import_lower_case_first.lowerCaseFirst)(modelOrTypeDef)]) == null ? void 0 : _a.fields) == null ? void 0 : _b[field];
return (_b = (_a = container == null ? void 0 : container[lowerCaseFirst(modelOrTypeDef)]) == null ? void 0 : _a.fields) == null ? void 0 : _b[field];
}

@@ -151,7 +173,7 @@ function requireField(modelMeta, model, field, isTypeDef = false) {

var _a;
return (_a = modelMeta.models[(0, import_lower_case_first.lowerCaseFirst)(model)]) == null ? void 0 : _a.fields;
return (_a = modelMeta.models[lowerCaseFirst(model)]) == null ? void 0 : _a.fields;
}
function getUniqueConstraints(modelMeta, model) {
var _a;
return (_a = modelMeta.models[(0, import_lower_case_first.lowerCaseFirst)(model)]) == null ? void 0 : _a.uniqueConstraints;
return (_a = modelMeta.models[lowerCaseFirst(model)]) == null ? void 0 : _a.uniqueConstraints;
}

@@ -527,3 +549,2 @@

// src/cross/utils.ts
var import_lower_case_first2 = require("lower-case-first");
function getModelFields(data) {

@@ -559,3 +580,3 @@ return data ? Object.keys(data) : [];

var _a, _b;
const uniqueConstraints = (_b = (_a = modelMeta.models[(0, import_lower_case_first2.lowerCaseFirst)(model)]) == null ? void 0 : _a.uniqueConstraints) != null ? _b : {};
const uniqueConstraints = (_b = (_a = modelMeta.models[lowerCaseFirst(model)]) == null ? void 0 : _a.uniqueConstraints) != null ? _b : {};
const entries = Object.values(uniqueConstraints);

@@ -571,3 +592,3 @@ if (entries.length === 0) {

function getModelInfo(modelMeta, model, throwIfNotFound = false) {
const info = modelMeta.models[(0, import_lower_case_first2.lowerCaseFirst)(model)];
const info = modelMeta.models[lowerCaseFirst(model)];
if (!info && throwIfNotFound) {

@@ -580,3 +601,3 @@ throw new Error(`Unable to load info for ${model}`);

var _a;
const info = (_a = modelMeta.typeDefs) == null ? void 0 : _a[(0, import_lower_case_first2.lowerCaseFirst)(typeDef)];
const info = (_a = modelMeta.typeDefs) == null ? void 0 : _a[lowerCaseFirst(typeDef)];
if (!info && throwIfNotFound) {

@@ -812,3 +833,2 @@ throw new Error(`Unable to load info for ${typeDef}`);

// src/cross/query-analyzer.ts
var import_lower_case_first3 = require("lower-case-first");
function getReadModels(model, modelMeta, args) {

@@ -871,3 +891,3 @@ const result = /* @__PURE__ */ new Set();

visited.add(model);
const cascades = (_a = modelMeta.deleteCascade) == null ? void 0 : _a[(0, import_lower_case_first3.lowerCaseFirst)(model)];
const cascades = (_a = modelMeta.deleteCascade) == null ? void 0 : _a[lowerCaseFirst(model)];
if (!cascades) {

@@ -874,0 +894,0 @@ return;

@@ -18,6 +18,3 @@ "use strict";

const deepmerge_1 = __importDefault(require("deepmerge"));
const is_plain_object_1 = require("is-plain-object");
const lower_case_first_1 = require("lower-case-first");
const traverse_1 = __importDefault(require("traverse"));
const upper_case_first_1 = require("upper-case-first");
const zod_1 = require("zod");

@@ -27,2 +24,3 @@ const zod_validation_error_1 = require("zod-validation-error");

const cross_1 = require("../../../cross");
const local_helpers_1 = require("../../../local-helpers");
const version_1 = require("../../../version");

@@ -114,3 +112,3 @@ const query_utils_1 = require("../query-utils");

isTrue(condition) {
if (condition === null || condition === undefined || !(0, is_plain_object_1.isPlainObject)(condition)) {
if (condition === null || condition === undefined || !(0, local_helpers_1.isPlainObject)(condition)) {
return false;

@@ -137,3 +135,3 @@ }

isFalse(condition) {
if (condition === null || condition === undefined || !(0, is_plain_object_1.isPlainObject)(condition)) {
if (condition === null || condition === undefined || !(0, local_helpers_1.isPlainObject)(condition)) {
return false;

@@ -218,3 +216,3 @@ }

default: {
if (!(0, is_plain_object_1.isPlainObject)(value)) {
if (!(0, local_helpers_1.isPlainObject)(value)) {
// don't visit into non-plain object values - could be Date, array, etc.

@@ -246,3 +244,3 @@ result[key] = value;

}
const def = this.policy.policy[(0, lower_case_first_1.lowerCaseFirst)(model)];
const def = this.policy.policy[(0, local_helpers_1.lowerCaseFirst)(model)];
if (!def) {

@@ -609,3 +607,3 @@ throw this.unknownError(`unable to load policy guard for ${model}`);

var _a, _b;
return (_b = (_a = this.modelMeta.models[(0, lower_case_first_1.lowerCaseFirst)(model)]) === null || _a === void 0 ? void 0 : _a.uniqueConstraints) !== null && _b !== void 0 ? _b : {};
return (_b = (_a = this.modelMeta.models[(0, local_helpers_1.lowerCaseFirst)(model)]) === null || _a === void 0 ? void 0 : _a.uniqueConstraints) !== null && _b !== void 0 ? _b : {};
}

@@ -703,2 +701,3 @@ injectNestedReadConditions(db, model, args) {

return __awaiter(this, void 0, void 0, function* () {
var _a;
let guard = this.getAuthGuard(db, model, operation, preValue);

@@ -768,3 +767,3 @@ if (this.isFalse(guard) && !this.hasOverrideAuthGuard(model, operation)) {

}
if (schema) {
if (schema && !((_a = this.options.validation) === null || _a === void 0 ? void 0 : _a.inputOnlyValidationForUpdate)) {
// TODO: push down schema check to the database

@@ -1096,3 +1095,3 @@ this.validateZodSchema(model, undefined, result, true, (err) => {

var _a, _b;
return ((_b = (_a = this.policy.validation) === null || _a === void 0 ? void 0 : _a[(0, lower_case_first_1.lowerCaseFirst)(model)]) === null || _b === void 0 ? void 0 : _b.hasValidation) === true;
return ((_b = (_a = this.policy.validation) === null || _a === void 0 ? void 0 : _a[(0, local_helpers_1.lowerCaseFirst)(model)]) === null || _b === void 0 ? void 0 : _b.hasValidation) === true;
}

@@ -1116,3 +1115,3 @@ hasFieldLevelPolicy(model) {

}
const schemaKey = `${(0, upper_case_first_1.upperCaseFirst)(model)}${kind ? 'Prisma' + (0, upper_case_first_1.upperCaseFirst)(kind) : ''}Schema`;
const schemaKey = `${(0, local_helpers_1.upperCaseFirst)(model)}${kind ? 'Prisma' + (0, local_helpers_1.upperCaseFirst)(kind) : ''}Schema`;
if (excludePasswordFields) {

@@ -1129,3 +1128,3 @@ // The `excludePasswordFields` mode is to handle the issue the fields marked with `@password` change at runtime,

let result = schema;
const modelFields = (_a = this.modelMeta.models[(0, lower_case_first_1.lowerCaseFirst)(model)]) === null || _a === void 0 ? void 0 : _a.fields;
const modelFields = (_a = this.modelMeta.models[(0, local_helpers_1.lowerCaseFirst)(model)]) === null || _a === void 0 ? void 0 : _a.fields;
if (modelFields) {

@@ -1146,3 +1145,3 @@ for (const [key, field] of Object.entries(modelFields)) {

// get the schema without refinement: `[Model]WithoutRefineSchema`
const withoutRefineSchemaKey = `${(0, upper_case_first_1.upperCaseFirst)(model)}${kind ? 'Prisma' + (0, upper_case_first_1.upperCaseFirst)(kind) : ''}WithoutRefineSchema`;
const withoutRefineSchemaKey = `${(0, local_helpers_1.upperCaseFirst)(model)}${kind ? 'Prisma' + (0, local_helpers_1.upperCaseFirst)(kind) : ''}WithoutRefineSchema`;
schema = this.zodSchemas.models[withoutRefineSchemaKey];

@@ -1153,3 +1152,3 @@ if (schema) {

// refine function: `refine[Model]`
const refineFuncKey = `refine${(0, upper_case_first_1.upperCaseFirst)(model)}`;
const refineFuncKey = `refine${(0, local_helpers_1.upperCaseFirst)(model)}`;
const refineFunc = this.zodSchemas.models[refineFuncKey];

@@ -1156,0 +1155,0 @@ return typeof refineFunc === 'function' ? refineFunc(schema) : schema;

@@ -18,6 +18,3 @@ "use strict";

const deepmerge_1 = __importDefault(require("deepmerge"));
const is_plain_object_1 = require("is-plain-object");
const lower_case_first_1 = require("lower-case-first");
const traverse_1 = __importDefault(require("traverse"));
const upper_case_first_1 = require("upper-case-first");
const zod_1 = require("zod");

@@ -27,2 +24,3 @@ const zod_validation_error_1 = require("zod-validation-error");

const cross_1 = require("../../../cross");
const local_helpers_1 = require("../../../local-helpers");
const version_1 = require("../../../version");

@@ -114,3 +112,3 @@ const query_utils_1 = require("../query-utils");

isTrue(condition) {
if (condition === null || condition === undefined || !(0, is_plain_object_1.isPlainObject)(condition)) {
if (condition === null || condition === undefined || !(0, local_helpers_1.isPlainObject)(condition)) {
return false;

@@ -137,3 +135,3 @@ }

isFalse(condition) {
if (condition === null || condition === undefined || !(0, is_plain_object_1.isPlainObject)(condition)) {
if (condition === null || condition === undefined || !(0, local_helpers_1.isPlainObject)(condition)) {
return false;

@@ -218,3 +216,3 @@ }

default: {
if (!(0, is_plain_object_1.isPlainObject)(value)) {
if (!(0, local_helpers_1.isPlainObject)(value)) {
// don't visit into non-plain object values - could be Date, array, etc.

@@ -246,3 +244,3 @@ result[key] = value;

}
const def = this.policy.policy[(0, lower_case_first_1.lowerCaseFirst)(model)];
const def = this.policy.policy[(0, local_helpers_1.lowerCaseFirst)(model)];
if (!def) {

@@ -609,3 +607,3 @@ throw this.unknownError(`unable to load policy guard for ${model}`);

var _a, _b;
return (_b = (_a = this.modelMeta.models[(0, lower_case_first_1.lowerCaseFirst)(model)]) === null || _a === void 0 ? void 0 : _a.uniqueConstraints) !== null && _b !== void 0 ? _b : {};
return (_b = (_a = this.modelMeta.models[(0, local_helpers_1.lowerCaseFirst)(model)]) === null || _a === void 0 ? void 0 : _a.uniqueConstraints) !== null && _b !== void 0 ? _b : {};
}

@@ -703,2 +701,3 @@ injectNestedReadConditions(db, model, args) {

return __awaiter(this, void 0, void 0, function* () {
var _a;
let guard = this.getAuthGuard(db, model, operation, preValue);

@@ -768,3 +767,3 @@ if (this.isFalse(guard) && !this.hasOverrideAuthGuard(model, operation)) {

}
if (schema) {
if (schema && !((_a = this.options.validation) === null || _a === void 0 ? void 0 : _a.inputOnlyValidationForUpdate)) {
// TODO: push down schema check to the database

@@ -1096,3 +1095,3 @@ this.validateZodSchema(model, undefined, result, true, (err) => {

var _a, _b;
return ((_b = (_a = this.policy.validation) === null || _a === void 0 ? void 0 : _a[(0, lower_case_first_1.lowerCaseFirst)(model)]) === null || _b === void 0 ? void 0 : _b.hasValidation) === true;
return ((_b = (_a = this.policy.validation) === null || _a === void 0 ? void 0 : _a[(0, local_helpers_1.lowerCaseFirst)(model)]) === null || _b === void 0 ? void 0 : _b.hasValidation) === true;
}

@@ -1116,3 +1115,3 @@ hasFieldLevelPolicy(model) {

}
const schemaKey = `${(0, upper_case_first_1.upperCaseFirst)(model)}${kind ? 'Prisma' + (0, upper_case_first_1.upperCaseFirst)(kind) : ''}Schema`;
const schemaKey = `${(0, local_helpers_1.upperCaseFirst)(model)}${kind ? 'Prisma' + (0, local_helpers_1.upperCaseFirst)(kind) : ''}Schema`;
if (excludePasswordFields) {

@@ -1129,3 +1128,3 @@ // The `excludePasswordFields` mode is to handle the issue the fields marked with `@password` change at runtime,

let result = schema;
const modelFields = (_a = this.modelMeta.models[(0, lower_case_first_1.lowerCaseFirst)(model)]) === null || _a === void 0 ? void 0 : _a.fields;
const modelFields = (_a = this.modelMeta.models[(0, local_helpers_1.lowerCaseFirst)(model)]) === null || _a === void 0 ? void 0 : _a.fields;
if (modelFields) {

@@ -1146,3 +1145,3 @@ for (const [key, field] of Object.entries(modelFields)) {

// get the schema without refinement: `[Model]WithoutRefineSchema`
const withoutRefineSchemaKey = `${(0, upper_case_first_1.upperCaseFirst)(model)}${kind ? 'Prisma' + (0, upper_case_first_1.upperCaseFirst)(kind) : ''}WithoutRefineSchema`;
const withoutRefineSchemaKey = `${(0, local_helpers_1.upperCaseFirst)(model)}${kind ? 'Prisma' + (0, local_helpers_1.upperCaseFirst)(kind) : ''}WithoutRefineSchema`;
schema = this.zodSchemas.models[withoutRefineSchemaKey];

@@ -1153,3 +1152,3 @@ if (schema) {

// refine function: `refine[Model]`
const refineFuncKey = `refine${(0, upper_case_first_1.upperCaseFirst)(model)}`;
const refineFuncKey = `refine${(0, local_helpers_1.upperCaseFirst)(model)}`;
const refineFunc = this.zodSchemas.models[refineFuncKey];

@@ -1156,0 +1155,0 @@ return typeof refineFunc === 'function' ? refineFunc(schema) : schema;

{
"name": "@zenstackhq/runtime",
"displayName": "ZenStack Runtime Library",
"version": "2.15.1",
"version": "2.16.0",
"description": "Runtime of ZenStack for both client-side and server-side environments.",

@@ -17,2 +17,6 @@ "repository": {

},
"./local-helpers": {
"types": "./local-helpers/index.d.ts",
"default": "./local-helpers/index.js"
},
"./edge": {

@@ -93,8 +97,5 @@ "types": "./edge.d.ts",

"buffer": "^6.0.3",
"change-case": "^4.1.2",
"decimal.js-light": "^2.5.1",
"deepmerge": "^4.3.1",
"is-plain-object": "^5.0.0",
"logic-solver": "^2.0.1",
"lower-case-first": "^2.0.2",
"pluralize": "^8.0.0",

@@ -104,7 +105,5 @@ "safe-json-stringify": "^1.2.0",

"superjson": "^1.13.0",
"tiny-invariant": "^1.3.1",
"traverse": "^0.6.10",
"ts-pattern": "^4.3.0",
"tslib": "^2.4.1",
"upper-case-first": "^2.0.2",
"uuid": "^9.0.0",

@@ -115,3 +114,3 @@ "zod": "^3.22.4",

"peerDependencies": {
"@prisma/client": "5.0.0 - 6.8.x"
"@prisma/client": "5.0.0 - 6.10.x"
},

@@ -129,3 +128,6 @@ "author": {

"@types/traverse": "^0.6.37",
"@types/uuid": "^8.3.4"
"@types/uuid": "^8.3.4",
"decimal.js-light": "^2.5.1",
"superjson": "^1.13.0",
"uuid": "^9.0.0"
},

@@ -132,0 +134,0 @@ "scripts": {

@@ -121,2 +121,6 @@ import type { z } from 'zod';

encryption?: SimpleEncryption | CustomEncryption;
/**
* Options for data validation.
*/
validation?: ValidationOptions;
};

@@ -182,1 +186,17 @@ /**

};
/**
* Options for data validation.
*/
export type ValidationOptions = {
/**
* Whether to validate "update" operations based only on the input data. By default, ZenStack
* validates the entity after a update operation completes (inside a transaction), and rejects
* the operation if validation fails. This implies the entire entity needs to satisfy the
* validation rules, even for fields that are not part of the update input data.
*
* You can use this option to toggle the behavior to only validate the input data.
*
* Default is `false`.
*/
inputOnlyValidationForUpdate?: boolean;
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet