@gesslar/toolkit 3.35.0 → 3.36.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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "name": "gesslar",
6
6
  "url": "https://gesslar.dev"
7
7
  },
8
- "version": "3.35.0",
8
+ "version": "3.36.0",
9
9
  "license": "Unlicense",
10
10
  "homepage": "https://github.com/gesslar/toolkit#readme",
11
11
  "repository": {
@@ -46,6 +46,7 @@
46
46
  "files": [
47
47
  "src/",
48
48
  "types/",
49
+ "scripts/",
49
50
  "UNLICENSE.txt"
50
51
  ],
51
52
  "engines": {
@@ -0,0 +1,60 @@
1
+ /* -- temporarily turning off
2
+
3
+ import {readFile} from "node:fs/promises"
4
+ import {dirname, join} from "node:path"
5
+ import {fileURLToPath} from "node:url"
6
+
7
+ await(async() => {
8
+ const __dirname = dirname(fileURLToPath(import.meta.url))
9
+ const pkgPath = join(__dirname, "../package.json")
10
+
11
+ try {
12
+ const pkg = JSON.parse(await readFile(pkgPath, "utf-8"))
13
+ const nodeEngine = pkg.engines?.node
14
+
15
+ const versionMatch = nodeEngine?.match(/(?<target>\d+\.\d+\.\d+)$/)
16
+ const {target} = versionMatch?.groups ?? {}
17
+
18
+ if(!target)
19
+ throw new Error(`Could not parse target version from engines.node: "${nodeEngine}"`)
20
+
21
+ const current = process.versions.node
22
+
23
+ const isCompatible = (() => {
24
+ const c = current.split(".").map(Number)
25
+ const t = target.split(".").map(Number)
26
+
27
+ // Major
28
+ if(c[0] > t[0])
29
+ return true
30
+
31
+ if(c[0] < t[0])
32
+ return false
33
+
34
+ // Minor
35
+ if(c[1] > t[1])
36
+ return true
37
+
38
+ if(c[1] < t[1])
39
+ return false
40
+
41
+ // Patch
42
+ if(c[2] < t[2])
43
+ return false
44
+
45
+ return true
46
+ })()
47
+
48
+ if(!isCompatible) {
49
+ console.error(`\x1b[31m%s\x1b[0m`, `✖ Error: @gesslar/toolkit requires Node.js ${nodeEngine}`)
50
+ console.error(`\x1b[90m%s\x1b[0m`, ` Current version: ${current}`)
51
+ process.exit(1)
52
+ }
53
+ } catch(err) {
54
+ console.warn(`\x1b[33m%s\x1b[0m`, `⚠ Compatibility check failed: ${err.message}`)
55
+ // We exit 0 here if we want to allow the install to proceed despite a script error,
56
+ // or exit 1 to be strictly safe.
57
+ process.exit(0)
58
+ }
59
+ })()
60
+ */
@@ -686,4 +686,60 @@ export default class Collection {
686
686
 
687
687
  return Collection.transposeObjects(flattened)
688
688
  }
689
+
690
+ /**
691
+ * Computes the structured difference between two objects.
692
+ * Returns an object with three keys: `added`, `removed`, and `changed`.
693
+ * Nested objects are recursed into, producing the same structure.
694
+ * Primitive changes are represented as `{from, to}` pairs.
695
+ *
696
+ * @param {object|Array<unknown>} original - The original object or array to compare from
697
+ * @param {object|Array<unknown>} updated - The updated object or array to compare against
698
+ * @returns {{added: object, removed: object, changed: object}} Structured diff.
699
+ * `added` contains keys new in `updated` with their new values.
700
+ * `removed` contains keys absent from `updated` with their old values.
701
+ * `changed` contains keys present in both but with different values;
702
+ * primitives are `{from, to}` pairs, nested objects recurse.
703
+ * All three keys are always present, empty when there are no differences.
704
+ */
705
+ static diff(original, updated) {
706
+ const added = {}
707
+ const removed = {}
708
+ const changed = {}
709
+
710
+ for(const key of Object.keys(updated)) {
711
+ Valid.prototypePollutionProtection([key])
712
+
713
+ if(!Object.hasOwn(original, key)) {
714
+ added[key] = updated[key]
715
+ } else if(!Object.is(original[key], updated[key])) {
716
+ if(
717
+ (Data.isPlainObject(original[key]) &&
718
+ Data.isPlainObject(updated[key])) ||
719
+ (Array.isArray(original[key]) && Array.isArray(updated[key]))
720
+ ) {
721
+ const nested = Collection.diff(original[key], updated[key])
722
+ const hasChanges =
723
+ Object.keys(nested.added).length > 0 ||
724
+ Object.keys(nested.removed).length > 0 ||
725
+ Object.keys(nested.changed).length > 0
726
+
727
+ if(hasChanges)
728
+ changed[key] = nested
729
+
730
+ } else {
731
+ changed[key] = {from: original[key], to: updated[key]}
732
+ }
733
+ }
734
+ }
735
+
736
+ for(const key of Object.keys(original)) {
737
+ Valid.prototypePollutionProtection([key])
738
+
739
+ if(!Object.hasOwn(updated, key))
740
+ removed[key] = original[key]
741
+ }
742
+
743
+ return {added, removed, changed}
744
+ }
689
745
  }
@@ -244,5 +244,25 @@ export default class Collection {
244
244
  * @returns {object} Transposed object with arrays of values
245
245
  */
246
246
  static flattenObjectArray(input: Array<object> | Array<Array<object>>): object;
247
+ /**
248
+ * Computes the structured difference between two objects.
249
+ * Returns an object with three keys: `added`, `removed`, and `changed`.
250
+ * Nested objects are recursed into, producing the same structure.
251
+ * Primitive changes are represented as `{from, to}` pairs.
252
+ *
253
+ * @param {object|Array<unknown>} original - The original object or array to compare from
254
+ * @param {object|Array<unknown>} updated - The updated object or array to compare against
255
+ * @returns {{added: object, removed: object, changed: object}} Structured diff.
256
+ * `added` contains keys new in `updated` with their new values.
257
+ * `removed` contains keys absent from `updated` with their old values.
258
+ * `changed` contains keys present in both but with different values;
259
+ * primitives are `{from, to}` pairs, nested objects recurse.
260
+ * All three keys are always present, empty when there are no differences.
261
+ */
262
+ static diff(original: object | Array<unknown>, updated: object | Array<unknown>): {
263
+ added: object;
264
+ removed: object;
265
+ changed: object;
266
+ };
247
267
  }
248
268
  //# sourceMappingURL=Collection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../../src/browser/lib/Collection.js"],"names":[],"mappings":"AAcA;;;GAGG;AACH;IACE;;;;;;;;;OASG;IACH,6BANW,KAAK,CAAC,OAAO,CAAC,aACd,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,OAAO,YACjE,OAAO,GACL,OAAO,GAAC,SAAS,CAqB7B;IAED;;;;;;;;OAQG;IACH,8BALW,MAAM,aACN,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG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C,CA0C3B;IAED;;;;;;;;OAQG;IACH,sBALW,KAAK,CAAC,OAAO,CAAC,WACd,KAAK,CAAC,OAAO,CAAC,GACZ,KAAK,CAAC,OAAO,CAAC,CAW1B;IAED;;;;;;;;OAQG;IACH,2BALW,KAAK,CAAC,OAAO,CAAC,WACd,KAAK,CAAC,OAAO,CAAC,GACZ,KAAK,CAAC,OAAO,CAAC,CAY1B;IAED;;;;;;;;OAQG;IACH,0BALW,KAAK,CAAC,OAAO,CAAC,WACd,KAAK,CAAC,OAAO,CAAC,GACZ,KAAK,CAAC,OAAO,CAAC,CAiB1B;IAED;;;;;;;OAOG;IACH,iCAJW,KAAK,CAAC,MAAM,CAAC,GACX,MAAM,CA0BlB;IAED;;;;;;OAMG;IACH,iCAHW,KAAK,CAAC,MAAM,CAAC,GAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAChC,MAAM,CAMlB;CACF"}
1
+ {"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../../src/browser/lib/Collection.js"],"names":[],"mappings":"AAcA;;;GAGG;AACH;IACE;;;;;;;;;OASG;IACH,6BANW,KAAK,CAAC,OAAO,CAAC,aACd,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,OAAO,YACjE,OAAO,GACL,OAAO,GAAC,SAAS,CAqB7B;IAED;;;;;;;;OAQG;IACH,8BALW,MAAM,aACN,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,GACtD,OAAO,GAAC,SAAS,CAmB7B;IAED;;;;;;;;OAQG;IACH,2BALW,GAAG,CAAC,OAAO,CAAC,aACZ,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,KAAK,OAAO,GAC5C,OAAO,GAAC,SAAS,CAmB7B;IAED;;;;;;;;;OASG;IACH,2B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