@ariacompute/router-ts 1.3.0 → 1.3.2
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 +1 -1
- package/src/index.js +25 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -64,6 +64,12 @@ export class Router {
|
|
|
64
64
|
setup(u = {}) {
|
|
65
65
|
if (u.base_url !== undefined) this._auth.base_url = u.base_url;
|
|
66
66
|
if (u.token !== undefined) this._auth.token = u.token;
|
|
67
|
+
if (this._handle) {
|
|
68
|
+
this._syncFfiSetup(
|
|
69
|
+
u.base_url !== undefined ? u.base_url : null,
|
|
70
|
+
u.token !== undefined ? u.token : null,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
67
73
|
return this;
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -73,6 +79,7 @@ export class Router {
|
|
|
73
79
|
|
|
74
80
|
setupClear() {
|
|
75
81
|
this._auth = { base_url: "", token: "" };
|
|
82
|
+
if (this._handle) this._syncFfiSetup("", "");
|
|
76
83
|
return this;
|
|
77
84
|
}
|
|
78
85
|
|
|
@@ -83,6 +90,7 @@ export class Router {
|
|
|
83
90
|
this._fn.init = this._lib.func("aria_router_init", "void*", ["str"]);
|
|
84
91
|
this._fn.connect = this._lib.func("aria_router_connect", "void*", ["str"]);
|
|
85
92
|
this._fn.destroy = this._lib.func("aria_router_destroy", "void", ["void*"]);
|
|
93
|
+
this._fn.setup = this._lib.func("aria_router_setup", "void", ["void*", "str", "str"]);
|
|
86
94
|
this._fn.complete = this._lib.func("aria_router_complete", "int", [
|
|
87
95
|
"void*",
|
|
88
96
|
"str",
|
|
@@ -99,6 +107,21 @@ export class Router {
|
|
|
99
107
|
this._fn.lastError = this._lib.func("aria_router_last_error", "str", []);
|
|
100
108
|
}
|
|
101
109
|
|
|
110
|
+
_syncFfiSetup(baseUrl, token) {
|
|
111
|
+
if (!this._handle || !this._fn.setup) return;
|
|
112
|
+
// koffi: null → NULL pointer (leave unchanged); string updates field.
|
|
113
|
+
this._fn.setup(this._handle, baseUrl, token);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
_syncAuthIfSet() {
|
|
117
|
+
if (this._auth.base_url || this._auth.token) {
|
|
118
|
+
this._syncFfiSetup(
|
|
119
|
+
this._auth.base_url || null,
|
|
120
|
+
this._auth.token || null,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
102
125
|
_err(fallback) {
|
|
103
126
|
const err = this._fn.lastError?.();
|
|
104
127
|
return err || fallback;
|
|
@@ -113,6 +136,7 @@ export class Router {
|
|
|
113
136
|
}
|
|
114
137
|
this._handle = this._fn.init(pathArg);
|
|
115
138
|
if (!this._handle) throw new Error(this._err("init failed"));
|
|
139
|
+
this._syncAuthIfSet();
|
|
116
140
|
return this;
|
|
117
141
|
}
|
|
118
142
|
|
|
@@ -121,6 +145,7 @@ export class Router {
|
|
|
121
145
|
if (this._handle) this.close();
|
|
122
146
|
this._handle = this._fn.connect(baseUrl);
|
|
123
147
|
if (!this._handle) throw new Error(this._err("connect failed"));
|
|
148
|
+
this._syncAuthIfSet();
|
|
124
149
|
return this;
|
|
125
150
|
}
|
|
126
151
|
|