mongolite-ts 0.2.3 → 0.3.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.
@@ -1,147 +0,0 @@
1
- import { getNestedValue, setNestedValue, unsetNestedValue } from './document-utils.js';
2
- /**
3
- * Class to handle update operations on documents
4
- */
5
- export class UpdateOperationHandler {
6
- /**
7
- * Apply update operations to a document
8
- * @param doc The document to modify
9
- * @param update The update operations to apply
10
- * @returns Whether the document was modified
11
- */
12
- applyUpdateOperations(doc, update) {
13
- let modified = false;
14
- // Process update operators
15
- for (const operator in update) {
16
- const opArgs = update[operator];
17
- if (!opArgs)
18
- continue;
19
- switch (operator) {
20
- case '$set':
21
- for (const path in opArgs) {
22
- const value = opArgs[path];
23
- setNestedValue(doc, path, value);
24
- modified = true;
25
- }
26
- break;
27
- case '$unset':
28
- for (const path in opArgs) {
29
- unsetNestedValue(doc, path);
30
- modified = true;
31
- }
32
- break;
33
- case '$inc':
34
- for (const path in opArgs) {
35
- const value = opArgs[path];
36
- if (typeof value === 'number') {
37
- const currentValue = getNestedValue(doc, path) || 0;
38
- if (typeof currentValue === 'number') {
39
- setNestedValue(doc, path, currentValue + value);
40
- modified = true;
41
- }
42
- }
43
- }
44
- break;
45
- case '$push':
46
- for (const path in opArgs) {
47
- const value = opArgs[path];
48
- const currentValue = getNestedValue(doc, path);
49
- if (Array.isArray(currentValue)) {
50
- if (typeof value === 'object' && value !== null && '$each' in value) {
51
- if (Array.isArray(value.$each)) {
52
- currentValue.push(...value.$each);
53
- modified = true;
54
- }
55
- }
56
- else {
57
- currentValue.push(value);
58
- modified = true;
59
- }
60
- }
61
- else if (currentValue === undefined) {
62
- // If the field doesn't exist, create it as an array
63
- if (typeof value === 'object' && value !== null && '$each' in value) {
64
- if (Array.isArray(value.$each)) {
65
- setNestedValue(doc, path, [...value.$each]);
66
- modified = true;
67
- }
68
- }
69
- else {
70
- setNestedValue(doc, path, [value]);
71
- modified = true;
72
- }
73
- }
74
- }
75
- break;
76
- case '$pull':
77
- for (const path in opArgs) {
78
- const value = opArgs[path];
79
- const currentValue = getNestedValue(doc, path);
80
- if (Array.isArray(currentValue)) {
81
- // Simple equality pull
82
- const newArray = currentValue.filter((item) => {
83
- if (typeof value === 'object' && value !== null) {
84
- // For objects, we need to check all criteria
85
- for (const key in value) {
86
- if (typeof item === 'object' &&
87
- item !== null &&
88
- !this.matchesFilterValue(item[key], value[key])) {
89
- return true; // Keep the item if it doesn't match the criteria
90
- }
91
- }
92
- return false; // Remove if all criteria match
93
- }
94
- else {
95
- // Simple equality check for primitives
96
- return item !== value;
97
- }
98
- });
99
- if (newArray.length !== currentValue.length) {
100
- setNestedValue(doc, path, newArray);
101
- modified = true;
102
- }
103
- }
104
- }
105
- break;
106
- }
107
- }
108
- return modified;
109
- }
110
- /**
111
- * Check if a value matches a filter condition
112
- */
113
- matchesFilterValue(value, condition) {
114
- if (typeof condition === 'object' && condition !== null) {
115
- // Check for operators
116
- // This is a simplified version, in a real implementation you'd handle many operators
117
- if ('$eq' in condition) {
118
- return value === condition.$eq;
119
- }
120
- else if ('$ne' in condition) {
121
- return value !== condition.$ne;
122
- }
123
- else if ('$gt' in condition) {
124
- return value > condition.$gt;
125
- }
126
- else if ('$gte' in condition) {
127
- return value >= condition.$gte;
128
- }
129
- else if ('$lt' in condition) {
130
- return value < condition.$lt;
131
- }
132
- else if ('$lte' in condition) {
133
- return value <= condition.$lte;
134
- }
135
- else if ('$in' in condition && Array.isArray(condition.$in)) {
136
- return condition.$in.includes(value);
137
- }
138
- else if ('$nin' in condition && Array.isArray(condition.$nin)) {
139
- return !condition.$nin.includes(value);
140
- }
141
- // For a complete implementation, handle more operators
142
- }
143
- // Default to simple equality
144
- return value === condition;
145
- }
146
- }
147
- //# sourceMappingURL=update-operations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"update-operations.js","sourceRoot":"","sources":["../src/update-operations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAA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