@stryke/prisma-trpc-generator 0.7.1 → 0.7.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.
@@ -7326,28 +7326,6 @@ function resolvePaths(...paths) {
7326
7326
  return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
7327
7327
  }
7328
7328
  __name(resolvePaths, "resolvePaths");
7329
- function relativePath(from, to) {
7330
- const _from = resolvePath(from).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7331
- const _to = resolvePath(to).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7332
- if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
7333
- return _to.join("/");
7334
- }
7335
- const _fromCopy = [
7336
- ..._from
7337
- ];
7338
- for (const segment of _fromCopy) {
7339
- if (_to[0] !== segment) {
7340
- break;
7341
- }
7342
- _from.shift();
7343
- _to.shift();
7344
- }
7345
- return [
7346
- ..._from.map(() => ".."),
7347
- ..._to
7348
- ].join("/");
7349
- }
7350
- __name(relativePath, "relativePath");
7351
7329
 
7352
7330
  // ../string-format/src/lower-case-first.ts
7353
7331
  init_cjs_shims();
@@ -7603,15 +7581,15 @@ __name(getPrismaGeneratorHelper, "getPrismaGeneratorHelper");
7603
7581
  // src/utils/get-relative-path.ts
7604
7582
  init_cjs_shims();
7605
7583
  var import_node_path3 = __toESM(require("node:path"), 1);
7606
- function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath) {
7607
- const fromPath = import_node_path3.default.join(outputPath, "routers", "helpers");
7584
+ function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath, fromPath) {
7585
+ const _fromPath = fromPath || outputPath;
7608
7586
  let toPath = import_node_path3.default.join(outputPath, filePath);
7609
7587
  if (isOutsideOutputPath) {
7610
7588
  const schemaPathSplit = schemaPath?.split(import_node_path3.default.sep);
7611
7589
  const schemaPathWithoutFileAndExtension = schemaPathSplit.slice(0, schemaPathSplit.length - 1).join(import_node_path3.default.posix.sep);
7612
7590
  toPath = import_node_path3.default.join(schemaPathWithoutFileAndExtension, filePath);
7613
7591
  }
7614
- const newPath = import_node_path3.default.relative(fromPath, toPath).split(import_node_path3.default.sep).join(import_node_path3.default.posix.sep);
7592
+ const newPath = import_node_path3.default.relative(_fromPath, toPath).split(import_node_path3.default.sep).join(import_node_path3.default.posix.sep);
7615
7593
  return newPath;
7616
7594
  }
7617
7595
  __name(getRelativePath, "getRelativePath");
@@ -7637,7 +7615,7 @@ var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, va
7637
7615
  const outputDir = internals.parseEnvValue(options.generator.output);
7638
7616
  let shieldPath = joinPaths(outputDir, "shield");
7639
7617
  if (typeof value === "string") {
7640
- shieldPath = joinPaths(relativePath(outputDir, options.schemaPath), value);
7618
+ shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
7641
7619
  }
7642
7620
  sourceFile.addImportDeclaration({
7643
7621
  moduleSpecifier: shieldPath,
@@ -7657,37 +7635,30 @@ var generateRouterImport = /* @__PURE__ */ __name((sourceFile, modelNamePlural,
7657
7635
  async function generateBaseRouter(sourceFile, config, options) {
7658
7636
  const internals = await getPrismaInternals();
7659
7637
  const outputDir = internals.parseEnvValue(options.generator.output);
7660
- const relativeContextPath = joinPaths(relativePath(outputDir, options.schemaPath), config.contextPath);
7661
7638
  sourceFile.addStatements(
7662
7639
  /* ts */
7663
7640
  `
7664
- import type { Context } from '${relativeContextPath}';
7665
- `
7641
+ import type { Context } from '${getRelativePath(outputDir, config.contextPath, true, options.schemaPath)}';`
7666
7642
  );
7667
7643
  if (config.trpcOptions) {
7668
7644
  sourceFile.addStatements(
7669
7645
  /* ts */
7670
7646
  `
7671
- import trpcOptions from '${getRelativePath(outputDir, typeof config.trpcOptions === "boolean" ? joinPaths(outputDir, "options") : config.trpcOptions, true, options.schemaPath)}';
7672
- `
7647
+ import trpcOptions from '${getRelativePath(outputDir, typeof config.trpcOptions === "boolean" ? joinPaths(outputDir, "options") : config.trpcOptions, true, options.schemaPath)}';`
7673
7648
  );
7674
7649
  }
7675
7650
  if (config.withNext) {
7676
7651
  sourceFile.addStatements(
7677
7652
  /* ts */
7678
- `
7679
- import { createContext } from '${relativeContextPath}';
7680
- import { initTRPC, TRPCError } from '@trpc/server';
7681
- import { experimental_nextAppDirCaller } from '@trpc/server/adapters/next-app-dir';
7682
- import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler';
7683
- `
7653
+ `import { createContext } from '${getRelativePath(outputDir, config.contextPath, true, options.schemaPath)}';
7654
+ import { initTRPC } from '@trpc/server';
7655
+ import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler';`
7684
7656
  );
7685
7657
  }
7686
7658
  sourceFile.addStatements(
7687
7659
  /* ts */
7688
7660
  `
7689
- export const t = initTRPC.context<Context>().create(${config.trpcOptions ? "trpcOptions" : ""});
7690
- `
7661
+ export const t = initTRPC.context<Context>().create(${config.trpcOptions ? "trpcOptions" : ""});`
7691
7662
  );
7692
7663
  const middlewares = [];
7693
7664
  if (config.withMiddleware && typeof config.withMiddleware === "boolean") {
@@ -7776,13 +7747,7 @@ export const createCallerFactory = t.createCallerFactory;`
7776
7747
  }
7777
7748
  sourceFile.addStatements(
7778
7749
  /* ts */
7779
- `
7780
- .use(${middleware.type === "shield" ? "permissionsMiddleware" : "globalMiddleware"})${config.withNext ? `.experimental_caller(
7781
- experimental_nextAppDirCaller({
7782
- normalizeFormData: true,
7783
- }),
7784
- )` : ""}
7785
- `
7750
+ `.use(${middleware.type === "shield" ? "permissionsMiddleware" : "globalMiddleware"})`
7786
7751
  );
7787
7752
  });
7788
7753
  }
@@ -7965,7 +7930,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
7965
7930
  var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
7966
7931
  return `export const permissions = ${shieldObjectText};`;
7967
7932
  }, "wrapWithExport");
7968
- var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, shieldOutputDir) => {
7933
+ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, outputDir) => {
7969
7934
  if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
7970
7935
  return "";
7971
7936
  }
@@ -7992,7 +7957,7 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
7992
7957
  return "";
7993
7958
  }
7994
7959
  let shieldText = getImports("trpc-shield");
7995
- shieldText += getImports("context", relativePath(shieldOutputDir, joinPaths(options.schemaPath, config.contextPath)));
7960
+ shieldText += getImports("context", getRelativePath(outputDir, config.contextPath, true, options.schemaPath));
7996
7961
  shieldText += "\n\n";
7997
7962
  shieldText += wrapWithExport({
7998
7963
  shieldObjectText: wrapWithTrpcShieldCall({
@@ -10339,11 +10304,11 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
10339
10304
  }, "writeFileSafely");
10340
10305
  var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
10341
10306
  const rows = Array.from(indexExports).map((filePath) => {
10342
- let relativePath2 = import_node_path4.default.relative(import_node_path4.default.dirname(indexPath), filePath);
10343
- if (relativePath2.endsWith(".ts")) {
10344
- relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
10307
+ let relativePath = import_node_path4.default.relative(import_node_path4.default.dirname(indexPath), filePath);
10308
+ if (relativePath.endsWith(".ts")) {
10309
+ relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts"));
10345
10310
  }
10346
- const normalized = correctPath(relativePath2);
10311
+ const normalized = correctPath(relativePath);
10347
10312
  return `export * from './${normalized}'`;
10348
10313
  });
10349
10314
  await writeFileSafely(indexPath, rows.join("\n"), false);
@@ -11630,26 +11595,12 @@ async function generate(options) {
11630
11595
  consoleLog("Skipping tRPC Shield generation as path provided already exists");
11631
11596
  } else {
11632
11597
  consoleLog("Constructing tRPC Shield source file");
11633
- const shieldOutputDir = typeof config.withShield === "string" ? findFilePath(config.withShield) : outputDir;
11598
+ const shieldOutputDir = typeof config.withShield === "string" && config.withShield !== "true" ? findFilePath(config.withShield) : outputDir;
11634
11599
  const shieldText = await constructShield({
11635
11600
  queries,
11636
11601
  mutations,
11637
11602
  subscriptions
11638
- }, config, {
11639
- ...options,
11640
- generator: {
11641
- ...options.generator,
11642
- output: {
11643
- fromEnvVar: null,
11644
- ...options.generator.output,
11645
- value: outputDir
11646
- },
11647
- config: {
11648
- ...options.generator.config,
11649
- contextPath: config.contextPath
11650
- }
11651
- }
11652
- }, shieldOutputDir);
11603
+ }, config, options, shieldOutputDir);
11653
11604
  consoleLog("Saving tRPC Shield source file to disk");
11654
11605
  await writeFileSafely(joinPaths(shieldOutputDir, "shield.ts"), shieldText);
11655
11606
  }
package/dist/generator.js CHANGED
@@ -7331,28 +7331,6 @@ function resolvePaths(...paths) {
7331
7331
  return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
7332
7332
  }
7333
7333
  __name(resolvePaths, "resolvePaths");
7334
- function relativePath(from, to) {
7335
- const _from = resolvePath(from).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7336
- const _to = resolvePath(to).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7337
- if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
7338
- return _to.join("/");
7339
- }
7340
- const _fromCopy = [
7341
- ..._from
7342
- ];
7343
- for (const segment of _fromCopy) {
7344
- if (_to[0] !== segment) {
7345
- break;
7346
- }
7347
- _from.shift();
7348
- _to.shift();
7349
- }
7350
- return [
7351
- ..._from.map(() => ".."),
7352
- ..._to
7353
- ].join("/");
7354
- }
7355
- __name(relativePath, "relativePath");
7356
7334
 
7357
7335
  // ../string-format/src/lower-case-first.ts
7358
7336
  init_esm_shims();
@@ -7608,15 +7586,15 @@ __name(getPrismaGeneratorHelper, "getPrismaGeneratorHelper");
7608
7586
  // src/utils/get-relative-path.ts
7609
7587
  init_esm_shims();
7610
7588
  import path2 from "node:path";
7611
- function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath) {
7612
- const fromPath = path2.join(outputPath, "routers", "helpers");
7589
+ function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath, fromPath) {
7590
+ const _fromPath = fromPath || outputPath;
7613
7591
  let toPath = path2.join(outputPath, filePath);
7614
7592
  if (isOutsideOutputPath) {
7615
7593
  const schemaPathSplit = schemaPath?.split(path2.sep);
7616
7594
  const schemaPathWithoutFileAndExtension = schemaPathSplit.slice(0, schemaPathSplit.length - 1).join(path2.posix.sep);
7617
7595
  toPath = path2.join(schemaPathWithoutFileAndExtension, filePath);
7618
7596
  }
7619
- const newPath = path2.relative(fromPath, toPath).split(path2.sep).join(path2.posix.sep);
7597
+ const newPath = path2.relative(_fromPath, toPath).split(path2.sep).join(path2.posix.sep);
7620
7598
  return newPath;
7621
7599
  }
7622
7600
  __name(getRelativePath, "getRelativePath");
@@ -7642,7 +7620,7 @@ var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, va
7642
7620
  const outputDir = internals.parseEnvValue(options.generator.output);
7643
7621
  let shieldPath = joinPaths(outputDir, "shield");
7644
7622
  if (typeof value === "string") {
7645
- shieldPath = joinPaths(relativePath(outputDir, options.schemaPath), value);
7623
+ shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
7646
7624
  }
7647
7625
  sourceFile.addImportDeclaration({
7648
7626
  moduleSpecifier: shieldPath,
@@ -7662,37 +7640,30 @@ var generateRouterImport = /* @__PURE__ */ __name((sourceFile, modelNamePlural,
7662
7640
  async function generateBaseRouter(sourceFile, config, options) {
7663
7641
  const internals = await getPrismaInternals();
7664
7642
  const outputDir = internals.parseEnvValue(options.generator.output);
7665
- const relativeContextPath = joinPaths(relativePath(outputDir, options.schemaPath), config.contextPath);
7666
7643
  sourceFile.addStatements(
7667
7644
  /* ts */
7668
7645
  `
7669
- import type { Context } from '${relativeContextPath}';
7670
- `
7646
+ import type { Context } from '${getRelativePath(outputDir, config.contextPath, true, options.schemaPath)}';`
7671
7647
  );
7672
7648
  if (config.trpcOptions) {
7673
7649
  sourceFile.addStatements(
7674
7650
  /* ts */
7675
7651
  `
7676
- import trpcOptions from '${getRelativePath(outputDir, typeof config.trpcOptions === "boolean" ? joinPaths(outputDir, "options") : config.trpcOptions, true, options.schemaPath)}';
7677
- `
7652
+ import trpcOptions from '${getRelativePath(outputDir, typeof config.trpcOptions === "boolean" ? joinPaths(outputDir, "options") : config.trpcOptions, true, options.schemaPath)}';`
7678
7653
  );
7679
7654
  }
7680
7655
  if (config.withNext) {
7681
7656
  sourceFile.addStatements(
7682
7657
  /* ts */
7683
- `
7684
- import { createContext } from '${relativeContextPath}';
7685
- import { initTRPC, TRPCError } from '@trpc/server';
7686
- import { experimental_nextAppDirCaller } from '@trpc/server/adapters/next-app-dir';
7687
- import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler';
7688
- `
7658
+ `import { createContext } from '${getRelativePath(outputDir, config.contextPath, true, options.schemaPath)}';
7659
+ import { initTRPC } from '@trpc/server';
7660
+ import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler';`
7689
7661
  );
7690
7662
  }
7691
7663
  sourceFile.addStatements(
7692
7664
  /* ts */
7693
7665
  `
7694
- export const t = initTRPC.context<Context>().create(${config.trpcOptions ? "trpcOptions" : ""});
7695
- `
7666
+ export const t = initTRPC.context<Context>().create(${config.trpcOptions ? "trpcOptions" : ""});`
7696
7667
  );
7697
7668
  const middlewares = [];
7698
7669
  if (config.withMiddleware && typeof config.withMiddleware === "boolean") {
@@ -7781,13 +7752,7 @@ export const createCallerFactory = t.createCallerFactory;`
7781
7752
  }
7782
7753
  sourceFile.addStatements(
7783
7754
  /* ts */
7784
- `
7785
- .use(${middleware.type === "shield" ? "permissionsMiddleware" : "globalMiddleware"})${config.withNext ? `.experimental_caller(
7786
- experimental_nextAppDirCaller({
7787
- normalizeFormData: true,
7788
- }),
7789
- )` : ""}
7790
- `
7755
+ `.use(${middleware.type === "shield" ? "permissionsMiddleware" : "globalMiddleware"})`
7791
7756
  );
7792
7757
  });
7793
7758
  }
@@ -7970,7 +7935,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
7970
7935
  var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
7971
7936
  return `export const permissions = ${shieldObjectText};`;
7972
7937
  }, "wrapWithExport");
7973
- var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, shieldOutputDir) => {
7938
+ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, outputDir) => {
7974
7939
  if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
7975
7940
  return "";
7976
7941
  }
@@ -7997,7 +7962,7 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
7997
7962
  return "";
7998
7963
  }
7999
7964
  let shieldText = getImports("trpc-shield");
8000
- shieldText += getImports("context", relativePath(shieldOutputDir, joinPaths(options.schemaPath, config.contextPath)));
7965
+ shieldText += getImports("context", getRelativePath(outputDir, config.contextPath, true, options.schemaPath));
8001
7966
  shieldText += "\n\n";
8002
7967
  shieldText += wrapWithExport({
8003
7968
  shieldObjectText: wrapWithTrpcShieldCall({
@@ -10344,11 +10309,11 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
10344
10309
  }, "writeFileSafely");
10345
10310
  var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
10346
10311
  const rows = Array.from(indexExports).map((filePath) => {
10347
- let relativePath2 = path3.relative(path3.dirname(indexPath), filePath);
10348
- if (relativePath2.endsWith(".ts")) {
10349
- relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
10312
+ let relativePath = path3.relative(path3.dirname(indexPath), filePath);
10313
+ if (relativePath.endsWith(".ts")) {
10314
+ relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts"));
10350
10315
  }
10351
- const normalized = correctPath(relativePath2);
10316
+ const normalized = correctPath(relativePath);
10352
10317
  return `export * from './${normalized}'`;
10353
10318
  });
10354
10319
  await writeFileSafely(indexPath, rows.join("\n"), false);
@@ -11635,26 +11600,12 @@ async function generate(options) {
11635
11600
  consoleLog("Skipping tRPC Shield generation as path provided already exists");
11636
11601
  } else {
11637
11602
  consoleLog("Constructing tRPC Shield source file");
11638
- const shieldOutputDir = typeof config.withShield === "string" ? findFilePath(config.withShield) : outputDir;
11603
+ const shieldOutputDir = typeof config.withShield === "string" && config.withShield !== "true" ? findFilePath(config.withShield) : outputDir;
11639
11604
  const shieldText = await constructShield({
11640
11605
  queries,
11641
11606
  mutations,
11642
11607
  subscriptions
11643
- }, config, {
11644
- ...options,
11645
- generator: {
11646
- ...options.generator,
11647
- output: {
11648
- fromEnvVar: null,
11649
- ...options.generator.output,
11650
- value: outputDir
11651
- },
11652
- config: {
11653
- ...options.generator.config,
11654
- contextPath: config.contextPath
11655
- }
11656
- }
11657
- }, shieldOutputDir);
11608
+ }, config, options, shieldOutputDir);
11658
11609
  consoleLog("Saving tRPC Shield source file to disk");
11659
11610
  await writeFileSafely(joinPaths(shieldOutputDir, "shield.ts"), shieldText);
11660
11611
  }
package/dist/index.cjs CHANGED
@@ -7322,28 +7322,6 @@ function resolvePaths(...paths) {
7322
7322
  return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
7323
7323
  }
7324
7324
  __name(resolvePaths, "resolvePaths");
7325
- function relativePath(from, to) {
7326
- const _from = resolvePath(from).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7327
- const _to = resolvePath(to).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7328
- if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
7329
- return _to.join("/");
7330
- }
7331
- const _fromCopy = [
7332
- ..._from
7333
- ];
7334
- for (const segment of _fromCopy) {
7335
- if (_to[0] !== segment) {
7336
- break;
7337
- }
7338
- _from.shift();
7339
- _to.shift();
7340
- }
7341
- return [
7342
- ..._from.map(() => ".."),
7343
- ..._to
7344
- ].join("/");
7345
- }
7346
- __name(relativePath, "relativePath");
7347
7325
 
7348
7326
  // ../string-format/src/lower-case-first.ts
7349
7327
  init_cjs_shims();
@@ -7599,15 +7577,15 @@ __name(getPrismaGeneratorHelper, "getPrismaGeneratorHelper");
7599
7577
  // src/utils/get-relative-path.ts
7600
7578
  init_cjs_shims();
7601
7579
  var import_node_path3 = __toESM(require("node:path"), 1);
7602
- function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath) {
7603
- const fromPath = import_node_path3.default.join(outputPath, "routers", "helpers");
7580
+ function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath, fromPath) {
7581
+ const _fromPath = fromPath || outputPath;
7604
7582
  let toPath = import_node_path3.default.join(outputPath, filePath);
7605
7583
  if (isOutsideOutputPath) {
7606
7584
  const schemaPathSplit = schemaPath?.split(import_node_path3.default.sep);
7607
7585
  const schemaPathWithoutFileAndExtension = schemaPathSplit.slice(0, schemaPathSplit.length - 1).join(import_node_path3.default.posix.sep);
7608
7586
  toPath = import_node_path3.default.join(schemaPathWithoutFileAndExtension, filePath);
7609
7587
  }
7610
- const newPath = import_node_path3.default.relative(fromPath, toPath).split(import_node_path3.default.sep).join(import_node_path3.default.posix.sep);
7588
+ const newPath = import_node_path3.default.relative(_fromPath, toPath).split(import_node_path3.default.sep).join(import_node_path3.default.posix.sep);
7611
7589
  return newPath;
7612
7590
  }
7613
7591
  __name(getRelativePath, "getRelativePath");
@@ -7633,7 +7611,7 @@ var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, va
7633
7611
  const outputDir = internals.parseEnvValue(options.generator.output);
7634
7612
  let shieldPath = joinPaths(outputDir, "shield");
7635
7613
  if (typeof value === "string") {
7636
- shieldPath = joinPaths(relativePath(outputDir, options.schemaPath), value);
7614
+ shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
7637
7615
  }
7638
7616
  sourceFile.addImportDeclaration({
7639
7617
  moduleSpecifier: shieldPath,
@@ -7653,37 +7631,30 @@ var generateRouterImport = /* @__PURE__ */ __name((sourceFile, modelNamePlural,
7653
7631
  async function generateBaseRouter(sourceFile, config, options) {
7654
7632
  const internals = await getPrismaInternals();
7655
7633
  const outputDir = internals.parseEnvValue(options.generator.output);
7656
- const relativeContextPath = joinPaths(relativePath(outputDir, options.schemaPath), config.contextPath);
7657
7634
  sourceFile.addStatements(
7658
7635
  /* ts */
7659
7636
  `
7660
- import type { Context } from '${relativeContextPath}';
7661
- `
7637
+ import type { Context } from '${getRelativePath(outputDir, config.contextPath, true, options.schemaPath)}';`
7662
7638
  );
7663
7639
  if (config.trpcOptions) {
7664
7640
  sourceFile.addStatements(
7665
7641
  /* ts */
7666
7642
  `
7667
- import trpcOptions from '${getRelativePath(outputDir, typeof config.trpcOptions === "boolean" ? joinPaths(outputDir, "options") : config.trpcOptions, true, options.schemaPath)}';
7668
- `
7643
+ import trpcOptions from '${getRelativePath(outputDir, typeof config.trpcOptions === "boolean" ? joinPaths(outputDir, "options") : config.trpcOptions, true, options.schemaPath)}';`
7669
7644
  );
7670
7645
  }
7671
7646
  if (config.withNext) {
7672
7647
  sourceFile.addStatements(
7673
7648
  /* ts */
7674
- `
7675
- import { createContext } from '${relativeContextPath}';
7676
- import { initTRPC, TRPCError } from '@trpc/server';
7677
- import { experimental_nextAppDirCaller } from '@trpc/server/adapters/next-app-dir';
7678
- import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler';
7679
- `
7649
+ `import { createContext } from '${getRelativePath(outputDir, config.contextPath, true, options.schemaPath)}';
7650
+ import { initTRPC } from '@trpc/server';
7651
+ import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler';`
7680
7652
  );
7681
7653
  }
7682
7654
  sourceFile.addStatements(
7683
7655
  /* ts */
7684
7656
  `
7685
- export const t = initTRPC.context<Context>().create(${config.trpcOptions ? "trpcOptions" : ""});
7686
- `
7657
+ export const t = initTRPC.context<Context>().create(${config.trpcOptions ? "trpcOptions" : ""});`
7687
7658
  );
7688
7659
  const middlewares = [];
7689
7660
  if (config.withMiddleware && typeof config.withMiddleware === "boolean") {
@@ -7772,13 +7743,7 @@ export const createCallerFactory = t.createCallerFactory;`
7772
7743
  }
7773
7744
  sourceFile.addStatements(
7774
7745
  /* ts */
7775
- `
7776
- .use(${middleware.type === "shield" ? "permissionsMiddleware" : "globalMiddleware"})${config.withNext ? `.experimental_caller(
7777
- experimental_nextAppDirCaller({
7778
- normalizeFormData: true,
7779
- }),
7780
- )` : ""}
7781
- `
7746
+ `.use(${middleware.type === "shield" ? "permissionsMiddleware" : "globalMiddleware"})`
7782
7747
  );
7783
7748
  });
7784
7749
  }
@@ -7961,7 +7926,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
7961
7926
  var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
7962
7927
  return `export const permissions = ${shieldObjectText};`;
7963
7928
  }, "wrapWithExport");
7964
- var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, shieldOutputDir) => {
7929
+ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, outputDir) => {
7965
7930
  if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
7966
7931
  return "";
7967
7932
  }
@@ -7988,7 +7953,7 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
7988
7953
  return "";
7989
7954
  }
7990
7955
  let shieldText = getImports("trpc-shield");
7991
- shieldText += getImports("context", relativePath(shieldOutputDir, joinPaths(options.schemaPath, config.contextPath)));
7956
+ shieldText += getImports("context", getRelativePath(outputDir, config.contextPath, true, options.schemaPath));
7992
7957
  shieldText += "\n\n";
7993
7958
  shieldText += wrapWithExport({
7994
7959
  shieldObjectText: wrapWithTrpcShieldCall({
@@ -10335,11 +10300,11 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
10335
10300
  }, "writeFileSafely");
10336
10301
  var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
10337
10302
  const rows = Array.from(indexExports).map((filePath) => {
10338
- let relativePath2 = import_node_path4.default.relative(import_node_path4.default.dirname(indexPath), filePath);
10339
- if (relativePath2.endsWith(".ts")) {
10340
- relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
10303
+ let relativePath = import_node_path4.default.relative(import_node_path4.default.dirname(indexPath), filePath);
10304
+ if (relativePath.endsWith(".ts")) {
10305
+ relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts"));
10341
10306
  }
10342
- const normalized = correctPath(relativePath2);
10307
+ const normalized = correctPath(relativePath);
10343
10308
  return `export * from './${normalized}'`;
10344
10309
  });
10345
10310
  await writeFileSafely(indexPath, rows.join("\n"), false);
@@ -11626,26 +11591,12 @@ async function generate(options) {
11626
11591
  consoleLog("Skipping tRPC Shield generation as path provided already exists");
11627
11592
  } else {
11628
11593
  consoleLog("Constructing tRPC Shield source file");
11629
- const shieldOutputDir = typeof config.withShield === "string" ? findFilePath(config.withShield) : outputDir;
11594
+ const shieldOutputDir = typeof config.withShield === "string" && config.withShield !== "true" ? findFilePath(config.withShield) : outputDir;
11630
11595
  const shieldText = await constructShield({
11631
11596
  queries,
11632
11597
  mutations,
11633
11598
  subscriptions
11634
- }, config, {
11635
- ...options,
11636
- generator: {
11637
- ...options.generator,
11638
- output: {
11639
- fromEnvVar: null,
11640
- ...options.generator.output,
11641
- value: outputDir
11642
- },
11643
- config: {
11644
- ...options.generator.config,
11645
- contextPath: config.contextPath
11646
- }
11647
- }
11648
- }, shieldOutputDir);
11599
+ }, config, options, shieldOutputDir);
11649
11600
  consoleLog("Saving tRPC Shield source file to disk");
11650
11601
  await writeFileSafely(joinPaths(shieldOutputDir, "shield.ts"), shieldText);
11651
11602
  }
package/dist/index.js CHANGED
@@ -7327,28 +7327,6 @@ function resolvePaths(...paths) {
7327
7327
  return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
7328
7328
  }
7329
7329
  __name(resolvePaths, "resolvePaths");
7330
- function relativePath(from, to) {
7331
- const _from = resolvePath(from).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7332
- const _to = resolvePath(to).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7333
- if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
7334
- return _to.join("/");
7335
- }
7336
- const _fromCopy = [
7337
- ..._from
7338
- ];
7339
- for (const segment of _fromCopy) {
7340
- if (_to[0] !== segment) {
7341
- break;
7342
- }
7343
- _from.shift();
7344
- _to.shift();
7345
- }
7346
- return [
7347
- ..._from.map(() => ".."),
7348
- ..._to
7349
- ].join("/");
7350
- }
7351
- __name(relativePath, "relativePath");
7352
7330
 
7353
7331
  // ../string-format/src/lower-case-first.ts
7354
7332
  init_esm_shims();
@@ -7604,15 +7582,15 @@ __name(getPrismaGeneratorHelper, "getPrismaGeneratorHelper");
7604
7582
  // src/utils/get-relative-path.ts
7605
7583
  init_esm_shims();
7606
7584
  import path2 from "node:path";
7607
- function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath) {
7608
- const fromPath = path2.join(outputPath, "routers", "helpers");
7585
+ function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath, fromPath) {
7586
+ const _fromPath = fromPath || outputPath;
7609
7587
  let toPath = path2.join(outputPath, filePath);
7610
7588
  if (isOutsideOutputPath) {
7611
7589
  const schemaPathSplit = schemaPath?.split(path2.sep);
7612
7590
  const schemaPathWithoutFileAndExtension = schemaPathSplit.slice(0, schemaPathSplit.length - 1).join(path2.posix.sep);
7613
7591
  toPath = path2.join(schemaPathWithoutFileAndExtension, filePath);
7614
7592
  }
7615
- const newPath = path2.relative(fromPath, toPath).split(path2.sep).join(path2.posix.sep);
7593
+ const newPath = path2.relative(_fromPath, toPath).split(path2.sep).join(path2.posix.sep);
7616
7594
  return newPath;
7617
7595
  }
7618
7596
  __name(getRelativePath, "getRelativePath");
@@ -7638,7 +7616,7 @@ var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, va
7638
7616
  const outputDir = internals.parseEnvValue(options.generator.output);
7639
7617
  let shieldPath = joinPaths(outputDir, "shield");
7640
7618
  if (typeof value === "string") {
7641
- shieldPath = joinPaths(relativePath(outputDir, options.schemaPath), value);
7619
+ shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
7642
7620
  }
7643
7621
  sourceFile.addImportDeclaration({
7644
7622
  moduleSpecifier: shieldPath,
@@ -7658,37 +7636,30 @@ var generateRouterImport = /* @__PURE__ */ __name((sourceFile, modelNamePlural,
7658
7636
  async function generateBaseRouter(sourceFile, config, options) {
7659
7637
  const internals = await getPrismaInternals();
7660
7638
  const outputDir = internals.parseEnvValue(options.generator.output);
7661
- const relativeContextPath = joinPaths(relativePath(outputDir, options.schemaPath), config.contextPath);
7662
7639
  sourceFile.addStatements(
7663
7640
  /* ts */
7664
7641
  `
7665
- import type { Context } from '${relativeContextPath}';
7666
- `
7642
+ import type { Context } from '${getRelativePath(outputDir, config.contextPath, true, options.schemaPath)}';`
7667
7643
  );
7668
7644
  if (config.trpcOptions) {
7669
7645
  sourceFile.addStatements(
7670
7646
  /* ts */
7671
7647
  `
7672
- import trpcOptions from '${getRelativePath(outputDir, typeof config.trpcOptions === "boolean" ? joinPaths(outputDir, "options") : config.trpcOptions, true, options.schemaPath)}';
7673
- `
7648
+ import trpcOptions from '${getRelativePath(outputDir, typeof config.trpcOptions === "boolean" ? joinPaths(outputDir, "options") : config.trpcOptions, true, options.schemaPath)}';`
7674
7649
  );
7675
7650
  }
7676
7651
  if (config.withNext) {
7677
7652
  sourceFile.addStatements(
7678
7653
  /* ts */
7679
- `
7680
- import { createContext } from '${relativeContextPath}';
7681
- import { initTRPC, TRPCError } from '@trpc/server';
7682
- import { experimental_nextAppDirCaller } from '@trpc/server/adapters/next-app-dir';
7683
- import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler';
7684
- `
7654
+ `import { createContext } from '${getRelativePath(outputDir, config.contextPath, true, options.schemaPath)}';
7655
+ import { initTRPC } from '@trpc/server';
7656
+ import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler';`
7685
7657
  );
7686
7658
  }
7687
7659
  sourceFile.addStatements(
7688
7660
  /* ts */
7689
7661
  `
7690
- export const t = initTRPC.context<Context>().create(${config.trpcOptions ? "trpcOptions" : ""});
7691
- `
7662
+ export const t = initTRPC.context<Context>().create(${config.trpcOptions ? "trpcOptions" : ""});`
7692
7663
  );
7693
7664
  const middlewares = [];
7694
7665
  if (config.withMiddleware && typeof config.withMiddleware === "boolean") {
@@ -7777,13 +7748,7 @@ export const createCallerFactory = t.createCallerFactory;`
7777
7748
  }
7778
7749
  sourceFile.addStatements(
7779
7750
  /* ts */
7780
- `
7781
- .use(${middleware.type === "shield" ? "permissionsMiddleware" : "globalMiddleware"})${config.withNext ? `.experimental_caller(
7782
- experimental_nextAppDirCaller({
7783
- normalizeFormData: true,
7784
- }),
7785
- )` : ""}
7786
- `
7751
+ `.use(${middleware.type === "shield" ? "permissionsMiddleware" : "globalMiddleware"})`
7787
7752
  );
7788
7753
  });
7789
7754
  }
@@ -7966,7 +7931,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
7966
7931
  var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
7967
7932
  return `export const permissions = ${shieldObjectText};`;
7968
7933
  }, "wrapWithExport");
7969
- var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, shieldOutputDir) => {
7934
+ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, outputDir) => {
7970
7935
  if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
7971
7936
  return "";
7972
7937
  }
@@ -7993,7 +7958,7 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
7993
7958
  return "";
7994
7959
  }
7995
7960
  let shieldText = getImports("trpc-shield");
7996
- shieldText += getImports("context", relativePath(shieldOutputDir, joinPaths(options.schemaPath, config.contextPath)));
7961
+ shieldText += getImports("context", getRelativePath(outputDir, config.contextPath, true, options.schemaPath));
7997
7962
  shieldText += "\n\n";
7998
7963
  shieldText += wrapWithExport({
7999
7964
  shieldObjectText: wrapWithTrpcShieldCall({
@@ -10340,11 +10305,11 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
10340
10305
  }, "writeFileSafely");
10341
10306
  var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
10342
10307
  const rows = Array.from(indexExports).map((filePath) => {
10343
- let relativePath2 = path3.relative(path3.dirname(indexPath), filePath);
10344
- if (relativePath2.endsWith(".ts")) {
10345
- relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
10308
+ let relativePath = path3.relative(path3.dirname(indexPath), filePath);
10309
+ if (relativePath.endsWith(".ts")) {
10310
+ relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts"));
10346
10311
  }
10347
- const normalized = correctPath(relativePath2);
10312
+ const normalized = correctPath(relativePath);
10348
10313
  return `export * from './${normalized}'`;
10349
10314
  });
10350
10315
  await writeFileSafely(indexPath, rows.join("\n"), false);
@@ -11631,26 +11596,12 @@ async function generate(options) {
11631
11596
  consoleLog("Skipping tRPC Shield generation as path provided already exists");
11632
11597
  } else {
11633
11598
  consoleLog("Constructing tRPC Shield source file");
11634
- const shieldOutputDir = typeof config.withShield === "string" ? findFilePath(config.withShield) : outputDir;
11599
+ const shieldOutputDir = typeof config.withShield === "string" && config.withShield !== "true" ? findFilePath(config.withShield) : outputDir;
11635
11600
  const shieldText = await constructShield({
11636
11601
  queries,
11637
11602
  mutations,
11638
11603
  subscriptions
11639
- }, config, {
11640
- ...options,
11641
- generator: {
11642
- ...options.generator,
11643
- output: {
11644
- fromEnvVar: null,
11645
- ...options.generator.output,
11646
- value: outputDir
11647
- },
11648
- config: {
11649
- ...options.generator.config,
11650
- contextPath: config.contextPath
11651
- }
11652
- }
11653
- }, shieldOutputDir);
11604
+ }, config, options, shieldOutputDir);
11654
11605
  consoleLog("Saving tRPC Shield source file to disk");
11655
11606
  await writeFileSafely(joinPaths(shieldOutputDir, "shield.ts"), shieldText);
11656
11607
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/prisma-trpc-generator",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "description": "A fork of the prisma-trpc-generator code to work in ESM with Prisma v6.",
6
6
  "repository": {