@magnetarjs/types
Advanced tools
Comparing version 0.8.2 to 0.8.3
@@ -1,3 +0,2 @@ | ||
import { PartialDeep } from 'type-fest'; | ||
import { U, O } from 'ts-toolbelt'; | ||
import { UnionToIntersection, PartialDeep, Spread } from 'type-fest'; | ||
@@ -48,3 +47,3 @@ /** | ||
*/ | ||
declare type OPaths<T, D extends number = 10> = [D] extends [never] ? never : U.Intersect<T, null | undefined> extends never ? T extends Record<string, any> ? { | ||
declare type OPaths<T, D extends number = 10> = [D] extends [never] ? never : UnionToIntersection<T | null | undefined> extends never ? T extends Record<string, any> ? { | ||
[K in keyof T]-?: K extends string ? `${K}` | Join<K, OPaths<T[K], Prev[D]>> : never; | ||
@@ -57,3 +56,3 @@ }[keyof T] : '' : ''; | ||
*/ | ||
declare type OLeaves<T, D extends number = 10> = [D] extends [never] ? '' : U.Intersect<T, null | undefined> extends never ? T extends Record<string, any> ? { | ||
declare type OLeaves<T, D extends number = 10> = [D] extends [never] ? '' : UnionToIntersection<T | null | undefined> extends never ? T extends Record<string, any> ? { | ||
[K in keyof T]-?: IsFullStringLiteral<K> extends true ? Join<K, OLeaves<T[K], Prev[D]>> : ''; | ||
@@ -76,3 +75,3 @@ }[keyof T] : '' : ''; | ||
*/ | ||
doc: DocFn<DocDataType, GranularTypes>; | ||
doc: DocFn<DocDataType>; | ||
/** | ||
@@ -116,3 +115,3 @@ * The id of the collection. When this is a nested collection, it will not include the full path, only the final part | ||
*/ | ||
stream: MagnetarStreamAction; | ||
stream: MagnetarStreamAction<DocDataType>; | ||
/** | ||
@@ -148,3 +147,3 @@ * @see {@link MagnetarInsertAction} | ||
*/ | ||
declare type ModifyWritePayload = (payload: Record<string, any>, docId?: string | void) => Record<string, any>; | ||
declare type ModifyWritePayload<DocDataType extends Record<string, any> = Record<string, any>> = (payload: PartialDeep<DocDataType>, docId?: string | void) => PartialDeep<DocDataType>; | ||
/** | ||
@@ -161,8 +160,8 @@ * This function will be executed everytime BEFORE the related action is triggered. The function defined will receive the payload of the action. You can then modify and return this payload. | ||
*/ | ||
declare type ModifyPayloadFnMap = { | ||
insert?: ModifyWritePayload; | ||
merge?: ModifyWritePayload; | ||
assign?: ModifyWritePayload; | ||
replace?: ModifyWritePayload; | ||
write?: ModifyWritePayload; | ||
declare type ModifyPayloadFnMap<DocDataType extends Record<string, any> = Record<string, any>> = { | ||
insert?: ModifyWritePayload<DocDataType>; | ||
merge?: ModifyWritePayload<DocDataType>; | ||
assign?: ModifyWritePayload<DocDataType>; | ||
replace?: ModifyWritePayload<DocDataType>; | ||
write?: ModifyWritePayload<DocDataType>; | ||
deleteProp?: ModifyDeletePropPayload; | ||
@@ -206,7 +205,7 @@ read?: ModifyReadPayload; | ||
*/ | ||
declare type OnAddedFn = (docData: Record<string, any> | undefined, docMetadata: DocMetadata) => Record<string, any> | void; | ||
declare type OnAddedFn<DocDataType extends Record<string, any> = Record<string, any>> = (docData: PartialDeep<DocDataType>, docMetadata: DocMetadata) => DocDataType | void; | ||
/** | ||
* Is triggered only while a 'stream' is open, and can modify docs that were modified on another client, before they are updated to the store data. When returning `undefined` they will be discarded & the modifications won't be applied to the store data. | ||
*/ | ||
declare type OnModifiedFn = (docData: Record<string, any> | undefined, docMetadata: DocMetadata) => Record<string, any> | void; | ||
declare type OnModifiedFn<DocDataType extends Record<string, any> = Record<string, any>> = (docData: PartialDeep<DocDataType>, docMetadata: DocMetadata) => PartialDeep<DocDataType> | void; | ||
/** | ||
@@ -219,11 +218,11 @@ * Is triggered only while a 'stream' is open, every time a document is either 'deleted' on another client OR if a document doesn't adhere to the clauses of that 'stream' anymore. When returning `undefined` they will not be removed from the store data. | ||
*/ | ||
interface ModifyReadResponseFnMap { | ||
declare type ModifyReadResponseFnMap<DocDataType extends Record<string, any> = Record<string, any>> = { | ||
/** | ||
* Can be used to modify docs that come in from 'stream' or 'fetch' actions, before they are added to your store data. When returning `undefined` they will be discarded & won't be added to the store data. | ||
*/ | ||
added?: OnAddedFn; | ||
added?: OnAddedFn<DocDataType>; | ||
/** | ||
* Is triggered only while a 'stream' is open, and can modify docs that were modified on another client, before they are updated to the store data. When returning `undefined` they will be discarded & the modifications won't be applied to the store data. | ||
*/ | ||
modified?: OnModifiedFn; | ||
modified?: OnModifiedFn<DocDataType>; | ||
/** | ||
@@ -233,3 +232,3 @@ * Is triggered only while a 'stream' is open, every time a document is either 'deleted' on another client OR if a document doesn't adhere to the clauses of that 'stream' anymore. When returning `undefined` they will not be removed from the store data. | ||
removed?: OnRemovedFn; | ||
} | ||
}; | ||
/** | ||
@@ -291,3 +290,3 @@ * These functions will be executed everytime BEFORE documents are added/modified/deleted in your local data store. The function defined will receive the payload with changes from the server. You can then modify and return this payload. | ||
*/ | ||
declare type PluginModuleConfig = O.Patch<Clauses, { | ||
declare type PluginModuleConfig = Spread<Clauses, { | ||
[key in string]: any; | ||
@@ -333,3 +332,3 @@ }>; | ||
}; | ||
declare type PluginStreamActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
declare type PluginStreamActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = Spread<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
/** | ||
@@ -349,3 +348,3 @@ * Whatever payload was passed to the action that was triggered | ||
declare type PluginStreamAction = (payload: PluginStreamActionPayload) => StreamResponse | DoOnStream | Promise<StreamResponse | DoOnStream>; | ||
declare type PluginFetchActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
declare type PluginFetchActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = Spread<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
/** | ||
@@ -362,3 +361,3 @@ * Whatever payload was passed to the action that was triggered | ||
declare type PluginFetchAction = (payload: PluginFetchActionPayload) => FetchResponse | DoOnFetch | Promise<FetchResponse | DoOnFetch>; | ||
declare type PluginWriteActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
declare type PluginWriteActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = Spread<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
/** | ||
@@ -376,3 +375,3 @@ * Whatever payload was passed to the action that was triggered | ||
declare type PluginWriteAction = (payload: PluginWriteActionPayload) => void | Promise<void | SyncBatch>; | ||
declare type PluginInsertActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
declare type PluginInsertActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = Spread<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
/** | ||
@@ -390,3 +389,3 @@ * Whatever payload was passed to the action that was triggered | ||
declare type PluginInsertAction = (payload: PluginInsertActionPayload) => string | Promise<string | [string, SyncBatch]>; | ||
declare type PluginDeletePropActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
declare type PluginDeletePropActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = Spread<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
/** | ||
@@ -408,3 +407,3 @@ * Whatever payload was passed to the action that was triggered | ||
declare type PluginDeletePropAction = (payload: PluginDeletePropActionPayload) => void | Promise<void | SyncBatch>; | ||
declare type PluginDeleteActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
declare type PluginDeleteActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = Spread<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
/** | ||
@@ -422,3 +421,3 @@ * Whatever payload was passed to the action that was triggered | ||
declare type PluginDeleteAction = (payload: PluginDeleteActionPayload) => void | Promise<void | SyncBatch>; | ||
declare type PluginRevertActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
declare type PluginRevertActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = Spread<PluginActionPayloadBase<SpecificPluginModuleConfig>, { | ||
/** | ||
@@ -487,3 +486,3 @@ * Whatever payload was passed to the action that was triggered | ||
*/ | ||
declare type MustExecuteOnRead = O.Compulsory<DoOnStream>; | ||
declare type MustExecuteOnRead = Required<DoOnStream>; | ||
/** | ||
@@ -548,7 +547,7 @@ * Plugin's response to a 'fetch' action, when acting as a "remote" Store Plugin. | ||
declare type EventFnBefore = (args: EventSharedPayload) => void | Promise<void>; | ||
declare type EventFnSuccess = (args: O.Patch<EventSharedPayload, EventPayloadPropResult>) => void | Promise<void>; | ||
declare type EventFnError = (args: O.Patch<EventSharedPayload, { | ||
declare type EventFnSuccess = (args: Spread<EventSharedPayload, EventPayloadPropResult>) => void | Promise<void>; | ||
declare type EventFnError = (args: Spread<EventSharedPayload, { | ||
error: any; | ||
}>) => void | Promise<void>; | ||
declare type EventFnRevert = (args: O.Patch<O.Omit<EventSharedPayload, 'abort'>, { | ||
declare type EventFnRevert = (args: Spread<Omit<EventSharedPayload, 'abort'>, { | ||
result: unknown; | ||
@@ -605,3 +604,3 @@ }>) => void | Promise<void>; | ||
*/ | ||
declare type ModuleConfig = { | ||
declare type ModuleConfig<DocDataType extends Record<string, any> = Record<string, any>> = { | ||
where?: WhereClause[]; | ||
@@ -613,4 +612,4 @@ orderBy?: OrderByClause[]; | ||
onError?: 'revert' | 'continue' | 'stop'; | ||
modifyPayloadOn?: ModifyPayloadFnMap; | ||
modifyReadResponseOn?: ModifyReadResponseFnMap; | ||
modifyPayloadOn?: ModifyPayloadFnMap<DocDataType>; | ||
modifyReadResponseOn?: ModifyReadResponseFnMap<DocDataType>; | ||
on?: EventNameFnMap; | ||
@@ -629,3 +628,3 @@ /** | ||
interface MagnetarInstance { | ||
globalConfig: O.Compulsory<GlobalConfig>; | ||
globalConfig: Required<GlobalConfig>; | ||
/** | ||
@@ -667,3 +666,3 @@ * @see {@link CollectionFn} | ||
insert: DocDataType; | ||
}>(idOrPath: string, moduleConfig?: ModuleConfig) => CollectionInstance<DocDataType, GranularTypes>; | ||
}>(idOrPath: string, moduleConfig?: ModuleConfig<DocDataType>) => CollectionInstance<DocDataType, GranularTypes>; | ||
/** | ||
@@ -673,11 +672,7 @@ * This is the `doc()` method type. | ||
*/ | ||
declare type DocFn<DocDataTypeInherited extends Record<string, any> = Record<string, any>, GranularTypesInherited extends { | ||
declare type DocFn<DocDataTypeInherited extends Record<string, any> = Record<string, any>> = <DocDataType extends Record<string, any> = DocDataTypeInherited, GranularTypes extends { | ||
insert: Record<string, any>; | ||
} = { | ||
insert: DocDataTypeInherited; | ||
}> = <DocDataType extends Record<string, any> = DocDataTypeInherited, GranularTypes extends { | ||
insert: Record<string, any>; | ||
} = DocDataType extends DocDataTypeInherited ? GranularTypesInherited : { | ||
insert: DocDataType; | ||
}>(idOrPath: string, moduleConfig?: ModuleConfig) => DocInstance<DocDataType, GranularTypes>; | ||
}>(idOrPath: string, moduleConfig?: ModuleConfig<DocDataType>) => DocInstance<DocDataType, GranularTypes>; | ||
@@ -729,3 +724,3 @@ declare type DocInstance<DocDataType extends Record<string, any> = Record<string, any>, GranularTypes extends { | ||
*/ | ||
stream: MagnetarStreamAction; | ||
stream: MagnetarStreamAction<DocDataType>; | ||
/** | ||
@@ -772,7 +767,7 @@ * @see {@link MagnetarInsertAction} | ||
*/ | ||
declare type ActionConfig = { | ||
declare type ActionConfig<DocDataType extends Record<string, any> = Record<string, any>> = { | ||
executionOrder?: StoreName[]; | ||
onError?: 'revert' | 'continue' | 'stop'; | ||
modifyPayloadOn?: ModifyPayloadFnMap; | ||
modifyReadResponseOn?: ModifyReadResponseFnMap; | ||
modifyPayloadOn?: ModifyPayloadFnMap<DocDataType>; | ||
modifyReadResponseOn?: ModifyReadResponseFnMap<DocDataType>; | ||
on?: EventNameFnMap; | ||
@@ -788,4 +783,9 @@ /** | ||
*/ | ||
declare type MagnetarStreamAction = (payload?: any | void, actionConfig?: ActionConfig) => Promise<void>; | ||
declare type MagnetarStreamAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload?: any | void, | ||
/** | ||
* TODO | ||
* @deprecated — should deprecated this "general" action config and replace with one specific for this action | ||
*/ | ||
actionConfig?: ActionConfig<DocDataType>) => Promise<void>; | ||
/** | ||
* Fetches document(s) and adds the data to your local store's state. | ||
@@ -810,4 +810,9 @@ * Fetch is optimistic by default — if it can find the doc's data in your local state, it will return that and prevent any remote fetches. | ||
force?: boolean; | ||
} | Record<string, any> | void, actionConfig?: ActionConfig) => Promise<calledFrom extends 'collection' ? Map<string, DocDataType> : DocDataType | undefined>; | ||
} | Record<string, any> | void, | ||
/** | ||
* TODO | ||
* @deprecated — should deprecated this "general" action config and replace with one specific for this action | ||
*/ | ||
actionConfig?: ActionConfig<DocDataType>) => Promise<calledFrom extends 'collection' ? Map<string, DocDataType> : DocDataType | undefined>; | ||
/** | ||
* @returns The new `doc()` instance after inserting. You can access the inserted `id` by checking this returned instance. | ||
@@ -819,12 +824,27 @@ * @example | ||
*/ | ||
declare type MagnetarInsertAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload: DocDataType, actionConfig?: ActionConfig) => Promise<DocInstance<DocDataType>>; | ||
declare type MagnetarInsertAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload: DocDataType, | ||
/** | ||
* TODO | ||
* @deprecated — should deprecated this "general" action config and replace with one specific for this action | ||
*/ | ||
actionConfig?: ActionConfig<DocDataType>) => Promise<DocInstance<DocDataType>>; | ||
/** | ||
* @returns the new document data after applying the changes to the local document (including any modifications from modifyPayloadOn) | ||
*/ | ||
declare type MagnetarWriteAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload: PartialDeep<DocDataType>, actionConfig?: ActionConfig) => Promise<DocDataType>; | ||
declare type MagnetarWriteAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload: PartialDeep<DocDataType>, | ||
/** | ||
* TODO | ||
* @deprecated — should deprecated this "general" action config and replace with one specific for this action | ||
*/ | ||
actionConfig?: ActionConfig<DocDataType>) => Promise<DocDataType>; | ||
/** | ||
* @returns the new document data after applying the changes to the local document (including any modifications from modifyPayloadOn) | ||
*/ | ||
declare type MagnetarDeletePropAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload: keyof DocDataType | string | (keyof DocDataType | string)[], actionConfig?: ActionConfig) => Promise<Partial<DocDataType>>; | ||
declare type MagnetarDeletePropAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload: keyof DocDataType | string | (keyof DocDataType | string)[], | ||
/** | ||
* TODO | ||
* @deprecated — should deprecated this "general" action config and replace with one specific for this action | ||
*/ | ||
actionConfig?: ActionConfig<DocDataType>) => Promise<Partial<DocDataType>>; | ||
/** | ||
* @param {*} [payload] When executing on a doc: no payload needed. When executing on a collection: you need to pass the document ID you want to delete. | ||
@@ -835,4 +855,9 @@ * @param {ActionConfig} [actionConfig] | ||
*/ | ||
declare type MagnetarDeleteAction = (payload?: any, actionConfig?: ActionConfig) => Promise<void>; | ||
declare type MagnetarDeleteAction = (payload?: any, | ||
/** | ||
* TODO | ||
* @deprecated — should deprecated this "general" action config and replace with one specific for this action | ||
*/ | ||
actionConfig?: ActionConfig) => Promise<void>; | ||
/** | ||
* All fetch promises with the payload passed to `fetch(payload)` as key (JSON.stringify) and the "fetch promise" as value. In case `fetch()` had no payload, use `undefined` | ||
@@ -839,0 +864,0 @@ */ |
{ | ||
"name": "@magnetarjs/types", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"sideEffects": false, | ||
@@ -23,3 +23,2 @@ "description": "Magnetar shared types", | ||
"dependencies": { | ||
"ts-toolbelt": "^9.6.0", | ||
"type-fest": "^3.2.0" | ||
@@ -26,0 +25,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42837
1
892
- Removedts-toolbelt@^9.6.0
- Removedts-toolbelt@9.6.0(transitive)