@plasius/economy 0.3.0 → 0.3.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.
package/dist/index.d.cts CHANGED
@@ -36,7 +36,7 @@ type IsoTimestamp = string;
36
36
  declare function assertEconomyIdentifier(value: string, label?: string): void;
37
37
  /** Parses a bounded ISO timestamp and returns milliseconds since epoch. */
38
38
  declare function parseIsoTimestamp(value: IsoTimestamp): number;
39
- /** Returns a new record with keys sorted for canonical serialization. */
39
+ /** Returns a new record with keys sorted by locale-independent code units. */
40
40
  declare function sortStringRecord(value: Readonly<Record<string, string>>): Readonly<Record<string, string>>;
41
41
 
42
42
  type TokenSource = "shopify" | "ayet" | "bitlabs" | "subscription" | "event" | "competition" | "adjustment";
package/dist/index.d.ts CHANGED
@@ -36,7 +36,7 @@ type IsoTimestamp = string;
36
36
  declare function assertEconomyIdentifier(value: string, label?: string): void;
37
37
  /** Parses a bounded ISO timestamp and returns milliseconds since epoch. */
38
38
  declare function parseIsoTimestamp(value: IsoTimestamp): number;
39
- /** Returns a new record with keys sorted for canonical serialization. */
39
+ /** Returns a new record with keys sorted by locale-independent code units. */
40
40
  declare function sortStringRecord(value: Readonly<Record<string, string>>): Readonly<Record<string, string>>;
41
41
 
42
42
  type TokenSource = "shopify" | "ayet" | "bitlabs" | "subscription" | "event" | "competition" | "adjustment";
package/dist/index.js CHANGED
@@ -81,6 +81,14 @@ function sumTokenSubunits(values) {
81
81
  return total;
82
82
  }
83
83
 
84
+ // src/canonical-order.ts
85
+ function compareUnicodeCodeUnits(left, right) {
86
+ if (left === right) {
87
+ return 0;
88
+ }
89
+ return left < right ? -1 : 1;
90
+ }
91
+
84
92
  // src/contracts.ts
85
93
  var ECONOMY_CONTRACT_VERSION = "1";
86
94
  var IDENTIFIER = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
@@ -117,7 +125,9 @@ function parseIsoTimestamp(value) {
117
125
  }
118
126
  function sortStringRecord(value) {
119
127
  return Object.fromEntries(
120
- Object.entries(value).sort(([left], [right]) => left.localeCompare(right))
128
+ Object.entries(value).sort(
129
+ ([left], [right]) => compareUnicodeCodeUnits(left, right)
130
+ )
121
131
  );
122
132
  }
123
133
 
@@ -1047,7 +1057,9 @@ function assertEconomicJournalTransaction(transaction) {
1047
1057
  }
1048
1058
  function canonicalTransactionPayload(transaction) {
1049
1059
  assertBalancedTransaction(transaction);
1050
- const postings = [...transaction.postings].sort((left, right) => left.postingId.localeCompare(right.postingId)).map((posting) => ({
1060
+ const postings = [...transaction.postings].sort(
1061
+ (left, right) => compareUnicodeCodeUnits(left.postingId, right.postingId)
1062
+ ).map((posting) => ({
1051
1063
  schemaVersion: posting.schemaVersion,
1052
1064
  postingId: posting.postingId,
1053
1065
  transactionId: posting.transactionId,