titanpl 6.0.0 → 7.0.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/package.json +2 -6
- package/packages/cli/index.js +25 -11
- package/packages/cli/package.json +4 -4
- package/packages/cli/src/commands/build-ext.js +157 -0
- package/packages/cli/src/commands/build.js +12 -0
- package/packages/cli/src/commands/create.js +160 -0
- package/packages/cli/src/commands/init.js +5 -11
- package/packages/cli/src/commands/run-ext.js +104 -0
- package/{titanpl-sdk → packages/core-source}/LICENSE +1 -1
- package/packages/core-source/README.md +128 -0
- package/packages/core-source/V8_SERIALIZATION.md +125 -0
- package/packages/core-source/configure.js +50 -0
- package/packages/core-source/globals.d.ts +2238 -0
- package/packages/core-source/index.d.ts +515 -0
- package/packages/core-source/index.js +639 -0
- package/packages/core-source/jsconfig.json +12 -0
- package/packages/core-source/mkctx.config.json +7 -0
- package/packages/core-source/native/Cargo.lock +1559 -0
- package/packages/core-source/native/Cargo.toml +30 -0
- package/packages/core-source/native/src/crypto_impl.rs +139 -0
- package/packages/core-source/native/src/lib.rs +702 -0
- package/packages/core-source/native/src/storage_impl.rs +73 -0
- package/packages/core-source/native/src/v8_impl.rs +93 -0
- package/packages/core-source/package-lock.json +1464 -0
- package/packages/core-source/package.json +53 -0
- package/packages/core-source/tests/buffer.test.js +78 -0
- package/packages/core-source/tests/cookies.test.js +117 -0
- package/packages/core-source/tests/crypto.test.js +142 -0
- package/packages/core-source/tests/fs.test.js +176 -0
- package/packages/core-source/tests/ls.test.js +149 -0
- package/packages/core-source/tests/net.test.js +84 -0
- package/packages/core-source/tests/os.test.js +81 -0
- package/packages/core-source/tests/path.test.js +102 -0
- package/packages/core-source/tests/response.test.js +146 -0
- package/packages/core-source/tests/session.test.js +110 -0
- package/packages/core-source/tests/setup.js +325 -0
- package/packages/core-source/tests/time.test.js +57 -0
- package/packages/core-source/tests/url.test.js +82 -0
- package/packages/core-source/titan-ext.d.ts +2 -0
- package/packages/core-source/titan.json +9 -0
- package/packages/core-source/vitest.config.js +8 -0
- package/packages/engine-darwin-arm64/README.md +0 -2
- package/packages/engine-darwin-arm64/package.json +1 -1
- package/packages/engine-linux-x64/README.md +0 -2
- package/packages/engine-linux-x64/package.json +1 -1
- package/packages/engine-win32-x64/README.md +0 -1
- package/packages/engine-win32-x64/bin/titan-server.exe +0 -0
- package/packages/engine-win32-x64/package.json +1 -1
- package/packages/native/README.md +0 -1
- package/packages/native/index.d.ts +25 -4
- package/packages/native/index.js +7 -0
- package/packages/native/package.json +2 -2
- package/packages/native/t.native.d.ts +167 -2
- package/packages/packet/index.js +103 -94
- package/packages/packet/package.json +1 -1
- package/packages/route/package.json +1 -1
- package/packages/sdk/index.js +2 -0
- package/packages/sdk/package.json +18 -0
- package/packages/sdk/test/index.js +120 -0
- package/templates/common/_tanfig.json +19 -13
- package/templates/extension/index.d.ts +26 -22
- package/templates/extension/index.js +15 -15
- package/templates/extension/native/Cargo.toml +5 -3
- package/templates/extension/native/src/lib.rs +2 -3
- package/templates/extension/package.json +10 -20
- package/templates/extension/titan.json +5 -16
- package/templates/extension/utils/registerExtension.js +44 -0
- package/templates/js/package.json +8 -8
- package/templates/rust-js/package.json +5 -5
- package/templates/rust-ts/package.json +5 -5
- package/templates/ts/package.json +8 -8
- package/packages/packet/node_modules/typescript/LICENSE.txt +0 -55
- package/packages/packet/node_modules/typescript/README.md +0 -50
- package/packages/packet/node_modules/typescript/SECURITY.md +0 -41
- package/packages/packet/node_modules/typescript/ThirdPartyNoticeText.txt +0 -193
- package/packages/packet/node_modules/typescript/bin/tsc +0 -2
- package/packages/packet/node_modules/typescript/bin/tsserver +0 -2
- package/packages/packet/node_modules/typescript/lib/_tsc.js +0 -133818
- package/packages/packet/node_modules/typescript/lib/_tsserver.js +0 -659
- package/packages/packet/node_modules/typescript/lib/_typingsInstaller.js +0 -222
- package/packages/packet/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/de/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/es/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/it/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/lib.d.ts +0 -22
- package/packages/packet/node_modules/typescript/lib/lib.decorators.d.ts +0 -384
- package/packages/packet/node_modules/typescript/lib/lib.decorators.legacy.d.ts +0 -22
- package/packages/packet/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +0 -41
- package/packages/packet/node_modules/typescript/lib/lib.dom.d.ts +0 -39429
- package/packages/packet/node_modules/typescript/lib/lib.dom.iterable.d.ts +0 -571
- package/packages/packet/node_modules/typescript/lib/lib.es2015.collection.d.ts +0 -147
- package/packages/packet/node_modules/typescript/lib/lib.es2015.core.d.ts +0 -597
- package/packages/packet/node_modules/typescript/lib/lib.es2015.d.ts +0 -28
- package/packages/packet/node_modules/typescript/lib/lib.es2015.generator.d.ts +0 -77
- package/packages/packet/node_modules/typescript/lib/lib.es2015.iterable.d.ts +0 -605
- package/packages/packet/node_modules/typescript/lib/lib.es2015.promise.d.ts +0 -81
- package/packages/packet/node_modules/typescript/lib/lib.es2015.proxy.d.ts +0 -128
- package/packages/packet/node_modules/typescript/lib/lib.es2015.reflect.d.ts +0 -144
- package/packages/packet/node_modules/typescript/lib/lib.es2015.symbol.d.ts +0 -46
- package/packages/packet/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +0 -326
- package/packages/packet/node_modules/typescript/lib/lib.es2016.array.include.d.ts +0 -116
- package/packages/packet/node_modules/typescript/lib/lib.es2016.d.ts +0 -21
- package/packages/packet/node_modules/typescript/lib/lib.es2016.full.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.es2016.intl.d.ts +0 -31
- package/packages/packet/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +0 -21
- package/packages/packet/node_modules/typescript/lib/lib.es2017.d.ts +0 -26
- package/packages/packet/node_modules/typescript/lib/lib.es2017.date.d.ts +0 -31
- package/packages/packet/node_modules/typescript/lib/lib.es2017.full.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.es2017.intl.d.ts +0 -44
- package/packages/packet/node_modules/typescript/lib/lib.es2017.object.d.ts +0 -49
- package/packages/packet/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +0 -135
- package/packages/packet/node_modules/typescript/lib/lib.es2017.string.d.ts +0 -45
- package/packages/packet/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +0 -53
- package/packages/packet/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +0 -77
- package/packages/packet/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +0 -53
- package/packages/packet/node_modules/typescript/lib/lib.es2018.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2018.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2018.intl.d.ts +0 -83
- package/packages/packet/node_modules/typescript/lib/lib.es2018.promise.d.ts +0 -30
- package/packages/packet/node_modules/typescript/lib/lib.es2018.regexp.d.ts +0 -37
- package/packages/packet/node_modules/typescript/lib/lib.es2019.array.d.ts +0 -79
- package/packages/packet/node_modules/typescript/lib/lib.es2019.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2019.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2019.intl.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.es2019.object.d.ts +0 -33
- package/packages/packet/node_modules/typescript/lib/lib.es2019.string.d.ts +0 -37
- package/packages/packet/node_modules/typescript/lib/lib.es2019.symbol.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2020.bigint.d.ts +0 -765
- package/packages/packet/node_modules/typescript/lib/lib.es2020.d.ts +0 -27
- package/packages/packet/node_modules/typescript/lib/lib.es2020.date.d.ts +0 -42
- package/packages/packet/node_modules/typescript/lib/lib.es2020.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2020.intl.d.ts +0 -474
- package/packages/packet/node_modules/typescript/lib/lib.es2020.number.d.ts +0 -28
- package/packages/packet/node_modules/typescript/lib/lib.es2020.promise.d.ts +0 -47
- package/packages/packet/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +0 -99
- package/packages/packet/node_modules/typescript/lib/lib.es2020.string.d.ts +0 -44
- package/packages/packet/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +0 -41
- package/packages/packet/node_modules/typescript/lib/lib.es2021.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.es2021.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2021.intl.d.ts +0 -166
- package/packages/packet/node_modules/typescript/lib/lib.es2021.promise.d.ts +0 -48
- package/packages/packet/node_modules/typescript/lib/lib.es2021.string.d.ts +0 -33
- package/packages/packet/node_modules/typescript/lib/lib.es2021.weakref.d.ts +0 -78
- package/packages/packet/node_modules/typescript/lib/lib.es2022.array.d.ts +0 -121
- package/packages/packet/node_modules/typescript/lib/lib.es2022.d.ts +0 -25
- package/packages/packet/node_modules/typescript/lib/lib.es2022.error.d.ts +0 -75
- package/packages/packet/node_modules/typescript/lib/lib.es2022.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2022.intl.d.ts +0 -145
- package/packages/packet/node_modules/typescript/lib/lib.es2022.object.d.ts +0 -26
- package/packages/packet/node_modules/typescript/lib/lib.es2022.regexp.d.ts +0 -39
- package/packages/packet/node_modules/typescript/lib/lib.es2022.string.d.ts +0 -25
- package/packages/packet/node_modules/typescript/lib/lib.es2023.array.d.ts +0 -924
- package/packages/packet/node_modules/typescript/lib/lib.es2023.collection.d.ts +0 -21
- package/packages/packet/node_modules/typescript/lib/lib.es2023.d.ts +0 -22
- package/packages/packet/node_modules/typescript/lib/lib.es2023.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2023.intl.d.ts +0 -56
- package/packages/packet/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +0 -65
- package/packages/packet/node_modules/typescript/lib/lib.es2024.collection.d.ts +0 -29
- package/packages/packet/node_modules/typescript/lib/lib.es2024.d.ts +0 -26
- package/packages/packet/node_modules/typescript/lib/lib.es2024.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2024.object.d.ts +0 -29
- package/packages/packet/node_modules/typescript/lib/lib.es2024.promise.d.ts +0 -35
- package/packages/packet/node_modules/typescript/lib/lib.es2024.regexp.d.ts +0 -25
- package/packages/packet/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +0 -68
- package/packages/packet/node_modules/typescript/lib/lib.es2024.string.d.ts +0 -29
- package/packages/packet/node_modules/typescript/lib/lib.es5.d.ts +0 -4601
- package/packages/packet/node_modules/typescript/lib/lib.es6.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.esnext.array.d.ts +0 -35
- package/packages/packet/node_modules/typescript/lib/lib.esnext.collection.d.ts +0 -96
- package/packages/packet/node_modules/typescript/lib/lib.esnext.d.ts +0 -29
- package/packages/packet/node_modules/typescript/lib/lib.esnext.decorators.d.ts +0 -28
- package/packages/packet/node_modules/typescript/lib/lib.esnext.disposable.d.ts +0 -193
- package/packages/packet/node_modules/typescript/lib/lib.esnext.error.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.esnext.float16.d.ts +0 -445
- package/packages/packet/node_modules/typescript/lib/lib.esnext.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.esnext.intl.d.ts +0 -21
- package/packages/packet/node_modules/typescript/lib/lib.esnext.iterator.d.ts +0 -148
- package/packages/packet/node_modules/typescript/lib/lib.esnext.promise.d.ts +0 -34
- package/packages/packet/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +0 -25
- package/packages/packet/node_modules/typescript/lib/lib.scripthost.d.ts +0 -322
- package/packages/packet/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +0 -41
- package/packages/packet/node_modules/typescript/lib/lib.webworker.d.ts +0 -13150
- package/packages/packet/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.webworker.iterable.d.ts +0 -340
- package/packages/packet/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/tsc.js +0 -8
- package/packages/packet/node_modules/typescript/lib/tsserver.js +0 -8
- package/packages/packet/node_modules/typescript/lib/tsserverlibrary.d.ts +0 -17
- package/packages/packet/node_modules/typescript/lib/tsserverlibrary.js +0 -21
- package/packages/packet/node_modules/typescript/lib/typesMap.json +0 -497
- package/packages/packet/node_modules/typescript/lib/typescript.d.ts +0 -11437
- package/packages/packet/node_modules/typescript/lib/typescript.js +0 -200276
- package/packages/packet/node_modules/typescript/lib/typingsInstaller.js +0 -8
- package/packages/packet/node_modules/typescript/lib/watchGuard.js +0 -53
- package/packages/packet/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/package.json +0 -120
- package/titanpl-sdk/README.md +0 -111
- package/titanpl-sdk/assets/titanpl-sdk.png +0 -0
- package/titanpl-sdk/bin/run.js +0 -274
- package/titanpl-sdk/index.js +0 -5
- package/titanpl-sdk/package-lock.json +0 -28
- package/titanpl-sdk/package.json +0 -40
- package/titanpl-sdk/templates/app/actions/hello.js +0 -5
- package/titanpl-sdk/templates/app/app.js +0 -7
- package/titanpl-sdk/templates/jsconfig.json +0 -19
- package/titanpl-sdk/templates/server/Cargo.toml +0 -52
- package/titanpl-sdk/templates/server/src/action_management.rs +0 -175
- package/titanpl-sdk/templates/server/src/errors.rs +0 -12
- package/titanpl-sdk/templates/server/src/extensions/builtin.rs +0 -1060
- package/titanpl-sdk/templates/server/src/extensions/external.rs +0 -338
- package/titanpl-sdk/templates/server/src/extensions/mod.rs +0 -580
- package/titanpl-sdk/templates/server/src/extensions/titan_core.js +0 -249
- package/titanpl-sdk/templates/server/src/fast_path.rs +0 -719
- package/titanpl-sdk/templates/server/src/main.rs +0 -607
- package/titanpl-sdk/templates/server/src/runtime.rs +0 -284
- package/titanpl-sdk/templates/server/src/utils.rs +0 -33
- package/titanpl-sdk/templates/titan/bundle.js +0 -259
- package/titanpl-sdk/templates/titan/dev.js +0 -390
- package/titanpl-sdk/templates/titan/error-box.js +0 -277
- package/titanpl-sdk/templates/titan/titan.js +0 -129
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
// Titan Core Runtime JS
|
|
2
|
-
// Safe Bootstrap — runs only once
|
|
3
|
-
if (!globalThis.__TITAN_CORE_LOADED__) {
|
|
4
|
-
globalThis.__TITAN_CORE_LOADED__ = true;
|
|
5
|
-
|
|
6
|
-
globalThis.global = globalThis;
|
|
7
|
-
|
|
8
|
-
// ensure t exists early
|
|
9
|
-
if (!globalThis.t) globalThis.t = {};
|
|
10
|
-
|
|
11
|
-
// defineAction identity helper
|
|
12
|
-
globalThis.defineAction = (fn) => {
|
|
13
|
-
if (fn.__titanWrapped) return fn;
|
|
14
|
-
|
|
15
|
-
const wrapped = function (req) {
|
|
16
|
-
const requestId = req.__titan_request_id;
|
|
17
|
-
|
|
18
|
-
if (req.rawBody && req.rawBody.byteLength !== undefined) {
|
|
19
|
-
try {
|
|
20
|
-
const decoder = new TextDecoder();
|
|
21
|
-
const text = decoder.decode(req.rawBody);
|
|
22
|
-
|
|
23
|
-
const contentType =
|
|
24
|
-
(req.headers && req.headers["content-type"]) ||
|
|
25
|
-
(req.headers && req.headers["Content-Type"]) ||
|
|
26
|
-
"";
|
|
27
|
-
|
|
28
|
-
if (contentType.includes("application/json")) {
|
|
29
|
-
req.body = text ? JSON.parse(text) : {};
|
|
30
|
-
} else if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
31
|
-
req.body = Object.fromEntries(new URLSearchParams(text));
|
|
32
|
-
} else {
|
|
33
|
-
req.body = text;
|
|
34
|
-
}
|
|
35
|
-
} catch (e) {
|
|
36
|
-
req.body = {};
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
req.body = {};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ===============================
|
|
43
|
-
|
|
44
|
-
const isSuspend = (err) => {
|
|
45
|
-
const msg = err && (err.message || String(err));
|
|
46
|
-
return msg && (msg.includes("__SUSPEND__") || msg.includes("SUSPEND"));
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
const result = fn(req);
|
|
51
|
-
|
|
52
|
-
if (result && typeof result.then === 'function') {
|
|
53
|
-
result.then(
|
|
54
|
-
(data) => t._finish_request(requestId, data),
|
|
55
|
-
(err) => {
|
|
56
|
-
if (isSuspend(err)) return;
|
|
57
|
-
t._finish_request(requestId, { error: err.message || String(err) });
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
} else {
|
|
61
|
-
t._finish_request(requestId, result);
|
|
62
|
-
}
|
|
63
|
-
} catch (err) {
|
|
64
|
-
if (isSuspend(err)) return;
|
|
65
|
-
t._finish_request(requestId, { error: err.message || String(err) });
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
wrapped.__titanWrapped = true;
|
|
70
|
-
return wrapped;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// TextDecoder Polyfill
|
|
75
|
-
globalThis.TextDecoder = class TextDecoder {
|
|
76
|
-
decode(buffer) {
|
|
77
|
-
return t.decodeUtf8(buffer);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// Titan Environment API
|
|
82
|
-
t.env = t.loadEnv ? t.loadEnv() : {};
|
|
83
|
-
|
|
84
|
-
// Async Proxy Creator
|
|
85
|
-
function createAsyncOp(op) {
|
|
86
|
-
return new Proxy(op, {
|
|
87
|
-
get(target, prop) {
|
|
88
|
-
if (
|
|
89
|
-
prop === "__titanAsync" ||
|
|
90
|
-
prop === "type" ||
|
|
91
|
-
prop === "data" ||
|
|
92
|
-
typeof prop === 'symbol'
|
|
93
|
-
) {
|
|
94
|
-
return target[prop];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
throw new Error(
|
|
98
|
-
`[Titan Error] Accessed '${String(prop)}' without drift(). `
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Response API (Dual-Signature)
|
|
105
|
-
// Supports TWO calling conventions for compatibility with fast-path parser:
|
|
106
|
-
//
|
|
107
|
-
// Positional (legacy):
|
|
108
|
-
// t.response.json(data, 201, { "X-Custom": "val" })
|
|
109
|
-
//
|
|
110
|
-
// Options object (preferred — matches fast-path syntax):
|
|
111
|
-
// t.response.json(data, { status: 201, headers: { "X-Custom": "val" } })
|
|
112
|
-
//
|
|
113
|
-
// The fast-path scanner parses the source code and expects the options-object
|
|
114
|
-
// form. Using the positional form works at runtime but won't be detected by
|
|
115
|
-
// fast-path. The options-object form works in BOTH paths.
|
|
116
|
-
//
|
|
117
|
-
// Internal helper to normalize the second argument:
|
|
118
|
-
function _parseResponseOpts(secondArg, thirdArg) {
|
|
119
|
-
let status = 200;
|
|
120
|
-
let extraHeaders = {};
|
|
121
|
-
|
|
122
|
-
if (secondArg !== undefined && secondArg !== null && typeof secondArg === 'object') {
|
|
123
|
-
// Options object form: { status: N, headers: {...} }
|
|
124
|
-
status = secondArg.status || 200;
|
|
125
|
-
extraHeaders = secondArg.headers || {};
|
|
126
|
-
// Also merge thirdArg if provided (defensive)
|
|
127
|
-
if (thirdArg && typeof thirdArg === 'object') {
|
|
128
|
-
extraHeaders = { ...extraHeaders, ...thirdArg };
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
// Positional form: (status, extraHeaders)
|
|
132
|
-
status = secondArg || 200;
|
|
133
|
-
extraHeaders = thirdArg || {};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return { status, extraHeaders };
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const titanResponse = {
|
|
140
|
-
json(data, second, third) {
|
|
141
|
-
const { status, extraHeaders } = _parseResponseOpts(second, third);
|
|
142
|
-
return {
|
|
143
|
-
_isResponse: true,
|
|
144
|
-
status,
|
|
145
|
-
headers: { "Content-Type": "application/json", ...extraHeaders },
|
|
146
|
-
body: JSON.stringify(data)
|
|
147
|
-
};
|
|
148
|
-
},
|
|
149
|
-
text(data, second, third) {
|
|
150
|
-
const { status, extraHeaders } = _parseResponseOpts(second, third);
|
|
151
|
-
return {
|
|
152
|
-
_isResponse: true,
|
|
153
|
-
status,
|
|
154
|
-
headers: { "Content-Type": "text/plain", ...extraHeaders },
|
|
155
|
-
body: String(data)
|
|
156
|
-
};
|
|
157
|
-
},
|
|
158
|
-
html(data, second, third) {
|
|
159
|
-
const { status, extraHeaders } = _parseResponseOpts(second, third);
|
|
160
|
-
return {
|
|
161
|
-
_isResponse: true,
|
|
162
|
-
status,
|
|
163
|
-
headers: { "Content-Type": "text/html", ...extraHeaders },
|
|
164
|
-
body: String(data)
|
|
165
|
-
};
|
|
166
|
-
},
|
|
167
|
-
redirect(url, second, third) {
|
|
168
|
-
const { status: rawStatus, extraHeaders } = _parseResponseOpts(second, third);
|
|
169
|
-
// For redirects, default to 302 and ensure 3xx range
|
|
170
|
-
let status = rawStatus;
|
|
171
|
-
if (status < 300 || status >= 400) status = 302;
|
|
172
|
-
return {
|
|
173
|
-
_isResponse: true,
|
|
174
|
-
status,
|
|
175
|
-
headers: { "Location": url, ...extraHeaders },
|
|
176
|
-
redirect: url
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
t.response = titanResponse;
|
|
182
|
-
|
|
183
|
-
// Drift Support
|
|
184
|
-
globalThis.drift = function (value) {
|
|
185
|
-
if (Array.isArray(value)) {
|
|
186
|
-
for (const item of value) {
|
|
187
|
-
if (!item || !item.__titanAsync) {
|
|
188
|
-
throw new Error("drift() array must contain async ops only.");
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
} else if (!value || !value.__titanAsync) {
|
|
192
|
-
throw new Error("drift() must wrap async ops.");
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return t._drift_call(value);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
// Safe Wrappers
|
|
199
|
-
|
|
200
|
-
// fetch
|
|
201
|
-
if (t.fetch && !t.fetch.__titanWrapped) {
|
|
202
|
-
const nativeFetch = t.fetch;
|
|
203
|
-
t.fetch = function (...args) {
|
|
204
|
-
return createAsyncOp(nativeFetch(...args));
|
|
205
|
-
};
|
|
206
|
-
t.fetch.__titanWrapped = true;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// db.connect
|
|
210
|
-
// db.connect
|
|
211
|
-
if (t.db && !t.db.__titanWrapped) {
|
|
212
|
-
const nativeDbConnect = t.db.connect;
|
|
213
|
-
|
|
214
|
-
t.db.connect = function (connString, options = {}) {
|
|
215
|
-
const conn = nativeDbConnect(connString, options);
|
|
216
|
-
|
|
217
|
-
if (!conn.query.__titanWrapped) {
|
|
218
|
-
const nativeQuery = conn.query;
|
|
219
|
-
|
|
220
|
-
conn.query = function (sql, params = []) {
|
|
221
|
-
if (typeof sql !== "string" || !sql.trim()) {
|
|
222
|
-
throw new Error("db.query(): SQL string required");
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (!Array.isArray(params)) {
|
|
226
|
-
throw new Error("db.query(): params must be array");
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return createAsyncOp({
|
|
230
|
-
__titanAsync: true,
|
|
231
|
-
type: "db_query",
|
|
232
|
-
data: {
|
|
233
|
-
conn: connString,
|
|
234
|
-
query: sql,
|
|
235
|
-
params
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
conn.query.__titanWrapped = true;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return conn;
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
t.db.__titanWrapped = true;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
}
|