@zenstackhq/schema 3.0.0-beta.15
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/LICENSE +21 -0
- package/dist/index.cjs +116 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +194 -0
- package/dist/index.d.ts +194 -0
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ZenStack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
ExpressionUtils: () => ExpressionUtils
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
|
|
28
|
+
// src/expression-utils.ts
|
|
29
|
+
var ExpressionUtils = {
|
|
30
|
+
literal: /* @__PURE__ */ __name((value) => {
|
|
31
|
+
return {
|
|
32
|
+
kind: "literal",
|
|
33
|
+
value
|
|
34
|
+
};
|
|
35
|
+
}, "literal"),
|
|
36
|
+
array: /* @__PURE__ */ __name((items) => {
|
|
37
|
+
return {
|
|
38
|
+
kind: "array",
|
|
39
|
+
items
|
|
40
|
+
};
|
|
41
|
+
}, "array"),
|
|
42
|
+
call: /* @__PURE__ */ __name((functionName, args) => {
|
|
43
|
+
return {
|
|
44
|
+
kind: "call",
|
|
45
|
+
function: functionName,
|
|
46
|
+
args
|
|
47
|
+
};
|
|
48
|
+
}, "call"),
|
|
49
|
+
binary: /* @__PURE__ */ __name((left, op, right) => {
|
|
50
|
+
return {
|
|
51
|
+
kind: "binary",
|
|
52
|
+
op,
|
|
53
|
+
left,
|
|
54
|
+
right
|
|
55
|
+
};
|
|
56
|
+
}, "binary"),
|
|
57
|
+
unary: /* @__PURE__ */ __name((op, operand) => {
|
|
58
|
+
return {
|
|
59
|
+
kind: "unary",
|
|
60
|
+
op,
|
|
61
|
+
operand
|
|
62
|
+
};
|
|
63
|
+
}, "unary"),
|
|
64
|
+
field: /* @__PURE__ */ __name((field) => {
|
|
65
|
+
return {
|
|
66
|
+
kind: "field",
|
|
67
|
+
field
|
|
68
|
+
};
|
|
69
|
+
}, "field"),
|
|
70
|
+
member: /* @__PURE__ */ __name((receiver, members) => {
|
|
71
|
+
return {
|
|
72
|
+
kind: "member",
|
|
73
|
+
receiver,
|
|
74
|
+
members
|
|
75
|
+
};
|
|
76
|
+
}, "member"),
|
|
77
|
+
_this: /* @__PURE__ */ __name(() => {
|
|
78
|
+
return {
|
|
79
|
+
kind: "this"
|
|
80
|
+
};
|
|
81
|
+
}, "_this"),
|
|
82
|
+
_null: /* @__PURE__ */ __name(() => {
|
|
83
|
+
return {
|
|
84
|
+
kind: "null"
|
|
85
|
+
};
|
|
86
|
+
}, "_null"),
|
|
87
|
+
and: /* @__PURE__ */ __name((expr, ...expressions) => {
|
|
88
|
+
return expressions.reduce((acc, exp) => ExpressionUtils.binary(acc, "&&", exp), expr);
|
|
89
|
+
}, "and"),
|
|
90
|
+
or: /* @__PURE__ */ __name((expr, ...expressions) => {
|
|
91
|
+
return expressions.reduce((acc, exp) => ExpressionUtils.binary(acc, "||", exp), expr);
|
|
92
|
+
}, "or"),
|
|
93
|
+
not: /* @__PURE__ */ __name((expr) => {
|
|
94
|
+
return ExpressionUtils.unary("!", expr);
|
|
95
|
+
}, "not"),
|
|
96
|
+
is: /* @__PURE__ */ __name((value, kind) => {
|
|
97
|
+
return !!value && typeof value === "object" && "kind" in value && value.kind === kind;
|
|
98
|
+
}, "is"),
|
|
99
|
+
isLiteral: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "literal"), "isLiteral"),
|
|
100
|
+
isArray: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "array"), "isArray"),
|
|
101
|
+
isCall: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "call"), "isCall"),
|
|
102
|
+
isNull: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "null"), "isNull"),
|
|
103
|
+
isThis: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "this"), "isThis"),
|
|
104
|
+
isUnary: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "unary"), "isUnary"),
|
|
105
|
+
isBinary: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "binary"), "isBinary"),
|
|
106
|
+
isField: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "field"), "isField"),
|
|
107
|
+
isMember: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "member"), "isMember"),
|
|
108
|
+
getLiteralValue: /* @__PURE__ */ __name((expr) => {
|
|
109
|
+
return ExpressionUtils.isLiteral(expr) ? expr.value : void 0;
|
|
110
|
+
}, "getLiteralValue")
|
|
111
|
+
};
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
ExpressionUtils
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/expression-utils.ts"],"sourcesContent":["export type * from './expression';\nexport * from './expression-utils';\nexport type * from './schema';\n","import type {\n ArrayExpression,\n BinaryExpression,\n BinaryOperator,\n CallExpression,\n Expression,\n FieldExpression,\n LiteralExpression,\n MemberExpression,\n NullExpression,\n ThisExpression,\n UnaryExpression,\n UnaryOperator,\n} from './expression';\n\n/**\n * Utility functions to create and work with Expression objects\n */\nexport const ExpressionUtils = {\n literal: (value: string | number | boolean): LiteralExpression => {\n return {\n kind: 'literal',\n value,\n };\n },\n\n array: (items: Expression[]): ArrayExpression => {\n return {\n kind: 'array',\n items,\n };\n },\n\n call: (functionName: string, args?: Expression[]): CallExpression => {\n return {\n kind: 'call',\n function: functionName,\n args,\n };\n },\n\n binary: (left: Expression, op: BinaryOperator, right: Expression): BinaryExpression => {\n return {\n kind: 'binary',\n op,\n left,\n right,\n };\n },\n\n unary: (op: UnaryOperator, operand: Expression): UnaryExpression => {\n return {\n kind: 'unary',\n op,\n operand,\n };\n },\n\n field: (field: string): FieldExpression => {\n return {\n kind: 'field',\n field,\n };\n },\n\n member: (receiver: Expression, members: string[]): MemberExpression => {\n return {\n kind: 'member',\n receiver: receiver,\n members,\n };\n },\n\n _this: (): ThisExpression => {\n return {\n kind: 'this',\n };\n },\n\n _null: (): NullExpression => {\n return {\n kind: 'null',\n };\n },\n\n and: (expr: Expression, ...expressions: Expression[]) => {\n return expressions.reduce((acc, exp) => ExpressionUtils.binary(acc, '&&', exp), expr);\n },\n\n or: (expr: Expression, ...expressions: Expression[]) => {\n return expressions.reduce((acc, exp) => ExpressionUtils.binary(acc, '||', exp), expr);\n },\n\n not: (expr: Expression) => {\n return ExpressionUtils.unary('!', expr);\n },\n\n is: (value: unknown, kind: Expression['kind']): value is Expression => {\n return !!value && typeof value === 'object' && 'kind' in value && value.kind === kind;\n },\n\n isLiteral: (value: unknown): value is LiteralExpression => ExpressionUtils.is(value, 'literal'),\n\n isArray: (value: unknown): value is ArrayExpression => ExpressionUtils.is(value, 'array'),\n\n isCall: (value: unknown): value is CallExpression => ExpressionUtils.is(value, 'call'),\n\n isNull: (value: unknown): value is NullExpression => ExpressionUtils.is(value, 'null'),\n\n isThis: (value: unknown): value is ThisExpression => ExpressionUtils.is(value, 'this'),\n\n isUnary: (value: unknown): value is UnaryExpression => ExpressionUtils.is(value, 'unary'),\n\n isBinary: (value: unknown): value is BinaryExpression => ExpressionUtils.is(value, 'binary'),\n\n isField: (value: unknown): value is FieldExpression => ExpressionUtils.is(value, 'field'),\n\n isMember: (value: unknown): value is MemberExpression => ExpressionUtils.is(value, 'member'),\n\n getLiteralValue: (expr: Expression): string | number | boolean | undefined => {\n return ExpressionUtils.isLiteral(expr) ? expr.value : undefined;\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;ACiBO,IAAMA,kBAAkB;EAC3BC,SAAS,wBAACC,UAAAA;AACN,WAAO;MACHC,MAAM;MACND;IACJ;EACJ,GALS;EAOTE,OAAO,wBAACC,UAAAA;AACJ,WAAO;MACHF,MAAM;MACNE;IACJ;EACJ,GALO;EAOPC,MAAM,wBAACC,cAAsBC,SAAAA;AACzB,WAAO;MACHL,MAAM;MACNM,UAAUF;MACVC;IACJ;EACJ,GANM;EAQNE,QAAQ,wBAACC,MAAkBC,IAAoBC,UAAAA;AAC3C,WAAO;MACHV,MAAM;MACNS;MACAD;MACAE;IACJ;EACJ,GAPQ;EASRC,OAAO,wBAACF,IAAmBG,YAAAA;AACvB,WAAO;MACHZ,MAAM;MACNS;MACAG;IACJ;EACJ,GANO;EAQPC,OAAO,wBAACA,UAAAA;AACJ,WAAO;MACHb,MAAM;MACNa;IACJ;EACJ,GALO;EAOPC,QAAQ,wBAACC,UAAsBC,YAAAA;AAC3B,WAAO;MACHhB,MAAM;MACNe;MACAC;IACJ;EACJ,GANQ;EAQRC,OAAO,6BAAA;AACH,WAAO;MACHjB,MAAM;IACV;EACJ,GAJO;EAMPkB,OAAO,6BAAA;AACH,WAAO;MACHlB,MAAM;IACV;EACJ,GAJO;EAMPmB,KAAK,wBAACC,SAAqBC,gBAAAA;AACvB,WAAOA,YAAYC,OAAO,CAACC,KAAKC,QAAQ3B,gBAAgBU,OAAOgB,KAAK,MAAMC,GAAAA,GAAMJ,IAAAA;EACpF,GAFK;EAILK,IAAI,wBAACL,SAAqBC,gBAAAA;AACtB,WAAOA,YAAYC,OAAO,CAACC,KAAKC,QAAQ3B,gBAAgBU,OAAOgB,KAAK,MAAMC,GAAAA,GAAMJ,IAAAA;EACpF,GAFI;EAIJM,KAAK,wBAACN,SAAAA;AACF,WAAOvB,gBAAgBc,MAAM,KAAKS,IAAAA;EACtC,GAFK;EAILO,IAAI,wBAAC5B,OAAgBC,SAAAA;AACjB,WAAO,CAAC,CAACD,SAAS,OAAOA,UAAU,YAAY,UAAUA,SAASA,MAAMC,SAASA;EACrF,GAFI;EAIJ4B,WAAW,wBAAC7B,UAA+CF,gBAAgB8B,GAAG5B,OAAO,SAAA,GAA1E;EAEX8B,SAAS,wBAAC9B,UAA6CF,gBAAgB8B,GAAG5B,OAAO,OAAA,GAAxE;EAET+B,QAAQ,wBAAC/B,UAA4CF,gBAAgB8B,GAAG5B,OAAO,MAAA,GAAvE;EAERgC,QAAQ,wBAAChC,UAA4CF,gBAAgB8B,GAAG5B,OAAO,MAAA,GAAvE;EAERiC,QAAQ,wBAACjC,UAA4CF,gBAAgB8B,GAAG5B,OAAO,MAAA,GAAvE;EAERkC,SAAS,wBAAClC,UAA6CF,gBAAgB8B,GAAG5B,OAAO,OAAA,GAAxE;EAETmC,UAAU,wBAACnC,UAA8CF,gBAAgB8B,GAAG5B,OAAO,QAAA,GAAzE;EAEVoC,SAAS,wBAACpC,UAA6CF,gBAAgB8B,GAAG5B,OAAO,OAAA,GAAxE;EAETqC,UAAU,wBAACrC,UAA8CF,gBAAgB8B,GAAG5B,OAAO,QAAA,GAAzE;EAEVsC,iBAAiB,wBAACjB,SAAAA;AACd,WAAOvB,gBAAgB+B,UAAUR,IAAAA,IAAQA,KAAKrB,QAAQuC;EAC1D,GAFiB;AAGrB;","names":["ExpressionUtils","literal","value","kind","array","items","call","functionName","args","function","binary","left","op","right","unary","operand","field","member","receiver","members","_this","_null","and","expr","expressions","reduce","acc","exp","or","not","is","isLiteral","isArray","isCall","isNull","isThis","isUnary","isBinary","isField","isMember","getLiteralValue","undefined"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
|
|
3
|
+
type Expression = LiteralExpression | ArrayExpression | FieldExpression | MemberExpression | CallExpression | UnaryExpression | BinaryExpression | ThisExpression | NullExpression;
|
|
4
|
+
type LiteralExpression = {
|
|
5
|
+
kind: 'literal';
|
|
6
|
+
value: string | number | boolean;
|
|
7
|
+
};
|
|
8
|
+
type ArrayExpression = {
|
|
9
|
+
kind: 'array';
|
|
10
|
+
items: Expression[];
|
|
11
|
+
};
|
|
12
|
+
type FieldExpression = {
|
|
13
|
+
kind: 'field';
|
|
14
|
+
field: string;
|
|
15
|
+
};
|
|
16
|
+
type MemberExpression = {
|
|
17
|
+
kind: 'member';
|
|
18
|
+
receiver: Expression;
|
|
19
|
+
members: string[];
|
|
20
|
+
};
|
|
21
|
+
type UnaryExpression = {
|
|
22
|
+
kind: 'unary';
|
|
23
|
+
op: UnaryOperator;
|
|
24
|
+
operand: Expression;
|
|
25
|
+
};
|
|
26
|
+
type BinaryExpression = {
|
|
27
|
+
kind: 'binary';
|
|
28
|
+
op: BinaryOperator;
|
|
29
|
+
left: Expression;
|
|
30
|
+
right: Expression;
|
|
31
|
+
};
|
|
32
|
+
type CallExpression = {
|
|
33
|
+
kind: 'call';
|
|
34
|
+
function: string;
|
|
35
|
+
args?: Expression[];
|
|
36
|
+
};
|
|
37
|
+
type ThisExpression = {
|
|
38
|
+
kind: 'this';
|
|
39
|
+
};
|
|
40
|
+
type NullExpression = {
|
|
41
|
+
kind: 'null';
|
|
42
|
+
};
|
|
43
|
+
type UnaryOperator = '!';
|
|
44
|
+
type BinaryOperator = '&&' | '||' | '==' | '!=' | '<' | '<=' | '>' | '>=' | '?' | '!' | '^' | 'in';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Utility functions to create and work with Expression objects
|
|
48
|
+
*/
|
|
49
|
+
declare const ExpressionUtils: {
|
|
50
|
+
literal: (value: string | number | boolean) => LiteralExpression;
|
|
51
|
+
array: (items: Expression[]) => ArrayExpression;
|
|
52
|
+
call: (functionName: string, args?: Expression[]) => CallExpression;
|
|
53
|
+
binary: (left: Expression, op: BinaryOperator, right: Expression) => BinaryExpression;
|
|
54
|
+
unary: (op: UnaryOperator, operand: Expression) => UnaryExpression;
|
|
55
|
+
field: (field: string) => FieldExpression;
|
|
56
|
+
member: (receiver: Expression, members: string[]) => MemberExpression;
|
|
57
|
+
_this: () => ThisExpression;
|
|
58
|
+
_null: () => NullExpression;
|
|
59
|
+
and: (expr: Expression, ...expressions: Expression[]) => Expression;
|
|
60
|
+
or: (expr: Expression, ...expressions: Expression[]) => Expression;
|
|
61
|
+
not: (expr: Expression) => UnaryExpression;
|
|
62
|
+
is: (value: unknown, kind: Expression["kind"]) => value is Expression;
|
|
63
|
+
isLiteral: (value: unknown) => value is LiteralExpression;
|
|
64
|
+
isArray: (value: unknown) => value is ArrayExpression;
|
|
65
|
+
isCall: (value: unknown) => value is CallExpression;
|
|
66
|
+
isNull: (value: unknown) => value is NullExpression;
|
|
67
|
+
isThis: (value: unknown) => value is ThisExpression;
|
|
68
|
+
isUnary: (value: unknown) => value is UnaryExpression;
|
|
69
|
+
isBinary: (value: unknown) => value is BinaryExpression;
|
|
70
|
+
isField: (value: unknown) => value is FieldExpression;
|
|
71
|
+
isMember: (value: unknown) => value is MemberExpression;
|
|
72
|
+
getLiteralValue: (expr: Expression) => string | number | boolean | undefined;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
type DataSourceProviderType = 'sqlite' | 'postgresql';
|
|
76
|
+
type DataSourceProvider = {
|
|
77
|
+
type: DataSourceProviderType;
|
|
78
|
+
};
|
|
79
|
+
type SchemaDef = {
|
|
80
|
+
provider: DataSourceProvider;
|
|
81
|
+
models: Record<string, ModelDef>;
|
|
82
|
+
enums?: Record<string, EnumDef>;
|
|
83
|
+
typeDefs?: Record<string, TypeDefDef>;
|
|
84
|
+
plugins: Record<string, unknown>;
|
|
85
|
+
procedures?: Record<string, ProcedureDef>;
|
|
86
|
+
authType?: GetModels<SchemaDef>;
|
|
87
|
+
};
|
|
88
|
+
type ModelDef = {
|
|
89
|
+
name: string;
|
|
90
|
+
baseModel?: string;
|
|
91
|
+
fields: Record<string, FieldDef>;
|
|
92
|
+
attributes?: AttributeApplication[];
|
|
93
|
+
uniqueFields: Record<string, Pick<FieldDef, 'type'> | Record<string, Pick<FieldDef, 'type'>>>;
|
|
94
|
+
idFields: string[];
|
|
95
|
+
computedFields?: Record<string, Function>;
|
|
96
|
+
isDelegate?: boolean;
|
|
97
|
+
subModels?: string[];
|
|
98
|
+
isView?: boolean;
|
|
99
|
+
};
|
|
100
|
+
type AttributeApplication = {
|
|
101
|
+
name: string;
|
|
102
|
+
args?: AttributeArg[];
|
|
103
|
+
};
|
|
104
|
+
type AttributeArg = {
|
|
105
|
+
name?: string;
|
|
106
|
+
value: Expression;
|
|
107
|
+
};
|
|
108
|
+
type CascadeAction = 'SetNull' | 'Cascade' | 'Restrict' | 'NoAction' | 'SetDefault';
|
|
109
|
+
type RelationInfo = {
|
|
110
|
+
name?: string;
|
|
111
|
+
fields?: string[];
|
|
112
|
+
references?: string[];
|
|
113
|
+
opposite?: string;
|
|
114
|
+
onDelete?: CascadeAction;
|
|
115
|
+
onUpdate?: CascadeAction;
|
|
116
|
+
};
|
|
117
|
+
type FieldDef = {
|
|
118
|
+
name: string;
|
|
119
|
+
type: string;
|
|
120
|
+
id?: boolean;
|
|
121
|
+
array?: boolean;
|
|
122
|
+
optional?: boolean;
|
|
123
|
+
unique?: boolean;
|
|
124
|
+
updatedAt?: boolean;
|
|
125
|
+
attributes?: AttributeApplication[];
|
|
126
|
+
default?: MappedBuiltinType | Expression | unknown[];
|
|
127
|
+
relation?: RelationInfo;
|
|
128
|
+
foreignKeyFor?: string[];
|
|
129
|
+
computed?: boolean;
|
|
130
|
+
originModel?: string;
|
|
131
|
+
isDiscriminator?: boolean;
|
|
132
|
+
};
|
|
133
|
+
type ProcedureParam = {
|
|
134
|
+
name: string;
|
|
135
|
+
type: string;
|
|
136
|
+
optional?: boolean;
|
|
137
|
+
};
|
|
138
|
+
type ProcedureDef = {
|
|
139
|
+
params: [...ProcedureParam[]];
|
|
140
|
+
returnType: string;
|
|
141
|
+
mutation?: boolean;
|
|
142
|
+
};
|
|
143
|
+
type BuiltinType = 'String' | 'Boolean' | 'Int' | 'Float' | 'BigInt' | 'Decimal' | 'DateTime' | 'Bytes' | 'Json' | 'Unsupported';
|
|
144
|
+
type MappedBuiltinType = string | boolean | number | bigint | Decimal | Date;
|
|
145
|
+
type EnumDef = Record<string, string>;
|
|
146
|
+
type TypeDefDef = {
|
|
147
|
+
name: string;
|
|
148
|
+
fields: Record<string, FieldDef>;
|
|
149
|
+
attributes?: AttributeApplication[];
|
|
150
|
+
};
|
|
151
|
+
type GetModels<Schema extends SchemaDef> = Extract<keyof Schema['models'], string>;
|
|
152
|
+
type GetDelegateModels<Schema extends SchemaDef> = keyof {
|
|
153
|
+
[Key in GetModels<Schema> as Schema['models'][Key]['isDelegate'] extends true ? Key : never]: true;
|
|
154
|
+
};
|
|
155
|
+
type GetSubModels<Schema extends SchemaDef, Model extends GetModels<Schema>> = GetModel<Schema, Model>['subModels'] extends string[] ? Extract<GetModel<Schema, Model>['subModels'][number], GetModels<Schema>> : never;
|
|
156
|
+
type GetModel<Schema extends SchemaDef, Model extends GetModels<Schema>> = Schema['models'][Model];
|
|
157
|
+
type GetEnums<Schema extends SchemaDef> = keyof Schema['enums'];
|
|
158
|
+
type GetEnum<Schema extends SchemaDef, Enum extends GetEnums<Schema>> = Schema['enums'][Enum];
|
|
159
|
+
type GetTypeDefs<Schema extends SchemaDef> = Extract<keyof Schema['typeDefs'], string>;
|
|
160
|
+
type GetTypeDef<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>> = Schema['typeDefs'] extends Record<string, unknown> ? Schema['typeDefs'][TypeDef] : never;
|
|
161
|
+
type GetModelFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = Extract<keyof GetModel<Schema, Model>['fields'], string>;
|
|
162
|
+
type GetModelField<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModel<Schema, Model>['fields'][Field];
|
|
163
|
+
type GetModelDiscriminator<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
|
|
164
|
+
[Key in GetModelFields<Schema, Model> as FieldIsDelegateDiscriminator<Schema, Model, Key> extends true ? GetModelField<Schema, Model, Key>['originModel'] extends string ? never : Key : never]: true;
|
|
165
|
+
};
|
|
166
|
+
type GetModelFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = Schema['models'][Model]['fields'][Field]['type'];
|
|
167
|
+
type GetTypeDefFields<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>> = Extract<keyof GetTypeDef<Schema, TypeDef>['fields'], string>;
|
|
168
|
+
type GetTypeDefField<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Field extends GetTypeDefFields<Schema, TypeDef>> = GetTypeDef<Schema, TypeDef>['fields'][Field];
|
|
169
|
+
type ScalarFields<Schema extends SchemaDef, Model extends GetModels<Schema>, IncludeComputed extends boolean = true> = keyof {
|
|
170
|
+
[Key in GetModelFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends object ? never : GetModelField<Schema, Model, Key>['foreignKeyFor'] extends string[] ? never : IncludeComputed extends true ? Key : FieldIsComputed<Schema, Model, Key> extends true ? never : Key]: Key;
|
|
171
|
+
};
|
|
172
|
+
type ForeignKeyFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
|
|
173
|
+
[Key in GetModelFields<Schema, Model> as GetModelField<Schema, Model, Key>['foreignKeyFor'] extends string[] ? Key : never]: Key;
|
|
174
|
+
};
|
|
175
|
+
type NonRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
|
|
176
|
+
[Key in GetModelFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends object ? never : Key]: Key;
|
|
177
|
+
};
|
|
178
|
+
type RelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
|
|
179
|
+
[Key in GetModelFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends object ? Key : never]: Key;
|
|
180
|
+
};
|
|
181
|
+
type FieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['type'];
|
|
182
|
+
type RelationFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = GetModelField<Schema, Model, Field>['type'] extends GetModels<Schema> ? GetModelField<Schema, Model, Field>['type'] : never;
|
|
183
|
+
type ModelFieldIsOptional<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['optional'] extends true ? true : false;
|
|
184
|
+
type TypeDefFieldIsOptional<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Field extends GetTypeDefFields<Schema, TypeDef>> = GetTypeDefField<Schema, TypeDef, Field>['optional'] extends true ? true : false;
|
|
185
|
+
type FieldIsRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['relation'] extends object ? true : false;
|
|
186
|
+
type FieldIsArray<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['array'] extends true ? true : false;
|
|
187
|
+
type FieldIsComputed<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['computed'] extends true ? true : false;
|
|
188
|
+
type FieldHasDefault<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['default'] extends object | number | string | boolean ? true : GetModelField<Schema, Model, Field>['updatedAt'] extends true ? true : false;
|
|
189
|
+
type FieldIsRelationArray<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = FieldIsRelation<Schema, Model, Field> extends true ? FieldIsArray<Schema, Model, Field> : false;
|
|
190
|
+
type IsDelegateModel<Schema extends SchemaDef, Model extends GetModels<Schema>> = Schema['models'][Model]['isDelegate'] extends true ? true : false;
|
|
191
|
+
type FieldIsDelegateRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = GetModelFieldType<Schema, Model, Field> extends GetModels<Schema> ? IsDelegateModel<Schema, GetModelFieldType<Schema, Model, Field>> : false;
|
|
192
|
+
type FieldIsDelegateDiscriminator<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['isDiscriminator'] extends true ? true : false;
|
|
193
|
+
|
|
194
|
+
export { type ArrayExpression, type AttributeApplication, type AttributeArg, type BinaryExpression, type BinaryOperator, type BuiltinType, type CallExpression, type CascadeAction, type DataSourceProvider, type DataSourceProviderType, type EnumDef, type Expression, ExpressionUtils, type FieldDef, type FieldExpression, type FieldHasDefault, type FieldIsArray, type FieldIsComputed, type FieldIsDelegateDiscriminator, type FieldIsDelegateRelation, type FieldIsRelation, type FieldIsRelationArray, type FieldType, type ForeignKeyFields, type GetDelegateModels, type GetEnum, type GetEnums, type GetModel, type GetModelDiscriminator, type GetModelField, type GetModelFieldType, type GetModelFields, type GetModels, type GetSubModels, type GetTypeDef, type GetTypeDefField, type GetTypeDefFields, type GetTypeDefs, type IsDelegateModel, type LiteralExpression, type MappedBuiltinType, type MemberExpression, type ModelDef, type ModelFieldIsOptional, type NonRelationFields, type NullExpression, type ProcedureDef, type ProcedureParam, type RelationFieldType, type RelationFields, type RelationInfo, type ScalarFields, type SchemaDef, type ThisExpression, type TypeDefDef, type TypeDefFieldIsOptional, type UnaryExpression, type UnaryOperator };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
|
|
3
|
+
type Expression = LiteralExpression | ArrayExpression | FieldExpression | MemberExpression | CallExpression | UnaryExpression | BinaryExpression | ThisExpression | NullExpression;
|
|
4
|
+
type LiteralExpression = {
|
|
5
|
+
kind: 'literal';
|
|
6
|
+
value: string | number | boolean;
|
|
7
|
+
};
|
|
8
|
+
type ArrayExpression = {
|
|
9
|
+
kind: 'array';
|
|
10
|
+
items: Expression[];
|
|
11
|
+
};
|
|
12
|
+
type FieldExpression = {
|
|
13
|
+
kind: 'field';
|
|
14
|
+
field: string;
|
|
15
|
+
};
|
|
16
|
+
type MemberExpression = {
|
|
17
|
+
kind: 'member';
|
|
18
|
+
receiver: Expression;
|
|
19
|
+
members: string[];
|
|
20
|
+
};
|
|
21
|
+
type UnaryExpression = {
|
|
22
|
+
kind: 'unary';
|
|
23
|
+
op: UnaryOperator;
|
|
24
|
+
operand: Expression;
|
|
25
|
+
};
|
|
26
|
+
type BinaryExpression = {
|
|
27
|
+
kind: 'binary';
|
|
28
|
+
op: BinaryOperator;
|
|
29
|
+
left: Expression;
|
|
30
|
+
right: Expression;
|
|
31
|
+
};
|
|
32
|
+
type CallExpression = {
|
|
33
|
+
kind: 'call';
|
|
34
|
+
function: string;
|
|
35
|
+
args?: Expression[];
|
|
36
|
+
};
|
|
37
|
+
type ThisExpression = {
|
|
38
|
+
kind: 'this';
|
|
39
|
+
};
|
|
40
|
+
type NullExpression = {
|
|
41
|
+
kind: 'null';
|
|
42
|
+
};
|
|
43
|
+
type UnaryOperator = '!';
|
|
44
|
+
type BinaryOperator = '&&' | '||' | '==' | '!=' | '<' | '<=' | '>' | '>=' | '?' | '!' | '^' | 'in';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Utility functions to create and work with Expression objects
|
|
48
|
+
*/
|
|
49
|
+
declare const ExpressionUtils: {
|
|
50
|
+
literal: (value: string | number | boolean) => LiteralExpression;
|
|
51
|
+
array: (items: Expression[]) => ArrayExpression;
|
|
52
|
+
call: (functionName: string, args?: Expression[]) => CallExpression;
|
|
53
|
+
binary: (left: Expression, op: BinaryOperator, right: Expression) => BinaryExpression;
|
|
54
|
+
unary: (op: UnaryOperator, operand: Expression) => UnaryExpression;
|
|
55
|
+
field: (field: string) => FieldExpression;
|
|
56
|
+
member: (receiver: Expression, members: string[]) => MemberExpression;
|
|
57
|
+
_this: () => ThisExpression;
|
|
58
|
+
_null: () => NullExpression;
|
|
59
|
+
and: (expr: Expression, ...expressions: Expression[]) => Expression;
|
|
60
|
+
or: (expr: Expression, ...expressions: Expression[]) => Expression;
|
|
61
|
+
not: (expr: Expression) => UnaryExpression;
|
|
62
|
+
is: (value: unknown, kind: Expression["kind"]) => value is Expression;
|
|
63
|
+
isLiteral: (value: unknown) => value is LiteralExpression;
|
|
64
|
+
isArray: (value: unknown) => value is ArrayExpression;
|
|
65
|
+
isCall: (value: unknown) => value is CallExpression;
|
|
66
|
+
isNull: (value: unknown) => value is NullExpression;
|
|
67
|
+
isThis: (value: unknown) => value is ThisExpression;
|
|
68
|
+
isUnary: (value: unknown) => value is UnaryExpression;
|
|
69
|
+
isBinary: (value: unknown) => value is BinaryExpression;
|
|
70
|
+
isField: (value: unknown) => value is FieldExpression;
|
|
71
|
+
isMember: (value: unknown) => value is MemberExpression;
|
|
72
|
+
getLiteralValue: (expr: Expression) => string | number | boolean | undefined;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
type DataSourceProviderType = 'sqlite' | 'postgresql';
|
|
76
|
+
type DataSourceProvider = {
|
|
77
|
+
type: DataSourceProviderType;
|
|
78
|
+
};
|
|
79
|
+
type SchemaDef = {
|
|
80
|
+
provider: DataSourceProvider;
|
|
81
|
+
models: Record<string, ModelDef>;
|
|
82
|
+
enums?: Record<string, EnumDef>;
|
|
83
|
+
typeDefs?: Record<string, TypeDefDef>;
|
|
84
|
+
plugins: Record<string, unknown>;
|
|
85
|
+
procedures?: Record<string, ProcedureDef>;
|
|
86
|
+
authType?: GetModels<SchemaDef>;
|
|
87
|
+
};
|
|
88
|
+
type ModelDef = {
|
|
89
|
+
name: string;
|
|
90
|
+
baseModel?: string;
|
|
91
|
+
fields: Record<string, FieldDef>;
|
|
92
|
+
attributes?: AttributeApplication[];
|
|
93
|
+
uniqueFields: Record<string, Pick<FieldDef, 'type'> | Record<string, Pick<FieldDef, 'type'>>>;
|
|
94
|
+
idFields: string[];
|
|
95
|
+
computedFields?: Record<string, Function>;
|
|
96
|
+
isDelegate?: boolean;
|
|
97
|
+
subModels?: string[];
|
|
98
|
+
isView?: boolean;
|
|
99
|
+
};
|
|
100
|
+
type AttributeApplication = {
|
|
101
|
+
name: string;
|
|
102
|
+
args?: AttributeArg[];
|
|
103
|
+
};
|
|
104
|
+
type AttributeArg = {
|
|
105
|
+
name?: string;
|
|
106
|
+
value: Expression;
|
|
107
|
+
};
|
|
108
|
+
type CascadeAction = 'SetNull' | 'Cascade' | 'Restrict' | 'NoAction' | 'SetDefault';
|
|
109
|
+
type RelationInfo = {
|
|
110
|
+
name?: string;
|
|
111
|
+
fields?: string[];
|
|
112
|
+
references?: string[];
|
|
113
|
+
opposite?: string;
|
|
114
|
+
onDelete?: CascadeAction;
|
|
115
|
+
onUpdate?: CascadeAction;
|
|
116
|
+
};
|
|
117
|
+
type FieldDef = {
|
|
118
|
+
name: string;
|
|
119
|
+
type: string;
|
|
120
|
+
id?: boolean;
|
|
121
|
+
array?: boolean;
|
|
122
|
+
optional?: boolean;
|
|
123
|
+
unique?: boolean;
|
|
124
|
+
updatedAt?: boolean;
|
|
125
|
+
attributes?: AttributeApplication[];
|
|
126
|
+
default?: MappedBuiltinType | Expression | unknown[];
|
|
127
|
+
relation?: RelationInfo;
|
|
128
|
+
foreignKeyFor?: string[];
|
|
129
|
+
computed?: boolean;
|
|
130
|
+
originModel?: string;
|
|
131
|
+
isDiscriminator?: boolean;
|
|
132
|
+
};
|
|
133
|
+
type ProcedureParam = {
|
|
134
|
+
name: string;
|
|
135
|
+
type: string;
|
|
136
|
+
optional?: boolean;
|
|
137
|
+
};
|
|
138
|
+
type ProcedureDef = {
|
|
139
|
+
params: [...ProcedureParam[]];
|
|
140
|
+
returnType: string;
|
|
141
|
+
mutation?: boolean;
|
|
142
|
+
};
|
|
143
|
+
type BuiltinType = 'String' | 'Boolean' | 'Int' | 'Float' | 'BigInt' | 'Decimal' | 'DateTime' | 'Bytes' | 'Json' | 'Unsupported';
|
|
144
|
+
type MappedBuiltinType = string | boolean | number | bigint | Decimal | Date;
|
|
145
|
+
type EnumDef = Record<string, string>;
|
|
146
|
+
type TypeDefDef = {
|
|
147
|
+
name: string;
|
|
148
|
+
fields: Record<string, FieldDef>;
|
|
149
|
+
attributes?: AttributeApplication[];
|
|
150
|
+
};
|
|
151
|
+
type GetModels<Schema extends SchemaDef> = Extract<keyof Schema['models'], string>;
|
|
152
|
+
type GetDelegateModels<Schema extends SchemaDef> = keyof {
|
|
153
|
+
[Key in GetModels<Schema> as Schema['models'][Key]['isDelegate'] extends true ? Key : never]: true;
|
|
154
|
+
};
|
|
155
|
+
type GetSubModels<Schema extends SchemaDef, Model extends GetModels<Schema>> = GetModel<Schema, Model>['subModels'] extends string[] ? Extract<GetModel<Schema, Model>['subModels'][number], GetModels<Schema>> : never;
|
|
156
|
+
type GetModel<Schema extends SchemaDef, Model extends GetModels<Schema>> = Schema['models'][Model];
|
|
157
|
+
type GetEnums<Schema extends SchemaDef> = keyof Schema['enums'];
|
|
158
|
+
type GetEnum<Schema extends SchemaDef, Enum extends GetEnums<Schema>> = Schema['enums'][Enum];
|
|
159
|
+
type GetTypeDefs<Schema extends SchemaDef> = Extract<keyof Schema['typeDefs'], string>;
|
|
160
|
+
type GetTypeDef<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>> = Schema['typeDefs'] extends Record<string, unknown> ? Schema['typeDefs'][TypeDef] : never;
|
|
161
|
+
type GetModelFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = Extract<keyof GetModel<Schema, Model>['fields'], string>;
|
|
162
|
+
type GetModelField<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModel<Schema, Model>['fields'][Field];
|
|
163
|
+
type GetModelDiscriminator<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
|
|
164
|
+
[Key in GetModelFields<Schema, Model> as FieldIsDelegateDiscriminator<Schema, Model, Key> extends true ? GetModelField<Schema, Model, Key>['originModel'] extends string ? never : Key : never]: true;
|
|
165
|
+
};
|
|
166
|
+
type GetModelFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = Schema['models'][Model]['fields'][Field]['type'];
|
|
167
|
+
type GetTypeDefFields<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>> = Extract<keyof GetTypeDef<Schema, TypeDef>['fields'], string>;
|
|
168
|
+
type GetTypeDefField<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Field extends GetTypeDefFields<Schema, TypeDef>> = GetTypeDef<Schema, TypeDef>['fields'][Field];
|
|
169
|
+
type ScalarFields<Schema extends SchemaDef, Model extends GetModels<Schema>, IncludeComputed extends boolean = true> = keyof {
|
|
170
|
+
[Key in GetModelFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends object ? never : GetModelField<Schema, Model, Key>['foreignKeyFor'] extends string[] ? never : IncludeComputed extends true ? Key : FieldIsComputed<Schema, Model, Key> extends true ? never : Key]: Key;
|
|
171
|
+
};
|
|
172
|
+
type ForeignKeyFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
|
|
173
|
+
[Key in GetModelFields<Schema, Model> as GetModelField<Schema, Model, Key>['foreignKeyFor'] extends string[] ? Key : never]: Key;
|
|
174
|
+
};
|
|
175
|
+
type NonRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
|
|
176
|
+
[Key in GetModelFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends object ? never : Key]: Key;
|
|
177
|
+
};
|
|
178
|
+
type RelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
|
|
179
|
+
[Key in GetModelFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends object ? Key : never]: Key;
|
|
180
|
+
};
|
|
181
|
+
type FieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['type'];
|
|
182
|
+
type RelationFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = GetModelField<Schema, Model, Field>['type'] extends GetModels<Schema> ? GetModelField<Schema, Model, Field>['type'] : never;
|
|
183
|
+
type ModelFieldIsOptional<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['optional'] extends true ? true : false;
|
|
184
|
+
type TypeDefFieldIsOptional<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Field extends GetTypeDefFields<Schema, TypeDef>> = GetTypeDefField<Schema, TypeDef, Field>['optional'] extends true ? true : false;
|
|
185
|
+
type FieldIsRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['relation'] extends object ? true : false;
|
|
186
|
+
type FieldIsArray<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['array'] extends true ? true : false;
|
|
187
|
+
type FieldIsComputed<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['computed'] extends true ? true : false;
|
|
188
|
+
type FieldHasDefault<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['default'] extends object | number | string | boolean ? true : GetModelField<Schema, Model, Field>['updatedAt'] extends true ? true : false;
|
|
189
|
+
type FieldIsRelationArray<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = FieldIsRelation<Schema, Model, Field> extends true ? FieldIsArray<Schema, Model, Field> : false;
|
|
190
|
+
type IsDelegateModel<Schema extends SchemaDef, Model extends GetModels<Schema>> = Schema['models'][Model]['isDelegate'] extends true ? true : false;
|
|
191
|
+
type FieldIsDelegateRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = GetModelFieldType<Schema, Model, Field> extends GetModels<Schema> ? IsDelegateModel<Schema, GetModelFieldType<Schema, Model, Field>> : false;
|
|
192
|
+
type FieldIsDelegateDiscriminator<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['isDiscriminator'] extends true ? true : false;
|
|
193
|
+
|
|
194
|
+
export { type ArrayExpression, type AttributeApplication, type AttributeArg, type BinaryExpression, type BinaryOperator, type BuiltinType, type CallExpression, type CascadeAction, type DataSourceProvider, type DataSourceProviderType, type EnumDef, type Expression, ExpressionUtils, type FieldDef, type FieldExpression, type FieldHasDefault, type FieldIsArray, type FieldIsComputed, type FieldIsDelegateDiscriminator, type FieldIsDelegateRelation, type FieldIsRelation, type FieldIsRelationArray, type FieldType, type ForeignKeyFields, type GetDelegateModels, type GetEnum, type GetEnums, type GetModel, type GetModelDiscriminator, type GetModelField, type GetModelFieldType, type GetModelFields, type GetModels, type GetSubModels, type GetTypeDef, type GetTypeDefField, type GetTypeDefFields, type GetTypeDefs, type IsDelegateModel, type LiteralExpression, type MappedBuiltinType, type MemberExpression, type ModelDef, type ModelFieldIsOptional, type NonRelationFields, type NullExpression, type ProcedureDef, type ProcedureParam, type RelationFieldType, type RelationFields, type RelationInfo, type ScalarFields, type SchemaDef, type ThisExpression, type TypeDefDef, type TypeDefFieldIsOptional, type UnaryExpression, type UnaryOperator };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/expression-utils.ts
|
|
5
|
+
var ExpressionUtils = {
|
|
6
|
+
literal: /* @__PURE__ */ __name((value) => {
|
|
7
|
+
return {
|
|
8
|
+
kind: "literal",
|
|
9
|
+
value
|
|
10
|
+
};
|
|
11
|
+
}, "literal"),
|
|
12
|
+
array: /* @__PURE__ */ __name((items) => {
|
|
13
|
+
return {
|
|
14
|
+
kind: "array",
|
|
15
|
+
items
|
|
16
|
+
};
|
|
17
|
+
}, "array"),
|
|
18
|
+
call: /* @__PURE__ */ __name((functionName, args) => {
|
|
19
|
+
return {
|
|
20
|
+
kind: "call",
|
|
21
|
+
function: functionName,
|
|
22
|
+
args
|
|
23
|
+
};
|
|
24
|
+
}, "call"),
|
|
25
|
+
binary: /* @__PURE__ */ __name((left, op, right) => {
|
|
26
|
+
return {
|
|
27
|
+
kind: "binary",
|
|
28
|
+
op,
|
|
29
|
+
left,
|
|
30
|
+
right
|
|
31
|
+
};
|
|
32
|
+
}, "binary"),
|
|
33
|
+
unary: /* @__PURE__ */ __name((op, operand) => {
|
|
34
|
+
return {
|
|
35
|
+
kind: "unary",
|
|
36
|
+
op,
|
|
37
|
+
operand
|
|
38
|
+
};
|
|
39
|
+
}, "unary"),
|
|
40
|
+
field: /* @__PURE__ */ __name((field) => {
|
|
41
|
+
return {
|
|
42
|
+
kind: "field",
|
|
43
|
+
field
|
|
44
|
+
};
|
|
45
|
+
}, "field"),
|
|
46
|
+
member: /* @__PURE__ */ __name((receiver, members) => {
|
|
47
|
+
return {
|
|
48
|
+
kind: "member",
|
|
49
|
+
receiver,
|
|
50
|
+
members
|
|
51
|
+
};
|
|
52
|
+
}, "member"),
|
|
53
|
+
_this: /* @__PURE__ */ __name(() => {
|
|
54
|
+
return {
|
|
55
|
+
kind: "this"
|
|
56
|
+
};
|
|
57
|
+
}, "_this"),
|
|
58
|
+
_null: /* @__PURE__ */ __name(() => {
|
|
59
|
+
return {
|
|
60
|
+
kind: "null"
|
|
61
|
+
};
|
|
62
|
+
}, "_null"),
|
|
63
|
+
and: /* @__PURE__ */ __name((expr, ...expressions) => {
|
|
64
|
+
return expressions.reduce((acc, exp) => ExpressionUtils.binary(acc, "&&", exp), expr);
|
|
65
|
+
}, "and"),
|
|
66
|
+
or: /* @__PURE__ */ __name((expr, ...expressions) => {
|
|
67
|
+
return expressions.reduce((acc, exp) => ExpressionUtils.binary(acc, "||", exp), expr);
|
|
68
|
+
}, "or"),
|
|
69
|
+
not: /* @__PURE__ */ __name((expr) => {
|
|
70
|
+
return ExpressionUtils.unary("!", expr);
|
|
71
|
+
}, "not"),
|
|
72
|
+
is: /* @__PURE__ */ __name((value, kind) => {
|
|
73
|
+
return !!value && typeof value === "object" && "kind" in value && value.kind === kind;
|
|
74
|
+
}, "is"),
|
|
75
|
+
isLiteral: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "literal"), "isLiteral"),
|
|
76
|
+
isArray: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "array"), "isArray"),
|
|
77
|
+
isCall: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "call"), "isCall"),
|
|
78
|
+
isNull: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "null"), "isNull"),
|
|
79
|
+
isThis: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "this"), "isThis"),
|
|
80
|
+
isUnary: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "unary"), "isUnary"),
|
|
81
|
+
isBinary: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "binary"), "isBinary"),
|
|
82
|
+
isField: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "field"), "isField"),
|
|
83
|
+
isMember: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "member"), "isMember"),
|
|
84
|
+
getLiteralValue: /* @__PURE__ */ __name((expr) => {
|
|
85
|
+
return ExpressionUtils.isLiteral(expr) ? expr.value : void 0;
|
|
86
|
+
}, "getLiteralValue")
|
|
87
|
+
};
|
|
88
|
+
export {
|
|
89
|
+
ExpressionUtils
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/expression-utils.ts"],"sourcesContent":["import type {\n ArrayExpression,\n BinaryExpression,\n BinaryOperator,\n CallExpression,\n Expression,\n FieldExpression,\n LiteralExpression,\n MemberExpression,\n NullExpression,\n ThisExpression,\n UnaryExpression,\n UnaryOperator,\n} from './expression';\n\n/**\n * Utility functions to create and work with Expression objects\n */\nexport const ExpressionUtils = {\n literal: (value: string | number | boolean): LiteralExpression => {\n return {\n kind: 'literal',\n value,\n };\n },\n\n array: (items: Expression[]): ArrayExpression => {\n return {\n kind: 'array',\n items,\n };\n },\n\n call: (functionName: string, args?: Expression[]): CallExpression => {\n return {\n kind: 'call',\n function: functionName,\n args,\n };\n },\n\n binary: (left: Expression, op: BinaryOperator, right: Expression): BinaryExpression => {\n return {\n kind: 'binary',\n op,\n left,\n right,\n };\n },\n\n unary: (op: UnaryOperator, operand: Expression): UnaryExpression => {\n return {\n kind: 'unary',\n op,\n operand,\n };\n },\n\n field: (field: string): FieldExpression => {\n return {\n kind: 'field',\n field,\n };\n },\n\n member: (receiver: Expression, members: string[]): MemberExpression => {\n return {\n kind: 'member',\n receiver: receiver,\n members,\n };\n },\n\n _this: (): ThisExpression => {\n return {\n kind: 'this',\n };\n },\n\n _null: (): NullExpression => {\n return {\n kind: 'null',\n };\n },\n\n and: (expr: Expression, ...expressions: Expression[]) => {\n return expressions.reduce((acc, exp) => ExpressionUtils.binary(acc, '&&', exp), expr);\n },\n\n or: (expr: Expression, ...expressions: Expression[]) => {\n return expressions.reduce((acc, exp) => ExpressionUtils.binary(acc, '||', exp), expr);\n },\n\n not: (expr: Expression) => {\n return ExpressionUtils.unary('!', expr);\n },\n\n is: (value: unknown, kind: Expression['kind']): value is Expression => {\n return !!value && typeof value === 'object' && 'kind' in value && value.kind === kind;\n },\n\n isLiteral: (value: unknown): value is LiteralExpression => ExpressionUtils.is(value, 'literal'),\n\n isArray: (value: unknown): value is ArrayExpression => ExpressionUtils.is(value, 'array'),\n\n isCall: (value: unknown): value is CallExpression => ExpressionUtils.is(value, 'call'),\n\n isNull: (value: unknown): value is NullExpression => ExpressionUtils.is(value, 'null'),\n\n isThis: (value: unknown): value is ThisExpression => ExpressionUtils.is(value, 'this'),\n\n isUnary: (value: unknown): value is UnaryExpression => ExpressionUtils.is(value, 'unary'),\n\n isBinary: (value: unknown): value is BinaryExpression => ExpressionUtils.is(value, 'binary'),\n\n isField: (value: unknown): value is FieldExpression => ExpressionUtils.is(value, 'field'),\n\n isMember: (value: unknown): value is MemberExpression => ExpressionUtils.is(value, 'member'),\n\n getLiteralValue: (expr: Expression): string | number | boolean | undefined => {\n return ExpressionUtils.isLiteral(expr) ? expr.value : undefined;\n },\n};\n"],"mappings":";;;;AAkBO,IAAMA,kBAAkB;EAC3BC,SAAS,wBAACC,UAAAA;AACN,WAAO;MACHC,MAAM;MACND;IACJ;EACJ,GALS;EAOTE,OAAO,wBAACC,UAAAA;AACJ,WAAO;MACHF,MAAM;MACNE;IACJ;EACJ,GALO;EAOPC,MAAM,wBAACC,cAAsBC,SAAAA;AACzB,WAAO;MACHL,MAAM;MACNM,UAAUF;MACVC;IACJ;EACJ,GANM;EAQNE,QAAQ,wBAACC,MAAkBC,IAAoBC,UAAAA;AAC3C,WAAO;MACHV,MAAM;MACNS;MACAD;MACAE;IACJ;EACJ,GAPQ;EASRC,OAAO,wBAACF,IAAmBG,YAAAA;AACvB,WAAO;MACHZ,MAAM;MACNS;MACAG;IACJ;EACJ,GANO;EAQPC,OAAO,wBAACA,UAAAA;AACJ,WAAO;MACHb,MAAM;MACNa;IACJ;EACJ,GALO;EAOPC,QAAQ,wBAACC,UAAsBC,YAAAA;AAC3B,WAAO;MACHhB,MAAM;MACNe;MACAC;IACJ;EACJ,GANQ;EAQRC,OAAO,6BAAA;AACH,WAAO;MACHjB,MAAM;IACV;EACJ,GAJO;EAMPkB,OAAO,6BAAA;AACH,WAAO;MACHlB,MAAM;IACV;EACJ,GAJO;EAMPmB,KAAK,wBAACC,SAAqBC,gBAAAA;AACvB,WAAOA,YAAYC,OAAO,CAACC,KAAKC,QAAQ3B,gBAAgBU,OAAOgB,KAAK,MAAMC,GAAAA,GAAMJ,IAAAA;EACpF,GAFK;EAILK,IAAI,wBAACL,SAAqBC,gBAAAA;AACtB,WAAOA,YAAYC,OAAO,CAACC,KAAKC,QAAQ3B,gBAAgBU,OAAOgB,KAAK,MAAMC,GAAAA,GAAMJ,IAAAA;EACpF,GAFI;EAIJM,KAAK,wBAACN,SAAAA;AACF,WAAOvB,gBAAgBc,MAAM,KAAKS,IAAAA;EACtC,GAFK;EAILO,IAAI,wBAAC5B,OAAgBC,SAAAA;AACjB,WAAO,CAAC,CAACD,SAAS,OAAOA,UAAU,YAAY,UAAUA,SAASA,MAAMC,SAASA;EACrF,GAFI;EAIJ4B,WAAW,wBAAC7B,UAA+CF,gBAAgB8B,GAAG5B,OAAO,SAAA,GAA1E;EAEX8B,SAAS,wBAAC9B,UAA6CF,gBAAgB8B,GAAG5B,OAAO,OAAA,GAAxE;EAET+B,QAAQ,wBAAC/B,UAA4CF,gBAAgB8B,GAAG5B,OAAO,MAAA,GAAvE;EAERgC,QAAQ,wBAAChC,UAA4CF,gBAAgB8B,GAAG5B,OAAO,MAAA,GAAvE;EAERiC,QAAQ,wBAACjC,UAA4CF,gBAAgB8B,GAAG5B,OAAO,MAAA,GAAvE;EAERkC,SAAS,wBAAClC,UAA6CF,gBAAgB8B,GAAG5B,OAAO,OAAA,GAAxE;EAETmC,UAAU,wBAACnC,UAA8CF,gBAAgB8B,GAAG5B,OAAO,QAAA,GAAzE;EAEVoC,SAAS,wBAACpC,UAA6CF,gBAAgB8B,GAAG5B,OAAO,OAAA,GAAxE;EAETqC,UAAU,wBAACrC,UAA8CF,gBAAgB8B,GAAG5B,OAAO,QAAA,GAAzE;EAEVsC,iBAAiB,wBAACjB,SAAAA;AACd,WAAOvB,gBAAgB+B,UAAUR,IAAAA,IAAQA,KAAKrB,QAAQuC;EAC1D,GAFiB;AAGrB;","names":["ExpressionUtils","literal","value","kind","array","items","call","functionName","args","function","binary","left","op","right","unary","operand","field","member","receiver","members","_this","_null","and","expr","expressions","reduce","acc","exp","or","not","is","isLiteral","isArray","isCall","isNull","isThis","isUnary","isBinary","isField","isMember","getLiteralValue","undefined"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zenstackhq/schema",
|
|
3
|
+
"version": "3.0.0-beta.15",
|
|
4
|
+
"description": "ZenStack Runtime Schema",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [],
|
|
7
|
+
"author": "ZenStack Team",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"decimal.js": "^10.4.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@zenstackhq/eslint-config": "3.0.0-beta.15",
|
|
29
|
+
"@zenstackhq/typescript-config": "3.0.0-beta.15"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc --noEmit && tsup-node",
|
|
33
|
+
"watch": "tsup-node --watch",
|
|
34
|
+
"lint": "eslint src --ext ts",
|
|
35
|
+
"pack": "pnpm pack"
|
|
36
|
+
}
|
|
37
|
+
}
|