storion 0.7.1 → 0.7.5

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.
@@ -1,4 +1,4 @@
1
- import { e as emitter, w as withHooks, h as hasReadHook, t as trackRead, a as hasWriteHook, c as trackWrite, s as scheduleNotification, b as batch } from "./emitter-BA44OHdL.js";
1
+ import { a as SetupPhaseError, c as LifetimeMismatchError, e as emitter, w as withHooks, I as InvalidActionError, h as hasReadHook, t as trackRead, f as hasWriteHook, i as trackWrite, d as StoreDisposedError, s as scheduleNotification, b as batch } from "./emitter-XwTUpyGv.js";
2
2
  const STORION_TYPE = Symbol("STORION");
3
3
  function is$1(value, kind) {
4
4
  return value !== null && (typeof value === "object" || typeof value === "function") && STORION_TYPE in value && value[STORION_TYPE] === kind;
@@ -1863,8 +1863,9 @@ function createStoreContext(options) {
1863
1863
  // Implementation handles both StoreSpec and Factory overloads
1864
1864
  get(specOrFactory) {
1865
1865
  if (!isSetupPhase()) {
1866
- throw new Error(
1867
- `get() can only be called during setup phase. Do not call get() inside actions or async callbacks. Declare all dependencies at the top of your setup function.`
1866
+ throw new SetupPhaseError(
1867
+ "get",
1868
+ "Declare all dependencies at the top of your setup function."
1868
1869
  );
1869
1870
  }
1870
1871
  if (!isSpec(specOrFactory)) {
@@ -1875,9 +1876,7 @@ function createStoreContext(options) {
1875
1876
  if (currentLifetime === "keepAlive" && depLifetime === "autoDispose") {
1876
1877
  const currentName = spec.options.name ?? "unknown";
1877
1878
  const depName = depSpec.name ?? "unknown";
1878
- throw new Error(
1879
- `Lifetime mismatch: Store "${currentName}" (keepAlive) cannot depend on store "${depName}" (autoDispose). A long-lived store cannot depend on a store that may be disposed. Either change "${currentName}" to autoDispose, or change "${depName}" to keepAlive.`
1880
- );
1879
+ throw new LifetimeMismatchError(currentName, depName, "depend on");
1881
1880
  }
1882
1881
  const instance = resolver.get(depSpec);
1883
1882
  onDependency == null ? void 0 : onDependency(instance);
@@ -1890,8 +1889,9 @@ function createStoreContext(options) {
1890
1889
  // Implementation handles StoreSpec, Factory, and parameterized Factory overloads
1891
1890
  create(specOrFactory, ...args) {
1892
1891
  if (!isSetupPhase()) {
1893
- throw new Error(
1894
- `create() can only be called during setup phase. Do not call create() inside actions or async callbacks. Declare all child stores at the top of your setup function.`
1892
+ throw new SetupPhaseError(
1893
+ "create",
1894
+ "Declare all child stores at the top of your setup function."
1895
1895
  );
1896
1896
  }
1897
1897
  if (!isSpec(specOrFactory)) {
@@ -1904,9 +1904,7 @@ function createStoreContext(options) {
1904
1904
  if (currentLifetime === "keepAlive" && childLifetime === "autoDispose") {
1905
1905
  const currentName = spec.options.name ?? "unknown";
1906
1906
  const childName = childSpec.name ?? "unknown";
1907
- throw new Error(
1908
- `Lifetime mismatch: Store "${currentName}" (keepAlive) cannot create child store "${childName}" (autoDispose). A long-lived store cannot create a store that may be disposed before it. Either change "${currentName}" to autoDispose, or change "${childName}" to keepAlive.`
1909
- );
1907
+ throw new LifetimeMismatchError(currentName, childName, "create");
1910
1908
  }
1911
1909
  const instance = resolver.create(childSpec);
1912
1910
  onDispose == null ? void 0 : onDispose(willDispose(instance));
@@ -1924,16 +1922,15 @@ function createStoreContext(options) {
1924
1922
  },
1925
1923
  mixin(mixin, ...args) {
1926
1924
  if (!isSetupPhase()) {
1927
- throw new Error(
1928
- `mixin() can only be called during setup phase. Do not call mixin() inside actions or async callbacks.`
1929
- );
1925
+ throw new SetupPhaseError("mixin");
1930
1926
  }
1931
1927
  return mixin(ctx, ...args);
1932
1928
  },
1933
1929
  focus(path, options2) {
1934
1930
  if (!isSetupPhase()) {
1935
- throw new Error(
1936
- `focus() can only be called during setup phase. Do not call focus() inside actions or async callbacks. Use the .to() method on an existing focus for dynamic sub-paths.`
1931
+ throw new SetupPhaseError(
1932
+ "focus",
1933
+ "Use the .to() method on an existing focus for dynamic sub-paths."
1937
1934
  );
1938
1935
  }
1939
1936
  const focusCtx = {
@@ -2383,14 +2380,12 @@ function createStoreInstance(spec, resolver, instanceOptions = {}) {
2383
2380
  const wrappedActions = {};
2384
2381
  for (const [name, action] of Object.entries(actions)) {
2385
2382
  if (typeof action !== "function") {
2386
- throw new Error(
2387
- `Action "${name}" must be a function, got ${typeof action}. If using focus(), destructure it and return the getter/setter separately: const [get, set] = focus("path"); return { get, set };`
2388
- );
2383
+ throw new InvalidActionError(name, typeof action);
2389
2384
  }
2390
2385
  const wrappedAction = wrapFn(action, (originalAction) => {
2391
2386
  const wrapper = (...args) => {
2392
2387
  if (disposed) {
2393
- throw new Error(`Cannot call action on disposed store: ${storeId}`);
2388
+ throw new StoreDisposedError(storeId);
2394
2389
  }
2395
2390
  const actionNameKey = name;
2396
2391
  const nthKey = name;
package/dist/storion.js CHANGED
@@ -1,8 +1,8 @@
1
- import { t as tryDispose, i as isSpec, S as STORION_TYPE, r as resolveEquality, u as unwrapFn, m as shallowEqual } from "./store-BroaE7p4.js";
2
- import { n, l, g, a, h, d, f, k, e, j, b, p, s, o, w } from "./store-BroaE7p4.js";
3
- import { e as emitter, u as untrack, g as getHooks, w as withHooks } from "./emitter-BA44OHdL.js";
4
- import { b as b2 } from "./emitter-BA44OHdL.js";
5
- import { e as e2 } from "./effect-DPAYSuW3.js";
1
+ import { t as tryDispose, i as isSpec, S as STORION_TYPE, r as resolveEquality, u as unwrapFn, m as shallowEqual } from "./store-CwgUVEWv.js";
2
+ import { n, l, g, a, h, d, f, k, e, j, b, p, s, o, w } from "./store-CwgUVEWv.js";
3
+ import { e as emitter, u as untrack, g as getHooks, H as HooksContextError, w as withHooks } from "./emitter-XwTUpyGv.js";
4
+ import { A, E, I, c, L, P, a as a2, d as d2, S, b as b2 } from "./emitter-XwTUpyGv.js";
5
+ import { e as e2 } from "./effect-ByI1oRBq.js";
6
6
  function extractDisplayName(factory) {
7
7
  if (isSpec(factory)) {
8
8
  return factory.displayName;
@@ -268,9 +268,7 @@ function pick(selector, equality) {
268
268
  var _a;
269
269
  const parentHooks = getHooks();
270
270
  if (!parentHooks.onRead) {
271
- throw new Error(
272
- "pick() must be called inside an effect or useStore selector. It requires an active hooks.onRead context."
273
- );
271
+ throw new HooksContextError("pick", "an effect or useStore selector");
274
272
  }
275
273
  const equalityFn = resolveEquality(equality);
276
274
  const currentReads = [];
@@ -450,7 +448,17 @@ trigger.clearAll = () => {
450
448
  cache.clear();
451
449
  };
452
450
  export {
451
+ A as AsyncFunctionError,
452
+ E as EffectRefreshError,
453
+ HooksContextError,
454
+ I as InvalidActionError,
455
+ c as LifetimeMismatchError,
456
+ L as LocalStoreDependencyError,
457
+ P as ProviderMissingError,
453
458
  STORION_TYPE,
459
+ a2 as SetupPhaseError,
460
+ d2 as StoreDisposedError,
461
+ S as StorionError,
454
462
  applyExcept,
455
463
  applyFor,
456
464
  b2 as batch,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storion",
3
- "version": "0.7.1",
3
+ "version": "0.7.5",
4
4
  "description": "Reactive stores for modern apps. Type-safe. Auto-tracked. Effortlessly composable",
5
5
  "type": "module",
6
6
  "main": "./dist/storion.js",
@@ -46,9 +46,9 @@
46
46
  "version:minor": "npm version minor -m \"chore: bump version to %s\"",
47
47
  "version:major": "npm version major -m \"chore: bump version to %s\"",
48
48
  "prepublishOnly": "pnpm run build",
49
- "release:patch": "git status --porcelain | grep -q . && echo 'Error: uncommitted changes' && exit 1; pnpm version:patch && git add -A && git commit --amend --no-edit && git push && git push --tags && npm publish",
50
- "release:minor": "git status --porcelain | grep -q . && echo 'Error: uncommitted changes' && exit 1; pnpm version:minor && git add -A && git commit --amend --no-edit && git push && git push --tags && npm publish",
51
- "release:major": "git status --porcelain | grep -q . && echo 'Error: uncommitted changes' && exit 1; pnpm version:major && git add -A && git commit --amend --no-edit && git push && git push --tags && npm publish",
49
+ "release:patch": "git status --porcelain | grep -q . && echo 'Error: uncommitted changes' && exit 1; pnpm version:patch && git add -A && git commit --amend --no-edit && npm publish",
50
+ "release:minor": "git status --porcelain | grep -q . && echo 'Error: uncommitted changes' && exit 1; pnpm version:minor && git add -A && git commit --amend --no-edit && npm publish",
51
+ "release:major": "git status --porcelain | grep -q . && echo 'Error: uncommitted changes' && exit 1; pnpm version:major && git add -A && git commit --amend --no-edit && npm publish",
52
52
  "publish:dry": "npm publish --dry-run"
53
53
  },
54
54
  "keywords": [