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.14 to 0.3.0

63

dist/index.cjs.js

@@ -8,13 +8,2 @@ 'use strict';

const actionNameTypeMap = {
fetch: 'read',
stream: 'read',
insert: 'write',
merge: 'write',
assign: 'write',
replace: 'write',
deleteProp: 'write',
delete: 'delete',
};
/*! *****************************************************************************

@@ -45,2 +34,13 @@ Copyright (c) Microsoft Corporation.

const actionNameTypeMap = {
fetch: 'read',
stream: 'read',
insert: 'write',
merge: 'write',
assign: 'write',
replace: 'write',
deleteProp: 'write',
delete: 'delete',
};
/**

@@ -861,2 +861,6 @@ * handleAction is responsible for executing (1) on.before (2) the action provided by the store plugin (3) on.error / on.success (4) optional: onNextStoresSuccess.

/**
* All collections visited so far, kept to be able to clear all data
*/
const collectionNames = new Set();
/**
* the global storage for WriteLock objects

@@ -878,5 +882,40 @@ * @see {@link WriteLock}

const fetchPromiseMap = new Map(); // apply type upon get/set
function awaitAllWriteLocks() {
return __awaiter(this, void 0, void 0, function* () {
for (const [_, writelock] of writeLockMap) {
if (writelock.promise)
yield writelock.promise;
}
});
}
function awaitAllFetches() {
return __awaiter(this, void 0, void 0, function* () {
for (const [_, fetchPromises] of fetchPromiseMap) {
yield Promise.all([...fetchPromises.values()]);
}
});
}
function clearAllData() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
yield awaitAllWriteLocks();
yield awaitAllFetches();
for (const collectionName of collectionNames) {
(_a = collection(collectionName).data) === null || _a === void 0 ? void 0 : _a.clear();
}
});
}
function closeAllStreams() {
return __awaiter(this, void 0, void 0, function* () {
yield awaitAllWriteLocks();
yield awaitAllFetches();
for (const collectionName of collectionNames) {
collection(collectionName).closeAllStreams();
}
});
}
function getModuleInstance(modulePath, moduleConfig = {}, moduleType, docFn, collectionFn) {
throwIfInvalidModulePath(modulePath, moduleType);
const [collectionPath, docId] = getCollectionPathDocIdEntry(modulePath);
collectionNames.add(collectionPath);
const pathFilterIdentifier = getPathFilterIdentifier(modulePath, moduleConfig);

@@ -944,2 +983,4 @@ // grab (and set) the WriteLock for this module

doc: doc,
clearAllData,
closeAllStreams,
};

@@ -946,0 +987,0 @@ return instance;

import { merge, mergeAndConcat } from 'merge-anything';
import { isPlainObject, isFunction, isArray, isFullString, isPromise, isFullArray } from 'is-what';
const actionNameTypeMap = {
fetch: 'read',
stream: 'read',
insert: 'write',
merge: 'write',
assign: 'write',
replace: 'write',
deleteProp: 'write',
delete: 'delete',
};
/*! *****************************************************************************

@@ -40,2 +29,13 @@ Copyright (c) Microsoft Corporation.

const actionNameTypeMap = {
fetch: 'read',
stream: 'read',
insert: 'write',
merge: 'write',
assign: 'write',
replace: 'write',
deleteProp: 'write',
delete: 'delete',
};
/**

@@ -856,2 +856,6 @@ * handleAction is responsible for executing (1) on.before (2) the action provided by the store plugin (3) on.error / on.success (4) optional: onNextStoresSuccess.

/**
* All collections visited so far, kept to be able to clear all data
*/
const collectionNames = new Set();
/**
* the global storage for WriteLock objects

@@ -873,5 +877,40 @@ * @see {@link WriteLock}

const fetchPromiseMap = new Map(); // apply type upon get/set
function awaitAllWriteLocks() {
return __awaiter(this, void 0, void 0, function* () {
for (const [_, writelock] of writeLockMap) {
if (writelock.promise)
yield writelock.promise;
}
});
}
function awaitAllFetches() {
return __awaiter(this, void 0, void 0, function* () {
for (const [_, fetchPromises] of fetchPromiseMap) {
yield Promise.all([...fetchPromises.values()]);
}
});
}
function clearAllData() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
yield awaitAllWriteLocks();
yield awaitAllFetches();
for (const collectionName of collectionNames) {
(_a = collection(collectionName).data) === null || _a === void 0 ? void 0 : _a.clear();
}
});
}
function closeAllStreams() {
return __awaiter(this, void 0, void 0, function* () {
yield awaitAllWriteLocks();
yield awaitAllFetches();
for (const collectionName of collectionNames) {
collection(collectionName).closeAllStreams();
}
});
}
function getModuleInstance(modulePath, moduleConfig = {}, moduleType, docFn, collectionFn) {
throwIfInvalidModulePath(modulePath, moduleType);
const [collectionPath, docId] = getCollectionPathDocIdEntry(modulePath);
collectionNames.add(collectionPath);
const pathFilterIdentifier = getPathFilterIdentifier(modulePath, moduleConfig);

@@ -939,2 +978,4 @@ // grab (and set) the WriteLock for this module

doc: doc,
clearAllData,
closeAllStreams,
};

@@ -941,0 +982,0 @@ return instance;

@@ -20,2 +20,10 @@ /// <reference types="node" />

doc: DocFn;
/**
* Clear all data of the entire Magnetar instance
*/
clearAllData: () => Promise<void>;
/**
* Close all streams of the entire Magnetar instance
*/
closeAllStreams: () => Promise<void>;
}

@@ -22,0 +30,0 @@ /**

7

package.json
{
"name": "@magnetarjs/core",
"version": "0.2.14",
"version": "0.3.0",
"sideEffects": false,

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

"author": "Luca Ban - Mesqueeb",
"funding": "https://github.com/sponsors/mesqueeb",
"license": "TBD",

@@ -26,3 +27,3 @@ "homepage": "https://github.com/cycraft/magnetar#readme",

"devDependencies": {
"@magnetarjs/test-utils": "^0.1.12"
"@magnetarjs/test-utils": "^0.1.13"
},

@@ -70,3 +71,3 @@ "keywords": [

},
"gitHead": "67effeefcd07d8e1dd1683bf461952db9893002e"
"gitHead": "f29396898e679a5a68787cbb9e65ab63289d0343"
}

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

doc: DocFn
/**
* Clear all data of the entire Magnetar instance
*/
clearAllData: () => Promise<void>
/**
* Close all streams of the entire Magnetar instance
*/
closeAllStreams: () => Promise<void>
}

@@ -76,2 +84,7 @@

/**
* All collections visited so far, kept to be able to clear all data
*/
const collectionNames = new Set<string>()
/**
* the global storage for WriteLock objects

@@ -94,2 +107,30 @@ * @see {@link WriteLock}

async function awaitAllWriteLocks (): Promise<void> {
for (const [_, writelock] of writeLockMap) {
if (writelock.promise) await writelock.promise
}
}
async function awaitAllFetches (): Promise<void> {
for (const [_, fetchPromises] of fetchPromiseMap) {
await Promise.all([...fetchPromises.values()])
}
}
async function clearAllData (): Promise<void> {
await awaitAllWriteLocks()
await awaitAllFetches()
for (const collectionName of collectionNames) {
collection(collectionName).data?.clear()
}
}
async function closeAllStreams (): Promise<void> {
await awaitAllWriteLocks()
await awaitAllFetches()
for (const collectionName of collectionNames) {
collection(collectionName).closeAllStreams()
}
}
function getModuleInstance(

@@ -105,2 +146,4 @@ modulePath: string,

const [collectionPath, docId] = getCollectionPathDocIdEntry(modulePath)
collectionNames.add(collectionPath)
const pathFilterIdentifier = getPathFilterIdentifier(modulePath, moduleConfig)

@@ -188,4 +231,6 @@

doc: doc as DocFn,
clearAllData,
closeAllStreams,
}
return instance
}
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