Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@magnetarjs/types

Package Overview
Dependencies
Maintainers
3
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@magnetarjs/types - npm Package Compare versions

Comparing version 1.1.0 to 1.2.1

4

dist/Collection.d.ts

@@ -29,7 +29,7 @@ import { DocFn } from './Magnetar.js';

/**
* Holds the fetched "sum" of the fields on which you called `fetchSum()` so far. This only gets updated when `fetchSum` is called, it is not automatically updated when local `data` changes.
* Holds the fetched "sum" of the fields on which you called `fetchSum()` so far. This only gets updated when `fetchSum` is called, it is not automatically updated when local cached `data` changes.
*/
sum: PartialDeep<PickNumbers<DocDataType>>;
/**
* Holds the fetched "average" of the fields on which you called `fetchAverage()` so far. This only gets updated when `fetchAverage` is called, it is not automatically updated when local `data` changes.
* Holds the fetched "average" of the fields on which you called `fetchAverage()` so far. This only gets updated when `fetchAverage` is called, it is not automatically updated when local cached `data` changes.
*/

@@ -36,0 +36,0 @@ average: PartialDeep<PickNumbers<DocDataType>>;

@@ -17,4 +17,4 @@ import { DocInstance } from '../Doc.js';

* @example
* // first update the server and await that before updating the local store:
* { executionOrder: ['remote', 'local'] }
* // first update the server and await that before updating the local cache store:
* { executionOrder: ['remote', 'cache'] }
* @example

@@ -54,4 +54,4 @@ * // don't throw errors for this action, wherever it might fail

/**
* Fetches document(s) and adds the data to your local store's state.
* 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.
* Fetches document(s) and adds the data to your local cache store's state.
* Fetch is optimistic by default — if it can find the doc's data in your local cache state, it will return that and prevent any remote fetches.
* You can force a re-fetch by passing `{ force: true }`

@@ -87,3 +87,3 @@ * @returns the document(s) data that was fetched. If you need to access other metadata that was retrieved during fetching, you can use `modifyReadResponse.added`.

/**
* Fetches a collection's document count and caches this count to your local store's state.
* Fetches a collection's document count and caches this count to your local cache store's state.
* @returns the document count that was fetched.

@@ -99,3 +99,3 @@ * @example

/**
* Fetches a collection's document sum for a the passed fieldPath and caches this sum to your local store's state.
* Fetches a collection's document sum for a the passed fieldPath and caches this sum to your local cache store's state.
* @returns the document sum that was fetched.

@@ -115,3 +115,3 @@ * @example

/**
* Fetches a collection's document average for a the passed fieldPath and caches this average to your local store's state.
* Fetches a collection's document average for a the passed fieldPath and caches this average to your local cache store's state.
* @returns the document average that was fetched.

@@ -148,3 +148,3 @@ * @example

/**
* @returns the new document data after applying the changes to the local document (including any modifications from modifyPayloadOn)
* @returns the new document data after applying the changes to the cached document (including any modifications from modifyPayloadOn)
*/

@@ -162,3 +162,3 @@ export type MagnetarWriteAction<DocDataType extends {

/**
* @returns the new document data after applying the changes to the local document (including any modifications from modifyPayloadOn)
* @returns the new document data after applying the changes to the cached document (including any modifications from modifyPayloadOn)
*/

@@ -165,0 +165,0 @@ export type MagnetarDeletePropAction<DocDataType extends {

@@ -26,7 +26,6 @@ import { Limit, OrderByClause, QueryClause, WhereClause } from './clauses.js';

export type GlobalConfig = {
/**
* the storeName of the plugin that will keep your local data cache for usage with your client.
*/
localStoreName: StoreName;
stores: {
/** the cache store, this plugin is responsible for the data to be linked to your UI */
cache: PluginInstance;
/** any other stores you can choose the key name of */
[storeName: string]: PluginInstance;

@@ -33,0 +32,0 @@ };

@@ -8,7 +8,7 @@ export type StoreName = string;

/**
* In case the doc was returned optimisticly (from the local store data) then `exists` will be `'unknown'`
* In case the doc was returned optimisticly (from the local cache store data) then `exists` will be `'unknown'`
*/
exists: boolean | 'unknown';
/**
* In case the doc was returned optimisticly (from the local store data) then `metadata` will be absent
* In case the doc was returned optimisticly (from the local cache store data) then `metadata` will be absent
*/

@@ -15,0 +15,0 @@ metadata?: {

@@ -28,3 +28,3 @@ import { DocMetadata } from './core.js';

/**
* 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.
* These functions will be executed everytime BEFORE documents are added/modified/deleted in your cache data store. The function defined will receive the payload with changes from the server. You can then modify and return this payload.
*/

@@ -50,3 +50,3 @@ export type ModifyReadResponseFnMap<DocDataType extends {

/**
* 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.
* These functions will be executed everytime BEFORE documents are added/modified/deleted in your cache data store. The function defined will receive the payload with changes from the server. You can then modify and return this payload.
*/

@@ -53,0 +53,0 @@ export type ModifyReadResponseFnsMap = {

@@ -49,7 +49,7 @@ import { ActionConfig, ActionName } from './actions.js';

/**
* This must be provided by Store Plugins that have "local" data. It is triggered ONCE when the module (doc or collection) is instantiated. In any case, an empty Map for the collectionPath (to be derived from the modulePath) must be set up.
* This must be provided by Store Plugins that have "cache" data. It is triggered ONCE when the module (doc or collection) is instantiated. In any case, an empty Map for the collectionPath (to be derived from the modulePath) must be set up.
*/
setupModule?: (pluginModuleSetupPayload: PluginModuleSetupPayload) => void;
/**
* This must be provided by Store Plugins that have "local" data. It is triggered EVERY TIME the module's `.data` is accessed. The `modulePath` will be either that of a "collection" or a "doc". When it's a collection, it must return a Map with the ID as key and the doc data as value `Map<string, DocDataType>`. When it's a "doc" it must return the doc data directly `DocDataType`.
* This must be provided by Store Plugins that have "cache" data. It is triggered EVERY TIME the module's `.data` is accessed. The `modulePath` will be either that of a "collection" or a "doc". When it's a collection, it must return a Map with the ID as key and the doc data as value `Map<string, DocDataType>`. When it's a "doc" it must return the doc data directly `DocDataType`.
*/

@@ -62,11 +62,11 @@ getModuleData?: (pluginModuleSetupPayload: PluginModuleSetupPayload) => {

/**
* This must be provided by Store Plugins that have "local" data. It should signify wether or not the document exists. Must return `undefined` when not sure (if the document was never fetched). It is triggered EVERY TIME the module's `.data` is accessed.
* This must be provided by Store Plugins that have "cache" data. It should signify wether or not the document exists. Must return `undefined` when not sure (if the document was never fetched). It is triggered EVERY TIME the module's `.data` is accessed.
*/
getModuleExists?: (pluginModuleSetupPayload: Pick<PluginModuleSetupPayload, 'collectionPath' | 'docId'>) => undefined | 'error' | boolean;
/**
* This must be provided by Store Plugins that have "local" data. It is triggered EVERY TIME the module's `.count` is accessed. The `modulePath` will always be that of a "collection". It must return the fetched doc count, or fall back to `.data.size` in case it hasn't fetched the doc count yet.
* This must be provided by Store Plugins that have "cache" data. It is triggered EVERY TIME the module's `.count` is accessed. The `modulePath` will always be that of a "collection". It must return the fetched doc count, or fall back to `.data.size` in case it hasn't fetched the doc count yet.
*/
getModuleCount?: (pluginModuleSetupPayload: Omit<PluginModuleSetupPayload, 'docId'>) => number;
/**
* This must be provided by Store Plugins that have "local" data. It is triggered EVERY TIME the module's `.count` is accessed. The `modulePath` will always be that of a "collection". It must return the fetched doc sum/average for the fields requested so far
* This must be provided by Store Plugins that have "cache" data. It is triggered EVERY TIME the module's `.count` is accessed. The `modulePath` will always be that of a "collection". It must return the fetched doc sum/average for the fields requested so far
*/

@@ -84,3 +84,3 @@ getModuleAggregate?: (kind: 'sum' | 'average', pluginModuleSetupPayload: Omit<PluginModuleSetupPayload, 'docId'>) => {

/**
* Where, orderBy, limit clauses or extra config a dev might pass when instanciates a module as second param (under `configPerStore`). Eg. `collection('pokedex', { configPerStore: { local: pluginModuleConfig } })`
* Where, orderBy, limit clauses or extra config a dev might pass when instanciates a module as second param (under `configPerStore`). Eg. `collection('pokedex', { configPerStore: { cache: pluginModuleConfig } })`
*/

@@ -137,3 +137,3 @@ export type PluginModuleConfig = Clauses & {

* MustExecuteOnRead:
* The functions for 'added', 'modified' and 'removed' **must** be executed by the plugin whenever the stream sees any of these changes. These are the functions that will pass the data to the other "local" Store Plugins.
* The functions for 'added', 'modified' and 'removed' **must** be executed by the plugin whenever the stream sees any of these changes. These are the functions that will pass the data to the other "cache" Store Plugins.
*/

@@ -143,3 +143,3 @@ mustExecuteOnRead: MustExecuteOnRead;

/**
* Should handle 'stream' for collections & docs. (use `getCollectionPathDocIdEntry(modulePath)` helper, based on what it returns, you know if it's a collection or doc). Should return `StreamResponse` when acting as a "remote" Store Plugin, and `DoOnStream` when acting as "local" Store Plugin.
* Should handle 'stream' for collections & docs. (use `getCollectionPathDocIdEntry(modulePath)` helper, based on what it returns, you know if it's a collection or doc). Should return `StreamResponse` when acting as a "remote" Store Plugin, and `DoOnStream` when acting as "cache" Store Plugin.
*/

@@ -158,3 +158,3 @@ export type PluginStreamAction = (payload: PluginStreamActionPayload) => StreamResponse | DoOnStream | Promise<StreamResponse | DoOnStream>;

/**
* Should handle 'fetch' for collections & docs. (use `getCollectionPathDocIdEntry(modulePath)` helper, based on what it returns, you know if it's a collection or doc). Should return `FetchResponse` when acting as a "remote" Store Plugin, and `DoOnFetch` when acting as "local" Store Plugin.
* Should handle 'fetch' for collections & docs. (use `getCollectionPathDocIdEntry(modulePath)` helper, based on what it returns, you know if it's a collection or doc). Should return `FetchResponse` when acting as a "remote" Store Plugin, and `DoOnFetch` when acting as "cache" Store Plugin.
*/

@@ -164,3 +164,3 @@ export type PluginFetchAction = (payload: PluginFetchActionPayload) => FetchResponse | DoOnFetch | Promise<FetchResponse | DoOnFetch>;

/**
* Should handle 'fetchCount' for collections. Should return `FetchAggregateResponse` when acting as a "remote" Store Plugin, and `DoOnFetchAggregate` when acting as "local" Store Plugin.
* Should handle 'fetchCount' for collections. Should return `FetchAggregateResponse` when acting as a "remote" Store Plugin, and `DoOnFetchAggregate` when acting as "cache" Store Plugin.
*/

@@ -173,3 +173,3 @@ export type PluginFetchCountAction = (payload: PluginFetchCountActionPayload) => FetchAggregateResponse | DoOnFetchAggregate | Promise<FetchAggregateResponse | DoOnFetchAggregate>;

/**
* Should handle 'fetchSum' 'fetchAverage' for collections. Should return `FetchAggregateResponse` when acting as a "remote" Store Plugin, and `DoOnFetchAggregate` when acting as "local" Store Plugin.
* Should handle 'fetchSum' 'fetchAverage' for collections. Should return `FetchAggregateResponse` when acting as a "remote" Store Plugin, and `DoOnFetchAggregate` when acting as "cache" Store Plugin.
*/

@@ -268,3 +268,3 @@ export type PluginFetchAggregateAction = (payload: PluginFetchAggregateActionPayload) => FetchAggregateResponse | DoOnFetchAggregate | Promise<FetchAggregateResponse | DoOnFetchAggregate>;

/**
* Plugin's response to a 'stream' action, when acting as a "local" Store Plugin.
* Plugin's response to a 'stream' action, when acting as a "cache" Store Plugin.
*/

@@ -275,3 +275,3 @@ export type DoOnStream = {

*
* As local store plugin this should be a function that covers the logic to save the payload to the local state.
* As local cache store plugin this should be a function that covers the logic to save the payload to the local cache state.
* As remote store plugin this is what must be executed during the events.

@@ -283,3 +283,3 @@ */

*
* As local store plugin this should be a function that covers the logic to update the payload in the local state.
* As local cache store plugin this should be a function that covers the logic to update the payload in the local cache state.
* As remote store plugin this is what must be executed during the events.

@@ -291,3 +291,3 @@ */

*
* As local store plugin this should be a function that covers the logic to remove the payload from the local state.
* As local cache store plugin this should be a function that covers the logic to remove the payload from the local cache state.
* As remote store plugin this is what must be executed during the events.

@@ -307,3 +307,3 @@ */

* MustExecuteOnRead:
* The functions for 'added', 'modified' and 'removed' **must** be executed by the plugin whenever the stream sees any of these changes. These are the functions that will pass the data to the other "local" Store Plugins.
* The functions for 'added', 'modified' and 'removed' **must** be executed by the plugin whenever the stream sees any of these changes. These are the functions that will pass the data to the other "cache" Store Plugins.
*/

@@ -324,3 +324,3 @@ export type MustExecuteOnRead = Required<DoOnStream>;

/**
* Plugin's response to a 'fetch' action, when acting as a "local" Store Plugin.
* Plugin's response to a 'fetch' action, when acting as a "cache" Store Plugin.
*/

@@ -337,5 +337,5 @@ export type DoOnFetch = (docData: {

/**
* The local store should provide a function that will store the fetchCount when it comes in from the remote store.
* The local cache store should provide a function that will store the fetchCount when it comes in from the remote store.
*/
export type DoOnFetchAggregate = (payload: FetchAggregateResponse) => undefined;
export {};
{
"name": "@magnetarjs/types",
"version": "1.1.0",
"version": "1.2.1",
"type": "module",

@@ -16,2 +16,7 @@ "sideEffects": false,

],
"scripts": {
"typecheck": "tsc --noEmit",
"build": "del-cli dist && tsc",
"test": "echo none"
},
"author": "Luca Ban - Mesqueeb",

@@ -42,2 +47,4 @@ "funding": "https://github.com/sponsors/mesqueeb",

"data-store",
"data-cache",
"cache-store",
"local-store",

@@ -56,9 +63,3 @@ "remote-store",

"url": "https://github.com/cycraft/magnetar/issues"
},
"scripts": {
"typecheck": "tsc --noEmit",
"build": "del-cli dist && tsc",
"dev": "pnpm build --watch",
"test": "echo none"
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc