@stryke/prisma-trpc-generator 0.7.5 → 0.8.0

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.
@@ -7334,6 +7334,28 @@ function resolvePaths(...paths) {
7334
7334
  return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
7335
7335
  }
7336
7336
  __name(resolvePaths, "resolvePaths");
7337
+ function relativePath(from, to) {
7338
+ const _from = resolvePath(from).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7339
+ const _to = resolvePath(to).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7340
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
7341
+ return _to.join("/");
7342
+ }
7343
+ const _fromCopy = [
7344
+ ..._from
7345
+ ];
7346
+ for (const segment of _fromCopy) {
7347
+ if (_to[0] !== segment) {
7348
+ break;
7349
+ }
7350
+ _from.shift();
7351
+ _to.shift();
7352
+ }
7353
+ return [
7354
+ ..._from.map(() => ".."),
7355
+ ..._to
7356
+ ].join("/");
7357
+ }
7358
+ __name(relativePath, "relativePath");
7337
7359
 
7338
7360
  // ../string-format/src/lower-case-first.ts
7339
7361
  init_cjs_shims();
@@ -7377,7 +7399,7 @@ var configSchema = z.object({
7377
7399
  withZod: z.coerce.boolean().or(z.string()).default(true),
7378
7400
  withNext: z.coerce.boolean().or(z.string()).default(true),
7379
7401
  contextPath: z.string().default("../src/trpc/context"),
7380
- trpcOptions: z.coerce.boolean().or(z.string()).optional(),
7402
+ trpcOptions: z.coerce.boolean().or(z.string()).default(true),
7381
7403
  showModelNameInProcedure: z.coerce.boolean().or(z.string()).default(true),
7382
7404
  generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
7383
7405
  return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
@@ -7589,7 +7611,7 @@ function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath,
7589
7611
  const schemaPathWithoutFileAndExtension = schemaPathSplit.slice(0, schemaPathSplit.length - 1).join(import_node_path3.default.posix.sep);
7590
7612
  toPath = import_node_path3.default.join(schemaPathWithoutFileAndExtension, filePath);
7591
7613
  }
7592
- const newPath = import_node_path3.default.relative(_fromPath, toPath).split(import_node_path3.default.sep).join(import_node_path3.default.posix.sep);
7614
+ const newPath = relativePath(_fromPath, toPath).split(import_node_path3.default.sep).join(import_node_path3.default.posix.sep);
7593
7615
  return newPath;
7594
7616
  }
7595
7617
  __name(getRelativePath, "getRelativePath");
@@ -7700,7 +7722,8 @@ async function generateBaseRouter(sourceFile, config, options) {
7700
7722
  sourceFile.addStatements(
7701
7723
  /* ts */
7702
7724
  `
7703
- export const permissionsMiddleware = t.middleware(permissions); `
7725
+ export const permissionsMiddleware = t.middleware(permissions);
7726
+ `
7704
7727
  );
7705
7728
  middlewares.push({
7706
7729
  type: "shield",
@@ -7725,14 +7748,6 @@ export const createCallerFactory = t.createCallerFactory;`
7725
7748
  `
7726
7749
  export const publicProcedure = t.procedure; `
7727
7750
  );
7728
- if (config.withNext) {
7729
- sourceFile.addStatements(
7730
- /* ts */
7731
- `
7732
- export const createAction = createTRPCServerActionHandler(t, createContext);
7733
- `
7734
- );
7735
- }
7736
7751
  if (middlewares.length > 0) {
7737
7752
  const procName = getProcedureName(config);
7738
7753
  middlewares.forEach((middleware, i) => {
@@ -7749,6 +7764,15 @@ export const createCallerFactory = t.createCallerFactory;`
7749
7764
  );
7750
7765
  });
7751
7766
  }
7767
+ if (config.withNext) {
7768
+ sourceFile.addStatements(
7769
+ /* ts */
7770
+ `
7771
+ export const createAction: ReturnType<typeof createTRPCServerActionHandler> =
7772
+ createTRPCServerActionHandler(t, createContext);
7773
+ `
7774
+ );
7775
+ }
7752
7776
  }
7753
7777
  __name(generateBaseRouter, "generateBaseRouter");
7754
7778
  function generateProcedure(sourceFile, name, typeName, modelName, opType, baseOpType, config) {
@@ -7902,7 +7926,7 @@ var getImports = /* @__PURE__ */ __name((type, newPath) => {
7902
7926
  if (type === "trpc") {
7903
7927
  statement = "import * as trpc from '@trpc/server';\n";
7904
7928
  } else if (type === "trpc-shield") {
7905
- statement = "import { shield, allow } from 'trpc-shield';\n";
7929
+ statement = "import { shield, allow } from '@stryke/trpc-next/shield';\n";
7906
7930
  } else if (type === "context") {
7907
7931
  statement = `import type { Context } from '${newPath}';
7908
7932
  `;
@@ -7926,7 +7950,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
7926
7950
  return wrapped;
7927
7951
  }, "wrapWithTrpcShieldCall");
7928
7952
  var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
7929
- return `export const permissions = ${shieldObjectText};`;
7953
+ return `export const permissions: ReturnType<typeof shield<Context>> = ${shieldObjectText};`;
7930
7954
  }, "wrapWithExport");
7931
7955
  var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, outputDir) => {
7932
7956
  if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
@@ -10302,11 +10326,11 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
10302
10326
  }, "writeFileSafely");
10303
10327
  var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
10304
10328
  const rows = Array.from(indexExports).map((filePath) => {
10305
- let relativePath = import_node_path4.default.relative(import_node_path4.default.dirname(indexPath), filePath);
10306
- if (relativePath.endsWith(".ts")) {
10307
- relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts"));
10329
+ let relativePath2 = import_node_path4.default.relative(import_node_path4.default.dirname(indexPath), filePath);
10330
+ if (relativePath2.endsWith(".ts")) {
10331
+ relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
10308
10332
  }
10309
- const normalized = correctPath(relativePath);
10333
+ const normalized = correctPath(relativePath2);
10310
10334
  return `export * from './${normalized}'`;
10311
10335
  });
10312
10336
  await writeFileSafely(indexPath, rows.join("\n"), false);
@@ -11610,21 +11634,49 @@ async function generate(options) {
11610
11634
  const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
11611
11635
  consoleLog("Generating tRPC options source file");
11612
11636
  await writeFileSafely(trpcOptionsOutputPath, `import { ZodError } from 'zod';${config.withNext ? '\nimport { transformer } from "@stryke/trpc-next/shared";' : ""}
11637
+ import type {
11638
+ DataTransformerOptions,
11639
+ RootConfig
11640
+ } from "@trpc/server/unstable-core-do-not-import";
11641
+ import type { Context } from "../context";
11613
11642
 
11614
- export default {${config.withNext ? "\n transformer," : ""}
11643
+ interface RuntimeConfigOptions<
11644
+ TContext extends object,
11645
+ TMeta extends object = object
11646
+ > extends Partial<
11647
+ Omit<
11648
+ RootConfig<{
11649
+ ctx: TContext;
11650
+ meta: TMeta;
11651
+ errorShape: any;
11652
+ transformer: any;
11653
+ }>,
11654
+ "$types" | "transformer"
11655
+ >
11656
+ > {
11657
+ /**
11658
+ * Use a data transformer
11659
+ * @see https://trpc.io/docs/v11/data-transformers
11660
+ */
11661
+ transformer?: DataTransformerOptions;
11662
+ }
11663
+
11664
+ const options: RuntimeConfigOptions<Context> = {${config.withNext ? "\n transformer," : ""}
11615
11665
  errorFormatter({ shape, error }) {
11616
11666
  return {
11617
11667
  ...shape,
11618
11668
  data: {
11619
11669
  ...shape.data,
11620
11670
  zodError:
11621
- error.code === 'BAD_REQUEST' && error.cause instanceof ZodError
11671
+ error.code === "BAD_REQUEST" && error.cause instanceof ZodError
11622
11672
  ? error.cause.flatten()
11623
- : null,
11624
- },
11673
+ : null
11674
+ }
11625
11675
  };
11626
- },
11676
+ }
11627
11677
  };
11678
+
11679
+ export default options;
11628
11680
  `);
11629
11681
  }
11630
11682
  resolveModelsComments(models, hiddenModels);
package/dist/generator.js CHANGED
@@ -7339,6 +7339,28 @@ function resolvePaths(...paths) {
7339
7339
  return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
7340
7340
  }
7341
7341
  __name(resolvePaths, "resolvePaths");
7342
+ function relativePath(from, to) {
7343
+ const _from = resolvePath(from).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7344
+ const _to = resolvePath(to).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7345
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
7346
+ return _to.join("/");
7347
+ }
7348
+ const _fromCopy = [
7349
+ ..._from
7350
+ ];
7351
+ for (const segment of _fromCopy) {
7352
+ if (_to[0] !== segment) {
7353
+ break;
7354
+ }
7355
+ _from.shift();
7356
+ _to.shift();
7357
+ }
7358
+ return [
7359
+ ..._from.map(() => ".."),
7360
+ ..._to
7361
+ ].join("/");
7362
+ }
7363
+ __name(relativePath, "relativePath");
7342
7364
 
7343
7365
  // ../string-format/src/lower-case-first.ts
7344
7366
  init_esm_shims();
@@ -7382,7 +7404,7 @@ var configSchema = z.object({
7382
7404
  withZod: z.coerce.boolean().or(z.string()).default(true),
7383
7405
  withNext: z.coerce.boolean().or(z.string()).default(true),
7384
7406
  contextPath: z.string().default("../src/trpc/context"),
7385
- trpcOptions: z.coerce.boolean().or(z.string()).optional(),
7407
+ trpcOptions: z.coerce.boolean().or(z.string()).default(true),
7386
7408
  showModelNameInProcedure: z.coerce.boolean().or(z.string()).default(true),
7387
7409
  generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
7388
7410
  return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
@@ -7594,7 +7616,7 @@ function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath,
7594
7616
  const schemaPathWithoutFileAndExtension = schemaPathSplit.slice(0, schemaPathSplit.length - 1).join(path2.posix.sep);
7595
7617
  toPath = path2.join(schemaPathWithoutFileAndExtension, filePath);
7596
7618
  }
7597
- const newPath = path2.relative(_fromPath, toPath).split(path2.sep).join(path2.posix.sep);
7619
+ const newPath = relativePath(_fromPath, toPath).split(path2.sep).join(path2.posix.sep);
7598
7620
  return newPath;
7599
7621
  }
7600
7622
  __name(getRelativePath, "getRelativePath");
@@ -7705,7 +7727,8 @@ async function generateBaseRouter(sourceFile, config, options) {
7705
7727
  sourceFile.addStatements(
7706
7728
  /* ts */
7707
7729
  `
7708
- export const permissionsMiddleware = t.middleware(permissions); `
7730
+ export const permissionsMiddleware = t.middleware(permissions);
7731
+ `
7709
7732
  );
7710
7733
  middlewares.push({
7711
7734
  type: "shield",
@@ -7730,14 +7753,6 @@ export const createCallerFactory = t.createCallerFactory;`
7730
7753
  `
7731
7754
  export const publicProcedure = t.procedure; `
7732
7755
  );
7733
- if (config.withNext) {
7734
- sourceFile.addStatements(
7735
- /* ts */
7736
- `
7737
- export const createAction = createTRPCServerActionHandler(t, createContext);
7738
- `
7739
- );
7740
- }
7741
7756
  if (middlewares.length > 0) {
7742
7757
  const procName = getProcedureName(config);
7743
7758
  middlewares.forEach((middleware, i) => {
@@ -7754,6 +7769,15 @@ export const createCallerFactory = t.createCallerFactory;`
7754
7769
  );
7755
7770
  });
7756
7771
  }
7772
+ if (config.withNext) {
7773
+ sourceFile.addStatements(
7774
+ /* ts */
7775
+ `
7776
+ export const createAction: ReturnType<typeof createTRPCServerActionHandler> =
7777
+ createTRPCServerActionHandler(t, createContext);
7778
+ `
7779
+ );
7780
+ }
7757
7781
  }
7758
7782
  __name(generateBaseRouter, "generateBaseRouter");
7759
7783
  function generateProcedure(sourceFile, name, typeName, modelName, opType, baseOpType, config) {
@@ -7907,7 +7931,7 @@ var getImports = /* @__PURE__ */ __name((type, newPath) => {
7907
7931
  if (type === "trpc") {
7908
7932
  statement = "import * as trpc from '@trpc/server';\n";
7909
7933
  } else if (type === "trpc-shield") {
7910
- statement = "import { shield, allow } from 'trpc-shield';\n";
7934
+ statement = "import { shield, allow } from '@stryke/trpc-next/shield';\n";
7911
7935
  } else if (type === "context") {
7912
7936
  statement = `import type { Context } from '${newPath}';
7913
7937
  `;
@@ -7931,7 +7955,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
7931
7955
  return wrapped;
7932
7956
  }, "wrapWithTrpcShieldCall");
7933
7957
  var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
7934
- return `export const permissions = ${shieldObjectText};`;
7958
+ return `export const permissions: ReturnType<typeof shield<Context>> = ${shieldObjectText};`;
7935
7959
  }, "wrapWithExport");
7936
7960
  var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, outputDir) => {
7937
7961
  if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
@@ -10307,11 +10331,11 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
10307
10331
  }, "writeFileSafely");
10308
10332
  var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
10309
10333
  const rows = Array.from(indexExports).map((filePath) => {
10310
- let relativePath = path3.relative(path3.dirname(indexPath), filePath);
10311
- if (relativePath.endsWith(".ts")) {
10312
- relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts"));
10334
+ let relativePath2 = path3.relative(path3.dirname(indexPath), filePath);
10335
+ if (relativePath2.endsWith(".ts")) {
10336
+ relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
10313
10337
  }
10314
- const normalized = correctPath(relativePath);
10338
+ const normalized = correctPath(relativePath2);
10315
10339
  return `export * from './${normalized}'`;
10316
10340
  });
10317
10341
  await writeFileSafely(indexPath, rows.join("\n"), false);
@@ -11615,21 +11639,49 @@ async function generate(options) {
11615
11639
  const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
11616
11640
  consoleLog("Generating tRPC options source file");
11617
11641
  await writeFileSafely(trpcOptionsOutputPath, `import { ZodError } from 'zod';${config.withNext ? '\nimport { transformer } from "@stryke/trpc-next/shared";' : ""}
11642
+ import type {
11643
+ DataTransformerOptions,
11644
+ RootConfig
11645
+ } from "@trpc/server/unstable-core-do-not-import";
11646
+ import type { Context } from "../context";
11618
11647
 
11619
- export default {${config.withNext ? "\n transformer," : ""}
11648
+ interface RuntimeConfigOptions<
11649
+ TContext extends object,
11650
+ TMeta extends object = object
11651
+ > extends Partial<
11652
+ Omit<
11653
+ RootConfig<{
11654
+ ctx: TContext;
11655
+ meta: TMeta;
11656
+ errorShape: any;
11657
+ transformer: any;
11658
+ }>,
11659
+ "$types" | "transformer"
11660
+ >
11661
+ > {
11662
+ /**
11663
+ * Use a data transformer
11664
+ * @see https://trpc.io/docs/v11/data-transformers
11665
+ */
11666
+ transformer?: DataTransformerOptions;
11667
+ }
11668
+
11669
+ const options: RuntimeConfigOptions<Context> = {${config.withNext ? "\n transformer," : ""}
11620
11670
  errorFormatter({ shape, error }) {
11621
11671
  return {
11622
11672
  ...shape,
11623
11673
  data: {
11624
11674
  ...shape.data,
11625
11675
  zodError:
11626
- error.code === 'BAD_REQUEST' && error.cause instanceof ZodError
11676
+ error.code === "BAD_REQUEST" && error.cause instanceof ZodError
11627
11677
  ? error.cause.flatten()
11628
- : null,
11629
- },
11678
+ : null
11679
+ }
11630
11680
  };
11631
- },
11681
+ }
11632
11682
  };
11683
+
11684
+ export default options;
11633
11685
  `);
11634
11686
  }
11635
11687
  resolveModelsComments(models, hiddenModels);
package/dist/index.cjs CHANGED
@@ -7330,6 +7330,28 @@ function resolvePaths(...paths) {
7330
7330
  return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
7331
7331
  }
7332
7332
  __name(resolvePaths, "resolvePaths");
7333
+ function relativePath(from, to) {
7334
+ const _from = resolvePath(from).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7335
+ const _to = resolvePath(to).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7336
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
7337
+ return _to.join("/");
7338
+ }
7339
+ const _fromCopy = [
7340
+ ..._from
7341
+ ];
7342
+ for (const segment of _fromCopy) {
7343
+ if (_to[0] !== segment) {
7344
+ break;
7345
+ }
7346
+ _from.shift();
7347
+ _to.shift();
7348
+ }
7349
+ return [
7350
+ ..._from.map(() => ".."),
7351
+ ..._to
7352
+ ].join("/");
7353
+ }
7354
+ __name(relativePath, "relativePath");
7333
7355
 
7334
7356
  // ../string-format/src/lower-case-first.ts
7335
7357
  init_cjs_shims();
@@ -7373,7 +7395,7 @@ var configSchema = z.object({
7373
7395
  withZod: z.coerce.boolean().or(z.string()).default(true),
7374
7396
  withNext: z.coerce.boolean().or(z.string()).default(true),
7375
7397
  contextPath: z.string().default("../src/trpc/context"),
7376
- trpcOptions: z.coerce.boolean().or(z.string()).optional(),
7398
+ trpcOptions: z.coerce.boolean().or(z.string()).default(true),
7377
7399
  showModelNameInProcedure: z.coerce.boolean().or(z.string()).default(true),
7378
7400
  generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
7379
7401
  return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
@@ -7585,7 +7607,7 @@ function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath,
7585
7607
  const schemaPathWithoutFileAndExtension = schemaPathSplit.slice(0, schemaPathSplit.length - 1).join(import_node_path3.default.posix.sep);
7586
7608
  toPath = import_node_path3.default.join(schemaPathWithoutFileAndExtension, filePath);
7587
7609
  }
7588
- const newPath = import_node_path3.default.relative(_fromPath, toPath).split(import_node_path3.default.sep).join(import_node_path3.default.posix.sep);
7610
+ const newPath = relativePath(_fromPath, toPath).split(import_node_path3.default.sep).join(import_node_path3.default.posix.sep);
7589
7611
  return newPath;
7590
7612
  }
7591
7613
  __name(getRelativePath, "getRelativePath");
@@ -7696,7 +7718,8 @@ async function generateBaseRouter(sourceFile, config, options) {
7696
7718
  sourceFile.addStatements(
7697
7719
  /* ts */
7698
7720
  `
7699
- export const permissionsMiddleware = t.middleware(permissions); `
7721
+ export const permissionsMiddleware = t.middleware(permissions);
7722
+ `
7700
7723
  );
7701
7724
  middlewares.push({
7702
7725
  type: "shield",
@@ -7721,14 +7744,6 @@ export const createCallerFactory = t.createCallerFactory;`
7721
7744
  `
7722
7745
  export const publicProcedure = t.procedure; `
7723
7746
  );
7724
- if (config.withNext) {
7725
- sourceFile.addStatements(
7726
- /* ts */
7727
- `
7728
- export const createAction = createTRPCServerActionHandler(t, createContext);
7729
- `
7730
- );
7731
- }
7732
7747
  if (middlewares.length > 0) {
7733
7748
  const procName = getProcedureName(config);
7734
7749
  middlewares.forEach((middleware, i) => {
@@ -7745,6 +7760,15 @@ export const createCallerFactory = t.createCallerFactory;`
7745
7760
  );
7746
7761
  });
7747
7762
  }
7763
+ if (config.withNext) {
7764
+ sourceFile.addStatements(
7765
+ /* ts */
7766
+ `
7767
+ export const createAction: ReturnType<typeof createTRPCServerActionHandler> =
7768
+ createTRPCServerActionHandler(t, createContext);
7769
+ `
7770
+ );
7771
+ }
7748
7772
  }
7749
7773
  __name(generateBaseRouter, "generateBaseRouter");
7750
7774
  function generateProcedure(sourceFile, name, typeName, modelName, opType, baseOpType, config) {
@@ -7898,7 +7922,7 @@ var getImports = /* @__PURE__ */ __name((type, newPath) => {
7898
7922
  if (type === "trpc") {
7899
7923
  statement = "import * as trpc from '@trpc/server';\n";
7900
7924
  } else if (type === "trpc-shield") {
7901
- statement = "import { shield, allow } from 'trpc-shield';\n";
7925
+ statement = "import { shield, allow } from '@stryke/trpc-next/shield';\n";
7902
7926
  } else if (type === "context") {
7903
7927
  statement = `import type { Context } from '${newPath}';
7904
7928
  `;
@@ -7922,7 +7946,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
7922
7946
  return wrapped;
7923
7947
  }, "wrapWithTrpcShieldCall");
7924
7948
  var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
7925
- return `export const permissions = ${shieldObjectText};`;
7949
+ return `export const permissions: ReturnType<typeof shield<Context>> = ${shieldObjectText};`;
7926
7950
  }, "wrapWithExport");
7927
7951
  var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, outputDir) => {
7928
7952
  if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
@@ -10298,11 +10322,11 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
10298
10322
  }, "writeFileSafely");
10299
10323
  var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
10300
10324
  const rows = Array.from(indexExports).map((filePath) => {
10301
- let relativePath = import_node_path4.default.relative(import_node_path4.default.dirname(indexPath), filePath);
10302
- if (relativePath.endsWith(".ts")) {
10303
- relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts"));
10325
+ let relativePath2 = import_node_path4.default.relative(import_node_path4.default.dirname(indexPath), filePath);
10326
+ if (relativePath2.endsWith(".ts")) {
10327
+ relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
10304
10328
  }
10305
- const normalized = correctPath(relativePath);
10329
+ const normalized = correctPath(relativePath2);
10306
10330
  return `export * from './${normalized}'`;
10307
10331
  });
10308
10332
  await writeFileSafely(indexPath, rows.join("\n"), false);
@@ -11606,21 +11630,49 @@ async function generate(options) {
11606
11630
  const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
11607
11631
  consoleLog("Generating tRPC options source file");
11608
11632
  await writeFileSafely(trpcOptionsOutputPath, `import { ZodError } from 'zod';${config.withNext ? '\nimport { transformer } from "@stryke/trpc-next/shared";' : ""}
11633
+ import type {
11634
+ DataTransformerOptions,
11635
+ RootConfig
11636
+ } from "@trpc/server/unstable-core-do-not-import";
11637
+ import type { Context } from "../context";
11609
11638
 
11610
- export default {${config.withNext ? "\n transformer," : ""}
11639
+ interface RuntimeConfigOptions<
11640
+ TContext extends object,
11641
+ TMeta extends object = object
11642
+ > extends Partial<
11643
+ Omit<
11644
+ RootConfig<{
11645
+ ctx: TContext;
11646
+ meta: TMeta;
11647
+ errorShape: any;
11648
+ transformer: any;
11649
+ }>,
11650
+ "$types" | "transformer"
11651
+ >
11652
+ > {
11653
+ /**
11654
+ * Use a data transformer
11655
+ * @see https://trpc.io/docs/v11/data-transformers
11656
+ */
11657
+ transformer?: DataTransformerOptions;
11658
+ }
11659
+
11660
+ const options: RuntimeConfigOptions<Context> = {${config.withNext ? "\n transformer," : ""}
11611
11661
  errorFormatter({ shape, error }) {
11612
11662
  return {
11613
11663
  ...shape,
11614
11664
  data: {
11615
11665
  ...shape.data,
11616
11666
  zodError:
11617
- error.code === 'BAD_REQUEST' && error.cause instanceof ZodError
11667
+ error.code === "BAD_REQUEST" && error.cause instanceof ZodError
11618
11668
  ? error.cause.flatten()
11619
- : null,
11620
- },
11669
+ : null
11670
+ }
11621
11671
  };
11622
- },
11672
+ }
11623
11673
  };
11674
+
11675
+ export default options;
11624
11676
  `);
11625
11677
  }
11626
11678
  resolveModelsComments(models, hiddenModels);
package/dist/index.js CHANGED
@@ -7335,6 +7335,28 @@ function resolvePaths(...paths) {
7335
7335
  return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
7336
7336
  }
7337
7337
  __name(resolvePaths, "resolvePaths");
7338
+ function relativePath(from, to) {
7339
+ const _from = resolvePath(from).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7340
+ const _to = resolvePath(to).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
7341
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
7342
+ return _to.join("/");
7343
+ }
7344
+ const _fromCopy = [
7345
+ ..._from
7346
+ ];
7347
+ for (const segment of _fromCopy) {
7348
+ if (_to[0] !== segment) {
7349
+ break;
7350
+ }
7351
+ _from.shift();
7352
+ _to.shift();
7353
+ }
7354
+ return [
7355
+ ..._from.map(() => ".."),
7356
+ ..._to
7357
+ ].join("/");
7358
+ }
7359
+ __name(relativePath, "relativePath");
7338
7360
 
7339
7361
  // ../string-format/src/lower-case-first.ts
7340
7362
  init_esm_shims();
@@ -7378,7 +7400,7 @@ var configSchema = z.object({
7378
7400
  withZod: z.coerce.boolean().or(z.string()).default(true),
7379
7401
  withNext: z.coerce.boolean().or(z.string()).default(true),
7380
7402
  contextPath: z.string().default("../src/trpc/context"),
7381
- trpcOptions: z.coerce.boolean().or(z.string()).optional(),
7403
+ trpcOptions: z.coerce.boolean().or(z.string()).default(true),
7382
7404
  showModelNameInProcedure: z.coerce.boolean().or(z.string()).default(true),
7383
7405
  generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
7384
7406
  return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
@@ -7590,7 +7612,7 @@ function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath,
7590
7612
  const schemaPathWithoutFileAndExtension = schemaPathSplit.slice(0, schemaPathSplit.length - 1).join(path2.posix.sep);
7591
7613
  toPath = path2.join(schemaPathWithoutFileAndExtension, filePath);
7592
7614
  }
7593
- const newPath = path2.relative(_fromPath, toPath).split(path2.sep).join(path2.posix.sep);
7615
+ const newPath = relativePath(_fromPath, toPath).split(path2.sep).join(path2.posix.sep);
7594
7616
  return newPath;
7595
7617
  }
7596
7618
  __name(getRelativePath, "getRelativePath");
@@ -7701,7 +7723,8 @@ async function generateBaseRouter(sourceFile, config, options) {
7701
7723
  sourceFile.addStatements(
7702
7724
  /* ts */
7703
7725
  `
7704
- export const permissionsMiddleware = t.middleware(permissions); `
7726
+ export const permissionsMiddleware = t.middleware(permissions);
7727
+ `
7705
7728
  );
7706
7729
  middlewares.push({
7707
7730
  type: "shield",
@@ -7726,14 +7749,6 @@ export const createCallerFactory = t.createCallerFactory;`
7726
7749
  `
7727
7750
  export const publicProcedure = t.procedure; `
7728
7751
  );
7729
- if (config.withNext) {
7730
- sourceFile.addStatements(
7731
- /* ts */
7732
- `
7733
- export const createAction = createTRPCServerActionHandler(t, createContext);
7734
- `
7735
- );
7736
- }
7737
7752
  if (middlewares.length > 0) {
7738
7753
  const procName = getProcedureName(config);
7739
7754
  middlewares.forEach((middleware, i) => {
@@ -7750,6 +7765,15 @@ export const createCallerFactory = t.createCallerFactory;`
7750
7765
  );
7751
7766
  });
7752
7767
  }
7768
+ if (config.withNext) {
7769
+ sourceFile.addStatements(
7770
+ /* ts */
7771
+ `
7772
+ export const createAction: ReturnType<typeof createTRPCServerActionHandler> =
7773
+ createTRPCServerActionHandler(t, createContext);
7774
+ `
7775
+ );
7776
+ }
7753
7777
  }
7754
7778
  __name(generateBaseRouter, "generateBaseRouter");
7755
7779
  function generateProcedure(sourceFile, name, typeName, modelName, opType, baseOpType, config) {
@@ -7903,7 +7927,7 @@ var getImports = /* @__PURE__ */ __name((type, newPath) => {
7903
7927
  if (type === "trpc") {
7904
7928
  statement = "import * as trpc from '@trpc/server';\n";
7905
7929
  } else if (type === "trpc-shield") {
7906
- statement = "import { shield, allow } from 'trpc-shield';\n";
7930
+ statement = "import { shield, allow } from '@stryke/trpc-next/shield';\n";
7907
7931
  } else if (type === "context") {
7908
7932
  statement = `import type { Context } from '${newPath}';
7909
7933
  `;
@@ -7927,7 +7951,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
7927
7951
  return wrapped;
7928
7952
  }, "wrapWithTrpcShieldCall");
7929
7953
  var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
7930
- return `export const permissions = ${shieldObjectText};`;
7954
+ return `export const permissions: ReturnType<typeof shield<Context>> = ${shieldObjectText};`;
7931
7955
  }, "wrapWithExport");
7932
7956
  var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, outputDir) => {
7933
7957
  if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
@@ -10303,11 +10327,11 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
10303
10327
  }, "writeFileSafely");
10304
10328
  var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
10305
10329
  const rows = Array.from(indexExports).map((filePath) => {
10306
- let relativePath = path3.relative(path3.dirname(indexPath), filePath);
10307
- if (relativePath.endsWith(".ts")) {
10308
- relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts"));
10330
+ let relativePath2 = path3.relative(path3.dirname(indexPath), filePath);
10331
+ if (relativePath2.endsWith(".ts")) {
10332
+ relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
10309
10333
  }
10310
- const normalized = correctPath(relativePath);
10334
+ const normalized = correctPath(relativePath2);
10311
10335
  return `export * from './${normalized}'`;
10312
10336
  });
10313
10337
  await writeFileSafely(indexPath, rows.join("\n"), false);
@@ -11611,21 +11635,49 @@ async function generate(options) {
11611
11635
  const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
11612
11636
  consoleLog("Generating tRPC options source file");
11613
11637
  await writeFileSafely(trpcOptionsOutputPath, `import { ZodError } from 'zod';${config.withNext ? '\nimport { transformer } from "@stryke/trpc-next/shared";' : ""}
11638
+ import type {
11639
+ DataTransformerOptions,
11640
+ RootConfig
11641
+ } from "@trpc/server/unstable-core-do-not-import";
11642
+ import type { Context } from "../context";
11614
11643
 
11615
- export default {${config.withNext ? "\n transformer," : ""}
11644
+ interface RuntimeConfigOptions<
11645
+ TContext extends object,
11646
+ TMeta extends object = object
11647
+ > extends Partial<
11648
+ Omit<
11649
+ RootConfig<{
11650
+ ctx: TContext;
11651
+ meta: TMeta;
11652
+ errorShape: any;
11653
+ transformer: any;
11654
+ }>,
11655
+ "$types" | "transformer"
11656
+ >
11657
+ > {
11658
+ /**
11659
+ * Use a data transformer
11660
+ * @see https://trpc.io/docs/v11/data-transformers
11661
+ */
11662
+ transformer?: DataTransformerOptions;
11663
+ }
11664
+
11665
+ const options: RuntimeConfigOptions<Context> = {${config.withNext ? "\n transformer," : ""}
11616
11666
  errorFormatter({ shape, error }) {
11617
11667
  return {
11618
11668
  ...shape,
11619
11669
  data: {
11620
11670
  ...shape.data,
11621
11671
  zodError:
11622
- error.code === 'BAD_REQUEST' && error.cause instanceof ZodError
11672
+ error.code === "BAD_REQUEST" && error.cause instanceof ZodError
11623
11673
  ? error.cause.flatten()
11624
- : null,
11625
- },
11674
+ : null
11675
+ }
11626
11676
  };
11627
- },
11677
+ }
11628
11678
  };
11679
+
11680
+ export default options;
11629
11681
  `);
11630
11682
  }
11631
11683
  resolveModelsComments(models, hiddenModels);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/prisma-trpc-generator",
3
- "version": "0.7.5",
3
+ "version": "0.8.0",
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": {