lucid-extension-sdk 0.0.133 → 0.0.134
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/package.json +1 -1
- package/sdk/data/branchedcollectionid.d.ts +4 -0
- package/sdk/data/branchedcollectionid.js +16 -0
- package/sdk/data/collectionproxy.d.ts +6 -0
- package/sdk/data/collectionproxy.js +14 -0
- package/sdk/data/patchcollectionproxy.d.ts +52 -0
- package/sdk/data/patchcollectionproxy.js +74 -0
- package/sdk/document/mapproxy.d.ts +1 -0
- package/sdk/document/mapproxy.js +9 -0
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.patchCollectionIdFromPossibleBranchedCollectionId = exports.branchedCollectionId = void 0;
|
|
4
|
+
/** @ignore */
|
|
5
|
+
function branchedCollectionId(upstreamId) {
|
|
6
|
+
return upstreamId + '_b';
|
|
7
|
+
}
|
|
8
|
+
exports.branchedCollectionId = branchedCollectionId;
|
|
9
|
+
/** @ignore */
|
|
10
|
+
function patchCollectionIdFromPossibleBranchedCollectionId(branchId) {
|
|
11
|
+
if (branchId && branchId.endsWith('_b')) {
|
|
12
|
+
return branchId.substring(0, branchId.length - 2);
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
exports.patchCollectionIdFromPossibleBranchedCollectionId = patchCollectionIdFromPossibleBranchedCollectionId;
|
|
@@ -3,6 +3,7 @@ import { MapProxy } from '../document/mapproxy';
|
|
|
3
3
|
import { PropertyStoreProxy } from '../document/propertystoreproxy';
|
|
4
4
|
import { EditorClient } from '../editorclient';
|
|
5
5
|
import { DataItemProxy } from './dataitemproxy';
|
|
6
|
+
import { PatchCollectionProxy } from './patchcollectionproxy';
|
|
6
7
|
import { SchemaDefinition } from './schemadefinition';
|
|
7
8
|
/**
|
|
8
9
|
* A collection is a set of data items, each with the same set of fields (though some data items may not have all
|
|
@@ -30,6 +31,11 @@ export declare class CollectionProxy extends PropertyStoreProxy {
|
|
|
30
31
|
* is not a branch
|
|
31
32
|
*/
|
|
32
33
|
getBranchedFrom(): CollectionProxy | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* @returns information about any changes made locally to the collection that have not been synchronized
|
|
36
|
+
* with the external data source.
|
|
37
|
+
*/
|
|
38
|
+
getLocalChanges(): PatchCollectionProxy | undefined;
|
|
33
39
|
/**
|
|
34
40
|
* The data items in this collection, organized by their primary key. The primary key is usually calculated
|
|
35
41
|
* from the content of the data item, but may differ from the expected value in some circumstances, e.g. if
|
|
@@ -4,7 +4,9 @@ exports.CollectionProxy = void 0;
|
|
|
4
4
|
const checks_1 = require("../core/checks");
|
|
5
5
|
const mapproxy_1 = require("../document/mapproxy");
|
|
6
6
|
const propertystoreproxy_1 = require("../document/propertystoreproxy");
|
|
7
|
+
const branchedcollectionid_1 = require("./branchedcollectionid");
|
|
7
8
|
const dataitemproxy_1 = require("./dataitemproxy");
|
|
9
|
+
const patchcollectionproxy_1 = require("./patchcollectionproxy");
|
|
8
10
|
const schemadefinition_1 = require("./schemadefinition");
|
|
9
11
|
/**
|
|
10
12
|
* A collection is a set of data items, each with the same set of fields (though some data items may not have all
|
|
@@ -51,6 +53,18 @@ class CollectionProxy extends propertystoreproxy_1.PropertyStoreProxy {
|
|
|
51
53
|
const id = this.properties.get('BranchedFrom');
|
|
52
54
|
return id ? new CollectionProxy(id, this.client) : undefined;
|
|
53
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* @returns information about any changes made locally to the collection that have not been synchronized
|
|
58
|
+
* with the external data source.
|
|
59
|
+
*/
|
|
60
|
+
getLocalChanges() {
|
|
61
|
+
const patchCollectionId = (0, branchedcollectionid_1.patchCollectionIdFromPossibleBranchedCollectionId)(this.id);
|
|
62
|
+
const original = this.getBranchedFrom();
|
|
63
|
+
if (!patchCollectionId || !original) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return new patchcollectionproxy_1.PatchCollectionProxy(this.client, this, new CollectionProxy(patchCollectionId, this.client), original);
|
|
67
|
+
}
|
|
54
68
|
patchItems(patch) {
|
|
55
69
|
var _a, _b;
|
|
56
70
|
const changed = {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { EditorClient } from '../editorclient';
|
|
2
|
+
import { CollectionProxy } from './collectionproxy';
|
|
3
|
+
import { DataItemProxy } from './dataitemproxy';
|
|
4
|
+
export declare class PatchedDataItemProxy extends DataItemProxy {
|
|
5
|
+
/**
|
|
6
|
+
* The names of all fields that have been changed locally on this data item and
|
|
7
|
+
* not yet synced back to the external data source.
|
|
8
|
+
*/
|
|
9
|
+
readonly changedFields: string[];
|
|
10
|
+
/**
|
|
11
|
+
* The original data item, before local changes. You can query the original values
|
|
12
|
+
* for the changedFields from this data item.
|
|
13
|
+
*/
|
|
14
|
+
readonly original: DataItemProxy;
|
|
15
|
+
constructor(primaryKey: string, collection: CollectionProxy,
|
|
16
|
+
/**
|
|
17
|
+
* The names of all fields that have been changed locally on this data item and
|
|
18
|
+
* not yet synced back to the external data source.
|
|
19
|
+
*/
|
|
20
|
+
changedFields: string[],
|
|
21
|
+
/**
|
|
22
|
+
* The original data item, before local changes. You can query the original values
|
|
23
|
+
* for the changedFields from this data item.
|
|
24
|
+
*/
|
|
25
|
+
original: DataItemProxy, client: EditorClient);
|
|
26
|
+
}
|
|
27
|
+
export declare class PatchCollectionProxy {
|
|
28
|
+
private readonly client;
|
|
29
|
+
private readonly branchedCollection;
|
|
30
|
+
private readonly patchCollection;
|
|
31
|
+
private readonly originalCollection;
|
|
32
|
+
/**
|
|
33
|
+
* Use CollectionProxy.getLocalChanges() to get a PatchCollectionProxy rather
|
|
34
|
+
* than constructing one directly.
|
|
35
|
+
*/
|
|
36
|
+
constructor(client: EditorClient, branchedCollection: CollectionProxy, patchCollection: CollectionProxy, originalCollection: CollectionProxy);
|
|
37
|
+
/**
|
|
38
|
+
* @returns all data items that have been added to this collection locally, but that
|
|
39
|
+
* have not yet been synced back to the external data source.
|
|
40
|
+
*/
|
|
41
|
+
getAddedItems(): DataItemProxy[];
|
|
42
|
+
/**
|
|
43
|
+
* @returns all data items that were deleted from this collection locally, but that
|
|
44
|
+
* have not yet been deleted in the external data source.
|
|
45
|
+
*/
|
|
46
|
+
getDeletedItems(): DataItemProxy[];
|
|
47
|
+
/**
|
|
48
|
+
* @returns all data items that have been changed locally, but that have not
|
|
49
|
+
* yet been synced back to the external data source.
|
|
50
|
+
*/
|
|
51
|
+
getChangedItems(): PatchedDataItemProxy[];
|
|
52
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PatchCollectionProxy = exports.PatchedDataItemProxy = void 0;
|
|
4
|
+
const dataitemproxy_1 = require("./dataitemproxy");
|
|
5
|
+
class PatchedDataItemProxy extends dataitemproxy_1.DataItemProxy {
|
|
6
|
+
constructor(primaryKey, collection,
|
|
7
|
+
/**
|
|
8
|
+
* The names of all fields that have been changed locally on this data item and
|
|
9
|
+
* not yet synced back to the external data source.
|
|
10
|
+
*/
|
|
11
|
+
changedFields,
|
|
12
|
+
/**
|
|
13
|
+
* The original data item, before local changes. You can query the original values
|
|
14
|
+
* for the changedFields from this data item.
|
|
15
|
+
*/
|
|
16
|
+
original, client) {
|
|
17
|
+
super(primaryKey, collection, client);
|
|
18
|
+
this.changedFields = changedFields;
|
|
19
|
+
this.original = original;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.PatchedDataItemProxy = PatchedDataItemProxy;
|
|
23
|
+
class PatchCollectionProxy {
|
|
24
|
+
/**
|
|
25
|
+
* Use CollectionProxy.getLocalChanges() to get a PatchCollectionProxy rather
|
|
26
|
+
* than constructing one directly.
|
|
27
|
+
*/
|
|
28
|
+
constructor(client, branchedCollection, patchCollection, originalCollection) {
|
|
29
|
+
this.client = client;
|
|
30
|
+
this.branchedCollection = branchedCollection;
|
|
31
|
+
this.patchCollection = patchCollection;
|
|
32
|
+
this.originalCollection = originalCollection;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @returns all data items that have been added to this collection locally, but that
|
|
36
|
+
* have not yet been synced back to the external data source.
|
|
37
|
+
*/
|
|
38
|
+
getAddedItems() {
|
|
39
|
+
//Note: We could get this list directly from the metadata collection associated with the
|
|
40
|
+
//patch collection, but at this time we're not sure we want to expose metadata collections
|
|
41
|
+
//to the extension API, so this somewhat less-performance-optimal solution seems like the
|
|
42
|
+
//best overall answer.
|
|
43
|
+
return this.patchCollection.items.filter((item, primaryKey) => !this.originalCollection.items.get(primaryKey).exists());
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @returns all data items that were deleted from this collection locally, but that
|
|
47
|
+
* have not yet been deleted in the external data source.
|
|
48
|
+
*/
|
|
49
|
+
getDeletedItems() {
|
|
50
|
+
//See comment in getAddedItems
|
|
51
|
+
return this.originalCollection.items.filter((item, primaryKey) => !this.branchedCollection.items.get(primaryKey).exists());
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @returns all data items that have been changed locally, but that have not
|
|
55
|
+
* yet been synced back to the external data source.
|
|
56
|
+
*/
|
|
57
|
+
getChangedItems() {
|
|
58
|
+
const changed = [];
|
|
59
|
+
for (const [primaryKey, patchItem] of this.patchCollection.items) {
|
|
60
|
+
const original = this.originalCollection.items.get(primaryKey);
|
|
61
|
+
if (original.exists()) {
|
|
62
|
+
//Not just using .keys() because we want to filter out undefined values,
|
|
63
|
+
//which the `for...of` iterator on patchItem.fields (MapProxy) does for us.
|
|
64
|
+
const changedFields = [];
|
|
65
|
+
for (const [key] of patchItem.fields) {
|
|
66
|
+
changedFields.push(key);
|
|
67
|
+
}
|
|
68
|
+
changed.push(new PatchedDataItemProxy(primaryKey, this.branchedCollection, changedFields, original, this.client));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return changed;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.PatchCollectionProxy = PatchCollectionProxy;
|
|
@@ -10,6 +10,7 @@ export declare class MapProxy<KEY, VALUE> {
|
|
|
10
10
|
[Symbol.iterator](): Iterator<[KEY, VALUE]>;
|
|
11
11
|
values(): Generator<VALUE, void, unknown>;
|
|
12
12
|
find(filter: (item: VALUE, key: KEY) => boolean): VALUE | undefined;
|
|
13
|
+
filter(filter: (item: VALUE, key: KEY) => boolean): VALUE[];
|
|
13
14
|
keys(): KEY[];
|
|
14
15
|
get size(): number;
|
|
15
16
|
get(key: KEY): VALUE;
|
package/sdk/document/mapproxy.js
CHANGED
|
@@ -35,6 +35,15 @@ class MapProxy {
|
|
|
35
35
|
}
|
|
36
36
|
return undefined;
|
|
37
37
|
}
|
|
38
|
+
filter(filter) {
|
|
39
|
+
const filtered = [];
|
|
40
|
+
for (const [key, value] of this) {
|
|
41
|
+
if (filter(value, key)) {
|
|
42
|
+
filtered.push(value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return filtered;
|
|
46
|
+
}
|
|
38
47
|
keys() {
|
|
39
48
|
return this.getKeys();
|
|
40
49
|
}
|