@wxn0brp/db-core 0.12.13 → 0.12.14
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/types/arg.d.ts +8 -0
- package/dist/types/collection.d.ts +1 -0
- package/dist/types/export.d.ts +2 -0
- package/dist/types/query.d.ts +7 -0
- package/dist/types/searchOpts.d.ts +12 -2
- package/dist/types/types.d.ts +3 -0
- package/dist/utils/deprecation.d.ts +1 -0
- package/dist/utils/deprecation.js +15 -0
- package/dist/utils/hasFieldsAdvanced.js +3 -0
- package/dist/utils/process.js +7 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/types/arg.d.ts
CHANGED
|
@@ -5,7 +5,15 @@ import { UpdaterArg } from "./updater.js";
|
|
|
5
5
|
export type Arg<T = any> = {
|
|
6
6
|
[K in keyof T]?: any;
|
|
7
7
|
} & Record<string, any>;
|
|
8
|
+
/**
|
|
9
|
+
* Function-based search.
|
|
10
|
+
* @deprecated Use operator objects or a plugin instead.
|
|
11
|
+
*/
|
|
8
12
|
export type SearchFunc<T = any> = (data: T, context: VContext) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Function-based updater.
|
|
15
|
+
* @deprecated Use operator objects instead.
|
|
16
|
+
*/
|
|
9
17
|
export type UpdaterFunc<T = any> = (data: T, context: VContext) => Data | void;
|
|
10
18
|
export type Search<T = any, AllowFn extends boolean = true> = AllowFn extends true ? SearchOptions<T> | SearchFunc<T> : SearchOptions<T>;
|
|
11
19
|
export type Updater<T = any, AllowFn extends boolean = true> = AllowFn extends true ? UpdaterArg<T> | UpdaterFunc<T> : UpdaterArg<T>;
|
package/dist/types/export.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export declare namespace ValtheraTypes {
|
|
|
10
10
|
type Data = import("./data.js").Data;
|
|
11
11
|
type SearchOptions = import("./searchOpts.js").SearchOptions;
|
|
12
12
|
type Id = import("./Id.js").Id;
|
|
13
|
+
/** @deprecated */
|
|
13
14
|
type Context = import("./types.js").VContext;
|
|
15
|
+
/** @deprecated */
|
|
14
16
|
type VContext = import("./types.js").VContext;
|
|
15
17
|
}
|
package/dist/types/query.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export interface VQuery<T = Data, AllowFn extends boolean = true> {
|
|
|
19
19
|
/** logic path, dir or file, depends on context */
|
|
20
20
|
collection?: string;
|
|
21
21
|
search?: Search<T, AllowFn>;
|
|
22
|
+
/** @deprecated */
|
|
22
23
|
context?: VContext;
|
|
23
24
|
dbFindOpts?: DbFindOpts<T>;
|
|
24
25
|
findOpts?: FindOpts<T>;
|
|
@@ -49,20 +50,24 @@ export declare namespace VQueryT {
|
|
|
49
50
|
search?: Search<T, AllowFn>;
|
|
50
51
|
findOpts?: FindOpts<T>;
|
|
51
52
|
dbFindOpts?: DbFindOpts<T>;
|
|
53
|
+
/** @deprecated */
|
|
52
54
|
context?: VContext;
|
|
53
55
|
};
|
|
54
56
|
type FindOne<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
|
|
55
57
|
search: Search<T, AllowFn>;
|
|
56
58
|
findOpts?: FindOpts<T>;
|
|
59
|
+
/** @deprecated */
|
|
57
60
|
context?: VContext;
|
|
58
61
|
};
|
|
59
62
|
type Update<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
|
|
60
63
|
search: Search<T, AllowFn>;
|
|
61
64
|
updater: Updater<T, AllowFn>;
|
|
65
|
+
/** @deprecated */
|
|
62
66
|
context?: VContext;
|
|
63
67
|
};
|
|
64
68
|
type Remove<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
|
|
65
69
|
search: Search<T, AllowFn>;
|
|
70
|
+
/** @deprecated */
|
|
66
71
|
context?: VContext;
|
|
67
72
|
};
|
|
68
73
|
type UpdateOneOrAdd<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
|
|
@@ -70,11 +75,13 @@ export declare namespace VQueryT {
|
|
|
70
75
|
updater: Updater<T, AllowFn>;
|
|
71
76
|
add_arg?: Arg<T>;
|
|
72
77
|
id_gen?: boolean;
|
|
78
|
+
/** @deprecated */
|
|
73
79
|
context?: VContext;
|
|
74
80
|
};
|
|
75
81
|
type ToggleOne<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
|
|
76
82
|
search: Search<T, AllowFn>;
|
|
77
83
|
data: Arg<T>;
|
|
84
|
+
/** @deprecated */
|
|
78
85
|
context?: VContext;
|
|
79
86
|
};
|
|
80
87
|
interface UpdateOneOrAddResult<T> {
|
|
@@ -72,10 +72,20 @@ export type ArrayOperators<T = any> = {
|
|
|
72
72
|
/** [1, 2, 3] has size 3 */
|
|
73
73
|
$size?: NestedValue<T, number>;
|
|
74
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* Raw regex pattern string.
|
|
77
|
+
* @deprecated Pass a `RegExp` instance instead.
|
|
78
|
+
*/
|
|
79
|
+
export interface RawRegexPattern extends String {
|
|
80
|
+
}
|
|
75
81
|
/** String Operators with nested support */
|
|
76
82
|
export type StringOperators<T = any> = {
|
|
77
|
-
/**
|
|
78
|
-
|
|
83
|
+
/**
|
|
84
|
+
* "John" matches /oh/
|
|
85
|
+
*
|
|
86
|
+
* Prefer a `RegExp` instance; raw strings ({@link RawRegexPattern}) are deprecated.
|
|
87
|
+
*/
|
|
88
|
+
$regex?: NestedValue<T, RegExp | RawRegexPattern, string>;
|
|
79
89
|
/** "John" starts with "Jo" */
|
|
80
90
|
$startsWith?: NestedValue<T, string, string>;
|
|
81
91
|
/** "John" ends with "hn" */
|
package/dist/types/types.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function warnDeprecated(code: string, message: string): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const warned = new Set();
|
|
2
|
+
export function warnDeprecated(code, message) {
|
|
3
|
+
if (warned.has(code))
|
|
4
|
+
return;
|
|
5
|
+
warned.add(code);
|
|
6
|
+
const proc = globalThis.process;
|
|
7
|
+
if (typeof proc?.emitWarning === "function") {
|
|
8
|
+
proc.emitWarning(message, {
|
|
9
|
+
type: "DeprecationWarning",
|
|
10
|
+
code,
|
|
11
|
+
});
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
console.warn(message);
|
|
15
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { QueryValidationError } from "../errors.js";
|
|
2
|
+
import { warnDeprecated } from "./deprecation.js";
|
|
2
3
|
import { hasFields } from "./hasFields.js";
|
|
3
4
|
import { compareIds } from "./id.js";
|
|
4
5
|
import { isUnsafeKey } from "./security.js";
|
|
@@ -69,6 +70,8 @@ function mainCheck(obj, fields) {
|
|
|
69
70
|
regex: (data, regexData) => {
|
|
70
71
|
if (typeof data !== "string")
|
|
71
72
|
return false;
|
|
73
|
+
if (typeof regexData === "string")
|
|
74
|
+
warnDeprecated("VALTHERA_REGEX_STRING_PATTERN", "$regex with a string pattern is deprecated; pass a RegExp instance instead.");
|
|
72
75
|
const regex = typeof regexData === "string" ? new RegExp(regexData) : regexData;
|
|
73
76
|
return regex.test(data);
|
|
74
77
|
},
|
package/dist/utils/process.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { warnDeprecated } from "./deprecation.js";
|
|
1
2
|
import { hasFieldsAdvanced } from "./hasFieldsAdvanced.js";
|
|
2
3
|
import { updateFindObject } from "./updateFindObject.js";
|
|
3
4
|
import { updateObjectAdvanced } from "./updateObject.js";
|
|
@@ -10,8 +11,11 @@ export function matchObj(config, obj) {
|
|
|
10
11
|
const { search, context } = config;
|
|
11
12
|
if (search === undefined || search === null)
|
|
12
13
|
return true;
|
|
13
|
-
if (typeof search === "function"
|
|
14
|
-
|
|
14
|
+
if (typeof search === "function") {
|
|
15
|
+
warnDeprecated("VALTHERA_FUNCTION_SEARCH", "Function-based search is deprecated; use operator objects or a plugin.");
|
|
16
|
+
if (search(obj, context))
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
15
19
|
if (typeof search === "object" &&
|
|
16
20
|
!Array.isArray(search) &&
|
|
17
21
|
hasFieldsAdvanced(obj, search))
|
|
@@ -28,6 +32,7 @@ export function updateObj(config, obj) {
|
|
|
28
32
|
return obj;
|
|
29
33
|
}
|
|
30
34
|
if (typeof updater === "function") {
|
|
35
|
+
warnDeprecated("VALTHERA_FUNCTION_UPDATER", "Function-based updater is deprecated; use operator objects.");
|
|
31
36
|
const updateObjValue = updater(obj, context);
|
|
32
37
|
if (updateObjValue)
|
|
33
38
|
return updateObjValue;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.12.
|
|
1
|
+
export declare const version = "0.12.14";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.12.
|
|
1
|
+
export const version = "0.12.14";
|