@niledatabase/server 5.3.3-alpha.2 → 5.3.3-alpha.3
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 +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +21 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +25 -38
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import pg, { Pool,
|
|
1
|
+
import pg, { Pool, PoolClient, PoolConfig } from 'pg';
|
|
2
2
|
|
|
3
3
|
type LogFunction = (message: string | unknown, meta?: Record<string, unknown>) => void;
|
|
4
4
|
type Loggable = {
|
|
@@ -611,11 +611,11 @@ type ExtensionResult<TParams> = {
|
|
|
611
611
|
id: string;
|
|
612
612
|
withContext?: (ctx: CTX) => Promise<void>;
|
|
613
613
|
onRequest?: (params: TParams, ctx: CTX) => void | Promise<void | RequestInit>;
|
|
614
|
-
onResponse?: (params: TParams, ctx: CTX) => void | Promise<void>;
|
|
614
|
+
onResponse?: (params: TParams, ctx: CTX) => void | Response | Promise<void | Response>;
|
|
615
615
|
onHandleRequest?: (params?: TParams) => RouteReturn | Promise<RouteReturn>;
|
|
616
616
|
onConfigure?: (instance: Server) => void;
|
|
617
|
-
withUserId?: () => string
|
|
618
|
-
withTenantId?: () => string
|
|
617
|
+
withUserId?: () => string | null | undefined | Promise<string | null | undefined>;
|
|
618
|
+
withTenantId?: () => string | null | undefined | Promise<string | null | undefined>;
|
|
619
619
|
replace?: {
|
|
620
620
|
handlers: (handlers: NileHandlers) => Any;
|
|
621
621
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import pg, { Pool,
|
|
1
|
+
import pg, { Pool, PoolClient, PoolConfig } from 'pg';
|
|
2
2
|
|
|
3
3
|
type LogFunction = (message: string | unknown, meta?: Record<string, unknown>) => void;
|
|
4
4
|
type Loggable = {
|
|
@@ -611,11 +611,11 @@ type ExtensionResult<TParams> = {
|
|
|
611
611
|
id: string;
|
|
612
612
|
withContext?: (ctx: CTX) => Promise<void>;
|
|
613
613
|
onRequest?: (params: TParams, ctx: CTX) => void | Promise<void | RequestInit>;
|
|
614
|
-
onResponse?: (params: TParams, ctx: CTX) => void | Promise<void>;
|
|
614
|
+
onResponse?: (params: TParams, ctx: CTX) => void | Response | Promise<void | Response>;
|
|
615
615
|
onHandleRequest?: (params?: TParams) => RouteReturn | Promise<RouteReturn>;
|
|
616
616
|
onConfigure?: (instance: Server) => void;
|
|
617
|
-
withUserId?: () => string
|
|
618
|
-
withTenantId?: () => string
|
|
617
|
+
withUserId?: () => string | null | undefined | Promise<string | null | undefined>;
|
|
618
|
+
withTenantId?: () => string | null | undefined | Promise<string | null | undefined>;
|
|
619
619
|
replace?: {
|
|
620
620
|
handlers: (handlers: NileHandlers) => Any;
|
|
621
621
|
};
|
package/dist/index.js
CHANGED
|
@@ -80,7 +80,6 @@ function assertValidUUID(val, fieldName) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
// src/api/utils/routes/index.ts
|
|
83
|
-
var NILEDB_API_URL = process.env.NILEDB_API_URL;
|
|
84
83
|
var DEFAULT_PREFIX = "/api";
|
|
85
84
|
var PROVIDER_SLUG_REGEX = /^[a-z0-9_-]+$/i;
|
|
86
85
|
function isValidProviderSlug(value) {
|
|
@@ -153,7 +152,7 @@ function filterNullUndefined(obj) {
|
|
|
153
152
|
);
|
|
154
153
|
}
|
|
155
154
|
function makeRestUrl(apiUrl, path, qp) {
|
|
156
|
-
const url = apiUrl || NILEDB_API_URL;
|
|
155
|
+
const url = apiUrl || process.env.NILEDB_API_URL;
|
|
157
156
|
if (!url) {
|
|
158
157
|
throw new Error(
|
|
159
158
|
"An API url is required. Set it via NILEDB_API_URL. Was auto configuration run?"
|
|
@@ -163,7 +162,9 @@ function makeRestUrl(apiUrl, path, qp) {
|
|
|
163
162
|
filterNullUndefined(qp)
|
|
164
163
|
);
|
|
165
164
|
const strParams = params.toString();
|
|
166
|
-
|
|
165
|
+
const base = url.replace(/\/+$/, "");
|
|
166
|
+
const cleanPath = path.replace(/^\/+/, "");
|
|
167
|
+
return `${base}/${cleanPath}${strParams ? `?${strParams}` : ""}`;
|
|
167
168
|
}
|
|
168
169
|
function normalizePathname(pathname) {
|
|
169
170
|
const trimmed = pathname.replace(/\/+$/, "");
|
|
@@ -695,11 +696,14 @@ async function withNileContext(config, fn, nameOrOptions = "unknown") {
|
|
|
695
696
|
});
|
|
696
697
|
}
|
|
697
698
|
function parseCookieHeader(header) {
|
|
698
|
-
return header.split(";").map((c) => c.trim()).filter(Boolean).reduce(
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
699
|
+
return header.split(";").map((c) => c.trim()).filter(Boolean).reduce(
|
|
700
|
+
(acc, curr) => {
|
|
701
|
+
const [key18, ...val] = curr.split("=");
|
|
702
|
+
if (key18) acc[key18] = val.join("=");
|
|
703
|
+
return acc;
|
|
704
|
+
},
|
|
705
|
+
{}
|
|
706
|
+
);
|
|
703
707
|
}
|
|
704
708
|
function serializeCookies(cookies) {
|
|
705
709
|
return Object.entries(cookies).map(([k, v]) => `${k}=${v}`).join("; ");
|
|
@@ -784,7 +788,7 @@ async function request(url, _init, config) {
|
|
|
784
788
|
if (bodyStream === request2.body) {
|
|
785
789
|
try {
|
|
786
790
|
bodyText = await request2.clone().text();
|
|
787
|
-
} catch
|
|
791
|
+
} catch {
|
|
788
792
|
bodyText = await new Response(bodyStream).text();
|
|
789
793
|
}
|
|
790
794
|
} else {
|
|
@@ -802,7 +806,7 @@ async function request(url, _init, config) {
|
|
|
802
806
|
params.body = bodyText;
|
|
803
807
|
}
|
|
804
808
|
}
|
|
805
|
-
} catch
|
|
809
|
+
} catch {
|
|
806
810
|
error("Failed to parse request body");
|
|
807
811
|
}
|
|
808
812
|
}
|
|
@@ -2348,7 +2352,7 @@ var getUsername = (cfg) => {
|
|
|
2348
2352
|
if (url.username) {
|
|
2349
2353
|
return decodeURIComponent(url.username);
|
|
2350
2354
|
}
|
|
2351
|
-
} catch
|
|
2355
|
+
} catch {
|
|
2352
2356
|
}
|
|
2353
2357
|
}
|
|
2354
2358
|
throw new Error(
|
|
@@ -2360,7 +2364,7 @@ var getPassword = (cfg) => {
|
|
|
2360
2364
|
const logger = config.logger;
|
|
2361
2365
|
const log = logProtector(logger);
|
|
2362
2366
|
if (stringCheck(config?.password)) {
|
|
2363
|
-
log
|
|
2367
|
+
log?.("[config]").info("***");
|
|
2364
2368
|
return String(config?.password);
|
|
2365
2369
|
}
|
|
2366
2370
|
const pass = stringCheck(process.env.NILEDB_PASSWORD);
|
|
@@ -2375,7 +2379,7 @@ var getPassword = (cfg) => {
|
|
|
2375
2379
|
if (url.password) {
|
|
2376
2380
|
return decodeURIComponent(url.password);
|
|
2377
2381
|
}
|
|
2378
|
-
} catch
|
|
2382
|
+
} catch {
|
|
2379
2383
|
}
|
|
2380
2384
|
}
|
|
2381
2385
|
throw new Error(
|
|
@@ -2402,7 +2406,7 @@ var getDatabaseName = (cfg) => {
|
|
|
2402
2406
|
if (dbName) {
|
|
2403
2407
|
return dbName;
|
|
2404
2408
|
}
|
|
2405
|
-
} catch
|
|
2409
|
+
} catch {
|
|
2406
2410
|
}
|
|
2407
2411
|
}
|
|
2408
2412
|
throw new Error(
|
|
@@ -2440,7 +2444,7 @@ function getDbHost(cfg) {
|
|
|
2440
2444
|
const pgUrl = new URL(pg2);
|
|
2441
2445
|
info(`[NILEDB_POSTGRES_URL] ${pgUrl.hostname}`);
|
|
2442
2446
|
return pgUrl.hostname;
|
|
2443
|
-
} catch
|
|
2447
|
+
} catch {
|
|
2444
2448
|
}
|
|
2445
2449
|
}
|
|
2446
2450
|
info("[default] db.thenile.dev");
|
|
@@ -2465,7 +2469,7 @@ function getDbPort(cfg) {
|
|
|
2465
2469
|
if (pgUrl.port) {
|
|
2466
2470
|
return Number(pgUrl.port);
|
|
2467
2471
|
}
|
|
2468
|
-
} catch
|
|
2472
|
+
} catch {
|
|
2469
2473
|
}
|
|
2470
2474
|
}
|
|
2471
2475
|
info("[default] 5432");
|
|
@@ -4331,7 +4335,7 @@ function updateConfig(response, config, req) {
|
|
|
4331
4335
|
}
|
|
4332
4336
|
|
|
4333
4337
|
// src/Server.ts
|
|
4334
|
-
var SCOPED_INIT = Symbol("SCOPED_INIT");
|
|
4338
|
+
var SCOPED_INIT = /* @__PURE__ */ Symbol("SCOPED_INIT");
|
|
4335
4339
|
var Server = class _Server {
|
|
4336
4340
|
users;
|
|
4337
4341
|
tenants;
|