titanpl 4.0.2 → 7.0.0-beta
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 +11 -5
- package/packages/cli/index.js +25 -11
- package/packages/cli/package.json +5 -5
- 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/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 +10 -0
- package/packages/native/index.js +4 -0
- package/packages/native/package.json +1 -1
- package/packages/native/t.native.d.ts +175 -44
- package/packages/packet/README.md +0 -1
- package/packages/packet/index.js +19 -2
- package/packages/packet/package.json +1 -1
- package/packages/route/README.md +21 -0
- package/packages/route/index.d.ts +1 -0
- package/packages/route/index.js +22 -0
- 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/Dockerfile +9 -45
- package/templates/common/_tanfig.json +17 -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 +4 -4
- package/templates/rust-ts/package.json +4 -4
- package/templates/ts/package.json +8 -8
- package/templates/common/app/t.native.d.ts +0 -2043
- package/templates/common/app/t.native.js +0 -39
- package/titanpl-sdk/LICENSE +0 -15
- 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 -1055
- 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
package/packages/route/index.js
CHANGED
|
@@ -42,6 +42,28 @@ const t = {
|
|
|
42
42
|
|
|
43
43
|
start(port = 3000, msg = "", threads, stack_mb = 8) {
|
|
44
44
|
globalThis.__TITAN_CONFIG__ = { port, msg, threads, stack_mb };
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
ws(route) {
|
|
48
|
+
return {
|
|
49
|
+
action(name) {
|
|
50
|
+
if (route.includes(":")) {
|
|
51
|
+
if (!dynamicRoutes["WS"]) dynamicRoutes["WS"] = [];
|
|
52
|
+
dynamicRoutes["WS"].push({
|
|
53
|
+
method: "WS",
|
|
54
|
+
pattern: route,
|
|
55
|
+
action: name
|
|
56
|
+
});
|
|
57
|
+
actionMap[`WS:${route}`] = name;
|
|
58
|
+
} else {
|
|
59
|
+
routes[`WS:${route}`] = {
|
|
60
|
+
type: "websocket",
|
|
61
|
+
value: name
|
|
62
|
+
};
|
|
63
|
+
actionMap[`WS:${route}`] = name;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
45
67
|
}
|
|
46
68
|
};
|
|
47
69
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@titanpl/sdk",
|
|
3
|
+
"version": "7.0.0-beta",
|
|
4
|
+
"description": "The official SDK for Titan Planet extensions and testing.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./test": "./test/index.js"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"titanpl",
|
|
13
|
+
"titan",
|
|
14
|
+
"sdk"
|
|
15
|
+
],
|
|
16
|
+
"author": "ezetgalaxy",
|
|
17
|
+
"license": "ISC"
|
|
18
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import vm from 'node:vm';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a lightweight production-grade test environment for Titan extensions.
|
|
8
|
+
* Provides isolation via node:vm and a full t-object emulation.
|
|
9
|
+
*/
|
|
10
|
+
export async function createTestEnv(options) {
|
|
11
|
+
const { extPath, allowWasm = false, allowNative = false } = options;
|
|
12
|
+
const absolutePath = path.resolve(extPath);
|
|
13
|
+
const titanJsonPath = path.join(absolutePath, 'titan.json');
|
|
14
|
+
|
|
15
|
+
if (!fs.existsSync(titanJsonPath)) {
|
|
16
|
+
throw new Error(`[@titanpl/sdk/test] titan.json not found at ${absolutePath}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const titanJson = JSON.parse(fs.readFileSync(titanJsonPath, 'utf8'));
|
|
20
|
+
|
|
21
|
+
// Create the global 't' mock
|
|
22
|
+
const tMock = {
|
|
23
|
+
_logs: [],
|
|
24
|
+
_calls: [],
|
|
25
|
+
log: (name, ...args) => {
|
|
26
|
+
const entry = `[${name}] ${args.join(' ')}`;
|
|
27
|
+
tMock._logs.push(entry);
|
|
28
|
+
console.log('\x1b[36m%s\x1b[0m', entry);
|
|
29
|
+
},
|
|
30
|
+
__native: {
|
|
31
|
+
call: async (ext, fn, args) => {
|
|
32
|
+
if (!allowNative) throw new Error(`[@titanpl/sdk/test] Native call blocked (allowNative: false)`);
|
|
33
|
+
tMock._calls.push({ type: 'native', ext, fn, args });
|
|
34
|
+
return `[MOCK_NATIVE_RESULT]`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Create a VM context
|
|
40
|
+
const context = {
|
|
41
|
+
t: tMock,
|
|
42
|
+
global: {},
|
|
43
|
+
globalThis: {},
|
|
44
|
+
console: console,
|
|
45
|
+
setTimeout,
|
|
46
|
+
clearTimeout,
|
|
47
|
+
process: { env: { ...process.env } }
|
|
48
|
+
};
|
|
49
|
+
context.global = context;
|
|
50
|
+
context.globalThis = context;
|
|
51
|
+
|
|
52
|
+
vm.createContext(context);
|
|
53
|
+
|
|
54
|
+
// Load extension entry
|
|
55
|
+
const entryPath = path.join(absolutePath, titanJson.entry);
|
|
56
|
+
const code = fs.readFileSync(entryPath, 'utf8');
|
|
57
|
+
|
|
58
|
+
// Resolve relative imports within the extension
|
|
59
|
+
// Simple loader: replace relative imports with absolute ones or mock them
|
|
60
|
+
// For a real production-ready test env, we'd use a custom loader or compile with ESBuild.
|
|
61
|
+
// For now, we'll use a functional script wrapper.
|
|
62
|
+
|
|
63
|
+
const script = new vm.Script(`
|
|
64
|
+
(async () => {
|
|
65
|
+
${code.replace(/import\s+{([^}]+)}\s+from\s+'\.\/utils\/registerExtension\.js'/g, 'const {$1} = t._registerHelper;')}
|
|
66
|
+
})()
|
|
67
|
+
`);
|
|
68
|
+
|
|
69
|
+
// Add registration helper to 't'
|
|
70
|
+
tMock._registerHelper = {
|
|
71
|
+
registerExtension: (name, module) => {
|
|
72
|
+
tMock[name] = module;
|
|
73
|
+
console.log(`[@titanpl/sdk/test] Registered extension: ${name}`);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
await script.runInContext(context);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.error(`[@titanpl/sdk/test] Runtime error in extension '${titanJson.name}':`, err);
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
/**
|
|
86
|
+
* Call an extension method
|
|
87
|
+
*/
|
|
88
|
+
call: async (path, args = []) => {
|
|
89
|
+
const [extName, methodName] = path.split('.');
|
|
90
|
+
if (!tMock[extName]) throw new Error(`Extension '${extName}' not registered`);
|
|
91
|
+
if (!tMock[extName][methodName]) throw new Error(`Method '${methodName}' not found on extension '${extName}'`);
|
|
92
|
+
|
|
93
|
+
return await tMock[extName][methodName](...args);
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Assert a method result
|
|
98
|
+
*/
|
|
99
|
+
assert: async (path, args, expected) => {
|
|
100
|
+
const result = await tMock.call(path, args);
|
|
101
|
+
if (JSON.stringify(result) !== JSON.stringify(expected)) {
|
|
102
|
+
throw new Error(`Assertion Failed for ${path}\nExpected: ${JSON.stringify(expected)}\nActual: ${JSON.stringify(result)}`);
|
|
103
|
+
}
|
|
104
|
+
console.log(`\x1b[32m✔ Assertion Passed: ${path}\x1b[0m`);
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Get all logs captured during execution
|
|
109
|
+
*/
|
|
110
|
+
getLogs: () => tMock._logs,
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Teardown the environment
|
|
114
|
+
*/
|
|
115
|
+
teardown: async () => {
|
|
116
|
+
// Cleanup context and references
|
|
117
|
+
for (const key in tMock) delete tMock[key];
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
@@ -19,28 +19,10 @@ RUN npm install -g @titanpl/cli
|
|
|
19
19
|
|
|
20
20
|
RUN npm install --include=optional
|
|
21
21
|
|
|
22
|
-
# ------------------------------------------------
|
|
23
|
-
# Extract Titan Extensions (packages with titan.json)
|
|
24
|
-
# ------------------------------------------------
|
|
25
|
-
RUN mkdir -p /app/.ext && \
|
|
26
|
-
find node_modules -mindepth 2 -maxdepth 3 -type f -name "titan.json" | while read file; do \
|
|
27
|
-
pkg_dir=$(dirname "$file"); \
|
|
28
|
-
pkg_name=$(basename "$pkg_dir"); \
|
|
29
|
-
echo "Extracting Titan extension: $pkg_name"; \
|
|
30
|
-
cp -a "$pkg_dir" "/app/.ext/$pkg_name"; \
|
|
31
|
-
rm -rf "/app/.ext/$pkg_name/node_modules"; \
|
|
32
|
-
done
|
|
33
|
-
|
|
34
|
-
# ------------------------------------------------
|
|
35
|
-
# Copy ANY installed Titan Engine (Architecture agnostic)
|
|
36
|
-
# ------------------------------------------------
|
|
37
|
-
RUN mkdir -p /app/.ext/@titanpl && \
|
|
38
|
-
cp -r node_modules/@titanpl/engine-linux-* /app/.ext/@titanpl/
|
|
39
|
-
|
|
40
22
|
COPY . .
|
|
41
23
|
|
|
42
|
-
# Run the Titan build step
|
|
43
|
-
RUN npx titan build
|
|
24
|
+
# Run the Titan release build step (generates a 'build' folder)
|
|
25
|
+
RUN npx titan build --release
|
|
44
26
|
|
|
45
27
|
|
|
46
28
|
# ================================================================
|
|
@@ -57,30 +39,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
57
39
|
ca-certificates curl \
|
|
58
40
|
&& rm -rf /var/lib/apt/lists/*
|
|
59
41
|
|
|
60
|
-
#
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
# titan extensions + engine
|
|
64
|
-
COPY --from=builder /app/.ext ./.ext
|
|
65
|
-
|
|
66
|
-
# runtime assets
|
|
67
|
-
COPY --from=builder /app/package.json ./package.json
|
|
68
|
-
|
|
69
|
-
# ---------------- OPTIONAL APP FOLDERS ----------------
|
|
70
|
-
# Static assets
|
|
71
|
-
# COPY --from=builder /app/app/static ./static
|
|
72
|
-
|
|
73
|
-
# Public assets
|
|
74
|
-
# COPY --from=builder /app/app/public ./public
|
|
75
|
-
|
|
76
|
-
# DB
|
|
77
|
-
# COPY --from=builder /app/app/db ./db
|
|
42
|
+
# Copy EVERYTHING from the generated build folder into Stage 2
|
|
43
|
+
# This includes dist/, .ext/, package.json, .env, and the titan-server binary
|
|
44
|
+
COPY --from=builder /app/build/ ./
|
|
78
45
|
|
|
79
46
|
# CRITICAL SYSTEM SETUP:
|
|
80
|
-
#
|
|
81
|
-
|
|
82
|
-
RUN echo "TITAN_DEV=0" > .env && \
|
|
83
|
-
ln -s /app/.ext /app/node_modules && \
|
|
47
|
+
# Ensure the worker threads can find the extensions through the symlink
|
|
48
|
+
RUN ln -s /app/.ext /app/node_modules && \
|
|
84
49
|
chown -R titan:titan /app
|
|
85
50
|
|
|
86
51
|
# Standard environment variables
|
|
@@ -95,6 +60,5 @@ EXPOSE 5100
|
|
|
95
60
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
|
96
61
|
CMD curl -f http://localhost:5100/ || exit 1
|
|
97
62
|
|
|
98
|
-
# DYNAMIC ENTRYPOINT:
|
|
99
|
-
|
|
100
|
-
CMD ["/bin/sh", "-c", "exec $(find .ext/@titanpl/engine-linux-* -name titan-server -type f | head -n 1) run dist"]
|
|
63
|
+
# DYNAMIC ENTRYPOINT: Use the portable binary in the root of /app
|
|
64
|
+
CMD ["./titan-server", "start"]
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "{{name}}",
|
|
3
|
+
"description": "A powerful TitanPL project",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"extensions": {
|
|
6
|
+
"allowWasm": false,
|
|
7
|
+
"allowNative": []
|
|
8
|
+
},
|
|
9
|
+
"build": {
|
|
10
|
+
"purpose": "test",
|
|
11
|
+
"files": [
|
|
12
|
+
"public",
|
|
13
|
+
"static",
|
|
14
|
+
"db",
|
|
15
|
+
"tanfig.json"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
14
18
|
}
|
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @package ext-template
|
|
3
|
+
* Professional extension template for the TitanPL framework.
|
|
4
|
+
*/
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
/** Main configuration interface */
|
|
7
|
+
export interface Config {
|
|
8
|
+
/** Secure key or secret */
|
|
9
|
+
secret?: string;
|
|
10
|
+
/** Custom logging function */
|
|
11
|
+
log?: (msg: string) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Standard Success Response */
|
|
15
|
+
export interface Result {
|
|
16
|
+
result: string;
|
|
17
|
+
status: "ok" | "error";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Main Extension class */
|
|
21
|
+
declare class Extension {
|
|
22
|
+
constructor(config?: Config);
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
calc(a: number, b: number): number;
|
|
24
|
+
/** Hash a string synchronously using bcryptjs */
|
|
25
|
+
hash(data: string): string;
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
}
|
|
27
|
+
/** Standard execution for processing input */
|
|
28
|
+
execute(input: string): Result;
|
|
25
29
|
}
|
|
26
30
|
|
|
27
|
-
export
|
|
31
|
+
export default Extension;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
if (typeof Titan === "undefined") globalThis.Titan = t;
|
|
3
|
-
const EXT_KEY = "{{name}}";
|
|
1
|
+
import { registerExtension } from './utils/registerExtension.js';
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// Example Wrapper for Native function
|
|
13
|
-
calc: function (a, b) {
|
|
14
|
-
// Assumes the native function 'add' is mapped in titan.json
|
|
15
|
-
return t[EXT_KEY].add(a, b);
|
|
3
|
+
const myExt = {
|
|
4
|
+
/**
|
|
5
|
+
* A sample function that can be called from any Titan Action.
|
|
6
|
+
*/
|
|
7
|
+
hello: () => {
|
|
8
|
+
t.log("{{name}}", "Hello from extension!");
|
|
9
|
+
return "hello";
|
|
16
10
|
}
|
|
17
|
-
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// If this is a Wasm or Native extension, bindings will be injected here during build.
|
|
14
|
+
// Use 'titan build ext' to generate them.
|
|
15
|
+
|
|
16
|
+
registerExtension("{{name}}", myExt);
|
|
17
|
+
export default myExt;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
name = "
|
|
3
|
-
version = "
|
|
4
|
-
edition = "
|
|
2
|
+
name = "my-extension-native"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
edition = "2021"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
7
7
|
crate-type = ["cdylib"]
|
|
8
8
|
|
|
9
9
|
[dependencies]
|
|
10
|
+
serde = { version = "1.0", features = ["derive"] }
|
|
11
|
+
serde_json = "1.0"
|
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A
|
|
2
|
+
"name": "my-extension",
|
|
3
|
+
"version": "7.0.0-beta",
|
|
4
|
+
"description": "A high-performance TitanPL extension.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"keywords": [
|
|
12
|
-
"titan planet",
|
|
13
|
-
"extension"
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"titan.json",
|
|
10
|
+
"jsconfig.json",
|
|
11
|
+
"README.md"
|
|
14
12
|
],
|
|
15
|
-
"author": "",
|
|
16
|
-
"license": "ISC",
|
|
17
13
|
"dependencies": {
|
|
18
|
-
"@titanpl/
|
|
19
|
-
"chokidar": "^5.0.0",
|
|
20
|
-
"esbuild": "^0.27.2",
|
|
21
|
-
"titanpl-sdk": "2.0.4"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"@tgrv/microgravity": "latest"
|
|
14
|
+
"@titanpl/sdk": "7.0.0-beta"
|
|
25
15
|
}
|
|
26
16
|
}
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"functions": {
|
|
8
|
-
"add": {
|
|
9
|
-
"symbol": "add",
|
|
10
|
-
"parameters": [
|
|
11
|
-
"f64",
|
|
12
|
-
"f64"
|
|
13
|
-
],
|
|
14
|
-
"result": "f64"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
2
|
+
"name": "my-extension",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "wasm",
|
|
5
|
+
"entry": "index.js",
|
|
6
|
+
"description": "A high-performance TitanPL extension."
|
|
18
7
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// utils/registerExtension.js
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Safely registers an extension in the global t object
|
|
5
|
+
* @param {string} extensionName - Unique name for the extension
|
|
6
|
+
* @param {any} extensionModule - The extension module/object to register
|
|
7
|
+
* @returns {boolean} True if registration was successful
|
|
8
|
+
*/
|
|
9
|
+
export function registerExtension(extensionName, extensionModule) {
|
|
10
|
+
// Check for global t object
|
|
11
|
+
if (typeof t === 'undefined') {
|
|
12
|
+
console.warn(`[registerExtension] Global 't' object not available. Cannot register: ${extensionName}`);
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Input validation
|
|
17
|
+
if (!extensionName || typeof extensionName !== 'string') {
|
|
18
|
+
console.error('[registerExtension] Invalid extension name provided');
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Check for naming conflicts
|
|
23
|
+
if (t[extensionName]) {
|
|
24
|
+
console.warn(`[registerExtension] '${extensionName}' already exists in global t object, overwriting`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
// Register the extension
|
|
29
|
+
t[extensionName] = extensionModule;
|
|
30
|
+
|
|
31
|
+
console.log(`[registerExtension] Successfully registered '${extensionName}'`);
|
|
32
|
+
|
|
33
|
+
return true;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
// Structured error reporting
|
|
36
|
+
console.error(`[registerExtension] Failed to register '${extensionName}':`, {
|
|
37
|
+
error: error.message,
|
|
38
|
+
extensionName,
|
|
39
|
+
moduleType: typeof extensionModule
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
"template": "js"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@titanpl/cli": "
|
|
10
|
-
"@titanpl/route": "
|
|
11
|
-
"@titanpl/native": "
|
|
9
|
+
"@titanpl/cli": "7.0.0-beta",
|
|
10
|
+
"@titanpl/route": "7.0.0-beta",
|
|
11
|
+
"@titanpl/native": "7.0.0-beta",
|
|
12
12
|
"@titanpl/core": "latest",
|
|
13
13
|
"@titanpl/node": "latest",
|
|
14
|
-
"@titanpl/packet": "
|
|
14
|
+
"@titanpl/packet": "7.0.0-beta"
|
|
15
15
|
},
|
|
16
16
|
"optionalDependencies": {
|
|
17
|
-
"@titanpl/engine-linux-x64": "
|
|
18
|
-
"@titanpl/engine-win32-x64": "
|
|
17
|
+
"@titanpl/engine-linux-x64": "7.0.0-beta",
|
|
18
|
+
"@titanpl/engine-win32-x64": "7.0.0-beta"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "titan build",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"eslint": "^9.39.2",
|
|
29
29
|
"eslint-plugin-titanpl": "latest"
|
|
30
30
|
},
|
|
31
|
-
"version": "
|
|
32
|
-
}
|
|
31
|
+
"version": "7.0.0-beta"
|
|
32
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "titanpl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-beta",
|
|
4
4
|
"description": "A Titan Planet server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"titan": {
|
|
7
7
|
"template": "rust-js"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@titanpl/cli": "
|
|
11
|
-
"@titanpl/route": "
|
|
12
|
-
"@titanpl/native": "
|
|
10
|
+
"@titanpl/cli": "7.0.0-beta",
|
|
11
|
+
"@titanpl/route": "7.0.0-beta",
|
|
12
|
+
"@titanpl/native": "7.0.0-beta",
|
|
13
13
|
"@titanpl/core": "latest",
|
|
14
14
|
"@titanpl/node": "latest"
|
|
15
15
|
},
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "titanpl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-beta",
|
|
4
4
|
"description": "A Titan Planet server (Rust + TypeScript)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"titan": {
|
|
7
7
|
"template": "rust-ts"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@titanpl/cli": "
|
|
11
|
-
"@titanpl/route": "
|
|
12
|
-
"@titanpl/native": "
|
|
10
|
+
"@titanpl/cli": "7.0.0-beta",
|
|
11
|
+
"@titanpl/route": "7.0.0-beta",
|
|
12
|
+
"@titanpl/native": "7.0.0-beta",
|
|
13
13
|
"@titanpl/core": "latest",
|
|
14
14
|
"@titanpl/node": "latest",
|
|
15
15
|
"typescript": "^5.0.0"
|
|
@@ -6,18 +6,18 @@
|
|
|
6
6
|
"template": "ts"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@titanpl/cli": "
|
|
10
|
-
"@titanpl/route": "
|
|
11
|
-
"@titanpl/native": "
|
|
9
|
+
"@titanpl/cli": "7.0.0-beta",
|
|
10
|
+
"@titanpl/route": "7.0.0-beta",
|
|
11
|
+
"@titanpl/native": "7.0.0-beta",
|
|
12
12
|
"@titanpl/core": "latest",
|
|
13
13
|
"@titanpl/node": "latest",
|
|
14
|
-
"@titanpl/packet": "
|
|
14
|
+
"@titanpl/packet": "7.0.0-beta",
|
|
15
15
|
"typescript": "^5.0.0"
|
|
16
16
|
},
|
|
17
17
|
"optionalDependencies": {
|
|
18
18
|
"@titanpl/engine-linux-arm64": "2.0.5",
|
|
19
|
-
"@titanpl/engine-linux-x64": "
|
|
20
|
-
"@titanpl/engine-win32-x64": "
|
|
19
|
+
"@titanpl/engine-linux-x64": "7.0.0-beta",
|
|
20
|
+
"@titanpl/engine-win32-x64": "7.0.0-beta"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "titan build",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"eslint-plugin-titanpl": "latest",
|
|
32
32
|
"@typescript-eslint/parser": "^8.54.0"
|
|
33
33
|
},
|
|
34
|
-
"version": "
|
|
35
|
-
}
|
|
34
|
+
"version": "7.0.0-beta"
|
|
35
|
+
}
|