-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change all import with .js suffix, which will help nodejs(e…
…sm) to import code clear.
- Loading branch information
1 parent
5dca262
commit d5d0446
Showing
121 changed files
with
540 additions
and
501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"name": "tianji", | ||
"private": true, | ||
"version": "1.12.1", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "concurrently --kill-others npm:dev:server npm:dev:web", | ||
"dev:web": "cd src/client && pnpm dev", | ||
|
@@ -15,9 +16,9 @@ | |
"build:app": "pnpm build:server && pnpm build:client", | ||
"build:client": "cd src/client && pnpm build", | ||
"build:server": "cd src/server && pnpm build", | ||
"build:tracker": "ts-node scripts/build-tracker.ts", | ||
"build:geo": "ts-node scripts/build-geo.ts", | ||
"build:openapi": "ts-node --project ./tsconfig.base.json ./scripts/build-openapi-schema.ts && cd packages/client-sdk && pnpm generate:client", | ||
"build:tracker": "tsx scripts/build-tracker.ts", | ||
"build:geo": "tsx scripts/build-geo.ts", | ||
"build:openapi": "tsx --project ./tsconfig.base.json ./scripts/build-openapi-schema.ts && cd packages/client-sdk && pnpm generate:client", | ||
"check:type": "pnpm -r check:type", | ||
"release": "release-it", | ||
"release:patch": "release-it -i patch", | ||
|
@@ -30,12 +31,14 @@ | |
"@types/tar": "^6.1.10", | ||
"concurrently": "^8.2.2", | ||
"cross-env": "^7.0.3", | ||
"dotenv": "^16.3.1", | ||
"fs-extra": "^11.2.0", | ||
"prettier-plugin-tailwindcss": "^0.5.12", | ||
"release-it": "^17.0.1", | ||
"tar": "^6.1.15", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.2.2", | ||
"tsx": "^4.16.2", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.12" | ||
}, | ||
"dependencies": { | ||
|
@@ -47,6 +50,9 @@ | |
"pnpm": { | ||
"overrides": { | ||
"dayjs": "1.11.10" | ||
}, | ||
"patchedDependencies": { | ||
"[email protected]": "patches/[email protected]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
diff --git a/dist/zod-prisma.cjs.development.js b/dist/zod-prisma.cjs.development.js | ||
index fb04fd45d6e6d9407ed9ab0b13533b05f3ae4d08..ce51f3065af5dc3e13dcb796293d45cc03e21b7b 100644 | ||
--- a/dist/zod-prisma.cjs.development.js | ||
+++ b/dist/zod-prisma.cjs.development.js | ||
@@ -194,7 +194,7 @@ const writeImportsForModel = (model, sourceFile, config, { | ||
if (filteredFields.length > 0) { | ||
importList.push({ | ||
kind: tsMorph.StructureKind.ImportDeclaration, | ||
- moduleSpecifier: './index', | ||
+ moduleSpecifier: './index.js', | ||
namedImports: Array.from(new Set(filteredFields.flatMap(f => [`Complete${f.type}`, relatedModelName(f.type)]))) | ||
}); | ||
} | ||
@@ -284,7 +284,7 @@ const populateModelFile = (model, sourceFile, config, prismaOptions) => { | ||
}; | ||
const generateBarrelFile = (models, indexFile) => { | ||
models.forEach(model => indexFile.addExportDeclaration({ | ||
- moduleSpecifier: `./${model.name.toLowerCase()}` | ||
+ moduleSpecifier: `./${model.name.toLowerCase()}.js` | ||
})); | ||
}; | ||
|
||
diff --git a/dist/zod-prisma.cjs.production.min.js b/dist/zod-prisma.cjs.production.min.js | ||
index 9720e85802156e5765b0cc277a5c3dbed9b5a2e8..a4df60874a24897582785ebd61bc86f29f89b7b4 100644 | ||
--- a/dist/zod-prisma.cjs.production.min.js | ||
+++ b/dist/zod-prisma.cjs.production.min.js | ||
@@ -1,2 +1,2 @@ | ||
-"use strict";var e=require("@prisma/generator-helper"),t=require("typescript"),a=require("zod"),r=require("path"),i=require("ts-morph"),n=require("parenthesis");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=o(r);const s=a.z.enum(["true","false"]).transform((e=>JSON.parse(e))),c=a.z.object({relationModel:s.default("true").or(a.z.literal("default")),modelSuffix:a.z.string().default("Model"),modelCase:a.z.enum(["PascalCase","camelCase"]).default("PascalCase"),useDecimalJs:s.default("false"),imports:a.z.string().optional(),prismaJsonNullability:s.default("true")}),d=(e,t,a=!0)=>t.forEach((t=>e.write(t).conditionalNewLine(a))),m=({modelCase:e,modelSuffix:t,relationModel:a})=>{const r=(a,r="")=>("camelCase"===e&&(a=a.slice(0,1).toLowerCase()+a.slice(1)),`${r}${a}${t}`);return{modelName:e=>r(e,"default"===a?"_":""),relatedModelName:e=>r("default"===a?e.toString():`Related${e.toString()}`)}},u=e=>{const t=e.replace(/^\\\\\?\\/,"").replace(/\\/g,"/").replace(/\/\/+/g,"/");return t.includes("/node_modules/")?t.split("/node_modules/").slice(-1)[0]:t.startsWith("../")?t:"./"+t},p=e=>{const t=[];if(e){const a=e.split("\n").filter((e=>!e.trimStart().startsWith("@zod")));a.length&&(t.push("/**"),a.forEach((e=>t.push(` * ${e}`))),t.push(" */"))}return t},f=e=>e.split("\n").filter((e=>e.trimStart().startsWith("@zod"))).map((e=>e.trimStart().slice(4))).flatMap((e=>{return(t=n.parse(e),t.reduce(((e,t,a)=>a%2==0?[...e,[t]]:[...e.slice(0,-1),[...e.slice(-1)[0],t]]),[])).slice(0,-1).map((([e,t])=>e.replace(/\)?\./,"")+`${n.stringify(t)})`));var t})),h=(e,t=(e=>e.toString()))=>{let a="z.unknown()",r=[""];if("scalar"===e.kind)switch(e.type){case"String":a="z.string()";break;case"Int":a="z.number()",r.push("int()");break;case"BigInt":a="z.bigint()";break;case"DateTime":a="z.date()";break;case"Float":case"Decimal":a="z.number()";break;case"Json":a="jsonSchema";break;case"Boolean":a="z.boolean()";break;case"Bytes":a="z.unknown()"}else"enum"===e.kind?a=`z.nativeEnum(${e.type})`:"object"===e.kind&&(a=t(e.type));var i,n,o;return e.isList&&r.push("array()"),e.documentation&&(a=null!=(i=null==(n=f(e.documentation).find((e=>e.startsWith("custom("))))?void 0:n.slice(7).slice(0,-1))?i:a,r.push(...(o=e.documentation,f(o).filter((e=>!e.startsWith("custom(")))))),e.isRequired||"Json"===e.type||r.push("nullish()"),`${a}${r.join(".")}`};e.generatorHandler({onManifest:()=>({version:"0.5.4",prettyName:"Zod Schemas",defaultOutput:"zod"}),onGenerate(e){const a=new i.Project,r=e.dmmf.datamodel.models,{schemaPath:n}=e,o=e.generator.output.value,s=e.otherGenerators.find((e=>"prisma-client-js"===e.provider.value)).output.value,f=c.safeParse(e.generator.config);if(!f.success)throw new Error("Incorrect config provided. Please check the values you provided and try again.");const z=f.data,S={clientPath:s,outputPath:o,schemaPath:n},y=a.createSourceFile(`${o}/index.ts`,{},{overwrite:!0});return((e,t)=>{e.forEach((e=>t.addExportDeclaration({moduleSpecifier:`./${e.name.toLowerCase()}`})))})(r,y),y.formatText({indentSize:2,convertTabsToSpaces:!0,semicolons:t.SemicolonPreference.Remove}),r.forEach((e=>{const r=a.createSourceFile(`${o}/${e.name.toLowerCase()}.ts`,{},{overwrite:!0});((e,t,a,r)=>{((e,t,a,{schemaPath:r,outputPath:n,clientPath:o})=>{const{relatedModelName:s}=m(a),c=[{kind:i.StructureKind.ImportDeclaration,namespaceImport:"z",moduleSpecifier:"zod"}];a.imports&&c.push({kind:i.StructureKind.ImportDeclaration,namespaceImport:"imports",moduleSpecifier:u(l.default.relative(n,l.default.resolve(l.default.dirname(r),a.imports)))}),a.useDecimalJs&&e.fields.some((e=>"Decimal"===e.type))&&c.push({kind:i.StructureKind.ImportDeclaration,namedImports:["Decimal"],moduleSpecifier:"decimal.js"});const d=e.fields.filter((e=>"enum"===e.kind)),p=e.fields.filter((e=>"object"===e.kind)),f=l.default.relative(n,o);if(d.length>0&&c.push({kind:i.StructureKind.ImportDeclaration,isTypeOnly:0===d.length,moduleSpecifier:u(f),namedImports:d.map((e=>e.type))}),!1!==a.relationModel&&p.length>0){const t=p.filter((t=>t.type!==e.name));t.length>0&&c.push({kind:i.StructureKind.ImportDeclaration,moduleSpecifier:"./index",namedImports:Array.from(new Set(t.flatMap((e=>[`Complete${e.type}`,s(e.type)]))))})}t.addImportDeclarations(c)})(e,t,a,r),((e,t,a,r)=>{e.fields.some((e=>"Json"===e.type))&&t.addStatements((e=>{e.newLine(),d(e,["// Helper schema for JSON fields","type Literal = boolean | number | string"+(a.prismaJsonNullability?"":"| null"),"type Json = Literal | { [key: string]: Json } | Json[]",`const literalSchema = z.union([z.string(), z.number(), z.boolean()${a.prismaJsonNullability?"":", z.null()"}])`,"const jsonSchema: z.ZodSchema<Json> = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]))"])})),a.useDecimalJs&&e.fields.some((e=>"Decimal"===e.type))&&t.addStatements((e=>{e.newLine(),d(e,["// Helper schema for Decimal fields","z",".instanceof(Decimal)",".or(z.string())",".or(z.number())",".refine((value) => {"," try {"," return new Decimal(value);"," } catch (error) {"," return false;"," }","})",".transform((value) => new Decimal(value));"])}))})(e,t,a),((e,t,a,r)=>{const{modelName:n}=m(a);t.addVariableStatement({declarationKind:i.VariableDeclarationKind.Const,isExported:!0,leadingTrivia:e=>e.blankLineIfLastNot(),declarations:[{name:n(e.name),initializer(t){t.write("z.object(").inlineBlock((()=>{e.fields.filter((e=>"object"!==e.kind)).forEach((e=>{d(t,p(e.documentation)),t.write(`${e.name}: ${h(e)}`).write(",").newLine()}))})).write(")")}}]})})(e,t,a),((e,t)=>e.fields.some((e=>"object"===e.kind))&&!1!==t.relationModel)(e,a)&&((e,t,a,r)=>{const{modelName:n,relatedModelName:o}=m(a),l=e.fields.filter((e=>"object"===e.kind));t.addInterface({name:`Complete${e.name}`,isExported:!0,extends:[`z.infer<typeof ${n(e.name)}>`],properties:l.map((e=>({hasQuestionToken:!e.isRequired,name:e.name,type:`Complete${e.type}${e.isList?"[]":""}${e.isRequired?"":" | null"}`})))}),t.addStatements((t=>d(t,["","/**",` * ${o(e.name)} contains all relations on your model in addition to the scalars`," *"," * NOTE: Lazy required in case of potential circular dependencies within schema"," */"]))),t.addVariableStatement({declarationKind:i.VariableDeclarationKind.Const,isExported:!0,declarations:[{name:o(e.name),type:`z.ZodSchema<Complete${e.name}>`,initializer(t){t.write(`z.lazy(() => ${n(e.name)}.extend(`).inlineBlock((()=>{l.forEach((e=>{d(t,p(e.documentation)),t.write(`${e.name}: ${h(e,o)}`).write(",").newLine()}))})).write("))")}}]})})(e,t,a)})(e,r,z,S),r.formatText({indentSize:2,convertTabsToSpaces:!0,semicolons:t.SemicolonPreference.Remove})})),a.save()}}); | ||
+"use strict";var e=require("@prisma/generator-helper"),t=require("typescript"),a=require("zod"),r=require("path"),i=require("ts-morph"),n=require("parenthesis");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=o(r);const s=a.z.enum(["true","false"]).transform((e=>JSON.parse(e))),c=a.z.object({relationModel:s.default("true").or(a.z.literal("default")),modelSuffix:a.z.string().default("Model"),modelCase:a.z.enum(["PascalCase","camelCase"]).default("PascalCase"),useDecimalJs:s.default("false"),imports:a.z.string().optional(),prismaJsonNullability:s.default("true")}),d=(e,t,a=!0)=>t.forEach((t=>e.write(t).conditionalNewLine(a))),m=({modelCase:e,modelSuffix:t,relationModel:a})=>{const r=(a,r="")=>("camelCase"===e&&(a=a.slice(0,1).toLowerCase()+a.slice(1)),`${r}${a}${t}`);return{modelName:e=>r(e,"default"===a?"_":""),relatedModelName:e=>r("default"===a?e.toString():`Related${e.toString()}`)}},u=e=>{const t=e.replace(/^\\\\\?\\/,"").replace(/\\/g,"/").replace(/\/\/+/g,"/");return t.includes("/node_modules/")?t.split("/node_modules/").slice(-1)[0]:t.startsWith("../")?t:"./"+t},p=e=>{const t=[];if(e){const a=e.split("\n").filter((e=>!e.trimStart().startsWith("@zod")));a.length&&(t.push("/**"),a.forEach((e=>t.push(` * ${e}`))),t.push(" */"))}return t},f=e=>e.split("\n").filter((e=>e.trimStart().startsWith("@zod"))).map((e=>e.trimStart().slice(4))).flatMap((e=>{return(t=n.parse(e),t.reduce(((e,t,a)=>a%2==0?[...e,[t]]:[...e.slice(0,-1),[...e.slice(-1)[0],t]]),[])).slice(0,-1).map((([e,t])=>e.replace(/\)?\./,"")+`${n.stringify(t)})`));var t})),h=(e,t=(e=>e.toString()))=>{let a="z.unknown()",r=[""];if("scalar"===e.kind)switch(e.type){case"String":a="z.string()";break;case"Int":a="z.number()",r.push("int()");break;case"BigInt":a="z.bigint()";break;case"DateTime":a="z.date()";break;case"Float":case"Decimal":a="z.number()";break;case"Json":a="jsonSchema";break;case"Boolean":a="z.boolean()";break;case"Bytes":a="z.unknown()"}else"enum"===e.kind?a=`z.nativeEnum(${e.type})`:"object"===e.kind&&(a=t(e.type));var i,n,o;return e.isList&&r.push("array()"),e.documentation&&(a=null!=(i=null==(n=f(e.documentation).find((e=>e.startsWith("custom("))))?void 0:n.slice(7).slice(0,-1))?i:a,r.push(...(o=e.documentation,f(o).filter((e=>!e.startsWith("custom(")))))),e.isRequired||"Json"===e.type||r.push("nullish()"),`${a}${r.join(".")}`};e.generatorHandler({onManifest:()=>({version:"0.5.4",prettyName:"Zod Schemas",defaultOutput:"zod"}),onGenerate(e){const a=new i.Project,r=e.dmmf.datamodel.models,{schemaPath:n}=e,o=e.generator.output.value,s=e.otherGenerators.find((e=>"prisma-client-js"===e.provider.value)).output.value,f=c.safeParse(e.generator.config);if(!f.success)throw new Error("Incorrect config provided. Please check the values you provided and try again.");const z=f.data,S={clientPath:s,outputPath:o,schemaPath:n},y=a.createSourceFile(`${o}/index.ts`,{},{overwrite:!0});return((e,t)=>{e.forEach((e=>t.addExportDeclaration({moduleSpecifier:`./${e.name.toLowerCase()}.js`})))})(r,y),y.formatText({indentSize:2,convertTabsToSpaces:!0,semicolons:t.SemicolonPreference.Remove}),r.forEach((e=>{const r=a.createSourceFile(`${o}/${e.name.toLowerCase()}.ts`,{},{overwrite:!0});((e,t,a,r)=>{((e,t,a,{schemaPath:r,outputPath:n,clientPath:o})=>{const{relatedModelName:s}=m(a),c=[{kind:i.StructureKind.ImportDeclaration,namespaceImport:"z",moduleSpecifier:"zod"}];a.imports&&c.push({kind:i.StructureKind.ImportDeclaration,namespaceImport:"imports",moduleSpecifier:u(l.default.relative(n,l.default.resolve(l.default.dirname(r),a.imports)))}),a.useDecimalJs&&e.fields.some((e=>"Decimal"===e.type))&&c.push({kind:i.StructureKind.ImportDeclaration,namedImports:["Decimal"],moduleSpecifier:"decimal.js"});const d=e.fields.filter((e=>"enum"===e.kind)),p=e.fields.filter((e=>"object"===e.kind)),f=l.default.relative(n,o);if(d.length>0&&c.push({kind:i.StructureKind.ImportDeclaration,isTypeOnly:0===d.length,moduleSpecifier:u(f),namedImports:d.map((e=>e.type))}),!1!==a.relationModel&&p.length>0){const t=p.filter((t=>t.type!==e.name));t.length>0&&c.push({kind:i.StructureKind.ImportDeclaration,moduleSpecifier:"./index.js",namedImports:Array.from(new Set(t.flatMap((e=>[`Complete${e.type}`,s(e.type)]))))})}t.addImportDeclarations(c)})(e,t,a,r),((e,t,a,r)=>{e.fields.some((e=>"Json"===e.type))&&t.addStatements((e=>{e.newLine(),d(e,["// Helper schema for JSON fields","type Literal = boolean | number | string"+(a.prismaJsonNullability?"":"| null"),"type Json = Literal | { [key: string]: Json } | Json[]",`const literalSchema = z.union([z.string(), z.number(), z.boolean()${a.prismaJsonNullability?"":", z.null()"}])`,"const jsonSchema: z.ZodSchema<Json> = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]))"])})),a.useDecimalJs&&e.fields.some((e=>"Decimal"===e.type))&&t.addStatements((e=>{e.newLine(),d(e,["// Helper schema for Decimal fields","z",".instanceof(Decimal)",".or(z.string())",".or(z.number())",".refine((value) => {"," try {"," return new Decimal(value);"," } catch (error) {"," return false;"," }","})",".transform((value) => new Decimal(value));"])}))})(e,t,a),((e,t,a,r)=>{const{modelName:n}=m(a);t.addVariableStatement({declarationKind:i.VariableDeclarationKind.Const,isExported:!0,leadingTrivia:e=>e.blankLineIfLastNot(),declarations:[{name:n(e.name),initializer(t){t.write("z.object(").inlineBlock((()=>{e.fields.filter((e=>"object"!==e.kind)).forEach((e=>{d(t,p(e.documentation)),t.write(`${e.name}: ${h(e)}`).write(",").newLine()}))})).write(")")}}]})})(e,t,a),((e,t)=>e.fields.some((e=>"object"===e.kind))&&!1!==t.relationModel)(e,a)&&((e,t,a,r)=>{const{modelName:n,relatedModelName:o}=m(a),l=e.fields.filter((e=>"object"===e.kind));t.addInterface({name:`Complete${e.name}`,isExported:!0,extends:[`z.infer<typeof ${n(e.name)}>`],properties:l.map((e=>({hasQuestionToken:!e.isRequired,name:e.name,type:`Complete${e.type}${e.isList?"[]":""}${e.isRequired?"":" | null"}`})))}),t.addStatements((t=>d(t,["","/**",` * ${o(e.name)} contains all relations on your model in addition to the scalars`," *"," * NOTE: Lazy required in case of potential circular dependencies within schema"," */"]))),t.addVariableStatement({declarationKind:i.VariableDeclarationKind.Const,isExported:!0,declarations:[{name:o(e.name),type:`z.ZodSchema<Complete${e.name}>`,initializer(t){t.write(`z.lazy(() => ${n(e.name)}.extend(`).inlineBlock((()=>{l.forEach((e=>{d(t,p(e.documentation)),t.write(`${e.name}: ${h(e,o)}`).write(",").newLine()}))})).write("))")}}]})})(e,t,a)})(e,r,z,S),r.formatText({indentSize:2,convertTabsToSpaces:!0,semicolons:t.SemicolonPreference.Remove})})),a.save()}}); | ||
//# sourceMappingURL=zod-prisma.cjs.production.min.js.map |
Oops, something went wrong.