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.0.1 to 1.1.0

dist/types/utils/PickNumbers.d.ts

20

dist/Collection.d.ts
import { DocFn } from './Magnetar.js';
import { FetchMetaDataCollection, MagnetarDeleteAction, MagnetarFetchAction, MagnetarFetchCountAction, MagnetarInsertAction, MagnetarStreamAction } from './types/actions.js';
import { FetchMetaDataCollection, MagnetarDeleteAction, MagnetarFetchAction, MagnetarFetchAverageAction, MagnetarFetchCountAction, MagnetarFetchSumAction, MagnetarInsertAction, MagnetarStreamAction } from './types/actions.js';
import { Query, WhereFilterOp, WhereFilterValue } from './types/clauses.js';
import { DeepPropType } from './types/utils/DeepPropType.js';
import { DefaultTo } from './types/utils/DefaultTo.js';
import { PartialDeep } from './types/utils/PartialDeep.js';
import { OPathsWithOptional } from './types/utils/Paths.js';
import { PickNumbers } from './types/utils/PickNumbers.js';
export type CollectionInstance<DocDataType extends {

@@ -27,2 +29,10 @@ [key: string]: any;

/**
* 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.
*/
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.
*/
average: PartialDeep<PickNumbers<DocDataType>>;
/**
* `doc` is available on every collection for chaining

@@ -69,2 +79,10 @@ * @see {@link DocFn}

/**
* @see {@link MagnetarFetchSumAction}
*/
fetchSum: MagnetarFetchSumAction<DocDataType>;
/**
* @see {@link MagnetarFetchAverageAction}
*/
fetchAverage: MagnetarFetchAverageAction<DocDataType>;
/**
* @see {@link MagnetarFetchAction}

@@ -71,0 +89,0 @@ */

@@ -22,3 +22,4 @@ export * from './Collection.js';

export * from './types/utils/Paths.js';
export * from './types/utils/PickNumbers.js';
export * from './types/utils/Split.js';
export * from './types/utils/Tuple.js';

@@ -22,3 +22,4 @@ export * from './Collection.js';

export * from './types/utils/Paths.js';
export * from './types/utils/PickNumbers.js';
export * from './types/utils/Split.js';
export * from './types/utils/Tuple.js';

@@ -7,2 +7,3 @@ import { DocInstance } from '../Doc.js';

import { PartialDeep } from './utils/PartialDeep.js';
import { OPathsWithOptional } from './utils/Paths.js';
/**

@@ -12,3 +13,3 @@ * these are all the actions that Magnetar streamlines, whichever plugin is used

*/
export type ActionName = 'fetch' | 'fetchCount' | 'stream' | 'insert' | 'merge' | 'assign' | 'replace' | 'deleteProp' | 'delete';
export type ActionName = 'fetch' | 'fetchCount' | 'fetchSum' | 'fetchAverage' | 'stream' | 'insert' | 'merge' | 'assign' | 'replace' | 'deleteProp' | 'delete';
/**

@@ -97,2 +98,32 @@ * You can pass options to this action specifically;

/**
* Fetches a collection's document sum for a the passed fieldPath and caches this sum to your local store's state.
* @returns the document sum that was fetched.
* @example
* magnetar.collection('pokedex').sum // {}
*
* const sum = await magnetar.collection('pokedex').fetchSum('base.HP')
* sum // 10_000
* magnetar.collection('pokedex').sum // { base: { HP: 10_000 } }
*/
export type MagnetarFetchSumAction<DocDataType extends {
[key: string]: any;
} = {
[key: string]: any;
}> = (fieldPath: OPathsWithOptional<DocDataType>) => Promise<number>;
/**
* Fetches a collection's document average for a the passed fieldPath and caches this average to your local store's state.
* @returns the document average that was fetched.
* @example
* magnetar.collection('pokedex').average // 0
*
* const average = await magnetar.collection('pokedex').fetchAverage('base.HP')
* average // 88
* magnetar.collection('pokedex').average // { base: { HP: 88 } }
*/
export type MagnetarFetchAverageAction<DocDataType extends {
[key: string]: any;
} = {
[key: string]: any;
}> = (fieldPath: OPathsWithOptional<DocDataType>) => Promise<number>;
/**
* @returns The new `doc()` instance after inserting. You can access the inserted `id` by checking this returned instance.

@@ -156,3 +187,3 @@ * @example

export type FetchPromises = {
[key in 'fetch' | 'fetchCount']: Map<string, Promise<any>>;
[key in 'fetch' | 'fetchCount' | 'fetchSum' | 'fetchAverage']: Map<string, Promise<any>>;
};

@@ -159,0 +190,0 @@ /**

4

dist/types/actionsInternal.d.ts

@@ -1,2 +0,2 @@

import { ActionName, MagnetarDeleteAction, MagnetarDeletePropAction, MagnetarFetchAction, MagnetarFetchCountAction, MagnetarInsertAction, MagnetarStreamAction, MagnetarWriteAction } from './actions.js';
import { ActionName, MagnetarDeleteAction, MagnetarDeletePropAction, MagnetarFetchAction, MagnetarFetchAverageAction, MagnetarFetchCountAction, MagnetarFetchSumAction, MagnetarInsertAction, MagnetarStreamAction, MagnetarWriteAction } from './actions.js';
/**

@@ -6,2 +6,2 @@ * ActionType is only used as a shortcut to set the execution order in the global/module/action settings.

export type ActionType = 'read' | 'write' | 'delete';
export type ActionTernary<TActionName extends ActionName> = TActionName extends 'stream' ? MagnetarStreamAction : TActionName extends 'fetchCount' ? MagnetarFetchCountAction : TActionName extends 'fetch' ? MagnetarFetchAction : TActionName extends 'delete' ? MagnetarDeleteAction : TActionName extends 'deleteProp' ? MagnetarDeletePropAction : TActionName extends 'insert' ? MagnetarInsertAction : MagnetarWriteAction;
export type ActionTernary<TActionName extends ActionName> = TActionName extends 'stream' ? MagnetarStreamAction : TActionName extends 'fetchCount' ? MagnetarFetchCountAction : TActionName extends 'fetchSum' ? MagnetarFetchSumAction : TActionName extends 'fetchAverage' ? MagnetarFetchAverageAction : TActionName extends 'fetch' ? MagnetarFetchAction : TActionName extends 'delete' ? MagnetarDeleteAction : TActionName extends 'deleteProp' ? MagnetarDeletePropAction : TActionName extends 'insert' ? MagnetarInsertAction : MagnetarWriteAction;
import { ActionName } from './actions.js';
import { DoOnFetch, DoOnFetchCount, DoOnStream, FetchCountResponse, FetchResponse, PluginModuleConfig, StreamResponse, SyncBatch } from './plugins.js';
import { DoOnFetch, DoOnFetchAggregate, DoOnStream, FetchAggregateResponse, FetchResponse, PluginModuleConfig, StreamResponse, SyncBatch } from './plugins.js';
import { MergeDeep } from './utils/MergeDeep.js';

@@ -53,3 +53,3 @@ export type EventName = 'before' | 'success' | 'error' | 'revert';

type EventPayloadPropResult = {
result: undefined | string | FetchCountResponse | DoOnFetchCount | FetchResponse | DoOnFetch | StreamResponse | DoOnStream | SyncBatch | [string, SyncBatch];
result: undefined | string | FetchAggregateResponse | DoOnFetchAggregate | FetchResponse | DoOnFetch | StreamResponse | DoOnStream | SyncBatch | [string, SyncBatch];
};

@@ -56,0 +56,0 @@ export type EventFnBefore = (args: EventSharedPayload) => void | Promise<void>;

@@ -32,4 +32,6 @@ import { ActionConfig, ActionName } from './actions.js';

actions: {
fetch?: PluginFetchAction;
fetchCount?: PluginFetchCountAction;
fetch?: PluginFetchAction;
fetchSum?: PluginFetchAggregateAction;
fetchAverage?: PluginFetchAggregateAction;
stream?: PluginStreamAction;

@@ -68,2 +70,10 @@ insert?: PluginInsertAction;

/**
* 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
*/
getModuleAggregate?: (kind: 'sum' | 'average', pluginModuleSetupPayload: Omit<PluginModuleSetupPayload, 'docId'>) => {
[key in string]: number | {
[key in string]: unknown;
};
};
/**
* This is an optional function that some "remote" Store Plugins can provide to sync any pending writes that might have stacked because of a `syncDebounceMs`.

@@ -150,5 +160,13 @@ */

/**
* Should handle 'fetchCount' for collections. Should return `FetchCountResponse` when acting as a "remote" Store Plugin, and `DoOnFetchCount` 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 "local" Store Plugin.
*/
export type PluginFetchCountAction = (payload: PluginFetchCountActionPayload) => FetchCountResponse | DoOnFetchCount | Promise<FetchCountResponse | DoOnFetchCount>;
export type PluginFetchCountAction = (payload: PluginFetchCountActionPayload) => FetchAggregateResponse | DoOnFetchAggregate | Promise<FetchAggregateResponse | DoOnFetchAggregate>;
export type PluginFetchAggregateActionPayload<T = PluginModuleConfig> = Omit<MergeDeep<PluginActionPayloadBase<T>, {
/** The target fieldPath */
payload: string;
}>, 'docId'>;
/**
* Should handle 'fetchSum' 'fetchAverage' for collections. Should return `FetchAggregateResponse` when acting as a "remote" Store Plugin, and `DoOnFetchAggregate` when acting as "local" Store Plugin.
*/
export type PluginFetchAggregateAction = (payload: PluginFetchAggregateActionPayload) => FetchAggregateResponse | DoOnFetchAggregate | Promise<FetchAggregateResponse | DoOnFetchAggregate>;
export type PluginWriteActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = MergeDeep<PluginActionPayloadBase<SpecificPluginModuleConfig>, {

@@ -306,9 +324,7 @@ /**

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

@@ -5,0 +5,0 @@ "sideEffects": false,

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