@zenstackhq/sdk 0.6.0-pre.2 → 1.0.0-alpha.101
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/README.md +5 -1
- package/code-gen.d.ts +5 -0
- package/code-gen.js +54 -0
- package/code-gen.js.map +1 -0
- package/constants.d.ts +25 -0
- package/constants.js +30 -0
- package/constants.js.map +1 -0
- package/dmmf-helpers/aggregate-helpers.d.ts +5 -0
- package/dmmf-helpers/aggregate-helpers.js +64 -0
- package/dmmf-helpers/aggregate-helpers.js.map +1 -0
- package/dmmf-helpers/include-helpers.d.ts +2 -0
- package/dmmf-helpers/include-helpers.js +77 -0
- package/dmmf-helpers/include-helpers.js.map +1 -0
- package/dmmf-helpers/index.d.ts +7 -0
- package/dmmf-helpers/index.js +24 -0
- package/dmmf-helpers/index.js.map +1 -0
- package/dmmf-helpers/missing-types-helper.d.ts +2 -0
- package/dmmf-helpers/missing-types-helper.js +15 -0
- package/dmmf-helpers/missing-types-helper.js.map +1 -0
- package/dmmf-helpers/model-helpers.d.ts +6 -0
- package/dmmf-helpers/model-helpers.js +39 -0
- package/dmmf-helpers/model-helpers.js.map +1 -0
- package/dmmf-helpers/modelArgs-helpers.d.ts +2 -0
- package/dmmf-helpers/modelArgs-helpers.js +60 -0
- package/dmmf-helpers/modelArgs-helpers.js.map +1 -0
- package/dmmf-helpers/select-helpers.d.ts +2 -0
- package/dmmf-helpers/select-helpers.js +137 -0
- package/dmmf-helpers/select-helpers.js.map +1 -0
- package/dmmf-helpers/types.d.ts +20 -0
- package/dmmf-helpers/types.js +3 -0
- package/dmmf-helpers/types.js.map +1 -0
- package/index.d.ts +5 -12
- package/index.js +19 -9
- package/index.js.map +1 -1
- package/package.json +9 -4
- package/policy.d.ts +13 -0
- package/policy.js +70 -0
- package/policy.js.map +1 -0
- package/types.d.ts +23 -0
- package/types.js +13 -0
- package/types.js.map +1 -0
- package/utils.d.ts +11 -1
- package/utils.js +76 -2
- package/utils.js.map +1 -1
package/README.md
CHANGED
package/code-gen.d.ts
ADDED
package/code-gen.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.emitProject = void 0;
|
|
16
|
+
const prettier_1 = __importDefault(require("prettier"));
|
|
17
|
+
const formatOptions = {
|
|
18
|
+
trailingComma: 'all',
|
|
19
|
+
tabWidth: 4,
|
|
20
|
+
printWidth: 120,
|
|
21
|
+
bracketSpacing: true,
|
|
22
|
+
semi: true,
|
|
23
|
+
singleQuote: true,
|
|
24
|
+
useTabs: false,
|
|
25
|
+
parser: 'typescript',
|
|
26
|
+
};
|
|
27
|
+
function formatFile(sourceFile) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
try {
|
|
30
|
+
const content = sourceFile.getFullText();
|
|
31
|
+
const formatted = prettier_1.default.format(content, formatOptions);
|
|
32
|
+
sourceFile.replaceWithText(formatted);
|
|
33
|
+
yield sourceFile.save();
|
|
34
|
+
}
|
|
35
|
+
catch (_a) {
|
|
36
|
+
/* empty */
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Emit a TS project to JS files.
|
|
42
|
+
*/
|
|
43
|
+
function emitProject(project, format = true) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (format) {
|
|
46
|
+
yield Promise.all(project.getSourceFiles().map((sf) => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
yield formatFile(sf);
|
|
48
|
+
})));
|
|
49
|
+
}
|
|
50
|
+
yield project.emit();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.emitProject = emitProject;
|
|
54
|
+
//# sourceMappingURL=code-gen.js.map
|
package/code-gen.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-gen.js","sourceRoot":"","sources":["../src/code-gen.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAAgC;AAGhC,MAAM,aAAa,GAAG;IAClB,aAAa,EAAE,KAAK;IACpB,QAAQ,EAAE,CAAC;IACX,UAAU,EAAE,GAAG;IACf,cAAc,EAAE,IAAI;IACpB,IAAI,EAAE,IAAI;IACV,WAAW,EAAE,IAAI;IACjB,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,YAAY;CACd,CAAC;AAEX,SAAe,UAAU,CAAC,UAAsB;;QAC5C,IAAI;YACA,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;YACzC,MAAM,SAAS,GAAG,kBAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAC1D,UAAU,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;YACtC,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;SAC3B;QAAC,WAAM;YACJ,WAAW;SACd;IACL,CAAC;CAAA;AAED;;GAEG;AACH,SAAsB,WAAW,CAAC,OAAgB,EAAE,MAAM,GAAG,IAAI;;QAC7D,IAAI,MAAM,EAAE;YACR,MAAM,OAAO,CAAC,GAAG,CACb,OAAO,CAAC,cAAc,EAAE,CAAC,GAAG,CAAC,CAAO,EAAE,EAAE,EAAE;gBACtC,MAAM,UAAU,CAAC,EAAE,CAAC,CAAC;YACzB,CAAC,CAAA,CAAC,CACL,CAAC;SACL;QACD,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;CAAA;AATD,kCASC"}
|
package/constants.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auxiliary database field for supporting policy check for nested writes
|
|
3
|
+
*/
|
|
4
|
+
export declare const TRANSACTION_FIELD_NAME = "zenstack_transaction";
|
|
5
|
+
/**
|
|
6
|
+
* Auxiliary database field for building up policy check queries
|
|
7
|
+
*/
|
|
8
|
+
export declare const GUARD_FIELD_NAME = "zenstack_guard";
|
|
9
|
+
/**
|
|
10
|
+
* All Auxiliary fields.
|
|
11
|
+
*/
|
|
12
|
+
export declare const AUXILIARY_FIELDS: string[];
|
|
13
|
+
/**
|
|
14
|
+
* Reasons for a CRUD operation to fail.
|
|
15
|
+
*/
|
|
16
|
+
export declare enum CrudFailureReason {
|
|
17
|
+
/**
|
|
18
|
+
* CRUD suceeded but the result was not readable.
|
|
19
|
+
*/
|
|
20
|
+
RESULT_NOT_READABLE = "RESULT_NOT_READABLE"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @zenstackhq/runtime package name
|
|
24
|
+
*/
|
|
25
|
+
export declare const RUNTIME_PACKAGE = "@zenstackhq/runtime";
|
package/constants.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RUNTIME_PACKAGE = exports.CrudFailureReason = exports.AUXILIARY_FIELDS = exports.GUARD_FIELD_NAME = exports.TRANSACTION_FIELD_NAME = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Auxiliary database field for supporting policy check for nested writes
|
|
6
|
+
*/
|
|
7
|
+
exports.TRANSACTION_FIELD_NAME = 'zenstack_transaction';
|
|
8
|
+
/**
|
|
9
|
+
* Auxiliary database field for building up policy check queries
|
|
10
|
+
*/
|
|
11
|
+
exports.GUARD_FIELD_NAME = 'zenstack_guard';
|
|
12
|
+
/**
|
|
13
|
+
* All Auxiliary fields.
|
|
14
|
+
*/
|
|
15
|
+
exports.AUXILIARY_FIELDS = [exports.TRANSACTION_FIELD_NAME, exports.GUARD_FIELD_NAME];
|
|
16
|
+
/**
|
|
17
|
+
* Reasons for a CRUD operation to fail.
|
|
18
|
+
*/
|
|
19
|
+
var CrudFailureReason;
|
|
20
|
+
(function (CrudFailureReason) {
|
|
21
|
+
/**
|
|
22
|
+
* CRUD suceeded but the result was not readable.
|
|
23
|
+
*/
|
|
24
|
+
CrudFailureReason["RESULT_NOT_READABLE"] = "RESULT_NOT_READABLE";
|
|
25
|
+
})(CrudFailureReason = exports.CrudFailureReason || (exports.CrudFailureReason = {}));
|
|
26
|
+
/**
|
|
27
|
+
* @zenstackhq/runtime package name
|
|
28
|
+
*/
|
|
29
|
+
exports.RUNTIME_PACKAGE = '@zenstackhq/runtime';
|
|
30
|
+
//# sourceMappingURL=constants.js.map
|
package/constants.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,sBAAsB,GAAG,sBAAsB,CAAC;AAE7D;;GAEG;AACU,QAAA,gBAAgB,GAAG,gBAAgB,CAAC;AAEjD;;GAEG;AACU,QAAA,gBAAgB,GAAG,CAAC,8BAAsB,EAAE,wBAAgB,CAAC,CAAC;AAE3E;;GAEG;AACH,IAAY,iBAKX;AALD,WAAY,iBAAiB;IACzB;;OAEG;IACH,gEAA2C,CAAA;AAC/C,CAAC,EALW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAK5B;AAED;;GAEG;AACU,QAAA,eAAe,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DMMF } from '@prisma/generator-helper';
|
|
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;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAggregateOperationSupport = exports.addMissingInputObjectTypesForAggregate = exports.isAggregateInputType = void 0;
|
|
4
|
+
const isAggregateOutputType = (name) => /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(name);
|
|
5
|
+
const isAggregateInputType = (name) => name.endsWith('CountAggregateInput') ||
|
|
6
|
+
name.endsWith('SumAggregateInput') ||
|
|
7
|
+
name.endsWith('AvgAggregateInput') ||
|
|
8
|
+
name.endsWith('MinAggregateInput') ||
|
|
9
|
+
name.endsWith('MaxAggregateInput');
|
|
10
|
+
exports.isAggregateInputType = isAggregateInputType;
|
|
11
|
+
function addMissingInputObjectTypesForAggregate(inputObjectTypes, outputObjectTypes) {
|
|
12
|
+
const aggregateOutputTypes = outputObjectTypes.filter(({ name }) => isAggregateOutputType(name));
|
|
13
|
+
for (const aggregateOutputType of aggregateOutputTypes) {
|
|
14
|
+
const name = aggregateOutputType.name.replace(/(?:OutputType|Output)$/, '');
|
|
15
|
+
inputObjectTypes.push({
|
|
16
|
+
constraints: { maxNumFields: null, minNumFields: null },
|
|
17
|
+
name: `${name}Input`,
|
|
18
|
+
fields: aggregateOutputType.fields.map((field) => ({
|
|
19
|
+
name: field.name,
|
|
20
|
+
isNullable: false,
|
|
21
|
+
isRequired: false,
|
|
22
|
+
inputTypes: [
|
|
23
|
+
{
|
|
24
|
+
isList: false,
|
|
25
|
+
type: 'True',
|
|
26
|
+
location: 'scalar',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
})),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.addMissingInputObjectTypesForAggregate = addMissingInputObjectTypesForAggregate;
|
|
34
|
+
function resolveAggregateOperationSupport(inputObjectTypes) {
|
|
35
|
+
const aggregateOperationSupport = {};
|
|
36
|
+
for (const inputType of inputObjectTypes) {
|
|
37
|
+
if ((0, exports.isAggregateInputType)(inputType.name)) {
|
|
38
|
+
const name = inputType.name.replace('AggregateInput', '');
|
|
39
|
+
if (name.endsWith('Count')) {
|
|
40
|
+
const model = name.replace('Count', '');
|
|
41
|
+
aggregateOperationSupport[model] = Object.assign(Object.assign({}, aggregateOperationSupport[model]), { count: true });
|
|
42
|
+
}
|
|
43
|
+
else if (name.endsWith('Min')) {
|
|
44
|
+
const model = name.replace('Min', '');
|
|
45
|
+
aggregateOperationSupport[model] = Object.assign(Object.assign({}, aggregateOperationSupport[model]), { min: true });
|
|
46
|
+
}
|
|
47
|
+
else if (name.endsWith('Max')) {
|
|
48
|
+
const model = name.replace('Max', '');
|
|
49
|
+
aggregateOperationSupport[model] = Object.assign(Object.assign({}, aggregateOperationSupport[model]), { max: true });
|
|
50
|
+
}
|
|
51
|
+
else if (name.endsWith('Sum')) {
|
|
52
|
+
const model = name.replace('Sum', '');
|
|
53
|
+
aggregateOperationSupport[model] = Object.assign(Object.assign({}, aggregateOperationSupport[model]), { sum: true });
|
|
54
|
+
}
|
|
55
|
+
else if (name.endsWith('Avg')) {
|
|
56
|
+
const model = name.replace('Avg', '');
|
|
57
|
+
aggregateOperationSupport[model] = Object.assign(Object.assign({}, aggregateOperationSupport[model]), { avg: true });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return aggregateOperationSupport;
|
|
62
|
+
}
|
|
63
|
+
exports.resolveAggregateOperationSupport = resolveAggregateOperationSupport;
|
|
64
|
+
//# sourceMappingURL=aggregate-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate-helpers.js","sourceRoot":"","sources":["../../src/dmmf-helpers/aggregate-helpers.ts"],"names":[],"mappings":";;;AAGA,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,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC;IACjG,KAAK,MAAM,mBAAmB,IAAI,oBAAoB,EAAE;QACpD,MAAM,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC,CAAC;QAC5E,gBAAgB,CAAC,IAAI,CAAC;YAClB,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE;YACvD,IAAI,EAAE,GAAG,IAAI,OAAO;YACpB,MAAM,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBAC/C,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,UAAU,EAAE,KAAK;gBACjB,U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,QAAQ,CAAC,KAAK,CAAC,EAAE;gBAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBACtC,yBAAyB,CAAC,KAAK,CAAC,mCACzB,yBAAyB,CAAC,KAAK,CAAC,KACnC,GAAG,EAAE,IAAI,GACZ,CAAC;aACL;iBAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;gBAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBACtC,yBAAyB,CAAC,KAAK,CAAC,mCACzB,yBAAyB,CAAC,KAAK,CAAC,KACnC,GAAG,EAAE,IAAI,GACZ,CAAC;aACL;SACJ;KACJ;IACD,OAAO,yBAAyB,CAAC;AACrC,CAAC;AAvCD,4EAuCC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addMissingInputObjectTypesForInclude = void 0;
|
|
4
|
+
const model_helpers_1 = require("./model-helpers");
|
|
5
|
+
function addMissingInputObjectTypesForInclude(inputObjectTypes, models) {
|
|
6
|
+
// generate input object types necessary to support ModelInclude with relation support
|
|
7
|
+
const generatedIncludeInputObjectTypes = generateModelIncludeInputObjectTypes(models);
|
|
8
|
+
for (const includeInputObjectType of generatedIncludeInputObjectTypes) {
|
|
9
|
+
inputObjectTypes.push(includeInputObjectType);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.addMissingInputObjectTypesForInclude = addMissingInputObjectTypesForInclude;
|
|
13
|
+
function generateModelIncludeInputObjectTypes(models) {
|
|
14
|
+
const modelIncludeInputObjectTypes = [];
|
|
15
|
+
for (const model of models) {
|
|
16
|
+
const { name: modelName, fields: modelFields } = model;
|
|
17
|
+
const fields = [];
|
|
18
|
+
for (const modelField of modelFields) {
|
|
19
|
+
const { name: modelFieldName, isList, type } = modelField;
|
|
20
|
+
const isRelationField = (0, model_helpers_1.checkIsModelRelationField)(modelField);
|
|
21
|
+
if (isRelationField) {
|
|
22
|
+
const field = {
|
|
23
|
+
name: modelFieldName,
|
|
24
|
+
isRequired: false,
|
|
25
|
+
isNullable: false,
|
|
26
|
+
inputTypes: [
|
|
27
|
+
{ isList: false, type: 'Boolean', location: 'scalar' },
|
|
28
|
+
{
|
|
29
|
+
isList: false,
|
|
30
|
+
type: isList ? `${type}FindManyArgs` : `${type}Args`,
|
|
31
|
+
location: 'inputObjectTypes',
|
|
32
|
+
namespace: 'prisma',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
fields.push(field);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* include is not generated for models that do not have a relation with any other models
|
|
41
|
+
* -> continue onto the next model
|
|
42
|
+
*/
|
|
43
|
+
const hasRelationToAnotherModel = (0, model_helpers_1.checkModelHasModelRelation)(model);
|
|
44
|
+
if (!hasRelationToAnotherModel) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const hasManyRelationToAnotherModel = (0, model_helpers_1.checkModelHasManyModelRelation)(model);
|
|
48
|
+
const shouldAddCountField = hasManyRelationToAnotherModel;
|
|
49
|
+
if (shouldAddCountField) {
|
|
50
|
+
const inputTypes = [{ isList: false, type: 'Boolean', location: 'scalar' }];
|
|
51
|
+
inputTypes.push({
|
|
52
|
+
isList: false,
|
|
53
|
+
type: `${modelName}CountOutputTypeArgs`,
|
|
54
|
+
location: 'inputObjectTypes',
|
|
55
|
+
namespace: 'prisma',
|
|
56
|
+
});
|
|
57
|
+
const _countField = {
|
|
58
|
+
name: '_count',
|
|
59
|
+
isRequired: false,
|
|
60
|
+
isNullable: false,
|
|
61
|
+
inputTypes,
|
|
62
|
+
};
|
|
63
|
+
fields.push(_countField);
|
|
64
|
+
}
|
|
65
|
+
const modelIncludeInputObjectType = {
|
|
66
|
+
name: `${modelName}Include`,
|
|
67
|
+
constraints: {
|
|
68
|
+
maxNumFields: null,
|
|
69
|
+
minNumFields: null,
|
|
70
|
+
},
|
|
71
|
+
fields,
|
|
72
|
+
};
|
|
73
|
+
modelIncludeInputObjectTypes.push(modelIncludeInputObjectType);
|
|
74
|
+
}
|
|
75
|
+
return modelIncludeInputObjectTypes;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=include-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"include-helpers.js","sourceRoot":"","sources":["../../src/dmmf-helpers/include-helpers.ts"],"names":[],"mappings":";;;AACA,mDAAwH;AAExH,SAAgB,oCAAoC,CAAC,gBAAkC,EAAE,MAAoB;IACzG,sFAAsF;IACtF,MAAM,gCAAgC,GAAG,oCAAoC,CAAC,MAAM,CAAC,CAAC;IAEtF,KAAK,MAAM,sBAAsB,IAAI,gCAAgC,EAAE;QACnE,gBAAgB,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;KACjD;AACL,CAAC;AAPD,oFAOC;AACD,SAAS,oCAAoC,CAAC,MAAoB;IAC9D,MAAM,4BAA4B,GAAqB,EAAE,CAAC;IAC1D,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QACxB,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;QACvD,MAAM,MAAM,GAAqB,EAAE,CAAC;QAEpC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;YAClC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC;YAE1D,MAAM,eAAe,GAAG,IAAA,yCAAyB,EAAC,UAAU,CAAC,CAAC;YAE9D,IAAI,eAAe,EAAE;gBACjB,MAAM,KAAK,GAAmB;oBAC1B,IAAI,EAAE,cAAc;oBACpB,UAAU,EAAE,KAAK;oBACjB,UAAU,EAAE,KAAK;oBACjB,UAAU,EAAE;wBACR,E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SACT,CAAC;QACF,4BAA4B,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;KAClE;IACD,OAAO,4BAA4B,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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("./aggregate-helpers"), exports);
|
|
18
|
+
__exportStar(require("./include-helpers"), exports);
|
|
19
|
+
__exportStar(require("./model-helpers"), exports);
|
|
20
|
+
__exportStar(require("./modelArgs-helpers"), exports);
|
|
21
|
+
__exportStar(require("./select-helpers"), exports);
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
23
|
+
__exportStar(require("./missing-types-helper"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dmmf-helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,oDAAkC;AAClC,kDAAgC;AAChC,sDAAoC;AACpC,mDAAiC;AACjC,0CAAwB;AACxB,yDAAuC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addMissingInputObjectTypes = void 0;
|
|
4
|
+
const aggregate_helpers_1 = require("./aggregate-helpers");
|
|
5
|
+
const include_helpers_1 = require("./include-helpers");
|
|
6
|
+
const modelArgs_helpers_1 = require("./modelArgs-helpers");
|
|
7
|
+
const select_helpers_1 = require("./select-helpers");
|
|
8
|
+
function addMissingInputObjectTypes(inputObjectTypes, outputObjectTypes, models) {
|
|
9
|
+
(0, aggregate_helpers_1.addMissingInputObjectTypesForAggregate)(inputObjectTypes, outputObjectTypes);
|
|
10
|
+
(0, select_helpers_1.addMissingInputObjectTypesForSelect)(inputObjectTypes, outputObjectTypes, models);
|
|
11
|
+
(0, modelArgs_helpers_1.addMissingInputObjectTypesForModelArgs)(inputObjectTypes, models);
|
|
12
|
+
(0, include_helpers_1.addMissingInputObjectTypesForInclude)(inputObjectTypes, models);
|
|
13
|
+
}
|
|
14
|
+
exports.addMissingInputObjectTypes = addMissingInputObjectTypes;
|
|
15
|
+
//# sourceMappingURL=missing-types-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"missing-types-helper.js","sourceRoot":"","sources":["../../src/dmmf-helpers/missing-types-helper.ts"],"names":[],"mappings":";;;AACA,2DAA6E;AAC7E,uDAAyE;AACzE,2DAA6E;AAC7E,qDAAuE;AAEvE,SAAgB,0BAA0B,CACtC,gBAAkC,EAClC,iBAAoC,EACpC,MAAoB;IAEpB,IAAA,0DAAsC,EAAC,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;IAC5E,IAAA,oDAAmC,EAAC,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,CAAC,CAAC;IACjF,IAAA,0DAAsC,EAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IACjE,IAAA,sDAAoC,EAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;AACnE,CAAC;AATD,gEASC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
export declare function checkModelHasModelRelation(model: DMMF.Model): boolean;
|
|
3
|
+
export declare function checkModelHasManyModelRelation(model: DMMF.Model): boolean;
|
|
4
|
+
export declare function checkIsModelRelationField(modelField: DMMF.Field): boolean;
|
|
5
|
+
export declare function checkIsManyModelRelationField(modelField: DMMF.Field): boolean;
|
|
6
|
+
export declare function findModelByName(models: DMMF.Model[], modelName: string): DMMF.Model | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findModelByName = exports.checkIsManyModelRelationField = exports.checkIsModelRelationField = exports.checkModelHasManyModelRelation = exports.checkModelHasModelRelation = void 0;
|
|
4
|
+
function checkModelHasModelRelation(model) {
|
|
5
|
+
const { fields: modelFields } = model;
|
|
6
|
+
for (const modelField of modelFields) {
|
|
7
|
+
const isRelationField = checkIsModelRelationField(modelField);
|
|
8
|
+
if (isRelationField) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
exports.checkModelHasModelRelation = checkModelHasModelRelation;
|
|
15
|
+
function checkModelHasManyModelRelation(model) {
|
|
16
|
+
const { fields: modelFields } = model;
|
|
17
|
+
for (const modelField of modelFields) {
|
|
18
|
+
const isManyRelationField = checkIsManyModelRelationField(modelField);
|
|
19
|
+
if (isManyRelationField) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
exports.checkModelHasManyModelRelation = checkModelHasManyModelRelation;
|
|
26
|
+
function checkIsModelRelationField(modelField) {
|
|
27
|
+
const { kind, relationName } = modelField;
|
|
28
|
+
return kind === 'object' && !!relationName;
|
|
29
|
+
}
|
|
30
|
+
exports.checkIsModelRelationField = checkIsModelRelationField;
|
|
31
|
+
function checkIsManyModelRelationField(modelField) {
|
|
32
|
+
return checkIsModelRelationField(modelField) && modelField.isList;
|
|
33
|
+
}
|
|
34
|
+
exports.checkIsManyModelRelationField = checkIsManyModelRelationField;
|
|
35
|
+
function findModelByName(models, modelName) {
|
|
36
|
+
return models.find(({ name }) => name === modelName);
|
|
37
|
+
}
|
|
38
|
+
exports.findModelByName = findModelByName;
|
|
39
|
+
//# sourceMappingURL=model-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-helpers.js","sourceRoot":"","sources":["../../src/dmmf-helpers/model-helpers.ts"],"names":[],"mappings":";;;AAEA,SAAgB,0BAA0B,CAAC,KAAiB;IACxD,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IACtC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QAClC,MAAM,eAAe,GAAG,yBAAyB,CAAC,UAAU,CAAC,CAAC;QAC9D,IAAI,eAAe,EAAE;YACjB,OAAO,IAAI,CAAC;SACf;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AATD,gEASC;AAED,SAAgB,8BAA8B,CAAC,KAAiB;IAC5D,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IACtC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QAClC,MAAM,mBAAmB,GAAG,6BAA6B,CAAC,UAAU,CAAC,CAAC;QACtE,IAAI,mBAAmB,EAAE;YACrB,OAAO,IAAI,CAAC;SACf;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AATD,wEASC;AAED,SAAgB,yBAAyB,CAAC,UAAsB;IAC5D,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,UAAU,CAAC;IAC1C,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,YAAY,CAAC;AAC/C,CAAC;AAHD,8DAGC;AAED,SAAgB,6BAA6B,CAAC,UAAsB;IAChE,OAAO,yBAAyB,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC;AACtE,CAAC;AAFD,sEAEC;AAED,SAAgB,eAAe,CAAC,MAAoB,EAAE,SAAiB;IACnE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;AACzD,CAAC;AAFD,0CAEC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addMissingInputObjectTypesForModelArgs = void 0;
|
|
4
|
+
const model_helpers_1 = require("./model-helpers");
|
|
5
|
+
function addMissingInputObjectTypesForModelArgs(inputObjectTypes, models) {
|
|
6
|
+
const modelArgsInputObjectTypes = generateModelArgsInputObjectTypes(models);
|
|
7
|
+
for (const modelArgsInputObjectType of modelArgsInputObjectTypes) {
|
|
8
|
+
inputObjectTypes.push(modelArgsInputObjectType);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.addMissingInputObjectTypesForModelArgs = addMissingInputObjectTypesForModelArgs;
|
|
12
|
+
function generateModelArgsInputObjectTypes(models) {
|
|
13
|
+
const modelArgsInputObjectTypes = [];
|
|
14
|
+
for (const model of models) {
|
|
15
|
+
const { name: modelName } = model;
|
|
16
|
+
const fields = [];
|
|
17
|
+
const selectField = {
|
|
18
|
+
name: 'select',
|
|
19
|
+
isRequired: false,
|
|
20
|
+
isNullable: false,
|
|
21
|
+
inputTypes: [
|
|
22
|
+
{
|
|
23
|
+
isList: false,
|
|
24
|
+
type: `${modelName}Select`,
|
|
25
|
+
location: 'inputObjectTypes',
|
|
26
|
+
namespace: 'prisma',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
fields.push(selectField);
|
|
31
|
+
const hasRelationToAnotherModel = (0, model_helpers_1.checkModelHasModelRelation)(model);
|
|
32
|
+
if (hasRelationToAnotherModel) {
|
|
33
|
+
const includeField = {
|
|
34
|
+
name: 'include',
|
|
35
|
+
isRequired: false,
|
|
36
|
+
isNullable: false,
|
|
37
|
+
inputTypes: [
|
|
38
|
+
{
|
|
39
|
+
isList: false,
|
|
40
|
+
type: `${modelName}Include`,
|
|
41
|
+
location: 'inputObjectTypes',
|
|
42
|
+
namespace: 'prisma',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
fields.push(includeField);
|
|
47
|
+
}
|
|
48
|
+
const modelArgsInputObjectType = {
|
|
49
|
+
name: `${modelName}Args`,
|
|
50
|
+
constraints: {
|
|
51
|
+
maxNumFields: null,
|
|
52
|
+
minNumFields: null,
|
|
53
|
+
},
|
|
54
|
+
fields,
|
|
55
|
+
};
|
|
56
|
+
modelArgsInputObjectTypes.push(modelArgsInputObjectType);
|
|
57
|
+
}
|
|
58
|
+
return modelArgsInputObjectTypes;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=modelArgs-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modelArgs-helpers.js","sourceRoot":"","sources":["../../src/dmmf-helpers/modelArgs-helpers.ts"],"names":[],"mappings":";;;AACA,mDAA6D;AAE7D,SAAgB,sCAAsC,CAAC,gBAAkC,EAAE,MAAoB;IAC3G,MAAM,yBAAyB,GAAG,iCAAiC,CAAC,MAAM,CAAC,CAAC;IAE5E,KAAK,MAAM,wBAAwB,IAAI,yBAAyB,EAAE;QAC9D,gBAAgB,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;KACnD;AACL,CAAC;AAND,wFAMC;AACD,SAAS,iCAAiC,CAAC,MAAoB;IAC3D,MAAM,yBAAyB,GAAqB,EAAE,CAAC;IACvD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QACxB,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;QAClC,MAAM,MAAM,GAAqB,EAAE,CAAC;QAEpC,MAAM,WAAW,GAAmB;YAChC,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,KAAK;YACjB,UAAU,EAAE,KAAK;YACjB,UAAU,EAAE;gBACR;oBACI,MAAM,EAAE,KAAK;oBACb,IAAI,EAAE,GAAG,SAAS,QAAQ;oBAC1B,QAAQ,EAAE,kBAAkB;oBAC5B,SAAS,EAAE,QAAQ;iBACtB;aACJ;SACJ,CAAC;QACF,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAEzB,MAAM,yBAAyB,GAAG,IAAA,0CAA0B,EAAC,KAAK,CAAC,CAAC;QAEpE,IAAI,yBAAyB,EAAE;YAC3B,MAAM,YAAY,GAAmB;gBACjC,IAAI,EAAE,SAAS;gBACf,UAAU,EAAE,KAAK;gBACjB,UAAU,EAAE,KAAK;gBACjB,UAAU,EAAE;oBACR;wBACI,MAAM,EAAE,KAAK;wBACb,IAAI,EAAE,GAAG,SAAS,SAAS;wBAC3B,QAAQ,EAAE,kBAAkB;wBAC5B,SAAS,EAAE,QAAQ;qBACtB;iBACJ;aACJ,CAAC;YACF,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SAC7B;QAED,MAAM,wBAAwB,GAAmB;YAC7C,IAAI,EAAE,GAAG,SAAS,MAAM;YACxB,WAAW,EAAE;gBACT,YAAY,EAAE,IAAI;gBAClB,YAAY,EAAE,IAAI;aACrB;YACD,MAAM;SACT,CAAC;QACF,yBAAyB,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;KAC5D;IACD,OAAO,yBAAyB,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addMissingInputObjectTypesForSelect = void 0;
|
|
4
|
+
const model_helpers_1 = require("./model-helpers");
|
|
5
|
+
function addMissingInputObjectTypesForSelect(inputObjectTypes, outputObjectTypes, models) {
|
|
6
|
+
// generate input object types necessary to support ModelSelect._count
|
|
7
|
+
const modelCountOutputTypes = getModelCountOutputTypes(outputObjectTypes);
|
|
8
|
+
const modelCountOutputTypeSelectInputObjectTypes = generateModelCountOutputTypeSelectInputObjectTypes(modelCountOutputTypes);
|
|
9
|
+
const modelCountOutputTypeArgsInputObjectTypes = generateModelCountOutputTypeArgsInputObjectTypes(modelCountOutputTypes);
|
|
10
|
+
const modelSelectInputObjectTypes = generateModelSelectInputObjectTypes(models);
|
|
11
|
+
const generatedInputObjectTypes = [
|
|
12
|
+
modelCountOutputTypeSelectInputObjectTypes,
|
|
13
|
+
modelCountOutputTypeArgsInputObjectTypes,
|
|
14
|
+
modelSelectInputObjectTypes,
|
|
15
|
+
].flat();
|
|
16
|
+
for (const inputObjectType of generatedInputObjectTypes) {
|
|
17
|
+
inputObjectTypes.push(inputObjectType);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.addMissingInputObjectTypesForSelect = addMissingInputObjectTypesForSelect;
|
|
21
|
+
function getModelCountOutputTypes(outputObjectTypes) {
|
|
22
|
+
return outputObjectTypes.filter(({ name }) => name.includes('CountOutputType'));
|
|
23
|
+
}
|
|
24
|
+
function generateModelCountOutputTypeSelectInputObjectTypes(modelCountOutputTypes) {
|
|
25
|
+
const modelCountOutputTypeSelectInputObjectTypes = [];
|
|
26
|
+
for (const modelCountOutputType of modelCountOutputTypes) {
|
|
27
|
+
const { name: modelCountOutputTypeName, fields: modelCountOutputTypeFields } = modelCountOutputType;
|
|
28
|
+
const modelCountOutputTypeSelectInputObjectType = {
|
|
29
|
+
name: `${modelCountOutputTypeName}Select`,
|
|
30
|
+
constraints: {
|
|
31
|
+
maxNumFields: null,
|
|
32
|
+
minNumFields: null,
|
|
33
|
+
},
|
|
34
|
+
fields: modelCountOutputTypeFields.map(({ name }) => ({
|
|
35
|
+
name,
|
|
36
|
+
isRequired: false,
|
|
37
|
+
isNullable: false,
|
|
38
|
+
inputTypes: [
|
|
39
|
+
{
|
|
40
|
+
isList: false,
|
|
41
|
+
type: `Boolean`,
|
|
42
|
+
location: 'scalar',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
})),
|
|
46
|
+
};
|
|
47
|
+
modelCountOutputTypeSelectInputObjectTypes.push(modelCountOutputTypeSelectInputObjectType);
|
|
48
|
+
}
|
|
49
|
+
return modelCountOutputTypeSelectInputObjectTypes;
|
|
50
|
+
}
|
|
51
|
+
function generateModelCountOutputTypeArgsInputObjectTypes(modelCountOutputTypes) {
|
|
52
|
+
const modelCountOutputTypeArgsInputObjectTypes = [];
|
|
53
|
+
for (const modelCountOutputType of modelCountOutputTypes) {
|
|
54
|
+
const { name: modelCountOutputTypeName } = modelCountOutputType;
|
|
55
|
+
const modelCountOutputTypeArgsInputObjectType = {
|
|
56
|
+
name: `${modelCountOutputTypeName}Args`,
|
|
57
|
+
constraints: {
|
|
58
|
+
maxNumFields: null,
|
|
59
|
+
minNumFields: null,
|
|
60
|
+
},
|
|
61
|
+
fields: [
|
|
62
|
+
{
|
|
63
|
+
name: 'select',
|
|
64
|
+
isRequired: false,
|
|
65
|
+
isNullable: false,
|
|
66
|
+
inputTypes: [
|
|
67
|
+
{
|
|
68
|
+
isList: false,
|
|
69
|
+
type: `${modelCountOutputTypeName}Select`,
|
|
70
|
+
location: 'inputObjectTypes',
|
|
71
|
+
namespace: 'prisma',
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
modelCountOutputTypeArgsInputObjectTypes.push(modelCountOutputTypeArgsInputObjectType);
|
|
78
|
+
}
|
|
79
|
+
return modelCountOutputTypeArgsInputObjectTypes;
|
|
80
|
+
}
|
|
81
|
+
function generateModelSelectInputObjectTypes(models) {
|
|
82
|
+
const modelSelectInputObjectTypes = [];
|
|
83
|
+
for (const model of models) {
|
|
84
|
+
const { name: modelName, fields: modelFields } = model;
|
|
85
|
+
const fields = [];
|
|
86
|
+
for (const modelField of modelFields) {
|
|
87
|
+
const { name: modelFieldName, isList, type } = modelField;
|
|
88
|
+
const isRelationField = (0, model_helpers_1.checkIsModelRelationField)(modelField);
|
|
89
|
+
const field = {
|
|
90
|
+
name: modelFieldName,
|
|
91
|
+
isRequired: false,
|
|
92
|
+
isNullable: false,
|
|
93
|
+
inputTypes: [{ isList: false, type: 'Boolean', location: 'scalar' }],
|
|
94
|
+
};
|
|
95
|
+
if (isRelationField) {
|
|
96
|
+
const schemaArgInputType = {
|
|
97
|
+
isList: false,
|
|
98
|
+
type: isList ? `${type}FindManyArgs` : `${type}Args`,
|
|
99
|
+
location: 'inputObjectTypes',
|
|
100
|
+
namespace: 'prisma',
|
|
101
|
+
};
|
|
102
|
+
field.inputTypes.push(schemaArgInputType);
|
|
103
|
+
}
|
|
104
|
+
fields.push(field);
|
|
105
|
+
}
|
|
106
|
+
const hasManyRelationToAnotherModel = (0, model_helpers_1.checkModelHasManyModelRelation)(model);
|
|
107
|
+
const shouldAddCountField = hasManyRelationToAnotherModel;
|
|
108
|
+
if (shouldAddCountField) {
|
|
109
|
+
const _countField = {
|
|
110
|
+
name: '_count',
|
|
111
|
+
isRequired: false,
|
|
112
|
+
isNullable: false,
|
|
113
|
+
inputTypes: [
|
|
114
|
+
{ isList: false, type: 'Boolean', location: 'scalar' },
|
|
115
|
+
{
|
|
116
|
+
isList: false,
|
|
117
|
+
type: `${modelName}CountOutputTypeArgs`,
|
|
118
|
+
location: 'inputObjectTypes',
|
|
119
|
+
namespace: 'prisma',
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
};
|
|
123
|
+
fields.push(_countField);
|
|
124
|
+
}
|
|
125
|
+
const modelSelectInputObjectType = {
|
|
126
|
+
name: `${modelName}Select`,
|
|
127
|
+
constraints: {
|
|
128
|
+
maxNumFields: null,
|
|
129
|
+
minNumFields: null,
|
|
130
|
+
},
|
|
131
|
+
fields,
|
|
132
|
+
};
|
|
133
|
+
modelSelectInputObjectTypes.push(modelSelectInputObjectType);
|
|
134
|
+
}
|
|
135
|
+
return modelSelectInputObjectTypes;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=select-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-helpers.js","sourceRoot":"","sources":["../../src/dmmf-helpers/select-helpers.ts"],"names":[],"mappings":";;;AACA,mDAA4F;AAE5F,SAAgB,mCAAmC,CAC/C,gBAAkC,EAClC,iBAAoC,EACpC,MAAoB;IAEpB,sEAAsE;IACtE,MAAM,qBAAqB,GAAG,wBAAwB,CAAC,iBAAiB,CAAC,CAAC;IAC1E,MAAM,0CAA0C,GAC5C,kDAAkD,CAAC,qBAAqB,CAAC,CAAC;IAC9E,MAAM,wCAAwC,GAC1C,gDAAgD,CAAC,qBAAqB,CAAC,CAAC;IAE5E,MAAM,2BAA2B,GAAG,mCAAmC,CAAC,MAAM,CAAC,CAAC;IAEhF,MAAM,yBAAyB,GAAG;QAC9B,0CAA0C;QAC1C,wCAAwC;QACxC,2BAA2B;KAC9B,CAAC,IAAI,EAAE,CAAC;IAET,KAAK,MAAM,eAAe,IAAI,yBAAyB,EAAE;QACrD,gBAAgB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;KAC1C;AACL,CAAC;AAvBD,kFAuBC;AAED,SAAS,wBAAwB,CAAC,iBAAoC;IAClE,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC;AACpF,CAAC;AAED,SAAS,kDAAkD,CAAC,qBAAwC;IAChG,MAAM,0CAA0C,GAAqB,EAAE,CAAC;IACxE,KAAK,MAAM,oBAAoB,IAAI,qBAAqB,EAAE;QACtD,MAAM,EAAE,IAAI,EAAE,wBAAwB,EAAE,MAAM,EAAE,0BAA0B,EAAE,GAAG,oBAAoB,CAAC;QACpG,MAAM,yCAAyC,GAAmB;YAC9D,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K;gBACjB,UAAU,EAAE;oBACR,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE;oBACtD;wBACI,MAAM,EAAE,KAAK;wBACb,IAAI,EAAE,GAAG,SAAS,qBAAqB;wBACvC,QAAQ,EAAE,kBAAkB;wBAC5B,SAAS,EAAE,QAAQ;qBACtB;iBACJ;aACJ,CAAC;YACF,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;SAC5B;QAED,MAAM,0BAA0B,GAAmB;YAC/C,IAAI,EAAE,GAAG,SAAS,QAAQ;YAC1B,WAAW,EAAE;gBACT,YAAY,EAAE,IAAI;gBAClB,YAAY,EAAE,IAAI;aACrB;YACD,MAAM;SACT,CAAC;QACF,2BAA2B,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;KAChE;IACD,OAAO,2BAA2B,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DMMF as PrismaDMMF } from '@prisma/generator-helper';
|
|
2
|
+
export type TransformerParams = {
|
|
3
|
+
enumTypes?: PrismaDMMF.SchemaEnum[];
|
|
4
|
+
fields?: PrismaDMMF.SchemaArg[];
|
|
5
|
+
name?: string;
|
|
6
|
+
models?: PrismaDMMF.Model[];
|
|
7
|
+
modelOperations?: PrismaDMMF.ModelMapping[];
|
|
8
|
+
aggregateOperationSupport?: AggregateOperationSupport;
|
|
9
|
+
isDefaultPrismaClientOutput?: boolean;
|
|
10
|
+
prismaClientOutputPath?: string;
|
|
11
|
+
};
|
|
12
|
+
export type AggregateOperationSupport = {
|
|
13
|
+
[model: string]: {
|
|
14
|
+
count?: boolean;
|
|
15
|
+
min?: boolean;
|
|
16
|
+
max?: boolean;
|
|
17
|
+
sum?: boolean;
|
|
18
|
+
avg?: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/dmmf-helpers/types.ts"],"names":[],"mappings":""}
|
package/index.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
} & Record<string, OptionValue | OptionValue[]>;
|
|
7
|
-
export type PluginFunction = (model: Model, options: PluginOptions, dmmf?: DMMF.Document) => Promise<string[]> | string[] | Promise<void> | void;
|
|
8
|
-
export declare class PluginError extends Error {
|
|
9
|
-
constructor(message: string);
|
|
10
|
-
}
|
|
11
|
-
export declare const GUARD_FIELD_NAME = "zenstack_guard";
|
|
12
|
-
export declare const TRANSACTION_FIELD_NAME = "zenstack_transaction";
|
|
1
|
+
export * from './code-gen';
|
|
2
|
+
export * from './constants';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export * from './utils';
|
|
5
|
+
export * from './policy';
|
package/index.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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("./code-gen"), exports);
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./utils"), exports);
|
|
21
|
+
__exportStar(require("./policy"), exports);
|
|
12
22
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,8CAA4B;AAC5B,0CAAwB;AACxB,0CAAwB;AACxB,2CAAyB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenstackhq/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.101",
|
|
4
4
|
"description": "ZenStack plugin development SDK",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -12,14 +12,19 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@prisma/generator-helper": "^4.7.1",
|
|
15
|
-
"
|
|
15
|
+
"prettier": "^2.8.3",
|
|
16
|
+
"ts-morph": "^16.0.0",
|
|
17
|
+
"@zenstackhq/language": "1.0.0-alpha.101"
|
|
16
18
|
},
|
|
17
19
|
"devDependencies": {
|
|
20
|
+
"copyfiles": "^2.4.1",
|
|
21
|
+
"rimraf": "^3.0.2",
|
|
18
22
|
"typescript": "^4.9.4"
|
|
19
23
|
},
|
|
20
24
|
"scripts": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
25
|
+
"clean": "rimraf dist",
|
|
26
|
+
"lint": "eslint src --ext ts",
|
|
27
|
+
"build": "pnpm lint && pnpm clean && tsc && copyfiles ./package.json ./LICENSE ./README.md dist",
|
|
23
28
|
"watch": "tsc --watch",
|
|
24
29
|
"publish-dev": "pnpm build && pnpm publish --tag dev"
|
|
25
30
|
}
|
package/policy.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DataModel, DataModelAttribute } from './ast';
|
|
2
|
+
export declare const VALIDATION_ATTRIBUTES: string[];
|
|
3
|
+
export declare function analyzePolicies(dataModel: DataModel): {
|
|
4
|
+
allows: DataModelAttribute[];
|
|
5
|
+
denies: DataModelAttribute[];
|
|
6
|
+
create: boolean | undefined;
|
|
7
|
+
read: boolean | undefined;
|
|
8
|
+
update: boolean | undefined;
|
|
9
|
+
delete: boolean | undefined;
|
|
10
|
+
allowAll: boolean;
|
|
11
|
+
denyAll: boolean;
|
|
12
|
+
hasFieldValidation: boolean;
|
|
13
|
+
};
|
package/policy.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyzePolicies = exports.VALIDATION_ATTRIBUTES = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
exports.VALIDATION_ATTRIBUTES = [
|
|
6
|
+
'@length',
|
|
7
|
+
'@regex',
|
|
8
|
+
'@startsWith',
|
|
9
|
+
'@endsWith',
|
|
10
|
+
'@email',
|
|
11
|
+
'@url',
|
|
12
|
+
'@datetime',
|
|
13
|
+
'@gt',
|
|
14
|
+
'@gte',
|
|
15
|
+
'@lt',
|
|
16
|
+
'@lte',
|
|
17
|
+
];
|
|
18
|
+
function analyzePolicies(dataModel) {
|
|
19
|
+
const allows = dataModel.attributes.filter((attr) => { var _a; return ((_a = attr.decl.ref) === null || _a === void 0 ? void 0 : _a.name) === '@@allow'; });
|
|
20
|
+
const denies = dataModel.attributes.filter((attr) => { var _a; return ((_a = attr.decl.ref) === null || _a === void 0 ? void 0 : _a.name) === '@@deny'; });
|
|
21
|
+
const create = toStaticPolicy('create', allows, denies);
|
|
22
|
+
const read = toStaticPolicy('read', allows, denies);
|
|
23
|
+
const update = toStaticPolicy('update', allows, denies);
|
|
24
|
+
const del = toStaticPolicy('delete', allows, denies);
|
|
25
|
+
const hasFieldValidation = dataModel.fields.some((field) => field.attributes.some((attr) => exports.VALIDATION_ATTRIBUTES.includes(attr.decl.$refText)));
|
|
26
|
+
return {
|
|
27
|
+
allows,
|
|
28
|
+
denies,
|
|
29
|
+
create,
|
|
30
|
+
read,
|
|
31
|
+
update,
|
|
32
|
+
delete: del,
|
|
33
|
+
allowAll: create === true && read === true && update === true && del === true,
|
|
34
|
+
denyAll: create === false && read === false && update === false && del === false,
|
|
35
|
+
hasFieldValidation,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.analyzePolicies = analyzePolicies;
|
|
39
|
+
function toStaticPolicy(operation, allows, denies) {
|
|
40
|
+
const filteredDenies = forOperation(operation, denies);
|
|
41
|
+
if (filteredDenies.some((rule) => (0, utils_1.getLiteral)(rule.args[1].value) === true)) {
|
|
42
|
+
// any constant true deny rule
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const filteredAllows = forOperation(operation, allows);
|
|
46
|
+
if (filteredAllows.length === 0) {
|
|
47
|
+
// no allow rule
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (filteredDenies.length === 0 &&
|
|
51
|
+
filteredAllows.some((rule) => (0, utils_1.getLiteral)(rule.args[1].value) === true)) {
|
|
52
|
+
// any constant true allow rule
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
function forOperation(operation, rules) {
|
|
58
|
+
return rules.filter((rule) => {
|
|
59
|
+
const ops = (0, utils_1.getLiteral)(rule.args[0].value);
|
|
60
|
+
if (!ops) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (ops === 'all') {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
const splitOps = ops.split(',').map((p) => p.trim());
|
|
67
|
+
return splitOps.includes(operation);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=policy.js.map
|
package/policy.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":";;;AACA,mCAAqC;AAExB,QAAA,qBAAqB,GAAG;IACjC,SAAS;IACT,QAAQ;IACR,aAAa;IACb,WAAW;IACX,QAAQ;IACR,MAAM;IACN,WAAW;IACX,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;CACT,CAAC;AAEF,SAAgB,eAAe,CAAC,SAAoB;IAChD,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,WAAC,OAAA,CAAA,MAAA,IAAI,CAAC,IAAI,CAAC,GAAG,0CAAE,IAAI,MAAK,SAAS,CAAA,EAAA,CAAC,CAAC;IACxF,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,WAAC,OAAA,CAAA,MAAA,IAAI,CAAC,IAAI,CAAC,GAAG,0CAAE,IAAI,MAAK,QAAQ,CAAA,EAAA,CAAC,CAAC;IAEvF,MAAM,MAAM,GAAG,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACxD,MAAM,GAAG,GAAG,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACrD,MAAM,kBAAkB,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CA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E,+BAA+B;QAC/B,OAAO,IAAI,CAAC;KACf;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,SAAS,YAAY,CAAC,SAAiB,EAAE,KAA2B;IAChE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACzB,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAS,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACnD,IAAI,CAAC,GAAG,EAAE;YACN,OAAO,KAAK,CAAC;SAChB;QACD,IAAI,GAAG,KAAK,KAAK,EAAE;YACf,OAAO,IAAI,CAAC;SACf;QACD,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QACrD,OAAO,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
import { Model } from '@zenstackhq/language/ast';
|
|
3
|
+
/**
|
|
4
|
+
* Plugin configuration option value type
|
|
5
|
+
*/
|
|
6
|
+
export type OptionValue = string | number | boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Plugin configuration oiptions
|
|
9
|
+
*/
|
|
10
|
+
export type PluginOptions = {
|
|
11
|
+
provider?: string;
|
|
12
|
+
schemaPath: string;
|
|
13
|
+
} & Record<string, OptionValue | OptionValue[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Plugin entry point function definition
|
|
16
|
+
*/
|
|
17
|
+
export type PluginFunction = (model: Model, options: PluginOptions, dmmf?: DMMF.Document, config?: Record<string, string>) => Promise<string[]> | string[] | Promise<void> | void;
|
|
18
|
+
/**
|
|
19
|
+
* Plugin error
|
|
20
|
+
*/
|
|
21
|
+
export declare class PluginError extends Error {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
package/types.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.PluginError = PluginError;
|
|
13
|
+
//# sourceMappingURL=types.js.map
|
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAuBA;;GAEG;AACH,MAAa,WAAY,SAAQ,KAAK;IAClC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;CACJ;AAJD,kCAIC"}
|
package/utils.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import { AstNode, Expression, Reference } from '@zenstackhq/language/ast';
|
|
1
|
+
import { AstNode, DataModel, DataModelAttribute, DataModelField, DataModelFieldAttribute, Enum, EnumField, Expression, Model, Reference } from '@zenstackhq/language/ast';
|
|
2
|
+
/**
|
|
3
|
+
* Gets data models that are not ignored
|
|
4
|
+
*/
|
|
5
|
+
export declare function getDataModels(model: Model): DataModel[];
|
|
2
6
|
export declare function resolved<T extends AstNode>(ref: Reference<T>): T;
|
|
3
7
|
export declare function getLiteral<T extends string | number | boolean | any = any>(expr: Expression | undefined): T | undefined;
|
|
4
8
|
export declare function getArray(expr: Expression | undefined): Expression[] | undefined;
|
|
5
9
|
export declare function getLiteralArray<T extends string | number | boolean | any = any>(expr: Expression | undefined): (T | undefined)[] | undefined;
|
|
10
|
+
export declare function getObjectLiteral<T>(expr: Expression | undefined): T | undefined;
|
|
11
|
+
export default function indentString(string: string, count?: number): string;
|
|
12
|
+
export declare function hasAttribute(decl: DataModel | DataModelField | Enum | EnumField, name: string): boolean;
|
|
13
|
+
export declare function getAttributeArgs(attr: DataModelAttribute | DataModelFieldAttribute): Record<string, Expression>;
|
|
14
|
+
export declare function getAttributeArg(attr: DataModelAttribute | DataModelFieldAttribute, name: string): Expression | undefined;
|
|
15
|
+
export declare function getAttributeArgLiteral<T extends string | number | boolean>(attr: DataModelAttribute | DataModelFieldAttribute, name: string): T | undefined;
|
package/utils.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLiteralArray = exports.getArray = exports.getLiteral = exports.resolved = void 0;
|
|
3
|
+
exports.getAttributeArgLiteral = exports.getAttributeArg = exports.getAttributeArgs = exports.hasAttribute = exports.getObjectLiteral = exports.getLiteralArray = exports.getArray = exports.getLiteral = exports.resolved = exports.getDataModels = void 0;
|
|
4
4
|
const ast_1 = require("@zenstackhq/language/ast");
|
|
5
|
+
/**
|
|
6
|
+
* Gets data models that are not ignored
|
|
7
|
+
*/
|
|
8
|
+
function getDataModels(model) {
|
|
9
|
+
return model.declarations.filter((d) => (0, ast_1.isDataModel)(d) && !hasAttribute(d, '@@ignore'));
|
|
10
|
+
}
|
|
11
|
+
exports.getDataModels = getDataModels;
|
|
5
12
|
function resolved(ref) {
|
|
6
13
|
if (!ref.ref) {
|
|
7
14
|
throw new Error(`Reference not resolved: ${ref.$refText}`);
|
|
@@ -9,6 +16,7 @@ function resolved(ref) {
|
|
|
9
16
|
return ref.ref;
|
|
10
17
|
}
|
|
11
18
|
exports.resolved = resolved;
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
20
|
function getLiteral(expr) {
|
|
13
21
|
if (!(0, ast_1.isLiteralExpr)(expr)) {
|
|
14
22
|
return undefined;
|
|
@@ -25,7 +33,73 @@ function getLiteralArray(expr) {
|
|
|
25
33
|
if (!arr) {
|
|
26
34
|
return undefined;
|
|
27
35
|
}
|
|
28
|
-
return arr.map((item) => getLiteral(item));
|
|
36
|
+
return arr.map((item) => { var _a; return (_a = getLiteral(item)) !== null && _a !== void 0 ? _a : getObjectLiteral(item); });
|
|
29
37
|
}
|
|
30
38
|
exports.getLiteralArray = getLiteralArray;
|
|
39
|
+
function getObjectLiteral(expr) {
|
|
40
|
+
if (!expr || !(0, ast_1.isObjectExpr)(expr)) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const result = {};
|
|
44
|
+
for (const field of expr.fields) {
|
|
45
|
+
let fieldValue;
|
|
46
|
+
if ((0, ast_1.isLiteralExpr)(field.value)) {
|
|
47
|
+
fieldValue = getLiteral(field.value);
|
|
48
|
+
}
|
|
49
|
+
else if ((0, ast_1.isArrayExpr)(field.value)) {
|
|
50
|
+
fieldValue = getLiteralArray(field.value);
|
|
51
|
+
}
|
|
52
|
+
else if ((0, ast_1.isObjectExpr)(field.value)) {
|
|
53
|
+
fieldValue = getObjectLiteral(field.value);
|
|
54
|
+
}
|
|
55
|
+
if (fieldValue === undefined) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
result[field.name] = fieldValue;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
exports.getObjectLiteral = getObjectLiteral;
|
|
65
|
+
function indentString(string, count = 4) {
|
|
66
|
+
const indent = ' ';
|
|
67
|
+
return string.replace(/^(?!\s*$)/gm, indent.repeat(count));
|
|
68
|
+
}
|
|
69
|
+
exports.default = indentString;
|
|
70
|
+
function hasAttribute(decl, name) {
|
|
71
|
+
return !!decl.attributes.find((attr) => resolved(attr.decl).name === name);
|
|
72
|
+
}
|
|
73
|
+
exports.hasAttribute = hasAttribute;
|
|
74
|
+
function getAttributeArgs(attr) {
|
|
75
|
+
const result = {};
|
|
76
|
+
for (const arg of attr.args) {
|
|
77
|
+
if (!arg.$resolvedParam) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
result[arg.$resolvedParam.name] = arg.value;
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
exports.getAttributeArgs = getAttributeArgs;
|
|
85
|
+
function getAttributeArg(attr, name) {
|
|
86
|
+
var _a;
|
|
87
|
+
for (const arg of attr.args) {
|
|
88
|
+
if (((_a = arg.$resolvedParam) === null || _a === void 0 ? void 0 : _a.name) === name) {
|
|
89
|
+
return arg.value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
exports.getAttributeArg = getAttributeArg;
|
|
95
|
+
function getAttributeArgLiteral(attr, name) {
|
|
96
|
+
var _a;
|
|
97
|
+
for (const arg of attr.args) {
|
|
98
|
+
if (((_a = arg.$resolvedParam) === null || _a === void 0 ? void 0 : _a.name) === name) {
|
|
99
|
+
return getLiteral(arg.value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
exports.getAttributeArgLiteral = getAttributeArgLiteral;
|
|
31
105
|
//# sourceMappingURL=utils.js.map
|
package/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,kDAekC;AAElC;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAY;IACtC,OAAO,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAkB,EAAE,CAAC,IAAA,iBAAW,EAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;AAC5G,CAAC;AAFD,sCAEC;AAED,SAAgB,QAA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