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.0.21 to 0.0.22

9

dist/index.cjs.js

@@ -445,4 +445,3 @@ 'use strict';

if (actionName === 'insert' && docId) {
// we do not pass the `moduleConfig`, because it's the moduleConfig of the "collection" in this case
resolve(docFn(modulePath));
resolve(docFn(modulePath, moduleConfig));
return;

@@ -452,3 +451,3 @@ }

if (docId || !collectionFn) {
resolve(docFn(modulePath, moduleConfig));
resolve(docFn(modulePath, moduleConfig).data);
if (actionName === 'fetch')

@@ -459,4 +458,4 @@ fetchPromises.delete(fetchPromiseKey);

// all other actions triggered on collections ('fetch' is the only possibility left)
// should return the collection:
resolve(collectionFn(modulePath, moduleConfig));
// 'fetch' should return `Map<string, DocDataType>` or `DocDataType`
resolve(collectionFn(modulePath, moduleConfig).data);
if (actionName === 'fetch')

@@ -463,0 +462,0 @@ fetchPromises.delete(fetchPromiseKey);

@@ -441,4 +441,3 @@ import { merge, mergeAndConcat } from 'merge-anything';

if (actionName === 'insert' && docId) {
// we do not pass the `moduleConfig`, because it's the moduleConfig of the "collection" in this case
resolve(docFn(modulePath));
resolve(docFn(modulePath, moduleConfig));
return;

@@ -448,3 +447,3 @@ }

if (docId || !collectionFn) {
resolve(docFn(modulePath, moduleConfig));
resolve(docFn(modulePath, moduleConfig).data);
if (actionName === 'fetch')

@@ -455,4 +454,4 @@ fetchPromises.delete(fetchPromiseKey);

// all other actions triggered on collections ('fetch' is the only possibility left)
// should return the collection:
resolve(collectionFn(modulePath, moduleConfig));
// 'fetch' should return `Map<string, DocDataType>` or `DocDataType`
resolve(collectionFn(modulePath, moduleConfig).data);
if (actionName === 'fetch')

@@ -459,0 +458,0 @@ fetchPromises.delete(fetchPromiseKey);

@@ -34,3 +34,3 @@ import { O } from 'ts-toolbelt';

insert: MagnetarInsertAction<DocDataType>;
delete: MagnetarDeleteAction<DocDataType>;
delete: MagnetarDeleteAction;
where: (fieldPath: string, operator: WhereFilterOp, value: any) => CollectionInstance<DocDataType>;

@@ -37,0 +37,0 @@ orderBy: (fieldPath: string, direction?: 'asc' | 'desc') => CollectionInstance<DocDataType>;

@@ -41,3 +41,3 @@ import { O } from 'ts-toolbelt';

*/
delete: MagnetarDeleteAction<DocDataType>;
delete: MagnetarDeleteAction;
};

@@ -44,0 +44,0 @@ export declare function createDocWithContext<DocDataType extends Record<string, any>>([collectionPath, docId]: [string, string | undefined], moduleConfig: ModuleConfig, globalConfig: O.Compulsory<GlobalConfig>, docFn: DocFn<DocDataType>, collectionFn: CollectionFn, streamAndFetchPromises: {

@@ -5,3 +5,2 @@ import { O } from 'ts-toolbelt';

import { DocInstance } from '../Doc';
import { CollectionInstance } from '../Collection';
/**

@@ -25,10 +24,31 @@ * these are all the actions that Magnetar streamlines, whichever plugin is used

}, Partial<O.Omit<SharedConfig, 'localStoreName' | 'executionOrder'>>>;
/**
* Opens a continuous stream to a document or collection.
* @returns the open stream promise. This will never resolve as long as the stream is open.
*/
export declare type MagnetarStreamAction = (payload?: any | void, actionConfig?: ActionConfig) => Promise<void>;
/**
* Fetches document(s) and adds the data to your local store's state.
* @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`.
*/
export declare type MagnetarFetchAction<DocDataType extends Record<string, any> = Record<string, any>, calledFrom extends 'collection' | 'doc' = 'collection' | 'doc'> = (payload?: {
ifUnfetched?: boolean;
} | Record<string, any> | void, actionConfig?: ActionConfig) => Promise<calledFrom extends 'collection' ? CollectionInstance<DocDataType> : DocInstance<DocDataType>>;
} | Record<string, any> | void, actionConfig?: ActionConfig) => Promise<calledFrom extends 'collection' ? Map<string, DocDataType> : DocDataType>;
/**
* @returns The new `doc()` instance after inserting. You can access the inserted `id` by checking this returned instance.
* @example
* const newDoc = collection('myDocs').insert({ some: 'payload' })
* newDoc.id // the generated id
* newDoc.data // { some: 'payload' }
*/
export declare type MagnetarInsertAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload: DocDataType, actionConfig?: ActionConfig) => Promise<DocInstance<DocDataType>>;
export declare type MagnetarWriteAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload: O.Optional<DocDataType, keyof DocDataType, 'deep'>, actionConfig?: ActionConfig) => Promise<DocInstance<DocDataType>>;
export declare type MagnetarDeletePropAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload: keyof DocDataType | string | (keyof DocDataType | string)[], actionConfig?: ActionConfig) => Promise<DocInstance<DocDataType>>;
/**
* @returns the new document data after applying the changes to the local document (including any modifications from modifyPayloadOn)
*/
export declare type MagnetarWriteAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload: O.Optional<DocDataType, keyof DocDataType, 'deep'>, actionConfig?: ActionConfig) => Promise<DocDataType>;
/**
* @returns the new document data after applying the changes to the local document (including any modifications from modifyPayloadOn)
*/
export declare type MagnetarDeletePropAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload: keyof DocDataType | string | (keyof DocDataType | string)[], actionConfig?: ActionConfig) => 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.

@@ -39,3 +59,3 @@ * @param {ActionConfig} [actionConfig]

*/
export declare type MagnetarDeleteAction<DocDataType extends Record<string, any> = Record<string, any>> = (payload?: any, actionConfig?: ActionConfig) => Promise<DocInstance<DocDataType>>;
export declare type MagnetarDeleteAction = (payload?: any, actionConfig?: ActionConfig) => Promise<void>;
/**

@@ -42,0 +62,0 @@ * All open streams with the payload passed to `stream(payload)` as key and the "closeStream" function as value. In case `stream()` had no payload, use `undefined`

{
"name": "@magnetarjs/core",
"version": "0.0.21",
"version": "0.0.22",
"sideEffects": false,

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

},
"gitHead": "431709c8bde8a6a626b4366750097be8ca232472"
"gitHead": "6f7e1b9b3440de3408be14439a31a9a4967377fd"
}

@@ -53,3 +53,3 @@ import { O } from 'ts-toolbelt'

insert: MagnetarInsertAction<DocDataType>
delete: MagnetarDeleteAction<DocDataType>
delete: MagnetarDeleteAction

@@ -86,3 +86,3 @@ // filters

const insert = handleActionPerStore([collectionPath, docId], moduleConfig, globalConfig, 'insert', actionNameTypeMap.insert, fetchPromises, docFn, collectionFn) as MagnetarInsertAction<DocDataType> //prettier-ignore
const _delete = handleActionPerStore([collectionPath, docId], moduleConfig, globalConfig, 'delete', actionNameTypeMap.delete, fetchPromises, docFn, collectionFn) as MagnetarDeleteAction<DocDataType> //prettier-ignore
const _delete = handleActionPerStore([collectionPath, docId], moduleConfig, globalConfig, 'delete', actionNameTypeMap.delete, fetchPromises, docFn, collectionFn) as MagnetarDeleteAction //prettier-ignore
const fetch = handleActionPerStore([collectionPath, docId], moduleConfig, globalConfig, 'fetch', actionNameTypeMap.fetch, fetchPromises, docFn, collectionFn) as MagnetarFetchAction<DocDataType, 'collection'> //prettier-ignore

@@ -89,0 +89,0 @@ const stream = handleStreamPerStore([collectionPath, docId], moduleConfig, globalConfig, actionNameTypeMap.stream, streamPromiseInfo) // prettier-ignore

@@ -60,3 +60,3 @@ import { O } from 'ts-toolbelt'

*/
delete: MagnetarDeleteAction<DocDataType>
delete: MagnetarDeleteAction
}

@@ -93,3 +93,3 @@

deleteProp: (handleActionPerStore([collectionPath, docId], moduleConfig, globalConfig, 'deleteProp', actionNameTypeMap.deleteProp, fetchPromises, docFn) as MagnetarDeletePropAction<DocDataType>), // prettier-ignore
delete: (handleActionPerStore([collectionPath, docId], moduleConfig, globalConfig, 'delete', actionNameTypeMap.delete, fetchPromises, docFn) as MagnetarDeleteAction<DocDataType>), // prettier-ignore
delete: (handleActionPerStore([collectionPath, docId], moduleConfig, globalConfig, 'delete', actionNameTypeMap.delete, fetchPromises, docFn) as MagnetarDeleteAction), // prettier-ignore
fetch: (handleActionPerStore([collectionPath, docId], moduleConfig, globalConfig, 'fetch', actionNameTypeMap.fetch, fetchPromises, docFn) as MagnetarFetchAction<DocDataType, 'doc'>), // prettier-ignore

@@ -96,0 +96,0 @@ stream: handleStreamPerStore([collectionPath, docId], moduleConfig, globalConfig, actionNameTypeMap.stream, streamPromiseInfo), // prettier-ignore

@@ -23,4 +23,2 @@ /* eslint-disable no-inner-declarations */

import { ModuleConfig, GlobalConfig } from '../types/config'
import { CollectionInstance } from '../Collection'
import { DocInstance } from '../Doc'
import { CollectionFn, DocFn } from '../Magnetar'

@@ -53,9 +51,6 @@ import { getPluginModuleConfig } from '../helpers/moduleHelpers'

| MagnetarInsertAction<any>
| MagnetarDeleteAction<any>
| MagnetarDeleteAction
| MagnetarDeletePropAction<any> {
// returns the action the dev can call with myModule.insert() etc.
return function (
payload?: any,
actionConfig: ActionConfig = {}
): Promise<DocInstance | CollectionInstance> {
return function (payload?: any, actionConfig: ActionConfig = {}): Promise<any> {
const fetchPromiseKey = JSON.stringify(payload)

@@ -66,3 +61,3 @@ const foundFetchPromise = fetchPromises.get(fetchPromiseKey)

// eslint-disable-next-line no-async-promise-executor
const actionPromise = new Promise<DocInstance | CollectionInstance>(async (resolve, reject) => {
const actionPromise = new Promise<any>(async (resolve, reject) => {
try {

@@ -197,4 +192,3 @@ let docId = _docId

if (actionName === 'insert' && docId) {
// we do not pass the `moduleConfig`, because it's the moduleConfig of the "collection" in this case
resolve(docFn(modulePath))
resolve(docFn(modulePath, moduleConfig))
return

@@ -205,3 +199,3 @@ }

if (docId || !collectionFn) {
resolve(docFn(modulePath, moduleConfig))
resolve(docFn(modulePath, moduleConfig).data)
if (actionName === 'fetch') fetchPromises.delete(fetchPromiseKey)

@@ -212,4 +206,4 @@ return

// all other actions triggered on collections ('fetch' is the only possibility left)
// should return the collection:
resolve(collectionFn(modulePath, moduleConfig))
// 'fetch' should return `Map<string, DocDataType>` or `DocDataType`
resolve(collectionFn(modulePath, moduleConfig).data)
if (actionName === 'fetch') fetchPromises.delete(fetchPromiseKey)

@@ -216,0 +210,0 @@ } catch (error) {

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

import { DocInstance } from '../Doc'
import { CollectionInstance } from '../Collection'

@@ -31,2 +30,6 @@ /**

/**
* Opens a continuous stream to a document or collection.
* @returns the open stream promise. This will never resolve as long as the stream is open.
*/
export type MagnetarStreamAction = (

@@ -37,2 +40,6 @@ payload?: any | void,

/**
* Fetches document(s) and adds the data to your local store's state.
* @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`.
*/
export type MagnetarFetchAction<

@@ -44,6 +51,11 @@ DocDataType extends Record<string, any> = Record<string, any>,

actionConfig?: ActionConfig
) => Promise<
calledFrom extends 'collection' ? CollectionInstance<DocDataType> : DocInstance<DocDataType>
>
) => Promise<calledFrom extends 'collection' ? Map<string, DocDataType> : DocDataType>
/**
* @returns The new `doc()` instance after inserting. You can access the inserted `id` by checking this returned instance.
* @example
* const newDoc = collection('myDocs').insert({ some: 'payload' })
* newDoc.id // the generated id
* newDoc.data // { some: 'payload' }
*/
export type MagnetarInsertAction<DocDataType extends Record<string, any> = Record<string, any>> = (

@@ -54,7 +66,13 @@ payload: DocDataType,

/**
* @returns the new document data after applying the changes to the local document (including any modifications from modifyPayloadOn)
*/
export type MagnetarWriteAction<DocDataType extends Record<string, any> = Record<string, any>> = (
payload: O.Optional<DocDataType, keyof DocDataType, 'deep'>,
actionConfig?: ActionConfig
) => Promise<DocInstance<DocDataType>>
) => Promise<DocDataType>
/**
* @returns the new document data after applying the changes to the local document (including any modifications from modifyPayloadOn)
*/
export type MagnetarDeletePropAction<

@@ -65,3 +83,3 @@ DocDataType extends Record<string, any> = Record<string, any>

actionConfig?: ActionConfig
) => Promise<DocInstance<DocDataType>>
) => Promise<Partial<DocDataType>>

@@ -74,6 +92,3 @@ /**

*/
export type MagnetarDeleteAction<DocDataType extends Record<string, any> = Record<string, any>> = (
payload?: any,
actionConfig?: ActionConfig
) => Promise<DocInstance<DocDataType>>
export type MagnetarDeleteAction = (payload?: any, actionConfig?: ActionConfig) => Promise<void>

@@ -80,0 +95,0 @@ /**

@@ -20,3 +20,3 @@ import { pokedex } from '@magnetarjs/test-utils'

const { pokedexModule } = createMagnetarInstance()
t.deepEqual(pokedexModule.data.size, 1)
t.is(pokedexModule.data.size, 1)
t.deepEqual(pokedexModule.data.get('1'), pokedex(1))

@@ -29,3 +29,3 @@

}
t.deepEqual(pokedexModule.data.size, 0)
t.is(pokedexModule.data.size, 0)
t.deepEqual(pokedexModule.data.get('1'), undefined)

@@ -32,0 +32,0 @@ })

@@ -37,3 +37,4 @@ import test from 'ava'

try {
const queryModuleRef = await pokedexModule.where('name', '==', 'Flareon').fetch()
const queryModuleRef = pokedexModule.where('name', '==', 'Flareon')
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -50,3 +51,4 @@ const expected = [pokedex(136)]

try {
const queryModuleRef = await pokedexModule.where('name', '!=', 'Bulbasaur').limit(1).fetch()
const queryModuleRef = pokedexModule.where('name', '!=', 'Bulbasaur').limit(1)
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -63,3 +65,4 @@ const expected = [pokedex(2)]

try {
const queryModuleRef = await pokedexModule.where('base.HP', '==', 10).fetch()
const queryModuleRef = pokedexModule.where('base.HP', '==', 10)
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -76,3 +79,4 @@ const expected = [pokedex(50)]

try {
const queryModuleRef = await pokedexModule.where('base.HP', '<', 11).fetch()
const queryModuleRef = pokedexModule.where('base.HP', '<', 11)
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -89,3 +93,4 @@ const expected = [pokedex(50)]

try {
const queryModuleRef = await pokedexModule.where('base.HP', '<=', 10).fetch()
const queryModuleRef = pokedexModule.where('base.HP', '<=', 10)
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -102,3 +107,4 @@ const expected = [pokedex(50)]

try {
const queryModuleRef = await pokedexModule.where('base.HP', '>', 249).fetch()
const queryModuleRef = pokedexModule.where('base.HP', '>', 249)
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -115,3 +121,4 @@ const expected = [pokedex(113)]

try {
const queryModuleRef = await pokedexModule.where('base.HP', '>=', 250).fetch()
const queryModuleRef = pokedexModule.where('base.HP', '>=', 250)
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -128,3 +135,4 @@ const expected = [pokedex(113)]

try {
const queryModuleRef = await pokedexModule.where('type', 'array-contains', 'Steel').fetch()
const queryModuleRef = pokedexModule.where('type', 'array-contains', 'Steel')
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -141,5 +149,4 @@ const expected = [pokedex(81), pokedex(82)]

try {
const queryModuleRef = await pokedexModule
.where('name', 'in', ['Vaporeon', 'Jolteon', 'Flareon'])
.fetch()
const queryModuleRef = pokedexModule.where('name', 'in', ['Vaporeon', 'Jolteon', 'Flareon'])
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -156,6 +163,6 @@ const expected = [pokedex(134), pokedex(135), pokedex(136)]

try {
const queryModuleRef = await pokedexModule
const queryModuleRef = pokedexModule
.where('type', 'array-contains-any', ['Steel', 'Ice'])
.where('name', 'not-in', [pokedex(81).name, pokedex(82).name, pokedex(91).name])
.fetch()
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -172,5 +179,4 @@ const expected = [pokedex(87), pokedex(124), pokedex(131), pokedex(144)]

try {
const queryModuleRef = await pokedexModule
.where('type', 'array-contains-any', ['Steel', 'Ice'])
.fetch()
const queryModuleRef = pokedexModule.where('type', 'array-contains-any', ['Steel', 'Ice'])
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -195,6 +201,6 @@ const expected = [

try {
const queryModuleRef = await pokedexModule
const queryModuleRef = pokedexModule
.where('type', 'array-contains', 'Fire')
.where('base.Speed', '>=', 100)
.fetch()
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -211,7 +217,7 @@ const expected = [pokedex(6), pokedex(38), pokedex(78)]

try {
const queryModuleRef = await pokedexModule
const queryModuleRef = pokedexModule
.where('type', 'array-contains', 'Fire')
.where('base.Speed', '>=', 100)
.orderBy('name', 'desc')
.fetch()
await queryModuleRef.fetch()
// Rapidash 78

@@ -231,3 +237,4 @@ // Ninetales 38

try {
const queryModuleRef = await pokedexModule.limit(10).fetch()
const queryModuleRef = pokedexModule.limit(10)
await queryModuleRef.fetch()
const actual = [...queryModuleRef.data.values()]

@@ -234,0 +241,0 @@ const expected = [

@@ -54,3 +54,3 @@ import test from 'ava'

// check data of reference returned
t.deepEqual(result.data, trainerModule.data)
t.deepEqual(result, trainerModule.data)
} catch (error) {

@@ -79,4 +79,3 @@ t.fail(error)

// check data of reference returned
t.deepEqual(result.data, undefined)
t.deepEqual(result.id, trainerModule.id)
t.deepEqual(result, undefined)
} catch (error) {

@@ -115,4 +114,4 @@ t.fail(error)

const result = await pokedexModule.fetch()
t.deepEqual(result.data.get('1'), pokedex(1))
t.deepEqual(result.data.get('136'), pokedex(136))
t.deepEqual(result.get('1'), pokedex(1))
t.deepEqual(result.get('136'), pokedex(136))
} catch (error) {

@@ -132,3 +131,3 @@ t.fail(error)

const result = await trainerModule.fetch()
t.deepEqual(result.data, { name: 'Luca', age: 10, dream: 'job' })
t.deepEqual(result, { name: 'Luca', age: 10, dream: 'job' })
} catch (error) {

@@ -145,3 +144,4 @@ t.fail(error)

try {
const queryModuleRef = await pokedexModuleWithQuery.fetch()
const queryModuleRef = pokedexModuleWithQuery
await queryModuleRef.fetch()
t.deepEqual([...queryModuleRef.data.values()], [pokedex(136)])

@@ -148,0 +148,0 @@ } catch (error) {

@@ -204,4 +204,4 @@ import test from 'ava'

})
t.deepEqual(result.data.get('1'), pokedex(1))
t.deepEqual(result.data.get('136'), undefined)
t.deepEqual(result.get('1'), pokedex(1))
t.deepEqual(result.get('136'), undefined)
} catch (error) {

@@ -208,0 +208,0 @@ t.fail(error)

@@ -72,3 +72,3 @@ import test from 'ava'

})
t.is(result.id, pokedexModule.id)
t.deepEqual(result.data, pokedexModule.data.get('7'))
} catch (error) {

@@ -75,0 +75,0 @@ t.fail(error)

@@ -12,4 +12,4 @@ import test from 'ava'

// const result = await pokedexModule.fetch()
// t.deepEqual(result.data.get('1'), pokedex(1))
// t.deepEqual(result.data.get('136'), pokedex(136))
// t.deepEqual(result.get('1'), pokedex(1))
// t.deepEqual(result.get('136'), pokedex(136))
// } catch (error) {

@@ -16,0 +16,0 @@ // t.fail(error)

@@ -28,3 +28,3 @@ import test from 'ava'

t.deepEqual(payloadInSuccessEvent, { auth: 'Bearer 123123' })
t.deepEqual(result.data.get('136'), { ...pokedex(136), seen: true })
t.deepEqual(result.get('136'), { ...pokedex(136), seen: true })
} catch (error) {

@@ -114,3 +114,3 @@ t.fail(error)

t.deepEqual(payloadInSuccessEvent, { auth: 'Bearer 123123' })
t.deepEqual(result.data.get('136'), { ...pokedex(136), seen: true })
t.deepEqual(result.get('136'), { ...pokedex(136), seen: true })
} catch (error) {

@@ -198,4 +198,4 @@ t.fail(error)

// the remote result SHOULD HAVE the applied defaults
t.deepEqual(result.data.get('1'), { ...pokedex(1), seen: true })
t.deepEqual(result.data.get('136'), { ...pokedex(136), seen: true })
t.deepEqual(result.get('1'), { ...pokedex(1), seen: true })
t.deepEqual(result.get('136'), { ...pokedex(136), seen: true })
t.deepEqual(payloadInSuccessEvent, { auth: 'Bearer 123123' })

@@ -202,0 +202,0 @@ } catch (error) {

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