@squidcloud/client 1.0.98 → 1.0.99

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.
Files changed (103) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/common/src/ai-assistant.context.d.ts +12 -12
  3. package/dist/common/src/ai-assistant.schemas.d.ts +1 -1
  4. package/dist/common/src/ai-assistant.types.d.ts +12 -12
  5. package/dist/common/src/api-call.context.d.ts +13 -13
  6. package/dist/common/src/api.types.d.ts +4 -4
  7. package/dist/common/src/application.schemas.d.ts +1 -1
  8. package/dist/common/src/application.types.d.ts +184 -184
  9. package/dist/common/src/backend-function.schemas.d.ts +1 -1
  10. package/dist/common/src/backend-function.types.d.ts +1 -1
  11. package/dist/common/src/backend-run.types.d.ts +2 -2
  12. package/dist/common/src/bundle-api.types.d.ts +36 -36
  13. package/dist/common/src/bundle-data.types.d.ts +4 -4
  14. package/dist/common/src/communication.types.d.ts +12 -12
  15. package/dist/common/src/context.types.d.ts +40 -40
  16. package/dist/common/src/distributed-lock.context.d.ts +5 -5
  17. package/dist/common/src/document.types.d.ts +22 -22
  18. package/dist/common/src/graphql.context.d.ts +7 -7
  19. package/dist/common/src/graphql.types.d.ts +9 -9
  20. package/dist/common/src/heartbeat.types.d.ts +1 -1
  21. package/dist/common/src/http-status.enum.d.ts +50 -50
  22. package/dist/common/src/index.d.ts +53 -53
  23. package/dist/common/src/integrations/ai_assistant.types.d.ts +30 -30
  24. package/dist/common/src/integrations/api.types.d.ts +80 -80
  25. package/dist/common/src/integrations/auth.types.d.ts +39 -39
  26. package/dist/common/src/integrations/database.types.d.ts +236 -236
  27. package/dist/common/src/integrations/index.d.ts +101 -101
  28. package/dist/common/src/integrations/observability.types.d.ts +23 -23
  29. package/dist/common/src/logger.types.d.ts +21 -21
  30. package/dist/common/src/metrics.types.d.ts +1 -1
  31. package/dist/common/src/mutation.context.d.ts +14 -14
  32. package/dist/common/src/mutation.schemas.d.ts +1 -1
  33. package/dist/common/src/mutation.types.d.ts +53 -53
  34. package/dist/common/src/named-query.context.d.ts +4 -4
  35. package/dist/common/src/named-query.schemas.d.ts +1 -1
  36. package/dist/common/src/named-query.types.d.ts +1 -1
  37. package/dist/common/src/query/base-query-builder.d.ts +196 -196
  38. package/dist/common/src/query/index.d.ts +3 -3
  39. package/dist/common/src/query/query-context.d.ts +137 -137
  40. package/dist/common/src/query/serialized-query.types.d.ts +24 -24
  41. package/dist/common/src/query.types.d.ts +59 -59
  42. package/dist/common/src/regions.d.ts +1 -1
  43. package/dist/common/src/schema/schema.types.d.ts +54 -54
  44. package/dist/common/src/secret.schemas.d.ts +1 -1
  45. package/dist/common/src/secret.types.d.ts +8 -8
  46. package/dist/common/src/security.types.d.ts +1 -1
  47. package/dist/common/src/socket.schemas.d.ts +1 -1
  48. package/dist/common/src/socket.types.d.ts +1 -1
  49. package/dist/common/src/time-units.d.ts +1 -1
  50. package/dist/common/src/trigger.types.d.ts +1 -1
  51. package/dist/common/src/types.d.ts +14 -14
  52. package/dist/common/src/utils/array.d.ts +1 -1
  53. package/dist/common/src/utils/assert.d.ts +1 -1
  54. package/dist/common/src/utils/error.d.ts +4 -4
  55. package/dist/common/src/utils/http.d.ts +2 -2
  56. package/dist/common/src/utils/id.d.ts +2 -2
  57. package/dist/common/src/utils/lock.manager.d.ts +14 -14
  58. package/dist/common/src/utils/nullish.d.ts +2 -2
  59. package/dist/common/src/utils/object.d.ts +5 -5
  60. package/dist/common/src/utils/serialization.d.ts +6 -6
  61. package/dist/common/src/utils/transforms.d.ts +18 -18
  62. package/dist/common/src/utils/url.d.ts +1 -1
  63. package/dist/common/src/utils/validation.d.ts +30 -30
  64. package/dist/common/src/webhook-response.d.ts +1 -1
  65. package/dist/esm/index.js +1 -1
  66. package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +1239 -1239
  67. package/dist/typescript-client/src/ai-assistant-client.d.ts +167 -167
  68. package/dist/typescript-client/src/ai-client.factory.d.ts +11 -11
  69. package/dist/typescript-client/src/api.manager.d.ts +15 -15
  70. package/dist/typescript-client/src/auth.manager.d.ts +23 -23
  71. package/dist/typescript-client/src/backend-function.manager.d.ts +13 -13
  72. package/dist/typescript-client/src/client-id.service.d.ts +25 -25
  73. package/dist/typescript-client/src/collection-reference.d.ts +81 -81
  74. package/dist/typescript-client/src/collection-reference.factory.d.ts +13 -13
  75. package/dist/typescript-client/src/connection-details.d.ts +23 -23
  76. package/dist/typescript-client/src/data.manager.d.ts +172 -172
  77. package/dist/typescript-client/src/destruct.manager.d.ts +12 -12
  78. package/dist/typescript-client/src/distributed-lock.manager.d.ts +19 -19
  79. package/dist/typescript-client/src/document-identity.service.d.ts +12 -12
  80. package/dist/typescript-client/src/document-reference.d.ts +140 -140
  81. package/dist/typescript-client/src/document-reference.factory.d.ts +13 -13
  82. package/dist/typescript-client/src/document-store.d.ts +11 -11
  83. package/dist/typescript-client/src/graphql-client.d.ts +14 -14
  84. package/dist/typescript-client/src/graphql-client.factory.d.ts +11 -11
  85. package/dist/typescript-client/src/index.d.ts +8 -8
  86. package/dist/typescript-client/src/mutation/mutation-sender.d.ts +10 -10
  87. package/dist/typescript-client/src/named-query.manager.d.ts +12 -12
  88. package/dist/typescript-client/src/query/deserializer.d.ts +3 -3
  89. package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +161 -161
  90. package/dist/typescript-client/src/query/local-query-manager.d.ts +9 -9
  91. package/dist/typescript-client/src/query/query-builder.factory.d.ts +76 -76
  92. package/dist/typescript-client/src/query/query-subscription.manager.d.ts +170 -170
  93. package/dist/typescript-client/src/rpc.manager.d.ts +29 -29
  94. package/dist/typescript-client/src/socket.manager.d.ts +33 -33
  95. package/dist/typescript-client/src/squid.d.ts +218 -218
  96. package/dist/typescript-client/src/state/action.applier.d.ts +7 -7
  97. package/dist/typescript-client/src/state/actions.d.ts +29 -29
  98. package/dist/typescript-client/src/state/path_trie.d.ts +27 -27
  99. package/dist/typescript-client/src/state/state.service.d.ts +22 -22
  100. package/dist/typescript-client/src/state/state.service.spec.d.ts +1 -1
  101. package/dist/typescript-client/src/testing/setup-tests.d.ts +1 -1
  102. package/dist/typescript-client/src/types.d.ts +2 -2
  103. package/package.json +1 -1
package/dist/cjs/index.js CHANGED
@@ -9,4 +9,4 @@
9
9
  ${e.query}
10
10
  `,variables:e.variables})).data}async mutate(e){return(await this.client.mutate({mutation:Sa`
11
11
  ${e.query}
12
- `})).data}}class xa{constructor(e,t,r){this.rpcManager=e,this.region=t,this.appId=r,this.clientsMap=new Map}get(e){let t=this.clientsMap.get(e);return t||(t=new Na(this.rpcManager,e,this.region,this.appId),this.clientsMap.set(e,t),t)}}class Aa{constructor(e,t,r){this.rpcManager=e,this.lockManager=t,this.querySubscriptionManager=r}async sendMutations(e,t){const r=Q(e),n=r.map((e=>`sendMutation_${F(e.squidDocIdObj)}`));await this.lockManager.lock(...n),await this.querySubscriptionManager.waitForAllQueriesToFinish();try{const e={mutations:r,integrationId:t};return await this.rpcManager.post("mutation/mutate",e)}finally{this.lockManager.release(...n)}}}class Ra{constructor(e,t){this.rpcManager=e,this.socketManager=t,this.ongoingNamedQueryExecutions={},t.observeNotifications().pipe((0,b.filter)((e=>"namedQuery"===e.type)),qe((e=>e))).subscribe((e=>{this.handleNamedQueryResponse(e.clientRequestId,e.payload)}))}executeNamedQueryAndSubscribe(e,t,r){const n=te(),i=new b.Subject;this.ongoingNamedQueryExecutions[n]=i;const o={integrationId:e,queryName:t,paramsRecordStr:u(r),clientRequestId:n};return this.rpcManager.post("named-query/execute",o).catch((r=>{console.error("Got error while executing named query",t,"for integration",e,r),i.error(r),i.complete()})),i.pipe((0,b.finalize)((()=>{delete this.ongoingNamedQueryExecutions[n]})),(0,b.share)())}handleNamedQueryResponse(e,t){const r=this.ongoingNamedQueryExecutions[e];if(!r)return;const n=l(t);n.success?r.next(n.result):(r.error(new Error(n.result)),r.complete())}}class Pa{constructor(e,t,r){this.documentStore=e,this.documentReferenceFactory=t,this.querySubscriptionManager=r}peek(e){if(!this.querySubscriptionManager.findValidParentOfQuery(e))return[];const{integrationId:t,collectionName:r}=e,n=new g(e),i=this.documentReferenceFactory.getDocumentsForCollection(t,r).filter((e=>n.documentMatchesQuery(e.data))),o={};return i.forEach((e=>{o[e.squidDocId]=e})),this.documentStore.sortAndLimitDocs(new Set(Object.keys(o)),e).map((e=>o[F(e.__docId__,r,t)]))}}function ja(e,t){return oe((function(r,n){var i=0;r.subscribe(Me(n,(function(r){return e.call(t,r,i++)&&n.next(r)})))}))}function Ca(e){return[ka.SET_PATH,ka.DELETE_PATH].includes(e.type)}function $a(e){return e.type===ka.BATCH_ACTION}function Ma(e){const t=[];if(Ca(e))t.push(e);else if($a(e))for(const r of e.payload)t.push(...Ma(r));return t}function Fa(e,t){return La(e,t)}function qa(e){return"object"==typeof e}function La(e,t){let r=e;if(Ca(t))r=function(e,t,r=[]){switch(t.type){case ka.DELETE_PATH:return Va(e,t.path);case ka.SET_PATH:const n=t;return function(e,t,r,n){return Qa(e,t,r,n)}(e,t.path,r,n.payload);case ka.BATCH_ACTION:throw new Error("Unsupported")}}(e,t,[]);else{if(!$a(t))throw new Error(`Invalid action type: ${t.type}`);r=t.payload.reduce(((e,t)=>La(e,t)),e)}return r}function Va(e,t){if(!t.length)throw new Error("can not delete an empty path");const r=t[0];if(1===t.length)return function(e,t){if(e instanceof Array)throw new Error("Cannot remove an item from an array");const r=Object.assign({},e);return delete r[t],r}(e,r);const n=t.slice(1),i=Ba(e,r);if(!i)return e;if(!qa(i))throw new Error("Cannot delete from a non object state.");const o=Va(i,n);return o===i?e:Ua(e,r,o)}function Qa(e,t,r,n){if(!t.length){if(qa(n))return n;throw new Error("Relative path cannot be of length 0 when the new value is not an object.")}const i=t[0],o=[...r,i];if(1===t.length)return Ua(e,i,n);const s=t.slice(1),a=Ba(e,i);return void 0!==a&&qa(a)?Ua(e,i,Qa(a,s,o,n)):Qa(e=Ua(e,i,{}),t,r,n)}function Ua(e,t,r){return(e=Object.assign({},e))[t]=r,e}function Ba(e,t){return e instanceof Array?e[function(e){const t=Number(e);if(isNaN(t))throw new Error(`The value is not a number: Actual: ${e}`);return Math.floor(t)}(t)]:e[t]}!function(e){e.DELETE_PATH="DELETE_PATH",e.SET_PATH="SET_PATH",e.BATCH_ACTION="BATCH_ACTION"}(ka||(ka={}));class za{constructor(){this.root=new Ya}getOrCreatePathTrieNode(e,t){let r=this.root;for(const t of e)r.children.get(t)||r.children.set(t,new Ya),r=r.children.get(t);return void 0!==t&&(r.nodeData=t),r}getPathTrieNode(e){let t=this.root;for(const r of e){if(!t)return;t=t.children.get(r)}return t}getPathTrie(e){let t=this.root;for(const r of e){if(!t)return;t=t.children.get(r)}if(t){const e=new za;return e.root=t,e}}iterateBfs(e){this.iterateInternal(this.root,e,[])}removeNode(e){e.length||(this.root=new Ya);const t=[this.root];for(const r of e){const e=t[t.length-1].children.get(r);if(!e)throw new Error("Node does not exist");t.push(e)}for(let r=t.length-1;r>0;r--){const n=t[r],i=e[r-1];if((n.nodeData||n.children.size)&&r!==t.length-1)break;t[r-1].children.delete(i)}}clearNodeData(e){const t=this.getPathTrieNode(e);t&&(t.nodeData=void 0,t.children.size||this.removeNode(e))}getNodeList(e){const t=[];let r=this.root;for(const n of e){if(!r)return t;t.push(r),r=r.children.get(n)}return t}iterateInternal(e,t,r){if(!1!==t(e.nodeData,r))for(const[n,i]of e.children)this.iterateInternal(i,t,r.concat(n))}}class Ya{constructor(){this.children=new Map([])}}class Wa{constructor(){this.subscriptionsTree=new za,this.state={},this.batchCount=0,this.batchedActions=[]}dispatch(e){this.batchCount>0&&this.batchedActions.push(e),this.state=Fa(this.state,e),0===this.batchCount&&this.dispatchSubscriptions(e)}runInBatch(e){this.batchCount++;try{e()}finally{if(this.batchCount--,0===this.batchCount&&this.batchedActions.length){const e={type:ka.BATCH_ACTION,payload:[...this.batchedActions]};this.batchedActions.splice(0),this.dispatch(e)}}}observePath(e,t){return new b.Observable((r=>{const n=this.getOrCreateSubjectForPath(e);r.next(this.getStateInPath(e));const i=n.pipe(ja((e=>{if(!t)return!0;const r=new za,n=t();for(const e of n)r.getOrCreatePathTrieNode(e,!0);const i=Ma(e.action).map((e=>e.path));let o=!1;for(const e of i)if(0===r.getNodeList(e).length){o=!0;break}return o})),qe((e=>e.data))).subscribe(r);return()=>{i.unsubscribe(),n.observed||(n.complete(),this.subscriptionsTree.clearNodeData(e))}}))}setKeyInPath(e,t,r,n=!1){this.setInPath([...e,t],r,n)}setPartial(e,t,r=!1){let n=this.getStateInPath(e);n||(n={}),this.setInPath(e,Object.assign(Object.assign({},n),t),r)}setInPath(e,t,r=!1){if(r&&this.getStateInPath(e)===t)return;const n={type:ka.SET_PATH,path:e,payload:t};this.dispatch(n)}pushToArray(e,t){let r=this.getStateInPath(e);r=r?[...r]:[],r.push(t),this.setInPath(e,r)}deletePath(e){const t={type:ka.DELETE_PATH,path:e};this.dispatch(t)}getState(){return this.state}getStateInPath(e){return Ka(this.state,e)}destroy(){this.subscriptionsTree.iterateBfs((e=>{e&&e.subject&&e.subject.complete()}))}getOrCreateSubjectForPath(e){const t=this.subscriptionsTree.getOrCreatePathTrieNode(e);t.nodeData||(t.nodeData=new Ha);const r=t.nodeData;return r.subject||(r.subject=new b.Subject),r.subject}dispatchSubscriptions(e){const t=function(e,t){const r=new za;for(const n of Ma(e)){let e=r.getOrCreatePathTrieNode(n.path);if(!t||e.nodeData)continue;let i=t.getPathTrieNode(n.path);if(i){const t=[[e,i]];for(;t.length;){const r=t.shift();if(e=r[0],i=r[1],!e.nodeData){for(const[r,n]of i.children)e.children.get(r)||e.children.set(r,new Ya),t.push([e.children.get(r),n]);e.nodeData=!0}}}}return r}(e,this.subscriptionsTree);t.iterateBfs(((t,r)=>{const n=this.subscriptionsTree.getPathTrieNode(r);n&&n.nodeData&&n.nodeData.subject.next({action:e,data:Ka(this.getState(),r)})}))}}function Ka(e,t){let r=e;for(const e of t){if(null==r)return;if(!qa(r))throw new Error("result must be a state object");r=r[e]}return r}class Ha{}const Ga="client";class Ja{constructor(e,t,r,n,i){this.rpcManager=e,this.clientIdService=t,this.documentStore=r,this.destructManager=n,this.documentIdentityService=i,this.safeToSendQueriesToServer=new b.BehaviorSubject(!0),this.onOrphanDocuments=new b.Subject,this.ongoingQueries=new Map,this.inflightQueriesCount=new b.BehaviorSubject(0),this.clientRequestIdToLocalDocuments=new Map,this.localDocumentToClientRequestIds=new Map,this.queryMappingManager=new Xa,this.documentIdentityService.observeChanges().subscribe(this.migrateDocIds.bind(this)),this.clientIdService.observeClientReadyToBeRegenerated().subscribe((()=>{this.refreshOngoingQueries()})),this.destructManager.onPreDestruct((()=>{this.predestruct()}))}hasOngoingQuery(e){return this.ongoingQueries.has(e)}getQuery(e){return T(this.ongoingQueries.get(e),"UNKNOWN_QUERY").query}setGotInitialResult(e){const t=T(this.ongoingQueries.get(e));t.gotInitialResponse?this.removeClientRequestIdMapping(e):t.gotInitialResponse=!0}findQueriesForDocument(e,t){const{collectionName:r,integrationId:n}=M(t),i=this.queryMappingManager.getMapping(Ga,r,n);return i?function(e,t){var r;const n=[...e.unconditional||[]],i=new Map;for(const[n,o]of Object.entries(e.conditional||{})){const e=l(n);let s;if(f(e)){const n=null!==(r=k(t,e.fieldName))&&void 0!==r?r:null;s=p(e.value,n,e.operator)}else s=Za(e,t);if(s)for(const e of o)i.set(e,(i.get(e)||0)+1)}for(const[t,r]of i.entries())r>=e.queriesMetadata[t].condCount&&n.push(t);return n}(i,e):[]}setClientRequestIdsForLocalDoc(e,t){const r=this.localDocumentToClientRequestIds.get(e)||new Set,n=new Set(t?this.findQueriesForDocument(t,e).map((e=>function(e){const t=e.split("_");return{clientId:t[0],clientRequestId:t[1]}}(e).clientRequestId)):[]),i=new Set([...r,...n]);for(const t of[...r]){if(n.has(t))continue;r.delete(t);const i=this.clientRequestIdToLocalDocuments.get(t);i&&(i.delete(e),i.size||this.clientRequestIdToLocalDocuments.delete(t)),r.size||this.localDocumentToClientRequestIds.delete(e)}for(const t of n){let r=this.localDocumentToClientRequestIds.get(e);r||(r=new Set,this.localDocumentToClientRequestIds.set(e,r)),r.add(t);let n=this.clientRequestIdToLocalDocuments.get(t);n||(n=new Set,this.clientRequestIdToLocalDocuments.set(t,n)),n.add(e)}return[...i]}errorOutAllQueries(e,t){const r=this.localDocumentToClientRequestIds.get(e)||new Set;for(const e of r){const r=this.ongoingQueries.get(e);r&&(r.dataSubject.error(t),r.done=!0)}}notifyAllSubscriptions(e){const t=new Set;for(const r of e){const e=this.ongoingQueries.get(r);if(!e)continue;if(!e.gotInitialResponse||!e.activated)continue;const n=this.clientRequestIdToLocalDocuments.get(r),i=this.documentStore.sortAndLimitDocs(n,e.query),o=e.supportedQueries.map((e=>this.updateOngoingQueryWithNewDataFromSupportingQuery(i,e))).some(Boolean);let s=e;for(;!s.allObservables;)s=T(null==s?void 0:s.supportingOngoingQuery);o&&t.add(s),e.dataSubject.next(i)}for(const e of t){const t=this.collectAllObservables(e);T(e.allObservables).next(t)}}isValidParent(e){if(!e.activated||e.isInFlight||e.isEmptyForJoin||e.done||!e.subscribe||!e.gotInitialResponse||!e.dataSubject.value)return!1;const t=-1===e.query.limit?1e3:e.query.limit;return!(e.dataSubject.value.length>=t)}findValidParentOfOngoingQuery(e){if(e.forceFetchFromServer)return;const t=new g(e.query);for(const r of this.ongoingQueries.values())if(e!==r&&this.isValidParent(r)&&t.isSubqueryOfQuery(r.query))return r}findValidParentOfQuery(e){const t=new g(e);for(const e of this.ongoingQueries.values())if(this.isValidParent(e)&&t.isSubqueryOfQuery(e.query))return e}processQuery(e,t,r,n,i,s){return(0,b.defer)((()=>{const a=this.createOngoingQueryGraph(e,t,r,n,i,!0);s&&(a.forceFetchFromServer=!0),this.sendQueryToServerOrUseParentQuery(a),a.allObservables=new b.ReplaySubject(1);const c=a.allObservables.pipe((0,b.switchMap)((e=>(0,b.combineLatest)(e).pipe(qe((e=>this.joinResults(e,n,a)))))),ja((()=>this.allOngoingQueriesGotInitialResult(a))),(0,b.startWith)(void 0),(0,b.pairwise)(),ja((([e,t])=>!o.isEqual(e,t))),qe((([e,t])=>t)),i?(0,b.tap)():(0,b.take)(1),(0,b.finalize)((()=>{var e;a.dataSubject.complete(),a.done=!0,this.completeAllSupportedQueries(a).then(),null===(e=a.allObservables)||void 0===e||e.complete()}))),u=this.collectAllObservables(a);return a.allObservables.next(u),c})).pipe((0,b.share)())}hasOngoingQueryForDocId(e){const t=this.localDocumentToClientRequestIds.get(e);return!!t&&!!t.size}removeClientRequestIdMapping(e){const t=this.clientRequestIdToLocalDocuments.get(e);if(!t)return;this.clientRequestIdToLocalDocuments.delete(e);const r=[];for(const n of t){const t=T(this.localDocumentToClientRequestIds.get(n));t.delete(e),t.size||(this.localDocumentToClientRequestIds.delete(n),r.push(n))}r.length&&this.onOrphanDocuments.next(r)}async waitForAllQueriesToFinish(){return(0,b.firstValueFrom)(this.inflightQueriesCount.pipe(ja((e=>0===e)))).then((()=>{}))}registerQueryFinalizer(e){const t=e.clientRequestId,r=y(this.clientIdService.getClientId(),t);e.dataSubject.pipe((0,b.finalize)((async()=>{if(e.unsubscribeBlockerCount.value>0&&await(0,b.firstValueFrom)((0,b.race)(this.destructManager.observeIsDestructing(),e.unsubscribeBlockerCount.pipe(ja((e=>0===e))))),this.queryMappingManager.removeQuery(t,r).then(),this.ongoingQueries.delete(t),e.subscribe&&!e.isEmptyForJoin&&e.activated){const r={clientRequestId:t};this.rpcManager.post("query/unsubscribe",r).catch((t=>{console.error("Got error while unsubscribing from query",e.query,t)}))}this.removeClientRequestIdMapping(t),this.ongoingQueries.delete(t)})),ja(Boolean)).subscribe({error:()=>{}})}createOngoingQueryGraph(e,t,r,n,i,o,s={}){if(s[t])return s[t];const a=te(),c=[],u={clientRequestId:a,activated:o,alias:t,query:e,subscribe:i,dataSubject:new b.BehaviorSubject(null),supportedQueries:c,supportingOngoingQuery:void 0,joinCondition:void 0,gotInitialResponse:!1,isEmptyForJoin:!1,unsubscribeBlockerCount:new b.BehaviorSubject(0),queryRegistered:new b.BehaviorSubject(!1),done:!1,isInFlight:!1,forceFetchFromServer:!1};this.registerQueryFinalizer(u),this.ongoingQueries.set(a,u),s[t]=u;for(const[e,o]of Object.entries(n)){const a=o.leftAlias;if(a!==t&&e!==t)continue;const l=a===t?e:a;if(a===t){const e=this.createOngoingQueryGraph(r[l],l,r,n,i,!1,s);e.joinCondition=o,c.push(e)}else u.supportingOngoingQuery=this.createOngoingQueryGraph(r[l],l,r,n,i,!1,s)}return u}collectAllObservables(e,t=[]){if(e.isEmptyForJoin)return t;const r=e.alias;t.push(e.dataSubject.pipe(ja(Boolean),qe((e=>({docs:e,alias:r})))));for(const r of e.supportedQueries)this.collectAllObservables(r,t);return t}joinResults(e,t,r){const n=e.reduce(((e,t)=>(e[t.alias]?e[t.alias].push(...t.docs):e[t.alias]=[...t.docs],e)),{});let i=n[r.alias].map((e=>({[r.alias]:e})));const o=this.getOngoingQueriesBfs(r),s=new Set;for(let e=1;e<o.length;e++){const r=o[e].alias;s.has(r)||(s.add(r),i=this.join(i,r,n[r],t[r]))}return i}join(e,t,r,n){if(!e.length)return e;const i=Object.keys(e[0]);if(!n||!i.includes(n.leftAlias))throw new Error("No join condition found for alias "+t);const o=new Map;return(r||[]).forEach((e=>{const t=e[n.right];o.has(t)||o.set(t,[]),T(o.get(t)).push(e)})),e.flatMap((e=>{var r;const i=o.get(null===(r=e[n.leftAlias])||void 0===r?void 0:r[n.left])||[];return i.length?i.map((r=>Object.assign(Object.assign({},e),{[t]:r}))):n.isInner?[]:[Object.assign(Object.assign({},e),{[t]:void 0})]}))}getOngoingQueriesBfs(e){const t=[],r=[e];for(;r.length;){const e=T(r.shift());e.isEmptyForJoin||(t.push(e),r.push(...e.supportedQueries))}return t}updateOngoingQueryWithNewDataFromSupportingQuery(e,t){var r;const n=T(t.joinCondition),i=t.query;if(t.activated){const s=T(null===(r=t.supportingOngoingQuery)||void 0===r?void 0:r.supportedQueries).filter((e=>e.alias===t.alias)),a=new Set(e.map((e=>{var t;return null!==(t=e[n.left])&&void 0!==t?t:null})));for(const e of s)e.query.conditions.filter(f).filter((e=>e.fieldName===n.right)).forEach((e=>{a.delete(e.value)}));if(0===a.size)return!1;const c=o.cloneDeep(i);c.conditions=c.conditions.filter((e=>!f(e)||e.fieldName!==n.right)),[...a].forEach((e=>{c.conditions.push({fieldName:n.right,operator:"==",value:e})}));const u=Object.assign(Object.assign({},t),{query:c,activated:!0,gotInitialResponse:!1,dataSubject:new b.BehaviorSubject(null),clientRequestId:te(),isEmptyForJoin:!1});return this.registerQueryFinalizer(u),this.ongoingQueries.set(u.clientRequestId,u),T(t.supportingOngoingQuery).supportedQueries.push(u),this.sendQueryToServerOrUseParentQuery(u),!0}{const r=e.map((e=>{var t;return{fieldName:n.right,operator:"==",value:null!==(t=e[n.left])&&void 0!==t?t:null}}));return t.activated=!0,r.length?(i.conditions.push(...r),this.sendQueryToServerOrUseParentQuery(t)):t.isEmptyForJoin=!0,!0}}allOngoingQueriesGotInitialResult(e){return!!e.isEmptyForJoin||!!e.gotInitialResponse&&(!e.supportedQueries.length||e.supportedQueries.every((e=>this.allOngoingQueriesGotInitialResult(e))))}async completeAllSupportedQueries(e){const t=[...e.supportedQueries||[]];for(;t.length;){const e=T(t.shift());t.push(...e.supportedQueries||[]),await(0,b.firstValueFrom)(e.unsubscribeBlockerCount.pipe(ja((e=>0===e)))),e.dataSubject.complete()}}predestruct(){this.safeToSendQueriesToServer.next(!1),this.safeToSendQueriesToServer.complete(),this.unsubscribe()}unsubscribe(){var e;const t=[...this.ongoingQueries.values()];for(const r of t)r.dataSubject.complete(),null===(e=r.allObservables)||void 0===e||e.complete()}hasSubscription(e){var t;return!!(null===(t=this.ongoingQueries.get(e))||void 0===t?void 0:t.subscribe)}sendQueryToServerOrUseParentQuery(e){if(this.destructManager.isDestructing)return;const t=e.query,r=e.clientRequestId,n=y(this.clientIdService.getClientId(),r);this.queryMappingManager.addQuery(Ga,t,n),this.ongoingQueries.set(r,e);const i=this.findValidParentOfOngoingQuery(e);i?this.useParentOngoingQuery(e,i).then():this.sendQueryToServer(e)}async useParentOngoingQuery(e,t){const r={clientRequestId:e.clientRequestId,query:e.query,parentClientRequestId:t.clientRequestId},n=new g(e.query);t.unsubscribeBlockerCount.next(t.unsubscribeBlockerCount.value+1);try{await(0,b.firstValueFrom)(t.queryRegistered.pipe(ja(Boolean)))}catch(t){return e.dataSubject.error(t),e.queryRegistered.error(t),void(e.done=!0)}if(this.destructManager.isDestructing)return;if(e.done)return;this.rpcManager.post("query/register",r).then((()=>{e.queryRegistered.next(!0)})).catch((r=>{console.error("Query error",e.query,t.query,r),e.dataSubject.error(r),e.done=!0})).finally((()=>{t.unsubscribeBlockerCount.next(t.unsubscribeBlockerCount.value-1),e.isInFlight=!1}));const i=(0,b.race)(e.queryRegistered.pipe(ja(Boolean),(0,b.delay)(2e3),(0,b.take)(1)),this.destructManager.observeIsDestructing().pipe((0,b.take)(1)));t.dataSubject.pipe((0,b.takeWhile)((()=>!e.done)),(0,b.takeUntil)(i),ja(Boolean),(0,b.tap)((()=>{e.gotInitialResponse||this.setGotInitialResult(e.clientRequestId)})),qe((e=>e.filter((e=>n.documentMatchesQuery(e)))))).subscribe({next:t=>{for(const r of t)this.setClientRequestIdsForLocalDoc(F(r.__docId__,e.query.collectionName,e.query.integrationId),r);this.notifyAllSubscriptions([e.clientRequestId])},error:t=>e.dataSubject.error(t)})}sendQueryToServer(e){const t={query:e.query,clientRequestId:e.clientRequestId,subscribe:e.subscribe};this.safeToSendQueriesToServer.pipe(ja(Boolean),(0,b.take)(1)).subscribe((()=>{e.done||(this.inflightQueriesCount.next(this.inflightQueriesCount.value+1),e.isInFlight=!0,this.rpcManager.post("query/query",t).catch((t=>{e.dataSubject.error(t),e.done=!0,e.queryRegistered.error("query failed")})).then((()=>{e.queryRegistered.next(!0)})).finally((()=>{this.inflightQueriesCount.next(this.inflightQueriesCount.value-1),e.isInFlight=!1})))}))}refreshOngoingQueries(){for(const e of this.ongoingQueries.values())this.sendQueryToServerOrUseParentQuery(e)}migrateDocIds(e){const t=Object.keys(e);for(const r of this.clientRequestIdToLocalDocuments.values())t.forEach((t=>{r.has(t)&&(r.delete(t),r.add(e[t]))}));t.forEach((t=>{A(this.localDocumentToClientRequestIds,t,e[t])}))}}function Za(e,t){var r;for(const n of e.fields){const e=null!==(r=k(t,n.fieldName))&&void 0!==r?r:null;if(p(n.value,e,n.operator))return!0;if(p(n.value,e,"!="))return!1}return!1}class Xa{constructor(){this.stateService=new Wa,this.querySubscriptionIdToQuery={}}addQuery(e,t,r){this.stateService.runInBatch((()=>{let e=0;const n=new Set;for(const i of t.conditions){if(f(i)&&["=="].includes(i.operator)){const t=h(i.fieldName);n.has(t)||(e++,n.add(t))}else e++;const o=this.getConditionStatePath(t,i),s=[...this.stateService.getStateInPath(o)||[]];H(s,r),this.stateService.setInPath(o,s)}if(!t.conditions.length){const e=["queryMapping",t.collectionName,t.integrationId,"mapping","unconditional"],n=[...this.stateService.getStateInPath(e)||[]];H(n,r),this.stateService.setInPath(e,n)}this.stateService.setInPath([...this.getQueryMetadataStatePath(t,r),"condCount"],e)})),this.querySubscriptionIdToQuery[r]=t}async removeQuery(e,t){const r=this.querySubscriptionIdToQuery[t];if(r)return this.stateService.runInBatch((()=>{for(const e of r.conditions){const n=this.getConditionStatePath(r,e),i=[...this.stateService.getStateInPath(n)||[]];G(i,t),i.length?this.stateService.setInPath(n,i):this.stateService.deletePath(n)}if(!r.conditions.length){const e=["queryMapping",r.collectionName,r.integrationId,"mapping","unconditional"],n=[...this.stateService.getStateInPath(e)||[]];G(n,t),this.stateService.setInPath(e,n)}this.stateService.deletePath(this.getQueryMetadataStatePath(r,t))})),r}getMapping(e,t,r){return this.stateService.getStateInPath(["queryMapping",t,r,"mapping"])}getQueryMetadataStatePath(e,t){return["queryMapping",e.collectionName,e.integrationId,"mapping","queriesMetadata",`${t}`]}getConditionStatePath(e,t){return["queryMapping",e.collectionName,e.integrationId,"mapping","conditional",d(t)]}}class ec{constructor(e,t,r,n,i={},o,s){this.region=e,this.appId=t,this.socketManager=r,this.destructManager=n,this.headers=i,this.authManager=o,this.clientIdService=s,this.staticHeaders={},this.onGoingRpcCounter=new b.BehaviorSubject(0);for(const[e,t]of Object.entries(i))this.setStaticHeader(e,t);const a=this.authManager.getApiKey();a&&this.setStaticHeader("Authorization",`ApiKey ${a}`),this.clientIdService.observeClientId().subscribe((e=>{e?this.setStaticHeader("x-squid-clientid",e):this.deleteStaticHeader("x-squid-clientid")})),this.authManager.observeAuthIdToken().subscribe((e=>{if(e.token){let t=`Bearer ${e.token}`;e.integrationId&&(t+=`; IntegrationId ${e.integrationId}`),this.setStaticHeader("Authorization",t)}else this.deleteStaticHeader("Authorization")})),n.onDestruct((async()=>{await this.awaitAllSettled()}))}async awaitAllSettled(){await(0,b.firstValueFrom)(this.onGoingRpcCounter.pipe((0,b.filter)((e=>0===e))))}setStaticHeader(e,t){this.staticHeaders[e]=t}deleteStaticHeader(e){delete this.staticHeaders[e]}getStaticHeaders(){return this.staticHeaders}async post(e,t){this.onGoingRpcCounter.next(this.onGoingRpcCounter.value+1);try{await(0,b.firstValueFrom)((0,b.race)(this.socketManager.observeConnectionReady().pipe((0,b.filter)(Boolean)),this.destructManager.observeIsDestructing())),await this.authManager.waitForReadyState();let r={"Content-Type":"application/json"};Object.keys(this.staticHeaders)&&(r=Object.assign(Object.assign({},r),this.staticHeaders));const n=X(this.region,this.appId,e),i=await Da()(n,{method:"POST",body:u(t),headers:r});let o,s;try{o=await i.text();try{s=JSON.parse(o)}catch(e){}}catch(e){o="Cannot read body"}if(!i.ok)throw new tc(i.status,i.statusText,i.headers,i.url,null==s?void 0:s.message);return s||o}finally{this.onGoingRpcCounter.next(this.onGoingRpcCounter.value-1)}}}class tc extends Error{constructor(e,t,r,n,i){super(i||`RPC error ${e} ${t} calling ${n}`),this.statusCode=e,this.statusText=t,this.headers=r,this.url=n}}const rc=require("socket.io-client"),nc=e=>e();class ic{constructor(e,t,r,n=nc,i,o={},s){this.clientIdService=e,this.region=t,this.appId=r,this.messageNotificationWrapper=n,this.destructManager=i,this.authManager=s,this.webSocketObserver=new b.Subject,this.allMessagesObserver=new b.Subject,this.connectionReady=new b.BehaviorSubject(!1),this.seenMessageIds=new Set,this.firstConnection=!0,this.clientTooOldThreshold=3e5,this.destructManager.onDestruct((async()=>{await this.destruct()})),this.setupMessageAcknowledgments(),this.connect(Object.assign({},o)),this.connectionReady.pipe((0,b.skip)(1),(0,b.filter)((e=>!e)),(0,b.switchMap)((()=>(0,b.race)((0,b.timer)(this.clientTooOldThreshold),this.connectionReady.pipe((0,b.filter)(Boolean)),this.destructManager.observeIsDestructing())))).subscribe((()=>{this.connectionReady.value||this.destructManager.isDestructing||(this.clientIdService.notifyClientTooOld(),this.connect(Object.assign({},o)))})),this.connectionReady.pipe((0,b.filter)(Boolean)).subscribe((()=>{this.clientIdService.isClientTooOld()&&this.clientIdService.notifyClientReadyToBeRegenerated()}))}observeNotifications(){return this.webSocketObserver.asObservable()}observeConnectionReady(){return this.connectionReady.asObservable().pipe((0,b.distinctUntilChanged)())}sendMessage(e){this.authManager.waitForReadyState().then((()=>{(0,b.firstValueFrom)(this.connectionReady.pipe((0,b.filter)(Boolean))).then((()=>{const t=this.authManager.getAuthToken();T(this.socket).emit("message",Object.assign(Object.assign({},e),{authToken:t}))}))}))}connect(e){const t=X(this.region,this.appId,""),r={clientId:this.clientIdService.getClientId()};this.socket=(0,rc.io)(t,{query:r,reconnectionDelay:5e3,transports:["websocket"],extraHeaders:e}),this.socket.on("connect",(()=>{})),this.socket.on("disconnect",((e,t)=>{this.connectionReady.next(!1)})),this.socket.on("connectionReady",(()=>{this.connectionReady.next(!0),this.firstConnection||this.sendMessage({type:"catchup"}),this.firstConnection=!1})),this.socket.on("message",(e=>{const t=l(e);for(const e of t)this.allMessagesObserver.next(e),this.seenMessageIds.has(e.messageId)||(this.seenMessageIds.add(e.messageId),this.messageNotificationWrapper((()=>{this.webSocketObserver.next(e)})))}))}setupMessageAcknowledgments(){const e=new b.Subject;this.allMessagesObserver.subscribe((t=>{(null==t?void 0:t.messageId)&&e.next(t.messageId)}));const t=[];e.pipe((0,b.tap)((e=>t.push(e))),(0,b.debounceTime)(100)).subscribe((async()=>{const e=[...t.splice(0)];this.sendMessage({type:"acknowledge",payload:e})}))}async destruct(){var e;this.sendMessage({type:"kill"}),this.connectionReady.next(!1),await(0,b.firstValueFrom)((0,b.timer)(0)),null===(e=this.socket)||void 0===e||e.disconnect(),this.webSocketObserver.complete(),this.allMessagesObserver.complete()}}class oc{constructor(e){this.destructManager=new pt,this.setAuthIdToken=(e,t)=>{this.authManager.setAuthIdToken(e,t)},this.collection=(e,r=t.built_in_db)=>(this.validateNotDestructed(),this.collectionReferenceFactory.get(e,r)),this.runInTransaction=e=>(this.validateNotDestructed(),this.dataManager.runInTransaction(e)),this.executeFunction=(e,...t)=>(this.validateNotDestructed(),(0,b.firstValueFrom)(this.backendFunctionManager.executeFunctionAndSubscribe(e,...t))),this.executeNamedQuery=(e,t,r)=>(this.validateNotDestructed(),(0,b.firstValueFrom)(this.namedQueryManager.executeNamedQueryAndSubscribe(e,t,r))),this.callApi=(e,t,r={})=>(this.validateNotDestructed(),(0,b.firstValueFrom)(this.apiManager.callApiAndSubscribe(e,t,r))),this.graphql=e=>(this.validateNotDestructed(),this.graphqlClientFactory.get(e)),this.ai=()=>(this.validateNotDestructed(),{assistant:e=>this.aiClientFactory.getAssistant(e)}),this.acquireLock=(e,t=!0)=>(this.validateNotDestructed(),this.distributedLockManager.lock(e,t)),this.destruct=async()=>{if(!this.destructManager.isDestructing)return this.destructManager.destruct().finally((()=>{const e=Object.entries(oc.squidInstancesMap).find((([,e])=>e===this));e&&delete oc.squidInstancesMap[e[0]]}))},this.connectionDetails=()=>(this.validateNotDestructed(),this._connectionDetails),this.unsubscribe=async()=>{this.querySubscriptionManager.unsubscribe(),await this.rpcManager.awaitAllSettled()},I(e.appId,"APP_ID_MUST_BE_PROVIDED");const r="prod"!==e.environmentId&&e.squidDeveloperId,n=function(e,t,r){return`${C(e,t)}${r?`-${r}`:""}`}(e.appId,e.environmentId,r?e.squidDeveloperId:void 0),i=function(e,t){const r={};return ee(e)&&(r["x-squid-appid"]=t),r}(e.region,n);this.clientIdService=new ct(this.destructManager),this.authManager=new st(this.destructManager,e.apiKey),this.socketManager=new ic(this.clientIdService,e.region,n,e.messageNotificationWrapper,this.destructManager,i,this.authManager),this.rpcManager=new ec(e.region,n,this.socketManager,this.destructManager,i,this.authManager,this.clientIdService),this.documentStore=new bt,this.lockManager=new re,this.distributedLockManager=new mt(this.socketManager,this.destructManager),this.documentIdentityService=new vt(this.documentStore,this.destructManager),this.documentReferenceFactory=new gt(this.documentIdentityService),this.querySubscriptionManager=new Ja(this.rpcManager,this.clientIdService,this.documentStore,this.destructManager,this.documentIdentityService),this.localQueryManager=new Pa(this.documentStore,this.documentReferenceFactory,this.querySubscriptionManager);const o=new Aa(this.rpcManager,this.lockManager,this.querySubscriptionManager);this.queryBuilderFactory=new We(this.querySubscriptionManager,this.localQueryManager,this.documentReferenceFactory,this.documentIdentityService),this.collectionReferenceFactory=new ut(this.documentReferenceFactory,this.queryBuilderFactory,this.querySubscriptionManager),this.dataManager=new dt(this.documentStore,o,this.socketManager,this.querySubscriptionManager,this.queryBuilderFactory,this.lockManager,this.destructManager,this.documentIdentityService),this.documentReferenceFactory.setDataManager(this.dataManager),this.backendFunctionManager=new at(this.clientIdService,this.rpcManager,this.socketManager),this.namedQueryManager=new Ra(this.rpcManager,this.socketManager),this.apiManager=new ot(this.clientIdService,this.rpcManager,this.socketManager,e.apiServerUrlOverrideMapping),this.graphqlClientFactory=new xa(this.rpcManager,e.region,n),this.aiClientFactory=new it(this.rpcManager,this.socketManager),this._connectionDetails=new lt(this.clientIdService,this.socketManager)}static getInstance(e){const t=c(e);let r=oc.squidInstancesMap[t];return r||(r=new oc(e),oc.squidInstancesMap[t]=r,r)}static getInstances(){return Object.values(oc.squidInstancesMap)}validateNotDestructed(){I(!this.destructManager.isDestructing,"The client was already destructed.")}}oc.squidInstancesMap={}})();var i=exports;for(var o in n)i[o]=n[o];n.__esModule&&Object.defineProperty(i,"__esModule",{value:!0})})();
12
+ `})).data}}class xa{constructor(e,t,r){this.rpcManager=e,this.region=t,this.appId=r,this.clientsMap=new Map}get(e){let t=this.clientsMap.get(e);return t||(t=new Na(this.rpcManager,e,this.region,this.appId),this.clientsMap.set(e,t),t)}}class Aa{constructor(e,t,r){this.rpcManager=e,this.lockManager=t,this.querySubscriptionManager=r}async sendMutations(e,t){const r=Q(e),n=r.map((e=>`sendMutation_${F(e.squidDocIdObj)}`));await this.lockManager.lock(...n),await this.querySubscriptionManager.waitForAllQueriesToFinish();try{const e={mutations:r,integrationId:t};return await this.rpcManager.post("mutation/mutate",e)}finally{this.lockManager.release(...n)}}}class Ra{constructor(e,t){this.rpcManager=e,this.socketManager=t,this.ongoingNamedQueryExecutions={},t.observeNotifications().pipe((0,b.filter)((e=>"namedQuery"===e.type)),qe((e=>e))).subscribe((e=>{this.handleNamedQueryResponse(e.clientRequestId,e.payload)}))}executeNamedQueryAndSubscribe(e,t,r){const n=te(),i=new b.Subject;this.ongoingNamedQueryExecutions[n]=i;const o={integrationId:e,queryName:t,paramsRecordStr:u(r),clientRequestId:n};return this.rpcManager.post("named-query/execute",o).catch((r=>{console.error("Got error while executing named query",t,"for integration",e,r),i.error(r),i.complete()})),i.pipe((0,b.finalize)((()=>{delete this.ongoingNamedQueryExecutions[n]})),(0,b.share)())}handleNamedQueryResponse(e,t){const r=this.ongoingNamedQueryExecutions[e];if(!r)return;const n=l(t);n.success?r.next(n.result):(r.error(new Error(n.result)),r.complete())}}class Pa{constructor(e,t,r){this.documentStore=e,this.documentReferenceFactory=t,this.querySubscriptionManager=r}peek(e){if(!this.querySubscriptionManager.findValidParentOfQuery(e))return[];const{integrationId:t,collectionName:r}=e,n=new g(e),i=this.documentReferenceFactory.getDocumentsForCollection(t,r).filter((e=>n.documentMatchesQuery(e.data))),o={};return i.forEach((e=>{o[e.squidDocId]=e})),this.documentStore.sortAndLimitDocs(new Set(Object.keys(o)),e).map((e=>o[F(e.__docId__,r,t)]))}}function ja(e,t){return oe((function(r,n){var i=0;r.subscribe(Me(n,(function(r){return e.call(t,r,i++)&&n.next(r)})))}))}function Ca(e){return[ka.SET_PATH,ka.DELETE_PATH].includes(e.type)}function $a(e){return e.type===ka.BATCH_ACTION}function Ma(e){const t=[];if(Ca(e))t.push(e);else if($a(e))for(const r of e.payload)t.push(...Ma(r));return t}function Fa(e,t){return La(e,t)}function qa(e){return"object"==typeof e}function La(e,t){let r=e;if(Ca(t))r=function(e,t,r=[]){switch(t.type){case ka.DELETE_PATH:return Va(e,t.path);case ka.SET_PATH:const n=t;return function(e,t,r,n){return Qa(e,t,r,n)}(e,t.path,r,n.payload);case ka.BATCH_ACTION:throw new Error("Unsupported")}}(e,t,[]);else{if(!$a(t))throw new Error(`Invalid action type: ${t.type}`);r=t.payload.reduce(((e,t)=>La(e,t)),e)}return r}function Va(e,t){if(!t.length)throw new Error("can not delete an empty path");const r=t[0];if(1===t.length)return function(e,t){if(e instanceof Array)throw new Error("Cannot remove an item from an array");const r=Object.assign({},e);return delete r[t],r}(e,r);const n=t.slice(1),i=Ba(e,r);if(!i)return e;if(!qa(i))throw new Error("Cannot delete from a non object state.");const o=Va(i,n);return o===i?e:Ua(e,r,o)}function Qa(e,t,r,n){if(!t.length){if(qa(n))return n;throw new Error("Relative path cannot be of length 0 when the new value is not an object.")}const i=t[0],o=[...r,i];if(1===t.length)return Ua(e,i,n);const s=t.slice(1),a=Ba(e,i);return void 0!==a&&qa(a)?Ua(e,i,Qa(a,s,o,n)):Qa(e=Ua(e,i,{}),t,r,n)}function Ua(e,t,r){return(e=Object.assign({},e))[t]=r,e}function Ba(e,t){return e instanceof Array?e[function(e){const t=Number(e);if(isNaN(t))throw new Error(`The value is not a number: Actual: ${e}`);return Math.floor(t)}(t)]:e[t]}!function(e){e.DELETE_PATH="DELETE_PATH",e.SET_PATH="SET_PATH",e.BATCH_ACTION="BATCH_ACTION"}(ka||(ka={}));class za{constructor(){this.root=new Ya}getOrCreatePathTrieNode(e,t){let r=this.root;for(const t of e)r.children.get(t)||r.children.set(t,new Ya),r=r.children.get(t);return void 0!==t&&(r.nodeData=t),r}getPathTrieNode(e){let t=this.root;for(const r of e){if(!t)return;t=t.children.get(r)}return t}getPathTrie(e){let t=this.root;for(const r of e){if(!t)return;t=t.children.get(r)}if(t){const e=new za;return e.root=t,e}}iterateBfs(e){this.iterateInternal(this.root,e,[])}removeNode(e){e.length||(this.root=new Ya);const t=[this.root];for(const r of e){const e=t[t.length-1].children.get(r);if(!e)throw new Error("Node does not exist");t.push(e)}for(let r=t.length-1;r>0;r--){const n=t[r],i=e[r-1];if((n.nodeData||n.children.size)&&r!==t.length-1)break;t[r-1].children.delete(i)}}clearNodeData(e){const t=this.getPathTrieNode(e);t&&(t.nodeData=void 0,t.children.size||this.removeNode(e))}getNodeList(e){const t=[];let r=this.root;for(const n of e){if(!r)return t;t.push(r),r=r.children.get(n)}return t}iterateInternal(e,t,r){if(!1!==t(e.nodeData,r))for(const[n,i]of e.children)this.iterateInternal(i,t,r.concat(n))}}class Ya{constructor(){this.children=new Map([])}}class Wa{constructor(){this.subscriptionsTree=new za,this.state={},this.batchCount=0,this.batchedActions=[]}dispatch(e){this.batchCount>0&&this.batchedActions.push(e),this.state=Fa(this.state,e),0===this.batchCount&&this.dispatchSubscriptions(e)}runInBatch(e){this.batchCount++;try{e()}finally{if(this.batchCount--,0===this.batchCount&&this.batchedActions.length){const e={type:ka.BATCH_ACTION,payload:[...this.batchedActions]};this.batchedActions.splice(0),this.dispatch(e)}}}observePath(e,t){return new b.Observable((r=>{const n=this.getOrCreateSubjectForPath(e);r.next(this.getStateInPath(e));const i=n.pipe(ja((e=>{if(!t)return!0;const r=new za,n=t();for(const e of n)r.getOrCreatePathTrieNode(e,!0);const i=Ma(e.action).map((e=>e.path));let o=!1;for(const e of i)if(0===r.getNodeList(e).length){o=!0;break}return o})),qe((e=>e.data))).subscribe(r);return()=>{i.unsubscribe(),n.observed||(n.complete(),this.subscriptionsTree.clearNodeData(e))}}))}setKeyInPath(e,t,r,n=!1){this.setInPath([...e,t],r,n)}setPartial(e,t,r=!1){let n=this.getStateInPath(e);n||(n={}),this.setInPath(e,Object.assign(Object.assign({},n),t),r)}setInPath(e,t,r=!1){if(r&&this.getStateInPath(e)===t)return;const n={type:ka.SET_PATH,path:e,payload:t};this.dispatch(n)}pushToArray(e,t){let r=this.getStateInPath(e);r=r?[...r]:[],r.push(t),this.setInPath(e,r)}deletePath(e){const t={type:ka.DELETE_PATH,path:e};this.dispatch(t)}getState(){return this.state}getStateInPath(e){return Ka(this.state,e)}destroy(){this.subscriptionsTree.iterateBfs((e=>{e&&e.subject&&e.subject.complete()}))}getOrCreateSubjectForPath(e){const t=this.subscriptionsTree.getOrCreatePathTrieNode(e);t.nodeData||(t.nodeData=new Ha);const r=t.nodeData;return r.subject||(r.subject=new b.Subject),r.subject}dispatchSubscriptions(e){const t=function(e,t){const r=new za;for(const n of Ma(e)){let e=r.getOrCreatePathTrieNode(n.path);if(!t||e.nodeData)continue;let i=t.getPathTrieNode(n.path);if(i){const t=[[e,i]];for(;t.length;){const r=t.shift();if(e=r[0],i=r[1],!e.nodeData){for(const[r,n]of i.children)e.children.get(r)||e.children.set(r,new Ya),t.push([e.children.get(r),n]);e.nodeData=!0}}}}return r}(e,this.subscriptionsTree);t.iterateBfs(((t,r)=>{const n=this.subscriptionsTree.getPathTrieNode(r);n&&n.nodeData&&n.nodeData.subject.next({action:e,data:Ka(this.getState(),r)})}))}}function Ka(e,t){let r=e;for(const e of t){if(null==r)return;if(!qa(r))throw new Error("result must be a state object");r=r[e]}return r}class Ha{}const Ga="client";class Ja{constructor(e,t,r,n,i){this.rpcManager=e,this.clientIdService=t,this.documentStore=r,this.destructManager=n,this.documentIdentityService=i,this.safeToSendQueriesToServer=new b.BehaviorSubject(!0),this.onOrphanDocuments=new b.Subject,this.ongoingQueries=new Map,this.inflightQueriesCount=new b.BehaviorSubject(0),this.clientRequestIdToLocalDocuments=new Map,this.localDocumentToClientRequestIds=new Map,this.queryMappingManager=new Xa,this.documentIdentityService.observeChanges().subscribe(this.migrateDocIds.bind(this)),this.clientIdService.observeClientReadyToBeRegenerated().subscribe((()=>{this.refreshOngoingQueries()})),this.destructManager.onPreDestruct((()=>{this.predestruct()}))}hasOngoingQuery(e){return this.ongoingQueries.has(e)}getQuery(e){return T(this.ongoingQueries.get(e),"UNKNOWN_QUERY").query}setGotInitialResult(e){const t=this.ongoingQueries.get(e);t&&!t.gotInitialResponse?t.gotInitialResponse=!0:this.removeClientRequestIdMapping(e)}findQueriesForDocument(e,t){const{collectionName:r,integrationId:n}=M(t),i=this.queryMappingManager.getMapping(Ga,r,n);return i?function(e,t){var r;const n=[...e.unconditional||[]],i=new Map;for(const[n,o]of Object.entries(e.conditional||{})){const e=l(n);let s;if(f(e)){const n=null!==(r=k(t,e.fieldName))&&void 0!==r?r:null;s=p(e.value,n,e.operator)}else s=Za(e,t);if(s)for(const e of o)i.set(e,(i.get(e)||0)+1)}for(const[t,r]of i.entries())r>=e.queriesMetadata[t].condCount&&n.push(t);return n}(i,e):[]}setClientRequestIdsForLocalDoc(e,t){const r=this.localDocumentToClientRequestIds.get(e)||new Set,n=new Set(t?this.findQueriesForDocument(t,e).map((e=>function(e){const t=e.split("_");return{clientId:t[0],clientRequestId:t[1]}}(e).clientRequestId)):[]),i=new Set([...r,...n]);for(const t of[...r]){if(n.has(t))continue;r.delete(t);const i=this.clientRequestIdToLocalDocuments.get(t);i&&(i.delete(e),i.size||this.clientRequestIdToLocalDocuments.delete(t)),r.size||this.localDocumentToClientRequestIds.delete(e)}for(const t of n){let r=this.localDocumentToClientRequestIds.get(e);r||(r=new Set,this.localDocumentToClientRequestIds.set(e,r)),r.add(t);let n=this.clientRequestIdToLocalDocuments.get(t);n||(n=new Set,this.clientRequestIdToLocalDocuments.set(t,n)),n.add(e)}return[...i]}errorOutAllQueries(e,t){const r=this.localDocumentToClientRequestIds.get(e)||new Set;for(const e of r){const r=this.ongoingQueries.get(e);r&&(r.dataSubject.error(t),r.done=!0)}}notifyAllSubscriptions(e){const t=new Set;for(const r of e){const e=this.ongoingQueries.get(r);if(!e)continue;if(!e.gotInitialResponse||!e.activated)continue;const n=this.clientRequestIdToLocalDocuments.get(r),i=this.documentStore.sortAndLimitDocs(n,e.query),o=e.supportedQueries.map((e=>this.updateOngoingQueryWithNewDataFromSupportingQuery(i,e))).some(Boolean);let s=e;for(;!s.allObservables;)s=T(null==s?void 0:s.supportingOngoingQuery);o&&t.add(s),e.dataSubject.next(i)}for(const e of t){const t=this.collectAllObservables(e);T(e.allObservables).next(t)}}isValidParent(e){if(!e.activated||e.isInFlight||e.isEmptyForJoin||e.done||!e.subscribe||!e.gotInitialResponse||!e.dataSubject.value)return!1;const t=-1===e.query.limit?1e3:e.query.limit;return!(e.dataSubject.value.length>=t)}findValidParentOfOngoingQuery(e){if(e.forceFetchFromServer)return;const t=new g(e.query);for(const r of this.ongoingQueries.values())if(e!==r&&this.isValidParent(r)&&t.isSubqueryOfQuery(r.query))return r}findValidParentOfQuery(e){const t=new g(e);for(const e of this.ongoingQueries.values())if(this.isValidParent(e)&&t.isSubqueryOfQuery(e.query))return e}processQuery(e,t,r,n,i,s){return(0,b.defer)((()=>{const a=this.createOngoingQueryGraph(e,t,r,n,i,!0);s&&(a.forceFetchFromServer=!0),this.sendQueryToServerOrUseParentQuery(a),a.allObservables=new b.ReplaySubject(1);const c=a.allObservables.pipe((0,b.switchMap)((e=>(0,b.combineLatest)(e).pipe(qe((e=>this.joinResults(e,n,a)))))),ja((()=>this.allOngoingQueriesGotInitialResult(a))),(0,b.startWith)(void 0),(0,b.pairwise)(),ja((([e,t])=>!o.isEqual(e,t))),qe((([e,t])=>t)),i?(0,b.tap)():(0,b.take)(1),(0,b.finalize)((()=>{var e;a.dataSubject.complete(),a.done=!0,this.completeAllSupportedQueries(a).then(),null===(e=a.allObservables)||void 0===e||e.complete()}))),u=this.collectAllObservables(a);return a.allObservables.next(u),c})).pipe((0,b.share)())}hasOngoingQueryForDocId(e){const t=this.localDocumentToClientRequestIds.get(e);return!!t&&!!t.size}removeClientRequestIdMapping(e){const t=this.clientRequestIdToLocalDocuments.get(e);if(!t)return;this.clientRequestIdToLocalDocuments.delete(e);const r=[];for(const n of t){const t=T(this.localDocumentToClientRequestIds.get(n));t.delete(e),t.size||(this.localDocumentToClientRequestIds.delete(n),r.push(n))}r.length&&this.onOrphanDocuments.next(r)}async waitForAllQueriesToFinish(){return(0,b.firstValueFrom)(this.inflightQueriesCount.pipe(ja((e=>0===e)))).then((()=>{}))}registerQueryFinalizer(e){const t=e.clientRequestId,r=y(this.clientIdService.getClientId(),t);e.dataSubject.pipe((0,b.finalize)((async()=>{if(e.unsubscribeBlockerCount.value>0&&await(0,b.firstValueFrom)((0,b.race)(this.destructManager.observeIsDestructing(),e.unsubscribeBlockerCount.pipe(ja((e=>0===e))))),this.queryMappingManager.removeQuery(t,r).then(),this.ongoingQueries.delete(t),e.subscribe&&!e.isEmptyForJoin&&e.activated){const r={clientRequestId:t};this.rpcManager.post("query/unsubscribe",r).catch((t=>{console.error("Got error while unsubscribing from query",e.query,t)}))}this.removeClientRequestIdMapping(t),this.ongoingQueries.delete(t)})),ja(Boolean)).subscribe({error:()=>{}})}createOngoingQueryGraph(e,t,r,n,i,o,s={}){if(s[t])return s[t];const a=te(),c=[],u={clientRequestId:a,activated:o,alias:t,query:e,subscribe:i,dataSubject:new b.BehaviorSubject(null),supportedQueries:c,supportingOngoingQuery:void 0,joinCondition:void 0,gotInitialResponse:!1,isEmptyForJoin:!1,unsubscribeBlockerCount:new b.BehaviorSubject(0),queryRegistered:new b.BehaviorSubject(!1),done:!1,isInFlight:!1,forceFetchFromServer:!1};this.registerQueryFinalizer(u),this.ongoingQueries.set(a,u),s[t]=u;for(const[e,o]of Object.entries(n)){const a=o.leftAlias;if(a!==t&&e!==t)continue;const l=a===t?e:a;if(a===t){const e=this.createOngoingQueryGraph(r[l],l,r,n,i,!1,s);e.joinCondition=o,c.push(e)}else u.supportingOngoingQuery=this.createOngoingQueryGraph(r[l],l,r,n,i,!1,s)}return u}collectAllObservables(e,t=[]){if(e.isEmptyForJoin)return t;const r=e.alias;t.push(e.dataSubject.pipe(ja(Boolean),qe((e=>({docs:e,alias:r})))));for(const r of e.supportedQueries)this.collectAllObservables(r,t);return t}joinResults(e,t,r){const n=e.reduce(((e,t)=>(e[t.alias]?e[t.alias].push(...t.docs):e[t.alias]=[...t.docs],e)),{});let i=n[r.alias].map((e=>({[r.alias]:e})));const o=this.getOngoingQueriesBfs(r),s=new Set;for(let e=1;e<o.length;e++){const r=o[e].alias;s.has(r)||(s.add(r),i=this.join(i,r,n[r],t[r]))}return i}join(e,t,r,n){if(!e.length)return e;const i=Object.keys(e[0]);if(!n||!i.includes(n.leftAlias))throw new Error("No join condition found for alias "+t);const o=new Map;return(r||[]).forEach((e=>{const t=e[n.right];o.has(t)||o.set(t,[]),T(o.get(t)).push(e)})),e.flatMap((e=>{var r;const i=o.get(null===(r=e[n.leftAlias])||void 0===r?void 0:r[n.left])||[];return i.length?i.map((r=>Object.assign(Object.assign({},e),{[t]:r}))):n.isInner?[]:[Object.assign(Object.assign({},e),{[t]:void 0})]}))}getOngoingQueriesBfs(e){const t=[],r=[e];for(;r.length;){const e=T(r.shift());e.isEmptyForJoin||(t.push(e),r.push(...e.supportedQueries))}return t}updateOngoingQueryWithNewDataFromSupportingQuery(e,t){var r;const n=T(t.joinCondition),i=t.query;if(t.activated){const s=T(null===(r=t.supportingOngoingQuery)||void 0===r?void 0:r.supportedQueries).filter((e=>e.alias===t.alias)),a=new Set(e.map((e=>{var t;return null!==(t=e[n.left])&&void 0!==t?t:null})));for(const e of s)e.query.conditions.filter(f).filter((e=>e.fieldName===n.right)).forEach((e=>{a.delete(e.value)}));if(0===a.size)return!1;const c=o.cloneDeep(i);c.conditions=c.conditions.filter((e=>!f(e)||e.fieldName!==n.right)),[...a].forEach((e=>{c.conditions.push({fieldName:n.right,operator:"==",value:e})}));const u=Object.assign(Object.assign({},t),{query:c,activated:!0,gotInitialResponse:!1,dataSubject:new b.BehaviorSubject(null),clientRequestId:te(),isEmptyForJoin:!1});return this.registerQueryFinalizer(u),this.ongoingQueries.set(u.clientRequestId,u),T(t.supportingOngoingQuery).supportedQueries.push(u),this.sendQueryToServerOrUseParentQuery(u),!0}{const r=e.map((e=>{var t;return{fieldName:n.right,operator:"==",value:null!==(t=e[n.left])&&void 0!==t?t:null}}));return t.activated=!0,r.length?(i.conditions.push(...r),this.sendQueryToServerOrUseParentQuery(t)):t.isEmptyForJoin=!0,!0}}allOngoingQueriesGotInitialResult(e){return!!e.isEmptyForJoin||!!e.gotInitialResponse&&(!e.supportedQueries.length||e.supportedQueries.every((e=>this.allOngoingQueriesGotInitialResult(e))))}async completeAllSupportedQueries(e){const t=[...e.supportedQueries||[]];for(;t.length;){const e=T(t.shift());t.push(...e.supportedQueries||[]),await(0,b.firstValueFrom)(e.unsubscribeBlockerCount.pipe(ja((e=>0===e)))),e.dataSubject.complete()}}predestruct(){this.safeToSendQueriesToServer.next(!1),this.safeToSendQueriesToServer.complete(),this.unsubscribe()}unsubscribe(){var e;const t=[...this.ongoingQueries.values()];for(const r of t)r.dataSubject.complete(),null===(e=r.allObservables)||void 0===e||e.complete()}hasSubscription(e){var t;return!!(null===(t=this.ongoingQueries.get(e))||void 0===t?void 0:t.subscribe)}sendQueryToServerOrUseParentQuery(e){if(this.destructManager.isDestructing)return;const t=e.query,r=e.clientRequestId,n=y(this.clientIdService.getClientId(),r);this.queryMappingManager.addQuery(Ga,t,n),this.ongoingQueries.set(r,e);const i=this.findValidParentOfOngoingQuery(e);i?this.useParentOngoingQuery(e,i).then():this.sendQueryToServer(e)}async useParentOngoingQuery(e,t){const r={clientRequestId:e.clientRequestId,query:e.query,parentClientRequestId:t.clientRequestId},n=new g(e.query);t.unsubscribeBlockerCount.next(t.unsubscribeBlockerCount.value+1);try{await(0,b.firstValueFrom)(t.queryRegistered.pipe(ja(Boolean)))}catch(t){return e.dataSubject.error(t),e.queryRegistered.error(t),void(e.done=!0)}if(this.destructManager.isDestructing)return;if(e.done)return;this.rpcManager.post("query/register",r).then((()=>{e.queryRegistered.next(!0)})).catch((r=>{console.error("Query error",e.query,t.query,r),e.dataSubject.error(r),e.done=!0})).finally((()=>{t.unsubscribeBlockerCount.next(t.unsubscribeBlockerCount.value-1),e.isInFlight=!1}));const i=(0,b.race)(e.queryRegistered.pipe(ja(Boolean),(0,b.delay)(2e3),(0,b.take)(1)),this.destructManager.observeIsDestructing().pipe((0,b.take)(1)));t.dataSubject.pipe((0,b.takeWhile)((()=>!e.done)),(0,b.takeUntil)(i),ja(Boolean),(0,b.tap)((()=>{e.gotInitialResponse||this.setGotInitialResult(e.clientRequestId)})),qe((e=>e.filter((e=>n.documentMatchesQuery(e)))))).subscribe({next:t=>{for(const r of t)this.setClientRequestIdsForLocalDoc(F(r.__docId__,e.query.collectionName,e.query.integrationId),r);this.notifyAllSubscriptions([e.clientRequestId])},error:t=>e.dataSubject.error(t)})}sendQueryToServer(e){const t={query:e.query,clientRequestId:e.clientRequestId,subscribe:e.subscribe};this.safeToSendQueriesToServer.pipe(ja(Boolean),(0,b.take)(1)).subscribe((()=>{e.done||(this.inflightQueriesCount.next(this.inflightQueriesCount.value+1),e.isInFlight=!0,this.rpcManager.post("query/query",t).catch((t=>{e.dataSubject.error(t),e.done=!0,e.queryRegistered.error("query failed")})).then((()=>{e.queryRegistered.next(!0)})).finally((()=>{this.inflightQueriesCount.next(this.inflightQueriesCount.value-1),e.isInFlight=!1})))}))}refreshOngoingQueries(){for(const e of this.ongoingQueries.values())this.sendQueryToServerOrUseParentQuery(e)}migrateDocIds(e){const t=Object.keys(e);for(const r of this.clientRequestIdToLocalDocuments.values())t.forEach((t=>{r.has(t)&&(r.delete(t),r.add(e[t]))}));t.forEach((t=>{A(this.localDocumentToClientRequestIds,t,e[t])}))}}function Za(e,t){var r;for(const n of e.fields){const e=null!==(r=k(t,n.fieldName))&&void 0!==r?r:null;if(p(n.value,e,n.operator))return!0;if(p(n.value,e,"!="))return!1}return!1}class Xa{constructor(){this.stateService=new Wa,this.querySubscriptionIdToQuery={}}addQuery(e,t,r){this.stateService.runInBatch((()=>{let e=0;const n=new Set;for(const i of t.conditions){if(f(i)&&["=="].includes(i.operator)){const t=h(i.fieldName);n.has(t)||(e++,n.add(t))}else e++;const o=this.getConditionStatePath(t,i),s=[...this.stateService.getStateInPath(o)||[]];H(s,r),this.stateService.setInPath(o,s)}if(!t.conditions.length){const e=["queryMapping",t.collectionName,t.integrationId,"mapping","unconditional"],n=[...this.stateService.getStateInPath(e)||[]];H(n,r),this.stateService.setInPath(e,n)}this.stateService.setInPath([...this.getQueryMetadataStatePath(t,r),"condCount"],e)})),this.querySubscriptionIdToQuery[r]=t}async removeQuery(e,t){const r=this.querySubscriptionIdToQuery[t];if(r)return this.stateService.runInBatch((()=>{for(const e of r.conditions){const n=this.getConditionStatePath(r,e),i=[...this.stateService.getStateInPath(n)||[]];G(i,t),i.length?this.stateService.setInPath(n,i):this.stateService.deletePath(n)}if(!r.conditions.length){const e=["queryMapping",r.collectionName,r.integrationId,"mapping","unconditional"],n=[...this.stateService.getStateInPath(e)||[]];G(n,t),this.stateService.setInPath(e,n)}this.stateService.deletePath(this.getQueryMetadataStatePath(r,t))})),r}getMapping(e,t,r){return this.stateService.getStateInPath(["queryMapping",t,r,"mapping"])}getQueryMetadataStatePath(e,t){return["queryMapping",e.collectionName,e.integrationId,"mapping","queriesMetadata",`${t}`]}getConditionStatePath(e,t){return["queryMapping",e.collectionName,e.integrationId,"mapping","conditional",d(t)]}}class ec{constructor(e,t,r,n,i={},o,s){this.region=e,this.appId=t,this.socketManager=r,this.destructManager=n,this.headers=i,this.authManager=o,this.clientIdService=s,this.staticHeaders={},this.onGoingRpcCounter=new b.BehaviorSubject(0);for(const[e,t]of Object.entries(i))this.setStaticHeader(e,t);const a=this.authManager.getApiKey();a&&this.setStaticHeader("Authorization",`ApiKey ${a}`),this.clientIdService.observeClientId().subscribe((e=>{e?this.setStaticHeader("x-squid-clientid",e):this.deleteStaticHeader("x-squid-clientid")})),this.authManager.observeAuthIdToken().subscribe((e=>{if(e.token){let t=`Bearer ${e.token}`;e.integrationId&&(t+=`; IntegrationId ${e.integrationId}`),this.setStaticHeader("Authorization",t)}else this.deleteStaticHeader("Authorization")})),n.onDestruct((async()=>{await this.awaitAllSettled()}))}async awaitAllSettled(){await(0,b.firstValueFrom)(this.onGoingRpcCounter.pipe((0,b.filter)((e=>0===e))))}setStaticHeader(e,t){this.staticHeaders[e]=t}deleteStaticHeader(e){delete this.staticHeaders[e]}getStaticHeaders(){return this.staticHeaders}async post(e,t){this.onGoingRpcCounter.next(this.onGoingRpcCounter.value+1);try{await(0,b.firstValueFrom)((0,b.race)(this.socketManager.observeConnectionReady().pipe((0,b.filter)(Boolean)),this.destructManager.observeIsDestructing())),await this.authManager.waitForReadyState();let r={"Content-Type":"application/json"};Object.keys(this.staticHeaders)&&(r=Object.assign(Object.assign({},r),this.staticHeaders));const n=X(this.region,this.appId,e),i=await Da()(n,{method:"POST",body:u(t),headers:r});let o,s;try{o=await i.text();try{s=JSON.parse(o)}catch(e){}}catch(e){o="Cannot read body"}if(!i.ok)throw new tc(i.status,i.statusText,i.headers,i.url,null==s?void 0:s.message);return s||o}finally{this.onGoingRpcCounter.next(this.onGoingRpcCounter.value-1)}}}class tc extends Error{constructor(e,t,r,n,i){super(i||`RPC error ${e} ${t} calling ${n}`),this.statusCode=e,this.statusText=t,this.headers=r,this.url=n}}const rc=require("socket.io-client"),nc=e=>e();class ic{constructor(e,t,r,n=nc,i,o={},s){this.clientIdService=e,this.region=t,this.appId=r,this.messageNotificationWrapper=n,this.destructManager=i,this.authManager=s,this.webSocketObserver=new b.Subject,this.allMessagesObserver=new b.Subject,this.connectionReady=new b.BehaviorSubject(!1),this.seenMessageIds=new Set,this.firstConnection=!0,this.clientTooOldThreshold=3e5,this.destructManager.onDestruct((async()=>{await this.destruct()})),this.setupMessageAcknowledgments(),this.connect(Object.assign({},o)),this.connectionReady.pipe((0,b.skip)(1),(0,b.filter)((e=>!e)),(0,b.switchMap)((()=>(0,b.race)((0,b.timer)(this.clientTooOldThreshold),this.connectionReady.pipe((0,b.filter)(Boolean)),this.destructManager.observeIsDestructing())))).subscribe((()=>{this.connectionReady.value||this.destructManager.isDestructing||(this.clientIdService.notifyClientTooOld(),this.connect(Object.assign({},o)))})),this.connectionReady.pipe((0,b.filter)(Boolean)).subscribe((()=>{this.clientIdService.isClientTooOld()&&this.clientIdService.notifyClientReadyToBeRegenerated()}))}observeNotifications(){return this.webSocketObserver.asObservable()}observeConnectionReady(){return this.connectionReady.asObservable().pipe((0,b.distinctUntilChanged)())}sendMessage(e){this.authManager.waitForReadyState().then((()=>{(0,b.firstValueFrom)(this.connectionReady.pipe((0,b.filter)(Boolean))).then((()=>{const t=this.authManager.getAuthToken();T(this.socket).emit("message",Object.assign(Object.assign({},e),{authToken:t}))}))}))}connect(e){const t=X(this.region,this.appId,""),r={clientId:this.clientIdService.getClientId()};this.socket=(0,rc.io)(t,{query:r,reconnectionDelay:5e3,transports:["websocket"],extraHeaders:e}),this.socket.on("connect",(()=>{})),this.socket.on("disconnect",((e,t)=>{this.connectionReady.next(!1)})),this.socket.on("connectionReady",(()=>{this.connectionReady.next(!0),this.firstConnection||this.sendMessage({type:"catchup"}),this.firstConnection=!1})),this.socket.on("message",(e=>{const t=l(e);for(const e of t)this.allMessagesObserver.next(e),this.seenMessageIds.has(e.messageId)||(this.seenMessageIds.add(e.messageId),this.messageNotificationWrapper((()=>{this.webSocketObserver.next(e)})))}))}setupMessageAcknowledgments(){const e=new b.Subject;this.allMessagesObserver.subscribe((t=>{(null==t?void 0:t.messageId)&&e.next(t.messageId)}));const t=[];e.pipe((0,b.tap)((e=>t.push(e))),(0,b.debounceTime)(100)).subscribe((async()=>{const e=[...t.splice(0)];this.sendMessage({type:"acknowledge",payload:e})}))}async destruct(){var e;this.sendMessage({type:"kill"}),this.connectionReady.next(!1),await(0,b.firstValueFrom)((0,b.timer)(0)),null===(e=this.socket)||void 0===e||e.disconnect(),this.webSocketObserver.complete(),this.allMessagesObserver.complete()}}class oc{constructor(e){this.destructManager=new pt,this.setAuthIdToken=(e,t)=>{this.authManager.setAuthIdToken(e,t)},this.collection=(e,r=t.built_in_db)=>(this.validateNotDestructed(),this.collectionReferenceFactory.get(e,r)),this.runInTransaction=e=>(this.validateNotDestructed(),this.dataManager.runInTransaction(e)),this.executeFunction=(e,...t)=>(this.validateNotDestructed(),(0,b.firstValueFrom)(this.backendFunctionManager.executeFunctionAndSubscribe(e,...t))),this.executeNamedQuery=(e,t,r)=>(this.validateNotDestructed(),(0,b.firstValueFrom)(this.namedQueryManager.executeNamedQueryAndSubscribe(e,t,r))),this.callApi=(e,t,r={})=>(this.validateNotDestructed(),(0,b.firstValueFrom)(this.apiManager.callApiAndSubscribe(e,t,r))),this.graphql=e=>(this.validateNotDestructed(),this.graphqlClientFactory.get(e)),this.ai=()=>(this.validateNotDestructed(),{assistant:e=>this.aiClientFactory.getAssistant(e)}),this.acquireLock=(e,t=!0)=>(this.validateNotDestructed(),this.distributedLockManager.lock(e,t)),this.destruct=async()=>{if(!this.destructManager.isDestructing)return this.destructManager.destruct().finally((()=>{const e=Object.entries(oc.squidInstancesMap).find((([,e])=>e===this));e&&delete oc.squidInstancesMap[e[0]]}))},this.connectionDetails=()=>(this.validateNotDestructed(),this._connectionDetails),this.unsubscribe=async()=>{this.querySubscriptionManager.unsubscribe(),await this.rpcManager.awaitAllSettled()},I(e.appId,"APP_ID_MUST_BE_PROVIDED");const r="prod"!==e.environmentId&&e.squidDeveloperId,n=function(e,t,r){return`${C(e,t)}${r?`-${r}`:""}`}(e.appId,e.environmentId,r?e.squidDeveloperId:void 0),i=function(e,t){const r={};return ee(e)&&(r["x-squid-appid"]=t),r}(e.region,n);this.clientIdService=new ct(this.destructManager),this.authManager=new st(this.destructManager,e.apiKey),this.socketManager=new ic(this.clientIdService,e.region,n,e.messageNotificationWrapper,this.destructManager,i,this.authManager),this.rpcManager=new ec(e.region,n,this.socketManager,this.destructManager,i,this.authManager,this.clientIdService),this.documentStore=new bt,this.lockManager=new re,this.distributedLockManager=new mt(this.socketManager,this.destructManager),this.documentIdentityService=new vt(this.documentStore,this.destructManager),this.documentReferenceFactory=new gt(this.documentIdentityService),this.querySubscriptionManager=new Ja(this.rpcManager,this.clientIdService,this.documentStore,this.destructManager,this.documentIdentityService),this.localQueryManager=new Pa(this.documentStore,this.documentReferenceFactory,this.querySubscriptionManager);const o=new Aa(this.rpcManager,this.lockManager,this.querySubscriptionManager);this.queryBuilderFactory=new We(this.querySubscriptionManager,this.localQueryManager,this.documentReferenceFactory,this.documentIdentityService),this.collectionReferenceFactory=new ut(this.documentReferenceFactory,this.queryBuilderFactory,this.querySubscriptionManager),this.dataManager=new dt(this.documentStore,o,this.socketManager,this.querySubscriptionManager,this.queryBuilderFactory,this.lockManager,this.destructManager,this.documentIdentityService),this.documentReferenceFactory.setDataManager(this.dataManager),this.backendFunctionManager=new at(this.clientIdService,this.rpcManager,this.socketManager),this.namedQueryManager=new Ra(this.rpcManager,this.socketManager),this.apiManager=new ot(this.clientIdService,this.rpcManager,this.socketManager,e.apiServerUrlOverrideMapping),this.graphqlClientFactory=new xa(this.rpcManager,e.region,n),this.aiClientFactory=new it(this.rpcManager,this.socketManager),this._connectionDetails=new lt(this.clientIdService,this.socketManager)}static getInstance(e){const t=c(e);let r=oc.squidInstancesMap[t];return r||(r=new oc(e),oc.squidInstancesMap[t]=r,r)}static getInstances(){return Object.values(oc.squidInstancesMap)}validateNotDestructed(){I(!this.destructManager.isDestructing,"The client was already destructed.")}}oc.squidInstancesMap={}})();var i=exports;for(var o in n)i[o]=n[o];n.__esModule&&Object.defineProperty(i,"__esModule",{value:!0})})();
@@ -1,12 +1,12 @@
1
- import { AiAssistantMutationType, AiAssistantResourceType } from './ai-assistant.types';
2
- export declare class AiAssistantChatContext {
3
- readonly prompt: string;
4
- readonly profileId: string;
5
- }
6
- /** A context provided to the security rules of an AI Assistant mutation. */
7
- export declare class AiAssistantMutationContext {
8
- readonly type: AiAssistantMutationType;
9
- readonly resource: AiAssistantResourceType;
10
- readonly profileId: string;
11
- readonly payload: any;
12
- }
1
+ import { AiAssistantMutationType, AiAssistantResourceType } from './ai-assistant.types';
2
+ export declare class AiAssistantChatContext {
3
+ readonly prompt: string;
4
+ readonly profileId: string;
5
+ }
6
+ /** A context provided to the security rules of an AI Assistant mutation. */
7
+ export declare class AiAssistantMutationContext {
8
+ readonly type: AiAssistantMutationType;
9
+ readonly resource: AiAssistantResourceType;
10
+ readonly profileId: string;
11
+ readonly payload: any;
12
+ }
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,12 +1,12 @@
1
- /** The supported Open AI model names. */
2
- export type OpenAiModelName = 'gpt-3.5-turbo' | 'gpt-4';
3
- export type AiAssistantContextType = 'text' | 'url';
4
- export interface AiAssistantTextContext {
5
- type: 'text';
6
- data: string;
7
- }
8
- export interface AiAssistantUrlContext {
9
- type: 'url';
10
- data: string;
11
- }
12
- export type AiAssistantContext = AiAssistantTextContext | AiAssistantUrlContext;
1
+ /** The supported Open AI model names. */
2
+ export type OpenAiModelName = 'gpt-3.5-turbo' | 'gpt-4';
3
+ export type AiAssistantContextType = 'text' | 'url';
4
+ export interface AiAssistantTextContext {
5
+ type: 'text';
6
+ data: string;
7
+ }
8
+ export interface AiAssistantUrlContext {
9
+ type: 'url';
10
+ data: string;
11
+ }
12
+ export type AiAssistantContext = AiAssistantTextContext | AiAssistantUrlContext;
@@ -1,13 +1,13 @@
1
- import { ApiHeaders } from './api.types';
2
- import { ApiEndpointId, HttpMethod } from './integrations';
3
- /** The context of an API call. */
4
- export declare class ApiCallContext {
5
- readonly endpointId: ApiEndpointId;
6
- readonly url: string;
7
- readonly method: HttpMethod;
8
- readonly headers: ApiHeaders;
9
- readonly body: Record<string, any>;
10
- readonly queryParams: Record<string, string | number | boolean>;
11
- readonly pathParams: Record<string, string>;
12
- readonly serverUrlOverride: string | undefined;
13
- }
1
+ import { ApiHeaders } from './api.types';
2
+ import { ApiEndpointId, HttpMethod } from './integrations';
3
+ /** The context of an API call. */
4
+ export declare class ApiCallContext {
5
+ readonly endpointId: ApiEndpointId;
6
+ readonly url: string;
7
+ readonly method: HttpMethod;
8
+ readonly headers: ApiHeaders;
9
+ readonly body: Record<string, any>;
10
+ readonly queryParams: Record<string, string | number | boolean>;
11
+ readonly pathParams: Record<string, string>;
12
+ readonly serverUrlOverride: string | undefined;
13
+ }
@@ -1,4 +1,4 @@
1
- /** The headers of an API call. */
2
- export type ApiHeaders = Record<string, string | number | boolean>;
3
- /** The query parameters of an API call. */
4
- export type ApiQueryParams = Record<string, string | number | boolean>;
1
+ /** The headers of an API call. */
2
+ export type ApiHeaders = Record<string, string | number | boolean>;
3
+ /** The query parameters of an API call. */
4
+ export type ApiQueryParams = Record<string, string | number | boolean>;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,184 +1,184 @@
1
- import { AppId, EnvironmentId, IntegrationId } from './communication.types';
2
- import { AiAssistantConfiguration, GraphQLConnectionOptions, IntegrationAiAssistantSchema, IntegrationApiSchema, IntegrationDataSchema, IntegrationGraphQLSchema, IntegrationType, MongoConnectionOptions, MssqlConnectionOptions, MySqlConnectionOptions, OpenApiDiscoveryOptions, OracleConnectionOptions, PostgresConnectionOptions, SnowflakeConnectionOptions } from './integrations';
3
- /** A type alias for a string that represents a webhook. */
4
- export type WebhookId = string;
5
- /** A type alias for a string that represents a named query. */
6
- export type QueryName = string;
7
- /** A type alias for a string that represents a trigger id. */
8
- export type TriggerId = string;
9
- /** A type alias for a string that represents a scheduler id. */
10
- export type SchedulerId = string;
11
- /** The supported cron expression string. */
12
- export type CronExpressionString = `${string} ${string} ${string} ${string} ${string}` | `${string} ${string} ${string} ${string}`;
13
- /** A set of predefined cron expressions. */
14
- export declare enum CronExpression {
15
- EVERY_SECOND = "* * * * * *",
16
- EVERY_5_SECONDS = "*/5 * * * * *",
17
- EVERY_10_SECONDS = "*/10 * * * * *",
18
- EVERY_30_SECONDS = "*/30 * * * * *",
19
- EVERY_MINUTE = "*/1 * * * *",
20
- EVERY_5_MINUTES = "0 */5 * * * *",
21
- EVERY_10_MINUTES = "0 */10 * * * *",
22
- EVERY_30_MINUTES = "0 */30 * * * *",
23
- EVERY_HOUR = "0 0-23/1 * * *",
24
- EVERY_2_HOURS = "0 0-23/2 * * *",
25
- EVERY_3_HOURS = "0 0-23/3 * * *",
26
- EVERY_4_HOURS = "0 0-23/4 * * *",
27
- EVERY_5_HOURS = "0 0-23/5 * * *",
28
- EVERY_6_HOURS = "0 0-23/6 * * *",
29
- EVERY_7_HOURS = "0 0-23/7 * * *",
30
- EVERY_8_HOURS = "0 0-23/8 * * *",
31
- EVERY_9_HOURS = "0 0-23/9 * * *",
32
- EVERY_10_HOURS = "0 0-23/10 * * *",
33
- EVERY_11_HOURS = "0 0-23/11 * * *",
34
- EVERY_12_HOURS = "0 0-23/12 * * *",
35
- EVERY_DAY_AT_1AM = "0 01 * * *",
36
- EVERY_DAY_AT_2AM = "0 02 * * *",
37
- EVERY_DAY_AT_3AM = "0 03 * * *",
38
- EVERY_DAY_AT_4AM = "0 04 * * *",
39
- EVERY_DAY_AT_5AM = "0 05 * * *",
40
- EVERY_DAY_AT_6AM = "0 06 * * *",
41
- EVERY_DAY_AT_7AM = "0 07 * * *",
42
- EVERY_DAY_AT_8AM = "0 08 * * *",
43
- EVERY_DAY_AT_9AM = "0 09 * * *",
44
- EVERY_DAY_AT_10AM = "0 10 * * *",
45
- EVERY_DAY_AT_11AM = "0 11 * * *",
46
- EVERY_DAY_AT_NOON = "0 12 * * *",
47
- EVERY_DAY_AT_1PM = "0 13 * * *",
48
- EVERY_DAY_AT_2PM = "0 14 * * *",
49
- EVERY_DAY_AT_3PM = "0 15 * * *",
50
- EVERY_DAY_AT_4PM = "0 16 * * *",
51
- EVERY_DAY_AT_5PM = "0 17 * * *",
52
- EVERY_DAY_AT_6PM = "0 18 * * *",
53
- EVERY_DAY_AT_7PM = "0 19 * * *",
54
- EVERY_DAY_AT_8PM = "0 20 * * *",
55
- EVERY_DAY_AT_9PM = "0 21 * * *",
56
- EVERY_DAY_AT_10PM = "0 22 * * *",
57
- EVERY_DAY_AT_11PM = "0 23 * * *",
58
- EVERY_DAY_AT_MIDNIGHT = "0 0 * * *",
59
- EVERY_WEEK = "0 0 * * 0",
60
- EVERY_WEEKDAY = "0 0 * * 1-5",
61
- EVERY_WEEKEND = "0 0 * * 6,0",
62
- EVERY_1ST_DAY_OF_MONTH_AT_MIDNIGHT = "0 0 1 * *",
63
- EVERY_1ST_DAY_OF_MONTH_AT_NOON = "0 12 1 * *",
64
- EVERY_2ND_HOUR = "0 */2 * * *",
65
- EVERY_2ND_HOUR_FROM_1AM_THROUGH_11PM = "0 1-23/2 * * *",
66
- EVERY_2ND_MONTH = "0 0 1 */2 *",
67
- EVERY_QUARTER = "0 0 1 */3 *",
68
- EVERY_6_MONTHS = "0 0 1 */6 *",
69
- EVERY_YEAR = "0 0 1 0 *",
70
- EVERY_30_MINUTES_BETWEEN_9AM_AND_5PM = "0 */30 9-17 * * *",
71
- EVERY_30_MINUTES_BETWEEN_9AM_AND_6PM = "0 */30 9-18 * * *",
72
- EVERY_30_MINUTES_BETWEEN_10AM_AND_7PM = "0 */30 10-19 * * *",
73
- MONDAY_TO_FRIDAY_AT_1AM = "0 0 01 * * 1-5",
74
- MONDAY_TO_FRIDAY_AT_2AM = "0 0 02 * * 1-5",
75
- MONDAY_TO_FRIDAY_AT_3AM = "0 0 03 * * 1-5",
76
- MONDAY_TO_FRIDAY_AT_4AM = "0 0 04 * * 1-5",
77
- MONDAY_TO_FRIDAY_AT_5AM = "0 0 05 * * 1-5",
78
- MONDAY_TO_FRIDAY_AT_6AM = "0 0 06 * * 1-5",
79
- MONDAY_TO_FRIDAY_AT_7AM = "0 0 07 * * 1-5",
80
- MONDAY_TO_FRIDAY_AT_8AM = "0 0 08 * * 1-5",
81
- MONDAY_TO_FRIDAY_AT_9AM = "0 0 09 * * 1-5",
82
- MONDAY_TO_FRIDAY_AT_09_30AM = "0 30 09 * * 1-5",
83
- MONDAY_TO_FRIDAY_AT_10AM = "0 0 10 * * 1-5",
84
- MONDAY_TO_FRIDAY_AT_11AM = "0 0 11 * * 1-5",
85
- MONDAY_TO_FRIDAY_AT_11_30AM = "0 30 11 * * 1-5",
86
- MONDAY_TO_FRIDAY_AT_12PM = "0 0 12 * * 1-5",
87
- MONDAY_TO_FRIDAY_AT_1PM = "0 0 13 * * 1-5",
88
- MONDAY_TO_FRIDAY_AT_2PM = "0 0 14 * * 1-5",
89
- MONDAY_TO_FRIDAY_AT_3PM = "0 0 15 * * 1-5",
90
- MONDAY_TO_FRIDAY_AT_4PM = "0 0 16 * * 1-5",
91
- MONDAY_TO_FRIDAY_AT_5PM = "0 0 17 * * 1-5",
92
- MONDAY_TO_FRIDAY_AT_6PM = "0 0 18 * * 1-5",
93
- MONDAY_TO_FRIDAY_AT_7PM = "0 0 19 * * 1-5",
94
- MONDAY_TO_FRIDAY_AT_8PM = "0 0 20 * * 1-5",
95
- MONDAY_TO_FRIDAY_AT_9PM = "0 0 21 * * 1-5",
96
- MONDAY_TO_FRIDAY_AT_10PM = "0 0 22 * * 1-5",
97
- MONDAY_TO_FRIDAY_AT_11PM = "0 0 23 * * 1-5"
98
- }
99
- interface BaseUpsertDataIntegrationRequest extends BaseUpsertIntegrationRequest {
100
- supportsExternalChanges?: boolean;
101
- }
102
- export interface UpsertInternalIntegrationRequest extends BaseUpsertDataIntegrationRequest {
103
- type: IntegrationType.built_in_db;
104
- schema?: IntegrationDataSchema;
105
- }
106
- export interface UpsertMongoDbIntegrationRequest extends BaseUpsertDataIntegrationRequest {
107
- type: IntegrationType.mongo;
108
- schema?: IntegrationDataSchema;
109
- configuration: {
110
- connectionOptions: MongoConnectionOptions;
111
- };
112
- }
113
- export interface UpsertMySqlIntegrationRequest extends BaseUpsertDataIntegrationRequest {
114
- type: IntegrationType.mysql;
115
- schema?: IntegrationDataSchema;
116
- configuration: {
117
- connectionOptions: MySqlConnectionOptions;
118
- };
119
- }
120
- export interface UpsertOracleIntegrationRequest extends BaseUpsertDataIntegrationRequest {
121
- type: IntegrationType.oracledb;
122
- schema?: IntegrationDataSchema;
123
- configuration: {
124
- connectionOptions: OracleConnectionOptions;
125
- };
126
- }
127
- export interface UpsertMssqlIntegrationRequest extends BaseUpsertDataIntegrationRequest {
128
- type: IntegrationType.mssql;
129
- schema?: IntegrationDataSchema;
130
- configuration: {
131
- connectionOptions: MssqlConnectionOptions;
132
- };
133
- }
134
- export interface UpsertPostgresIntegrationRequest extends BaseUpsertDataIntegrationRequest {
135
- type: IntegrationType.postgres;
136
- schema?: IntegrationDataSchema;
137
- configuration: {
138
- connectionOptions: PostgresConnectionOptions;
139
- };
140
- }
141
- export interface UpsertCockroachIntegrationRequest extends BaseUpsertDataIntegrationRequest {
142
- type: IntegrationType.cockroach;
143
- schema?: IntegrationDataSchema;
144
- configuration: {
145
- connectionOptions: PostgresConnectionOptions;
146
- };
147
- }
148
- export interface UpsertSnowflakeIntegrationRequest extends BaseUpsertDataIntegrationRequest {
149
- type: IntegrationType.snowflake;
150
- schema?: IntegrationDataSchema;
151
- configuration: {
152
- connectionOptions: SnowflakeConnectionOptions;
153
- };
154
- }
155
- export interface UpsertGraphQLIntegrationRequest extends BaseUpsertIntegrationRequest {
156
- type: IntegrationType.graphql;
157
- schema?: IntegrationGraphQLSchema;
158
- configuration: {
159
- connectionOptions: GraphQLConnectionOptions;
160
- };
161
- }
162
- export interface UpsertApiIntegrationRequest extends BaseUpsertIntegrationRequest {
163
- type: IntegrationType.api;
164
- schema?: IntegrationApiSchema;
165
- configuration?: {
166
- discoveryOptions: OpenApiDiscoveryOptions;
167
- };
168
- }
169
- export interface UpsertAiAssistantIntegrationRequest extends BaseUpsertIntegrationRequest {
170
- type: IntegrationType.ai_assistant;
171
- schema?: IntegrationAiAssistantSchema;
172
- configuration: AiAssistantConfiguration;
173
- }
174
- export interface DeleteIntegrationRequest {
175
- integrationId: IntegrationId;
176
- }
177
- export interface UpdateAllowedHostsRequest {
178
- allowedHosts: string[];
179
- }
180
- export interface CreateEnvironmentRequest {
181
- sourceAppId: AppId;
182
- environmentId: EnvironmentId;
183
- }
184
- export {};
1
+ import { AppId, EnvironmentId, IntegrationId } from './communication.types';
2
+ import { AiAssistantConfiguration, GraphQLConnectionOptions, IntegrationAiAssistantSchema, IntegrationApiSchema, IntegrationDataSchema, IntegrationGraphQLSchema, IntegrationType, MongoConnectionOptions, MssqlConnectionOptions, MySqlConnectionOptions, OpenApiDiscoveryOptions, OracleConnectionOptions, PostgresConnectionOptions, SnowflakeConnectionOptions } from './integrations';
3
+ /** A type alias for a string that represents a webhook. */
4
+ export type WebhookId = string;
5
+ /** A type alias for a string that represents a named query. */
6
+ export type QueryName = string;
7
+ /** A type alias for a string that represents a trigger id. */
8
+ export type TriggerId = string;
9
+ /** A type alias for a string that represents a scheduler id. */
10
+ export type SchedulerId = string;
11
+ /** The supported cron expression string. */
12
+ export type CronExpressionString = `${string} ${string} ${string} ${string} ${string}` | `${string} ${string} ${string} ${string}`;
13
+ /** A set of predefined cron expressions. */
14
+ export declare enum CronExpression {
15
+ EVERY_SECOND = "* * * * * *",
16
+ EVERY_5_SECONDS = "*/5 * * * * *",
17
+ EVERY_10_SECONDS = "*/10 * * * * *",
18
+ EVERY_30_SECONDS = "*/30 * * * * *",
19
+ EVERY_MINUTE = "*/1 * * * *",
20
+ EVERY_5_MINUTES = "0 */5 * * * *",
21
+ EVERY_10_MINUTES = "0 */10 * * * *",
22
+ EVERY_30_MINUTES = "0 */30 * * * *",
23
+ EVERY_HOUR = "0 0-23/1 * * *",
24
+ EVERY_2_HOURS = "0 0-23/2 * * *",
25
+ EVERY_3_HOURS = "0 0-23/3 * * *",
26
+ EVERY_4_HOURS = "0 0-23/4 * * *",
27
+ EVERY_5_HOURS = "0 0-23/5 * * *",
28
+ EVERY_6_HOURS = "0 0-23/6 * * *",
29
+ EVERY_7_HOURS = "0 0-23/7 * * *",
30
+ EVERY_8_HOURS = "0 0-23/8 * * *",
31
+ EVERY_9_HOURS = "0 0-23/9 * * *",
32
+ EVERY_10_HOURS = "0 0-23/10 * * *",
33
+ EVERY_11_HOURS = "0 0-23/11 * * *",
34
+ EVERY_12_HOURS = "0 0-23/12 * * *",
35
+ EVERY_DAY_AT_1AM = "0 01 * * *",
36
+ EVERY_DAY_AT_2AM = "0 02 * * *",
37
+ EVERY_DAY_AT_3AM = "0 03 * * *",
38
+ EVERY_DAY_AT_4AM = "0 04 * * *",
39
+ EVERY_DAY_AT_5AM = "0 05 * * *",
40
+ EVERY_DAY_AT_6AM = "0 06 * * *",
41
+ EVERY_DAY_AT_7AM = "0 07 * * *",
42
+ EVERY_DAY_AT_8AM = "0 08 * * *",
43
+ EVERY_DAY_AT_9AM = "0 09 * * *",
44
+ EVERY_DAY_AT_10AM = "0 10 * * *",
45
+ EVERY_DAY_AT_11AM = "0 11 * * *",
46
+ EVERY_DAY_AT_NOON = "0 12 * * *",
47
+ EVERY_DAY_AT_1PM = "0 13 * * *",
48
+ EVERY_DAY_AT_2PM = "0 14 * * *",
49
+ EVERY_DAY_AT_3PM = "0 15 * * *",
50
+ EVERY_DAY_AT_4PM = "0 16 * * *",
51
+ EVERY_DAY_AT_5PM = "0 17 * * *",
52
+ EVERY_DAY_AT_6PM = "0 18 * * *",
53
+ EVERY_DAY_AT_7PM = "0 19 * * *",
54
+ EVERY_DAY_AT_8PM = "0 20 * * *",
55
+ EVERY_DAY_AT_9PM = "0 21 * * *",
56
+ EVERY_DAY_AT_10PM = "0 22 * * *",
57
+ EVERY_DAY_AT_11PM = "0 23 * * *",
58
+ EVERY_DAY_AT_MIDNIGHT = "0 0 * * *",
59
+ EVERY_WEEK = "0 0 * * 0",
60
+ EVERY_WEEKDAY = "0 0 * * 1-5",
61
+ EVERY_WEEKEND = "0 0 * * 6,0",
62
+ EVERY_1ST_DAY_OF_MONTH_AT_MIDNIGHT = "0 0 1 * *",
63
+ EVERY_1ST_DAY_OF_MONTH_AT_NOON = "0 12 1 * *",
64
+ EVERY_2ND_HOUR = "0 */2 * * *",
65
+ EVERY_2ND_HOUR_FROM_1AM_THROUGH_11PM = "0 1-23/2 * * *",
66
+ EVERY_2ND_MONTH = "0 0 1 */2 *",
67
+ EVERY_QUARTER = "0 0 1 */3 *",
68
+ EVERY_6_MONTHS = "0 0 1 */6 *",
69
+ EVERY_YEAR = "0 0 1 0 *",
70
+ EVERY_30_MINUTES_BETWEEN_9AM_AND_5PM = "0 */30 9-17 * * *",
71
+ EVERY_30_MINUTES_BETWEEN_9AM_AND_6PM = "0 */30 9-18 * * *",
72
+ EVERY_30_MINUTES_BETWEEN_10AM_AND_7PM = "0 */30 10-19 * * *",
73
+ MONDAY_TO_FRIDAY_AT_1AM = "0 0 01 * * 1-5",
74
+ MONDAY_TO_FRIDAY_AT_2AM = "0 0 02 * * 1-5",
75
+ MONDAY_TO_FRIDAY_AT_3AM = "0 0 03 * * 1-5",
76
+ MONDAY_TO_FRIDAY_AT_4AM = "0 0 04 * * 1-5",
77
+ MONDAY_TO_FRIDAY_AT_5AM = "0 0 05 * * 1-5",
78
+ MONDAY_TO_FRIDAY_AT_6AM = "0 0 06 * * 1-5",
79
+ MONDAY_TO_FRIDAY_AT_7AM = "0 0 07 * * 1-5",
80
+ MONDAY_TO_FRIDAY_AT_8AM = "0 0 08 * * 1-5",
81
+ MONDAY_TO_FRIDAY_AT_9AM = "0 0 09 * * 1-5",
82
+ MONDAY_TO_FRIDAY_AT_09_30AM = "0 30 09 * * 1-5",
83
+ MONDAY_TO_FRIDAY_AT_10AM = "0 0 10 * * 1-5",
84
+ MONDAY_TO_FRIDAY_AT_11AM = "0 0 11 * * 1-5",
85
+ MONDAY_TO_FRIDAY_AT_11_30AM = "0 30 11 * * 1-5",
86
+ MONDAY_TO_FRIDAY_AT_12PM = "0 0 12 * * 1-5",
87
+ MONDAY_TO_FRIDAY_AT_1PM = "0 0 13 * * 1-5",
88
+ MONDAY_TO_FRIDAY_AT_2PM = "0 0 14 * * 1-5",
89
+ MONDAY_TO_FRIDAY_AT_3PM = "0 0 15 * * 1-5",
90
+ MONDAY_TO_FRIDAY_AT_4PM = "0 0 16 * * 1-5",
91
+ MONDAY_TO_FRIDAY_AT_5PM = "0 0 17 * * 1-5",
92
+ MONDAY_TO_FRIDAY_AT_6PM = "0 0 18 * * 1-5",
93
+ MONDAY_TO_FRIDAY_AT_7PM = "0 0 19 * * 1-5",
94
+ MONDAY_TO_FRIDAY_AT_8PM = "0 0 20 * * 1-5",
95
+ MONDAY_TO_FRIDAY_AT_9PM = "0 0 21 * * 1-5",
96
+ MONDAY_TO_FRIDAY_AT_10PM = "0 0 22 * * 1-5",
97
+ MONDAY_TO_FRIDAY_AT_11PM = "0 0 23 * * 1-5"
98
+ }
99
+ interface BaseUpsertDataIntegrationRequest extends BaseUpsertIntegrationRequest {
100
+ supportsExternalChanges?: boolean;
101
+ }
102
+ export interface UpsertInternalIntegrationRequest extends BaseUpsertDataIntegrationRequest {
103
+ type: IntegrationType.built_in_db;
104
+ schema?: IntegrationDataSchema;
105
+ }
106
+ export interface UpsertMongoDbIntegrationRequest extends BaseUpsertDataIntegrationRequest {
107
+ type: IntegrationType.mongo;
108
+ schema?: IntegrationDataSchema;
109
+ configuration: {
110
+ connectionOptions: MongoConnectionOptions;
111
+ };
112
+ }
113
+ export interface UpsertMySqlIntegrationRequest extends BaseUpsertDataIntegrationRequest {
114
+ type: IntegrationType.mysql;
115
+ schema?: IntegrationDataSchema;
116
+ configuration: {
117
+ connectionOptions: MySqlConnectionOptions;
118
+ };
119
+ }
120
+ export interface UpsertOracleIntegrationRequest extends BaseUpsertDataIntegrationRequest {
121
+ type: IntegrationType.oracledb;
122
+ schema?: IntegrationDataSchema;
123
+ configuration: {
124
+ connectionOptions: OracleConnectionOptions;
125
+ };
126
+ }
127
+ export interface UpsertMssqlIntegrationRequest extends BaseUpsertDataIntegrationRequest {
128
+ type: IntegrationType.mssql;
129
+ schema?: IntegrationDataSchema;
130
+ configuration: {
131
+ connectionOptions: MssqlConnectionOptions;
132
+ };
133
+ }
134
+ export interface UpsertPostgresIntegrationRequest extends BaseUpsertDataIntegrationRequest {
135
+ type: IntegrationType.postgres;
136
+ schema?: IntegrationDataSchema;
137
+ configuration: {
138
+ connectionOptions: PostgresConnectionOptions;
139
+ };
140
+ }
141
+ export interface UpsertCockroachIntegrationRequest extends BaseUpsertDataIntegrationRequest {
142
+ type: IntegrationType.cockroach;
143
+ schema?: IntegrationDataSchema;
144
+ configuration: {
145
+ connectionOptions: PostgresConnectionOptions;
146
+ };
147
+ }
148
+ export interface UpsertSnowflakeIntegrationRequest extends BaseUpsertDataIntegrationRequest {
149
+ type: IntegrationType.snowflake;
150
+ schema?: IntegrationDataSchema;
151
+ configuration: {
152
+ connectionOptions: SnowflakeConnectionOptions;
153
+ };
154
+ }
155
+ export interface UpsertGraphQLIntegrationRequest extends BaseUpsertIntegrationRequest {
156
+ type: IntegrationType.graphql;
157
+ schema?: IntegrationGraphQLSchema;
158
+ configuration: {
159
+ connectionOptions: GraphQLConnectionOptions;
160
+ };
161
+ }
162
+ export interface UpsertApiIntegrationRequest extends BaseUpsertIntegrationRequest {
163
+ type: IntegrationType.api;
164
+ schema?: IntegrationApiSchema;
165
+ configuration?: {
166
+ discoveryOptions: OpenApiDiscoveryOptions;
167
+ };
168
+ }
169
+ export interface UpsertAiAssistantIntegrationRequest extends BaseUpsertIntegrationRequest {
170
+ type: IntegrationType.ai_assistant;
171
+ schema?: IntegrationAiAssistantSchema;
172
+ configuration: AiAssistantConfiguration;
173
+ }
174
+ export interface DeleteIntegrationRequest {
175
+ integrationId: IntegrationId;
176
+ }
177
+ export interface UpdateAllowedHostsRequest {
178
+ allowedHosts: string[];
179
+ }
180
+ export interface CreateEnvironmentRequest {
181
+ sourceAppId: AppId;
182
+ environmentId: EnvironmentId;
183
+ }
184
+ export {};
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,2 +1,2 @@
1
- import { ApplicationSecrets } from './secret.types';
2
- export declare function convertToRunSecrets(appSecrets: ApplicationSecrets): RunSecrets;
1
+ import { ApplicationSecrets } from './secret.types';
2
+ export declare function convertToRunSecrets(appSecrets: ApplicationSecrets): RunSecrets;