phecda-server 1.4.1 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ import { resolve } from "path";
6
6
  import { createUnplugin } from "unplugin";
7
7
 
8
8
  // src/compiler.ts
9
- var Pcompiler = class {
9
+ var Compiler = class {
10
10
  classMap = {};
11
11
  name;
12
12
  constructor() {
@@ -45,7 +45,7 @@ return ret
45
45
  `;
46
46
  }
47
47
  };
48
- __name(Pcompiler, "Pcompiler");
48
+ __name(Compiler, "Compiler");
49
49
  function genParams(decorators) {
50
50
  return decorators.map((_, i) => {
51
51
  return `${`arg${i}`}`;
@@ -82,15 +82,17 @@ var unplugin = createUnplugin((options = {}) => {
82
82
  },
83
83
  transform(code) {
84
84
  const meta = JSON.parse(code);
85
- const compiler = new Pcompiler();
85
+ const compiler = new Compiler();
86
86
  for (const i of meta)
87
87
  compiler.addMethod(i);
88
- this.emitFile({
89
- type: "asset",
90
- fileName: `${compiler.name}.client.ts`,
91
- needsCodeReference: false,
92
- source: compiler.createRequest()
93
- });
88
+ if (command !== "serve") {
89
+ this.emitFile({
90
+ type: "asset",
91
+ fileName: `${compiler.name}.client.ts`,
92
+ needsCodeReference: false,
93
+ source: compiler.createRequest()
94
+ });
95
+ }
94
96
  return {
95
97
  code: compiler.getContent()
96
98
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/unplugin/unplugin.ts","../../src/compiler.ts"],"sourcesContent":["import { resolve } from 'path'\nimport { createUnplugin } from 'unplugin'\nimport { Pcompiler } from '../compiler'\nimport type { ServerMeta } from '../types'\n\nexport const unplugin = createUnplugin((options: { localPath?: string } = {}) => {\n const { localPath = 'pmeta.js' } = options\n\n let command: string\n const metaPath = resolve(process.cwd(), localPath).replace(/\\\\/g, '/')\n\n return {\n name: 'phecda-server:client',\n enforce: 'pre',\n vite: {\n configResolved(config) {\n command = config.command\n },\n\n buildStart() {\n if (command !== 'serve') {\n this.emitFile({\n type: 'chunk',\n id: metaPath,\n fileName: localPath,\n preserveSignature: 'allow-extension',\n })\n }\n },\n\n },\n resolveId(id) {\n if (id.endsWith('.controller'))\n\n return metaPath\n },\n transform(code) {\n const meta = JSON.parse(code) as ServerMeta[]\n const compiler = new Pcompiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n\n this.emitFile({\n type: 'asset',\n fileName: `${compiler.name}.client.ts`,\n needsCodeReference: false,\n source: compiler.createRequest(),\n })\n\n return { code: compiler.getContent() }\n },\n\n transformInclude(id) {\n return id === metaPath\n },\n\n }\n})\n","import type { ServerMeta } from './types'\n\nexport class Pcompiler {\n classMap: Record<string, { [key: string]: string }> = {}\n name: string\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n createRequest() {\n let content = 'import {useC} from \\'phecda-server\\'\\n'\n for (const name in this.classMap)\n content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n return content\n }\n\n addMethod(args: ServerMeta) {\n const {\n route: {\n route = '/',\n type = 'get',\n } = {}, name, method, params, tag,\n } = args\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n this.name = name\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(${genParams(params)}){\nconst ret={tag:\"${tag}-${method}\",body:{},query:{},params:{},realParam:'',method:\"${type}\",url:\"${url}\"}\n${params.filter(item => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n}\n\nfunction genParams(decorators: any[]) {\n return decorators.map((_, i) => {\n return `${`arg${i}`}`\n }).join(',')\n}\n"],"mappings":";;;;AAAA,SAASA,eAAe;AACxB,SAASC,sBAAsB;;;ACCxB,IAAMC,YAAN,MAAMA;EACXC,WAAsD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E;AACJ,QAAMC,WAAWC,QAAQC,QAAQC,IAAG,GAAIL,SAAAA,EAAWM,QAAQ,OAAO,GAAA;AAElE,SAAO;IACLC,MAAM;IACNC,SAAS;IACTC,MAAM;MACJC,eAAeC,QAAQ;AACrBV,kBAAUU,OAAOV;MACnB;MAEAW,aAAa;AACX,YAAIX,YAAY,SAAS;AACvB,eAAKY,SAAS;YACZC,MAAM;YACNC,IAAIb;YACJc,UAAUhB;YACViB,mBAAmB;UACrB,CAAA;QACF;MACF;IAEF;IACAC,UAAUH,IAAI;AACZ,UAAIA,GAAGI,SAAS,aAAA;AAEd,eAAOjB;IACX;IACAkB,UAAUC,MAAM;AACd,YAAMC,OAAOC,KAAKC,MAAMH,IAAAA;AACxB,YAAMI,WAAW,IAAIC,UAAAA;AAErB,iBAAWC,KAAKL;AACdG,iBAASG,UAAUD,CAAAA;AAErB,WAAKd,SAAS;QACZC,MAAM;QACNE,UAAU,GAAGS,SAASlB;QACtBsB,oBAAoB;QACpBC,QAAQL,SAASM,cAAa;MAChC,CAAA;AAEA,aAAO;QAAEV,MAAMI,SAASO,WAAU;MAAG;IACvC;IAEAC,iBAAiBlB,IAAI;AACnB,aAAOA,OAAOb;IAChB;EAEF;AACF,CAAA;","names":["resolve","createUnplugin","Pcompiler","classMap","name","constructor","getContent","content","Object","values","reduce","p","c","createRequest","keys","join","addMethod","args","route","type","method","params","tag","url","replace","genParams","filter","item","key","i","decorators","map","_","unplugin","createUnplugin","options","localPath","command","metaPath","resolve","process","cwd","replace","name","enforce","vite","configResolved","config","buildStart","emitFile","type","id","fileName","preserveSignature","resolveId","endsWith","transform","code","meta","JSON","parse","compiler","Pcompiler","i","addMethod","needsCodeReference","source","createRequest","getContent","transformInclude"]}
1
+ {"version":3,"sources":["../../src/unplugin/unplugin.ts","../../src/compiler.ts"],"sourcesContent":["import { resolve } from 'path'\nimport { createUnplugin } from 'unplugin'\nimport { Compiler } from '../compiler'\nimport type { P } from '../types'\n\nexport const unplugin = createUnplugin((options: { localPath?: string } = {}) => {\n const { localPath = 'pmeta.js' } = options\n\n let command: string\n const metaPath = resolve(process.cwd(), localPath).replace(/\\\\/g, '/')\n\n return {\n name: 'phecda-server:client',\n enforce: 'pre',\n vite: {\n configResolved(config) {\n command = config.command\n },\n\n buildStart() {\n if (command !== 'serve') {\n this.emitFile({\n type: 'chunk',\n id: metaPath,\n fileName: localPath,\n preserveSignature: 'allow-extension',\n })\n }\n },\n\n },\n resolveId(id) {\n if (id.endsWith('.controller'))\n\n return metaPath\n },\n transform(code) {\n const meta = JSON.parse(code) as P.Meta[]\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n\n if (command !== 'serve') {\n this.emitFile({\n type: 'asset',\n fileName: `${compiler.name}.client.ts`,\n needsCodeReference: false,\n source: compiler.createRequest(),\n })\n }\n\n return { code: compiler.getContent() }\n },\n\n transformInclude(id) {\n return id === metaPath\n },\n\n }\n})\n","import type { P } from './types'\n\nexport class Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n name: string\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n createRequest() {\n let content = 'import {useC} from \\'phecda-server\\'\\n'\n for (const name in this.classMap)\n content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n return content\n }\n\n addMethod(args: P.Meta) {\n const {\n route: {\n route = '/',\n type = 'get',\n } = {}, name, method, params, tag,\n } = args\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n this.name = name\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(${genParams(params)}){\nconst ret={tag:\"${tag}-${method}\",body:{},query:{},params:{},realParam:'',method:\"${type}\",url:\"${url}\"}\n${params.filter(item => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n}\n\nfunction genParams(decorators: any[]) {\n return decorators.map((_, i) => {\n return `${`arg${i}`}`\n }).join(',')\n}\n"],"mappings":";;;;AAAA,SAASA,eAAe;AACxB,SAASC,sBAAsB;;;ACCxB,IAAMC,WAAN,MAAMA;EACXC,WAAsD,CAAC;EACvDC;EACAC,cAAc;EAAE;EAEhBC,aAAa;AACX,QAAIC,UAAU;AAEd,eAAWH,QAAQ,KAAKD,UAAU;AAChCI,iBAAW;uBACMH;cACTI,OAAOC,OAAO,KAAKN,SAASC,KAAK,EAAEM,OAAO,CAACC,GAAGC,MAAMD,IAAIC,CAAAA;;IAElE;AACA,WAAOL;EACT;EAEAM,gBAAgB;AACd,QAAIN,UAAU;AACd,eAAWH,QAAQ,KAAKD;AACtBI,iBAAW,iBAAiBC,OAAOM,KAAK,KAAKX,SAASC,KAAK,EAAEW,KAAK,GAAA,WAAcX;;AAClF,WAAOG;EACT;EAEAS,UAAUC,MAAc;AACtB,UAAM,EACJC,OAAO,EACLA,QAAQ,KACRC,OAAO,MAAK,IACV,CAAC,GAAGf,MAAMgB,QAAQC,QAAQC,IAAG,IAC/BL;AACJ,UAAMM,MAAML,MAAMM,QAAQ,iBAAiB,EAAA;AAC3C,SAAKpB,OAAOA;AACZ,QAAI,CAAC,KAAKD,SAASC;AACjB,WAAKD,SAASC,QAAQ,CAAC;AACzB,SAAKD,SAASC,MAAMgB,UAAU;MAC5BA,UAAUK,UAAUJ,MAAAA;kBACRC,OAAOF,2DAA2DD,cAAcI;EAChGF,OAAOK,OAAOC,CAAAA,SAAQA,KAAKC,GAAG,EAAElB,OAAO,CAACC,GAAGC,GAAGiB,MAAM,GAAGlB,QAAQC,EAAEO,QAAQP,EAAEgB,UAAUC;EAAMjB,EAAEO,SAAS,WAAW,yBAAyBU;IAAQ,MAAM,EAAA;;;;EAIxJ;AACF;AA3Ca3B;AA6Cb,SAASuB,UAAUK,YAAmB;AACpC,SAAOA,WAAWC,IAAI,CAACC,GAAGH,MAAM;AAC9B,WAAO,GAAG,MAAMA;EAClB,CAAA,EAAGd,KAAK,GAAA;AACV;AAJSU;;;AD1CF,IAAMQ,WAAWC,eAAe,CAACC,UAAkC,CAAC,MAAM;AAC/E,QAAM,EAAEC,YAAY,WAAU,IAAKD;AAEnC,MAAIE;AACJ,QAAMC,WAAWC,QAAQC,QAAQC,IAAG,GAAIL,SAAAA,EAAWM,QAAQ,OAAO,GAAA;AAElE,SAAO;IACLC,MAAM;IACNC,SAAS;IACTC,MAAM;MACJC,eAAeC,QAAQ;AACrBV,kBAAUU,OAAOV;MACnB;MAEAW,aAAa;AACX,YAAIX,YAAY,SAAS;AACvB,eAAKY,SAAS;YACZC,MAAM;YACNC,IAAIb;YACJc,UAAUhB;YACViB,mBAAmB;UACrB,CAAA;QACF;MACF;IAEF;IACAC,UAAUH,IAAI;AACZ,UAAIA,GAAGI,SAAS,aAAA;AAEd,eAAOjB;IACX;IACAkB,UAAUC,MAAM;AACd,YAAMC,OAAOC,KAAKC,MAAMH,IAAAA;AACxB,YAAMI,WAAW,IAAIC,SAAAA;AAErB,iBAAWC,KAAKL;AACdG,iBAASG,UAAUD,CAAAA;AAErB,UAAI1B,YAAY,SAAS;AACvB,aAAKY,SAAS;UACZC,MAAM;UACNE,UAAU,GAAGS,SAASlB;UACtBsB,oBAAoB;UACpBC,QAAQL,SAASM,cAAa;QAChC,CAAA;MACF;AAEA,aAAO;QAAEV,MAAMI,SAASO,WAAU;MAAG;IACvC;IAEAC,iBAAiBlB,IAAI;AACnB,aAAOA,OAAOb;IAChB;EAEF;AACF,CAAA;","names":["resolve","createUnplugin","Compiler","classMap","name","constructor","getContent","content","Object","values","reduce","p","c","createRequest","keys","join","addMethod","args","route","type","method","params","tag","url","replace","genParams","filter","item","key","i","decorators","map","_","unplugin","createUnplugin","options","localPath","command","metaPath","resolve","process","cwd","replace","name","enforce","vite","configResolved","config","buildStart","emitFile","type","id","fileName","preserveSignature","resolveId","endsWith","transform","code","meta","JSON","parse","compiler","Compiler","i","addMethod","needsCodeReference","source","createRequest","getContent","transformInclude"]}
@@ -30,7 +30,7 @@ var import_path = require("path");
30
30
  var import_unplugin = require("unplugin");
31
31
 
32
32
  // src/compiler.ts
33
- var Pcompiler = class {
33
+ var Compiler = class {
34
34
  classMap = {};
35
35
  name;
36
36
  constructor() {
@@ -69,7 +69,7 @@ return ret
69
69
  `;
70
70
  }
71
71
  };
72
- __name(Pcompiler, "Pcompiler");
72
+ __name(Compiler, "Compiler");
73
73
  function genParams(decorators) {
74
74
  return decorators.map((_, i) => {
75
75
  return `${`arg${i}`}`;
@@ -106,15 +106,17 @@ var unplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
106
106
  },
107
107
  transform(code) {
108
108
  const meta = JSON.parse(code);
109
- const compiler = new Pcompiler();
109
+ const compiler = new Compiler();
110
110
  for (const i of meta)
111
111
  compiler.addMethod(i);
112
- this.emitFile({
113
- type: "asset",
114
- fileName: `${compiler.name}.client.ts`,
115
- needsCodeReference: false,
116
- source: compiler.createRequest()
117
- });
112
+ if (command !== "serve") {
113
+ this.emitFile({
114
+ type: "asset",
115
+ fileName: `${compiler.name}.client.ts`,
116
+ needsCodeReference: false,
117
+ source: compiler.createRequest()
118
+ });
119
+ }
118
120
  return {
119
121
  code: compiler.getContent()
120
122
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/unplugin/vite.ts","../../src/unplugin/unplugin.ts","../../src/compiler.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\nimport { unplugin } from './unplugin'\nexport default unplugin.vite as (options?: { localPath?: string | undefined } | undefined) => PluginOption\n","import { resolve } from 'path'\nimport { createUnplugin } from 'unplugin'\nimport { Pcompiler } from '../compiler'\nimport type { ServerMeta } from '../types'\n\nexport const unplugin = createUnplugin((options: { localPath?: string } = {}) => {\n const { localPath = 'pmeta.js' } = options\n\n let command: string\n const metaPath = resolve(process.cwd(), localPath).replace(/\\\\/g, '/')\n\n return {\n name: 'phecda-server:client',\n enforce: 'pre',\n vite: {\n configResolved(config) {\n command = config.command\n },\n\n buildStart() {\n if (command !== 'serve') {\n this.emitFile({\n type: 'chunk',\n id: metaPath,\n fileName: localPath,\n preserveSignature: 'allow-extension',\n })\n }\n },\n\n },\n resolveId(id) {\n if (id.endsWith('.controller'))\n\n return metaPath\n },\n transform(code) {\n const meta = JSON.parse(code) as ServerMeta[]\n const compiler = new Pcompiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n\n this.emitFile({\n type: 'asset',\n fileName: `${compiler.name}.client.ts`,\n needsCodeReference: false,\n source: compiler.createRequest(),\n })\n\n return { code: compiler.getContent() }\n },\n\n transformInclude(id) {\n return id === metaPath\n },\n\n }\n})\n","import type { ServerMeta } from './types'\n\nexport class Pcompiler {\n classMap: Record<string, { [key: string]: string }> = {}\n name: string\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n createRequest() {\n let content = 'import {useC} from \\'phecda-server\\'\\n'\n for (const name in this.classMap)\n content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n return content\n }\n\n addMethod(args: ServerMeta) {\n const {\n route: {\n route = '/',\n type = 'get',\n } = {}, name, method, params, tag,\n } = args\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n this.name = name\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(${genParams(params)}){\nconst ret={tag:\"${tag}-${method}\",body:{},query:{},params:{},realParam:'',method:\"${type}\",url:\"${url}\"}\n${params.filter(item => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n}\n\nfunction genParams(decorators: any[]) {\n return decorators.map((_, i) => {\n return `${`arg${i}`}`\n }).join(',')\n}\n"],"mappings":";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;AD1CF,IAAMQ,eAAWC,gCAAe,CAACC,UAAkC,CAAC,MAAM;AAC/E,QAAM,EAAEC,YAAY,WAAU,IAAKD;AAEnC,MAAIE;AACJ,QAAMC,eAAWC,qBAAQC,QAAQC,IAAG,GAAIL,SAAAA,EAAWM,QAAQ,OAAO,GAAA;AAElE,SAAO;IACLC,MAAM;IACNC,SAAS;IACTC,MAAM;MACJC,eAAeC,QAAQ;AACrBV,kBAAUU,OAAOV;MACnB;MAEAW,aAAa;AACX,YAAIX,YAAY,SAAS;AACvB,eAAKY,SAAS;YACZC,MAAM;YACNC,IAAIb;YACJc,UAAUhB;YACViB,mBAAmB;UACrB,CAAA;QACF;MACF;IAEF;IACAC,UAAUH,IAAI;AACZ,UAAIA,GAAGI,SAAS,aAAA;AAEd,eAAOjB;IACX;IACAkB,UAAUC,MAAM;AACd,YAAMC,OAAOC,KAAKC,MAAMH,IAAAA;AACxB,YAAMI,WAAW,IAAIC,UAAAA;AAErB,iBAAWC,KAAKL;AACdG,iBAASG,UAAUD,CAAAA;AAErB,WAAKd,SAAS;QACZC,MAAM;QACNE,UAAU,GAAGS,SAASlB;QACtBsB,oBAAoB;QACpBC,QAAQL,SAASM,cAAa;MAChC,CAAA;AAEA,aAAO;QAAEV,MAAMI,SAASO,WAAU;MAAG;IACvC;IAEAC,iBAAiBlB,IAAI;AACnB,aAAOA,OAAOb;IAChB;EAEF;AACF,CAAA;;;ADxDA,IAAA,eAAegC,SAASC;","names":["Pcompiler","classMap","name","constructor","getContent","content","Object","values","reduce","p","c","createRequest","keys","join","addMethod","args","route","type","method","params","tag","url","replace","genParams","filter","item","key","i","decorators","map","_","unplugin","createUnplugin","options","localPath","command","metaPath","resolve","process","cwd","replace","name","enforce","vite","configResolved","config","buildStart","emitFile","type","id","fileName","preserveSignature","resolveId","endsWith","transform","code","meta","JSON","parse","compiler","Pcompiler","i","addMethod","needsCodeReference","source","createRequest","getContent","transformInclude","unplugin","vite"]}
1
+ {"version":3,"sources":["../../src/unplugin/vite.ts","../../src/unplugin/unplugin.ts","../../src/compiler.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\nimport { unplugin } from './unplugin'\nexport default unplugin.vite as (options?: { localPath?: string | undefined } | undefined) => PluginOption\n","import { resolve } from 'path'\nimport { createUnplugin } from 'unplugin'\nimport { Compiler } from '../compiler'\nimport type { P } from '../types'\n\nexport const unplugin = createUnplugin((options: { localPath?: string } = {}) => {\n const { localPath = 'pmeta.js' } = options\n\n let command: string\n const metaPath = resolve(process.cwd(), localPath).replace(/\\\\/g, '/')\n\n return {\n name: 'phecda-server:client',\n enforce: 'pre',\n vite: {\n configResolved(config) {\n command = config.command\n },\n\n buildStart() {\n if (command !== 'serve') {\n this.emitFile({\n type: 'chunk',\n id: metaPath,\n fileName: localPath,\n preserveSignature: 'allow-extension',\n })\n }\n },\n\n },\n resolveId(id) {\n if (id.endsWith('.controller'))\n\n return metaPath\n },\n transform(code) {\n const meta = JSON.parse(code) as P.Meta[]\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n\n if (command !== 'serve') {\n this.emitFile({\n type: 'asset',\n fileName: `${compiler.name}.client.ts`,\n needsCodeReference: false,\n source: compiler.createRequest(),\n })\n }\n\n return { code: compiler.getContent() }\n },\n\n transformInclude(id) {\n return id === metaPath\n },\n\n }\n})\n","import type { P } from './types'\n\nexport class Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n name: string\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n createRequest() {\n let content = 'import {useC} from \\'phecda-server\\'\\n'\n for (const name in this.classMap)\n content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n return content\n }\n\n addMethod(args: P.Meta) {\n const {\n route: {\n route = '/',\n type = 'get',\n } = {}, name, method, params, tag,\n } = args\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n this.name = name\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(${genParams(params)}){\nconst ret={tag:\"${tag}-${method}\",body:{},query:{},params:{},realParam:'',method:\"${type}\",url:\"${url}\"}\n${params.filter(item => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n}\n\nfunction genParams(decorators: any[]) {\n return decorators.map((_, i) => {\n return `${`arg${i}`}`\n }).join(',')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;ACDA,kBAAwB;AACxB,sBAA+B;;;ACCxB,IAAMA,WAAN,MAAMA;EACXC,WAAsD,CAAC;EACvDC;EACAC,cAAc;EAAE;EAEhBC,aAAa;AACX,QAAIC,UAAU;AAEd,eAAWH,QAAQ,KAAKD,UAAU;AAChCI,iBAAW;uBACMH;cACTI,OAAOC,OAAO,KAAKN,SAASC,KAAK,EAAEM,OAAO,CAACC,GAAGC,MAAMD,IAAIC,CAAAA;;IAElE;AACA,WAAOL;EACT;EAEAM,gBAAgB;AACd,QAAIN,UAAU;AACd,eAAWH,QAAQ,KAAKD;AACtBI,iBAAW,iBAAiBC,OAAOM,KAAK,KAAKX,SAASC,KAAK,EAAEW,KAAK,GAAA,WAAcX;;AAClF,WAAOG;EACT;EAEAS,UAAUC,MAAc;AACtB,UAAM,EACJC,OAAO,EACLA,QAAQ,KACRC,OAAO,MAAK,IACV,CAAC,GAAGf,MAAMgB,QAAQC,QAAQC,IAAG,IAC/BL;AACJ,UAAMM,MAAML,MAAMM,QAAQ,iBAAiB,EAAA;AAC3C,SAAKpB,OAAOA;AACZ,QAAI,CAAC,KAAKD,SAASC;AACjB,WAAKD,SAASC,QAAQ,CAAC;AACzB,SAAKD,SAASC,MAAMgB,UAAU;MAC5BA,UAAUK,UAAUJ,MAAAA;kBACRC,OAAOF,2DAA2DD,cAAcI;EACh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,aAAOA,OAAOb;IAChB;EAEF;AACF,CAAA;;;AD1DA,IAAA,eAAegC,SAASC;","names":["Compiler","classMap","name","constructor","getContent","content","Object","values","reduce","p","c","createRequest","keys","join","addMethod","args","route","type","method","params","tag","url","replace","genParams","filter","item","key","i","decorators","map","_","unplugin","createUnplugin","options","localPath","command","metaPath","resolve","process","cwd","replace","name","enforce","vite","configResolved","config","buildStart","emitFile","type","id","fileName","preserveSignature","resolveId","endsWith","transform","code","meta","JSON","parse","compiler","Compiler","i","addMethod","needsCodeReference","source","createRequest","getContent","transformInclude","unplugin","vite"]}
@@ -6,7 +6,7 @@ import { resolve } from "path";
6
6
  import { createUnplugin } from "unplugin";
7
7
 
8
8
  // src/compiler.ts
9
- var Pcompiler = class {
9
+ var Compiler = class {
10
10
  classMap = {};
11
11
  name;
12
12
  constructor() {
@@ -45,7 +45,7 @@ return ret
45
45
  `;
46
46
  }
47
47
  };
48
- __name(Pcompiler, "Pcompiler");
48
+ __name(Compiler, "Compiler");
49
49
  function genParams(decorators) {
50
50
  return decorators.map((_, i) => {
51
51
  return `${`arg${i}`}`;
@@ -82,15 +82,17 @@ var unplugin = createUnplugin((options = {}) => {
82
82
  },
83
83
  transform(code) {
84
84
  const meta = JSON.parse(code);
85
- const compiler = new Pcompiler();
85
+ const compiler = new Compiler();
86
86
  for (const i of meta)
87
87
  compiler.addMethod(i);
88
- this.emitFile({
89
- type: "asset",
90
- fileName: `${compiler.name}.client.ts`,
91
- needsCodeReference: false,
92
- source: compiler.createRequest()
93
- });
88
+ if (command !== "serve") {
89
+ this.emitFile({
90
+ type: "asset",
91
+ fileName: `${compiler.name}.client.ts`,
92
+ needsCodeReference: false,
93
+ source: compiler.createRequest()
94
+ });
95
+ }
94
96
  return {
95
97
  code: compiler.getContent()
96
98
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/unplugin/unplugin.ts","../../src/compiler.ts","../../src/unplugin/vite.ts"],"sourcesContent":["import { resolve } from 'path'\nimport { createUnplugin } from 'unplugin'\nimport { Pcompiler } from '../compiler'\nimport type { ServerMeta } from '../types'\n\nexport const unplugin = createUnplugin((options: { localPath?: string } = {}) => {\n const { localPath = 'pmeta.js' } = options\n\n let command: string\n const metaPath = resolve(process.cwd(), localPath).replace(/\\\\/g, '/')\n\n return {\n name: 'phecda-server:client',\n enforce: 'pre',\n vite: {\n configResolved(config) {\n command = config.command\n },\n\n buildStart() {\n if (command !== 'serve') {\n this.emitFile({\n type: 'chunk',\n id: metaPath,\n fileName: localPath,\n preserveSignature: 'allow-extension',\n })\n }\n },\n\n },\n resolveId(id) {\n if (id.endsWith('.controller'))\n\n return metaPath\n },\n transform(code) {\n const meta = JSON.parse(code) as ServerMeta[]\n const compiler = new Pcompiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n\n this.emitFile({\n type: 'asset',\n fileName: `${compiler.name}.client.ts`,\n needsCodeReference: false,\n source: compiler.createRequest(),\n })\n\n return { code: compiler.getContent() }\n },\n\n transformInclude(id) {\n return id === metaPath\n },\n\n }\n})\n","import type { ServerMeta } from './types'\n\nexport class Pcompiler {\n classMap: Record<string, { [key: string]: string }> = {}\n name: string\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n createRequest() {\n let content = 'import {useC} from \\'phecda-server\\'\\n'\n for (const name in this.classMap)\n content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n return content\n }\n\n addMethod(args: ServerMeta) {\n const {\n route: {\n route = '/',\n type = 'get',\n } = {}, name, method, params, tag,\n } = args\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n this.name = name\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(${genParams(params)}){\nconst ret={tag:\"${tag}-${method}\",body:{},query:{},params:{},realParam:'',method:\"${type}\",url:\"${url}\"}\n${params.filter(item => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n}\n\nfunction genParams(decorators: any[]) {\n return decorators.map((_, i) => {\n return `${`arg${i}`}`\n }).join(',')\n}\n","import type { PluginOption } from 'vite'\nimport { unplugin } from './unplugin'\nexport default unplugin.vite as (options?: { localPath?: string | undefined } | undefined) => PluginOption\n"],"mappings":";;;;AAAA,SAASA,eAAe;AACxB,SAASC,sBAAsB;;;ACCxB,IAAMC,YAAN,MAAMA;EACXC,WAAsD,CAAC;EACvDC;EACAC,cAAc;EAAE;EAEhBC,aAAa;AACX,QAAIC,UAAU;AAEd,eAAWH,QAAQ,KAAKD,UAAU;AAChCI,iBAAW;uBACMH;cACTI,OAAOC,OAAO,KAAKN,SAASC,KAAK,EAAEM,OAAO,CAACC,GAAGC,MAAMD,IAAIC,CAAAA;;IAElE;AACA,WAAOL;EACT;EAEAM,gBAAgB;AACd,QAAIN,UAAU;AACd,eAAWH,QAAQ,KAAKD;AACtBI,iBAAW,iBAAiBC,OAAOM,KAAK,KAAKX,SAASC,KAAK,EAAEW,KAAK,GAAA,WAAcX;;AAClF,WAAOG;EACT;EAEAS,UAAUC,MAAkB;AAC1B,UAAM,EACJC,OAAO,EACLA,QAAQ,KACRC,OAAO,MAAK,IACV,CAAC,GAAGf,MAAMgB,QAAQC,QAAQC,IAAG,IAC/BL;AACJ,UAAMM,MAAML,MAAMM,QAAQ,iBAAiB,EAAA;AAC3C,SAAKpB,OAAOA;AACZ,QAAI,CAAC,KAAKD,SAASC;AACjB,WAAKD,SAASC,QAAQ,CAAC;AACzB,SAAKD,SAASC,MAAMgB,UAAU;MAC5BA,UAAUK,UAAUJ,MAAAA;kBACRC,OAAOF,2DAA2DD,cAAcI;EAChGF,OAAOK,OAAOC,CAAAA,SAAQA,KAAKC,GAAG,EAAElB,OAAO,CAACC,GAAGC,GAAGiB,MAAM,GAAGlB,QAAQC,EAAEO,QAAQP,EAAEgB,UAAUC;EAAMjB,EAAEO,SAAS,WAAW,yBAAyBU;IAAQ,MAAM,EAAA;;;;EAIxJ;AACF;AA3Ca3B;AA6Cb,SAASuB,UAAUK,YAAmB;AACpC,SAAOA,WAAWC,IAAI,CAACC,GAAGH,MAAM;AAC9B,WAAO,GAAG,MAAMA;EAClB,CAAA,EAAGd,KAAK,GAAA;AACV;AAJSU;;;AD1CF,IAAMQ,WAAWC,eAAe,CAACC,UAAkC,CAAC,MAAM;AAC/E,QAAM,EAAEC,YAAY,WAAU,IAAKD;AAEnC,MAAIE;AACJ,QAAMC,WAAWC,QAAQC,QAAQC,IAAG,GAAIL,SAAAA,EAAWM,QAAQ,OAAO,GAAA;AAElE,SAAO;IACLC,MAAM;IACNC,SAAS;IACTC,MAAM;MACJC,eAAeC,QAAQ;AACrBV,kBAAUU,OAAOV;MACnB;MAEAW,aAAa;AACX,YAAIX,YAAY,SAAS;AACvB,eAAKY,SAAS;YACZC,MAAM;YACNC,IAAIb;YACJc,UAAUhB;YACViB,mBAAmB;UACrB,CAAA;QACF;MACF;IAEF;IACAC,UAAUH,IAAI;AACZ,UAAIA,GAAGI,SAAS,aAAA;AAEd,eAAOjB;IACX;IACAkB,UAAUC,MAAM;AACd,YAAMC,OAAOC,KAAKC,MAAMH,IAAAA;AACxB,YAAMI,WAAW,IAAIC,UAAAA;AAErB,iBAAWC,KAAKL;AACdG,iBAASG,UAAUD,CAAAA;AAErB,WAAKd,SAAS;QACZC,MAAM;QACNE,UAAU,GAAGS,SAASlB;QACtBsB,oBAAoB;QACpBC,QAAQL,SAASM,cAAa;MAChC,CAAA;AAEA,aAAO;QAAEV,MAAMI,SAASO,WAAU;MAAG;IACvC;IAEAC,iBAAiBlB,IAAI;AACnB,aAAOA,OAAOb;IAChB;EAEF;AACF,CAAA;;;AExDA,IAAA,eAAegC,SAASC;","names":["resolve","createUnplugin","Pcompiler","classMap","name","constructor","getContent","content","Object","values","reduce","p","c","createRequest","keys","join","addMethod","args","route","type","method","params","tag","url","replace","genParams","filter","item","key","i","decorators","map","_","unplugin","createUnplugin","options","localPath","command","metaPath","resolve","process","cwd","replace","name","enforce","vite","configResolved","config","buildStart","emitFile","type","id","fileName","preserveSignature","resolveId","endsWith","transform","code","meta","JSON","parse","compiler","Pcompiler","i","addMethod","needsCodeReference","source","createRequest","getContent","transformInclude","unplugin","vite"]}
1
+ {"version":3,"sources":["../../src/unplugin/unplugin.ts","../../src/compiler.ts","../../src/unplugin/vite.ts"],"sourcesContent":["import { resolve } from 'path'\nimport { createUnplugin } from 'unplugin'\nimport { Compiler } from '../compiler'\nimport type { P } from '../types'\n\nexport const unplugin = createUnplugin((options: { localPath?: string } = {}) => {\n const { localPath = 'pmeta.js' } = options\n\n let command: string\n const metaPath = resolve(process.cwd(), localPath).replace(/\\\\/g, '/')\n\n return {\n name: 'phecda-server:client',\n enforce: 'pre',\n vite: {\n configResolved(config) {\n command = config.command\n },\n\n buildStart() {\n if (command !== 'serve') {\n this.emitFile({\n type: 'chunk',\n id: metaPath,\n fileName: localPath,\n preserveSignature: 'allow-extension',\n })\n }\n },\n\n },\n resolveId(id) {\n if (id.endsWith('.controller'))\n\n return metaPath\n },\n transform(code) {\n const meta = JSON.parse(code) as P.Meta[]\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n\n if (command !== 'serve') {\n this.emitFile({\n type: 'asset',\n fileName: `${compiler.name}.client.ts`,\n needsCodeReference: false,\n source: compiler.createRequest(),\n })\n }\n\n return { code: compiler.getContent() }\n },\n\n transformInclude(id) {\n return id === metaPath\n },\n\n }\n})\n","import type { P } from './types'\n\nexport class Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n name: string\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n createRequest() {\n let content = 'import {useC} from \\'phecda-server\\'\\n'\n for (const name in this.classMap)\n content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n return content\n }\n\n addMethod(args: P.Meta) {\n const {\n route: {\n route = '/',\n type = 'get',\n } = {}, name, method, params, tag,\n } = args\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n this.name = name\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(${genParams(params)}){\nconst ret={tag:\"${tag}-${method}\",body:{},query:{},params:{},realParam:'',method:\"${type}\",url:\"${url}\"}\n${params.filter(item => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n}\n\nfunction genParams(decorators: any[]) {\n return decorators.map((_, i) => {\n return `${`arg${i}`}`\n }).join(',')\n}\n","import type { PluginOption } from 'vite'\nimport { unplugin } from './unplugin'\nexport default unplugin.vite as (options?: { localPath?: string | undefined } | undefined) => PluginOption\n"],"mappings":";;;;AAAA,SAASA,eAAe;AACxB,SAASC,sBAAsB;;;ACCxB,IAAMC,WAAN,MAAMA;EACXC,WAAsD,CAAC;EACvDC;EACAC,cAAc;EAAE;EAEhBC,aAAa;AACX,QAAIC,UAAU;AAEd,eAAWH,QAAQ,KAAKD,UAAU;AAChCI,iBAAW;uBACMH;cACTI,OAAOC,OAAO,KAAKN,SAASC,KAAK,EAAEM,OAAO,CAACC,GAAGC,MAAMD,IAAIC,CAAAA;;IAElE;AACA,WAAOL;EACT;EAEAM,gBAAgB;AACd,QAAIN,UAAU;AACd,eAAWH,QAAQ,KAAKD;AACtBI,iBAAW,iBAAiBC,OAAOM,KAAK,KAAKX,SAASC,KAAK,EAAEW,KAAK,GAAA,WAAcX;;AAClF,WAAOG;EACT;EAEAS,UAAUC,MAAc;AACtB,UAAM,EACJC,OAAO,EACLA,QAAQ,KACRC,OAAO,MAAK,IACV,CAAC,GAAGf,MAAMgB,QAAQC,QAAQC,IA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BAASG,UAAUD,CAAAA;AAErB,UAAI1B,YAAY,SAAS;AACvB,aAAKY,SAAS;UACZC,MAAM;UACNE,UAAU,GAAGS,SAASlB;UACtBsB,oBAAoB;UACpBC,QAAQL,SAASM,cAAa;QAChC,CAAA;MACF;AAEA,aAAO;QAAEV,MAAMI,SAASO,WAAU;MAAG;IACvC;IAEAC,iBAAiBlB,IAAI;AACnB,aAAOA,OAAOb;IAChB;EAEF;AACF,CAAA;;;AE1DA,IAAA,eAAegC,SAASC;","names":["resolve","createUnplugin","Compiler","classMap","name","constructor","getContent","content","Object","values","reduce","p","c","createRequest","keys","join","addMethod","args","route","type","method","params","tag","url","replace","genParams","filter","item","key","i","decorators","map","_","unplugin","createUnplugin","options","localPath","command","metaPath","resolve","process","cwd","replace","name","enforce","vite","configResolved","config","buildStart","emitFile","type","id","fileName","preserveSignature","resolveId","endsWith","transform","code","meta","JSON","parse","compiler","Compiler","i","addMethod","needsCodeReference","source","createRequest","getContent","transformInclude","unplugin","vite"]}
@@ -30,7 +30,7 @@ var import_path = require("path");
30
30
  var import_unplugin = require("unplugin");
31
31
 
32
32
  // src/compiler.ts
33
- var Pcompiler = class {
33
+ var Compiler = class {
34
34
  classMap = {};
35
35
  name;
36
36
  constructor() {
@@ -69,7 +69,7 @@ return ret
69
69
  `;
70
70
  }
71
71
  };
72
- __name(Pcompiler, "Pcompiler");
72
+ __name(Compiler, "Compiler");
73
73
  function genParams(decorators) {
74
74
  return decorators.map((_, i) => {
75
75
  return `${`arg${i}`}`;
@@ -106,15 +106,17 @@ var unplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
106
106
  },
107
107
  transform(code) {
108
108
  const meta = JSON.parse(code);
109
- const compiler = new Pcompiler();
109
+ const compiler = new Compiler();
110
110
  for (const i of meta)
111
111
  compiler.addMethod(i);
112
- this.emitFile({
113
- type: "asset",
114
- fileName: `${compiler.name}.client.ts`,
115
- needsCodeReference: false,
116
- source: compiler.createRequest()
117
- });
112
+ if (command !== "serve") {
113
+ this.emitFile({
114
+ type: "asset",
115
+ fileName: `${compiler.name}.client.ts`,
116
+ needsCodeReference: false,
117
+ source: compiler.createRequest()
118
+ });
119
+ }
118
120
  return {
119
121
  code: compiler.getContent()
120
122
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/unplugin/webpack.ts","../../src/unplugin/unplugin.ts","../../src/compiler.ts"],"sourcesContent":["import { unplugin } from './unplugin'\n\nexport const Server = unplugin.webpack\n","import { resolve } from 'path'\nimport { createUnplugin } from 'unplugin'\nimport { Pcompiler } from '../compiler'\nimport type { ServerMeta } from '../types'\n\nexport const unplugin = createUnplugin((options: { localPath?: string } = {}) => {\n const { localPath = 'pmeta.js' } = options\n\n let command: string\n const metaPath = resolve(process.cwd(), localPath).replace(/\\\\/g, '/')\n\n return {\n name: 'phecda-server:client',\n enforce: 'pre',\n vite: {\n configResolved(config) {\n command = config.command\n },\n\n buildStart() {\n if (command !== 'serve') {\n this.emitFile({\n type: 'chunk',\n id: metaPath,\n fileName: localPath,\n preserveSignature: 'allow-extension',\n })\n }\n },\n\n },\n resolveId(id) {\n if (id.endsWith('.controller'))\n\n return metaPath\n },\n transform(code) {\n const meta = JSON.parse(code) as ServerMeta[]\n const compiler = new Pcompiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n\n this.emitFile({\n type: 'asset',\n fileName: `${compiler.name}.client.ts`,\n needsCodeReference: false,\n source: compiler.createRequest(),\n })\n\n return { code: compiler.getContent() }\n },\n\n transformInclude(id) {\n return id === metaPath\n },\n\n }\n})\n","import type { ServerMeta } from './types'\n\nexport class Pcompiler {\n classMap: Record<string, { [key: string]: string }> = {}\n name: string\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n createRequest() {\n let content = 'import {useC} from \\'phecda-server\\'\\n'\n for (const name in this.classMap)\n content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n return content\n }\n\n addMethod(args: ServerMeta) {\n const {\n route: {\n route = '/',\n type = 'get',\n } = {}, name, method, params, tag,\n } = args\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n this.name = name\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(${genParams(params)}){\nconst ret={tag:\"${tag}-${method}\",body:{},query:{},params:{},realParam:'',method:\"${type}\",url:\"${url}\"}\n${params.filter(item => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n}\n\nfunction genParams(decorators: any[]) {\n return decorators.map((_, i) => {\n return `${`arg${i}`}`\n }).join(',')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,kBAAwB;AACxB,sBAA+B;;;ACCxB,IAAMA,YAAN,MAAMA;EACXC,WAAsD,CAAC;EACvDC;EACAC,cAAc;EAAE;EAEhBC,aAAa;AACX,QAAIC,UAAU;AAEd,eAAWH,QAAQ,KAAKD,UAAU;AAChCI,iBAAW;uBACMH;cACTI,OAAOC,OAAO,KAAKN,SAASC,KAAK,EAAEM,OAAO,CAACC,GAAGC,MAAMD,IAAIC,CAAAA;;IAElE;AACA,WAAOL;EACT;EAEAM,gBAAgB;AACd,QAAIN,UAAU;AACd,eAAWH,QAAQ,KAAKD;AACtBI,iBAAW,iBAAiBC,OAAOM,KAAK,KAAKX,SAASC,KAAK,EAAEW,KAAK,GAAA,WAAcX;;AAClF,WAAOG;EACT;EAEAS,UAAUC,MAAkB;AAC1B,UAAM,EACJC,OAAO,EACLA,QAAQ,KACRC,OAAO,MAAK,IACV,CAAC,GAAGf,MAAMgB,QAAQC,QAAQC,IAAG,IAC/BL;AACJ,UAAMM,MAAML,MAAMM,QAAQ,iBAAiB,EAAA;AAC3C,SAAKpB,OAAOA;AACZ,QAAI,CAAC,KAA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QAAQL,SAASM,cAAa;MAChC,CAAA;AAEA,aAAO;QAAEV,MAAMI,SAASO,WAAU;MAAG;IACvC;IAEAC,iBAAiBlB,IAAI;AACnB,aAAOA,OAAOb;IAChB;EAEF;AACF,CAAA;;;ADxDO,IAAMgC,SAASC,SAASC;","names":["Pcompiler","classMap","name","constructor","getContent","content","Object","values","reduce","p","c","createRequest","keys","join","addMethod","args","route","type","method","params","tag","url","replace","genParams","filter","item","key","i","decorators","map","_","unplugin","createUnplugin","options","localPath","command","metaPath","resolve","process","cwd","replace","name","enforce","vite","configResolved","config","buildStart","emitFile","type","id","fileName","preserveSignature","resolveId","endsWith","transform","code","meta","JSON","parse","compiler","Pcompiler","i","addMethod","needsCodeReference","source","createRequest","getContent","transformInclude","Server","unplugin","webpack"]}
1
+ {"version":3,"sources":["../../src/unplugin/webpack.ts","../../src/unplugin/unplugin.ts","../../src/compiler.ts"],"sourcesContent":["import { unplugin } from './unplugin'\n\nexport const Server = unplugin.webpack\n","import { resolve } from 'path'\nimport { createUnplugin } from 'unplugin'\nimport { Compiler } from '../compiler'\nimport type { P } from '../types'\n\nexport const unplugin = createUnplugin((options: { localPath?: string } = {}) => {\n const { localPath = 'pmeta.js' } = options\n\n let command: string\n const metaPath = resolve(process.cwd(), localPath).replace(/\\\\/g, '/')\n\n return {\n name: 'phecda-server:client',\n enforce: 'pre',\n vite: {\n configResolved(config) {\n command = config.command\n },\n\n buildStart() {\n if (command !== 'serve') {\n this.emitFile({\n type: 'chunk',\n id: metaPath,\n fileName: localPath,\n preserveSignature: 'allow-extension',\n })\n }\n },\n\n },\n resolveId(id) {\n if (id.endsWith('.controller'))\n\n return metaPath\n },\n transform(code) {\n const meta = JSON.parse(code) as P.Meta[]\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n\n if (command !== 'serve') {\n this.emitFile({\n type: 'asset',\n fileName: `${compiler.name}.client.ts`,\n needsCodeReference: false,\n source: compiler.createRequest(),\n })\n }\n\n return { code: compiler.getContent() }\n },\n\n transformInclude(id) {\n return id === metaPath\n },\n\n }\n})\n","import type { P } from './types'\n\nexport class Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n name: string\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n createRequest() {\n let content = 'import {useC} from \\'phecda-server\\'\\n'\n for (const name in this.classMap)\n content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n return content\n }\n\n addMethod(args: P.Meta) {\n const {\n route: {\n route = '/',\n type = 'get',\n } = {}, name, method, params, tag,\n } = args\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n this.name = name\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(${genParams(params)}){\nconst ret={tag:\"${tag}-${method}\",body:{},query:{},params:{},realParam:'',method:\"${type}\",url:\"${url}\"}\n${params.filter(item => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n}\n\nfunction genParams(decorators: any[]) {\n return decorators.map((_, i) => {\n return `${`arg${i}`}`\n }).join(',')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,kBAAwB;AACxB,sBAA+B;;;ACCxB,IAAMA,WAAN,MAAMA;EACXC,WAAsD,CAAC;EACvDC;EACAC,cAAc;EAAE;EAEhBC,aAAa;AACX,QAAIC,UAAU;AAEd,eAAWH,QAAQ,KAAKD,UAAU;AAChCI,iBAAW;uBACMH;cACTI,OAAOC,OAAO,KAAKN,SAASC,KAAK,EAAEM,OAAO,CAACC,GAAGC,MAAMD,IAAIC,CAAAA;;IAElE;AACA,WAAOL;EACT;EAEAM,gBAAgB;AACd,QAAIN,UAAU;AACd,eAAWH,QAAQ,KAAKD;AAC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ACrB,CAAA;QACF;MACF;IAEF;IACAC,UAAUH,IAAI;AACZ,UAAIA,GAAGI,SAAS,aAAA;AAEd,eAAOjB;IACX;IACAkB,UAAUC,MAAM;AACd,YAAMC,OAAOC,KAAKC,MAAMH,IAAAA;AACxB,YAAMI,WAAW,IAAIC,SAAAA;AAErB,iBAAWC,KAAKL;AACdG,iBAASG,UAAUD,CAAAA;AAErB,UAAI1B,YAAY,SAAS;AACvB,aAAKY,SAAS;UACZC,MAAM;UACNE,UAAU,GAAGS,SAASlB;UACtBsB,oBAAoB;UACpBC,QAAQL,SAASM,cAAa;QAChC,CAAA;MACF;AAEA,aAAO;QAAEV,MAAMI,SAASO,WAAU;MAAG;IACvC;IAEAC,iBAAiBlB,IAAI;AACnB,aAAOA,OAAOb;IAChB;EAEF;AACF,CAAA;;;AD1DO,IAAMgC,SAASC,SAASC;","names":["Compiler","classMap","name","constructor","getContent","content","Object","values","reduce","p","c","createRequest","keys","join","addMethod","args","route","type","method","params","tag","url","replace","genParams","filter","item","key","i","decorators","map","_","unplugin","createUnplugin","options","localPath","command","metaPath","resolve","process","cwd","replace","name","enforce","vite","configResolved","config","buildStart","emitFile","type","id","fileName","preserveSignature","resolveId","endsWith","transform","code","meta","JSON","parse","compiler","Compiler","i","addMethod","needsCodeReference","source","createRequest","getContent","transformInclude","Server","unplugin","webpack"]}
@@ -6,7 +6,7 @@ import { resolve } from "path";
6
6
  import { createUnplugin } from "unplugin";
7
7
 
8
8
  // src/compiler.ts
9
- var Pcompiler = class {
9
+ var Compiler = class {
10
10
  classMap = {};
11
11
  name;
12
12
  constructor() {
@@ -45,7 +45,7 @@ return ret
45
45
  `;
46
46
  }
47
47
  };
48
- __name(Pcompiler, "Pcompiler");
48
+ __name(Compiler, "Compiler");
49
49
  function genParams(decorators) {
50
50
  return decorators.map((_, i) => {
51
51
  return `${`arg${i}`}`;
@@ -82,15 +82,17 @@ var unplugin = createUnplugin((options = {}) => {
82
82
  },
83
83
  transform(code) {
84
84
  const meta = JSON.parse(code);
85
- const compiler = new Pcompiler();
85
+ const compiler = new Compiler();
86
86
  for (const i of meta)
87
87
  compiler.addMethod(i);
88
- this.emitFile({
89
- type: "asset",
90
- fileName: `${compiler.name}.client.ts`,
91
- needsCodeReference: false,
92
- source: compiler.createRequest()
93
- });
88
+ if (command !== "serve") {
89
+ this.emitFile({
90
+ type: "asset",
91
+ fileName: `${compiler.name}.client.ts`,
92
+ needsCodeReference: false,
93
+ source: compiler.createRequest()
94
+ });
95
+ }
94
96
  return {
95
97
  code: compiler.getContent()
96
98
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/unplugin/unplugin.ts","../../src/compiler.ts","../../src/unplugin/webpack.ts"],"sourcesContent":["import { resolve } from 'path'\nimport { createUnplugin } from 'unplugin'\nimport { Pcompiler } from '../compiler'\nimport type { ServerMeta } from '../types'\n\nexport const unplugin = createUnplugin((options: { localPath?: string } = {}) => {\n const { localPath = 'pmeta.js' } = options\n\n let command: string\n const metaPath = resolve(process.cwd(), localPath).replace(/\\\\/g, '/')\n\n return {\n name: 'phecda-server:client',\n enforce: 'pre',\n vite: {\n configResolved(config) {\n command = config.command\n },\n\n buildStart() {\n if (command !== 'serve') {\n this.emitFile({\n type: 'chunk',\n id: metaPath,\n fileName: localPath,\n preserveSignature: 'allow-extension',\n })\n }\n },\n\n },\n resolveId(id) {\n if (id.endsWith('.controller'))\n\n return metaPath\n },\n transform(code) {\n const meta = JSON.parse(code) as ServerMeta[]\n const compiler = new Pcompiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n\n this.emitFile({\n type: 'asset',\n fileName: `${compiler.name}.client.ts`,\n needsCodeReference: false,\n source: compiler.createRequest(),\n })\n\n return { code: compiler.getContent() }\n },\n\n transformInclude(id) {\n return id === metaPath\n },\n\n }\n})\n","import type { ServerMeta } from './types'\n\nexport class Pcompiler {\n classMap: Record<string, { [key: string]: string }> = {}\n name: string\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n createRequest() {\n let content = 'import {useC} from \\'phecda-server\\'\\n'\n for (const name in this.classMap)\n content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n return content\n }\n\n addMethod(args: ServerMeta) {\n const {\n route: {\n route = '/',\n type = 'get',\n } = {}, name, method, params, tag,\n } = args\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n this.name = name\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(${genParams(params)}){\nconst ret={tag:\"${tag}-${method}\",body:{},query:{},params:{},realParam:'',method:\"${type}\",url:\"${url}\"}\n${params.filter(item => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n}\n\nfunction genParams(decorators: any[]) {\n return decorators.map((_, i) => {\n return `${`arg${i}`}`\n }).join(',')\n}\n","import { unplugin } from './unplugin'\n\nexport const Server = unplugin.webpack\n"],"mappings":";;;;AAAA,SAASA,eAAe;AACxB,SAASC,sBAAsB;;;ACCxB,IAAMC,YAAN,MAAMA;EACXC,WAAsD,CAAC;EACvDC;EACAC,cAAc;EAAE;EAEhBC,aAAa;AACX,QAAIC,UAAU;AAEd,eAAWH,QAAQ,KAAKD,UAAU;AAChCI,iBAAW;uBACMH;cACTI,OAAOC,OAAO,KAAKN,SAASC,KAAK,EAAEM,OAAO,CAACC,GAAGC,MAAMD,IAAIC,CAAAA;;IAElE;AACA,WAAOL;EACT;EAEAM,gBAAgB;AACd,QAAIN,UAAU;AACd,eAAWH,QAAQ,KAAKD;AACtBI,iBAAW,iBAAiBC,OAAOM,KAAK,KAAKX,SAASC,KAAK,EAAEW,KAAK,GAAA,WAAcX;;AAClF,WAAOG;EACT;EAEAS,UAAUC,MAAkB;AAC1B,UAAM,EACJC,OAAO,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AMH,IAAAA;AACxB,YAAMI,WAAW,IAAIC,UAAAA;AAErB,iBAAWC,KAAKL;AACdG,iBAASG,UAAUD,CAAAA;AAErB,WAAKd,SAAS;QACZC,MAAM;QACNE,UAAU,GAAGS,SAASlB;QACtBsB,oBAAoB;QACpBC,QAAQL,SAASM,cAAa;MAChC,CAAA;AAEA,aAAO;QAAEV,MAAMI,SAASO,WAAU;MAAG;IACvC;IAEAC,iBAAiBlB,IAAI;AACnB,aAAOA,OAAOb;IAChB;EAEF;AACF,CAAA;;;AExDO,IAAMgC,SAASC,SAASC;","names":["resolve","createUnplugin","Pcompiler","classMap","name","constructor","getContent","content","Object","values","reduce","p","c","createRequest","keys","join","addMethod","args","route","type","method","params","tag","url","replace","genParams","filter","item","key","i","decorators","map","_","unplugin","createUnplugin","options","localPath","command","metaPath","resolve","process","cwd","replace","name","enforce","vite","configResolved","config","buildStart","emitFile","type","id","fileName","preserveSignature","resolveId","endsWith","transform","code","meta","JSON","parse","compiler","Pcompiler","i","addMethod","needsCodeReference","source","createRequest","getContent","transformInclude","Server","unplugin","webpack"]}
1
+ {"version":3,"sources":["../../src/unplugin/unplugin.ts","../../src/compiler.ts","../../src/unplugin/webpack.ts"],"sourcesContent":["import { resolve } from 'path'\nimport { createUnplugin } from 'unplugin'\nimport { Compiler } from '../compiler'\nimport type { P } from '../types'\n\nexport const unplugin = createUnplugin((options: { localPath?: string } = {}) => {\n const { localPath = 'pmeta.js' } = options\n\n let command: string\n const metaPath = resolve(process.cwd(), localPath).replace(/\\\\/g, '/')\n\n return {\n name: 'phecda-server:client',\n enforce: 'pre',\n vite: {\n configResolved(config) {\n command = config.command\n },\n\n buildStart() {\n if (command !== 'serve') {\n this.emitFile({\n type: 'chunk',\n id: metaPath,\n fileName: localPath,\n preserveSignature: 'allow-extension',\n })\n }\n },\n\n },\n resolveId(id) {\n if (id.endsWith('.controller'))\n\n return metaPath\n },\n transform(code) {\n const meta = JSON.parse(code) as P.Meta[]\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n\n if (command !== 'serve') {\n this.emitFile({\n type: 'asset',\n fileName: `${compiler.name}.client.ts`,\n needsCodeReference: false,\n source: compiler.createRequest(),\n })\n }\n\n return { code: compiler.getContent() }\n },\n\n transformInclude(id) {\n return id === metaPath\n },\n\n }\n})\n","import type { P } from './types'\n\nexport class Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n name: string\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n createRequest() {\n let content = 'import {useC} from \\'phecda-server\\'\\n'\n for (const name in this.classMap)\n content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n return content\n }\n\n addMethod(args: P.Meta) {\n const {\n route: {\n route = '/',\n type = 'get',\n } = {}, name, method, params, tag,\n } = args\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n this.name = name\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(${genParams(params)}){\nconst ret={tag:\"${tag}-${method}\",body:{},query:{},params:{},realParam:'',method:\"${type}\",url:\"${url}\"}\n${params.filter(item => item.key).reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n}\n\nfunction genParams(decorators: any[]) {\n return decorators.map((_, i) => {\n return `${`arg${i}`}`\n }).join(',')\n}\n","import { unplugin } from './unplugin'\n\nexport const Server = unplugin.webpack\n"],"mappings":";;;;AAAA,SAASA,eAAe;AACxB,SAASC,sBAAsB;;;ACCxB,IAAMC,WAAN,MAAMA;EACXC,WAAsD,CAAC;EACvDC;EACAC,cAAc;EAAE;EAEhBC,aAAa;AACX,QAAIC,UAAU;AAEd,eAAWH,QAAQ,KAAKD,UAAU;AAChCI,iBAAW;uBACMH;cACTI,OA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;MACJC,eAAeC,QAAQ;AACrBV,kBAAUU,OAAOV;MACnB;MAEAW,aAAa;AACX,YAAIX,YAAY,SAAS;AACvB,eAAKY,SAAS;YACZC,MAAM;YACNC,IAAIb;YACJc,UAAUhB;YACViB,mBAAmB;UACrB,CAAA;QACF;MACF;IAEF;IACAC,UAAUH,IAAI;AACZ,UAAIA,GAAGI,SAAS,aAAA;AAEd,eAAOjB;IACX;IACAkB,UAAUC,MAAM;AACd,YAAMC,OAAOC,KAAKC,MAAMH,IAAAA;AACxB,YAAMI,WAAW,IAAIC,SAAAA;AAErB,iBAAWC,KAAKL;AACdG,iBAASG,UAAUD,CAAAA;AAErB,UAAI1B,YAAY,SAAS;AACvB,aAAKY,SAAS;UACZC,MAAM;UACNE,UAAU,GAAGS,SAASlB;UACtBsB,oBAAoB;UACpBC,QAAQL,SAASM,cAAa;QAChC,CAAA;MACF;AAEA,aAAO;QAAEV,MAAMI,SAASO,WAAU;MAAG;IACvC;IAEAC,iBAAiBlB,IAAI;AACnB,aAAOA,OAAOb;IAChB;EAEF;AACF,CAAA;;;AE1DO,IAAMgC,SAASC,SAASC;","names":["resolve","createUnplugin","Compiler","classMap","name","constructor","getContent","content","Object","values","reduce","p","c","createRequest","keys","join","addMethod","args","route","type","method","params","tag","url","replace","genParams","filter","item","key","i","decorators","map","_","unplugin","createUnplugin","options","localPath","command","metaPath","resolve","process","cwd","replace","name","enforce","vite","configResolved","config","buildStart","emitFile","type","id","fileName","preserveSignature","resolveId","endsWith","transform","code","meta","JSON","parse","compiler","Compiler","i","addMethod","needsCodeReference","source","createRequest","getContent","transformInclude","Server","unplugin","webpack"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-server",
3
- "version": "1.4.1",
3
+ "version": "1.5.1",
4
4
  "description": "types share between server and client,`nestjs` format",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -78,7 +78,7 @@
78
78
  "eventemitter3": "^5.0.0",
79
79
  "reflect-metadata": "^0.1.13",
80
80
  "unplugin": "^1.3.1",
81
- "phecda-core": "1.4.0"
81
+ "phecda-core": "1.4.1"
82
82
  },
83
83
  "scripts": {
84
84
  "dev": "tsup --watch",
@@ -1,116 +0,0 @@
1
- import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
- import { Request, Response } from 'express';
3
- import amqplib from 'amqplib';
4
- import { Events } from 'phecda-core';
5
-
6
- declare class Pmeta {
7
- data: ServerMeta;
8
- handlers: PHandler[];
9
- reflect: any[];
10
- constructor(data: ServerMeta, handlers: PHandler[], reflect: any[]);
11
- }
12
-
13
- type Construct<T = any> = new (...args: any[]) => T;
14
- interface Emitter {
15
- on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
16
- once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
17
- off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
18
- removeAllListeners<N extends keyof Events>(eventName: N): void;
19
- emit<N extends keyof Events>(eventName: N, param: Events[N]): void;
20
- }
21
- interface PHandler {
22
- error?: (arg: any) => void;
23
- }
24
- interface ServerMeta {
25
- route?: {
26
- type: RequestType;
27
- route: string;
28
- };
29
- mq?: {
30
- queue: string;
31
- routeKey: string;
32
- options: amqplib.Options.Consume;
33
- };
34
- meta?: any;
35
- header: Record<string, string>;
36
- params: {
37
- type: string;
38
- index: number;
39
- key: string;
40
- validate?: boolean;
41
- }[];
42
- guards: string[];
43
- interceptors: string[];
44
- middlewares: string[];
45
- method: string;
46
- name: string;
47
- tag: string;
48
- }
49
- type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
50
- type MergeType = <R extends Promise<any>[]>(...args: R) => {
51
- [K in keyof R]: Awaited<R[K]>;
52
- };
53
- interface BaseError {
54
- error: true;
55
- status: number;
56
- }
57
- interface PError extends BaseError {
58
- message: string;
59
- description: string;
60
- }
61
- type ResOrErr<R> = {
62
- [K in keyof R]: Awaited<R[K]> | PError;
63
- };
64
- type PRes<T> = T;
65
- interface ServerContextData {
66
- request?: Request<any, any, any, any, Record<string, any>>;
67
- response?: Response<any, Record<string, any>>;
68
- }
69
- interface MqContextData {
70
- content?: string;
71
- message?: any;
72
- channel?: amqplib.Channel;
73
- }
74
- interface ServerMergeCtx {
75
- request: Request;
76
- response: Response;
77
- meta: Record<string, Pmeta>;
78
- tags?: string[];
79
- }
80
- interface ServerCtx {
81
- request: Request;
82
- response: Response;
83
- meta: Pmeta;
84
- }
85
- declare class Base {
86
- context: ServerMergeCtx | ServerCtx;
87
- }
88
- type Pguard = ((contextData: ServerCtx, isMerge?: false) => Promise<boolean> | boolean) | ((contextData: ServerMergeCtx, isMerge?: true) => Promise<boolean> | boolean);
89
- type Pinterceptor = ((contextData: ServerCtx, isMerge?: false) => any) | ((contextData: ServerMergeCtx, isMerge?: true) => any);
90
-
91
- interface RequestArgs {
92
- body: Record<string, any>;
93
- query: Record<string, string>;
94
- params: Record<string, string>;
95
- realParam: string;
96
- method: RequestType;
97
- url: string;
98
- tag: string;
99
- }
100
- type MergedReqArg = Pick<RequestArgs, 'body' | 'query' | 'params' | 'tag'>;
101
- declare function toReq(arg: RequestArgs): {
102
- method: RequestType;
103
- url: string;
104
- body: Record<string, any>;
105
- query: string;
106
- params: string;
107
- };
108
- declare const merge: (...args: RequestArgs[]) => MergedReqArg[];
109
- type RequestMethod = <F extends (...args: any[]) => any>(fn: F, args: Parameters<F>) => Promise<ReturnType<F>>;
110
- declare function createReq(instance: AxiosInstance): <R>(arg: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<PRes<Awaited<R>>>>;
111
- declare function createSeriesReq(instance: AxiosInstance, key?: string): <R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>>;
112
- declare function createParallelReq(instance: AxiosInstance, key?: string): <R extends unknown[]>(args: R, config?: AxiosRequestConfig) => Promise<AxiosResponse<ResOrErr<PRes<R>>>>;
113
- declare function isError<T = any>(data: T | PError): data is PError;
114
- declare function $S(index: number, key?: string): any;
115
-
116
- export { $S as $, BaseError as B, Construct as C, Emitter as E, MergeType as M, Pmeta as P, RequestType as R, ServerMergeCtx as S, ServerCtx as a, Pguard as b, Pinterceptor as c, ServerMeta as d, PHandler as e, PError as f, ResOrErr as g, PRes as h, ServerContextData as i, MqContextData as j, Base as k, RequestMethod as l, merge as m, createReq as n, createSeriesReq as o, createParallelReq as p, isError as q, toReq as t };