@midwayjs/one-shot 4.0.0-beta.10
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/LICENSE +21 -0
- package/dist/configuration.d.ts +6 -0
- package/dist/configuration.js +35 -0
- package/dist/framework.d.ts +16 -0
- package/dist/framework.js +48 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +23 -0
- package/dist/interface.d.ts +19 -0
- package/dist/interface.js +3 -0
- package/index.d.ts +9 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013 - Now midwayjs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.OneShotConfiguration = void 0;
|
|
10
|
+
const core_1 = require("@midwayjs/core");
|
|
11
|
+
/**
|
|
12
|
+
* One-shot component configuration.
|
|
13
|
+
*/
|
|
14
|
+
let OneShotConfiguration = class OneShotConfiguration {
|
|
15
|
+
};
|
|
16
|
+
exports.OneShotConfiguration = OneShotConfiguration;
|
|
17
|
+
exports.OneShotConfiguration = OneShotConfiguration = __decorate([
|
|
18
|
+
(0, core_1.Configuration)({
|
|
19
|
+
namespace: 'oneShot',
|
|
20
|
+
importConfigs: [
|
|
21
|
+
{
|
|
22
|
+
default: {
|
|
23
|
+
midwayLogger: {
|
|
24
|
+
clients: {
|
|
25
|
+
oneShotLogger: {
|
|
26
|
+
fileLogName: 'midway-one-shot.log',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
})
|
|
34
|
+
], OneShotConfiguration);
|
|
35
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseFramework, IMidwayBootstrapOptions } from '@midwayjs/core';
|
|
2
|
+
import { IMidwayOneShotApplication, IMidwayOneShotContext, OneShotConfigOptions, OneShotRunner } from './interface';
|
|
3
|
+
/**
|
|
4
|
+
* Framework for one-shot scripts.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MidwayOneShotFramework extends BaseFramework<IMidwayOneShotApplication, IMidwayOneShotContext, OneShotConfigOptions> {
|
|
7
|
+
protected frameworkLoggerName: string;
|
|
8
|
+
configure(): OneShotConfigOptions;
|
|
9
|
+
applicationInitialize(_options: IMidwayBootstrapOptions): Promise<void>;
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Execute a one-shot runner class once.
|
|
13
|
+
*/
|
|
14
|
+
runScript<T = unknown, R = unknown>(Runner: new (...args: unknown[]) => OneShotRunner<T, R>, payload?: T, ctxData?: Partial<IMidwayOneShotContext>): Promise<R>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=framework.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MidwayOneShotFramework = void 0;
|
|
10
|
+
const core_1 = require("@midwayjs/core");
|
|
11
|
+
/**
|
|
12
|
+
* Framework for one-shot scripts.
|
|
13
|
+
*/
|
|
14
|
+
let MidwayOneShotFramework = class MidwayOneShotFramework extends core_1.BaseFramework {
|
|
15
|
+
frameworkLoggerName = 'oneShotLogger';
|
|
16
|
+
configure() {
|
|
17
|
+
return this.configService.getConfiguration('oneShot');
|
|
18
|
+
}
|
|
19
|
+
async applicationInitialize(_options) {
|
|
20
|
+
void _options;
|
|
21
|
+
this.app = {};
|
|
22
|
+
}
|
|
23
|
+
async run() {
|
|
24
|
+
// one-shot framework runs on demand
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Execute a one-shot runner class once.
|
|
28
|
+
*/
|
|
29
|
+
async runScript(Runner, payload, ctxData = {}) {
|
|
30
|
+
const ctx = this.app.createAnonymousContext({
|
|
31
|
+
...ctxData,
|
|
32
|
+
payload,
|
|
33
|
+
});
|
|
34
|
+
const fn = await this.applyMiddleware(async (ctx) => {
|
|
35
|
+
const instance = (await ctx.requestContext.getAsync(Runner));
|
|
36
|
+
if (!instance?.run) {
|
|
37
|
+
throw new core_1.MidwayCommonError('One-shot runner must implement run().');
|
|
38
|
+
}
|
|
39
|
+
return await instance.run(payload, ctx);
|
|
40
|
+
});
|
|
41
|
+
return (await fn(ctx));
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.MidwayOneShotFramework = MidwayOneShotFramework;
|
|
45
|
+
exports.MidwayOneShotFramework = MidwayOneShotFramework = __decorate([
|
|
46
|
+
(0, core_1.Framework)()
|
|
47
|
+
], MidwayOneShotFramework);
|
|
48
|
+
//# sourceMappingURL=framework.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Configuration = exports.Framework = void 0;
|
|
18
|
+
__exportStar(require("./interface"), exports);
|
|
19
|
+
var framework_1 = require("./framework");
|
|
20
|
+
Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return framework_1.MidwayOneShotFramework; } });
|
|
21
|
+
var configuration_1 = require("./configuration");
|
|
22
|
+
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.OneShotConfiguration; } });
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IConfigurationOptions, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
|
|
2
|
+
export interface OneShotConfigOptions extends IConfigurationOptions {
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* One-shot execution context.
|
|
6
|
+
*/
|
|
7
|
+
export interface IMidwayOneShotContext extends IMidwayContext {
|
|
8
|
+
payload?: unknown;
|
|
9
|
+
}
|
|
10
|
+
export type IMidwayOneShotApplication = IMidwayApplication<IMidwayOneShotContext>;
|
|
11
|
+
export type Application = IMidwayOneShotApplication;
|
|
12
|
+
export type Context = IMidwayOneShotContext;
|
|
13
|
+
/**
|
|
14
|
+
* One-shot runner contract.
|
|
15
|
+
*/
|
|
16
|
+
export interface OneShotRunner<T = unknown, R = unknown> {
|
|
17
|
+
run(payload?: T, ctx?: IMidwayOneShotContext): R | Promise<R>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=interface.d.ts.map
|
package/index.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@midwayjs/one-shot",
|
|
3
|
+
"version": "4.0.0-beta.10",
|
|
4
|
+
"description": "Midway One-shot Framework",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"typings": "index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"midway",
|
|
9
|
+
"component",
|
|
10
|
+
"one-shot"
|
|
11
|
+
],
|
|
12
|
+
"author": "czy88840616@gmail.com",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/**/*.js",
|
|
15
|
+
"dist/**/*.d.ts",
|
|
16
|
+
"index.d.ts"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
|
|
21
|
+
"cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
|
|
22
|
+
"ci": "npm run test",
|
|
23
|
+
"lint": "mwts check"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@midwayjs/core": "^4.0.0-beta.10"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@midwayjs/mock": "^4.0.0-beta.10"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=20"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"gitHead": "1b1856629913703f67304155aaf611ec936a81ac"
|
|
36
|
+
}
|