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

@magnetarjs/core

Package Overview
Dependencies
Maintainers
2
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.8.4 to 0.9.0

7

dist/index.d.ts

@@ -11,11 +11,6 @@ import { GlobalConfig, MagnetarInstance, WriteLock } from '@magnetarjs/types';

declare type CollectionPath = string;
declare type DocId = string | undefined;
/**
* Returns a tuple with `[CollectionPath, DocId]` if the `DocId` is `undefined` that means that the `modulePath` passed is a collection!
*
* @param {string} modulePath
* @returns {[CollectionPath, DocId]} is [string, string | undefined]
*/
declare function getCollectionPathDocIdEntry(modulePath: string): [CollectionPath, DocId];
declare function getCollectionPathDocIdEntry(modulePath: string): [CollectionPath: string, DocId: string | undefined];
/**

@@ -22,0 +17,0 @@ * Gets all WriteLock objects of a certain `collectionPath` from the `WriteLockMap`

86

dist/index.js

@@ -33,2 +33,3 @@ "use strict";

var import_getorset_anything2 = require("getorset-anything");
var import_is_what7 = require("is-what");

@@ -222,6 +223,11 @@ // src/Collection.ts

function getPathFilterIdentifier(modulePath, moduleConfig) {
const { limit, orderBy, where, startAfter } = moduleConfig;
const config = JSON.stringify({ limit, orderBy, where, startAfter });
const { where, orderBy, startAfter, limit } = moduleConfig;
const config = JSON.stringify({ where, orderBy, startAfter, limit });
return `${modulePath}${MODULE_IDENTIFIER_SPLIT}${config}`;
}
function getPathWhereOrderByIdentifier(modulePath, moduleConfig) {
const { where, orderBy } = moduleConfig;
const config = JSON.stringify({ where, orderBy });
return `${modulePath}${MODULE_IDENTIFIER_SPLIT}${config}`;
}
function getPluginModuleConfig(moduleConfig, storeName) {

@@ -241,3 +247,3 @@ const { where, orderBy, limit, startAfter, configPerStore = {} } = moduleConfig;

}
function getDataFnFromDataStore(moduleConfig, globalConfig) {
function getDataFromDataStore(moduleConfig, globalConfig, collectionPath, docId) {
const localStoreName = globalConfig.localStoreName;

@@ -250,14 +256,14 @@ throwIfNolocalStoreName(localStoreName);

const pluginModuleConfig = getPluginModuleConfig(moduleConfig, localStoreName);
return (collectionPath, docId) => getModuleData({ collectionPath, docId, pluginModuleConfig });
return getModuleData({ collectionPath, docId, pluginModuleConfig });
}
function getDataProxyHandler([collectionPath, docId], moduleConfig, globalConfig) {
const getModuleData = getDataFnFromDataStore(moduleConfig, globalConfig);
function proxify(target, propExecutionDic) {
const dataHandler = {
get: function(target, key, proxyRef) {
if (key === "data")
return getModuleData(collectionPath, docId);
return Reflect.get(target, key, proxyRef);
get: function(target2, key, proxyRef) {
if (key in propExecutionDic) {
return propExecutionDic[key]();
}
return Reflect.get(target2, key, proxyRef);
}
};
return dataHandler;
return new Proxy(target, dataHandler);
}

@@ -283,3 +289,3 @@

function handleActionPerStore(sharedParams, actionName, actionType) {
const { collectionPath, _docId, moduleConfig, globalConfig, fetchPromises, writeLockMap, docFn, collectionFn } = sharedParams;
const { collectionPath, _docId, moduleConfig, globalConfig, fetchPromises, writeLockMap, docFn, collectionFn, setLastFetched } = sharedParams;
return function(payload, actionConfig = {}) {

@@ -417,3 +423,5 @@ const fetchPromiseKey = JSON.stringify(payload);

if (isFetchResponse(resultFromPlugin)) {
for (const docMetaData of resultFromPlugin.docs) {
const { docs, reachedEnd, last } = resultFromPlugin;
setLastFetched == null ? void 0 : setLastFetched({ reachedEnd, last });
for (const docMetaData of docs) {
executeOnFns(doOnFetchFns, docMetaData.data, [docMetaData]);

@@ -631,12 +639,12 @@ }

// src/Collection.ts
function createCollectionWithContext([collectionPath, docId], moduleConfig, globalConfig, docFn, collectionFn, streamAndFetchPromises) {
function createCollectionWithContext(collectionPath, moduleConfig, globalConfig, docFn, collectionFn, streamAndFetchPromises, fetchMeta) {
const { writeLockMap, fetchPromises, cacheStream, streaming, closeStream, closeAllStreams } = streamAndFetchPromises;
const id = collectionPath.split("/").slice(-1)[0];
const path = collectionPath;
const doc = (docId2, _moduleConfig = {}) => {
return docFn(`${path}/${docId2}`, (0, import_merge_anything.merge)(moduleConfig, _moduleConfig));
const doc = (docId, _moduleConfig = {}) => {
return docFn(`${path}/${docId}`, (0, import_merge_anything.merge)(moduleConfig, _moduleConfig));
};
const sharedParams = {
collectionPath,
_docId: docId,
_docId: void 0,
moduleConfig,

@@ -647,3 +655,4 @@ globalConfig,

docFn,
collectionFn
collectionFn,
setLastFetched: fetchMeta.set
};

@@ -653,5 +662,5 @@ const insert = handleActionPerStore(sharedParams, "insert", import_types.actionNameTypeMap.insert);

const fetch = handleActionPerStore(sharedParams, "fetch", import_types.actionNameTypeMap.fetch);
const stream = handleStreamPerStore([collectionPath, docId], moduleConfig, globalConfig, import_types.actionNameTypeMap.stream, streaming, cacheStream, writeLockMap);
const stream = handleStreamPerStore([collectionPath, void 0], moduleConfig, globalConfig, import_types.actionNameTypeMap.stream, streaming, cacheStream, writeLockMap);
const actions = { stream, fetch, insert, delete: _delete };
executeSetupModulePerStore(globalConfig.stores, [collectionPath, docId], moduleConfig);
executeSetupModulePerStore(globalConfig.stores, [collectionPath, void 0], moduleConfig);
function where(fieldPath, operator, value) {

@@ -671,2 +680,4 @@ const whereClause = [fieldPath, operator, value];

function startAfter(...values) {
if (values[0] === void 0)
return collectionFn(path, moduleConfig);
const isDoc = values[0] && typeof values[0] === "object";

@@ -689,8 +700,6 @@ return collectionFn(path, {

};
const dataProxyHandler = getDataProxyHandler(
[collectionPath, docId],
moduleConfig,
globalConfig
);
return new Proxy(moduleInstance, dataProxyHandler);
return proxify(moduleInstance, {
data: () => getDataFromDataStore(moduleConfig, globalConfig, collectionPath),
fetched: fetchMeta.get
});
}

@@ -721,3 +730,2 @@

const { writeLockMap, fetchPromises, cacheStream, streaming, closeStream } = streamAndFetchPromises;
const id = docId;
const path = [collectionPath, docId].join("/");

@@ -749,3 +757,3 @@ const collection = (collectionId, _moduleConfig = {}) => {

collection,
id,
id: docId,
path,

@@ -756,8 +764,5 @@ streaming,

};
const dataProxyHandler = getDataProxyHandler(
[collectionPath, docId],
moduleConfig,
globalConfig
);
return new Proxy(moduleInstance, dataProxyHandler);
return proxify(moduleInstance, {
data: () => getDataFromDataStore(moduleConfig, globalConfig, collectionPath, docId)
});
}

@@ -773,2 +778,3 @@

const fetchPromiseMap = /* @__PURE__ */ new Map();
const fetchMetaMap = /* @__PURE__ */ new Map();
async function clearAllData() {

@@ -791,2 +797,7 @@ var _a;

const fetchPromises = (0, import_getorset_anything2.mapGetOrSet)(fetchPromiseMap, pathFilterIdentifier, () => /* @__PURE__ */ new Map());
const pathWhereOrderByIdentifier = getPathWhereOrderByIdentifier(modulePath, moduleConfig);
const fetchMeta = {
get: () => fetchMetaMap.get(pathWhereOrderByIdentifier) || { reachedEnd: false, last: void 0 },
set: (payload) => fetchMetaMap.set(pathWhereOrderByIdentifier, payload)
};
function cacheStream(closeStreamFn, streamingPromise) {

@@ -825,3 +836,3 @@ closeStreamFnMap.set(pathFilterIdentifier, closeStreamFn);

};
if (moduleType === "doc") {
if (moduleType === "doc" && (0, import_is_what7.isString)(docId)) {
return createDocWithContext(

@@ -837,3 +848,3 @@ [collectionPath, docId],

return createCollectionWithContext(
[collectionPath, docId],
collectionPath,
moduleConfig,

@@ -843,3 +854,4 @@ globalConfig,

collectionFn,
streamAndFetchPromises
streamAndFetchPromises,
fetchMeta
);

@@ -846,0 +858,0 @@ }

{
"name": "@magnetarjs/core",
"version": "0.8.4",
"version": "0.9.0",
"sideEffects": false,

@@ -23,4 +23,4 @@ "description": "Magnetar core library.",

"dependencies": {
"@magnetarjs/types": "0.8.4",
"@magnetarjs/utils": "0.8.4",
"@magnetarjs/types": "0.9.0",
"@magnetarjs/utils": "0.9.0",
"getorset-anything": "^0.0.2",

@@ -31,3 +31,3 @@ "is-what": "^3.14.1",

"devDependencies": {
"@magnetarjs/test-utils": "0.8.4"
"@magnetarjs/test-utils": "0.9.0"
},

@@ -34,0 +34,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

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