@symbiote-native/cellular 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.
@@ -2,6 +2,10 @@ import { type Signal } from '@angular/core';
2
2
  import { type PermissionResponse } from '../../../core';
3
3
  export declare class PermissionsService {
4
4
  private readonly status;
5
+ private readonly fetchError;
6
+ private isAutoFetchStarted;
7
+ /** Why the auto-fetch left `status` at null. Cleared by the next successful get()/request(). */
8
+ readonly error: Signal<Error | null>;
5
9
  connect(): Signal<PermissionResponse | null>;
6
10
  get(): Promise<PermissionResponse>;
7
11
  request(): Promise<PermissionResponse>;
@@ -37,6 +37,11 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
37
37
  //
38
38
  // readonly status = inject(PermissionsService).connect();
39
39
  // // template: {{ status()?.granted }}
40
+ //
41
+ // The auto-fetch has nobody to reject to, so its failure lands in the `error` signal instead of
42
+ // escaping as an unhandled rejection: a null status with a non-null error is how a consumer tells
43
+ // "the fetch failed" from "not fetched yet". get()/request() still reject to their direct caller —
44
+ // only the automatic call is made safe.
40
45
  import { Injectable, signal } from '@angular/core';
41
46
  import { getPermissionsAsync, requestPermissionsAsync, } from '../../../core/index.js';
42
47
  let PermissionsService = (() => {
@@ -54,20 +59,32 @@ let PermissionsService = (() => {
54
59
  __runInitializers(_classThis, _classExtraInitializers);
55
60
  }
56
61
  status = signal(null);
62
+ fetchError = signal(null);
63
+ isAutoFetchStarted = false;
64
+ /** Why the auto-fetch left `status` at null. Cleared by the next successful get()/request(). */
65
+ error = this.fetchError.asReadonly();
57
66
  connect() {
58
- if (this.status() === null) {
59
- void this.get();
67
+ // Latched rather than guarded on `status() === null`: a failed fetch leaves status null
68
+ // forever, so the old guard turned every later connect() into another native call — unbounded
69
+ // once connect() is reached from a change-detected expression instead of a field initializer.
70
+ if (!this.isAutoFetchStarted) {
71
+ this.isAutoFetchStarted = true;
72
+ this.get().catch((cause) => {
73
+ this.fetchError.set(cause instanceof Error ? cause : new Error(String(cause)));
74
+ });
60
75
  }
61
76
  return this.status.asReadonly();
62
77
  }
63
78
  async get() {
64
79
  const response = await getPermissionsAsync();
65
80
  this.status.set(response);
81
+ this.fetchError.set(null);
66
82
  return response;
67
83
  }
68
84
  async request() {
69
85
  const response = await requestPermissionsAsync();
70
86
  this.status.set(response);
87
+ this.fetchError.set(null);
71
88
  return response;
72
89
  }
73
90
  };
@@ -2,5 +2,6 @@ import { type PermissionResponse } from '../../../core';
2
2
  export declare function usePermissions(): [
3
3
  PermissionResponse | null,
4
4
  () => Promise<PermissionResponse>,
5
- () => Promise<PermissionResponse>
5
+ () => Promise<PermissionResponse>,
6
+ Error | null
6
7
  ];
@@ -1,28 +1,41 @@
1
1
  // React lifecycle wiring over the framework-agnostic core (core/cellular.ts) — fetches the
2
2
  // current permission status on mount, then exposes request/get to re-check imperatively.
3
+ //
4
+ // The mount fetch has nobody to reject to, so its failure lands in the 4th tuple slot (`error`)
5
+ // instead of escaping as an unhandled rejection: a null status with a non-null error is how a
6
+ // consumer tells "the fetch failed" from "not fetched yet". get()/request() still reject to their
7
+ // direct caller — only the automatic call is made safe.
3
8
  import { useCallback, useEffect, useRef, useState } from 'react';
4
9
  import { getPermissionsAsync, requestPermissionsAsync, } from '../../../core/index.js';
5
10
  export function usePermissions() {
6
11
  const isMounted = useRef(true);
7
12
  const [status, setStatus] = useState(null);
13
+ const [error, setError] = useState(null);
8
14
  const getPermission = useCallback(async () => {
9
15
  const response = await getPermissionsAsync();
10
- if (isMounted.current)
16
+ if (isMounted.current) {
11
17
  setStatus(response);
18
+ setError(null);
19
+ }
12
20
  return response;
13
21
  }, []);
14
22
  const requestPermission = useCallback(async () => {
15
23
  const response = await requestPermissionsAsync();
16
- if (isMounted.current)
24
+ if (isMounted.current) {
17
25
  setStatus(response);
26
+ setError(null);
27
+ }
18
28
  return response;
19
29
  }, []);
20
30
  useEffect(() => {
21
31
  isMounted.current = true;
22
- void getPermission();
32
+ getPermission().catch((cause) => {
33
+ if (isMounted.current)
34
+ setError(cause instanceof Error ? cause : new Error(String(cause)));
35
+ });
23
36
  return () => {
24
37
  isMounted.current = false;
25
38
  };
26
39
  }, [getPermission]);
27
- return [status, requestPermission, getPermission];
40
+ return [status, requestPermission, getPermission, error];
28
41
  }
@@ -0,0 +1,2 @@
1
+ export { usePermissions } from './runes/use-permissions.svelte';
2
+ export * from '../core';
@@ -0,0 +1,6 @@
1
+ // @symbiote-native/cellular/svelte: the Svelte entry over the framework-agnostic core, plus
2
+ // usePermissions — the only stateful surface this package needs a lifecycle wrapper for. The
3
+ // lifecycle bucket is `runes/` (never `hooks/`/`composables/`, those are React's and Vue's terms)
4
+ // — see adapters/svelte/src/runes for the same convention.
5
+ export { usePermissions } from './runes/use-permissions.svelte';
6
+ export * from '../core/index.js';
@@ -0,0 +1,7 @@
1
+ import { type PermissionResponse } from '../../core';
2
+ export declare function usePermissions(): {
3
+ readonly status: PermissionResponse | null;
4
+ readonly error: Error | null;
5
+ request: () => Promise<PermissionResponse>;
6
+ get: () => Promise<PermissionResponse>;
7
+ };
@@ -0,0 +1,55 @@
1
+ // Svelte lifecycle wiring over the framework-agnostic core (core/cellular.ts) — fetches the
2
+ // current permission status on mount, then exposes request/get to re-check imperatively. The
3
+ // Svelte twin of vue/composables/use-permissions and react/hooks/use-permissions.
4
+ //
5
+ // `.svelte.ts` (not `.ts`): runes ($state/$effect) are only usable in a file with this extension
6
+ // outside an actual `.svelte` component. `runes/` is Svelte's own term for the bucket React calls
7
+ // `hooks/` and Vue calls `composables/` — see adapters/svelte/src/runes.
8
+ //
9
+ // Vue's onMounted collapses into a `$effect` with no teardown (there is no ongoing subscription
10
+ // here, just a one-shot get). The effect only WRITES `status` (through `get()`), never reads it,
11
+ // so its dependency set stays empty and it fires exactly once on mount.
12
+ //
13
+ // `status` comes back as a GETTER on the returned object rather than a raw `$state` variable:
14
+ // Svelte 5 reactivity is lexically scoped to the declaring module, so a raw `let x = $state(...)`
15
+ // handed out of a plain function arrives dead at the caller. Reading `.status` is the Svelte
16
+ // equivalent of unwrapping Vue's `Ref` via `.value`.
17
+ //
18
+ // The mount fetch has nobody to reject to, so its failure lands in `error` (a second boxed getter,
19
+ // same reason as `status`) instead of escaping as an unhandled rejection: a null status with a
20
+ // non-null error is how a consumer tells "the fetch failed" from "not fetched yet".
21
+ // get()/request() still reject to their direct caller — only the automatic call is made safe.
22
+ import { getPermissionsAsync, requestPermissionsAsync } from '../../core/index.js';
23
+ export function usePermissions() {
24
+ let status = $state(null);
25
+ let error = $state(null);
26
+ const get = async () => {
27
+ const response = await getPermissionsAsync();
28
+ status = response;
29
+ error = null;
30
+ return response;
31
+ };
32
+ const request = async () => {
33
+ const response = await requestPermissionsAsync();
34
+ status = response;
35
+ error = null;
36
+ return response;
37
+ };
38
+ $effect(() => {
39
+ // The catch runs after the effect has settled, so writing `error` there adds no dependency and
40
+ // the effect still fires exactly once.
41
+ get().catch((cause) => {
42
+ error = cause instanceof Error ? cause : new Error(String(cause));
43
+ });
44
+ });
45
+ return {
46
+ get status() {
47
+ return status;
48
+ },
49
+ get error() {
50
+ return error;
51
+ },
52
+ request,
53
+ get,
54
+ };
55
+ }
@@ -2,6 +2,7 @@ import { type Ref } from '@vue/runtime-core';
2
2
  import { type PermissionResponse } from '../../../core';
3
3
  export declare function usePermissions(): {
4
4
  status: Ref<PermissionResponse | null>;
5
+ error: Ref<Error | null>;
5
6
  request: () => Promise<PermissionResponse>;
6
7
  get: () => Promise<PermissionResponse>;
7
8
  };
@@ -1,21 +1,31 @@
1
1
  // Vue lifecycle wiring over the framework-agnostic core (core/cellular.ts) — fetches the
2
2
  // current permission status on mount, then exposes request/get to re-check imperatively.
3
+ //
4
+ // The mount fetch has nobody to reject to, so its failure lands in the `error` ref instead of
5
+ // escaping as an unhandled rejection: a null status with a non-null error is how a consumer tells
6
+ // "the fetch failed" from "not fetched yet". get()/request() still reject to their direct caller —
7
+ // only the automatic call is made safe.
3
8
  import { onMounted, ref } from '@vue/runtime-core';
4
9
  import { getPermissionsAsync, requestPermissionsAsync, } from '../../../core/index.js';
5
10
  export function usePermissions() {
6
11
  const status = ref(null);
12
+ const error = ref(null);
7
13
  const get = async () => {
8
14
  const response = await getPermissionsAsync();
9
15
  status.value = response;
16
+ error.value = null;
10
17
  return response;
11
18
  };
12
19
  const request = async () => {
13
20
  const response = await requestPermissionsAsync();
14
21
  status.value = response;
22
+ error.value = null;
15
23
  return response;
16
24
  };
17
25
  onMounted(() => {
18
- void get();
26
+ get().catch((cause) => {
27
+ error.value = cause instanceof Error ? cause : new Error(String(cause));
28
+ });
19
29
  });
20
- return { status, request, get };
30
+ return { status, error, request, get };
21
31
  }
@@ -3,6 +3,10 @@ import { type PermissionResponse } from '../../../core';
3
3
  import * as i0 from "@angular/core";
4
4
  export declare class PermissionsService {
5
5
  private readonly status;
6
+ private readonly fetchError;
7
+ private isAutoFetchStarted;
8
+ /** Why the auto-fetch left `status` at null. Cleared by the next successful get()/request(). */
9
+ readonly error: Signal<Error | null>;
6
10
  connect(): Signal<PermissionResponse | null>;
7
11
  get(): Promise<PermissionResponse>;
8
12
  request(): Promise<PermissionResponse>;
@@ -3,32 +3,50 @@
3
3
  //
4
4
  // readonly status = inject(PermissionsService).connect();
5
5
  // // template: {{ status()?.granted }}
6
+ //
7
+ // The auto-fetch has nobody to reject to, so its failure lands in the `error` signal instead of
8
+ // escaping as an unhandled rejection: a null status with a non-null error is how a consumer tells
9
+ // "the fetch failed" from "not fetched yet". get()/request() still reject to their direct caller —
10
+ // only the automatic call is made safe.
6
11
  import { Injectable, signal } from '@angular/core';
7
12
  import { getPermissionsAsync, requestPermissionsAsync, } from '../../../core';
8
13
  import * as i0 from "@angular/core";
9
14
  export class PermissionsService {
10
15
  status = signal(null, /* @ts-ignore */
11
16
  ...(ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []));
17
+ fetchError = signal(null, /* @ts-ignore */
18
+ ...(ngDevMode ? [{ debugName: "fetchError" }] : /* istanbul ignore next */ []));
19
+ isAutoFetchStarted = false;
20
+ /** Why the auto-fetch left `status` at null. Cleared by the next successful get()/request(). */
21
+ error = this.fetchError.asReadonly();
12
22
  connect() {
13
- if (this.status() === null) {
14
- void this.get();
23
+ // Latched rather than guarded on `status() === null`: a failed fetch leaves status null
24
+ // forever, so the old guard turned every later connect() into another native call — unbounded
25
+ // once connect() is reached from a change-detected expression instead of a field initializer.
26
+ if (!this.isAutoFetchStarted) {
27
+ this.isAutoFetchStarted = true;
28
+ this.get().catch((cause) => {
29
+ this.fetchError.set(cause instanceof Error ? cause : new Error(String(cause)));
30
+ });
15
31
  }
16
32
  return this.status.asReadonly();
17
33
  }
18
34
  async get() {
19
35
  const response = await getPermissionsAsync();
20
36
  this.status.set(response);
37
+ this.fetchError.set(null);
21
38
  return response;
22
39
  }
23
40
  async request() {
24
41
  const response = await requestPermissionsAsync();
25
42
  this.status.set(response);
43
+ this.fetchError.set(null);
26
44
  return response;
27
45
  }
28
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: PermissionsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
29
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: PermissionsService, providedIn: 'root' });
46
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: PermissionsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
47
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: PermissionsService, providedIn: 'root' });
30
48
  }
31
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: PermissionsService, decorators: [{
49
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: PermissionsService, decorators: [{
32
50
  type: Injectable,
33
51
  args: [{ providedIn: 'root' }]
34
52
  }] });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/angular/services/permissions.service/index.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,uEAAuE;AACvE,EAAE;AACF,4DAA4D;AAC5D,yCAAyC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AAChE,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GAExB,MAAM,eAAe,CAAC;;AAGvB,MAAM,OAAO,kBAAkB;IACZ,MAAM,GAAG,MAAM,CAA4B,IAAI;+EAAC,CAAC;IAElE,OAAO;QACL,IAAI,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC;YAC3B,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC;QAClB,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,QAAQ,GAAG,MAAM,mBAAmB,EAAE,CAAC;QAC7C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,QAAQ,GAAG,MAAM,uBAAuB,EAAE,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1B,OAAO,QAAQ,CAAC;IAClB,CAAC;uGApBU,kBAAkB;2GAAlB,kBAAkB,cADL,MAAM;;2FACnB,kBAAkB;kBAD9B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/angular/services/permissions.service/index.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,uEAAuE;AACvE,EAAE;AACF,4DAA4D;AAC5D,yCAAyC;AACzC,EAAE;AACF,gGAAgG;AAChG,kGAAkG;AAClG,mGAAmG;AACnG,wCAAwC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AAChE,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GAExB,MAAM,eAAe,CAAC;;AAGvB,MAAM,OAAO,kBAAkB;IACZ,MAAM,GAAG,MAAM,CAA4B,IAAI;+EAAC,CAAC;IACjD,UAAU,GAAG,MAAM,CAAe,IAAI;mFAAC,CAAC;IACjD,kBAAkB,GAAG,KAAK,CAAC;IAEnC,gGAAgG;IACvF,KAAK,GAAyB,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;IAEpE,OAAO;QACL,wFAAwF;QACxF,8FAA8F;QAC9F,8FAA8F;QAC9F,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC7B,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;YAC/B,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBAClC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjF,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,QAAQ,GAAG,MAAM,mBAAmB,EAAE,CAAC;QAC7C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,QAAQ,GAAG,MAAM,uBAAuB,EAAE,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1B,OAAO,QAAQ,CAAC;IAClB,CAAC;uGAjCU,kBAAkB;2GAAlB,kBAAkB,cADL,MAAM;;2FACnB,kBAAkB;kBAD9B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbiote-native/cellular",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "expo-cellular wrapped for SymbioteNative — one framework-agnostic core, built once and reachable from the React, Vue, and Angular adapters. Cellular generation (2G/3G/4G/5G), carrier/SIM info on Android (ISO country code, carrier name, MCC/MNC), VoIP-support detection, and the permission get/request pair gating carrier info on Android.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -30,6 +30,10 @@
30
30
  "types": "./build/react/index.d.ts",
31
31
  "default": "./build/react/index.js"
32
32
  },
33
+ "./svelte": {
34
+ "types": "./build/svelte/index.d.ts",
35
+ "default": "./build/svelte/index.js"
36
+ },
33
37
  "./angular": {
34
38
  "types": "./build-ngc/angular/index.d.ts",
35
39
  "react-native": "./build-ngc/angular/index.js",
@@ -53,15 +57,17 @@
53
57
  "expo-modules-core": "57.0.5"
54
58
  },
55
59
  "peerDependencies": {
60
+ "@symbiote-native/angular": ">=0.6.2",
56
61
  "@symbiote-native/engine": ">=0.1.7",
62
+ "@symbiote-native/react": ">=0.2.8",
63
+ "@symbiote-native/svelte": ">=0.1.0",
64
+ "@symbiote-native/vue": ">=0.3.8",
57
65
  "@angular/core": ">=20",
58
66
  "@vue/runtime-core": "^3.5.13",
59
67
  "react": ">=19.0.0",
60
68
  "react-native": ">=0.86",
61
- "vue": ">=3.5.0",
62
- "@symbiote-native/angular": "0.6.2",
63
- "@symbiote-native/react": "0.2.8",
64
- "@symbiote-native/vue": "0.3.8"
69
+ "svelte": ">=5.56.0",
70
+ "vue": ">=3.5.0"
65
71
  },
66
72
  "peerDependenciesMeta": {
67
73
  "@symbiote-native/angular": {
@@ -70,6 +76,9 @@
70
76
  "@symbiote-native/react": {
71
77
  "optional": true
72
78
  },
79
+ "@symbiote-native/svelte": {
80
+ "optional": true
81
+ },
73
82
  "@symbiote-native/vue": {
74
83
  "optional": true
75
84
  },
@@ -82,24 +91,29 @@
82
91
  "react": {
83
92
  "optional": true
84
93
  },
94
+ "svelte": {
95
+ "optional": true
96
+ },
85
97
  "vue": {
86
98
  "optional": true
87
99
  }
88
100
  },
89
101
  "devDependencies": {
90
- "@angular/compiler": "^22",
91
- "@angular/compiler-cli": "^22",
92
- "@angular/core": "^22",
102
+ "@angular/compiler": "~22.0.8",
103
+ "@angular/compiler-cli": "~22.0.8",
104
+ "@angular/core": "~22.0.8",
93
105
  "@types/node": "^26.0.0",
94
106
  "@types/react": "^19.2.0",
95
107
  "@vue/runtime-core": "^3.5.13",
96
108
  "react": "19.2.3",
109
+ "svelte": "^5.56.0",
97
110
  "typescript": "~6.0.0",
98
- "@symbiote-native/angular": "0.6.2",
99
- "@symbiote-native/engine": "0.1.7",
100
- "@symbiote-native/react": "0.2.8",
111
+ "@symbiote-native/angular": "0.7.0",
112
+ "@symbiote-native/engine": "0.2.0",
113
+ "@symbiote-native/react": "0.3.0",
114
+ "@symbiote-native/svelte": "0.2.0",
101
115
  "@symbiote-native/test-utils": "0.1.6",
102
- "@symbiote-native/vue": "0.3.8"
116
+ "@symbiote-native/vue": "0.4.0"
103
117
  },
104
118
  "scripts": {
105
119
  "typecheck": "tsc --build",
@@ -3,6 +3,11 @@
3
3
  //
4
4
  // readonly status = inject(PermissionsService).connect();
5
5
  // // template: {{ status()?.granted }}
6
+ //
7
+ // The auto-fetch has nobody to reject to, so its failure lands in the `error` signal instead of
8
+ // escaping as an unhandled rejection: a null status with a non-null error is how a consumer tells
9
+ // "the fetch failed" from "not fetched yet". get()/request() still reject to their direct caller —
10
+ // only the automatic call is made safe.
6
11
  import { Injectable, signal, type Signal } from '@angular/core';
7
12
  import {
8
13
  getPermissionsAsync,
@@ -13,10 +18,21 @@ import {
13
18
  @Injectable({ providedIn: 'root' })
14
19
  export class PermissionsService {
15
20
  private readonly status = signal<PermissionResponse | null>(null);
21
+ private readonly fetchError = signal<Error | null>(null);
22
+ private isAutoFetchStarted = false;
23
+
24
+ /** Why the auto-fetch left `status` at null. Cleared by the next successful get()/request(). */
25
+ readonly error: Signal<Error | null> = this.fetchError.asReadonly();
16
26
 
17
27
  connect(): Signal<PermissionResponse | null> {
18
- if (this.status() === null) {
19
- void this.get();
28
+ // Latched rather than guarded on `status() === null`: a failed fetch leaves status null
29
+ // forever, so the old guard turned every later connect() into another native call — unbounded
30
+ // once connect() is reached from a change-detected expression instead of a field initializer.
31
+ if (!this.isAutoFetchStarted) {
32
+ this.isAutoFetchStarted = true;
33
+ this.get().catch((cause: unknown) => {
34
+ this.fetchError.set(cause instanceof Error ? cause : new Error(String(cause)));
35
+ });
20
36
  }
21
37
  return this.status.asReadonly();
22
38
  }
@@ -24,12 +40,14 @@ export class PermissionsService {
24
40
  async get(): Promise<PermissionResponse> {
25
41
  const response = await getPermissionsAsync();
26
42
  this.status.set(response);
43
+ this.fetchError.set(null);
27
44
  return response;
28
45
  }
29
46
 
30
47
  async request(): Promise<PermissionResponse> {
31
48
  const response = await requestPermissionsAsync();
32
49
  this.status.set(response);
50
+ this.fetchError.set(null);
33
51
  return response;
34
52
  }
35
53
  }
@@ -1,5 +1,10 @@
1
1
  // React lifecycle wiring over the framework-agnostic core (core/cellular.ts) — fetches the
2
2
  // current permission status on mount, then exposes request/get to re-check imperatively.
3
+ //
4
+ // The mount fetch has nobody to reject to, so its failure lands in the 4th tuple slot (`error`)
5
+ // instead of escaping as an unhandled rejection: a null status with a non-null error is how a
6
+ // consumer tells "the fetch failed" from "not fetched yet". get()/request() still reject to their
7
+ // direct caller — only the automatic call is made safe.
3
8
  import { useCallback, useEffect, useRef, useState } from 'react';
4
9
  import {
5
10
  getPermissionsAsync,
@@ -11,29 +16,39 @@ export function usePermissions(): [
11
16
  PermissionResponse | null,
12
17
  () => Promise<PermissionResponse>,
13
18
  () => Promise<PermissionResponse>,
19
+ Error | null,
14
20
  ] {
15
21
  const isMounted = useRef(true);
16
22
  const [status, setStatus] = useState<PermissionResponse | null>(null);
23
+ const [error, setError] = useState<Error | null>(null);
17
24
 
18
25
  const getPermission = useCallback(async () => {
19
26
  const response = await getPermissionsAsync();
20
- if (isMounted.current) setStatus(response);
27
+ if (isMounted.current) {
28
+ setStatus(response);
29
+ setError(null);
30
+ }
21
31
  return response;
22
32
  }, []);
23
33
 
24
34
  const requestPermission = useCallback(async () => {
25
35
  const response = await requestPermissionsAsync();
26
- if (isMounted.current) setStatus(response);
36
+ if (isMounted.current) {
37
+ setStatus(response);
38
+ setError(null);
39
+ }
27
40
  return response;
28
41
  }, []);
29
42
 
30
43
  useEffect(() => {
31
44
  isMounted.current = true;
32
- void getPermission();
45
+ getPermission().catch((cause: unknown) => {
46
+ if (isMounted.current) setError(cause instanceof Error ? cause : new Error(String(cause)));
47
+ });
33
48
  return () => {
34
49
  isMounted.current = false;
35
50
  };
36
51
  }, [getPermission]);
37
52
 
38
- return [status, requestPermission, getPermission];
53
+ return [status, requestPermission, getPermission, error];
39
54
  }
@@ -0,0 +1,6 @@
1
+ // @symbiote-native/cellular/svelte: the Svelte entry over the framework-agnostic core, plus
2
+ // usePermissions — the only stateful surface this package needs a lifecycle wrapper for. The
3
+ // lifecycle bucket is `runes/` (never `hooks/`/`composables/`, those are React's and Vue's terms)
4
+ // — see adapters/svelte/src/runes for the same convention.
5
+ export { usePermissions } from './runes/use-permissions.svelte';
6
+ export * from '../core';
@@ -0,0 +1,65 @@
1
+ // Svelte lifecycle wiring over the framework-agnostic core (core/cellular.ts) — fetches the
2
+ // current permission status on mount, then exposes request/get to re-check imperatively. The
3
+ // Svelte twin of vue/composables/use-permissions and react/hooks/use-permissions.
4
+ //
5
+ // `.svelte.ts` (not `.ts`): runes ($state/$effect) are only usable in a file with this extension
6
+ // outside an actual `.svelte` component. `runes/` is Svelte's own term for the bucket React calls
7
+ // `hooks/` and Vue calls `composables/` — see adapters/svelte/src/runes.
8
+ //
9
+ // Vue's onMounted collapses into a `$effect` with no teardown (there is no ongoing subscription
10
+ // here, just a one-shot get). The effect only WRITES `status` (through `get()`), never reads it,
11
+ // so its dependency set stays empty and it fires exactly once on mount.
12
+ //
13
+ // `status` comes back as a GETTER on the returned object rather than a raw `$state` variable:
14
+ // Svelte 5 reactivity is lexically scoped to the declaring module, so a raw `let x = $state(...)`
15
+ // handed out of a plain function arrives dead at the caller. Reading `.status` is the Svelte
16
+ // equivalent of unwrapping Vue's `Ref` via `.value`.
17
+ //
18
+ // The mount fetch has nobody to reject to, so its failure lands in `error` (a second boxed getter,
19
+ // same reason as `status`) instead of escaping as an unhandled rejection: a null status with a
20
+ // non-null error is how a consumer tells "the fetch failed" from "not fetched yet".
21
+ // get()/request() still reject to their direct caller — only the automatic call is made safe.
22
+ import { getPermissionsAsync, requestPermissionsAsync, type PermissionResponse } from '../../core';
23
+
24
+ export function usePermissions(): {
25
+ readonly status: PermissionResponse | null;
26
+ readonly error: Error | null;
27
+ request: () => Promise<PermissionResponse>;
28
+ get: () => Promise<PermissionResponse>;
29
+ } {
30
+ let status = $state<PermissionResponse | null>(null);
31
+ let error = $state<Error | null>(null);
32
+
33
+ const get = async (): Promise<PermissionResponse> => {
34
+ const response = await getPermissionsAsync();
35
+ status = response;
36
+ error = null;
37
+ return response;
38
+ };
39
+
40
+ const request = async (): Promise<PermissionResponse> => {
41
+ const response = await requestPermissionsAsync();
42
+ status = response;
43
+ error = null;
44
+ return response;
45
+ };
46
+
47
+ $effect(() => {
48
+ // The catch runs after the effect has settled, so writing `error` there adds no dependency and
49
+ // the effect still fires exactly once.
50
+ get().catch((cause: unknown) => {
51
+ error = cause instanceof Error ? cause : new Error(String(cause));
52
+ });
53
+ });
54
+
55
+ return {
56
+ get status(): PermissionResponse | null {
57
+ return status;
58
+ },
59
+ get error(): Error | null {
60
+ return error;
61
+ },
62
+ request,
63
+ get,
64
+ };
65
+ }
@@ -0,0 +1,6 @@
1
+ // Pulls in svelte's ambient global declarations ($state/$effect/...) for this package's tsc
2
+ // program. adapters/svelte gets these for free because render.ts does a real value import from
3
+ // 'svelte' (any file in a program importing a module loads its ambient globals for the whole
4
+ // program); this package has no such import, so a triple-slash reference does the same job
5
+ // explicitly rather than relying on an incidental side-effect.
6
+ /// <reference types="svelte" />
@@ -1,5 +1,10 @@
1
1
  // Vue lifecycle wiring over the framework-agnostic core (core/cellular.ts) — fetches the
2
2
  // current permission status on mount, then exposes request/get to re-check imperatively.
3
+ //
4
+ // The mount fetch has nobody to reject to, so its failure lands in the `error` ref instead of
5
+ // escaping as an unhandled rejection: a null status with a non-null error is how a consumer tells
6
+ // "the fetch failed" from "not fetched yet". get()/request() still reject to their direct caller —
7
+ // only the automatic call is made safe.
3
8
  import { onMounted, ref, type Ref } from '@vue/runtime-core';
4
9
  import {
5
10
  getPermissionsAsync,
@@ -9,26 +14,32 @@ import {
9
14
 
10
15
  export function usePermissions(): {
11
16
  status: Ref<PermissionResponse | null>;
17
+ error: Ref<Error | null>;
12
18
  request: () => Promise<PermissionResponse>;
13
19
  get: () => Promise<PermissionResponse>;
14
20
  } {
15
21
  const status = ref<PermissionResponse | null>(null);
22
+ const error = ref<Error | null>(null);
16
23
 
17
24
  const get = async () => {
18
25
  const response = await getPermissionsAsync();
19
26
  status.value = response;
27
+ error.value = null;
20
28
  return response;
21
29
  };
22
30
 
23
31
  const request = async () => {
24
32
  const response = await requestPermissionsAsync();
25
33
  status.value = response;
34
+ error.value = null;
26
35
  return response;
27
36
  };
28
37
 
29
38
  onMounted(() => {
30
- void get();
39
+ get().catch((cause: unknown) => {
40
+ error.value = cause instanceof Error ? cause : new Error(String(cause));
41
+ });
31
42
  });
32
43
 
33
- return { status, request, get };
44
+ return { status, error, request, get };
34
45
  }