@web-ts-toolkit/moo 0.36.0 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ // src/plugins/new-document.ts
2
+ var stateKey = "newDocumentPlugin";
3
+ function newDocumentPlugin(schema, options) {
4
+ schema.pre("save", function newDocumentPluginPreSave() {
5
+ this.$locals[stateKey] = { wasNew: this.isNew };
6
+ });
7
+ schema.post("save", async function newDocumentPluginPostSave(document) {
8
+ const state = this.$locals[stateKey];
9
+ if (!state?.wasNew) return;
10
+ await options.fn.call(this, document);
11
+ });
12
+ }
13
+ export {
14
+ newDocumentPlugin
15
+ };