lucid-extension-sdk 0.0.278 → 0.0.283
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/dataconnector/actions/action.d.ts +4 -38
- package/dataconnector/actions/action.js +1 -43
- package/dataconnector/actions/patch.d.ts +101 -0
- package/dataconnector/actions/patch.js +177 -0
- package/dataconnector/actions/serializedactions.d.ts +2 -1
- package/dataconnector/actions/serializedactions.js +27 -20
- package/dataconnector/actions/serializedpatchtypes.d.ts +79 -0
- package/dataconnector/actions/serializedpatchtypes.js +35 -0
- package/dataconnector/dataconnector.d.ts +8 -5
- package/dataconnector/dataconnector.js +4 -2
- package/dataconnector/dataconnectorclient.d.ts +2 -1
- package/dataconnector/dataconnectorclient.js +2 -2
- package/dataconnector/datasourceupdatetypes.d.ts +3 -1
- package/dataconnector/datasourceupdatetypes.js +6 -2
- package/dataconnector/debugserver.d.ts +3 -2
- package/dataconnector/itemrekeyer.d.ts +2 -1
- package/dataconnector/itemrekeyer.js +5 -2
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataUpdateFilterType } from '../../data/dataupdatefiltertype';
|
|
2
2
|
import { DataSourceClient } from '../datasourceclient';
|
|
3
|
-
import {
|
|
3
|
+
import { ItemPatch, Patch } from './patch';
|
|
4
4
|
export type CollectionId = string;
|
|
5
5
|
export type ItemPrimaryKey = string;
|
|
6
6
|
/**
|
|
@@ -68,49 +68,15 @@ export type PatchItems = {
|
|
|
68
68
|
[fieldName: string]: unknown;
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
|
-
/** A patch to be applied against the 3rd party datasource with changes coming from Lucid */
|
|
72
|
-
export declare class Patch {
|
|
73
|
-
/** The id of the patch */
|
|
74
|
-
id: string;
|
|
75
|
-
/** Mapping of item primary keys to new items introduced by Lucid */
|
|
76
|
-
itemsAdded: PatchItems;
|
|
77
|
-
/** Mapping of item primary keys to sparse changesets of pre-existing items changed by Lucid */
|
|
78
|
-
itemsChanged: PatchItems;
|
|
79
|
-
/** List of item primary keys deleted by Lucid */
|
|
80
|
-
itemsDeleted: string[];
|
|
81
|
-
/** */
|
|
82
|
-
itemOrderChanged: [string, string | null][] | undefined;
|
|
83
|
-
/** The syncSourceId of the changed data source */
|
|
84
|
-
syncSourceId: string;
|
|
85
|
-
/** The syncCollectionId of the changed collection */
|
|
86
|
-
syncCollectionId: CollectionId;
|
|
87
|
-
constructor(
|
|
88
|
-
/** The id of the patch */
|
|
89
|
-
id: string,
|
|
90
|
-
/** Mapping of item primary keys to new items introduced by Lucid */
|
|
91
|
-
itemsAdded: PatchItems,
|
|
92
|
-
/** Mapping of item primary keys to sparse changesets of pre-existing items changed by Lucid */
|
|
93
|
-
itemsChanged: PatchItems,
|
|
94
|
-
/** List of item primary keys deleted by Lucid */
|
|
95
|
-
itemsDeleted: string[],
|
|
96
|
-
/** */
|
|
97
|
-
itemOrderChanged: [string, string | null][] | undefined,
|
|
98
|
-
/** The syncSourceId of the changed data source */
|
|
99
|
-
syncSourceId: string,
|
|
100
|
-
/** The syncCollectionId of the changed collection */
|
|
101
|
-
syncCollectionId: CollectionId);
|
|
102
|
-
getChange(collections?: PatchChangeCollection[]): PatchChange;
|
|
103
|
-
toJSON(): object;
|
|
104
|
-
}
|
|
105
71
|
/**
|
|
106
72
|
* A patch action is a kind of synchronous style action. It occurs when data is changed in the Lucid editor. All the
|
|
107
73
|
* changes are collected in the patches field.
|
|
108
74
|
**/
|
|
109
|
-
export declare class DataConnectorPatchAction extends DataConnectorAction {
|
|
110
|
-
/** changes applied by Lucid */ patches:
|
|
75
|
+
export declare class DataConnectorPatchAction<P extends Patch = ItemPatch> extends DataConnectorAction {
|
|
76
|
+
/** changes applied by Lucid */ patches: P[];
|
|
111
77
|
client: DataSourceClient;
|
|
112
78
|
constructor(context: DataConnectorActionContext,
|
|
113
|
-
/** changes applied by Lucid */ patches:
|
|
79
|
+
/** changes applied by Lucid */ patches: P[], client: DataSourceClient, name?: string);
|
|
114
80
|
}
|
|
115
81
|
/**
|
|
116
82
|
* A description of an existing webhook that Lucid is keeping track of.
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataConnectorManageWebhookAction = exports.Webhook = exports.DataConnectorPatchAction = exports.
|
|
3
|
+
exports.DataConnectorManageWebhookAction = exports.Webhook = exports.DataConnectorPatchAction = exports.DataConnectorSynchronousAction = exports.DataConnectorAsynchronousAction = exports.DataConnectorAction = exports.DataConnectorActionContext = void 0;
|
|
4
4
|
const dataconnectoractionkeys_1 = require("./dataconnectoractionkeys");
|
|
5
|
-
const patchresponsebody_1 = require("./patchresponsebody");
|
|
6
5
|
/**
|
|
7
6
|
* This holds all the contextual information about a give data action.
|
|
8
7
|
*/
|
|
@@ -62,47 +61,6 @@ class DataConnectorSynchronousAction extends DataConnectorAction {
|
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
exports.DataConnectorSynchronousAction = DataConnectorSynchronousAction;
|
|
65
|
-
/** A patch to be applied against the 3rd party datasource with changes coming from Lucid */
|
|
66
|
-
class Patch {
|
|
67
|
-
constructor(
|
|
68
|
-
/** The id of the patch */
|
|
69
|
-
id,
|
|
70
|
-
/** Mapping of item primary keys to new items introduced by Lucid */
|
|
71
|
-
itemsAdded,
|
|
72
|
-
/** Mapping of item primary keys to sparse changesets of pre-existing items changed by Lucid */
|
|
73
|
-
itemsChanged,
|
|
74
|
-
/** List of item primary keys deleted by Lucid */
|
|
75
|
-
itemsDeleted,
|
|
76
|
-
/** */
|
|
77
|
-
itemOrderChanged,
|
|
78
|
-
/** The syncSourceId of the changed data source */
|
|
79
|
-
syncSourceId,
|
|
80
|
-
/** The syncCollectionId of the changed collection */
|
|
81
|
-
syncCollectionId) {
|
|
82
|
-
this.id = id;
|
|
83
|
-
this.itemsAdded = itemsAdded;
|
|
84
|
-
this.itemsChanged = itemsChanged;
|
|
85
|
-
this.itemsDeleted = itemsDeleted;
|
|
86
|
-
this.itemOrderChanged = itemOrderChanged;
|
|
87
|
-
this.syncSourceId = syncSourceId;
|
|
88
|
-
this.syncCollectionId = syncCollectionId;
|
|
89
|
-
}
|
|
90
|
-
getChange(collections = []) {
|
|
91
|
-
return new patchresponsebody_1.PatchChange(this.id, this.syncSourceId, collections);
|
|
92
|
-
}
|
|
93
|
-
toJSON() {
|
|
94
|
-
return {
|
|
95
|
-
'Id': this.id,
|
|
96
|
-
'ItemsAdded': this.itemsAdded,
|
|
97
|
-
'ItemsChanged': this.itemsChanged,
|
|
98
|
-
'ItemsDeleted': this.itemsDeleted,
|
|
99
|
-
'ItemOrderChanged': this.itemOrderChanged,
|
|
100
|
-
'SyncSourceId': this.syncSourceId,
|
|
101
|
-
'SyncCollectionId': this.syncCollectionId,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.Patch = Patch;
|
|
106
64
|
/**
|
|
107
65
|
* A patch action is a kind of synchronous style action. It occurs when data is changed in the Lucid editor. All the
|
|
108
66
|
* changes are collected in the patches field.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { FieldTypeDefinition } from '../../core/data/fieldtypedefinition/fieldtypedefinition';
|
|
2
|
+
import { CollectionId, PatchItems } from './action';
|
|
3
|
+
import { PatchChange, PatchChangeCollection } from './patchresponsebody';
|
|
4
|
+
import { SerializedThirdPartyColumn, SerializedThirdPartyColumnPatch } from './serializedpatchtypes';
|
|
5
|
+
export type PatchParser<P extends Patch> = (id: string, x: unknown) => P | undefined;
|
|
6
|
+
/** A patch to be applied against the 3rd party datasource with changes coming from Lucid */
|
|
7
|
+
export declare abstract class Patch {
|
|
8
|
+
/** The id of the patch */
|
|
9
|
+
id: string;
|
|
10
|
+
/** The syncSourceId of the changed data source */
|
|
11
|
+
syncSourceId: string;
|
|
12
|
+
/** The syncCollectionId of the changed collection */
|
|
13
|
+
syncCollectionId: CollectionId;
|
|
14
|
+
constructor(
|
|
15
|
+
/** The id of the patch */
|
|
16
|
+
id: string,
|
|
17
|
+
/** The syncSourceId of the changed data source */
|
|
18
|
+
syncSourceId: string,
|
|
19
|
+
/** The syncCollectionId of the changed collection */
|
|
20
|
+
syncCollectionId: CollectionId);
|
|
21
|
+
getChange(collections?: PatchChangeCollection[]): PatchChange;
|
|
22
|
+
abstract toJSON(): object;
|
|
23
|
+
abstract clone(): this;
|
|
24
|
+
}
|
|
25
|
+
export declare const genericPatchParser: PatchParser<Patch>;
|
|
26
|
+
export declare class ItemPatch extends Patch {
|
|
27
|
+
/** Mapping of item primary keys to new items introduced by Lucid */
|
|
28
|
+
itemsAdded: PatchItems;
|
|
29
|
+
/** Mapping of item primary keys to sparse changesets of pre-existing items changed by Lucid */
|
|
30
|
+
itemsChanged: PatchItems;
|
|
31
|
+
/** List of item primary keys deleted by Lucid */
|
|
32
|
+
itemsDeleted: string[];
|
|
33
|
+
/** */
|
|
34
|
+
itemOrderChanged: [string, string | null][] | undefined;
|
|
35
|
+
constructor(
|
|
36
|
+
/** The id of the patch */
|
|
37
|
+
id: string,
|
|
38
|
+
/** Mapping of item primary keys to new items introduced by Lucid */
|
|
39
|
+
itemsAdded: PatchItems,
|
|
40
|
+
/** Mapping of item primary keys to sparse changesets of pre-existing items changed by Lucid */
|
|
41
|
+
itemsChanged: PatchItems,
|
|
42
|
+
/** List of item primary keys deleted by Lucid */
|
|
43
|
+
itemsDeleted: string[],
|
|
44
|
+
/** */
|
|
45
|
+
itemOrderChanged: [string, string | null][] | undefined,
|
|
46
|
+
/** The syncSourceId of the changed data source */
|
|
47
|
+
syncSourceId: string,
|
|
48
|
+
/** The syncCollectionId of the changed collection */
|
|
49
|
+
syncCollectionId: CollectionId);
|
|
50
|
+
toJSON(): object;
|
|
51
|
+
clone(): this;
|
|
52
|
+
}
|
|
53
|
+
export declare const itemPatchParser: PatchParser<ItemPatch>;
|
|
54
|
+
export declare class ThirdPartyColumn {
|
|
55
|
+
readonly name: string;
|
|
56
|
+
readonly fieldType: FieldTypeDefinition;
|
|
57
|
+
constructor(name: string, fieldType: FieldTypeDefinition);
|
|
58
|
+
clone(): ThirdPartyColumn;
|
|
59
|
+
toJSON(): object;
|
|
60
|
+
static deserialize(data: SerializedThirdPartyColumn): ThirdPartyColumn;
|
|
61
|
+
}
|
|
62
|
+
export declare class ThirdPartyColumnPatch {
|
|
63
|
+
readonly name?: string | undefined;
|
|
64
|
+
readonly fieldType?: FieldTypeDefinition | undefined;
|
|
65
|
+
constructor(name?: string | undefined, fieldType?: FieldTypeDefinition | undefined);
|
|
66
|
+
clone(): ThirdPartyColumnPatch;
|
|
67
|
+
toJSON(): object;
|
|
68
|
+
static deserialize(data: SerializedThirdPartyColumnPatch): ThirdPartyColumnPatch;
|
|
69
|
+
}
|
|
70
|
+
export declare class SchemaPatch extends Patch {
|
|
71
|
+
/** Mapping of item primary keys to new items introduced by Lucid */
|
|
72
|
+
columnsAdded: ThirdPartyColumn[];
|
|
73
|
+
/** Mapping of item primary keys to sparse changesets of pre-existing items changed by Lucid */
|
|
74
|
+
columnsChanged: Record<string, ThirdPartyColumnPatch>;
|
|
75
|
+
/** List of item primary keys deleted by Lucid */
|
|
76
|
+
columnsDeleted: string[];
|
|
77
|
+
/** */
|
|
78
|
+
columnOrdering: [string, string | null][] | undefined;
|
|
79
|
+
/** Changes to the primary key */
|
|
80
|
+
primaryKey: string[] | undefined;
|
|
81
|
+
constructor(
|
|
82
|
+
/** The id of the patch */
|
|
83
|
+
id: string,
|
|
84
|
+
/** Mapping of item primary keys to new items introduced by Lucid */
|
|
85
|
+
columnsAdded: ThirdPartyColumn[],
|
|
86
|
+
/** Mapping of item primary keys to sparse changesets of pre-existing items changed by Lucid */
|
|
87
|
+
columnsChanged: Record<string, ThirdPartyColumnPatch>,
|
|
88
|
+
/** List of item primary keys deleted by Lucid */
|
|
89
|
+
columnsDeleted: string[],
|
|
90
|
+
/** */
|
|
91
|
+
columnOrdering: [string, string | null][] | undefined,
|
|
92
|
+
/** Changes to the primary key */
|
|
93
|
+
primaryKey: string[] | undefined,
|
|
94
|
+
/** The syncSourceId of the changed data source */
|
|
95
|
+
syncSourceId: string,
|
|
96
|
+
/** The syncCollectionId of the changed collection */
|
|
97
|
+
syncCollectionId: CollectionId);
|
|
98
|
+
toJSON(): object;
|
|
99
|
+
clone(): this;
|
|
100
|
+
}
|
|
101
|
+
export declare const schemaPatchParser: PatchParser<SchemaPatch>;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schemaPatchParser = exports.SchemaPatch = exports.ThirdPartyColumnPatch = exports.ThirdPartyColumn = exports.itemPatchParser = exports.ItemPatch = exports.genericPatchParser = exports.Patch = void 0;
|
|
4
|
+
const fieldtypedefinition_1 = require("../../core/data/fieldtypedefinition/fieldtypedefinition");
|
|
5
|
+
const patchresponsebody_1 = require("./patchresponsebody");
|
|
6
|
+
const serializedpatchtypes_1 = require("./serializedpatchtypes");
|
|
7
|
+
function objMap(obj, f) {
|
|
8
|
+
const result = {};
|
|
9
|
+
for (const key in obj) {
|
|
10
|
+
result[key] = f(obj[key]);
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
/** A patch to be applied against the 3rd party datasource with changes coming from Lucid */
|
|
15
|
+
class Patch {
|
|
16
|
+
constructor(
|
|
17
|
+
/** The id of the patch */
|
|
18
|
+
id,
|
|
19
|
+
/** The syncSourceId of the changed data source */
|
|
20
|
+
syncSourceId,
|
|
21
|
+
/** The syncCollectionId of the changed collection */
|
|
22
|
+
syncCollectionId) {
|
|
23
|
+
this.id = id;
|
|
24
|
+
this.syncSourceId = syncSourceId;
|
|
25
|
+
this.syncCollectionId = syncCollectionId;
|
|
26
|
+
}
|
|
27
|
+
getChange(collections = []) {
|
|
28
|
+
return new patchresponsebody_1.PatchChange(this.id, this.syncSourceId, collections);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Patch = Patch;
|
|
32
|
+
const genericPatchParser = (id, x) => {
|
|
33
|
+
var _a;
|
|
34
|
+
return (_a = (0, exports.itemPatchParser)(id, x)) !== null && _a !== void 0 ? _a : (0, exports.schemaPatchParser)(id, x);
|
|
35
|
+
};
|
|
36
|
+
exports.genericPatchParser = genericPatchParser;
|
|
37
|
+
class ItemPatch extends Patch {
|
|
38
|
+
constructor(
|
|
39
|
+
/** The id of the patch */
|
|
40
|
+
id,
|
|
41
|
+
/** Mapping of item primary keys to new items introduced by Lucid */
|
|
42
|
+
itemsAdded,
|
|
43
|
+
/** Mapping of item primary keys to sparse changesets of pre-existing items changed by Lucid */
|
|
44
|
+
itemsChanged,
|
|
45
|
+
/** List of item primary keys deleted by Lucid */
|
|
46
|
+
itemsDeleted,
|
|
47
|
+
/** */
|
|
48
|
+
itemOrderChanged,
|
|
49
|
+
/** The syncSourceId of the changed data source */
|
|
50
|
+
syncSourceId,
|
|
51
|
+
/** The syncCollectionId of the changed collection */
|
|
52
|
+
syncCollectionId) {
|
|
53
|
+
super(id, syncSourceId, syncCollectionId);
|
|
54
|
+
this.itemsAdded = itemsAdded;
|
|
55
|
+
this.itemsChanged = itemsChanged;
|
|
56
|
+
this.itemsDeleted = itemsDeleted;
|
|
57
|
+
this.itemOrderChanged = itemOrderChanged;
|
|
58
|
+
}
|
|
59
|
+
toJSON() {
|
|
60
|
+
return {
|
|
61
|
+
'Id': this.id,
|
|
62
|
+
'ItemsAdded': this.itemsAdded,
|
|
63
|
+
'ItemsChanged': this.itemsChanged,
|
|
64
|
+
'ItemsDeleted': this.itemsDeleted,
|
|
65
|
+
'ItemOrderChanged': this.itemOrderChanged,
|
|
66
|
+
'SyncSourceId': this.syncSourceId,
|
|
67
|
+
'SyncCollectionId': this.syncCollectionId,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
clone() {
|
|
71
|
+
return new ItemPatch(this.id, objMap(this.itemsAdded, (item) => objMap(item, (v) => v)), objMap(this.itemsChanged, (item) => objMap(item, (v) => v)), [...this.itemsDeleted], this.itemOrderChanged && [...this.itemOrderChanged], this.syncSourceId, this.syncCollectionId);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.ItemPatch = ItemPatch;
|
|
75
|
+
function _itemPatchParser(id, patch) {
|
|
76
|
+
var _a;
|
|
77
|
+
return new ItemPatch(id, patch['itemsAdded'], patch['itemsChanged'], patch['itemsDeleted'], (_a = patch['itemOrderChanged']) !== null && _a !== void 0 ? _a : undefined, patch['syncSourceId'], patch['syncCollectionId']);
|
|
78
|
+
}
|
|
79
|
+
const itemPatchParser = (id, patch) => {
|
|
80
|
+
if ((0, serializedpatchtypes_1.patchItemValidator)(patch)) {
|
|
81
|
+
return _itemPatchParser(id, patch);
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
};
|
|
85
|
+
exports.itemPatchParser = itemPatchParser;
|
|
86
|
+
class ThirdPartyColumn {
|
|
87
|
+
constructor(name, fieldType) {
|
|
88
|
+
this.name = name;
|
|
89
|
+
this.fieldType = fieldType;
|
|
90
|
+
}
|
|
91
|
+
clone() {
|
|
92
|
+
return new ThirdPartyColumn(this.name, this.fieldType);
|
|
93
|
+
}
|
|
94
|
+
toJSON() {
|
|
95
|
+
return { 'Name': this.name, 'FieldType': (0, fieldtypedefinition_1.serializeFieldTypeDefinition)(this.fieldType) };
|
|
96
|
+
}
|
|
97
|
+
static deserialize(data) {
|
|
98
|
+
return new ThirdPartyColumn(data['name'], (0, fieldtypedefinition_1.deserializeFieldTypeDefinition)(data['fieldType']));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.ThirdPartyColumn = ThirdPartyColumn;
|
|
102
|
+
class ThirdPartyColumnPatch {
|
|
103
|
+
constructor(name, fieldType) {
|
|
104
|
+
this.name = name;
|
|
105
|
+
this.fieldType = fieldType;
|
|
106
|
+
}
|
|
107
|
+
clone() {
|
|
108
|
+
return new ThirdPartyColumnPatch(this.name, this.fieldType);
|
|
109
|
+
}
|
|
110
|
+
toJSON() {
|
|
111
|
+
return {
|
|
112
|
+
'Name': this.name,
|
|
113
|
+
'FieldType': this.fieldType != null ? (0, fieldtypedefinition_1.serializeFieldTypeDefinition)(this.fieldType) : undefined,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
static deserialize(data) {
|
|
117
|
+
var _a;
|
|
118
|
+
const result = new ThirdPartyColumnPatch((_a = data['name']) !== null && _a !== void 0 ? _a : undefined, data['fieldType'] != null ? (0, fieldtypedefinition_1.deserializeFieldTypeDefinition)(data['fieldType']) : undefined);
|
|
119
|
+
console.log(`\n\nSerialization result: ${JSON.stringify(result.toJSON())}\n\n`);
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.ThirdPartyColumnPatch = ThirdPartyColumnPatch;
|
|
124
|
+
class SchemaPatch extends Patch {
|
|
125
|
+
constructor(
|
|
126
|
+
/** The id of the patch */
|
|
127
|
+
id,
|
|
128
|
+
/** Mapping of item primary keys to new items introduced by Lucid */
|
|
129
|
+
columnsAdded,
|
|
130
|
+
/** Mapping of item primary keys to sparse changesets of pre-existing items changed by Lucid */
|
|
131
|
+
columnsChanged,
|
|
132
|
+
/** List of item primary keys deleted by Lucid */
|
|
133
|
+
columnsDeleted,
|
|
134
|
+
/** */
|
|
135
|
+
columnOrdering,
|
|
136
|
+
/** Changes to the primary key */
|
|
137
|
+
primaryKey,
|
|
138
|
+
/** The syncSourceId of the changed data source */
|
|
139
|
+
syncSourceId,
|
|
140
|
+
/** The syncCollectionId of the changed collection */
|
|
141
|
+
syncCollectionId) {
|
|
142
|
+
super(id, syncSourceId, syncCollectionId);
|
|
143
|
+
this.columnsAdded = columnsAdded;
|
|
144
|
+
this.columnsChanged = columnsChanged;
|
|
145
|
+
this.columnsDeleted = columnsDeleted;
|
|
146
|
+
this.columnOrdering = columnOrdering;
|
|
147
|
+
this.primaryKey = primaryKey;
|
|
148
|
+
}
|
|
149
|
+
toJSON() {
|
|
150
|
+
return {
|
|
151
|
+
'Id': this.id,
|
|
152
|
+
'ColumnsAdded': this.columnsAdded.map((column) => column.toJSON()),
|
|
153
|
+
'ColumnsChanged': objMap(this.columnsChanged, (column) => column.toJSON()),
|
|
154
|
+
'ColumnsDeleted': this.columnsDeleted,
|
|
155
|
+
'ColumnOrdering': this.columnOrdering,
|
|
156
|
+
'SyncSourceId': this.syncSourceId,
|
|
157
|
+
'SyncCollectionId': this.syncCollectionId,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
clone() {
|
|
161
|
+
return new SchemaPatch(this.id, this.columnsAdded.map((columnAdded) => columnAdded.clone()), objMap(this.columnsChanged, (columnChange) => columnChange.clone()), [...this.columnsDeleted], this.columnOrdering && [
|
|
162
|
+
...this.columnOrdering.map(([base, target]) => [base, target]),
|
|
163
|
+
], this.primaryKey && [...this.primaryKey], this.syncSourceId, this.syncCollectionId);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.SchemaPatch = SchemaPatch;
|
|
167
|
+
function _schemaPatchParser(id, patch) {
|
|
168
|
+
var _a, _b;
|
|
169
|
+
return new SchemaPatch(id, patch['columnsAdded'].map(ThirdPartyColumn.deserialize), objMap(patch['columnsChanged'], ThirdPartyColumnPatch.deserialize), patch['columnsDeleted'], (_a = patch['columnOrdering']) !== null && _a !== void 0 ? _a : undefined, (_b = patch['primaryKey']) !== null && _b !== void 0 ? _b : undefined, patch['syncSourceId'], patch['syncCollectionId']);
|
|
170
|
+
}
|
|
171
|
+
const schemaPatchParser = (id, patch) => {
|
|
172
|
+
if ((0, serializedpatchtypes_1.patchSchemaValidator)(patch)) {
|
|
173
|
+
return _schemaPatchParser(id, patch);
|
|
174
|
+
}
|
|
175
|
+
return undefined;
|
|
176
|
+
};
|
|
177
|
+
exports.schemaPatchParser = schemaPatchParser;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { isString } from '../../core/checks';
|
|
2
2
|
import { DataConnectorClient } from '../dataconnectorclient';
|
|
3
3
|
import { DataConnectorAction } from './action';
|
|
4
|
+
import { Patch, PatchParser } from './patch';
|
|
4
5
|
export declare const actionsHeaderValidator: (subject: unknown) => subject is import("../..").DestructureGuardedTypeObj<{
|
|
5
6
|
'x-lucid-rsa-nonce': typeof isString;
|
|
6
7
|
'x-lucid-signature': typeof isString;
|
|
7
8
|
}>;
|
|
8
9
|
/** Function to convert the lucid action wire format into a clean list of actions */
|
|
9
|
-
export declare function deserializeActions(client: DataConnectorClient, actions: unknown): DataConnectorAction[] | undefined;
|
|
10
|
+
export declare function deserializeActions<P extends Patch>(client: DataConnectorClient, actions: unknown, patchParser: PatchParser<P>): DataConnectorAction[] | undefined;
|
|
@@ -24,27 +24,19 @@ const serializedActionsBaseValidator = (0, validators_1.objectValidator)({
|
|
|
24
24
|
const serializedPatchDataValidator = (0, validators_1.objectValidator)({
|
|
25
25
|
packageVersion: checks_1.isString,
|
|
26
26
|
patches: (0, validators_1.arrayValidator)((0, validators_1.objectValidator)({
|
|
27
|
-
patch:
|
|
28
|
-
itemsAdded: (0, validators_1.objectOfValidator)(checks_1.isObjectUnsafe),
|
|
29
|
-
itemsChanged: (0, validators_1.objectOfValidator)(checks_1.isObjectUnsafe),
|
|
30
|
-
itemsDeleted: (0, validators_1.arrayValidator)(checks_1.isString),
|
|
31
|
-
itemOrderChanged: (0, validators_1.nullableOption)((0, validators_1.arrayValidator)((0, validators_1.tupleValidator)(checks_1.isString, (0, validators_1.nullable)(checks_1.isString)))),
|
|
32
|
-
syncSourceId: checks_1.isString,
|
|
33
|
-
syncCollectionId: checks_1.isString,
|
|
34
|
-
adapterType: (0, checks_1.isLiteral)('EXTENSION_API'),
|
|
35
|
-
syncSchema: checks_1.isUnknown,
|
|
36
|
-
}),
|
|
27
|
+
patch: checks_1.isUnknown,
|
|
37
28
|
id: checks_1.isString,
|
|
38
29
|
})),
|
|
39
30
|
userCredential: checks_1.isString,
|
|
40
31
|
documentUpdateToken: checks_1.isString,
|
|
41
32
|
});
|
|
42
|
-
const parseSerializedPatches = (patches) => {
|
|
43
|
-
return patches
|
|
44
|
-
|
|
33
|
+
const parseSerializedPatches = (patches, patchParser) => {
|
|
34
|
+
return patches
|
|
35
|
+
.map((patch) => {
|
|
45
36
|
const p = patch['patch'];
|
|
46
|
-
return
|
|
47
|
-
})
|
|
37
|
+
return patchParser(patch['id'], p);
|
|
38
|
+
})
|
|
39
|
+
.filter(checks_1.isDefAndNotNull);
|
|
48
40
|
};
|
|
49
41
|
const serializedManageWebhookDataValidator = (0, validators_1.objectValidator)({
|
|
50
42
|
webhooks: (0, validators_1.arrayValidator)((0, validators_1.objectValidator)({
|
|
@@ -54,7 +46,7 @@ const serializedManageWebhookDataValidator = (0, validators_1.objectValidator)({
|
|
|
54
46
|
webhookToken: checks_1.isString,
|
|
55
47
|
});
|
|
56
48
|
/** Function to convert the lucid action wire format into a clean list of actions */
|
|
57
|
-
function deserializeActions(client, actions) {
|
|
49
|
+
function deserializeActions(client, actions, patchParser) {
|
|
58
50
|
const parsedActions = typeof actions === 'string' ? JSON.parse(actions) : actions;
|
|
59
51
|
if (!serializedActionsBaseValidator(parsedActions)) {
|
|
60
52
|
return;
|
|
@@ -66,11 +58,21 @@ function deserializeActions(client, actions) {
|
|
|
66
58
|
console.log(`Failing validation step`);
|
|
67
59
|
return;
|
|
68
60
|
}
|
|
69
|
-
|
|
61
|
+
const parsedData = data
|
|
62
|
+
.map((item) => {
|
|
70
63
|
const context = new action_1.DataConnectorActionContext(parsedActions['packageId'], item['packageVersion'], item['userCredential'], parsedActions['dataConnectorName'], parsedActions['dataConnectorName'], parsedActions['documentCollections'], parsedActions['updateFilterType']);
|
|
71
|
-
const patches = parseSerializedPatches(item['patches']);
|
|
64
|
+
const patches = parseSerializedPatches(item['patches'], patchParser);
|
|
65
|
+
if (patches.length < item['patches'].length) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
72
68
|
return new action_1.DataConnectorPatchAction(context, patches, client.getDataSourceClient(item['documentUpdateToken']));
|
|
73
|
-
})
|
|
69
|
+
})
|
|
70
|
+
.filter(checks_1.isDefAndNotNull);
|
|
71
|
+
if (parsedData.length < data.length) {
|
|
72
|
+
console.log(`Failing validation step`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
return parsedData;
|
|
74
76
|
}
|
|
75
77
|
if (!parsedActions['packageVersion'] || !parsedActions['userCredential']) {
|
|
76
78
|
return;
|
|
@@ -80,8 +82,13 @@ function deserializeActions(client, actions) {
|
|
|
80
82
|
return;
|
|
81
83
|
}
|
|
82
84
|
const context = new action_1.DataConnectorActionContext(parsedActions['packageId'], parsedActions['packageVersion'], parsedActions['userCredential'], parsedActions['dataConnectorName'], parsedActions['dataConnectorName'], parsedActions['documentCollections'], parsedActions['updateFilterType']);
|
|
85
|
+
const parsedPatches = parseSerializedPatches(data['patches'], patchParser);
|
|
86
|
+
if (parsedPatches.length < data['patches'].length) {
|
|
87
|
+
console.log(`Failing validation step`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
83
90
|
return [
|
|
84
|
-
new action_1.DataConnectorPatchAction(context,
|
|
91
|
+
new action_1.DataConnectorPatchAction(context, parsedPatches, client.getDataSourceClient(data['documentUpdateToken']), dataconnectoractionkeys_1.DataConnectorActionKeys.UnbatchedPatch),
|
|
85
92
|
];
|
|
86
93
|
}
|
|
87
94
|
const context = new action_1.DataConnectorActionContext(parsedActions['packageId'], parsedActions['packageVersion'], parsedActions['userCredential'], parsedActions['dataConnectorName'], parsedActions['dataConnectorName'], parsedActions['documentCollections'], parsedActions['updateFilterType']);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { isString, isUnknown } from '../../core/checks';
|
|
2
|
+
import { isSerializedFieldTypeDefinition } from '../../core/data/fieldtypedefinition/fieldtypedefinition';
|
|
3
|
+
import { GuardToType } from '../../core/guards';
|
|
4
|
+
export declare const patchItemValidator: (subject: unknown) => subject is import("../../core/guards").DestructureGuardedTypeObj<{
|
|
5
|
+
itemsAdded: (x: unknown) => x is Record<any, {
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}>;
|
|
8
|
+
itemsChanged: (x: unknown) => x is Record<any, {
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}>;
|
|
11
|
+
itemsDeleted: (p1: unknown) => p1 is string[];
|
|
12
|
+
itemOrderChanged: (x: unknown) => x is [string, string | null][] | null | undefined;
|
|
13
|
+
syncSourceId: typeof isString;
|
|
14
|
+
syncCollectionId: typeof isString;
|
|
15
|
+
adapterType: (x: unknown) => x is "EXTENSION_API";
|
|
16
|
+
syncSchema: typeof isUnknown;
|
|
17
|
+
}>;
|
|
18
|
+
export type SerializedItemPatch = GuardToType<typeof patchItemValidator>;
|
|
19
|
+
export declare const thirdPartyColumnValidator: (subject: unknown) => subject is import("../../core/guards").DestructureGuardedTypeObj<{
|
|
20
|
+
name: typeof isString;
|
|
21
|
+
fieldType: typeof isSerializedFieldTypeDefinition;
|
|
22
|
+
}>;
|
|
23
|
+
export declare const thirdPartyColumnPatchValidator: (subject: unknown) => subject is import("../../core/guards").DestructureGuardedTypeObj<{
|
|
24
|
+
name: (x: unknown) => x is string | null | undefined;
|
|
25
|
+
fieldType: (x: unknown) => x is import("../../core/data/fieldtypedefinition/fieldtypedefinition").SerializedFieldTypeDefinition | null | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
export declare const patchSchemaValidator: (subject: unknown) => subject is import("../../core/guards").DestructureGuardedTypeObj<{
|
|
28
|
+
columnsAdded: (p1: unknown) => p1 is import("../../core/guards").DestructureGuardedTypeObj<{
|
|
29
|
+
name: typeof isString;
|
|
30
|
+
fieldType: typeof isSerializedFieldTypeDefinition;
|
|
31
|
+
}>[];
|
|
32
|
+
columnsChanged: (x: unknown) => x is {
|
|
33
|
+
[key: string]: import("../../core/guards").DestructureGuardedTypeObj<{
|
|
34
|
+
name: (x: unknown) => x is string | null | undefined;
|
|
35
|
+
fieldType: (x: unknown) => x is import("../../core/data/fieldtypedefinition/fieldtypedefinition").SerializedFieldTypeDefinition | null | undefined;
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
38
|
+
columnsDeleted: (p1: unknown) => p1 is string[];
|
|
39
|
+
columnOrdering: (x: unknown) => x is [string, string | null][] | null | undefined;
|
|
40
|
+
primaryKey: (x: unknown) => x is string[] | null | undefined;
|
|
41
|
+
syncSourceId: typeof isString;
|
|
42
|
+
syncCollectionId: typeof isString;
|
|
43
|
+
adapterType: (x: unknown) => x is "EXTENSION_API";
|
|
44
|
+
}>;
|
|
45
|
+
export type SerializedSchemaPatch = GuardToType<typeof patchSchemaValidator>;
|
|
46
|
+
export declare const patchValidator: (x: unknown) => x is import("../../core/guards").DestructureGuardedTypeObj<{
|
|
47
|
+
itemsAdded: (x: unknown) => x is Record<any, {
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
}>;
|
|
50
|
+
itemsChanged: (x: unknown) => x is Record<any, {
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}>;
|
|
53
|
+
itemsDeleted: (p1: unknown) => p1 is string[];
|
|
54
|
+
itemOrderChanged: (x: unknown) => x is [string, string | null][] | null | undefined;
|
|
55
|
+
syncSourceId: typeof isString;
|
|
56
|
+
syncCollectionId: typeof isString;
|
|
57
|
+
adapterType: (x: unknown) => x is "EXTENSION_API";
|
|
58
|
+
syncSchema: typeof isUnknown;
|
|
59
|
+
}> | import("../../core/guards").DestructureGuardedTypeObj<{
|
|
60
|
+
columnsAdded: (p1: unknown) => p1 is import("../../core/guards").DestructureGuardedTypeObj<{
|
|
61
|
+
name: typeof isString;
|
|
62
|
+
fieldType: typeof isSerializedFieldTypeDefinition;
|
|
63
|
+
}>[];
|
|
64
|
+
columnsChanged: (x: unknown) => x is {
|
|
65
|
+
[key: string]: import("../../core/guards").DestructureGuardedTypeObj<{
|
|
66
|
+
name: (x: unknown) => x is string | null | undefined;
|
|
67
|
+
fieldType: (x: unknown) => x is import("../../core/data/fieldtypedefinition/fieldtypedefinition").SerializedFieldTypeDefinition | null | undefined;
|
|
68
|
+
}>;
|
|
69
|
+
};
|
|
70
|
+
columnsDeleted: (p1: unknown) => p1 is string[];
|
|
71
|
+
columnOrdering: (x: unknown) => x is [string, string | null][] | null | undefined;
|
|
72
|
+
primaryKey: (x: unknown) => x is string[] | null | undefined;
|
|
73
|
+
syncSourceId: typeof isString;
|
|
74
|
+
syncCollectionId: typeof isString;
|
|
75
|
+
adapterType: (x: unknown) => x is "EXTENSION_API";
|
|
76
|
+
}>;
|
|
77
|
+
export type SerializedPatch = GuardToType<typeof patchValidator>;
|
|
78
|
+
export type SerializedThirdPartyColumn = GuardToType<typeof thirdPartyColumnValidator>;
|
|
79
|
+
export type SerializedThirdPartyColumnPatch = GuardToType<typeof thirdPartyColumnPatchValidator>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.patchValidator = exports.patchSchemaValidator = exports.thirdPartyColumnPatchValidator = exports.thirdPartyColumnValidator = exports.patchItemValidator = void 0;
|
|
4
|
+
const checks_1 = require("../../core/checks");
|
|
5
|
+
const fieldtypedefinition_1 = require("../../core/data/fieldtypedefinition/fieldtypedefinition");
|
|
6
|
+
const validators_1 = require("../../core/validators/validators");
|
|
7
|
+
exports.patchItemValidator = (0, validators_1.objectValidator)({
|
|
8
|
+
itemsAdded: (0, validators_1.objectOfValidator)(checks_1.isObjectUnsafe),
|
|
9
|
+
itemsChanged: (0, validators_1.objectOfValidator)(checks_1.isObjectUnsafe),
|
|
10
|
+
itemsDeleted: (0, validators_1.arrayValidator)(checks_1.isString),
|
|
11
|
+
itemOrderChanged: (0, validators_1.nullableOption)((0, validators_1.arrayValidator)((0, validators_1.tupleValidator)(checks_1.isString, (0, validators_1.nullable)(checks_1.isString)))),
|
|
12
|
+
syncSourceId: checks_1.isString,
|
|
13
|
+
syncCollectionId: checks_1.isString,
|
|
14
|
+
adapterType: (0, checks_1.isLiteral)('EXTENSION_API'),
|
|
15
|
+
syncSchema: checks_1.isUnknown,
|
|
16
|
+
});
|
|
17
|
+
exports.thirdPartyColumnValidator = (0, validators_1.objectValidator)({
|
|
18
|
+
name: checks_1.isString,
|
|
19
|
+
fieldType: fieldtypedefinition_1.isSerializedFieldTypeDefinition,
|
|
20
|
+
});
|
|
21
|
+
exports.thirdPartyColumnPatchValidator = (0, validators_1.objectValidator)({
|
|
22
|
+
name: (0, validators_1.nullableOption)(checks_1.isString),
|
|
23
|
+
fieldType: (0, validators_1.nullableOption)(fieldtypedefinition_1.isSerializedFieldTypeDefinition),
|
|
24
|
+
});
|
|
25
|
+
exports.patchSchemaValidator = (0, validators_1.objectValidator)({
|
|
26
|
+
columnsAdded: (0, validators_1.arrayValidator)(exports.thirdPartyColumnValidator),
|
|
27
|
+
columnsChanged: (0, validators_1.mapValidator)(exports.thirdPartyColumnPatchValidator),
|
|
28
|
+
columnsDeleted: (0, validators_1.arrayValidator)(checks_1.isString),
|
|
29
|
+
columnOrdering: (0, validators_1.nullableOption)((0, validators_1.arrayValidator)((0, validators_1.tupleValidator)(checks_1.isString, (0, validators_1.nullable)(checks_1.isString)))),
|
|
30
|
+
primaryKey: (0, validators_1.nullableOption)((0, validators_1.arrayValidator)(checks_1.isString)),
|
|
31
|
+
syncSourceId: checks_1.isString,
|
|
32
|
+
syncCollectionId: checks_1.isString,
|
|
33
|
+
adapterType: (0, checks_1.isLiteral)('EXTENSION_API'),
|
|
34
|
+
});
|
|
35
|
+
exports.patchValidator = (0, validators_1.either)(exports.patchItemValidator, exports.patchSchemaValidator);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DataConnectorAction, DataConnectorAsynchronousAction, DataConnectorManageWebhookAction, DataConnectorPatchAction, Webhook } from './actions/action';
|
|
2
2
|
import { DataConnectorActionKeys } from './actions/dataconnectoractionkeys';
|
|
3
|
+
import { ItemPatch, Patch, PatchParser } from './actions/patch';
|
|
3
4
|
import { PatchChange } from './actions/patchresponsebody';
|
|
4
5
|
import { DataConnectorClient } from './dataconnectorclient';
|
|
5
6
|
import { ExpressAppLike, RunDebugServerOptions } from './debugserver';
|
|
@@ -42,11 +43,13 @@ export declare class DataConnectorResponseError extends Error {
|
|
|
42
43
|
response: string;
|
|
43
44
|
constructor(message: string, response: string);
|
|
44
45
|
}
|
|
45
|
-
type ActionTypeForName<Name extends string, Asynchronous = boolean> = Name extends `${DataConnectorActionKeys.Patch}` ? ActionRequest<DataConnectorPatchAction
|
|
46
|
+
type ActionTypeForName<P extends Patch, Name extends string, Asynchronous = boolean> = Name extends `${DataConnectorActionKeys.Patch}` ? ActionRequest<DataConnectorPatchAction<P>, PatchChange[]> : Name extends `${DataConnectorActionKeys.UnbatchedPatch}` ? ActionRequest<DataConnectorPatchAction<P>, PatchChange[]> : Name extends `${DataConnectorActionKeys.ManageWebhook}` ? ActionRequest<DataConnectorManageWebhookAction, Webhook> : ActionRequest<Asynchronous extends true ? DataConnectorAsynchronousAction : DataConnectorAction>;
|
|
46
47
|
/** Factory class to define a bunch of action handlers. */
|
|
47
|
-
export declare class DataConnector {
|
|
48
|
+
export declare class DataConnector<P extends Patch = ItemPatch> {
|
|
48
49
|
private client;
|
|
50
|
+
private patchParser;
|
|
49
51
|
constructor(client: DataConnectorClient);
|
|
52
|
+
constructor(client: DataConnectorClient, optPatchParser: P extends ItemPatch ? never : PatchParser<P>);
|
|
50
53
|
actions: Record<string, {
|
|
51
54
|
actionResponder: ActionRequest<DataConnectorAsynchronousAction>;
|
|
52
55
|
asynchronous: true;
|
|
@@ -56,11 +59,11 @@ export declare class DataConnector {
|
|
|
56
59
|
}>;
|
|
57
60
|
routes: Record<string, DataConnectorRoute>;
|
|
58
61
|
/** Factory to define an action request handler */
|
|
59
|
-
defineAction<T extends string>(name: T, request: ActionTypeForName<T>, asynchronous?: boolean): DataConnector
|
|
62
|
+
defineAction<T extends string>(name: T, request: ActionTypeForName<P, T>, asynchronous?: boolean): DataConnector<P>;
|
|
60
63
|
/** Factory to define an asynchronous action request handler */
|
|
61
|
-
defineAsynchronousAction<T extends string>(name: T, request: ActionTypeForName<T, true>): DataConnector
|
|
64
|
+
defineAsynchronousAction<T extends string>(name: T, request: ActionTypeForName<P, T, true>): DataConnector<P>;
|
|
62
65
|
/** Factory to define a route handler */
|
|
63
|
-
defineRoute(name: string, request: DataConnectorRoute): DataConnector
|
|
66
|
+
defineRoute(name: string, request: DataConnectorRoute): DataConnector<P>;
|
|
64
67
|
/** Call a defined action handler and gather its serialized response */
|
|
65
68
|
runAction(url: string, headers: Record<string, string[] | string | undefined>, body: unknown): Promise<{
|
|
66
69
|
status: number;
|
|
@@ -6,6 +6,7 @@ const validators_1 = require("../core/validators/validators");
|
|
|
6
6
|
const action_1 = require("./actions/action");
|
|
7
7
|
const dataconnectoractionkeys_1 = require("./actions/dataconnectoractionkeys");
|
|
8
8
|
const managewebhookresponsebody_1 = require("./actions/managewebhookresponsebody");
|
|
9
|
+
const patch_1 = require("./actions/patch");
|
|
9
10
|
const patchresponsebody_1 = require("./actions/patchresponsebody");
|
|
10
11
|
const debugserver_1 = require("./debugserver");
|
|
11
12
|
const itemrekeyer_1 = require("./itemrekeyer");
|
|
@@ -51,10 +52,11 @@ class DataConnectorResponseError extends Error {
|
|
|
51
52
|
exports.DataConnectorResponseError = DataConnectorResponseError;
|
|
52
53
|
/** Factory class to define a bunch of action handlers. */
|
|
53
54
|
class DataConnector {
|
|
54
|
-
constructor(client) {
|
|
55
|
+
constructor(client, optPatchParser) {
|
|
55
56
|
this.client = client;
|
|
56
57
|
this.actions = {};
|
|
57
58
|
this.routes = {};
|
|
59
|
+
this.patchParser = optPatchParser !== null && optPatchParser !== void 0 ? optPatchParser : patch_1.itemPatchParser;
|
|
58
60
|
}
|
|
59
61
|
/** Factory to define an action request handler */
|
|
60
62
|
defineAction(name, request, asynchronous = false) {
|
|
@@ -73,7 +75,7 @@ class DataConnector {
|
|
|
73
75
|
/** Call a defined action handler and gather its serialized response */
|
|
74
76
|
async runAction(url, headers, body) {
|
|
75
77
|
const state = new DataConnectorRequestState(new itemrekeyer_1.ItemRekeyer());
|
|
76
|
-
const actions = await this.client.parseActions(url, headers, body);
|
|
78
|
+
const actions = await this.client.parseActions(url, headers, body, this.patchParser);
|
|
77
79
|
if (!actions) {
|
|
78
80
|
console.warn('Received bad request', url, headers, body);
|
|
79
81
|
return { status: 404, body: { error: 'Bad request' } };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JsonObject } from '../core/jsonserializable';
|
|
2
2
|
import { DataConnectorAction } from './actions/action';
|
|
3
|
+
import { Patch, PatchParser } from './actions/patch';
|
|
3
4
|
import { CryptoDependencies } from './cryptodependencies';
|
|
4
5
|
import { DataSourceClient, MockDataSourceClient } from './datasourceclient';
|
|
5
6
|
import { SignatureValidator } from './signaturevalidator';
|
|
@@ -33,7 +34,7 @@ export declare class DataConnectorClient {
|
|
|
33
34
|
* you're not running in a NodeJS environment */
|
|
34
35
|
getPublicKey(): Promise<string>;
|
|
35
36
|
/** Validate and parse an action request from Lucid */
|
|
36
|
-
parseActions(url: string, headers: Record<string, string | string[] | unknown>, actions: unknown): Promise<DataConnectorAction[] | undefined>;
|
|
37
|
+
parseActions<P extends Patch>(url: string, headers: Record<string, string | string[] | unknown>, actions: unknown, patchParser: PatchParser<P>): Promise<DataConnectorAction[] | undefined>;
|
|
37
38
|
/** @ignore */
|
|
38
39
|
getSecretFromWebhook(webhookUpdateToken: string, WebhookValidationSecret: WebhookValidationSecret): Promise<string | undefined>;
|
|
39
40
|
/** @ignore */
|
|
@@ -38,14 +38,14 @@ class DataConnectorClient {
|
|
|
38
38
|
return this.cachedPublicKey;
|
|
39
39
|
}
|
|
40
40
|
/** Validate and parse an action request from Lucid */
|
|
41
|
-
async parseActions(url, headers, actions) {
|
|
41
|
+
async parseActions(url, headers, actions, patchParser) {
|
|
42
42
|
if (!(0, serializedactions_1.actionsHeaderValidator)(headers)) {
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
if (!(await this.getSignatureValidator()).validate(actions, headers, url)) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
-
return (0, serializedactions_1.deserializeActions)(this, actions);
|
|
48
|
+
return (0, serializedactions_1.deserializeActions)(this, actions, patchParser);
|
|
49
49
|
}
|
|
50
50
|
/** @ignore */
|
|
51
51
|
async getSecretFromWebhook(webhookUpdateToken, WebhookValidationSecret) {
|
|
@@ -72,9 +72,10 @@ export declare class ItemsPatchInexhaustive {
|
|
|
72
72
|
export declare class ItemsPatchExhaustive {
|
|
73
73
|
items: Map<string, SerializedFields>;
|
|
74
74
|
rekeyingMap?: Map<string, string | null> | undefined;
|
|
75
|
+
fieldNamesChanged?: Map<string, string> | undefined;
|
|
75
76
|
errors?: Map<string, SerializedLucidDictionary> | undefined;
|
|
76
77
|
private readonly _brand;
|
|
77
|
-
constructor(items: Map<string, SerializedFields>, rekeyingMap?: Map<string, string | null> | undefined, errors?: Map<string, SerializedLucidDictionary> | undefined);
|
|
78
|
+
constructor(items: Map<string, SerializedFields>, rekeyingMap?: Map<string, string | null> | undefined, fieldNamesChanged?: Map<string, string> | undefined, errors?: Map<string, SerializedLucidDictionary> | undefined);
|
|
78
79
|
}
|
|
79
80
|
export type ItemsPatch = {
|
|
80
81
|
/**
|
|
@@ -94,6 +95,7 @@ export type SerializedItemsPatch = {
|
|
|
94
95
|
} | {
|
|
95
96
|
'exhaustiveItems': Record<string, SerializedFields>;
|
|
96
97
|
'rekeyingMap'?: Record<string, string | null>;
|
|
98
|
+
'fieldNamesChanged'?: Record<string, string>;
|
|
97
99
|
'errors'?: Record<string, SerializedLucidDictionary>;
|
|
98
100
|
};
|
|
99
101
|
export declare function serializeItemsPatch(patch: ItemsPatch): SerializedItemsPatch;
|
|
@@ -22,9 +22,10 @@ class ItemsPatchInexhaustive {
|
|
|
22
22
|
}
|
|
23
23
|
exports.ItemsPatchInexhaustive = ItemsPatchInexhaustive;
|
|
24
24
|
class ItemsPatchExhaustive {
|
|
25
|
-
constructor(items, rekeyingMap, errors) {
|
|
25
|
+
constructor(items, rekeyingMap, fieldNamesChanged, errors) {
|
|
26
26
|
this.items = items;
|
|
27
27
|
this.rekeyingMap = rekeyingMap;
|
|
28
|
+
this.fieldNamesChanged = fieldNamesChanged;
|
|
28
29
|
this.errors = errors;
|
|
29
30
|
this._brand = ItemsPatchExhaustive;
|
|
30
31
|
}
|
|
@@ -36,10 +37,13 @@ function serializeErrors(errors) {
|
|
|
36
37
|
function serializeRekeyingMap(rekeyingMap) {
|
|
37
38
|
return rekeyingMap && { 'rekeyingMap': (0, object_1.fromEntries)(rekeyingMap) };
|
|
38
39
|
}
|
|
40
|
+
function serializeFieldNamesChanged(fieldNamesChanged) {
|
|
41
|
+
return fieldNamesChanged && { 'fieldNamesChanged': (0, object_1.fromEntries)(fieldNamesChanged) };
|
|
42
|
+
}
|
|
39
43
|
function serializeItemsPatch(patch) {
|
|
40
44
|
var _a;
|
|
41
45
|
if (patch instanceof ItemsPatchExhaustive) {
|
|
42
|
-
return Object.assign(Object.assign({ 'exhaustiveItems': (0, object_1.fromEntries)(patch.items.entries()) }, serializeRekeyingMap(patch.rekeyingMap)), serializeErrors(patch.errors));
|
|
46
|
+
return Object.assign(Object.assign(Object.assign({ 'exhaustiveItems': (0, object_1.fromEntries)(patch.items.entries()) }, serializeRekeyingMap(patch.rekeyingMap)), serializeFieldNamesChanged(patch.fieldNamesChanged)), serializeErrors(patch.errors));
|
|
43
47
|
}
|
|
44
48
|
else {
|
|
45
49
|
return Object.assign({ 'items': (0, object_1.fromEntries)(patch.items.entries()), 'itemsDeleted': (_a = patch.itemsDeleted) !== null && _a !== void 0 ? _a : [] }, serializeErrors(patch.errors));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Patch } from './actions/patch';
|
|
1
2
|
import { DataConnector } from './dataconnector';
|
|
2
3
|
/** @ignore */
|
|
3
4
|
export type ExpressLike = {
|
|
@@ -42,6 +43,6 @@ export type RunDebugServerOptions = {
|
|
|
42
43
|
app?: ExpressAppLike;
|
|
43
44
|
};
|
|
44
45
|
/** @ignore */
|
|
45
|
-
export declare function routeDebugServer(dataConnector: DataConnector
|
|
46
|
+
export declare function routeDebugServer<P extends Patch>(dataConnector: DataConnector<P>, options: RunDebugServerOptions): ExpressAppLike;
|
|
46
47
|
/** @ignore */
|
|
47
|
-
export declare function runDebugServer(dataConnector: DataConnector
|
|
48
|
+
export declare function runDebugServer<P extends Patch>(dataConnector: DataConnector<P>, options: RunDebugServerOptions): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FormattedPrimaryKey } from '../core/data/fieldspecification';
|
|
2
|
-
import {
|
|
2
|
+
import { PatchItems } from './actions/action';
|
|
3
|
+
import { Patch } from './actions/patch';
|
|
3
4
|
import { ItemsPatch } from './datasourceupdatetypes';
|
|
4
5
|
export declare class RekeyingMap {
|
|
5
6
|
map: Map<string, string | null>;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ItemRekeyer = exports.RekeyingMap = void 0;
|
|
4
4
|
const fieldspecification_1 = require("../core/data/fieldspecification");
|
|
5
5
|
const object_1 = require("../core/object");
|
|
6
|
-
const
|
|
6
|
+
const patch_1 = require("./actions/patch");
|
|
7
7
|
const datasourceupdatetypes_1 = require("./datasourceupdatetypes");
|
|
8
8
|
function calculateRekeyingMap(itemsPatch, primaryKey) {
|
|
9
9
|
var _a, _b;
|
|
@@ -55,7 +55,10 @@ class RekeyingMap {
|
|
|
55
55
|
}
|
|
56
56
|
getRekeyedPatch(patch) {
|
|
57
57
|
var _a;
|
|
58
|
-
|
|
58
|
+
if (patch instanceof patch_1.ItemPatch) {
|
|
59
|
+
return new patch_1.ItemPatch(patch.id, this.getRecordWithNewKeys(patch.itemsAdded), this.getRecordWithNewKeys(patch.itemsChanged), patch.itemsDeleted.map((key) => this.getNewKey(key)), (_a = patch.itemOrderChanged) === null || _a === void 0 ? void 0 : _a.map(([a, b]) => [this.getNewKey(a), b && this.getNewKey(b)]), patch.syncSourceId, patch.syncCollectionId);
|
|
60
|
+
}
|
|
61
|
+
return patch.clone();
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
exports.RekeyingMap = RekeyingMap;
|