@chipmobilesdk/rn-core 0.1.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.
- package/CHANGELOG.md +64 -0
- package/lib/commonjs/diagnostics/index.js +81 -0
- package/lib/commonjs/diagnostics/index.js.map +1 -0
- package/lib/commonjs/errors/index.js +86 -0
- package/lib/commonjs/errors/index.js.map +1 -0
- package/lib/commonjs/index.js +305 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/intl/index.js +98 -0
- package/lib/commonjs/intl/index.js.map +1 -0
- package/lib/commonjs/kv/index.js +83 -0
- package/lib/commonjs/kv/index.js.map +1 -0
- package/lib/commonjs/lazy/index.js +63 -0
- package/lib/commonjs/lazy/index.js.map +1 -0
- package/lib/commonjs/listeners/index.js +110 -0
- package/lib/commonjs/listeners/index.js.map +1 -0
- package/lib/commonjs/messages/index.js +53 -0
- package/lib/commonjs/messages/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/react/index.js +93 -0
- package/lib/commonjs/react/index.js.map +1 -0
- package/lib/commonjs/redact/index.js +128 -0
- package/lib/commonjs/redact/index.js.map +1 -0
- package/lib/commonjs/runtime/index.js +77 -0
- package/lib/commonjs/runtime/index.js.map +1 -0
- package/lib/commonjs/runtime/lifecycle.js +105 -0
- package/lib/commonjs/runtime/lifecycle.js.map +1 -0
- package/lib/commonjs/scheduler/index.js +216 -0
- package/lib/commonjs/scheduler/index.js.map +1 -0
- package/lib/commonjs/store/index.js +39 -0
- package/lib/commonjs/store/index.js.map +1 -0
- package/lib/commonjs/testing/conformance.js +79 -0
- package/lib/commonjs/testing/conformance.js.map +1 -0
- package/lib/commonjs/testing/index.js +58 -0
- package/lib/commonjs/testing/index.js.map +1 -0
- package/lib/commonjs/testing/lifecycle.js +37 -0
- package/lib/commonjs/testing/lifecycle.js.map +1 -0
- package/lib/commonjs/testing/redaction.js +118 -0
- package/lib/commonjs/testing/redaction.js.map +1 -0
- package/lib/commonjs/testing/scheduler.js +51 -0
- package/lib/commonjs/testing/scheduler.js.map +1 -0
- package/lib/module/diagnostics/index.js +75 -0
- package/lib/module/diagnostics/index.js.map +1 -0
- package/lib/module/errors/index.js +78 -0
- package/lib/module/errors/index.js.map +1 -0
- package/lib/module/index.js +24 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/intl/index.js +91 -0
- package/lib/module/intl/index.js.map +1 -0
- package/lib/module/kv/index.js +76 -0
- package/lib/module/kv/index.js.map +1 -0
- package/lib/module/lazy/index.js +59 -0
- package/lib/module/lazy/index.js.map +1 -0
- package/lib/module/listeners/index.js +104 -0
- package/lib/module/listeners/index.js.map +1 -0
- package/lib/module/messages/index.js +48 -0
- package/lib/module/messages/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/react/index.js +86 -0
- package/lib/module/react/index.js.map +1 -0
- package/lib/module/redact/index.js +118 -0
- package/lib/module/redact/index.js.map +1 -0
- package/lib/module/runtime/index.js +52 -0
- package/lib/module/runtime/index.js.map +1 -0
- package/lib/module/runtime/lifecycle.js +99 -0
- package/lib/module/runtime/lifecycle.js.map +1 -0
- package/lib/module/scheduler/index.js +203 -0
- package/lib/module/scheduler/index.js.map +1 -0
- package/lib/module/store/index.js +33 -0
- package/lib/module/store/index.js.map +1 -0
- package/lib/module/testing/conformance.js +72 -0
- package/lib/module/testing/conformance.js.map +1 -0
- package/lib/module/testing/index.js +12 -0
- package/lib/module/testing/index.js.map +1 -0
- package/lib/module/testing/lifecycle.js +32 -0
- package/lib/module/testing/lifecycle.js.map +1 -0
- package/lib/module/testing/redaction.js +113 -0
- package/lib/module/testing/redaction.js.map +1 -0
- package/lib/module/testing/scheduler.js +47 -0
- package/lib/module/testing/scheduler.js.map +1 -0
- package/lib/typescript/commonjs/diagnostics/index.d.ts +49 -0
- package/lib/typescript/commonjs/diagnostics/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/errors/index.d.ts +59 -0
- package/lib/typescript/commonjs/errors/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +22 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/intl/index.d.ts +25 -0
- package/lib/typescript/commonjs/intl/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/kv/index.d.ts +38 -0
- package/lib/typescript/commonjs/kv/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/lazy/index.d.ts +36 -0
- package/lib/typescript/commonjs/lazy/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/listeners/index.d.ts +61 -0
- package/lib/typescript/commonjs/listeners/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/messages/index.d.ts +39 -0
- package/lib/typescript/commonjs/messages/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/react/index.d.ts +38 -0
- package/lib/typescript/commonjs/react/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/redact/index.d.ts +47 -0
- package/lib/typescript/commonjs/redact/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/runtime/index.d.ts +21 -0
- package/lib/typescript/commonjs/runtime/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/runtime/lifecycle.d.ts +34 -0
- package/lib/typescript/commonjs/runtime/lifecycle.d.ts.map +1 -0
- package/lib/typescript/commonjs/scheduler/index.d.ts +108 -0
- package/lib/typescript/commonjs/scheduler/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/store/index.d.ts +18 -0
- package/lib/typescript/commonjs/store/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts +35 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/index.d.ts +10 -0
- package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/lifecycle.d.ts +15 -0
- package/lib/typescript/commonjs/testing/lifecycle.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/redaction.d.ts +35 -0
- package/lib/typescript/commonjs/testing/redaction.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/scheduler.d.ts +15 -0
- package/lib/typescript/commonjs/testing/scheduler.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/index.d.ts +49 -0
- package/lib/typescript/module/diagnostics/index.d.ts.map +1 -0
- package/lib/typescript/module/errors/index.d.ts +59 -0
- package/lib/typescript/module/errors/index.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +22 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/intl/index.d.ts +25 -0
- package/lib/typescript/module/intl/index.d.ts.map +1 -0
- package/lib/typescript/module/kv/index.d.ts +38 -0
- package/lib/typescript/module/kv/index.d.ts.map +1 -0
- package/lib/typescript/module/lazy/index.d.ts +36 -0
- package/lib/typescript/module/lazy/index.d.ts.map +1 -0
- package/lib/typescript/module/listeners/index.d.ts +61 -0
- package/lib/typescript/module/listeners/index.d.ts.map +1 -0
- package/lib/typescript/module/messages/index.d.ts +39 -0
- package/lib/typescript/module/messages/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/react/index.d.ts +38 -0
- package/lib/typescript/module/react/index.d.ts.map +1 -0
- package/lib/typescript/module/redact/index.d.ts +47 -0
- package/lib/typescript/module/redact/index.d.ts.map +1 -0
- package/lib/typescript/module/runtime/index.d.ts +21 -0
- package/lib/typescript/module/runtime/index.d.ts.map +1 -0
- package/lib/typescript/module/runtime/lifecycle.d.ts +34 -0
- package/lib/typescript/module/runtime/lifecycle.d.ts.map +1 -0
- package/lib/typescript/module/scheduler/index.d.ts +108 -0
- package/lib/typescript/module/scheduler/index.d.ts.map +1 -0
- package/lib/typescript/module/store/index.d.ts +18 -0
- package/lib/typescript/module/store/index.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance.d.ts +35 -0
- package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/module/testing/index.d.ts +10 -0
- package/lib/typescript/module/testing/index.d.ts.map +1 -0
- package/lib/typescript/module/testing/lifecycle.d.ts +15 -0
- package/lib/typescript/module/testing/lifecycle.d.ts.map +1 -0
- package/lib/typescript/module/testing/redaction.d.ts +35 -0
- package/lib/typescript/module/testing/redaction.d.ts.map +1 -0
- package/lib/typescript/module/testing/scheduler.d.ts +15 -0
- package/lib/typescript/module/testing/scheduler.d.ts.map +1 -0
- package/package.json +154 -46
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,69 @@
|
|
|
1
1
|
# @chipmobilesdk/rn-core
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Every package now ships built JavaScript with declaration files, instead of asking the
|
|
8
|
+
app to compile its TypeScript. ([#22](https://github.com/operationd8979/chip-mobile-sdk/pull/22))
|
|
9
|
+
|
|
10
|
+
Each tarball carries `lib/commonjs`, `lib/module` and `lib/typescript` (built with
|
|
11
|
+
`react-native-builder-bob`), and `src/` alongside them. What that changes for a
|
|
12
|
+
consumer:
|
|
13
|
+
|
|
14
|
+
- **Nothing to add to `transformIgnorePatterns`.** `require` resolves to the CommonJS
|
|
15
|
+
build, so an app's Jest loads this package without being told to transform it. That
|
|
16
|
+
was the one thing every consuming app had to know about us (DEP-04).
|
|
17
|
+
- **Typechecking reads our `.d.ts`** rather than compiling our source under our
|
|
18
|
+
`tsconfig`. A consumer's stricter — or looser — settings no longer meet our code.
|
|
19
|
+
- **`import` resolves to ESM**, so a bundler can tree-shake what it does not use.
|
|
20
|
+
|
|
21
|
+
No exported name changed, and no subpath moved: `.`, `./testing`, `./push`,
|
|
22
|
+
`./advanced`, `./app-auth`, `./keychain` and rn-core's twelve subpaths resolve exactly
|
|
23
|
+
as before, each now with its own declarations for both module systems. publint and
|
|
24
|
+
`attw --profile node16` pass on all twelve packages, which they could not before.
|
|
25
|
+
|
|
26
|
+
Inside the monorepo nothing changed either, and that is deliberate: every subpath also
|
|
27
|
+
declares a private `chipmobilesdk-source` condition pointing at its TypeScript, and
|
|
28
|
+
Metro, Jest and `tsc` here ask for that condition first. The demo app bundles 371
|
|
29
|
+
modules straight from `packages/*/src`, so editing a package still changes the app with
|
|
30
|
+
no build step, and coverage is still measured on the source. The condition is named for
|
|
31
|
+
this organization rather than using the conventional `source` because third-party
|
|
32
|
+
packages declare that one too — `@dr.pogodin/react-native-fs` does — and asking for it
|
|
33
|
+
pulled their sources into our stricter compile.
|
|
34
|
+
|
|
35
|
+
`npm run build:packages` builds everything, `prepack` rebuilds before any `npm pack`,
|
|
36
|
+
and `lib/` is git-ignored: the published bytes are produced by the release, never
|
|
37
|
+
committed. `npm run check:manifests` now fails a package whose `main`, `module`,
|
|
38
|
+
`types`, `source` condition, `files`, build script or `prepack` do not match this shape.
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- Each package's public API and its weight are now recorded in the repository, so a change
|
|
43
|
+
to either is reviewed rather than discovered. ([#23](https://github.com/operationd8979/chip-mobile-sdk/pull/23))
|
|
44
|
+
|
|
45
|
+
`packages/<pkg>/etc/*.api.md` is an api-extractor report per entrypoint — twenty-seven
|
|
46
|
+
of them, generated from the declarations the package publishes and committed. A renamed
|
|
47
|
+
type, a widened union, one more optional field: all of it shows up in a pull request's
|
|
48
|
+
diff. `npm run check:api` fails when a report is out of date and `npm run api:update`
|
|
49
|
+
rewrites them.
|
|
50
|
+
|
|
51
|
+
A report that moves now needs a **minor or major** changeset for that package.
|
|
52
|
+
`check:changesets` enforces it, because the report is generated from what the package
|
|
53
|
+
publishes, and a patch release that moves the public surface is how a consumer's build
|
|
54
|
+
breaks on `npm update`. A report added for the first time is a baseline, not a change.
|
|
55
|
+
`./testing` deliberately has no report: test doubles are not a surface a release is
|
|
56
|
+
gated on.
|
|
57
|
+
|
|
58
|
+
`npm run check:size` holds every entrypoint to a budget in `.size-limit.json`, measured
|
|
59
|
+
on the ESM build with peers and rn-core treated as external — they are what an app
|
|
60
|
+
installs beside us, not our weight. Each budget started at today's measurement plus five
|
|
61
|
+
per cent, so growth becomes a decision someone makes instead of a drift nobody sees. The
|
|
62
|
+
current figures run from 500 B (`rn-core/lazy`) to 19 kB (rn-notification).
|
|
63
|
+
|
|
64
|
+
No behaviour or API changed in this release; the entry is here so the changelog records
|
|
65
|
+
when the reports and the budgets began.
|
|
66
|
+
|
|
3
67
|
## 0.1.0
|
|
4
68
|
|
|
5
69
|
### Minor Changes
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createDiagnosticChannel = createDiagnosticChannel;
|
|
7
|
+
exports.hasSdkSinks = hasSdkSinks;
|
|
8
|
+
exports.installSdkSink = installSdkSink;
|
|
9
|
+
var _index = require("../listeners/index.js");
|
|
10
|
+
var _index2 = require("../redact/index.js");
|
|
11
|
+
/**
|
|
12
|
+
* One diagnostic stream for every package (CORE-08).
|
|
13
|
+
*
|
|
14
|
+
* Each package keeps its own typed events (`AdEvent`, `PaymentEvent`...), and also
|
|
15
|
+
* reports what it observed as an `SdkDiagnostic` through a channel. An app installs
|
|
16
|
+
* one `DiagnosticSink` and receives every package's diagnostics in one shape, so
|
|
17
|
+
* wiring crash reporting or analytics is one adapter rather than ten.
|
|
18
|
+
*
|
|
19
|
+
* Sinks live in a registry anchored on `Symbol.for`, so a sink installed through
|
|
20
|
+
* one copy of rn-core also receives diagnostics from packages bundling another.
|
|
21
|
+
* Every context passes through a redactor before any sink sees it.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const REGISTRY = Symbol.for('chipmobilesdk.diagnosticSinks');
|
|
25
|
+
function sinks() {
|
|
26
|
+
const host = globalThis;
|
|
27
|
+
host[REGISTRY] ??= new Set();
|
|
28
|
+
return host[REGISTRY];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Sends every package's diagnostics to `sink` until the returned function is
|
|
33
|
+
* called. A sink that throws is reported on a fresh task and never affects the
|
|
34
|
+
* package that emitted.
|
|
35
|
+
*/
|
|
36
|
+
function installSdkSink(sink) {
|
|
37
|
+
const registry = sinks();
|
|
38
|
+
registry.add(sink);
|
|
39
|
+
let active = true;
|
|
40
|
+
return () => {
|
|
41
|
+
if (!active) return;
|
|
42
|
+
active = false;
|
|
43
|
+
registry.delete(sink);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Whether any sink is installed, for a package that would do extra work only to feed one. */
|
|
48
|
+
function hasSdkSinks() {
|
|
49
|
+
return sinks().size > 0;
|
|
50
|
+
}
|
|
51
|
+
function createDiagnosticChannel(pkg, options = {}) {
|
|
52
|
+
const redactor = options.redactor ?? (0, _index2.createRedactor)();
|
|
53
|
+
const now = options.now ?? Date.now;
|
|
54
|
+
return {
|
|
55
|
+
emit(code, severity, context, correlationId) {
|
|
56
|
+
const targets = options.sink ? [options.sink, ...sinks()] : [...sinks()];
|
|
57
|
+
if (targets.length === 0) return;
|
|
58
|
+
const redacted = redactor.context(context);
|
|
59
|
+
const diagnostic = {
|
|
60
|
+
pkg,
|
|
61
|
+
code,
|
|
62
|
+
severity,
|
|
63
|
+
at: now(),
|
|
64
|
+
...(correlationId === undefined ? {} : {
|
|
65
|
+
correlationId
|
|
66
|
+
}),
|
|
67
|
+
...(redacted === undefined ? {} : {
|
|
68
|
+
context: redacted
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
for (const sink of targets) {
|
|
72
|
+
try {
|
|
73
|
+
sink(diagnostic);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
(0, _index.reportAsynchronously)(error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_index","require","_index2","REGISTRY","Symbol","for","sinks","host","globalThis","Set","installSdkSink","sink","registry","add","active","delete","hasSdkSinks","size","createDiagnosticChannel","pkg","options","redactor","createRedactor","now","Date","emit","code","severity","context","correlationId","targets","length","redacted","diagnostic","at","undefined","error","reportAsynchronously"],"sourceRoot":"../../../src","sources":["diagnostics/index.ts"],"mappings":";;;;;;;;AAaA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAuBA,MAAME,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;AACO,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;AACO,SAASK,WAAWA,CAAA,EAAY;EACtC,OAAOV,KAAK,CAAC,CAAC,CAACW,IAAI,GAAG,CAAC;AACxB;AAmBO,SAASC,uBAAuBA,CACtCC,GAAW,EACXC,OAAiC,GAAG,CAAC,CAAC,EACZ;EAC1B,MAAMC,QAAQ,GAAGD,OAAO,CAACC,QAAQ,IAAI,IAAAC,sBAAc,EAAC,CAAC;EACrD,MAAMC,GAAG,GAAGH,OAAO,CAACG,GAAG,IAAIC,IAAI,CAACD,GAAG;EAEnC,OAAO;IACNE,IAAIA,CAACC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,aAAa,EAAE;MAC5C,MAAMC,OAAO,GAAGV,OAAO,CAACT,IAAI,GAAG,CAACS,OAAO,CAACT,IAAI,EAAE,GAAGL,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAGA,KAAK,CAAC,CAAC,CAAC;MACxE,IAAIwB,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC1B,MAAMC,QAAQ,GAAGX,QAAQ,CAACO,OAAO,CAACA,OAAO,CAAC;MAC1C,MAAMK,UAA+B,GAAG;QACvCd,GAAG;QACHO,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,MAAMrB,IAAI,IAAImB,OAAO,EAAE;QAC3B,IAAI;UACHnB,IAAI,CAACsB,UAAU,CAAC;QACjB,CAAC,CAAC,OAAOG,KAAK,EAAE;UACf,IAAAC,2BAAoB,EAACD,KAAK,CAAC;QAC5B;MACD;IACD;EACD,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SdkError = void 0;
|
|
7
|
+
exports.createIssueCollector = createIssueCollector;
|
|
8
|
+
exports.defineErrorCodes = defineErrorCodes;
|
|
9
|
+
exports.isSdkError = isSdkError;
|
|
10
|
+
/**
|
|
11
|
+
* One error model for every @chipmobilesdk package (CORE-11).
|
|
12
|
+
*
|
|
13
|
+
* Each package keeps its own public error class and code union (`AdsError`,
|
|
14
|
+
* `PaymentError`...); those classes extend `SdkError`, so an app can handle any
|
|
15
|
+
* package's failure the same way: a code, whether retrying can help, and a cause
|
|
16
|
+
* that has already been through redaction.
|
|
17
|
+
*
|
|
18
|
+
* `isSdkError` checks a brand rather than `instanceof`, so it holds when an app
|
|
19
|
+
* ends up with two copies of this package (two versions in node_modules), which
|
|
20
|
+
* would make `instanceof SdkError` false for half its errors.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const BRAND = Symbol.for('chipmobilesdk.error');
|
|
24
|
+
class SdkError extends Error {
|
|
25
|
+
/** The package that raised the error, e.g. `rn-ads`. */
|
|
26
|
+
|
|
27
|
+
constructor(pkg, code, options = {}) {
|
|
28
|
+
super(options.message ?? code);
|
|
29
|
+
this.name = 'SdkError';
|
|
30
|
+
this.pkg = pkg;
|
|
31
|
+
this.code = code;
|
|
32
|
+
this.retryable = options.retryable ?? false;
|
|
33
|
+
if (options.redactedCause !== undefined) {
|
|
34
|
+
this.redactedCause = options.redactedCause;
|
|
35
|
+
}
|
|
36
|
+
// Keeps subclasses' prototypes intact where Error subclassing is transpiled.
|
|
37
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.SdkError = SdkError;
|
|
41
|
+
Object.defineProperty(SdkError.prototype, BRAND, {
|
|
42
|
+
value: true
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/** True for an error raised by any @chipmobilesdk package, from any copy of this one. */
|
|
46
|
+
function isSdkError(value) {
|
|
47
|
+
return typeof value === 'object' && value !== null && value[BRAND] === true;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A package's closed code set and which of its codes are retryable, declared
|
|
51
|
+
* once instead of a union, an array and a `Set` kept in step by hand.
|
|
52
|
+
*/
|
|
53
|
+
function defineErrorCodes(codes, options = {}) {
|
|
54
|
+
const all = new Set(codes);
|
|
55
|
+
const retryable = new Set(options.retryable ?? []);
|
|
56
|
+
return {
|
|
57
|
+
codes: Object.freeze([...codes]),
|
|
58
|
+
is: value => typeof value === 'string' && all.has(value),
|
|
59
|
+
isRetryable: code => retryable.has(code)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Collects every problem in a config before throwing, so an app sees all of them
|
|
64
|
+
* at once rather than one per fix-and-restart cycle.
|
|
65
|
+
*/
|
|
66
|
+
function createIssueCollector() {
|
|
67
|
+
const issues = [];
|
|
68
|
+
return {
|
|
69
|
+
add(path, message) {
|
|
70
|
+
issues.push({
|
|
71
|
+
path,
|
|
72
|
+
message
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
get issues() {
|
|
76
|
+
return issues;
|
|
77
|
+
},
|
|
78
|
+
/** Throws what `toError` builds from the issues, when there are any. */
|
|
79
|
+
throwIfAny(toError) {
|
|
80
|
+
if (issues.length > 0) {
|
|
81
|
+
throw toError([...issues]);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# 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","exports","defineProperty","value","isSdkError","defineErrorCodes","codes","all","Set","freeze","is","has","isRetryable","createIssueCollector","issues","add","path","push","throwIfAny","toError","length"],"sourceRoot":"../../../src","sources":["errors/index.ts"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,KAAK,GAAGC,MAAM,CAACC,GAAG,CAAC,qBAAqB,CAAC;AAWxC,MAAMC,QAAQ,SAAuCC,KAAK,CAAC;EACjE;;EAMAC,WAAWA,CAACC,GAAW,EAAEC,IAAU,EAAEC,OAAwB,GAAG,CAAC,CAAC,EAAE;IACnE,KAAK,CAACA,OAAO,CAACC,OAAO,IAAIF,IAAI,CAAC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B,oBAAoBA,CAAA,EAAG;EACtC,MAAMC,MAAqB,GAAG,EAAE;EAChC,OAAO;IACNC,GAAGA,CAACC,IAAY,EAAEzB,OAAe,EAAQ;MACxCuB,MAAM,CAACG,IAAI,CAAC;QAAED,IAAI;QAAEzB;MAAQ,CAAC,CAAC;IAC/B,CAAC;IACD,IAAIuB,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,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "COMMON_PATTERNS", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _index2.COMMON_PATTERNS;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "PATH_PATTERN", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _index2.PATH_PATTERN;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "REDACTED", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _index2.REDACTED;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "SdkError", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _index.SdkError;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "appLifecycle", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _index8.appLifecycle;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "byPlatform", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _index8.byPlatform;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "checkInteger", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _index5.checkInteger;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "checkRange", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _index5.checkRange;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "clearIntlCaches", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _index0.clearIntlCaches;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "computeBackoff", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _index5.computeBackoff;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "createAppLifecycle", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _index8.createAppLifecycle;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "createDiagnosticChannel", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _index4.createDiagnosticChannel;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "createEmitter", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _index3.createEmitter;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "createExclusive", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _index5.createExclusive;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(exports, "createIssueCollector", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function () {
|
|
93
|
+
return _index.createIssueCollector;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(exports, "createListenerSet", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: function () {
|
|
99
|
+
return _index3.createListenerSet;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
Object.defineProperty(exports, "createMemoryKeyValue", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
get: function () {
|
|
105
|
+
return _index7.createMemoryKeyValue;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
Object.defineProperty(exports, "createRateLimiter", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get: function () {
|
|
111
|
+
return _index5.createRateLimiter;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(exports, "createRedactor", {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
get: function () {
|
|
117
|
+
return _index2.createRedactor;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
Object.defineProperty(exports, "createSingleFlight", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function () {
|
|
123
|
+
return _index5.createSingleFlight;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperty(exports, "createStore", {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
get: function () {
|
|
129
|
+
return _index9.createStore;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
Object.defineProperty(exports, "createTimerSet", {
|
|
133
|
+
enumerable: true,
|
|
134
|
+
get: function () {
|
|
135
|
+
return _index5.createTimerSet;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
Object.defineProperty(exports, "currentPlatform", {
|
|
139
|
+
enumerable: true,
|
|
140
|
+
get: function () {
|
|
141
|
+
return _index8.currentPlatform;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
Object.defineProperty(exports, "defineErrorCodes", {
|
|
145
|
+
enumerable: true,
|
|
146
|
+
get: function () {
|
|
147
|
+
return _index.defineErrorCodes;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
Object.defineProperty(exports, "defineMessages", {
|
|
151
|
+
enumerable: true,
|
|
152
|
+
get: function () {
|
|
153
|
+
return _index1.defineMessages;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
Object.defineProperty(exports, "describeShape", {
|
|
157
|
+
enumerable: true,
|
|
158
|
+
get: function () {
|
|
159
|
+
return _index2.describeShape;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
Object.defineProperty(exports, "formatMessage", {
|
|
163
|
+
enumerable: true,
|
|
164
|
+
get: function () {
|
|
165
|
+
return _index1.formatMessage;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty(exports, "fromMmkvLike", {
|
|
169
|
+
enumerable: true,
|
|
170
|
+
get: function () {
|
|
171
|
+
return _index7.fromMmkvLike;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
Object.defineProperty(exports, "getDateTimeFormat", {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get: function () {
|
|
177
|
+
return _index0.getDateTimeFormat;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
Object.defineProperty(exports, "getNumberFormat", {
|
|
181
|
+
enumerable: true,
|
|
182
|
+
get: function () {
|
|
183
|
+
return _index0.getNumberFormat;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(exports, "hasSdkSinks", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function () {
|
|
189
|
+
return _index4.hasSdkSinks;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
Object.defineProperty(exports, "installSdkSink", {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function () {
|
|
195
|
+
return _index4.installSdkSink;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
Object.defineProperty(exports, "isDevBuild", {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
get: function () {
|
|
201
|
+
return _index8.isDevBuild;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
Object.defineProperty(exports, "isSdkError", {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
get: function () {
|
|
207
|
+
return _index.isSdkError;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
Object.defineProperty(exports, "isValidTimeZone", {
|
|
211
|
+
enumerable: true,
|
|
212
|
+
get: function () {
|
|
213
|
+
return _index0.isValidTimeZone;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
Object.defineProperty(exports, "lazyPeer", {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
get: function () {
|
|
219
|
+
return _index6.lazyPeer;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
Object.defineProperty(exports, "leadingIdentifier", {
|
|
223
|
+
enumerable: true,
|
|
224
|
+
get: function () {
|
|
225
|
+
return _index2.leadingIdentifier;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
Object.defineProperty(exports, "namespaced", {
|
|
229
|
+
enumerable: true,
|
|
230
|
+
get: function () {
|
|
231
|
+
return _index7.namespaced;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
Object.defineProperty(exports, "onForeground", {
|
|
235
|
+
enumerable: true,
|
|
236
|
+
get: function () {
|
|
237
|
+
return _index8.onForeground;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
Object.defineProperty(exports, "openDurable", {
|
|
241
|
+
enumerable: true,
|
|
242
|
+
get: function () {
|
|
243
|
+
return _index7.openDurable;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
Object.defineProperty(exports, "pickAllowed", {
|
|
247
|
+
enumerable: true,
|
|
248
|
+
get: function () {
|
|
249
|
+
return _index2.pickAllowed;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
Object.defineProperty(exports, "realScheduler", {
|
|
253
|
+
enumerable: true,
|
|
254
|
+
get: function () {
|
|
255
|
+
return _index5.realScheduler;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
Object.defineProperty(exports, "redactPatterns", {
|
|
259
|
+
enumerable: true,
|
|
260
|
+
get: function () {
|
|
261
|
+
return _index2.redactPatterns;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
Object.defineProperty(exports, "reportAsynchronously", {
|
|
265
|
+
enumerable: true,
|
|
266
|
+
get: function () {
|
|
267
|
+
return _index3.reportAsynchronously;
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
Object.defineProperty(exports, "runWithRetry", {
|
|
271
|
+
enumerable: true,
|
|
272
|
+
get: function () {
|
|
273
|
+
return _index5.runWithRetry;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
Object.defineProperty(exports, "setPlatformOverride", {
|
|
277
|
+
enumerable: true,
|
|
278
|
+
get: function () {
|
|
279
|
+
return _index8.setPlatformOverride;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
Object.defineProperty(exports, "shallowEqual", {
|
|
283
|
+
enumerable: true,
|
|
284
|
+
get: function () {
|
|
285
|
+
return _index9.shallowEqual;
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
Object.defineProperty(exports, "withTimeout", {
|
|
289
|
+
enumerable: true,
|
|
290
|
+
get: function () {
|
|
291
|
+
return _index5.withTimeout;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
var _index = require("./errors/index.js");
|
|
295
|
+
var _index2 = require("./redact/index.js");
|
|
296
|
+
var _index3 = require("./listeners/index.js");
|
|
297
|
+
var _index4 = require("./diagnostics/index.js");
|
|
298
|
+
var _index5 = require("./scheduler/index.js");
|
|
299
|
+
var _index6 = require("./lazy/index.js");
|
|
300
|
+
var _index7 = require("./kv/index.js");
|
|
301
|
+
var _index8 = require("./runtime/index.js");
|
|
302
|
+
var _index9 = require("./store/index.js");
|
|
303
|
+
var _index0 = require("./intl/index.js");
|
|
304
|
+
var _index1 = require("./messages/index.js");
|
|
305
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_index","require","_index2","_index3","_index4","_index5","_index6","_index7","_index8","_index9","_index0","_index1"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,IAAAA,MAAA,GAAAC,OAAA;AASA,IAAAC,OAAA,GAAAD,OAAA;AAYA,IAAAE,OAAA,GAAAF,OAAA;AAWA,IAAAG,OAAA,GAAAH,OAAA;AAUA,IAAAI,OAAA,GAAAJ,OAAA;AAmBA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AAQA,IAAAO,OAAA,GAAAP,OAAA;AAcA,IAAAQ,OAAA,GAAAR,OAAA;AACA,IAAAS,OAAA,GAAAT,OAAA;AACA,IAAAU,OAAA,GAAAV,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.clearIntlCaches = clearIntlCaches;
|
|
7
|
+
exports.getDateTimeFormat = getDateTimeFormat;
|
|
8
|
+
exports.getNumberFormat = getNumberFormat;
|
|
9
|
+
exports.isValidTimeZone = isValidTimeZone;
|
|
10
|
+
/**
|
|
11
|
+
* Cached `Intl` formatters (PERF-01, PERF-08, I18N-03, NOT-20).
|
|
12
|
+
*
|
|
13
|
+
* Constructing an `Intl.DateTimeFormat` or `Intl.NumberFormat` is expensive on
|
|
14
|
+
* Hermes, and rn-notification built one per time-zone calculation (thousands in a
|
|
15
|
+
* recurrence expansion) while rn-i18n built one per formatted value. Formatters
|
|
16
|
+
* are immutable once built, so one per (locale, options) is shared. Each cache is
|
|
17
|
+
* a small LRU: the working set is a few locales and zones, and an app that cycles
|
|
18
|
+
* through many still holds a bounded number.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const CAPACITY = 32;
|
|
22
|
+
function lru(capacity) {
|
|
23
|
+
const entries = new Map();
|
|
24
|
+
return {
|
|
25
|
+
get(key, create) {
|
|
26
|
+
const hit = entries.get(key);
|
|
27
|
+
if (hit !== undefined) {
|
|
28
|
+
// Re-insert to mark it most recently used.
|
|
29
|
+
entries.delete(key);
|
|
30
|
+
entries.set(key, hit);
|
|
31
|
+
return hit;
|
|
32
|
+
}
|
|
33
|
+
const value = create();
|
|
34
|
+
entries.set(key, value);
|
|
35
|
+
if (entries.size > capacity) {
|
|
36
|
+
const oldest = entries.keys().next().value;
|
|
37
|
+
if (oldest !== undefined) entries.delete(oldest);
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
},
|
|
41
|
+
clear: () => entries.clear(),
|
|
42
|
+
size: () => entries.size
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A stable key for an options object: keys sorted, so `{a, b}` and `{b, a}` share. */
|
|
47
|
+
function keyOf(locale, options) {
|
|
48
|
+
if (!options) return `${locale ?? ''}|`;
|
|
49
|
+
const sorted = Object.keys(options).sort().map(key => `${key}=${String(options[key])}`);
|
|
50
|
+
return `${locale ?? ''}|${sorted.join(',')}`;
|
|
51
|
+
}
|
|
52
|
+
const numberFormats = lru(CAPACITY);
|
|
53
|
+
const dateTimeFormats = lru(CAPACITY);
|
|
54
|
+
const timeZones = new Map();
|
|
55
|
+
const TIME_ZONE_MEMO_LIMIT = 256;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A shared `Intl.NumberFormat`. Throws what the constructor throws (an unknown
|
|
59
|
+
* currency, say): callers decide how a bad option is reported.
|
|
60
|
+
*/
|
|
61
|
+
function getNumberFormat(locale, options) {
|
|
62
|
+
return numberFormats.get(keyOf(locale, options), () => new Intl.NumberFormat(locale, options));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A shared `Intl.DateTimeFormat`. Throws what the constructor throws. */
|
|
66
|
+
function getDateTimeFormat(locale, options) {
|
|
67
|
+
return dateTimeFormats.get(keyOf(locale, options), () => new Intl.DateTimeFormat(locale, options));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Whether `Intl` accepts the IANA zone, memoized. Hermes raises a hard error for
|
|
72
|
+
* an unknown zone, so a stored zone is checked here before it reaches `Intl`.
|
|
73
|
+
*/
|
|
74
|
+
function isValidTimeZone(timeZone) {
|
|
75
|
+
if (timeZone.length === 0) return false;
|
|
76
|
+
const known = timeZones.get(timeZone);
|
|
77
|
+
if (known !== undefined) return known;
|
|
78
|
+
let valid;
|
|
79
|
+
try {
|
|
80
|
+
getDateTimeFormat('en-US', {
|
|
81
|
+
timeZone
|
|
82
|
+
}).format(0);
|
|
83
|
+
valid = true;
|
|
84
|
+
} catch {
|
|
85
|
+
valid = false;
|
|
86
|
+
}
|
|
87
|
+
if (timeZones.size >= TIME_ZONE_MEMO_LIMIT) timeZones.clear();
|
|
88
|
+
timeZones.set(timeZone, valid);
|
|
89
|
+
return valid;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Test seam: drops every cached formatter and zone check. */
|
|
93
|
+
function clearIntlCaches() {
|
|
94
|
+
numberFormats.clear();
|
|
95
|
+
dateTimeFormats.clear();
|
|
96
|
+
timeZones.clear();
|
|
97
|
+
}
|
|
98
|
+
//# 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;IACDK,KAAK,EAAEA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