@niledatabase/server 5.0.0-alpha.16 → 5.0.0-alpha.17
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/index.d.mts +2 -6
- package/dist/index.d.ts +2 -6
- package/dist/index.js +24 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -557,12 +557,7 @@ declare class Server {
|
|
|
557
557
|
tenantId?: string;
|
|
558
558
|
userId?: string;
|
|
559
559
|
}, ...remaining: unknown[]) => void;
|
|
560
|
-
getContext():
|
|
561
|
-
headers: Headers | undefined;
|
|
562
|
-
userId: string | null | undefined;
|
|
563
|
-
tenantId: string | null | undefined;
|
|
564
|
-
preserveHeaders: boolean;
|
|
565
|
-
};
|
|
560
|
+
getContext(): any;
|
|
566
561
|
}
|
|
567
562
|
declare function create(config?: NileConfig): Server;
|
|
568
563
|
|
|
@@ -578,6 +573,7 @@ type ExtensionResult = {
|
|
|
578
573
|
onHandleRequest?: (...params: Any) => RouteReturn | Promise<RouteReturn>;
|
|
579
574
|
onConfigure?: (...params: Any) => void;
|
|
580
575
|
onSetContext?: (...params: Any) => void;
|
|
576
|
+
onGetContext?: () => Any;
|
|
581
577
|
};
|
|
582
578
|
type Extension = (instance: Server) => ExtensionResult;
|
|
583
579
|
declare enum ExtensionState {
|
package/dist/index.d.ts
CHANGED
|
@@ -557,12 +557,7 @@ declare class Server {
|
|
|
557
557
|
tenantId?: string;
|
|
558
558
|
userId?: string;
|
|
559
559
|
}, ...remaining: unknown[]) => void;
|
|
560
|
-
getContext():
|
|
561
|
-
headers: Headers | undefined;
|
|
562
|
-
userId: string | null | undefined;
|
|
563
|
-
tenantId: string | null | undefined;
|
|
564
|
-
preserveHeaders: boolean;
|
|
565
|
-
};
|
|
560
|
+
getContext(): any;
|
|
566
561
|
}
|
|
567
562
|
declare function create(config?: NileConfig): Server;
|
|
568
563
|
|
|
@@ -578,6 +573,7 @@ type ExtensionResult = {
|
|
|
578
573
|
onHandleRequest?: (...params: Any) => RouteReturn | Promise<RouteReturn>;
|
|
579
574
|
onConfigure?: (...params: Any) => void;
|
|
580
575
|
onSetContext?: (...params: Any) => void;
|
|
576
|
+
onGetContext?: () => Any;
|
|
581
577
|
};
|
|
582
578
|
type Extension = (instance: Server) => ExtensionResult;
|
|
583
579
|
declare enum ExtensionState {
|
package/dist/index.js
CHANGED
|
@@ -3229,6 +3229,19 @@ var Server = class {
|
|
|
3229
3229
|
* @returns undefined
|
|
3230
3230
|
*/
|
|
3231
3231
|
setContext = (req, ...remaining) => {
|
|
3232
|
+
let ok = false;
|
|
3233
|
+
if (req && typeof req === "object" && "tenantId" in req) {
|
|
3234
|
+
ok = true;
|
|
3235
|
+
this.#config.tenantId = req.tenantId;
|
|
3236
|
+
}
|
|
3237
|
+
if (req && typeof req === "object" && "userId" in req) {
|
|
3238
|
+
ok = true;
|
|
3239
|
+
this.#config.userId = req.userId;
|
|
3240
|
+
}
|
|
3241
|
+
if (req && typeof req === "object" && "preserveHeaders" in req) {
|
|
3242
|
+
ok = true;
|
|
3243
|
+
this.#preserveHeaders = Boolean(req.preserveHeaders);
|
|
3244
|
+
}
|
|
3232
3245
|
let atLeastOne = false;
|
|
3233
3246
|
if (this.#config?.extensions) {
|
|
3234
3247
|
for (const create2 of this.#config.extensions) {
|
|
@@ -3261,19 +3274,6 @@ var Server = class {
|
|
|
3261
3274
|
}
|
|
3262
3275
|
} catch {
|
|
3263
3276
|
}
|
|
3264
|
-
let ok = false;
|
|
3265
|
-
if (req && typeof req === "object" && "tenantId" in req) {
|
|
3266
|
-
ok = true;
|
|
3267
|
-
this.#config.tenantId = req.tenantId;
|
|
3268
|
-
}
|
|
3269
|
-
if (req && typeof req === "object" && "userId" in req) {
|
|
3270
|
-
ok = true;
|
|
3271
|
-
this.#config.userId = req.userId;
|
|
3272
|
-
}
|
|
3273
|
-
if (req && typeof req === "object" && "preserveHeaders" in req) {
|
|
3274
|
-
ok = true;
|
|
3275
|
-
this.#preserveHeaders = Boolean(req.preserveHeaders);
|
|
3276
|
-
}
|
|
3277
3277
|
if (ok) {
|
|
3278
3278
|
return;
|
|
3279
3279
|
}
|
|
@@ -3296,6 +3296,17 @@ var Server = class {
|
|
|
3296
3296
|
}
|
|
3297
3297
|
};
|
|
3298
3298
|
getContext() {
|
|
3299
|
+
if (this.#config?.extensions) {
|
|
3300
|
+
for (const create2 of this.#config.extensions) {
|
|
3301
|
+
if (typeof create2 !== "function") {
|
|
3302
|
+
continue;
|
|
3303
|
+
}
|
|
3304
|
+
const ext = create2(this);
|
|
3305
|
+
if (typeof ext.onGetContext === "function") {
|
|
3306
|
+
return ext.onGetContext();
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3299
3310
|
return {
|
|
3300
3311
|
headers: this.#headers,
|
|
3301
3312
|
userId: this.#config?.userId,
|