@valbuild/shared 0.57.0 → 0.59.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.
@@ -0,0 +1,46 @@
1
+ import { Json, ModuleId, PatchId, SerializedSchema, ValApi } from "@valbuild/core";
2
+ import { result } from "@valbuild/core/fp";
3
+ import { Patch, PatchError } from "@valbuild/core/patch";
4
+ export declare class ValStore {
5
+ private readonly api;
6
+ private readonly subscribers;
7
+ private readonly listeners;
8
+ private readonly drafts;
9
+ private readonly schema;
10
+ constructor(api: ValApi);
11
+ getModule(moduleId: ModuleId, refetch?: boolean): Promise<result.Ok<{
12
+ source: Json;
13
+ schema: SerializedSchema;
14
+ }> | result.Err<{
15
+ message: string;
16
+ }>>;
17
+ applyPatch(moduleId: ModuleId, patch: Patch): Promise<result.Result<Record<ModuleId, {
18
+ patch_id: PatchId;
19
+ }>, PatchError | {
20
+ message: string;
21
+ }>>;
22
+ update(moduleIds: ModuleId[]): Promise<void>;
23
+ reset(): Promise<result.Result<ModuleId[], {
24
+ message: string;
25
+ details: {
26
+ fetchError: {
27
+ message: string;
28
+ statusCode?: number | undefined;
29
+ };
30
+ };
31
+ }>>;
32
+ updateTree(treePath?: string): Promise<result.Result<ModuleId[], {
33
+ message: string;
34
+ details: {
35
+ fetchError: {
36
+ message: string;
37
+ statusCode?: number;
38
+ };
39
+ };
40
+ }>>;
41
+ subscribe: (moduleIds: ModuleId[]) => (listener: () => void) => () => void;
42
+ private emitChange;
43
+ getSnapshot: (moduleIds: ModuleId[]) => () => Record<ModuleId, Json> | undefined;
44
+ getServerSnapshot: (moduleIds: ModuleId[]) => () => Record<ModuleId, Json> | undefined;
45
+ get: (moduleIds: ModuleId[]) => Record<ModuleId, Json> | undefined;
46
+ }
@@ -1,4 +1,4 @@
1
1
  export * from "./richtext/conversion/index.js";
2
2
  export * from "./mimeType/index.js";
3
3
  export * from "./server/types.js";
4
- export * from "./IValStore.js";
4
+ export * from "./ValStore.js";
@@ -1,4 +1,4 @@
1
- import { ApiTreeResponse, Json } from "@valbuild/core";
1
+ import { ApiPostValidationErrorResponse, ApiTreeResponse, Json } from "@valbuild/core";
2
2
  export declare const VAL_SESSION_COOKIE: "val_session";
3
3
  export declare const VAL_STATE_COOKIE: "val_state";
4
4
  export declare const VAL_ENABLE_COOKIE_NAME: "val_enable";
@@ -38,11 +38,17 @@ export type ValServerResult<Names extends ValCookiesNames, Body extends string |
38
38
  cookies?: ValServerResultCookies<Names>;
39
39
  body?: Body;
40
40
  } | ValServerError;
41
- export type ValServerJsonResult<Body extends Json | ApiTreeResponse | never = never> = {
41
+ export type ValServerJsonResult<Body extends Json | ApiPostValidationErrorResponse | ApiTreeResponse | never = never, Error extends Json | ApiPostValidationErrorResponse | never = never> = {
42
42
  status: 200 | 201;
43
43
  json: Body;
44
- } | ValServerError;
45
- export type ValServerGenericResult = ValServerJsonResult<Json> | ValServerError | ValServerRedirectResult<ValCookiesNames> | ValServerResult<ValCookiesNames, string | ReadableStream<Uint8Array>>;
44
+ } | ValServerError | (Error extends Json | ApiPostValidationErrorResponse ? {
45
+ status: 400;
46
+ json: Error;
47
+ } : never);
48
+ export type ValServerGenericResult = ValServerJsonResult<Json> | ValServerError | {
49
+ status: 400;
50
+ json: ApiPostValidationErrorResponse;
51
+ } | ValServerRedirectResult<ValCookiesNames> | ValServerResult<ValCookiesNames, string | ReadableStream<Uint8Array>>;
46
52
  export type ValUIRequestHandler = (path: string, url: string) => Promise<ValServerGenericResult>;
47
53
  export type ValSession = {
48
54
  mode: "unauthorized";