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

@magnetarjs/core

Package Overview
Dependencies
Maintainers
1
Versions
152
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@magnetarjs/core - npm Package Compare versions

Comparing version 0.2.0 to 0.2.2

21

dist/index.cjs.js

@@ -6,3 +6,2 @@ 'use strict';

var mergeAnything = require('merge-anything');
var filterAnything = require('filter-anything');
var isWhat = require('is-what');

@@ -49,2 +48,3 @@

* in any event/hook it's possible for the dev to modify the result & also abort the execution chain, which prevents calling handleAction on the next store as well
* @returns unknown is returned in case of an error
*/

@@ -391,4 +391,8 @@ function handleAction(args) {

const doOnFetchFns = modifyReadResponseMap.added;
/**
* All possible results from the plugins.
* `unknown` in case an error was thrown
*/
let resultFromPlugin;
// handle and await each action in sequence
let resultFromPlugin;
for (const [i, storeName] of storesToExecute.entries()) {

@@ -442,8 +446,13 @@ // a previous iteration stopped the execution:

}
// special handling for 'insert' (resultFromPlugin will always be `string`)
if (actionName === 'insert' && isWhat.isFullString(resultFromPlugin)) {
// special handling for 'insert' (resultFromPlugin will always be `string | [string, SyncBatch]`)
if (actionName === 'insert') {
// update the modulePath if a doc with random ID was inserted in a collection
// if this is the case the result will be a string - the randomly genererated ID
if (!docId) {
docId = resultFromPlugin;
if (isWhat.isFullString(resultFromPlugin)) {
docId = resultFromPlugin;
}
if (isWhat.isFullArray(resultFromPlugin) && isWhat.isFullString(resultFromPlugin[0])) {
docId = resultFromPlugin[0];
}
modulePath = [collectionPath, docId].filter(Boolean).join('/');

@@ -643,3 +652,3 @@ }

const doc = (docId, _moduleConfig = {}) => {
return docFn(`${path}/${docId}`, mergeAnything.merge(filterAnything.omit(moduleConfig, ['configPerStore']), _moduleConfig));
return docFn(`${path}/${docId}`, mergeAnything.merge(moduleConfig, _moduleConfig));
};

@@ -646,0 +655,0 @@ const insert = handleActionPerStore([collectionPath, docId], moduleConfig, globalConfig, 'insert', actionNameTypeMap.insert, fetchPromises, docFn, collectionFn); //prettier-ignore

import { merge, mergeAndConcat } from 'merge-anything';
import { omit } from 'filter-anything';
import { isPlainObject, isFunction, isArray, isFullString, isPromise } from 'is-what';
import { isPlainObject, isFunction, isArray, isFullString, isPromise, isFullArray } from 'is-what';

@@ -44,2 +43,3 @@ const actionNameTypeMap = {

* in any event/hook it's possible for the dev to modify the result & also abort the execution chain, which prevents calling handleAction on the next store as well
* @returns unknown is returned in case of an error
*/

@@ -386,4 +386,8 @@ function handleAction(args) {

const doOnFetchFns = modifyReadResponseMap.added;
/**
* All possible results from the plugins.
* `unknown` in case an error was thrown
*/
let resultFromPlugin;
// handle and await each action in sequence
let resultFromPlugin;
for (const [i, storeName] of storesToExecute.entries()) {

@@ -437,8 +441,13 @@ // a previous iteration stopped the execution:

}
// special handling for 'insert' (resultFromPlugin will always be `string`)
if (actionName === 'insert' && isFullString(resultFromPlugin)) {
// special handling for 'insert' (resultFromPlugin will always be `string | [string, SyncBatch]`)
if (actionName === 'insert') {
// update the modulePath if a doc with random ID was inserted in a collection
// if this is the case the result will be a string - the randomly genererated ID
if (!docId) {
docId = resultFromPlugin;
if (isFullString(resultFromPlugin)) {
docId = resultFromPlugin;
}
if (isFullArray(resultFromPlugin) && isFullString(resultFromPlugin[0])) {
docId = resultFromPlugin[0];
}
modulePath = [collectionPath, docId].filter(Boolean).join('/');

@@ -638,3 +647,3 @@ }

const doc = (docId, _moduleConfig = {}) => {
return docFn(`${path}/${docId}`, merge(omit(moduleConfig, ['configPerStore']), _moduleConfig));
return docFn(`${path}/${docId}`, merge(moduleConfig, _moduleConfig));
};

@@ -641,0 +650,0 @@ const insert = handleActionPerStore([collectionPath, docId], moduleConfig, globalConfig, 'insert', actionNameTypeMap.insert, fetchPromises, docFn, collectionFn); //prettier-ignore

import { ActionConfig, ActionName } from '../types/actions';
import { SyncBatch } from '../types/plugins';
import { EventNameFnsMap } from '../types/events';

@@ -8,2 +9,3 @@ import { PluginModuleConfig, PluginFetchAction, PluginWriteAction, PluginDeleteAction, PluginDeletePropAction, PluginInsertAction, FetchResponse } from '../types/plugins';

* in any event/hook it's possible for the dev to modify the result & also abort the execution chain, which prevents calling handleAction on the next store as well
* @returns unknown is returned in case of an error
*/

@@ -23,2 +25,2 @@ export declare function handleAction(args: {

storeName: string;
}): Promise<void | string | FetchResponse | OnAddedFn | unknown>;
}): Promise<void | string | FetchResponse | OnAddedFn | SyncBatch | [string, SyncBatch] | unknown>;
import { O } from 'ts-toolbelt';
import { ActionName } from './actions';
import { FetchResponse, StreamResponse, DoOnStream, DoOnFetch, PluginModuleConfig } from './plugins';
import { FetchResponse, StreamResponse, DoOnStream, DoOnFetch, PluginModuleConfig, SyncBatch } from './plugins';
export declare type EventName = 'before' | 'success' | 'error' | 'revert';

@@ -49,3 +49,3 @@ declare type EventSharedPayload = {

declare type EventPayloadPropResult = {
result: void | string | FetchResponse | DoOnFetch | StreamResponse | DoOnStream;
result: void | string | FetchResponse | DoOnFetch | StreamResponse | DoOnStream | SyncBatch | [string, SyncBatch];
};

@@ -57,3 +57,5 @@ export declare type EventFnBefore = (args: EventSharedPayload) => void | Promise<void>;

}>) => void | Promise<void>;
export declare type EventFnRevert = (args: O.Patch<O.Omit<EventSharedPayload, 'abort'>, EventPayloadPropResult>) => void | Promise<void>;
export declare type EventFnRevert = (args: O.Patch<O.Omit<EventSharedPayload, 'abort'>, {
result: unknown;
}>) => void | Promise<void>;
export declare type EventFn = EventFnBefore | EventFnSuccess | EventFnError | EventFnRevert;

@@ -60,0 +62,0 @@ export declare type EventNameFnMap = {

@@ -6,2 +6,11 @@ import { O } from 'ts-toolbelt';

import { Clauses } from './clauses';
declare type DocumentPath = string;
export declare type SyncBatch = {
insert: Map<DocumentPath, Record<string, any>>;
assign: Map<DocumentPath, Record<string, any>>;
merge: Map<DocumentPath, Record<string, any>>;
replace: Map<DocumentPath, Record<string, any>>;
deleteProp: Map<DocumentPath, Set<string>>;
delete: Set<string>;
};
/**

@@ -117,4 +126,7 @@ * A Plugin is a single function that returns a plugin instance. The pluginOptions can be anything the plugin might need to instantiate.

* Should handle 'merge' 'assign' 'replace' for docs. (use `getCollectionPathDocIdEntry(modulePath)` helper)
* @returns
* - `void` if the plugin writes one by one
* - `SyncBatch` If the plugin batches multiple write actions together, it will return the sync batch information
*/
export declare type PluginWriteAction = (payload: PluginWriteActionPayload) => void | Promise<void>;
export declare type PluginWriteAction = (payload: PluginWriteActionPayload) => void | Promise<void | SyncBatch>;
export declare type PluginInsertActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<PluginActionPayloadBase<SpecificPluginModuleConfig>, {

@@ -128,4 +140,7 @@ /**

* Should handle 'insert' for collections & docs. Must return the new document's ID! When executed on a collection, the plugin must provide a newly generated ID. (use `getCollectionPathDocIdEntry(modulePath)` helper, based on what it returns, you know if it's a collection or doc)
* @returns
* - `string` if the plugin writes one by one — the new document's ID
* - `[string, SyncBatch]` if the plugin batches multiple write actions together — (1) the new document's ID (2) the sync batch information
*/
export declare type PluginInsertAction = (payload: PluginInsertActionPayload) => string | Promise<string>;
export declare type PluginInsertAction = (payload: PluginInsertActionPayload) => string | Promise<string | [string, SyncBatch]>;
export declare type PluginDeletePropActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<PluginActionPayloadBase<SpecificPluginModuleConfig>, {

@@ -143,4 +158,7 @@ /**

* Should handle 'deleteProp' for docs. (use `getCollectionPathDocIdEntry(modulePath)` helper)
* @returns
* - `void` if the plugin writes one by one
* - `SyncBatch` If the plugin batches multiple write actions together, it will return the sync batch information
*/
export declare type PluginDeletePropAction = (payload: PluginDeletePropActionPayload) => void | Promise<void>;
export declare type PluginDeletePropAction = (payload: PluginDeletePropActionPayload) => void | Promise<void | SyncBatch>;
export declare type PluginDeleteActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<PluginActionPayloadBase<SpecificPluginModuleConfig>, {

@@ -154,4 +172,7 @@ /**

* Should handle 'delete' for collections & docs. (use `getCollectionPathDocIdEntry(modulePath)` helper)
* @returns
* - `void` if the plugin writes one by one
* - `SyncBatch` If the plugin batches multiple write actions together, it will return the sync batch information
*/
export declare type PluginDeleteAction = (payload: PluginDeleteActionPayload) => void | Promise<void>;
export declare type PluginDeleteAction = (payload: PluginDeleteActionPayload) => void | Promise<void | SyncBatch>;
export declare type PluginRevertActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<PluginActionPayloadBase<SpecificPluginModuleConfig>, {

@@ -244,1 +265,2 @@ /**

export declare function isFetchResponse(payload: any): payload is FetchResponse;
export {};
{
"name": "@magnetarjs/core",
"version": "0.2.0",
"version": "0.2.2",
"sideEffects": false,

@@ -20,3 +20,2 @@ "description": "Magnetar core library.",

"dependencies": {
"filter-anything": "^2.2.1",
"is-what": "^3.14.1",

@@ -27,3 +26,3 @@ "merge-anything": "^4.0.1",

"devDependencies": {
"@magnetarjs/test-utils": "^0.1.1",
"@magnetarjs/test-utils": "^0.1.3",
"ava": "^3.15.0"

@@ -72,3 +71,3 @@ },

},
"gitHead": "448ad93374face6e7308c1ac0b3bd4f6cd96b59a"
"gitHead": "4751cb51a6820e1f53a9954cf71a7585ad095c26"
}
import { O } from 'ts-toolbelt'
import { merge, mergeAndConcat } from 'merge-anything'
import { omit } from 'filter-anything'
import {

@@ -115,3 +114,3 @@ MagnetarFetchAction,

const doc: DocFn<DocDataType> = (docId: string, _moduleConfig: ModuleConfig = {}) => {
return docFn(`${path}/${docId}`, merge(omit(moduleConfig, ['configPerStore']), _moduleConfig))
return docFn(`${path}/${docId}`, merge(moduleConfig, _moduleConfig))
}

@@ -118,0 +117,0 @@

import { ActionConfig, ActionName } from '../types/actions'
import { SyncBatch } from '../types/plugins'

@@ -18,2 +19,3 @@ import { EventNameFnsMap } from '../types/events'

* in any event/hook it's possible for the dev to modify the result & also abort the execution chain, which prevents calling handleAction on the next store as well
* @returns unknown is returned in case of an error
*/

@@ -33,3 +35,3 @@ export async function handleAction(args: {

storeName: string
}): Promise<void | string | FetchResponse | OnAddedFn | unknown> {
}): Promise<void | string | FetchResponse | OnAddedFn | SyncBatch | [string, SyncBatch] | unknown> {
const {

@@ -63,3 +65,3 @@ collectionPath,

}
let result: void | string | FetchResponse | OnAddedFn
let result: void | string | FetchResponse | OnAddedFn | SyncBatch | [string, SyncBatch]
try {

@@ -66,0 +68,0 @@ // triggering the action provided by the plugin

/* eslint-disable no-inner-declarations */
import { O } from 'ts-toolbelt'
import { isFullString, isPromise } from 'is-what'
import { isFullArray, isFullString, isPromise } from 'is-what'
import { handleAction } from './handleAction'

@@ -17,3 +17,3 @@ import { getEventNameFnsMap } from '../types/events'

import { ActionType, ActionTernary } from '../types/actionsInternal'
import { FetchResponse, isDoOnFetch, isFetchResponse, DoOnFetch } from '../types/plugins'
import { FetchResponse, isDoOnFetch, isFetchResponse, DoOnFetch, SyncBatch } from '../types/plugins'
import { getModifyPayloadFnsMap } from '../types/modifyPayload'

@@ -109,4 +109,8 @@ import { OnAddedFn, getModifyReadResponseFnsMap } from '../types/modifyReadResponse'

/**
* All possible results from the plugins.
* `unknown` in case an error was thrown
*/
let resultFromPlugin: void | string | unknown | FetchResponse | OnAddedFn | SyncBatch | [string, SyncBatch]
// handle and await each action in sequence
let resultFromPlugin: void | string | FetchResponse | OnAddedFn | any
for (const [i, storeName] of storesToExecute.entries()) {

@@ -160,8 +164,13 @@ // a previous iteration stopped the execution:

// special handling for 'insert' (resultFromPlugin will always be `string`)
if (actionName === 'insert' && isFullString(resultFromPlugin)) {
// special handling for 'insert' (resultFromPlugin will always be `string | [string, SyncBatch]`)
if (actionName === 'insert') {
// update the modulePath if a doc with random ID was inserted in a collection
// if this is the case the result will be a string - the randomly genererated ID
if (!docId) {
docId = resultFromPlugin
if (isFullString(resultFromPlugin)) {
docId = resultFromPlugin
}
if (isFullArray(resultFromPlugin) && isFullString(resultFromPlugin[0])) {
docId = resultFromPlugin[0]
}
modulePath = [collectionPath, docId].filter(Boolean).join('/')

@@ -168,0 +177,0 @@ }

import { O } from 'ts-toolbelt'
import { ActionName } from './actions'
import { FetchResponse, StreamResponse, DoOnStream, DoOnFetch, PluginModuleConfig } from './plugins'
import { FetchResponse, StreamResponse, DoOnStream, DoOnFetch, PluginModuleConfig, SyncBatch } from './plugins'

@@ -53,3 +53,3 @@ // events

type EventPayloadPropResult = {
result: void | string | FetchResponse | DoOnFetch | StreamResponse | DoOnStream
result: void | string | FetchResponse | DoOnFetch | StreamResponse | DoOnStream | SyncBatch | [string, SyncBatch]
}

@@ -68,3 +68,3 @@

export type EventFnRevert = (
args: O.Patch<O.Omit<EventSharedPayload, 'abort'>, EventPayloadPropResult>
args: O.Patch<O.Omit<EventSharedPayload, 'abort'>, { result: unknown }>
) => void | Promise<void>

@@ -71,0 +71,0 @@

@@ -11,2 +11,11 @@ import { O } from 'ts-toolbelt'

// these are the interfaces that plugins need to use and implement
type DocumentPath = string
export type SyncBatch = {
insert: Map<DocumentPath, Record<string, any>>
assign: Map<DocumentPath, Record<string, any>>
merge: Map<DocumentPath, Record<string, any>>
replace: Map<DocumentPath, Record<string, any>>
deleteProp: Map<DocumentPath, Set<string>>
delete: Set<string>
}

@@ -144,4 +153,9 @@ /**

* Should handle 'merge' 'assign' 'replace' for docs. (use `getCollectionPathDocIdEntry(modulePath)` helper)
* @returns
* - `void` if the plugin writes one by one
* - `SyncBatch` If the plugin batches multiple write actions together, it will return the sync batch information
*/
export type PluginWriteAction = (payload: PluginWriteActionPayload) => void | Promise<void>
export type PluginWriteAction = (
payload: PluginWriteActionPayload
) => void | Promise<void | SyncBatch>

@@ -159,4 +173,9 @@ export type PluginInsertActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<

* Should handle 'insert' for collections & docs. Must return the new document's ID! When executed on a collection, the plugin must provide a newly generated ID. (use `getCollectionPathDocIdEntry(modulePath)` helper, based on what it returns, you know if it's a collection or doc)
* @returns
* - `string` if the plugin writes one by one — the new document's ID
* - `[string, SyncBatch]` if the plugin batches multiple write actions together — (1) the new document's ID (2) the sync batch information
*/
export type PluginInsertAction = (payload: PluginInsertActionPayload) => string | Promise<string>
export type PluginInsertAction = (
payload: PluginInsertActionPayload
) => string | Promise<string | [string, SyncBatch]>

@@ -179,6 +198,9 @@ export type PluginDeletePropActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> =

* Should handle 'deleteProp' for docs. (use `getCollectionPathDocIdEntry(modulePath)` helper)
* @returns
* - `void` if the plugin writes one by one
* - `SyncBatch` If the plugin batches multiple write actions together, it will return the sync batch information
*/
export type PluginDeletePropAction = (
payload: PluginDeletePropActionPayload
) => void | Promise<void>
) => void | Promise<void | SyncBatch>

@@ -196,4 +218,9 @@ export type PluginDeleteActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<

* Should handle 'delete' for collections & docs. (use `getCollectionPathDocIdEntry(modulePath)` helper)
* @returns
* - `void` if the plugin writes one by one
* - `SyncBatch` If the plugin batches multiple write actions together, it will return the sync batch information
*/
export type PluginDeleteAction = (payload: PluginDeleteActionPayload) => void | Promise<void>
export type PluginDeleteAction = (
payload: PluginDeleteActionPayload
) => void | Promise<void | SyncBatch>

@@ -200,0 +227,0 @@ export type PluginRevertActionPayload<SpecificPluginModuleConfig = PluginModuleConfig> = O.Patch<

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