@zenstackhq/sdk 3.0.0-alpha.2 → 3.0.0-alpha.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 CHANGED
@@ -852,27 +852,6 @@ var TsSchemaGenerator = class {
852
852
  ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("ExpressionUtils"))
853
853
  ])), ts.factory.createStringLiteral("@zenstackhq/runtime/schema"));
854
854
  statements.push(runtimeImportDecl);
855
- const { type: providerType } = this.getDataSourceProvider(model);
856
- switch (providerType) {
857
- case "sqlite": {
858
- const pathImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, ts.factory.createIdentifier("path"), void 0), ts.factory.createStringLiteral("node:path"));
859
- statements.push(pathImportDecl);
860
- const urlImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, ts.factory.createIdentifier("url"), void 0), ts.factory.createStringLiteral("node:url"));
861
- statements.push(urlImportDecl);
862
- const dialectConfigImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
863
- ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("toDialectConfig"))
864
- ])), ts.factory.createStringLiteral("@zenstackhq/runtime/utils/sqlite-utils"));
865
- statements.push(dialectConfigImportDecl);
866
- break;
867
- }
868
- case "postgresql": {
869
- const dialectConfigImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
870
- ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("toDialectConfig"))
871
- ])), ts.factory.createStringLiteral("@zenstackhq/runtime/utils/pg-utils"));
872
- statements.push(dialectConfigImportDecl);
873
- break;
874
- }
875
- }
876
855
  const declaration = ts.factory.createVariableStatement([
877
856
  ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
878
857
  ], ts.factory.createVariableDeclarationList([
@@ -909,8 +888,7 @@ var TsSchemaGenerator = class {
909
888
  createProviderObject(model) {
910
889
  const dsProvider = this.getDataSourceProvider(model);
911
890
  return ts.factory.createObjectLiteralExpression([
912
- ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider.type)),
913
- ts.factory.createPropertyAssignment("dialectConfigProvider", this.createDialectConfigProvider(dsProvider))
891
+ ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider.type))
914
892
  ], true);
915
893
  }
916
894
  createModelsObject(model) {
@@ -1218,44 +1196,6 @@ var TsSchemaGenerator = class {
1218
1196
  createLiteralNode(arg) {
1219
1197
  return arg === null ? ts.factory.createNull() : typeof arg === "string" ? ts.factory.createStringLiteral(arg) : typeof arg === "number" ? ts.factory.createNumericLiteral(arg) : arg === true ? ts.factory.createTrue() : arg === false ? ts.factory.createFalse() : void 0;
1220
1198
  }
1221
- createDialectConfigProvider(dsProvider) {
1222
- const type = dsProvider.type;
1223
- let urlExpr;
1224
- if (dsProvider.env !== void 0) {
1225
- urlExpr = ts.factory.createIdentifier(`process.env['${dsProvider.env}']`);
1226
- } else {
1227
- urlExpr = ts.factory.createStringLiteral(dsProvider.url);
1228
- if (type === "sqlite") {
1229
- let parsedUrl;
1230
- try {
1231
- parsedUrl = new URL(dsProvider.url);
1232
- } catch {
1233
- }
1234
- if (parsedUrl) {
1235
- if (parsedUrl.protocol !== "file:") {
1236
- throw new Error("Invalid SQLite URL: only file protocol is supported");
1237
- }
1238
- urlExpr = ts.factory.createStringLiteral(dsProvider.url.replace(/^file:/, ""));
1239
- }
1240
- }
1241
- }
1242
- return (0, import_ts_pattern2.match)(type).with("sqlite", () => {
1243
- return ts.factory.createFunctionExpression(void 0, void 0, void 0, void 0, void 0, void 0, ts.factory.createBlock([
1244
- ts.factory.createReturnStatement(ts.factory.createCallExpression(ts.factory.createIdentifier("toDialectConfig"), void 0, [
1245
- urlExpr,
1246
- ts.factory.createIdentifier(`typeof __dirname !== 'undefined' ? __dirname : path.dirname(url.fileURLToPath(import.meta.url))`)
1247
- ]))
1248
- ], true));
1249
- }).with("postgresql", () => {
1250
- return ts.factory.createFunctionExpression(void 0, void 0, void 0, void 0, void 0, void 0, ts.factory.createBlock([
1251
- ts.factory.createReturnStatement(ts.factory.createCallExpression(ts.factory.createIdentifier("toDialectConfig"), void 0, [
1252
- urlExpr
1253
- ]))
1254
- ], true));
1255
- }).otherwise(() => {
1256
- throw new Error(`Unsupported provider: ${type}`);
1257
- });
1258
- }
1259
1199
  createProceduresObject(procedures) {
1260
1200
  return ts.factory.createObjectLiteralExpression(procedures.map((proc) => ts.factory.createPropertyAssignment(proc.name, this.createProcedureObject(proc))), true);
1261
1201
  }