@tachybase/actions 0.23.8
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/.turbo/turbo-build.log +9 -0
- package/LICENSE +201 -0
- package/lib/actions/add.d.ts +2 -0
- package/lib/actions/add.js +40 -0
- package/lib/actions/count.d.ts +2 -0
- package/lib/actions/count.js +39 -0
- package/lib/actions/create.d.ts +2 -0
- package/lib/actions/create.js +42 -0
- package/lib/actions/destroy.d.ts +2 -0
- package/lib/actions/destroy.js +40 -0
- package/lib/actions/first-or-create.d.ts +1 -0
- package/lib/actions/first-or-create.js +28 -0
- package/lib/actions/get.d.ts +1 -0
- package/lib/actions/get.js +31 -0
- package/lib/actions/index.d.ts +13 -0
- package/lib/actions/index.js +45 -0
- package/lib/actions/list.d.ts +2 -0
- package/lib/actions/list.js +225 -0
- package/lib/actions/move.d.ts +18 -0
- package/lib/actions/move.js +168 -0
- package/lib/actions/proxy-to-repository.d.ts +2 -0
- package/lib/actions/proxy-to-repository.js +50 -0
- package/lib/actions/remove.d.ts +1 -0
- package/lib/actions/remove.js +28 -0
- package/lib/actions/set.d.ts +1 -0
- package/lib/actions/set.js +28 -0
- package/lib/actions/toggle.d.ts +2 -0
- package/lib/actions/toggle.js +39 -0
- package/lib/actions/update-or-create.d.ts +1 -0
- package/lib/actions/update-or-create.js +28 -0
- package/lib/actions/update.d.ts +1 -0
- package/lib/actions/update.js +40 -0
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js +30 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +67 -0
- package/lib/utils.d.ts +8 -0
- package/lib/utils.js +60 -0
- package/package.json +24 -0
package/lib/constants.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
DEFAULT_PAGE: () => DEFAULT_PAGE,
|
|
21
|
+
DEFAULT_PER_PAGE: () => DEFAULT_PER_PAGE
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(constants_exports);
|
|
24
|
+
const DEFAULT_PAGE = 1;
|
|
25
|
+
const DEFAULT_PER_PAGE = 20;
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
DEFAULT_PAGE,
|
|
29
|
+
DEFAULT_PER_PAGE
|
|
30
|
+
});
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Cache } from '@tachybase/cache';
|
|
2
|
+
import { Database } from '@tachybase/database';
|
|
3
|
+
import { Action } from '@tachybase/resourcer';
|
|
4
|
+
import Koa from 'koa';
|
|
5
|
+
import * as actions from './actions';
|
|
6
|
+
export * as utils from './utils';
|
|
7
|
+
export * from './constants';
|
|
8
|
+
export type Next = () => Promise<any>;
|
|
9
|
+
export interface Context extends Koa.Context {
|
|
10
|
+
db: Database;
|
|
11
|
+
cache: Cache;
|
|
12
|
+
action: Action;
|
|
13
|
+
body: any;
|
|
14
|
+
app: any;
|
|
15
|
+
/**
|
|
16
|
+
* 是否包裹 data 对象,比如返回的 body 为 "success",withoutDataWrapping 为 false 的时候,返回的 body 会被包成 { "data": "success" }
|
|
17
|
+
*/
|
|
18
|
+
withoutDataWrapping?: boolean;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}
|
|
21
|
+
export declare function registerActions(api: any): void;
|
|
22
|
+
export default actions;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
default: () => src_default,
|
|
33
|
+
registerActions: () => registerActions,
|
|
34
|
+
utils: () => utils
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
var import_lodash = __toESM(require("lodash"));
|
|
38
|
+
var actions = __toESM(require("./actions"));
|
|
39
|
+
var utils = __toESM(require("./utils"));
|
|
40
|
+
__reExport(src_exports, require("./constants"), module.exports);
|
|
41
|
+
function registerActions(api) {
|
|
42
|
+
api.actions(
|
|
43
|
+
import_lodash.default.pick(actions, [
|
|
44
|
+
"add",
|
|
45
|
+
"create",
|
|
46
|
+
"destroy",
|
|
47
|
+
"get",
|
|
48
|
+
"list",
|
|
49
|
+
"remove",
|
|
50
|
+
"set",
|
|
51
|
+
"toggle",
|
|
52
|
+
"update",
|
|
53
|
+
"move",
|
|
54
|
+
"firstOrCreate",
|
|
55
|
+
"updateOrCreate",
|
|
56
|
+
"count"
|
|
57
|
+
])
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
__name(registerActions, "registerActions");
|
|
61
|
+
var src_default = actions;
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
registerActions,
|
|
65
|
+
utils,
|
|
66
|
+
...require("./constants")
|
|
67
|
+
});
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MultipleRelationRepository, Repository } from '@tachybase/database';
|
|
2
|
+
import { Context } from '.';
|
|
3
|
+
export declare function pageArgsToLimitArgs(page: number, pageSize: number): {
|
|
4
|
+
offset: number;
|
|
5
|
+
limit: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function getRepositoryFromParams(ctx: Context): Repository<any, any> | MultipleRelationRepository;
|
|
8
|
+
export declare function RelationRepositoryActionBuilder(method: 'remove' | 'set'): (ctx: Context, next: any) => Promise<void>;
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
RelationRepositoryActionBuilder: () => RelationRepositoryActionBuilder,
|
|
22
|
+
getRepositoryFromParams: () => getRepositoryFromParams,
|
|
23
|
+
pageArgsToLimitArgs: () => pageArgsToLimitArgs
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(utils_exports);
|
|
26
|
+
function pageArgsToLimitArgs(page, pageSize) {
|
|
27
|
+
return {
|
|
28
|
+
offset: (page - 1) * pageSize,
|
|
29
|
+
limit: pageSize
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
__name(pageArgsToLimitArgs, "pageArgsToLimitArgs");
|
|
33
|
+
function getRepositoryFromParams(ctx) {
|
|
34
|
+
const { resourceName, sourceId, actionName } = ctx.action;
|
|
35
|
+
if (sourceId === "_" && ["get", "list"].includes(actionName)) {
|
|
36
|
+
const collection = ctx.db.getCollection(resourceName);
|
|
37
|
+
return ctx.db.getRepository(collection.name);
|
|
38
|
+
}
|
|
39
|
+
if (sourceId) {
|
|
40
|
+
return ctx.db.getRepository(resourceName, sourceId);
|
|
41
|
+
}
|
|
42
|
+
return ctx.db.getRepository(resourceName);
|
|
43
|
+
}
|
|
44
|
+
__name(getRepositoryFromParams, "getRepositoryFromParams");
|
|
45
|
+
function RelationRepositoryActionBuilder(method) {
|
|
46
|
+
return async function(ctx, next) {
|
|
47
|
+
const repository = getRepositoryFromParams(ctx);
|
|
48
|
+
const filterByTk = ctx.action.params.filterByTk || ctx.action.params.filterByTks || ctx.action.params.values;
|
|
49
|
+
await repository[method](filterByTk);
|
|
50
|
+
ctx.status = 200;
|
|
51
|
+
await next();
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
__name(RelationRepositoryActionBuilder, "RelationRepositoryActionBuilder");
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
RelationRepositoryActionBuilder,
|
|
58
|
+
getRepositoryFromParams,
|
|
59
|
+
pageArgsToLimitArgs
|
|
60
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tachybase/actions",
|
|
3
|
+
"version": "0.23.8",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"koa": "^2.15.3",
|
|
10
|
+
"lodash": "4.17.21",
|
|
11
|
+
"sequelize": "^6.37.5",
|
|
12
|
+
"@tachybase/resourcer": "0.23.8",
|
|
13
|
+
"@tachybase/utils": "0.23.8",
|
|
14
|
+
"@tachybase/cache": "0.23.8",
|
|
15
|
+
"@tachybase/database": "0.23.8"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/koa": "^2.15.0",
|
|
19
|
+
"@types/lodash": "^4.17.13"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tachybase-build --no-dts @tachybase/actions"
|
|
23
|
+
}
|
|
24
|
+
}
|