@squidcloud/client 1.0.128 → 1.0.130
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/cjs/index.js +474 -227
- package/dist/common/src/bundle-api.types.d.ts +3 -0
- package/dist/common/src/index.d.ts +1 -0
- package/dist/common/src/integrations/database.types.d.ts +28 -2
- package/dist/common/src/integrations/index.d.ts +4 -2
- package/dist/common/src/native-query.context.d.ts +7 -0
- package/dist/typescript-client/src/ai.types.d.ts +9 -0
- package/dist/typescript-client/src/auth.manager.d.ts +27 -13
- package/dist/typescript-client/src/named-query.manager.d.ts +1 -2
- package/dist/typescript-client/src/native-query-manager.d.ts +18 -0
- package/dist/typescript-client/src/rpc.manager.d.ts +1 -1
- package/dist/typescript-client/src/socket.manager.d.ts +9 -1
- package/dist/typescript-client/src/squid.d.ts +42 -6
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -27050,6 +27050,7 @@ const DatabaseIntegrationTypes = [
|
|
|
27050
27050
|
IntegrationType.built_in_db,
|
|
27051
27051
|
IntegrationType.mongo,
|
|
27052
27052
|
IntegrationType.mysql,
|
|
27053
|
+
IntegrationType.bigquery,
|
|
27053
27054
|
IntegrationType.mssql,
|
|
27054
27055
|
IntegrationType.postgres,
|
|
27055
27056
|
IntegrationType.cockroach,
|
|
@@ -27116,6 +27117,24 @@ const MysqlConnectionOptionsSchema = {
|
|
|
27116
27117
|
connectionLimit: { type: 'number', nullable: false },
|
|
27117
27118
|
},
|
|
27118
27119
|
};
|
|
27120
|
+
const BigQueryConnectionOptionsSchema = {
|
|
27121
|
+
type: 'object',
|
|
27122
|
+
nullable: false,
|
|
27123
|
+
required: ['secrets', 'projectId', 'datasetId', 'email'],
|
|
27124
|
+
properties: {
|
|
27125
|
+
projectId: { type: 'string', nullable: false },
|
|
27126
|
+
datasetId: { type: 'string', nullable: false },
|
|
27127
|
+
email: { type: 'string', nullable: false },
|
|
27128
|
+
secrets: {
|
|
27129
|
+
type: 'object',
|
|
27130
|
+
required: ['privateKey'],
|
|
27131
|
+
nullable: false,
|
|
27132
|
+
properties: {
|
|
27133
|
+
privateKey: { type: 'string', nullable: false, isSecret: {} },
|
|
27134
|
+
},
|
|
27135
|
+
},
|
|
27136
|
+
},
|
|
27137
|
+
};
|
|
27119
27138
|
const OracleConnectionOptionsSchema = {
|
|
27120
27139
|
type: 'object',
|
|
27121
27140
|
nullable: false,
|
|
@@ -27359,6 +27378,27 @@ const UpsertIntegrationRequestSchema = {
|
|
|
27359
27378
|
},
|
|
27360
27379
|
},
|
|
27361
27380
|
},
|
|
27381
|
+
{
|
|
27382
|
+
type: 'object',
|
|
27383
|
+
properties: {
|
|
27384
|
+
type: { const: IntegrationType.bigquery },
|
|
27385
|
+
config: {
|
|
27386
|
+
type: 'object',
|
|
27387
|
+
required: ['configuration'],
|
|
27388
|
+
properties: {
|
|
27389
|
+
supportsExternalChanges: { type: 'boolean', nullable: true },
|
|
27390
|
+
configuration: {
|
|
27391
|
+
type: 'object',
|
|
27392
|
+
nullable: false,
|
|
27393
|
+
required: ['connectionOptions'],
|
|
27394
|
+
properties: {
|
|
27395
|
+
connectionOptions: BigQueryConnectionOptionsSchema,
|
|
27396
|
+
},
|
|
27397
|
+
},
|
|
27398
|
+
},
|
|
27399
|
+
},
|
|
27400
|
+
},
|
|
27401
|
+
},
|
|
27362
27402
|
{
|
|
27363
27403
|
type: 'object',
|
|
27364
27404
|
properties: {
|
|
@@ -27774,6 +27814,20 @@ const TestDataConnectionRequestSchema = {
|
|
|
27774
27814
|
},
|
|
27775
27815
|
},
|
|
27776
27816
|
},
|
|
27817
|
+
{
|
|
27818
|
+
type: 'object',
|
|
27819
|
+
required: ['configuration'],
|
|
27820
|
+
properties: {
|
|
27821
|
+
type: { const: IntegrationType.bigquery },
|
|
27822
|
+
configuration: {
|
|
27823
|
+
type: 'object',
|
|
27824
|
+
required: ['connectionOptions'],
|
|
27825
|
+
properties: {
|
|
27826
|
+
connectionOptions: BigQueryConnectionOptionsSchema,
|
|
27827
|
+
},
|
|
27828
|
+
},
|
|
27829
|
+
},
|
|
27830
|
+
},
|
|
27777
27831
|
{
|
|
27778
27832
|
type: 'object',
|
|
27779
27833
|
required: ['configuration'],
|
|
@@ -27901,6 +27955,14 @@ const DiscoverDataConnectionSchemaRequestSchema = {
|
|
|
27901
27955
|
connectionOptions: MysqlConnectionOptionsSchema,
|
|
27902
27956
|
},
|
|
27903
27957
|
},
|
|
27958
|
+
{
|
|
27959
|
+
type: 'object',
|
|
27960
|
+
required: ['connectionOptions'],
|
|
27961
|
+
properties: {
|
|
27962
|
+
integrationType: { const: IntegrationType.bigquery },
|
|
27963
|
+
connectionOptions: BigQueryConnectionOptionsSchema,
|
|
27964
|
+
},
|
|
27965
|
+
},
|
|
27904
27966
|
{
|
|
27905
27967
|
type: 'object',
|
|
27906
27968
|
required: ['connectionOptions'],
|
|
@@ -28165,14 +28227,14 @@ class mutation_context_MutationContext {
|
|
|
28165
28227
|
|
|
28166
28228
|
function sortKeys(json) {
|
|
28167
28229
|
if (Array.isArray(json)) {
|
|
28168
|
-
return json.map(
|
|
28230
|
+
return json.map(o => sortKeys(o));
|
|
28169
28231
|
}
|
|
28170
28232
|
if (typeof json !== 'object' || json === null || json instanceof Date) {
|
|
28171
28233
|
return json;
|
|
28172
28234
|
}
|
|
28173
28235
|
const keys = Object.keys(json);
|
|
28174
28236
|
const result = {};
|
|
28175
|
-
keys.sort().forEach(
|
|
28237
|
+
keys.sort().forEach(key => {
|
|
28176
28238
|
result[key] = sortKeys(json[key]);
|
|
28177
28239
|
});
|
|
28178
28240
|
return result;
|
|
@@ -28183,14 +28245,14 @@ function serialization_normalizeJsonAsString(json) {
|
|
|
28183
28245
|
function serialization_serializeObj(obj) {
|
|
28184
28246
|
if (obj === undefined)
|
|
28185
28247
|
return null;
|
|
28186
|
-
const objWithReplacedDates = lodash.cloneDeepWith(obj,
|
|
28248
|
+
const objWithReplacedDates = lodash.cloneDeepWith(obj, value => {
|
|
28187
28249
|
return lodash.isDate(value) ? { $date: value.toISOString() } : undefined;
|
|
28188
28250
|
});
|
|
28189
28251
|
return JSON.stringify(objWithReplacedDates);
|
|
28190
28252
|
}
|
|
28191
28253
|
function deserializeObj(str) {
|
|
28192
28254
|
const deserializedObj = JSON.parse(str);
|
|
28193
|
-
return lodash.cloneDeepWith(deserializedObj,
|
|
28255
|
+
return lodash.cloneDeepWith(deserializedObj, value => {
|
|
28194
28256
|
return lodash.isObject(value) && lodash.has(value, '$date') && Object.keys(value).length === 1
|
|
28195
28257
|
? new Date(value['$date'])
|
|
28196
28258
|
: undefined;
|
|
@@ -28551,8 +28613,8 @@ class query_context_QueryContext {
|
|
|
28551
28613
|
* @returns Whether the query is a subquery of the parent condition.
|
|
28552
28614
|
*/
|
|
28553
28615
|
isSubqueryOfCondition(condition) {
|
|
28554
|
-
const conditions = this.parsedConditions.filter(
|
|
28555
|
-
return !!conditions.find(
|
|
28616
|
+
const conditions = this.parsedConditions.filter(c => c.fieldName === condition.fieldName);
|
|
28617
|
+
return !!conditions.find(c => this.evaluateSubset(c, condition));
|
|
28556
28618
|
}
|
|
28557
28619
|
/**
|
|
28558
28620
|
* Verifies that the query is a subquery of the specified conditions. A subquery is defined as a query that evaluates
|
|
@@ -28564,7 +28626,7 @@ class query_context_QueryContext {
|
|
|
28564
28626
|
*/
|
|
28565
28627
|
isSubqueryOfConditions(conditions) {
|
|
28566
28628
|
const parsedConditions = this.parseConditions(conditions);
|
|
28567
|
-
return parsedConditions.every(
|
|
28629
|
+
return parsedConditions.every(c => this.isSubqueryOfCondition(c));
|
|
28568
28630
|
}
|
|
28569
28631
|
/**
|
|
28570
28632
|
* Verifies that the query is a subquery of the specified query. A subquery is defined as a query that evaluates
|
|
@@ -28590,7 +28652,7 @@ class query_context_QueryContext {
|
|
|
28590
28652
|
* @returns An array of conditions that involve any of the specified field names.
|
|
28591
28653
|
*/
|
|
28592
28654
|
getConditionsFor(...fieldNames) {
|
|
28593
|
-
return this.parsedConditions.filter(
|
|
28655
|
+
return this.parsedConditions.filter(cond => fieldNames.includes(cond.fieldName));
|
|
28594
28656
|
}
|
|
28595
28657
|
/**
|
|
28596
28658
|
* Returns all conditions that apply to the specified field name. This method provides
|
|
@@ -28600,7 +28662,7 @@ class query_context_QueryContext {
|
|
|
28600
28662
|
* @returns An array of conditions that involve the specified field name.
|
|
28601
28663
|
*/
|
|
28602
28664
|
getConditionsForField(fieldName) {
|
|
28603
|
-
return this.parsedConditions.filter(
|
|
28665
|
+
return this.parsedConditions.filter(cond => cond.fieldName === fieldName);
|
|
28604
28666
|
}
|
|
28605
28667
|
/**
|
|
28606
28668
|
* Returns true if the given document can be a result of the query.
|
|
@@ -28658,7 +28720,7 @@ class query_context_QueryContext {
|
|
|
28658
28720
|
const parsedConditions = [];
|
|
28659
28721
|
const inMap = new Map();
|
|
28660
28722
|
const notInMap = new Map();
|
|
28661
|
-
conditions.forEach(
|
|
28723
|
+
conditions.forEach(c => {
|
|
28662
28724
|
switch (c.operator) {
|
|
28663
28725
|
case '==':
|
|
28664
28726
|
case 'in':
|
|
@@ -28905,7 +28967,7 @@ class Pagination {
|
|
|
28905
28967
|
*/
|
|
28906
28968
|
this.navigatingToLastPage = false;
|
|
28907
28969
|
this.lastElement = null;
|
|
28908
|
-
this.snapshotSubject.pipe((0,external_rxjs_namespaceObject.switchAll)()).subscribe(
|
|
28970
|
+
this.snapshotSubject.pipe((0,external_rxjs_namespaceObject.switchAll)()).subscribe(data => this.dataReceived(data));
|
|
28909
28971
|
this.templateSnapshotEmitter = snapshotEmitter.clone();
|
|
28910
28972
|
this.options = Object.assign({ pageSize: 100, subscribe: true }, options);
|
|
28911
28973
|
this.goToFirstPage();
|
|
@@ -28955,7 +29017,7 @@ class Pagination {
|
|
|
28955
29017
|
async dataReceived(data) {
|
|
28956
29018
|
// Because documents might be deleted by the time we need them (if we are not subscribed), we save the extracted
|
|
28957
29019
|
// data here. This is the only place we're allowed to call extractData.
|
|
28958
|
-
const extractedData = data.map(
|
|
29020
|
+
const extractedData = data.map(s => this.templateSnapshotEmitter.extractData(s));
|
|
28959
29021
|
if (data.length === 0) {
|
|
28960
29022
|
if (this.onFirstPage) {
|
|
28961
29023
|
this.internalStateObserver.next({ numBefore: 0, numAfter: 0, data, extractedData });
|
|
@@ -28969,7 +29031,7 @@ class Pagination {
|
|
|
28969
29031
|
if (this.lastElement !== null) {
|
|
28970
29032
|
// We just executed a `prev` and we know what the last element is on the page but not the first.
|
|
28971
29033
|
// We need to find the first element on the page instead, because that's our anchor.
|
|
28972
|
-
const numAfter = extractedData.filter(
|
|
29034
|
+
const numAfter = extractedData.filter(s => this.compare(s, this.lastElement) === 1).length;
|
|
28973
29035
|
this.firstElement = extractedData[data.length - numAfter - this.options.pageSize];
|
|
28974
29036
|
this.lastElement = null;
|
|
28975
29037
|
}
|
|
@@ -28979,7 +29041,7 @@ class Pagination {
|
|
|
28979
29041
|
this.navigatingToLastPage = false;
|
|
28980
29042
|
}
|
|
28981
29043
|
}
|
|
28982
|
-
const numBefore = extractedData.filter(
|
|
29044
|
+
const numBefore = extractedData.filter(s => this.compare(s, this.firstElement) === -1).length;
|
|
28983
29045
|
const numAfter = Math.max(0, data.length - numBefore - this.options.pageSize);
|
|
28984
29046
|
// Current page is empty, go to previous page
|
|
28985
29047
|
if (numBefore === data.length) {
|
|
@@ -28996,24 +29058,24 @@ class Pagination {
|
|
|
28996
29058
|
.limit(this.options.pageSize * 3)
|
|
28997
29059
|
.flipSortOrder();
|
|
28998
29060
|
if (startingDoc) {
|
|
28999
|
-
newSnapshotEmitter.addCompositeCondition(this.templateSnapshotEmitter.getSortOrders().map(
|
|
29061
|
+
newSnapshotEmitter.addCompositeCondition(this.templateSnapshotEmitter.getSortOrders().map(sortOrder => {
|
|
29000
29062
|
return {
|
|
29001
29063
|
fieldName: sortOrder.fieldName,
|
|
29002
29064
|
operator: sortOrder.asc ? '<=' : '>=',
|
|
29003
|
-
value: getInPath(startingDoc, sortOrder.fieldName),
|
|
29065
|
+
value: getInPath(startingDoc, sortOrder.fieldName) || null,
|
|
29004
29066
|
};
|
|
29005
29067
|
}));
|
|
29006
29068
|
}
|
|
29007
|
-
this.snapshotSubject.next(newSnapshotEmitter.snapshots(this.options.subscribe).pipe((0,external_rxjs_namespaceObject.map)(
|
|
29069
|
+
this.snapshotSubject.next(newSnapshotEmitter.snapshots(this.options.subscribe).pipe((0,external_rxjs_namespaceObject.map)(s => s.reverse())));
|
|
29008
29070
|
}
|
|
29009
29071
|
else {
|
|
29010
29072
|
const newSnapshotEmitter = this.templateSnapshotEmitter.clone().limit(this.options.pageSize * 3);
|
|
29011
29073
|
if (startingDoc) {
|
|
29012
|
-
newSnapshotEmitter.addCompositeCondition(this.templateSnapshotEmitter.getSortOrders().map(
|
|
29074
|
+
newSnapshotEmitter.addCompositeCondition(this.templateSnapshotEmitter.getSortOrders().map(sortOrder => {
|
|
29013
29075
|
return {
|
|
29014
29076
|
fieldName: sortOrder.fieldName,
|
|
29015
29077
|
operator: sortOrder.asc ? '>=' : '<=',
|
|
29016
|
-
value: getInPath(startingDoc, sortOrder.fieldName),
|
|
29078
|
+
value: getInPath(startingDoc, sortOrder.fieldName) || null,
|
|
29017
29079
|
};
|
|
29018
29080
|
}));
|
|
29019
29081
|
}
|
|
@@ -29029,7 +29091,7 @@ class Pagination {
|
|
|
29029
29091
|
// It is possible that we get here and unsubscribe() was called. In that case we might not get any new state,
|
|
29030
29092
|
// so to avoid stalling we return an empty page in that situation. (We can't return the last page we saw
|
|
29031
29093
|
// because that has already been deleted, and also because it's possible that we've never seen any data.)
|
|
29032
|
-
this.isDestroyed.pipe((0,external_rxjs_namespaceObject.filter)(Boolean), (0,external_rxjs_namespaceObject.map)(
|
|
29094
|
+
this.isDestroyed.pipe((0,external_rxjs_namespaceObject.filter)(Boolean), (0,external_rxjs_namespaceObject.map)(_ => ({
|
|
29033
29095
|
data: [],
|
|
29034
29096
|
extractedData: [],
|
|
29035
29097
|
numBefore: 0,
|
|
@@ -29068,7 +29130,11 @@ class Pagination {
|
|
|
29068
29130
|
/** Returns a promise that resolves when the next page of data is available. */
|
|
29069
29131
|
async next() {
|
|
29070
29132
|
const { numBefore, extractedData } = await this.waitForInternalState();
|
|
29071
|
-
|
|
29133
|
+
// Setting the firstElement implicitly moves us to the next page. If we are on the last page, we don't change
|
|
29134
|
+
// firstElement because we want next() to be a no-op.
|
|
29135
|
+
if (numBefore + this.options.pageSize < extractedData.length) {
|
|
29136
|
+
this.firstElement = extractedData[numBefore + this.options.pageSize];
|
|
29137
|
+
}
|
|
29072
29138
|
this.internalStateObserver.next(null);
|
|
29073
29139
|
this.doNewQuery(extractedData[numBefore], false);
|
|
29074
29140
|
return await this.waitForData();
|
|
@@ -29079,7 +29145,7 @@ class Pagination {
|
|
|
29079
29145
|
}
|
|
29080
29146
|
/** Returns an observable that emits the current state of the pagination. */
|
|
29081
29147
|
observeState() {
|
|
29082
|
-
return this.internalStateObserver.pipe((0,external_rxjs_namespaceObject.filter)((state) => state !== null), (0,external_rxjs_namespaceObject.map)(
|
|
29148
|
+
return this.internalStateObserver.pipe((0,external_rxjs_namespaceObject.filter)((state) => state !== null), (0,external_rxjs_namespaceObject.map)(state => {
|
|
29083
29149
|
return this.internalStateToState(state);
|
|
29084
29150
|
}));
|
|
29085
29151
|
}
|
|
@@ -29114,7 +29180,7 @@ class Pagination {
|
|
|
29114
29180
|
.limit(this.options.pageSize * 3)
|
|
29115
29181
|
.flipSortOrder()
|
|
29116
29182
|
.snapshots(this.options.subscribe)
|
|
29117
|
-
.pipe((0,external_rxjs_namespaceObject.map)(
|
|
29183
|
+
.pipe((0,external_rxjs_namespaceObject.map)(s => s.reverse()));
|
|
29118
29184
|
this.snapshotSubject.next(lastPageSnapshot);
|
|
29119
29185
|
return await this.waitForData();
|
|
29120
29186
|
}
|
|
@@ -29137,12 +29203,14 @@ class Pagination {
|
|
|
29137
29203
|
|
|
29138
29204
|
|
|
29139
29205
|
|
|
29206
|
+
|
|
29140
29207
|
/** @internal */
|
|
29141
29208
|
const ExecuteFunctionSecureAnnotations = (/* unused pure expression or super */ null && ([
|
|
29142
29209
|
'secureDistributedLock',
|
|
29143
29210
|
'secureQuery',
|
|
29144
29211
|
'secureMutation',
|
|
29145
29212
|
'secureNamedQuery',
|
|
29213
|
+
'secureNativeQuery',
|
|
29146
29214
|
'secureGraphQL',
|
|
29147
29215
|
'secureApi',
|
|
29148
29216
|
'secureAiAssistantChat',
|
|
@@ -29159,6 +29227,8 @@ function transformParams(params, executeFunctionAnnotationType) {
|
|
|
29159
29227
|
return [new MutationContext(params[0].mutation, params[0].beforeAndAfterDocs, params[0].serverTimestamp)];
|
|
29160
29228
|
case 'secureNamedQuery':
|
|
29161
29229
|
return [new NamedQueryContext(params[0])];
|
|
29230
|
+
case 'secureNativeQuery':
|
|
29231
|
+
return [new NativeQueryContext(params[0], params[1], params[2])];
|
|
29162
29232
|
case 'secureDistributedLock':
|
|
29163
29233
|
return [new DistributedLockContext(params[0].mutex, params[0].exclusive)];
|
|
29164
29234
|
case 'secureGraphQL':
|
|
@@ -29687,12 +29757,12 @@ function convertInsertToUpdate(insertMutation) {
|
|
|
29687
29757
|
function reduceMutations(mutations) {
|
|
29688
29758
|
let result = [];
|
|
29689
29759
|
(0,external_rxjs_namespaceObject.from)(mutations)
|
|
29690
|
-
.pipe((0,external_rxjs_namespaceObject.groupBy)(
|
|
29760
|
+
.pipe((0,external_rxjs_namespaceObject.groupBy)(mutation => {
|
|
29691
29761
|
return `${mutation.squidDocIdObj.integrationId}${mutation.squidDocIdObj.collectionName}/${mutation.squidDocIdObj.docId}`;
|
|
29692
|
-
}), (0,external_rxjs_namespaceObject.mergeMap)(
|
|
29762
|
+
}), (0,external_rxjs_namespaceObject.mergeMap)(mutationsGroup => mutationsGroup.pipe((0,external_rxjs_namespaceObject.reduce)((mutationA, mutationB) => {
|
|
29693
29763
|
return mergeMutations(mutationA, mutationB);
|
|
29694
29764
|
}))), (0,external_rxjs_namespaceObject.toArray)())
|
|
29695
|
-
.subscribe(
|
|
29765
|
+
.subscribe(value => {
|
|
29696
29766
|
result = value;
|
|
29697
29767
|
});
|
|
29698
29768
|
return result;
|
|
@@ -29975,13 +30045,13 @@ function validateCorrectStringType(value) {
|
|
|
29975
30045
|
function isRightType(value, type) {
|
|
29976
30046
|
// TODO: the method is ambiguous when the value is an empty array and will return 'true' for any type.
|
|
29977
30047
|
if (Array.isArray(value)) {
|
|
29978
|
-
return value.every(
|
|
30048
|
+
return value.every(element => typeof element === type);
|
|
29979
30049
|
}
|
|
29980
30050
|
return typeof value === type;
|
|
29981
30051
|
}
|
|
29982
30052
|
/** Returns true if 'obj' has only keys listed in the 'keys'. Object can't be an array. */
|
|
29983
30053
|
function hasOnlyKeys(obj, keys) {
|
|
29984
|
-
return !Array.isArray(obj) && [...Object.keys(obj)].every(
|
|
30054
|
+
return !Array.isArray(obj) && [...Object.keys(obj)].every(key => keys.includes(key));
|
|
29985
30055
|
}
|
|
29986
30056
|
|
|
29987
30057
|
;// CONCATENATED MODULE: ../common/src/schema/schema.types.ts
|
|
@@ -30084,7 +30154,7 @@ function validateSchema(schema, data, updatedPaths = [], dataBefore = {}) {
|
|
|
30084
30154
|
fieldPath = `${fieldPath}/${schemaError.params['missingProperty']}`;
|
|
30085
30155
|
}
|
|
30086
30156
|
fieldPath = fieldPath.slice(1).replace(/\//g, '.') + '.';
|
|
30087
|
-
if (updatedPaths.some(
|
|
30157
|
+
if (updatedPaths.some(updatedPath => fieldPath.startsWith(updatedPath + '.'))) {
|
|
30088
30158
|
throw new ValidationError(`${fieldPath} does not conform with the collection schema.`, HttpStatus.BAD_REQUEST);
|
|
30089
30159
|
}
|
|
30090
30160
|
}
|
|
@@ -30321,7 +30391,17 @@ function validateTruthy(value, message, statusCode = HttpStatus.BAD_REQUEST, det
|
|
|
30321
30391
|
}
|
|
30322
30392
|
|
|
30323
30393
|
;// CONCATENATED MODULE: ../common/src/utils/http.ts
|
|
30324
|
-
const kotlinControllers = [
|
|
30394
|
+
const kotlinControllers = [
|
|
30395
|
+
'query',
|
|
30396
|
+
'aiData',
|
|
30397
|
+
'api',
|
|
30398
|
+
'backend-function',
|
|
30399
|
+
'webhooks',
|
|
30400
|
+
'ws',
|
|
30401
|
+
'quota',
|
|
30402
|
+
'named-query',
|
|
30403
|
+
'native-query',
|
|
30404
|
+
];
|
|
30325
30405
|
function getApplicationUrl(regionPrefix, appId, path) {
|
|
30326
30406
|
const baseUrl = 'https://squid.cloud';
|
|
30327
30407
|
const parsedBaseUrl = new URL(baseUrl);
|
|
@@ -30408,7 +30488,7 @@ class LockManager {
|
|
|
30408
30488
|
}
|
|
30409
30489
|
}
|
|
30410
30490
|
canGetLock(...mutexes) {
|
|
30411
|
-
return !mutexes.some(
|
|
30491
|
+
return !mutexes.some(mutex => { var _a; return (_a = this.locks[mutex]) === null || _a === void 0 ? void 0 : _a.value; });
|
|
30412
30492
|
}
|
|
30413
30493
|
lockSync(...mutexes) {
|
|
30414
30494
|
(0,dist.assertTruthy)(this.canGetLock(...mutexes), 'Cannot acquire lock sync');
|
|
@@ -30545,10 +30625,13 @@ function createWebSocketWrapper(url, opts = {}) {
|
|
|
30545
30625
|
ws.send(x);
|
|
30546
30626
|
},
|
|
30547
30627
|
close(code = 4999, message) {
|
|
30548
|
-
|
|
30549
|
-
|
|
30550
|
-
|
|
30551
|
-
|
|
30628
|
+
try {
|
|
30629
|
+
$.connected = false;
|
|
30630
|
+
clearTimeout(timer);
|
|
30631
|
+
timer = undefined;
|
|
30632
|
+
ws.close(code, message);
|
|
30633
|
+
}
|
|
30634
|
+
catch (e) { }
|
|
30552
30635
|
},
|
|
30553
30636
|
};
|
|
30554
30637
|
$.open();
|
|
@@ -30608,6 +30691,7 @@ function createWebSocketWrapper(url, opts = {}) {
|
|
|
30608
30691
|
|
|
30609
30692
|
|
|
30610
30693
|
|
|
30694
|
+
|
|
30611
30695
|
|
|
30612
30696
|
|
|
30613
30697
|
|
|
@@ -31549,7 +31633,7 @@ class JoinQueryBuilder extends BaseQueryBuilder {
|
|
|
31549
31633
|
}
|
|
31550
31634
|
return this.querySubscriptionManager
|
|
31551
31635
|
.processQuery(this.build(), this.rootAlias, lodash.cloneDeep(this.joins), lodash.cloneDeep(this.joinConditions), subscribe, false)
|
|
31552
|
-
.pipe(map_map(
|
|
31636
|
+
.pipe(map_map(docs => docs.map(docRecord => {
|
|
31553
31637
|
const result = {};
|
|
31554
31638
|
for (const [alias, doc] of Object.entries(docRecord)) {
|
|
31555
31639
|
const collectionName = alias === this.rootAlias ? this.collectionName : this.joins[alias].collectionName;
|
|
@@ -31633,9 +31717,9 @@ class DereferencedJoin {
|
|
|
31633
31717
|
}
|
|
31634
31718
|
/** @inheritDoc */
|
|
31635
31719
|
snapshots(subscribe) {
|
|
31636
|
-
return this.joinQueryBuilder.snapshots(subscribe).pipe(map_map(
|
|
31637
|
-
return docs.map(
|
|
31638
|
-
return lodash.mapValues(doc,
|
|
31720
|
+
return this.joinQueryBuilder.snapshots(subscribe).pipe(map_map(docs => {
|
|
31721
|
+
return docs.map(doc => {
|
|
31722
|
+
return lodash.mapValues(doc, doc1 => {
|
|
31639
31723
|
return doc1 === null || doc1 === void 0 ? void 0 : doc1.data;
|
|
31640
31724
|
});
|
|
31641
31725
|
});
|
|
@@ -31688,8 +31772,8 @@ class DereferencedGroupedJoin {
|
|
|
31688
31772
|
}
|
|
31689
31773
|
/** @inheritDoc */
|
|
31690
31774
|
snapshots(subscribe) {
|
|
31691
|
-
return this.groupedJoin.snapshots(subscribe).pipe(map_map(
|
|
31692
|
-
return docs.map(
|
|
31775
|
+
return this.groupedJoin.snapshots(subscribe).pipe(map_map(docs => {
|
|
31776
|
+
return docs.map(doc => {
|
|
31693
31777
|
return this.dereference(doc, this.groupedJoin.joinQueryBuilder.rootAlias);
|
|
31694
31778
|
});
|
|
31695
31779
|
}));
|
|
@@ -31762,7 +31846,7 @@ class GroupedJoin {
|
|
|
31762
31846
|
}
|
|
31763
31847
|
/** @inheritDoc */
|
|
31764
31848
|
snapshots(subscribe) {
|
|
31765
|
-
return this.joinQueryBuilder.snapshots(subscribe).pipe(map_map(
|
|
31849
|
+
return this.joinQueryBuilder.snapshots(subscribe).pipe(map_map(docs => {
|
|
31766
31850
|
return this.groupData(docs, this.joinQueryBuilder.rootAlias);
|
|
31767
31851
|
}));
|
|
31768
31852
|
}
|
|
@@ -31777,12 +31861,12 @@ class GroupedJoin {
|
|
|
31777
31861
|
return new DereferencedGroupedJoin(this);
|
|
31778
31862
|
}
|
|
31779
31863
|
groupData(input, rootAlias) {
|
|
31780
|
-
const oneLevelGroup = lodash.groupBy(input,
|
|
31864
|
+
const oneLevelGroup = lodash.groupBy(input, inputRow => { var _a; return (_a = inputRow[rootAlias]) === null || _a === void 0 ? void 0 : _a.squidDocId; });
|
|
31781
31865
|
return Object.values(oneLevelGroup)
|
|
31782
|
-
.filter(
|
|
31866
|
+
.filter(value => {
|
|
31783
31867
|
return value[0][rootAlias] !== undefined;
|
|
31784
31868
|
})
|
|
31785
|
-
.map(
|
|
31869
|
+
.map(value => {
|
|
31786
31870
|
const rights = this.joinQueryBuilder.leftToRight[rootAlias];
|
|
31787
31871
|
const actualValue = value[0][rootAlias];
|
|
31788
31872
|
if (rights.length === 0) {
|
|
@@ -31957,12 +32041,12 @@ class MergedQueryBuilder {
|
|
|
31957
32041
|
constructor(...snapshotEmitters) {
|
|
31958
32042
|
if (snapshotEmitters.length === 0)
|
|
31959
32043
|
throw new Error('At least one query builder must be provided');
|
|
31960
|
-
this.snapshotEmitters = snapshotEmitters.map(
|
|
31961
|
-
const maxLimit = Math.max(...this.snapshotEmitters.map(
|
|
32044
|
+
this.snapshotEmitters = snapshotEmitters.map(builder => builder.clone());
|
|
32045
|
+
const maxLimit = Math.max(...this.snapshotEmitters.map(builder => {
|
|
31962
32046
|
const limit = builder.getLimit();
|
|
31963
32047
|
return limit === -1 ? 1000 : limit;
|
|
31964
32048
|
}));
|
|
31965
|
-
this.snapshotEmitters.forEach(
|
|
32049
|
+
this.snapshotEmitters.forEach(builder => builder.limit(maxLimit));
|
|
31966
32050
|
const sortOrder = this.snapshotEmitters[0].getSortOrders();
|
|
31967
32051
|
for (const builder of this.snapshotEmitters) {
|
|
31968
32052
|
const builderSortOrder = builder.getSortOrders();
|
|
@@ -31986,7 +32070,7 @@ class MergedQueryBuilder {
|
|
|
31986
32070
|
* @inheritDoc
|
|
31987
32071
|
*/
|
|
31988
32072
|
snapshots(subscribe = true) {
|
|
31989
|
-
const observables = this.snapshotEmitters.map(
|
|
32073
|
+
const observables = this.snapshotEmitters.map(builder => builder.snapshots(subscribe));
|
|
31990
32074
|
return this.or(this.snapshotEmitters[0].getSortOrders(), ...observables);
|
|
31991
32075
|
}
|
|
31992
32076
|
/**
|
|
@@ -31996,7 +32080,7 @@ class MergedQueryBuilder {
|
|
|
31996
32080
|
throw new Error('peek is not currently supported for merged queries');
|
|
31997
32081
|
}
|
|
31998
32082
|
or(sort, ...observables) {
|
|
31999
|
-
return (0,external_rxjs_namespaceObject.combineLatest)([...observables]).pipe((0,external_rxjs_namespaceObject.map)(
|
|
32083
|
+
return (0,external_rxjs_namespaceObject.combineLatest)([...observables]).pipe((0,external_rxjs_namespaceObject.map)(results => {
|
|
32000
32084
|
const seenData = new Set();
|
|
32001
32085
|
const flatResult = results.flat();
|
|
32002
32086
|
const result = [];
|
|
@@ -32027,7 +32111,7 @@ class MergedQueryBuilder {
|
|
|
32027
32111
|
}));
|
|
32028
32112
|
}
|
|
32029
32113
|
clone() {
|
|
32030
|
-
return new MergedQueryBuilder(...this.snapshotEmitters.map(
|
|
32114
|
+
return new MergedQueryBuilder(...this.snapshotEmitters.map(builder => builder.clone()));
|
|
32031
32115
|
}
|
|
32032
32116
|
getSortOrders() {
|
|
32033
32117
|
return this.snapshotEmitters[0].getSortOrders();
|
|
@@ -32039,20 +32123,20 @@ class MergedQueryBuilder {
|
|
|
32039
32123
|
return this;
|
|
32040
32124
|
}
|
|
32041
32125
|
limit(limit) {
|
|
32042
|
-
this.snapshotEmitters.forEach(
|
|
32126
|
+
this.snapshotEmitters.forEach(builder => builder.limit(limit));
|
|
32043
32127
|
return this;
|
|
32044
32128
|
}
|
|
32045
32129
|
getLimit() {
|
|
32046
32130
|
return this.snapshotEmitters[0].getLimit();
|
|
32047
32131
|
}
|
|
32048
32132
|
flipSortOrder() {
|
|
32049
|
-
this.snapshotEmitters.forEach(
|
|
32133
|
+
this.snapshotEmitters.forEach(builder => builder.flipSortOrder());
|
|
32050
32134
|
return this;
|
|
32051
32135
|
}
|
|
32052
32136
|
serialize() {
|
|
32053
32137
|
return {
|
|
32054
32138
|
type: 'merged',
|
|
32055
|
-
queries: this.snapshotEmitters.map(
|
|
32139
|
+
queries: this.snapshotEmitters.map(s => s.serialize()),
|
|
32056
32140
|
};
|
|
32057
32141
|
}
|
|
32058
32142
|
extractData(data) {
|
|
@@ -32147,7 +32231,7 @@ class DocumentReference {
|
|
|
32147
32231
|
.getForDocument(this.squidDocId)
|
|
32148
32232
|
.dereference()
|
|
32149
32233
|
.snapshots()
|
|
32150
|
-
.pipe((0,external_rxjs_namespaceObject.map)(
|
|
32234
|
+
.pipe((0,external_rxjs_namespaceObject.map)(results => {
|
|
32151
32235
|
(0,dist.truthy)(results.length <= 1, 'Got more than one doc for the same id:' + this.squidDocId);
|
|
32152
32236
|
return results.length ? results[0] : undefined;
|
|
32153
32237
|
}));
|
|
@@ -32360,7 +32444,7 @@ class DereferenceEmitter {
|
|
|
32360
32444
|
}
|
|
32361
32445
|
/** @inheritDoc */
|
|
32362
32446
|
peek() {
|
|
32363
|
-
return this.queryBuilder.peek().map(
|
|
32447
|
+
return this.queryBuilder.peek().map(ref => ref.data);
|
|
32364
32448
|
}
|
|
32365
32449
|
/** @inheritDoc */
|
|
32366
32450
|
snapshot() {
|
|
@@ -32368,8 +32452,8 @@ class DereferenceEmitter {
|
|
|
32368
32452
|
}
|
|
32369
32453
|
/** @inheritDoc */
|
|
32370
32454
|
snapshots(subscribe) {
|
|
32371
|
-
return this.queryBuilder.snapshots(subscribe).pipe(map_map(
|
|
32372
|
-
return refs.map(
|
|
32455
|
+
return this.queryBuilder.snapshots(subscribe).pipe(map_map(refs => {
|
|
32456
|
+
return refs.map(ref => ref.data);
|
|
32373
32457
|
}));
|
|
32374
32458
|
}
|
|
32375
32459
|
getSortOrders() {
|
|
@@ -32459,7 +32543,7 @@ class QueryBuilder extends BaseQueryBuilder {
|
|
|
32459
32543
|
return this.query.limit;
|
|
32460
32544
|
}
|
|
32461
32545
|
limitBy(limit, ...fields) {
|
|
32462
|
-
const sorts = this.query.sortOrder.map(
|
|
32546
|
+
const sorts = this.query.sortOrder.map(s => {
|
|
32463
32547
|
return s.fieldName;
|
|
32464
32548
|
});
|
|
32465
32549
|
(0,dist.assertTruthy)(lodash.isEqual(fields.sort(), sorts.slice(0, fields.length).sort()), 'All fields in limitBy must be appear in the first fields in the sortBy list.');
|
|
@@ -32470,7 +32554,7 @@ class QueryBuilder extends BaseQueryBuilder {
|
|
|
32470
32554
|
sortBy(fieldName, asc = true) {
|
|
32471
32555
|
const fieldSort = { asc, fieldName };
|
|
32472
32556
|
validateFieldSort(fieldSort);
|
|
32473
|
-
(0,dist.assertTruthy)(!this.query.sortOrder.some(
|
|
32557
|
+
(0,dist.assertTruthy)(!this.query.sortOrder.some(so => so.fieldName === fieldName), `${fieldName} already in the sort list.`);
|
|
32474
32558
|
this.query.sortOrder.push(fieldSort);
|
|
32475
32559
|
return this;
|
|
32476
32560
|
}
|
|
@@ -32484,15 +32568,15 @@ class QueryBuilder extends BaseQueryBuilder {
|
|
|
32484
32568
|
mergeConditions() {
|
|
32485
32569
|
const simpleConditions = this.query.conditions.filter(isSimpleCondition);
|
|
32486
32570
|
const result = [];
|
|
32487
|
-
const groupByFieldName = lodash.groupBy(simpleConditions || [],
|
|
32571
|
+
const groupByFieldName = lodash.groupBy(simpleConditions || [], condition => condition.fieldName);
|
|
32488
32572
|
for (const fieldNameGroup of Object.values(groupByFieldName)) {
|
|
32489
|
-
const groupByOperator = lodash.groupBy(fieldNameGroup,
|
|
32573
|
+
const groupByOperator = lodash.groupBy(fieldNameGroup, operator => operator.operator);
|
|
32490
32574
|
for (const [operator, operatorGroup] of Object.entries(groupByOperator)) {
|
|
32491
32575
|
if (operator === '==' || operator === '!=') {
|
|
32492
32576
|
result.push(...operatorGroup);
|
|
32493
32577
|
continue;
|
|
32494
32578
|
}
|
|
32495
|
-
const sorted = lodash.sortBy(operatorGroup,
|
|
32579
|
+
const sorted = lodash.sortBy(operatorGroup, o => o.value);
|
|
32496
32580
|
if (operator === '>' || operator === '>=') {
|
|
32497
32581
|
result.push(sorted[sorted.length - 1]);
|
|
32498
32582
|
}
|
|
@@ -32504,7 +32588,7 @@ class QueryBuilder extends BaseQueryBuilder {
|
|
|
32504
32588
|
}
|
|
32505
32589
|
}
|
|
32506
32590
|
}
|
|
32507
|
-
return [...this.query.conditions.filter(
|
|
32591
|
+
return [...this.query.conditions.filter(c => !isSimpleCondition(c)), ...result];
|
|
32508
32592
|
}
|
|
32509
32593
|
// noinspection JSUnusedGlobalSymbols
|
|
32510
32594
|
getSortOrder() {
|
|
@@ -32540,8 +32624,8 @@ class QueryBuilder extends BaseQueryBuilder {
|
|
|
32540
32624
|
const query = this.build();
|
|
32541
32625
|
return this.querySubscriptionManager
|
|
32542
32626
|
.processQuery(query, this.collectionName, {}, {}, subscribe, this.forceFetchFromServer)
|
|
32543
|
-
.pipe(map_map(
|
|
32544
|
-
return docs.map(
|
|
32627
|
+
.pipe(map_map(docs => {
|
|
32628
|
+
return docs.map(docRecord => {
|
|
32545
32629
|
(0,dist.assertTruthy)(Object.keys(docRecord).length === 1);
|
|
32546
32630
|
const doc = docRecord[this.collectionName];
|
|
32547
32631
|
const squidDocId = getSquidDocId((0,dist.truthy)(doc).__docId__, this.collectionName, this.integrationId);
|
|
@@ -32555,7 +32639,7 @@ class QueryBuilder extends BaseQueryBuilder {
|
|
|
32555
32639
|
changes() {
|
|
32556
32640
|
let beforeDocMap = undefined;
|
|
32557
32641
|
let beforeDocSet = new Set();
|
|
32558
|
-
return this.snapshots().pipe((0,external_rxjs_namespaceObject.combineLatestWith)(this.documentIdentityService.observeChanges().pipe((0,external_rxjs_namespaceObject.switchMap)(
|
|
32642
|
+
return this.snapshots().pipe((0,external_rxjs_namespaceObject.combineLatestWith)(this.documentIdentityService.observeChanges().pipe((0,external_rxjs_namespaceObject.switchMap)(idResolutionMap => {
|
|
32559
32643
|
Object.entries(idResolutionMap).forEach(([squidDocId, newSquidDocId]) => {
|
|
32560
32644
|
replaceKeyInRecord(beforeDocMap || {}, squidDocId, newSquidDocId);
|
|
32561
32645
|
});
|
|
@@ -32632,7 +32716,7 @@ class QueryBuilder extends BaseQueryBuilder {
|
|
|
32632
32716
|
return this;
|
|
32633
32717
|
}
|
|
32634
32718
|
flipSortOrder() {
|
|
32635
|
-
this.query.sortOrder = this.query.sortOrder.map(
|
|
32719
|
+
this.query.sortOrder = this.query.sortOrder.map(sort => {
|
|
32636
32720
|
return Object.assign(Object.assign({}, sort), { asc: !sort.asc });
|
|
32637
32721
|
});
|
|
32638
32722
|
if (this.query.limitBy) {
|
|
@@ -32693,7 +32777,7 @@ function deserializeSimpleQuery(squid, serializedQuery) {
|
|
|
32693
32777
|
function deserializeMergedQuery(squid, serializedQuery) {
|
|
32694
32778
|
const { queries } = serializedQuery;
|
|
32695
32779
|
const { collectionName, integrationId } = getCollection(queries[0]);
|
|
32696
|
-
const builders = queries.map(
|
|
32780
|
+
const builders = queries.map(q => deserializeQuery(squid, q));
|
|
32697
32781
|
return squid.collection(collectionName, integrationId).or(...builders);
|
|
32698
32782
|
}
|
|
32699
32783
|
function deserializeJoinQuery(squid, serializedQuery) {
|
|
@@ -32758,8 +32842,8 @@ class AiAssistantClient {
|
|
|
32758
32842
|
this.ongoingChatSequences = {};
|
|
32759
32843
|
this.socketManager
|
|
32760
32844
|
.observeNotifications()
|
|
32761
|
-
.pipe((0,external_rxjs_namespaceObject.filter)((notification) => notification.type === 'aiAssistant'), map_map(
|
|
32762
|
-
.subscribe(
|
|
32845
|
+
.pipe((0,external_rxjs_namespaceObject.filter)((notification) => notification.type === 'aiAssistant'), map_map(n => n))
|
|
32846
|
+
.subscribe(notification => {
|
|
32763
32847
|
this.handleChatResponse(notification).then();
|
|
32764
32848
|
});
|
|
32765
32849
|
}
|
|
@@ -32798,14 +32882,14 @@ class AiAssistantClient {
|
|
|
32798
32882
|
if (complete) {
|
|
32799
32883
|
return (0,external_rxjs_namespaceObject.of)({ value, complete });
|
|
32800
32884
|
}
|
|
32801
|
-
return (0,external_rxjs_namespaceObject.of)(value).pipe((0,external_rxjs_namespaceObject.delay)(5), map_map(
|
|
32885
|
+
return (0,external_rxjs_namespaceObject.of)(value).pipe((0,external_rxjs_namespaceObject.delay)(5), map_map(char => ({ value: char, complete: false })));
|
|
32802
32886
|
}), (0,external_rxjs_namespaceObject.takeWhile)(({ complete }) => !complete, true))
|
|
32803
32887
|
.subscribe({
|
|
32804
32888
|
next: ({ value }) => {
|
|
32805
32889
|
accumulatedValue += value;
|
|
32806
32890
|
subject.next(accumulatedValue);
|
|
32807
32891
|
},
|
|
32808
|
-
error:
|
|
32892
|
+
error: e => {
|
|
32809
32893
|
console.error(e);
|
|
32810
32894
|
},
|
|
32811
32895
|
complete: () => {
|
|
@@ -32819,7 +32903,7 @@ class AiAssistantClient {
|
|
|
32819
32903
|
integrationId: this.integrationId,
|
|
32820
32904
|
clientRequestId,
|
|
32821
32905
|
};
|
|
32822
|
-
this.rpcManager.post('ai/assistant/chat', request).catch(
|
|
32906
|
+
this.rpcManager.post('ai/assistant/chat', request).catch(e => {
|
|
32823
32907
|
subject.error(e);
|
|
32824
32908
|
subject.complete();
|
|
32825
32909
|
});
|
|
@@ -33128,7 +33212,7 @@ class ApiManager {
|
|
|
33128
33212
|
request,
|
|
33129
33213
|
serverUrlOverride: this.apiServerUrlOverrideMapping[integrationId],
|
|
33130
33214
|
};
|
|
33131
|
-
return (0,external_rxjs_namespaceObject.race)((0,external_rxjs_namespaceObject.from)(this.rpcManager.post('api/call', callApiRequest)).pipe(map_map(
|
|
33215
|
+
return (0,external_rxjs_namespaceObject.race)((0,external_rxjs_namespaceObject.from)(this.rpcManager.post('api/call', callApiRequest)).pipe(map_map(response => {
|
|
33132
33216
|
if (response.success) {
|
|
33133
33217
|
return deserializeObj(response.payload);
|
|
33134
33218
|
}
|
|
@@ -33143,45 +33227,87 @@ class ApiManager {
|
|
|
33143
33227
|
|
|
33144
33228
|
;// CONCATENATED MODULE: ./src/auth.manager.ts
|
|
33145
33229
|
|
|
33230
|
+
|
|
33146
33231
|
class AuthManager {
|
|
33147
|
-
constructor(
|
|
33148
|
-
this.destructManager = destructManager;
|
|
33232
|
+
constructor(apiKey, authTokenProvider) {
|
|
33149
33233
|
this.apiKey = apiKey;
|
|
33150
|
-
|
|
33151
|
-
this.
|
|
33152
|
-
|
|
33153
|
-
|
|
33154
|
-
|
|
33155
|
-
|
|
33156
|
-
|
|
33157
|
-
|
|
33234
|
+
// By default, the auth provider resolves to 'undefined' token.
|
|
33235
|
+
this.authDataProvider = async () => ({ token: undefined });
|
|
33236
|
+
if (authTokenProvider) {
|
|
33237
|
+
this.setAuthTokenProvider(authTokenProvider, undefined);
|
|
33238
|
+
}
|
|
33239
|
+
}
|
|
33240
|
+
/**
|
|
33241
|
+
* Sets a new ID token or an ID token provider.
|
|
33242
|
+
* Deprecated. Pass the provider via constructor parameters.
|
|
33243
|
+
*/
|
|
33244
|
+
setAuthIdToken(tokenArg, integrationId) {
|
|
33245
|
+
// Using this warning in DD we can track how many active clients use the deprecated API.
|
|
33246
|
+
console.warn('Using a deprecated setAuthIdToken method. Update code to pass AuthTokenProvider in Squid constructor.');
|
|
33247
|
+
// Convert the input into AuthTokenProvider.
|
|
33248
|
+
if (typeof tokenArg === 'string' || tokenArg === undefined) {
|
|
33249
|
+
this.setAuthTokenProvider(async () => tokenArg, integrationId);
|
|
33250
|
+
return;
|
|
33251
|
+
}
|
|
33252
|
+
if (typeof tokenArg === 'function') {
|
|
33253
|
+
this.setAuthTokenProvider(tokenArg, integrationId);
|
|
33254
|
+
return;
|
|
33255
|
+
}
|
|
33256
|
+
(0,dist.assertTruthy)(typeof tokenArg === 'object');
|
|
33257
|
+
if ((0,external_rxjs_namespaceObject.isObservable)(tokenArg)) {
|
|
33258
|
+
this.setAuthTokenProvider(() => (0,external_rxjs_namespaceObject.firstValueFrom)(tokenArg), integrationId);
|
|
33259
|
+
return;
|
|
33260
|
+
}
|
|
33261
|
+
// tokenArg is a Promise.
|
|
33262
|
+
this.setAuthTokenProvider(() => tokenArg, integrationId);
|
|
33263
|
+
}
|
|
33264
|
+
setAuthTokenProvider(tokenProvider, integrationId) {
|
|
33265
|
+
this.authDataProvider = async () => {
|
|
33266
|
+
const authData = { token: await tokenProvider(integrationId), integrationId };
|
|
33267
|
+
this.lastUsedJwtTokenForDeprecatedCode = authData.token;
|
|
33268
|
+
this.lastUsedIntegrationIdForDeprecatedCode = integrationId;
|
|
33269
|
+
return authData;
|
|
33270
|
+
};
|
|
33158
33271
|
}
|
|
33159
|
-
|
|
33160
|
-
this.
|
|
33161
|
-
this.authIdTokenSet.next(false);
|
|
33162
|
-
const authDataObservable = !idToken || typeof idToken === 'string'
|
|
33163
|
-
? (0,external_rxjs_namespaceObject.of)({ token: idToken, integrationId })
|
|
33164
|
-
: (0,external_rxjs_namespaceObject.from)(idToken).pipe((0,external_rxjs_namespaceObject.map)((idToken) => ({ token: idToken, integrationId })));
|
|
33165
|
-
this.authIdTokenObservableSubject.next(authDataObservable);
|
|
33272
|
+
async getAuthData() {
|
|
33273
|
+
return this.authDataProvider();
|
|
33166
33274
|
}
|
|
33275
|
+
/**
|
|
33276
|
+
* Returns an observable over AuthData.
|
|
33277
|
+
* Deprecated: the method will be removed soon. Use getAuthData().
|
|
33278
|
+
*/
|
|
33167
33279
|
observeAuthIdToken() {
|
|
33168
|
-
|
|
33169
|
-
|
|
33170
|
-
|
|
33171
|
-
if (this.shouldWaitForAuth && !this.destructManager.isDestructing) {
|
|
33172
|
-
await (0,external_rxjs_namespaceObject.firstValueFrom)((0,external_rxjs_namespaceObject.race)(this.authIdTokenSet.asObservable().pipe((0,external_rxjs_namespaceObject.filter)(Boolean)), this.destructManager.observeIsDestructing()));
|
|
33173
|
-
}
|
|
33280
|
+
const authData$ = new external_rxjs_namespaceObject.ReplaySubject();
|
|
33281
|
+
this.getAuthData().then(value => authData$.next(value));
|
|
33282
|
+
return authData$;
|
|
33174
33283
|
}
|
|
33175
33284
|
getApiKey() {
|
|
33176
33285
|
return this.apiKey;
|
|
33177
33286
|
}
|
|
33287
|
+
/**
|
|
33288
|
+
* Returns the last used Auth token.
|
|
33289
|
+
* Deprecated. Use: `getToken()` instead.
|
|
33290
|
+
*/
|
|
33178
33291
|
getAuthToken() {
|
|
33179
33292
|
if (this.apiKey) {
|
|
33180
33293
|
return { type: 'ApiKey', token: this.apiKey };
|
|
33181
33294
|
}
|
|
33182
|
-
if (!this.
|
|
33295
|
+
if (!this.lastUsedJwtTokenForDeprecatedCode)
|
|
33183
33296
|
return undefined;
|
|
33184
|
-
return {
|
|
33297
|
+
return {
|
|
33298
|
+
type: 'Bearer',
|
|
33299
|
+
token: this.lastUsedJwtTokenForDeprecatedCode,
|
|
33300
|
+
integrationId: this.lastUsedIntegrationIdForDeprecatedCode,
|
|
33301
|
+
};
|
|
33302
|
+
}
|
|
33303
|
+
async getToken() {
|
|
33304
|
+
if (this.apiKey) {
|
|
33305
|
+
return { type: 'ApiKey', token: this.apiKey };
|
|
33306
|
+
}
|
|
33307
|
+
const { token, integrationId } = await this.getAuthData();
|
|
33308
|
+
if (!token)
|
|
33309
|
+
return undefined;
|
|
33310
|
+
return { type: 'Bearer', token, integrationId };
|
|
33185
33311
|
}
|
|
33186
33312
|
}
|
|
33187
33313
|
|
|
@@ -33199,7 +33325,7 @@ class BackendFunctionManager {
|
|
|
33199
33325
|
functionName,
|
|
33200
33326
|
paramsArrayStr: serialization_serializeObj(params),
|
|
33201
33327
|
};
|
|
33202
|
-
return (0,external_rxjs_namespaceObject.race)((0,external_rxjs_namespaceObject.from)(this.rpcManager.post('backend-function/execute', request)).pipe(map_map(
|
|
33328
|
+
return (0,external_rxjs_namespaceObject.race)((0,external_rxjs_namespaceObject.from)(this.rpcManager.post('backend-function/execute', request)).pipe(map_map(response => {
|
|
33203
33329
|
if (!response.success) {
|
|
33204
33330
|
throw new Error(response.payload);
|
|
33205
33331
|
}
|
|
@@ -33236,7 +33362,7 @@ class ClientIdService {
|
|
|
33236
33362
|
return this.clientIdSubject;
|
|
33237
33363
|
}
|
|
33238
33364
|
observeClientTooOld() {
|
|
33239
|
-
return this.clientTooOldSubject.pipe((0,external_rxjs_namespaceObject.filter)(
|
|
33365
|
+
return this.clientTooOldSubject.pipe((0,external_rxjs_namespaceObject.filter)(v => v), (0,external_rxjs_namespaceObject.map)(() => undefined));
|
|
33240
33366
|
}
|
|
33241
33367
|
/** there was a long-term disconnection of the socket */
|
|
33242
33368
|
notifyClientTooOld() {
|
|
@@ -33249,7 +33375,7 @@ class ClientIdService {
|
|
|
33249
33375
|
observeClientReadyToBeRegenerated() {
|
|
33250
33376
|
return this.clientTooOldSubject.pipe(
|
|
33251
33377
|
// skip the initial connection
|
|
33252
|
-
(0,external_rxjs_namespaceObject.skip)(1), (0,external_rxjs_namespaceObject.filter)(
|
|
33378
|
+
(0,external_rxjs_namespaceObject.skip)(1), (0,external_rxjs_namespaceObject.filter)(v => !v), (0,external_rxjs_namespaceObject.map)(v => undefined));
|
|
33253
33379
|
}
|
|
33254
33380
|
getClientId() {
|
|
33255
33381
|
return this.clientIdSubject.value;
|
|
@@ -33296,7 +33422,7 @@ class ConnectionDetails {
|
|
|
33296
33422
|
this.clientIdService = clientIdService;
|
|
33297
33423
|
this.socketManager = socketManager;
|
|
33298
33424
|
this.isConnected = false;
|
|
33299
|
-
this.socketManager.observeConnectionReady().subscribe(
|
|
33425
|
+
this.socketManager.observeConnectionReady().subscribe(isConnected => {
|
|
33300
33426
|
this.isConnected = isConnected;
|
|
33301
33427
|
});
|
|
33302
33428
|
}
|
|
@@ -33415,7 +33541,7 @@ class DataManager {
|
|
|
33415
33541
|
this.handleNotifications();
|
|
33416
33542
|
this.startDeleteExpiredTimestampsJob();
|
|
33417
33543
|
this.handleOrphanDocs();
|
|
33418
|
-
this.outgoingMutationsEmpty.subscribe(
|
|
33544
|
+
this.outgoingMutationsEmpty.subscribe(isEmpty => {
|
|
33419
33545
|
/**
|
|
33420
33546
|
* We should not send queries to the server before we know that all outgoing updates were
|
|
33421
33547
|
* applied on the server.
|
|
@@ -33528,7 +33654,7 @@ class DataManager {
|
|
|
33528
33654
|
this.docIdToLocalTimestamp.set(squidDocId, new Date().getTime());
|
|
33529
33655
|
}
|
|
33530
33656
|
const allClientRequestIds = this.querySubscriptionManager.setClientRequestIdsForLocalDoc(squidDocId, docAfter);
|
|
33531
|
-
allClientRequestIds.forEach(
|
|
33657
|
+
allClientRequestIds.forEach(clientRequestId => this.batchClientRequestIds.add(clientRequestId));
|
|
33532
33658
|
}, transactionId);
|
|
33533
33659
|
}
|
|
33534
33660
|
/** Same as runInTransaction with the exception that the passed function runs synchronously. */
|
|
@@ -33571,13 +33697,13 @@ class DataManager {
|
|
|
33571
33697
|
handleNotifications() {
|
|
33572
33698
|
this.socketManager
|
|
33573
33699
|
.observeNotifications()
|
|
33574
|
-
.pipe((0,external_rxjs_namespaceObject.filter)((notification) => notification.type === 'mutations'), map_map(
|
|
33575
|
-
.subscribe(
|
|
33700
|
+
.pipe((0,external_rxjs_namespaceObject.filter)((notification) => notification.type === 'mutations'), map_map(n => n))
|
|
33701
|
+
.subscribe(notification => {
|
|
33576
33702
|
this.outgoingMutationsEmpty.pipe((0,external_rxjs_namespaceObject.filter)(Boolean), (0,external_rxjs_namespaceObject.take)(1)).subscribe(() => {
|
|
33577
33703
|
this.handleIncomingMutations(notification.payload);
|
|
33578
33704
|
});
|
|
33579
33705
|
});
|
|
33580
|
-
this.querySubscriptionManager.observeQueryResults().subscribe(
|
|
33706
|
+
this.querySubscriptionManager.observeQueryResults().subscribe(queryResult => {
|
|
33581
33707
|
this.outgoingMutationsEmpty.pipe((0,external_rxjs_namespaceObject.filter)(Boolean), (0,external_rxjs_namespaceObject.take)(1)).subscribe(() => {
|
|
33582
33708
|
this.handleIncomingQuerySnapshots(queryResult);
|
|
33583
33709
|
});
|
|
@@ -33612,7 +33738,7 @@ class DataManager {
|
|
|
33612
33738
|
const squidDocId = getSquidDocId(doc.__docId__, query.collectionName, query.integrationId);
|
|
33613
33739
|
squidDocIdToNewData[squidDocId] = { properties: doc, timestamp: doc.__ts__ };
|
|
33614
33740
|
}
|
|
33615
|
-
this.runInTransactionSync(
|
|
33741
|
+
this.runInTransactionSync(transactionId => {
|
|
33616
33742
|
this.querySubscriptionManager.setGotInitialResult(queryResult.clientRequestId);
|
|
33617
33743
|
this.batchClientRequestIds.add(queryResult.clientRequestId);
|
|
33618
33744
|
const someDocumentsWereOutdated = this.applyIncomingUpdates(squidDocIdToNewData, transactionId);
|
|
@@ -33672,7 +33798,7 @@ class DataManager {
|
|
|
33672
33798
|
/** The incomingUpdate was applied locally - remove it from pendingIncomingUpdates. */
|
|
33673
33799
|
this.pendingIncomingUpdates.delete(squidDocId);
|
|
33674
33800
|
const allClientRequestIds = this.querySubscriptionManager.setClientRequestIdsForLocalDoc(squidDocId, incomingUpdate.properties);
|
|
33675
|
-
allClientRequestIds.forEach(
|
|
33801
|
+
allClientRequestIds.forEach(clientRequestId => {
|
|
33676
33802
|
this.batchClientRequestIds.add(clientRequestId);
|
|
33677
33803
|
});
|
|
33678
33804
|
/**
|
|
@@ -33782,7 +33908,7 @@ class DataManager {
|
|
|
33782
33908
|
try {
|
|
33783
33909
|
await promise_pool_dist.PromisePool.for(outgoingMutationsByIntegrationId)
|
|
33784
33910
|
.withConcurrency(outgoingMutationsByIntegrationId.length || 1)
|
|
33785
|
-
.handleError(
|
|
33911
|
+
.handleError(e => {
|
|
33786
33912
|
throw e;
|
|
33787
33913
|
})
|
|
33788
33914
|
.process(async ([integrationId, outgoingMutations]) => {
|
|
@@ -33811,9 +33937,9 @@ class DataManager {
|
|
|
33811
33937
|
}
|
|
33812
33938
|
async sendMutationsForIntegration(outgoingMutations, integrationId) {
|
|
33813
33939
|
try {
|
|
33814
|
-
const { timestamp, idResolutionMap = {}, refreshList = [], } = await this.mutationSender.sendMutations(outgoingMutations.map(
|
|
33940
|
+
const { timestamp, idResolutionMap = {}, refreshList = [], } = await this.mutationSender.sendMutations(outgoingMutations.map(outgoingMutation => outgoingMutation.mutation), integrationId);
|
|
33815
33941
|
this.documentIdentityService.migrate(idResolutionMap);
|
|
33816
|
-
refreshList.forEach(
|
|
33942
|
+
refreshList.forEach(docId => {
|
|
33817
33943
|
this.refreshDocIdToTimestamp.set(idResolutionMap[docId] || docId, timestamp);
|
|
33818
33944
|
});
|
|
33819
33945
|
for (const outgoingMutation of outgoingMutations) {
|
|
@@ -33915,7 +34041,7 @@ class DataManager {
|
|
|
33915
34041
|
* An orphan document should not stay locally since it may be stale after some time.
|
|
33916
34042
|
*/
|
|
33917
34043
|
handleOrphanDocs() {
|
|
33918
|
-
this.querySubscriptionManager.onOrphanDocuments.subscribe(
|
|
34044
|
+
this.querySubscriptionManager.onOrphanDocuments.subscribe(orphanDocs => {
|
|
33919
34045
|
for (const squidDocId of orphanDocs) {
|
|
33920
34046
|
if (!this.isTracked(squidDocId)) {
|
|
33921
34047
|
this.forgetDocument(squidDocId);
|
|
@@ -33942,8 +34068,8 @@ class DataManager {
|
|
|
33942
34068
|
this.setExpiration(squidDocId, true);
|
|
33943
34069
|
}
|
|
33944
34070
|
migrateDocIds(idResolutionMap) {
|
|
33945
|
-
this.pendingOutgoingMutations.forEach(
|
|
33946
|
-
outgoingMutations.forEach(
|
|
34071
|
+
this.pendingOutgoingMutations.forEach(outgoingMutations => {
|
|
34072
|
+
outgoingMutations.forEach(outgoingMutation => {
|
|
33947
34073
|
const squidDocId = getSquidDocId(outgoingMutation.mutation.squidDocIdObj);
|
|
33948
34074
|
const resolvedId = idResolutionMap[squidDocId];
|
|
33949
34075
|
if (resolvedId) {
|
|
@@ -34023,21 +34149,21 @@ class DistributedLockManager {
|
|
|
34023
34149
|
this.ongoingLocks = {};
|
|
34024
34150
|
this.acquireLockMessagesFromServer = this.socketManager
|
|
34025
34151
|
.observeNotifications()
|
|
34026
|
-
.pipe((0,external_rxjs_namespaceObject.filter)(
|
|
34152
|
+
.pipe((0,external_rxjs_namespaceObject.filter)(message => message.type === 'lockAcquired'));
|
|
34027
34153
|
this.releaseLockMessagesFromServer = this.socketManager
|
|
34028
34154
|
.observeNotifications()
|
|
34029
|
-
.pipe((0,external_rxjs_namespaceObject.filter)(
|
|
34155
|
+
.pipe((0,external_rxjs_namespaceObject.filter)(message => message.type === 'lockReleased'));
|
|
34030
34156
|
// we may override this value in tests
|
|
34031
34157
|
this.lockWaitForConnectionThreshold = 2000;
|
|
34032
34158
|
destructManager.onPreDestruct(() => {
|
|
34033
34159
|
this.releaseAllLocks();
|
|
34034
34160
|
});
|
|
34035
|
-
this.socketManager.observeConnectionReady().subscribe(
|
|
34161
|
+
this.socketManager.observeConnectionReady().subscribe(ready => {
|
|
34036
34162
|
if (ready)
|
|
34037
34163
|
return;
|
|
34038
34164
|
this.releaseAllLocks();
|
|
34039
34165
|
});
|
|
34040
|
-
this.releaseLockMessagesFromServer.subscribe(
|
|
34166
|
+
this.releaseLockMessagesFromServer.subscribe(message => {
|
|
34041
34167
|
const lock = this.ongoingLocks[message.payload.clientRequestId];
|
|
34042
34168
|
if (lock === undefined)
|
|
34043
34169
|
return;
|
|
@@ -34072,7 +34198,7 @@ class DistributedLockManager {
|
|
|
34072
34198
|
lockId: undefined,
|
|
34073
34199
|
},
|
|
34074
34200
|
};
|
|
34075
|
-
})), this.acquireLockMessagesFromServer.pipe((0,external_rxjs_namespaceObject.filter)(
|
|
34201
|
+
})), this.acquireLockMessagesFromServer.pipe((0,external_rxjs_namespaceObject.filter)(message => message.payload.clientRequestId === clientRequestId))));
|
|
34076
34202
|
if (!result.payload.lockId) {
|
|
34077
34203
|
throw new Error(`Failed to acquire lock: ${result.payload.error}`);
|
|
34078
34204
|
}
|
|
@@ -34179,7 +34305,7 @@ class DocumentReferenceFactory {
|
|
|
34179
34305
|
*/
|
|
34180
34306
|
getDocumentsForCollection(integrationId, collectionName) {
|
|
34181
34307
|
const collectionKey = this.getCollectionKey(integrationId, collectionName);
|
|
34182
|
-
return (this.documentsForCollection.get(collectionKey) || []).filter(
|
|
34308
|
+
return (this.documentsForCollection.get(collectionKey) || []).filter(d => d.hasData);
|
|
34183
34309
|
}
|
|
34184
34310
|
/**
|
|
34185
34311
|
* @internal
|
|
@@ -34258,18 +34384,18 @@ class DocumentStore {
|
|
|
34258
34384
|
return 0;
|
|
34259
34385
|
}
|
|
34260
34386
|
group(sortedDocs, sortFieldNames) {
|
|
34261
|
-
return Object.values(lodash_default().groupBy(sortedDocs,
|
|
34262
|
-
return serialization_normalizeJsonAsString(sortFieldNames.map(
|
|
34387
|
+
return Object.values(lodash_default().groupBy(sortedDocs, doc => {
|
|
34388
|
+
return serialization_normalizeJsonAsString(sortFieldNames.map(fieldName => getInPath(doc, fieldName)));
|
|
34263
34389
|
}));
|
|
34264
34390
|
}
|
|
34265
34391
|
sortAndLimitDocs(docIdSet, query) {
|
|
34266
34392
|
if (docIdSet.size === 0) {
|
|
34267
34393
|
return [];
|
|
34268
34394
|
}
|
|
34269
|
-
const docs = [...docIdSet].map(
|
|
34395
|
+
const docs = [...docIdSet].map(id => this.squidDocIdToDoc.get(id)).filter(dist.isNonNullable);
|
|
34270
34396
|
const { sortOrder, limitBy } = query;
|
|
34271
|
-
const sortFieldNames = sortOrder.map(
|
|
34272
|
-
const sortOrders = sortOrder.map(
|
|
34397
|
+
const sortFieldNames = sortOrder.map(s => s.fieldName);
|
|
34398
|
+
const sortOrders = sortOrder.map(s => (s.asc ? 'asc' : 'desc'));
|
|
34273
34399
|
const sortedDocs = docs.sort((a, b) => {
|
|
34274
34400
|
return this.compareSquidDocs(a, b, sortFieldNames, sortOrders);
|
|
34275
34401
|
});
|
|
@@ -34281,10 +34407,10 @@ class DocumentStore {
|
|
|
34281
34407
|
const sortedGroups = this.group(sortedDocs, fields);
|
|
34282
34408
|
let limitedGroups;
|
|
34283
34409
|
if (reverseSort) {
|
|
34284
|
-
limitedGroups = sortedGroups.map(
|
|
34410
|
+
limitedGroups = sortedGroups.map(group => group.slice(-internalLimit));
|
|
34285
34411
|
}
|
|
34286
34412
|
else {
|
|
34287
|
-
limitedGroups = sortedGroups.map(
|
|
34413
|
+
limitedGroups = sortedGroups.map(group => group.slice(0, internalLimit));
|
|
34288
34414
|
}
|
|
34289
34415
|
return limitedGroups.flat().slice(0, mainLimit);
|
|
34290
34416
|
}
|
|
@@ -47572,7 +47698,7 @@ class MutationSender {
|
|
|
47572
47698
|
}
|
|
47573
47699
|
async sendMutations(mutations, integrationId) {
|
|
47574
47700
|
const reducedMutations = reduceMutations(mutations);
|
|
47575
|
-
const mutexes = reducedMutations.map(
|
|
47701
|
+
const mutexes = reducedMutations.map(mutation => `sendMutation_${getSquidDocId(mutation.squidDocIdObj)}`);
|
|
47576
47702
|
await this.lockManager.lock(...mutexes);
|
|
47577
47703
|
await this.querySender.waitForAllQueriesToFinish();
|
|
47578
47704
|
try {
|
|
@@ -47602,12 +47728,11 @@ class MutationSender {
|
|
|
47602
47728
|
class NamedQueryManager {
|
|
47603
47729
|
constructor(rpcManager, socketManager) {
|
|
47604
47730
|
this.rpcManager = rpcManager;
|
|
47605
|
-
this.socketManager = socketManager;
|
|
47606
47731
|
this.ongoingNamedQueryExecutions = {};
|
|
47607
47732
|
socketManager
|
|
47608
47733
|
.observeNotifications()
|
|
47609
|
-
.pipe((0,external_rxjs_namespaceObject.filter)((notification) => notification.type === 'namedQuery'), map_map(
|
|
47610
|
-
.subscribe(
|
|
47734
|
+
.pipe((0,external_rxjs_namespaceObject.filter)((notification) => notification.type === 'namedQuery'), map_map(n => n))
|
|
47735
|
+
.subscribe(notification => {
|
|
47611
47736
|
this.handleNamedQueryResponse(notification.clientRequestId, notification.payload);
|
|
47612
47737
|
});
|
|
47613
47738
|
}
|
|
@@ -47621,7 +47746,7 @@ class NamedQueryManager {
|
|
|
47621
47746
|
paramsRecordStr: serialization_serializeObj(params),
|
|
47622
47747
|
clientRequestId,
|
|
47623
47748
|
};
|
|
47624
|
-
this.rpcManager.post('named-query/execute', request).catch(
|
|
47749
|
+
this.rpcManager.post('named-query/execute', request).catch(e => {
|
|
47625
47750
|
console.error('Got error while executing named query', queryName, 'for integration', integrationId, e);
|
|
47626
47751
|
subject.error(e);
|
|
47627
47752
|
subject.complete();
|
|
@@ -47662,13 +47787,13 @@ class LocalQueryManager {
|
|
|
47662
47787
|
const queryContext = new query_context_QueryContext(query);
|
|
47663
47788
|
const references = this.documentReferenceFactory
|
|
47664
47789
|
.getDocumentsForCollection(integrationId, collectionName)
|
|
47665
|
-
.filter(
|
|
47790
|
+
.filter(doc => queryContext.documentMatchesQuery(doc.data));
|
|
47666
47791
|
const refMap = {};
|
|
47667
|
-
references.forEach(
|
|
47792
|
+
references.forEach(reference => {
|
|
47668
47793
|
refMap[reference.squidDocId] = reference;
|
|
47669
47794
|
});
|
|
47670
47795
|
const documents = this.documentStore.sortAndLimitDocs(new Set(Object.keys(refMap)), query);
|
|
47671
|
-
return documents.map(
|
|
47796
|
+
return documents.map(doc => refMap[getSquidDocId(doc.__docId__, collectionName, integrationId)]);
|
|
47672
47797
|
}
|
|
47673
47798
|
}
|
|
47674
47799
|
|
|
@@ -48025,7 +48150,7 @@ class StateService {
|
|
|
48025
48150
|
const subscription = subject
|
|
48026
48151
|
.pipe(
|
|
48027
48152
|
// If there are path to exclude - remove them
|
|
48028
|
-
filter(
|
|
48153
|
+
filter(dataAndAction => {
|
|
48029
48154
|
if (!pathsToExcludeFn)
|
|
48030
48155
|
return true;
|
|
48031
48156
|
const pathToExcludeTrie = new PathTrie();
|
|
@@ -48033,7 +48158,7 @@ class StateService {
|
|
|
48033
48158
|
for (const pathToExclude of pathsToExclude) {
|
|
48034
48159
|
pathToExcludeTrie.getOrCreatePathTrieNode(pathToExclude, true);
|
|
48035
48160
|
}
|
|
48036
|
-
const pathsInAction = extractAllPathActions(dataAndAction.action).map(
|
|
48161
|
+
const pathsInAction = extractAllPathActions(dataAndAction.action).map(a => a.path);
|
|
48037
48162
|
let affectsNonExcludedPaths = false;
|
|
48038
48163
|
for (const pathInAction of pathsInAction) {
|
|
48039
48164
|
if (pathToExcludeTrie.getNodeList(pathInAction).length === 0) {
|
|
@@ -48044,7 +48169,7 @@ class StateService {
|
|
|
48044
48169
|
return affectsNonExcludedPaths;
|
|
48045
48170
|
}),
|
|
48046
48171
|
// Extract the data
|
|
48047
|
-
map_map(
|
|
48172
|
+
map_map(dataAndAction => dataAndAction.data))
|
|
48048
48173
|
.subscribe(observer);
|
|
48049
48174
|
return () => {
|
|
48050
48175
|
subscription.unsubscribe();
|
|
@@ -48258,7 +48383,7 @@ class QuerySubscriptionManager {
|
|
|
48258
48383
|
setClientRequestIdsForLocalDoc(squidDocId, properties) {
|
|
48259
48384
|
const clientRequestIdsBefore = this.localDocumentToClientRequestIds.get(squidDocId) || new Set();
|
|
48260
48385
|
const clientRequestIdsAfter = new Set(properties
|
|
48261
|
-
? this.findQueriesForDocument(properties, squidDocId).map(
|
|
48386
|
+
? this.findQueriesForDocument(properties, squidDocId).map(querySubscriptionId => parseQuerySubscriptionId(querySubscriptionId).clientRequestId)
|
|
48262
48387
|
: []);
|
|
48263
48388
|
const allClientRequestIds = new Set([...clientRequestIdsBefore, ...clientRequestIdsAfter]);
|
|
48264
48389
|
for (const clientRequestIdBefore of [...clientRequestIdsBefore]) {
|
|
@@ -48302,7 +48427,12 @@ class QuerySubscriptionManager {
|
|
|
48302
48427
|
const ongoingQuery = this.ongoingQueries.get(clientRequestId);
|
|
48303
48428
|
if (!ongoingQuery)
|
|
48304
48429
|
continue;
|
|
48305
|
-
|
|
48430
|
+
if (!this.destructManager.isDestructing) {
|
|
48431
|
+
ongoingQuery.dataSubject.error(err);
|
|
48432
|
+
}
|
|
48433
|
+
else {
|
|
48434
|
+
ongoingQuery.dataSubject.complete();
|
|
48435
|
+
}
|
|
48306
48436
|
ongoingQuery.done = true;
|
|
48307
48437
|
// TODO handle joins
|
|
48308
48438
|
}
|
|
@@ -48314,12 +48444,12 @@ class QuerySubscriptionManager {
|
|
|
48314
48444
|
const ongoingQuery = this.ongoingQueries.get(clientRequestId);
|
|
48315
48445
|
if (!ongoingQuery)
|
|
48316
48446
|
continue;
|
|
48317
|
-
if (!ongoingQuery.gotInitialResponse || !ongoingQuery.activated)
|
|
48447
|
+
if (!ongoingQuery.gotInitialResponse || !ongoingQuery.activated || ongoingQuery.isInFlight)
|
|
48318
48448
|
continue;
|
|
48319
48449
|
const docIdSet = this.clientRequestIdToLocalDocuments.get(clientRequestId) || new Set();
|
|
48320
48450
|
const result = this.documentStore.sortAndLimitDocs(docIdSet, ongoingQuery.query);
|
|
48321
48451
|
const observablesUpdated = ongoingQuery.supportedQueries
|
|
48322
|
-
.map(
|
|
48452
|
+
.map(supportedOngoingQuery => this.updateOngoingQueryWithNewDataFromSupportingQuery(result, supportedOngoingQuery))
|
|
48323
48453
|
.some(Boolean);
|
|
48324
48454
|
let rootOngoingQuery = ongoingQuery;
|
|
48325
48455
|
while (!rootOngoingQuery.allObservables) {
|
|
@@ -48414,8 +48544,8 @@ class QuerySubscriptionManager {
|
|
|
48414
48544
|
}
|
|
48415
48545
|
this.sendQueryToServerOrUseParentQuery(rootOngoingQuery);
|
|
48416
48546
|
rootOngoingQuery.allObservables = new external_rxjs_namespaceObject.ReplaySubject(1);
|
|
48417
|
-
const result = rootOngoingQuery.allObservables.pipe((0,external_rxjs_namespaceObject.switchMap)(
|
|
48418
|
-
return (0,external_rxjs_namespaceObject.combineLatest)(allObservables).pipe(map_map(
|
|
48547
|
+
const result = rootOngoingQuery.allObservables.pipe((0,external_rxjs_namespaceObject.switchMap)(allObservables => {
|
|
48548
|
+
return (0,external_rxjs_namespaceObject.combineLatest)(allObservables).pipe(map_map(allResults => {
|
|
48419
48549
|
return this.joinResults(allResults, joinConditions, rootOngoingQuery);
|
|
48420
48550
|
}));
|
|
48421
48551
|
}), filter(() => {
|
|
@@ -48472,7 +48602,7 @@ class QuerySubscriptionManager {
|
|
|
48472
48602
|
ongoingQuery.dataSubject
|
|
48473
48603
|
.pipe((0,external_rxjs_namespaceObject.finalize)(async () => {
|
|
48474
48604
|
if (ongoingQuery.unsubscribeBlockerCount.value > 0) {
|
|
48475
|
-
await (0,external_rxjs_namespaceObject.firstValueFrom)((0,external_rxjs_namespaceObject.race)(this.destructManager.observeIsDestructing(), ongoingQuery.unsubscribeBlockerCount.pipe(filter(
|
|
48605
|
+
await (0,external_rxjs_namespaceObject.firstValueFrom)((0,external_rxjs_namespaceObject.race)(this.destructManager.observeIsDestructing(), ongoingQuery.unsubscribeBlockerCount.pipe(filter(count => count === 0))));
|
|
48476
48606
|
}
|
|
48477
48607
|
this.queryMappingManager.removeQuery(querySubscriptionId).then();
|
|
48478
48608
|
this.ongoingQueries.delete(clientRequestId);
|
|
@@ -48481,7 +48611,9 @@ class QuerySubscriptionManager {
|
|
|
48481
48611
|
const unsubscribeRequest = {
|
|
48482
48612
|
clientRequestId,
|
|
48483
48613
|
};
|
|
48484
|
-
this.rpcManager.post('query/unsubscribe', unsubscribeRequest).catch(
|
|
48614
|
+
this.rpcManager.post('query/unsubscribe', unsubscribeRequest).catch(e => {
|
|
48615
|
+
if (this.destructManager.isDestructing)
|
|
48616
|
+
return;
|
|
48485
48617
|
console.error('Got error while unsubscribing from query', ongoingQuery.query, e);
|
|
48486
48618
|
});
|
|
48487
48619
|
}
|
|
@@ -48544,7 +48676,7 @@ class QuerySubscriptionManager {
|
|
|
48544
48676
|
return result;
|
|
48545
48677
|
}
|
|
48546
48678
|
const alias = ongoingQuery.alias;
|
|
48547
|
-
result.push(ongoingQuery.dataSubject.pipe(filter(Boolean), map_map(
|
|
48679
|
+
result.push(ongoingQuery.dataSubject.pipe(filter(Boolean), map_map(docs => {
|
|
48548
48680
|
return { docs, alias };
|
|
48549
48681
|
})));
|
|
48550
48682
|
for (const supportedQuery of ongoingQuery.supportedQueries) {
|
|
@@ -48562,7 +48694,7 @@ class QuerySubscriptionManager {
|
|
|
48562
48694
|
}
|
|
48563
48695
|
return accum;
|
|
48564
48696
|
}, {});
|
|
48565
|
-
let result = aliasToDocs[rootOngoingQuery.alias].map(
|
|
48697
|
+
let result = aliasToDocs[rootOngoingQuery.alias].map(doc => ({
|
|
48566
48698
|
[rootOngoingQuery.alias]: doc,
|
|
48567
48699
|
}));
|
|
48568
48700
|
const ongoingQueriesInOrder = this.getOngoingQueriesBfs(rootOngoingQuery);
|
|
@@ -48586,17 +48718,17 @@ class QuerySubscriptionManager {
|
|
|
48586
48718
|
throw new Error('No join condition found for alias ' + rightAlias);
|
|
48587
48719
|
}
|
|
48588
48720
|
const rightAsMap = new Map();
|
|
48589
|
-
(rightDocs || []).forEach(
|
|
48721
|
+
(rightDocs || []).forEach(doc => {
|
|
48590
48722
|
const val = doc[joinCondition.right];
|
|
48591
48723
|
if (!rightAsMap.has(val))
|
|
48592
48724
|
rightAsMap.set(val, []);
|
|
48593
48725
|
(0,dist.truthy)(rightAsMap.get(val)).push(doc);
|
|
48594
48726
|
});
|
|
48595
|
-
return left.flatMap(
|
|
48727
|
+
return left.flatMap(leftElement => {
|
|
48596
48728
|
var _a;
|
|
48597
48729
|
const rightDocsWithSameValue = rightAsMap.get((_a = leftElement[joinCondition.leftAlias]) === null || _a === void 0 ? void 0 : _a[joinCondition.left]) || [];
|
|
48598
48730
|
if (rightDocsWithSameValue.length) {
|
|
48599
|
-
return rightDocsWithSameValue.map(
|
|
48731
|
+
return rightDocsWithSameValue.map(rightDoc => (Object.assign(Object.assign({}, leftElement), { [rightAlias]: rightDoc })));
|
|
48600
48732
|
}
|
|
48601
48733
|
else if (joinCondition.isInner) {
|
|
48602
48734
|
return [];
|
|
@@ -48623,7 +48755,7 @@ class QuerySubscriptionManager {
|
|
|
48623
48755
|
const joinCondition = (0,dist.truthy)(supportedOngoingQuery.joinCondition);
|
|
48624
48756
|
const query = supportedOngoingQuery.query;
|
|
48625
48757
|
if (!supportedOngoingQuery.activated) {
|
|
48626
|
-
const newConditions = supportingQueryResult.map(
|
|
48758
|
+
const newConditions = supportingQueryResult.map(supportingDoc => {
|
|
48627
48759
|
var _a;
|
|
48628
48760
|
return {
|
|
48629
48761
|
fieldName: joinCondition.right,
|
|
@@ -48643,13 +48775,13 @@ class QuerySubscriptionManager {
|
|
|
48643
48775
|
return true;
|
|
48644
48776
|
}
|
|
48645
48777
|
else {
|
|
48646
|
-
const supportedQueriesWithSameAlias = (0,dist.truthy)((_a = supportedOngoingQuery.supportingOngoingQuery) === null || _a === void 0 ? void 0 : _a.supportedQueries).filter(
|
|
48647
|
-
const allNeededValues = new Set(supportingQueryResult.map(
|
|
48778
|
+
const supportedQueriesWithSameAlias = (0,dist.truthy)((_a = supportedOngoingQuery.supportingOngoingQuery) === null || _a === void 0 ? void 0 : _a.supportedQueries).filter(q => q.alias === supportedOngoingQuery.alias);
|
|
48779
|
+
const allNeededValues = new Set(supportingQueryResult.map(resultDoc => { var _a; return (_a = resultDoc[joinCondition.left]) !== null && _a !== void 0 ? _a : null; }));
|
|
48648
48780
|
for (const supportedQuery of supportedQueriesWithSameAlias) {
|
|
48649
48781
|
supportedQuery.query.conditions
|
|
48650
48782
|
.filter(isSimpleCondition)
|
|
48651
|
-
.filter(
|
|
48652
|
-
.forEach(
|
|
48783
|
+
.filter(cond => cond.fieldName === joinCondition.right)
|
|
48784
|
+
.forEach(cond => {
|
|
48653
48785
|
allNeededValues.delete(cond.value);
|
|
48654
48786
|
});
|
|
48655
48787
|
}
|
|
@@ -48657,8 +48789,8 @@ class QuerySubscriptionManager {
|
|
|
48657
48789
|
return false;
|
|
48658
48790
|
}
|
|
48659
48791
|
const newQuery = lodash.cloneDeep(query);
|
|
48660
|
-
newQuery.conditions = newQuery.conditions.filter(
|
|
48661
|
-
[...allNeededValues].forEach(
|
|
48792
|
+
newQuery.conditions = newQuery.conditions.filter(cond => !isSimpleCondition(cond) || cond.fieldName !== joinCondition.right);
|
|
48793
|
+
[...allNeededValues].forEach(value => {
|
|
48662
48794
|
newQuery.conditions.push({
|
|
48663
48795
|
fieldName: joinCondition.right,
|
|
48664
48796
|
operator: '==',
|
|
@@ -48680,14 +48812,14 @@ class QuerySubscriptionManager {
|
|
|
48680
48812
|
return false;
|
|
48681
48813
|
if (!rootOngoingQuery.supportedQueries.length)
|
|
48682
48814
|
return true;
|
|
48683
|
-
return rootOngoingQuery.supportedQueries.every(
|
|
48815
|
+
return rootOngoingQuery.supportedQueries.every(ongoingQuery => this.allOngoingQueriesGotInitialResult(ongoingQuery));
|
|
48684
48816
|
}
|
|
48685
48817
|
async completeAllSupportedQueries(rootOngoingQuery) {
|
|
48686
48818
|
const supportedQueries = [...(rootOngoingQuery.supportedQueries || [])];
|
|
48687
48819
|
while (supportedQueries.length) {
|
|
48688
48820
|
const supportedQuery = (0,dist.truthy)(supportedQueries.shift());
|
|
48689
48821
|
supportedQueries.push(...(supportedQuery.supportedQueries || []));
|
|
48690
|
-
await (0,external_rxjs_namespaceObject.firstValueFrom)(supportedQuery.unsubscribeBlockerCount.pipe(filter(
|
|
48822
|
+
await (0,external_rxjs_namespaceObject.firstValueFrom)(supportedQuery.unsubscribeBlockerCount.pipe(filter(count => count === 0)));
|
|
48691
48823
|
supportedQuery.dataSubject.complete();
|
|
48692
48824
|
}
|
|
48693
48825
|
}
|
|
@@ -48744,8 +48876,14 @@ class QuerySubscriptionManager {
|
|
|
48744
48876
|
await (0,external_rxjs_namespaceObject.firstValueFrom)(parentOngoingQuery.queryRegistered.pipe(filter(Boolean)));
|
|
48745
48877
|
}
|
|
48746
48878
|
catch (e) {
|
|
48747
|
-
|
|
48748
|
-
|
|
48879
|
+
if (!this.destructManager.isDestructing) {
|
|
48880
|
+
ongoingQuery.dataSubject.error(e);
|
|
48881
|
+
ongoingQuery.queryRegistered.error(e);
|
|
48882
|
+
}
|
|
48883
|
+
else {
|
|
48884
|
+
ongoingQuery.dataSubject.complete();
|
|
48885
|
+
ongoingQuery.queryRegistered.complete();
|
|
48886
|
+
}
|
|
48749
48887
|
ongoingQuery.done = true;
|
|
48750
48888
|
return;
|
|
48751
48889
|
}
|
|
@@ -48757,16 +48895,22 @@ class QuerySubscriptionManager {
|
|
|
48757
48895
|
this.rpcManager
|
|
48758
48896
|
.post('query/register', queryRegisterRequest)
|
|
48759
48897
|
.then(() => {
|
|
48898
|
+
ongoingQuery.isInFlight = false;
|
|
48760
48899
|
ongoingQuery.queryRegistered.next(true);
|
|
48761
48900
|
})
|
|
48762
|
-
.catch(
|
|
48763
|
-
|
|
48764
|
-
|
|
48901
|
+
.catch(e => {
|
|
48902
|
+
ongoingQuery.isInFlight = false;
|
|
48903
|
+
if (!this.destructManager.isDestructing) {
|
|
48904
|
+
console.error('Query error', ongoingQuery.query, parentOngoingQuery.query, e);
|
|
48905
|
+
ongoingQuery.dataSubject.error(e);
|
|
48906
|
+
}
|
|
48907
|
+
else {
|
|
48908
|
+
ongoingQuery.dataSubject.complete();
|
|
48909
|
+
}
|
|
48765
48910
|
ongoingQuery.done = true;
|
|
48766
48911
|
})
|
|
48767
48912
|
.finally(() => {
|
|
48768
48913
|
parentOngoingQuery.unsubscribeBlockerCount.next(parentOngoingQuery.unsubscribeBlockerCount.value - 1);
|
|
48769
|
-
ongoingQuery.isInFlight = false;
|
|
48770
48914
|
});
|
|
48771
48915
|
const takeUntilNotifier = (0,external_rxjs_namespaceObject.race)(
|
|
48772
48916
|
/**
|
|
@@ -48782,15 +48926,22 @@ class QuerySubscriptionManager {
|
|
|
48782
48926
|
if (ongoingQuery.gotInitialResponse)
|
|
48783
48927
|
return;
|
|
48784
48928
|
this.setGotInitialResult(ongoingQuery.clientRequestId);
|
|
48785
|
-
}), map_map(
|
|
48929
|
+
}), map_map(documents => documents.filter(doc => queryContext.documentMatchesQuery(doc))))
|
|
48786
48930
|
.subscribe({
|
|
48787
|
-
next:
|
|
48931
|
+
next: results => {
|
|
48788
48932
|
for (const result of results) {
|
|
48789
48933
|
this.setClientRequestIdsForLocalDoc(getSquidDocId(result.__docId__, ongoingQuery.query.collectionName, ongoingQuery.query.integrationId), result);
|
|
48790
48934
|
}
|
|
48791
48935
|
this.notifyAllSubscriptions([ongoingQuery.clientRequestId]);
|
|
48792
48936
|
},
|
|
48793
|
-
error:
|
|
48937
|
+
error: e => {
|
|
48938
|
+
if (!this.destructManager.isDestructing) {
|
|
48939
|
+
ongoingQuery.dataSubject.error(e);
|
|
48940
|
+
}
|
|
48941
|
+
else {
|
|
48942
|
+
ongoingQuery.dataSubject.complete();
|
|
48943
|
+
}
|
|
48944
|
+
},
|
|
48794
48945
|
});
|
|
48795
48946
|
}
|
|
48796
48947
|
/**
|
|
@@ -48811,18 +48962,23 @@ class QuerySubscriptionManager {
|
|
|
48811
48962
|
ongoingQuery.isInFlight = true;
|
|
48812
48963
|
this.querySender
|
|
48813
48964
|
.sendQuery(queryRequest)
|
|
48814
|
-
.then(
|
|
48965
|
+
.then(queryResult => {
|
|
48966
|
+
ongoingQuery.isInFlight = false;
|
|
48815
48967
|
ongoingQuery.queryRegistered.next(true);
|
|
48816
48968
|
this.queryResultsSubject.next(queryResult);
|
|
48817
48969
|
})
|
|
48818
|
-
.catch(
|
|
48819
|
-
DebugLogger.debug('Query error', ongoingQuery.query, e);
|
|
48820
|
-
ongoingQuery.dataSubject.error(e);
|
|
48821
|
-
ongoingQuery.done = true;
|
|
48822
|
-
ongoingQuery.queryRegistered.error('query failed');
|
|
48823
|
-
})
|
|
48824
|
-
.finally(() => {
|
|
48970
|
+
.catch(e => {
|
|
48825
48971
|
ongoingQuery.isInFlight = false;
|
|
48972
|
+
if (!this.destructManager.isDestructing) {
|
|
48973
|
+
DebugLogger.debug('Query error', ongoingQuery.query, e);
|
|
48974
|
+
ongoingQuery.dataSubject.error(e);
|
|
48975
|
+
ongoingQuery.queryRegistered.error('query failed');
|
|
48976
|
+
}
|
|
48977
|
+
else {
|
|
48978
|
+
ongoingQuery.dataSubject.complete();
|
|
48979
|
+
ongoingQuery.queryRegistered.complete();
|
|
48980
|
+
}
|
|
48981
|
+
ongoingQuery.done = true;
|
|
48826
48982
|
});
|
|
48827
48983
|
}
|
|
48828
48984
|
/** naive way to refresh queries/subscriptions when we have a new client id */
|
|
@@ -48835,14 +48991,14 @@ class QuerySubscriptionManager {
|
|
|
48835
48991
|
migrateDocIds(idResolutionMap) {
|
|
48836
48992
|
const squidDocIds = Object.keys(idResolutionMap);
|
|
48837
48993
|
for (const set of this.clientRequestIdToLocalDocuments.values()) {
|
|
48838
|
-
squidDocIds.forEach(
|
|
48994
|
+
squidDocIds.forEach(key => {
|
|
48839
48995
|
if (set.has(key)) {
|
|
48840
48996
|
set.delete(key);
|
|
48841
48997
|
set.add(idResolutionMap[key]);
|
|
48842
48998
|
}
|
|
48843
48999
|
});
|
|
48844
49000
|
}
|
|
48845
|
-
squidDocIds.forEach(
|
|
49001
|
+
squidDocIds.forEach(key => {
|
|
48846
49002
|
replaceKeyInMap(this.localDocumentToClientRequestIds, key, idResolutionMap[key]);
|
|
48847
49003
|
});
|
|
48848
49004
|
}
|
|
@@ -49061,7 +49217,7 @@ class RpcManager {
|
|
|
49061
49217
|
if (apiKey) {
|
|
49062
49218
|
this.setStaticHeader('Authorization', `ApiKey ${apiKey}`);
|
|
49063
49219
|
}
|
|
49064
|
-
this.clientIdService.observeClientId().subscribe(
|
|
49220
|
+
this.clientIdService.observeClientId().subscribe(clientId => {
|
|
49065
49221
|
if (clientId) {
|
|
49066
49222
|
this.setStaticHeader('x-squid-clientid', clientId);
|
|
49067
49223
|
}
|
|
@@ -49069,18 +49225,6 @@ class RpcManager {
|
|
|
49069
49225
|
this.deleteStaticHeader('x-squid-clientid');
|
|
49070
49226
|
}
|
|
49071
49227
|
});
|
|
49072
|
-
this.authManager.observeAuthIdToken().subscribe((authData) => {
|
|
49073
|
-
if (authData.token) {
|
|
49074
|
-
let header = `Bearer ${authData.token}`;
|
|
49075
|
-
if (authData.integrationId) {
|
|
49076
|
-
header += `; IntegrationId ${authData.integrationId}`;
|
|
49077
|
-
}
|
|
49078
|
-
this.setStaticHeader('Authorization', header);
|
|
49079
|
-
}
|
|
49080
|
-
else {
|
|
49081
|
-
this.deleteStaticHeader('Authorization');
|
|
49082
|
-
}
|
|
49083
|
-
});
|
|
49084
49228
|
destructManager.onDestruct(async () => {
|
|
49085
49229
|
await this.awaitAllSettled();
|
|
49086
49230
|
});
|
|
@@ -49091,8 +49235,18 @@ class RpcManager {
|
|
|
49091
49235
|
secret: new RateLimiter(20 * rateLimiterMultiplier, 5),
|
|
49092
49236
|
};
|
|
49093
49237
|
}
|
|
49238
|
+
async getAuthHeaders() {
|
|
49239
|
+
const { token, integrationId } = await this.authManager.getAuthData();
|
|
49240
|
+
if (!token)
|
|
49241
|
+
return {};
|
|
49242
|
+
let header = `Bearer ${token}`;
|
|
49243
|
+
if (integrationId) {
|
|
49244
|
+
header += `; IntegrationId ${integrationId}`;
|
|
49245
|
+
}
|
|
49246
|
+
return { Authorization: header };
|
|
49247
|
+
}
|
|
49094
49248
|
async awaitAllSettled() {
|
|
49095
|
-
await (0,external_rxjs_namespaceObject.firstValueFrom)(this.onGoingRpcCounter.pipe((0,external_rxjs_namespaceObject.filter)(
|
|
49249
|
+
await (0,external_rxjs_namespaceObject.firstValueFrom)(this.onGoingRpcCounter.pipe((0,external_rxjs_namespaceObject.filter)(value => value === 0)));
|
|
49096
49250
|
}
|
|
49097
49251
|
setStaticHeader(key, value) {
|
|
49098
49252
|
this.staticHeaders[key] = value;
|
|
@@ -49103,24 +49257,22 @@ class RpcManager {
|
|
|
49103
49257
|
getStaticHeaders() {
|
|
49104
49258
|
return this.staticHeaders;
|
|
49105
49259
|
}
|
|
49106
|
-
async ready() {
|
|
49107
|
-
await this.authManager.waitForReadyState();
|
|
49108
|
-
}
|
|
49109
49260
|
async post(path, message, files = []) {
|
|
49110
49261
|
this.onGoingRpcCounter.next(this.onGoingRpcCounter.value + 1);
|
|
49111
49262
|
try {
|
|
49112
49263
|
await this.getRateLimiterBucket(path).consume();
|
|
49113
|
-
await (0,external_rxjs_namespaceObject.firstValueFrom)((0,external_rxjs_namespaceObject.from)(this.ready()).pipe((0,external_rxjs_namespaceObject.timeout)(20000)));
|
|
49114
49264
|
let headers = {};
|
|
49115
49265
|
if (Object.keys(this.staticHeaders)) {
|
|
49116
49266
|
headers = Object.assign(Object.assign({}, headers), this.staticHeaders);
|
|
49117
49267
|
}
|
|
49268
|
+
const authHeaders = await this.getAuthHeaders();
|
|
49269
|
+
headers = Object.assign(Object.assign({}, headers), authHeaders);
|
|
49118
49270
|
DebugLogger.debug(`sending request: path: ${path} message: ${JSON.stringify(message)}`);
|
|
49119
49271
|
const url = getApplicationUrl(this.region, this.appId, path);
|
|
49120
49272
|
let response;
|
|
49121
49273
|
if (files.length) {
|
|
49122
49274
|
const formData = new FormData();
|
|
49123
|
-
files.forEach(
|
|
49275
|
+
files.forEach(file => {
|
|
49124
49276
|
formData.append('files', file);
|
|
49125
49277
|
});
|
|
49126
49278
|
formData.append('body', serialization_serializeObj(message));
|
|
@@ -49202,7 +49354,7 @@ class SecretClient {
|
|
|
49202
49354
|
return this.rpcManager.post('/secret/getAll', {});
|
|
49203
49355
|
}
|
|
49204
49356
|
upsert(key, value) {
|
|
49205
|
-
return this.upsertMany([{ key, value }]).then(
|
|
49357
|
+
return this.upsertMany([{ key, value }]).then(entries => entries[0]);
|
|
49206
49358
|
}
|
|
49207
49359
|
upsertMany(entries) {
|
|
49208
49360
|
const request = { entries };
|
|
@@ -49279,25 +49431,47 @@ class SocketManager {
|
|
|
49279
49431
|
});
|
|
49280
49432
|
this.setupMessageAcknowledgments();
|
|
49281
49433
|
this.connect();
|
|
49282
|
-
this.
|
|
49283
|
-
|
|
49434
|
+
this.lastTick = new Date();
|
|
49435
|
+
this.tickInterval = setInterval(() => this.tick(), 5000);
|
|
49436
|
+
this.observeConnectionReady()
|
|
49437
|
+
.pipe((0,external_rxjs_namespaceObject.skip)(1), (0,external_rxjs_namespaceObject.filter)(v => !v), (0,external_rxjs_namespaceObject.switchMap)(() => {
|
|
49284
49438
|
return (0,external_rxjs_namespaceObject.race)((0,external_rxjs_namespaceObject.timer)(this.clientTooOldThreshold), this.connectionReady.pipe((0,external_rxjs_namespaceObject.filter)(Boolean)), this.destructManager.observeIsDestructing());
|
|
49285
49439
|
}))
|
|
49286
49440
|
.subscribe(() => {
|
|
49287
|
-
if (this.connectionReady.value
|
|
49288
|
-
DebugLogger.debug('Client
|
|
49441
|
+
if (this.connectionReady.value) {
|
|
49442
|
+
DebugLogger.debug('Client reconnected before becoming too old. Ignoring...');
|
|
49289
49443
|
return;
|
|
49290
49444
|
}
|
|
49291
|
-
this.
|
|
49292
|
-
DebugLogger.debug('Client too old. Reconnecting...');
|
|
49293
|
-
this.connect();
|
|
49445
|
+
this.refreshClient();
|
|
49294
49446
|
});
|
|
49295
|
-
this.
|
|
49447
|
+
this.observeConnectionReady()
|
|
49448
|
+
.pipe((0,external_rxjs_namespaceObject.filter)(Boolean))
|
|
49449
|
+
.subscribe(() => {
|
|
49296
49450
|
if (this.clientIdService.isClientTooOld()) {
|
|
49297
49451
|
this.clientIdService.notifyClientReadyToBeRegenerated();
|
|
49298
49452
|
}
|
|
49299
49453
|
});
|
|
49300
49454
|
}
|
|
49455
|
+
refreshClient() {
|
|
49456
|
+
if (this.destructManager.isDestructing) {
|
|
49457
|
+
DebugLogger.debug('Client too old but is destructed. Ignoring...');
|
|
49458
|
+
return;
|
|
49459
|
+
}
|
|
49460
|
+
else if (this.clientIdService.isClientTooOld()) {
|
|
49461
|
+
DebugLogger.debug('Client is already marked as too old. Ignoring...');
|
|
49462
|
+
return;
|
|
49463
|
+
}
|
|
49464
|
+
this.clientIdService.notifyClientTooOld();
|
|
49465
|
+
DebugLogger.debug('Client too old. Reconnecting...');
|
|
49466
|
+
this.connect();
|
|
49467
|
+
}
|
|
49468
|
+
tick() {
|
|
49469
|
+
const diff = Math.abs(Date.now() - this.lastTick.getTime());
|
|
49470
|
+
if (diff > this.clientTooOldThreshold) {
|
|
49471
|
+
this.refreshClient();
|
|
49472
|
+
}
|
|
49473
|
+
this.lastTick = new Date();
|
|
49474
|
+
}
|
|
49301
49475
|
observeNotifications() {
|
|
49302
49476
|
return this.webSocketObserver.asObservable();
|
|
49303
49477
|
}
|
|
@@ -49305,12 +49479,39 @@ class SocketManager {
|
|
|
49305
49479
|
return this.connectionReady.asObservable().pipe((0,external_rxjs_namespaceObject.distinctUntilChanged)());
|
|
49306
49480
|
}
|
|
49307
49481
|
sendMessage(message) {
|
|
49308
|
-
this.
|
|
49309
|
-
|
|
49310
|
-
|
|
49311
|
-
|
|
49312
|
-
|
|
49313
|
-
|
|
49482
|
+
this.sendMessageAsync(message).then();
|
|
49483
|
+
}
|
|
49484
|
+
async sendMessageAsync(message) {
|
|
49485
|
+
var _a;
|
|
49486
|
+
await (0,external_rxjs_namespaceObject.firstValueFrom)(this.connectionReady.pipe((0,external_rxjs_namespaceObject.filter)(Boolean)));
|
|
49487
|
+
const authToken = await this.authManager.getToken();
|
|
49488
|
+
if (!this.connectionReady.value) {
|
|
49489
|
+
// Connection state was changed during `await this.authManager.getToken()` call. Retry.
|
|
49490
|
+
await this.sendMessageAsync(message);
|
|
49491
|
+
return;
|
|
49492
|
+
}
|
|
49493
|
+
try {
|
|
49494
|
+
(0,dist.assertTruthy)(this.socket, 'Socket is undefined in sendMessageAsync');
|
|
49495
|
+
this.socket.send(serialization_serializeObj({ message, authToken }));
|
|
49496
|
+
}
|
|
49497
|
+
catch (e) {
|
|
49498
|
+
if (!((_a = this.socket) === null || _a === void 0 ? void 0 : _a.connected)) {
|
|
49499
|
+
// Message sending is failed due to the websocket IO error. Retry.
|
|
49500
|
+
this.connectionReady.next(false);
|
|
49501
|
+
await this.sendMessageAsync(message);
|
|
49502
|
+
}
|
|
49503
|
+
else {
|
|
49504
|
+
console.error('Websocket message is ignored due to a non-recoverable error', e);
|
|
49505
|
+
}
|
|
49506
|
+
}
|
|
49507
|
+
}
|
|
49508
|
+
/** Sends 'kill' message ignoring 'connectionReady' observable. */
|
|
49509
|
+
sendKillMessage() {
|
|
49510
|
+
var _a;
|
|
49511
|
+
if (!((_a = this.socket) === null || _a === void 0 ? void 0 : _a.connected))
|
|
49512
|
+
return;
|
|
49513
|
+
const message = { type: 'kill' };
|
|
49514
|
+
this.socket.send(serialization_serializeObj({ message }));
|
|
49314
49515
|
}
|
|
49315
49516
|
connect() {
|
|
49316
49517
|
var _a;
|
|
@@ -49337,6 +49538,11 @@ class SocketManager {
|
|
|
49337
49538
|
onerror: (e) => console.error('WebSocket error:', e),
|
|
49338
49539
|
});
|
|
49339
49540
|
}
|
|
49541
|
+
disconnect() {
|
|
49542
|
+
var _a;
|
|
49543
|
+
this.connectionReady.next(false);
|
|
49544
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.close(4998);
|
|
49545
|
+
}
|
|
49340
49546
|
onConnectionReady() {
|
|
49341
49547
|
this.connectionReady.next(true);
|
|
49342
49548
|
this.sendMessage({ type: 'catchup' });
|
|
@@ -49369,7 +49575,7 @@ class SocketManager {
|
|
|
49369
49575
|
});
|
|
49370
49576
|
const collectedMessageIds = [];
|
|
49371
49577
|
ackSubject
|
|
49372
|
-
.pipe((0,external_rxjs_namespaceObject.tap)(
|
|
49578
|
+
.pipe((0,external_rxjs_namespaceObject.tap)(messageId => collectedMessageIds.push(messageId)), (0,external_rxjs_namespaceObject.debounceTime)(100))
|
|
49373
49579
|
.subscribe(async () => {
|
|
49374
49580
|
const messageIds = [...collectedMessageIds.splice(0)];
|
|
49375
49581
|
this.sendMessage({ type: 'acknowledge', payload: messageIds });
|
|
@@ -49377,10 +49583,15 @@ class SocketManager {
|
|
|
49377
49583
|
}
|
|
49378
49584
|
async destruct() {
|
|
49379
49585
|
var _a;
|
|
49380
|
-
this.
|
|
49586
|
+
this.sendKillMessage();
|
|
49587
|
+
// Wait until VM processes socket message before closing the socket.
|
|
49588
|
+
// Without the sleep below, there is a race condition between socket closing
|
|
49589
|
+
// and 'kill' message sending, so 'kill' may not be delivered at all.
|
|
49590
|
+
await (0,external_rxjs_namespaceObject.firstValueFrom)((0,external_rxjs_namespaceObject.timer)(0));
|
|
49381
49591
|
this.connectionReady.next(false);
|
|
49382
49592
|
// Allow the message to be sent by waiting on a 0 timer.
|
|
49383
49593
|
await (0,external_rxjs_namespaceObject.firstValueFrom)((0,external_rxjs_namespaceObject.timer)(0));
|
|
49594
|
+
clearInterval(this.tickInterval);
|
|
49384
49595
|
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
|
|
49385
49596
|
this.webSocketObserver.complete();
|
|
49386
49597
|
this.allMessagesObserver.complete();
|
|
@@ -49454,7 +49665,7 @@ class QuerySender {
|
|
|
49454
49665
|
}
|
|
49455
49666
|
}
|
|
49456
49667
|
catch (e) {
|
|
49457
|
-
responseSubjects.forEach(
|
|
49668
|
+
responseSubjects.forEach(responseSubject => responseSubject.error(e));
|
|
49458
49669
|
}
|
|
49459
49670
|
finally {
|
|
49460
49671
|
this.inflightQueriesCount.next(this.inflightQueriesCount.value - pendingQueryRequests.length);
|
|
@@ -49462,7 +49673,7 @@ class QuerySender {
|
|
|
49462
49673
|
}
|
|
49463
49674
|
/** Will resolve once all the in-flight queries are done. */
|
|
49464
49675
|
async waitForAllQueriesToFinish() {
|
|
49465
|
-
return (0,external_rxjs_namespaceObject.firstValueFrom)(this.inflightQueriesCount.pipe(filter(
|
|
49676
|
+
return (0,external_rxjs_namespaceObject.firstValueFrom)(this.inflightQueriesCount.pipe(filter(count => count === 0))).then(() => {
|
|
49466
49677
|
return undefined;
|
|
49467
49678
|
});
|
|
49468
49679
|
}
|
|
@@ -49472,6 +49683,17 @@ class QuerySender {
|
|
|
49472
49683
|
}
|
|
49473
49684
|
}
|
|
49474
49685
|
|
|
49686
|
+
;// CONCATENATED MODULE: ./src/native-query-manager.ts
|
|
49687
|
+
class NativeQueryManager {
|
|
49688
|
+
constructor(rpcManager) {
|
|
49689
|
+
this.rpcManager = rpcManager;
|
|
49690
|
+
}
|
|
49691
|
+
async executeNativeQuery(integrationId, request) {
|
|
49692
|
+
const executeRequest = Object.assign({ integrationId }, request);
|
|
49693
|
+
return this.rpcManager.post('native-query/execute', executeRequest);
|
|
49694
|
+
}
|
|
49695
|
+
}
|
|
49696
|
+
|
|
49475
49697
|
;// CONCATENATED MODULE: ./src/squid.ts
|
|
49476
49698
|
|
|
49477
49699
|
|
|
@@ -49497,6 +49719,7 @@ class QuerySender {
|
|
|
49497
49719
|
|
|
49498
49720
|
|
|
49499
49721
|
|
|
49722
|
+
|
|
49500
49723
|
|
|
49501
49724
|
|
|
49502
49725
|
/**
|
|
@@ -49517,16 +49740,19 @@ class Squid {
|
|
|
49517
49740
|
// Note: The following methods are bound using arrow functions to ensure that if a user accesses the methods via
|
|
49518
49741
|
// destructuring (i.e. `{ setAuthIdToken } = squid`) then `this` will still be bound to the Squid class.
|
|
49519
49742
|
/**
|
|
49520
|
-
* Sets the
|
|
49521
|
-
* to the security rules.
|
|
49743
|
+
* Sets the authorization access token (OAuth2.0) that will be sent to the server and will be used for providing the
|
|
49744
|
+
* `auth` object to the security rules.
|
|
49745
|
+
*
|
|
49746
|
+
* @deprecated: pass `AuthTokenProvider` in the constructor of the class.
|
|
49522
49747
|
*
|
|
49523
|
-
* @param
|
|
49524
|
-
*
|
|
49748
|
+
* @param accessToken The OAuth2.0 access token or a promise that resolves with the access token.
|
|
49749
|
+
* When undefined, no authorization information is sent.
|
|
49750
|
+
* The Observable variant of the parameter is deprecated and will be removed soon.
|
|
49525
49751
|
* @param integrationId The id of the integration.
|
|
49526
49752
|
* @returns void
|
|
49527
49753
|
*/
|
|
49528
|
-
this.setAuthIdToken = (
|
|
49529
|
-
this.authManager.setAuthIdToken(
|
|
49754
|
+
this.setAuthIdToken = (accessToken, integrationId) => {
|
|
49755
|
+
this.authManager.setAuthIdToken(accessToken, integrationId);
|
|
49530
49756
|
};
|
|
49531
49757
|
/**
|
|
49532
49758
|
* Returns a reference to the collection in the provided integration.
|
|
@@ -49592,6 +49818,22 @@ class Squid {
|
|
|
49592
49818
|
this.validateNotDestructed();
|
|
49593
49819
|
return (0,external_rxjs_namespaceObject.firstValueFrom)(this.namedQueryManager.executeNamedQueryAndSubscribe(integrationId, queryName, params));
|
|
49594
49820
|
};
|
|
49821
|
+
/**
|
|
49822
|
+
* Executes a native relational query with the given parameters and returns a promise with the result.
|
|
49823
|
+
*
|
|
49824
|
+
* Native queries allow you to execute raw SQL or other database-specific queries directly against the database.
|
|
49825
|
+
* This can be useful when you need to perform operations that are not easily accomplished with named queries or
|
|
49826
|
+
* other high-level abstractions.
|
|
49827
|
+
*
|
|
49828
|
+
* @param integrationId The id of the integration that the query is associated with.
|
|
49829
|
+
* @param query The raw SQL or other database-specific query to execute.
|
|
49830
|
+
* @param params (Optional) The parameters to pass to the query. Defaults to an empty object.
|
|
49831
|
+
* @returns A promise that resolves with the result of the query.
|
|
49832
|
+
* @type {Promise<Array<SquidDocument>>}
|
|
49833
|
+
*/
|
|
49834
|
+
this.executeNativeRelationalQuery = (integrationId, query, params = {}) => {
|
|
49835
|
+
return this.nativeQueryManager.executeNativeQuery(integrationId, { type: 'relational', query, params });
|
|
49836
|
+
};
|
|
49595
49837
|
/**
|
|
49596
49838
|
* Invokes the given HTTP API (defined by the integration ID and the endpoint ID) with the given request parameters
|
|
49597
49839
|
* and returns a promise with the response. The structure of the request and the response is defined in the
|
|
@@ -49632,6 +49874,10 @@ class Squid {
|
|
|
49632
49874
|
this.validateNotDestructed();
|
|
49633
49875
|
return {
|
|
49634
49876
|
assistant: (integrationId) => this.aiClientFactory.getAssistant(integrationId),
|
|
49877
|
+
executeAiQuery: (integrationId, prompt) => {
|
|
49878
|
+
const req = { integrationId, prompt };
|
|
49879
|
+
return this.rpcManager.post('aiData/executeAiQuery', req);
|
|
49880
|
+
},
|
|
49635
49881
|
};
|
|
49636
49882
|
};
|
|
49637
49883
|
/**
|
|
@@ -49679,7 +49925,7 @@ class Squid {
|
|
|
49679
49925
|
const appId = appIdWithEnvironmentIdAndDevId(options.appId, options.environmentId, shouldAddDeveloperId ? options.squidDeveloperId : undefined);
|
|
49680
49926
|
const httpHeaders = getApplicationHttpHeaders(options.region, appId);
|
|
49681
49927
|
this.clientIdService = new ClientIdService(this.destructManager);
|
|
49682
|
-
this.authManager = new AuthManager(
|
|
49928
|
+
this.authManager = new AuthManager(options.apiKey, options.authTokenProvider);
|
|
49683
49929
|
this.socketManager = new SocketManager(this.clientIdService, options.region, appId, options.messageNotificationWrapper, this.destructManager, this.authManager);
|
|
49684
49930
|
this.rpcManager = new RpcManager(options.region, appId, this.destructManager, httpHeaders, this.authManager, this.clientIdService);
|
|
49685
49931
|
this.documentStore = new DocumentStore();
|
|
@@ -49697,6 +49943,7 @@ class Squid {
|
|
|
49697
49943
|
this.documentReferenceFactory.setDataManager(this.dataManager);
|
|
49698
49944
|
this.backendFunctionManager = new BackendFunctionManager(this.clientIdService, this.rpcManager);
|
|
49699
49945
|
this.namedQueryManager = new NamedQueryManager(this.rpcManager, this.socketManager);
|
|
49946
|
+
this.nativeQueryManager = new NativeQueryManager(this.rpcManager);
|
|
49700
49947
|
this.apiManager = new ApiManager(this.clientIdService, this.rpcManager, options.apiServerUrlOverrideMapping);
|
|
49701
49948
|
this.graphqlClientFactory = new GraphQLClientFactory(this.rpcManager, options.region, appId);
|
|
49702
49949
|
this.aiClientFactory = new AiClientFactory(this.rpcManager, this.socketManager);
|