@zenstackhq/sdk 2.16.0 → 3.0.0-alpha.1
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 +1 -1
- package/dist/index.cjs +1906 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +196 -0
- package/dist/index.d.ts +196 -0
- package/dist/index.js +1872 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.cjs +19 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +138 -0
- package/dist/schema.d.ts +138 -0
- package/dist/schema.js +1 -0
- package/dist/schema.js.map +1 -0
- package/package.json +43 -39
- package/README.md +0 -5
- package/ast.d.ts +0 -1
- package/ast.js +0 -18
- package/ast.js.map +0 -1
- package/code-gen.d.ts +0 -37
- package/code-gen.js +0 -114
- package/code-gen.js.map +0 -1
- package/constants.d.ts +0 -15
- package/constants.js +0 -21
- package/constants.js.map +0 -1
- package/dmmf-helpers/aggregate-helpers.d.ts +0 -5
- package/dmmf-helpers/aggregate-helpers.js +0 -65
- package/dmmf-helpers/aggregate-helpers.js.map +0 -1
- package/dmmf-helpers/include-helpers.d.ts +0 -2
- package/dmmf-helpers/include-helpers.js +0 -88
- package/dmmf-helpers/include-helpers.js.map +0 -1
- package/dmmf-helpers/index.d.ts +0 -7
- package/dmmf-helpers/index.js +0 -24
- package/dmmf-helpers/index.js.map +0 -1
- package/dmmf-helpers/missing-types-helper.d.ts +0 -2
- package/dmmf-helpers/missing-types-helper.js +0 -14
- package/dmmf-helpers/missing-types-helper.js.map +0 -1
- package/dmmf-helpers/model-helpers.d.ts +0 -16
- package/dmmf-helpers/model-helpers.js +0 -38
- package/dmmf-helpers/model-helpers.js.map +0 -1
- package/dmmf-helpers/modelArgs-helpers.d.ts +0 -2
- package/dmmf-helpers/modelArgs-helpers.js +0 -67
- package/dmmf-helpers/modelArgs-helpers.js.map +0 -1
- package/dmmf-helpers/select-helpers.d.ts +0 -2
- package/dmmf-helpers/select-helpers.js +0 -152
- package/dmmf-helpers/select-helpers.js.map +0 -1
- package/dmmf-helpers/types.d.ts +0 -20
- package/dmmf-helpers/types.js +0 -3
- package/dmmf-helpers/types.js.map +0 -1
- package/index.d.ts +0 -11
- package/index.js +0 -30
- package/index.js.map +0 -1
- package/model-meta-generator.d.ts +0 -24
- package/model-meta-generator.js +0 -458
- package/model-meta-generator.js.map +0 -1
- package/names.d.ts +0 -9
- package/names.js +0 -17
- package/names.js.map +0 -1
- package/path.d.ts +0 -4
- package/path.js +0 -15
- package/path.js.map +0 -1
- package/policy.d.ts +0 -13
- package/policy.js +0 -57
- package/policy.js.map +0 -1
- package/prisma.d.ts +0 -21
- package/prisma.js +0 -84
- package/prisma.js.map +0 -1
- package/types.d.ts +0 -97
- package/types.js +0 -14
- package/types.js.map +0 -1
- package/typescript-expression-transformer.d.ts +0 -64
- package/typescript-expression-transformer.js +0 -491
- package/typescript-expression-transformer.js.map +0 -1
- package/utils.d.ts +0 -103
- package/utils.js +0 -633
- package/utils.js.map +0 -1
- package/validation.d.ts +0 -7
- package/validation.js +0 -37
- package/validation.js.map +0 -1
- package/zmodel-code-generator.d.ts +0 -66
- package/zmodel-code-generator.js +0 -353
- package/zmodel-code-generator.js.map +0 -1
package/prisma.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.getPrismaClientImportSpec = getPrismaClientImportSpec;
|
|
8
|
-
exports.getDMMF = getDMMF;
|
|
9
|
-
exports.getPrismaVersion = getPrismaVersion;
|
|
10
|
-
exports.supportCreateMany = supportCreateMany;
|
|
11
|
-
const internals_1 = require("@prisma/internals");
|
|
12
|
-
const runtime_1 = require("@zenstackhq/runtime");
|
|
13
|
-
const path_1 = __importDefault(require("path"));
|
|
14
|
-
const semver_1 = __importDefault(require("semver"));
|
|
15
|
-
const constants_1 = require("./constants");
|
|
16
|
-
const utils_1 = require("./utils");
|
|
17
|
-
const path_2 = require("./path");
|
|
18
|
-
/**
|
|
19
|
-
* Given an import context directory and plugin options, compute the import spec for the Prisma Client.
|
|
20
|
-
*/
|
|
21
|
-
function getPrismaClientImportSpec(importingFromDir, options) {
|
|
22
|
-
if (!options.prismaClientPath || options.prismaClientPath === '@prisma/client') {
|
|
23
|
-
return '@prisma/client';
|
|
24
|
-
}
|
|
25
|
-
if (options.prismaClientPath.startsWith(constants_1.RUNTIME_PACKAGE) ||
|
|
26
|
-
options.prismaClientPath.startsWith(runtime_1.DEFAULT_RUNTIME_LOAD_PATH)) {
|
|
27
|
-
return options.prismaClientPath;
|
|
28
|
-
}
|
|
29
|
-
if (path_1.default.isAbsolute(options.prismaClientPath)) {
|
|
30
|
-
// absolute path
|
|
31
|
-
return options.prismaClientPath;
|
|
32
|
-
}
|
|
33
|
-
// resolve absolute path based on the zmodel file location
|
|
34
|
-
const resolvedPrismaClientOutput = path_1.default.resolve(path_1.default.dirname(options.schemaPath), options.prismaClientPath);
|
|
35
|
-
// translate to path relative to the importing context directory
|
|
36
|
-
let result = (0, path_2.normalizedRelative)(importingFromDir, resolvedPrismaClientOutput);
|
|
37
|
-
// remove leading `node_modules` (which may be provided by the user)
|
|
38
|
-
result = result.replace(/^([./\\]*)?node_modules\//, '');
|
|
39
|
-
return normalizePath(result);
|
|
40
|
-
}
|
|
41
|
-
function normalizePath(p) {
|
|
42
|
-
return p ? p.split(path_1.default.sep).join(path_1.default.posix.sep) : p;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Loads Prisma DMMF
|
|
46
|
-
*/
|
|
47
|
-
function getDMMF(options) {
|
|
48
|
-
return (0, internals_1.getDMMF)(options);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Gets the installed Prisma's version
|
|
52
|
-
*/
|
|
53
|
-
function getPrismaVersion() {
|
|
54
|
-
if (process.env.ZENSTACK_TEST === '1') {
|
|
55
|
-
// test environment
|
|
56
|
-
try {
|
|
57
|
-
return require(path_1.default.resolve('./node_modules/@prisma/client/package.json')).version;
|
|
58
|
-
}
|
|
59
|
-
catch (_a) {
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
return require('@prisma/client/package.json').version;
|
|
65
|
-
}
|
|
66
|
-
catch (_b) {
|
|
67
|
-
try {
|
|
68
|
-
return require('prisma/package.json').version;
|
|
69
|
-
}
|
|
70
|
-
catch (_c) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Returns if the given model supports `createMany` operation.
|
|
77
|
-
*/
|
|
78
|
-
function supportCreateMany(model) {
|
|
79
|
-
// `createMany` is supported for sqlite since Prisma 5.12.0
|
|
80
|
-
const prismaVersion = getPrismaVersion();
|
|
81
|
-
const dsProvider = (0, utils_1.getDataSourceProvider)(model);
|
|
82
|
-
return dsProvider !== 'sqlite' || (prismaVersion && semver_1.default.gte(prismaVersion, '5.12.0'));
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=prisma.js.map
|
package/prisma.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.js","sourceRoot":"","sources":["../src/prisma.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;;;AAgBvD,8DA2BC;AASD,0BAEC;AAKD,4CAmBC;AAKD,8CAKC;AArFD,iDAA6E;AAC7E,iDAAgE;AAChE,gDAAwB;AACxB,oDAA4B;AAE5B,2CAA8C;AAE9C,mCAAgD;AAChD,iCAA4C;AAE5C;;GAEG;AACH,SAAgB,yBAAyB,CAAC,gBAAwB,EAAE,OAAsB;IACtF,IAAI,CAAC,OAAO,CAAC,gBA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QACpC,mBAAmB;QACnB,IAAI,CAAC;YACD,OAAO,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAAC,CAAC,OAAO,CAAC;QACvF,CAAC;QAAC,WAAM,CAAC;YACL,OAAO,SAAS,CAAC;QACrB,CAAC;IACL,CAAC;IAED,IAAI,CAAC;QACD,OAAO,OAAO,CAAC,6BAA6B,CAAC,CAAC,OAAO,CAAC;IAC1D,CAAC;IAAC,WAAM,CAAC;QACL,IAAI,CAAC;YACD,OAAO,OAAO,CAAC,qBAAqB,CAAC,CAAC,OAAO,CAAC;QAClD,CAAC;QAAC,WAAM,CAAC;YACL,OAAO,SAAS,CAAC;QACrB,CAAC;IACL,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAAY;IAC1C,2DAA2D;IAC3D,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC;IACzC,MAAM,UAAU,GAAG,IAAA,6BAAqB,EAAC,KAAK,CAAC,CAAC;IAChD,OAAO,UAAU,KAAK,QAAQ,IAAI,CAAC,aAAa,IAAI,gBAAM,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC7F,CAAC"}
|
package/types.d.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import type { DMMF } from '@prisma/generator-helper';
|
|
2
|
-
import { Model } from '@zenstackhq/language/ast';
|
|
3
|
-
import type { Project } from 'ts-morph';
|
|
4
|
-
/**
|
|
5
|
-
* Plugin configuration option value type
|
|
6
|
-
*/
|
|
7
|
-
export type OptionValue = string | number | boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Plugin configuration options
|
|
10
|
-
*/
|
|
11
|
-
export type PluginDeclaredOptions = {
|
|
12
|
-
/***
|
|
13
|
-
* The provider package
|
|
14
|
-
*/
|
|
15
|
-
provider: string;
|
|
16
|
-
} & Record<string, OptionValue | OptionValue[]>;
|
|
17
|
-
/**
|
|
18
|
-
* Plugin configuration options for execution
|
|
19
|
-
*/
|
|
20
|
-
export type PluginOptions = {
|
|
21
|
-
/**
|
|
22
|
-
* ZModel schema absolute path
|
|
23
|
-
*/
|
|
24
|
-
schemaPath: string;
|
|
25
|
-
/**
|
|
26
|
-
* PrismaClient import path, either relative to `schemaPath` or absolute
|
|
27
|
-
*/
|
|
28
|
-
prismaClientPath?: string;
|
|
29
|
-
/**
|
|
30
|
-
* PrismaClient's TypeScript declaration file's path
|
|
31
|
-
* @private
|
|
32
|
-
*/
|
|
33
|
-
prismaClientDtsPath?: string;
|
|
34
|
-
/**
|
|
35
|
-
* An optional map of full names to shortened names
|
|
36
|
-
* @private
|
|
37
|
-
*/
|
|
38
|
-
shortNameMap?: Map<string, string>;
|
|
39
|
-
} & PluginDeclaredOptions;
|
|
40
|
-
/**
|
|
41
|
-
* Global options that apply to all plugins
|
|
42
|
-
*/
|
|
43
|
-
export type PluginGlobalOptions = {
|
|
44
|
-
/**
|
|
45
|
-
* Default output directory
|
|
46
|
-
*/
|
|
47
|
-
output?: string;
|
|
48
|
-
/**
|
|
49
|
-
* Whether to compile the generated code
|
|
50
|
-
*/
|
|
51
|
-
compile: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* The `ts-morph` project used for code generation.
|
|
54
|
-
* @private
|
|
55
|
-
*/
|
|
56
|
-
tsProject: Project;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Plugin run results.
|
|
60
|
-
*/
|
|
61
|
-
export type PluginResult = {
|
|
62
|
-
/**
|
|
63
|
-
* Warnings
|
|
64
|
-
*/
|
|
65
|
-
warnings: string[];
|
|
66
|
-
/**
|
|
67
|
-
* PrismaClient path, either relative to zmodel path or absolute, if the plugin
|
|
68
|
-
* generated a PrismaClient
|
|
69
|
-
*/
|
|
70
|
-
prismaClientPath?: string;
|
|
71
|
-
/**
|
|
72
|
-
* PrismaClient's TypeScript declaration file's path
|
|
73
|
-
* @private
|
|
74
|
-
*/
|
|
75
|
-
prismaClientDtsPath?: string;
|
|
76
|
-
/**
|
|
77
|
-
* An optional Prisma DMMF document that a plugin can generate
|
|
78
|
-
* @private
|
|
79
|
-
*/
|
|
80
|
-
dmmf?: DMMF.Document;
|
|
81
|
-
/**
|
|
82
|
-
* An optional map of full names to shortened names
|
|
83
|
-
* @private
|
|
84
|
-
*/
|
|
85
|
-
shortNameMap?: Map<string, string>;
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Plugin entry point function definition
|
|
89
|
-
*/
|
|
90
|
-
export type PluginFunction = (model: Model, options: PluginOptions, dmmf: DMMF.Document | undefined, globalOptions?: PluginGlobalOptions) => Promise<PluginResult> | PluginResult | Promise<void> | void;
|
|
91
|
-
/**
|
|
92
|
-
* Plugin error
|
|
93
|
-
*/
|
|
94
|
-
export declare class PluginError extends Error {
|
|
95
|
-
plugin: string;
|
|
96
|
-
constructor(plugin: string, message: string);
|
|
97
|
-
}
|
package/types.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PluginError = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Plugin error
|
|
6
|
-
*/
|
|
7
|
-
class PluginError extends Error {
|
|
8
|
-
constructor(plugin, message) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.plugin = plugin;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.PluginError = PluginError;
|
|
14
|
-
//# sourceMappingURL=types.js.map
|
package/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA+GA;;GAEG;AACH,MAAa,WAAY,SAAQ,KAAK;IAClC,YAAmB,MAAc,EAAE,OAAe;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAC;QADA,WAAM,GAAN,MAAM,CAAQ;IAEjC,CAAC;CACJ;AAJD,kCAIC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Expression } from '@zenstackhq/language/ast';
|
|
2
|
-
import { ExpressionContext } from './constants';
|
|
3
|
-
export declare class TypeScriptExpressionTransformerError extends Error {
|
|
4
|
-
constructor(message: string);
|
|
5
|
-
}
|
|
6
|
-
type Options = {
|
|
7
|
-
isPostGuard?: boolean;
|
|
8
|
-
fieldReferenceContext?: string;
|
|
9
|
-
thisExprContext?: string;
|
|
10
|
-
futureRefContext?: string;
|
|
11
|
-
context: ExpressionContext;
|
|
12
|
-
operationContext?: 'read' | 'create' | 'update' | 'postUpdate' | 'delete';
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Transforms ZModel expression to plain TypeScript expression.
|
|
16
|
-
*/
|
|
17
|
-
export declare class TypeScriptExpressionTransformer {
|
|
18
|
-
private readonly options;
|
|
19
|
-
/**
|
|
20
|
-
* Constructs a new TypeScriptExpressionTransformer.
|
|
21
|
-
*
|
|
22
|
-
* @param isPostGuard indicates if we're writing for post-update conditions
|
|
23
|
-
*/
|
|
24
|
-
constructor(options: Options);
|
|
25
|
-
/**
|
|
26
|
-
* Transforms the given expression to a TypeScript expression.
|
|
27
|
-
* @param normalizeUndefined if undefined values should be normalized to null
|
|
28
|
-
* @returns
|
|
29
|
-
*/
|
|
30
|
-
transform(expr: Expression, normalizeUndefined?: boolean): string;
|
|
31
|
-
private this;
|
|
32
|
-
private memberAccess;
|
|
33
|
-
private invocation;
|
|
34
|
-
private _auth;
|
|
35
|
-
private _now;
|
|
36
|
-
private _length;
|
|
37
|
-
private _contains;
|
|
38
|
-
private _startsWith;
|
|
39
|
-
private _endsWith;
|
|
40
|
-
private _regex;
|
|
41
|
-
private _email;
|
|
42
|
-
private _datetime;
|
|
43
|
-
private _url;
|
|
44
|
-
private _has;
|
|
45
|
-
private _hasEvery;
|
|
46
|
-
private _hasSome;
|
|
47
|
-
private _isEmpty;
|
|
48
|
-
private _check;
|
|
49
|
-
private toStringWithCaseChange;
|
|
50
|
-
private _currentModel;
|
|
51
|
-
private _currentOperation;
|
|
52
|
-
private ensureBoolean;
|
|
53
|
-
private ensureBooleanTernary;
|
|
54
|
-
private reference;
|
|
55
|
-
private null;
|
|
56
|
-
private array;
|
|
57
|
-
private literal;
|
|
58
|
-
private unary;
|
|
59
|
-
private isModelType;
|
|
60
|
-
private binary;
|
|
61
|
-
private extractNullComparison;
|
|
62
|
-
private collectionPredicate;
|
|
63
|
-
}
|
|
64
|
-
export {};
|