seishiro 0.1.6-untest
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 +661 -0
- package/README.md +124 -0
- package/helper/format-key.d.ts +1 -0
- package/helper/format-key.js +9 -0
- package/index.d.ts +4 -0
- package/index.js +14 -0
- package/lib/actions.d.ts +135 -0
- package/lib/actions.js +175 -0
- package/lib/message.d.ts +41 -0
- package/lib/message.js +122 -0
- package/lib/policy.d.ts +33 -0
- package/lib/policy.js +73 -0
- package/lib/registry.d.ts +29 -0
- package/lib/registry.js +72 -0
- package/package.json +21 -0
- package/types/message.type.d.ts +13 -0
- package/types/message.type.js +3 -0
- package/types/policy.type.d.ts +10 -0
- package/types/policy.type.js +2 -0
- package/types/registry.type.d.ts +16 -0
- package/types/registry.type.js +2 -0
- package/var/message.d.ts +1 -0
- package/var/message.js +4 -0
- package/var/registry.d.ts +3 -0
- package/var/registry.js +6 -0
package/lib/policy.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* @name PolicyBuilder
|
|
5
|
+
*/
|
|
6
|
+
class PolicyBuilder {
|
|
7
|
+
constructor({ passkey, version_now, version_min, version_forceupdate = true, }) {
|
|
8
|
+
if (!passkey || !version_now || !version_min) {
|
|
9
|
+
throw new Error("PolicyBuilder: passkey, version_now, and version_min are required!");
|
|
10
|
+
}
|
|
11
|
+
this.passkey = passkey;
|
|
12
|
+
this.version_now = version_now;
|
|
13
|
+
this.version_min = version_min;
|
|
14
|
+
this.version_forceupdate = version_forceupdate;
|
|
15
|
+
this.noaction_api = [];
|
|
16
|
+
this.noaction_server = [];
|
|
17
|
+
}
|
|
18
|
+
noaction(type = "", action = []) {
|
|
19
|
+
const onlyAllowed = ["server-action", "api-action"];
|
|
20
|
+
for (let actionRes of action) {
|
|
21
|
+
if (!onlyAllowed.includes(actionRes)) {
|
|
22
|
+
throw new Error(`Invalid action type: ${actionRes}. Only allowed actions are: ${onlyAllowed.join(", ")}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (typeof type !== "string") {
|
|
26
|
+
throw new Error(`Invalid key type, it only string!`);
|
|
27
|
+
}
|
|
28
|
+
for (let actionRes of action) {
|
|
29
|
+
if (actionRes === "api-action") {
|
|
30
|
+
this.noaction_api.push(type);
|
|
31
|
+
}
|
|
32
|
+
else if (actionRes === "server-action") {
|
|
33
|
+
this.noaction_server.push(type);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
compareVersions(v1, v2) {
|
|
38
|
+
const clean = (v) => v.replace(/-.*$/, "");
|
|
39
|
+
const p1 = clean(v1).split(".").map(Number);
|
|
40
|
+
const p2 = clean(v2).split(".").map(Number);
|
|
41
|
+
for (let i = 0; i < Math.max(p1.length, p2.length); i++) {
|
|
42
|
+
const n1 = p1[i] || 0;
|
|
43
|
+
const n2 = p2[i] || 0;
|
|
44
|
+
if (n1 > n2)
|
|
45
|
+
return 1;
|
|
46
|
+
if (n1 < n2)
|
|
47
|
+
return -1;
|
|
48
|
+
}
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
version_info(version = "") {
|
|
52
|
+
const comparisonMin = this.compareVersions(version, this.version_min);
|
|
53
|
+
const comparisonNow = this.compareVersions(version, this.version_now);
|
|
54
|
+
const minimumVersion = comparisonMin >= 0;
|
|
55
|
+
const matchWithNow = comparisonNow >= 0;
|
|
56
|
+
return {
|
|
57
|
+
info_upgrade: this.version_forceupdate,
|
|
58
|
+
is_version_min: minimumVersion,
|
|
59
|
+
is_version_now: matchWithNow,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
apply() {
|
|
63
|
+
return {
|
|
64
|
+
passkey: this.passkey,
|
|
65
|
+
version_now: this.version_now,
|
|
66
|
+
version_min: this.version_min,
|
|
67
|
+
version_forceupdate: this.version_forceupdate,
|
|
68
|
+
noaction_api: this.noaction_api,
|
|
69
|
+
noaction_server: this.noaction_server,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.default = PolicyBuilder;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RegistryKey, RegistryFunction, RegistryLogic, RegistryMiddleware } from "../types/registry.type";
|
|
2
|
+
/**
|
|
3
|
+
* @name RegistryBuilder
|
|
4
|
+
*/
|
|
5
|
+
export default class RegistryBuilder {
|
|
6
|
+
private registry_logic;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* @name set
|
|
10
|
+
* @param key RegistryKey
|
|
11
|
+
* @param function_regis RegistryFunction
|
|
12
|
+
* @param middleware RegistryMiddleware
|
|
13
|
+
*/
|
|
14
|
+
set(key: RegistryKey, function_regis: RegistryFunction, middleware?: RegistryMiddleware): void;
|
|
15
|
+
/**
|
|
16
|
+
* @name get
|
|
17
|
+
* @param key string
|
|
18
|
+
*/
|
|
19
|
+
get(key: RegistryKey): RegistryFunction | [RegistryMiddleware, RegistryFunction] | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* @name apply
|
|
22
|
+
*/
|
|
23
|
+
apply(): RegistryLogic;
|
|
24
|
+
/**
|
|
25
|
+
* @name use
|
|
26
|
+
* @param input RegistryBuilder | RegistryLogic
|
|
27
|
+
*/
|
|
28
|
+
use(input: RegistryBuilder | RegistryLogic): void;
|
|
29
|
+
}
|
package/lib/registry.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const format_key_1 = __importDefault(require("../helper/format-key"));
|
|
7
|
+
/**
|
|
8
|
+
* @name RegistryBuilder
|
|
9
|
+
*/
|
|
10
|
+
class RegistryBuilder {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.registry_logic = {};
|
|
13
|
+
this.registry_logic = {};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @name set
|
|
17
|
+
* @param key RegistryKey
|
|
18
|
+
* @param function_regis RegistryFunction
|
|
19
|
+
* @param middleware RegistryMiddleware
|
|
20
|
+
*/
|
|
21
|
+
set(key, function_regis, middleware) {
|
|
22
|
+
const keyStr = (0, format_key_1.default)(key);
|
|
23
|
+
if (typeof function_regis !== "function") {
|
|
24
|
+
throw new Error("Registry function is only type function!");
|
|
25
|
+
}
|
|
26
|
+
if (typeof key !== "string") {
|
|
27
|
+
throw new Error("Registry key is only type string!");
|
|
28
|
+
}
|
|
29
|
+
if (!!middleware && typeof middleware === "function") {
|
|
30
|
+
this.registry_logic[keyStr] = [middleware, function_regis];
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.registry_logic[keyStr] = function_regis;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @name get
|
|
38
|
+
* @param key string
|
|
39
|
+
*/
|
|
40
|
+
get(key) {
|
|
41
|
+
const keyStr = (0, format_key_1.default)(key);
|
|
42
|
+
return this.registry_logic[keyStr] || undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @name apply
|
|
46
|
+
*/
|
|
47
|
+
apply() {
|
|
48
|
+
return this.registry_logic;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @name use
|
|
52
|
+
* @param input RegistryBuilder | RegistryLogic
|
|
53
|
+
*/
|
|
54
|
+
use(input) {
|
|
55
|
+
const logic = input instanceof RegistryBuilder ? input.registry_logic : input;
|
|
56
|
+
if (typeof logic === "object" && logic !== null) {
|
|
57
|
+
Object.entries(logic).forEach(([key, val]) => {
|
|
58
|
+
if (Array.isArray(val)) {
|
|
59
|
+
const [middleware, func] = val;
|
|
60
|
+
this.set(key, func, middleware);
|
|
61
|
+
}
|
|
62
|
+
else if (typeof val === "function") {
|
|
63
|
+
this.set(key, val);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new Error('The "use" input must be a RegistryBuilder or mapping object!');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.default = RegistryBuilder;
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "seishiro",
|
|
3
|
+
"version": "0.1.6-untest",
|
|
4
|
+
"description": "A simple response context API that eliminates the complexity of routing folder structures and replaces them with a single control center.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"build:package": "rm -r dist && tsc && cp ./package.json ./dist/ && cp ./README.md ./dist/ && cp ./LICENSE ./dist/",
|
|
10
|
+
"bun:build": "bun build ./src/**/*.ts --outdir ./dist",
|
|
11
|
+
"test": "bun test",
|
|
12
|
+
"lint": "biome check",
|
|
13
|
+
"format": "biome format --write"
|
|
14
|
+
},
|
|
15
|
+
"license": "AGPL-3.0",
|
|
16
|
+
"author": "Ernestoyoofi",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@biomejs/biome": "^2.3.13",
|
|
19
|
+
"@types/jest": "^30.0.0"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type MessageKey = string;
|
|
2
|
+
export type MessageLang = string | "en" | "id";
|
|
3
|
+
export type MessageValue = string;
|
|
4
|
+
export type MessageErrorContext = string;
|
|
5
|
+
export type MessageErrorContextSlug = string;
|
|
6
|
+
export type MessageErrorContextOpt = object;
|
|
7
|
+
export type MessageErrorContextTrack = string;
|
|
8
|
+
export type MessageLogicLang = {
|
|
9
|
+
[key: MessageLang]: {
|
|
10
|
+
[key: MessageKey]: MessageValue;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type MessageLogic = Record<MessageKey, MessageValue>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type PolicyPassKey = string;
|
|
2
|
+
export type PolicyVersionNow = string;
|
|
3
|
+
export type PolicyVersionMin = string;
|
|
4
|
+
export type PolicyVersionForceUpdate = boolean;
|
|
5
|
+
export type PolicyNoActionKey = string;
|
|
6
|
+
type AllowedActions = "server-action" | "api-action";
|
|
7
|
+
export type PolicyNoActionBase = AllowedActions[];
|
|
8
|
+
export type PolicyNoActionAPIAction = string[];
|
|
9
|
+
export type PolicyNoActionServerAction = string[];
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type RegistryKey = string;
|
|
2
|
+
export type RegistryParams = {
|
|
3
|
+
system: {
|
|
4
|
+
cookies: object;
|
|
5
|
+
headers: object;
|
|
6
|
+
ip: string;
|
|
7
|
+
location: string;
|
|
8
|
+
lang: string | "en";
|
|
9
|
+
};
|
|
10
|
+
type: RegistryKey;
|
|
11
|
+
middleware?: object | Function | Promise<any>;
|
|
12
|
+
data: object;
|
|
13
|
+
};
|
|
14
|
+
export type RegistryFunction = (params: RegistryParams) => any;
|
|
15
|
+
export type RegistryMiddleware = (params: RegistryParams) => any;
|
|
16
|
+
export type RegistryLogic = Record<RegistryKey, RegistryFunction | [RegistryMiddleware, RegistryFunction]>;
|
package/var/message.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DefaultLanguage: string;
|
package/var/message.js
ADDED
package/var/registry.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PolicyAction = exports.APIAction = exports.ServerAction = void 0;
|
|
4
|
+
exports.ServerAction = "server-action";
|
|
5
|
+
exports.APIAction = "api-action";
|
|
6
|
+
exports.PolicyAction = ["server-action", "api-action"];
|