@stryke/prisma-trpc-generator 0.7.2 → 0.7.4
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/generator.cjs +30 -54
- package/dist/generator.js +30 -54
- package/dist/index.cjs +30 -54
- package/dist/index.js +30 -54
- package/package.json +1 -1
package/dist/generator.cjs
CHANGED
|
@@ -7303,6 +7303,14 @@ function findFilePath(filePath) {
|
|
|
7303
7303
|
}), "");
|
|
7304
7304
|
}
|
|
7305
7305
|
__name(findFilePath, "findFilePath");
|
|
7306
|
+
function findFileExtension(filePath) {
|
|
7307
|
+
if (filePath === "..") {
|
|
7308
|
+
return "";
|
|
7309
|
+
}
|
|
7310
|
+
const match = /.(\.[^./]+|\.)$/.exec(normalizeWindowsPath2(filePath));
|
|
7311
|
+
return match && match[1] || EMPTY_STRING;
|
|
7312
|
+
}
|
|
7313
|
+
__name(findFileExtension, "findFileExtension");
|
|
7306
7314
|
function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
|
|
7307
7315
|
const paths = normalizeWindowsPath2(path6).split("/");
|
|
7308
7316
|
let resolvedPath = "";
|
|
@@ -7326,28 +7334,6 @@ function resolvePaths(...paths) {
|
|
|
7326
7334
|
return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
|
|
7327
7335
|
}
|
|
7328
7336
|
__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
7337
|
|
|
7352
7338
|
// ../string-format/src/lower-case-first.ts
|
|
7353
7339
|
init_cjs_shims();
|
|
@@ -7383,24 +7369,16 @@ var ModelAction = /* @__PURE__ */ function(ModelAction2) {
|
|
|
7383
7369
|
ModelAction2["aggregateRaw"] = "aggregateRaw";
|
|
7384
7370
|
return ModelAction2;
|
|
7385
7371
|
}(ModelAction || {});
|
|
7386
|
-
var configBoolean = z.enum([
|
|
7387
|
-
"true",
|
|
7388
|
-
"false"
|
|
7389
|
-
]).transform((arg) => JSON.parse(arg));
|
|
7390
|
-
var configMiddleware = z.union([
|
|
7391
|
-
configBoolean,
|
|
7392
|
-
z.string().default("../src/trpc/middleware")
|
|
7393
|
-
]);
|
|
7394
7372
|
var modelActionEnum = z.nativeEnum(ModelAction);
|
|
7395
7373
|
var configSchema = z.object({
|
|
7396
|
-
debug:
|
|
7397
|
-
withMiddleware:
|
|
7398
|
-
withShield: z.boolean().or(z.string()).default(
|
|
7399
|
-
withZod:
|
|
7400
|
-
withNext:
|
|
7374
|
+
debug: z.boolean().or(z.string()).default(false),
|
|
7375
|
+
withMiddleware: z.boolean().or(z.string()).default(false),
|
|
7376
|
+
withShield: z.boolean().or(z.string()).default(true),
|
|
7377
|
+
withZod: z.boolean().default(true),
|
|
7378
|
+
withNext: z.boolean().default(true),
|
|
7401
7379
|
contextPath: z.string().default("../src/trpc/context"),
|
|
7402
|
-
trpcOptions: z.boolean().or(z.string()).
|
|
7403
|
-
showModelNameInProcedure:
|
|
7380
|
+
trpcOptions: z.boolean().or(z.string()).default(true),
|
|
7381
|
+
showModelNameInProcedure: z.boolean().default(true),
|
|
7404
7382
|
generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
|
|
7405
7383
|
return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
|
|
7406
7384
|
})
|
|
@@ -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
|
|
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(
|
|
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");
|
|
@@ -7632,9 +7610,7 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7632
7610
|
namedImports: imports
|
|
7633
7611
|
});
|
|
7634
7612
|
}, "generateCreateRouterImport");
|
|
7635
|
-
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, value) => {
|
|
7636
|
-
const internals = await getPrismaInternals();
|
|
7637
|
-
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
7613
|
+
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, outputDir, value) => {
|
|
7638
7614
|
let shieldPath = joinPaths(outputDir, "shield");
|
|
7639
7615
|
if (typeof value === "string") {
|
|
7640
7616
|
shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
|
|
@@ -7952,7 +7928,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
|
|
|
7952
7928
|
var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
|
|
7953
7929
|
return `export const permissions = ${shieldObjectText};`;
|
|
7954
7930
|
}, "wrapWithExport");
|
|
7955
|
-
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options,
|
|
7931
|
+
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, outputDir) => {
|
|
7956
7932
|
if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
|
|
7957
7933
|
return "";
|
|
7958
7934
|
}
|
|
@@ -7979,7 +7955,7 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
|
|
|
7979
7955
|
return "";
|
|
7980
7956
|
}
|
|
7981
7957
|
let shieldText = getImports("trpc-shield");
|
|
7982
|
-
shieldText += getImports("context",
|
|
7958
|
+
shieldText += getImports("context", getRelativePath(outputDir, config.contextPath, true, options.schemaPath));
|
|
7983
7959
|
shieldText += "\n\n";
|
|
7984
7960
|
shieldText += wrapWithExport({
|
|
7985
7961
|
shieldObjectText: wrapWithTrpcShieldCall({
|
|
@@ -10326,11 +10302,11 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
|
|
|
10326
10302
|
}, "writeFileSafely");
|
|
10327
10303
|
var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
|
|
10328
10304
|
const rows = Array.from(indexExports).map((filePath) => {
|
|
10329
|
-
let
|
|
10330
|
-
if (
|
|
10331
|
-
|
|
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"));
|
|
10332
10308
|
}
|
|
10333
|
-
const normalized = correctPath(
|
|
10309
|
+
const normalized = correctPath(relativePath);
|
|
10334
10310
|
return `export * from './${normalized}'`;
|
|
10335
10311
|
});
|
|
10336
10312
|
await writeFileSafely(indexPath, rows.join("\n"), false);
|
|
@@ -11617,7 +11593,7 @@ async function generate(options) {
|
|
|
11617
11593
|
consoleLog("Skipping tRPC Shield generation as path provided already exists");
|
|
11618
11594
|
} else {
|
|
11619
11595
|
consoleLog("Constructing tRPC Shield source file");
|
|
11620
|
-
const shieldOutputDir = typeof config.withShield === "string" ? findFilePath(config.withShield) : outputDir;
|
|
11596
|
+
const shieldOutputDir = typeof config.withShield === "string" ? findFileExtension(config.withShield) ? findFilePath(config.withShield) : config.withShield : outputDir;
|
|
11621
11597
|
const shieldText = await constructShield({
|
|
11622
11598
|
queries,
|
|
11623
11599
|
mutations,
|
|
@@ -11652,16 +11628,16 @@ export default {${config.withNext ? "\n transformer," : ""}
|
|
|
11652
11628
|
`);
|
|
11653
11629
|
}
|
|
11654
11630
|
resolveModelsComments(models, hiddenModels);
|
|
11655
|
-
const
|
|
11631
|
+
const trpcExports = project.createSourceFile(import_node_path6.default.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11656
11632
|
overwrite: true
|
|
11657
11633
|
});
|
|
11658
11634
|
consoleLog("Generating tRPC imports");
|
|
11659
11635
|
if (config.withShield) {
|
|
11660
|
-
await generateShieldImport(
|
|
11636
|
+
await generateShieldImport(trpcExports, options, outputDir, config.withShield);
|
|
11661
11637
|
}
|
|
11662
11638
|
consoleLog("Generating tRPC base router");
|
|
11663
|
-
await generateBaseRouter(
|
|
11664
|
-
|
|
11639
|
+
await generateBaseRouter(trpcExports, config, options);
|
|
11640
|
+
trpcExports.formatText({
|
|
11665
11641
|
indentSize: 2
|
|
11666
11642
|
});
|
|
11667
11643
|
const appRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "routers", `index.ts`), void 0, {
|
package/dist/generator.js
CHANGED
|
@@ -7308,6 +7308,14 @@ function findFilePath(filePath) {
|
|
|
7308
7308
|
}), "");
|
|
7309
7309
|
}
|
|
7310
7310
|
__name(findFilePath, "findFilePath");
|
|
7311
|
+
function findFileExtension(filePath) {
|
|
7312
|
+
if (filePath === "..") {
|
|
7313
|
+
return "";
|
|
7314
|
+
}
|
|
7315
|
+
const match = /.(\.[^./]+|\.)$/.exec(normalizeWindowsPath2(filePath));
|
|
7316
|
+
return match && match[1] || EMPTY_STRING;
|
|
7317
|
+
}
|
|
7318
|
+
__name(findFileExtension, "findFileExtension");
|
|
7311
7319
|
function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
|
|
7312
7320
|
const paths = normalizeWindowsPath2(path6).split("/");
|
|
7313
7321
|
let resolvedPath = "";
|
|
@@ -7331,28 +7339,6 @@ function resolvePaths(...paths) {
|
|
|
7331
7339
|
return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
|
|
7332
7340
|
}
|
|
7333
7341
|
__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
7342
|
|
|
7357
7343
|
// ../string-format/src/lower-case-first.ts
|
|
7358
7344
|
init_esm_shims();
|
|
@@ -7388,24 +7374,16 @@ var ModelAction = /* @__PURE__ */ function(ModelAction2) {
|
|
|
7388
7374
|
ModelAction2["aggregateRaw"] = "aggregateRaw";
|
|
7389
7375
|
return ModelAction2;
|
|
7390
7376
|
}(ModelAction || {});
|
|
7391
|
-
var configBoolean = z.enum([
|
|
7392
|
-
"true",
|
|
7393
|
-
"false"
|
|
7394
|
-
]).transform((arg) => JSON.parse(arg));
|
|
7395
|
-
var configMiddleware = z.union([
|
|
7396
|
-
configBoolean,
|
|
7397
|
-
z.string().default("../src/trpc/middleware")
|
|
7398
|
-
]);
|
|
7399
7377
|
var modelActionEnum = z.nativeEnum(ModelAction);
|
|
7400
7378
|
var configSchema = z.object({
|
|
7401
|
-
debug:
|
|
7402
|
-
withMiddleware:
|
|
7403
|
-
withShield: z.boolean().or(z.string()).default(
|
|
7404
|
-
withZod:
|
|
7405
|
-
withNext:
|
|
7379
|
+
debug: z.boolean().or(z.string()).default(false),
|
|
7380
|
+
withMiddleware: z.boolean().or(z.string()).default(false),
|
|
7381
|
+
withShield: z.boolean().or(z.string()).default(true),
|
|
7382
|
+
withZod: z.boolean().default(true),
|
|
7383
|
+
withNext: z.boolean().default(true),
|
|
7406
7384
|
contextPath: z.string().default("../src/trpc/context"),
|
|
7407
|
-
trpcOptions: z.boolean().or(z.string()).
|
|
7408
|
-
showModelNameInProcedure:
|
|
7385
|
+
trpcOptions: z.boolean().or(z.string()).default(true),
|
|
7386
|
+
showModelNameInProcedure: z.boolean().default(true),
|
|
7409
7387
|
generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
|
|
7410
7388
|
return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
|
|
7411
7389
|
})
|
|
@@ -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
|
|
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(
|
|
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");
|
|
@@ -7637,9 +7615,7 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7637
7615
|
namedImports: imports
|
|
7638
7616
|
});
|
|
7639
7617
|
}, "generateCreateRouterImport");
|
|
7640
|
-
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, value) => {
|
|
7641
|
-
const internals = await getPrismaInternals();
|
|
7642
|
-
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
7618
|
+
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, outputDir, value) => {
|
|
7643
7619
|
let shieldPath = joinPaths(outputDir, "shield");
|
|
7644
7620
|
if (typeof value === "string") {
|
|
7645
7621
|
shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
|
|
@@ -7957,7 +7933,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
|
|
|
7957
7933
|
var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
|
|
7958
7934
|
return `export const permissions = ${shieldObjectText};`;
|
|
7959
7935
|
}, "wrapWithExport");
|
|
7960
|
-
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options,
|
|
7936
|
+
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, outputDir) => {
|
|
7961
7937
|
if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
|
|
7962
7938
|
return "";
|
|
7963
7939
|
}
|
|
@@ -7984,7 +7960,7 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
|
|
|
7984
7960
|
return "";
|
|
7985
7961
|
}
|
|
7986
7962
|
let shieldText = getImports("trpc-shield");
|
|
7987
|
-
shieldText += getImports("context",
|
|
7963
|
+
shieldText += getImports("context", getRelativePath(outputDir, config.contextPath, true, options.schemaPath));
|
|
7988
7964
|
shieldText += "\n\n";
|
|
7989
7965
|
shieldText += wrapWithExport({
|
|
7990
7966
|
shieldObjectText: wrapWithTrpcShieldCall({
|
|
@@ -10331,11 +10307,11 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
|
|
|
10331
10307
|
}, "writeFileSafely");
|
|
10332
10308
|
var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
|
|
10333
10309
|
const rows = Array.from(indexExports).map((filePath) => {
|
|
10334
|
-
let
|
|
10335
|
-
if (
|
|
10336
|
-
|
|
10310
|
+
let relativePath = path3.relative(path3.dirname(indexPath), filePath);
|
|
10311
|
+
if (relativePath.endsWith(".ts")) {
|
|
10312
|
+
relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts"));
|
|
10337
10313
|
}
|
|
10338
|
-
const normalized = correctPath(
|
|
10314
|
+
const normalized = correctPath(relativePath);
|
|
10339
10315
|
return `export * from './${normalized}'`;
|
|
10340
10316
|
});
|
|
10341
10317
|
await writeFileSafely(indexPath, rows.join("\n"), false);
|
|
@@ -11622,7 +11598,7 @@ async function generate(options) {
|
|
|
11622
11598
|
consoleLog("Skipping tRPC Shield generation as path provided already exists");
|
|
11623
11599
|
} else {
|
|
11624
11600
|
consoleLog("Constructing tRPC Shield source file");
|
|
11625
|
-
const shieldOutputDir = typeof config.withShield === "string" ? findFilePath(config.withShield) : outputDir;
|
|
11601
|
+
const shieldOutputDir = typeof config.withShield === "string" ? findFileExtension(config.withShield) ? findFilePath(config.withShield) : config.withShield : outputDir;
|
|
11626
11602
|
const shieldText = await constructShield({
|
|
11627
11603
|
queries,
|
|
11628
11604
|
mutations,
|
|
@@ -11657,16 +11633,16 @@ export default {${config.withNext ? "\n transformer," : ""}
|
|
|
11657
11633
|
`);
|
|
11658
11634
|
}
|
|
11659
11635
|
resolveModelsComments(models, hiddenModels);
|
|
11660
|
-
const
|
|
11636
|
+
const trpcExports = project.createSourceFile(path5.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11661
11637
|
overwrite: true
|
|
11662
11638
|
});
|
|
11663
11639
|
consoleLog("Generating tRPC imports");
|
|
11664
11640
|
if (config.withShield) {
|
|
11665
|
-
await generateShieldImport(
|
|
11641
|
+
await generateShieldImport(trpcExports, options, outputDir, config.withShield);
|
|
11666
11642
|
}
|
|
11667
11643
|
consoleLog("Generating tRPC base router");
|
|
11668
|
-
await generateBaseRouter(
|
|
11669
|
-
|
|
11644
|
+
await generateBaseRouter(trpcExports, config, options);
|
|
11645
|
+
trpcExports.formatText({
|
|
11670
11646
|
indentSize: 2
|
|
11671
11647
|
});
|
|
11672
11648
|
const appRouter = project.createSourceFile(path5.resolve(outputDir, "routers", `index.ts`), void 0, {
|
package/dist/index.cjs
CHANGED
|
@@ -7299,6 +7299,14 @@ function findFilePath(filePath) {
|
|
|
7299
7299
|
}), "");
|
|
7300
7300
|
}
|
|
7301
7301
|
__name(findFilePath, "findFilePath");
|
|
7302
|
+
function findFileExtension(filePath) {
|
|
7303
|
+
if (filePath === "..") {
|
|
7304
|
+
return "";
|
|
7305
|
+
}
|
|
7306
|
+
const match = /.(\.[^./]+|\.)$/.exec(normalizeWindowsPath2(filePath));
|
|
7307
|
+
return match && match[1] || EMPTY_STRING;
|
|
7308
|
+
}
|
|
7309
|
+
__name(findFileExtension, "findFileExtension");
|
|
7302
7310
|
function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
|
|
7303
7311
|
const paths = normalizeWindowsPath2(path6).split("/");
|
|
7304
7312
|
let resolvedPath = "";
|
|
@@ -7322,28 +7330,6 @@ function resolvePaths(...paths) {
|
|
|
7322
7330
|
return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
|
|
7323
7331
|
}
|
|
7324
7332
|
__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
7333
|
|
|
7348
7334
|
// ../string-format/src/lower-case-first.ts
|
|
7349
7335
|
init_cjs_shims();
|
|
@@ -7379,24 +7365,16 @@ var ModelAction = /* @__PURE__ */ function(ModelAction2) {
|
|
|
7379
7365
|
ModelAction2["aggregateRaw"] = "aggregateRaw";
|
|
7380
7366
|
return ModelAction2;
|
|
7381
7367
|
}(ModelAction || {});
|
|
7382
|
-
var configBoolean = z.enum([
|
|
7383
|
-
"true",
|
|
7384
|
-
"false"
|
|
7385
|
-
]).transform((arg) => JSON.parse(arg));
|
|
7386
|
-
var configMiddleware = z.union([
|
|
7387
|
-
configBoolean,
|
|
7388
|
-
z.string().default("../src/trpc/middleware")
|
|
7389
|
-
]);
|
|
7390
7368
|
var modelActionEnum = z.nativeEnum(ModelAction);
|
|
7391
7369
|
var configSchema = z.object({
|
|
7392
|
-
debug:
|
|
7393
|
-
withMiddleware:
|
|
7394
|
-
withShield: z.boolean().or(z.string()).default(
|
|
7395
|
-
withZod:
|
|
7396
|
-
withNext:
|
|
7370
|
+
debug: z.boolean().or(z.string()).default(false),
|
|
7371
|
+
withMiddleware: z.boolean().or(z.string()).default(false),
|
|
7372
|
+
withShield: z.boolean().or(z.string()).default(true),
|
|
7373
|
+
withZod: z.boolean().default(true),
|
|
7374
|
+
withNext: z.boolean().default(true),
|
|
7397
7375
|
contextPath: z.string().default("../src/trpc/context"),
|
|
7398
|
-
trpcOptions: z.boolean().or(z.string()).
|
|
7399
|
-
showModelNameInProcedure:
|
|
7376
|
+
trpcOptions: z.boolean().or(z.string()).default(true),
|
|
7377
|
+
showModelNameInProcedure: z.boolean().default(true),
|
|
7400
7378
|
generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
|
|
7401
7379
|
return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
|
|
7402
7380
|
})
|
|
@@ -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
|
|
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(
|
|
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");
|
|
@@ -7628,9 +7606,7 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7628
7606
|
namedImports: imports
|
|
7629
7607
|
});
|
|
7630
7608
|
}, "generateCreateRouterImport");
|
|
7631
|
-
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, value) => {
|
|
7632
|
-
const internals = await getPrismaInternals();
|
|
7633
|
-
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
7609
|
+
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, outputDir, value) => {
|
|
7634
7610
|
let shieldPath = joinPaths(outputDir, "shield");
|
|
7635
7611
|
if (typeof value === "string") {
|
|
7636
7612
|
shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
|
|
@@ -7948,7 +7924,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
|
|
|
7948
7924
|
var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
|
|
7949
7925
|
return `export const permissions = ${shieldObjectText};`;
|
|
7950
7926
|
}, "wrapWithExport");
|
|
7951
|
-
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options,
|
|
7927
|
+
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, outputDir) => {
|
|
7952
7928
|
if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
|
|
7953
7929
|
return "";
|
|
7954
7930
|
}
|
|
@@ -7975,7 +7951,7 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
|
|
|
7975
7951
|
return "";
|
|
7976
7952
|
}
|
|
7977
7953
|
let shieldText = getImports("trpc-shield");
|
|
7978
|
-
shieldText += getImports("context",
|
|
7954
|
+
shieldText += getImports("context", getRelativePath(outputDir, config.contextPath, true, options.schemaPath));
|
|
7979
7955
|
shieldText += "\n\n";
|
|
7980
7956
|
shieldText += wrapWithExport({
|
|
7981
7957
|
shieldObjectText: wrapWithTrpcShieldCall({
|
|
@@ -10322,11 +10298,11 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
|
|
|
10322
10298
|
}, "writeFileSafely");
|
|
10323
10299
|
var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
|
|
10324
10300
|
const rows = Array.from(indexExports).map((filePath) => {
|
|
10325
|
-
let
|
|
10326
|
-
if (
|
|
10327
|
-
|
|
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"));
|
|
10328
10304
|
}
|
|
10329
|
-
const normalized = correctPath(
|
|
10305
|
+
const normalized = correctPath(relativePath);
|
|
10330
10306
|
return `export * from './${normalized}'`;
|
|
10331
10307
|
});
|
|
10332
10308
|
await writeFileSafely(indexPath, rows.join("\n"), false);
|
|
@@ -11613,7 +11589,7 @@ async function generate(options) {
|
|
|
11613
11589
|
consoleLog("Skipping tRPC Shield generation as path provided already exists");
|
|
11614
11590
|
} else {
|
|
11615
11591
|
consoleLog("Constructing tRPC Shield source file");
|
|
11616
|
-
const shieldOutputDir = typeof config.withShield === "string" ? findFilePath(config.withShield) : outputDir;
|
|
11592
|
+
const shieldOutputDir = typeof config.withShield === "string" ? findFileExtension(config.withShield) ? findFilePath(config.withShield) : config.withShield : outputDir;
|
|
11617
11593
|
const shieldText = await constructShield({
|
|
11618
11594
|
queries,
|
|
11619
11595
|
mutations,
|
|
@@ -11648,16 +11624,16 @@ export default {${config.withNext ? "\n transformer," : ""}
|
|
|
11648
11624
|
`);
|
|
11649
11625
|
}
|
|
11650
11626
|
resolveModelsComments(models, hiddenModels);
|
|
11651
|
-
const
|
|
11627
|
+
const trpcExports = project.createSourceFile(import_node_path6.default.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11652
11628
|
overwrite: true
|
|
11653
11629
|
});
|
|
11654
11630
|
consoleLog("Generating tRPC imports");
|
|
11655
11631
|
if (config.withShield) {
|
|
11656
|
-
await generateShieldImport(
|
|
11632
|
+
await generateShieldImport(trpcExports, options, outputDir, config.withShield);
|
|
11657
11633
|
}
|
|
11658
11634
|
consoleLog("Generating tRPC base router");
|
|
11659
|
-
await generateBaseRouter(
|
|
11660
|
-
|
|
11635
|
+
await generateBaseRouter(trpcExports, config, options);
|
|
11636
|
+
trpcExports.formatText({
|
|
11661
11637
|
indentSize: 2
|
|
11662
11638
|
});
|
|
11663
11639
|
const appRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "routers", `index.ts`), void 0, {
|
package/dist/index.js
CHANGED
|
@@ -7304,6 +7304,14 @@ function findFilePath(filePath) {
|
|
|
7304
7304
|
}), "");
|
|
7305
7305
|
}
|
|
7306
7306
|
__name(findFilePath, "findFilePath");
|
|
7307
|
+
function findFileExtension(filePath) {
|
|
7308
|
+
if (filePath === "..") {
|
|
7309
|
+
return "";
|
|
7310
|
+
}
|
|
7311
|
+
const match = /.(\.[^./]+|\.)$/.exec(normalizeWindowsPath2(filePath));
|
|
7312
|
+
return match && match[1] || EMPTY_STRING;
|
|
7313
|
+
}
|
|
7314
|
+
__name(findFileExtension, "findFileExtension");
|
|
7307
7315
|
function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
|
|
7308
7316
|
const paths = normalizeWindowsPath2(path6).split("/");
|
|
7309
7317
|
let resolvedPath = "";
|
|
@@ -7327,28 +7335,6 @@ function resolvePaths(...paths) {
|
|
|
7327
7335
|
return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
|
|
7328
7336
|
}
|
|
7329
7337
|
__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
7338
|
|
|
7353
7339
|
// ../string-format/src/lower-case-first.ts
|
|
7354
7340
|
init_esm_shims();
|
|
@@ -7384,24 +7370,16 @@ var ModelAction = /* @__PURE__ */ function(ModelAction2) {
|
|
|
7384
7370
|
ModelAction2["aggregateRaw"] = "aggregateRaw";
|
|
7385
7371
|
return ModelAction2;
|
|
7386
7372
|
}(ModelAction || {});
|
|
7387
|
-
var configBoolean = z.enum([
|
|
7388
|
-
"true",
|
|
7389
|
-
"false"
|
|
7390
|
-
]).transform((arg) => JSON.parse(arg));
|
|
7391
|
-
var configMiddleware = z.union([
|
|
7392
|
-
configBoolean,
|
|
7393
|
-
z.string().default("../src/trpc/middleware")
|
|
7394
|
-
]);
|
|
7395
7373
|
var modelActionEnum = z.nativeEnum(ModelAction);
|
|
7396
7374
|
var configSchema = z.object({
|
|
7397
|
-
debug:
|
|
7398
|
-
withMiddleware:
|
|
7399
|
-
withShield: z.boolean().or(z.string()).default(
|
|
7400
|
-
withZod:
|
|
7401
|
-
withNext:
|
|
7375
|
+
debug: z.boolean().or(z.string()).default(false),
|
|
7376
|
+
withMiddleware: z.boolean().or(z.string()).default(false),
|
|
7377
|
+
withShield: z.boolean().or(z.string()).default(true),
|
|
7378
|
+
withZod: z.boolean().default(true),
|
|
7379
|
+
withNext: z.boolean().default(true),
|
|
7402
7380
|
contextPath: z.string().default("../src/trpc/context"),
|
|
7403
|
-
trpcOptions: z.boolean().or(z.string()).
|
|
7404
|
-
showModelNameInProcedure:
|
|
7381
|
+
trpcOptions: z.boolean().or(z.string()).default(true),
|
|
7382
|
+
showModelNameInProcedure: z.boolean().default(true),
|
|
7405
7383
|
generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
|
|
7406
7384
|
return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
|
|
7407
7385
|
})
|
|
@@ -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
|
|
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(
|
|
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");
|
|
@@ -7633,9 +7611,7 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7633
7611
|
namedImports: imports
|
|
7634
7612
|
});
|
|
7635
7613
|
}, "generateCreateRouterImport");
|
|
7636
|
-
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, value) => {
|
|
7637
|
-
const internals = await getPrismaInternals();
|
|
7638
|
-
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
7614
|
+
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, outputDir, value) => {
|
|
7639
7615
|
let shieldPath = joinPaths(outputDir, "shield");
|
|
7640
7616
|
if (typeof value === "string") {
|
|
7641
7617
|
shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
|
|
@@ -7953,7 +7929,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
|
|
|
7953
7929
|
var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
|
|
7954
7930
|
return `export const permissions = ${shieldObjectText};`;
|
|
7955
7931
|
}, "wrapWithExport");
|
|
7956
|
-
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options,
|
|
7932
|
+
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, outputDir) => {
|
|
7957
7933
|
if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
|
|
7958
7934
|
return "";
|
|
7959
7935
|
}
|
|
@@ -7980,7 +7956,7 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
|
|
|
7980
7956
|
return "";
|
|
7981
7957
|
}
|
|
7982
7958
|
let shieldText = getImports("trpc-shield");
|
|
7983
|
-
shieldText += getImports("context",
|
|
7959
|
+
shieldText += getImports("context", getRelativePath(outputDir, config.contextPath, true, options.schemaPath));
|
|
7984
7960
|
shieldText += "\n\n";
|
|
7985
7961
|
shieldText += wrapWithExport({
|
|
7986
7962
|
shieldObjectText: wrapWithTrpcShieldCall({
|
|
@@ -10327,11 +10303,11 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
|
|
|
10327
10303
|
}, "writeFileSafely");
|
|
10328
10304
|
var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
|
|
10329
10305
|
const rows = Array.from(indexExports).map((filePath) => {
|
|
10330
|
-
let
|
|
10331
|
-
if (
|
|
10332
|
-
|
|
10306
|
+
let relativePath = path3.relative(path3.dirname(indexPath), filePath);
|
|
10307
|
+
if (relativePath.endsWith(".ts")) {
|
|
10308
|
+
relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts"));
|
|
10333
10309
|
}
|
|
10334
|
-
const normalized = correctPath(
|
|
10310
|
+
const normalized = correctPath(relativePath);
|
|
10335
10311
|
return `export * from './${normalized}'`;
|
|
10336
10312
|
});
|
|
10337
10313
|
await writeFileSafely(indexPath, rows.join("\n"), false);
|
|
@@ -11618,7 +11594,7 @@ async function generate(options) {
|
|
|
11618
11594
|
consoleLog("Skipping tRPC Shield generation as path provided already exists");
|
|
11619
11595
|
} else {
|
|
11620
11596
|
consoleLog("Constructing tRPC Shield source file");
|
|
11621
|
-
const shieldOutputDir = typeof config.withShield === "string" ? findFilePath(config.withShield) : outputDir;
|
|
11597
|
+
const shieldOutputDir = typeof config.withShield === "string" ? findFileExtension(config.withShield) ? findFilePath(config.withShield) : config.withShield : outputDir;
|
|
11622
11598
|
const shieldText = await constructShield({
|
|
11623
11599
|
queries,
|
|
11624
11600
|
mutations,
|
|
@@ -11653,16 +11629,16 @@ export default {${config.withNext ? "\n transformer," : ""}
|
|
|
11653
11629
|
`);
|
|
11654
11630
|
}
|
|
11655
11631
|
resolveModelsComments(models, hiddenModels);
|
|
11656
|
-
const
|
|
11632
|
+
const trpcExports = project.createSourceFile(path5.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11657
11633
|
overwrite: true
|
|
11658
11634
|
});
|
|
11659
11635
|
consoleLog("Generating tRPC imports");
|
|
11660
11636
|
if (config.withShield) {
|
|
11661
|
-
await generateShieldImport(
|
|
11637
|
+
await generateShieldImport(trpcExports, options, outputDir, config.withShield);
|
|
11662
11638
|
}
|
|
11663
11639
|
consoleLog("Generating tRPC base router");
|
|
11664
|
-
await generateBaseRouter(
|
|
11665
|
-
|
|
11640
|
+
await generateBaseRouter(trpcExports, config, options);
|
|
11641
|
+
trpcExports.formatText({
|
|
11666
11642
|
indentSize: 2
|
|
11667
11643
|
});
|
|
11668
11644
|
const appRouter = project.createSourceFile(path5.resolve(outputDir, "routers", `index.ts`), void 0, {
|