@merkaly/nuxt 0.13.0 → 0.13.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.
package/README.md CHANGED
@@ -67,7 +67,7 @@ export default defineNuxtPlugin(() => {
67
67
  });
68
68
  ```
69
69
 
70
- A loader returns an adapter (`withAdapter()` result, preferably with `immediate: false`, the bootstrap runs it), a promise or a plain value. An adapter with an api error, or a rejected promise, fails the stage. Every stage is optional: an app without loaders skips it.
70
+ A loader returns an adapter (`withAdapter()` result, preferably with `immediate: false`, the bootstrap runs it), a promise or a plain value. An adapter with an api error, an empty `data`, or a rejected promise, fails the stage. The adapter `data` may be typed `T | undefined` (the usual `default: () => undefined`). Every stage is optional: an app without loaders skips it.
71
71
 
72
72
  Two composables hold the state, shared by the whole app:
73
73
 
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.14.0"
6
6
  },
7
- "version": "0.13.0",
7
+ "version": "0.13.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -101,10 +101,10 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
101
101
  }>, {
102
102
  title: string;
103
103
  disabled: boolean;
104
+ multiple: boolean;
104
105
  accept: string[];
105
106
  hint: string;
106
107
  maxSize: number;
107
- multiple: boolean;
108
108
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
109
109
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
110
110
  declare const _default: typeof __VLS_export;
@@ -101,10 +101,10 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
101
101
  }>, {
102
102
  title: string;
103
103
  disabled: boolean;
104
+ multiple: boolean;
104
105
  accept: string[];
105
106
  hint: string;
106
107
  maxSize: number;
107
- multiple: boolean;
108
108
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
109
109
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
110
110
  declare const _default: typeof __VLS_export;
@@ -7,8 +7,8 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
7
7
  type: import("vue").PropType<string>;
8
8
  };
9
9
  }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
10
- "update:modelValue": (value: string) => any;
11
10
  change: () => any;
11
+ "update:modelValue": (value: string) => any;
12
12
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
13
13
  debounce: {
14
14
  type: NumberConstructor;
@@ -18,8 +18,8 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
18
18
  type: import("vue").PropType<string>;
19
19
  };
20
20
  }>> & Readonly<{
21
- "onUpdate:modelValue"?: ((value: string) => any) | undefined;
22
21
  onChange?: (() => any) | undefined;
22
+ "onUpdate:modelValue"?: ((value: string) => any) | undefined;
23
23
  }>, {
24
24
  debounce: number;
25
25
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -7,8 +7,8 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
7
7
  type: import("vue").PropType<string>;
8
8
  };
9
9
  }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
10
- "update:modelValue": (value: string) => any;
11
10
  change: () => any;
11
+ "update:modelValue": (value: string) => any;
12
12
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
13
13
  debounce: {
14
14
  type: NumberConstructor;
@@ -18,8 +18,8 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
18
18
  type: import("vue").PropType<string>;
19
19
  };
20
20
  }>> & Readonly<{
21
- "onUpdate:modelValue"?: ((value: string) => any) | undefined;
22
21
  onChange?: (() => any) | undefined;
22
+ "onUpdate:modelValue"?: ((value: string) => any) | undefined;
23
23
  }>, {
24
24
  debounce: number;
25
25
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -1,10 +1,10 @@
1
1
  import { useAuth } from "../composables/useAuth.js";
2
2
  import { inApp, runBootstrapStage, useBootstrapState } from "./state.js";
3
3
  export const runBootstrap = async (nuxtApp) => {
4
- const { error, fail, isAuthenticated, token } = inApp(nuxtApp, useAuth);
4
+ const { error, fail, isAuthenticated, token } = await inApp(nuxtApp, useAuth);
5
5
  if (error.value || nuxtApp.payload.error) return;
6
- const failStage = (stage) => {
7
- const reason = inApp(nuxtApp, () => useBootstrapState(stage)).error.value;
6
+ const failStage = async (stage) => {
7
+ const reason = (await inApp(nuxtApp, () => useBootstrapState(stage))).error.value;
8
8
  return fail({ message: reason?.message || `${stage} failed`, stage, status: reason?.status });
9
9
  };
10
10
  if (!await runBootstrapStage(nuxtApp, "organization")) return failStage("organization");
@@ -11,10 +11,14 @@ export interface BootstrapError {
11
11
  status?: number;
12
12
  }
13
13
  interface AdapterLike<T> {
14
- data: Ref<T>;
15
- error: Ref<unknown>;
14
+ readonly data: {
15
+ readonly value: T | null | undefined;
16
+ };
17
+ readonly error: {
18
+ readonly value: unknown;
19
+ };
16
20
  execute: () => Promise<void>;
17
- loading: Ref<boolean>;
21
+ readonly loading: Ref<boolean>;
18
22
  }
19
23
  export type BootstrapLoader<T = unknown> = () => T | Promise<T> | AdapterLike<T>;
20
24
  export interface BootstrapLoaders {
@@ -25,7 +29,7 @@ interface StageData {
25
29
  organization: MerkalyOrganization;
26
30
  user: MerkalyUser;
27
31
  }
28
- export declare const inApp: <T>(nuxtApp: NuxtApp, fn: () => T) => T;
32
+ export declare const inApp: <T>(nuxtApp: NuxtApp, fn: () => T) => Promise<T>;
29
33
  export declare const registerBootstrapLoaders: (nuxtApp: NuxtApp, loaders: BootstrapLoaders) => void;
30
34
  export declare const useBootstrapState: <S extends BootstrapStage>(stage: S) => {
31
35
  data: Ref<StageData[S] | undefined, StageData[S] | undefined>;
@@ -1,6 +1,6 @@
1
1
  import { computed, useState } from "#imports";
2
2
  import { until } from "@vueuse/core";
3
- export const inApp = (nuxtApp, fn) => nuxtApp.runWithContext(fn);
3
+ export const inApp = async (nuxtApp, fn) => await nuxtApp.runWithContext(fn);
4
4
  const registry = /* @__PURE__ */ new WeakMap();
5
5
  export const registerBootstrapLoaders = (nuxtApp, loaders) => {
6
6
  registry.set(nuxtApp, { ...registry.get(nuxtApp), ...loaders });
@@ -24,13 +24,14 @@ const resolveLoader = async (nuxtApp, loader) => {
24
24
  if (result.loading.value) await until(result.loading).toBe(false);
25
25
  else await result.execute();
26
26
  if (result.error.value) throw result.error.value;
27
+ if (result.data.value == null) throw new Error("Empty response");
27
28
  return result.data.value;
28
29
  };
29
- export const runBootstrapStage = (nuxtApp, stage, { force = false } = {}) => {
30
+ export const runBootstrapStage = async (nuxtApp, stage, { force = false } = {}) => {
30
31
  const loader = registry.get(nuxtApp)?.[stage];
31
- const { data, error, status } = inApp(nuxtApp, () => useBootstrapState(stage));
32
- if (!loader) return Promise.resolve(true);
33
- if (status.value === "success" && !force) return Promise.resolve(true);
32
+ const { data, error, status } = await inApp(nuxtApp, () => useBootstrapState(stage));
33
+ if (!loader) return true;
34
+ if (status.value === "success" && !force) return true;
34
35
  status.value = "pending";
35
36
  error.value = void 0;
36
37
  return resolveLoader(nuxtApp, loader).then((value) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merkaly/nuxt",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/merkaly-io/nuxt.git"