@thoughtbot/superglue 2.0.0-alpha.1 → 2.0.0-alpha.10

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 { Action, ThunkDispatch, EnhancedStore, Tuple, StoreEnhancer, ThunkAction } from '@reduxjs/toolkit';
1
+ import { Action, EnhancedStore, Tuple, StoreEnhancer, ThunkDispatch, ThunkAction } from '@reduxjs/toolkit';
2
2
  import { History } from 'history';
3
3
 
4
4
  type FetchArgs = [string, BasicRequestInit];
@@ -42,8 +42,8 @@ interface RemoteProps extends BaseProps {
42
42
  pageKey?: PageKey;
43
43
  force?: boolean;
44
44
  }
45
- interface BeforeSave {
46
- <T extends PageResponse>(prevPage: SaveResponse, receivedPage: T): T;
45
+ interface BeforeSave<T = JSONMappable> {
46
+ <U extends SaveResponse<T> | GraftResponse<T>>(prevPage: Page<T>, receivedPage: U): U;
47
47
  }
48
48
  interface ApplicationRemote {
49
49
  (input: string | PageKey, options?: RemoteProps & {
@@ -69,6 +69,17 @@ declare const rootReducer: {
69
69
  fragments: typeof fragmentReducer;
70
70
  };
71
71
 
72
+ type FragmentProxy = {
73
+ __fragment: true;
74
+ };
75
+ type ProxiedContent<T> = T extends Fragment<infer U, true> ? ProxiedContent<U> & FragmentProxy : T extends Fragment<infer U, false | undefined> ? (ProxiedContent<U> & FragmentProxy) | undefined : T extends (infer U)[] ? ProxiedContent<U>[] : T extends object ? {
76
+ [K in keyof T]: ProxiedContent<T[K]>;
77
+ } : T;
78
+ type FragmentRefOrId = FragmentRef | string;
79
+ declare function useContent<T = JSONMappable>(): ProxiedContent<T>;
80
+ declare function useContent<T = JSONMappable>(fragmentRef: FragmentRefOrId): ProxiedContent<T>;
81
+ declare function unproxy<T>(proxy: T): Unproxy<T>;
82
+
72
83
  type PageKey = string;
73
84
  type RestoreStrategy = 'fromCacheOnly' | 'revisitOnly' | 'fromCacheAndRevisitInBackground';
74
85
  type NavigationAction = 'push' | 'replace' | 'none';
@@ -82,15 +93,13 @@ type JSONObject = {
82
93
  type JSONMappable = JSONValue[] | JSONObject;
83
94
  type JSONKeyable = JSONObject[] | JSONObject;
84
95
  type JSONValue = JSONPrimitive | JSONMappable;
85
- type Fragment<T> = {
96
+ type Fragment<T, Present = false> = {
86
97
  __id: string;
87
- } & {
88
98
  __fragmentType?: T;
99
+ __required?: Present extends boolean ? Present : false;
89
100
  };
90
- type Unproxied<T> = T extends Fragment<unknown> ? {
91
- __id: string;
92
- } : T extends (infer U)[] ? Unproxied<U>[] : T extends object ? {
93
- [K in keyof T]: Unproxied<T[K]>;
101
+ type Unproxy<T> = T extends FragmentProxy ? FragmentRef : T extends Fragment<unknown, unknown> ? FragmentRef : T extends (infer U)[] ? Unproxy<U>[] : T extends object ? {
102
+ [K in keyof T]: Unproxy<T[K]>;
94
103
  } : T;
95
104
  interface ParsedResponse {
96
105
  rsp: Response;
@@ -108,7 +117,7 @@ type SaveResponse<T = JSONMappable> = {
108
117
  componentIdentifier: ComponentIdentifier;
109
118
  assets: string[];
110
119
  csrfToken?: string;
111
- fragments: FragmentRef[];
120
+ fragments: FragmentPath[];
112
121
  defers: Defer[];
113
122
  slices: JSONObject;
114
123
  action: 'savePage';
@@ -123,34 +132,37 @@ type GraftResponse<T = JSONMappable> = {
123
132
  componentIdentifier: ComponentIdentifier;
124
133
  assets: string[];
125
134
  csrfToken?: string;
126
- fragments: FragmentRef[];
135
+ fragments: FragmentPath[];
127
136
  defers: Defer[];
128
137
  slices: JSONObject;
129
138
  action: 'graft';
130
139
  renderedAt: number;
131
- restoreStrategy: RestoreStrategy;
132
140
  path: Keypath;
133
141
  fragmentContext?: string;
134
142
  };
135
- type StreamMutateMessage = {
143
+ type StreamMessage = {
136
144
  data: JSONMappable;
137
145
  fragmentIds: string[];
138
146
  handler: 'append' | 'prepend' | 'save';
139
147
  options: Record<string, string>;
140
148
  };
141
149
  type StreamResponse = {
142
- data: StreamMutateMessage[];
143
- fragments: FragmentRef[];
150
+ data: StreamMessage[];
151
+ fragments: FragmentPath[];
144
152
  assets: string[];
145
153
  csrfToken?: string;
146
154
  action: 'handleStreamResponse';
147
155
  renderedAt: number;
156
+ slices: JSONObject;
148
157
  };
149
158
  type PageResponse = GraftResponse | SaveResponse | StreamResponse;
150
- type FragmentRef = {
159
+ type FragmentPath = {
151
160
  id: string;
152
161
  path: Keypath;
153
162
  };
163
+ type FragmentRef = {
164
+ __id: string;
165
+ };
154
166
  type AllPages<T = JSONMappable> = Record<PageKey, Page<T>>;
155
167
  type AllFragments = Record<string, JSONMappable>;
156
168
  interface SuperglueState {
@@ -268,4 +280,4 @@ declare const visit: VisitCreator;
268
280
 
269
281
  declare function saveAndProcessPage(pageKey: string, page: PageResponse): SaveAndProcessPageThunk;
270
282
 
271
- export { type Visit as $, type ApplicationRemote as A, type VisitCreator as B, type ComponentIdentifier as C, type Defer as D, type RemoteCreator as E, type FetchArgs as F, type GraftResponse as G, type Handlers as H, type Dispatch as I, type JSONMappable as J, type Keypath as K, type UJSHandlers as L, type Meta as M, type NavigationContextProps as N, type HistoryState as O, type PageKey as P, type SaveAndProcessPageThunk as Q, type RestoreStrategy as R, type SuperglueStore as S, type MetaThunk as T, type Unproxied as U, type VisitMeta as V, type VisitMetaThunk as W, type DefermentThunk as X, type BasicRequestInit as Y, type BuildStore as Z, type BuildVisitAndRemote as _, type JSONValue as a, type VisitProps as a0, type Remote as a1, type RemoteProps as a2, type BeforeSave as a3, type GraftingSuccessAction as a4, type GraftingErrorAction as a5, MismatchedComponentError as a6, remote as a7, visit as a8, type NavigationProviderProps as b, type NavigateTo as c, type SaveResponse as d, type SuperglueState as e, type SetupProps as f, type ApplicationVisit as g, type ApplicationProps as h, superglueReducer as i, type NavigationAction as j, type JSONPrimitive as k, type JSONObject as l, type JSONKeyable as m, type Fragment as n, type ParsedResponse as o, pageReducer as p, type Page as q, rootReducer as r, saveAndProcessPage as s, type StreamMutateMessage as t, type StreamResponse as u, type PageResponse as v, type FragmentRef as w, type AllPages as x, type AllFragments as y, type RootState as z };
283
+ export { type BasicRequestInit as $, type ApplicationRemote as A, type AllPages as B, type ComponentIdentifier as C, type Defer as D, type AllFragments as E, type FetchArgs as F, type GraftResponse as G, type Handlers as H, type RootState as I, type JSONMappable as J, type Keypath as K, type VisitCreator as L, type Meta as M, type NavigationProviderProps as N, type RemoteCreator as O, type PageKey as P, type Dispatch as Q, type RestoreStrategy as R, type SuperglueStore as S, type UJSHandlers as T, type Unproxy as U, type VisitMeta as V, type HistoryState as W, type SaveAndProcessPageThunk as X, type MetaThunk as Y, type VisitMetaThunk as Z, type DefermentThunk as _, type JSONValue as a, type BuildStore as a0, type BuildVisitAndRemote as a1, type Visit as a2, type VisitProps as a3, type Remote as a4, type RemoteProps as a5, type BeforeSave as a6, type GraftingSuccessAction as a7, type GraftingErrorAction as a8, useContent as a9, MismatchedComponentError as aa, remote as ab, visit as ac, type NavigateTo as b, type NavigationContextProps as c, type SaveResponse as d, type PageResponse as e, type Fragment as f, type FragmentProxy as g, type SuperglueState as h, type ApplicationProps as i, type SetupProps as j, type ApplicationVisit as k, superglueReducer as l, type NavigationAction as m, type JSONPrimitive as n, type JSONObject as o, pageReducer as p, type JSONKeyable as q, rootReducer as r, saveAndProcessPage as s, type ParsedResponse as t, unproxy as u, type Page as v, type StreamMessage as w, type StreamResponse as x, type FragmentPath as y, type FragmentRef as z };
@@ -1,8 +1,8 @@
1
1
  import * as history from 'history';
2
- import { J as JSONMappable, K as Keypath, a as JSONValue, P as PageKey, A as ApplicationRemote, S as SuperglueStore, N as NavigationContextProps, b as NavigationProviderProps, c as NavigateTo, d as SaveResponse, F as FetchArgs, U as Unproxied, e as SuperglueState, f as SetupProps, g as ApplicationVisit, H as Handlers, h as ApplicationProps } from './index-MyfFLe4E.mjs';
3
- export { y as AllFragments, x as AllPages, Y as BasicRequestInit, a3 as BeforeSave, Z as BuildStore, _ as BuildVisitAndRemote, C as ComponentIdentifier, D as Defer, X as DefermentThunk, I as Dispatch, n as Fragment, w as FragmentRef, G as GraftResponse, a5 as GraftingErrorAction, a4 as GraftingSuccessAction, O as HistoryState, m as JSONKeyable, l as JSONObject, k as JSONPrimitive, M as Meta, T as MetaThunk, j as NavigationAction, q as Page, v as PageResponse, o as ParsedResponse, a1 as Remote, E as RemoteCreator, a2 as RemoteProps, R as RestoreStrategy, z as RootState, Q as SaveAndProcessPageThunk, t as StreamMutateMessage, u as StreamResponse, L as UJSHandlers, $ as Visit, B as VisitCreator, V as VisitMeta, W as VisitMetaThunk, a0 as VisitProps, p as pageReducer, r as rootReducer, s as saveAndProcessPage, i as superglueReducer } from './index-MyfFLe4E.mjs';
2
+ import { J as JSONMappable, K as Keypath, a as JSONValue, P as PageKey, A as ApplicationRemote, S as SuperglueStore, N as NavigationProviderProps, b as NavigateTo, c as NavigationContextProps, F as FetchArgs, d as SaveResponse, e as PageResponse, f as Fragment, U as Unproxy, g as FragmentProxy, h as SuperglueState, i as ApplicationProps, j as SetupProps, k as ApplicationVisit, H as Handlers } from './index-j0c-9ZLt.mjs';
3
+ export { E as AllFragments, B as AllPages, $ as BasicRequestInit, a6 as BeforeSave, a0 as BuildStore, a1 as BuildVisitAndRemote, C as ComponentIdentifier, D as Defer, _ as DefermentThunk, Q as Dispatch, y as FragmentPath, z as FragmentRef, G as GraftResponse, a8 as GraftingErrorAction, a7 as GraftingSuccessAction, W as HistoryState, q as JSONKeyable, o as JSONObject, n as JSONPrimitive, M as Meta, Y as MetaThunk, m as NavigationAction, v as Page, t as ParsedResponse, a4 as Remote, O as RemoteCreator, a5 as RemoteProps, R as RestoreStrategy, I as RootState, X as SaveAndProcessPageThunk, w as StreamMessage, x as StreamResponse, T as UJSHandlers, a2 as Visit, L as VisitCreator, V as VisitMeta, Z as VisitMetaThunk, a3 as VisitProps, p as pageReducer, r as rootReducer, s as saveAndProcessPage, l as superglueReducer, u as unproxy, a9 as useContent } from './index-j0c-9ZLt.mjs';
4
4
  import React from 'react';
5
- import { Subscription, Consumer, ChannelNameWithParams } from '@rails/actioncable';
5
+ import { ChannelNameWithParams, Subscription } from '@rails/actioncable';
6
6
  import { DebouncedFunc } from 'lodash';
7
7
  import * as _reduxjs_toolkit from '@reduxjs/toolkit';
8
8
 
@@ -31,7 +31,7 @@ declare class StreamActions {
31
31
  }
32
32
  declare function useStreamSource(channel: StreamSourceProps): {
33
33
  connected: boolean;
34
- subscription: Subscription<Consumer> | null;
34
+ subscription: Subscription | null;
35
35
  };
36
36
 
37
37
  declare const NavigationContext: React.Context<NavigationContextProps>;
@@ -66,28 +66,19 @@ declare const beforeRemote: _reduxjs_toolkit.ActionCreatorWithPayload<{
66
66
  currentPageKey: PageKey;
67
67
  fetchArgs: FetchArgs;
68
68
  }, string>;
69
+ declare const receiveResponse: _reduxjs_toolkit.ActionCreatorWithPreparedPayload<[{
70
+ pageKey: string;
71
+ response: PageResponse;
72
+ }], {
73
+ pageKey: string;
74
+ response: PageResponse;
75
+ }, "@@superglue/RECEIVE_RESPONSE", never, never>;
69
76
 
70
- type ProxiedContent<T> = T & {
71
- readonly [K in keyof T]: T[K] extends {
72
- __id: string;
73
- } ? unknown : T[K] extends (infer U)[] ? ProxiedContent<U>[] : T[K] extends object ? ProxiedContent<T[K]> : T[K];
77
+ type Unpack<T> = T extends Fragment<infer U, unknown> ? U : T extends FragmentProxy ? T : never;
78
+ declare function useSetFragment(): {
79
+ <T extends Fragment<unknown, unknown>>(fragmentRef: T, updater: (draft: Unproxy<Unpack<T>>) => void): void;
80
+ <T = unknown>(fragmentId: string, updater: (draft: T) => void): void;
74
81
  };
75
- type FragmentRef = {
76
- __id: string;
77
- } | string;
78
- declare function useContent<T = JSONMappable>(): ProxiedContent<T>;
79
- declare function useContent<T = JSONMappable>(fragmentRef: FragmentRef): ProxiedContent<T>;
80
- declare function useContent<T = JSONMappable>(fragmentRef: FragmentRef, options: {
81
- optional: false;
82
- }): ProxiedContent<T>;
83
- declare function useContent<T = JSONMappable>(fragmentRef: FragmentRef, options: {
84
- optional: true;
85
- }): ProxiedContent<T> | undefined;
86
- declare function unproxy<T>(proxy: T): Unproxied<T>;
87
-
88
- declare function useSetFragment(): (fragmentRef: {
89
- __id: string;
90
- } | string, updater: (draft: unknown) => void) => void;
91
82
 
92
83
  declare function useSuperglue(): SuperglueState;
93
84
 
@@ -102,4 +93,4 @@ declare const setup: ({ initialPage, baseUrl, path, store, buildVisitAndRemote,
102
93
  };
103
94
  declare function Application({ initialPage, baseUrl, path, store, buildVisitAndRemote, history, mapping, ...rest }: ApplicationProps): React.JSX.Element;
104
95
 
105
- export { Application, ApplicationProps, ApplicationRemote, ApplicationVisit, FetchArgs, GRAFTING_ERROR, GRAFTING_SUCCESS, Handlers, JSONMappable, JSONValue, Keypath, NavigateTo, NavigationContext, NavigationContextProps, NavigationProvider, NavigationProviderProps, PageKey, SaveResponse, SetupProps, SuperglueState, SuperglueStore, Unproxied, beforeFetch, beforeRemote, beforeVisit, copyPage, getIn, prepareStore, removePage, saveResponse, setup, unproxy, urlToPageKey, useContent, useSetFragment, useStreamSource, useSuperglue };
96
+ export { Application, ApplicationProps, ApplicationRemote, ApplicationVisit, FetchArgs, Fragment, GRAFTING_ERROR, GRAFTING_SUCCESS, Handlers, JSONMappable, JSONValue, Keypath, NavigateTo, NavigationContext, NavigationContextProps, NavigationProvider, NavigationProviderProps, PageKey, PageResponse, SaveResponse, SetupProps, SuperglueState, SuperglueStore, Unproxy, beforeFetch, beforeRemote, beforeVisit, copyPage, getIn, prepareStore, receiveResponse, removePage, saveResponse, setup, urlToPageKey, useSetFragment, useStreamSource, useSuperglue };