cogsbox-state 0.5.434 → 0.5.435

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.
@@ -113,7 +113,9 @@ export type InsertParams<S> = S | ((prevState: {
113
113
  state: S;
114
114
  uuid: string;
115
115
  }) => S);
116
- export type UpdateType<T> = (payload: UpdateArg<T>) => void;
116
+ export type UpdateType<T> = (payload: UpdateArg<T>) => {
117
+ synced: () => void;
118
+ };
117
119
  export type InsertType<T> = (payload: InsertParams<T>, index?: number) => void;
118
120
  export type InsertTypeObj<T> = (payload: InsertParams<T>) => void;
119
121
  export type ValidationError = {
@@ -193,10 +195,18 @@ type ValidationOptionsType = {
193
195
  zodSchema?: z.ZodTypeAny;
194
196
  onBlur?: boolean;
195
197
  };
198
+ type SyncApi = {
199
+ updateState: (data: {
200
+ operation: any;
201
+ }) => void;
202
+ connected: boolean;
203
+ clientId: string | null;
204
+ subscribers: string[];
205
+ };
196
206
  export type OptionsType<T extends unknown = unknown> = {
197
207
  log?: boolean;
198
208
  componentId?: string;
199
- serverSync?: ServerSyncType<T>;
209
+ cogsSync?: (stateObject: StateObject<T>) => SyncApi;
200
210
  validation?: ValidationOptionsType;
201
211
  serverState?: {
202
212
  id?: string | number;
@@ -237,24 +247,6 @@ export type OptionsType<T extends unknown = unknown> = {
237
247
  defaultState?: T;
238
248
  dependencies?: any[];
239
249
  };
240
- export type ServerSyncType<T> = {
241
- testKey?: string;
242
- syncKey: (({ state }: {
243
- state: T;
244
- }) => string) | string;
245
- syncFunction: ({ state }: {
246
- state: T;
247
- }) => void;
248
- debounce?: number;
249
- snapshot?: {
250
- name: (({ state }: {
251
- state: T;
252
- }) => string) | string;
253
- stateKeys: StateKeys[];
254
- currentUrl: string;
255
- currentParams?: URLSearchParams;
256
- };
257
- };
258
250
  export type ValidationWrapperOptions<T extends unknown = unknown> = {
259
251
  children: React.ReactNode;
260
252
  active: boolean;
@@ -304,7 +296,7 @@ type LocalStorageData<T> = {
304
296
  stateSource?: 'default' | 'server' | 'localStorage';
305
297
  };
306
298
  export declare const notifyComponent: (stateKey: string, componentId: string) => void;
307
- export declare function useCogsStateFn<TStateObject extends unknown>(stateObject: TStateObject, { stateKey, serverSync, localStorage, formElements, reactiveDeps, reactiveType, componentId, defaultState, syncUpdate, dependencies, serverState, }?: {
299
+ export declare function useCogsStateFn<TStateObject extends unknown>(stateObject: TStateObject, { stateKey, localStorage, formElements, reactiveDeps, reactiveType, componentId, defaultState, syncUpdate, dependencies, serverState, }?: {
308
300
  stateKey?: string;
309
301
  componentId?: string;
310
302
  defaultState?: TStateObject;