@peers-app/peers-sdk 0.14.0 → 0.15.0
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/context/data-context.d.ts +4 -4
- package/dist/context/data-context.js +1 -1
- package/dist/context/index.d.ts +3 -3
- package/dist/context/index.js +4 -0
- package/dist/context/user-context-singleton.js +13 -14
- package/dist/context/user-context.d.ts +4 -4
- package/dist/context/user-context.js +48 -31
- package/dist/data/assistants.d.ts +1 -1
- package/dist/data/assistants.js +35 -24
- package/dist/data/change-tracking.d.ts +8 -8
- package/dist/data/change-tracking.js +45 -39
- package/dist/data/channels.js +5 -5
- package/dist/data/data-locks.d.ts +2 -2
- package/dist/data/data-locks.js +21 -23
- package/dist/data/data-locks.test.js +73 -75
- package/dist/data/device-sync-info.d.ts +1 -1
- package/dist/data/device-sync-info.js +4 -4
- package/dist/data/devices.d.ts +1 -1
- package/dist/data/devices.js +9 -12
- package/dist/data/embeddings.js +14 -11
- package/dist/data/files/file-read-stream.d.ts +2 -2
- package/dist/data/files/file-read-stream.js +23 -14
- package/dist/data/files/file-write-stream.d.ts +2 -2
- package/dist/data/files/file-write-stream.js +8 -8
- package/dist/data/files/file.types.d.ts +2 -2
- package/dist/data/files/file.types.js +17 -11
- package/dist/data/files/files.d.ts +6 -6
- package/dist/data/files/files.js +17 -19
- package/dist/data/files/files.test.js +213 -214
- package/dist/data/files/index.d.ts +4 -4
- package/dist/data/files/index.js +4 -4
- package/dist/data/group-member-roles.js +2 -2
- package/dist/data/group-members.d.ts +5 -5
- package/dist/data/group-members.js +27 -18
- package/dist/data/group-members.test.js +73 -73
- package/dist/data/group-permissions.d.ts +3 -3
- package/dist/data/group-permissions.js +13 -11
- package/dist/data/group-share.d.ts +2 -2
- package/dist/data/group-share.js +29 -24
- package/dist/data/groups.d.ts +4 -4
- package/dist/data/groups.js +27 -19
- package/dist/data/groups.test.js +44 -44
- package/dist/data/index.d.ts +6 -6
- package/dist/data/index.js +6 -6
- package/dist/data/knowledge/peer-types.js +9 -9
- package/dist/data/messages.d.ts +5 -5
- package/dist/data/messages.js +43 -30
- package/dist/data/orm/client-proxy.data-source.d.ts +4 -4
- package/dist/data/orm/client-proxy.data-source.js +10 -12
- package/dist/data/orm/cursor.d.ts +1 -1
- package/dist/data/orm/cursor.js +2 -2
- package/dist/data/orm/cursor.test.js +92 -93
- package/dist/data/orm/data-query.d.ts +3 -3
- package/dist/data/orm/data-query.js +24 -18
- package/dist/data/orm/data-query.mongo.d.ts +1 -1
- package/dist/data/orm/data-query.mongo.js +49 -51
- package/dist/data/orm/data-query.mongo.test.js +173 -204
- package/dist/data/orm/data-query.sqlite.d.ts +1 -1
- package/dist/data/orm/data-query.sqlite.js +84 -73
- package/dist/data/orm/data-query.sqlite.test.js +164 -176
- package/dist/data/orm/data-query.test.js +216 -224
- package/dist/data/orm/decorators.js +3 -3
- package/dist/data/orm/dependency-injection.test.js +53 -56
- package/dist/data/orm/doc.d.ts +4 -4
- package/dist/data/orm/doc.js +17 -21
- package/dist/data/orm/event-registry.d.ts +1 -1
- package/dist/data/orm/event-registry.test.js +16 -16
- package/dist/data/orm/factory.d.ts +2 -2
- package/dist/data/orm/factory.js +33 -33
- package/dist/data/orm/index.d.ts +10 -10
- package/dist/data/orm/index.js +10 -10
- package/dist/data/orm/multi-cursors.d.ts +1 -1
- package/dist/data/orm/multi-cursors.js +6 -6
- package/dist/data/orm/multi-cursors.test.js +152 -144
- package/dist/data/orm/sql.data-source.d.ts +7 -7
- package/dist/data/orm/sql.data-source.js +88 -93
- package/dist/data/orm/sql.data-source.test.js +109 -101
- package/dist/data/orm/subscribable.data-source.d.ts +4 -4
- package/dist/data/orm/subscribable.data-source.js +5 -5
- package/dist/data/orm/table-container-events.test.js +34 -26
- package/dist/data/orm/table-container.d.ts +6 -6
- package/dist/data/orm/table-container.js +33 -21
- package/dist/data/orm/table-container.test.js +64 -53
- package/dist/data/orm/table-definitions.system.d.ts +3 -3
- package/dist/data/orm/table-definitions.system.js +3 -3
- package/dist/data/orm/table-definitions.type.d.ts +5 -5
- package/dist/data/orm/table-dependencies.d.ts +2 -2
- package/dist/data/orm/table.d.ts +5 -5
- package/dist/data/orm/table.event-source.test.js +105 -115
- package/dist/data/orm/table.js +35 -34
- package/dist/data/orm/types.d.ts +3 -3
- package/dist/data/orm/types.js +26 -25
- package/dist/data/orm/types.test.js +166 -92
- package/dist/data/package-permissions.d.ts +1 -1
- package/dist/data/package-permissions.js +2 -2
- package/dist/data/package-version-permissions.d.ts +1 -1
- package/dist/data/package-version-permissions.js +2 -2
- package/dist/data/package-versions.d.ts +9 -9
- package/dist/data/package-versions.js +47 -33
- package/dist/data/packages.d.ts +2 -2
- package/dist/data/packages.js +36 -18
- package/dist/data/packages.utils.d.ts +2 -2
- package/dist/data/packages.utils.js +4 -4
- package/dist/data/persistent-vars.d.ts +15 -15
- package/dist/data/persistent-vars.js +165 -154
- package/dist/data/table-definitions-table.d.ts +5 -5
- package/dist/data/table-definitions-table.js +13 -12
- package/dist/data/tool-tests.js +6 -6
- package/dist/data/tools.js +29 -19
- package/dist/data/user-permissions.d.ts +1 -1
- package/dist/data/user-permissions.js +5 -5
- package/dist/data/user-permissions.test.js +90 -88
- package/dist/data/user-trust-levels.js +10 -10
- package/dist/data/users.d.ts +4 -4
- package/dist/data/users.js +16 -15
- package/dist/data/voice-messages.d.ts +2 -2
- package/dist/data/voice-messages.js +13 -13
- package/dist/data/welcome-modal.pvar.js +3 -1
- package/dist/data/workflow-logs.js +26 -18
- package/dist/data/workflow-runs.d.ts +6 -6
- package/dist/data/workflow-runs.js +70 -44
- package/dist/data/workflows.d.ts +2 -2
- package/dist/data/workflows.js +7 -9
- package/dist/device/binary-peer-connection-v2.d.ts +7 -7
- package/dist/device/binary-peer-connection-v2.js +32 -28
- package/dist/device/binary-peer-connection-v2.test.js +80 -67
- package/dist/device/binary-peer-connection.d.ts +7 -7
- package/dist/device/binary-peer-connection.js +29 -28
- package/dist/device/binary-peer-connection.test.js +35 -31
- package/dist/device/connection.d.ts +5 -5
- package/dist/device/connection.js +59 -48
- package/dist/device/connection.test.js +74 -68
- package/dist/device/device-election.d.ts +2 -2
- package/dist/device/device-election.js +25 -20
- package/dist/device/device-election.test.js +35 -36
- package/dist/device/device.d.ts +2 -2
- package/dist/device/device.js +10 -4
- package/dist/device/device.test.js +16 -17
- package/dist/device/get-trust-level-fn.d.ts +2 -2
- package/dist/device/get-trust-level-fn.js +22 -11
- package/dist/device/get-trust-level-fn.test.js +58 -58
- package/dist/device/socket-io-binary-peer.d.ts +1 -1
- package/dist/device/socket-io-binary-peer.js +16 -13
- package/dist/device/socket.type.d.ts +2 -2
- package/dist/device/streamed-socket.d.ts +2 -2
- package/dist/device/streamed-socket.js +8 -8
- package/dist/device/streamed-socket.test.js +40 -40
- package/dist/device/tx-encoding.test.js +77 -77
- package/dist/events.d.ts +1 -1
- package/dist/events.js +5 -2
- package/dist/group-invite/group-invite.js +110 -19
- package/dist/group-invite/group-invite.pvars.d.ts +2 -2
- package/dist/group-invite/group-invite.pvars.js +21 -13
- package/dist/group-invite/group-invite.types.d.ts +1 -1
- package/dist/group-invite/index.d.ts +3 -3
- package/dist/group-invite/index.js +1 -1
- package/dist/index.d.ts +25 -24
- package/dist/index.js +30 -25
- package/dist/keys.d.ts +3 -3
- package/dist/keys.js +31 -30
- package/dist/keys.test.js +69 -61
- package/dist/logging/console-logger.d.ts +1 -1
- package/dist/logging/console-logger.js +35 -40
- package/dist/logging/console-logger.test.js +115 -115
- package/dist/logging/console-logs.table.d.ts +3 -3
- package/dist/logging/console-logs.table.js +28 -23
- package/dist/mentions.js +16 -12
- package/dist/observable.d.ts +2 -2
- package/dist/observable.js +15 -9
- package/dist/observable.test.js +47 -47
- package/dist/package-loader/get-require.js +3 -4
- package/dist/package-loader/package-loader.d.ts +2 -2
- package/dist/package-loader/package-loader.js +52 -34
- package/dist/peers-ui/peers-ui.d.ts +2 -2
- package/dist/peers-ui/peers-ui.js +2 -4
- package/dist/peers-ui/peers-ui.types.d.ts +3 -3
- package/dist/peers-ui/peers-ui.types.js +0 -1
- package/dist/rpc-types.d.ts +61 -59
- package/dist/rpc-types.js +61 -55
- package/dist/serial-json.d.ts +1 -1
- package/dist/serial-json.js +50 -43
- package/dist/serial-json.test.js +22 -22
- package/dist/system-ids.js +8 -8
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/tools-factory.d.ts +1 -1
- package/dist/tools/tools-factory.js +2 -2
- package/dist/types/assistant-runner-args.d.ts +3 -3
- package/dist/types/peer-device.d.ts +1 -1
- package/dist/types/peers-package.d.ts +3 -3
- package/dist/types/workflow-logger.d.ts +1 -1
- package/dist/types/workflow-run-context.d.ts +4 -4
- package/dist/types/workflow.d.ts +4 -4
- package/dist/types/workflow.js +27 -14
- package/dist/types/zod-types.d.ts +2 -1
- package/dist/types/zod-types.js +9 -3
- package/dist/user-connect/connection-code.d.ts +1 -1
- package/dist/user-connect/connection-code.js +7 -7
- package/dist/user-connect/connection-code.test.js +106 -106
- package/dist/user-connect/index.d.ts +3 -3
- package/dist/user-connect/index.js +1 -1
- package/dist/user-connect/user-connect.pvars.js +13 -11
- package/dist/user-connect/user-connect.types.d.ts +3 -3
- package/dist/users.query.d.ts +2 -2
- package/dist/users.query.js +40 -30
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +34 -32
- package/dist/utils.test.js +12 -8
- package/dist/workflow-log-formatter.d.ts +1 -1
- package/dist/workflow-log-formatter.js +17 -18
- package/package.json +14 -8
|
@@ -1,398 +1,367 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const data_query_mongo_1 = require("./data-query.mongo");
|
|
4
|
-
describe(
|
|
5
|
-
describe(
|
|
6
|
-
it(
|
|
4
|
+
describe("dataFilterToMongoQuery", () => {
|
|
5
|
+
describe("Scalar values", () => {
|
|
6
|
+
it("should handle null values", () => {
|
|
7
7
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(null)).toBe(null);
|
|
8
8
|
});
|
|
9
|
-
it(
|
|
9
|
+
it("should handle undefined values", () => {
|
|
10
10
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(undefined)).toBe(undefined);
|
|
11
11
|
});
|
|
12
|
-
it(
|
|
12
|
+
it("should handle primitive values", () => {
|
|
13
13
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(42)).toBe(42);
|
|
14
|
-
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(
|
|
14
|
+
expect((0, data_query_mongo_1.dataFilterToMongoQuery)("test")).toBe("test");
|
|
15
15
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(true)).toBe(true);
|
|
16
16
|
});
|
|
17
|
-
it(
|
|
18
|
-
const date = new Date(
|
|
17
|
+
it("should handle Date objects", () => {
|
|
18
|
+
const date = new Date("2023-01-01");
|
|
19
19
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(date)).toBe(date);
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
|
-
describe(
|
|
23
|
-
it(
|
|
22
|
+
describe("Empty filters", () => {
|
|
23
|
+
it("should handle empty object filters", () => {
|
|
24
24
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)({})).toEqual({});
|
|
25
25
|
});
|
|
26
|
-
it(
|
|
26
|
+
it("should handle empty array filters", () => {
|
|
27
27
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)([])).toEqual({});
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
|
-
describe(
|
|
31
|
-
it(
|
|
32
|
-
const filter = { name:
|
|
33
|
-
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name:
|
|
30
|
+
describe("Simple field conditions", () => {
|
|
31
|
+
it("should handle basic field equality", () => {
|
|
32
|
+
const filter = { name: "John" };
|
|
33
|
+
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: "John" });
|
|
34
34
|
});
|
|
35
|
-
it(
|
|
36
|
-
const filter = { name:
|
|
37
|
-
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name:
|
|
35
|
+
it("should handle multiple fields", () => {
|
|
36
|
+
const filter = { name: "John", age: 30 };
|
|
37
|
+
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: "John", age: 30 });
|
|
38
38
|
});
|
|
39
|
-
it(
|
|
39
|
+
it("should handle null field values", () => {
|
|
40
40
|
const filter = { name: null };
|
|
41
41
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: null });
|
|
42
42
|
});
|
|
43
|
-
it(
|
|
43
|
+
it("should handle undefined field values", () => {
|
|
44
44
|
const filter = { name: undefined };
|
|
45
45
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: null });
|
|
46
46
|
});
|
|
47
|
-
it(
|
|
48
|
-
const filter = { names: [
|
|
49
|
-
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow(
|
|
47
|
+
it("should throw error for direct array usage", () => {
|
|
48
|
+
const filter = { names: ["John", "Jane"] };
|
|
49
|
+
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("Invalid filter: Arrays are not allowed as direct field values. Use $in instead");
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
|
-
describe(
|
|
53
|
-
describe(
|
|
54
|
-
it(
|
|
52
|
+
describe("MongoDB operators (direct mapping)", () => {
|
|
53
|
+
describe("$eq operator", () => {
|
|
54
|
+
it("should handle $eq operator", () => {
|
|
55
55
|
const filter = { age: { $eq: 30 } };
|
|
56
56
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $eq: 30 } });
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
|
-
describe(
|
|
60
|
-
it(
|
|
59
|
+
describe("$ne operator", () => {
|
|
60
|
+
it("should handle $ne operator", () => {
|
|
61
61
|
const filter = { age: { $ne: 30 } };
|
|
62
62
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $ne: 30 } });
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
|
-
describe(
|
|
66
|
-
it(
|
|
65
|
+
describe("Comparison operators", () => {
|
|
66
|
+
it("should handle $gt operator", () => {
|
|
67
67
|
const filter = { age: { $gt: 18 } };
|
|
68
68
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $gt: 18 } });
|
|
69
69
|
});
|
|
70
|
-
it(
|
|
70
|
+
it("should handle $gte operator", () => {
|
|
71
71
|
const filter = { age: { $gte: 18 } };
|
|
72
72
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $gte: 18 } });
|
|
73
73
|
});
|
|
74
|
-
it(
|
|
74
|
+
it("should handle $lt operator", () => {
|
|
75
75
|
const filter = { age: { $lt: 65 } };
|
|
76
76
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $lt: 65 } });
|
|
77
77
|
});
|
|
78
|
-
it(
|
|
78
|
+
it("should handle $lte operator", () => {
|
|
79
79
|
const filter = { age: { $lte: 65 } };
|
|
80
80
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $lte: 65 } });
|
|
81
81
|
});
|
|
82
|
-
it(
|
|
82
|
+
it("should handle multiple comparison operators", () => {
|
|
83
83
|
const filter = { age: { $gte: 18, $lt: 65 } };
|
|
84
84
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ age: { $gte: 18, $lt: 65 } });
|
|
85
85
|
});
|
|
86
86
|
});
|
|
87
|
-
describe(
|
|
88
|
-
it(
|
|
89
|
-
const filter = { status: { $in: [
|
|
90
|
-
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ status: { $in: [
|
|
87
|
+
describe("$in and $nin operators", () => {
|
|
88
|
+
it("should handle $in operator", () => {
|
|
89
|
+
const filter = { status: { $in: ["active", "pending"] } };
|
|
90
|
+
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ status: { $in: ["active", "pending"] } });
|
|
91
91
|
});
|
|
92
|
-
it(
|
|
93
|
-
const filter = { status: { $nin: [
|
|
94
|
-
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
|
|
92
|
+
it("should handle $nin operator", () => {
|
|
93
|
+
const filter = { status: { $nin: ["inactive", "deleted"] } };
|
|
94
|
+
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
|
|
95
|
+
status: { $nin: ["inactive", "deleted"] },
|
|
96
|
+
});
|
|
95
97
|
});
|
|
96
|
-
it(
|
|
98
|
+
it("should handle empty arrays", () => {
|
|
97
99
|
const filter = { status: { $in: [] } };
|
|
98
100
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ status: { $in: [] } });
|
|
99
101
|
});
|
|
100
102
|
});
|
|
101
|
-
describe(
|
|
102
|
-
it(
|
|
103
|
+
describe("$exists operator", () => {
|
|
104
|
+
it("should handle $exists: true", () => {
|
|
103
105
|
const filter = { email: { $exists: true } };
|
|
104
106
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ email: { $exists: true } });
|
|
105
107
|
});
|
|
106
|
-
it(
|
|
108
|
+
it("should handle $exists: false", () => {
|
|
107
109
|
const filter = { email: { $exists: false } };
|
|
108
110
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ email: { $exists: false } });
|
|
109
111
|
});
|
|
110
112
|
});
|
|
111
113
|
});
|
|
112
|
-
describe(
|
|
113
|
-
describe(
|
|
114
|
-
it(
|
|
115
|
-
const filter = { $or: [{ name:
|
|
114
|
+
describe("Logical operators", () => {
|
|
115
|
+
describe("$or operator", () => {
|
|
116
|
+
it("should handle $or with multiple conditions", () => {
|
|
117
|
+
const filter = { $or: [{ name: "John" }, { age: 30 }] };
|
|
116
118
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
|
|
117
|
-
$or: [{ name:
|
|
119
|
+
$or: [{ name: "John" }, { age: 30 }],
|
|
118
120
|
});
|
|
119
121
|
});
|
|
120
|
-
it(
|
|
122
|
+
it("should handle empty $or array", () => {
|
|
121
123
|
const filter = { $or: [] };
|
|
122
124
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ $or: [] });
|
|
123
125
|
});
|
|
124
|
-
it(
|
|
126
|
+
it("should handle $or with complex conditions", () => {
|
|
125
127
|
const filter = {
|
|
126
|
-
$or: [
|
|
127
|
-
{ name: 'John', age: { $gte: 18 } },
|
|
128
|
-
{ status: { $in: ['active', 'pending'] } }
|
|
129
|
-
]
|
|
128
|
+
$or: [{ name: "John", age: { $gte: 18 } }, { status: { $in: ["active", "pending"] } }],
|
|
130
129
|
};
|
|
131
130
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
|
|
132
|
-
$or: [
|
|
133
|
-
{ name: 'John', age: { $gte: 18 } },
|
|
134
|
-
{ status: { $in: ['active', 'pending'] } }
|
|
135
|
-
]
|
|
131
|
+
$or: [{ name: "John", age: { $gte: 18 } }, { status: { $in: ["active", "pending"] } }],
|
|
136
132
|
});
|
|
137
133
|
});
|
|
138
134
|
});
|
|
139
|
-
describe(
|
|
140
|
-
it(
|
|
141
|
-
const filter = { $and: [{ name:
|
|
135
|
+
describe("$and operator", () => {
|
|
136
|
+
it("should handle $and with multiple conditions", () => {
|
|
137
|
+
const filter = { $and: [{ name: "John" }, { age: 30 }] };
|
|
142
138
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
|
|
143
|
-
$and: [{ name:
|
|
139
|
+
$and: [{ name: "John" }, { age: 30 }],
|
|
144
140
|
});
|
|
145
141
|
});
|
|
146
|
-
it(
|
|
142
|
+
it("should handle empty $and array", () => {
|
|
147
143
|
const filter = { $and: [] };
|
|
148
144
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({});
|
|
149
145
|
});
|
|
150
|
-
it(
|
|
146
|
+
it("should handle nested $and and $or", () => {
|
|
151
147
|
const filter = {
|
|
152
148
|
$and: [
|
|
153
|
-
{ status:
|
|
149
|
+
{ status: "active" },
|
|
154
150
|
{
|
|
155
|
-
$or: [
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
]
|
|
159
|
-
}
|
|
160
|
-
]
|
|
151
|
+
$or: [{ age: { $gte: 18 } }, { verified: true }],
|
|
152
|
+
},
|
|
153
|
+
],
|
|
161
154
|
};
|
|
162
155
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
|
|
163
156
|
$and: [
|
|
164
|
-
{ status:
|
|
157
|
+
{ status: "active" },
|
|
165
158
|
{
|
|
166
|
-
$or: [
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
]
|
|
170
|
-
}
|
|
171
|
-
]
|
|
159
|
+
$or: [{ age: { $gte: 18 } }, { verified: true }],
|
|
160
|
+
},
|
|
161
|
+
],
|
|
172
162
|
});
|
|
173
163
|
});
|
|
174
164
|
});
|
|
175
|
-
describe(
|
|
176
|
-
it(
|
|
177
|
-
const filter = [{ name:
|
|
178
|
-
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name:
|
|
165
|
+
describe("Array filters (OR logic)", () => {
|
|
166
|
+
it("should handle single condition arrays", () => {
|
|
167
|
+
const filter = [{ name: "John" }];
|
|
168
|
+
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({ name: "John" });
|
|
179
169
|
});
|
|
180
|
-
it(
|
|
181
|
-
const filter = [{ name:
|
|
170
|
+
it("should handle multiple condition arrays", () => {
|
|
171
|
+
const filter = [{ name: "John" }, { age: 30 }, { city: "NYC" }];
|
|
182
172
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
|
|
183
|
-
$or: [{ name:
|
|
173
|
+
$or: [{ name: "John" }, { age: 30 }, { city: "NYC" }],
|
|
184
174
|
});
|
|
185
175
|
});
|
|
186
|
-
it(
|
|
176
|
+
it("should handle complex array conditions", () => {
|
|
187
177
|
const filter = [
|
|
188
|
-
{ name:
|
|
189
|
-
{ status: { $in: [
|
|
178
|
+
{ name: "John", age: { $gte: 18 } },
|
|
179
|
+
{ status: { $in: ["active", "pending"] } },
|
|
190
180
|
];
|
|
191
181
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
|
|
192
|
-
$or: [
|
|
193
|
-
{ name: 'John', age: { $gte: 18 } },
|
|
194
|
-
{ status: { $in: ['active', 'pending'] } }
|
|
195
|
-
]
|
|
182
|
+
$or: [{ name: "John", age: { $gte: 18 } }, { status: { $in: ["active", "pending"] } }],
|
|
196
183
|
});
|
|
197
184
|
});
|
|
198
185
|
});
|
|
199
186
|
});
|
|
200
|
-
describe(
|
|
201
|
-
describe(
|
|
202
|
-
it(
|
|
203
|
-
const filter = { $matchWords:
|
|
204
|
-
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow(
|
|
187
|
+
describe("Custom operators", () => {
|
|
188
|
+
describe("$matchWords operator", () => {
|
|
189
|
+
it("should throw error for $matchWords (needs field context)", () => {
|
|
190
|
+
const filter = { $matchWords: "hello world" };
|
|
191
|
+
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$matchWords with multiple words requires field context");
|
|
205
192
|
});
|
|
206
|
-
it(
|
|
193
|
+
it("should throw error for non-string values", () => {
|
|
207
194
|
const filter = { $matchWords: 123 };
|
|
208
|
-
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow(
|
|
195
|
+
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$matchWords value must be a string");
|
|
209
196
|
});
|
|
210
197
|
});
|
|
211
|
-
describe(
|
|
212
|
-
it(
|
|
213
|
-
const filter = { $substr: [
|
|
198
|
+
describe("$substr operator", () => {
|
|
199
|
+
it("should convert $substr to MongoDB $expr format", () => {
|
|
200
|
+
const filter = { $substr: ["$fieldName", 1, 3] };
|
|
214
201
|
const result = (0, data_query_mongo_1.dataFilterToMongoQuery)(filter);
|
|
215
202
|
expect(result).toEqual({
|
|
216
203
|
$expr: {
|
|
217
|
-
$substr: [
|
|
218
|
-
}
|
|
204
|
+
$substr: ["$fieldName", 1, 3],
|
|
205
|
+
},
|
|
219
206
|
});
|
|
220
207
|
});
|
|
221
|
-
it(
|
|
222
|
-
const filter = { $substr: [
|
|
208
|
+
it("should handle string literals in $substr", () => {
|
|
209
|
+
const filter = { $substr: ["literal text", 0, 5] };
|
|
223
210
|
const result = (0, data_query_mongo_1.dataFilterToMongoQuery)(filter);
|
|
224
211
|
expect(result).toEqual({
|
|
225
212
|
$expr: {
|
|
226
|
-
$substr: [
|
|
227
|
-
}
|
|
213
|
+
$substr: ["literal text", 0, 5],
|
|
214
|
+
},
|
|
228
215
|
});
|
|
229
216
|
});
|
|
230
|
-
it(
|
|
231
|
-
const filter = { $substr: [
|
|
232
|
-
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow(
|
|
217
|
+
it("should throw error for invalid $substr arguments", () => {
|
|
218
|
+
const filter = { $substr: ["$field"] }; // Missing arguments
|
|
219
|
+
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$substr requires exactly 3 arguments");
|
|
233
220
|
});
|
|
234
|
-
it(
|
|
235
|
-
const filter = { $substr:
|
|
236
|
-
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow(
|
|
221
|
+
it("should throw error for non-array $substr", () => {
|
|
222
|
+
const filter = { $substr: "invalid" };
|
|
223
|
+
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$substr requires exactly 3 arguments");
|
|
237
224
|
});
|
|
238
225
|
});
|
|
239
|
-
describe(
|
|
240
|
-
it(
|
|
241
|
-
const filter = { $expr: [{ $substr: [
|
|
226
|
+
describe("$expr operator", () => {
|
|
227
|
+
it("should convert simple $expr to MongoDB format", () => {
|
|
228
|
+
const filter = { $expr: [{ $substr: ["$id", 0, 1] }, { $eq: "A" }] };
|
|
242
229
|
const result = (0, data_query_mongo_1.dataFilterToMongoQuery)(filter);
|
|
243
230
|
expect(result).toEqual({
|
|
244
231
|
$expr: {
|
|
245
|
-
$eq: [
|
|
246
|
-
|
|
247
|
-
'A'
|
|
248
|
-
]
|
|
249
|
-
}
|
|
232
|
+
$eq: [{ $substr: ["$id", 0, 1] }, "A"],
|
|
233
|
+
},
|
|
250
234
|
});
|
|
251
235
|
});
|
|
252
|
-
it(
|
|
253
|
-
const filter = { $expr: [{ $substr: [
|
|
236
|
+
it("should handle $expr with different operators", () => {
|
|
237
|
+
const filter = { $expr: [{ $substr: ["$name", 0, 1] }, { $ne: "Z" }] };
|
|
254
238
|
const result = (0, data_query_mongo_1.dataFilterToMongoQuery)(filter);
|
|
255
239
|
expect(result).toEqual({
|
|
256
240
|
$expr: {
|
|
257
|
-
$ne: [
|
|
258
|
-
|
|
259
|
-
'Z'
|
|
260
|
-
]
|
|
261
|
-
}
|
|
241
|
+
$ne: [{ $substr: ["$name", 0, 1] }, "Z"],
|
|
242
|
+
},
|
|
262
243
|
});
|
|
263
244
|
});
|
|
264
|
-
it(
|
|
265
|
-
const filter = { $expr: [
|
|
245
|
+
it("should default to $eq for simple expressions", () => {
|
|
246
|
+
const filter = { $expr: ["$field1", "$field2"] };
|
|
266
247
|
const result = (0, data_query_mongo_1.dataFilterToMongoQuery)(filter);
|
|
267
248
|
expect(result).toEqual({
|
|
268
249
|
$expr: {
|
|
269
|
-
$eq: [
|
|
270
|
-
}
|
|
250
|
+
$eq: ["$field1", "$field2"],
|
|
251
|
+
},
|
|
271
252
|
});
|
|
272
253
|
});
|
|
273
|
-
it(
|
|
274
|
-
const filter = { $expr: [
|
|
275
|
-
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow(
|
|
254
|
+
it("should throw error for invalid $expr format", () => {
|
|
255
|
+
const filter = { $expr: ["single_argument"] };
|
|
256
|
+
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$expr requires exactly 2 arguments");
|
|
276
257
|
});
|
|
277
258
|
});
|
|
278
259
|
});
|
|
279
|
-
describe(
|
|
280
|
-
it(
|
|
281
|
-
const filter = { field: { $unknown:
|
|
282
|
-
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow(
|
|
260
|
+
describe("Error cases", () => {
|
|
261
|
+
it("should throw error for unknown operators", () => {
|
|
262
|
+
const filter = { field: { $unknown: "value" } };
|
|
263
|
+
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("Unknown operator: $unknown");
|
|
283
264
|
});
|
|
284
|
-
it(
|
|
285
|
-
const filter = { field: { invalidOp:
|
|
286
|
-
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow(
|
|
265
|
+
it("should throw error for operators without $ prefix", () => {
|
|
266
|
+
const filter = { field: { invalidOp: "value" } };
|
|
267
|
+
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("Invalid operator: invalidOp. Operators must start with $");
|
|
287
268
|
});
|
|
288
|
-
it(
|
|
289
|
-
const filter = { field: { $matchWords:
|
|
290
|
-
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow(
|
|
269
|
+
it("should throw error for nested $matchWords", () => {
|
|
270
|
+
const filter = { field: { $matchWords: "test" } };
|
|
271
|
+
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$matchWords should be handled at field level");
|
|
291
272
|
});
|
|
292
|
-
it(
|
|
293
|
-
const filter = { field: { $substr: [
|
|
294
|
-
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow(
|
|
273
|
+
it("should throw error for nested $substr", () => {
|
|
274
|
+
const filter = { field: { $substr: ["$other", 0, 1] } };
|
|
275
|
+
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$substr should be handled at field level");
|
|
295
276
|
});
|
|
296
|
-
it(
|
|
297
|
-
const filter = { field: { $expr: [
|
|
298
|
-
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow(
|
|
277
|
+
it("should throw error for nested $expr", () => {
|
|
278
|
+
const filter = { field: { $expr: ["$a", "$b"] } };
|
|
279
|
+
expect(() => (0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toThrow("$expr should be handled at field level");
|
|
299
280
|
});
|
|
300
281
|
});
|
|
301
|
-
describe(
|
|
302
|
-
it(
|
|
282
|
+
describe("Complex nested scenarios", () => {
|
|
283
|
+
it("should handle deeply nested conditions", () => {
|
|
303
284
|
const filter = {
|
|
304
285
|
$and: [
|
|
305
|
-
{ status:
|
|
286
|
+
{ status: "active" },
|
|
306
287
|
{
|
|
307
|
-
$or: [
|
|
308
|
-
{ age: { $gte: 18, $lt: 65 } },
|
|
309
|
-
{ verified: true }
|
|
310
|
-
]
|
|
288
|
+
$or: [{ age: { $gte: 18, $lt: 65 } }, { verified: true }],
|
|
311
289
|
},
|
|
312
|
-
{ role: { $in: [
|
|
313
|
-
]
|
|
290
|
+
{ role: { $in: ["user", "admin"] } },
|
|
291
|
+
],
|
|
314
292
|
};
|
|
315
293
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
|
|
316
294
|
$and: [
|
|
317
|
-
{ status:
|
|
295
|
+
{ status: "active" },
|
|
318
296
|
{
|
|
319
|
-
$or: [
|
|
320
|
-
{ age: { $gte: 18, $lt: 65 } },
|
|
321
|
-
{ verified: true }
|
|
322
|
-
]
|
|
297
|
+
$or: [{ age: { $gte: 18, $lt: 65 } }, { verified: true }],
|
|
323
298
|
},
|
|
324
|
-
{ role: { $in: [
|
|
325
|
-
]
|
|
299
|
+
{ role: { $in: ["user", "admin"] } },
|
|
300
|
+
],
|
|
326
301
|
});
|
|
327
302
|
});
|
|
328
|
-
it(
|
|
303
|
+
it("should handle mixed array and object filters", () => {
|
|
329
304
|
const filter = [
|
|
330
|
-
{ name:
|
|
305
|
+
{ name: "John", age: { $gte: 18 } },
|
|
331
306
|
{
|
|
332
|
-
$and: [
|
|
333
|
-
|
|
334
|
-
{ verified: true }
|
|
335
|
-
]
|
|
336
|
-
}
|
|
307
|
+
$and: [{ status: "active" }, { verified: true }],
|
|
308
|
+
},
|
|
337
309
|
];
|
|
338
310
|
expect((0, data_query_mongo_1.dataFilterToMongoQuery)(filter)).toEqual({
|
|
339
311
|
$or: [
|
|
340
|
-
{ name:
|
|
312
|
+
{ name: "John", age: { $gte: 18 } },
|
|
341
313
|
{
|
|
342
|
-
$and: [
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
]
|
|
346
|
-
}
|
|
347
|
-
]
|
|
314
|
+
$and: [{ status: "active" }, { verified: true }],
|
|
315
|
+
},
|
|
316
|
+
],
|
|
348
317
|
});
|
|
349
318
|
});
|
|
350
319
|
});
|
|
351
320
|
});
|
|
352
|
-
describe(
|
|
353
|
-
it(
|
|
321
|
+
describe("sortByToMongoSort", () => {
|
|
322
|
+
it("should handle empty sort", () => {
|
|
354
323
|
expect((0, data_query_mongo_1.sortByToMongoSort)()).toEqual({});
|
|
355
324
|
expect((0, data_query_mongo_1.sortByToMongoSort)([])).toEqual({});
|
|
356
325
|
});
|
|
357
|
-
it(
|
|
358
|
-
expect((0, data_query_mongo_1.sortByToMongoSort)([
|
|
326
|
+
it("should handle ascending sort", () => {
|
|
327
|
+
expect((0, data_query_mongo_1.sortByToMongoSort)(["name"])).toEqual({ name: 1 });
|
|
359
328
|
});
|
|
360
|
-
it(
|
|
361
|
-
expect((0, data_query_mongo_1.sortByToMongoSort)([
|
|
329
|
+
it("should handle descending sort", () => {
|
|
330
|
+
expect((0, data_query_mongo_1.sortByToMongoSort)(["-name"])).toEqual({ name: -1 });
|
|
362
331
|
});
|
|
363
|
-
it(
|
|
364
|
-
expect((0, data_query_mongo_1.sortByToMongoSort)([
|
|
332
|
+
it("should handle multiple sort fields", () => {
|
|
333
|
+
expect((0, data_query_mongo_1.sortByToMongoSort)(["name", "-age", "created"])).toEqual({
|
|
365
334
|
name: 1,
|
|
366
335
|
age: -1,
|
|
367
|
-
created: 1
|
|
336
|
+
created: 1,
|
|
368
337
|
});
|
|
369
338
|
});
|
|
370
|
-
it(
|
|
371
|
-
expect((0, data_query_mongo_1.sortByToMongoSort)([
|
|
372
|
-
|
|
373
|
-
|
|
339
|
+
it("should handle complex field names", () => {
|
|
340
|
+
expect((0, data_query_mongo_1.sortByToMongoSort)(["-user.name", "profile.age"])).toEqual({
|
|
341
|
+
"user.name": -1,
|
|
342
|
+
"profile.age": 1,
|
|
374
343
|
});
|
|
375
344
|
});
|
|
376
345
|
});
|
|
377
|
-
describe(
|
|
378
|
-
it(
|
|
346
|
+
describe("paginationToMongoSkipLimit", () => {
|
|
347
|
+
it("should handle no pagination", () => {
|
|
379
348
|
expect((0, data_query_mongo_1.paginationToMongoSkipLimit)()).toEqual({});
|
|
380
349
|
});
|
|
381
|
-
it(
|
|
350
|
+
it("should handle only pageSize", () => {
|
|
382
351
|
expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(undefined, 10)).toEqual({ limit: 10 });
|
|
383
352
|
});
|
|
384
|
-
it(
|
|
353
|
+
it("should handle only page (no effect without pageSize)", () => {
|
|
385
354
|
expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(2)).toEqual({});
|
|
386
355
|
});
|
|
387
|
-
it(
|
|
356
|
+
it("should handle page and pageSize", () => {
|
|
388
357
|
expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(1, 10)).toEqual({ limit: 10 });
|
|
389
358
|
expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(2, 10)).toEqual({ limit: 10, skip: 10 });
|
|
390
359
|
expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(3, 20)).toEqual({ limit: 20, skip: 40 });
|
|
391
360
|
});
|
|
392
|
-
it(
|
|
361
|
+
it("should handle fractional numbers", () => {
|
|
393
362
|
expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(2.7, 10.3)).toEqual({ limit: 10, skip: 21 });
|
|
394
363
|
});
|
|
395
|
-
it(
|
|
364
|
+
it("should handle zero page", () => {
|
|
396
365
|
expect((0, data_query_mongo_1.paginationToMongoSkipLimit)(0, 10)).toEqual({ limit: 10 });
|
|
397
366
|
});
|
|
398
367
|
});
|