@zenstackhq/sdk 2.16.0 → 3.0.0-alpha.0

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.
Files changed (81) hide show
  1. package/LICENSE +1 -1
  2. package/dist/index.cjs +1906 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +196 -0
  5. package/dist/index.d.ts +196 -0
  6. package/dist/index.js +1872 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/schema.cjs +19 -0
  9. package/dist/schema.cjs.map +1 -0
  10. package/dist/schema.d.cts +138 -0
  11. package/dist/schema.d.ts +138 -0
  12. package/dist/schema.js +1 -0
  13. package/dist/schema.js.map +1 -0
  14. package/package.json +43 -39
  15. package/README.md +0 -5
  16. package/ast.d.ts +0 -1
  17. package/ast.js +0 -18
  18. package/ast.js.map +0 -1
  19. package/code-gen.d.ts +0 -37
  20. package/code-gen.js +0 -114
  21. package/code-gen.js.map +0 -1
  22. package/constants.d.ts +0 -15
  23. package/constants.js +0 -21
  24. package/constants.js.map +0 -1
  25. package/dmmf-helpers/aggregate-helpers.d.ts +0 -5
  26. package/dmmf-helpers/aggregate-helpers.js +0 -65
  27. package/dmmf-helpers/aggregate-helpers.js.map +0 -1
  28. package/dmmf-helpers/include-helpers.d.ts +0 -2
  29. package/dmmf-helpers/include-helpers.js +0 -88
  30. package/dmmf-helpers/include-helpers.js.map +0 -1
  31. package/dmmf-helpers/index.d.ts +0 -7
  32. package/dmmf-helpers/index.js +0 -24
  33. package/dmmf-helpers/index.js.map +0 -1
  34. package/dmmf-helpers/missing-types-helper.d.ts +0 -2
  35. package/dmmf-helpers/missing-types-helper.js +0 -14
  36. package/dmmf-helpers/missing-types-helper.js.map +0 -1
  37. package/dmmf-helpers/model-helpers.d.ts +0 -16
  38. package/dmmf-helpers/model-helpers.js +0 -38
  39. package/dmmf-helpers/model-helpers.js.map +0 -1
  40. package/dmmf-helpers/modelArgs-helpers.d.ts +0 -2
  41. package/dmmf-helpers/modelArgs-helpers.js +0 -67
  42. package/dmmf-helpers/modelArgs-helpers.js.map +0 -1
  43. package/dmmf-helpers/select-helpers.d.ts +0 -2
  44. package/dmmf-helpers/select-helpers.js +0 -152
  45. package/dmmf-helpers/select-helpers.js.map +0 -1
  46. package/dmmf-helpers/types.d.ts +0 -20
  47. package/dmmf-helpers/types.js +0 -3
  48. package/dmmf-helpers/types.js.map +0 -1
  49. package/index.d.ts +0 -11
  50. package/index.js +0 -30
  51. package/index.js.map +0 -1
  52. package/model-meta-generator.d.ts +0 -24
  53. package/model-meta-generator.js +0 -458
  54. package/model-meta-generator.js.map +0 -1
  55. package/names.d.ts +0 -9
  56. package/names.js +0 -17
  57. package/names.js.map +0 -1
  58. package/path.d.ts +0 -4
  59. package/path.js +0 -15
  60. package/path.js.map +0 -1
  61. package/policy.d.ts +0 -13
  62. package/policy.js +0 -57
  63. package/policy.js.map +0 -1
  64. package/prisma.d.ts +0 -21
  65. package/prisma.js +0 -84
  66. package/prisma.js.map +0 -1
  67. package/types.d.ts +0 -97
  68. package/types.js +0 -14
  69. package/types.js.map +0 -1
  70. package/typescript-expression-transformer.d.ts +0 -64
  71. package/typescript-expression-transformer.js +0 -491
  72. package/typescript-expression-transformer.js.map +0 -1
  73. package/utils.d.ts +0 -103
  74. package/utils.js +0 -633
  75. package/utils.js.map +0 -1
  76. package/validation.d.ts +0 -7
  77. package/validation.js +0 -37
  78. package/validation.js.map +0 -1
  79. package/zmodel-code-generator.d.ts +0 -66
  80. package/zmodel-code-generator.js +0 -353
  81. package/zmodel-code-generator.js.map +0 -1
@@ -0,0 +1,138 @@
1
+ import Decimal from 'decimal.js';
2
+ export { OperandExpression } from 'kysely';
3
+
4
+ type Expression = LiteralExpression | ArrayExpression | FieldExpression | MemberExpression | CallExpression | UnaryExpression | BinaryExpression | ThisExpression | NullExpression;
5
+ type LiteralExpression = {
6
+ kind: 'literal';
7
+ value: string | number | boolean;
8
+ };
9
+ type ArrayExpression = {
10
+ kind: 'array';
11
+ items: Expression[];
12
+ };
13
+ type FieldExpression = {
14
+ kind: 'field';
15
+ field: string;
16
+ };
17
+ type MemberExpression = {
18
+ kind: 'member';
19
+ receiver: Expression;
20
+ members: string[];
21
+ };
22
+ type UnaryExpression = {
23
+ kind: 'unary';
24
+ op: UnaryOperator;
25
+ operand: Expression;
26
+ };
27
+ type BinaryExpression = {
28
+ kind: 'binary';
29
+ op: BinaryOperator;
30
+ left: Expression;
31
+ right: Expression;
32
+ };
33
+ type CallExpression = {
34
+ kind: 'call';
35
+ function: string;
36
+ args?: Expression[];
37
+ };
38
+ type ThisExpression = {
39
+ kind: 'this';
40
+ };
41
+ type NullExpression = {
42
+ kind: 'null';
43
+ };
44
+ type UnaryOperator = '!';
45
+ type BinaryOperator = '&&' | '||' | '==' | '!=' | '<' | '<=' | '>' | '>=' | '?' | '!' | '^' | 'in';
46
+
47
+ type DataSourceProviderType = 'sqlite' | 'postgresql';
48
+ type DataSourceProvider = {
49
+ type: DataSourceProviderType;
50
+ dialectConfigProvider: () => object;
51
+ };
52
+ type SchemaDef = {
53
+ provider: DataSourceProvider;
54
+ models: Record<string, ModelDef>;
55
+ enums?: Record<string, EnumDef>;
56
+ plugins: Record<string, unknown>;
57
+ procedures?: Record<string, ProcedureDef>;
58
+ authType?: GetModels<SchemaDef>;
59
+ };
60
+ type ModelDef = {
61
+ fields: Record<string, FieldDef>;
62
+ attributes?: AttributeApplication[];
63
+ uniqueFields: Record<string, Pick<FieldDef, 'type'> | Record<string, Pick<FieldDef, 'type'>>>;
64
+ idFields: string[];
65
+ computedFields?: Record<string, Function>;
66
+ };
67
+ type AttributeApplication = {
68
+ name: string;
69
+ args?: AttributeArg[];
70
+ };
71
+ type AttributeArg = {
72
+ name?: string;
73
+ value: Expression;
74
+ };
75
+ type CascadeAction = 'SetNull' | 'Cascade' | 'Restrict' | 'NoAction' | 'SetDefault';
76
+ type RelationInfo = {
77
+ name?: string;
78
+ fields?: string[];
79
+ references?: string[];
80
+ opposite?: string;
81
+ onDelete?: CascadeAction;
82
+ onUpdate?: CascadeAction;
83
+ };
84
+ type FieldDef = {
85
+ type: string;
86
+ id?: boolean;
87
+ array?: boolean;
88
+ optional?: boolean;
89
+ unique?: boolean;
90
+ updatedAt?: boolean;
91
+ attributes?: AttributeApplication[];
92
+ default?: MappedBuiltinType | Expression;
93
+ relation?: RelationInfo;
94
+ foreignKeyFor?: string[];
95
+ computed?: boolean;
96
+ };
97
+ type ProcedureParam = {
98
+ name: string;
99
+ type: string;
100
+ optional?: boolean;
101
+ };
102
+ type ProcedureDef = {
103
+ params: [...ProcedureParam[]];
104
+ returnType: string;
105
+ mutation?: boolean;
106
+ };
107
+ type BuiltinType = 'String' | 'Boolean' | 'Int' | 'Float' | 'BigInt' | 'Decimal' | 'DateTime' | 'Bytes';
108
+ type MappedBuiltinType = string | boolean | number | bigint | Decimal | Date;
109
+ type EnumDef = Record<string, string>;
110
+ type GetModels<Schema extends SchemaDef> = Extract<keyof Schema['models'], string>;
111
+ type GetModel<Schema extends SchemaDef, Model extends GetModels<Schema>> = Schema['models'][Model];
112
+ type GetEnums<Schema extends SchemaDef> = keyof Schema['enums'];
113
+ type GetEnum<Schema extends SchemaDef, Enum extends GetEnums<Schema>> = Schema['enums'][Enum];
114
+ type GetFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = Extract<keyof GetModel<Schema, Model>['fields'], string>;
115
+ type GetField<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>> = Schema['models'][Model]['fields'][Field];
116
+ type GetFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>> = Schema['models'][Model]['fields'][Field]['type'];
117
+ type ScalarFields<Schema extends SchemaDef, Model extends GetModels<Schema>, IncludeComputed extends boolean = true> = keyof {
118
+ [Key in GetFields<Schema, Model> as GetField<Schema, Model, Key>['relation'] extends object ? never : GetField<Schema, Model, Key>['foreignKeyFor'] extends string[] ? never : IncludeComputed extends true ? Key : FieldIsComputed<Schema, Model, Key> extends true ? never : Key]: Key;
119
+ };
120
+ type ForeignKeyFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
121
+ [Key in GetFields<Schema, Model> as GetField<Schema, Model, Key>['foreignKeyFor'] extends string[] ? Key : never]: Key;
122
+ };
123
+ type NonRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
124
+ [Key in GetFields<Schema, Model> as GetField<Schema, Model, Key>['relation'] extends object ? never : Key]: Key;
125
+ };
126
+ type RelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
127
+ [Key in GetFields<Schema, Model> as GetField<Schema, Model, Key>['relation'] extends object ? Key : never]: Key;
128
+ };
129
+ type FieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>> = GetField<Schema, Model, Field>['type'];
130
+ type RelationFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = GetField<Schema, Model, Field>['type'] extends GetModels<Schema> ? GetField<Schema, Model, Field>['type'] : never;
131
+ type FieldIsOptional<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>> = GetField<Schema, Model, Field>['optional'] extends true ? true : false;
132
+ type FieldIsRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>> = GetField<Schema, Model, Field>['relation'] extends object ? true : false;
133
+ type FieldIsArray<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>> = GetField<Schema, Model, Field>['array'] extends true ? true : false;
134
+ type FieldIsComputed<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>> = GetField<Schema, Model, Field>['computed'] extends true ? true : false;
135
+ type FieldHasDefault<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>> = GetField<Schema, Model, Field>['default'] extends object | number | string | boolean ? true : GetField<Schema, Model, Field>['updatedAt'] extends true ? true : false;
136
+ type FieldIsRelationArray<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>> = FieldIsRelation<Schema, Model, Field> extends true ? FieldIsArray<Schema, Model, Field> : false;
137
+
138
+ export type { ArrayExpression, AttributeApplication, AttributeArg, BinaryExpression, BinaryOperator, BuiltinType, CallExpression, CascadeAction, DataSourceProvider, DataSourceProviderType, EnumDef, Expression, FieldDef, FieldExpression, FieldHasDefault, FieldIsArray, FieldIsComputed, FieldIsOptional, FieldIsRelation, FieldIsRelationArray, FieldType, ForeignKeyFields, GetEnum, GetEnums, GetField, GetFieldType, GetFields, GetModel, GetModels, LiteralExpression, MappedBuiltinType, MemberExpression, ModelDef, NonRelationFields, NullExpression, ProcedureDef, ProcedureParam, RelationFieldType, RelationFields, RelationInfo, ScalarFields, SchemaDef, ThisExpression, UnaryExpression, UnaryOperator };
package/dist/schema.js ADDED
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,51 +1,55 @@
1
1
  {
2
2
  "name": "@zenstackhq/sdk",
3
- "version": "2.16.0",
4
- "description": "ZenStack plugin development SDK",
5
- "main": "index.js",
6
- "publishConfig": {
7
- "directory": "dist",
8
- "linkDirectory": true
9
- },
3
+ "version": "3.0.0-alpha.0",
4
+ "description": "ZenStack SDK",
5
+ "type": "module",
10
6
  "keywords": [],
11
- "author": "",
7
+ "author": "ZenStack Team",
12
8
  "license": "MIT",
13
- "dependencies": {
14
- "@prisma/generator-helper": "6.10.x",
15
- "@prisma/internals": "6.10.x",
16
- "langium": "1.3.1",
17
- "semver": "^7.5.2",
18
- "ts-morph": "^16.0.0",
19
- "ts-pattern": "^4.3.0",
20
- "@zenstackhq/language": "2.16.0",
21
- "@zenstackhq/runtime": "2.16.0"
22
- },
23
- "devDependencies": {
24
- "@types/semver": "^7.3.13"
25
- },
9
+ "files": [
10
+ "dist"
11
+ ],
26
12
  "exports": {
27
13
  ".": {
28
- "types": "./index.d.ts",
29
- "default": "./index.js"
30
- },
31
- "./ast": {
32
- "types": "./ast.d.ts",
33
- "default": "./ast.js"
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
+ }
34
22
  },
35
- "./prisma": {
36
- "types": "./prisma.d.ts",
37
- "default": "./prisma.js"
38
- },
39
- "./dmmf-helpers": {
40
- "types": "./dmmf-helpers/index.d.ts",
41
- "default": "./dmmf-helpers/index.js"
42
- },
43
- "./package.json": "./package.json"
23
+ "./schema": {
24
+ "import": {
25
+ "types": "./dist/schema.d.ts",
26
+ "default": "./dist/schema.js"
27
+ },
28
+ "require": {
29
+ "types": "./dist/schema.d.cts",
30
+ "default": "./dist/schema.cjs"
31
+ }
32
+ }
33
+ },
34
+ "dependencies": {
35
+ "langium": "~3.3.0",
36
+ "tiny-invariant": "^1.3.3",
37
+ "tmp": "^0.2.3",
38
+ "ts-pattern": "^5.7.0",
39
+ "typescript": "^5.8.3",
40
+ "@zenstackhq/language": "3.0.0-alpha.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^20.0.0",
44
+ "@types/tmp": "^0.2.6",
45
+ "decimal.js": "^10.4.3",
46
+ "kysely": "^0.27.6"
44
47
  },
45
48
  "scripts": {
46
- "clean": "rimraf dist",
49
+ "build": "tsup-node",
50
+ "watch": "tsup-node --watch",
47
51
  "lint": "eslint src --ext ts",
48
- "build": "pnpm lint --max-warnings=0 && pnpm clean && tsc && copyfiles ./package.json ./LICENSE ./README.md dist && pnpm pack dist --pack-destination ../../../.build",
49
- "watch": "tsc --watch"
52
+ "test": "vitest",
53
+ "pack": "pnpm pack"
50
54
  }
51
55
  }
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # ZenStack plugin development SDK
2
-
3
- This package provides types and utilities for developing a ZenStack plugin.
4
-
5
- Visit [Homepage](https://zenstack.dev) for more details.
package/ast.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from '@zenstackhq/language/ast';
package/ast.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("@zenstackhq/language/ast"), exports);
18
- //# sourceMappingURL=ast.js.map
package/ast.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"ast.js","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC"}
package/code-gen.d.ts DELETED
@@ -1,37 +0,0 @@
1
- import { CompilerOptions, Project, SourceFile } from 'ts-morph';
2
- /**
3
- * Creates a TS code generation project
4
- */
5
- export declare function createProject(options?: CompilerOptions): Project;
6
- export declare function saveSourceFile(sourceFile: SourceFile): void;
7
- /**
8
- * Persists a TS project to disk.
9
- */
10
- export declare function saveProject(project: Project): Promise<void>;
11
- /**
12
- * Emit a TS project to JS files.
13
- */
14
- export declare function emitProject(project: Project): Promise<void>;
15
- export interface CodeWriter {
16
- block(callback: () => void): void;
17
- inlineBlock(callback: () => void): void;
18
- write(text: string): void;
19
- writeLine(text: string): void;
20
- conditionalWrite(condition: boolean, text: string): void;
21
- }
22
- /**
23
- * A fast code writer.
24
- */
25
- export declare class FastWriter implements CodeWriter {
26
- private readonly indentSize;
27
- private content;
28
- private indentLevel;
29
- constructor(indentSize?: number);
30
- get result(): string;
31
- block(callback: () => void): void;
32
- inlineBlock(callback: () => void): void;
33
- write(text: string): void;
34
- writeLine(text: string): void;
35
- conditionalWrite(condition: boolean, text: string): void;
36
- private indent;
37
- }
package/code-gen.js DELETED
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.FastWriter = void 0;
13
- exports.createProject = createProject;
14
- exports.saveSourceFile = saveSourceFile;
15
- exports.saveProject = saveProject;
16
- exports.emitProject = emitProject;
17
- const ts_morph_1 = require("ts-morph");
18
- const types_1 = require("./types");
19
- /**
20
- * Creates a TS code generation project
21
- */
22
- function createProject(options) {
23
- return new ts_morph_1.Project({
24
- compilerOptions: Object.assign({ target: ts_morph_1.ScriptTarget.ES2016, module: ts_morph_1.ModuleKind.CommonJS, esModuleInterop: true, declaration: true, strict: true, skipLibCheck: true, noEmitOnError: true, noImplicitAny: false, skipDefaultLibCheck: true, types: [] }, options),
25
- });
26
- }
27
- function saveSourceFile(sourceFile) {
28
- sourceFile.replaceWithText(`/******************************************************************************
29
- * This file was generated by ZenStack CLI.
30
- ******************************************************************************/
31
-
32
- /* eslint-disable */
33
- // @ts-nocheck
34
-
35
- ${sourceFile.getText()}`);
36
- sourceFile.formatText();
37
- sourceFile.saveSync();
38
- }
39
- /**
40
- * Persists a TS project to disk.
41
- */
42
- function saveProject(project) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- project.getSourceFiles().forEach(saveSourceFile);
45
- yield project.save();
46
- });
47
- }
48
- /**
49
- * Emit a TS project to JS files.
50
- */
51
- function emitProject(project) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- // ignore type checking for all source files
54
- for (const sf of project.getSourceFiles()) {
55
- sf.insertStatements(0, '// @ts-nocheck');
56
- }
57
- const errors = project.getPreEmitDiagnostics().filter((d) => d.getCategory() === ts_morph_1.DiagnosticCategory.Error);
58
- if (errors.length > 0) {
59
- console.error('Error compiling generated code:');
60
- console.error(project.formatDiagnosticsWithColorAndContext(errors.slice(0, 10)));
61
- yield project.save();
62
- throw new types_1.PluginError('', `Error compiling generated code`);
63
- }
64
- const result = yield project.emit();
65
- const emitErrors = result.getDiagnostics().filter((d) => d.getCategory() === ts_morph_1.DiagnosticCategory.Error);
66
- if (emitErrors.length > 0) {
67
- console.error('Some generated code is not emitted:');
68
- console.error(project.formatDiagnosticsWithColorAndContext(emitErrors.slice(0, 10)));
69
- yield project.save();
70
- throw new types_1.PluginError('', `Error emitting generated code`);
71
- }
72
- });
73
- }
74
- /**
75
- * A fast code writer.
76
- */
77
- class FastWriter {
78
- constructor(indentSize = 4) {
79
- this.indentSize = indentSize;
80
- this.content = '';
81
- this.indentLevel = 0;
82
- }
83
- get result() {
84
- return this.content;
85
- }
86
- block(callback) {
87
- this.content += '{\n';
88
- this.indentLevel++;
89
- callback();
90
- this.indentLevel--;
91
- this.content += '\n}';
92
- }
93
- inlineBlock(callback) {
94
- this.content += '{';
95
- callback();
96
- this.content += '}';
97
- }
98
- write(text) {
99
- this.content += this.indent(text);
100
- }
101
- writeLine(text) {
102
- this.content += `${this.indent(text)}\n`;
103
- }
104
- conditionalWrite(condition, text) {
105
- if (condition) {
106
- this.write(text);
107
- }
108
- }
109
- indent(text) {
110
- return ' '.repeat(this.indentLevel * this.indentSize) + text;
111
- }
112
- }
113
- exports.FastWriter = FastWriter;
114
- //# sourceMappingURL=code-gen.js.map
package/code-gen.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"code-gen.js","sourceRoot":"","sources":["../src/code-gen.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,sCAgBC;AAED,wCAaC;AAKD,kCAGC;AAKD,kCAuBC;AAzED,uCAA8G;AAC9G,mCAAsC;AAEtC;;GAEG;AACH,SAAgB,aAAa,CAAC,OAAyB;IACnD,OAAO,IAAI,kBAAO,CAAC;QACf,eAAe,kBACX,MAAM,EAAE,uBAAY,CAAC,MAAM,EAC3B,MAAM,EAAE,qBAAU,CAAC,QAAQ,EAC3B,eAAe,EAAE,IAAI,EACrB,WAAW,EAAE,IAAI,EACjB,MAAM,EAAE,IAAI,EACZ,YAAY,EAAE,IAAI,EAClB,aAAa,EAAE,IAAI,EACnB,aAAa,EAAE,KAAK,EACpB,mBAAmB,EAAE,IAAI,EACzB,KAAK,EAAE,EAAE,IACN,OAAO,CACb;KACJ,CAAC,CAAC;AACP,CAAC;AAED,SAAgB,cAAc,CAAC,UAAsB;IACjD,UAAU,CAAC,eAAe,CACtB;;;;;;;MAOF,UAAU,CAAC,OAAO,EAAE,EAAE,CACvB,CAAC;IACF,UAAU,CAAC,UAAU,EAAE,CAAC;IACxB,UAAU,CAAC,QAAQ,EAAE,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,SAAsB,WAAW,CAAC,OAAgB;;QAC9C,OAAO,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACjD,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;CAAA;AAED;;GAEG;AACH,SAAsB,WAAW,CAAC,OAAgB;;QAC9C,4CAA4C;QAC5C,KAAK,MAAM,EAAE,IAAI,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;YACxC,EAAE,CAAC,gBAAgB,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;QAC7C,CAAC;QAED,MAAM,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CAAC;IAE/C,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,QAAoB;QACtB,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC;QACtB,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,QAAQ,EAAE,CAAC;QACX,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC;IAC1B,CAAC;IAED,WAAW,CAAC,QAAoB;QAC5B,IAAI,CAAC,OAAO,IAAI,GAAG,CAAC;QACpB,QAAQ,EAAE,CAAC;QACX,IAAI,CAAC,OAAO,IAAI,GAAG,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,IAAY;QACd,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,SAAS,CAAC,IAAY;QAClB,IAAI,CAAC,OAAO,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;IAC7C,CAAC;IAED,gBAAgB,CAAC,SAAkB,EAAE,IAAY;QAC7C,IAAI,SAAS,EAAE,CAAC;YACZ,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;IACL,CAAC;IAEO,MAAM,CAAC,IAAY;QACvB,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IACjE,CAAC;CACJ;AAzCD,gCAyCC"}
package/constants.d.ts DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * @zenstackhq/runtime package name
3
- */
4
- export declare const RUNTIME_PACKAGE = "@zenstackhq/runtime";
5
- export { CrudFailureReason } from '@zenstackhq/runtime';
6
- /**
7
- * Expression context
8
- */
9
- export declare enum ExpressionContext {
10
- DefaultValue = "DefaultValue",
11
- AccessPolicy = "AccessPolicy",
12
- ValidationRule = "ValidationRule",
13
- Index = "Index"
14
- }
15
- export declare const STD_LIB_MODULE_NAME = "stdlib.zmodel";
package/constants.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.STD_LIB_MODULE_NAME = exports.ExpressionContext = exports.CrudFailureReason = exports.RUNTIME_PACKAGE = void 0;
4
- /**
5
- * @zenstackhq/runtime package name
6
- */
7
- exports.RUNTIME_PACKAGE = '@zenstackhq/runtime';
8
- var runtime_1 = require("@zenstackhq/runtime");
9
- Object.defineProperty(exports, "CrudFailureReason", { enumerable: true, get: function () { return runtime_1.CrudFailureReason; } });
10
- /**
11
- * Expression context
12
- */
13
- var ExpressionContext;
14
- (function (ExpressionContext) {
15
- ExpressionContext["DefaultValue"] = "DefaultValue";
16
- ExpressionContext["AccessPolicy"] = "AccessPolicy";
17
- ExpressionContext["ValidationRule"] = "ValidationRule";
18
- ExpressionContext["Index"] = "Index";
19
- })(ExpressionContext || (exports.ExpressionContext = ExpressionContext = {}));
20
- exports.STD_LIB_MODULE_NAME = 'stdlib.zmodel';
21
- //# sourceMappingURL=constants.js.map
package/constants.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,eAAe,GAAG,qBAAqB,CAAC;AAErD,+CAAwD;AAA/C,4GAAA,iBAAiB,OAAA;AAE1B;;GAEG;AACH,IAAY,iBAKX;AALD,WAAY,iBAAiB;IACzB,kDAA6B,CAAA;IAC7B,kDAA6B,CAAA;IAC7B,sDAAiC,CAAA;IACjC,oCAAe,CAAA;AACnB,CAAC,EALW,iBAAiB,iCAAjB,iBAAiB,QAK5B;AAEY,QAAA,mBAAmB,GAAG,eAAe,CAAC"}
@@ -1,5 +0,0 @@
1
- import type { DMMF } from '../prisma';
2
- import { AggregateOperationSupport } from './types';
3
- export declare const isAggregateInputType: (name: string) => boolean;
4
- export declare function addMissingInputObjectTypesForAggregate(inputObjectTypes: DMMF.InputType[], outputObjectTypes: DMMF.OutputType[]): void;
5
- export declare function resolveAggregateOperationSupport(inputObjectTypes: DMMF.InputType[]): AggregateOperationSupport;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAggregateInputType = void 0;
4
- exports.addMissingInputObjectTypesForAggregate = addMissingInputObjectTypesForAggregate;
5
- exports.resolveAggregateOperationSupport = resolveAggregateOperationSupport;
6
- const local_helpers_1 = require("@zenstackhq/runtime/local-helpers");
7
- const isAggregateOutputType = (name) => /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(name);
8
- const isAggregateInputType = (name) => name.endsWith('CountAggregateInput') ||
9
- name.endsWith('SumAggregateInput') ||
10
- name.endsWith('AvgAggregateInput') ||
11
- name.endsWith('MinAggregateInput') ||
12
- name.endsWith('MaxAggregateInput');
13
- exports.isAggregateInputType = isAggregateInputType;
14
- function addMissingInputObjectTypesForAggregate(inputObjectTypes, outputObjectTypes) {
15
- const aggregateOutputTypes = outputObjectTypes.filter(({ name }) => isAggregateOutputType(name));
16
- for (const aggregateOutputType of aggregateOutputTypes) {
17
- const name = aggregateOutputType.name.replace(/(?:OutputType|Output)$/, '');
18
- inputObjectTypes.push({
19
- constraints: { maxNumFields: null, minNumFields: null },
20
- name: `${(0, local_helpers_1.upperCaseFirst)(name)}Input`,
21
- fields: aggregateOutputType.fields.map((field) => ({
22
- name: field.name,
23
- isNullable: false,
24
- isRequired: false,
25
- inputTypes: [
26
- {
27
- isList: false,
28
- type: 'True',
29
- location: 'scalar',
30
- },
31
- ],
32
- })),
33
- });
34
- }
35
- }
36
- function resolveAggregateOperationSupport(inputObjectTypes) {
37
- const aggregateOperationSupport = {};
38
- for (const inputType of inputObjectTypes) {
39
- if ((0, exports.isAggregateInputType)(inputType.name)) {
40
- const name = inputType.name.replace('AggregateInput', '');
41
- if (name.endsWith('Count')) {
42
- const model = name.replace('Count', '');
43
- aggregateOperationSupport[model] = Object.assign(Object.assign({}, aggregateOperationSupport[model]), { count: true });
44
- }
45
- else if (name.endsWith('Min')) {
46
- const model = name.replace('Min', '');
47
- aggregateOperationSupport[model] = Object.assign(Object.assign({}, aggregateOperationSupport[model]), { min: true });
48
- }
49
- else if (name.endsWith('Max')) {
50
- const model = name.replace('Max', '');
51
- aggregateOperationSupport[model] = Object.assign(Object.assign({}, aggregateOperationSupport[model]), { max: true });
52
- }
53
- else if (name.endsWith('Sum')) {
54
- const model = name.replace('Sum', '');
55
- aggregateOperationSupport[model] = Object.assign(Object.assign({}, aggregateOperationSupport[model]), { sum: true });
56
- }
57
- else if (name.endsWith('Avg')) {
58
- const model = name.replace('Avg', '');
59
- aggregateOperationSupport[model] = Object.assign(Object.assign({}, aggregateOperationSupport[model]), { avg: true });
60
- }
61
- }
62
- }
63
- return aggregateOperationSupport;
64
- }
65
- //# sourceMappingURL=aggregate-helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aggregate-helpers.js","sourceRoot":"","sources":["../../src/dmmf-helpers/aggregate-helpers.ts"],"names":[],"mappings":";;;AAaA,wFAwBC;AAED,4EAuCC;AA9ED,qEAAmE;AAInE,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,+CAA+C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEpG,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAE,EAAE,CACjD,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC;IACpC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC;IAClC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC;IAClC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC;IAClC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;AAL1B,QAAA,oBAAoB,wBAKM;AAEvC,SAAgB,sCAAsC,CAClD,gBAAkC,EAClC,iBAAoC;IAEpC,MAAM,oBAAoB,GAAG,iBAAiB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TypesForInclude(inputObjectTypes: DMMF.InputType[], models: readonly DMMF.Model[]): void;
@@ -1,88 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.addMissingInputObjectTypesForInclude = addMissingInputObjectTypesForInclude;
7
- const semver_1 = __importDefault(require("semver"));
8
- const prisma_1 = require("../prisma");
9
- const model_helpers_1 = require("./model-helpers");
10
- function addMissingInputObjectTypesForInclude(inputObjectTypes, models) {
11
- // generate input object types necessary to support ModelInclude with relation support
12
- const generatedIncludeInputObjectTypes = generateModelIncludeInputObjectTypes(models);
13
- for (const includeInputObjectType of generatedIncludeInputObjectTypes) {
14
- inputObjectTypes.push(includeInputObjectType);
15
- }
16
- }
17
- function generateModelIncludeInputObjectTypes(models) {
18
- const modelIncludeInputObjectTypes = [];
19
- const prismaVersion = (0, prisma_1.getPrismaVersion)();
20
- for (const model of models) {
21
- const { name: modelName, fields: modelFields } = model;
22
- const fields = [];
23
- for (const modelField of modelFields) {
24
- const { name: modelFieldName, isList, type } = modelField;
25
- const isRelationField = (0, model_helpers_1.checkIsModelRelationField)(modelField);
26
- if (isRelationField) {
27
- const field = {
28
- name: modelFieldName,
29
- isRequired: false,
30
- isNullable: false,
31
- inputTypes: [
32
- { isList: false, type: 'Boolean', location: 'scalar' },
33
- {
34
- isList: false,
35
- type: isList
36
- ? `${type}FindManyArgs`
37
- : prismaVersion && semver_1.default.gte(prismaVersion, '6.0.0')
38
- ? `${type}DefaultArgs` // Prisma 6+ removed [Model]Args type
39
- : `${type}Args`,
40
- location: 'inputObjectTypes',
41
- namespace: 'prisma',
42
- },
43
- ],
44
- };
45
- fields.push(field);
46
- }
47
- }
48
- /**
49
- * include is not generated for models that do not have a relation with any other models
50
- * -> continue onto the next model
51
- */
52
- const hasRelationToAnotherModel = (0, model_helpers_1.checkModelHasModelRelation)(model);
53
- if (!hasRelationToAnotherModel) {
54
- continue;
55
- }
56
- const hasManyRelationToAnotherModel = (0, model_helpers_1.checkModelHasManyModelRelation)(model);
57
- const shouldAddCountField = hasManyRelationToAnotherModel;
58
- if (shouldAddCountField) {
59
- const inputTypes = [{ isList: false, type: 'Boolean', location: 'scalar' }];
60
- inputTypes.push({
61
- isList: false,
62
- type: prismaVersion && semver_1.default.gte(prismaVersion, '6.0.0')
63
- ? `${modelName}CountOutputTypeDefaultArgs` // Prisma 6+ removed [Model]CountOutputTypeArgs type
64
- : `${modelName}CountOutputTypeArgs`,
65
- location: 'inputObjectTypes',
66
- namespace: 'prisma',
67
- });
68
- const _countField = {
69
- name: '_count',
70
- isRequired: false,
71
- isNullable: false,
72
- inputTypes,
73
- };
74
- fields.push(_countField);
75
- }
76
- const modelIncludeInputObjectType = {
77
- name: `${modelName}Include`,
78
- constraints: {
79
- maxNumFields: null,
80
- minNumFields: null,
81
- },
82
- fields,
83
- };
84
- modelIncludeInputObjectTypes.push(modelIncludeInputObjectType);
85
- }
86
- return modelIncludeInputObjectTypes;
87
- }
88
- //# sourceMappingURL=include-helpers.js.map