@wxn0brp/db 0.10.0 → 0.20.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.
Files changed (87) hide show
  1. package/LICENSE +1 -1
  2. package/dist/{helpers/autoCreate.d.ts → autoCreate.d.ts} +2 -2
  3. package/dist/{helpers/autoCreate.js → autoCreate.js} +2 -2
  4. package/dist/{db/graph.d.ts → graph.d.ts} +1 -1
  5. package/dist/index.d.ts +8 -15
  6. package/dist/index.js +7 -10
  7. package/dist/valthera.d.ts +7 -0
  8. package/dist/valthera.js +14 -0
  9. package/dist/version.js +1 -1
  10. package/package.json +11 -21
  11. package/dist/actions/action.d.ts +0 -69
  12. package/dist/actions/action.js +0 -234
  13. package/dist/actions/memory.d.ts +0 -72
  14. package/dist/actions/memory.js +0 -145
  15. package/dist/base/actions.d.ts +0 -17
  16. package/dist/base/actions.js +0 -56
  17. package/dist/base/db.d.ts +0 -21
  18. package/dist/base/db.js +0 -56
  19. package/dist/client/function.d.ts +0 -5
  20. package/dist/client/function.js +0 -30
  21. package/dist/client/graph.d.ts +0 -54
  22. package/dist/client/graph.js +0 -108
  23. package/dist/client/remote.d.ts +0 -15
  24. package/dist/client/remote.js +0 -1
  25. package/dist/client/valthera.d.ts +0 -74
  26. package/dist/client/valthera.js +0 -135
  27. package/dist/db/valthera.d.ts +0 -75
  28. package/dist/db/valthera.js +0 -110
  29. package/dist/file/customFileCpu.d.ts +0 -18
  30. package/dist/file/customFileCpu.js +0 -68
  31. package/dist/file/find.d.ts +0 -11
  32. package/dist/file/find.js +0 -73
  33. package/dist/file/index.d.ts +0 -3
  34. package/dist/file/index.js +0 -16
  35. package/dist/file/remove.d.ts +0 -7
  36. package/dist/file/remove.js +0 -41
  37. package/dist/file/update.d.ts +0 -7
  38. package/dist/file/update.js +0 -50
  39. package/dist/file/utils.d.ts +0 -8
  40. package/dist/file/utils.js +0 -84
  41. package/dist/helpers/CollectionManager.d.ts +0 -43
  42. package/dist/helpers/CollectionManager.js +0 -57
  43. package/dist/helpers/executor.d.ts +0 -28
  44. package/dist/helpers/executor.js +0 -45
  45. package/dist/helpers/format.d.ts +0 -12
  46. package/dist/helpers/format.js +0 -23
  47. package/dist/helpers/gen.d.ts +0 -8
  48. package/dist/helpers/gen.js +0 -134
  49. package/dist/helpers/relation.d.ts +0 -10
  50. package/dist/helpers/relation.js +0 -155
  51. package/dist/helpers/updateOneOrAdd.d.ts +0 -2
  52. package/dist/helpers/updateOneOrAdd.js +0 -18
  53. package/dist/types/Id.d.ts +0 -3
  54. package/dist/types/Id.js +0 -1
  55. package/dist/types/arg.d.ts +0 -12
  56. package/dist/types/arg.js +0 -1
  57. package/dist/types/data.d.ts +0 -4
  58. package/dist/types/data.js +0 -1
  59. package/dist/types/export.d.ts +0 -11
  60. package/dist/types/export.js +0 -1
  61. package/dist/types/fileCpu.d.ts +0 -51
  62. package/dist/types/fileCpu.js +0 -1
  63. package/dist/types/options.d.ts +0 -19
  64. package/dist/types/options.js +0 -1
  65. package/dist/types/query.d.ts +0 -15
  66. package/dist/types/query.js +0 -1
  67. package/dist/types/relation.d.ts +0 -28
  68. package/dist/types/relation.js +0 -1
  69. package/dist/types/searchOpts.d.ts +0 -62
  70. package/dist/types/searchOpts.js +0 -7
  71. package/dist/types/types.d.ts +0 -3
  72. package/dist/types/types.js +0 -1
  73. package/dist/types/updater.d.ts +0 -26
  74. package/dist/types/updater.js +0 -4
  75. package/dist/types/valthera.d.ts +0 -36
  76. package/dist/types/valthera.js +0 -1
  77. package/dist/utils/hasFields.d.ts +0 -7
  78. package/dist/utils/hasFields.js +0 -18
  79. package/dist/utils/hasFieldsAdvanced.d.ts +0 -5
  80. package/dist/utils/hasFieldsAdvanced.js +0 -176
  81. package/dist/utils/sort.d.ts +0 -1
  82. package/dist/utils/sort.js +0 -23
  83. package/dist/utils/updateFindObject.d.ts +0 -11
  84. package/dist/utils/updateFindObject.js +0 -28
  85. package/dist/utils/updateObject.d.ts +0 -7
  86. package/dist/utils/updateObject.js +0 -145
  87. /package/dist/{db/graph.js → graph.js} +0 -0
@@ -1,145 +0,0 @@
1
- /**
2
- * Updates an object with new values.
3
- * @param obj - The object to update.
4
- * @param fields - An object containing new values to update in the target object.
5
- */
6
- export default function updateObjectAdvanced(obj, fields) {
7
- if (typeof fields !== "object" || fields === null) {
8
- throw new Error("Fields must be an object or object array");
9
- }
10
- const fieldsArray = Array.isArray(fields) ? fields : [fields];
11
- for (const field of fieldsArray) {
12
- if (typeof field !== "object" || field === null) {
13
- throw new Error("Fields must be an object or object array");
14
- }
15
- updateAdvanced(obj, field);
16
- const fieldsSubset = removeAdvancedOperators({ ...field });
17
- updateObject(obj, fieldsSubset);
18
- }
19
- return obj;
20
- }
21
- function updateAdvanced(obj, fields) {
22
- updateArray(obj, fields);
23
- updateNested(obj, fields);
24
- updateIncrement(obj, fields);
25
- updateUnset(obj, fields);
26
- updateRename(obj, fields);
27
- }
28
- function removeAdvancedOperators(fields) {
29
- const advancedOperators = [
30
- "push", "pushset", "pull", "pullall",
31
- "inc", "dec",
32
- "unset",
33
- "merge",
34
- "rename"
35
- ].map(operator => "$" + operator);
36
- advancedOperators.forEach(operator => delete fields[operator]);
37
- return fields;
38
- }
39
- function updateArray(obj, fields) {
40
- if ("$push" in fields) {
41
- for (const [key, value] of Object.entries(fields["$push"])) {
42
- if (Array.isArray(obj[key])) {
43
- obj[key].push(value);
44
- }
45
- else {
46
- obj[key] = [value];
47
- }
48
- }
49
- }
50
- if ("$pushset" in fields) {
51
- for (const [key, value] of Object.entries(fields["$pushset"])) {
52
- if (Array.isArray(obj[key])) {
53
- obj[key].push(value);
54
- }
55
- else {
56
- obj[key] = [value];
57
- }
58
- obj[key] = [...new Set(obj[key])];
59
- }
60
- }
61
- if ("$pull" in fields) {
62
- for (const [key, value] of Object.entries(fields["$pull"])) {
63
- if (Array.isArray(obj[key])) {
64
- obj[key] = obj[key].filter(item => item !== value);
65
- }
66
- }
67
- }
68
- if ("$pullall" in fields) {
69
- for (const [key, values] of Object.entries(fields["$pullall"])) {
70
- if (Array.isArray(obj[key])) {
71
- obj[key] = obj[key].filter(item => !values.includes(item));
72
- }
73
- }
74
- }
75
- }
76
- function updateNested(obj, fields) {
77
- if ("$merge" in fields) {
78
- for (const [key, value] of Object.entries(fields["$merge"])) {
79
- if (typeof obj[key] === "object" && typeof value === "object") {
80
- obj[key] = { ...obj[key], ...value };
81
- }
82
- else {
83
- obj[key] = value;
84
- }
85
- }
86
- }
87
- }
88
- function updateIncrement(obj, fields) {
89
- if ("$inc" in fields) {
90
- for (const [key, value] of Object.entries(fields["$inc"])) {
91
- if (typeof obj[key] === "number" && typeof value === "number") {
92
- obj[key] += value;
93
- }
94
- else if (!(key in obj)) {
95
- obj[key] = value;
96
- }
97
- else {
98
- throw new Error(`Cannot increment non-numeric value at key: ${key}`);
99
- }
100
- }
101
- }
102
- if ("$dec" in fields) {
103
- for (const [key, value] of Object.entries(fields["$dec"])) {
104
- if (typeof obj[key] === "number" && typeof value === "number") {
105
- obj[key] -= value;
106
- }
107
- else if (!(key in obj)) {
108
- obj[key] = value;
109
- }
110
- else {
111
- throw new Error(`Cannot decrement non-numeric value at key: ${key}`);
112
- }
113
- }
114
- }
115
- }
116
- function updateUnset(obj, fields) {
117
- if ("$unset" in fields) {
118
- for (const key of Object.keys(fields["$unset"])) {
119
- delete obj[key];
120
- }
121
- }
122
- }
123
- function updateRename(obj, fields) {
124
- if ("$rename" in fields) {
125
- for (const [oldKey, newKey] of Object.entries(fields["$rename"])) {
126
- if (oldKey in obj) {
127
- obj[newKey] = obj[oldKey];
128
- delete obj[oldKey];
129
- }
130
- }
131
- }
132
- }
133
- /**
134
- * Updates an object with new values.
135
- * @param obj - The object to update.
136
- * @param newVal - An object containing new values to update in the target object.
137
- */
138
- function updateObject(obj, newVal) {
139
- for (let key in newVal) {
140
- if (newVal.hasOwnProperty(key)) {
141
- obj[key] = newVal[key];
142
- }
143
- }
144
- return obj;
145
- }
File without changes