express-file-cluster 0.1.6 → 0.1.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/dist/auth/index.cjs +13 -96
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +7 -51
- package/dist/auth/index.js.map +1 -1
- package/dist/chunk-M7UOT4ZR.js +60 -0
- package/dist/chunk-M7UOT4ZR.js.map +1 -0
- package/dist/chunk-MQNVNOH5.cjs +48 -0
- package/dist/chunk-MQNVNOH5.cjs.map +1 -0
- package/dist/chunk-MZPG5HXL.js +48 -0
- package/dist/chunk-MZPG5HXL.js.map +1 -0
- package/dist/chunk-PFJWEU4E.cjs +60 -0
- package/dist/chunk-PFJWEU4E.cjs.map +1 -0
- package/dist/chunk-UDE6S53C.cjs +42 -0
- package/dist/chunk-UDE6S53C.cjs.map +1 -0
- package/dist/chunk-Z5YNIVQG.js +42 -0
- package/dist/chunk-Z5YNIVQG.js.map +1 -0
- package/dist/cli/index.cjs +101 -167
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +16 -59
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +92 -186
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +20 -70
- package/dist/index.js.map +1 -1
- package/dist/tasks/index.cjs +13 -68
- package/dist/tasks/index.cjs.map +1 -1
- package/dist/tasks/index.d.cts +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.js +7 -33
- package/dist/tasks/index.js.map +1 -1
- package/dist/{types-CkpRAA3y.d.cts → types-Dj9-sLOK.d.cts} +1 -1
- package/dist/{types-CkpRAA3y.d.ts → types-Dj9-sLOK.d.ts} +1 -1
- package/package.json +1 -1
package/dist/auth/index.cjs
CHANGED
|
@@ -1,98 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
29
2
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
function configureAuth(config) {
|
|
43
|
-
_config = config;
|
|
44
|
-
}
|
|
45
|
-
function getConfig() {
|
|
46
|
-
if (!_config) throw new Error("[EFC] Auth not configured \u2014 pass jwtSecret to ignite()");
|
|
47
|
-
return _config;
|
|
48
|
-
}
|
|
49
|
-
function issueToken(res, payload) {
|
|
50
|
-
const { secret, expiresIn, cookieDomain } = getConfig();
|
|
51
|
-
const token = import_jsonwebtoken.default.sign(payload, secret, { expiresIn });
|
|
52
|
-
res.cookie("efc_token", token, {
|
|
53
|
-
httpOnly: true,
|
|
54
|
-
secure: process.env["NODE_ENV"] === "production",
|
|
55
|
-
sameSite: "strict",
|
|
56
|
-
...cookieDomain !== void 0 && { domain: cookieDomain }
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function revokeToken(res) {
|
|
60
|
-
res.clearCookie("efc_token");
|
|
61
|
-
}
|
|
62
|
-
function signToken(payload) {
|
|
63
|
-
const { secret, expiresIn } = getConfig();
|
|
64
|
-
return import_jsonwebtoken.default.sign(payload, secret, { expiresIn });
|
|
65
|
-
}
|
|
66
|
-
var requireAuth = (req, res, next) => {
|
|
67
|
-
const { secret, strategy } = getConfig();
|
|
68
|
-
try {
|
|
69
|
-
let token;
|
|
70
|
-
if (strategy === "http-only") {
|
|
71
|
-
const cookies = req.cookies;
|
|
72
|
-
token = cookies["efc_token"];
|
|
73
|
-
} else {
|
|
74
|
-
const auth = req.headers["authorization"];
|
|
75
|
-
if (typeof auth === "string" && auth.startsWith("Bearer ")) {
|
|
76
|
-
token = auth.slice(7);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (!token) {
|
|
80
|
-
res.status(401).json({ error: "Unauthorized" });
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const decoded = import_jsonwebtoken.default.verify(token, secret);
|
|
84
|
-
req.user = decoded;
|
|
85
|
-
next();
|
|
86
|
-
} catch {
|
|
87
|
-
res.status(401).json({ error: "Unauthorized" });
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
-
0 && (module.exports = {
|
|
92
|
-
configureAuth,
|
|
93
|
-
issueToken,
|
|
94
|
-
requireAuth,
|
|
95
|
-
revokeToken,
|
|
96
|
-
signToken
|
|
97
|
-
});
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkPFJWEU4Ecjs = require('../chunk-PFJWEU4E.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.configureAuth = _chunkPFJWEU4Ecjs.configureAuth; exports.issueToken = _chunkPFJWEU4Ecjs.issueToken; exports.requireAuth = _chunkPFJWEU4Ecjs.requireAuth; exports.revokeToken = _chunkPFJWEU4Ecjs.revokeToken; exports.signToken = _chunkPFJWEU4Ecjs.signToken;
|
|
98
15
|
//# sourceMappingURL=index.cjs.map
|
package/dist/auth/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/efc.js/efc.js/packages/core/dist/auth/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B;AACE;AACA;AACA;AACA;AACA;AACF,sQAAC","file":"/home/runner/work/efc.js/efc.js/packages/core/dist/auth/index.cjs"}
|
package/dist/auth/index.d.cts
CHANGED
package/dist/auth/index.d.ts
CHANGED
package/dist/auth/index.js
CHANGED
|
@@ -1,54 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (!_config) throw new Error("[EFC] Auth not configured \u2014 pass jwtSecret to ignite()");
|
|
9
|
-
return _config;
|
|
10
|
-
}
|
|
11
|
-
function issueToken(res, payload) {
|
|
12
|
-
const { secret, expiresIn, cookieDomain } = getConfig();
|
|
13
|
-
const token = jwt.sign(payload, secret, { expiresIn });
|
|
14
|
-
res.cookie("efc_token", token, {
|
|
15
|
-
httpOnly: true,
|
|
16
|
-
secure: process.env["NODE_ENV"] === "production",
|
|
17
|
-
sameSite: "strict",
|
|
18
|
-
...cookieDomain !== void 0 && { domain: cookieDomain }
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
function revokeToken(res) {
|
|
22
|
-
res.clearCookie("efc_token");
|
|
23
|
-
}
|
|
24
|
-
function signToken(payload) {
|
|
25
|
-
const { secret, expiresIn } = getConfig();
|
|
26
|
-
return jwt.sign(payload, secret, { expiresIn });
|
|
27
|
-
}
|
|
28
|
-
var requireAuth = (req, res, next) => {
|
|
29
|
-
const { secret, strategy } = getConfig();
|
|
30
|
-
try {
|
|
31
|
-
let token;
|
|
32
|
-
if (strategy === "http-only") {
|
|
33
|
-
const cookies = req.cookies;
|
|
34
|
-
token = cookies["efc_token"];
|
|
35
|
-
} else {
|
|
36
|
-
const auth = req.headers["authorization"];
|
|
37
|
-
if (typeof auth === "string" && auth.startsWith("Bearer ")) {
|
|
38
|
-
token = auth.slice(7);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (!token) {
|
|
42
|
-
res.status(401).json({ error: "Unauthorized" });
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const decoded = jwt.verify(token, secret);
|
|
46
|
-
req.user = decoded;
|
|
47
|
-
next();
|
|
48
|
-
} catch {
|
|
49
|
-
res.status(401).json({ error: "Unauthorized" });
|
|
50
|
-
}
|
|
51
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
configureAuth,
|
|
3
|
+
issueToken,
|
|
4
|
+
requireAuth,
|
|
5
|
+
revokeToken,
|
|
6
|
+
signToken
|
|
7
|
+
} from "../chunk-M7UOT4ZR.js";
|
|
52
8
|
export {
|
|
53
9
|
configureAuth,
|
|
54
10
|
issueToken,
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/auth/index.ts
|
|
2
|
+
import jwt from "jsonwebtoken";
|
|
3
|
+
var _config = null;
|
|
4
|
+
function configureAuth(config) {
|
|
5
|
+
_config = config;
|
|
6
|
+
}
|
|
7
|
+
function getConfig() {
|
|
8
|
+
if (!_config) throw new Error("[EFC] Auth not configured \u2014 pass jwtSecret to ignite()");
|
|
9
|
+
return _config;
|
|
10
|
+
}
|
|
11
|
+
function issueToken(res, payload) {
|
|
12
|
+
const { secret, expiresIn, cookieDomain } = getConfig();
|
|
13
|
+
const token = jwt.sign(payload, secret, { expiresIn });
|
|
14
|
+
res.cookie("efc_token", token, {
|
|
15
|
+
httpOnly: true,
|
|
16
|
+
secure: process.env["NODE_ENV"] === "production",
|
|
17
|
+
sameSite: "strict",
|
|
18
|
+
...cookieDomain !== void 0 && { domain: cookieDomain }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function revokeToken(res) {
|
|
22
|
+
res.clearCookie("efc_token");
|
|
23
|
+
}
|
|
24
|
+
function signToken(payload) {
|
|
25
|
+
const { secret, expiresIn } = getConfig();
|
|
26
|
+
return jwt.sign(payload, secret, { expiresIn });
|
|
27
|
+
}
|
|
28
|
+
var requireAuth = (req, res, next) => {
|
|
29
|
+
const { secret, strategy } = getConfig();
|
|
30
|
+
try {
|
|
31
|
+
let token;
|
|
32
|
+
if (strategy === "http-only") {
|
|
33
|
+
const cookies = req.cookies;
|
|
34
|
+
token = cookies["efc_token"];
|
|
35
|
+
} else {
|
|
36
|
+
const auth = req.headers["authorization"];
|
|
37
|
+
if (typeof auth === "string" && auth.startsWith("Bearer ")) {
|
|
38
|
+
token = auth.slice(7);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!token) {
|
|
42
|
+
res.status(401).json({ error: "Unauthorized" });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const decoded = jwt.verify(token, secret);
|
|
46
|
+
req.user = decoded;
|
|
47
|
+
next();
|
|
48
|
+
} catch {
|
|
49
|
+
res.status(401).json({ error: "Unauthorized" });
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
configureAuth,
|
|
55
|
+
issueToken,
|
|
56
|
+
revokeToken,
|
|
57
|
+
signToken,
|
|
58
|
+
requireAuth
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=chunk-M7UOT4ZR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auth/index.ts"],"sourcesContent":["import type { RequestHandler, Response } from 'express';\nimport jwt from 'jsonwebtoken';\nimport type { AuthStrategy } from '../types.js';\n\ninterface AuthConfig {\n secret: string;\n strategy: AuthStrategy;\n expiresIn: string;\n cookieDomain?: string | undefined;\n}\n\nlet _config: AuthConfig | null = null;\n\nexport function configureAuth(config: AuthConfig): void {\n _config = config;\n}\n\nfunction getConfig(): AuthConfig {\n if (!_config) throw new Error('[EFC] Auth not configured — pass jwtSecret to ignite()');\n return _config;\n}\n\nexport function issueToken(res: Response, payload: Record<string, unknown>): void {\n const { secret, expiresIn, cookieDomain } = getConfig();\n // expiresIn is a plain string (e.g. '7d'); cast satisfies jwt's branded StringValue\n const token = jwt.sign(payload, secret, { expiresIn: expiresIn as jwt.SignOptions['expiresIn'] & string });\n res.cookie('efc_token', token, {\n httpOnly: true,\n secure: process.env['NODE_ENV'] === 'production',\n sameSite: 'strict',\n ...(cookieDomain !== undefined && { domain: cookieDomain }),\n });\n}\n\nexport function revokeToken(res: Response): void {\n res.clearCookie('efc_token');\n}\n\nexport function signToken(payload: Record<string, unknown>): string {\n const { secret, expiresIn } = getConfig();\n return jwt.sign(payload, secret, { expiresIn: expiresIn as jwt.SignOptions['expiresIn'] & string });\n}\n\nexport const requireAuth: RequestHandler = (req, res, next) => {\n const { secret, strategy } = getConfig();\n\n try {\n let token: string | undefined;\n\n if (strategy === 'http-only') {\n const cookies = (req as typeof req & { cookies: Record<string, string> }).cookies;\n token = cookies['efc_token'];\n } else {\n const auth = req.headers['authorization'];\n if (typeof auth === 'string' && auth.startsWith('Bearer ')) {\n token = auth.slice(7);\n }\n }\n\n if (!token) {\n res.status(401).json({ error: 'Unauthorized' });\n return;\n }\n\n const decoded = jwt.verify(token, secret);\n (req as typeof req & { user: unknown }).user = decoded;\n next();\n } catch {\n res.status(401).json({ error: 'Unauthorized' });\n }\n};\n"],"mappings":";AACA,OAAO,SAAS;AAUhB,IAAI,UAA6B;AAE1B,SAAS,cAAc,QAA0B;AACtD,YAAU;AACZ;AAEA,SAAS,YAAwB;AAC/B,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,6DAAwD;AACtF,SAAO;AACT;AAEO,SAAS,WAAW,KAAe,SAAwC;AAChF,QAAM,EAAE,QAAQ,WAAW,aAAa,IAAI,UAAU;AAEtD,QAAM,QAAQ,IAAI,KAAK,SAAS,QAAQ,EAAE,UAA8D,CAAC;AACzG,MAAI,OAAO,aAAa,OAAO;AAAA,IAC7B,UAAU;AAAA,IACV,QAAQ,QAAQ,IAAI,UAAU,MAAM;AAAA,IACpC,UAAU;AAAA,IACV,GAAI,iBAAiB,UAAa,EAAE,QAAQ,aAAa;AAAA,EAC3D,CAAC;AACH;AAEO,SAAS,YAAY,KAAqB;AAC/C,MAAI,YAAY,WAAW;AAC7B;AAEO,SAAS,UAAU,SAA0C;AAClE,QAAM,EAAE,QAAQ,UAAU,IAAI,UAAU;AACxC,SAAO,IAAI,KAAK,SAAS,QAAQ,EAAE,UAA8D,CAAC;AACpG;AAEO,IAAM,cAA8B,CAAC,KAAK,KAAK,SAAS;AAC7D,QAAM,EAAE,QAAQ,SAAS,IAAI,UAAU;AAEvC,MAAI;AACF,QAAI;AAEJ,QAAI,aAAa,aAAa;AAC5B,YAAM,UAAW,IAAyD;AAC1E,cAAQ,QAAQ,WAAW;AAAA,IAC7B,OAAO;AACL,YAAM,OAAO,IAAI,QAAQ,eAAe;AACxC,UAAI,OAAO,SAAS,YAAY,KAAK,WAAW,SAAS,GAAG;AAC1D,gBAAQ,KAAK,MAAM,CAAC;AAAA,MACtB;AAAA,IACF;AAEA,QAAI,CAAC,OAAO;AACV,UAAI,OAAO,GAAG,EAAE,KAAK,EAAE,OAAO,eAAe,CAAC;AAC9C;AAAA,IACF;AAEA,UAAM,UAAU,IAAI,OAAO,OAAO,MAAM;AACxC,IAAC,IAAuC,OAAO;AAC/C,SAAK;AAAA,EACP,QAAQ;AACN,QAAI,OAAO,GAAG,EAAE,KAAK,EAAE,OAAO,eAAe,CAAC;AAAA,EAChD;AACF;","names":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/router/scan.ts
|
|
2
|
+
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
3
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
4
|
+
var ROUTE_FILE_RE = /\.(ts|js|mts|mjs|cts|cjs)$/;
|
|
5
|
+
var DYNAMIC_SEGMENT_RE = /\[([^\]]+)\]/g;
|
|
6
|
+
function filePathToUrlPath(relativePath) {
|
|
7
|
+
let p = relativePath.replace(ROUTE_FILE_RE, "");
|
|
8
|
+
p = p.replace(/\/index$/, "");
|
|
9
|
+
p = p.replace(DYNAMIC_SEGMENT_RE, ":$1");
|
|
10
|
+
return p === "" ? "/" : p.startsWith("/") ? p : `/${p}`;
|
|
11
|
+
}
|
|
12
|
+
function extractParams(relativePath) {
|
|
13
|
+
const params = [];
|
|
14
|
+
let match;
|
|
15
|
+
const re = new RegExp(DYNAMIC_SEGMENT_RE.source, "g");
|
|
16
|
+
while ((match = re.exec(relativePath)) !== null) {
|
|
17
|
+
if (match[1]) params.push(match[1]);
|
|
18
|
+
}
|
|
19
|
+
return params;
|
|
20
|
+
}
|
|
21
|
+
function scanDir(dir, base = dir) {
|
|
22
|
+
if (!_fs2.default.existsSync(dir)) return [];
|
|
23
|
+
const entries = [];
|
|
24
|
+
const items = _fs2.default.readdirSync(dir, { withFileTypes: true });
|
|
25
|
+
for (const item of items) {
|
|
26
|
+
const fullPath = _path2.default.join(dir, item.name);
|
|
27
|
+
if (item.isDirectory()) {
|
|
28
|
+
entries.push(...scanDir(fullPath, base));
|
|
29
|
+
} else if (ROUTE_FILE_RE.test(item.name)) {
|
|
30
|
+
const relative = "/" + _path2.default.relative(base, fullPath).replace(/\\/g, "/");
|
|
31
|
+
entries.push({
|
|
32
|
+
urlPath: filePathToUrlPath(relative),
|
|
33
|
+
filePath: fullPath,
|
|
34
|
+
params: extractParams(relative)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return entries.sort((a, b) => {
|
|
39
|
+
const aDynamic = a.urlPath.includes(":") ? 1 : 0;
|
|
40
|
+
const bDynamic = b.urlPath.includes(":") ? 1 : 0;
|
|
41
|
+
return aDynamic - bDynamic || a.urlPath.localeCompare(b.urlPath);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
exports.scanDir = scanDir;
|
|
48
|
+
//# sourceMappingURL=chunk-MQNVNOH5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/efc.js/efc.js/packages/core/dist/chunk-MQNVNOH5.cjs","../src/router/scan.ts"],"names":[],"mappings":"AAAA;ACAA,gEAAe;AACf,wEAAiB;AAGjB,IAAM,cAAA,EAAgB,4BAAA;AACtB,IAAM,mBAAA,EAAqB,eAAA;AAE3B,SAAS,iBAAA,CAAkB,YAAA,EAA8B;AACvD,EAAA,IAAI,EAAA,EAAI,YAAA,CAAa,OAAA,CAAQ,aAAA,EAAe,EAAE,CAAA;AAE9C,EAAA,EAAA,EAAI,CAAA,CAAE,OAAA,CAAQ,UAAA,EAAY,EAAE,CAAA;AAE5B,EAAA,EAAA,EAAI,CAAA,CAAE,OAAA,CAAQ,kBAAA,EAAoB,KAAK,CAAA;AACvC,EAAA,OAAO,EAAA,IAAM,GAAA,EAAK,IAAA,EAAM,CAAA,CAAE,UAAA,CAAW,GAAG,EAAA,EAAI,EAAA,EAAI,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA;AACvD;AAEuD;AAC3B,EAAA;AACtB,EAAA;AACgD,EAAA;AACH,EAAA;AACb,IAAA;AACpC,EAAA;AACO,EAAA;AACT;AAEuE;AACpC,EAAA;AAEF,EAAA;AACoB,EAAA;AAEzB,EAAA;AACiB,IAAA;AACjB,IAAA;AACiB,MAAA;AACC,IAAA;AACG,MAAA;AAC9B,MAAA;AACwB,QAAA;AACzB,QAAA;AACoB,QAAA;AAC/B,MAAA;AACH,IAAA;AACF,EAAA;AAG8B,EAAA;AACmB,IAAA;AACA,IAAA;AACP,IAAA;AACzC,EAAA;AACH;ADTwD;AACA;AACA;AACA","file":"/home/runner/work/efc.js/efc.js/packages/core/dist/chunk-MQNVNOH5.cjs","sourcesContent":[null,"import fs from 'node:fs';\nimport path from 'node:path';\nimport type { RouteEntry } from '../types.js';\n\nconst ROUTE_FILE_RE = /\\.(ts|js|mts|mjs|cts|cjs)$/;\nconst DYNAMIC_SEGMENT_RE = /\\[([^\\]]+)\\]/g;\n\nfunction filePathToUrlPath(relativePath: string): string {\n let p = relativePath.replace(ROUTE_FILE_RE, '');\n // index files map to parent path\n p = p.replace(/\\/index$/, '');\n // [param] → :param\n p = p.replace(DYNAMIC_SEGMENT_RE, ':$1');\n return p === '' ? '/' : p.startsWith('/') ? p : `/${p}`;\n}\n\nfunction extractParams(relativePath: string): string[] {\n const params: string[] = [];\n let match: RegExpExecArray | null;\n const re = new RegExp(DYNAMIC_SEGMENT_RE.source, 'g');\n while ((match = re.exec(relativePath)) !== null) {\n if (match[1]) params.push(match[1]);\n }\n return params;\n}\n\nexport function scanDir(dir: string, base: string = dir): RouteEntry[] {\n if (!fs.existsSync(dir)) return [];\n\n const entries: RouteEntry[] = [];\n const items = fs.readdirSync(dir, { withFileTypes: true });\n\n for (const item of items) {\n const fullPath = path.join(dir, item.name);\n if (item.isDirectory()) {\n entries.push(...scanDir(fullPath, base));\n } else if (ROUTE_FILE_RE.test(item.name)) {\n const relative = '/' + path.relative(base, fullPath).replace(/\\\\/g, '/');\n entries.push({\n urlPath: filePathToUrlPath(relative),\n filePath: fullPath,\n params: extractParams(relative),\n });\n }\n }\n\n // Sort: static routes before dynamic ones at each segment level\n return entries.sort((a, b) => {\n const aDynamic = a.urlPath.includes(':') ? 1 : 0;\n const bDynamic = b.urlPath.includes(':') ? 1 : 0;\n return aDynamic - bDynamic || a.urlPath.localeCompare(b.urlPath);\n });\n}\n\nexport { filePathToUrlPath };\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/router/scan.ts
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
var ROUTE_FILE_RE = /\.(ts|js|mts|mjs|cts|cjs)$/;
|
|
5
|
+
var DYNAMIC_SEGMENT_RE = /\[([^\]]+)\]/g;
|
|
6
|
+
function filePathToUrlPath(relativePath) {
|
|
7
|
+
let p = relativePath.replace(ROUTE_FILE_RE, "");
|
|
8
|
+
p = p.replace(/\/index$/, "");
|
|
9
|
+
p = p.replace(DYNAMIC_SEGMENT_RE, ":$1");
|
|
10
|
+
return p === "" ? "/" : p.startsWith("/") ? p : `/${p}`;
|
|
11
|
+
}
|
|
12
|
+
function extractParams(relativePath) {
|
|
13
|
+
const params = [];
|
|
14
|
+
let match;
|
|
15
|
+
const re = new RegExp(DYNAMIC_SEGMENT_RE.source, "g");
|
|
16
|
+
while ((match = re.exec(relativePath)) !== null) {
|
|
17
|
+
if (match[1]) params.push(match[1]);
|
|
18
|
+
}
|
|
19
|
+
return params;
|
|
20
|
+
}
|
|
21
|
+
function scanDir(dir, base = dir) {
|
|
22
|
+
if (!fs.existsSync(dir)) return [];
|
|
23
|
+
const entries = [];
|
|
24
|
+
const items = fs.readdirSync(dir, { withFileTypes: true });
|
|
25
|
+
for (const item of items) {
|
|
26
|
+
const fullPath = path.join(dir, item.name);
|
|
27
|
+
if (item.isDirectory()) {
|
|
28
|
+
entries.push(...scanDir(fullPath, base));
|
|
29
|
+
} else if (ROUTE_FILE_RE.test(item.name)) {
|
|
30
|
+
const relative = "/" + path.relative(base, fullPath).replace(/\\/g, "/");
|
|
31
|
+
entries.push({
|
|
32
|
+
urlPath: filePathToUrlPath(relative),
|
|
33
|
+
filePath: fullPath,
|
|
34
|
+
params: extractParams(relative)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return entries.sort((a, b) => {
|
|
39
|
+
const aDynamic = a.urlPath.includes(":") ? 1 : 0;
|
|
40
|
+
const bDynamic = b.urlPath.includes(":") ? 1 : 0;
|
|
41
|
+
return aDynamic - bDynamic || a.urlPath.localeCompare(b.urlPath);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
scanDir
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=chunk-MZPG5HXL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/scan.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport type { RouteEntry } from '../types.js';\n\nconst ROUTE_FILE_RE = /\\.(ts|js|mts|mjs|cts|cjs)$/;\nconst DYNAMIC_SEGMENT_RE = /\\[([^\\]]+)\\]/g;\n\nfunction filePathToUrlPath(relativePath: string): string {\n let p = relativePath.replace(ROUTE_FILE_RE, '');\n // index files map to parent path\n p = p.replace(/\\/index$/, '');\n // [param] → :param\n p = p.replace(DYNAMIC_SEGMENT_RE, ':$1');\n return p === '' ? '/' : p.startsWith('/') ? p : `/${p}`;\n}\n\nfunction extractParams(relativePath: string): string[] {\n const params: string[] = [];\n let match: RegExpExecArray | null;\n const re = new RegExp(DYNAMIC_SEGMENT_RE.source, 'g');\n while ((match = re.exec(relativePath)) !== null) {\n if (match[1]) params.push(match[1]);\n }\n return params;\n}\n\nexport function scanDir(dir: string, base: string = dir): RouteEntry[] {\n if (!fs.existsSync(dir)) return [];\n\n const entries: RouteEntry[] = [];\n const items = fs.readdirSync(dir, { withFileTypes: true });\n\n for (const item of items) {\n const fullPath = path.join(dir, item.name);\n if (item.isDirectory()) {\n entries.push(...scanDir(fullPath, base));\n } else if (ROUTE_FILE_RE.test(item.name)) {\n const relative = '/' + path.relative(base, fullPath).replace(/\\\\/g, '/');\n entries.push({\n urlPath: filePathToUrlPath(relative),\n filePath: fullPath,\n params: extractParams(relative),\n });\n }\n }\n\n // Sort: static routes before dynamic ones at each segment level\n return entries.sort((a, b) => {\n const aDynamic = a.urlPath.includes(':') ? 1 : 0;\n const bDynamic = b.urlPath.includes(':') ? 1 : 0;\n return aDynamic - bDynamic || a.urlPath.localeCompare(b.urlPath);\n });\n}\n\nexport { filePathToUrlPath };\n"],"mappings":";AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AAGjB,IAAM,gBAAgB;AACtB,IAAM,qBAAqB;AAE3B,SAAS,kBAAkB,cAA8B;AACvD,MAAI,IAAI,aAAa,QAAQ,eAAe,EAAE;AAE9C,MAAI,EAAE,QAAQ,YAAY,EAAE;AAE5B,MAAI,EAAE,QAAQ,oBAAoB,KAAK;AACvC,SAAO,MAAM,KAAK,MAAM,EAAE,WAAW,GAAG,IAAI,IAAI,IAAI,CAAC;AACvD;AAEA,SAAS,cAAc,cAAgC;AACrD,QAAM,SAAmB,CAAC;AAC1B,MAAI;AACJ,QAAM,KAAK,IAAI,OAAO,mBAAmB,QAAQ,GAAG;AACpD,UAAQ,QAAQ,GAAG,KAAK,YAAY,OAAO,MAAM;AAC/C,QAAI,MAAM,CAAC,EAAG,QAAO,KAAK,MAAM,CAAC,CAAC;AAAA,EACpC;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,KAAa,OAAe,KAAmB;AACrE,MAAI,CAAC,GAAG,WAAW,GAAG,EAAG,QAAO,CAAC;AAEjC,QAAM,UAAwB,CAAC;AAC/B,QAAM,QAAQ,GAAG,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC;AAEzD,aAAW,QAAQ,OAAO;AACxB,UAAM,WAAW,KAAK,KAAK,KAAK,KAAK,IAAI;AACzC,QAAI,KAAK,YAAY,GAAG;AACtB,cAAQ,KAAK,GAAG,QAAQ,UAAU,IAAI,CAAC;AAAA,IACzC,WAAW,cAAc,KAAK,KAAK,IAAI,GAAG;AACxC,YAAM,WAAW,MAAM,KAAK,SAAS,MAAM,QAAQ,EAAE,QAAQ,OAAO,GAAG;AACvE,cAAQ,KAAK;AAAA,QACX,SAAS,kBAAkB,QAAQ;AAAA,QACnC,UAAU;AAAA,QACV,QAAQ,cAAc,QAAQ;AAAA,MAChC,CAAC;AAAA,IACH;AAAA,EACF;AAGA,SAAO,QAAQ,KAAK,CAAC,GAAG,MAAM;AAC5B,UAAM,WAAW,EAAE,QAAQ,SAAS,GAAG,IAAI,IAAI;AAC/C,UAAM,WAAW,EAAE,QAAQ,SAAS,GAAG,IAAI,IAAI;AAC/C,WAAO,WAAW,YAAY,EAAE,QAAQ,cAAc,EAAE,OAAO;AAAA,EACjE,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/auth/index.ts
|
|
2
|
+
var _jsonwebtoken = require('jsonwebtoken'); var _jsonwebtoken2 = _interopRequireDefault(_jsonwebtoken);
|
|
3
|
+
var _config = null;
|
|
4
|
+
function configureAuth(config) {
|
|
5
|
+
_config = config;
|
|
6
|
+
}
|
|
7
|
+
function getConfig() {
|
|
8
|
+
if (!_config) throw new Error("[EFC] Auth not configured \u2014 pass jwtSecret to ignite()");
|
|
9
|
+
return _config;
|
|
10
|
+
}
|
|
11
|
+
function issueToken(res, payload) {
|
|
12
|
+
const { secret, expiresIn, cookieDomain } = getConfig();
|
|
13
|
+
const token = _jsonwebtoken2.default.sign(payload, secret, { expiresIn });
|
|
14
|
+
res.cookie("efc_token", token, {
|
|
15
|
+
httpOnly: true,
|
|
16
|
+
secure: process.env["NODE_ENV"] === "production",
|
|
17
|
+
sameSite: "strict",
|
|
18
|
+
...cookieDomain !== void 0 && { domain: cookieDomain }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function revokeToken(res) {
|
|
22
|
+
res.clearCookie("efc_token");
|
|
23
|
+
}
|
|
24
|
+
function signToken(payload) {
|
|
25
|
+
const { secret, expiresIn } = getConfig();
|
|
26
|
+
return _jsonwebtoken2.default.sign(payload, secret, { expiresIn });
|
|
27
|
+
}
|
|
28
|
+
var requireAuth = (req, res, next) => {
|
|
29
|
+
const { secret, strategy } = getConfig();
|
|
30
|
+
try {
|
|
31
|
+
let token;
|
|
32
|
+
if (strategy === "http-only") {
|
|
33
|
+
const cookies = req.cookies;
|
|
34
|
+
token = cookies["efc_token"];
|
|
35
|
+
} else {
|
|
36
|
+
const auth = req.headers["authorization"];
|
|
37
|
+
if (typeof auth === "string" && auth.startsWith("Bearer ")) {
|
|
38
|
+
token = auth.slice(7);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!token) {
|
|
42
|
+
res.status(401).json({ error: "Unauthorized" });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const decoded = _jsonwebtoken2.default.verify(token, secret);
|
|
46
|
+
req.user = decoded;
|
|
47
|
+
next();
|
|
48
|
+
} catch (e) {
|
|
49
|
+
res.status(401).json({ error: "Unauthorized" });
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
exports.configureAuth = configureAuth; exports.issueToken = issueToken; exports.revokeToken = revokeToken; exports.signToken = signToken; exports.requireAuth = requireAuth;
|
|
60
|
+
//# sourceMappingURL=chunk-PFJWEU4E.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/efc.js/efc.js/packages/core/dist/chunk-PFJWEU4E.cjs","../src/auth/index.ts"],"names":[],"mappings":"AAAA;ACCA,wGAAgB;AAUhB,IAAI,QAAA,EAA6B,IAAA;AAE1B,SAAS,aAAA,CAAc,MAAA,EAA0B;AACtD,EAAA,QAAA,EAAU,MAAA;AACZ;AAEA,SAAS,SAAA,CAAA,EAAwB;AAC/B,EAAA,GAAA,CAAI,CAAC,OAAA,EAAS,MAAM,IAAI,KAAA,CAAM,6DAAwD,CAAA;AACtF,EAAA,OAAO,OAAA;AACT;AAEO,SAAS,UAAA,CAAW,GAAA,EAAe,OAAA,EAAwC;AAChF,EAAA,MAAM,EAAE,MAAA,EAAQ,SAAA,EAAW,aAAa,EAAA,EAAI,SAAA,CAAU,CAAA;AAEtD,EAAA,MAAM,MAAA,EAAQ,sBAAA,CAAI,IAAA,CAAK,OAAA,EAAS,MAAA,EAAQ,EAAE,UAA8D,CAAC,CAAA;AACzG,EAAA,GAAA,CAAI,MAAA,CAAO,WAAA,EAAa,KAAA,EAAO;AAAA,IAC7B,QAAA,EAAU,IAAA;AAAA,IACV,MAAA,EAAQ,OAAA,CAAQ,GAAA,CAAI,UAAU,EAAA,IAAM,YAAA;AAAA,IACpC,QAAA,EAAU,QAAA;AAAA,IACV,GAAI,aAAA,IAAiB,KAAA,EAAA,GAAa,EAAE,MAAA,EAAQ,aAAa;AAAA,EAC3D,CAAC,CAAA;AACH;AAEO,SAAS,WAAA,CAAY,GAAA,EAAqB;AAC/C,EAAA,GAAA,CAAI,WAAA,CAAY,WAAW,CAAA;AAC7B;AAEO,SAAS,SAAA,CAAU,OAAA,EAA0C;AAClE,EAAA,MAAM,EAAE,MAAA,EAAQ,UAAU,EAAA,EAAI,SAAA,CAAU,CAAA;AACxC,EAAA,OAAO,sBAAA,CAAI,IAAA,CAAK,OAAA,EAAS,MAAA,EAAQ,EAAE,UAA8D,CAAC,CAAA;AACpG;AAEO,IAAM,YAAA,EAA8B,CAAC,GAAA,EAAK,GAAA,EAAK,IAAA,EAAA,GAAS;AAC7D,EAAA,MAAM,EAAE,MAAA,EAAQ,SAAS,EAAA,EAAI,SAAA,CAAU,CAAA;AAEvC,EAAA,IAAI;AACF,IAAA,IAAI,KAAA;AAEJ,IAAA,GAAA,CAAI,SAAA,IAAa,WAAA,EAAa;AAC5B,MAAA,MAAM,QAAA,EAAW,GAAA,CAAyD,OAAA;AAC1E,MAAA,MAAA,EAAQ,OAAA,CAAQ,WAAW,CAAA;AAAA,IAC7B,EAAA,KAAO;AACL,MAAA,MAAM,KAAA,EAAO,GAAA,CAAI,OAAA,CAAQ,eAAe,CAAA;AACxC,MAAA,GAAA,CAAI,OAAO,KAAA,IAAS,SAAA,GAAY,IAAA,CAAK,UAAA,CAAW,SAAS,CAAA,EAAG;AAC1D,QAAA,MAAA,EAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA;AAAA,MACtB;AAAA,IACF;AAEA,IAAA,GAAA,CAAI,CAAC,KAAA,EAAO;AACV,MAAA,GAAA,CAAI,MAAA,CAAO,GAAG,CAAA,CAAE,IAAA,CAAK,EAAE,KAAA,EAAO,eAAe,CAAC,CAAA;AAC9C,MAAA,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,QAAA,EAAU,sBAAA,CAAI,MAAA,CAAO,KAAA,EAAO,MAAM,CAAA;AACxC,IAAC,GAAA,CAAuC,KAAA,EAAO,OAAA;AAC/C,IAAA,IAAA,CAAK,CAAA;AAAA,EACP,EAAA,UAAQ;AACN,IAAA,GAAA,CAAI,MAAA,CAAO,GAAG,CAAA,CAAE,IAAA,CAAK,EAAE,KAAA,EAAO,eAAe,CAAC,CAAA;AAAA,EAChD;AACF,CAAA;ADnBA;AACA;AACE;AACA;AACA;AACA;AACA;AACF,4KAAC","file":"/home/runner/work/efc.js/efc.js/packages/core/dist/chunk-PFJWEU4E.cjs","sourcesContent":[null,"import type { RequestHandler, Response } from 'express';\nimport jwt from 'jsonwebtoken';\nimport type { AuthStrategy } from '../types.js';\n\ninterface AuthConfig {\n secret: string;\n strategy: AuthStrategy;\n expiresIn: string;\n cookieDomain?: string | undefined;\n}\n\nlet _config: AuthConfig | null = null;\n\nexport function configureAuth(config: AuthConfig): void {\n _config = config;\n}\n\nfunction getConfig(): AuthConfig {\n if (!_config) throw new Error('[EFC] Auth not configured — pass jwtSecret to ignite()');\n return _config;\n}\n\nexport function issueToken(res: Response, payload: Record<string, unknown>): void {\n const { secret, expiresIn, cookieDomain } = getConfig();\n // expiresIn is a plain string (e.g. '7d'); cast satisfies jwt's branded StringValue\n const token = jwt.sign(payload, secret, { expiresIn: expiresIn as jwt.SignOptions['expiresIn'] & string });\n res.cookie('efc_token', token, {\n httpOnly: true,\n secure: process.env['NODE_ENV'] === 'production',\n sameSite: 'strict',\n ...(cookieDomain !== undefined && { domain: cookieDomain }),\n });\n}\n\nexport function revokeToken(res: Response): void {\n res.clearCookie('efc_token');\n}\n\nexport function signToken(payload: Record<string, unknown>): string {\n const { secret, expiresIn } = getConfig();\n return jwt.sign(payload, secret, { expiresIn: expiresIn as jwt.SignOptions['expiresIn'] & string });\n}\n\nexport const requireAuth: RequestHandler = (req, res, next) => {\n const { secret, strategy } = getConfig();\n\n try {\n let token: string | undefined;\n\n if (strategy === 'http-only') {\n const cookies = (req as typeof req & { cookies: Record<string, string> }).cookies;\n token = cookies['efc_token'];\n } else {\n const auth = req.headers['authorization'];\n if (typeof auth === 'string' && auth.startsWith('Bearer ')) {\n token = auth.slice(7);\n }\n }\n\n if (!token) {\n res.status(401).json({ error: 'Unauthorized' });\n return;\n }\n\n const decoded = jwt.verify(token, secret);\n (req as typeof req & { user: unknown }).user = decoded;\n next();\n } catch {\n res.status(401).json({ error: 'Unauthorized' });\n }\n};\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/tasks/index.ts
|
|
2
|
+
var taskRegistry = /* @__PURE__ */ new Map();
|
|
3
|
+
var defineTask = (handlerOrOptions, maybeHandler) => {
|
|
4
|
+
let options = {};
|
|
5
|
+
let handler;
|
|
6
|
+
if (typeof handlerOrOptions === "function") {
|
|
7
|
+
handler = handlerOrOptions;
|
|
8
|
+
} else {
|
|
9
|
+
options = handlerOrOptions;
|
|
10
|
+
if (!maybeHandler) throw new Error("[EFC] defineTask: handler function is required");
|
|
11
|
+
handler = maybeHandler;
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
handler,
|
|
15
|
+
options,
|
|
16
|
+
name: ""
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
var _impl = null;
|
|
20
|
+
function setEnqueueImpl(impl) {
|
|
21
|
+
_impl = impl;
|
|
22
|
+
}
|
|
23
|
+
async function enqueue(name, payload) {
|
|
24
|
+
if (!_impl) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`[EFC] Task queue not initialised. Set tasks.backend in ignite() config.`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return _impl(name, payload);
|
|
30
|
+
}
|
|
31
|
+
function registerTask(name, def) {
|
|
32
|
+
taskRegistry.set(name, { ...def, name });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
exports.taskRegistry = taskRegistry; exports.defineTask = defineTask; exports.setEnqueueImpl = setEnqueueImpl; exports.enqueue = enqueue; exports.registerTask = registerTask;
|
|
42
|
+
//# sourceMappingURL=chunk-UDE6S53C.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/efc.js/efc.js/packages/core/dist/chunk-UDE6S53C.cjs","../src/tasks/index.ts"],"names":[],"mappings":"AAAA;ACEO,IAAM,aAAA,kBAAe,IAAI,GAAA,CAA4B,CAAA;AAQrD,IAAM,WAAA,EAAiC,CAC5C,gBAAA,EACA,YAAA,EAAA,GACsB;AACtB,EAAA,IAAI,QAAA,EAAuB,CAAC,CAAA;AAC5B,EAAA,IAAI,OAAA;AAEJ,EAAA,GAAA,CAAI,OAAO,iBAAA,IAAqB,UAAA,EAAY;AAC1C,IAAA,QAAA,EAAU,gBAAA;AAAA,EACZ,EAAA,KAAO;AACL,IAAA,QAAA,EAAU,gBAAA;AACV,IAAA,GAAA,CAAI,CAAC,YAAA,EAAc,MAAM,IAAI,KAAA,CAAM,gDAAgD,CAAA;AACnF,IAAA,QAAA,EAAU,YAAA;AAAA,EACZ;AAEA,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA,EAAM;AAAA,EACR,CAAA;AACF,CAAA;AAGA,IAAI,MAAA,EAA4B,IAAA;AAEzB,SAAS,cAAA,CAAe,IAAA,EAAyB;AACtD,EAAA,MAAA,EAAQ,IAAA;AACV;AAEA,MAAA,SAAsB,OAAA,CAAW,IAAA,EAAc,OAAA,EAA2B;AACxE,EAAA,GAAA,CAAI,CAAC,KAAA,EAAO;AACV,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,uEAAA;AAAA,IACF,CAAA;AAAA,EACF;AACA,EAAA,OAAO,KAAA,CAAM,IAAA,EAAM,OAAkB,CAAA;AACvC;AAEO,SAAS,YAAA,CAAa,IAAA,EAAc,GAAA,EAA2B;AACpE,EAAA,YAAA,CAAa,GAAA,CAAI,IAAA,EAAM,EAAE,GAAG,GAAA,EAAK,KAAK,CAAC,CAAA;AACzC;ADjBA;AACA;AACE;AACA;AACA;AACA;AACA;AACF,8KAAC","file":"/home/runner/work/efc.js/efc.js/packages/core/dist/chunk-UDE6S53C.cjs","sourcesContent":[null,"import type { TaskDefinition, TaskOptions } from '../types.js';\n\nexport const taskRegistry = new Map<string, TaskDefinition>();\n\ntype HandlerFn<T> = (payload: T) => Promise<void>;\ntype DefineTaskOverload = {\n <T>(handler: HandlerFn<T>): TaskDefinition<T>;\n <T>(options: TaskOptions, handler: HandlerFn<T>): TaskDefinition<T>;\n};\n\nexport const defineTask: DefineTaskOverload = <T>(\n handlerOrOptions: HandlerFn<T> | TaskOptions,\n maybeHandler?: HandlerFn<T>,\n): TaskDefinition<T> => {\n let options: TaskOptions = {};\n let handler: HandlerFn<T>;\n\n if (typeof handlerOrOptions === 'function') {\n handler = handlerOrOptions;\n } else {\n options = handlerOrOptions;\n if (!maybeHandler) throw new Error('[EFC] defineTask: handler function is required');\n handler = maybeHandler;\n }\n\n return {\n handler: handler as (payload: unknown) => Promise<void>,\n options,\n name: '',\n };\n};\n\ntype EnqueueImpl = (name: string, payload: unknown) => Promise<void>;\nlet _impl: EnqueueImpl | null = null;\n\nexport function setEnqueueImpl(impl: EnqueueImpl): void {\n _impl = impl;\n}\n\nexport async function enqueue<T>(name: string, payload: T): Promise<void> {\n if (!_impl) {\n throw new Error(\n `[EFC] Task queue not initialised. Set tasks.backend in ignite() config.`,\n );\n }\n return _impl(name, payload as unknown);\n}\n\nexport function registerTask(name: string, def: TaskDefinition): void {\n taskRegistry.set(name, { ...def, name });\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/tasks/index.ts
|
|
2
|
+
var taskRegistry = /* @__PURE__ */ new Map();
|
|
3
|
+
var defineTask = (handlerOrOptions, maybeHandler) => {
|
|
4
|
+
let options = {};
|
|
5
|
+
let handler;
|
|
6
|
+
if (typeof handlerOrOptions === "function") {
|
|
7
|
+
handler = handlerOrOptions;
|
|
8
|
+
} else {
|
|
9
|
+
options = handlerOrOptions;
|
|
10
|
+
if (!maybeHandler) throw new Error("[EFC] defineTask: handler function is required");
|
|
11
|
+
handler = maybeHandler;
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
handler,
|
|
15
|
+
options,
|
|
16
|
+
name: ""
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
var _impl = null;
|
|
20
|
+
function setEnqueueImpl(impl) {
|
|
21
|
+
_impl = impl;
|
|
22
|
+
}
|
|
23
|
+
async function enqueue(name, payload) {
|
|
24
|
+
if (!_impl) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`[EFC] Task queue not initialised. Set tasks.backend in ignite() config.`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return _impl(name, payload);
|
|
30
|
+
}
|
|
31
|
+
function registerTask(name, def) {
|
|
32
|
+
taskRegistry.set(name, { ...def, name });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
taskRegistry,
|
|
37
|
+
defineTask,
|
|
38
|
+
setEnqueueImpl,
|
|
39
|
+
enqueue,
|
|
40
|
+
registerTask
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=chunk-Z5YNIVQG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tasks/index.ts"],"sourcesContent":["import type { TaskDefinition, TaskOptions } from '../types.js';\n\nexport const taskRegistry = new Map<string, TaskDefinition>();\n\ntype HandlerFn<T> = (payload: T) => Promise<void>;\ntype DefineTaskOverload = {\n <T>(handler: HandlerFn<T>): TaskDefinition<T>;\n <T>(options: TaskOptions, handler: HandlerFn<T>): TaskDefinition<T>;\n};\n\nexport const defineTask: DefineTaskOverload = <T>(\n handlerOrOptions: HandlerFn<T> | TaskOptions,\n maybeHandler?: HandlerFn<T>,\n): TaskDefinition<T> => {\n let options: TaskOptions = {};\n let handler: HandlerFn<T>;\n\n if (typeof handlerOrOptions === 'function') {\n handler = handlerOrOptions;\n } else {\n options = handlerOrOptions;\n if (!maybeHandler) throw new Error('[EFC] defineTask: handler function is required');\n handler = maybeHandler;\n }\n\n return {\n handler: handler as (payload: unknown) => Promise<void>,\n options,\n name: '',\n };\n};\n\ntype EnqueueImpl = (name: string, payload: unknown) => Promise<void>;\nlet _impl: EnqueueImpl | null = null;\n\nexport function setEnqueueImpl(impl: EnqueueImpl): void {\n _impl = impl;\n}\n\nexport async function enqueue<T>(name: string, payload: T): Promise<void> {\n if (!_impl) {\n throw new Error(\n `[EFC] Task queue not initialised. Set tasks.backend in ignite() config.`,\n );\n }\n return _impl(name, payload as unknown);\n}\n\nexport function registerTask(name: string, def: TaskDefinition): void {\n taskRegistry.set(name, { ...def, name });\n}\n"],"mappings":";AAEO,IAAM,eAAe,oBAAI,IAA4B;AAQrD,IAAM,aAAiC,CAC5C,kBACA,iBACsB;AACtB,MAAI,UAAuB,CAAC;AAC5B,MAAI;AAEJ,MAAI,OAAO,qBAAqB,YAAY;AAC1C,cAAU;AAAA,EACZ,OAAO;AACL,cAAU;AACV,QAAI,CAAC,aAAc,OAAM,IAAI,MAAM,gDAAgD;AACnF,cAAU;AAAA,EACZ;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,MAAM;AAAA,EACR;AACF;AAGA,IAAI,QAA4B;AAEzB,SAAS,eAAe,MAAyB;AACtD,UAAQ;AACV;AAEA,eAAsB,QAAW,MAAc,SAA2B;AACxE,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,MAAM,MAAM,OAAkB;AACvC;AAEO,SAAS,aAAa,MAAc,KAA2B;AACpE,eAAa,IAAI,MAAM,EAAE,GAAG,KAAK,KAAK,CAAC;AACzC;","names":[]}
|