@atscript/db 0.1.39 → 0.1.40

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 (64) hide show
  1. package/README.md +18 -18
  2. package/dist/agg.cjs +8 -3
  3. package/dist/agg.d.cts +7 -0
  4. package/dist/agg.d.mts +7 -0
  5. package/dist/agg.mjs +7 -3
  6. package/dist/control-DRgryKeg.cjs +14 -0
  7. package/dist/{control_as-bjmwe24C.mjs → control-IANbnfjG.mjs} +6 -18
  8. package/dist/db-readable-BQQzfguJ.d.cts +1249 -0
  9. package/dist/db-readable-Bbr4CjMb.d.mts +1249 -0
  10. package/dist/db-space-BUrQ5BFm.d.mts +309 -0
  11. package/dist/db-space-Vxpcnyt5.d.cts +309 -0
  12. package/dist/db-validator-plugin-07kDiis2.d.cts +22 -0
  13. package/dist/db-validator-plugin-CiqsHTI_.d.mts +22 -0
  14. package/dist/db-view-BntnAmXO.cjs +3071 -0
  15. package/dist/db-view-ZsoN91-q.mjs +2970 -0
  16. package/dist/index.cjs +95 -2801
  17. package/dist/index.d.cts +137 -0
  18. package/dist/index.d.mts +137 -0
  19. package/dist/index.mjs +55 -2761
  20. package/dist/{nested-writer-BkqL7cp3.cjs → nested-writer-BDXsDMPP.cjs} +196 -150
  21. package/dist/{nested-writer-NEN51mnR.mjs → nested-writer-Dmm1gbZV.mjs} +118 -70
  22. package/dist/ops-BdRAFLKY.d.mts +67 -0
  23. package/dist/ops-DXJ4Zw0P.d.cts +67 -0
  24. package/dist/ops.cjs +123 -0
  25. package/dist/ops.d.cts +2 -0
  26. package/dist/ops.d.mts +2 -0
  27. package/dist/ops.mjs +112 -0
  28. package/dist/plugin.cjs +90 -109
  29. package/dist/plugin.d.cts +6 -0
  30. package/dist/plugin.d.mts +6 -0
  31. package/dist/plugin.mjs +29 -49
  32. package/dist/rel.cjs +20 -20
  33. package/dist/rel.d.cts +119 -0
  34. package/dist/rel.d.mts +119 -0
  35. package/dist/rel.mjs +4 -5
  36. package/dist/{relation-helpers-guFL_oRf.cjs → relation-helpers-BYvsE1tR.cjs} +26 -22
  37. package/dist/{relation-helpers-DyBIlQnB.mjs → relation-helpers-CLasawQq.mjs} +11 -6
  38. package/dist/{relation-loader-Dv7qXYq7.mjs → relation-loader-BEOTXNcq.mjs} +63 -43
  39. package/dist/{relation-loader-CpnDRf9k.cjs → relation-loader-CRC5LcqM.cjs} +74 -49
  40. package/dist/shared.cjs +13 -13
  41. package/dist/{shared.d.ts → shared.d.cts} +14 -13
  42. package/dist/shared.d.mts +71 -0
  43. package/dist/shared.mjs +2 -3
  44. package/dist/sync.cjs +300 -252
  45. package/dist/sync.d.cts +369 -0
  46. package/dist/sync.d.mts +369 -0
  47. package/dist/sync.mjs +284 -233
  48. package/dist/{validation-utils-DEoCMmEb.cjs → validation-utils-DVJDijnB.cjs} +141 -109
  49. package/dist/{validation-utils-DhR_mtKa.mjs → validation-utils-DhjIjP1-.mjs} +71 -37
  50. package/package.json +30 -29
  51. package/LICENSE +0 -21
  52. package/dist/agg-BJFJ3dFQ.mjs +0 -8
  53. package/dist/agg-DnUWAOK8.cjs +0 -14
  54. package/dist/agg.d.ts +0 -13
  55. package/dist/chunk-CrpGerW8.cjs +0 -31
  56. package/dist/control_as-BFPERAF_.cjs +0 -28
  57. package/dist/index.d.ts +0 -1706
  58. package/dist/logger-B7oxCfLQ.mjs +0 -12
  59. package/dist/logger-Dt2v_-wb.cjs +0 -18
  60. package/dist/plugin.d.ts +0 -5
  61. package/dist/rel.d.ts +0 -1305
  62. package/dist/relation-loader-D4mTw6yH.cjs +0 -4
  63. package/dist/relation-loader-Ggy1ujwR.mjs +0 -4
  64. package/dist/sync.d.ts +0 -1878
package/dist/ops.cjs ADDED
@@ -0,0 +1,123 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/ops.ts
3
+ /** Increment a numeric field by `value` (default 1). */
4
+ function $inc(value = 1) {
5
+ return { $inc: value };
6
+ }
7
+ /** Decrement a numeric field by `value` (default 1). */
8
+ function $dec(value = 1) {
9
+ return { $dec: value };
10
+ }
11
+ /** Multiply a numeric field by `value`. */
12
+ function $mul(value) {
13
+ return { $mul: value };
14
+ }
15
+ /** Replace the entire array. */
16
+ function $replace(items) {
17
+ return { $replace: items };
18
+ }
19
+ /** Append items to an array. */
20
+ function $insert(items) {
21
+ return { $insert: items };
22
+ }
23
+ /** Insert-or-update items by key. */
24
+ function $upsert(items) {
25
+ return { $upsert: items };
26
+ }
27
+ /** Update existing items matched by key. */
28
+ function $update(items) {
29
+ return { $update: items };
30
+ }
31
+ /** Remove items matched by key or value. */
32
+ function $remove(items) {
33
+ return { $remove: items };
34
+ }
35
+ /** Returns true if obj has any own key other than `skip`. Zero-allocation. */
36
+ function _hasExtraKey(obj, skip) {
37
+ for (const k in obj) if (k !== skip) return true;
38
+ return false;
39
+ }
40
+ /**
41
+ * Returns `true` when `value` is a field operation object
42
+ * (`{ $inc: N }`, `{ $dec: N }`, or `{ $mul: N }`).
43
+ */
44
+ function isDbFieldOp(value) {
45
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
46
+ const v = value;
47
+ if ("$inc" in v) return typeof v.$inc === "number" && !_hasExtraKey(v, "$inc");
48
+ if ("$dec" in v) return typeof v.$dec === "number" && !_hasExtraKey(v, "$dec");
49
+ if ("$mul" in v) return typeof v.$mul === "number" && !_hasExtraKey(v, "$mul");
50
+ return false;
51
+ }
52
+ /**
53
+ * Extracts the normalized operation from a field op value.
54
+ * Returns `undefined` when `value` is not a field op.
55
+ *
56
+ * `$dec` is normalized to `{ op: 'inc', value: -N }` so consumers
57
+ * only need to handle `inc` and `mul`.
58
+ */
59
+ function getDbFieldOp(value) {
60
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return;
61
+ const v = value;
62
+ if (typeof v.$inc === "number" && !_hasExtraKey(v, "$inc")) return {
63
+ op: "inc",
64
+ value: v.$inc
65
+ };
66
+ if (typeof v.$dec === "number" && !_hasExtraKey(v, "$dec")) return {
67
+ op: "inc",
68
+ value: -v.$dec
69
+ };
70
+ if (typeof v.$mul === "number" && !_hasExtraKey(v, "$mul")) return {
71
+ op: "mul",
72
+ value: v.$mul
73
+ };
74
+ }
75
+ /**
76
+ * Separates field operations from a data payload.
77
+ *
78
+ * Mutates `data` in-place (removes op entries) and returns the separated ops.
79
+ * When no ops are found, returns `undefined` — zero allocation for the
80
+ * common non-op case.
81
+ *
82
+ * Hot path: uses `for...in` (no array allocation), inlines detection to
83
+ * avoid intermediate `{ op, value }` objects, and short-circuits on typeof.
84
+ */
85
+ function separateFieldOps(data) {
86
+ let ops;
87
+ for (const key in data) {
88
+ const value = data[key];
89
+ if (typeof value !== "object" || value === null || Array.isArray(value)) continue;
90
+ const v = value;
91
+ let opValue;
92
+ let opType;
93
+ if (typeof v.$inc === "number" && !_hasExtraKey(v, "$inc")) {
94
+ opValue = v.$inc;
95
+ opType = 0;
96
+ } else if (typeof v.$dec === "number" && !_hasExtraKey(v, "$dec")) {
97
+ opValue = -v.$dec;
98
+ opType = 0;
99
+ } else if (typeof v.$mul === "number" && !_hasExtraKey(v, "$mul")) {
100
+ opValue = v.$mul;
101
+ opType = 1;
102
+ }
103
+ if (opType !== void 0) {
104
+ if (!ops) ops = {};
105
+ if (opType === 0) (ops.inc ??= {})[key] = opValue;
106
+ else (ops.mul ??= {})[key] = opValue;
107
+ delete data[key];
108
+ }
109
+ }
110
+ return ops;
111
+ }
112
+ //#endregion
113
+ exports.$dec = $dec;
114
+ exports.$inc = $inc;
115
+ exports.$insert = $insert;
116
+ exports.$mul = $mul;
117
+ exports.$remove = $remove;
118
+ exports.$replace = $replace;
119
+ exports.$update = $update;
120
+ exports.$upsert = $upsert;
121
+ exports.getDbFieldOp = getDbFieldOp;
122
+ exports.isDbFieldOp = isDbFieldOp;
123
+ exports.separateFieldOps = separateFieldOps;
package/dist/ops.d.cts ADDED
@@ -0,0 +1,2 @@
1
+ import { a as $remove, c as $upsert, d as getDbFieldOp, f as isDbFieldOp, i as $mul, l as TDbFieldOp, n as $inc, o as $replace, p as separateFieldOps, r as $insert, s as $update, t as $dec, u as TFieldOps } from "./ops-DXJ4Zw0P.cjs";
2
+ export { $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, TDbFieldOp, TFieldOps, getDbFieldOp, isDbFieldOp, separateFieldOps };
package/dist/ops.d.mts ADDED
@@ -0,0 +1,2 @@
1
+ import { a as $remove, c as $upsert, d as getDbFieldOp, f as isDbFieldOp, i as $mul, l as TDbFieldOp, n as $inc, o as $replace, p as separateFieldOps, r as $insert, s as $update, t as $dec, u as TFieldOps } from "./ops-BdRAFLKY.mjs";
2
+ export { $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, TDbFieldOp, TFieldOps, getDbFieldOp, isDbFieldOp, separateFieldOps };
package/dist/ops.mjs ADDED
@@ -0,0 +1,112 @@
1
+ //#region src/ops.ts
2
+ /** Increment a numeric field by `value` (default 1). */
3
+ function $inc(value = 1) {
4
+ return { $inc: value };
5
+ }
6
+ /** Decrement a numeric field by `value` (default 1). */
7
+ function $dec(value = 1) {
8
+ return { $dec: value };
9
+ }
10
+ /** Multiply a numeric field by `value`. */
11
+ function $mul(value) {
12
+ return { $mul: value };
13
+ }
14
+ /** Replace the entire array. */
15
+ function $replace(items) {
16
+ return { $replace: items };
17
+ }
18
+ /** Append items to an array. */
19
+ function $insert(items) {
20
+ return { $insert: items };
21
+ }
22
+ /** Insert-or-update items by key. */
23
+ function $upsert(items) {
24
+ return { $upsert: items };
25
+ }
26
+ /** Update existing items matched by key. */
27
+ function $update(items) {
28
+ return { $update: items };
29
+ }
30
+ /** Remove items matched by key or value. */
31
+ function $remove(items) {
32
+ return { $remove: items };
33
+ }
34
+ /** Returns true if obj has any own key other than `skip`. Zero-allocation. */
35
+ function _hasExtraKey(obj, skip) {
36
+ for (const k in obj) if (k !== skip) return true;
37
+ return false;
38
+ }
39
+ /**
40
+ * Returns `true` when `value` is a field operation object
41
+ * (`{ $inc: N }`, `{ $dec: N }`, or `{ $mul: N }`).
42
+ */
43
+ function isDbFieldOp(value) {
44
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
45
+ const v = value;
46
+ if ("$inc" in v) return typeof v.$inc === "number" && !_hasExtraKey(v, "$inc");
47
+ if ("$dec" in v) return typeof v.$dec === "number" && !_hasExtraKey(v, "$dec");
48
+ if ("$mul" in v) return typeof v.$mul === "number" && !_hasExtraKey(v, "$mul");
49
+ return false;
50
+ }
51
+ /**
52
+ * Extracts the normalized operation from a field op value.
53
+ * Returns `undefined` when `value` is not a field op.
54
+ *
55
+ * `$dec` is normalized to `{ op: 'inc', value: -N }` so consumers
56
+ * only need to handle `inc` and `mul`.
57
+ */
58
+ function getDbFieldOp(value) {
59
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return;
60
+ const v = value;
61
+ if (typeof v.$inc === "number" && !_hasExtraKey(v, "$inc")) return {
62
+ op: "inc",
63
+ value: v.$inc
64
+ };
65
+ if (typeof v.$dec === "number" && !_hasExtraKey(v, "$dec")) return {
66
+ op: "inc",
67
+ value: -v.$dec
68
+ };
69
+ if (typeof v.$mul === "number" && !_hasExtraKey(v, "$mul")) return {
70
+ op: "mul",
71
+ value: v.$mul
72
+ };
73
+ }
74
+ /**
75
+ * Separates field operations from a data payload.
76
+ *
77
+ * Mutates `data` in-place (removes op entries) and returns the separated ops.
78
+ * When no ops are found, returns `undefined` — zero allocation for the
79
+ * common non-op case.
80
+ *
81
+ * Hot path: uses `for...in` (no array allocation), inlines detection to
82
+ * avoid intermediate `{ op, value }` objects, and short-circuits on typeof.
83
+ */
84
+ function separateFieldOps(data) {
85
+ let ops;
86
+ for (const key in data) {
87
+ const value = data[key];
88
+ if (typeof value !== "object" || value === null || Array.isArray(value)) continue;
89
+ const v = value;
90
+ let opValue;
91
+ let opType;
92
+ if (typeof v.$inc === "number" && !_hasExtraKey(v, "$inc")) {
93
+ opValue = v.$inc;
94
+ opType = 0;
95
+ } else if (typeof v.$dec === "number" && !_hasExtraKey(v, "$dec")) {
96
+ opValue = -v.$dec;
97
+ opType = 0;
98
+ } else if (typeof v.$mul === "number" && !_hasExtraKey(v, "$mul")) {
99
+ opValue = v.$mul;
100
+ opType = 1;
101
+ }
102
+ if (opType !== void 0) {
103
+ if (!ops) ops = {};
104
+ if (opType === 0) (ops.inc ??= {})[key] = opValue;
105
+ else (ops.mul ??= {})[key] = opValue;
106
+ delete data[key];
107
+ }
108
+ }
109
+ return ops;
110
+ }
111
+ //#endregion
112
+ export { $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, getDbFieldOp, isDbFieldOp, separateFieldOps };