@fluid-experimental/property-dds 2.0.0-dev.2.2.0.111723 → 2.0.0-dev.3.1.0.125672

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.
@@ -7,182 +7,218 @@ import { deflate, inflate } from "pako";
7
7
  import { compress, decompress } from "lz4js";
8
8
  import { bufferToString, stringToBuffer } from "@fluidframework/common-utils";
9
9
  import {
10
- IChannelAttributes,
11
- IFluidDataStoreRuntime,
12
- IChannelServices,
13
- IChannelFactory,
10
+ IChannelAttributes,
11
+ IFluidDataStoreRuntime,
12
+ IChannelServices,
13
+ IChannelFactory,
14
14
  } from "@fluidframework/datastore-definitions";
15
15
  import {
16
- IPropertyTreeConfig, IPropertyTreeMessage, ISharedPropertyTreeEncDec,
17
- ISnapshotSummary, SharedPropertyTree, SharedPropertyTreeOptions,
18
- }
19
- from "./propertyTree";
16
+ IPropertyTreeConfig,
17
+ IPropertyTreeMessage,
18
+ ISharedPropertyTreeEncDec,
19
+ ISnapshotSummary,
20
+ SharedPropertyTree,
21
+ SharedPropertyTreeOptions,
22
+ } from "./propertyTree";
20
23
  import { DeflatedPropertyTree, LZ4PropertyTree } from "./propertyTreeExt";
21
24
 
22
25
  export abstract class CompressedPropertyTreeFactory implements IChannelFactory {
23
- public abstract get attributes();
24
- public abstract get type();
25
- public abstract getEncodeFce();
26
- public abstract getDecodeFce();
27
- private createCompressionMethods(encodeFn, decodeFn): ISharedPropertyTreeEncDec {
28
- return {
29
- messageEncoder: {
30
- encode: (change: IPropertyTreeMessage) => {
31
- const changeSetStr = JSON.stringify(change.changeSet);
32
- const unzipped = new TextEncoder().encode(changeSetStr);
33
- const zipped: Buffer = encodeFn(unzipped);
34
- const zippedStr = bufferToString(zipped, "base64");
35
- if (zippedStr.length < changeSetStr.length) {
36
- // eslint-disable-next-line @typescript-eslint/dot-notation
37
- change["isZipped"] = "1";
38
- change.changeSet = zippedStr;
39
- }
40
- return change;
41
- },
42
- decode: (transferChange: IPropertyTreeMessage) => {
43
- // eslint-disable-next-line @typescript-eslint/dot-notation
44
- if (transferChange["isZipped"]) {
45
- const zipped = new Uint8Array(stringToBuffer(transferChange.changeSet, "base64"));
46
- const unzipped = decodeFn(zipped);
47
- const changeSetStr = new TextDecoder().decode(unzipped);
48
- transferChange.changeSet = JSON.parse(changeSetStr);
49
- }
50
- return transferChange;
51
- },
52
- },
53
- summaryEncoder: {
54
- encode: (snapshotSummary: ISnapshotSummary): Buffer => {
55
- const summaryStr = JSON.stringify(snapshotSummary);
56
- const unzipped = new TextEncoder().encode(summaryStr);
57
- const serializedSummary: Buffer = encodeFn(unzipped);
58
- return serializedSummary;
59
- },
60
- decode: (serializedSummary): ISnapshotSummary => {
61
- const unzipped = decodeFn(serializedSummary);
62
- const summaryStr = new TextDecoder().decode(unzipped);
63
- const snapshotSummary: ISnapshotSummary = JSON.parse(summaryStr);
64
- return snapshotSummary;
65
- },
66
- },
67
- };
68
- }
69
- public getEncDec(): ISharedPropertyTreeEncDec {
70
- return this.createCompressionMethods(this.getEncodeFce(), this.getDecodeFce());
71
- }
72
- public abstract newPropertyTree(
73
- id: string,
74
- runtime: IFluidDataStoreRuntime,
75
- attributes: IChannelAttributes,
76
- options: SharedPropertyTreeOptions,
77
- propertyTreeConfig: IPropertyTreeConfig): SharedPropertyTree;
78
-
79
- public async load(
80
- runtime: IFluidDataStoreRuntime,
81
- id: string,
82
- services: IChannelServices,
83
- attributes: IChannelAttributes,
84
- url?: string,
85
- ): Promise<SharedPropertyTree> {
86
- const options = {};
87
- const instance = this.newPropertyTree(id, runtime, attributes,
88
- options as SharedPropertyTreeOptions
89
- , { encDec: this.getEncDec() });
90
- await instance.load(services);
91
- return instance;
92
- }
93
-
94
- public create(document: IFluidDataStoreRuntime, id: string, requestUrl?: string): SharedPropertyTree {
95
- const options = {};
96
- const cell = this.newPropertyTree(id, document,
97
- this.attributes, options as SharedPropertyTreeOptions,
98
- { encDec: this.getEncDec() });
99
- cell.initializeLocal();
100
- return cell;
101
- }
26
+ public abstract get attributes();
27
+ public abstract get type();
28
+ public abstract getEncodeFce();
29
+ public abstract getDecodeFce();
30
+ private createCompressionMethods(encodeFn, decodeFn): ISharedPropertyTreeEncDec {
31
+ return {
32
+ messageEncoder: {
33
+ encode: (change: IPropertyTreeMessage) => {
34
+ const changeSetStr = JSON.stringify(change.changeSet);
35
+ const unzipped = new TextEncoder().encode(changeSetStr);
36
+ const zipped: Buffer = encodeFn(unzipped);
37
+ const zippedStr = bufferToString(zipped, "base64");
38
+ if (zippedStr.length < changeSetStr.length) {
39
+ // eslint-disable-next-line @typescript-eslint/dot-notation
40
+ change["isZipped"] = "1";
41
+ change.changeSet = zippedStr;
42
+ }
43
+ return change;
44
+ },
45
+ decode: (transferChange: IPropertyTreeMessage) => {
46
+ // eslint-disable-next-line @typescript-eslint/dot-notation
47
+ if (transferChange["isZipped"]) {
48
+ const zipped = new Uint8Array(
49
+ stringToBuffer(transferChange.changeSet, "base64"),
50
+ );
51
+ const unzipped = decodeFn(zipped);
52
+ const changeSetStr = new TextDecoder().decode(unzipped);
53
+ transferChange.changeSet = JSON.parse(changeSetStr);
54
+ }
55
+ return transferChange;
56
+ },
57
+ },
58
+ summaryEncoder: {
59
+ encode: (snapshotSummary: ISnapshotSummary): Buffer => {
60
+ const summaryStr = JSON.stringify(snapshotSummary);
61
+ const unzipped = new TextEncoder().encode(summaryStr);
62
+ const serializedSummary: Buffer = encodeFn(unzipped);
63
+ return serializedSummary;
64
+ },
65
+ decode: (serializedSummary): ISnapshotSummary => {
66
+ const unzipped = decodeFn(serializedSummary);
67
+ const summaryStr = new TextDecoder().decode(unzipped);
68
+ const snapshotSummary: ISnapshotSummary = JSON.parse(summaryStr);
69
+ return snapshotSummary;
70
+ },
71
+ },
72
+ };
73
+ }
74
+ public getEncDec(): ISharedPropertyTreeEncDec {
75
+ return this.createCompressionMethods(this.getEncodeFce(), this.getDecodeFce());
76
+ }
77
+ public abstract newPropertyTree(
78
+ id: string,
79
+ runtime: IFluidDataStoreRuntime,
80
+ attributes: IChannelAttributes,
81
+ options: SharedPropertyTreeOptions,
82
+ propertyTreeConfig: IPropertyTreeConfig,
83
+ ): SharedPropertyTree;
84
+
85
+ public async load(
86
+ runtime: IFluidDataStoreRuntime,
87
+ id: string,
88
+ services: IChannelServices,
89
+ attributes: IChannelAttributes,
90
+ url?: string,
91
+ ): Promise<SharedPropertyTree> {
92
+ const options = {};
93
+ const instance = this.newPropertyTree(
94
+ id,
95
+ runtime,
96
+ attributes,
97
+ options as SharedPropertyTreeOptions,
98
+ { encDec: this.getEncDec() },
99
+ );
100
+ await instance.load(services);
101
+ return instance;
102
+ }
103
+
104
+ public create(
105
+ document: IFluidDataStoreRuntime,
106
+ id: string,
107
+ requestUrl?: string,
108
+ ): SharedPropertyTree {
109
+ const options = {};
110
+ const cell = this.newPropertyTree(
111
+ id,
112
+ document,
113
+ this.attributes,
114
+ options as SharedPropertyTreeOptions,
115
+ { encDec: this.getEncDec() },
116
+ );
117
+ cell.initializeLocal();
118
+ return cell;
119
+ }
102
120
  }
103
121
 
104
122
  export class DeflatedPropertyTreeFactory extends CompressedPropertyTreeFactory {
105
- public static readonly Type = "DeflatedPropertyTree:84534a0fe613522101f6";
106
-
107
- public static readonly Attributes: IChannelAttributes = {
108
- type: DeflatedPropertyTreeFactory.Type,
109
- snapshotFormatVersion: "0.1",
110
- packageVersion: "0.0.1",
111
- };
112
-
113
- public async load(
114
- runtime: IFluidDataStoreRuntime,
115
- id: string,
116
- services: IChannelServices,
117
- attributes: IChannelAttributes,
118
- url?: string,
119
- ): Promise<DeflatedPropertyTree> {
120
- return await super.load(runtime, id, services, attributes, url) as DeflatedPropertyTree;
121
- }
122
-
123
- public create(document: IFluidDataStoreRuntime, id: string, requestUrl?: string): DeflatedPropertyTree {
124
- return super.create(document, id, requestUrl);
125
- }
126
-
127
- public get type() {
128
- return DeflatedPropertyTreeFactory.Type;
129
- }
130
-
131
- public get attributes() {
132
- return DeflatedPropertyTreeFactory.Attributes;
133
- }
134
-
135
- public getEncodeFce() { return deflate; }
136
- public getDecodeFce() { return inflate; }
137
- public newPropertyTree(
138
- id: string,
139
- runtime: IFluidDataStoreRuntime,
140
- attributes: IChannelAttributes,
141
- options: SharedPropertyTreeOptions,
142
- propertyTreeConfig: IPropertyTreeConfig): SharedPropertyTree {
143
- return new DeflatedPropertyTree(id, runtime, attributes, options, propertyTreeConfig);
144
- }
123
+ public static readonly Type = "DeflatedPropertyTree:84534a0fe613522101f6";
124
+
125
+ public static readonly Attributes: IChannelAttributes = {
126
+ type: DeflatedPropertyTreeFactory.Type,
127
+ snapshotFormatVersion: "0.1",
128
+ packageVersion: "0.0.1",
129
+ };
130
+
131
+ public async load(
132
+ runtime: IFluidDataStoreRuntime,
133
+ id: string,
134
+ services: IChannelServices,
135
+ attributes: IChannelAttributes,
136
+ url?: string,
137
+ ): Promise<DeflatedPropertyTree> {
138
+ return (await super.load(runtime, id, services, attributes, url)) as DeflatedPropertyTree;
139
+ }
140
+
141
+ public create(
142
+ document: IFluidDataStoreRuntime,
143
+ id: string,
144
+ requestUrl?: string,
145
+ ): DeflatedPropertyTree {
146
+ return super.create(document, id, requestUrl);
147
+ }
148
+
149
+ public get type() {
150
+ return DeflatedPropertyTreeFactory.Type;
151
+ }
152
+
153
+ public get attributes() {
154
+ return DeflatedPropertyTreeFactory.Attributes;
155
+ }
156
+
157
+ public getEncodeFce() {
158
+ return deflate;
159
+ }
160
+ public getDecodeFce() {
161
+ return inflate;
162
+ }
163
+ public newPropertyTree(
164
+ id: string,
165
+ runtime: IFluidDataStoreRuntime,
166
+ attributes: IChannelAttributes,
167
+ options: SharedPropertyTreeOptions,
168
+ propertyTreeConfig: IPropertyTreeConfig,
169
+ ): SharedPropertyTree {
170
+ return new DeflatedPropertyTree(id, runtime, attributes, options, propertyTreeConfig);
171
+ }
145
172
  }
146
173
 
147
174
  export class LZ4PropertyTreeFactory extends CompressedPropertyTreeFactory {
148
- public static readonly Type = "LZ4PropertyTree:84534a0fe613522101f6";
149
-
150
- public static readonly Attributes: IChannelAttributes = {
151
- type: LZ4PropertyTreeFactory.Type,
152
- snapshotFormatVersion: "0.1",
153
- packageVersion: "0.0.1",
154
- };
155
-
156
- public async load(
157
- runtime: IFluidDataStoreRuntime,
158
- id: string,
159
- services: IChannelServices,
160
- attributes: IChannelAttributes,
161
- url?: string,
162
- ): Promise<LZ4PropertyTree> {
163
- return await super.load(runtime, id, services, attributes, url) as LZ4PropertyTree;
164
- }
165
-
166
- public create(document: IFluidDataStoreRuntime, id: string, requestUrl?: string): LZ4PropertyTree {
167
- return super.create(document, id, requestUrl);
168
- }
169
-
170
- public get type() {
171
- return LZ4PropertyTreeFactory.Type;
172
- }
173
-
174
- public get attributes() {
175
- return LZ4PropertyTreeFactory.Attributes;
176
- }
177
-
178
- public getEncodeFce() { return compress; }
179
- public getDecodeFce() { return decompress; }
180
- public newPropertyTree(
181
- id: string,
182
- runtime: IFluidDataStoreRuntime,
183
- attributes: IChannelAttributes,
184
- options: SharedPropertyTreeOptions,
185
- propertyTreeConfig: IPropertyTreeConfig): SharedPropertyTree {
186
- return new LZ4PropertyTree(id, runtime, attributes, options, propertyTreeConfig);
187
- }
175
+ public static readonly Type = "LZ4PropertyTree:84534a0fe613522101f6";
176
+
177
+ public static readonly Attributes: IChannelAttributes = {
178
+ type: LZ4PropertyTreeFactory.Type,
179
+ snapshotFormatVersion: "0.1",
180
+ packageVersion: "0.0.1",
181
+ };
182
+
183
+ public async load(
184
+ runtime: IFluidDataStoreRuntime,
185
+ id: string,
186
+ services: IChannelServices,
187
+ attributes: IChannelAttributes,
188
+ url?: string,
189
+ ): Promise<LZ4PropertyTree> {
190
+ return (await super.load(runtime, id, services, attributes, url)) as LZ4PropertyTree;
191
+ }
192
+
193
+ public create(
194
+ document: IFluidDataStoreRuntime,
195
+ id: string,
196
+ requestUrl?: string,
197
+ ): LZ4PropertyTree {
198
+ return super.create(document, id, requestUrl);
199
+ }
200
+
201
+ public get type() {
202
+ return LZ4PropertyTreeFactory.Type;
203
+ }
204
+
205
+ public get attributes() {
206
+ return LZ4PropertyTreeFactory.Attributes;
207
+ }
208
+
209
+ public getEncodeFce() {
210
+ return compress;
211
+ }
212
+ public getDecodeFce() {
213
+ return decompress;
214
+ }
215
+ public newPropertyTree(
216
+ id: string,
217
+ runtime: IFluidDataStoreRuntime,
218
+ attributes: IChannelAttributes,
219
+ options: SharedPropertyTreeOptions,
220
+ propertyTreeConfig: IPropertyTreeConfig,
221
+ ): SharedPropertyTree {
222
+ return new LZ4PropertyTree(id, runtime, attributes, options, propertyTreeConfig);
223
+ }
188
224
  }
@@ -40,14 +40,28 @@ export class PropertyTreeFactory implements IChannelFactory {
40
40
  ): Promise<SharedPropertyTree> {
41
41
  const options = {};
42
42
  // default object
43
- const instance = new SharedPropertyTree(id, runtime, attributes, options as SharedPropertyTreeOptions);
43
+ const instance = new SharedPropertyTree(
44
+ id,
45
+ runtime,
46
+ attributes,
47
+ options as SharedPropertyTreeOptions,
48
+ );
44
49
  await instance.load(services);
45
50
  return instance;
46
51
  }
47
52
 
48
- public create(document: IFluidDataStoreRuntime, id: string, requestUrl?: string): SharedPropertyTree {
53
+ public create(
54
+ document: IFluidDataStoreRuntime,
55
+ id: string,
56
+ requestUrl?: string,
57
+ ): SharedPropertyTree {
49
58
  const options = {};
50
- const cell = new SharedPropertyTree(id, document, this.attributes, options as SharedPropertyTreeOptions);
59
+ const cell = new SharedPropertyTree(
60
+ id,
61
+ document,
62
+ this.attributes,
63
+ options as SharedPropertyTreeOptions,
64
+ );
51
65
 
52
66
  cell.initializeLocal();
53
67
  return cell;
@@ -2,6 +2,6 @@
2
2
  "extends": "./tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "outDir": "./lib",
5
- "module": "esnext"
6
- }
5
+ "module": "esnext",
6
+ },
7
7
  }
package/tsconfig.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "extends": "@fluidframework/build-common/ts-common-config.json",
3
- "exclude": [
4
- "src/test/**/*"
5
- ],
6
- "compilerOptions": {
3
+ "exclude": ["src/test/**/*"],
4
+ "compilerOptions": {
7
5
  "composite": true,
8
6
  "downlevelIteration": true,
9
7
  "noUnusedLocals": false,
10
8
  "outDir": "./dist",
11
- "rootDir": "./src"
9
+ "rootDir": "./src",
10
+ "types": ["node"],
12
11
  },
13
12
  "include": ["src/**/*"],
14
13
  }