@zenstackhq/runtime 3.0.0-alpha.4 → 3.0.0-alpha.6
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/client.cjs +266 -240
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -4
- package/dist/client.d.ts +2 -4
- package/dist/client.js +61 -36
- package/dist/client.js.map +1 -1
- package/dist/{contract-BBUC-uVq.d.cts → contract-DW8XGrtV.d.cts} +725 -697
- package/dist/{contract-BBUC-uVq.d.ts → contract-DW8XGrtV.d.ts} +725 -697
- package/dist/index.cjs +256 -238
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.js +53 -35
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy.cjs +34 -45
- package/dist/plugins/policy.cjs.map +1 -1
- package/dist/plugins/policy.d.cts +2 -4
- package/dist/plugins/policy.d.ts +2 -4
- package/dist/plugins/policy.js +6 -7
- package/dist/plugins/policy.js.map +1 -1
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.js.map +1 -1
- package/package.json +12 -14
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { C as ClientConstructor } from './contract-
|
|
2
|
-
export { a as ClientContract } from './contract-
|
|
3
|
-
import '@zenstackhq/sdk/schema';
|
|
1
|
+
import { C as ClientConstructor } from './contract-DW8XGrtV.cjs';
|
|
2
|
+
export { a as ClientContract } from './contract-DW8XGrtV.cjs';
|
|
4
3
|
import 'decimal.js';
|
|
4
|
+
import '@zenstackhq/sdk/schema';
|
|
5
5
|
import 'kysely';
|
|
6
|
-
import 'utility-types';
|
|
7
|
-
import '@zenstackhq/language/ast';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* ZenStack client.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { C as ClientConstructor } from './contract-
|
|
2
|
-
export { a as ClientContract } from './contract-
|
|
3
|
-
import '@zenstackhq/sdk/schema';
|
|
1
|
+
import { C as ClientConstructor } from './contract-DW8XGrtV.js';
|
|
2
|
+
export { a as ClientContract } from './contract-DW8XGrtV.js';
|
|
4
3
|
import 'decimal.js';
|
|
4
|
+
import '@zenstackhq/sdk/schema';
|
|
5
5
|
import 'kysely';
|
|
6
|
-
import 'utility-types';
|
|
7
|
-
import '@zenstackhq/language/ast';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* ZenStack client.
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
// src/client/client-impl.ts
|
|
9
|
+
import { lowerCaseFirst as lowerCaseFirst2 } from "@zenstackhq/common-helpers";
|
|
9
10
|
import { DefaultConnectionProvider, DefaultQueryExecutor as DefaultQueryExecutor2, Kysely, Log, PostgresDialect, SqliteDialect } from "kysely";
|
|
10
11
|
import { match as match19 } from "ts-pattern";
|
|
11
12
|
|
|
@@ -280,9 +281,9 @@ __name(safeJSONStringify, "safeJSONStringify");
|
|
|
280
281
|
|
|
281
282
|
// src/client/crud/operations/base.ts
|
|
282
283
|
import { createId } from "@paralleldrive/cuid2";
|
|
284
|
+
import { invariant as invariant7 } from "@zenstackhq/common-helpers";
|
|
283
285
|
import { expressionBuilder as expressionBuilder2, sql as sql4 } from "kysely";
|
|
284
286
|
import { nanoid } from "nanoid";
|
|
285
|
-
import invariant7 from "tiny-invariant";
|
|
286
287
|
import { match as match8 } from "ts-pattern";
|
|
287
288
|
import { ulid } from "ulid";
|
|
288
289
|
import * as uuid from "uuid";
|
|
@@ -300,21 +301,21 @@ var RejectedByPolicyError = class extends Error {
|
|
|
300
301
|
};
|
|
301
302
|
|
|
302
303
|
// src/plugins/policy/policy-handler.ts
|
|
304
|
+
import { invariant as invariant6 } from "@zenstackhq/common-helpers";
|
|
303
305
|
import { AliasNode as AliasNode3, BinaryOperationNode as BinaryOperationNode3, ColumnNode as ColumnNode2, DeleteQueryNode, FromNode as FromNode2, IdentifierNode as IdentifierNode2, InsertQueryNode, OperationNodeTransformer, OperatorNode as OperatorNode3, PrimitiveValueListNode, RawNode, ReturningNode, SelectionNode as SelectionNode2, SelectQueryNode as SelectQueryNode2, TableNode as TableNode3, UpdateQueryNode, ValueNode as ValueNode3, ValuesNode, WhereNode as WhereNode2 } from "kysely";
|
|
304
|
-
import invariant6 from "tiny-invariant";
|
|
305
306
|
import { match as match7 } from "ts-pattern";
|
|
306
307
|
|
|
307
308
|
// src/client/crud/dialects/index.ts
|
|
308
309
|
import { match as match4 } from "ts-pattern";
|
|
309
310
|
|
|
310
311
|
// src/client/crud/dialects/postgresql.ts
|
|
312
|
+
import { invariant as invariant2 } from "@zenstackhq/common-helpers";
|
|
311
313
|
import { sql as sql2 } from "kysely";
|
|
312
|
-
import invariant2 from "tiny-invariant";
|
|
313
314
|
import { match as match2 } from "ts-pattern";
|
|
314
315
|
|
|
315
316
|
// src/client/crud/dialects/base.ts
|
|
317
|
+
import { invariant, isPlainObject } from "@zenstackhq/common-helpers";
|
|
316
318
|
import { sql } from "kysely";
|
|
317
|
-
import invariant from "tiny-invariant";
|
|
318
319
|
import { match, P } from "ts-pattern";
|
|
319
320
|
|
|
320
321
|
// src/utils/enumerate.ts
|
|
@@ -332,7 +333,6 @@ function enumerate(x) {
|
|
|
332
333
|
__name(enumerate, "enumerate");
|
|
333
334
|
|
|
334
335
|
// src/client/crud/dialects/base.ts
|
|
335
|
-
import { isPlainObject } from "is-plain-object";
|
|
336
336
|
var BaseCrudDialect = class {
|
|
337
337
|
static {
|
|
338
338
|
__name(this, "BaseCrudDialect");
|
|
@@ -915,8 +915,8 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
915
915
|
};
|
|
916
916
|
|
|
917
917
|
// src/client/crud/dialects/sqlite.ts
|
|
918
|
+
import { invariant as invariant3 } from "@zenstackhq/common-helpers";
|
|
918
919
|
import { sql as sql3 } from "kysely";
|
|
919
|
-
import invariant3 from "tiny-invariant";
|
|
920
920
|
import { match as match3 } from "ts-pattern";
|
|
921
921
|
var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
922
922
|
static {
|
|
@@ -1460,12 +1460,12 @@ var ColumnCollector = class extends DefaultOperationNodeVisitor {
|
|
|
1460
1460
|
};
|
|
1461
1461
|
|
|
1462
1462
|
// src/plugins/policy/expression-transformer.ts
|
|
1463
|
+
import { invariant as invariant5 } from "@zenstackhq/common-helpers";
|
|
1463
1464
|
import { AliasNode as AliasNode2, BinaryOperationNode as BinaryOperationNode2, ColumnNode, expressionBuilder, FromNode, FunctionNode as FunctionNode2, IdentifierNode, OperatorNode as OperatorNode2, ReferenceNode as ReferenceNode2, SelectionNode, SelectQueryNode, TableNode as TableNode2, ValueListNode, ValueNode as ValueNode2, WhereNode } from "kysely";
|
|
1464
|
-
import invariant5 from "tiny-invariant";
|
|
1465
1465
|
import { match as match6 } from "ts-pattern";
|
|
1466
1466
|
|
|
1467
1467
|
// src/plugins/policy/expression-evaluator.ts
|
|
1468
|
-
import invariant4 from "
|
|
1468
|
+
import { invariant as invariant4 } from "@zenstackhq/common-helpers";
|
|
1469
1469
|
import { match as match5 } from "ts-pattern";
|
|
1470
1470
|
var ExpressionEvaluator = class {
|
|
1471
1471
|
static {
|
|
@@ -2385,7 +2385,7 @@ var PolicyPlugin = class {
|
|
|
2385
2385
|
};
|
|
2386
2386
|
|
|
2387
2387
|
// src/utils/clone.ts
|
|
2388
|
-
import { isPlainObject as isPlainObject2 } from "
|
|
2388
|
+
import { isPlainObject as isPlainObject2 } from "@zenstackhq/common-helpers";
|
|
2389
2389
|
function clone(value) {
|
|
2390
2390
|
if (Array.isArray(value)) {
|
|
2391
2391
|
return value.map((v) => clone(v));
|
|
@@ -3948,16 +3948,15 @@ var UpdateOperationHandler = class extends BaseOperationHandler {
|
|
|
3948
3948
|
import Decimal from "decimal.js";
|
|
3949
3949
|
import stableStringify from "json-stable-stringify";
|
|
3950
3950
|
import { match as match14, P as P2 } from "ts-pattern";
|
|
3951
|
-
import { z } from "zod";
|
|
3951
|
+
import { z } from "zod/v4";
|
|
3952
3952
|
var InputValidator = class {
|
|
3953
3953
|
static {
|
|
3954
3954
|
__name(this, "InputValidator");
|
|
3955
3955
|
}
|
|
3956
3956
|
schema;
|
|
3957
|
-
schemaCache;
|
|
3957
|
+
schemaCache = /* @__PURE__ */ new Map();
|
|
3958
3958
|
constructor(schema) {
|
|
3959
3959
|
this.schema = schema;
|
|
3960
|
-
this.schemaCache = /* @__PURE__ */ new Map();
|
|
3961
3960
|
}
|
|
3962
3961
|
validateFindArgs(model, unique, args) {
|
|
3963
3962
|
return this.validate(model, "find", {
|
|
@@ -4118,7 +4117,7 @@ var InputValidator = class {
|
|
|
4118
4117
|
}
|
|
4119
4118
|
}
|
|
4120
4119
|
}
|
|
4121
|
-
fields["$expr"] = z.
|
|
4120
|
+
fields["$expr"] = z.custom((v) => typeof v === "function").optional();
|
|
4122
4121
|
fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4123
4122
|
fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
|
|
4124
4123
|
fields["NOT"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
@@ -4925,11 +4924,11 @@ var QueryNameMapper = class extends OperationNodeTransformer2 {
|
|
|
4925
4924
|
__name(this, "QueryNameMapper");
|
|
4926
4925
|
}
|
|
4927
4926
|
schema;
|
|
4928
|
-
modelToTableMap;
|
|
4929
|
-
fieldToColumnMap;
|
|
4930
|
-
modelStack;
|
|
4927
|
+
modelToTableMap = /* @__PURE__ */ new Map();
|
|
4928
|
+
fieldToColumnMap = /* @__PURE__ */ new Map();
|
|
4929
|
+
modelStack = [];
|
|
4931
4930
|
constructor(schema) {
|
|
4932
|
-
super(), this.schema = schema
|
|
4931
|
+
super(), this.schema = schema;
|
|
4933
4932
|
for (const [modelName, modelDef] of Object.entries(schema.models)) {
|
|
4934
4933
|
const mappedName = this.getMappedName(modelDef);
|
|
4935
4934
|
if (mappedName) {
|
|
@@ -5386,8 +5385,8 @@ __export(functions_exports, {
|
|
|
5386
5385
|
search: () => search,
|
|
5387
5386
|
startsWith: () => startsWith
|
|
5388
5387
|
});
|
|
5388
|
+
import { invariant as invariant8, lowerCaseFirst, upperCaseFirst } from "@zenstackhq/common-helpers";
|
|
5389
5389
|
import { sql as sql8, ValueNode as ValueNode4 } from "kysely";
|
|
5390
|
-
import invariant8 from "tiny-invariant";
|
|
5391
5390
|
import { match as match16 } from "ts-pattern";
|
|
5392
5391
|
var contains = /* @__PURE__ */ __name((eb, args) => {
|
|
5393
5392
|
const [field, search2, caseInsensitive = false] = args;
|
|
@@ -5494,7 +5493,7 @@ var currentOperation = /* @__PURE__ */ __name((_eb, args, { operation }) => {
|
|
|
5494
5493
|
function processCasing(casing, result, model) {
|
|
5495
5494
|
const opNode = casing.toOperationNode();
|
|
5496
5495
|
invariant8(ValueNode4.is(opNode) && typeof opNode.value === "string", '"casting" parameter must be a string value');
|
|
5497
|
-
result = match16(opNode.value).with("original", () => model).with("upper", () => result.toUpperCase()).with("lower", () => result.toLowerCase()).with("capitalize", () =>
|
|
5496
|
+
result = match16(opNode.value).with("original", () => model).with("upper", () => result.toUpperCase()).with("lower", () => result.toLowerCase()).with("capitalize", () => upperCaseFirst(result)).with("uncapitalize", () => lowerCaseFirst(result)).otherwise(() => {
|
|
5498
5497
|
throw new Error(`Invalid casing value: ${opNode.value}. Must be "original", "upper", "lower", "capitalize", or "uncapitalize".`);
|
|
5499
5498
|
});
|
|
5500
5499
|
return result;
|
|
@@ -5502,8 +5501,8 @@ function processCasing(casing, result, model) {
|
|
|
5502
5501
|
__name(processCasing, "processCasing");
|
|
5503
5502
|
|
|
5504
5503
|
// src/client/helpers/schema-db-pusher.ts
|
|
5504
|
+
import { invariant as invariant9 } from "@zenstackhq/common-helpers";
|
|
5505
5505
|
import { sql as sql9 } from "kysely";
|
|
5506
|
-
import invariant9 from "tiny-invariant";
|
|
5507
5506
|
import { match as match17 } from "ts-pattern";
|
|
5508
5507
|
var SchemaDbPusher = class {
|
|
5509
5508
|
static {
|
|
@@ -5535,7 +5534,7 @@ var SchemaDbPusher = class {
|
|
|
5535
5534
|
for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) {
|
|
5536
5535
|
if (fieldDef.relation) {
|
|
5537
5536
|
table = this.addForeignKeyConstraint(table, model, fieldName, fieldDef);
|
|
5538
|
-
} else {
|
|
5537
|
+
} else if (!this.isComputedField(fieldDef)) {
|
|
5539
5538
|
table = this.createModelField(table, fieldName, fieldDef, modelDef);
|
|
5540
5539
|
}
|
|
5541
5540
|
}
|
|
@@ -5543,6 +5542,9 @@ var SchemaDbPusher = class {
|
|
|
5543
5542
|
table = this.addUniqueConstraint(table, modelDef);
|
|
5544
5543
|
return table;
|
|
5545
5544
|
}
|
|
5545
|
+
isComputedField(fieldDef) {
|
|
5546
|
+
return fieldDef.attributes?.some((a) => a.name === "@computed");
|
|
5547
|
+
}
|
|
5546
5548
|
addPrimaryKeyConstraint(table, model, modelDef) {
|
|
5547
5549
|
if (modelDef.idFields.length === 1) {
|
|
5548
5550
|
if (Object.values(modelDef.fields).some((f) => f.id)) {
|
|
@@ -5669,8 +5671,8 @@ function valueToPromise(thing) {
|
|
|
5669
5671
|
__name(valueToPromise, "valueToPromise");
|
|
5670
5672
|
|
|
5671
5673
|
// src/client/result-processor.ts
|
|
5674
|
+
import { invariant as invariant10 } from "@zenstackhq/common-helpers";
|
|
5672
5675
|
import Decimal2 from "decimal.js";
|
|
5673
|
-
import invariant10 from "tiny-invariant";
|
|
5674
5676
|
import { match as match18 } from "ts-pattern";
|
|
5675
5677
|
var ResultProcessor = class {
|
|
5676
5678
|
static {
|
|
@@ -5904,12 +5906,19 @@ var ClientImpl = class _ClientImpl {
|
|
|
5904
5906
|
const newOptions = {
|
|
5905
5907
|
...this.options,
|
|
5906
5908
|
plugins: [
|
|
5907
|
-
...this.options
|
|
5909
|
+
...this.options.plugins ?? [],
|
|
5908
5910
|
plugin
|
|
5909
5911
|
]
|
|
5910
5912
|
};
|
|
5911
5913
|
return new _ClientImpl(this.schema, newOptions, this);
|
|
5912
5914
|
}
|
|
5915
|
+
$unuse(pluginId) {
|
|
5916
|
+
const newOptions = {
|
|
5917
|
+
...this.options,
|
|
5918
|
+
plugins: this.options.plugins?.filter((p) => p.id !== pluginId)
|
|
5919
|
+
};
|
|
5920
|
+
return new _ClientImpl(this.schema, newOptions, this);
|
|
5921
|
+
}
|
|
5913
5922
|
$unuseAll() {
|
|
5914
5923
|
const newOptions = {
|
|
5915
5924
|
...this.options,
|
|
@@ -5965,22 +5974,31 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
5965
5974
|
}
|
|
5966
5975
|
return result;
|
|
5967
5976
|
}, "proceed");
|
|
5968
|
-
const context = {
|
|
5969
|
-
client,
|
|
5970
|
-
model,
|
|
5971
|
-
operation,
|
|
5972
|
-
queryArgs: args
|
|
5973
|
-
};
|
|
5974
5977
|
const plugins = [
|
|
5975
5978
|
...client.$options.plugins ?? []
|
|
5976
5979
|
];
|
|
5977
5980
|
for (const plugin of plugins) {
|
|
5978
|
-
if (plugin.onQuery) {
|
|
5979
|
-
const
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5981
|
+
if (plugin.onQuery && typeof plugin.onQuery === "object") {
|
|
5982
|
+
for (const [_model, modelHooks] of Object.entries(plugin.onQuery)) {
|
|
5983
|
+
if (_model === lowerCaseFirst2(model) || _model === "$allModels") {
|
|
5984
|
+
if (modelHooks && typeof modelHooks === "object") {
|
|
5985
|
+
for (const [op, opHooks] of Object.entries(modelHooks)) {
|
|
5986
|
+
if (op === operation || op === "$allOperations") {
|
|
5987
|
+
if (typeof opHooks === "function") {
|
|
5988
|
+
const _proceed = proceed;
|
|
5989
|
+
proceed = /* @__PURE__ */ __name(() => opHooks({
|
|
5990
|
+
client,
|
|
5991
|
+
model,
|
|
5992
|
+
operation,
|
|
5993
|
+
args,
|
|
5994
|
+
query: _proceed
|
|
5995
|
+
}), "proceed");
|
|
5996
|
+
}
|
|
5997
|
+
}
|
|
5998
|
+
}
|
|
5999
|
+
}
|
|
6000
|
+
}
|
|
6001
|
+
}
|
|
5984
6002
|
}
|
|
5985
6003
|
}
|
|
5986
6004
|
return proceed(args);
|