@luxdb/sdk 2.1.0 → 2.2.1
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/cjs/project.js +15 -8
- package/dist/cjs/ssr.js +6 -3
- package/dist/esm/project.js +15 -8
- package/dist/esm/ssr.js +6 -3
- package/dist/types/ssr.d.ts +7 -2
- package/package.json +1 -1
package/dist/cjs/project.js
CHANGED
|
@@ -665,29 +665,26 @@ function unwrapResult(payload) {
|
|
|
665
665
|
}
|
|
666
666
|
return payload;
|
|
667
667
|
}
|
|
668
|
-
function normalizeWhere(where) {
|
|
669
|
-
return where.trim().replace(/\s*(>=|<=|!=|=|>|<)\s*/g, ' $1 ');
|
|
670
|
-
}
|
|
671
668
|
function filtersToWhere(filters) {
|
|
672
669
|
return filters.map((filter) => {
|
|
673
670
|
const op = filterOperatorToWhere(filter.operator);
|
|
674
671
|
if (filter.operator === 'in' || filter.operator === 'notIn') {
|
|
675
672
|
const values = Array.isArray(filter.value) ? filter.value : [filter.value];
|
|
676
|
-
return
|
|
673
|
+
return `${filter.column} ${op} ( ${values.map(formatWhereValue).join(' ')} )`;
|
|
677
674
|
}
|
|
678
675
|
if (filter.operator === 'isValid' ||
|
|
679
676
|
filter.operator === 'isNotValid' ||
|
|
680
677
|
filter.operator === 'isNull' ||
|
|
681
678
|
filter.operator === 'isNotNull') {
|
|
682
|
-
return
|
|
679
|
+
return `${filter.column} ${op}`;
|
|
683
680
|
}
|
|
684
|
-
return
|
|
681
|
+
return `${filter.column} ${op} ${formatWhereValue(filter.value)}`;
|
|
685
682
|
}).join(' AND ');
|
|
686
683
|
}
|
|
687
684
|
function havingToWhere(filters) {
|
|
688
685
|
return filters.map((filter) => {
|
|
689
686
|
const op = filterOperatorToWhere(filter.operator);
|
|
690
|
-
return
|
|
687
|
+
return `${filter.column} ${op} ${formatWhereValue(filter.value)}`;
|
|
691
688
|
}).join(' AND ');
|
|
692
689
|
}
|
|
693
690
|
function filterOperatorToWhere(operator) {
|
|
@@ -724,7 +721,17 @@ function filterOperatorToWhere(operator) {
|
|
|
724
721
|
function formatWhereValue(value) {
|
|
725
722
|
if (value === null)
|
|
726
723
|
return '';
|
|
727
|
-
|
|
724
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
725
|
+
return String(value);
|
|
726
|
+
const str = String(value);
|
|
727
|
+
// Only quote values that would otherwise be split by the engine's WHERE
|
|
728
|
+
// tokenizer (whitespace), or that start with a quote (which the tokenizer
|
|
729
|
+
// would treat as an opening quote). Everything else stays bare, so simple
|
|
730
|
+
// values keep working against engines that predate quoted-WHERE support.
|
|
731
|
+
if (!/\s/.test(str) && !str.startsWith("'"))
|
|
732
|
+
return str;
|
|
733
|
+
const escaped = str.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
734
|
+
return `'${escaped}'`;
|
|
728
735
|
}
|
|
729
736
|
function createProjectClient(options) {
|
|
730
737
|
return new LuxProjectClient(options);
|
package/dist/cjs/ssr.js
CHANGED
|
@@ -3,21 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createServerClient = createServerClient;
|
|
4
4
|
const project_1 = require("./project");
|
|
5
5
|
const DEFAULT_COOKIE = 'lux-auth-session';
|
|
6
|
-
function createServerClient(url, key, options) {
|
|
6
|
+
function createServerClient(url, key, options = {}) {
|
|
7
7
|
const storageKey = options.auth?.storageKey ?? DEFAULT_COOKIE;
|
|
8
8
|
const cookieOptions = options.auth?.cookieOptions ?? {
|
|
9
9
|
path: '/',
|
|
10
10
|
sameSite: 'lax',
|
|
11
11
|
};
|
|
12
12
|
const { cookieOptions: _cookieOptions, ...authOptions } = options.auth ?? {};
|
|
13
|
+
// With cookies -> cookie-backed session (SSR). Without -> stateless backend
|
|
14
|
+
// client: no session storage, nothing to persist.
|
|
15
|
+
const hasCookies = options.cookies !== undefined;
|
|
13
16
|
return (0, project_1.createClient)(url, key, {
|
|
14
17
|
fetch: options.fetch,
|
|
15
18
|
auth: {
|
|
16
|
-
persistSession:
|
|
19
|
+
persistSession: hasCookies,
|
|
17
20
|
autoRefreshToken: false,
|
|
18
21
|
...authOptions,
|
|
19
22
|
storageKey,
|
|
20
|
-
storage: cookieStorage(options.cookies, cookieOptions),
|
|
23
|
+
storage: hasCookies ? cookieStorage(options.cookies, cookieOptions) : null,
|
|
21
24
|
},
|
|
22
25
|
});
|
|
23
26
|
}
|
package/dist/esm/project.js
CHANGED
|
@@ -654,29 +654,26 @@ function unwrapResult(payload) {
|
|
|
654
654
|
}
|
|
655
655
|
return payload;
|
|
656
656
|
}
|
|
657
|
-
function normalizeWhere(where) {
|
|
658
|
-
return where.trim().replace(/\s*(>=|<=|!=|=|>|<)\s*/g, ' $1 ');
|
|
659
|
-
}
|
|
660
657
|
function filtersToWhere(filters) {
|
|
661
658
|
return filters.map((filter) => {
|
|
662
659
|
const op = filterOperatorToWhere(filter.operator);
|
|
663
660
|
if (filter.operator === 'in' || filter.operator === 'notIn') {
|
|
664
661
|
const values = Array.isArray(filter.value) ? filter.value : [filter.value];
|
|
665
|
-
return
|
|
662
|
+
return `${filter.column} ${op} ( ${values.map(formatWhereValue).join(' ')} )`;
|
|
666
663
|
}
|
|
667
664
|
if (filter.operator === 'isValid' ||
|
|
668
665
|
filter.operator === 'isNotValid' ||
|
|
669
666
|
filter.operator === 'isNull' ||
|
|
670
667
|
filter.operator === 'isNotNull') {
|
|
671
|
-
return
|
|
668
|
+
return `${filter.column} ${op}`;
|
|
672
669
|
}
|
|
673
|
-
return
|
|
670
|
+
return `${filter.column} ${op} ${formatWhereValue(filter.value)}`;
|
|
674
671
|
}).join(' AND ');
|
|
675
672
|
}
|
|
676
673
|
function havingToWhere(filters) {
|
|
677
674
|
return filters.map((filter) => {
|
|
678
675
|
const op = filterOperatorToWhere(filter.operator);
|
|
679
|
-
return
|
|
676
|
+
return `${filter.column} ${op} ${formatWhereValue(filter.value)}`;
|
|
680
677
|
}).join(' AND ');
|
|
681
678
|
}
|
|
682
679
|
function filterOperatorToWhere(operator) {
|
|
@@ -713,7 +710,17 @@ function filterOperatorToWhere(operator) {
|
|
|
713
710
|
function formatWhereValue(value) {
|
|
714
711
|
if (value === null)
|
|
715
712
|
return '';
|
|
716
|
-
|
|
713
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
714
|
+
return String(value);
|
|
715
|
+
const str = String(value);
|
|
716
|
+
// Only quote values that would otherwise be split by the engine's WHERE
|
|
717
|
+
// tokenizer (whitespace), or that start with a quote (which the tokenizer
|
|
718
|
+
// would treat as an opening quote). Everything else stays bare, so simple
|
|
719
|
+
// values keep working against engines that predate quoted-WHERE support.
|
|
720
|
+
if (!/\s/.test(str) && !str.startsWith("'"))
|
|
721
|
+
return str;
|
|
722
|
+
const escaped = str.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
723
|
+
return `'${escaped}'`;
|
|
717
724
|
}
|
|
718
725
|
export function createProjectClient(options) {
|
|
719
726
|
return new LuxProjectClient(options);
|
package/dist/esm/ssr.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { createClient } from './project.js';
|
|
2
2
|
const DEFAULT_COOKIE = 'lux-auth-session';
|
|
3
|
-
export function createServerClient(url, key, options) {
|
|
3
|
+
export function createServerClient(url, key, options = {}) {
|
|
4
4
|
const storageKey = options.auth?.storageKey ?? DEFAULT_COOKIE;
|
|
5
5
|
const cookieOptions = options.auth?.cookieOptions ?? {
|
|
6
6
|
path: '/',
|
|
7
7
|
sameSite: 'lax',
|
|
8
8
|
};
|
|
9
9
|
const { cookieOptions: _cookieOptions, ...authOptions } = options.auth ?? {};
|
|
10
|
+
// With cookies -> cookie-backed session (SSR). Without -> stateless backend
|
|
11
|
+
// client: no session storage, nothing to persist.
|
|
12
|
+
const hasCookies = options.cookies !== undefined;
|
|
10
13
|
return createClient(url, key, {
|
|
11
14
|
fetch: options.fetch,
|
|
12
15
|
auth: {
|
|
13
|
-
persistSession:
|
|
16
|
+
persistSession: hasCookies,
|
|
14
17
|
autoRefreshToken: false,
|
|
15
18
|
...authOptions,
|
|
16
19
|
storageKey,
|
|
17
|
-
storage: cookieStorage(options.cookies, cookieOptions),
|
|
20
|
+
storage: hasCookies ? cookieStorage(options.cookies, cookieOptions) : null,
|
|
18
21
|
},
|
|
19
22
|
});
|
|
20
23
|
}
|
package/dist/types/ssr.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ export interface LuxServerClientOptions extends Omit<LuxProjectOptions, 'url' |
|
|
|
17
17
|
auth?: Omit<NonNullable<LuxProjectOptions['auth']>, 'storage'> & {
|
|
18
18
|
cookieOptions?: LuxCookieOptions;
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Cookie adapter for SSR session persistence (Next/SvelteKit/etc). Omit it
|
|
22
|
+
* for a stateless backend client (secret key, or `setSession` per request):
|
|
23
|
+
* `createServerClient(url, key)` then works with no cookie plumbing.
|
|
24
|
+
*/
|
|
25
|
+
cookies?: LuxCookieMethods;
|
|
21
26
|
}
|
|
22
|
-
export declare function createServerClient(url: string, key: string, options
|
|
27
|
+
export declare function createServerClient(url: string, key: string, options?: LuxServerClientOptions): import("./project").LuxProjectClient;
|
package/package.json
CHANGED