@midwayjs/process-agent 3.0.3 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/process-agent",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -18,21 +18,20 @@
|
|
|
18
18
|
"author": "",
|
|
19
19
|
"files": [
|
|
20
20
|
"dist/**/*.js",
|
|
21
|
-
"dist/**/*.d.ts"
|
|
22
|
-
"dist/**/*.js.map"
|
|
21
|
+
"dist/**/*.d.ts"
|
|
23
22
|
],
|
|
24
23
|
"engines": {
|
|
25
24
|
"node": ">=12"
|
|
26
25
|
},
|
|
27
26
|
"license": "MIT",
|
|
28
27
|
"devDependencies": {
|
|
29
|
-
"@midwayjs/core": "^3.0.
|
|
30
|
-
"@midwayjs/decorator": "^3.0.
|
|
31
|
-
"@midwayjs/koa": "^3.0.
|
|
32
|
-
"@midwayjs/mock": "^3.0.
|
|
28
|
+
"@midwayjs/core": "^3.0.6",
|
|
29
|
+
"@midwayjs/decorator": "^3.0.6",
|
|
30
|
+
"@midwayjs/koa": "^3.0.6",
|
|
31
|
+
"@midwayjs/mock": "^3.0.6"
|
|
33
32
|
},
|
|
34
33
|
"dependencies": {
|
|
35
34
|
"request": "2.88.2"
|
|
36
35
|
},
|
|
37
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "afaa5b59a2be85e915233a9268c0e05965dd5c61"
|
|
38
37
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAK6B;AAC7B,yCAAqD;AACrD,yBAAyB;AACzB,6BAA6B;A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CAAC;qBACD,MAAM,CAAC,QAAQ,CAAC,CAAC;aACrB;SACF;QACD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;YAC5B,MAAM,KAAK,GAAG,IAAA,4BAAgB,EAAC,yBAAyB,EAAE,MAAM,CAAC,CAAC;YAClE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,IAAI,IAAA,iBAAS,GAAE,EAAE;oBACf,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE;wBACtC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,GAAG;6BAC3B,sBAAsB,EAAE;6BACxB,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;wBACnC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;oBAC3C,CAAC,CAAC;iBACH;aACF;SACF;IACH,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,IAAA,iBAAS,GAAE,EAAE;YACf,IAAA,iBAAS,GAAE,CAAC;YACZ,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;SAC9C;IACH,CAAC;CACF,CAAA;AA/CC;IADC,IAAA,eAAG,GAAE;;sDACF;AAJO,yBAAyB;IAHrC,IAAA,yBAAa,EAAC;QACb,SAAS,EAAE,eAAe;KAC3B,CAAC;GACW,yBAAyB,CAmDrC;AAnDY,8DAAyB","sourcesContent":["import {\n App,\n Configuration,\n getClassMetadata,\n listModule,\n} from '@midwayjs/decorator';\nimport { isPrimary, closeLock } from './utils/utils';\nimport * as os from 'os';\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport * as http from 'http';\nimport * as qs from 'querystring';\n\n@Configuration({\n namespace: 'process-agent',\n})\nexport class ProcessAgentConfiguration {\n http_server: any;\n\n @App()\n app;\n\n async onReady() {\n const modules = listModule('primary:primary');\n const handlers = {};\n let sockFile = path.join(os.tmpdir(), 'midway-primary.sock');\n if (process.platform === 'win32') {\n sockFile =\n '\\\\\\\\.\\\\pipe\\\\' + sockFile.replace(/^\\//, '').replace(/\\//g, '-');\n }\n if (modules.length > 0 && process.platform !== 'win32') {\n if (isPrimary()) {\n if (fs.existsSync(sockFile)) {\n fs.unlinkSync(sockFile);\n }\n this.http_server = http\n .createServer((req, res) => {\n const query = qs.parse(req.url.substr('/?'.length));\n const params = JSON.parse(query.params as string);\n handlers[`${query.path}`](...params).then(result => {\n res.end(result);\n });\n })\n .listen(sockFile);\n }\n }\n for (const module of modules) {\n const rules = getClassMetadata('primary:primary:options', module);\n for (const rule of rules) {\n if (isPrimary()) {\n handlers[rule.name] = async (...args) => {\n const service = await this.app\n .createAnonymousContext()\n .requestContext.getAsync(module);\n return rule.value.call(service, ...args);\n };\n }\n }\n }\n }\n\n async onStop() {\n if (isPrimary()) {\n closeLock();\n this.http_server && this.http_server.close();\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"primary.js","sourceRoot":"","sources":["../../src/decorator/primary.ts"],"names":[],"mappings":";;;AAAA,mDAAsE;AACtE,mCAAmC;AACnC,6BAA6B;AAC7B,yBAAyB;AACzB,0CAA2C;AAC3C,kCAAkC;AAElC,SAAgB,YAAY;IAC1B,OAAO,UACL,MAAW,EACX,WAAmB,EACnB,UAA8B;QAE9B,IAAA,sBAAU,EAAC,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,qBAAqB,CAAC,CAAC;QAC/D,IAAI,CAAC,IAAA,iBAAS,GAAE,EAAE;YAChB,UAAU,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;gBAC7B,MAAM,MAAM,GAAG;oBACb,IAAI,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,WAAW,EAAE;oBACjD,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;iBAC7B,CAAC;gBACF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBACrC,OAAO,CACL;wBACE,GAAG,EAAE,eAAe,QAAQ,MAAM,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;qBACzD,EACD,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;wBACjB,IAAI,GAAG,EAAE;4BACP,MAAM,CAAC,GAAG,CAAC,CAAC;4BACZ,OAAO;yBACR;wBACD,OAAO,CAAC,IAAI,CAAC,CAAC;oBAChB,CAAC,CACF,CAAC;gBACJ,CAAC,CAAC,CAAC;YACL,CAAC,CAAC;SACH;QACD,IAAA,+BAAmB,EACjB,yBAAyB,EACzB;YACE,IAAI,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,WAAW,EAAE;YACjD,KAAK,EAAE,UAAU,CAAC,KAAK;SACxB,EACD,MAAM,CAAC,WAAW,CACnB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAvCD,oCAuCC","sourcesContent":["import { saveModule, attachClassMetadata } from '@midwayjs/decorator';\nimport * as request from 'request';\nimport * as path from 'path';\nimport * as os from 'os';\nimport { isPrimary } from '../utils/utils';\nimport * as qs from 'querystring';\n\nexport function RunInPrimary() {\n return function (\n target: any,\n propertyKey: string,\n descriptor: PropertyDescriptor\n ) {\n saveModule('primary:primary', target.constructor);\n const sockFile = path.join(os.tmpdir(), 'midway-primary.sock');\n if (!isPrimary()) {\n descriptor.value = (...args) => {\n const params = {\n path: `${target.constructor.name}_${propertyKey}`,\n params: JSON.stringify(args),\n };\n return new Promise((resolve, reject) => {\n request(\n {\n uri: `http://unix:${sockFile}:/?${qs.stringify(params)}`,\n },\n (err, res, body) => {\n if (err) {\n reject(err);\n return;\n }\n resolve(body);\n }\n );\n });\n };\n }\n attachClassMetadata(\n 'primary:primary:options',\n {\n name: `${target.constructor.name}_${propertyKey}`,\n value: descriptor.value,\n },\n target.constructor\n );\n };\n}\n"]}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAA6E;AAApE,8GAAA,yBAAyB,OAAiB;AACnD,+CAAmD;AAA1C,uGAAA,YAAY,OAAA","sourcesContent":["export { ProcessAgentConfiguration as Configuration } from './configuration';\nexport { RunInPrimary } from './decorator/primary';\n"]}
|
package/dist/utils/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,6BAA6B;AAC7B,yBAAyB;AACzB,yBAAyB;AAEzB,IAAI,GAAG,GAAG,IAAI,CAAC;AACf,IAAI,KAAK,GAAG,KAAK,CAAC;AAClB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;AAC1B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;AACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CACxB,EAAE,CAAC,MAAM,EAAE,EACX,iBAAiB,GAAG,CAAC,WAAW,EAAE,IAChC,GAAG,CAAC,QAAQ,EAAE,GAAG,CACnB,IAAI,GAAG,CAAC,OAAO,EAAE,IAAI,IAAI,OAAO,CACjC,CAAC;AACF,SAAgB,SAAS;IACvB,mBAAmB;IACnB,IAAI,OAAO,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,EAAE;QAC/C,OAAO,IAAI,CAAC;KACb;IAED,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE;QAC/C,0BAA0B;QAC1B,IAAI,KAAK,IAAI,GAAG,EAAE;YAChB,OAAO,IAAI,CAAC;SACb;aAAM,IAAI,KAAK,EAAE;YAChB,OAAO,KAAK,CAAC;SACd;aAAM;YACL,KAAK,GAAG,IAAI,CAAC;YACb,IAAI;gBACF,MAAM,MAAM,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBAC3C,GAAG,GAAG,MAAM,CAAC;gBACb,OAAO,IAAI,CAAC;aACb;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,KAAK,CAAC;aACd;SACF;KACF;IAED,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE;QACpC,iBAAiB;QACjB,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE;YACjD,OAAO,IAAI,CAAC;SACb;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAhCD,8BAgCC;AAED,SAAgB,SAAS;IACvB,IAAI,GAAG,EAAE;QACP,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAClB,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACxB,GAAG,GAAG,IAAI,CAAC;KACZ;AACH,CAAC;AAND,8BAMC","sourcesContent":["import * as cluster from 'cluster';\nimport * as path from 'path';\nimport * as os from 'os';\nimport * as fs from 'fs';\n\nlet gfp = null;\nlet bInit = false;\nconst ppid = process.ppid;\nconst now = new Date();\nconst lockFile = path.join(\n os.tmpdir(),\n `midway-master-${now.getFullYear()}-${\n now.getMonth() + 1\n }-${now.getDate()}-${ppid}.lock`\n);\nexport function isPrimary() {\n // fix for node v16\n if (cluster['isPrimary'] || cluster['isMaster']) {\n return true;\n }\n\n if (process.argv[1].indexOf('egg-cluster') >= 0) {\n // Is run with egg-scripts\n if (bInit && gfp) {\n return true;\n } else if (bInit) {\n return false;\n } else {\n bInit = true;\n try {\n const result = fs.openSync(lockFile, 'wx');\n gfp = result;\n return true;\n } catch (e) {\n return false;\n }\n }\n }\n\n if (process.env && process.env.pm_id) {\n //Is run with PM2\n if (parseInt(process.env.NODE_APP_INSTANCE) === 0) {\n return true;\n }\n }\n\n return false;\n}\n\nexport function closeLock() {\n if (gfp) {\n fs.closeSync(gfp);\n fs.unlinkSync(lockFile);\n gfp = null;\n }\n}\n"]}
|