@zenstackhq/sdk 3.8.0-beta.1 → 3.8.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +37 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -1
- package/dist/index.d.mts +15 -1
- package/dist/index.mjs +37 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.cts
CHANGED
|
@@ -200,5 +200,19 @@ declare class TsSchemaGenerator {
|
|
|
200
200
|
private generateInputTypes;
|
|
201
201
|
}
|
|
202
202
|
//#endregion
|
|
203
|
-
|
|
203
|
+
//#region src/tsconfig-utils.d.ts
|
|
204
|
+
/**
|
|
205
|
+
* Detects the file extension that should be appended to relative imports in
|
|
206
|
+
* generated TypeScript, by inspecting the nearest `tsconfig.json` to the given
|
|
207
|
+
* directory.
|
|
208
|
+
*
|
|
209
|
+
* Returns `'.js'` when the project uses native ESM module resolution
|
|
210
|
+
* (`node16`/`nodenext`), which requires explicit extensions on relative imports.
|
|
211
|
+
* Returns `undefined` for `bundler`/`node` resolution (where extensionless
|
|
212
|
+
* imports are the idiomatic, maximally-compatible form) or when no tsconfig is
|
|
213
|
+
* found.
|
|
214
|
+
*/
|
|
215
|
+
declare function detectImportFileExtension(fromDir: string): string | undefined;
|
|
216
|
+
//#endregion
|
|
217
|
+
export { CliGeneratorContext, CliPlugin, model_utils_d_exports as ModelUtils, PrismaSchemaGenerator, TsSchemaGenerator, TsSchemaGeneratorOptions, detectImportFileExtension };
|
|
204
218
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -200,5 +200,19 @@ declare class TsSchemaGenerator {
|
|
|
200
200
|
private generateInputTypes;
|
|
201
201
|
}
|
|
202
202
|
//#endregion
|
|
203
|
-
|
|
203
|
+
//#region src/tsconfig-utils.d.ts
|
|
204
|
+
/**
|
|
205
|
+
* Detects the file extension that should be appended to relative imports in
|
|
206
|
+
* generated TypeScript, by inspecting the nearest `tsconfig.json` to the given
|
|
207
|
+
* directory.
|
|
208
|
+
*
|
|
209
|
+
* Returns `'.js'` when the project uses native ESM module resolution
|
|
210
|
+
* (`node16`/`nodenext`), which requires explicit extensions on relative imports.
|
|
211
|
+
* Returns `undefined` for `bundler`/`node` resolution (where extensionless
|
|
212
|
+
* imports are the idiomatic, maximally-compatible form) or when no tsconfig is
|
|
213
|
+
* found.
|
|
214
|
+
*/
|
|
215
|
+
declare function detectImportFileExtension(fromDir: string): string | undefined;
|
|
216
|
+
//#endregion
|
|
217
|
+
export { CliGeneratorContext, CliPlugin, model_utils_d_exports as ModelUtils, PrismaSchemaGenerator, TsSchemaGenerator, TsSchemaGeneratorOptions, detectImportFileExtension };
|
|
204
218
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -407,16 +407,16 @@ var PrismaSchemaGenerator = class {
|
|
|
407
407
|
async generate() {
|
|
408
408
|
const prisma = new PrismaModel();
|
|
409
409
|
for (const decl of this.zmodel.declarations) switch (decl.$type) {
|
|
410
|
-
case DataSource:
|
|
410
|
+
case DataSource.$type:
|
|
411
411
|
this.generateDataSource(prisma, decl);
|
|
412
412
|
break;
|
|
413
|
-
case Enum:
|
|
413
|
+
case Enum.$type:
|
|
414
414
|
this.generateEnum(prisma, decl);
|
|
415
415
|
break;
|
|
416
|
-
case DataModel:
|
|
416
|
+
case DataModel.$type:
|
|
417
417
|
this.generateModel(prisma, decl);
|
|
418
418
|
break;
|
|
419
|
-
case GeneratorDecl:
|
|
419
|
+
case GeneratorDecl.$type:
|
|
420
420
|
this.generateGenerator(prisma, decl);
|
|
421
421
|
break;
|
|
422
422
|
}
|
|
@@ -530,7 +530,7 @@ var PrismaSchemaGenerator = class {
|
|
|
530
530
|
return new AttributeArg(arg.name, this.makeAttributeArgValue(arg.value));
|
|
531
531
|
}
|
|
532
532
|
makeAttributeArgValue(node) {
|
|
533
|
-
if (isLiteralExpr(node)) return new AttributeArgValue(match(node.$type).with(StringLiteral, () => "String").with(NumberLiteral, () => "Number").with(BooleanLiteral, () => "Boolean").exhaustive(), node.value);
|
|
533
|
+
if (isLiteralExpr(node)) return new AttributeArgValue(match(node.$type).with(StringLiteral.$type, () => "String").with(NumberLiteral.$type, () => "Number").with(BooleanLiteral.$type, () => "Boolean").exhaustive(), node.value);
|
|
534
534
|
else if (isArrayExpr(node)) return new AttributeArgValue("Array", new Array(...node.items.map((item) => this.makeAttributeArgValue(item))));
|
|
535
535
|
else if (isReferenceExpr(node)) return new AttributeArgValue("FieldReference", new FieldReference(node.target.ref.name, node.args.map((arg) => new FieldReferenceArg(arg.name, this.exprToText(arg.value)))));
|
|
536
536
|
else if (isInvocationExpr(node)) return new AttributeArgValue("FunctionCall", this.makeFunctionCall(node));
|
|
@@ -1171,6 +1171,37 @@ var TsSchemaGenerator = class {
|
|
|
1171
1171
|
}
|
|
1172
1172
|
};
|
|
1173
1173
|
//#endregion
|
|
1174
|
-
|
|
1174
|
+
//#region src/tsconfig-utils.ts
|
|
1175
|
+
/**
|
|
1176
|
+
* Detects the file extension that should be appended to relative imports in
|
|
1177
|
+
* generated TypeScript, by inspecting the nearest `tsconfig.json` to the given
|
|
1178
|
+
* directory.
|
|
1179
|
+
*
|
|
1180
|
+
* Returns `'.js'` when the project uses native ESM module resolution
|
|
1181
|
+
* (`node16`/`nodenext`), which requires explicit extensions on relative imports.
|
|
1182
|
+
* Returns `undefined` for `bundler`/`node` resolution (where extensionless
|
|
1183
|
+
* imports are the idiomatic, maximally-compatible form) or when no tsconfig is
|
|
1184
|
+
* found.
|
|
1185
|
+
*/
|
|
1186
|
+
function detectImportFileExtension(fromDir) {
|
|
1187
|
+
const configPath = ts.findConfigFile(fromDir, ts.sys.fileExists, "tsconfig.json");
|
|
1188
|
+
if (!configPath) return;
|
|
1189
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
1190
|
+
if (configFile.error) return;
|
|
1191
|
+
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
|
|
1192
|
+
let moduleResolution = parsed.options.moduleResolution;
|
|
1193
|
+
if (moduleResolution === void 0) switch (parsed.options.module) {
|
|
1194
|
+
case ts.ModuleKind.Node16:
|
|
1195
|
+
case ts.ModuleKind.Node18:
|
|
1196
|
+
case ts.ModuleKind.Node20:
|
|
1197
|
+
case ts.ModuleKind.NodeNext:
|
|
1198
|
+
moduleResolution = ts.ModuleResolutionKind.NodeNext;
|
|
1199
|
+
break;
|
|
1200
|
+
default: break;
|
|
1201
|
+
}
|
|
1202
|
+
if (moduleResolution === ts.ModuleResolutionKind.Node16 || moduleResolution === ts.ModuleResolutionKind.NodeNext) return ".js";
|
|
1203
|
+
}
|
|
1204
|
+
//#endregion
|
|
1205
|
+
export { model_utils_exports as ModelUtils, PrismaSchemaGenerator, TsSchemaGenerator, detectImportFileExtension };
|
|
1175
1206
|
|
|
1176
1207
|
//# sourceMappingURL=index.mjs.map
|