@knotx/data 0.2.6 → 0.2.7
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/dist/index.cjs +18 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,8 @@ const rxjs = require('rxjs');
|
|
|
4
4
|
const operators = require('rxjs/operators');
|
|
5
5
|
|
|
6
6
|
var __defProp$1 = Object.defineProperty;
|
|
7
|
+
var __defProps = Object.defineProperties;
|
|
8
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
9
|
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
8
10
|
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
9
11
|
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
@@ -19,6 +21,7 @@ var __spreadValues$1 = (a, b) => {
|
|
|
19
21
|
}
|
|
20
22
|
return a;
|
|
21
23
|
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
25
|
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
23
26
|
class DataManager {
|
|
24
27
|
constructor(tag) {
|
|
@@ -133,6 +136,18 @@ class DataManager {
|
|
|
133
136
|
}
|
|
134
137
|
return data;
|
|
135
138
|
}
|
|
139
|
+
dryRun(operation) {
|
|
140
|
+
switch (operation.type) {
|
|
141
|
+
case "commitDraft": {
|
|
142
|
+
const dataMap = this.applyOperation(new Map(this.dataMap$.value), __spreadProps(__spreadValues$1({}, operation), {
|
|
143
|
+
isDryRun: true
|
|
144
|
+
}));
|
|
145
|
+
return dataMap;
|
|
146
|
+
}
|
|
147
|
+
default:
|
|
148
|
+
return this.dataMap$.value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
136
151
|
applyOperation(dataMap, operation) {
|
|
137
152
|
switch (operation.type) {
|
|
138
153
|
case "add":
|
|
@@ -208,6 +223,9 @@ class DataManager {
|
|
|
208
223
|
operations.push({ type: "update", id, data });
|
|
209
224
|
}
|
|
210
225
|
});
|
|
226
|
+
if (operation.isDryRun) {
|
|
227
|
+
return this.applyOperation(dataMap, { type: "batch", operations });
|
|
228
|
+
}
|
|
211
229
|
if (operations.length > 0) {
|
|
212
230
|
this.dispatch({ type: "batch", operations });
|
|
213
231
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -48,6 +48,7 @@ interface DataStartDraftOperation<_T extends IData = IData> {
|
|
|
48
48
|
interface DataCommitDraftOperation<_T extends IData = IData> {
|
|
49
49
|
type: 'commitDraft';
|
|
50
50
|
draftId: string;
|
|
51
|
+
isDryRun?: boolean;
|
|
51
52
|
}
|
|
52
53
|
interface DataDiscardDraftOperation<_T extends IData = IData> {
|
|
53
54
|
type: 'discardDraft';
|
|
@@ -91,6 +92,7 @@ declare class DataManager<TData extends IData = IData, TTag extends string = any
|
|
|
91
92
|
getDraftDataList(draftId: string): TData[] | undefined;
|
|
92
93
|
getDraftData(draftId: string, dataId: string): TData | undefined;
|
|
93
94
|
getCurrentDraftData(dataId: string): TData | undefined;
|
|
95
|
+
dryRun(operation: DataOperation<TData>): Map<string, TData>;
|
|
94
96
|
private applyOperation;
|
|
95
97
|
private updateVersion;
|
|
96
98
|
private isPatchOperation;
|
package/dist/index.d.mts
CHANGED
|
@@ -48,6 +48,7 @@ interface DataStartDraftOperation<_T extends IData = IData> {
|
|
|
48
48
|
interface DataCommitDraftOperation<_T extends IData = IData> {
|
|
49
49
|
type: 'commitDraft';
|
|
50
50
|
draftId: string;
|
|
51
|
+
isDryRun?: boolean;
|
|
51
52
|
}
|
|
52
53
|
interface DataDiscardDraftOperation<_T extends IData = IData> {
|
|
53
54
|
type: 'discardDraft';
|
|
@@ -91,6 +92,7 @@ declare class DataManager<TData extends IData = IData, TTag extends string = any
|
|
|
91
92
|
getDraftDataList(draftId: string): TData[] | undefined;
|
|
92
93
|
getDraftData(draftId: string, dataId: string): TData | undefined;
|
|
93
94
|
getCurrentDraftData(dataId: string): TData | undefined;
|
|
95
|
+
dryRun(operation: DataOperation<TData>): Map<string, TData>;
|
|
94
96
|
private applyOperation;
|
|
95
97
|
private updateVersion;
|
|
96
98
|
private isPatchOperation;
|
package/dist/index.d.ts
CHANGED
|
@@ -48,6 +48,7 @@ interface DataStartDraftOperation<_T extends IData = IData> {
|
|
|
48
48
|
interface DataCommitDraftOperation<_T extends IData = IData> {
|
|
49
49
|
type: 'commitDraft';
|
|
50
50
|
draftId: string;
|
|
51
|
+
isDryRun?: boolean;
|
|
51
52
|
}
|
|
52
53
|
interface DataDiscardDraftOperation<_T extends IData = IData> {
|
|
53
54
|
type: 'discardDraft';
|
|
@@ -91,6 +92,7 @@ declare class DataManager<TData extends IData = IData, TTag extends string = any
|
|
|
91
92
|
getDraftDataList(draftId: string): TData[] | undefined;
|
|
92
93
|
getDraftData(draftId: string, dataId: string): TData | undefined;
|
|
93
94
|
getCurrentDraftData(dataId: string): TData | undefined;
|
|
95
|
+
dryRun(operation: DataOperation<TData>): Map<string, TData>;
|
|
94
96
|
private applyOperation;
|
|
95
97
|
private updateVersion;
|
|
96
98
|
private isPatchOperation;
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@ import { Subject, BehaviorSubject, pipe } from 'rxjs';
|
|
|
2
2
|
import { map, distinctUntilChanged, tap, scan } from 'rxjs/operators';
|
|
3
3
|
|
|
4
4
|
var __defProp$1 = Object.defineProperty;
|
|
5
|
+
var __defProps = Object.defineProperties;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
7
|
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
6
8
|
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
7
9
|
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
@@ -17,6 +19,7 @@ var __spreadValues$1 = (a, b) => {
|
|
|
17
19
|
}
|
|
18
20
|
return a;
|
|
19
21
|
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
23
|
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
24
|
class DataManager {
|
|
22
25
|
constructor(tag) {
|
|
@@ -131,6 +134,18 @@ class DataManager {
|
|
|
131
134
|
}
|
|
132
135
|
return data;
|
|
133
136
|
}
|
|
137
|
+
dryRun(operation) {
|
|
138
|
+
switch (operation.type) {
|
|
139
|
+
case "commitDraft": {
|
|
140
|
+
const dataMap = this.applyOperation(new Map(this.dataMap$.value), __spreadProps(__spreadValues$1({}, operation), {
|
|
141
|
+
isDryRun: true
|
|
142
|
+
}));
|
|
143
|
+
return dataMap;
|
|
144
|
+
}
|
|
145
|
+
default:
|
|
146
|
+
return this.dataMap$.value;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
134
149
|
applyOperation(dataMap, operation) {
|
|
135
150
|
switch (operation.type) {
|
|
136
151
|
case "add":
|
|
@@ -206,6 +221,9 @@ class DataManager {
|
|
|
206
221
|
operations.push({ type: "update", id, data });
|
|
207
222
|
}
|
|
208
223
|
});
|
|
224
|
+
if (operation.isDryRun) {
|
|
225
|
+
return this.applyOperation(dataMap, { type: "batch", operations });
|
|
226
|
+
}
|
|
209
227
|
if (operations.length > 0) {
|
|
210
228
|
this.dispatch({ type: "batch", operations });
|
|
211
229
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/data",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Data for Knotx",
|
|
5
5
|
"author": "boenfu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"rxjs": "^7.8.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@knotx/build-config": "0.2.
|
|
35
|
-
"@knotx/eslint-config": "0.2.
|
|
36
|
-
"@knotx/typescript-config": "0.2.
|
|
34
|
+
"@knotx/build-config": "0.2.7",
|
|
35
|
+
"@knotx/eslint-config": "0.2.7",
|
|
36
|
+
"@knotx/typescript-config": "0.2.7"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "unbuild",
|