@zenstackhq/schema 3.3.0-beta.2 → 3.3.0-beta.3
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/index.cjs +10 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -46,12 +46,13 @@ var ExpressionUtils = {
|
|
|
46
46
|
args
|
|
47
47
|
};
|
|
48
48
|
}, "call"),
|
|
49
|
-
binary: /* @__PURE__ */ __name((left, op, right) => {
|
|
49
|
+
binary: /* @__PURE__ */ __name((left, op, right, binding) => {
|
|
50
50
|
return {
|
|
51
51
|
kind: "binary",
|
|
52
52
|
op,
|
|
53
53
|
left,
|
|
54
|
-
right
|
|
54
|
+
right,
|
|
55
|
+
binding
|
|
55
56
|
};
|
|
56
57
|
}, "binary"),
|
|
57
58
|
unary: /* @__PURE__ */ __name((op, operand) => {
|
|
@@ -74,6 +75,12 @@ var ExpressionUtils = {
|
|
|
74
75
|
members
|
|
75
76
|
};
|
|
76
77
|
}, "member"),
|
|
78
|
+
binding: /* @__PURE__ */ __name((name) => {
|
|
79
|
+
return {
|
|
80
|
+
kind: "binding",
|
|
81
|
+
name
|
|
82
|
+
};
|
|
83
|
+
}, "binding"),
|
|
77
84
|
_this: /* @__PURE__ */ __name(() => {
|
|
78
85
|
return {
|
|
79
86
|
kind: "this"
|
|
@@ -105,6 +112,7 @@ var ExpressionUtils = {
|
|
|
105
112
|
isBinary: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "binary"), "isBinary"),
|
|
106
113
|
isField: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "field"), "isField"),
|
|
107
114
|
isMember: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "member"), "isMember"),
|
|
115
|
+
isBinding: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "binding"), "isBinding"),
|
|
108
116
|
getLiteralValue: /* @__PURE__ */ __name((expr) => {
|
|
109
117
|
return ExpressionUtils.isLiteral(expr) ? expr.value : void 0;
|
|
110
118
|
}, "getLiteralValue")
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +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;;;;;;;
|
|
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 BindingExpression,\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, binding?: string): BinaryExpression => {\n return {\n kind: 'binary',\n op,\n left,\n right,\n binding,\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 binding: (name: string): BindingExpression => {\n return {\n kind: 'binding',\n name,\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 isBinding: (value: unknown): value is BindingExpression => ExpressionUtils.is(value, 'binding'),\n\n getLiteralValue: (expr: Expression): string | number | boolean | undefined => {\n return ExpressionUtils.isLiteral(expr) ? expr.value : undefined;\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;ACkBO,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,OAAmBC,YAAAA;AAC9D,WAAO;MACHX,MAAM;MACNS;MACAD;MACAE;MACAC;IACJ;EACJ,GARQ;EAURC,OAAO,wBAACH,IAAmBI,YAAAA;AACvB,WAAO;MACHb,MAAM;MACNS;MACAI;IACJ;EACJ,GANO;EAQPC,OAAO,wBAACA,UAAAA;AACJ,WAAO;MACHd,MAAM;MACNc;IACJ;EACJ,GALO;EAOPC,QAAQ,wBAACC,UAAsBC,YAAAA;AAC3B,WAAO;MACHjB,MAAM;MACNgB;MACAC;IACJ;EACJ,GANQ;EAQRN,SAAS,wBAACO,SAAAA;AACN,WAAO;MACHlB,MAAM;MACNkB;IACJ;EACJ,GALS;EAOTC,OAAO,6BAAA;AACH,WAAO;MACHnB,MAAM;IACV;EACJ,GAJO;EAMPoB,OAAO,6BAAA;AACH,WAAO;MACHpB,MAAM;IACV;EACJ,GAJO;EAMPqB,KAAK,wBAACC,SAAqBC,gBAAAA;AACvB,WAAOA,YAAYC,OAAO,CAACC,KAAKC,QAAQ7B,gBAAgBU,OAAOkB,KAAK,MAAMC,GAAAA,GAAMJ,IAAAA;EACpF,GAFK;EAILK,IAAI,wBAACL,SAAqBC,gBAAAA;AACtB,WAAOA,YAAYC,OAAO,CAACC,KAAKC,QAAQ7B,gBAAgBU,OAAOkB,KAAK,MAAMC,GAAAA,GAAMJ,IAAAA;EACpF,GAFI;EAIJM,KAAK,wBAACN,SAAAA;AACF,WAAOzB,gBAAgBe,MAAM,KAAKU,IAAAA;EACtC,GAFK;EAILO,IAAI,wBAAC9B,OAAgBC,SAAAA;AACjB,WAAO,CAAC,CAACD,SAAS,OAAOA,UAAU,YAAY,UAAUA,SAASA,MAAMC,SAASA;EACrF,GAFI;EAIJ8B,WAAW,wBAAC/B,UAA+CF,gBAAgBgC,GAAG9B,OAAO,SAAA,GAA1E;EAEXgC,SAAS,wBAAChC,UAA6CF,gBAAgBgC,GAAG9B,OAAO,OAAA,GAAxE;EAETiC,QAAQ,wBAACjC,UAA4CF,gBAAgBgC,GAAG9B,OAAO,MAAA,GAAvE;EAERkC,QAAQ,wBAAClC,UAA4CF,gBAAgBgC,GAAG9B,OAAO,MAAA,GAAvE;EAERmC,QAAQ,wBAACnC,UAA4CF,gBAAgBgC,GAAG9B,OAAO,MAAA,GAAvE;EAERoC,SAAS,wBAACpC,UAA6CF,gBAAgBgC,GAAG9B,OAAO,OAAA,GAAxE;EAETqC,UAAU,wBAACrC,UAA8CF,gBAAgBgC,GAAG9B,OAAO,QAAA,GAAzE;EAEVsC,SAAS,wBAACtC,UAA6CF,gBAAgBgC,GAAG9B,OAAO,OAAA,GAAxE;EAETuC,UAAU,wBAACvC,UAA8CF,gBAAgBgC,GAAG9B,OAAO,QAAA,GAAzE;EAEVwC,WAAW,wBAACxC,UAA+CF,gBAAgBgC,GAAG9B,OAAO,SAAA,GAA1E;EAEXyC,iBAAiB,wBAAClB,SAAAA;AACd,WAAOzB,gBAAgBiC,UAAUR,IAAAA,IAAQA,KAAKvB,QAAQ0C;EAC1D,GAFiB;AAGrB;","names":["ExpressionUtils","literal","value","kind","array","items","call","functionName","args","function","binary","left","op","right","binding","unary","operand","field","member","receiver","members","name","_this","_null","and","expr","expressions","reduce","acc","exp","or","not","is","isLiteral","isArray","isCall","isNull","isThis","isUnary","isBinary","isField","isMember","isBinding","getLiteralValue","undefined"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
2
|
|
|
3
|
-
type Expression = LiteralExpression | ArrayExpression | FieldExpression | MemberExpression | CallExpression | UnaryExpression | BinaryExpression | ThisExpression | NullExpression;
|
|
3
|
+
type Expression = LiteralExpression | ArrayExpression | FieldExpression | MemberExpression | CallExpression | UnaryExpression | BinaryExpression | BindingExpression | ThisExpression | NullExpression;
|
|
4
4
|
type LiteralExpression = {
|
|
5
5
|
kind: 'literal';
|
|
6
6
|
value: string | number | boolean;
|
|
@@ -18,6 +18,10 @@ type MemberExpression = {
|
|
|
18
18
|
receiver: Expression;
|
|
19
19
|
members: string[];
|
|
20
20
|
};
|
|
21
|
+
type BindingExpression = {
|
|
22
|
+
kind: 'binding';
|
|
23
|
+
name: string;
|
|
24
|
+
};
|
|
21
25
|
type UnaryExpression = {
|
|
22
26
|
kind: 'unary';
|
|
23
27
|
op: UnaryOperator;
|
|
@@ -28,6 +32,7 @@ type BinaryExpression = {
|
|
|
28
32
|
op: BinaryOperator;
|
|
29
33
|
left: Expression;
|
|
30
34
|
right: Expression;
|
|
35
|
+
binding?: string;
|
|
31
36
|
};
|
|
32
37
|
type CallExpression = {
|
|
33
38
|
kind: 'call';
|
|
@@ -50,10 +55,11 @@ declare const ExpressionUtils: {
|
|
|
50
55
|
literal: (value: string | number | boolean) => LiteralExpression;
|
|
51
56
|
array: (items: Expression[]) => ArrayExpression;
|
|
52
57
|
call: (functionName: string, args?: Expression[]) => CallExpression;
|
|
53
|
-
binary: (left: Expression, op: BinaryOperator, right: Expression) => BinaryExpression;
|
|
58
|
+
binary: (left: Expression, op: BinaryOperator, right: Expression, binding?: string) => BinaryExpression;
|
|
54
59
|
unary: (op: UnaryOperator, operand: Expression) => UnaryExpression;
|
|
55
60
|
field: (field: string) => FieldExpression;
|
|
56
61
|
member: (receiver: Expression, members: string[]) => MemberExpression;
|
|
62
|
+
binding: (name: string) => BindingExpression;
|
|
57
63
|
_this: () => ThisExpression;
|
|
58
64
|
_null: () => NullExpression;
|
|
59
65
|
and: (expr: Expression, ...expressions: Expression[]) => Expression;
|
|
@@ -69,10 +75,11 @@ declare const ExpressionUtils: {
|
|
|
69
75
|
isBinary: (value: unknown) => value is BinaryExpression;
|
|
70
76
|
isField: (value: unknown) => value is FieldExpression;
|
|
71
77
|
isMember: (value: unknown) => value is MemberExpression;
|
|
78
|
+
isBinding: (value: unknown) => value is BindingExpression;
|
|
72
79
|
getLiteralValue: (expr: Expression) => string | number | boolean | undefined;
|
|
73
80
|
};
|
|
74
81
|
|
|
75
|
-
type DataSourceProviderType = 'sqlite' | 'postgresql';
|
|
82
|
+
type DataSourceProviderType = 'sqlite' | 'postgresql' | 'mysql';
|
|
76
83
|
type DataSourceProvider = {
|
|
77
84
|
type: DataSourceProviderType;
|
|
78
85
|
defaultSchema?: string;
|
|
@@ -152,6 +159,7 @@ type EnumField = {
|
|
|
152
159
|
attributes?: readonly AttributeApplication[];
|
|
153
160
|
};
|
|
154
161
|
type EnumDef = {
|
|
162
|
+
name: string;
|
|
155
163
|
fields?: Record<string, EnumField>;
|
|
156
164
|
values: Record<string, string>;
|
|
157
165
|
attributes?: readonly AttributeApplication[];
|
|
@@ -208,4 +216,4 @@ type IsDelegateModel<Schema extends SchemaDef, Model extends GetModels<Schema>>
|
|
|
208
216
|
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;
|
|
209
217
|
type FieldIsDelegateDiscriminator<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['isDiscriminator'] extends true ? true : false;
|
|
210
218
|
|
|
211
|
-
export { type ArrayExpression, type AttributeApplication, type AttributeArg, type BinaryExpression, type BinaryOperator, type BuiltinType, type CallExpression, type CascadeAction, type DataSourceProvider, type DataSourceProviderType, type EnumDef, type EnumField, 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 GetTypeDefFieldType, 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 TypeDefFieldIsArray, type TypeDefFieldIsOptional, type UnaryExpression, type UnaryOperator };
|
|
219
|
+
export { type ArrayExpression, type AttributeApplication, type AttributeArg, type BinaryExpression, type BinaryOperator, type BindingExpression, type BuiltinType, type CallExpression, type CascadeAction, type DataSourceProvider, type DataSourceProviderType, type EnumDef, type EnumField, 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 GetTypeDefFieldType, 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 TypeDefFieldIsArray, type TypeDefFieldIsOptional, type UnaryExpression, type UnaryOperator };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
2
|
|
|
3
|
-
type Expression = LiteralExpression | ArrayExpression | FieldExpression | MemberExpression | CallExpression | UnaryExpression | BinaryExpression | ThisExpression | NullExpression;
|
|
3
|
+
type Expression = LiteralExpression | ArrayExpression | FieldExpression | MemberExpression | CallExpression | UnaryExpression | BinaryExpression | BindingExpression | ThisExpression | NullExpression;
|
|
4
4
|
type LiteralExpression = {
|
|
5
5
|
kind: 'literal';
|
|
6
6
|
value: string | number | boolean;
|
|
@@ -18,6 +18,10 @@ type MemberExpression = {
|
|
|
18
18
|
receiver: Expression;
|
|
19
19
|
members: string[];
|
|
20
20
|
};
|
|
21
|
+
type BindingExpression = {
|
|
22
|
+
kind: 'binding';
|
|
23
|
+
name: string;
|
|
24
|
+
};
|
|
21
25
|
type UnaryExpression = {
|
|
22
26
|
kind: 'unary';
|
|
23
27
|
op: UnaryOperator;
|
|
@@ -28,6 +32,7 @@ type BinaryExpression = {
|
|
|
28
32
|
op: BinaryOperator;
|
|
29
33
|
left: Expression;
|
|
30
34
|
right: Expression;
|
|
35
|
+
binding?: string;
|
|
31
36
|
};
|
|
32
37
|
type CallExpression = {
|
|
33
38
|
kind: 'call';
|
|
@@ -50,10 +55,11 @@ declare const ExpressionUtils: {
|
|
|
50
55
|
literal: (value: string | number | boolean) => LiteralExpression;
|
|
51
56
|
array: (items: Expression[]) => ArrayExpression;
|
|
52
57
|
call: (functionName: string, args?: Expression[]) => CallExpression;
|
|
53
|
-
binary: (left: Expression, op: BinaryOperator, right: Expression) => BinaryExpression;
|
|
58
|
+
binary: (left: Expression, op: BinaryOperator, right: Expression, binding?: string) => BinaryExpression;
|
|
54
59
|
unary: (op: UnaryOperator, operand: Expression) => UnaryExpression;
|
|
55
60
|
field: (field: string) => FieldExpression;
|
|
56
61
|
member: (receiver: Expression, members: string[]) => MemberExpression;
|
|
62
|
+
binding: (name: string) => BindingExpression;
|
|
57
63
|
_this: () => ThisExpression;
|
|
58
64
|
_null: () => NullExpression;
|
|
59
65
|
and: (expr: Expression, ...expressions: Expression[]) => Expression;
|
|
@@ -69,10 +75,11 @@ declare const ExpressionUtils: {
|
|
|
69
75
|
isBinary: (value: unknown) => value is BinaryExpression;
|
|
70
76
|
isField: (value: unknown) => value is FieldExpression;
|
|
71
77
|
isMember: (value: unknown) => value is MemberExpression;
|
|
78
|
+
isBinding: (value: unknown) => value is BindingExpression;
|
|
72
79
|
getLiteralValue: (expr: Expression) => string | number | boolean | undefined;
|
|
73
80
|
};
|
|
74
81
|
|
|
75
|
-
type DataSourceProviderType = 'sqlite' | 'postgresql';
|
|
82
|
+
type DataSourceProviderType = 'sqlite' | 'postgresql' | 'mysql';
|
|
76
83
|
type DataSourceProvider = {
|
|
77
84
|
type: DataSourceProviderType;
|
|
78
85
|
defaultSchema?: string;
|
|
@@ -152,6 +159,7 @@ type EnumField = {
|
|
|
152
159
|
attributes?: readonly AttributeApplication[];
|
|
153
160
|
};
|
|
154
161
|
type EnumDef = {
|
|
162
|
+
name: string;
|
|
155
163
|
fields?: Record<string, EnumField>;
|
|
156
164
|
values: Record<string, string>;
|
|
157
165
|
attributes?: readonly AttributeApplication[];
|
|
@@ -208,4 +216,4 @@ type IsDelegateModel<Schema extends SchemaDef, Model extends GetModels<Schema>>
|
|
|
208
216
|
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;
|
|
209
217
|
type FieldIsDelegateDiscriminator<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['isDiscriminator'] extends true ? true : false;
|
|
210
218
|
|
|
211
|
-
export { type ArrayExpression, type AttributeApplication, type AttributeArg, type BinaryExpression, type BinaryOperator, type BuiltinType, type CallExpression, type CascadeAction, type DataSourceProvider, type DataSourceProviderType, type EnumDef, type EnumField, 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 GetTypeDefFieldType, 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 TypeDefFieldIsArray, type TypeDefFieldIsOptional, type UnaryExpression, type UnaryOperator };
|
|
219
|
+
export { type ArrayExpression, type AttributeApplication, type AttributeArg, type BinaryExpression, type BinaryOperator, type BindingExpression, type BuiltinType, type CallExpression, type CascadeAction, type DataSourceProvider, type DataSourceProviderType, type EnumDef, type EnumField, 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 GetTypeDefFieldType, 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 TypeDefFieldIsArray, type TypeDefFieldIsOptional, type UnaryExpression, type UnaryOperator };
|
package/dist/index.js
CHANGED
|
@@ -22,12 +22,13 @@ var ExpressionUtils = {
|
|
|
22
22
|
args
|
|
23
23
|
};
|
|
24
24
|
}, "call"),
|
|
25
|
-
binary: /* @__PURE__ */ __name((left, op, right) => {
|
|
25
|
+
binary: /* @__PURE__ */ __name((left, op, right, binding) => {
|
|
26
26
|
return {
|
|
27
27
|
kind: "binary",
|
|
28
28
|
op,
|
|
29
29
|
left,
|
|
30
|
-
right
|
|
30
|
+
right,
|
|
31
|
+
binding
|
|
31
32
|
};
|
|
32
33
|
}, "binary"),
|
|
33
34
|
unary: /* @__PURE__ */ __name((op, operand) => {
|
|
@@ -50,6 +51,12 @@ var ExpressionUtils = {
|
|
|
50
51
|
members
|
|
51
52
|
};
|
|
52
53
|
}, "member"),
|
|
54
|
+
binding: /* @__PURE__ */ __name((name) => {
|
|
55
|
+
return {
|
|
56
|
+
kind: "binding",
|
|
57
|
+
name
|
|
58
|
+
};
|
|
59
|
+
}, "binding"),
|
|
53
60
|
_this: /* @__PURE__ */ __name(() => {
|
|
54
61
|
return {
|
|
55
62
|
kind: "this"
|
|
@@ -81,6 +88,7 @@ var ExpressionUtils = {
|
|
|
81
88
|
isBinary: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "binary"), "isBinary"),
|
|
82
89
|
isField: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "field"), "isField"),
|
|
83
90
|
isMember: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "member"), "isMember"),
|
|
91
|
+
isBinding: /* @__PURE__ */ __name((value) => ExpressionUtils.is(value, "binding"), "isBinding"),
|
|
84
92
|
getLiteralValue: /* @__PURE__ */ __name((expr) => {
|
|
85
93
|
return ExpressionUtils.isLiteral(expr) ? expr.value : void 0;
|
|
86
94
|
}, "getLiteralValue")
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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":";;;;
|
|
1
|
+
{"version":3,"sources":["../src/expression-utils.ts"],"sourcesContent":["import type {\n ArrayExpression,\n BinaryExpression,\n BinaryOperator,\n BindingExpression,\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, binding?: string): BinaryExpression => {\n return {\n kind: 'binary',\n op,\n left,\n right,\n binding,\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 binding: (name: string): BindingExpression => {\n return {\n kind: 'binding',\n name,\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 isBinding: (value: unknown): value is BindingExpression => ExpressionUtils.is(value, 'binding'),\n\n getLiteralValue: (expr: Expression): string | number | boolean | undefined => {\n return ExpressionUtils.isLiteral(expr) ? expr.value : undefined;\n },\n};\n"],"mappings":";;;;AAmBO,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,OAAmBC,YAAAA;AAC9D,WAAO;MACHX,MAAM;MACNS;MACAD;MACAE;MACAC;IACJ;EACJ,GARQ;EAURC,OAAO,wBAACH,IAAmBI,YAAAA;AACvB,WAAO;MACHb,MAAM;MACNS;MACAI;IACJ;EACJ,GANO;EAQPC,OAAO,wBAACA,UAAAA;AACJ,WAAO;MACHd,MAAM;MACNc;IACJ;EACJ,GALO;EAOPC,QAAQ,wBAACC,UAAsBC,YAAAA;AAC3B,WAAO;MACHjB,MAAM;MACNgB;MACAC;IACJ;EACJ,GANQ;EAQRN,SAAS,wBAACO,SAAAA;AACN,WAAO;MACHlB,MAAM;MACNkB;IACJ;EACJ,GALS;EAOTC,OAAO,6BAAA;AACH,WAAO;MACHnB,MAAM;IACV;EACJ,GAJO;EAMPoB,OAAO,6BAAA;AACH,WAAO;MACHpB,MAAM;IACV;EACJ,GAJO;EAMPqB,KAAK,wBAACC,SAAqBC,gBAAAA;AACvB,WAAOA,YAAYC,OAAO,CAACC,KAAKC,QAAQ7B,gBAAgBU,OAAOkB,KAAK,MAAMC,GAAAA,GAAMJ,IAAAA;EACpF,GAFK;EAILK,IAAI,wBAACL,SAAqBC,gBAAAA;AACtB,WAAOA,YAAYC,OAAO,CAACC,KAAKC,QAAQ7B,gBAAgBU,OAAOkB,KAAK,MAAMC,GAAAA,GAAMJ,IAAAA;EACpF,GAFI;EAIJM,KAAK,wBAACN,SAAAA;AACF,WAAOzB,gBAAgBe,MAAM,KAAKU,IAAAA;EACtC,GAFK;EAILO,IAAI,wBAAC9B,OAAgBC,SAAAA;AACjB,WAAO,CAAC,CAACD,SAAS,OAAOA,UAAU,YAAY,UAAUA,SAASA,MAAMC,SAASA;EACrF,GAFI;EAIJ8B,WAAW,wBAAC/B,UAA+CF,gBAAgBgC,GAAG9B,OAAO,SAAA,GAA1E;EAEXgC,SAAS,wBAAChC,UAA6CF,gBAAgBgC,GAAG9B,OAAO,OAAA,GAAxE;EAETiC,QAAQ,wBAACjC,UAA4CF,gBAAgBgC,GAAG9B,OAAO,MAAA,GAAvE;EAERkC,QAAQ,wBAAClC,UAA4CF,gBAAgBgC,GAAG9B,OAAO,MAAA,GAAvE;EAERmC,QAAQ,wBAACnC,UAA4CF,gBAAgBgC,GAAG9B,OAAO,MAAA,GAAvE;EAERoC,SAAS,wBAACpC,UAA6CF,gBAAgBgC,GAAG9B,OAAO,OAAA,GAAxE;EAETqC,UAAU,wBAACrC,UAA8CF,gBAAgBgC,GAAG9B,OAAO,QAAA,GAAzE;EAEVsC,SAAS,wBAACtC,UAA6CF,gBAAgBgC,GAAG9B,OAAO,OAAA,GAAxE;EAETuC,UAAU,wBAACvC,UAA8CF,gBAAgBgC,GAAG9B,OAAO,QAAA,GAAzE;EAEVwC,WAAW,wBAACxC,UAA+CF,gBAAgBgC,GAAG9B,OAAO,SAAA,GAA1E;EAEXyC,iBAAiB,wBAAClB,SAAAA;AACd,WAAOzB,gBAAgBiC,UAAUR,IAAAA,IAAQA,KAAKvB,QAAQ0C;EAC1D,GAFiB;AAGrB;","names":["ExpressionUtils","literal","value","kind","array","items","call","functionName","args","function","binary","left","op","right","binding","unary","operand","field","member","receiver","members","name","_this","_null","and","expr","expressions","reduce","acc","exp","or","not","is","isLiteral","isArray","isCall","isNull","isThis","isUnary","isBinary","isField","isMember","isBinding","getLiteralValue","undefined"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenstackhq/schema",
|
|
3
|
-
"version": "3.3.0-beta.
|
|
3
|
+
"version": "3.3.0-beta.3",
|
|
4
4
|
"description": "ZenStack Runtime Schema",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [],
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"decimal.js": "^10.4.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@zenstackhq/eslint-config": "3.3.0-beta.
|
|
29
|
-
"@zenstackhq/typescript-config": "3.3.0-beta.
|
|
28
|
+
"@zenstackhq/eslint-config": "3.3.0-beta.3",
|
|
29
|
+
"@zenstackhq/typescript-config": "3.3.0-beta.3"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsc --noEmit && tsup-node",
|