@chipmobilesdk/rn-core 0.0.0 → 0.2.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.
Files changed (158) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/lib/commonjs/diagnostics/index.js +81 -0
  3. package/lib/commonjs/diagnostics/index.js.map +1 -0
  4. package/lib/commonjs/errors/index.js +86 -0
  5. package/lib/commonjs/errors/index.js.map +1 -0
  6. package/lib/commonjs/index.js +305 -0
  7. package/lib/commonjs/index.js.map +1 -0
  8. package/lib/commonjs/intl/index.js +98 -0
  9. package/lib/commonjs/intl/index.js.map +1 -0
  10. package/lib/commonjs/kv/index.js +83 -0
  11. package/lib/commonjs/kv/index.js.map +1 -0
  12. package/lib/commonjs/lazy/index.js +63 -0
  13. package/lib/commonjs/lazy/index.js.map +1 -0
  14. package/lib/commonjs/listeners/index.js +110 -0
  15. package/lib/commonjs/listeners/index.js.map +1 -0
  16. package/lib/commonjs/messages/index.js +53 -0
  17. package/lib/commonjs/messages/index.js.map +1 -0
  18. package/lib/commonjs/package.json +1 -0
  19. package/lib/commonjs/react/index.js +93 -0
  20. package/lib/commonjs/react/index.js.map +1 -0
  21. package/lib/commonjs/redact/index.js +128 -0
  22. package/lib/commonjs/redact/index.js.map +1 -0
  23. package/lib/commonjs/runtime/index.js +77 -0
  24. package/lib/commonjs/runtime/index.js.map +1 -0
  25. package/lib/commonjs/runtime/lifecycle.js +105 -0
  26. package/lib/commonjs/runtime/lifecycle.js.map +1 -0
  27. package/lib/commonjs/scheduler/index.js +216 -0
  28. package/lib/commonjs/scheduler/index.js.map +1 -0
  29. package/lib/commonjs/store/index.js +39 -0
  30. package/lib/commonjs/store/index.js.map +1 -0
  31. package/lib/commonjs/testing/conformance.js +79 -0
  32. package/lib/commonjs/testing/conformance.js.map +1 -0
  33. package/lib/commonjs/testing/index.js +58 -0
  34. package/lib/commonjs/testing/index.js.map +1 -0
  35. package/lib/commonjs/testing/lifecycle.js +37 -0
  36. package/lib/commonjs/testing/lifecycle.js.map +1 -0
  37. package/lib/commonjs/testing/redaction.js +118 -0
  38. package/lib/commonjs/testing/redaction.js.map +1 -0
  39. package/lib/commonjs/testing/scheduler.js +51 -0
  40. package/lib/commonjs/testing/scheduler.js.map +1 -0
  41. package/lib/module/diagnostics/index.js +75 -0
  42. package/lib/module/diagnostics/index.js.map +1 -0
  43. package/lib/module/errors/index.js +78 -0
  44. package/lib/module/errors/index.js.map +1 -0
  45. package/lib/module/index.js +24 -0
  46. package/lib/module/index.js.map +1 -0
  47. package/lib/module/intl/index.js +91 -0
  48. package/lib/module/intl/index.js.map +1 -0
  49. package/lib/module/kv/index.js +76 -0
  50. package/lib/module/kv/index.js.map +1 -0
  51. package/lib/module/lazy/index.js +59 -0
  52. package/lib/module/lazy/index.js.map +1 -0
  53. package/lib/module/listeners/index.js +104 -0
  54. package/lib/module/listeners/index.js.map +1 -0
  55. package/lib/module/messages/index.js +48 -0
  56. package/lib/module/messages/index.js.map +1 -0
  57. package/lib/module/package.json +1 -0
  58. package/lib/module/react/index.js +86 -0
  59. package/lib/module/react/index.js.map +1 -0
  60. package/lib/module/redact/index.js +118 -0
  61. package/lib/module/redact/index.js.map +1 -0
  62. package/lib/module/runtime/index.js +52 -0
  63. package/lib/module/runtime/index.js.map +1 -0
  64. package/lib/module/runtime/lifecycle.js +99 -0
  65. package/lib/module/runtime/lifecycle.js.map +1 -0
  66. package/lib/module/scheduler/index.js +203 -0
  67. package/lib/module/scheduler/index.js.map +1 -0
  68. package/lib/module/store/index.js +33 -0
  69. package/lib/module/store/index.js.map +1 -0
  70. package/lib/module/testing/conformance.js +72 -0
  71. package/lib/module/testing/conformance.js.map +1 -0
  72. package/lib/module/testing/index.js +12 -0
  73. package/lib/module/testing/index.js.map +1 -0
  74. package/lib/module/testing/lifecycle.js +32 -0
  75. package/lib/module/testing/lifecycle.js.map +1 -0
  76. package/lib/module/testing/redaction.js +113 -0
  77. package/lib/module/testing/redaction.js.map +1 -0
  78. package/lib/module/testing/scheduler.js +47 -0
  79. package/lib/module/testing/scheduler.js.map +1 -0
  80. package/lib/typescript/commonjs/diagnostics/index.d.ts +49 -0
  81. package/lib/typescript/commonjs/diagnostics/index.d.ts.map +1 -0
  82. package/lib/typescript/commonjs/errors/index.d.ts +59 -0
  83. package/lib/typescript/commonjs/errors/index.d.ts.map +1 -0
  84. package/lib/typescript/commonjs/index.d.ts +22 -0
  85. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  86. package/lib/typescript/commonjs/intl/index.d.ts +25 -0
  87. package/lib/typescript/commonjs/intl/index.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/kv/index.d.ts +38 -0
  89. package/lib/typescript/commonjs/kv/index.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/lazy/index.d.ts +36 -0
  91. package/lib/typescript/commonjs/lazy/index.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/listeners/index.d.ts +61 -0
  93. package/lib/typescript/commonjs/listeners/index.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/messages/index.d.ts +39 -0
  95. package/lib/typescript/commonjs/messages/index.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/package.json +1 -0
  97. package/lib/typescript/commonjs/react/index.d.ts +38 -0
  98. package/lib/typescript/commonjs/react/index.d.ts.map +1 -0
  99. package/lib/typescript/commonjs/redact/index.d.ts +47 -0
  100. package/lib/typescript/commonjs/redact/index.d.ts.map +1 -0
  101. package/lib/typescript/commonjs/runtime/index.d.ts +21 -0
  102. package/lib/typescript/commonjs/runtime/index.d.ts.map +1 -0
  103. package/lib/typescript/commonjs/runtime/lifecycle.d.ts +34 -0
  104. package/lib/typescript/commonjs/runtime/lifecycle.d.ts.map +1 -0
  105. package/lib/typescript/commonjs/scheduler/index.d.ts +108 -0
  106. package/lib/typescript/commonjs/scheduler/index.d.ts.map +1 -0
  107. package/lib/typescript/commonjs/store/index.d.ts +18 -0
  108. package/lib/typescript/commonjs/store/index.d.ts.map +1 -0
  109. package/lib/typescript/commonjs/testing/conformance.d.ts +35 -0
  110. package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
  111. package/lib/typescript/commonjs/testing/index.d.ts +10 -0
  112. package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
  113. package/lib/typescript/commonjs/testing/lifecycle.d.ts +15 -0
  114. package/lib/typescript/commonjs/testing/lifecycle.d.ts.map +1 -0
  115. package/lib/typescript/commonjs/testing/redaction.d.ts +35 -0
  116. package/lib/typescript/commonjs/testing/redaction.d.ts.map +1 -0
  117. package/lib/typescript/commonjs/testing/scheduler.d.ts +15 -0
  118. package/lib/typescript/commonjs/testing/scheduler.d.ts.map +1 -0
  119. package/lib/typescript/module/diagnostics/index.d.ts +49 -0
  120. package/lib/typescript/module/diagnostics/index.d.ts.map +1 -0
  121. package/lib/typescript/module/errors/index.d.ts +59 -0
  122. package/lib/typescript/module/errors/index.d.ts.map +1 -0
  123. package/lib/typescript/module/index.d.ts +22 -0
  124. package/lib/typescript/module/index.d.ts.map +1 -0
  125. package/lib/typescript/module/intl/index.d.ts +25 -0
  126. package/lib/typescript/module/intl/index.d.ts.map +1 -0
  127. package/lib/typescript/module/kv/index.d.ts +38 -0
  128. package/lib/typescript/module/kv/index.d.ts.map +1 -0
  129. package/lib/typescript/module/lazy/index.d.ts +36 -0
  130. package/lib/typescript/module/lazy/index.d.ts.map +1 -0
  131. package/lib/typescript/module/listeners/index.d.ts +61 -0
  132. package/lib/typescript/module/listeners/index.d.ts.map +1 -0
  133. package/lib/typescript/module/messages/index.d.ts +39 -0
  134. package/lib/typescript/module/messages/index.d.ts.map +1 -0
  135. package/lib/typescript/module/package.json +1 -0
  136. package/lib/typescript/module/react/index.d.ts +38 -0
  137. package/lib/typescript/module/react/index.d.ts.map +1 -0
  138. package/lib/typescript/module/redact/index.d.ts +47 -0
  139. package/lib/typescript/module/redact/index.d.ts.map +1 -0
  140. package/lib/typescript/module/runtime/index.d.ts +21 -0
  141. package/lib/typescript/module/runtime/index.d.ts.map +1 -0
  142. package/lib/typescript/module/runtime/lifecycle.d.ts +34 -0
  143. package/lib/typescript/module/runtime/lifecycle.d.ts.map +1 -0
  144. package/lib/typescript/module/scheduler/index.d.ts +108 -0
  145. package/lib/typescript/module/scheduler/index.d.ts.map +1 -0
  146. package/lib/typescript/module/store/index.d.ts +18 -0
  147. package/lib/typescript/module/store/index.d.ts.map +1 -0
  148. package/lib/typescript/module/testing/conformance.d.ts +35 -0
  149. package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
  150. package/lib/typescript/module/testing/index.d.ts +10 -0
  151. package/lib/typescript/module/testing/index.d.ts.map +1 -0
  152. package/lib/typescript/module/testing/lifecycle.d.ts +15 -0
  153. package/lib/typescript/module/testing/lifecycle.d.ts.map +1 -0
  154. package/lib/typescript/module/testing/redaction.d.ts +35 -0
  155. package/lib/typescript/module/testing/redaction.d.ts.map +1 -0
  156. package/lib/typescript/module/testing/scheduler.d.ts +15 -0
  157. package/lib/typescript/module/testing/scheduler.d.ts.map +1 -0
  158. package/package.json +154 -46
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_lifecycle","require","createManualLifecycle","initial","state","handlers","Set","source","currentState","addEventListener","_type","handler","add","remove","delete","port","createAppLifecycle","set","next","isSubscribed","size"],"sourceRoot":"../../../src","sources":["testing/lifecycle.ts"],"mappings":";;;;;;AAKA,IAAAA,UAAA,GAAAC,OAAA;AALA;AACA;AACA;AACA;AACA;;AAgBO,SAASC,qBAAqBA,CAACC,OAA0B,GAAG,QAAQ,EAAmB;EAC7F,IAAIC,KAAwB,GAAGD,OAAO;EACtC,MAAME,QAAQ,GAAG,IAAIC,GAAG,CAAwB,CAAC;EACjD,MAAMC,MAAsB,GAAG;IAC9B,IAAIC,YAAYA,CAAA,EAAG;MAClB,OAAOJ,KAAK;IACb,CAAC;IACDK,gBAAgBA,CAACC,KAAK,EAAEC,OAAO,EAAE;MAChCN,QAAQ,CAACO,GAAG,CAACD,OAAO,CAAC;MACrB,OAAO;QAAEE,MAAM,EAAEA,CAAA,KAAMR,QAAQ,CAACS,MAAM,CAACH,OAAO;MAAE,CAAC;IAClD;EACD,CAAC;EACD,OAAO;IACNI,IAAI,EAAE,IAAAC,6BAAkB,EAAC,MAAMT,MAAM,CAAC;IACtCU,GAAGA,CAACC,IAAI,EAAE;MACTd,KAAK,GAAGc,IAAI;MACZ,KAAK,MAAMP,OAAO,IAAI,CAAC,GAAGN,QAAQ,CAAC,EAAEM,OAAO,CAACO,IAAI,CAAC;IACnD,CAAC;IACDC,YAAY,EAAEA,CAAA,KAAMd,QAAQ,CAACe,IAAI,GAAG;EACrC,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.REDACTION_PROBES = void 0;
7
+ exports.redactionConformance = redactionConformance;
8
+ /**
9
+ * One set of secrets every package's redaction must remove (CORE-02).
10
+ *
11
+ * Packages redact with different policies (identifier-only, pattern-based,
12
+ * key-based), but none of them may let one of these through. Each package runs
13
+ * this against every redaction entrypoint it has; the report is plain data, so it
14
+ * runs in Jest and on a device alike.
15
+ */
16
+
17
+ const JWT_PAYLOAD = 'eyJzdWIiOiJ1c2VyLTEyMzQ1Njc4OTAiLCJlbWFpbCI6ImFAYi5jbyJ9';
18
+ const JWT = `eyJhbGciOiJIUzI1NiJ9.${JWT_PAYLOAD}.c2lnbmF0dXJlLXZhbHVl`;
19
+ const URL_TOKEN = 'tok3nV4lue9x';
20
+ const EMAIL = 'jane.doe+chip@example.com';
21
+ const UUID = '3f2b8c1e-9a4d-4e6f-8b2a-1c3d5e7f9a0b';
22
+ const PAYLOAD = 'QmFzZTY0UGF5bG9hZFRoYXRJc0xvbmdFbm91Z2hUb0JlQVNlY3JldEJsb2JYWVo';
23
+ const REDACTION_PROBES = exports.REDACTION_PROBES = Object.freeze([{
24
+ name: 'a JWT',
25
+ input: `token rejected: ${JWT}`,
26
+ secret: JWT_PAYLOAD
27
+ }, {
28
+ name: 'a URL carrying a token',
29
+ input: `GET https://api.example.com/v1/chat?access_token=${URL_TOKEN} failed`,
30
+ secret: URL_TOKEN
31
+ }, {
32
+ name: 'an e-mail address',
33
+ input: `no account for ${EMAIL}`,
34
+ secret: EMAIL
35
+ }, {
36
+ name: 'a UUID',
37
+ input: `device ${UUID} refused`,
38
+ secret: UUID
39
+ }, {
40
+ name: 'a base64 payload',
41
+ input: `body=${PAYLOAD}`,
42
+ secret: PAYLOAD
43
+ }, {
44
+ name: 'an Error whose message carries a token',
45
+ input: new Error(`request failed: ${JWT}`),
46
+ secret: JWT_PAYLOAD
47
+ }, {
48
+ name: 'an object carrying a JWT under an innocent key',
49
+ input: {
50
+ reason: `expired ${JWT}`
51
+ },
52
+ secret: JWT_PAYLOAD,
53
+ structured: true
54
+ }, {
55
+ name: 'a nested object carrying an e-mail address',
56
+ input: {
57
+ request: {
58
+ owner: EMAIL
59
+ }
60
+ },
61
+ secret: EMAIL,
62
+ structured: true
63
+ }]);
64
+ /**
65
+ * Everything a log line could show. An Error goes in with its message and its own
66
+ * fields: JSON.stringify renders one as `{}`, which would pass any secret.
67
+ */
68
+ function serialize(value) {
69
+ if (typeof value === 'string') return value;
70
+ try {
71
+ if (value instanceof Error) {
72
+ return `${value.name}: ${value.message} ${JSON.stringify({
73
+ ...value
74
+ })}`;
75
+ }
76
+ // JSON.stringify returns undefined for undefined and functions at run time.
77
+ const json = JSON.stringify(value, (_key, inner) => inner instanceof Error ? `${inner.name}: ${inner.message}` : inner);
78
+ return json ?? String(value);
79
+ } catch {
80
+ return String(value);
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Runs every probe through `redact` and reports each secret that survived.
86
+ * `stringsOnly` is for a redactor that only accepts text (rn-auth's `redact`).
87
+ */
88
+ function redactionConformance(redact, options = {}) {
89
+ const failures = [];
90
+ let checks = 0;
91
+ for (const probe of REDACTION_PROBES) {
92
+ if (options.stringsOnly && typeof probe.input !== 'string') continue;
93
+ if (probe.structured && options.stringsOnly) continue;
94
+ checks += 1;
95
+ let output;
96
+ try {
97
+ output = serialize(redact(probe.input));
98
+ } catch (error) {
99
+ failures.push({
100
+ check: probe.name,
101
+ detail: `redactor threw: ${String(error)}`
102
+ });
103
+ continue;
104
+ }
105
+ if (output.includes(probe.secret)) {
106
+ failures.push({
107
+ check: probe.name,
108
+ detail: 'the secret survived redaction'
109
+ });
110
+ }
111
+ }
112
+ return {
113
+ passed: failures.length === 0,
114
+ checks,
115
+ failures
116
+ };
117
+ }
118
+ //# sourceMappingURL=redaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["JWT_PAYLOAD","JWT","URL_TOKEN","EMAIL","UUID","PAYLOAD","REDACTION_PROBES","exports","Object","freeze","name","input","secret","Error","reason","structured","request","owner","serialize","value","message","JSON","stringify","json","_key","inner","String","redactionConformance","redact","options","failures","checks","probe","stringsOnly","output","error","push","check","detail","includes","passed","length"],"sourceRoot":"../../../src","sources":["testing/redaction.ts"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,MAAMA,WAAW,GAAG,0DAA0D;AAC9E,MAAMC,GAAG,GAAG,wBAAwBD,WAAW,uBAAuB;AACtE,MAAME,SAAS,GAAG,cAAc;AAChC,MAAMC,KAAK,GAAG,2BAA2B;AACzC,MAAMC,IAAI,GAAG,sCAAsC;AACnD,MAAMC,OAAO,GAAG,iEAAiE;AAE1E,MAAMC,gBAA2C,GAAAC,OAAA,CAAAD,gBAAA,GAAGE,MAAM,CAACC,MAAM,CAAC,CACxE;EAAEC,IAAI,EAAE,OAAO;EAAEC,KAAK,EAAE,mBAAmBV,GAAG,EAAE;EAAEW,MAAM,EAAEZ;AAAY,CAAC,EACvE;EACCU,IAAI,EAAE,wBAAwB;EAC9BC,KAAK,EAAE,oDAAoDT,SAAS,SAAS;EAC7EU,MAAM,EAAEV;AACT,CAAC,EACD;EAAEQ,IAAI,EAAE,mBAAmB;EAAEC,KAAK,EAAE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ACvB,OAAOF,IAAI,IAAIG,MAAM,CAACP,KAAK,CAAC;EAC7B,CAAC,CAAC,MAAM;IACP,OAAOO,MAAM,CAACP,KAAK,CAAC;EACrB;AACD;;AAEA;AACA;AACA;AACA;AACO,SAASQ,oBAAoBA,CACnCC,MAAmC,EACnCC,OAA2C,GAAG,CAAC,CAAC,EAC5B;EACpB,MAAMC,QAA8B,GAAG,EAAE;EACzC,IAAIC,MAAM,GAAG,CAAC;EACd,KAAK,MAAMC,KAAK,IAAI1B,gBAAgB,EAAE;IACrC,IAAIuB,OAAO,CAACI,WAAW,IAAI,OAAOD,KAAK,CAACrB,KAAK,KAAK,QAAQ,EAAE;IAC5D,IAAIqB,KAAK,CAACjB,UAAU,IAAIc,OAAO,CAACI,WAAW,EAAE;IAC7CF,MAAM,IAAI,CAAC;IACX,IAAIG,MAAc;IAClB,IAAI;MACHA,MAAM,GAAGhB,SAAS,CAACU,MAAM,CAACI,KAAK,CAACrB,KAAK,CAAC,CAAC;IACxC,CAAC,CAAC,OAAOwB,KAAK,EAAE;MACfL,QAAQ,CAACM,IAAI,CAAC;QAAEC,KAAK,EAAEL,KAAK,CAACtB,IAAI;QAAE4B,MAAM,EAAE,mBAAmBZ,MAAM,CAACS,KAAK,CAAC;MAAG,CAAC,CAAC;MAChF;IACD;IACA,IAAID,MAAM,CAACK,QAAQ,CAACP,KAAK,CAACpB,MAAM,CAAC,EAAE;MAClCkB,QAAQ,CAACM,IAAI,CAAC;QAAEC,KAAK,EAAEL,KAAK,CAACtB,IAAI;QAAE4B,MAAM,EAAE;MAAgC,CAAC,CAAC;IAC9E;EACD;EACA,OAAO;IAAEE,MAAM,EAAEV,QAAQ,CAACW,MAAM,KAAK,CAAC;IAAEV,MAAM;IAAED;EAAS,CAAC;AAC3D","ignoreList":[]}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createManualScheduler = createManualScheduler;
7
+ /**
8
+ * A scheduler a test drives by hand: nothing fires until `advance` moves the
9
+ * clock past it, so timing assertions are exact and instant.
10
+ */
11
+
12
+ function createManualScheduler(startMs = 0) {
13
+ let clock = startMs;
14
+ let nextId = 1;
15
+ const timers = new Map();
16
+ return {
17
+ setTimeout(callback, ms) {
18
+ const id = nextId++;
19
+ timers.set(id, {
20
+ at: clock + Math.max(0, ms),
21
+ callback
22
+ });
23
+ return id;
24
+ },
25
+ clearTimeout(handle) {
26
+ timers.delete(handle);
27
+ },
28
+ now: () => clock,
29
+ advance(ms) {
30
+ const target = clock + ms;
31
+ for (;;) {
32
+ let dueId;
33
+ let dueAt = Infinity;
34
+ for (const [id, timer] of timers) {
35
+ if (timer.at <= target && timer.at < dueAt) {
36
+ dueId = id;
37
+ dueAt = timer.at;
38
+ }
39
+ }
40
+ if (dueId === undefined) break;
41
+ const timer = timers.get(dueId);
42
+ timers.delete(dueId);
43
+ clock = dueAt;
44
+ timer?.callback();
45
+ }
46
+ clock = target;
47
+ },
48
+ pending: () => timers.size
49
+ };
50
+ }
51
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createManualScheduler","startMs","clock","nextId","timers","Map","setTimeout","callback","ms","id","set","at","Math","max","clearTimeout","handle","delete","now","advance","target","dueId","dueAt","Infinity","timer","undefined","get","pending","size"],"sourceRoot":"../../../src","sources":["testing/scheduler.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;;AAYO,SAASA,qBAAqBA,CAACC,OAAO,GAAG,CAAC,EAAmB;EACnE,IAAIC,KAAK,GAAGD,OAAO;EACnB,IAAIE,MAAM,GAAG,CAAC;EACd,MAAMC,MAAM,GAAG,IAAIC,GAAG,CAA+C,CAAC;EAEtE,OAAO;IACNC,UAAUA,CAACC,QAAQ,EAAEC,EAAE,EAAE;MACxB,MAAMC,EAAE,GAAGN,MAAM,EAAE;MACnBC,MAAM,CAACM,GAAG,CAACD,EAAE,EAAE;QAAEE,EAAE,EAAET,KAAK,GAAGU,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEL,EAAE,CAAC;QAAED;MAAS,CAAC,CAAC;MACzD,OAAOE,EAAE;IACV,CAAC;IACDK,YAAYA,CAACC,MAAM,EAAE;MACpBX,MAAM,CAACY,MAAM,CAACD,MAAgB,CAAC;IAChC,CAAC;IACDE,GAAG,EAAEA,CAAA,KAAMf,KAAK;IAChBgB,OAAOA,CAACV,EAAE,EAAE;MACX,MAAMW,MAAM,GAAGjB,KAAK,GAAGM,EAAE;MACzB,SAAS;QACR,IAAIY,KAAyB;QAC7B,IAAIC,KAAK,GAAGC,QAAQ;QACpB,KAAK,MAAM,CAACb,EAAE,EAAEc,KAAK,CAAC,IAAInB,MAAM,EAAE;UACjC,IAAImB,KAAK,CAACZ,EAAE,IAAIQ,MAAM,IAAII,KAAK,CAACZ,EAAE,GAAGU,KAAK,EAAE;YAC3CD,KAAK,GAAGX,EAAE;YACVY,KAAK,GAAGE,KAAK,CAACZ,EAAE;UACjB;QACD;QACA,IAAIS,KAAK,KAAKI,SAAS,EAAE;QACzB,MAAMD,KAAK,GAAGnB,MAAM,CAACqB,GAAG,CAACL,KAAK,CAAC;QAC/BhB,MAAM,CAACY,MAAM,CAACI,KAAK,CAAC;QACpBlB,KAAK,GAAGmB,KAAK;QACbE,KAAK,EAAEhB,QAAQ,CAAC,CAAC;MAClB;MACAL,KAAK,GAAGiB,MAAM;IACf,CAAC;IACDO,OAAO,EAAEA,CAAA,KAAMtB,MAAM,CAACuB;EACvB,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * One diagnostic stream for every package (CORE-08).
5
+ *
6
+ * Each package keeps its own typed events (`AdEvent`, `PaymentEvent`...), and also
7
+ * reports what it observed as an `SdkDiagnostic` through a channel. An app installs
8
+ * one `DiagnosticSink` and receives every package's diagnostics in one shape, so
9
+ * wiring crash reporting or analytics is one adapter rather than ten.
10
+ *
11
+ * Sinks live in a registry anchored on `Symbol.for`, so a sink installed through
12
+ * one copy of rn-core also receives diagnostics from packages bundling another.
13
+ * Every context passes through a redactor before any sink sees it.
14
+ */
15
+
16
+ import { reportAsynchronously } from "../listeners/index.js";
17
+ import { createRedactor } from "../redact/index.js";
18
+ const REGISTRY = Symbol.for('chipmobilesdk.diagnosticSinks');
19
+ function sinks() {
20
+ const host = globalThis;
21
+ host[REGISTRY] ??= new Set();
22
+ return host[REGISTRY];
23
+ }
24
+
25
+ /**
26
+ * Sends every package's diagnostics to `sink` until the returned function is
27
+ * called. A sink that throws is reported on a fresh task and never affects the
28
+ * package that emitted.
29
+ */
30
+ export function installSdkSink(sink) {
31
+ const registry = sinks();
32
+ registry.add(sink);
33
+ let active = true;
34
+ return () => {
35
+ if (!active) return;
36
+ active = false;
37
+ registry.delete(sink);
38
+ };
39
+ }
40
+
41
+ /** Whether any sink is installed, for a package that would do extra work only to feed one. */
42
+ export function hasSdkSinks() {
43
+ return sinks().size > 0;
44
+ }
45
+ export function createDiagnosticChannel(pkg, options = {}) {
46
+ const redactor = options.redactor ?? createRedactor();
47
+ const now = options.now ?? Date.now;
48
+ return {
49
+ emit(code, severity, context, correlationId) {
50
+ const targets = options.sink ? [options.sink, ...sinks()] : [...sinks()];
51
+ if (targets.length === 0) return;
52
+ const redacted = redactor.context(context);
53
+ const diagnostic = {
54
+ pkg,
55
+ code,
56
+ severity,
57
+ at: now(),
58
+ ...(correlationId === undefined ? {} : {
59
+ correlationId
60
+ }),
61
+ ...(redacted === undefined ? {} : {
62
+ context: redacted
63
+ })
64
+ };
65
+ for (const sink of targets) {
66
+ try {
67
+ sink(diagnostic);
68
+ } catch (error) {
69
+ reportAsynchronously(error);
70
+ }
71
+ }
72
+ }
73
+ };
74
+ }
75
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["reportAsynchronously","createRedactor","REGISTRY","Symbol","for","sinks","host","globalThis","Set","installSdkSink","sink","registry","add","active","delete","hasSdkSinks","size","createDiagnosticChannel","pkg","options","redactor","now","Date","emit","code","severity","context","correlationId","targets","length","redacted","diagnostic","at","undefined","error"],"sourceRoot":"../../../src","sources":["diagnostics/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,oBAAoB,QAAQ,uBAAc;AACnD,SAASC,cAAc,QAAuB,oBAAW;AAoBzD,MAAMC,QAAQ,GAAGC,MAAM,CAACC,GAAG,CAAC,+BAA+B,CAAC;AAE5D,SAASC,KAAKA,CAAA,EAAwB;EACrC,MAAMC,IAAI,GAAGC,UAAkD;EAC/DD,IAAI,CAACJ,QAAQ,CAAC,KAAK,IAAIM,GAAG,CAAC,CAAC;EAC5B,OAAOF,IAAI,CAACJ,QAAQ,CAAC;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASO,cAAcA,CAACC,IAAoB,EAAe;EACjE,MAAMC,QAAQ,GAAGN,KAAK,CAAC,CAAC;EACxBM,QAAQ,CAACC,GAAG,CAACF,IAAI,CAAC;EAClB,IAAIG,MAAM,GAAG,IAAI;EACjB,OAAO,MAAM;IACZ,IAAI,CAACA,MAAM,EAAE;IACbA,MAAM,GAAG,KAAK;IACdF,QAAQ,CAACG,MAAM,CAACJ,IAAI,CAAC;EACtB,CAAC;AACF;;AAEA;AACA,OAAO,SAASK,WAAWA,CAAA,EAAY;EACtC,OAAOV,KAAK,CAAC,CAAC,CAACW,IAAI,GAAG,CAAC;AACxB;AAmBA,OAAO,SAASC,uBAAuBA,CACtCC,GAAW,EACXC,OAAiC,GAAG,CAAC,CAAC,EACZ;EAC1B,MAAMC,QAAQ,GAAGD,OAAO,CAACC,QAAQ,IAAInB,cAAc,CAAC,CAAC;EACrD,MAAMoB,GAAG,GAAGF,OAAO,CAACE,GAAG,IAAIC,IAAI,CAACD,GAAG;EAEnC,OAAO;IACNE,IAAIA,CAACC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,aAAa,EAAE;MAC5C,MAAMC,OAAO,GAAGT,OAAO,CAACT,IAAI,GAAG,CAACS,OAAO,CAACT,IAAI,EAAE,GAAGL,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAGA,KAAK,CAAC,CAAC,CAAC;MACxE,IAAIuB,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC1B,MAAMC,QAAQ,GAAGV,QAAQ,CAACM,OAAO,CAACA,OAAO,CAAC;MAC1C,MAAMK,UAA+B,GAAG;QACvCb,GAAG;QACHM,IAAI;QACJC,QAAQ;QACRO,EAAE,EAAEX,GAAG,CAAC,CAAC;QACT,IAAIM,aAAa,KAAKM,SAAS,GAAG,CAAC,CAAC,GAAG;UAAEN;QAAc,CAAC,CAAC;QACzD,IAAIG,QAAQ,KAAKG,SAAS,GAAG,CAAC,CAAC,GAAG;UAAEP,OAAO,EAAEI;QAAS,CAAC;MACxD,CAAC;MACD,KAAK,MAAMpB,IAAI,IAAIkB,OAAO,EAAE;QAC3B,IAAI;UACHlB,IAAI,CAACqB,UAAU,CAAC;QACjB,CAAC,CAAC,OAAOG,KAAK,EAAE;UACflC,oBAAoB,CAACkC,KAAK,CAAC;QAC5B;MACD;IACD;EACD,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * One error model for every @chipmobilesdk package (CORE-11).
5
+ *
6
+ * Each package keeps its own public error class and code union (`AdsError`,
7
+ * `PaymentError`...); those classes extend `SdkError`, so an app can handle any
8
+ * package's failure the same way: a code, whether retrying can help, and a cause
9
+ * that has already been through redaction.
10
+ *
11
+ * `isSdkError` checks a brand rather than `instanceof`, so it holds when an app
12
+ * ends up with two copies of this package (two versions in node_modules), which
13
+ * would make `instanceof SdkError` false for half its errors.
14
+ */
15
+
16
+ const BRAND = Symbol.for('chipmobilesdk.error');
17
+ export class SdkError extends Error {
18
+ /** The package that raised the error, e.g. `rn-ads`. */
19
+
20
+ constructor(pkg, code, options = {}) {
21
+ super(options.message ?? code);
22
+ this.name = 'SdkError';
23
+ this.pkg = pkg;
24
+ this.code = code;
25
+ this.retryable = options.retryable ?? false;
26
+ if (options.redactedCause !== undefined) {
27
+ this.redactedCause = options.redactedCause;
28
+ }
29
+ // Keeps subclasses' prototypes intact where Error subclassing is transpiled.
30
+ Object.setPrototypeOf(this, new.target.prototype);
31
+ }
32
+ }
33
+ Object.defineProperty(SdkError.prototype, BRAND, {
34
+ value: true
35
+ });
36
+
37
+ /** True for an error raised by any @chipmobilesdk package, from any copy of this one. */
38
+ export function isSdkError(value) {
39
+ return typeof value === 'object' && value !== null && value[BRAND] === true;
40
+ }
41
+ /**
42
+ * A package's closed code set and which of its codes are retryable, declared
43
+ * once instead of a union, an array and a `Set` kept in step by hand.
44
+ */
45
+ export function defineErrorCodes(codes, options = {}) {
46
+ const all = new Set(codes);
47
+ const retryable = new Set(options.retryable ?? []);
48
+ return {
49
+ codes: Object.freeze([...codes]),
50
+ is: value => typeof value === 'string' && all.has(value),
51
+ isRetryable: code => retryable.has(code)
52
+ };
53
+ }
54
+ /**
55
+ * Collects every problem in a config before throwing, so an app sees all of them
56
+ * at once rather than one per fix-and-restart cycle.
57
+ */
58
+ export function createIssueCollector() {
59
+ const issues = [];
60
+ return {
61
+ add(path, message) {
62
+ issues.push({
63
+ path,
64
+ message
65
+ });
66
+ },
67
+ get issues() {
68
+ return issues;
69
+ },
70
+ /** Throws what `toError` builds from the issues, when there are any. */
71
+ throwIfAny(toError) {
72
+ if (issues.length > 0) {
73
+ throw toError([...issues]);
74
+ }
75
+ }
76
+ };
77
+ }
78
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["BRAND","Symbol","for","SdkError","Error","constructor","pkg","code","options","message","name","retryable","redactedCause","undefined","Object","setPrototypeOf","new","target","prototype","defineProperty","value","isSdkError","defineErrorCodes","codes","all","Set","freeze","is","has","isRetryable","createIssueCollector","issues","add","path","push","throwIfAny","toError","length"],"sourceRoot":"../../../src","sources":["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C;EAC1D,OAAO;IACNY,KAAK,EAAET,MAAM,CAACY,MAAM,CAAC,CAAC,GAAGH,KAAK,CAAC,CAAC;IAChCI,EAAE,EAAGP,KAAc,IAAoB,OAAOA,KAAK,KAAK,QAAQ,IAAII,GAAG,CAACI,GAAG,CAACR,KAAK,CAAC;IAClFS,WAAW,EAAEtB,IAAI,IAAII,SAAS,CAACiB,GAAG,CAACrB,IAAI;EACxC,CAAC;AACF;AAQA;AACA;AACA;AACA;AACA,OAAO,SAASuB,oBAAoBA,CAAA,EAAG;EACtC,MAAMC,MAAqB,GAAG,EAAE;EAChC,OAAO;IACNC,GAAGA,CAACC,IAAY,EAAExB,OAAe,EAAQ;MACxCsB,MAAM,CAACG,IAAI,CAAC;QAAED,IAAI;QAAExB;MAAQ,CAAC,CAAC;IAC/B,CAAC;IACD,IAAIsB,MAAMA,CAAA,EAA2B;MACpC,OAAOA,MAAM;IACd,CAAC;IACD;IACAI,UAAUA,CAACC,OAAkD,EAAQ;MACpE,IAAIL,MAAM,CAACM,MAAM,GAAG,CAAC,EAAE;QACtB,MAAMD,OAAO,CAAC,CAAC,GAAGL,MAAM,CAAC,CAAC;MAC3B;IACD;EACD,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @chipmobilesdk/rn-core — the shared foundation of the @chipmobilesdk packages:
5
+ * one error model, one redaction mechanism, one way to notify listeners and one
6
+ * diagnostic stream, so every package behaves the same way. Pure TypeScript, no
7
+ * native code.
8
+ *
9
+ * Each module is also its own entrypoint (`@chipmobilesdk/rn-core/errors`,
10
+ * `/redact`, `/listeners`, `/diagnostics`); test helpers are only at
11
+ * `@chipmobilesdk/rn-core/testing`.
12
+ */
13
+ export { SdkError, createIssueCollector, defineErrorCodes, isSdkError } from "./errors/index.js";
14
+ export { COMMON_PATTERNS, PATH_PATTERN, REDACTED, createRedactor, describeShape, leadingIdentifier, pickAllowed, redactPatterns } from "./redact/index.js";
15
+ export { createEmitter, createListenerSet, reportAsynchronously } from "./listeners/index.js";
16
+ export { createDiagnosticChannel, hasSdkSinks, installSdkSink } from "./diagnostics/index.js";
17
+ export { checkInteger, checkRange, computeBackoff, createExclusive, createRateLimiter, createSingleFlight, createTimerSet, realScheduler, runWithRetry, withTimeout } from "./scheduler/index.js";
18
+ export { lazyPeer } from "./lazy/index.js";
19
+ export { createMemoryKeyValue, fromMmkvLike, namespaced, openDurable } from "./kv/index.js";
20
+ export { appLifecycle, byPlatform, createAppLifecycle, currentPlatform, isDevBuild, onForeground, setPlatformOverride } from "./runtime/index.js";
21
+ export { createStore, shallowEqual } from "./store/index.js";
22
+ export { clearIntlCaches, getDateTimeFormat, getNumberFormat, isValidTimeZone } from "./intl/index.js";
23
+ export { defineMessages, formatMessage } from "./messages/index.js";
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SdkError","createIssueCollector","defineErrorCodes","isSdkError","COMMON_PATTERNS","PATH_PATTERN","REDACTED","createRedactor","describeShape","leadingIdentifier","pickAllowed","redactPatterns","createEmitter","createListenerSet","reportAsynchronously","createDiagnosticChannel","hasSdkSinks","installSdkSink","checkInteger","checkRange","computeBackoff","createExclusive","createRateLimiter","createSingleFlight","createTimerSet","realScheduler","runWithRetry","withTimeout","lazyPeer","createMemoryKeyValue","fromMmkvLike","namespaced","openDurable","appLifecycle","byPlatform","createAppLifecycle","currentPlatform","isDevBuild","onForeground","setPlatformOverride","createStore","shallowEqual","clearIntlCaches","getDateTimeFormat","getNumberFormat","isValidTimeZone","defineMessages","formatMessage"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SACCA,QAAQ,EACRC,oBAAoB,EACpBC,gBAAgB,EAChBC,UAAU,QAIJ,mBAAU;AACjB,SACCC,eAAe,EACfC,YAAY,EACZC,QAAQ,EACRC,cAAc,EACdC,aAAa,EACbC,iBAAiB,EACjBC,WAAW,EACXC,cAAc,QAGR,mBAAU;AACjB,SACCC,aAAa,EACbC,iBAAiB,EACjBC,oBAAoB,QAOd,sBAAa;AACpB,SACCC,uBAAuB,EACvBC,WAAW,EACXC,cAAc,QAMR,wBAAe;AACtB,SACCC,YAAY,EACZC,UAAU,EACVC,cAAc,EACdC,eAAe,EACfC,iBAAiB,EACjBC,kBAAkB,EAClBC,cAAc,EACdC,aAAa,EACbC,YAAY,EACZC,WAAW,QAQL,sBAAa;AACpB,SAASC,QAAQ,QAAwC,iBAAQ;AACjE,SACCC,oBAAoB,EACpBC,YAAY,EACZC,UAAU,EACVC,WAAW,QAGL,eAAM;AACb,SACCC,YAAY,EACZC,UAAU,EACVC,kBAAkB,EAClBC,eAAe,EACfC,UAAU,EACVC,YAAY,EACZC,mBAAmB,QAMb,oBAAW;AAClB,SAASC,WAAW,EAAEC,YAAY,QAAoB,kBAAS;AAC/D,SAASC,eAAe,EAAEC,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,QAAQ,iBAAQ;AAC7F,SACCC,cAAc,EACdC,aAAa,QAMP,qBAAY","ignoreList":[]}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Cached `Intl` formatters (PERF-01, PERF-08, I18N-03, NOT-20).
5
+ *
6
+ * Constructing an `Intl.DateTimeFormat` or `Intl.NumberFormat` is expensive on
7
+ * Hermes, and rn-notification built one per time-zone calculation (thousands in a
8
+ * recurrence expansion) while rn-i18n built one per formatted value. Formatters
9
+ * are immutable once built, so one per (locale, options) is shared. Each cache is
10
+ * a small LRU: the working set is a few locales and zones, and an app that cycles
11
+ * through many still holds a bounded number.
12
+ */
13
+
14
+ const CAPACITY = 32;
15
+ function lru(capacity) {
16
+ const entries = new Map();
17
+ return {
18
+ get(key, create) {
19
+ const hit = entries.get(key);
20
+ if (hit !== undefined) {
21
+ // Re-insert to mark it most recently used.
22
+ entries.delete(key);
23
+ entries.set(key, hit);
24
+ return hit;
25
+ }
26
+ const value = create();
27
+ entries.set(key, value);
28
+ if (entries.size > capacity) {
29
+ const oldest = entries.keys().next().value;
30
+ if (oldest !== undefined) entries.delete(oldest);
31
+ }
32
+ return value;
33
+ },
34
+ clear: () => entries.clear(),
35
+ size: () => entries.size
36
+ };
37
+ }
38
+
39
+ /** A stable key for an options object: keys sorted, so `{a, b}` and `{b, a}` share. */
40
+ function keyOf(locale, options) {
41
+ if (!options) return `${locale ?? ''}|`;
42
+ const sorted = Object.keys(options).sort().map(key => `${key}=${String(options[key])}`);
43
+ return `${locale ?? ''}|${sorted.join(',')}`;
44
+ }
45
+ const numberFormats = lru(CAPACITY);
46
+ const dateTimeFormats = lru(CAPACITY);
47
+ const timeZones = new Map();
48
+ const TIME_ZONE_MEMO_LIMIT = 256;
49
+
50
+ /**
51
+ * A shared `Intl.NumberFormat`. Throws what the constructor throws (an unknown
52
+ * currency, say): callers decide how a bad option is reported.
53
+ */
54
+ export function getNumberFormat(locale, options) {
55
+ return numberFormats.get(keyOf(locale, options), () => new Intl.NumberFormat(locale, options));
56
+ }
57
+
58
+ /** A shared `Intl.DateTimeFormat`. Throws what the constructor throws. */
59
+ export function getDateTimeFormat(locale, options) {
60
+ return dateTimeFormats.get(keyOf(locale, options), () => new Intl.DateTimeFormat(locale, options));
61
+ }
62
+
63
+ /**
64
+ * Whether `Intl` accepts the IANA zone, memoized. Hermes raises a hard error for
65
+ * an unknown zone, so a stored zone is checked here before it reaches `Intl`.
66
+ */
67
+ export function isValidTimeZone(timeZone) {
68
+ if (timeZone.length === 0) return false;
69
+ const known = timeZones.get(timeZone);
70
+ if (known !== undefined) return known;
71
+ let valid;
72
+ try {
73
+ getDateTimeFormat('en-US', {
74
+ timeZone
75
+ }).format(0);
76
+ valid = true;
77
+ } catch {
78
+ valid = false;
79
+ }
80
+ if (timeZones.size >= TIME_ZONE_MEMO_LIMIT) timeZones.clear();
81
+ timeZones.set(timeZone, valid);
82
+ return valid;
83
+ }
84
+
85
+ /** Test seam: drops every cached formatter and zone check. */
86
+ export function clearIntlCaches() {
87
+ numberFormats.clear();
88
+ dateTimeFormats.clear();
89
+ timeZones.clear();
90
+ }
91
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CAPACITY","lru","capacity","entries","Map","get","key","create","hit","undefined","delete","set","value","size","oldest","keys","next","clear","keyOf","locale","options","sorted","Object","sort","map","String","join","numberFormats","dateTimeFormats","timeZones","TIME_ZONE_MEMO_LIMIT","getNumberFormat","Intl","NumberFormat","getDateTimeFormat","DateTimeFormat","isValidTimeZone","timeZone","length","known","valid","format","clearIntlCaches"],"sourceRoot":"../../../src","sources":["intl/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,QAAQ,GAAG,EAAE;AAEnB,SAASC,GAAGA,CAAIC,QAAgB,EAAE;EACjC,MAAMC,OAAO,GAAG,IAAIC,GAAG,CAAY,CAAC;EACpC,OAAO;IACNC,GAAGA,CAACC,GAAW,EAAEC,MAAe,EAAK;MACpC,MAAMC,GAAG,GAAGL,OAAO,CAACE,GAAG,CAACC,GAAG,CAAC;MAC5B,IAAIE,GAAG,KAAKC,SAAS,EAAE;QACtB;QACAN,OAAO,CAACO,MAAM,CAACJ,GAAG,CAAC;QACnBH,OAAO,CAACQ,GAAG,CAACL,GAAG,EAAEE,GAAG,CAAC;QACrB,OAAOA,GAAG;MACX;MACA,MAAMI,KAAK,GAAGL,MAAM,CAAC,CAAC;MACtBJ,OAAO,CAACQ,GAAG,CAACL,GAAG,EAAEM,KAAK,CAAC;MACvB,IAAIT,OAAO,CAACU,IAAI,GAAGX,QAAQ,EAAE;QAC5B,MAAMY,MAAM,GAAGX,OAAO,CAACY,IAAI,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,CAACJ,KAAK;QAC1C,IAAIE,MAAM,KAAKL,SAAS,EAAEN,OAAO,CAACO,MAAM,CAACI,MAAM,CAAC;MACjD;MACA,OAAOF,KAAK;IACb,CAAC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A;AACA;AACA;AACA,OAAO,SAASgB,eAAeA,CAACC,QAAgB,EAAW;EAC1D,IAAIA,QAAQ,CAACC,MAAM,KAAK,CAAC,EAAE,OAAO,KAAK;EACvC,MAAMC,KAAK,GAAGV,SAAS,CAACxB,GAAG,CAACgC,QAAQ,CAAC;EACrC,IAAIE,KAAK,KAAK9B,SAAS,EAAE,OAAO8B,KAAK;EACrC,IAAIC,KAAc;EAClB,IAAI;IACHN,iBAAiB,CAAC,OAAO,EAAE;MAAEG;IAAS,CAAC,CAAC,CAACI,MAAM,CAAC,CAAC,CAAC;IAClDD,KAAK,GAAG,IAAI;EACb,CAAC,CAAC,MAAM;IACPA,KAAK,GAAG,KAAK;EACd;EACA,IAAIX,SAAS,CAAChB,IAAI,IAAIiB,oBAAoB,EAAED,SAAS,CAACZ,KAAK,CAAC,CAAC;EAC7DY,SAAS,CAAClB,GAAG,CAAC0B,QAAQ,EAAEG,KAAK,CAAC;EAC9B,OAAOA,KAAK;AACb;;AAEA;AACA,OAAO,SAASE,eAAeA,CAAA,EAAS;EACvCf,aAAa,CAACV,KAAK,CAAC,CAAC;EACrBW,eAAe,CAACX,KAAK,CAAC,CAAC;EACvBY,SAAS,CAACZ,KAAK,CAAC,CAAC;AAClB","ignoreList":[]}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * A synchronous key-value port (DEP-09, NOT-15, PERF-09).
5
+ *
6
+ * rn-payment and rn-notification each wrapped MMKV themselves, and one of them
7
+ * fell back to memory without telling anyone. Here the port says whether it is
8
+ * `durable`, and `openDurable` reports the fallback through `onDegraded`, so a
9
+ * package can emit its own diagnostic instead of silently losing state.
10
+ *
11
+ * rn-core never requires a storage peer itself: the package opens MMKV (or any
12
+ * store with the same shape) and hands it over as an `MmkvLike`.
13
+ */
14
+
15
+ /** The slice of a react-native-mmkv v4 instance the port uses. */
16
+
17
+ export function createMemoryKeyValue() {
18
+ const map = new Map();
19
+ return {
20
+ getString: key => map.get(key),
21
+ set: (key, value) => {
22
+ map.set(key, value);
23
+ },
24
+ remove: key => {
25
+ map.delete(key);
26
+ },
27
+ keys: () => [...map.keys()],
28
+ clearAll: () => map.clear(),
29
+ durable: false
30
+ };
31
+ }
32
+ export function fromMmkvLike(store) {
33
+ return {
34
+ getString: key => store.getString(key),
35
+ set: (key, value) => store.set(key, value),
36
+ remove: key => {
37
+ store.remove(key);
38
+ },
39
+ keys: () => store.getAllKeys(),
40
+ clearAll: () => store.clearAll(),
41
+ durable: true
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Opens the durable store, or falls back to memory and says so: `onDegraded`
47
+ * receives the reason once, and the returned port reports `durable: false`.
48
+ */
49
+ export function openDurable(open, onDegraded) {
50
+ try {
51
+ return fromMmkvLike(open());
52
+ } catch (cause) {
53
+ onDegraded?.(cause);
54
+ return createMemoryKeyValue();
55
+ }
56
+ }
57
+
58
+ /** Keys under `prefix:` only, so several owners can share one store. */
59
+ export function namespaced(port, prefix) {
60
+ const scope = `${prefix}:`;
61
+ return {
62
+ getString: key => port.getString(scope + key),
63
+ set: (key, value) => port.set(scope + key, value),
64
+ remove: key => port.remove(scope + key),
65
+ keys: () => port.keys().filter(key => key.startsWith(scope)).map(key => key.slice(scope.length)),
66
+ clearAll: () => {
67
+ for (const key of port.keys()) {
68
+ if (key.startsWith(scope)) port.remove(key);
69
+ }
70
+ },
71
+ get durable() {
72
+ return port.durable;
73
+ }
74
+ };
75
+ }
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createMemoryKeyValue","map","Map","getString","key","get","set","value","remove","delete","keys","clearAll","clear","durable","fromMmkvLike","store","getAllKeys","openDurable","open","onDegraded","cause","namespaced","port","prefix","scope","filter","startsWith","slice","length"],"sourceRoot":"../../../src","sources":["kv/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA;;AASA,OAAO,SAASA,oBAAoBA,CAAA,EAAiB;EACpD,MAA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AoB,CAAC,CAAC;EAC9B;AACD;;AAEA;AACA,OAAO,SAASqB,UAAUA,CAACC,IAAkB,EAAEC,MAAc,EAAgB;EAC5E,MAAMC,KAAK,GAAG,GAAGD,MAAM,GAAG;EAC1B,OAAO;IACNpB,SAAS,EAAEC,GAAG,IAAIkB,IAAI,CAACnB,SAAS,CAACqB,KAAK,GAAGpB,GAAG,CAAC;IAC7CE,GAAG,EAAEA,CAACF,GAAG,EAAEG,KAAK,KAAKe,IAAI,CAAChB,GAAG,CAACkB,KAAK,GAAGpB,GAAG,EAAEG,KAAK,CAAC;IACjDC,MAAM,EAAEJ,GAAG,IAAIkB,IAAI,CAACd,MAAM,CAACgB,KAAK,GAAGpB,GAAG,CAAC;IACvCM,IAAI,EAAEA,CAAA,KACLY,IAAI,CACFZ,IAAI,CAAC,CAAC,CACNe,MAAM,CAACrB,GAAG,IAAIA,GAAG,CAACsB,UAAU,CAACF,KAAK,CAAC,CAAC,CACpCvB,GAAG,CAACG,GAAG,IAAIA,GAAG,CAACuB,KAAK,CAACH,KAAK,CAACI,MAAM,CAAC,CAAC;IACtCjB,QAAQ,EAAEA,CAAA,KAAM;MACf,KAAK,MAAMP,GAAG,IAAIkB,IAAI,CAACZ,IAAI,CAAC,CAAC,EAAE;QAC9B,IAAIN,GAAG,CAACsB,UAAU,CAACF,KAAK,CAAC,EAAEF,IAAI,CAACd,MAAM,CAACJ,GAAG,CAAC;MAC5C;IACD,CAAC;IACD,IAAIS,OAAOA,CAAA,EAAG;MACb,OAAOS,IAAI,CAACT,OAAO;IACpB;EACD,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Lazy native peers (CORE-06).
5
+ *
6
+ * Every package loads its native peer on first use, so importing a package where
7
+ * the peer is absent (an unsupported platform, a build that excludes it) costs
8
+ * nothing and crashes nothing. There were 18 hand-written `require()` sites with
9
+ * four different failure policies, some silent. Here, one: the load runs once,
10
+ * its result (module or failure) is cached, and a missing peer is a typed result
11
+ * the package maps to its own error code.
12
+ *
13
+ * The `load` thunk must contain the literal `require('peer-name')` and live in the
14
+ * package that depends on the peer, so Metro sees and bundles it there.
15
+ */
16
+
17
+ export function lazyPeer(name, load) {
18
+ let cached;
19
+ let forced;
20
+ function get() {
21
+ if (forced) return forced;
22
+ if (!cached) {
23
+ try {
24
+ cached = {
25
+ ok: true,
26
+ module: load()
27
+ };
28
+ } catch (cause) {
29
+ cached = {
30
+ ok: false,
31
+ peer: name,
32
+ cause
33
+ };
34
+ }
35
+ }
36
+ return cached;
37
+ }
38
+ return {
39
+ name,
40
+ get,
41
+ require(fail) {
42
+ const result = get();
43
+ if (result.ok) return result.module;
44
+ throw fail(result.peer, result.cause);
45
+ },
46
+ isAvailable: () => get().ok,
47
+ override(fake) {
48
+ forced = fake === undefined ? undefined : fake === null ? {
49
+ ok: false,
50
+ peer: name,
51
+ cause: new Error(`${name} is overridden as absent`)
52
+ } : {
53
+ ok: true,
54
+ module: fake
55
+ };
56
+ }
57
+ };
58
+ }
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["lazyPeer","name","load","cached","forced","get","ok","module","cause","peer","require","fail","result","isAvailable","override","fake","undefined","Error"],"sourceRoot":"../../../src","sources":["lazy/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAoBA,OAAO,SAASA,QAAQA,CAAIC,IAAY,EAAEC,IAAa,EAAe;EACrE,IAAIC,MAAiC;EACrC,IAAIC,MAAiC;EAErC,SAASC,GAAGA,CAAA,EAAkB;IAC7B,IAAID,MAAM,EAAE,OAAOA,MAAM;IACzB,IAAI,CAACD,MAAM,EAAE;MACZ,IAAI;QACHA,MAAM,GAAG;UAAEG,EAAE,EAAE,IAAI;UAAEC,MAAM,EAAEL,IAAI,CAAC;QAAE,CAAC;MACtC,CAAC,CAAC,OAAOM,KAAK,EAAE;QACfL,MAAM,GAAG;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