@web-ts-toolkit/access-router 0.2.0
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 +201 -0
- package/README.md +377 -0
- package/index.d.mts +1589 -0
- package/index.d.ts +1589 -0
- package/index.js +4022 -0
- package/index.mjs +3979 -0
- package/package.json +55 -0
- package/processors.d.mts +11 -0
- package/processors.d.ts +11 -0
- package/processors.js +59 -0
- package/processors.mjs +35 -0
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@web-ts-toolkit/access-router",
|
|
3
|
+
"description": "Access-policy Express routers and in-memory data services for Mongoose-backed APIs",
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"express",
|
|
7
|
+
"mongoose",
|
|
8
|
+
"access",
|
|
9
|
+
"access-router",
|
|
10
|
+
"router"
|
|
11
|
+
],
|
|
12
|
+
"main": "./index.js",
|
|
13
|
+
"module": "./index.mjs",
|
|
14
|
+
"types": "./index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"import": "./index.mjs",
|
|
19
|
+
"require": "./index.js",
|
|
20
|
+
"default": "./index.js"
|
|
21
|
+
},
|
|
22
|
+
"./processors": {
|
|
23
|
+
"types": "./processors.d.ts",
|
|
24
|
+
"import": "./processors.mjs",
|
|
25
|
+
"require": "./processors.js",
|
|
26
|
+
"default": "./processors.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@web-ts-toolkit/express-json-router": "0.2.0",
|
|
31
|
+
"deep-diff": "^1.0.2",
|
|
32
|
+
"mongoose-schema-jsonschema": "^4.0.1",
|
|
33
|
+
"sift": "^17.1.3",
|
|
34
|
+
"@web-ts-toolkit/utils": "0.2.0",
|
|
35
|
+
"winston": "^3.19.0",
|
|
36
|
+
"zod": "^4.1.12"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"express": ">=5.0.0",
|
|
40
|
+
"mongoose": ">=8.0.0"
|
|
41
|
+
},
|
|
42
|
+
"author": "Junmin Ahn",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/egose/web-ts-toolkit/issues"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20"
|
|
48
|
+
},
|
|
49
|
+
"license": "Apache-2.0",
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/egose/web-ts-toolkit.git",
|
|
53
|
+
"directory": "packages/access-router"
|
|
54
|
+
}
|
|
55
|
+
}
|
package/processors.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface ProcessCopy {
|
|
2
|
+
src: string;
|
|
3
|
+
dest: string;
|
|
4
|
+
}
|
|
5
|
+
interface CopyAndDepopulateOptions {
|
|
6
|
+
mutable?: boolean;
|
|
7
|
+
idField?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const copyAndDepopulate: <T extends object>(docObject: T, operations: ProcessCopy[], options?: CopyAndDepopulateOptions) => T;
|
|
10
|
+
|
|
11
|
+
export { copyAndDepopulate };
|
package/processors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface ProcessCopy {
|
|
2
|
+
src: string;
|
|
3
|
+
dest: string;
|
|
4
|
+
}
|
|
5
|
+
interface CopyAndDepopulateOptions {
|
|
6
|
+
mutable?: boolean;
|
|
7
|
+
idField?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const copyAndDepopulate: <T extends object>(docObject: T, operations: ProcessCopy[], options?: CopyAndDepopulateOptions) => T;
|
|
10
|
+
|
|
11
|
+
export { copyAndDepopulate };
|
package/processors.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
|
|
19
|
+
// src/processors.ts
|
|
20
|
+
var processors_exports = {};
|
|
21
|
+
__export(processors_exports, {
|
|
22
|
+
copyAndDepopulate: () => copyAndDepopulate
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(processors_exports);
|
|
25
|
+
var import_utils = require("@web-ts-toolkit/utils");
|
|
26
|
+
var copyAndDepopulate = (docObject, operations, options = { mutable: true, idField: "_id" }) => {
|
|
27
|
+
const obj = (0, import_utils.get)(options, "mutable", true) ? docObject : (0, import_utils.cloneDeep)(docObject);
|
|
28
|
+
const idField = (0, import_utils.get)(options, "idField", "_id");
|
|
29
|
+
(0, import_utils.forEach)((0, import_utils.castArray)(operations), (op) => {
|
|
30
|
+
if (!op.src || !op.dest) return;
|
|
31
|
+
let targets = [obj];
|
|
32
|
+
const segs = op.src.split(".");
|
|
33
|
+
(0, import_utils.forEach)(segs, (seg, ind) => {
|
|
34
|
+
if (segs.length === ind + 1) {
|
|
35
|
+
(0, import_utils.forEach)(targets, (target) => {
|
|
36
|
+
const targetObject = target;
|
|
37
|
+
(0, import_utils.set)(targetObject, op.dest, (0, import_utils.get)(targetObject, seg));
|
|
38
|
+
(0, import_utils.set)(
|
|
39
|
+
targetObject,
|
|
40
|
+
seg,
|
|
41
|
+
(0, import_utils.isArray)(targetObject[seg]) ? (0, import_utils.map)(targetObject[seg], idField) : (0, import_utils.get)(targetObject, `${seg}.${idField}`)
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
targets = targets.reduce((ret, target) => {
|
|
46
|
+
const targetObject = target;
|
|
47
|
+
if ((0, import_utils.isArray)(targetObject[seg])) ret.push(...targetObject[seg]);
|
|
48
|
+
else ret.push(targetObject[seg]);
|
|
49
|
+
return ret;
|
|
50
|
+
}, []);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
return obj;
|
|
55
|
+
};
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
copyAndDepopulate
|
|
59
|
+
});
|
package/processors.mjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/processors.ts
|
|
2
|
+
import { castArray, cloneDeep, forEach, get, isArray, map, set } from "@web-ts-toolkit/utils";
|
|
3
|
+
var copyAndDepopulate = (docObject, operations, options = { mutable: true, idField: "_id" }) => {
|
|
4
|
+
const obj = get(options, "mutable", true) ? docObject : cloneDeep(docObject);
|
|
5
|
+
const idField = get(options, "idField", "_id");
|
|
6
|
+
forEach(castArray(operations), (op) => {
|
|
7
|
+
if (!op.src || !op.dest) return;
|
|
8
|
+
let targets = [obj];
|
|
9
|
+
const segs = op.src.split(".");
|
|
10
|
+
forEach(segs, (seg, ind) => {
|
|
11
|
+
if (segs.length === ind + 1) {
|
|
12
|
+
forEach(targets, (target) => {
|
|
13
|
+
const targetObject = target;
|
|
14
|
+
set(targetObject, op.dest, get(targetObject, seg));
|
|
15
|
+
set(
|
|
16
|
+
targetObject,
|
|
17
|
+
seg,
|
|
18
|
+
isArray(targetObject[seg]) ? map(targetObject[seg], idField) : get(targetObject, `${seg}.${idField}`)
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
targets = targets.reduce((ret, target) => {
|
|
23
|
+
const targetObject = target;
|
|
24
|
+
if (isArray(targetObject[seg])) ret.push(...targetObject[seg]);
|
|
25
|
+
else ret.push(targetObject[seg]);
|
|
26
|
+
return ret;
|
|
27
|
+
}, []);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return obj;
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
copyAndDepopulate
|
|
35
|
+
};
|