@zenstackhq/sdk 3.0.0-alpha.25 → 3.0.0-alpha.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -5
- package/dist/index.d.ts +37 -5
- package/dist/index.js +1 -7
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -33,12 +33,44 @@ declare namespace modelUtils {
|
|
|
33
33
|
export { modelUtils_DELEGATE_AUX_RELATION_PREFIX as DELEGATE_AUX_RELATION_PREFIX, modelUtils_getAttribute as getAttribute, modelUtils_getAuthDecl as getAuthDecl, modelUtils_getContainingModel as getContainingModel, modelUtils_getIdFields as getIdFields, modelUtils_hasAttribute as hasAttribute, modelUtils_isDelegateModel as isDelegateModel, modelUtils_isFromStdlib as isFromStdlib, modelUtils_isIdField as isIdField, modelUtils_isUniqueField as isUniqueField, modelUtils_resolved as resolved };
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Context passed to CLI plugins when calling `generate`.
|
|
38
|
+
*/
|
|
36
39
|
type CliGeneratorContext = {
|
|
40
|
+
/**
|
|
41
|
+
* ZModel file path.
|
|
42
|
+
*/
|
|
43
|
+
schemaFile: string;
|
|
44
|
+
/**
|
|
45
|
+
* ZModel AST.
|
|
46
|
+
*/
|
|
37
47
|
model: Model;
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Default output path for code generation.
|
|
50
|
+
*/
|
|
51
|
+
defaultOutputPath: string;
|
|
52
|
+
/**
|
|
53
|
+
* Plugin options provided by the user.
|
|
54
|
+
*/
|
|
55
|
+
pluginOptions: Record<string, unknown>;
|
|
40
56
|
};
|
|
41
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Contract for a CLI plugin.
|
|
59
|
+
*/
|
|
60
|
+
interface CliPlugin {
|
|
61
|
+
/**
|
|
62
|
+
* Plugin's display name.
|
|
63
|
+
*/
|
|
64
|
+
name: string;
|
|
65
|
+
/**
|
|
66
|
+
* Text to show during generation.
|
|
67
|
+
*/
|
|
68
|
+
statusText?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Code generation callback.
|
|
71
|
+
*/
|
|
72
|
+
generate(context: CliGeneratorContext): MaybePromise<void>;
|
|
73
|
+
}
|
|
42
74
|
|
|
43
75
|
declare class FunctionCall {
|
|
44
76
|
func: string;
|
|
@@ -90,7 +122,7 @@ declare class PrismaSchemaGenerator {
|
|
|
90
122
|
}
|
|
91
123
|
|
|
92
124
|
declare class TsSchemaGenerator {
|
|
93
|
-
generate(
|
|
125
|
+
generate(model: Model, outputDir: string): Promise<void>;
|
|
94
126
|
private generateSchema;
|
|
95
127
|
private generateSchemaStatements;
|
|
96
128
|
private createSchemaObject;
|
|
@@ -206,4 +238,4 @@ declare class ZModelCodeGenerator {
|
|
|
206
238
|
private isCollectionPredicateOperator;
|
|
207
239
|
}
|
|
208
240
|
|
|
209
|
-
export { type
|
|
241
|
+
export { type CliGeneratorContext, type CliPlugin, modelUtils as ModelUtils, PrismaSchemaGenerator, TsSchemaGenerator, ZModelCodeGenerator, type ZModelCodeOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -33,12 +33,44 @@ declare namespace modelUtils {
|
|
|
33
33
|
export { modelUtils_DELEGATE_AUX_RELATION_PREFIX as DELEGATE_AUX_RELATION_PREFIX, modelUtils_getAttribute as getAttribute, modelUtils_getAuthDecl as getAuthDecl, modelUtils_getContainingModel as getContainingModel, modelUtils_getIdFields as getIdFields, modelUtils_hasAttribute as hasAttribute, modelUtils_isDelegateModel as isDelegateModel, modelUtils_isFromStdlib as isFromStdlib, modelUtils_isIdField as isIdField, modelUtils_isUniqueField as isUniqueField, modelUtils_resolved as resolved };
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Context passed to CLI plugins when calling `generate`.
|
|
38
|
+
*/
|
|
36
39
|
type CliGeneratorContext = {
|
|
40
|
+
/**
|
|
41
|
+
* ZModel file path.
|
|
42
|
+
*/
|
|
43
|
+
schemaFile: string;
|
|
44
|
+
/**
|
|
45
|
+
* ZModel AST.
|
|
46
|
+
*/
|
|
37
47
|
model: Model;
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Default output path for code generation.
|
|
50
|
+
*/
|
|
51
|
+
defaultOutputPath: string;
|
|
52
|
+
/**
|
|
53
|
+
* Plugin options provided by the user.
|
|
54
|
+
*/
|
|
55
|
+
pluginOptions: Record<string, unknown>;
|
|
40
56
|
};
|
|
41
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Contract for a CLI plugin.
|
|
59
|
+
*/
|
|
60
|
+
interface CliPlugin {
|
|
61
|
+
/**
|
|
62
|
+
* Plugin's display name.
|
|
63
|
+
*/
|
|
64
|
+
name: string;
|
|
65
|
+
/**
|
|
66
|
+
* Text to show during generation.
|
|
67
|
+
*/
|
|
68
|
+
statusText?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Code generation callback.
|
|
71
|
+
*/
|
|
72
|
+
generate(context: CliGeneratorContext): MaybePromise<void>;
|
|
73
|
+
}
|
|
42
74
|
|
|
43
75
|
declare class FunctionCall {
|
|
44
76
|
func: string;
|
|
@@ -90,7 +122,7 @@ declare class PrismaSchemaGenerator {
|
|
|
90
122
|
}
|
|
91
123
|
|
|
92
124
|
declare class TsSchemaGenerator {
|
|
93
|
-
generate(
|
|
125
|
+
generate(model: Model, outputDir: string): Promise<void>;
|
|
94
126
|
private generateSchema;
|
|
95
127
|
private generateSchemaStatements;
|
|
96
128
|
private createSchemaObject;
|
|
@@ -206,4 +238,4 @@ declare class ZModelCodeGenerator {
|
|
|
206
238
|
private isCollectionPredicateOperator;
|
|
207
239
|
}
|
|
208
240
|
|
|
209
|
-
export { type
|
|
241
|
+
export { type CliGeneratorContext, type CliPlugin, modelUtils as ModelUtils, PrismaSchemaGenerator, TsSchemaGenerator, ZModelCodeGenerator, type ZModelCodeOptions };
|
package/dist/index.js
CHANGED
|
@@ -778,7 +778,6 @@ var PrismaSchemaGenerator = class {
|
|
|
778
778
|
|
|
779
779
|
// src/ts-schema-generator.ts
|
|
780
780
|
import { invariant } from "@zenstackhq/common-helpers";
|
|
781
|
-
import { loadDocument } from "@zenstackhq/language";
|
|
782
781
|
import { isArrayExpr as isArrayExpr2, isBinaryExpr, isDataField, isDataModel as isDataModel3, isDataSource, isEnum, isEnumField, isInvocationExpr as isInvocationExpr2, isLiteralExpr as isLiteralExpr3, isMemberAccessExpr, isNullExpr as isNullExpr2, isProcedure, isReferenceExpr as isReferenceExpr2, isThisExpr, isTypeDef as isTypeDef2, isUnaryExpr } from "@zenstackhq/language/ast";
|
|
783
782
|
import { getAllAttributes as getAllAttributes2, getAllFields as getAllFields3, isDataFieldReference } from "@zenstackhq/language/utils";
|
|
784
783
|
import fs from "fs";
|
|
@@ -789,12 +788,7 @@ var TsSchemaGenerator = class {
|
|
|
789
788
|
static {
|
|
790
789
|
__name(this, "TsSchemaGenerator");
|
|
791
790
|
}
|
|
792
|
-
async generate(
|
|
793
|
-
const loaded = await loadDocument(schemaFile, pluginModelFiles);
|
|
794
|
-
if (!loaded.success) {
|
|
795
|
-
throw new Error(`Error loading schema:${loaded.errors.join("\n")}`);
|
|
796
|
-
}
|
|
797
|
-
const { model } = loaded;
|
|
791
|
+
async generate(model, outputDir) {
|
|
798
792
|
fs.mkdirSync(outputDir, {
|
|
799
793
|
recursive: true
|
|
800
794
|
});
|