diff --git a/package.json b/package.json index 8c79da7..e750d29 100644 --- a/package.json +++ b/package.json @@ -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": { + "zod-prisma@0.5.4": "patches/zod-prisma@0.5.4.patch" } } } diff --git a/patches/zod-prisma@0.5.4.patch b/patches/zod-prisma@0.5.4.patch new file mode 100644 index 0000000..5b5ef17 --- /dev/null +++ b/patches/zod-prisma@0.5.4.patch @@ -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 = 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`],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`,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 = 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`],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`,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 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39b9f30..f2fcbf4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,11 @@ settings: overrides: dayjs: 1.11.10 +patchedDependencies: + zod-prisma@0.5.4: + hash: 7m3k6hik5q4kosvcy74j54segm + path: patches/zod-prisma@0.5.4.patch + importers: .: @@ -23,7 +28,7 @@ importers: devDependencies: '@release-it/conventional-changelog': specifier: ^8.0.1 - version: 8.0.1(release-it@17.0.1(typescript@5.2.2)) + version: 8.0.1(release-it@17.0.1(typescript@5.4.5)) '@types/fs-extra': specifier: ^11.0.3 version: 11.0.3 @@ -39,6 +44,9 @@ importers: cross-env: specifier: ^7.0.3 version: 7.0.3 + dotenv: + specifier: ^16.3.1 + version: 16.4.5 fs-extra: specifier: ^11.2.0 version: 11.2.0 @@ -47,16 +55,19 @@ importers: version: 0.5.12(prettier@3.2.5) release-it: specifier: ^17.0.1 - version: 17.0.1(typescript@5.2.2) + version: 17.0.1(typescript@5.4.5) tar: specifier: ^6.1.15 version: 6.1.15 ts-node: specifier: ^10.9.1 - version: 10.9.1(@types/node@18.17.12)(typescript@5.2.2) + version: 10.9.1(@types/node@18.17.12)(typescript@5.4.5) + tsx: + specifier: ^4.16.2 + version: 4.16.2 typescript: - specifier: ^5.2.2 - version: 5.2.2 + specifier: ^5.3.3 + version: 5.4.5 vite: specifier: ^5.0.12 version: 5.0.12(@types/node@18.17.12)(less@4.2.0)(terser@5.28.1) @@ -341,7 +352,7 @@ importers: devDependencies: '@i18next-toolkit/cli': specifier: ^1.2.2 - version: 1.2.2(buffer@6.0.3)(typescript@5.4.5) + version: 1.2.2(buffer@6.0.3)(typescript@5.5.4) '@tanstack/router-vite-plugin': specifier: ^1.20.5 version: 1.20.5 @@ -389,13 +400,13 @@ importers: version: 8.4.33 shadcn-ui: specifier: ^0.8.0 - version: 0.8.0(typescript@5.4.5) + version: 0.8.0(typescript@5.5.4) tailwindcss: specifier: ^3.4.1 - version: 3.4.1(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.4.5)) + version: 3.4.1(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.5.4)) tailwindcss-animate: specifier: ^1.0.7 - version: 1.0.7(tailwindcss@3.4.1(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.4.5))) + version: 1.0.7(tailwindcss@3.4.1(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.5.4))) vite: specifier: ^5.0.12 version: 5.0.12(@types/node@20.12.7)(less@4.2.0)(terser@5.28.1) @@ -406,8 +417,8 @@ importers: src/server: dependencies: '@auth/core': - specifier: ^0.31.0 - version: 0.31.0(nodemailer@6.9.8) + specifier: ^0.34.1 + version: 0.34.1(nodemailer@6.9.8) '@auth/express': specifier: ^0.5.5 version: 0.5.6(express@4.18.2)(nodemailer@6.9.8) @@ -518,7 +529,7 @@ importers: version: 0.4.4 puppeteer: specifier: ^21.7.0 - version: 21.7.0(typescript@5.4.5) + version: 21.7.0(typescript@5.5.4) request-ip: specifier: ^3.3.0 version: 3.3.0 @@ -536,7 +547,7 @@ importers: version: 1.2.0(@trpc/server@10.45.2)(zod@3.22.2) ts-node: specifier: ^10.9.1 - version: 10.9.1(@types/node@18.17.12)(typescript@5.4.5) + version: 10.9.1(@types/node@18.17.12)(typescript@5.5.4) uuid: specifier: ^9.0.1 version: 9.0.1 @@ -553,8 +564,8 @@ importers: specifier: ^3.22.2 version: 3.22.2 zod-prisma: - specifier: ^0.5.4 - version: 0.5.4(prisma@5.14.0)(zod@3.22.2) + specifier: 0.5.4 + version: 0.5.4(patch_hash=7m3k6hik5q4kosvcy74j54segm)(prisma@5.14.0)(zod@3.22.2) devDependencies: '@faker-js/faker': specifier: ^8.4.0 @@ -633,7 +644,7 @@ importers: version: 5.14.0 prisma-json-types-generator: specifier: 3.0.3 - version: 3.0.3(prisma@5.14.0)(typescript@5.4.5) + version: 3.0.3(prisma@5.14.0)(typescript@5.5.4) prisma-zod-generator: specifier: 0.8.13 version: 0.8.13(prisma@5.14.0) @@ -642,10 +653,13 @@ importers: version: 6.3.4 tailwindcss: specifier: ^3.3.5 - version: 3.3.5(ts-node@10.9.1(@types/node@18.17.12)(typescript@5.4.5)) + version: 3.3.5(ts-node@10.9.1(@types/node@18.17.12)(typescript@5.5.4)) tsx: specifier: ^4.16.2 version: 4.16.2 + typescript: + specifier: ^5.5.4 + version: 5.5.4 vite: specifier: ^5.0.12 version: 5.0.12(@types/node@18.17.12)(less@4.2.0)(terser@5.28.1) @@ -661,7 +675,7 @@ importers: devDependencies: tsup: specifier: ^8.2.3 - version: 8.2.3(jiti@1.21.0)(postcss@8.4.38)(tsx@4.16.2)(typescript@5.4.5) + version: 8.2.3(jiti@1.21.0)(postcss@8.4.38)(tsx@4.16.2)(typescript@5.5.4) vitest: specifier: ^1.2.1 version: 1.2.1(@types/node@20.12.7)(happy-dom@14.7.1)(less@4.2.0)(terser@5.28.1) @@ -1140,20 +1154,6 @@ packages: resolution: {integrity: sha512-hv/aXDILyroHioVW27etFMV+IX6FyNn41YwbeGIAt5h/7fUTQvHI5w3ols8qYAT8aQt3kzexq5ZwxFDxNHIhdQ==} engines: {node: '>= 16'} - '@auth/core@0.31.0': - resolution: {integrity: sha512-UKk3psvA1cRbk4/c9CkpWB8mdWrkKvzw0DmEYRsWolUQytQ2cRqx+hYuV6ZCsngw/xbj9hpmkZmAZEyq2g4fMg==} - peerDependencies: - '@simplewebauthn/browser': ^9.0.1 - '@simplewebauthn/server': ^9.0.2 - nodemailer: ^6.8.0 - peerDependenciesMeta: - '@simplewebauthn/browser': - optional: true - '@simplewebauthn/server': - optional: true - nodemailer: - optional: true - '@auth/core@0.34.1': resolution: {integrity: sha512-tuYU2VIbI8rFbkSwP710LmybB2FXJsPN7j3sjRVfN9SXVQBK2ej6LdewQaofpBGp4Mk+cC2UeiGNH0or4tgaeA==} peerDependencies: @@ -8951,10 +8951,6 @@ packages: resolution: {integrity: sha512-sBz8G/YjVniEz6lKPNpKxXwazJe4c19fEfV2GDMX6AjFz+MX9uDWIZW8XreVhkFW3fkIdTv/gxWr/Kks5FFAVw==} engines: {node: '>=10'} - minimatch@9.0.3: - resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} - engines: {node: '>=16 || 14 >=14.17'} - minimatch@9.0.5: resolution: {integrity: sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==} engines: {node: '>=16 || 14 >=14.17'} @@ -12342,6 +12338,11 @@ packages: engines: {node: '>=14.17'} hasBin: true + typescript@5.5.4: + resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==} + engines: {node: '>=14.17'} + hasBin: true + typewise-core@1.2.0: resolution: {integrity: sha512-2SCC/WLzj2SbUwzFOzqMCkz5amXLlxtJqDKTICqg30x+2DZxcfZN2MvQZmGfXWKNWaKK9pBPsvkcwv8bF/gxKg==} @@ -13968,18 +13969,6 @@ snapshots: '@types/json-schema': 7.0.15 js-yaml: 4.1.0 - '@auth/core@0.31.0(nodemailer@6.9.8)': - dependencies: - '@panva/hkdf': 1.2.1 - '@types/cookie': 0.6.0 - cookie: 0.6.0 - jose: 5.6.3 - oauth4webapi: 2.11.1 - preact: 10.11.3 - preact-render-to-string: 5.2.3(preact@10.11.3) - optionalDependencies: - nodemailer: 6.9.8 - '@auth/core@0.34.1(nodemailer@6.9.8)': dependencies: '@panva/hkdf': 1.2.1 @@ -15928,13 +15917,13 @@ snapshots: '@hutson/parse-repository-url@5.0.0': {} - '@i18next-toolkit/cli@1.2.2(buffer@6.0.3)(typescript@5.4.5)': + '@i18next-toolkit/cli@1.2.2(buffer@6.0.3)(typescript@5.5.4)': dependencies: '@i18next-toolkit/extractor': 1.1.0(buffer@6.0.3) '@i18next-toolkit/scanner': 1.0.0 '@langchain/core': 0.1.52 '@langchain/openai': 0.0.24 - cosmiconfig: 9.0.0(typescript@5.4.5) + cosmiconfig: 9.0.0(typescript@5.5.4) dotenv: 16.4.5 fs-extra: 11.2.0 inquirer: 8.2.6 @@ -17200,12 +17189,12 @@ snapshots: react: 18.3.1 react-redux: 7.2.9(react-dom@18.2.0(react@18.3.1))(react@18.3.1) - '@release-it/conventional-changelog@8.0.1(release-it@17.0.1(typescript@5.2.2))': + '@release-it/conventional-changelog@8.0.1(release-it@17.0.1(typescript@5.4.5))': dependencies: concat-stream: 2.0.0 conventional-changelog: 5.1.0 conventional-recommended-bump: 9.0.0 - release-it: 17.0.1(typescript@5.2.2) + release-it: 17.0.1(typescript@5.4.5) semver: 7.5.4 '@remix-run/router@1.8.0': {} @@ -17534,7 +17523,7 @@ snapshots: '@ts-morph/common@0.22.0': dependencies: fast-glob: 3.3.2 - minimatch: 9.0.3 + minimatch: 9.0.5 mkdirp: 3.0.1 path-browserify: 1.0.1 @@ -18379,7 +18368,7 @@ snapshots: '@types/bonjour@3.5.13': dependencies: - '@types/node': 18.17.12 + '@types/node': 18.18.13 '@types/codemirror@5.60.15': dependencies: @@ -18392,7 +18381,7 @@ snapshots: '@types/connect-history-api-fallback@1.5.4': dependencies: '@types/express-serve-static-core': 4.17.36 - '@types/node': 18.17.12 + '@types/node': 18.18.13 '@types/connect@3.4.35': dependencies: @@ -18410,7 +18399,7 @@ snapshots: '@types/cross-spawn@6.0.2': dependencies: - '@types/node': 18.17.12 + '@types/node': 18.18.13 '@types/cross-spawn@6.0.3': dependencies: @@ -18500,7 +18489,7 @@ snapshots: '@types/http-proxy@1.17.14': dependencies: - '@types/node': 18.17.12 + '@types/node': 18.18.13 '@types/istanbul-lib-coverage@2.0.6': {} @@ -18580,12 +18569,12 @@ snapshots: '@types/node-fetch@2.6.11': dependencies: - '@types/node': 18.17.12 + '@types/node': 18.18.13 form-data: 4.0.0 '@types/node-forge@1.3.11': dependencies: - '@types/node': 18.17.12 + '@types/node': 18.18.13 '@types/node@17.0.45': {} @@ -18697,7 +18686,7 @@ snapshots: '@types/sax@1.2.7': dependencies: - '@types/node': 18.17.12 + '@types/node': 18.18.13 '@types/send@0.17.1': dependencies: @@ -18716,7 +18705,7 @@ snapshots: '@types/sockjs@0.3.36': dependencies: - '@types/node': 18.17.12 + '@types/node': 18.18.13 '@types/statuses@2.0.5': {} @@ -18763,7 +18752,7 @@ snapshots: '@types/ws@8.5.10': dependencies: - '@types/node': 18.17.12 + '@types/node': 18.18.13 '@types/yargs-parser@21.0.3': {} @@ -20274,14 +20263,23 @@ snapshots: optionalDependencies: typescript: 5.4.5 - cosmiconfig@9.0.0(typescript@5.4.5): + cosmiconfig@8.3.6(typescript@5.5.4): + dependencies: + import-fresh: 3.3.0 + js-yaml: 4.1.0 + parse-json: 5.2.0 + path-type: 4.0.0 + optionalDependencies: + typescript: 5.5.4 + + cosmiconfig@9.0.0(typescript@5.5.4): dependencies: env-paths: 2.2.1 import-fresh: 3.3.0 js-yaml: 4.1.0 parse-json: 5.2.0 optionalDependencies: - typescript: 5.4.5 + typescript: 5.5.4 crc-32@1.2.2: {} @@ -22889,7 +22887,7 @@ snapshots: jest-util@29.7.0: dependencies: '@jest/types': 29.6.3 - '@types/node': 18.17.12 + '@types/node': 18.18.13 chalk: 4.1.2 ci-info: 3.8.0 graceful-fs: 4.2.11 @@ -22897,7 +22895,7 @@ snapshots: jest-worker@27.5.1: dependencies: - '@types/node': 18.17.12 + '@types/node': 18.18.13 merge-stream: 2.0.0 supports-color: 8.1.1 @@ -24230,10 +24228,6 @@ snapshots: dependencies: brace-expansion: 2.0.1 - minimatch@9.0.3: - dependencies: - brace-expansion: 2.0.1 - minimatch@9.0.5: dependencies: brace-expansion: 2.0.1 @@ -25186,13 +25180,13 @@ snapshots: camelcase-css: 2.0.1 postcss: 8.4.35 - postcss-load-config@4.0.1(postcss@8.4.33)(ts-node@10.9.1(@types/node@18.17.12)(typescript@5.4.5)): + postcss-load-config@4.0.1(postcss@8.4.33)(ts-node@10.9.1(@types/node@18.17.12)(typescript@5.5.4)): dependencies: lilconfig: 2.1.0 yaml: 2.3.2 optionalDependencies: postcss: 8.4.33 - ts-node: 10.9.1(@types/node@18.17.12)(typescript@5.4.5) + ts-node: 10.9.1(@types/node@18.17.12)(typescript@5.5.4) postcss-load-config@4.0.1(postcss@8.4.33)(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.2.2)): dependencies: @@ -25202,13 +25196,13 @@ snapshots: postcss: 8.4.33 ts-node: 10.9.1(@types/node@20.12.7)(typescript@5.2.2) - postcss-load-config@4.0.1(postcss@8.4.35)(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.4.5)): + postcss-load-config@4.0.1(postcss@8.4.35)(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.5.4)): dependencies: lilconfig: 2.1.0 yaml: 2.3.2 optionalDependencies: postcss: 8.4.35 - ts-node: 10.9.1(@types/node@20.12.7)(typescript@5.4.5) + ts-node: 10.9.1(@types/node@20.12.7)(typescript@5.5.4) postcss-load-config@6.0.1(jiti@1.21.0)(postcss@8.4.38)(tsx@4.16.2): dependencies: @@ -25526,7 +25520,7 @@ snapshots: postcss@8.4.31: dependencies: nanoid: 3.3.7 - picocolors: 1.0.0 + picocolors: 1.0.1 source-map-js: 1.2.0 postcss@8.4.33: @@ -25678,12 +25672,12 @@ snapshots: clsx: 2.1.0 react: 18.3.1 - prisma-json-types-generator@3.0.3(prisma@5.14.0)(typescript@5.4.5): + prisma-json-types-generator@3.0.3(prisma@5.14.0)(typescript@5.5.4): dependencies: '@prisma/generator-helper': 5.5.2 prisma: 5.14.0 tslib: 2.6.2 - typescript: 5.4.5 + typescript: 5.5.4 transitivePeerDependencies: - supports-color @@ -25814,10 +25808,10 @@ snapshots: - supports-color - utf-8-validate - puppeteer@21.7.0(typescript@5.4.5): + puppeteer@21.7.0(typescript@5.5.4): dependencies: '@puppeteer/browsers': 1.9.1 - cosmiconfig: 8.3.6(typescript@5.4.5) + cosmiconfig: 8.3.6(typescript@5.5.4) puppeteer-core: 21.7.0 transitivePeerDependencies: - bufferutil @@ -27102,13 +27096,13 @@ snapshots: relateurl@0.2.7: {} - release-it@17.0.1(typescript@5.2.2): + release-it@17.0.1(typescript@5.4.5): dependencies: '@iarna/toml': 2.2.5 '@octokit/rest': 20.0.2 async-retry: 1.3.3 chalk: 5.3.0 - cosmiconfig: 8.3.6(typescript@5.2.2) + cosmiconfig: 8.3.6(typescript@5.4.5) execa: 8.0.1 git-url-parse: 13.1.1 globby: 14.0.0 @@ -27612,7 +27606,7 @@ snapshots: setprototypeof@1.2.0: {} - shadcn-ui@0.8.0(typescript@5.4.5): + shadcn-ui@0.8.0(typescript@5.5.4): dependencies: '@antfu/ni': 0.21.4 '@babel/core': 7.24.0 @@ -27620,7 +27614,7 @@ snapshots: '@babel/plugin-transform-typescript': 7.23.6(@babel/core@7.24.0) chalk: 5.2.0 commander: 10.0.1 - cosmiconfig: 8.3.6(typescript@5.4.5) + cosmiconfig: 8.3.6(typescript@5.5.4) diff: 5.2.0 execa: 7.2.0 fast-glob: 3.3.2 @@ -28183,11 +28177,11 @@ snapshots: dependencies: '@babel/runtime': 7.24.0 - tailwindcss-animate@1.0.7(tailwindcss@3.4.1(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.4.5))): + tailwindcss-animate@1.0.7(tailwindcss@3.4.1(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.5.4))): dependencies: - tailwindcss: 3.4.1(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.4.5)) + tailwindcss: 3.4.1(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.5.4)) - tailwindcss@3.3.5(ts-node@10.9.1(@types/node@18.17.12)(typescript@5.4.5)): + tailwindcss@3.3.5(ts-node@10.9.1(@types/node@18.17.12)(typescript@5.5.4)): dependencies: '@alloc/quick-lru': 5.2.0 arg: 5.0.2 @@ -28206,7 +28200,7 @@ snapshots: postcss: 8.4.33 postcss-import: 15.1.0(postcss@8.4.33) postcss-js: 4.0.1(postcss@8.4.33) - postcss-load-config: 4.0.1(postcss@8.4.33)(ts-node@10.9.1(@types/node@18.17.12)(typescript@5.4.5)) + postcss-load-config: 4.0.1(postcss@8.4.33)(ts-node@10.9.1(@types/node@18.17.12)(typescript@5.5.4)) postcss-nested: 6.0.1(postcss@8.4.33) postcss-selector-parser: 6.0.13 resolve: 1.22.8 @@ -28241,7 +28235,7 @@ snapshots: transitivePeerDependencies: - ts-node - tailwindcss@3.4.1(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.4.5)): + tailwindcss@3.4.1(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.5.4)): dependencies: '@alloc/quick-lru': 5.2.0 arg: 5.0.2 @@ -28260,7 +28254,7 @@ snapshots: postcss: 8.4.35 postcss-import: 15.1.0(postcss@8.4.35) postcss-js: 4.0.1(postcss@8.4.35) - postcss-load-config: 4.0.1(postcss@8.4.35)(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.4.5)) + postcss-load-config: 4.0.1(postcss@8.4.35)(ts-node@10.9.1(@types/node@20.12.7)(typescript@5.5.4)) postcss-nested: 6.0.1(postcss@8.4.35) postcss-selector-parser: 6.0.15 resolve: 1.22.8 @@ -28534,24 +28528,6 @@ snapshots: '@ts-morph/common': 0.22.0 code-block-writer: 12.0.0 - ts-node@10.9.1(@types/node@18.17.12)(typescript@5.2.2): - dependencies: - '@cspotcode/source-map-support': 0.8.1 - '@tsconfig/node10': 1.0.9 - '@tsconfig/node12': 1.0.11 - '@tsconfig/node14': 1.0.3 - '@tsconfig/node16': 1.0.4 - '@types/node': 18.17.12 - acorn: 8.11.3 - acorn-walk: 8.3.2 - arg: 4.1.3 - create-require: 1.1.1 - diff: 4.0.2 - make-error: 1.3.6 - typescript: 5.2.2 - v8-compile-cache-lib: 3.0.1 - yn: 3.1.1 - ts-node@10.9.1(@types/node@18.17.12)(typescript@5.4.5): dependencies: '@cspotcode/source-map-support': 0.8.1 @@ -28570,6 +28546,24 @@ snapshots: v8-compile-cache-lib: 3.0.1 yn: 3.1.1 + ts-node@10.9.1(@types/node@18.17.12)(typescript@5.5.4): + dependencies: + '@cspotcode/source-map-support': 0.8.1 + '@tsconfig/node10': 1.0.9 + '@tsconfig/node12': 1.0.11 + '@tsconfig/node14': 1.0.3 + '@tsconfig/node16': 1.0.4 + '@types/node': 18.17.12 + acorn: 8.11.3 + acorn-walk: 8.3.2 + arg: 4.1.3 + create-require: 1.1.1 + diff: 4.0.2 + make-error: 1.3.6 + typescript: 5.5.4 + v8-compile-cache-lib: 3.0.1 + yn: 3.1.1 + ts-node@10.9.1(@types/node@20.12.7)(typescript@5.2.2): dependencies: '@cspotcode/source-map-support': 0.8.1 @@ -28588,7 +28582,7 @@ snapshots: v8-compile-cache-lib: 3.0.1 yn: 3.1.1 - ts-node@10.9.1(@types/node@20.12.7)(typescript@5.4.5): + ts-node@10.9.1(@types/node@20.12.7)(typescript@5.5.4): dependencies: '@cspotcode/source-map-support': 0.8.1 '@tsconfig/node10': 1.0.9 @@ -28602,7 +28596,7 @@ snapshots: create-require: 1.1.1 diff: 4.0.2 make-error: 1.3.6 - typescript: 5.4.5 + typescript: 5.5.4 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 optional: true @@ -28621,7 +28615,7 @@ snapshots: tslib@2.6.2: {} - tsup@8.2.3(jiti@1.21.0)(postcss@8.4.38)(tsx@4.16.2)(typescript@5.4.5): + tsup@8.2.3(jiti@1.21.0)(postcss@8.4.38)(tsx@4.16.2)(typescript@5.5.4): dependencies: bundle-require: 5.0.0(esbuild@0.23.0) cac: 6.7.14 @@ -28641,7 +28635,7 @@ snapshots: tree-kill: 1.2.2 optionalDependencies: postcss: 8.4.38 - typescript: 5.4.5 + typescript: 5.5.4 transitivePeerDependencies: - jiti - supports-color @@ -28721,6 +28715,8 @@ snapshots: typescript@5.4.5: {} + typescript@5.5.4: {} + typewise-core@1.2.0: {} typewise@1.0.3: @@ -29648,7 +29644,7 @@ snapshots: compress-commons: 4.1.2 readable-stream: 3.6.2 - zod-prisma@0.5.4(prisma@5.14.0)(zod@3.22.2): + zod-prisma@0.5.4(patch_hash=7m3k6hik5q4kosvcy74j54segm)(prisma@5.14.0)(zod@3.22.2): dependencies: '@prisma/generator-helper': 3.8.1 parenthesis: 3.1.8 diff --git a/scripts/build-geo.ts b/scripts/build-geo.ts index 077e282..126131d 100644 --- a/scripts/build-geo.ts +++ b/scripts/build-geo.ts @@ -1,4 +1,4 @@ -require('dotenv').config(); +import 'dotenv/config'; import fs from 'fs'; import path from 'path'; import https from 'https'; @@ -20,7 +20,7 @@ if (process.env.MAXMIND_LICENSE_KEY) { `?edition_id=${db}&license_key=${process.env.MAXMIND_LICENSE_KEY}&suffix=tar.gz`; } -const dest = path.resolve(__dirname, '../geo'); +const dest = path.resolve(process.cwd(), './geo'); if (!fs.existsSync(dest)) { fs.mkdirSync(dest); diff --git a/scripts/build-tracker.ts b/scripts/build-tracker.ts index da4d9cc..f92101b 100644 --- a/scripts/build-tracker.ts +++ b/scripts/build-tracker.ts @@ -1,5 +1,5 @@ import { resolve } from 'path'; -import vite from 'vite'; +import * as vite from 'vite'; console.log('Start Build Tracker'); @@ -7,13 +7,13 @@ vite .build({ build: { lib: { - entry: resolve(__dirname, '../src/tracker/index.js'), + entry: resolve(process.cwd(), './src/tracker/index.js'), name: 'tianji', fileName: () => 'tracker.js', formats: ['iife'], }, emptyOutDir: false, - outDir: resolve(__dirname, '../src/client/public'), + outDir: resolve(process.cwd(), './src/client/public'), }, }) .then((res) => { diff --git a/src/server/app.ts b/src/server/app.ts index 33f663f..5bd0469 100644 --- a/src/server/app.ts +++ b/src/server/app.ts @@ -4,24 +4,24 @@ import compression from 'compression'; import swaggerUI from 'swagger-ui-express'; import passport from 'passport'; import morgan from 'morgan'; -import { websiteRouter } from './router/website'; -import { workspaceRouter } from './router/workspace'; -import { telemetryRouter } from './router/telemetry'; +import { websiteRouter } from './router/website.js'; +import { workspaceRouter } from './router/workspace.js'; +import { telemetryRouter } from './router/telemetry.js'; import { trpcExpressMiddleware, trpcOpenapiDocument, trpcOpenapiHttpHandler, -} from './trpc'; -import { env } from './utils/env'; +} from './trpc/index.js'; +import { env } from './utils/env.js'; import cors from 'cors'; -import { serverStatusRouter } from './router/serverStatus'; -import { logger } from './utils/logger'; -import { monitorRouter } from './router/monitor'; -import { healthRouter } from './router/health'; +import { serverStatusRouter } from './router/serverStatus.js'; +import { logger } from './utils/logger.js'; +import { monitorRouter } from './router/monitor.js'; +import { healthRouter } from './router/health.js'; import path from 'path'; -import { monitorPageManager } from './model/monitor/page/manager'; +import { monitorPageManager } from './model/monitor/page/manager.js'; import { ExpressAuth } from '@auth/express'; -import { authConfig } from './model/auth'; +import { authConfig } from './model/auth.js'; const app = express(); diff --git a/src/server/cronjob/index.spec.ts b/src/server/cronjob/index.spec.ts index ca4aebe..71c11f6 100644 --- a/src/server/cronjob/index.spec.ts +++ b/src/server/cronjob/index.spec.ts @@ -1,5 +1,5 @@ import { describe, test } from 'vitest'; -import { initCronjob } from '.'; +import { initCronjob } from './index.js'; describe.runIf(process.env.TEST_CRONJOB)('cronjob', () => { const { dailyJob } = initCronjob(); diff --git a/src/server/cronjob/index.ts b/src/server/cronjob/index.ts index e532a94..5f1cc57 100644 --- a/src/server/cronjob/index.ts +++ b/src/server/cronjob/index.ts @@ -1,14 +1,14 @@ import { Cron } from 'croner'; -import { logger } from '../utils/logger'; -import { prisma } from '../model/_client'; +import { logger } from '../utils/logger.js'; +import { prisma } from '../model/_client.js'; import dayjs from 'dayjs'; import { FeedChannelNotifyFrequency, Prisma } from '@prisma/client'; -import { env } from '../utils/env'; -import { sendNotification } from '../model/notification'; -import { token } from '../model/notification/token'; +import { env } from '../utils/env.js'; +import { sendNotification } from '../model/notification/index.js'; +import { token } from '../model/notification/token/index.js'; import _ from 'lodash'; import pMap from 'p-map'; -import { sendFeedEventsNotify } from '../model/feed/event'; +import { sendFeedEventsNotify } from '../model/feed/event.js'; type WebsiteEventCountSqlReturn = { workspace_id: string; diff --git a/src/server/main.ts b/src/server/main.ts index f9ec172..913adc6 100644 --- a/src/server/main.ts +++ b/src/server/main.ts @@ -1,13 +1,13 @@ import 'dotenv/config'; -import './init'; -import { initUdpServer } from './udp/server'; +import './init.js'; +import { initUdpServer } from './udp/server.js'; import { createServer } from 'http'; -import { initSocketio } from './ws'; -import { monitorManager } from './model/monitor'; -import { env } from './utils/env'; -import { initCronjob } from './cronjob'; -import { logger } from './utils/logger'; -import { app } from './app'; +import { initSocketio } from './ws/index.js'; +import { monitorManager } from './model/monitor/index.js'; +import { env } from './utils/env.js'; +import { initCronjob } from './cronjob/index.js'; +import { logger } from './utils/logger.js'; +import { app } from './app.js'; const port = env.port; diff --git a/src/server/middleware/auth.ts b/src/server/middleware/auth.ts index 1cfa2ff..882c10b 100644 --- a/src/server/middleware/auth.ts +++ b/src/server/middleware/auth.ts @@ -1,9 +1,9 @@ -import { findUser } from '../model/user'; +import { findUser } from '../model/user.js'; import passport from 'passport'; import { Handler } from 'express'; import { Strategy as JwtStrategy, ExtractJwt } from 'passport-jwt'; import jwt from 'jsonwebtoken'; -import { jwtSecret } from '../utils/common'; +import { jwtSecret } from '../utils/common.js'; export const jwtIssuer = process.env.JWT_ISSUER || 'tianji.msgbyte.com'; export const jwtAudience = process.env.JWT_AUDIENCE || 'msgbyte.com'; diff --git a/src/server/middleware/workspace.ts b/src/server/middleware/workspace.ts index a8b8a94..99f0cc1 100644 --- a/src/server/middleware/workspace.ts +++ b/src/server/middleware/workspace.ts @@ -1,5 +1,5 @@ import { Handler } from 'express'; -import { getWorkspaceUser } from '../model/workspace'; +import { getWorkspaceUser } from '../model/workspace.js'; import { ROLES } from '@tianji/shared'; export function workspacePermission(roles: ROLES[] = []): Handler { @@ -11,7 +11,7 @@ export function workspacePermission(roles: ROLES[] = []): Handler { throw new Error('Cannot find workspace id'); } - const userId = req.user!.id; + const userId = (req.user as any).id; if (!userId) { throw new Error('This middleware should be use after auth()'); diff --git a/src/server/model/_client.ts b/src/server/model/_client.ts index fafa65d..64bd18c 100644 --- a/src/server/model/_client.ts +++ b/src/server/model/_client.ts @@ -1,6 +1,6 @@ import { PrismaClient } from '@prisma/client'; -import { logger } from '../utils/logger'; -import { env } from '../utils/env'; +import { logger } from '../utils/logger.js'; +import { env } from '../utils/env.js'; const debugEvent = { emit: 'event', diff --git a/src/server/model/_schema/index.ts b/src/server/model/_schema/index.ts index f6214e2..73ed074 100644 --- a/src/server/model/_schema/index.ts +++ b/src/server/model/_schema/index.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { MonitorModelSchema } from '../../prisma/zod'; +import { MonitorModelSchema } from '../../prisma/zod/index.js'; // Match prisma `JsonValue` export const jsonFieldSchema = z.union([ diff --git a/src/server/model/_schema/monitor.ts b/src/server/model/_schema/monitor.ts index d97b76f..03780aa 100644 --- a/src/server/model/_schema/monitor.ts +++ b/src/server/model/_schema/monitor.ts @@ -1,5 +1,5 @@ -import { MonitorInfo } from '../../../types'; -import { MonitorModelSchema } from '../../prisma/zod'; +import { MonitorInfo } from '../../../types/index.js'; +import { MonitorModelSchema } from '../../prisma/zod/monitor.js'; export type MonitorInfoWithNotificationIds = MonitorInfo & { notifications: { id: string }[]; diff --git a/src/server/model/auditLog.ts b/src/server/model/auditLog.ts index febcdae..2b3270d 100644 --- a/src/server/model/auditLog.ts +++ b/src/server/model/auditLog.ts @@ -1,5 +1,5 @@ import { WorkspaceAuditLogType } from '@prisma/client'; -import { prisma } from './_client'; +import { prisma } from './_client.js'; /** * create audit log which can query by log diff --git a/src/server/model/auth.ts b/src/server/model/auth.ts index d9b3eea..b7b4a19 100644 --- a/src/server/model/auth.ts +++ b/src/server/model/auth.ts @@ -1,8 +1,8 @@ import { AuthConfig } from '@auth/core'; import Nodemailer from '@auth/core/providers/nodemailer'; -import { env } from '../utils/env'; +import { env } from '../utils/env.js'; import { PrismaAdapter } from '@auth/prisma-adapter'; -import { prisma } from './_client'; +import { prisma } from './_client.js'; export const authConfig: Omit = { providers: [Nodemailer(env.auth.email)], diff --git a/src/server/model/feed/event.ts b/src/server/model/feed/event.ts index 8d001b9..d223bc1 100644 --- a/src/server/model/feed/event.ts +++ b/src/server/model/feed/event.ts @@ -1,15 +1,15 @@ import { FeedChannelNotifyFrequency, FeedEvent, Prisma } from '@prisma/client'; -import { subscribeEventBus } from '../../ws/shared'; -import { prisma } from '../_client'; -import { serializeJSON } from '../../utils/json'; -import { buildQueryWithCache } from '../../cache'; -import { sendNotification } from '../notification'; -import { ContentToken, token } from '../notification/token'; -import { logger } from '../../utils/logger'; +import { subscribeEventBus } from '../../ws/shared.js'; +import { prisma } from '../_client.js'; +import { serializeJSON } from '../../utils/json.js'; +import { buildQueryWithCache } from '../../cache/index.js'; +import { sendNotification } from '../notification/index.js'; +import { ContentToken, token } from '../notification/token/index.js'; +import { logger } from '../../utils/logger.js'; import { FeedChannelModelSchema, NotificationModelSchema, -} from '../../prisma/zod'; +} from '../../prisma/zod/index.js'; import dayjs from 'dayjs'; import { z } from 'zod'; diff --git a/src/server/model/monitor/index.bench.ts b/src/server/model/monitor/index.bench.ts index 5c121eb..1a6ce04 100644 --- a/src/server/model/monitor/index.bench.ts +++ b/src/server/model/monitor/index.bench.ts @@ -1,5 +1,5 @@ import { describe, bench } from 'vitest'; -import { prisma } from '../_client'; +import { prisma } from '../_client.js'; const workspaceId = process.env.BENCH_MONITOR_WORKSPACEID; const monitorId = process.env.BENCH_MONITOR_ID; diff --git a/src/server/model/monitor/index.ts b/src/server/model/monitor/index.ts index 7b56971..cc609a7 100644 --- a/src/server/model/monitor/index.ts +++ b/src/server/model/monitor/index.ts @@ -1,6 +1,6 @@ -import { prisma } from '../_client'; -import { monitorPublicInfoSchema } from '../_schema/monitor'; -import { MonitorManager } from './manager'; +import { prisma } from '../_client.js'; +import { monitorPublicInfoSchema } from '../_schema/monitor.js'; +import { MonitorManager } from './manager.js'; export const monitorManager = new MonitorManager(); diff --git a/src/server/model/monitor/manager.ts b/src/server/model/monitor/manager.ts index 705cefc..fca25e0 100644 --- a/src/server/model/monitor/manager.ts +++ b/src/server/model/monitor/manager.ts @@ -1,7 +1,7 @@ import { Monitor, Notification } from '@prisma/client'; -import { prisma } from '../_client'; -import { MonitorRunner } from './runner'; -import { logger } from '../../utils/logger'; +import { prisma } from '../_client.js'; +import { MonitorRunner } from './runner.js'; +import { logger } from '../../utils/logger.js'; export type MonitorUpsertData = Pick< Monitor, diff --git a/src/server/model/monitor/page/manager.ts b/src/server/model/monitor/page/manager.ts index c7e891a..67e80e5 100644 --- a/src/server/model/monitor/page/manager.ts +++ b/src/server/model/monitor/page/manager.ts @@ -1,5 +1,5 @@ -import { logger } from '../../../utils/logger'; -import { prisma } from '../../_client'; +import { logger } from '../../../utils/logger.js'; +import { prisma } from '../../_client.js'; class MonitorPageManager { private customDomainPage: Record< diff --git a/src/server/model/monitor/provider/__tests__/dns.spec.ts b/src/server/model/monitor/provider/__tests__/dns.spec.ts index 2f0ba5a..7855ed1 100644 --- a/src/server/model/monitor/provider/__tests__/dns.spec.ts +++ b/src/server/model/monitor/provider/__tests__/dns.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from 'vitest'; -import { dns } from '../dns'; +import { dns } from '../dns.js'; describe('dns', () => { test('run', async () => { diff --git a/src/server/model/monitor/provider/__tests__/openai.spec.ts b/src/server/model/monitor/provider/__tests__/openai.spec.ts index b9f7740..372b9ae 100644 --- a/src/server/model/monitor/provider/__tests__/openai.spec.ts +++ b/src/server/model/monitor/provider/__tests__/openai.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from 'vitest'; -import { getBillingCreditGrants } from '../openai'; +import { getBillingCreditGrants } from '../openai.js'; describe.runIf(!!process.env.TEST_OPENAI_SESS_KEY)('openai', () => { test('getBillingCreditGrants should be ok', async () => { diff --git a/src/server/model/monitor/provider/_utils.ts b/src/server/model/monitor/provider/_utils.ts index 4291216..3910d11 100644 --- a/src/server/model/monitor/provider/_utils.ts +++ b/src/server/model/monitor/provider/_utils.ts @@ -1,4 +1,4 @@ -import { prisma } from '../../_client'; +import { prisma } from '../../_client.js'; export async function saveMonitorStatus( monitorId: string, diff --git a/src/server/model/monitor/provider/custom.ts b/src/server/model/monitor/provider/custom.ts index d646379..3943104 100644 --- a/src/server/model/monitor/provider/custom.ts +++ b/src/server/model/monitor/provider/custom.ts @@ -1,7 +1,7 @@ -import { MonitorProvider } from './type'; +import { MonitorProvider } from './type.js'; import ivm from 'isolated-vm'; -import { buildSandbox, environmentScript } from '../../../utils/sandbox'; -import { env } from '../../../utils/env'; +import { buildSandbox, environmentScript } from '../../../utils/sandbox.js'; +import { env } from '../../../utils/env.js'; export const custom: MonitorProvider<{ code: string; diff --git a/src/server/model/monitor/provider/dns.ts b/src/server/model/monitor/provider/dns.ts index 6169cff..1136f11 100644 --- a/src/server/model/monitor/provider/dns.ts +++ b/src/server/model/monitor/provider/dns.ts @@ -1,4 +1,4 @@ -import { MonitorProvider } from './type'; +import { MonitorProvider } from './type.js'; import { Resolver } from 'dns'; export const dns: MonitorProvider<{ diff --git a/src/server/model/monitor/provider/http.ts b/src/server/model/monitor/provider/http.ts index 981bc0f..712018c 100644 --- a/src/server/model/monitor/provider/http.ts +++ b/src/server/model/monitor/provider/http.ts @@ -1,9 +1,9 @@ -import { MonitorProvider } from './type'; +import { MonitorProvider } from './type.js'; import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'; -import { logger } from '../../../utils/logger'; +import { logger } from '../../../utils/logger.js'; import dayjs from 'dayjs'; import https from 'https'; -import { saveMonitorStatus } from './_utils'; +import { saveMonitorStatus } from './_utils.js'; export const http: MonitorProvider<{ url: string; diff --git a/src/server/model/monitor/provider/index.ts b/src/server/model/monitor/provider/index.ts index 468fa7f..cd563f8 100644 --- a/src/server/model/monitor/provider/index.ts +++ b/src/server/model/monitor/provider/index.ts @@ -1,10 +1,10 @@ -import { http } from './http'; -import { ping } from './ping'; -import { openai } from './openai'; -import type { MonitorProvider } from './type'; -import { custom } from './custom'; -import { tcp } from './tcp'; -import { dns } from './dns'; +import { http } from './http.js'; +import { ping } from './ping.js'; +import { openai } from './openai.js'; +import type { MonitorProvider } from './type.js'; +import { custom } from './custom.js'; +import { tcp } from './tcp.js'; +import { dns } from './dns.js'; export const monitorProviders: Record> = { ping, diff --git a/src/server/model/monitor/provider/openai.ts b/src/server/model/monitor/provider/openai.ts index 8147c2a..e0ba7a7 100644 --- a/src/server/model/monitor/provider/openai.ts +++ b/src/server/model/monitor/provider/openai.ts @@ -1,7 +1,7 @@ import { z } from 'zod'; -import { MonitorProvider } from './type'; +import { MonitorProvider } from './type.js'; import axios from 'axios'; -import { saveMonitorStatus } from './_utils'; +import { saveMonitorStatus } from './_utils.js'; import _ from 'lodash'; const openaiCreditGrantsSchema = z.object({ diff --git a/src/server/model/monitor/provider/ping.ts b/src/server/model/monitor/provider/ping.ts index f01ef9b..bd399ad 100644 --- a/src/server/model/monitor/provider/ping.ts +++ b/src/server/model/monitor/provider/ping.ts @@ -1,4 +1,4 @@ -import { MonitorProvider } from './type'; +import { MonitorProvider } from './type.js'; import pingUtils from 'ping'; import os from 'os'; import chardet from 'chardet'; diff --git a/src/server/model/monitor/provider/tcp.ts b/src/server/model/monitor/provider/tcp.ts index d7584bd..45e6ae9 100644 --- a/src/server/model/monitor/provider/tcp.ts +++ b/src/server/model/monitor/provider/tcp.ts @@ -1,4 +1,4 @@ -import { MonitorProvider } from './type'; +import { MonitorProvider } from './type.js'; import tcpp from 'tcp-ping'; export const tcp: MonitorProvider<{ diff --git a/src/server/model/monitor/provider/type.ts b/src/server/model/monitor/provider/type.ts index 83b6a3e..08195bd 100644 --- a/src/server/model/monitor/provider/type.ts +++ b/src/server/model/monitor/provider/type.ts @@ -1,5 +1,5 @@ import { Monitor } from '@prisma/client'; -import type { ExactType } from '../../../../types'; +import type { ExactType } from '../../../../types/index.js'; export interface MonitorProvider> { run: (monitor: ExactType) => Promise; diff --git a/src/server/model/monitor/runner.ts b/src/server/model/monitor/runner.ts index bf9ec1f..48e5ccf 100644 --- a/src/server/model/monitor/runner.ts +++ b/src/server/model/monitor/runner.ts @@ -1,13 +1,13 @@ import { Monitor, Notification } from '@prisma/client'; -import { subscribeEventBus } from '../../ws/shared'; -import { prisma } from '../_client'; -import { monitorProviders } from './provider'; -import { sendNotification } from '../notification'; +import { subscribeEventBus } from '../../ws/shared.js'; +import { prisma } from '../_client.js'; +import { monitorProviders } from './provider/index.js'; +import { sendNotification } from '../notification/index.js'; import dayjs from 'dayjs'; -import { logger } from '../../utils/logger'; -import { token } from '../notification/token'; -import { ContentToken } from '../notification/token/type'; -import { createAuditLog } from '../auditLog'; +import { logger } from '../../utils/logger.js'; +import { token } from '../notification/token/index.js'; +import { ContentToken } from '../notification/token/type.js'; +import { createAuditLog } from '../auditLog.js'; /** * Class which actually run monitor data collect diff --git a/src/server/model/notification/index.ts b/src/server/model/notification/index.ts index 8d60e08..44fa6bc 100644 --- a/src/server/model/notification/index.ts +++ b/src/server/model/notification/index.ts @@ -1,7 +1,7 @@ import { Notification } from '@prisma/client'; -import { notificationProviders } from './provider'; -import { ExactType } from '../../../types'; -import { ContentToken } from './token'; +import { notificationProviders } from './provider/index.js'; +import { ExactType } from '../../../types/index.js'; +import { ContentToken } from './token/index.js'; export async function sendNotification( notification: ExactType< diff --git a/src/server/model/notification/provider/__tests__/apprise.spec.ts b/src/server/model/notification/provider/__tests__/apprise.spec.ts index b3faea7..8492f34 100644 --- a/src/server/model/notification/provider/__tests__/apprise.spec.ts +++ b/src/server/model/notification/provider/__tests__/apprise.spec.ts @@ -1,6 +1,6 @@ import { describe, test } from 'vitest'; -import { apprise } from '../apprise'; -import { token } from '../../token'; +import { apprise } from '../apprise.js'; +import { token } from '../../token/index.js'; describe.runIf(!!process.env.TEST_APPRISE_URL)('apprise', () => { test('apprise should be work', async () => { diff --git a/src/server/model/notification/provider/apprise.ts b/src/server/model/notification/provider/apprise.ts index 187eebd..44a00b6 100644 --- a/src/server/model/notification/provider/apprise.ts +++ b/src/server/model/notification/provider/apprise.ts @@ -1,5 +1,5 @@ -import { NotificationProvider } from './type'; -import { baseContentTokenizer } from '../token'; +import { NotificationProvider } from './type.js'; +import { baseContentTokenizer } from '../token/index.js'; import execa from 'execa'; interface ApprisePayload { diff --git a/src/server/model/notification/provider/feishu.ts b/src/server/model/notification/provider/feishu.ts index 39cff3d..b35845a 100644 --- a/src/server/model/notification/provider/feishu.ts +++ b/src/server/model/notification/provider/feishu.ts @@ -1,5 +1,5 @@ -import { NotificationProvider } from './type'; -import { baseContentTokenizer } from '../token'; +import { NotificationProvider } from './type.js'; +import { baseContentTokenizer } from '../token/index.js'; import axios from 'axios'; interface FeishuPayload { diff --git a/src/server/model/notification/provider/index.ts b/src/server/model/notification/provider/index.ts index 90ee93c..19c4b5c 100644 --- a/src/server/model/notification/provider/index.ts +++ b/src/server/model/notification/provider/index.ts @@ -1,9 +1,9 @@ -import { apprise } from './apprise'; -import { feishu } from './feishu'; -import { smtp } from './smtp'; -import { telegram } from './telegram'; -import { webhook } from './webhook'; -import type { NotificationProvider } from './type'; +import { apprise } from './apprise.js'; +import { feishu } from './feishu.js'; +import { smtp } from './smtp.js'; +import { telegram } from './telegram.js'; +import { webhook } from './webhook.js'; +import type { NotificationProvider } from './type.js'; export const notificationProviders: Record = { smtp, diff --git a/src/server/model/notification/provider/smtp.ts b/src/server/model/notification/provider/smtp.ts index ad27166..4a699ec 100644 --- a/src/server/model/notification/provider/smtp.ts +++ b/src/server/model/notification/provider/smtp.ts @@ -1,7 +1,7 @@ -import { NotificationProvider } from './type'; +import { NotificationProvider } from './type.js'; import nodemailer from 'nodemailer'; import SMTPTransport from 'nodemailer/lib/smtp-transport'; -import { htmlContentTokenizer } from '../token'; +import { htmlContentTokenizer } from '../token/index.js'; interface SMTPPayload { hostname: string; diff --git a/src/server/model/notification/provider/telegram.ts b/src/server/model/notification/provider/telegram.ts index 7aa4110..899c86a 100644 --- a/src/server/model/notification/provider/telegram.ts +++ b/src/server/model/notification/provider/telegram.ts @@ -1,7 +1,7 @@ -import { NotificationProvider } from './type'; -import { telegramContentTokenizer, token } from '../token'; +import { NotificationProvider } from './type.js'; +import { telegramContentTokenizer, token } from '../token/index.js'; import axios from 'axios'; -import { ImageContentToken } from '../token/type'; +import { ImageContentToken } from '../token/type.js'; interface TelegramPayload { botToken: string; diff --git a/src/server/model/notification/provider/type.ts b/src/server/model/notification/provider/type.ts index 2e35de8..7fdeaab 100644 --- a/src/server/model/notification/provider/type.ts +++ b/src/server/model/notification/provider/type.ts @@ -1,5 +1,5 @@ import { Notification } from '@prisma/client'; -import { ContentToken } from '../token'; +import { ContentToken } from '../token/index.js'; export interface NotificationProvider { send: ( diff --git a/src/server/model/notification/provider/webhook.ts b/src/server/model/notification/provider/webhook.ts index 34496ff..3d13d50 100644 --- a/src/server/model/notification/provider/webhook.ts +++ b/src/server/model/notification/provider/webhook.ts @@ -1,5 +1,5 @@ -import { NotificationProvider } from './type'; -import { baseContentTokenizer } from '../token'; +import { NotificationProvider } from './type.js'; +import { baseContentTokenizer } from '../token/index.js'; import axios from 'axios'; import dayjs from 'dayjs'; diff --git a/src/server/model/notification/token/index.ts b/src/server/model/notification/token/index.ts index ad892fe..4d6985d 100644 --- a/src/server/model/notification/token/index.ts +++ b/src/server/model/notification/token/index.ts @@ -1,7 +1,7 @@ -import { BaseContentTokenizer } from './tokenizer/base'; -import { HTMLContentTokenizer } from './tokenizer/html'; -import { MarkdownContentTokenizer } from './tokenizer/markdown'; -import { TelegramContentTokenizer } from './tokenizer/telegram'; +import { BaseContentTokenizer } from './tokenizer/base.js'; +import { HTMLContentTokenizer } from './tokenizer/html.js'; +import { MarkdownContentTokenizer } from './tokenizer/markdown.js'; +import { TelegramContentTokenizer } from './tokenizer/telegram.js'; import { ContentToken, ImageContentToken, @@ -11,7 +11,7 @@ import { TextContentToken, TitleContentToken, UrlContentToken, -} from './type'; +} from './type.js'; export type { ContentToken }; diff --git a/src/server/model/notification/token/tokenizer/base.ts b/src/server/model/notification/token/tokenizer/base.ts index da8168f..39ba98b 100644 --- a/src/server/model/notification/token/tokenizer/base.ts +++ b/src/server/model/notification/token/tokenizer/base.ts @@ -7,7 +7,7 @@ import { TextContentToken, TitleContentToken, UrlContentToken, -} from '../type'; +} from '../type.js'; export class BaseContentTokenizer { parseText(token: TextContentToken) { diff --git a/src/server/model/notification/token/tokenizer/html.ts b/src/server/model/notification/token/tokenizer/html.ts index 8b27b55..cee3225 100644 --- a/src/server/model/notification/token/tokenizer/html.ts +++ b/src/server/model/notification/token/tokenizer/html.ts @@ -5,8 +5,8 @@ import { ParagraphContentToken, TitleContentToken, UrlContentToken, -} from '../type'; -import { BaseContentTokenizer } from './base'; +} from '../type.js'; +import { BaseContentTokenizer } from './base.js'; export class HTMLContentTokenizer extends BaseContentTokenizer { parseImage(token: ImageContentToken) { diff --git a/src/server/model/notification/token/tokenizer/markdown.ts b/src/server/model/notification/token/tokenizer/markdown.ts index 0a141bd..316aeaa 100644 --- a/src/server/model/notification/token/tokenizer/markdown.ts +++ b/src/server/model/notification/token/tokenizer/markdown.ts @@ -4,8 +4,8 @@ import { ParagraphContentToken, TitleContentToken, UrlContentToken, -} from '../type'; -import { BaseContentTokenizer } from './base'; +} from '../type.js'; +import { BaseContentTokenizer } from './base.js'; export class MarkdownContentTokenizer extends BaseContentTokenizer { parseImage(token: ImageContentToken) { diff --git a/src/server/model/notification/token/tokenizer/telegram.ts b/src/server/model/notification/token/tokenizer/telegram.ts index 1f13366..0ec9513 100644 --- a/src/server/model/notification/token/tokenizer/telegram.ts +++ b/src/server/model/notification/token/tokenizer/telegram.ts @@ -4,8 +4,8 @@ import { TextContentToken, TitleContentToken, UrlContentToken, -} from '../type'; -import { BaseContentTokenizer } from './base'; +} from '../type.js'; +import { BaseContentTokenizer } from './base.js'; export class TelegramContentTokenizer extends BaseContentTokenizer { parseImage(token: ImageContentToken) { diff --git a/src/server/model/serverStatus.ts b/src/server/model/serverStatus.ts index 8db9f4d..dc59457 100644 --- a/src/server/model/serverStatus.ts +++ b/src/server/model/serverStatus.ts @@ -1,5 +1,5 @@ -import { ServerStatusInfo } from '../../types'; -import { createSubscribeInitializer, subscribeEventBus } from '../ws/shared'; +import { ServerStatusInfo } from '../../types/index.js'; +import { createSubscribeInitializer, subscribeEventBus } from '../ws/shared.js'; import _ from 'lodash'; import { isServerOnline } from '@tianji/shared'; diff --git a/src/server/model/telemetry.ts b/src/server/model/telemetry.ts index 396fb52..c862c59 100644 --- a/src/server/model/telemetry.ts +++ b/src/server/model/telemetry.ts @@ -1,14 +1,14 @@ import { Prisma, Telemetry, TelemetrySession } from '@prisma/client'; import { Request } from 'express'; -import { hashUuid } from '../utils/common'; -import { getRequestInfo } from '../utils/detect'; -import { prisma } from './_client'; +import { hashUuid } from '../utils/common.js'; +import { getRequestInfo } from '../utils/detect.js'; +import { prisma } from './_client.js'; import { BaseQueryFilters, getDateQuery, parseTelemetryFilters, -} from '../utils/prisma'; -import { SESSION_COLUMNS } from '../utils/const'; +} from '../utils/prisma.js'; +import { SESSION_COLUMNS } from '../utils/const.js'; export async function recordTelemetryEvent(req: Request) { const { name, title, start, fullNum, force, ...others } = req.query; diff --git a/src/server/model/user.ts b/src/server/model/user.ts index 7bb0155..808fc40 100644 --- a/src/server/model/user.ts +++ b/src/server/model/user.ts @@ -1,7 +1,7 @@ -import { prisma } from './_client'; +import { prisma } from './_client.js'; import bcryptjs from 'bcryptjs'; import { ROLES, SYSTEM_ROLES } from '@tianji/shared'; -import { jwtVerify } from '../middleware/auth'; +import { jwtVerify } from '../middleware/auth.js'; import { TRPCError } from '@trpc/server'; import { Prisma } from '@prisma/client'; diff --git a/src/server/model/website.ts b/src/server/model/website.ts index fea2300..0b72c80 100644 --- a/src/server/model/website.ts +++ b/src/server/model/website.ts @@ -1,23 +1,23 @@ import { Prisma, Website, WebsiteSession } from '@prisma/client'; -import { flattenJSON, hashUuid, isCuid, parseToken } from '../utils/common'; -import { prisma } from './_client'; +import { flattenJSON, hashUuid, isCuid, parseToken } from '../utils/common.js'; +import { prisma } from './_client.js'; import { Request } from 'express'; -import { getClientInfo } from '../utils/detect'; +import { getClientInfo } from '../utils/detect.js'; import { DATA_TYPE, EVENT_NAME_LENGTH, EVENT_TYPE, SESSION_COLUMNS, URL_LENGTH, -} from '../utils/const'; -import type { DynamicData } from '../utils/types'; +} from '../utils/const.js'; +import type { DynamicData } from '../utils/types.js'; import dayjs from 'dayjs'; import { WebsiteQueryFilters, getDateQuery, getTimestampIntervalQuery, parseWebsiteFilters, -} from '../utils/prisma'; +} from '../utils/prisma.js'; export interface WebsiteEventPayload { data?: object; @@ -209,8 +209,8 @@ export async function saveWebsiteEvent(data: { a.dynamicDataType === DATA_TYPE.number ? parseFloat(a.value).toFixed(4) : a.dynamicDataType === DATA_TYPE.date - ? a.value.split('.')[0] + 'Z' - : a.value.toString(), + ? a.value.split('.')[0] + 'Z' + : a.value.toString(), numberValue: a.dynamicDataType === DATA_TYPE.number ? a.value : null, dateValue: a.dynamicDataType === DATA_TYPE.date ? new Date(a.value) : null, @@ -242,8 +242,8 @@ export async function saveWebsiteSessionData(data: { a.dynamicDataType === DATA_TYPE.number ? parseFloat(a.value).toFixed(4) : a.dynamicDataType === DATA_TYPE.date - ? a.value.split('.')[0] + 'Z' - : a.value.toString(), + ? a.value.split('.')[0] + 'Z' + : a.value.toString(), numberValue: a.dynamicDataType === DATA_TYPE.number ? a.value : null, dateValue: a.dynamicDataType === DATA_TYPE.date ? new Date(a.value) : null, dataType: a.dynamicDataType, @@ -302,8 +302,8 @@ export async function getWebsiteSessionMetrics( where "WebsiteEvent"."websiteId" = ${websiteId} and "WebsiteEvent"."createdAt" between ${params.startDate}::timestamptz and ${ - params.endDate - }::timestamptz + params.endDate + }::timestamptz and "WebsiteEvent"."eventType" = ${EVENT_TYPE.pageView} ${filterQuery} group by 1 @@ -339,8 +339,8 @@ export async function getWebsitePageviewMetrics( where "WebsiteEvent"."websiteId" = ${websiteId} and "WebsiteEvent"."createdAt" between ${params.startDate}::timestamptz and ${ - params.endDate - }::timestamptz + params.endDate + }::timestamptz and "eventType" = ${eventType} ${excludeDomain} ${filterQuery} diff --git a/src/server/model/workspace.ts b/src/server/model/workspace.ts index 9b22885..9eaa2b4 100644 --- a/src/server/model/workspace.ts +++ b/src/server/model/workspace.ts @@ -1,6 +1,6 @@ -import { prisma } from './_client'; -import { parseWebsiteFilters } from '../utils/prisma'; -import { DEFAULT_RESET_DATE, EVENT_TYPE } from '../utils/const'; +import { prisma } from './_client.js'; +import { parseWebsiteFilters } from '../utils/prisma.js'; +import { DEFAULT_RESET_DATE, EVENT_TYPE } from '../utils/const.js'; export async function getWorkspaceUser(workspaceId: string, userId: string) { const info = await prisma.workspacesOnUsers.findFirst({ diff --git a/src/server/package.json b/src/server/package.json index eb68073..488f4a5 100644 --- a/src/server/package.json +++ b/src/server/package.json @@ -8,7 +8,7 @@ }, "scripts": { "dev": "tsx watch --env-file=.env ./main.ts", - "build": "tsc -p tsconfig.server.json", + "build": "tsc", "postinstall": "pnpm db:generate", "check:type": "tsc --noEmit --skipLibCheck --module esnext", "db:generate": "prisma generate", @@ -23,7 +23,7 @@ "keywords": [], "author": "moonrailgun ", "dependencies": { - "@auth/core": "^0.31.0", + "@auth/core": "^0.34.1", "@auth/express": "^0.5.5", "@auth/prisma-adapter": "^2.1.0", "@paralleldrive/cuid2": "^2.2.2", @@ -72,7 +72,7 @@ "winston": "^3.11.0", "yup": "^1.3.3", "zod": "^3.22.2", - "zod-prisma": "^0.5.4" + "zod-prisma": "0.5.4" }, "devDependencies": { "@faker-js/faker": "^8.4.0", @@ -105,6 +105,7 @@ "supertest": "^6.3.4", "tailwindcss": "^3.3.5", "tsx": "^4.16.2", + "typescript": "^5.5.4", "vite": "^5.0.12", "vitest": "^1.2.1" } diff --git a/src/server/prisma/schema.prisma b/src/server/prisma/schema.prisma index 6bb91b2..4066224 100644 --- a/src/server/prisma/schema.prisma +++ b/src/server/prisma/schema.prisma @@ -14,7 +14,7 @@ generator json { generator zod { provider = "zod-prisma" modelSuffix = "ModelSchema" - imports = "./zod/schemas" + imports = "./zod/schemas/index.js" } model User { diff --git a/src/server/prisma/scripts/populate-ip-location.ts b/src/server/prisma/scripts/populate-ip-location.ts index f31de9d..8d3796b 100644 --- a/src/server/prisma/scripts/populate-ip-location.ts +++ b/src/server/prisma/scripts/populate-ip-location.ts @@ -1,5 +1,5 @@ import { PrismaClient } from '@prisma/client'; -import { getLocation } from '../../utils/detect'; +import { getLocation } from '../../utils/detect.js'; import pMap from 'p-map'; const prisma = new PrismaClient(); diff --git a/src/server/prisma/zod/account.ts b/src/server/prisma/zod/account.ts index 43afd8d..15beaea 100644 --- a/src/server/prisma/zod/account.ts +++ b/src/server/prisma/zod/account.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteUser, RelatedUserModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteUser, RelatedUserModelSchema } from "./index.js" export const AccountModelSchema = z.object({ userId: z.string(), diff --git a/src/server/prisma/zod/feedchannel.ts b/src/server/prisma/zod/feedchannel.ts index 4e2c601..0b5df4f 100644 --- a/src/server/prisma/zod/feedchannel.ts +++ b/src/server/prisma/zod/feedchannel.ts @@ -1,7 +1,7 @@ import * as z from "zod" -import * as imports from "./schemas" +import * as imports from "./schemas/index.js" import { FeedChannelNotifyFrequency } from "@prisma/client" -import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteFeedEvent, RelatedFeedEventModelSchema, CompleteNotification, RelatedNotificationModelSchema } from "./index" +import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteFeedEvent, RelatedFeedEventModelSchema, CompleteNotification, RelatedNotificationModelSchema } from "./index.js" export const FeedChannelModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/feedevent.ts b/src/server/prisma/zod/feedevent.ts index 848d346..01d5960 100644 --- a/src/server/prisma/zod/feedevent.ts +++ b/src/server/prisma/zod/feedevent.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteFeedChannel, RelatedFeedChannelModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteFeedChannel, RelatedFeedChannelModelSchema } from "./index.js" export const FeedEventModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/index.ts b/src/server/prisma/zod/index.ts index c04017d..6b9f42f 100644 --- a/src/server/prisma/zod/index.ts +++ b/src/server/prisma/zod/index.ts @@ -1,26 +1,26 @@ -export * from "./user" -export * from "./account" -export * from "./session" -export * from "./verificationtoken" -export * from "./workspace" -export * from "./workspacesonusers" -export * from "./website" -export * from "./websitesession" -export * from "./websiteevent" -export * from "./websiteeventdata" -export * from "./websitesessiondata" -export * from "./telemetry" -export * from "./telemetrysession" -export * from "./telemetryevent" -export * from "./notification" -export * from "./monitor" -export * from "./monitorevent" -export * from "./monitordata" -export * from "./monitorstatus" -export * from "./monitorstatuspage" -export * from "./workspacedailyusage" -export * from "./workspaceauditlog" -export * from "./survey" -export * from "./surveyresult" -export * from "./feedchannel" -export * from "./feedevent" +export * from "./user.js" +export * from "./account.js" +export * from "./session.js" +export * from "./verificationtoken.js" +export * from "./workspace.js" +export * from "./workspacesonusers.js" +export * from "./website.js" +export * from "./websitesession.js" +export * from "./websiteevent.js" +export * from "./websiteeventdata.js" +export * from "./websitesessiondata.js" +export * from "./telemetry.js" +export * from "./telemetrysession.js" +export * from "./telemetryevent.js" +export * from "./notification.js" +export * from "./monitor.js" +export * from "./monitorevent.js" +export * from "./monitordata.js" +export * from "./monitorstatus.js" +export * from "./monitorstatuspage.js" +export * from "./workspacedailyusage.js" +export * from "./workspaceauditlog.js" +export * from "./survey.js" +export * from "./surveyresult.js" +export * from "./feedchannel.js" +export * from "./feedevent.js" diff --git a/src/server/prisma/zod/monitor.ts b/src/server/prisma/zod/monitor.ts index e5dc916..87a8fec 100644 --- a/src/server/prisma/zod/monitor.ts +++ b/src/server/prisma/zod/monitor.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteWebsite, RelatedWebsiteModelSchema, CompleteNotification, RelatedNotificationModelSchema, CompleteMonitorEvent, RelatedMonitorEventModelSchema, CompleteMonitorData, RelatedMonitorDataModelSchema, CompleteMonitorStatus, RelatedMonitorStatusModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteWebsite, RelatedWebsiteModelSchema, CompleteNotification, RelatedNotificationModelSchema, CompleteMonitorEvent, RelatedMonitorEventModelSchema, CompleteMonitorData, RelatedMonitorDataModelSchema, CompleteMonitorStatus, RelatedMonitorStatusModelSchema } from "./index.js" // Helper schema for JSON fields type Literal = boolean | number | string diff --git a/src/server/prisma/zod/monitordata.ts b/src/server/prisma/zod/monitordata.ts index 30dc5ab..e250dfb 100644 --- a/src/server/prisma/zod/monitordata.ts +++ b/src/server/prisma/zod/monitordata.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteMonitor, RelatedMonitorModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteMonitor, RelatedMonitorModelSchema } from "./index.js" export const MonitorDataModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/monitorevent.ts b/src/server/prisma/zod/monitorevent.ts index 0b78182..307334f 100644 --- a/src/server/prisma/zod/monitorevent.ts +++ b/src/server/prisma/zod/monitorevent.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteMonitor, RelatedMonitorModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteMonitor, RelatedMonitorModelSchema } from "./index.js" export const MonitorEventModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/monitorstatus.ts b/src/server/prisma/zod/monitorstatus.ts index bb6393b..fdf3d88 100644 --- a/src/server/prisma/zod/monitorstatus.ts +++ b/src/server/prisma/zod/monitorstatus.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteMonitor, RelatedMonitorModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteMonitor, RelatedMonitorModelSchema } from "./index.js" // Helper schema for JSON fields type Literal = boolean | number | string diff --git a/src/server/prisma/zod/monitorstatuspage.ts b/src/server/prisma/zod/monitorstatuspage.ts index 22f26b8..966f207 100644 --- a/src/server/prisma/zod/monitorstatuspage.ts +++ b/src/server/prisma/zod/monitorstatuspage.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWorkspace, RelatedWorkspaceModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWorkspace, RelatedWorkspaceModelSchema } from "./index.js" // Helper schema for JSON fields type Literal = boolean | number | string diff --git a/src/server/prisma/zod/notification.ts b/src/server/prisma/zod/notification.ts index 61643c8..bb7cb43 100644 --- a/src/server/prisma/zod/notification.ts +++ b/src/server/prisma/zod/notification.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteMonitor, RelatedMonitorModelSchema, CompleteFeedChannel, RelatedFeedChannelModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteMonitor, RelatedMonitorModelSchema, CompleteFeedChannel, RelatedFeedChannelModelSchema } from "./index.js" // Helper schema for JSON fields type Literal = boolean | number | string diff --git a/src/server/prisma/zod/session.ts b/src/server/prisma/zod/session.ts index 71cd197..0a2bd86 100644 --- a/src/server/prisma/zod/session.ts +++ b/src/server/prisma/zod/session.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteUser, RelatedUserModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteUser, RelatedUserModelSchema } from "./index.js" export const SessionModelSchema = z.object({ sessionToken: z.string(), diff --git a/src/server/prisma/zod/survey.ts b/src/server/prisma/zod/survey.ts index 0f9dba0..24b955d 100644 --- a/src/server/prisma/zod/survey.ts +++ b/src/server/prisma/zod/survey.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteSurveyResult, RelatedSurveyResultModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteSurveyResult, RelatedSurveyResultModelSchema } from "./index.js" // Helper schema for JSON fields type Literal = boolean | number | string diff --git a/src/server/prisma/zod/surveyresult.ts b/src/server/prisma/zod/surveyresult.ts index 831b7dd..65e0b9d 100644 --- a/src/server/prisma/zod/surveyresult.ts +++ b/src/server/prisma/zod/surveyresult.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteSurvey, RelatedSurveyModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteSurvey, RelatedSurveyModelSchema } from "./index.js" // Helper schema for JSON fields type Literal = boolean | number | string diff --git a/src/server/prisma/zod/telemetry.ts b/src/server/prisma/zod/telemetry.ts index 42d179d..6f2fd8e 100644 --- a/src/server/prisma/zod/telemetry.ts +++ b/src/server/prisma/zod/telemetry.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteTelemetrySession, RelatedTelemetrySessionModelSchema, CompleteTelemetryEvent, RelatedTelemetryEventModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteTelemetrySession, RelatedTelemetrySessionModelSchema, CompleteTelemetryEvent, RelatedTelemetryEventModelSchema } from "./index.js" export const TelemetryModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/telemetryevent.ts b/src/server/prisma/zod/telemetryevent.ts index 0ff0839..d75bfbb 100644 --- a/src/server/prisma/zod/telemetryevent.ts +++ b/src/server/prisma/zod/telemetryevent.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteTelemetry, RelatedTelemetryModelSchema, CompleteTelemetrySession, RelatedTelemetrySessionModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteTelemetry, RelatedTelemetryModelSchema, CompleteTelemetrySession, RelatedTelemetrySessionModelSchema } from "./index.js" // Helper schema for JSON fields type Literal = boolean | number | string diff --git a/src/server/prisma/zod/telemetrysession.ts b/src/server/prisma/zod/telemetrysession.ts index f05edf9..46e146d 100644 --- a/src/server/prisma/zod/telemetrysession.ts +++ b/src/server/prisma/zod/telemetrysession.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteTelemetry, RelatedTelemetryModelSchema, CompleteTelemetryEvent, RelatedTelemetryEventModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteTelemetry, RelatedTelemetryModelSchema, CompleteTelemetryEvent, RelatedTelemetryEventModelSchema } from "./index.js" export const TelemetrySessionModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/user.ts b/src/server/prisma/zod/user.ts index 65d5fa5..f5e0293 100644 --- a/src/server/prisma/zod/user.ts +++ b/src/server/prisma/zod/user.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteAccount, RelatedAccountModelSchema, CompleteSession, RelatedSessionModelSchema, CompleteWorkspacesOnUsers, RelatedWorkspacesOnUsersModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteAccount, RelatedAccountModelSchema, CompleteSession, RelatedSessionModelSchema, CompleteWorkspacesOnUsers, RelatedWorkspacesOnUsersModelSchema } from "./index.js" export const UserModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/verificationtoken.ts b/src/server/prisma/zod/verificationtoken.ts index 4478c55..e097d34 100644 --- a/src/server/prisma/zod/verificationtoken.ts +++ b/src/server/prisma/zod/verificationtoken.ts @@ -1,5 +1,5 @@ import * as z from "zod" -import * as imports from "./schemas" +import * as imports from "./schemas/index.js" export const VerificationTokenModelSchema = z.object({ identifier: z.string(), diff --git a/src/server/prisma/zod/website.ts b/src/server/prisma/zod/website.ts index b80bafa..6e3262b 100644 --- a/src/server/prisma/zod/website.ts +++ b/src/server/prisma/zod/website.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteMonitor, RelatedMonitorModelSchema, CompleteWebsiteSession, RelatedWebsiteSessionModelSchema, CompleteWebsiteEventData, RelatedWebsiteEventDataModelSchema, CompleteWebsiteSessionData, RelatedWebsiteSessionDataModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteMonitor, RelatedMonitorModelSchema, CompleteWebsiteSession, RelatedWebsiteSessionModelSchema, CompleteWebsiteEventData, RelatedWebsiteEventDataModelSchema, CompleteWebsiteSessionData, RelatedWebsiteSessionDataModelSchema } from "./index.js" export const WebsiteModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/websiteevent.ts b/src/server/prisma/zod/websiteevent.ts index 1420498..3d45c19 100644 --- a/src/server/prisma/zod/websiteevent.ts +++ b/src/server/prisma/zod/websiteevent.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWebsiteEventData, RelatedWebsiteEventDataModelSchema, CompleteWebsiteSession, RelatedWebsiteSessionModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWebsiteEventData, RelatedWebsiteEventDataModelSchema, CompleteWebsiteSession, RelatedWebsiteSessionModelSchema } from "./index.js" export const WebsiteEventModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/websiteeventdata.ts b/src/server/prisma/zod/websiteeventdata.ts index ed6bd66..77e655b 100644 --- a/src/server/prisma/zod/websiteeventdata.ts +++ b/src/server/prisma/zod/websiteeventdata.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWebsite, RelatedWebsiteModelSchema, CompleteWebsiteEvent, RelatedWebsiteEventModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWebsite, RelatedWebsiteModelSchema, CompleteWebsiteEvent, RelatedWebsiteEventModelSchema } from "./index.js" export const WebsiteEventDataModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/websitesession.ts b/src/server/prisma/zod/websitesession.ts index 6c3e700..969e376 100644 --- a/src/server/prisma/zod/websitesession.ts +++ b/src/server/prisma/zod/websitesession.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWebsite, RelatedWebsiteModelSchema, CompleteWebsiteEvent, RelatedWebsiteEventModelSchema, CompleteWebsiteSessionData, RelatedWebsiteSessionDataModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWebsite, RelatedWebsiteModelSchema, CompleteWebsiteEvent, RelatedWebsiteEventModelSchema, CompleteWebsiteSessionData, RelatedWebsiteSessionDataModelSchema } from "./index.js" export const WebsiteSessionModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/websitesessiondata.ts b/src/server/prisma/zod/websitesessiondata.ts index 845de6b..238e6e7 100644 --- a/src/server/prisma/zod/websitesessiondata.ts +++ b/src/server/prisma/zod/websitesessiondata.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWebsite, RelatedWebsiteModelSchema, CompleteWebsiteSession, RelatedWebsiteSessionModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWebsite, RelatedWebsiteModelSchema, CompleteWebsiteSession, RelatedWebsiteSessionModelSchema } from "./index.js" export const WebsiteSessionDataModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/workspace.ts b/src/server/prisma/zod/workspace.ts index 482b179..f5decf6 100644 --- a/src/server/prisma/zod/workspace.ts +++ b/src/server/prisma/zod/workspace.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWorkspacesOnUsers, RelatedWorkspacesOnUsersModelSchema, CompleteWebsite, RelatedWebsiteModelSchema, CompleteNotification, RelatedNotificationModelSchema, CompleteMonitor, RelatedMonitorModelSchema, CompleteMonitorStatusPage, RelatedMonitorStatusPageModelSchema, CompleteTelemetry, RelatedTelemetryModelSchema, CompleteUser, RelatedUserModelSchema, CompleteWorkspaceDailyUsage, RelatedWorkspaceDailyUsageModelSchema, CompleteWorkspaceAuditLog, RelatedWorkspaceAuditLogModelSchema, CompleteSurvey, RelatedSurveyModelSchema, CompleteFeedChannel, RelatedFeedChannelModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWorkspacesOnUsers, RelatedWorkspacesOnUsersModelSchema, CompleteWebsite, RelatedWebsiteModelSchema, CompleteNotification, RelatedNotificationModelSchema, CompleteMonitor, RelatedMonitorModelSchema, CompleteMonitorStatusPage, RelatedMonitorStatusPageModelSchema, CompleteTelemetry, RelatedTelemetryModelSchema, CompleteUser, RelatedUserModelSchema, CompleteWorkspaceDailyUsage, RelatedWorkspaceDailyUsageModelSchema, CompleteWorkspaceAuditLog, RelatedWorkspaceAuditLogModelSchema, CompleteSurvey, RelatedSurveyModelSchema, CompleteFeedChannel, RelatedFeedChannelModelSchema } from "./index.js" // Helper schema for JSON fields type Literal = boolean | number | string diff --git a/src/server/prisma/zod/workspaceauditlog.ts b/src/server/prisma/zod/workspaceauditlog.ts index c2613f3..ee6da4b 100644 --- a/src/server/prisma/zod/workspaceauditlog.ts +++ b/src/server/prisma/zod/workspaceauditlog.ts @@ -1,7 +1,7 @@ import * as z from "zod" -import * as imports from "./schemas" +import * as imports from "./schemas/index.js" import { WorkspaceAuditLogType } from "@prisma/client" -import { CompleteWorkspace, RelatedWorkspaceModelSchema } from "./index" +import { CompleteWorkspace, RelatedWorkspaceModelSchema } from "./index.js" export const WorkspaceAuditLogModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/workspacedailyusage.ts b/src/server/prisma/zod/workspacedailyusage.ts index ef22a74..9760aae 100644 --- a/src/server/prisma/zod/workspacedailyusage.ts +++ b/src/server/prisma/zod/workspacedailyusage.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteWorkspace, RelatedWorkspaceModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteWorkspace, RelatedWorkspaceModelSchema } from "./index.js" export const WorkspaceDailyUsageModelSchema = z.object({ id: z.string(), diff --git a/src/server/prisma/zod/workspacesonusers.ts b/src/server/prisma/zod/workspacesonusers.ts index 0e4701a..39d00d8 100644 --- a/src/server/prisma/zod/workspacesonusers.ts +++ b/src/server/prisma/zod/workspacesonusers.ts @@ -1,6 +1,6 @@ import * as z from "zod" -import * as imports from "./schemas" -import { CompleteUser, RelatedUserModelSchema, CompleteWorkspace, RelatedWorkspaceModelSchema } from "./index" +import * as imports from "./schemas/index.js" +import { CompleteUser, RelatedUserModelSchema, CompleteWorkspace, RelatedWorkspaceModelSchema } from "./index.js" export const WorkspacesOnUsersModelSchema = z.object({ userId: z.string(), diff --git a/src/server/router/__test__/telemetry.test.ts b/src/server/router/__test__/telemetry.test.ts index 3b82753..f50aef2 100644 --- a/src/server/router/__test__/telemetry.test.ts +++ b/src/server/router/__test__/telemetry.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from 'vitest'; -import { createTestContext } from '../../tests/utils'; -import { generateETag } from '../../utils/common'; +import { createTestContext } from '../../tests/utils.js'; +import { generateETag } from '../../utils/common.js'; describe('telemetry router', () => { const { app, createTestUser, createTestTelemetry } = createTestContext(); diff --git a/src/server/router/monitor.ts b/src/server/router/monitor.ts index 35799fa..f9ffadf 100644 --- a/src/server/router/monitor.ts +++ b/src/server/router/monitor.ts @@ -1,9 +1,12 @@ import { Router } from 'express'; -import { param, validate, query } from '../middleware/validate'; -import { numify } from '../utils/common'; +import { param, validate, query } from '../middleware/validate.js'; +import { numify } from '../utils/common.js'; import { makeBadge } from 'badge-maker'; -import { getMonitorPublicInfos, getMonitorRecentData } from '../model/monitor'; -import { checkEnvTrusty } from '../utils/env'; +import { + getMonitorPublicInfos, + getMonitorRecentData, +} from '../model/monitor/index.js'; +import { checkEnvTrusty } from '../utils/env.js'; export const monitorRouter = Router(); diff --git a/src/server/router/serverStatus.ts b/src/server/router/serverStatus.ts index 3f0cb67..4d710fd 100644 --- a/src/server/router/serverStatus.ts +++ b/src/server/router/serverStatus.ts @@ -1,8 +1,8 @@ import { Router } from 'express'; -import { body, header, param, validate } from '../middleware/validate'; -import { recordServerStatus } from '../model/serverStatus'; +import { body, header, param, validate } from '../middleware/validate.js'; +import { recordServerStatus } from '../model/serverStatus.js'; import fs from 'fs-extra'; -import { libraryPath } from '../utils/lib'; +import { libraryPath } from '../utils/lib.js'; export const serverStatusRouter = Router(); diff --git a/src/server/router/telemetry.ts b/src/server/router/telemetry.ts index 4db4c3f..501ed7e 100644 --- a/src/server/router/telemetry.ts +++ b/src/server/router/telemetry.ts @@ -1,9 +1,9 @@ import { Router } from 'express'; -import { query, validate } from '../middleware/validate'; -import { recordTelemetryEvent, sumTelemetryEvent } from '../model/telemetry'; -import { generateETag, numify } from '../utils/common'; +import { query, validate } from '../middleware/validate.js'; +import { recordTelemetryEvent, sumTelemetryEvent } from '../model/telemetry.js'; +import { generateETag, numify } from '../utils/common.js'; import { makeBadge } from 'badge-maker'; -import { env } from '../utils/env'; +import { env } from '../utils/env.js'; export const telemetryRouter = Router(); diff --git a/src/server/router/website.ts b/src/server/router/website.ts index f2103a1..f2cd4a4 100644 --- a/src/server/router/website.ts +++ b/src/server/router/website.ts @@ -1,13 +1,13 @@ import { Router } from 'express'; -import { body, validate } from '../middleware/validate'; +import { body, validate } from '../middleware/validate.js'; import * as yup from 'yup'; -import { COLLECTION_TYPE } from '../utils/const'; +import { COLLECTION_TYPE } from '../utils/const.js'; import { findSession, saveWebsiteEvent, saveWebsiteSessionData, -} from '../model/website'; -import { createToken } from '../utils/common'; +} from '../model/website.js'; +import { createToken } from '../utils/common.js'; import { hostnameRegex } from '@tianji/shared'; export const websiteRouter = Router(); diff --git a/src/server/router/workspace.ts b/src/server/router/workspace.ts index 345f965..0e38765 100644 --- a/src/server/router/workspace.ts +++ b/src/server/router/workspace.ts @@ -1,8 +1,8 @@ import { Router } from 'express'; -import { auth } from '../middleware/auth'; -import { param, validate } from '../middleware/validate'; -import { workspacePermission } from '../middleware/workspace'; -import { deleteWorkspaceWebsite } from '../model/workspace'; +import { auth } from '../middleware/auth.js'; +import { param, validate } from '../middleware/validate.js'; +import { workspacePermission } from '../middleware/workspace.js'; +import { deleteWorkspaceWebsite } from '../model/workspace.js'; import { ROLES } from '@tianji/shared'; export const workspaceRouter = Router(); diff --git a/src/server/tests/seeds/website.ts b/src/server/tests/seeds/website.ts index b764951..621c3c8 100644 --- a/src/server/tests/seeds/website.ts +++ b/src/server/tests/seeds/website.ts @@ -1,7 +1,7 @@ -import { prisma } from '../../model/_client'; -import { hashUuid } from '../../utils/common'; +import { prisma } from '../../model/_client.js'; +import { hashUuid } from '../../utils/common.js'; import { faker } from '@faker-js/faker'; -import { getLocation } from '../../utils/detect'; +import { getLocation } from '../../utils/detect.js'; import dayjs from 'dayjs'; import { WebsiteSession } from '@prisma/client'; diff --git a/src/server/tests/utils.ts b/src/server/tests/utils.ts index f9f4aa7..d2bb551 100644 --- a/src/server/tests/utils.ts +++ b/src/server/tests/utils.ts @@ -1,9 +1,9 @@ import supertest from 'supertest'; import { afterAll } from 'vitest'; -import { app } from '../app'; -import { prisma } from '../model/_client'; +import { app } from '../app.js'; +import { prisma } from '../model/_client.js'; import { PrismaPromise } from '@prisma/client'; -import { createUser } from '../model/user'; +import { createUser } from '../model/user.js'; import { nanoid } from 'nanoid'; export function createTestContext() { diff --git a/src/server/trpc/index.ts b/src/server/trpc/index.ts index 6834d2e..87f4972 100644 --- a/src/server/trpc/index.ts +++ b/src/server/trpc/index.ts @@ -1,11 +1,13 @@ import * as trpcExpress from '@trpc/server/adapters/express'; -import { createContext } from './trpc'; -import { appRouter } from './routers'; +import { createContext } from './trpc.js'; +import { appRouter } from './routers/index.js'; import { createOpenApiHttpHandler, generateOpenApiDocument, } from 'trpc-openapi'; -import { version } from '../../../package.json'; +const packageJson = await import('../../../package.json', { + assert: { type: 'json' }, +}); export type { inferRouterInputs, inferRouterOutputs } from '@trpc/server'; @@ -20,7 +22,7 @@ export const trpcExpressMiddleware = trpcExpress.createExpressMiddleware({ export const trpcOpenapiHttpHandler = createOpenApiHttpHandler({ router: appRouter, createContext, -}); +} as any); const description = `

Insight into everything

@@ -29,6 +31,6 @@ const description = ` export const trpcOpenapiDocument = generateOpenApiDocument(appRouter, { title: 'Tianji OpenAPI', description, - version: `v${version}`, + version: `v${packageJson.default.version}`, baseUrl: 'http://localhost:12345/open', }); diff --git a/src/server/trpc/routers/auditLog.ts b/src/server/trpc/routers/auditLog.ts index a3a9315..56d6ac3 100644 --- a/src/server/trpc/routers/auditLog.ts +++ b/src/server/trpc/routers/auditLog.ts @@ -1,9 +1,9 @@ import { z } from 'zod'; -import { OpenApiMetaInfo, router, workspaceProcedure } from '../trpc'; -import { OPENAPI_TAG } from '../../utils/const'; -import { WorkspaceAuditLogModelSchema } from '../../prisma/zod'; -import { prisma } from '../../model/_client'; -import { fetchDataByCursor } from '../../utils/prisma'; +import { OpenApiMetaInfo, router, workspaceProcedure } from '../trpc.js'; +import { OPENAPI_TAG } from '../../utils/const.js'; +import { WorkspaceAuditLogModelSchema } from '../../prisma/zod/index.js'; +import { prisma } from '../../model/_client.js'; +import { fetchDataByCursor } from '../../utils/prisma.js'; import { OpenApiMeta } from 'trpc-openapi'; export const auditLogRouter = router({ diff --git a/src/server/trpc/routers/billing.ts b/src/server/trpc/routers/billing.ts index d07f7a9..11fe132 100644 --- a/src/server/trpc/routers/billing.ts +++ b/src/server/trpc/routers/billing.ts @@ -1,7 +1,7 @@ import { z } from 'zod'; -import { OpenApiMetaInfo, router, workspaceProcedure } from '../trpc'; -import { OPENAPI_TAG } from '../../utils/const'; -import { prisma } from '../../model/_client'; +import { OpenApiMetaInfo, router, workspaceProcedure } from '../trpc.js'; +import { OPENAPI_TAG } from '../../utils/const.js'; +import { prisma } from '../../model/_client.js'; import { OpenApiMeta } from 'trpc-openapi'; export const billingRouter = router({ diff --git a/src/server/trpc/routers/feed/index.ts b/src/server/trpc/routers/feed/index.ts index 3e5b2ac..5924870 100644 --- a/src/server/trpc/routers/feed/index.ts +++ b/src/server/trpc/routers/feed/index.ts @@ -5,18 +5,21 @@ import { router, workspaceOwnerProcedure, workspaceProcedure, -} from '../../trpc'; -import { OPENAPI_TAG } from '../../../utils/const'; +} from '../../trpc.js'; +import { OPENAPI_TAG } from '../../../utils/const.js'; import { OpenApiMeta } from 'trpc-openapi'; import { FeedChannelModelSchema, FeedEventModelSchema, -} from '../../../prisma/zod'; -import { prisma } from '../../../model/_client'; +} from '../../../prisma/zod/index.js'; +import { prisma } from '../../../model/_client.js'; import _ from 'lodash'; -import { buildFeedPublicOpenapi, feedIntegrationRouter } from './integration'; -import { fetchDataByCursor } from '../../../utils/prisma'; -import { delFeedEventNotifyCache } from '../../../model/feed/event'; +import { + buildFeedPublicOpenapi, + feedIntegrationRouter, +} from './integration.js'; +import { fetchDataByCursor } from '../../../utils/prisma.js'; +import { delFeedEventNotifyCache } from '../../../model/feed/event.js'; export const feedRouter = router({ channels: workspaceProcedure diff --git a/src/server/trpc/routers/feed/integration.ts b/src/server/trpc/routers/feed/integration.ts index 86224e5..a4411fc 100644 --- a/src/server/trpc/routers/feed/integration.ts +++ b/src/server/trpc/routers/feed/integration.ts @@ -1,11 +1,11 @@ import { z } from 'zod'; -import { OpenApiMetaInfo, publicProcedure, router } from '../../trpc'; -import { prisma } from '../../../model/_client'; +import { OpenApiMetaInfo, publicProcedure, router } from '../../trpc.js'; +import { prisma } from '../../../model/_client.js'; import _ from 'lodash'; import { OpenApiMeta } from 'trpc-openapi'; -import { OPENAPI_TAG } from '../../../utils/const'; -import { createFeedEvent } from '../../../model/feed/event'; -import { tencentCloudAlarmSchema } from '../../../model/_schema/feed'; +import { OPENAPI_TAG } from '../../../utils/const.js'; +import { createFeedEvent } from '../../../model/feed/event.js'; +import { tencentCloudAlarmSchema } from '../../../model/_schema/feed.js'; export const feedIntegrationRouter = router({ github: publicProcedure diff --git a/src/server/trpc/routers/global.ts b/src/server/trpc/routers/global.ts index 80d12d9..d03b936 100644 --- a/src/server/trpc/routers/global.ts +++ b/src/server/trpc/routers/global.ts @@ -1,7 +1,7 @@ import { z } from 'zod'; -import { publicProcedure, router } from '../trpc'; -import { OPENAPI_TAG } from '../../utils/const'; -import { env } from '../../utils/env'; +import { publicProcedure, router } from '../trpc.js'; +import { OPENAPI_TAG } from '../../utils/const.js'; +import { env } from '../../utils/env.js'; export const globalRouter = router({ config: publicProcedure diff --git a/src/server/trpc/routers/index.ts b/src/server/trpc/routers/index.ts index c15dd52..7a9b002 100644 --- a/src/server/trpc/routers/index.ts +++ b/src/server/trpc/routers/index.ts @@ -1,16 +1,16 @@ -import { router } from '../trpc'; -import { notificationRouter } from './notification'; -import { websiteRouter } from './website'; -import { monitorRouter } from './monitor'; -import { userRouter } from './user'; -import { workspaceRouter } from './workspace'; -import { globalRouter } from './global'; -import { serverStatusRouter } from './serverStatus'; -import { auditLogRouter } from './auditLog'; -import { billingRouter } from './billing'; -import { telemetryRouter } from './telemetry'; -import { surveyRouter } from './survey'; -import { feedRouter } from './feed'; +import { router } from '../trpc.js'; +import { notificationRouter } from './notification.js'; +import { websiteRouter } from './website.js'; +import { monitorRouter } from './monitor.js'; +import { userRouter } from './user.js'; +import { workspaceRouter } from './workspace.js'; +import { globalRouter } from './global.js'; +import { serverStatusRouter } from './serverStatus.js'; +import { auditLogRouter } from './auditLog.js'; +import { billingRouter } from './billing.js'; +import { telemetryRouter } from './telemetry.js'; +import { surveyRouter } from './survey.js'; +import { feedRouter } from './feed/index.js'; export const appRouter = router({ global: globalRouter, diff --git a/src/server/trpc/routers/monitor.ts b/src/server/trpc/routers/monitor.ts index 945e9fa..a4fb064 100644 --- a/src/server/trpc/routers/monitor.ts +++ b/src/server/trpc/routers/monitor.ts @@ -4,34 +4,34 @@ import { router, workspaceOwnerProcedure, workspaceProcedure, -} from '../trpc'; -import { prisma } from '../../model/_client'; +} from '../trpc.js'; +import { prisma } from '../../model/_client.js'; import { z } from 'zod'; import { getMonitorData, getMonitorPublicInfos, getMonitorRecentData, monitorManager, -} from '../../model/monitor'; +} from '../../model/monitor/index.js'; import dayjs from 'dayjs'; import { monitorEventSchema, monitorInfoWithNotificationIdSchema, monitorStatusSchema, -} from '../../model/_schema'; -import { OPENAPI_TAG } from '../../utils/const'; +} from '../../model/_schema/index.js'; +import { OPENAPI_TAG } from '../../utils/const.js'; import { OpenApiMeta } from 'trpc-openapi'; import { MonitorModelSchema, MonitorStatusPageModelSchema, -} from '../../prisma/zod'; -import { runCodeInVM } from '../../model/monitor/provider/custom'; -import { createAuditLog } from '../../model/auditLog'; +} from '../../prisma/zod/index.js'; +import { runCodeInVM } from '../../model/monitor/provider/custom.js'; +import { createAuditLog } from '../../model/auditLog.js'; import { MonitorInfoWithNotificationIds, monitorPublicInfoSchema, -} from '../../model/_schema/monitor'; -import { monitorPageManager } from '../../model/monitor/page/manager'; +} from '../../model/_schema/monitor.js'; +import { monitorPageManager } from '../../model/monitor/page/manager.js'; export const monitorRouter = router({ all: workspaceProcedure diff --git a/src/server/trpc/routers/notification.ts b/src/server/trpc/routers/notification.ts index 42602b2..d1dbd1f 100644 --- a/src/server/trpc/routers/notification.ts +++ b/src/server/trpc/routers/notification.ts @@ -1,8 +1,12 @@ -import { router, workspaceOwnerProcedure, workspaceProcedure } from '../trpc'; +import { + router, + workspaceOwnerProcedure, + workspaceProcedure, +} from '../trpc.js'; import { z } from 'zod'; -import { prisma } from '../../model/_client'; -import { sendNotification } from '../../model/notification'; -import { token } from '../../model/notification/token'; +import { prisma } from '../../model/_client.js'; +import { sendNotification } from '../../model/notification/index.js'; +import { token } from '../../model/notification/token/index.js'; export const notificationRouter = router({ all: workspaceProcedure.query(({ input }) => { diff --git a/src/server/trpc/routers/serverStatus.ts b/src/server/trpc/routers/serverStatus.ts index 7472017..555c9a6 100644 --- a/src/server/trpc/routers/serverStatus.ts +++ b/src/server/trpc/routers/serverStatus.ts @@ -1,5 +1,5 @@ -import { router, workspaceOwnerProcedure } from '../trpc'; -import { clearOfflineServerStatus } from '../../model/serverStatus'; +import { router, workspaceOwnerProcedure } from '../trpc.js'; +import { clearOfflineServerStatus } from '../../model/serverStatus.js'; export const serverStatusRouter = router({ clearOfflineServerStatus: workspaceOwnerProcedure.mutation( diff --git a/src/server/trpc/routers/survey.ts b/src/server/trpc/routers/survey.ts index af3ee16..5ee8e87 100644 --- a/src/server/trpc/routers/survey.ts +++ b/src/server/trpc/routers/survey.ts @@ -5,16 +5,19 @@ import { router, workspaceOwnerProcedure, workspaceProcedure, -} from '../trpc'; -import { OPENAPI_TAG } from '../../utils/const'; -import { prisma } from '../../model/_client'; -import { SurveyModelSchema, SurveyResultModelSchema } from '../../prisma/zod'; +} from '../trpc.js'; +import { OPENAPI_TAG } from '../../utils/const.js'; +import { prisma } from '../../model/_client.js'; +import { + SurveyModelSchema, + SurveyResultModelSchema, +} from '../../prisma/zod/index.js'; import { OpenApiMeta } from 'trpc-openapi'; -import { hashUuid } from '../../utils/common'; -import { getRequestInfo } from '../../utils/detect'; -import { SurveyPayloadSchema } from '../../prisma/zod/schemas'; -import { buildCursorResponseSchema } from '../../utils/schema'; -import { fetchDataByCursor } from '../../utils/prisma'; +import { hashUuid } from '../../utils/common.js'; +import { getRequestInfo } from '../../utils/detect.js'; +import { SurveyPayloadSchema } from '../../prisma/zod/schemas/index.js'; +import { buildCursorResponseSchema } from '../../utils/schema.js'; +import { fetchDataByCursor } from '../../utils/prisma.js'; import { Prisma } from '@prisma/client'; export const surveyRouter = router({ diff --git a/src/server/trpc/routers/telemetry.ts b/src/server/trpc/routers/telemetry.ts index 8e4c11e..9105eb5 100644 --- a/src/server/trpc/routers/telemetry.ts +++ b/src/server/trpc/routers/telemetry.ts @@ -4,21 +4,21 @@ import { router, workspaceOwnerProcedure, workspaceProcedure, -} from '../trpc'; +} from '../trpc.js'; import { EVENT_COLUMNS, FILTER_COLUMNS, OPENAPI_TAG, SESSION_COLUMNS, -} from '../../utils/const'; -import { prisma } from '../../model/_client'; -import { TelemetryModelSchema } from '../../prisma/zod'; +} from '../../utils/const.js'; +import { prisma } from '../../model/_client.js'; +import { TelemetryModelSchema } from '../../prisma/zod/index.js'; import { OpenApiMeta } from 'trpc-openapi'; import { baseFilterSchema, baseStatsSchema, statsItemType, -} from '../../model/_schema/filter'; +} from '../../model/_schema/filter.js'; import { getTelemetryPageview, getTelemetryPageviewMetrics, @@ -26,8 +26,8 @@ import { getTelemetrySessionMetrics, getTelemetryStats, getTelemetryUrlMetrics, -} from '../../model/telemetry'; -import { BaseQueryFilters } from '../../utils/prisma'; +} from '../../model/telemetry.js'; +import { BaseQueryFilters } from '../../utils/prisma.js'; import dayjs from 'dayjs'; export const telemetryRouter = router({ diff --git a/src/server/trpc/routers/user.ts b/src/server/trpc/routers/user.ts index b777bd8..398cce7 100644 --- a/src/server/trpc/routers/user.ts +++ b/src/server/trpc/routers/user.ts @@ -1,4 +1,4 @@ -import { protectProedure, publicProcedure, router } from '../trpc'; +import { protectProedure, publicProcedure, router } from '../trpc.js'; import { z } from 'zod'; import { authUser, @@ -7,12 +7,12 @@ import { createAdminUser, createUser, getUserCount, -} from '../../model/user'; -import { jwtSign } from '../../middleware/auth'; +} from '../../model/user.js'; +import { jwtSign } from '../../middleware/auth.js'; import { TRPCError } from '@trpc/server'; -import { env } from '../../utils/env'; -import { userInfoSchema } from '../../model/_schema/index'; -import { OPENAPI_TAG } from '../../utils/const'; +import { env } from '../../utils/env.js'; +import { userInfoSchema } from '../../model/_schema/index.js'; +import { OPENAPI_TAG } from '../../utils/const.js'; export const userRouter = router({ login: publicProcedure diff --git a/src/server/trpc/routers/website.ts b/src/server/trpc/routers/website.ts index 8438ec1..7f4d44a 100644 --- a/src/server/trpc/routers/website.ts +++ b/src/server/trpc/routers/website.ts @@ -3,35 +3,35 @@ import { router, workspaceOwnerProcedure, workspaceProcedure, -} from '../trpc'; +} from '../trpc.js'; import { z } from 'zod'; import { getWebsiteOnlineUserCount, getWorkspaceWebsitePageview, getWorkspaceWebsiteSession, getWorkspaceWebsiteStats, -} from '../../model/website'; -import { prisma } from '../../model/_client'; +} from '../../model/website.js'; +import { prisma } from '../../model/_client.js'; import { EVENT_COLUMNS, FILTER_COLUMNS, OPENAPI_TAG, SESSION_COLUMNS, -} from '../../utils/const'; -import { parseDateRange } from '../../utils/common'; +} from '../../utils/const.js'; +import { parseDateRange } from '../../utils/common.js'; import { getWebsiteSessionMetrics, getWebsitePageviewMetrics, -} from '../../model/website'; -import { websiteInfoSchema } from '../../model/_schema'; +} from '../../model/website.js'; +import { websiteInfoSchema } from '../../model/_schema/index.js'; import { OpenApiMeta } from 'trpc-openapi'; import { hostnameRegex } from '@tianji/shared'; import { websiteFilterSchema, websiteStatsSchema, -} from '../../model/_schema/filter'; +} from '../../model/_schema/filter.js'; import dayjs from 'dayjs'; -import { WebsiteQueryFilters } from '../../utils/prisma'; +import { WebsiteQueryFilters } from '../../utils/prisma.js'; const websiteNameSchema = z.string().max(100); const websiteDomainSchema = z.union([ diff --git a/src/server/trpc/routers/workspace.ts b/src/server/trpc/routers/workspace.ts index 59b3f5e..ce20c5c 100644 --- a/src/server/trpc/routers/workspace.ts +++ b/src/server/trpc/routers/workspace.ts @@ -4,14 +4,14 @@ import { router, workspaceOwnerProcedure, workspaceProcedure, -} from '../trpc'; +} from '../trpc.js'; import { z } from 'zod'; -import { prisma } from '../../model/_client'; -import { workspaceDashboardLayoutSchema } from '../../model/_schema'; +import { prisma } from '../../model/_client.js'; +import { workspaceDashboardLayoutSchema } from '../../model/_schema/index.js'; import { Prisma } from '@prisma/client'; -import { OPENAPI_TAG } from '../../utils/const'; +import { OPENAPI_TAG } from '../../utils/const.js'; import { OpenApiMeta } from 'trpc-openapi'; -import { getServerCount } from '../../model/serverStatus'; +import { getServerCount } from '../../model/serverStatus.js'; export const workspaceRouter = router({ getUserWorkspaceRole: publicProcedure diff --git a/src/server/trpc/trpc.ts b/src/server/trpc/trpc.ts index 8b5de8b..9998017 100644 --- a/src/server/trpc/trpc.ts +++ b/src/server/trpc/trpc.ts @@ -1,8 +1,8 @@ import { initTRPC, inferAsyncReturnType, TRPCError } from '@trpc/server'; import _ from 'lodash'; import { z } from 'zod'; -import { jwtVerify } from '../middleware/auth'; -import { getWorkspaceUser } from '../model/workspace'; +import { jwtVerify } from '../middleware/auth.js'; +import { getWorkspaceUser } from '../model/workspace.js'; import { ROLES, SYSTEM_ROLES } from '@tianji/shared'; import type { IncomingMessage } from 'http'; import { OpenApiMeta } from 'trpc-openapi'; diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json index 44d78f8..9db9f8e 100644 --- a/src/server/tsconfig.json +++ b/src/server/tsconfig.json @@ -11,8 +11,10 @@ "baseUrl": ".", "skipLibCheck": true, "strict": true, + "noEmit": false, + "rootDirs": ["./", "../"], "typeRoots": ["types/", "node_modules/@types"] }, - "include": ["src/**/*.ts"], - "exclude": ["node_modules"] + "include": ["./**/*.ts", "../types/**/*.ts"], + "exclude": ["node_modules", "dist"] } diff --git a/src/server/tsconfig.server.json b/src/server/tsconfig.server.json deleted file mode 100644 index 540cf40..0000000 --- a/src/server/tsconfig.server.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["./**/*.ts", "../types/**/*.ts"], - "exclude": ["node_modules/**/*", "dist"], - "compilerOptions": { - "rootDirs": ["./", "../"], - "outDir": "./dist", - "noEmit": false - } -} diff --git a/src/server/udp/server.ts b/src/server/udp/server.ts index 56dd3f0..f87641d 100644 --- a/src/server/udp/server.ts +++ b/src/server/udp/server.ts @@ -1,6 +1,6 @@ import dgram from 'dgram'; -import { recordServerStatus } from '../model/serverStatus'; -import { logger } from '../utils/logger'; +import { recordServerStatus } from '../model/serverStatus.js'; +import { logger } from '../utils/logger.js'; export function initUdpServer(port: number) { const server = dgram.createSocket('udp4'); diff --git a/src/server/utils/__tests__/common.test.ts b/src/server/utils/__tests__/common.test.ts index 9bea001..86bbb67 100644 --- a/src/server/utils/__tests__/common.test.ts +++ b/src/server/utils/__tests__/common.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from 'vitest'; -import { md5 } from '../common'; +import { md5 } from '../common.js'; describe('md5', () => { test('normal test', async () => { diff --git a/src/server/utils/__tests__/detect.test.ts b/src/server/utils/__tests__/detect.test.ts index b5e9759..21a6eb3 100644 --- a/src/server/utils/__tests__/detect.test.ts +++ b/src/server/utils/__tests__/detect.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test } from 'vitest'; -import { getLocation } from '../detect'; +import { getLocation } from '../detect.js'; import fs from 'fs-extra'; -import { libraryPath } from '../lib'; +import { libraryPath } from '../lib.js'; describe.runIf(fs.existsSync(libraryPath.geoPath))('detect', () => { describe('getLocation', () => { diff --git a/src/server/utils/common.ts b/src/server/utils/common.ts index 656ebd3..9570a8b 100644 --- a/src/server/utils/common.ts +++ b/src/server/utils/common.ts @@ -1,15 +1,15 @@ import { v4, v5, validate } from 'uuid'; import crypto from 'crypto'; -import { DATA_TYPE } from './const'; -import { DynamicDataType } from './types'; +import { DATA_TYPE } from './const.js'; +import { DynamicDataType } from './types.js'; import dayjs from 'dayjs'; -import minMax from 'dayjs/plugin/minMax'; +import minMax from 'dayjs/plugin/minMax.js'; import jwt from 'jsonwebtoken'; import _ from 'lodash'; -import { getWorkspaceWebsiteDateRange } from '../model/workspace'; +import { getWorkspaceWebsiteDateRange } from '../model/workspace.js'; import { isCuid } from '@paralleldrive/cuid2'; import { getMinimumUnit } from '@tianji/shared'; -import { env } from './env'; +import { env } from './env.js'; export { isCuid }; diff --git a/src/server/utils/detect.ts b/src/server/utils/detect.ts index 8b7d913..17d8871 100644 --- a/src/server/utils/detect.ts +++ b/src/server/utils/detect.ts @@ -1,5 +1,5 @@ import { Request } from 'express'; -import type { WebsiteEventPayload } from '../model/website'; +import type { WebsiteEventPayload } from '../model/website.js'; import { getClientIp } from 'request-ip'; import isLocalhost from 'is-localhost-ip'; import { browserName, detectOS, OperatingSystem } from 'detect-browser'; @@ -9,9 +9,9 @@ import { LAPTOP_SCREEN_WIDTH, MOBILE_OS, MOBILE_SCREEN_WIDTH, -} from './const'; +} from './const.js'; import maxmind, { Reader, CityResponse } from 'maxmind'; -import { libraryPath } from './lib'; +import { libraryPath } from './lib.js'; import { IncomingMessage } from 'http'; import { parse as pareseAcceptLanguage } from 'accept-language-parser'; diff --git a/src/server/utils/prisma.ts b/src/server/utils/prisma.ts index a834b7f..02efc1f 100644 --- a/src/server/utils/prisma.ts +++ b/src/server/utils/prisma.ts @@ -1,10 +1,10 @@ import { Prisma } from '@prisma/client'; import dayjs from 'dayjs'; import _ from 'lodash'; -import { loadWebsite } from '../model/website'; -import { maxDate } from './common'; -import { FILTER_COLUMNS, OPERATORS, SESSION_COLUMNS } from './const'; -import { loadTelemetry } from '../model/telemetry'; +import { loadWebsite } from '../model/website.js'; +import { maxDate } from './common.js'; +import { FILTER_COLUMNS, OPERATORS, SESSION_COLUMNS } from './const.js'; +import { loadTelemetry } from '../model/telemetry.js'; const POSTGRESQL_DATE_FORMATS = { minute: 'YYYY-MM-DD HH24:MI:00', diff --git a/src/server/utils/screenshot/website.ts b/src/server/utils/screenshot/website.ts index 0b4e7e3..a03e5b9 100644 --- a/src/server/utils/screenshot/website.ts +++ b/src/server/utils/screenshot/website.ts @@ -1,7 +1,7 @@ import puppeteer from 'puppeteer'; -import { jwtSign } from '../../middleware/auth'; +import { jwtSign } from '../../middleware/auth.js'; import { SYSTEM_ROLES } from '@tianji/shared'; -import { env } from '../env'; +import { env } from '../env.js'; /** * take a screenshot for website detail diff --git a/src/server/utils/types.ts b/src/server/utils/types.ts index 8fe0b41..ffae137 100644 --- a/src/server/utils/types.ts +++ b/src/server/utils/types.ts @@ -1,4 +1,4 @@ -import { DATA_TYPE } from './const'; +import { DATA_TYPE } from './const.js'; type ObjectValues = T[keyof T]; export type DynamicDataType = ObjectValues; diff --git a/src/server/ws/index.ts b/src/server/ws/index.ts index 4db434c..55b17dd 100644 --- a/src/server/ws/index.ts +++ b/src/server/ws/index.ts @@ -1,9 +1,9 @@ import { Server as SocketIOServer } from 'socket.io'; import { Server as HTTPServer } from 'http'; -import { jwtVerify } from '../middleware/auth'; -import { socketEventBus } from './shared'; -import { isCuid } from '../utils/common'; -import { logger } from '../utils/logger'; +import { jwtVerify } from '../middleware/auth.js'; +import { socketEventBus } from './shared.js'; +import { isCuid } from '../utils/common.js'; +import { logger } from '../utils/logger.js'; export function initSocketio(httpServer: HTTPServer) { const io = new SocketIOServer(httpServer, { diff --git a/src/server/ws/shared.ts b/src/server/ws/shared.ts index b60382f..cdab798 100644 --- a/src/server/ws/shared.ts +++ b/src/server/ws/shared.ts @@ -1,8 +1,8 @@ import { EventEmitter } from 'eventemitter-strict'; import { Socket } from 'socket.io'; -import { MaybePromise, ServerStatusInfo } from '../../types'; +import { MaybePromise, ServerStatusInfo } from '../../types/index.js'; import { FeedEvent, MonitorData } from '@prisma/client'; -import { Serialize } from '../types/utils'; +import { Serialize } from '../types/utils.js'; type SubscribeEventFn = (workspaceId: string, eventData: T) => void; diff --git a/src/shared/tsup.config.ts b/src/shared/tsup.config.ts index 3c3ccba..2342251 100644 --- a/src/shared/tsup.config.ts +++ b/src/shared/tsup.config.ts @@ -12,6 +12,5 @@ export default defineConfig((options) => { tsconfig: 'tsconfig.json', splitting: false, sourcemap: true, - external: ['react'], }; }); diff --git a/src/types/index.ts b/src/types/index.ts index e7f5d5e..461a0ec 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,3 +1,3 @@ -export type * from './server'; -export type * from './monitor'; -export type * from './utils'; +export type * from './server.js'; +export type * from './monitor.js'; +export type * from './utils.js'; diff --git a/src/types/monitor.ts b/src/types/monitor.ts index b95517f..9b8877e 100644 --- a/src/types/monitor.ts +++ b/src/types/monitor.ts @@ -1,5 +1,5 @@ -import type { MonitorModelSchema } from '../server/prisma/zod'; -import { ExactType } from './utils'; +import type { MonitorModelSchema } from '../server/prisma/zod/index.js'; +import type { ExactType } from './utils.js'; import z from 'zod'; type Monitor = z.infer;