@magnetarjs/plugin-vue3
Advanced tools
Comparing version 0.12.13 to 0.13.0
@@ -28,14 +28,13 @@ "use strict"; | ||
// src/CreatePlugin.ts | ||
var import_types2 = require("@magnetarjs/types"); | ||
var import_utils2 = require("@magnetarjs/utils"); | ||
var import_copy_anything = require("copy-anything"); | ||
var import_filter_anything = require("filter-anything"); | ||
var import_getorset_anything = require("getorset-anything"); | ||
var import_is_what7 = require("is-what"); | ||
var import_getorset_anything = require("getorset-anything"); | ||
var import_vue = require("vue"); | ||
var import_types2 = require("@magnetarjs/types"); | ||
var import_utils2 = require("@magnetarjs/utils"); | ||
// src/actions/mergeAssignReplace.ts | ||
var import_merge_anything = require("merge-anything"); | ||
// src/actions/delete.ts | ||
var import_is_what = require("is-what"); | ||
function writeActionFactory(data, Vue3StoreOptions, actionName, makeBackup) { | ||
function deleteActionFactory(data, Vue3StoreOptions, makeBackup) { | ||
return function({ | ||
@@ -47,51 +46,8 @@ payload, | ||
}) { | ||
if (!docId) | ||
throw new Error("An non-existent action was triggered on a collection"); | ||
const collectionMap = data[collectionPath]; | ||
const _docId = docId || payload; | ||
if (!(0, import_is_what.isFullString)(_docId)) | ||
throw new Error("No ID passed to delete action."); | ||
if (makeBackup) | ||
makeBackup(collectionPath, docId); | ||
if (actionName === "replace" || !collectionMap.get(docId)) | ||
collectionMap.set(docId, {}); | ||
const docDataToMutate = collectionMap.get(docId); | ||
if (!docDataToMutate) | ||
throw new Error(`Document data not found for id: ${collectionPath} ${docId}`); | ||
if (actionName === "merge") { | ||
Object.entries(payload).forEach(([key, value]) => { | ||
const originalValue = docDataToMutate[key]; | ||
if ((0, import_is_what.isPlainObject)(originalValue) && (0, import_is_what.isPlainObject)(value)) { | ||
docDataToMutate[key] = (0, import_merge_anything.merge)(originalValue, value); | ||
} else { | ||
docDataToMutate[key] = value; | ||
} | ||
}); | ||
} | ||
if (actionName === "assign" || actionName === "replace") { | ||
Object.entries(payload).forEach(([key, value]) => { | ||
docDataToMutate[key] = value; | ||
}); | ||
} | ||
}; | ||
} | ||
// src/actions/insert.ts | ||
var import_is_what2 = require("is-what"); | ||
function insertActionFactory(data, Vue3StoreOptions, makeBackup) { | ||
return function({ | ||
payload, | ||
collectionPath, | ||
docId, | ||
pluginModuleConfig | ||
}) { | ||
const collectionMap = data[collectionPath]; | ||
const _docId = docId || ((0, import_is_what2.isFullString)(payload.id) ? payload.id : (0, import_is_what2.isNumber)(payload.id) ? `${payload.id}` : Vue3StoreOptions.generateRandomId()); | ||
if (makeBackup) | ||
makeBackup(collectionPath, _docId); | ||
collectionMap.set(_docId, {}); | ||
const docDataToMutate = collectionMap.get(_docId); | ||
if (!docDataToMutate) | ||
throw new Error(`Document data not found for id: ${collectionPath} ${_docId}`); | ||
Object.entries(payload).forEach(([key, value]) => { | ||
docDataToMutate[key] = value; | ||
}); | ||
return _docId; | ||
data[collectionPath].delete(_docId); | ||
}; | ||
@@ -101,3 +57,3 @@ } | ||
// src/actions/deleteProp.ts | ||
var import_is_what3 = require("is-what"); | ||
var import_is_what2 = require("is-what"); | ||
var import_path_to_prop = require("path-to-prop"); | ||
@@ -119,3 +75,3 @@ function deletePropActionFactory(data, Vue3StoreOptions, makeBackup) { | ||
makeBackup(collectionPath, docId); | ||
const payloadArray = (0, import_is_what3.isArray)(payload) ? payload : [payload]; | ||
const payloadArray = (0, import_is_what2.isArray)(payload) ? payload : [payload]; | ||
for (const propToDelete of payloadArray) { | ||
@@ -135,5 +91,9 @@ const isNestedPropPath = /[./]/.test(propToDelete); | ||
// src/actions/delete.ts | ||
// src/actions/fetch.ts | ||
var import_utils = require("@magnetarjs/utils"); | ||
var import_is_what4 = require("is-what"); | ||
function deleteActionFactory(data, Vue3StoreOptions, makeBackup) { | ||
// src/actions/insert.ts | ||
var import_is_what3 = require("is-what"); | ||
function insertActionFactory(data, Vue3StoreOptions, makeBackup) { | ||
return function({ | ||
@@ -145,8 +105,14 @@ payload, | ||
}) { | ||
const _docId = docId || payload; | ||
if (!(0, import_is_what4.isFullString)(_docId)) | ||
throw new Error("No ID passed to delete action."); | ||
const collectionMap = data[collectionPath]; | ||
const _docId = docId || ((0, import_is_what3.isFullString)(payload.id) ? payload.id : (0, import_is_what3.isNumber)(payload.id) ? `${payload.id}` : Vue3StoreOptions.generateRandomId()); | ||
if (makeBackup) | ||
makeBackup(collectionPath, _docId); | ||
data[collectionPath].delete(_docId); | ||
collectionMap.set(_docId, {}); | ||
const docDataToMutate = collectionMap.get(_docId); | ||
if (!docDataToMutate) | ||
throw new Error(`Document data not found for id: ${collectionPath} ${_docId}`); | ||
Object.entries(payload).forEach(([key, value]) => { | ||
docDataToMutate[key] = value; | ||
}); | ||
return _docId; | ||
}; | ||
@@ -156,4 +122,2 @@ } | ||
// src/actions/fetch.ts | ||
var import_is_what5 = require("is-what"); | ||
var import_utils = require("@magnetarjs/utils"); | ||
function fetchActionFactory(data, exists, Vue3StoreOptions) { | ||
@@ -171,4 +135,5 @@ return function({ | ||
if (!docId) { | ||
const { where, orderBy, limit, startAfter } = pluginModuleConfig; | ||
const { query, where, orderBy, limit, startAfter } = pluginModuleConfig; | ||
const collectionData = (0, import_utils.filterDataPerClauses)(data[collectionPath], { | ||
query, | ||
where, | ||
@@ -209,3 +174,3 @@ orderBy, | ||
const doOnFetchAction = (_payload, meta) => { | ||
const _docId = docId ? docId : meta === "error" ? void 0 : (0, import_is_what5.isFullString)(meta?.id) ? meta.id : (0, import_is_what5.isNumber)(meta?.id) ? `${meta.id}` : void 0; | ||
const _docId = docId ? docId : meta === "error" ? void 0 : (0, import_is_what4.isFullString)(meta?.id) ? meta.id : (0, import_is_what4.isNumber)(meta?.id) ? `${meta.id}` : void 0; | ||
const docPath = `${collectionPath}/${_docId}`; | ||
@@ -216,3 +181,3 @@ if (meta === "error") { | ||
} | ||
if ((0, import_is_what5.isBoolean)(meta?.exists)) { | ||
if ((0, import_is_what4.isBoolean)(meta?.exists)) { | ||
exists[docPath] = meta.exists; | ||
@@ -238,2 +203,81 @@ } | ||
// src/actions/fetchCount.ts | ||
var import_types = require("@magnetarjs/types"); | ||
function fetchCountActionFactory(pathCountDic, Vue3StoreOptions) { | ||
return function({ | ||
collectionPath, | ||
actionConfig, | ||
pluginModuleConfig | ||
}) { | ||
const pathId = (0, import_types.getPathWhereIdentifier)(collectionPath, pluginModuleConfig); | ||
const doOnFetchCountAction = ({ count }) => { | ||
if (count === void 0) | ||
return; | ||
pathCountDic[pathId] = count; | ||
}; | ||
return doOnFetchCountAction; | ||
}; | ||
} | ||
// src/actions/mergeAssignReplace.ts | ||
var import_merge_anything = require("merge-anything"); | ||
var import_is_what5 = require("is-what"); | ||
function writeActionFactory(data, Vue3StoreOptions, actionName, makeBackup) { | ||
return function({ | ||
payload, | ||
collectionPath, | ||
docId, | ||
pluginModuleConfig | ||
}) { | ||
if (!docId) | ||
throw new Error("An non-existent action was triggered on a collection"); | ||
const collectionMap = data[collectionPath]; | ||
if (makeBackup) | ||
makeBackup(collectionPath, docId); | ||
if (actionName === "replace" || !collectionMap.get(docId)) | ||
collectionMap.set(docId, {}); | ||
const docDataToMutate = collectionMap.get(docId); | ||
if (!docDataToMutate) | ||
throw new Error(`Document data not found for id: ${collectionPath} ${docId}`); | ||
if (actionName === "merge") { | ||
Object.entries(payload).forEach(([key, value]) => { | ||
const originalValue = docDataToMutate[key]; | ||
if ((0, import_is_what5.isPlainObject)(originalValue) && (0, import_is_what5.isPlainObject)(value)) { | ||
docDataToMutate[key] = (0, import_merge_anything.merge)(originalValue, value); | ||
} else { | ||
docDataToMutate[key] = value; | ||
} | ||
}); | ||
} | ||
if (actionName === "assign" || actionName === "replace") { | ||
Object.entries(payload).forEach(([key, value]) => { | ||
docDataToMutate[key] = value; | ||
}); | ||
} | ||
}; | ||
} | ||
// src/actions/revert.ts | ||
function revertActionFactory(data, Vue3StoreOptions, restoreBackup) { | ||
return function({ | ||
payload, | ||
collectionPath, | ||
docId, | ||
pluginModuleConfig, | ||
actionName, | ||
error | ||
}) { | ||
if (actionName === "stream" || actionName === "fetch") { | ||
return; | ||
} | ||
if (docId && ["insert", "merge", "assign", "replace", "delete", "deleteProp"].includes(actionName)) { | ||
restoreBackup(collectionPath, docId); | ||
return; | ||
} | ||
if (!docId && actionName === "insert") | ||
actionName = "insert on collections"; | ||
console.error(`[@magnetarjs/plugin-vue3] revert not yet implemented for ${actionName}`); | ||
}; | ||
} | ||
// src/actions/stream.ts | ||
@@ -302,43 +346,2 @@ var import_is_what6 = require("is-what"); | ||
// src/actions/revert.ts | ||
function revertActionFactory(data, Vue3StoreOptions, restoreBackup) { | ||
return function({ | ||
payload, | ||
collectionPath, | ||
docId, | ||
pluginModuleConfig, | ||
actionName, | ||
error | ||
}) { | ||
if (actionName === "stream" || actionName === "fetch") { | ||
return; | ||
} | ||
if (docId && ["insert", "merge", "assign", "replace", "delete", "deleteProp"].includes(actionName)) { | ||
restoreBackup(collectionPath, docId); | ||
return; | ||
} | ||
if (!docId && actionName === "insert") | ||
actionName = "insert on collections"; | ||
console.error(`[@magnetarjs/plugin-vue3] revert not yet implemented for ${actionName}`); | ||
}; | ||
} | ||
// src/actions/fetchCount.ts | ||
var import_types = require("@magnetarjs/types"); | ||
function fetchCountActionFactory(pathCountDic, Vue3StoreOptions) { | ||
return function({ | ||
collectionPath, | ||
actionConfig, | ||
pluginModuleConfig | ||
}) { | ||
const pathId = (0, import_types.getPathWhereIdentifier)(collectionPath, pluginModuleConfig); | ||
const doOnFetchCountAction = ({ count }) => { | ||
if (count === void 0) | ||
return; | ||
pathCountDic[pathId] = count; | ||
}; | ||
return doOnFetchCountAction; | ||
}; | ||
} | ||
// src/CreatePlugin.ts | ||
@@ -412,3 +415,9 @@ var CreatePlugin = (vue3StoreOptions) => { | ||
return dataCollectionMap.get(docId); | ||
const clauses = (0, import_filter_anything.pick)(pluginModuleConfig, ["where", "orderBy", "limit", "startAfter"]); | ||
const clauses = (0, import_filter_anything.pick)(pluginModuleConfig, [ | ||
"query", | ||
"where", | ||
"orderBy", | ||
"limit", | ||
"startAfter" | ||
]); | ||
return (0, import_utils2.filterDataPerClauses)(dataCollectionMap, clauses); | ||
@@ -430,3 +439,9 @@ }; | ||
return count; | ||
const clauses = (0, import_filter_anything.pick)(pluginModuleConfig, ["where", "orderBy", "limit", "startAfter"]); | ||
const clauses = (0, import_filter_anything.pick)(pluginModuleConfig, [ | ||
"query", | ||
"where", | ||
"orderBy", | ||
"limit", | ||
"startAfter" | ||
]); | ||
const collectionDB = data[collectionPath]; | ||
@@ -433,0 +448,0 @@ const dataFiltered = (0, import_utils2.filterDataPerClauses)(collectionDB, clauses); |
{ | ||
"name": "@magnetarjs/plugin-vue3", | ||
"version": "0.12.13", | ||
"version": "0.13.0", | ||
"sideEffects": false, | ||
@@ -32,9 +32,9 @@ "description": "Magnetar plugin vue3", | ||
"path-to-prop": "2.0.2", | ||
"@magnetarjs/types": "0.12.13", | ||
"@magnetarjs/utils": "0.12.13" | ||
"@magnetarjs/types": "0.13.0", | ||
"@magnetarjs/utils": "0.13.0" | ||
}, | ||
"devDependencies": { | ||
"vue": "^3.2.45", | ||
"@magnetarjs/core": "0.12.13", | ||
"@magnetarjs/test-utils": "0.12.13" | ||
"@magnetarjs/core": "0.13.0", | ||
"@magnetarjs/test-utils": "0.13.0" | ||
}, | ||
@@ -86,2 +86,3 @@ "keywords": [ | ||
"scripts": { | ||
"typecheck": "tsc --noEmit", | ||
"build": "tsup src/index.ts --clean --format esm,cjs --dts", | ||
@@ -88,0 +89,0 @@ "dev": "pnpm build --watch", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32510
914
+ Added@magnetarjs/types@0.13.0(transitive)
+ Added@magnetarjs/utils@0.13.0(transitive)
- Removed@magnetarjs/types@0.12.13(transitive)
- Removed@magnetarjs/utils@0.12.13(transitive)
Updated@magnetarjs/types@0.13.0
Updated@magnetarjs/utils@0.13.0