@fairfox/polly 0.29.1 → 0.29.2

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.
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Type guards for walking `unknown` values safely.
3
+ *
4
+ * Polly touches a lot of shapes it doesn't own: parsed JSON bodies
5
+ * from the signalling server, IndexedDB records, `postMessage`
6
+ * payloads, storage adapter returns. TypeScript sees every one of
7
+ * those as `unknown`, and the ergonomic-but-unsafe fix — a bare `as`
8
+ * cast — hides every shape mismatch until runtime. The helpers below
9
+ * are the thinnest possible layer that turns a runtime shape check
10
+ * into a compile-time narrowing, so the code that follows can read
11
+ * the value without a cast.
12
+ *
13
+ * Each guard checks own-properties only (`Object.hasOwn`), not the
14
+ * prototype chain. Walking into a prototype would make a simple
15
+ * `hasKeyInObject(x, "toString")` pass for any object, which is
16
+ * never what a caller looking for a specific data key intends.
17
+ */
18
+ /** Narrow `input` to an object carrying its own `key`. Returns true
19
+ * when the input is a non-null object with an own property under
20
+ * the given key. The value under the key is left as `unknown`;
21
+ * callers narrow further with `Array.isArray`, `typeof`, or another
22
+ * guard. */
23
+ export declare function hasKeyInObject<K extends string>(input: unknown, key: K): input is Record<K, unknown>;
24
+ /** Narrow `input` to a plain object (non-null, non-array). Useful as
25
+ * a prelude to reads off a record whose shape is known at the
26
+ * call site but typed as `unknown`. */
27
+ export declare function isRecord(input: unknown): input is Record<string, unknown>;
@@ -0,0 +1,84 @@
1
+ var __create = Object.create;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
12
+ var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
20
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
21
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
22
+ for (let key of __getOwnPropNames(mod))
23
+ if (!__hasOwnProp.call(to, key))
24
+ __defProp(to, key, {
25
+ get: __accessProp.bind(mod, key),
26
+ enumerable: true
27
+ });
28
+ if (canCache)
29
+ cache.set(mod, to);
30
+ return to;
31
+ };
32
+ var __toCommonJS = (from) => {
33
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
34
+ if (entry)
35
+ return entry;
36
+ entry = __defProp({}, "__esModule", { value: true });
37
+ if (from && typeof from === "object" || typeof from === "function") {
38
+ for (var key of __getOwnPropNames(from))
39
+ if (!__hasOwnProp.call(entry, key))
40
+ __defProp(entry, key, {
41
+ get: __accessProp.bind(from, key),
42
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
43
+ });
44
+ }
45
+ __moduleCache.set(from, entry);
46
+ return entry;
47
+ };
48
+ var __moduleCache;
49
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
50
+ var __returnValue = (v) => v;
51
+ function __exportSetter(name, newValue) {
52
+ this[name] = __returnValue.bind(null, newValue);
53
+ }
54
+ var __export = (target, all) => {
55
+ for (var name in all)
56
+ __defProp(target, name, {
57
+ get: all[name],
58
+ enumerable: true,
59
+ configurable: true,
60
+ set: __exportSetter.bind(all, name)
61
+ });
62
+ };
63
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
64
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
65
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
66
+ }) : x)(function(x) {
67
+ if (typeof require !== "undefined")
68
+ return require.apply(this, arguments);
69
+ throw Error('Dynamic require of "' + x + '" is not supported');
70
+ });
71
+
72
+ // src/shared/lib/guards.ts
73
+ function hasKeyInObject(input, key) {
74
+ return typeof input === "object" && input !== null && Object.hasOwn(input, key);
75
+ }
76
+ function isRecord(input) {
77
+ return typeof input === "object" && input !== null && !Array.isArray(input);
78
+ }
79
+ export {
80
+ isRecord,
81
+ hasKeyInObject
82
+ };
83
+
84
+ //# debugId=36892B8B579A457A64756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/shared/lib/guards.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Type guards for walking `unknown` values safely.\n *\n * Polly touches a lot of shapes it doesn't own: parsed JSON bodies\n * from the signalling server, IndexedDB records, `postMessage`\n * payloads, storage adapter returns. TypeScript sees every one of\n * those as `unknown`, and the ergonomic-but-unsafe fix — a bare `as`\n * cast — hides every shape mismatch until runtime. The helpers below\n * are the thinnest possible layer that turns a runtime shape check\n * into a compile-time narrowing, so the code that follows can read\n * the value without a cast.\n *\n * Each guard checks own-properties only (`Object.hasOwn`), not the\n * prototype chain. Walking into a prototype would make a simple\n * `hasKeyInObject(x, \"toString\")` pass for any object, which is\n * never what a caller looking for a specific data key intends.\n */\n\n/** Narrow `input` to an object carrying its own `key`. Returns true\n * when the input is a non-null object with an own property under\n * the given key. The value under the key is left as `unknown`;\n * callers narrow further with `Array.isArray`, `typeof`, or another\n * guard. */\nexport function hasKeyInObject<K extends string>(\n input: unknown,\n key: K\n): input is Record<K, unknown> {\n return typeof input === \"object\" && input !== null && Object.hasOwn(input, key);\n}\n\n/** Narrow `input` to a plain object (non-null, non-array). Useful as\n * a prelude to reads off a record whose shape is known at the\n * call site but typed as `unknown`. */\nexport function isRecord(input: unknown): input is Record<string, unknown> {\n return typeof input === \"object\" && input !== null && !Array.isArray(input);\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBO,SAAS,cAAgC,CAC9C,OACA,KAC6B;AAAA,EAC7B,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO,OAAO,OAAO,GAAG;AAAA;AAMzE,SAAS,QAAQ,CAAC,OAAkD;AAAA,EACzE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAAA;",
8
+ "debugId": "36892B8B579A457A64756E2164756E21",
9
+ "names": []
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fairfox/polly",
3
- "version": "0.29.1",
3
+ "version": "0.29.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Multi-execution-context framework with reactive state and cross-context messaging for Chrome extensions, PWAs, and worker-based applications",
@@ -46,6 +46,10 @@
46
46
  "import": "./dist/src/shared/lib/errors.js",
47
47
  "types": "./dist/shared/lib/errors.d.ts"
48
48
  },
49
+ "./guards": {
50
+ "import": "./dist/src/shared/lib/guards.js",
51
+ "types": "./dist/src/shared/lib/guards.d.ts"
52
+ },
49
53
  "./types": {
50
54
  "import": "./dist/src/shared/types/messages.js",
51
55
  "types": "./dist/shared/types/messages.d.ts"