@knotx/plugins-batch 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 格桑
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+
3
+ const core = require('@knotx/core');
4
+ const decorators = require('@knotx/decorators');
5
+ const rxjs = require('rxjs');
6
+
7
+ var __create = Object.create;
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
11
+ var __typeError = (msg) => {
12
+ throw TypeError(msg);
13
+ };
14
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
16
+ var __decoratorStart = (base) => {
17
+ var _a2;
18
+ return [, , , __create((_a2 = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a2 : null)];
19
+ };
20
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
21
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
22
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
23
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
24
+ var __runInitializers = (array, flags, self, value) => {
25
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
26
+ return value;
27
+ };
28
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
29
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
30
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
31
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
32
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
33
+ return __privateGet(this, extra);
34
+ }, set [name](x) {
35
+ return __privateSet(this, extra, x);
36
+ } }, name));
37
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
38
+ for (var i = decorators.length - 1; i >= 0; i--) {
39
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
40
+ if (k) {
41
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
42
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
43
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
44
+ }
45
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
46
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
47
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
48
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
49
+ }
50
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
51
+ };
52
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
53
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
54
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
55
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
56
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
57
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
58
+ var _init_dec, _addNodePipe_dec, _a, _init;
59
+ class Batch extends (_a = core.BasePlugin, _addNodePipe_dec = [decorators.inject.addNodePipe()], _init_dec = [decorators.OnInit], _a) {
60
+ constructor() {
61
+ super(...arguments);
62
+ __runInitializers(_init, 5, this);
63
+ __publicField(this, "name", "batch");
64
+ __publicField(this, "addNodePipe", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
65
+ }
66
+ init() {
67
+ this.addNodePipe({
68
+ transform: (operations$) => rxjs.pipe(
69
+ rxjs.exhaustMap((firstOperation) => {
70
+ if ("draftId" in firstOperation) {
71
+ return rxjs.of([firstOperation]);
72
+ }
73
+ return operations$.pipe(
74
+ rxjs.startWith(firstOperation),
75
+ rxjs.buffer(rxjs.timer(1e3)),
76
+ rxjs.take(1)
77
+ );
78
+ }),
79
+ rxjs.map((operations) => ({
80
+ type: "batch",
81
+ operations: operations.flatMap((op) => op.type === "batch" ? op.operations : op)
82
+ }))
83
+ )
84
+ });
85
+ }
86
+ }
87
+ _init = __decoratorStart(_a);
88
+ __decorateElement(_init, 1, "init", _init_dec, Batch);
89
+ __decorateElement(_init, 5, "addNodePipe", _addNodePipe_dec, Batch);
90
+ __decoratorMetadata(_init, Batch);
91
+
92
+ exports.Batch = Batch;
@@ -0,0 +1,9 @@
1
+ import { BasePlugin } from '@knotx/core';
2
+
3
+ declare class Batch extends BasePlugin<'batch'> {
4
+ name: "batch";
5
+ private addNodePipe;
6
+ init(): void;
7
+ }
8
+
9
+ export { Batch };
@@ -0,0 +1,9 @@
1
+ import { BasePlugin } from '@knotx/core';
2
+
3
+ declare class Batch extends BasePlugin<'batch'> {
4
+ name: "batch";
5
+ private addNodePipe;
6
+ init(): void;
7
+ }
8
+
9
+ export { Batch };
@@ -0,0 +1,9 @@
1
+ import { BasePlugin } from '@knotx/core';
2
+
3
+ declare class Batch extends BasePlugin<'batch'> {
4
+ name: "batch";
5
+ private addNodePipe;
6
+ init(): void;
7
+ }
8
+
9
+ export { Batch };
package/dist/index.mjs ADDED
@@ -0,0 +1,90 @@
1
+ import { BasePlugin } from '@knotx/core';
2
+ import { inject, OnInit } from '@knotx/decorators';
3
+ import { pipe, exhaustMap, of, startWith, buffer, timer, take, map } from 'rxjs';
4
+
5
+ var __create = Object.create;
6
+ var __defProp = Object.defineProperty;
7
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
9
+ var __typeError = (msg) => {
10
+ throw TypeError(msg);
11
+ };
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
+ var __decoratorStart = (base) => {
15
+ var _a2;
16
+ return [, , , __create((_a2 = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a2 : null)];
17
+ };
18
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
19
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
20
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
21
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
22
+ var __runInitializers = (array, flags, self, value) => {
23
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
24
+ return value;
25
+ };
26
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
27
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
28
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
29
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
30
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
31
+ return __privateGet(this, extra);
32
+ }, set [name](x) {
33
+ return __privateSet(this, extra, x);
34
+ } }, name));
35
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
36
+ for (var i = decorators.length - 1; i >= 0; i--) {
37
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
38
+ if (k) {
39
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
40
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
41
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
42
+ }
43
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
44
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
45
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
46
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
47
+ }
48
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
49
+ };
50
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
51
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
52
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
53
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
54
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
55
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
56
+ var _init_dec, _addNodePipe_dec, _a, _init;
57
+ class Batch extends (_a = BasePlugin, _addNodePipe_dec = [inject.addNodePipe()], _init_dec = [OnInit], _a) {
58
+ constructor() {
59
+ super(...arguments);
60
+ __runInitializers(_init, 5, this);
61
+ __publicField(this, "name", "batch");
62
+ __publicField(this, "addNodePipe", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
63
+ }
64
+ init() {
65
+ this.addNodePipe({
66
+ transform: (operations$) => pipe(
67
+ exhaustMap((firstOperation) => {
68
+ if ("draftId" in firstOperation) {
69
+ return of([firstOperation]);
70
+ }
71
+ return operations$.pipe(
72
+ startWith(firstOperation),
73
+ buffer(timer(1e3)),
74
+ take(1)
75
+ );
76
+ }),
77
+ map((operations) => ({
78
+ type: "batch",
79
+ operations: operations.flatMap((op) => op.type === "batch" ? op.operations : op)
80
+ }))
81
+ )
82
+ });
83
+ }
84
+ }
85
+ _init = __decoratorStart(_a);
86
+ __decorateElement(_init, 1, "init", _init_dec, Batch);
87
+ __decorateElement(_init, 5, "addNodePipe", _addNodePipe_dec, Batch);
88
+ __decoratorMetadata(_init, Batch);
89
+
90
+ export { Batch };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@knotx/plugins-batch",
3
+ "type": "module",
4
+ "version": "0.0.0",
5
+ "description": "Batch Plugin for Knotx",
6
+ "author": "boenfu",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/boenfu/knotx#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/boenfu/knotx.git",
12
+ "directory": "packages/plugins-batch"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "sideEffects": false,
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.mjs",
22
+ "require": "./dist/index.cjs"
23
+ }
24
+ },
25
+ "main": "./dist/index.cjs",
26
+ "module": "./dist/index.mjs",
27
+ "types": "./dist/index.d.ts",
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "dependencies": {
32
+ "rxjs": "^7.8.1",
33
+ "@knotx/core": "0.0.0",
34
+ "@knotx/decorators": "0.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "@knotx/eslint-config": "0.0.0",
38
+ "@knotx/jsx": "0.0.0",
39
+ "@knotx/build-config": "0.0.0",
40
+ "@knotx/typescript-config": "0.0.0"
41
+ },
42
+ "scripts": {
43
+ "build": "unbuild --failOnWarn=false",
44
+ "dev": "unbuild --stub",
45
+ "lint": "eslint .",
46
+ "typecheck": "tsc --noEmit"
47
+ }
48
+ }