@osdk/client 2.1.1 → 2.2.0-beta.10
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/CHANGELOG.md +129 -181
- package/build/browser/Client.js +1 -1
- package/build/browser/Client.js.map +1 -1
- package/build/browser/MinimalClientContext.js.map +1 -1
- package/build/browser/actions/ActionValidationError.js +1 -1
- package/build/browser/actions/ActionValidationError.js.map +1 -1
- package/build/browser/actions/actions.test.js +164 -87
- package/build/browser/actions/actions.test.js.map +1 -1
- package/build/browser/actions/applyAction.js +21 -15
- package/build/browser/actions/applyAction.js.map +1 -1
- package/build/browser/createClient.js +19 -8
- package/build/browser/createClient.js.map +1 -1
- package/build/browser/createClient.test.js +14 -6
- package/build/browser/createClient.test.js.map +1 -1
- package/build/browser/createMinimalClient.js +2 -2
- package/build/browser/createMinimalClient.js.map +1 -1
- package/build/browser/createMinimalClientHelper.js +25 -0
- package/build/browser/createMinimalClientHelper.js.map +1 -0
- package/build/browser/derivedProperties/createWithPropertiesObjectSet.js +106 -0
- package/build/browser/derivedProperties/createWithPropertiesObjectSet.js.map +1 -0
- package/build/browser/derivedProperties/createWithPropertiesObjectSet.test.js +100 -0
- package/build/browser/derivedProperties/createWithPropertiesObjectSet.test.js.map +1 -0
- package/build/browser/fetchMetadata.test.js +11 -9
- package/build/browser/fetchMetadata.test.js.map +1 -1
- package/build/browser/index.js +1 -0
- package/build/browser/index.js.map +1 -1
- package/build/browser/intellisense.test.js +5 -1
- package/build/browser/intellisense.test.js.map +1 -1
- package/build/browser/internal/conversions/modernToLegacyGroupByClause.js +7 -0
- package/build/browser/internal/conversions/modernToLegacyGroupByClause.js.map +1 -1
- package/build/browser/internal/conversions/modernToLegacyWhereClause.js +1 -1
- package/build/browser/internal/conversions/modernToLegacyWhereClause.js.map +1 -1
- package/build/browser/logger/BaseLogger.js +53 -0
- package/build/browser/logger/BaseLogger.js.map +1 -0
- package/build/{esm → browser/logger}/Logger.js.map +1 -1
- package/build/browser/logger/MinimalLogger.js +41 -0
- package/build/browser/logger/MinimalLogger.js.map +1 -0
- package/build/browser/object/AttachmentUpload.js +3 -0
- package/build/browser/object/AttachmentUpload.js.map +1 -1
- package/build/browser/object/SimpleOsdkProperties.js +2 -0
- package/build/browser/object/SimpleOsdkProperties.js.map +1 -0
- package/build/browser/object/aggregate.test.js +12 -2
- package/build/browser/object/aggregate.test.js.map +1 -1
- package/build/browser/object/attachment.test.js +20 -7
- package/build/browser/object/attachment.test.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/BaseHolder.js +2 -0
- package/build/browser/object/convertWireToOsdkObjects/BaseHolder.js.map +1 -0
- package/build/browser/object/convertWireToOsdkObjects/InterfaceHolder.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/ObjectHolder.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/createOsdkInterface.js +25 -0
- package/build/browser/object/convertWireToOsdkObjects/createOsdkInterface.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/createOsdkObject.js +10 -3
- package/build/browser/object/convertWireToOsdkObjects/createOsdkObject.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/getDollarAs.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/getDollarLink.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects.js +13 -4
- package/build/browser/object/convertWireToOsdkObjects.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects.test.js +17 -11
- package/build/browser/object/convertWireToOsdkObjects.test.js.map +1 -1
- package/build/{esm/observable/internal/ChangedObjects.js → browser/object/createObjectSpecifierFromPrimaryKey.js} +3 -7
- package/build/browser/object/createObjectSpecifierFromPrimaryKey.js.map +1 -0
- package/build/browser/object/fetchPage.js +13 -1
- package/build/browser/object/fetchPage.js.map +1 -1
- package/build/browser/object/fetchPage.test.js +56 -2
- package/build/browser/object/fetchPage.test.js.map +1 -1
- package/build/browser/object/geotimeseriesreference.test.js +56 -134
- package/build/browser/object/geotimeseriesreference.test.js.map +1 -1
- package/build/browser/object/media.test.js +19 -14
- package/build/browser/object/media.test.js.map +1 -1
- package/build/browser/object/object.test.js +166 -66
- package/build/browser/object/object.test.js.map +1 -1
- package/build/browser/object/timeseries.test.js +119 -85
- package/build/browser/object/timeseries.test.js.map +1 -1
- package/build/browser/objectSet/InterfaceObjectSet.test.js +37 -17
- package/build/browser/objectSet/InterfaceObjectSet.test.js.map +1 -1
- package/build/browser/objectSet/ObjectSet.test.js +313 -79
- package/build/browser/objectSet/ObjectSet.test.js.map +1 -1
- package/build/browser/objectSet/ObjectSetListenerWebsocket.js +18 -14
- package/build/browser/objectSet/ObjectSetListenerWebsocket.js.map +1 -1
- package/build/browser/objectSet/ObjectSetListenerWebsocket.test.js +16 -9
- package/build/browser/objectSet/ObjectSetListenerWebsocket.test.js.map +1 -1
- package/build/browser/objectSet/createObjectSet.js +16 -0
- package/build/browser/objectSet/createObjectSet.js.map +1 -1
- package/build/browser/observable/ListPayload.js.map +1 -1
- package/build/browser/observable/ObjectPayload.js.map +1 -1
- package/build/browser/observable/ObservableClient.js.map +1 -1
- package/build/browser/observable/OptimisticBuilder.js.map +1 -1
- package/build/browser/observable/internal/ActionApplication.js +102 -0
- package/build/browser/observable/internal/ActionApplication.js.map +1 -0
- package/build/browser/observable/internal/BulkObjectLoader.js +93 -0
- package/build/browser/observable/internal/BulkObjectLoader.js.map +1 -0
- package/build/browser/observable/internal/BulkObjectLoader.test.js +112 -0
- package/build/browser/observable/internal/BulkObjectLoader.test.js.map +1 -0
- package/build/browser/observable/internal/CacheKey.js +38 -1
- package/build/browser/observable/internal/CacheKey.js.map +1 -1
- package/build/browser/observable/internal/CacheKeys.js +4 -4
- package/build/browser/observable/internal/CacheKeys.js.map +1 -1
- package/build/browser/observable/internal/Changes.js +58 -0
- package/build/browser/observable/internal/Changes.js.map +1 -0
- package/build/browser/observable/internal/Layer.js +6 -3
- package/build/browser/observable/internal/Layer.js.map +1 -1
- package/build/browser/observable/internal/ListQuery.js +495 -129
- package/build/browser/observable/internal/ListQuery.js.map +1 -1
- package/build/browser/observable/internal/ObjectQuery.js +40 -14
- package/build/browser/observable/internal/ObjectQuery.js.map +1 -1
- package/build/browser/observable/internal/ObservableClientImpl.js +4 -12
- package/build/browser/observable/internal/ObservableClientImpl.js.map +1 -1
- package/build/browser/observable/internal/OptimisticJob.js +30 -29
- package/build/browser/observable/internal/OptimisticJob.js.map +1 -1
- package/build/browser/observable/internal/OrderByCanonicalizer.js +73 -0
- package/build/browser/observable/internal/OrderByCanonicalizer.js.map +1 -0
- package/build/browser/observable/internal/OrderByCanonicalizer.test.js +78 -0
- package/build/browser/observable/internal/OrderByCanonicalizer.test.js.map +1 -0
- package/build/browser/observable/internal/Query.js +79 -6
- package/build/browser/observable/internal/Query.js.map +1 -1
- package/build/browser/observable/internal/RefCounts.js +7 -2
- package/build/browser/observable/internal/RefCounts.js.map +1 -1
- package/build/browser/observable/internal/SimpleWhereClause.js +2 -0
- package/build/browser/observable/internal/SimpleWhereClause.js.map +1 -0
- package/build/browser/observable/internal/Store.js +138 -188
- package/build/browser/observable/internal/Store.js.map +1 -1
- package/build/browser/observable/internal/Store.test.js +664 -255
- package/build/browser/observable/internal/Store.test.js.map +1 -1
- package/build/browser/observable/internal/WhereClauseCanonicalizer.js +11 -3
- package/build/browser/observable/internal/WhereClauseCanonicalizer.js.map +1 -1
- package/build/browser/observable/internal/objectMatchesWhereClause.js +0 -4
- package/build/browser/observable/internal/objectMatchesWhereClause.js.map +1 -1
- package/build/browser/observable/internal/objectMatchesWhereClause.test.js.map +1 -1
- package/build/browser/observable/internal/testUtils.js +222 -19
- package/build/browser/observable/internal/testUtils.js.map +1 -1
- package/build/browser/ontology/StandardOntologyProvider.test.js +17 -16
- package/build/browser/ontology/StandardOntologyProvider.test.js.map +1 -1
- package/build/browser/public/unstable-do-not-use.js.map +1 -1
- package/build/browser/queries/applyQuery.js +33 -1
- package/build/browser/queries/applyQuery.js.map +1 -1
- package/build/browser/queries/queries.test.js +36 -13
- package/build/browser/queries/queries.test.js.map +1 -1
- package/build/browser/tsserver.js.map +1 -1
- package/build/browser/util/UserAgent.js +1 -1
- package/build/browser/util/UserAgent.js.map +1 -1
- package/build/browser/util/toDataValue.js +10 -2
- package/build/browser/util/toDataValue.js.map +1 -1
- package/build/browser/util/toDataValue.test.js +37 -16
- package/build/browser/util/toDataValue.test.js.map +1 -1
- package/build/browser/util/toDataValueQueries.js +27 -2
- package/build/browser/util/toDataValueQueries.js.map +1 -1
- package/build/cjs/{Client-C8K3E1vH.d.cts → Client-DBTcM9gB.d.cts} +1 -1
- package/build/cjs/{chunk-FWVJ2AKD.cjs → chunk-EY52J5Z4.cjs} +25 -15
- package/build/cjs/chunk-EY52J5Z4.cjs.map +1 -0
- package/build/cjs/{chunk-DLSRNRTA.cjs → chunk-MCQVHD2F.cjs} +155 -42
- package/build/cjs/chunk-MCQVHD2F.cjs.map +1 -0
- package/build/cjs/chunk-T4NIFYZS.cjs +14 -0
- package/build/cjs/chunk-T4NIFYZS.cjs.map +1 -0
- package/build/cjs/{graphql-JJX5MZPQ.cjs → graphql-RGM5SRWV.cjs} +43 -2
- package/build/cjs/graphql-RGM5SRWV.cjs.map +1 -0
- package/build/cjs/index.cjs +265 -94
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +6 -4
- package/build/cjs/public/internal.cjs +6 -6
- package/build/cjs/public/internal.d.cts +1 -1
- package/build/cjs/public/unstable-do-not-use.cjs +1087 -470
- package/build/cjs/public/unstable-do-not-use.cjs.map +1 -1
- package/build/cjs/public/unstable-do-not-use.d.cts +37 -27
- package/build/esm/Client.js +1 -1
- package/build/esm/Client.js.map +1 -1
- package/build/esm/MinimalClientContext.js.map +1 -1
- package/build/esm/actions/ActionValidationError.js +1 -1
- package/build/esm/actions/ActionValidationError.js.map +1 -1
- package/build/esm/actions/actions.test.js +164 -87
- package/build/esm/actions/actions.test.js.map +1 -1
- package/build/esm/actions/applyAction.js +21 -15
- package/build/esm/actions/applyAction.js.map +1 -1
- package/build/esm/createClient.js +19 -8
- package/build/esm/createClient.js.map +1 -1
- package/build/esm/createClient.test.js +14 -6
- package/build/esm/createClient.test.js.map +1 -1
- package/build/esm/createMinimalClient.js +2 -2
- package/build/esm/createMinimalClient.js.map +1 -1
- package/build/esm/createMinimalClientHelper.js +25 -0
- package/build/esm/createMinimalClientHelper.js.map +1 -0
- package/build/esm/derivedProperties/createWithPropertiesObjectSet.js +106 -0
- package/build/esm/derivedProperties/createWithPropertiesObjectSet.js.map +1 -0
- package/build/esm/derivedProperties/createWithPropertiesObjectSet.test.js +100 -0
- package/build/esm/derivedProperties/createWithPropertiesObjectSet.test.js.map +1 -0
- package/build/esm/fetchMetadata.test.js +11 -9
- package/build/esm/fetchMetadata.test.js.map +1 -1
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/intellisense.test.js +5 -1
- package/build/esm/intellisense.test.js.map +1 -1
- package/build/esm/internal/conversions/modernToLegacyGroupByClause.js +7 -0
- package/build/esm/internal/conversions/modernToLegacyGroupByClause.js.map +1 -1
- package/build/esm/internal/conversions/modernToLegacyWhereClause.js +1 -1
- package/build/esm/internal/conversions/modernToLegacyWhereClause.js.map +1 -1
- package/build/esm/logger/BaseLogger.js +53 -0
- package/build/esm/logger/BaseLogger.js.map +1 -0
- package/build/{browser → esm/logger}/Logger.js.map +1 -1
- package/build/esm/logger/MinimalLogger.js +41 -0
- package/build/esm/logger/MinimalLogger.js.map +1 -0
- package/build/esm/object/AttachmentUpload.js +3 -0
- package/build/esm/object/AttachmentUpload.js.map +1 -1
- package/build/esm/object/SimpleOsdkProperties.js +2 -0
- package/build/esm/object/SimpleOsdkProperties.js.map +1 -0
- package/build/esm/object/aggregate.test.js +12 -2
- package/build/esm/object/aggregate.test.js.map +1 -1
- package/build/esm/object/attachment.test.js +20 -7
- package/build/esm/object/attachment.test.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/BaseHolder.js +2 -0
- package/build/esm/object/convertWireToOsdkObjects/BaseHolder.js.map +1 -0
- package/build/esm/object/convertWireToOsdkObjects/InterfaceHolder.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/ObjectHolder.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/createOsdkInterface.js +25 -0
- package/build/esm/object/convertWireToOsdkObjects/createOsdkInterface.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/createOsdkObject.js +10 -3
- package/build/esm/object/convertWireToOsdkObjects/createOsdkObject.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/getDollarAs.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/getDollarLink.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects.js +13 -4
- package/build/esm/object/convertWireToOsdkObjects.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects.test.js +17 -11
- package/build/esm/object/convertWireToOsdkObjects.test.js.map +1 -1
- package/build/{browser/observable/internal/ChangedObjects.js → esm/object/createObjectSpecifierFromPrimaryKey.js} +3 -7
- package/build/esm/object/createObjectSpecifierFromPrimaryKey.js.map +1 -0
- package/build/esm/object/fetchPage.js +13 -1
- package/build/esm/object/fetchPage.js.map +1 -1
- package/build/esm/object/fetchPage.test.js +56 -2
- package/build/esm/object/fetchPage.test.js.map +1 -1
- package/build/esm/object/geotimeseriesreference.test.js +56 -134
- package/build/esm/object/geotimeseriesreference.test.js.map +1 -1
- package/build/esm/object/media.test.js +19 -14
- package/build/esm/object/media.test.js.map +1 -1
- package/build/esm/object/object.test.js +166 -66
- package/build/esm/object/object.test.js.map +1 -1
- package/build/esm/object/timeseries.test.js +119 -85
- package/build/esm/object/timeseries.test.js.map +1 -1
- package/build/esm/objectSet/InterfaceObjectSet.test.js +37 -17
- package/build/esm/objectSet/InterfaceObjectSet.test.js.map +1 -1
- package/build/esm/objectSet/ObjectSet.test.js +313 -79
- package/build/esm/objectSet/ObjectSet.test.js.map +1 -1
- package/build/esm/objectSet/ObjectSetListenerWebsocket.js +18 -14
- package/build/esm/objectSet/ObjectSetListenerWebsocket.js.map +1 -1
- package/build/esm/objectSet/ObjectSetListenerWebsocket.test.js +16 -9
- package/build/esm/objectSet/ObjectSetListenerWebsocket.test.js.map +1 -1
- package/build/esm/objectSet/createObjectSet.js +16 -0
- package/build/esm/objectSet/createObjectSet.js.map +1 -1
- package/build/esm/observable/ListPayload.js.map +1 -1
- package/build/esm/observable/ObjectPayload.js.map +1 -1
- package/build/esm/observable/ObservableClient.js.map +1 -1
- package/build/esm/observable/OptimisticBuilder.js.map +1 -1
- package/build/esm/observable/internal/ActionApplication.js +102 -0
- package/build/esm/observable/internal/ActionApplication.js.map +1 -0
- package/build/esm/observable/internal/BulkObjectLoader.js +93 -0
- package/build/esm/observable/internal/BulkObjectLoader.js.map +1 -0
- package/build/esm/observable/internal/BulkObjectLoader.test.js +112 -0
- package/build/esm/observable/internal/BulkObjectLoader.test.js.map +1 -0
- package/build/esm/observable/internal/CacheKey.js +38 -1
- package/build/esm/observable/internal/CacheKey.js.map +1 -1
- package/build/esm/observable/internal/CacheKeys.js +4 -4
- package/build/esm/observable/internal/CacheKeys.js.map +1 -1
- package/build/esm/observable/internal/Changes.js +58 -0
- package/build/esm/observable/internal/Changes.js.map +1 -0
- package/build/esm/observable/internal/Layer.js +6 -3
- package/build/esm/observable/internal/Layer.js.map +1 -1
- package/build/esm/observable/internal/ListQuery.js +495 -129
- package/build/esm/observable/internal/ListQuery.js.map +1 -1
- package/build/esm/observable/internal/ObjectQuery.js +40 -14
- package/build/esm/observable/internal/ObjectQuery.js.map +1 -1
- package/build/esm/observable/internal/ObservableClientImpl.js +4 -12
- package/build/esm/observable/internal/ObservableClientImpl.js.map +1 -1
- package/build/esm/observable/internal/OptimisticJob.js +30 -29
- package/build/esm/observable/internal/OptimisticJob.js.map +1 -1
- package/build/esm/observable/internal/OrderByCanonicalizer.js +73 -0
- package/build/esm/observable/internal/OrderByCanonicalizer.js.map +1 -0
- package/build/esm/observable/internal/OrderByCanonicalizer.test.js +78 -0
- package/build/esm/observable/internal/OrderByCanonicalizer.test.js.map +1 -0
- package/build/esm/observable/internal/Query.js +79 -6
- package/build/esm/observable/internal/Query.js.map +1 -1
- package/build/esm/observable/internal/RefCounts.js +7 -2
- package/build/esm/observable/internal/RefCounts.js.map +1 -1
- package/build/esm/observable/internal/SimpleWhereClause.js +2 -0
- package/build/esm/observable/internal/SimpleWhereClause.js.map +1 -0
- package/build/esm/observable/internal/Store.js +138 -188
- package/build/esm/observable/internal/Store.js.map +1 -1
- package/build/esm/observable/internal/Store.test.js +664 -255
- package/build/esm/observable/internal/Store.test.js.map +1 -1
- package/build/esm/observable/internal/WhereClauseCanonicalizer.js +11 -3
- package/build/esm/observable/internal/WhereClauseCanonicalizer.js.map +1 -1
- package/build/esm/observable/internal/objectMatchesWhereClause.js +0 -4
- package/build/esm/observable/internal/objectMatchesWhereClause.js.map +1 -1
- package/build/esm/observable/internal/objectMatchesWhereClause.test.js.map +1 -1
- package/build/esm/observable/internal/testUtils.js +222 -19
- package/build/esm/observable/internal/testUtils.js.map +1 -1
- package/build/esm/ontology/StandardOntologyProvider.test.js +17 -16
- package/build/esm/ontology/StandardOntologyProvider.test.js.map +1 -1
- package/build/esm/public/unstable-do-not-use.js.map +1 -1
- package/build/esm/queries/applyQuery.js +33 -1
- package/build/esm/queries/applyQuery.js.map +1 -1
- package/build/esm/queries/queries.test.js +36 -13
- package/build/esm/queries/queries.test.js.map +1 -1
- package/build/esm/tsserver.js.map +1 -1
- package/build/esm/util/UserAgent.js +1 -1
- package/build/esm/util/UserAgent.js.map +1 -1
- package/build/esm/util/toDataValue.js +10 -2
- package/build/esm/util/toDataValue.js.map +1 -1
- package/build/esm/util/toDataValue.test.js +37 -16
- package/build/esm/util/toDataValue.test.js.map +1 -1
- package/build/esm/util/toDataValueQueries.js +27 -2
- package/build/esm/util/toDataValueQueries.js.map +1 -1
- package/build/types/Client.d.ts +2 -2
- package/build/types/Client.d.ts.map +1 -1
- package/build/types/MinimalClientContext.d.ts +1 -1
- package/build/types/MinimalClientContext.d.ts.map +1 -1
- package/build/types/actions/applyAction.d.ts.map +1 -1
- package/build/types/createClient.d.ts +1 -1
- package/build/types/createClient.d.ts.map +1 -1
- package/build/types/createClient.test.d.ts +2 -1
- package/build/types/createClient.test.d.ts.map +1 -1
- package/build/types/createMinimalClientHelper.d.ts +1 -0
- package/build/types/createMinimalClientHelper.d.ts.map +1 -0
- package/build/types/derivedProperties/createWithPropertiesObjectSet.d.ts +1 -0
- package/build/types/derivedProperties/createWithPropertiesObjectSet.d.ts.map +1 -0
- package/build/types/derivedProperties/createWithPropertiesObjectSet.test.d.ts +1 -0
- package/build/types/derivedProperties/createWithPropertiesObjectSet.test.d.ts.map +1 -0
- package/build/types/index.d.ts +3 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/logger/BaseLogger.d.ts +31 -0
- package/build/types/logger/BaseLogger.d.ts.map +1 -0
- package/build/types/{Logger.d.ts → logger/Logger.d.ts} +1 -2
- package/build/types/logger/Logger.d.ts.map +1 -0
- package/build/types/logger/MinimalLogger.d.ts +8 -0
- package/build/types/logger/MinimalLogger.d.ts.map +1 -0
- package/build/types/object/AttachmentUpload.d.ts +3 -0
- package/build/types/object/AttachmentUpload.d.ts.map +1 -1
- package/build/types/object/SimpleOsdkProperties.d.ts +1 -0
- package/build/types/object/SimpleOsdkProperties.d.ts.map +1 -0
- package/build/types/object/convertWireToOsdkObjects/BaseHolder.d.ts +1 -0
- package/build/types/object/convertWireToOsdkObjects/BaseHolder.d.ts.map +1 -0
- package/build/types/object/convertWireToOsdkObjects.d.ts +8 -1
- package/build/types/object/convertWireToOsdkObjects.d.ts.map +1 -1
- package/build/types/object/createObjectSpecifierFromPrimaryKey.d.ts +2 -0
- package/build/types/object/createObjectSpecifierFromPrimaryKey.d.ts.map +1 -0
- package/build/types/object/object.test.d.ts.map +1 -1
- package/build/types/objectSet/ObjectSet.test.d.ts.map +1 -1
- package/build/types/observable/ListPayload.d.ts +5 -9
- package/build/types/observable/ListPayload.d.ts.map +1 -1
- package/build/types/observable/ObjectPayload.d.ts +4 -7
- package/build/types/observable/ObjectPayload.d.ts.map +1 -1
- package/build/types/observable/ObservableClient.d.ts +33 -10
- package/build/types/observable/ObservableClient.d.ts.map +1 -1
- package/build/types/observable/OptimisticBuilder.d.ts +1 -1
- package/build/types/observable/OptimisticBuilder.d.ts.map +1 -1
- package/build/types/observable/internal/ActionApplication.d.ts +9 -0
- package/build/types/observable/internal/ActionApplication.d.ts.map +1 -0
- package/build/types/observable/internal/BulkObjectLoader.d.ts +8 -0
- package/build/types/observable/internal/BulkObjectLoader.d.ts.map +1 -0
- package/build/types/observable/internal/BulkObjectLoader.test.d.ts +1 -0
- package/build/types/observable/internal/BulkObjectLoader.test.d.ts.map +1 -0
- package/build/types/observable/internal/CacheKeys.d.ts +2 -1
- package/build/types/observable/internal/CacheKeys.d.ts.map +1 -1
- package/build/types/observable/internal/Changes.d.ts +15 -0
- package/build/types/observable/internal/Changes.d.ts.map +1 -0
- package/build/types/observable/internal/Layer.d.ts +2 -1
- package/build/types/observable/internal/Layer.d.ts.map +1 -1
- package/build/types/observable/internal/ListQuery.d.ts +69 -23
- package/build/types/observable/internal/ListQuery.d.ts.map +1 -1
- package/build/types/observable/internal/ObjectQuery.d.ts +8 -9
- package/build/types/observable/internal/ObjectQuery.d.ts.map +1 -1
- package/build/types/observable/internal/OptimisticJob.d.ts +2 -2
- package/build/types/observable/internal/OptimisticJob.d.ts.map +1 -1
- package/build/types/observable/internal/OrderByCanonicalizer.d.ts +12 -0
- package/build/types/observable/internal/OrderByCanonicalizer.d.ts.map +1 -0
- package/build/types/observable/internal/OrderByCanonicalizer.test.d.ts +1 -0
- package/build/types/observable/internal/OrderByCanonicalizer.test.d.ts.map +1 -0
- package/build/types/observable/internal/Query.d.ts +45 -9
- package/build/types/observable/internal/Query.d.ts.map +1 -1
- package/build/types/observable/internal/RefCounts.d.ts.map +1 -1
- package/build/types/observable/internal/SimpleWhereClause.d.ts +2 -0
- package/build/types/observable/internal/SimpleWhereClause.d.ts.map +1 -0
- package/build/types/observable/internal/Store.d.ts +33 -29
- package/build/types/observable/internal/Store.d.ts.map +1 -1
- package/build/types/observable/internal/WhereClauseCanonicalizer.d.ts +2 -1
- package/build/types/observable/internal/WhereClauseCanonicalizer.d.ts.map +1 -1
- package/build/types/observable/internal/objectMatchesWhereClause.d.ts +4 -2
- package/build/types/observable/internal/objectMatchesWhereClause.d.ts.map +1 -1
- package/build/types/observable/internal/testUtils.d.ts +49 -9
- package/build/types/observable/internal/testUtils.d.ts.map +1 -1
- package/build/types/public/unstable-do-not-use.d.ts +1 -4
- package/build/types/public/unstable-do-not-use.d.ts.map +1 -1
- package/build/types/queries/applyQuery.d.ts.map +1 -1
- package/build/types/tsserver.d.ts +1 -1
- package/build/types/tsserver.d.ts.map +1 -1
- package/package.json +18 -14
- package/build/browser/observable/internal/ChangedObjects.js.map +0 -1
- package/build/cjs/chunk-DLSRNRTA.cjs.map +0 -1
- package/build/cjs/chunk-FWVJ2AKD.cjs.map +0 -1
- package/build/cjs/graphql-JJX5MZPQ.cjs.map +0 -1
- package/build/esm/observable/internal/ChangedObjects.js.map +0 -1
- package/build/types/Logger.d.ts.map +0 -1
- package/build/types/observable/internal/ChangedObjects.d.ts +0 -7
- package/build/types/observable/internal/ChangedObjects.d.ts.map +0 -1
- /package/build/browser/{Logger.js → logger/Logger.js} +0 -0
- /package/build/esm/{Logger.js → logger/Logger.js} +0 -0
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkT4NIFYZS_cjs = require('../chunk-T4NIFYZS.cjs');
|
|
4
|
+
var chunkEY52J5Z4_cjs = require('../chunk-EY52J5Z4.cjs');
|
|
4
5
|
require('../chunk-Q7SFCCGT.cjs');
|
|
5
6
|
var rxjs = require('rxjs');
|
|
6
7
|
var invariant2 = require('tiny-invariant');
|
|
7
|
-
var trie = require('@wry/trie');
|
|
8
8
|
var mnemonist = require('mnemonist');
|
|
9
|
+
var trie = require('@wry/trie');
|
|
9
10
|
var deepEqual = require('fast-deep-equal');
|
|
11
|
+
var groupBy = require('object.groupby');
|
|
12
|
+
var shared_net_errors = require('@osdk/shared.net.errors');
|
|
10
13
|
|
|
11
14
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
15
|
|
|
13
16
|
var invariant2__default = /*#__PURE__*/_interopDefault(invariant2);
|
|
14
17
|
var deepEqual__default = /*#__PURE__*/_interopDefault(deepEqual);
|
|
18
|
+
var groupBy__default = /*#__PURE__*/_interopDefault(groupBy);
|
|
15
19
|
|
|
16
20
|
// src/observable/internal/ObservableClientImpl.ts
|
|
17
21
|
var ObservableClientImpl = class {
|
|
18
22
|
#store;
|
|
19
23
|
constructor(store) {
|
|
20
24
|
this.#store = store;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
observeList(apiName, where, options, subFn) {
|
|
26
|
-
return this.#store.observeList(apiName, where, options, subFn);
|
|
27
|
-
}
|
|
28
|
-
applyAction(action, args, opts) {
|
|
29
|
-
return this.#store.applyAction(action, args, opts);
|
|
30
|
-
}
|
|
31
|
-
canonicalizeWhereClause(where) {
|
|
32
|
-
return this.#store.whereCanonicalizer.canonicalize(where);
|
|
25
|
+
this.observeObject = store.observeObject.bind(store);
|
|
26
|
+
this.observeList = store.observeList.bind(store);
|
|
27
|
+
this.applyAction = store.applyAction.bind(store);
|
|
28
|
+
this.canonicalizeWhereClause = store.canonicalizeWhereClause.bind(store);
|
|
33
29
|
}
|
|
34
30
|
};
|
|
35
31
|
|
|
32
|
+
// src/observable/DebugFlags.ts
|
|
33
|
+
process.env.NODE_ENV !== "production" && false;
|
|
34
|
+
var DEBUG_CACHE_KEYS = process.env.NODE_ENV !== "production" && false;
|
|
35
|
+
|
|
36
36
|
// ../../node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
|
|
37
37
|
function isNodeProcess() {
|
|
38
38
|
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
@@ -48,7 +48,7 @@ function isNodeProcess() {
|
|
|
48
48
|
return false;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
// ../../node_modules/.pnpm/msw@2.7.
|
|
51
|
+
// ../../node_modules/.pnpm/msw@2.7.3_@types+node@22.13.0_typescript@5.5.4/node_modules/msw/lib/core/delay.mjs
|
|
52
52
|
var SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647;
|
|
53
53
|
var MIN_SERVER_RESPONSE_TIME = 100;
|
|
54
54
|
var MAX_SERVER_RESPONSE_TIME = 400;
|
|
@@ -86,9 +86,213 @@ async function delay(durationOrMode) {
|
|
|
86
86
|
return new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
// src/observable/
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
// src/observable/internal/CacheKey.ts
|
|
90
|
+
function DEBUG_ONLY__cacheKeyToString(x) {
|
|
91
|
+
if (process.env.NODE_ENV !== "production") {
|
|
92
|
+
return `${x.type}CacheKey<${x.otherKeys.map((xx) => JSON.stringify(xx)).join(", ")}>`.replaceAll('"', "'");
|
|
93
|
+
} else {
|
|
94
|
+
throw new Error("not implemented");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function DEBUG_ONLY__cacheKeysToString(x) {
|
|
98
|
+
if (process.env.NODE_ENV !== "production") {
|
|
99
|
+
return "\n - " + x.map(DEBUG_ONLY__cacheKeyToString).join("\n - ");
|
|
100
|
+
} else {
|
|
101
|
+
throw new Error("not implemented");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/observable/internal/Changes.ts
|
|
106
|
+
var Changes = class {
|
|
107
|
+
modifiedObjects = new mnemonist.MultiMap();
|
|
108
|
+
addedObjects = new mnemonist.MultiMap();
|
|
109
|
+
added = /* @__PURE__ */ new Set();
|
|
110
|
+
modified = /* @__PURE__ */ new Set();
|
|
111
|
+
registerObject = (cacheKey, data, isNew) => {
|
|
112
|
+
this[isNew ? "addedObjects" : "modifiedObjects"].set(data.$apiName, data);
|
|
113
|
+
this[isNew ? "added" : "modified"].add(cacheKey);
|
|
114
|
+
};
|
|
115
|
+
registerList = (key) => {
|
|
116
|
+
this.modified.add(key);
|
|
117
|
+
};
|
|
118
|
+
isEmpty() {
|
|
119
|
+
return this.modifiedObjects.size === 0 && this.addedObjects.size === 0 && this.added.size === 0 && this.modified.size === 0;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
function createChangedObjects() {
|
|
123
|
+
return new Changes();
|
|
124
|
+
}
|
|
125
|
+
function DEBUG_ONLY__changesToString(changes) {
|
|
126
|
+
if (process.env.NODE_ENV !== "production") {
|
|
127
|
+
return JSON.stringify({
|
|
128
|
+
modifiedObjects: multimapHelper(changes.modifiedObjects),
|
|
129
|
+
addedObjects: multimapHelper(changes.addedObjects),
|
|
130
|
+
added: listHelper(changes.added),
|
|
131
|
+
modified: listHelper(changes.modified)
|
|
132
|
+
}, null, 2);
|
|
133
|
+
} else {
|
|
134
|
+
throw new Error("not implemented");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function listHelper(set) {
|
|
138
|
+
return Array.from(set).map(DEBUG_ONLY__cacheKeyToString);
|
|
139
|
+
}
|
|
140
|
+
function multimapHelper(multimap) {
|
|
141
|
+
return Object.fromEntries(Array.from(multimap.associations()).map(([type, objects]) => {
|
|
142
|
+
return [type, objects.map((o) => o.$primaryKey)];
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/observable/internal/OptimisticId.ts
|
|
147
|
+
function createOptimisticId() {
|
|
148
|
+
if (process.env.NODE_ENV !== "production") {
|
|
149
|
+
if (createOptimisticId.counter === undefined) {
|
|
150
|
+
createOptimisticId.counter = 0;
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
__optimisticId: createOptimisticId.counter++
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return /* @__PURE__ */ Object.create(null);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// src/observable/internal/OptimisticJob.ts
|
|
160
|
+
var OptimisticJob = class {
|
|
161
|
+
#result;
|
|
162
|
+
constructor(store, optimisticId) {
|
|
163
|
+
const updatedObjects = [];
|
|
164
|
+
const addedObjectPromises = [];
|
|
165
|
+
this.getResult = () => {
|
|
166
|
+
return this.#result ??= (async () => {
|
|
167
|
+
const addedObjects = await Promise.allSettled(addedObjectPromises);
|
|
168
|
+
const {
|
|
169
|
+
batchResult
|
|
170
|
+
} = store.batch({
|
|
171
|
+
optimisticId
|
|
172
|
+
}, (batch) => {
|
|
173
|
+
for (const obj of addedObjects) {
|
|
174
|
+
if (obj.status === "fulfilled") {
|
|
175
|
+
store.getObjectQuery(obj.value.$objectType, obj.value.$primaryKey).writeToStore(obj.value, "loading", batch);
|
|
176
|
+
} else {
|
|
177
|
+
throw obj;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
for (const obj of updatedObjects) {
|
|
181
|
+
store.getObjectQuery(obj.$objectType, obj.$primaryKey).writeToStore(obj, "loading", batch);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
return batchResult.changes;
|
|
185
|
+
})();
|
|
186
|
+
};
|
|
187
|
+
this.context = {
|
|
188
|
+
updateObject(value) {
|
|
189
|
+
updatedObjects.push(value);
|
|
190
|
+
return this;
|
|
191
|
+
},
|
|
192
|
+
createObject(type, pk, properties) {
|
|
193
|
+
const create = store.client[chunkEY52J5Z4_cjs.additionalContext].objectFactory2(store.client[chunkEY52J5Z4_cjs.additionalContext], [{
|
|
194
|
+
$primaryKey: pk,
|
|
195
|
+
$apiName: type.apiName,
|
|
196
|
+
$objectType: type.apiName,
|
|
197
|
+
...properties
|
|
198
|
+
}], undefined).then((objs) => {
|
|
199
|
+
return objs[0];
|
|
200
|
+
});
|
|
201
|
+
addedObjectPromises.push(create);
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
function runOptimisticJob(store, optimisticUpdate) {
|
|
208
|
+
if (!optimisticUpdate) {
|
|
209
|
+
return () => Promise.resolve();
|
|
210
|
+
}
|
|
211
|
+
const optimisticId = createOptimisticId();
|
|
212
|
+
const job = new OptimisticJob(store, optimisticId);
|
|
213
|
+
optimisticUpdate(job.context);
|
|
214
|
+
const optimisticApplicationDone = job.getResult();
|
|
215
|
+
return () => {
|
|
216
|
+
return optimisticApplicationDone.then(
|
|
217
|
+
// we don't want to leak the result
|
|
218
|
+
() => undefined
|
|
219
|
+
).finally(() => {
|
|
220
|
+
store.removeLayer(optimisticId);
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/observable/internal/ActionApplication.ts
|
|
226
|
+
var ACTION_DELAY = process.env.NODE_ENV === "production" ? 0 : 1e3;
|
|
227
|
+
var ActionApplication = class {
|
|
228
|
+
constructor(store) {
|
|
229
|
+
this.store = store;
|
|
230
|
+
}
|
|
231
|
+
applyAction = (action, args, {
|
|
232
|
+
optimisticUpdate
|
|
233
|
+
} = {}) => {
|
|
234
|
+
const logger = process.env.NODE_ENV !== "production" ? this.store.logger?.child({
|
|
235
|
+
methodName: "applyAction"
|
|
236
|
+
}) : this.store.logger;
|
|
237
|
+
const removeOptimisticResult = runOptimisticJob(this.store, optimisticUpdate);
|
|
238
|
+
return (async () => {
|
|
239
|
+
try {
|
|
240
|
+
const actionResults = await this.store.client(action).applyAction(args, {
|
|
241
|
+
$returnEdits: true
|
|
242
|
+
});
|
|
243
|
+
if (process.env.NODE_ENV !== "production") {
|
|
244
|
+
if (ACTION_DELAY > 0) {
|
|
245
|
+
logger?.debug("action done, pausing");
|
|
246
|
+
await delay(ACTION_DELAY);
|
|
247
|
+
logger?.debug("action done, pausing done");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
await this.#invalidateActionEditResponse(actionResults);
|
|
251
|
+
return actionResults;
|
|
252
|
+
} finally {
|
|
253
|
+
if (process.env.NODE_ENV !== "production") {
|
|
254
|
+
logger?.debug("optimistic action complete; remove the results");
|
|
255
|
+
}
|
|
256
|
+
await removeOptimisticResult();
|
|
257
|
+
}
|
|
258
|
+
})();
|
|
259
|
+
};
|
|
260
|
+
#invalidateActionEditResponse = async (value) => {
|
|
261
|
+
const typesToInvalidate = /* @__PURE__ */ new Set();
|
|
262
|
+
let changes;
|
|
263
|
+
if (value.type === "edits") {
|
|
264
|
+
const promisesToWait = [];
|
|
265
|
+
for (const obj of value.modifiedObjects) {
|
|
266
|
+
promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
|
|
267
|
+
}
|
|
268
|
+
for (const obj of value.addedObjects) {
|
|
269
|
+
promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
|
|
270
|
+
typesToInvalidate.add(obj.objectType);
|
|
271
|
+
}
|
|
272
|
+
await Promise.all(promisesToWait);
|
|
273
|
+
const changes2 = createChangedObjects();
|
|
274
|
+
for (const changeType of ["addedObjects", "modifiedObjects"]) {
|
|
275
|
+
for (const {
|
|
276
|
+
objectType,
|
|
277
|
+
primaryKey
|
|
278
|
+
} of value[changeType] ?? []) {
|
|
279
|
+
const cacheKey = this.store.getCacheKey("object", objectType, primaryKey);
|
|
280
|
+
const obj = this.store.getValue(cacheKey);
|
|
281
|
+
if (obj && obj.value) {
|
|
282
|
+
changes2[changeType].set(objectType, obj.value);
|
|
283
|
+
(changeType === "addedObjects" ? changes2.added : changes2.modified).add(cacheKey);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
for (const apiName of value.editedObjectTypes) {
|
|
289
|
+
typesToInvalidate.add(apiName.toString());
|
|
290
|
+
await this.store.invalidateObjectType(apiName, changes);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return value;
|
|
294
|
+
};
|
|
295
|
+
};
|
|
92
296
|
var CacheKeys = class {
|
|
93
297
|
#cacheKeys = new trie.Trie(false, (keys) => {
|
|
94
298
|
const ret = {
|
|
@@ -100,15 +304,15 @@ var CacheKeys = class {
|
|
|
100
304
|
});
|
|
101
305
|
#cacheKeyFactories = /* @__PURE__ */ new Map();
|
|
102
306
|
#onCreate;
|
|
103
|
-
constructor(whereCanonicalizer, onCreate) {
|
|
307
|
+
constructor(whereCanonicalizer, orderByCanonicalizer, onCreate) {
|
|
104
308
|
this.#onCreate = onCreate;
|
|
105
309
|
this.#registerCacheKeyFactory("object", (apiName, pk) => {
|
|
106
310
|
if (process.env.NODE_ENV !== "production" && DEBUG_CACHE_KEYS) ;
|
|
107
311
|
return this.#cacheKeys.lookupArray(["object", apiName, pk]);
|
|
108
312
|
});
|
|
109
|
-
this.#registerCacheKeyFactory("list", (apiName, where) => {
|
|
313
|
+
this.#registerCacheKeyFactory("list", (type, apiName, where, orderBy) => {
|
|
110
314
|
if (process.env.NODE_ENV !== "production" && DEBUG_CACHE_KEYS) ;
|
|
111
|
-
return this.#cacheKeys.lookupArray(["list", apiName, whereCanonicalizer.canonicalize(where)]);
|
|
315
|
+
return this.#cacheKeys.lookupArray(["list", type, apiName, whereCanonicalizer.canonicalize(where), orderByCanonicalizer.canonicalize(orderBy)]);
|
|
112
316
|
});
|
|
113
317
|
}
|
|
114
318
|
#registerCacheKeyFactory(type, factory) {
|
|
@@ -123,12 +327,6 @@ var CacheKeys = class {
|
|
|
123
327
|
this.#cacheKeys.remove(cacheKey.type, ...cacheKey.otherKeys);
|
|
124
328
|
}
|
|
125
329
|
};
|
|
126
|
-
function createChangedObjects() {
|
|
127
|
-
return {
|
|
128
|
-
modifiedObjects: new mnemonist.MultiMap(),
|
|
129
|
-
addedObjects: new mnemonist.MultiMap()
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
330
|
|
|
133
331
|
// src/observable/internal/WeakMapWithEntries.ts
|
|
134
332
|
var WeakMapWithEntries = class {
|
|
@@ -262,11 +460,14 @@ var Layer = class _Layer {
|
|
|
262
460
|
this.#parent = this.#parent.removeLayer(layerId);
|
|
263
461
|
return this;
|
|
264
462
|
}
|
|
265
|
-
return this.#parent
|
|
463
|
+
return this.#parent.removeLayer(layerId);
|
|
266
464
|
}
|
|
267
465
|
entries() {
|
|
268
466
|
return this.#cache.entries();
|
|
269
467
|
}
|
|
468
|
+
keys() {
|
|
469
|
+
return this.#cache.keys();
|
|
470
|
+
}
|
|
270
471
|
get(cacheKey) {
|
|
271
472
|
return this.#cache.get(cacheKey) ?? this.#parent?.get(cacheKey);
|
|
272
473
|
}
|
|
@@ -275,11 +476,11 @@ var Layer = class _Layer {
|
|
|
275
476
|
}
|
|
276
477
|
};
|
|
277
478
|
var Entry = class {
|
|
278
|
-
constructor(cacheKey, value, lastUpdated) {
|
|
479
|
+
constructor(cacheKey, value, lastUpdated, status = "init") {
|
|
279
480
|
this.cacheKey = cacheKey;
|
|
280
481
|
this.value = value;
|
|
281
482
|
this.lastUpdated = lastUpdated;
|
|
282
|
-
this.status =
|
|
483
|
+
this.status = status;
|
|
283
484
|
}
|
|
284
485
|
};
|
|
285
486
|
function is$and(whereClause) {
|
|
@@ -368,46 +569,172 @@ function objectSortaMatchesWhereClause(o, whereClause, strict) {
|
|
|
368
569
|
});
|
|
369
570
|
}
|
|
370
571
|
|
|
572
|
+
// ../../node_modules/.pnpm/p-defer@4.0.1/node_modules/p-defer/index.js
|
|
573
|
+
function pDefer() {
|
|
574
|
+
const deferred = {};
|
|
575
|
+
deferred.promise = new Promise((resolve, reject) => {
|
|
576
|
+
deferred.resolve = resolve;
|
|
577
|
+
deferred.reject = reject;
|
|
578
|
+
});
|
|
579
|
+
return deferred;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// src/observable/internal/BulkObjectLoader.ts
|
|
583
|
+
var weakCache = new mnemonist.DefaultWeakMap((c) => new BulkObjectLoader(c));
|
|
584
|
+
function getBulkObjectLoader(client) {
|
|
585
|
+
return weakCache.get(client);
|
|
586
|
+
}
|
|
587
|
+
var BulkObjectLoader = class {
|
|
588
|
+
#client;
|
|
589
|
+
#m = new mnemonist.DefaultMap(() => ({
|
|
590
|
+
data: [],
|
|
591
|
+
timer: undefined
|
|
592
|
+
}));
|
|
593
|
+
#logger;
|
|
594
|
+
#maxWait;
|
|
595
|
+
#maxEntries;
|
|
596
|
+
constructor(client, maxWait = 25, maxEntries = 100) {
|
|
597
|
+
this.#client = client;
|
|
598
|
+
this.#logger = client[chunkEY52J5Z4_cjs.additionalContext].logger;
|
|
599
|
+
this.#maxWait = maxWait;
|
|
600
|
+
this.#maxEntries = maxEntries;
|
|
601
|
+
}
|
|
602
|
+
fetch(apiName, primaryKey) {
|
|
603
|
+
const deferred = pDefer();
|
|
604
|
+
const entry = this.#m.get(apiName);
|
|
605
|
+
entry.data.push({
|
|
606
|
+
primaryKey,
|
|
607
|
+
deferred
|
|
608
|
+
});
|
|
609
|
+
if (!entry.timer) {
|
|
610
|
+
entry.timer = setTimeout(() => {
|
|
611
|
+
this.#loadObjects(apiName, entry.data);
|
|
612
|
+
}, this.#maxWait);
|
|
613
|
+
}
|
|
614
|
+
if (entry.data.length >= this.#maxEntries) {
|
|
615
|
+
clearTimeout(entry.timer);
|
|
616
|
+
this.#loadObjects(apiName, entry.data);
|
|
617
|
+
}
|
|
618
|
+
return deferred.promise;
|
|
619
|
+
}
|
|
620
|
+
#loadObjects(apiName, arr) {
|
|
621
|
+
this.#m.delete(apiName);
|
|
622
|
+
this.#reallyLoadObjects(apiName, arr).catch((e) => {
|
|
623
|
+
this.#logger?.error("Unhandled exception", e);
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
async #reallyLoadObjects(apiName, arr) {
|
|
627
|
+
const miniDef = {
|
|
628
|
+
type: "object",
|
|
629
|
+
apiName
|
|
630
|
+
};
|
|
631
|
+
const objMetadata = await this.#client.fetchMetadata(miniDef);
|
|
632
|
+
const pks = arr.map((x) => x.primaryKey);
|
|
633
|
+
const {
|
|
634
|
+
data
|
|
635
|
+
} = await this.#client(miniDef).where({
|
|
636
|
+
[objMetadata.primaryKeyApiName]: {
|
|
637
|
+
$in: pks
|
|
638
|
+
}
|
|
639
|
+
}).fetchPage({
|
|
640
|
+
$pageSize: pks.length
|
|
641
|
+
});
|
|
642
|
+
for (const {
|
|
643
|
+
primaryKey,
|
|
644
|
+
deferred
|
|
645
|
+
} of arr) {
|
|
646
|
+
const object = data.find((x) => x.$primaryKey === primaryKey);
|
|
647
|
+
if (object) {
|
|
648
|
+
deferred.resolve(object);
|
|
649
|
+
} else {
|
|
650
|
+
deferred.reject(new shared_net_errors.PalantirApiError("Object not found"));
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
|
|
371
656
|
// src/observable/internal/Query.ts
|
|
372
657
|
var Query = class {
|
|
373
658
|
retainCount = 0;
|
|
374
659
|
#connectable;
|
|
375
660
|
#subscription;
|
|
376
661
|
#subject;
|
|
377
|
-
|
|
662
|
+
/** @internal */
|
|
663
|
+
constructor(store, observable, opts, cacheKey, logger) {
|
|
378
664
|
this.options = opts;
|
|
379
665
|
this.cacheKey = cacheKey;
|
|
380
666
|
this.store = store;
|
|
381
667
|
this.#subject = observable;
|
|
668
|
+
this.logger = logger ?? (process.env.NODE_ENV === "production" ? store.client[chunkEY52J5Z4_cjs.additionalContext].logger : store.client[chunkEY52J5Z4_cjs.additionalContext].logger?.child({}, {
|
|
669
|
+
msgPrefix: process.env.NODE_ENV !== "production" ? `Query<${cacheKey.type}, ${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>` : "Query"
|
|
670
|
+
}));
|
|
382
671
|
}
|
|
383
672
|
subscribe(observer) {
|
|
384
673
|
this.#connectable ??= this._createConnectable(this.#subject);
|
|
385
674
|
this.#subscription = this.#connectable.connect();
|
|
386
675
|
return this.#connectable.subscribe(observer);
|
|
387
676
|
}
|
|
388
|
-
|
|
677
|
+
/**
|
|
678
|
+
* Causes the query to revalidate. This will cause the query to fetch
|
|
679
|
+
* the latest data from the server and update the store if it is deemed
|
|
680
|
+
* "stale" or if `force` is true.
|
|
681
|
+
*
|
|
682
|
+
* @param force
|
|
683
|
+
* @returns
|
|
684
|
+
*/
|
|
685
|
+
async revalidate(force) {
|
|
686
|
+
const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
|
|
687
|
+
methodName: "revalidate"
|
|
688
|
+
}) : this.logger;
|
|
389
689
|
if (force) {
|
|
390
690
|
this.abortController?.abort();
|
|
391
691
|
}
|
|
392
692
|
if (this.pendingFetch) {
|
|
393
|
-
|
|
693
|
+
if (process.env.NODE_ENV !== "production") {
|
|
694
|
+
logger?.info("Fetch is already pending, using it");
|
|
695
|
+
}
|
|
696
|
+
await this.pendingFetch;
|
|
697
|
+
return;
|
|
394
698
|
}
|
|
395
699
|
if ((this.options.dedupeInterval ?? 0) > 0 && this.lastFetchStarted != null && Date.now() - this.lastFetchStarted < (this.options.dedupeInterval ?? 0)) {
|
|
700
|
+
if (process.env.NODE_ENV !== "production") {
|
|
701
|
+
logger?.debug("Within dupeInterval, aborting revalidate");
|
|
702
|
+
}
|
|
396
703
|
return Promise.resolve();
|
|
397
704
|
}
|
|
705
|
+
if (process.env.NODE_ENV !== "production") {
|
|
706
|
+
logger?.debug("Starting actual revalidate");
|
|
707
|
+
}
|
|
398
708
|
this.store.batch({}, (batch) => {
|
|
399
709
|
this.setStatus("loading", batch);
|
|
400
710
|
});
|
|
401
711
|
this._preFetch();
|
|
402
712
|
this.lastFetchStarted = Date.now();
|
|
403
|
-
|
|
713
|
+
if (process.env.NODE_ENV !== "production") {
|
|
714
|
+
logger?.debug("calling _fetchAndStore()");
|
|
715
|
+
}
|
|
716
|
+
this.pendingFetch = this._fetchAndStore().finally(() => {
|
|
717
|
+
logger?.info("finally _fetchAndStore()");
|
|
404
718
|
this.pendingFetch = undefined;
|
|
405
719
|
});
|
|
406
|
-
|
|
720
|
+
await this.pendingFetch;
|
|
721
|
+
return;
|
|
407
722
|
}
|
|
408
723
|
_preFetch() {
|
|
409
724
|
}
|
|
725
|
+
/**
|
|
726
|
+
* Sets the status of the query in the store (but does not store that in `changes`).
|
|
727
|
+
*
|
|
728
|
+
* @param status
|
|
729
|
+
* @param batch
|
|
730
|
+
* @returns
|
|
731
|
+
*/
|
|
410
732
|
setStatus(status, batch) {
|
|
733
|
+
if (process.env.NODE_ENV !== "production") {
|
|
734
|
+
this.logger?.child({
|
|
735
|
+
methodName: "setStatus"
|
|
736
|
+
}).debug(status);
|
|
737
|
+
}
|
|
411
738
|
const existing = batch.read(this.cacheKey);
|
|
412
739
|
if (existing?.status === status) return;
|
|
413
740
|
batch.write(this.cacheKey, existing?.value, status);
|
|
@@ -419,69 +746,250 @@ var Query = class {
|
|
|
419
746
|
this.#subscription?.unsubscribe();
|
|
420
747
|
this._dispose();
|
|
421
748
|
}
|
|
749
|
+
/**
|
|
750
|
+
* Per query type dispose functionality
|
|
751
|
+
*/
|
|
422
752
|
_dispose() {
|
|
423
753
|
}
|
|
754
|
+
/**
|
|
755
|
+
* The purpose of this method is to provide a way for others to write
|
|
756
|
+
* directly into the store for this query.
|
|
757
|
+
*
|
|
758
|
+
* @param data
|
|
759
|
+
* @param status
|
|
760
|
+
* @param batch
|
|
761
|
+
*/
|
|
762
|
+
/**
|
|
763
|
+
* @param changes
|
|
764
|
+
* @param optimisticId
|
|
765
|
+
* @returns If revalidation is needed, a promise that resolves after the
|
|
766
|
+
* revalidation is complete. Otherwise, undefined.
|
|
767
|
+
*/
|
|
424
768
|
};
|
|
425
769
|
|
|
426
|
-
// src/observable/internal/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
#pendingPageFetch;
|
|
437
|
-
#toRelease = /* @__PURE__ */ new Set();
|
|
438
|
-
constructor(store, subject, type, whereClause, cacheKey, opts) {
|
|
439
|
-
super(store, subject, opts, cacheKey);
|
|
440
|
-
this.#client = store.client;
|
|
441
|
-
this.#type = type;
|
|
442
|
-
this.#whereClause = whereClause;
|
|
443
|
-
rxjs.observeOn(rxjs.asyncScheduler);
|
|
770
|
+
// src/observable/internal/ObjectQuery.ts
|
|
771
|
+
var ObjectQuery = class extends Query {
|
|
772
|
+
#apiName;
|
|
773
|
+
#pk;
|
|
774
|
+
constructor(store, subject, type, pk, cacheKey, opts) {
|
|
775
|
+
super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunkEY52J5Z4_cjs.additionalContext].logger?.child({}, {
|
|
776
|
+
msgPrefix: `ObjectQuery<${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>`
|
|
777
|
+
}) : undefined);
|
|
778
|
+
this.#apiName = type;
|
|
779
|
+
this.#pk = pk;
|
|
444
780
|
}
|
|
445
781
|
_createConnectable(subject) {
|
|
446
|
-
return rxjs.connectable(subject.pipe(
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
resetOnDisconnect: false,
|
|
461
|
-
connector: () => new rxjs.ReplaySubject(1)
|
|
782
|
+
return rxjs.connectable(subject.pipe(rxjs.map((x) => {
|
|
783
|
+
return {
|
|
784
|
+
status: x.status,
|
|
785
|
+
object: x.value,
|
|
786
|
+
lastUpdated: x.lastUpdated,
|
|
787
|
+
isOptimistic: x.isOptimistic
|
|
788
|
+
};
|
|
789
|
+
})), {
|
|
790
|
+
connector: () => new rxjs.BehaviorSubject({
|
|
791
|
+
status: "init",
|
|
792
|
+
object: undefined,
|
|
793
|
+
lastUpdated: 0,
|
|
794
|
+
isOptimistic: false
|
|
795
|
+
})
|
|
462
796
|
});
|
|
463
797
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
type: "object",
|
|
470
|
-
apiName: this.#type
|
|
471
|
-
}).where(this.#whereClause);
|
|
472
|
-
while (true) {
|
|
473
|
-
const entry = await this.#fetchPageAndUpdate(objectSet, "loading", this.abortController?.signal);
|
|
474
|
-
if (!entry) {
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
!entry.value?.data ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false) : invariant2__default.default(false) : undefined;
|
|
478
|
-
const count = entry.value.data.length;
|
|
479
|
-
if (count > this.#minNumResults || this.#nextPageToken == null) {
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
798
|
+
async _fetchAndStore() {
|
|
799
|
+
if (process.env.NODE_ENV !== "production") {
|
|
800
|
+
this.logger?.child({
|
|
801
|
+
methodName: "_fetchAndStore"
|
|
802
|
+
}).info("calling fetchOne");
|
|
482
803
|
}
|
|
804
|
+
const obj = await getBulkObjectLoader(this.store.client).fetch(this.#apiName, this.#pk);
|
|
483
805
|
this.store.batch({}, (batch) => {
|
|
484
|
-
this.
|
|
806
|
+
this.writeToStore(obj, "loaded", batch);
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
writeToStore(data, status, batch) {
|
|
810
|
+
const entry = batch.read(this.cacheKey);
|
|
811
|
+
if (entry && deepEqual__default.default(data, entry.value)) {
|
|
812
|
+
if (process.env.NODE_ENV !== "production") {
|
|
813
|
+
this.logger?.child({
|
|
814
|
+
methodName: "writeToStore"
|
|
815
|
+
}).debug(`Object was deep equal, just setting status`);
|
|
816
|
+
}
|
|
817
|
+
return batch.write(this.cacheKey, entry.value, status);
|
|
818
|
+
}
|
|
819
|
+
if (process.env.NODE_ENV !== "production") {
|
|
820
|
+
this.logger?.child({
|
|
821
|
+
methodName: "writeToStore"
|
|
822
|
+
}).debug(JSON.stringify({
|
|
823
|
+
status
|
|
824
|
+
}), data);
|
|
825
|
+
}
|
|
826
|
+
const ret = batch.write(this.cacheKey, data, status);
|
|
827
|
+
batch.changes.registerObject(
|
|
828
|
+
this.cacheKey,
|
|
829
|
+
data,
|
|
830
|
+
/* isNew */
|
|
831
|
+
!entry
|
|
832
|
+
);
|
|
833
|
+
return ret;
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
function storeOsdkInstances(store, values, batch) {
|
|
837
|
+
return values.map((v) => {
|
|
838
|
+
return store.getObjectQuery(v.$apiName, v.$primaryKey).writeToStore(v, "loaded", batch).cacheKey;
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// src/observable/internal/ListQuery.ts
|
|
843
|
+
var API_NAME_IDX = 1;
|
|
844
|
+
var BaseListQuery = class extends Query {
|
|
845
|
+
//
|
|
846
|
+
// Per list type implementations
|
|
847
|
+
//
|
|
848
|
+
//
|
|
849
|
+
// Shared Implementations
|
|
850
|
+
//
|
|
851
|
+
/**
|
|
852
|
+
* Only intended to be "protected" and used by subclasses but exposed for
|
|
853
|
+
* testing.
|
|
854
|
+
*
|
|
855
|
+
* @param objectCacheKeys
|
|
856
|
+
* @param append
|
|
857
|
+
* @param status
|
|
858
|
+
* @param batch
|
|
859
|
+
* @returns
|
|
860
|
+
*/
|
|
861
|
+
_updateList(objectCacheKeys, append, status, batch) {
|
|
862
|
+
if (process.env.NODE_ENV !== "production") {
|
|
863
|
+
const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
|
|
864
|
+
methodName: "updateList"
|
|
865
|
+
}) : this.logger;
|
|
866
|
+
logger?.debug(`{status: ${status}}`, JSON.stringify(objectCacheKeys, null, 2));
|
|
867
|
+
}
|
|
868
|
+
objectCacheKeys = this.#retainReleaseAppend(batch, append, objectCacheKeys);
|
|
869
|
+
objectCacheKeys = this._sortCacheKeys(objectCacheKeys, batch);
|
|
870
|
+
objectCacheKeys = removeDuplicates(objectCacheKeys, batch);
|
|
871
|
+
return this.writeToStore({
|
|
872
|
+
data: objectCacheKeys
|
|
873
|
+
}, status, batch);
|
|
874
|
+
}
|
|
875
|
+
writeToStore(data, status, batch) {
|
|
876
|
+
const entry = batch.read(this.cacheKey);
|
|
877
|
+
if (entry && deepEqual__default.default(data, entry.value)) {
|
|
878
|
+
if (process.env.NODE_ENV !== "production") {
|
|
879
|
+
this.logger?.child({
|
|
880
|
+
methodName: "writeToStore"
|
|
881
|
+
}).debug(`Object was deep equal, just setting status`);
|
|
882
|
+
}
|
|
883
|
+
return batch.write(this.cacheKey, entry.value, status);
|
|
884
|
+
}
|
|
885
|
+
if (process.env.NODE_ENV !== "production") {
|
|
886
|
+
this.logger?.child({
|
|
887
|
+
methodName: "writeToStore"
|
|
888
|
+
}).debug(`{status: ${status}},`, DEBUG_ONLY__cacheKeysToString(data.data));
|
|
889
|
+
}
|
|
890
|
+
const ret = batch.write(this.cacheKey, data, status);
|
|
891
|
+
batch.changes.registerList(this.cacheKey);
|
|
892
|
+
return ret;
|
|
893
|
+
}
|
|
894
|
+
#retainReleaseAppend(batch, append, objectCacheKeys) {
|
|
895
|
+
const existingList = batch.read(this.cacheKey);
|
|
896
|
+
if (!batch.optimisticWrite) {
|
|
897
|
+
if (!append) {
|
|
898
|
+
for (const objectCacheKey of existingList?.value?.data ?? []) {
|
|
899
|
+
this.store.release(objectCacheKey);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
for (const objectCacheKey of objectCacheKeys) {
|
|
903
|
+
this.store.retain(objectCacheKey);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
if (append) {
|
|
907
|
+
objectCacheKeys = [...existingList?.value?.data ?? [], ...objectCacheKeys];
|
|
908
|
+
}
|
|
909
|
+
return objectCacheKeys;
|
|
910
|
+
}
|
|
911
|
+
_dispose() {
|
|
912
|
+
console.log("DISPOSE LIST QUERY");
|
|
913
|
+
this.store.batch({}, (batch) => {
|
|
914
|
+
const entry = batch.read(this.cacheKey);
|
|
915
|
+
if (entry) {
|
|
916
|
+
for (const objectCacheKey of entry.value?.data ?? []) {
|
|
917
|
+
this.store.release(objectCacheKey);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
var ListQuery = class extends BaseListQuery {
|
|
924
|
+
// pageSize?: number; // this is the internal page size. we need to track this properly
|
|
925
|
+
#type;
|
|
926
|
+
#apiName;
|
|
927
|
+
#whereClause;
|
|
928
|
+
// this represents the minimum number of results we need to load if we revalidate
|
|
929
|
+
#minNumResults = 0;
|
|
930
|
+
#nextPageToken;
|
|
931
|
+
#pendingPageFetch;
|
|
932
|
+
#orderBy;
|
|
933
|
+
#objectSet;
|
|
934
|
+
#sortFns;
|
|
935
|
+
constructor(store, subject, apiType, apiName, whereClause, orderBy, cacheKey, opts) {
|
|
936
|
+
super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunkEY52J5Z4_cjs.additionalContext].logger?.child({}, {
|
|
937
|
+
msgPrefix: `ListQuery<${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>`
|
|
938
|
+
}) : undefined);
|
|
939
|
+
this.#type = apiType;
|
|
940
|
+
this.#apiName = apiName;
|
|
941
|
+
this.#whereClause = whereClause;
|
|
942
|
+
this.#orderBy = orderBy;
|
|
943
|
+
this.#objectSet = store.client({
|
|
944
|
+
type: this.#type,
|
|
945
|
+
apiName: this.#apiName
|
|
946
|
+
}).where(this.#whereClause);
|
|
947
|
+
this.#sortFns = createOrderBySortFns(this.#orderBy);
|
|
948
|
+
}
|
|
949
|
+
get canonicalWhere() {
|
|
950
|
+
return this.#whereClause;
|
|
951
|
+
}
|
|
952
|
+
_createConnectable(subject) {
|
|
953
|
+
return rxjs.connectable(subject.pipe(
|
|
954
|
+
rxjs.switchMap((listEntry) => {
|
|
955
|
+
return rxjs.combineLatest({
|
|
956
|
+
resolvedList: listEntry?.value?.data == null ? rxjs.of([]) : rxjs.combineLatest(listEntry.value.data.map((cacheKey) => this.store.getSubject(cacheKey).pipe(rxjs.map((objectEntry) => objectEntry?.value)))),
|
|
957
|
+
isOptimistic: rxjs.of(listEntry.isOptimistic),
|
|
958
|
+
fetchMore: rxjs.of(this.fetchMore),
|
|
959
|
+
hasMore: rxjs.of(this.#nextPageToken != null),
|
|
960
|
+
status: rxjs.of(listEntry.status),
|
|
961
|
+
lastUpdated: rxjs.of(listEntry.lastUpdated)
|
|
962
|
+
});
|
|
963
|
+
}),
|
|
964
|
+
// like throttle but returns the tail
|
|
965
|
+
rxjs.auditTime(0)
|
|
966
|
+
), {
|
|
967
|
+
resetOnDisconnect: false,
|
|
968
|
+
connector: () => new rxjs.ReplaySubject(1)
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
_preFetch() {
|
|
972
|
+
this.#nextPageToken = undefined;
|
|
973
|
+
}
|
|
974
|
+
async _fetchAndStore() {
|
|
975
|
+
if (process.env.NODE_ENV !== "production") {
|
|
976
|
+
this.logger?.child({
|
|
977
|
+
methodName: "_fetchAndStore"
|
|
978
|
+
}).info("fetching pages");
|
|
979
|
+
}
|
|
980
|
+
while (true) {
|
|
981
|
+
const entry = await this.#fetchPageAndUpdate(this.#objectSet, "loading", this.abortController?.signal);
|
|
982
|
+
if (!entry) {
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
!entry.value?.data ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false) : invariant2__default.default(false) : undefined;
|
|
986
|
+
const count = entry.value.data.length;
|
|
987
|
+
if (count > this.#minNumResults || this.#nextPageToken == null) {
|
|
988
|
+
break;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
this.store.batch({}, (batch) => {
|
|
992
|
+
this.setStatus("loaded", batch);
|
|
485
993
|
});
|
|
486
994
|
return Promise.resolve();
|
|
487
995
|
}
|
|
@@ -502,271 +1010,421 @@ var ListQuery = class extends Query {
|
|
|
502
1010
|
this.store.batch({}, (batch) => {
|
|
503
1011
|
this.setStatus("loading", batch);
|
|
504
1012
|
});
|
|
505
|
-
|
|
506
|
-
type: "object",
|
|
507
|
-
apiName: this.#type
|
|
508
|
-
}).where(this.#whereClause);
|
|
509
|
-
this.pendingFetch = this.#fetchPageAndUpdate(objectSet, "loaded", this.abortController?.signal).finally(() => {
|
|
1013
|
+
this.pendingFetch = this.#fetchPageAndUpdate(this.#objectSet, "loaded", this.abortController?.signal).finally(() => {
|
|
510
1014
|
this.#pendingPageFetch = undefined;
|
|
511
1015
|
});
|
|
512
1016
|
return this.pendingFetch;
|
|
513
1017
|
};
|
|
514
1018
|
async #fetchPageAndUpdate(objectSet, status, signal) {
|
|
515
1019
|
const append = this.#nextPageToken != null;
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
1020
|
+
try {
|
|
1021
|
+
let {
|
|
1022
|
+
data,
|
|
1023
|
+
nextPageToken
|
|
1024
|
+
} = await objectSet.fetchPage({
|
|
1025
|
+
$nextPageToken: this.#nextPageToken,
|
|
1026
|
+
$pageSize: this.options.pageSize,
|
|
1027
|
+
// For now this keeps the shared test code from falling apart
|
|
1028
|
+
// but shouldn't be needed ideally
|
|
1029
|
+
...Object.keys(this.#orderBy).length > 0 ? {
|
|
1030
|
+
$orderBy: this.#orderBy
|
|
1031
|
+
} : {}
|
|
1032
|
+
});
|
|
1033
|
+
if (signal?.aborted) {
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
this.#nextPageToken = nextPageToken;
|
|
1037
|
+
if (this.#type === "interface") {
|
|
1038
|
+
data = await reloadDataAsFullObjects(this.store.client, data);
|
|
1039
|
+
}
|
|
1040
|
+
const {
|
|
1041
|
+
retVal
|
|
1042
|
+
} = this.store.batch({}, (batch) => {
|
|
1043
|
+
return this._updateList(storeOsdkInstances(this.store, data, batch), append, nextPageToken ? status : "loaded", batch);
|
|
1044
|
+
});
|
|
1045
|
+
return retVal;
|
|
1046
|
+
} catch (e) {
|
|
1047
|
+
this.logger?.error("error", e);
|
|
1048
|
+
this.store.getSubject(this.cacheKey).error(e);
|
|
525
1049
|
}
|
|
526
|
-
this.#nextPageToken = nextPageToken;
|
|
527
|
-
const {
|
|
528
|
-
retVal
|
|
529
|
-
} = this.store.batch({}, (batch) => {
|
|
530
|
-
return this.updateList(data, append, nextPageToken ? status : "loaded", batch);
|
|
531
|
-
});
|
|
532
|
-
return retVal;
|
|
533
1050
|
}
|
|
534
1051
|
/**
|
|
535
|
-
*
|
|
1052
|
+
* Will revalidate the list if its query is affected by invalidating the
|
|
1053
|
+
* apiName of the object type passed in.
|
|
536
1054
|
*
|
|
537
|
-
* @param
|
|
538
|
-
* @param optimisticId
|
|
1055
|
+
* @param apiName to invalidate
|
|
539
1056
|
* @returns
|
|
540
1057
|
*/
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
1058
|
+
revalidateObjectType = async (apiName) => {
|
|
1059
|
+
if (this.#type === "object") {
|
|
1060
|
+
if (this.#apiName === apiName) {
|
|
1061
|
+
await this.revalidate(
|
|
1062
|
+
/* force */
|
|
1063
|
+
true
|
|
1064
|
+
);
|
|
1065
|
+
return;
|
|
1066
|
+
} else {
|
|
1067
|
+
return;
|
|
547
1068
|
}
|
|
548
|
-
|
|
1069
|
+
}
|
|
1070
|
+
const objectMetadata = await this.store.client.fetchMetadata({
|
|
1071
|
+
type: "object",
|
|
1072
|
+
apiName
|
|
1073
|
+
});
|
|
1074
|
+
if (this.#apiName in objectMetadata.interfaceMap) {
|
|
1075
|
+
await this.revalidate(
|
|
1076
|
+
/* force */
|
|
1077
|
+
true
|
|
1078
|
+
);
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
/**
|
|
1083
|
+
* Note: This method is not async because I want it to return right after it
|
|
1084
|
+
* finishes the synchronous updates. The promise that is returned
|
|
1085
|
+
* will resolve after the revalidation is complete.
|
|
1086
|
+
* @param changes
|
|
1087
|
+
* @param optimisticId
|
|
1088
|
+
* @returns If revalidation is needed, a promise that resolves after the
|
|
1089
|
+
* revalidation is complete. Otherwise, undefined.
|
|
1090
|
+
*/
|
|
1091
|
+
maybeUpdateAndRevalidate = (changes, optimisticId) => {
|
|
1092
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1093
|
+
this.logger?.child({
|
|
1094
|
+
methodName: "maybeUpdateAndRevalidate"
|
|
1095
|
+
}).debug(DEBUG_ONLY__changesToString(changes));
|
|
1096
|
+
}
|
|
1097
|
+
if (changes.modified.has(this.cacheKey)) return;
|
|
1098
|
+
changes.modified.add(this.cacheKey);
|
|
1099
|
+
try {
|
|
1100
|
+
const relevantObjects = this._extractRelevantObjects(changes);
|
|
1101
|
+
if (relevantObjects.added.all.length === 0 && relevantObjects.modified.all.length === 0) {
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
const status = optimisticId || relevantObjects.added.sortaMatches.size > 0 || relevantObjects.modified.sortaMatches.size > 0 ? "loading" : "loaded";
|
|
1105
|
+
const newList = [];
|
|
1106
|
+
let needsRevalidation = false;
|
|
1107
|
+
this.store.batch({
|
|
1108
|
+
optimisticId,
|
|
1109
|
+
changes
|
|
1110
|
+
}, (batch) => {
|
|
1111
|
+
const existingList = new Set(batch.read(this.cacheKey)?.value?.data);
|
|
1112
|
+
const toAdd = new Set(
|
|
1113
|
+
// easy case. objects are new to the cache and they match this filter
|
|
1114
|
+
relevantObjects.added.strictMatches
|
|
1115
|
+
);
|
|
1116
|
+
const toRemove = /* @__PURE__ */ new Set();
|
|
1117
|
+
for (const obj of relevantObjects.modified.all) {
|
|
1118
|
+
if (relevantObjects.modified.strictMatches.has(obj)) {
|
|
1119
|
+
const objectCacheKey = this.store.getCacheKey("object", obj.$objectType, obj.$primaryKey);
|
|
1120
|
+
if (!existingList.has(objectCacheKey)) {
|
|
1121
|
+
toAdd.add(obj);
|
|
1122
|
+
}
|
|
1123
|
+
continue;
|
|
1124
|
+
} else if (batch.optimisticWrite) {
|
|
1125
|
+
continue;
|
|
1126
|
+
} else {
|
|
1127
|
+
const existingObjectCacheKey = this.store.getCacheKey("object", obj.$objectType, obj.$primaryKey);
|
|
1128
|
+
toRemove.add(existingObjectCacheKey);
|
|
1129
|
+
if (relevantObjects.modified.sortaMatches.has(obj)) {
|
|
1130
|
+
needsRevalidation = true;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
for (const key of existingList) {
|
|
1135
|
+
if (toRemove.has(key)) continue;
|
|
1136
|
+
newList.push(key);
|
|
1137
|
+
}
|
|
1138
|
+
for (const obj of toAdd) {
|
|
1139
|
+
newList.push(this.store.getCacheKey("object", obj.$objectType, obj.$primaryKey));
|
|
1140
|
+
}
|
|
1141
|
+
this._updateList(
|
|
1142
|
+
newList,
|
|
1143
|
+
/* append */
|
|
1144
|
+
false,
|
|
1145
|
+
status,
|
|
1146
|
+
batch
|
|
1147
|
+
);
|
|
1148
|
+
});
|
|
1149
|
+
if (needsRevalidation) {
|
|
1150
|
+
return this.revalidate(true);
|
|
1151
|
+
}
|
|
1152
|
+
return void 0;
|
|
1153
|
+
} finally {
|
|
1154
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1155
|
+
this.logger?.child({
|
|
1156
|
+
methodName: "maybeUpdateAndRevalidate"
|
|
1157
|
+
}).debug("in finally");
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
_extractRelevantObjects(changes) {
|
|
1162
|
+
const relevantObjects = this.#type === "object" ? this.#extractRelevantObjectsForTypeObject(changes) : this.#extractRelevantObjectsForTypeInterface(changes);
|
|
1163
|
+
for (const group of Object.values(relevantObjects)) {
|
|
1164
|
+
for (const obj of group.all ?? []) {
|
|
549
1165
|
const strictMatch = objectSortaMatchesWhereClause(obj, this.#whereClause, true);
|
|
550
1166
|
if (strictMatch) {
|
|
551
|
-
|
|
1167
|
+
group.strictMatches.add(obj);
|
|
552
1168
|
} else {
|
|
553
1169
|
const sortaMatch = objectSortaMatchesWhereClause(obj, this.#whereClause, false);
|
|
554
1170
|
if (sortaMatch) {
|
|
555
|
-
|
|
1171
|
+
group.sortaMatches.add(obj);
|
|
556
1172
|
}
|
|
557
1173
|
}
|
|
558
1174
|
}
|
|
559
1175
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
1176
|
+
return relevantObjects;
|
|
1177
|
+
}
|
|
1178
|
+
#extractRelevantObjectsForTypeInterface(changes) {
|
|
1179
|
+
const added = Array.from(changes.addedObjects).filter(([, object]) => {
|
|
1180
|
+
return this.#apiName in object[chunkT4NIFYZS_cjs.ObjectDefRef].interfaceMap;
|
|
1181
|
+
}).map(([, object]) => object.$as(this.#apiName));
|
|
1182
|
+
const modified = Array.from(changes.modifiedObjects).filter(([, object]) => {
|
|
1183
|
+
return this.#apiName in object[chunkT4NIFYZS_cjs.ObjectDefRef].interfaceMap;
|
|
1184
|
+
}).map(([, object]) => object.$as(this.#apiName));
|
|
1185
|
+
return {
|
|
1186
|
+
added: {
|
|
1187
|
+
all: added,
|
|
1188
|
+
strictMatches: /* @__PURE__ */ new Set(),
|
|
1189
|
+
sortaMatches: /* @__PURE__ */ new Set()
|
|
1190
|
+
},
|
|
1191
|
+
modified: {
|
|
1192
|
+
all: modified,
|
|
1193
|
+
strictMatches: /* @__PURE__ */ new Set(),
|
|
1194
|
+
sortaMatches: /* @__PURE__ */ new Set()
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
569
1197
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
1198
|
+
#extractRelevantObjectsForTypeObject(changes) {
|
|
1199
|
+
return {
|
|
1200
|
+
added: {
|
|
1201
|
+
all: changes.addedObjects.get(this.cacheKey.otherKeys[API_NAME_IDX]) ?? [],
|
|
1202
|
+
strictMatches: /* @__PURE__ */ new Set(),
|
|
1203
|
+
sortaMatches: /* @__PURE__ */ new Set()
|
|
1204
|
+
},
|
|
1205
|
+
modified: {
|
|
1206
|
+
all: changes.modifiedObjects.get(this.cacheKey.otherKeys[API_NAME_IDX]) ?? [],
|
|
1207
|
+
strictMatches: /* @__PURE__ */ new Set(),
|
|
1208
|
+
sortaMatches: /* @__PURE__ */ new Set()
|
|
575
1209
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
_sortCacheKeys(objectCacheKeys, batch) {
|
|
1213
|
+
if (Object.keys(this.#orderBy).length > 0) {
|
|
1214
|
+
objectCacheKeys = objectCacheKeys.sort((a, b) => {
|
|
1215
|
+
for (const sortFn of this.#sortFns) {
|
|
1216
|
+
const ret = sortFn(batch.read(a)?.value?.$as(this.#apiName), batch.read(b)?.value?.$as(this.#apiName));
|
|
1217
|
+
if (ret !== 0) {
|
|
1218
|
+
return ret;
|
|
1219
|
+
}
|
|
580
1220
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
if (needsRevalidation) {
|
|
584
|
-
return this.revalidate(true);
|
|
1221
|
+
return 0;
|
|
1222
|
+
});
|
|
585
1223
|
}
|
|
586
|
-
return
|
|
1224
|
+
return objectCacheKeys;
|
|
587
1225
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
1226
|
+
registerStreamUpdates(sub) {
|
|
1227
|
+
const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
|
|
1228
|
+
methodName: "registerStreamUpdates"
|
|
1229
|
+
}) : this.logger;
|
|
1230
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1231
|
+
logger?.child({
|
|
1232
|
+
methodName: "observeList"
|
|
1233
|
+
}).info("Subscribing from websocket");
|
|
1234
|
+
}
|
|
1235
|
+
const websocketSubscription = this.#objectSet.subscribe({
|
|
1236
|
+
onChange: this.#onOswChange.bind(this),
|
|
1237
|
+
onError: this.#onOswError.bind(this),
|
|
1238
|
+
onOutOfDate: this.#onOswOutOfDate.bind(this),
|
|
1239
|
+
onSuccessfulSubscription: this.#onOswSuccessfulSubscription.bind(this)
|
|
593
1240
|
});
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
this.#toRelease.delete(objectCacheKey);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
for (const objectCacheKey of objectCacheKeys) {
|
|
603
|
-
this.#toRelease.add(objectCacheKey);
|
|
604
|
-
this.store.retain(objectCacheKey);
|
|
1241
|
+
sub.add(() => {
|
|
1242
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1243
|
+
logger?.child({
|
|
1244
|
+
methodName: "observeList"
|
|
1245
|
+
}).info("Unsubscribing from websocket");
|
|
605
1246
|
}
|
|
1247
|
+
websocketSubscription.unsubscribe();
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
#onOswSuccessfulSubscription() {
|
|
1251
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1252
|
+
this.logger?.child({
|
|
1253
|
+
methodName: "onSuccessfulSubscription"
|
|
1254
|
+
}).debug("");
|
|
606
1255
|
}
|
|
607
|
-
|
|
608
|
-
|
|
1256
|
+
}
|
|
1257
|
+
#onOswOutOfDate() {
|
|
1258
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1259
|
+
this.logger?.child({
|
|
1260
|
+
methodName: "onOutOfDate"
|
|
1261
|
+
}).info("");
|
|
609
1262
|
}
|
|
610
|
-
return this.writeToStore({
|
|
611
|
-
data: objectCacheKeys
|
|
612
|
-
}, status, batch);
|
|
613
1263
|
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
1264
|
+
#onOswError(errors) {
|
|
1265
|
+
if (this.logger) {
|
|
1266
|
+
this.logger?.child({
|
|
1267
|
+
methodName: "onError"
|
|
1268
|
+
}).error("subscription errors", errors);
|
|
618
1269
|
}
|
|
619
|
-
const ret = batch.write(this.cacheKey, data, status);
|
|
620
|
-
batch.modifiedLists.add(this.cacheKey);
|
|
621
|
-
return ret;
|
|
622
1270
|
}
|
|
623
|
-
|
|
624
|
-
|
|
1271
|
+
#onOswChange({
|
|
1272
|
+
object: objOrIface,
|
|
1273
|
+
state
|
|
1274
|
+
}) {
|
|
1275
|
+
const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
|
|
1276
|
+
methodName: "registerStreamUpdates"
|
|
1277
|
+
}) : this.logger;
|
|
1278
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1279
|
+
logger?.child({
|
|
1280
|
+
methodName: "onChange"
|
|
1281
|
+
}).debug(`Got an update of type: ${state}`, objOrIface);
|
|
1282
|
+
}
|
|
1283
|
+
if (state === "ADDED_OR_UPDATED") {
|
|
1284
|
+
const object = objOrIface.$apiName !== objOrIface.$objectType ? objOrIface.$as(objOrIface.$objectType) : objOrIface;
|
|
1285
|
+
this.store.batch({}, (batch) => {
|
|
1286
|
+
storeOsdkInstances(this.store, [object], batch);
|
|
1287
|
+
});
|
|
1288
|
+
} else if (state === "REMOVED") {
|
|
1289
|
+
this.#onOswRemoved(objOrIface, logger);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
#onOswRemoved(objOrIface, logger) {
|
|
625
1293
|
this.store.batch({}, (batch) => {
|
|
626
|
-
const
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
1294
|
+
const existing = batch.read(this.cacheKey);
|
|
1295
|
+
!existing ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "the truth value for our list should exist as we already subscribed") : invariant2__default.default(false) : undefined;
|
|
1296
|
+
if (existing.status === "loaded") {
|
|
1297
|
+
const objectCacheKey = this.store.getCacheKey("object", objOrIface.$objectType, objOrIface.$primaryKey);
|
|
1298
|
+
const newObjects = existing.value?.data.filter((o) => o !== objectCacheKey);
|
|
1299
|
+
if (newObjects?.length !== existing.value?.data.length) {
|
|
1300
|
+
batch.changes.registerList(this.cacheKey);
|
|
1301
|
+
batch.write(this.cacheKey, {
|
|
1302
|
+
data: newObjects ?? []
|
|
1303
|
+
}, "loaded");
|
|
630
1304
|
}
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1308
|
+
logger?.info("Removing an object from an object list that is in the middle of being loaded.", existing);
|
|
631
1309
|
}
|
|
1310
|
+
this.revalidate(
|
|
1311
|
+
/* force */
|
|
1312
|
+
true
|
|
1313
|
+
).catch((e) => {
|
|
1314
|
+
if (logger) {
|
|
1315
|
+
logger?.error("Uncaught error while revalidating list", e);
|
|
1316
|
+
} else {
|
|
1317
|
+
console.error("Uncaught error while revalidating list", e);
|
|
1318
|
+
}
|
|
1319
|
+
});
|
|
632
1320
|
});
|
|
633
1321
|
}
|
|
634
1322
|
};
|
|
635
|
-
function
|
|
636
|
-
|
|
1323
|
+
function removeDuplicates(objectCacheKeys, batch) {
|
|
1324
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1325
|
+
objectCacheKeys = objectCacheKeys.filter((key) => {
|
|
1326
|
+
batch.read(key);
|
|
1327
|
+
if (visited.has(key)) {
|
|
1328
|
+
return false;
|
|
1329
|
+
}
|
|
1330
|
+
visited.add(key);
|
|
1331
|
+
return true;
|
|
1332
|
+
});
|
|
1333
|
+
return objectCacheKeys;
|
|
637
1334
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
1335
|
+
function createOrderBySortFns(orderBy) {
|
|
1336
|
+
return Object.entries(orderBy).map(([key, order]) => {
|
|
1337
|
+
return (a, b) => {
|
|
1338
|
+
const aValue = a?.[key];
|
|
1339
|
+
const bValue = b?.[key];
|
|
1340
|
+
if (aValue == null && bValue == null) {
|
|
1341
|
+
return 0;
|
|
1342
|
+
}
|
|
1343
|
+
if (aValue == null) {
|
|
1344
|
+
return 1;
|
|
1345
|
+
}
|
|
1346
|
+
if (bValue == null) {
|
|
1347
|
+
return -1;
|
|
1348
|
+
}
|
|
1349
|
+
const m = order === "asc" ? -1 : 1;
|
|
1350
|
+
return aValue < bValue ? m : aValue > bValue ? -m : 0;
|
|
1351
|
+
};
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
async function reloadDataAsFullObjects(client, data) {
|
|
1355
|
+
const groups = groupBy__default.default(data, (x) => x.$objectType);
|
|
1356
|
+
const objectTypeToPrimaryKeyToObject = Object.fromEntries(await Promise.all(Object.entries(groups).map(async ([apiName, objects]) => {
|
|
1357
|
+
const objectDef = objects[0][chunkT4NIFYZS_cjs.UnderlyingOsdkObject][chunkT4NIFYZS_cjs.ObjectDefRef];
|
|
1358
|
+
const where = {
|
|
1359
|
+
[objectDef.primaryKeyApiName]: {
|
|
1360
|
+
$in: objects.map((x) => x.$primaryKey)
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
const result = await client(objectDef).where(where).fetchPage();
|
|
1364
|
+
return [apiName, Object.fromEntries(result.data.map((x) => [x.$primaryKey, x]))];
|
|
1365
|
+
})));
|
|
1366
|
+
data = data.map((obj) => {
|
|
1367
|
+
!objectTypeToPrimaryKeyToObject[obj.$objectType][obj.$primaryKey] ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Could not find object ${obj.$objectType} ${obj.$primaryKey}`) : invariant2__default.default(false) : undefined;
|
|
1368
|
+
return objectTypeToPrimaryKeyToObject[obj.$objectType][obj.$primaryKey];
|
|
1369
|
+
});
|
|
1370
|
+
return data;
|
|
1371
|
+
}
|
|
1372
|
+
function isListCacheKey(cacheKey) {
|
|
1373
|
+
return cacheKey.type === "list";
|
|
1374
|
+
}
|
|
1375
|
+
var defaultMakeData = () => /* @__PURE__ */ Object.create(null);
|
|
1376
|
+
var WeakRefTrie = class {
|
|
1377
|
+
#finalizer = new FinalizationRegistry((orderBy) => {
|
|
1378
|
+
this.#trie.removeArray(Object.entries(orderBy).flat());
|
|
1379
|
+
});
|
|
1380
|
+
#trie;
|
|
1381
|
+
constructor(makeData = defaultMakeData) {
|
|
1382
|
+
this.#trie = new trie.Trie(false, (array) => {
|
|
1383
|
+
const data = makeData(array);
|
|
1384
|
+
this.#finalizer.register(data, array);
|
|
1385
|
+
return new WeakRef(data);
|
|
671
1386
|
});
|
|
672
1387
|
}
|
|
673
|
-
|
|
674
|
-
const
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
if (entry) {
|
|
680
|
-
batch.modifiedObjects.add(this.cacheKey);
|
|
681
|
-
} else {
|
|
682
|
-
batch.addedObjects.add(this.cacheKey);
|
|
1388
|
+
lookupArray(array) {
|
|
1389
|
+
const maybe = this.#trie.lookupArray(array);
|
|
1390
|
+
let ret = maybe.deref();
|
|
1391
|
+
if (maybe && !ret) {
|
|
1392
|
+
this.#trie.removeArray(array);
|
|
1393
|
+
ret = this.#trie.lookupArray(array).deref();
|
|
683
1394
|
}
|
|
684
1395
|
return ret;
|
|
685
1396
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
if (createOptimisticId.counter === undefined) {
|
|
692
|
-
createOptimisticId.counter = 0;
|
|
1397
|
+
peekArray(array) {
|
|
1398
|
+
const maybe = this.#trie.peekArray(array);
|
|
1399
|
+
const ret = maybe?.deref();
|
|
1400
|
+
if (maybe && !ret) {
|
|
1401
|
+
this.#trie.removeArray(array);
|
|
693
1402
|
}
|
|
694
|
-
return
|
|
695
|
-
__optimisticId: createOptimisticId.counter++
|
|
696
|
-
};
|
|
1403
|
+
return ret;
|
|
697
1404
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
// src/observable/internal/OptimisticJob.ts
|
|
702
|
-
var OptimisticJob = class {
|
|
703
|
-
#result;
|
|
704
|
-
constructor(store, optimisticId) {
|
|
705
|
-
const updatedObjects = [];
|
|
706
|
-
const addedObjects = [];
|
|
707
|
-
this.getResult = () => {
|
|
708
|
-
return this.#result ??= (async () => {
|
|
709
|
-
const changes = {
|
|
710
|
-
addedObjects: new mnemonist.MultiMap(),
|
|
711
|
-
modifiedObjects: new mnemonist.MultiMap()
|
|
712
|
-
};
|
|
713
|
-
const settled = await Promise.allSettled(addedObjects);
|
|
714
|
-
for (const added of settled) {
|
|
715
|
-
if (added.status === "fulfilled") {
|
|
716
|
-
changes.addedObjects.set(added.value.$objectType, added.value);
|
|
717
|
-
} else {
|
|
718
|
-
throw added;
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
for (const modified of updatedObjects) {
|
|
722
|
-
changes.modifiedObjects.set(modified.$apiName, modified);
|
|
723
|
-
}
|
|
724
|
-
store.batch({
|
|
725
|
-
optimisticId
|
|
726
|
-
}, (batch) => {
|
|
727
|
-
for (const a of ["addedObjects", "modifiedObjects"]) {
|
|
728
|
-
for (const b of changes[a].values()) {
|
|
729
|
-
store.getObjectQuery(b.$objectType, b.$primaryKey).writeToStore(b, "loading", batch);
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
});
|
|
733
|
-
return changes;
|
|
734
|
-
})();
|
|
735
|
-
};
|
|
736
|
-
this.context = {
|
|
737
|
-
updateObject(value) {
|
|
738
|
-
updatedObjects.push(value);
|
|
739
|
-
return this;
|
|
740
|
-
},
|
|
741
|
-
createObject(type, pk, properties) {
|
|
742
|
-
const create = store.client[chunkFWVJ2AKD_cjs.additionalContext].objectFactory2(store.client[chunkFWVJ2AKD_cjs.additionalContext], [{
|
|
743
|
-
$primaryKey: pk,
|
|
744
|
-
$apiName: type.apiName,
|
|
745
|
-
$objectType: type.apiName,
|
|
746
|
-
...properties
|
|
747
|
-
}], undefined).then((x) => x[0]);
|
|
748
|
-
addedObjects.push(create);
|
|
749
|
-
return this;
|
|
750
|
-
}
|
|
751
|
-
};
|
|
1405
|
+
removeArray(array) {
|
|
1406
|
+
return this.#trie.removeArray(array)?.deref();
|
|
752
1407
|
}
|
|
753
1408
|
};
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
1409
|
+
var OrderByCanonicalizer = class {
|
|
1410
|
+
#trie = new WeakRefTrie((array) => {
|
|
1411
|
+
const pairs = array.reduce(function(result, _, index, array2) {
|
|
1412
|
+
if (index % 2 === 0 && array2[index] != null) {
|
|
1413
|
+
result.push(array2.slice(index, index + 2));
|
|
1414
|
+
}
|
|
1415
|
+
return result;
|
|
1416
|
+
}, []);
|
|
1417
|
+
let data = Object.fromEntries(pairs);
|
|
1418
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1419
|
+
data = Object.freeze(data);
|
|
1420
|
+
}
|
|
1421
|
+
return data;
|
|
763
1422
|
});
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
});
|
|
1423
|
+
canonicalize = (orderBy) => {
|
|
1424
|
+
const strings = Object.entries(orderBy).flat();
|
|
1425
|
+
return this.#trie.lookupArray(strings);
|
|
768
1426
|
};
|
|
769
|
-
}
|
|
1427
|
+
};
|
|
770
1428
|
|
|
771
1429
|
// src/observable/internal/RefCounts.ts
|
|
772
1430
|
var RefCounts = class {
|
|
@@ -792,8 +1450,8 @@ var RefCounts = class {
|
|
|
792
1450
|
}
|
|
793
1451
|
}
|
|
794
1452
|
release(key) {
|
|
795
|
-
const count = this.refCounts.get(key)
|
|
796
|
-
if (count === 1) {
|
|
1453
|
+
const count = this.refCounts.get(key);
|
|
1454
|
+
if (count === undefined) ; else if (count === 1) {
|
|
797
1455
|
this.refCounts.delete(key);
|
|
798
1456
|
this.gcMap.set(key, Date.now() + this.keepAlive);
|
|
799
1457
|
} else {
|
|
@@ -814,6 +1472,14 @@ var RefCounts = class {
|
|
|
814
1472
|
}
|
|
815
1473
|
};
|
|
816
1474
|
var WhereClauseCanonicalizer = class {
|
|
1475
|
+
/**
|
|
1476
|
+
* This is a shortcut cache for any WhereClause's that we have
|
|
1477
|
+
* seen and already canonicalized. The theory behind this
|
|
1478
|
+
* is that well behaving React applications will either `useMemo`
|
|
1479
|
+
* their where clause, or store it in state or pass it through as
|
|
1480
|
+
* props such that we are likely to get the same WhereClause
|
|
1481
|
+
* object multiple times and we can skip unnecessary work.
|
|
1482
|
+
*/
|
|
817
1483
|
#cache = /* @__PURE__ */ new WeakMap();
|
|
818
1484
|
/**
|
|
819
1485
|
* This is a trie that stores the sorted collapsed keys of a where clause to
|
|
@@ -831,14 +1497,14 @@ var WhereClauseCanonicalizer = class {
|
|
|
831
1497
|
return this.#cache.get(where);
|
|
832
1498
|
}
|
|
833
1499
|
const keysSet = /* @__PURE__ */ new Set();
|
|
834
|
-
const
|
|
1500
|
+
const calculatedCanon = this.#toCanon(where, keysSet);
|
|
835
1501
|
const cacheKey = this.#trie.lookupArray(Array.from(keysSet).sort());
|
|
836
1502
|
const lookupEntry = this.#existingOptions.get(cacheKey) ?? {
|
|
837
1503
|
options: []
|
|
838
1504
|
};
|
|
839
1505
|
this.#existingOptions.set(cacheKey, lookupEntry);
|
|
840
|
-
const canon = lookupEntry.options.find((ref) => deepEqual__default.default(ref.deref(),
|
|
841
|
-
if (canon ===
|
|
1506
|
+
const canon = lookupEntry.options.find((ref) => deepEqual__default.default(ref.deref(), calculatedCanon))?.deref() ?? calculatedCanon;
|
|
1507
|
+
if (canon === calculatedCanon) {
|
|
842
1508
|
lookupEntry.options.push(new WeakRef(canon));
|
|
843
1509
|
}
|
|
844
1510
|
this.#cache.set(where, canon);
|
|
@@ -871,7 +1537,6 @@ var WhereClauseCanonicalizer = class {
|
|
|
871
1537
|
};
|
|
872
1538
|
|
|
873
1539
|
// src/observable/internal/Store.ts
|
|
874
|
-
var ACTION_DELAY = process.env.NODE_ENV === "production" ? 0 : 1e3;
|
|
875
1540
|
function createInitEntry(cacheKey) {
|
|
876
1541
|
return {
|
|
877
1542
|
cacheKey,
|
|
@@ -882,17 +1547,26 @@ function createInitEntry(cacheKey) {
|
|
|
882
1547
|
}
|
|
883
1548
|
var Store = class {
|
|
884
1549
|
whereCanonicalizer = new WhereClauseCanonicalizer();
|
|
1550
|
+
orderByCanonicalizer = new OrderByCanonicalizer();
|
|
885
1551
|
#truthLayer = new Layer(undefined, undefined);
|
|
886
1552
|
#topLayer;
|
|
887
|
-
|
|
1553
|
+
/** @internal */
|
|
1554
|
+
// we can use a regular Map here because the refCounting will
|
|
1555
|
+
// handle cleanup.
|
|
1556
|
+
#queries = /* @__PURE__ */ new Map();
|
|
888
1557
|
#cacheKeyToSubject = /* @__PURE__ */ new WeakMap();
|
|
889
1558
|
#cacheKeys;
|
|
890
1559
|
#refCounts = new RefCounts(6e4, (k) => this.#cleanupCacheKey(k));
|
|
1560
|
+
// we are currently only using this for debug logging and should just remove it in the future if that
|
|
1561
|
+
// continues to be true
|
|
891
1562
|
#finalizationRegistry;
|
|
892
1563
|
constructor(client) {
|
|
893
1564
|
this.client = client;
|
|
1565
|
+
this.logger = client[chunkEY52J5Z4_cjs.additionalContext].logger?.child({}, {
|
|
1566
|
+
msgPrefix: "Store"
|
|
1567
|
+
});
|
|
894
1568
|
this.#topLayer = this.#truthLayer;
|
|
895
|
-
this.#cacheKeys = new CacheKeys(this.whereCanonicalizer, (k) => {
|
|
1569
|
+
this.#cacheKeys = new CacheKeys(this.whereCanonicalizer, this.orderByCanonicalizer, (k) => {
|
|
896
1570
|
this.#refCounts.register(k);
|
|
897
1571
|
});
|
|
898
1572
|
setInterval(() => {
|
|
@@ -970,63 +1644,73 @@ var Store = class {
|
|
|
970
1644
|
}
|
|
971
1645
|
return subject;
|
|
972
1646
|
};
|
|
1647
|
+
canonicalizeWhereClause(where) {
|
|
1648
|
+
return this.whereCanonicalizer.canonicalize(where);
|
|
1649
|
+
}
|
|
973
1650
|
observeObject(apiName, pk, options, subFn) {
|
|
974
1651
|
if (typeof apiName !== "string") {
|
|
975
1652
|
apiName = apiName.apiName;
|
|
976
1653
|
}
|
|
977
1654
|
const query = this.getObjectQuery(apiName, pk);
|
|
978
|
-
this
|
|
1655
|
+
this.retain(query.cacheKey);
|
|
979
1656
|
if (options.mode !== "offline") {
|
|
980
|
-
|
|
1657
|
+
query.revalidate(options.mode === "force").catch((e) => {
|
|
1658
|
+
subFn.error(e);
|
|
1659
|
+
if (this.logger) {
|
|
1660
|
+
this.logger.error("Unhandled error in observeObject", e);
|
|
1661
|
+
} else {
|
|
1662
|
+
throw e;
|
|
1663
|
+
}
|
|
1664
|
+
});
|
|
981
1665
|
}
|
|
982
|
-
const sub = query.subscribe(
|
|
983
|
-
next: subFn
|
|
984
|
-
});
|
|
1666
|
+
const sub = query.subscribe(subFn);
|
|
985
1667
|
return {
|
|
986
1668
|
unsubscribe: () => {
|
|
987
1669
|
sub.unsubscribe();
|
|
988
|
-
this
|
|
1670
|
+
this.release(query.cacheKey);
|
|
989
1671
|
}
|
|
990
1672
|
};
|
|
991
1673
|
}
|
|
992
|
-
observeList(
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
}
|
|
996
|
-
const query = this.getListQuery(apiName, where, options);
|
|
997
|
-
this.#refCounts.retain(query.cacheKey);
|
|
1674
|
+
observeList(options, subFn) {
|
|
1675
|
+
const query = this.getListQuery(options.type, options.where ?? {}, options.orderBy ?? {}, options);
|
|
1676
|
+
this.retain(query.cacheKey);
|
|
998
1677
|
if (options.mode !== "offline") {
|
|
999
|
-
|
|
1678
|
+
query.revalidate(options.mode === "force").catch((x) => {
|
|
1679
|
+
subFn.error(x);
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
const sub = query.subscribe(subFn);
|
|
1683
|
+
if (options.streamUpdates) {
|
|
1684
|
+
query.registerStreamUpdates(sub);
|
|
1000
1685
|
}
|
|
1001
|
-
const sub = query.subscribe({
|
|
1002
|
-
next: subFn
|
|
1003
|
-
});
|
|
1004
1686
|
return {
|
|
1005
1687
|
unsubscribe: () => {
|
|
1006
1688
|
sub.unsubscribe();
|
|
1007
|
-
this
|
|
1689
|
+
this.release(query.cacheKey);
|
|
1008
1690
|
}
|
|
1009
1691
|
};
|
|
1010
1692
|
}
|
|
1011
|
-
|
|
1693
|
+
peekQuery(cacheKey) {
|
|
1012
1694
|
return this.#queries.get(cacheKey);
|
|
1013
1695
|
}
|
|
1014
1696
|
#getQuery(cacheKey, createQuery) {
|
|
1015
|
-
let query = this
|
|
1697
|
+
let query = this.peekQuery(cacheKey);
|
|
1016
1698
|
if (!query) {
|
|
1017
1699
|
query = createQuery();
|
|
1018
1700
|
this.#queries.set(cacheKey, query);
|
|
1019
1701
|
}
|
|
1020
1702
|
return query;
|
|
1021
1703
|
}
|
|
1022
|
-
getListQuery(
|
|
1023
|
-
|
|
1024
|
-
apiName
|
|
1025
|
-
|
|
1704
|
+
getListQuery(def, where, orderBy, opts) {
|
|
1705
|
+
const {
|
|
1706
|
+
apiName,
|
|
1707
|
+
type
|
|
1708
|
+
} = def;
|
|
1026
1709
|
const canonWhere = this.whereCanonicalizer.canonicalize(where);
|
|
1027
|
-
const
|
|
1710
|
+
const canonOrderBy = this.orderByCanonicalizer.canonicalize(orderBy);
|
|
1711
|
+
const listCacheKey = this.getCacheKey("list", type, apiName, canonWhere, canonOrderBy);
|
|
1028
1712
|
return this.#getQuery(listCacheKey, () => {
|
|
1029
|
-
return new ListQuery(this, this.getSubject(listCacheKey), apiName, canonWhere, listCacheKey, opts);
|
|
1713
|
+
return new ListQuery(this, this.getSubject(listCacheKey), type, apiName, canonWhere, canonOrderBy, listCacheKey, opts);
|
|
1030
1714
|
});
|
|
1031
1715
|
}
|
|
1032
1716
|
getObjectQuery(apiName, pk) {
|
|
@@ -1038,23 +1722,17 @@ var Store = class {
|
|
|
1038
1722
|
dedupeInterval: 0
|
|
1039
1723
|
}));
|
|
1040
1724
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
apiName = apiName.apiName;
|
|
1044
|
-
}
|
|
1045
|
-
const objectCacheKey = this.getCacheKey("object", apiName, pk);
|
|
1046
|
-
const objEntry = this.#topLayer.get(objectCacheKey);
|
|
1047
|
-
return objEntry?.value;
|
|
1725
|
+
getValue(cacheKey) {
|
|
1726
|
+
return this.#topLayer.get(cacheKey);
|
|
1048
1727
|
}
|
|
1049
1728
|
batch = ({
|
|
1050
|
-
optimisticId
|
|
1729
|
+
optimisticId,
|
|
1730
|
+
changes = createChangedObjects()
|
|
1051
1731
|
}, batchFn) => {
|
|
1052
1732
|
!(optimisticId === undefined || !!optimisticId) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "optimistic must be undefined or not falsy") : invariant2__default.default(false) : undefined;
|
|
1053
1733
|
let needsLayer = optimisticId !== undefined;
|
|
1054
1734
|
const batchContext = {
|
|
1055
|
-
|
|
1056
|
-
modifiedObjects: /* @__PURE__ */ new Set(),
|
|
1057
|
-
modifiedLists: /* @__PURE__ */ new Set(),
|
|
1735
|
+
changes,
|
|
1058
1736
|
createLayerIfNeeded: () => {
|
|
1059
1737
|
if (needsLayer) {
|
|
1060
1738
|
this.#topLayer = this.#topLayer.addLayer(optimisticId);
|
|
@@ -1066,16 +1744,12 @@ var Store = class {
|
|
|
1066
1744
|
const oldTopValue = this.#topLayer.get(cacheKey);
|
|
1067
1745
|
if (optimisticId) batchContext.createLayerIfNeeded();
|
|
1068
1746
|
const writeLayer = optimisticId ? this.#topLayer : this.#truthLayer;
|
|
1069
|
-
const newValue =
|
|
1070
|
-
cacheKey,
|
|
1071
|
-
value,
|
|
1072
|
-
lastUpdated: Date.now(),
|
|
1073
|
-
status
|
|
1074
|
-
};
|
|
1747
|
+
const newValue = new Entry(cacheKey, value, Date.now(), status);
|
|
1075
1748
|
writeLayer.set(cacheKey, newValue);
|
|
1076
1749
|
const newTopValue = this.#topLayer.get(cacheKey);
|
|
1077
1750
|
if (oldTopValue !== newTopValue) {
|
|
1078
1751
|
this.#cacheKeyToSubject.get(cacheKey)?.next({
|
|
1752
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-spread
|
|
1079
1753
|
...newValue,
|
|
1080
1754
|
isOptimistic: newTopValue?.value !== this.#truthLayer.get(cacheKey)?.value
|
|
1081
1755
|
});
|
|
@@ -1087,76 +1761,87 @@ var Store = class {
|
|
|
1087
1761
|
}
|
|
1088
1762
|
};
|
|
1089
1763
|
const retVal = batchFn(batchContext);
|
|
1764
|
+
this.maybeRevalidateQueries(changes, optimisticId).catch((e) => {
|
|
1765
|
+
if (this.logger) {
|
|
1766
|
+
this.logger.error("Unhandled error in batch", e);
|
|
1767
|
+
} else {
|
|
1768
|
+
console.error("Unhandled error in batch", e);
|
|
1769
|
+
throw e;
|
|
1770
|
+
}
|
|
1771
|
+
});
|
|
1090
1772
|
return {
|
|
1091
1773
|
batchResult: batchContext,
|
|
1092
|
-
retVal
|
|
1774
|
+
retVal,
|
|
1775
|
+
changes: batchContext.changes
|
|
1093
1776
|
};
|
|
1094
1777
|
};
|
|
1095
1778
|
invalidateObject(apiName, pk) {
|
|
1096
1779
|
if (typeof apiName !== "string") {
|
|
1097
1780
|
apiName = apiName.apiName;
|
|
1098
1781
|
}
|
|
1099
|
-
|
|
1100
|
-
|
|
1782
|
+
return this.getObjectQuery(apiName, pk).revalidate(
|
|
1783
|
+
/* force */
|
|
1784
|
+
true
|
|
1785
|
+
);
|
|
1101
1786
|
}
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
if (
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
}
|
|
1109
|
-
maybeUpdateLists(changes, optimisticId) {
|
|
1110
|
-
for (const [cacheKey, v] of this.#truthLayer.entries()) {
|
|
1111
|
-
if (isListCacheKey(cacheKey)) {
|
|
1112
|
-
void this.#peekQuery(cacheKey)?.maybeUpdate(changes, optimisticId);
|
|
1787
|
+
async maybeRevalidateQueries(changes, optimisticId) {
|
|
1788
|
+
if (changes.isEmpty()) {
|
|
1789
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1790
|
+
this.logger?.child({
|
|
1791
|
+
methodName: "maybeRevalidateQueries"
|
|
1792
|
+
}).debug("No changes, aborting");
|
|
1113
1793
|
}
|
|
1794
|
+
return;
|
|
1114
1795
|
}
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1796
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1797
|
+
this.logger?.child({
|
|
1798
|
+
methodName: "maybeRevalidateQueries"
|
|
1799
|
+
}).debug(DEBUG_ONLY__changesToString(changes), {
|
|
1800
|
+
optimisticId
|
|
1801
|
+
});
|
|
1119
1802
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1803
|
+
try {
|
|
1804
|
+
const promises = [];
|
|
1805
|
+
for (const cacheKey of this.#queries.keys()) {
|
|
1806
|
+
const promise = this.peekQuery(cacheKey)?.maybeUpdateAndRevalidate?.(changes, optimisticId);
|
|
1807
|
+
if (promise) promises.push(promise);
|
|
1808
|
+
}
|
|
1809
|
+
await Promise.all(promises);
|
|
1810
|
+
} finally {
|
|
1811
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1812
|
+
this.logger?.child({
|
|
1813
|
+
methodName: "maybeRevalidateQueries"
|
|
1814
|
+
}).debug("in finally", DEBUG_ONLY__changesToString(changes));
|
|
1123
1815
|
}
|
|
1124
1816
|
}
|
|
1125
1817
|
}
|
|
1126
|
-
|
|
1818
|
+
/**
|
|
1819
|
+
* @param apiName
|
|
1820
|
+
* @param changes The changes we know about / to update
|
|
1821
|
+
* @returns
|
|
1822
|
+
*/
|
|
1823
|
+
invalidateObjectType(apiName, changes) {
|
|
1127
1824
|
if (typeof apiName !== "string") {
|
|
1128
1825
|
apiName = apiName.apiName;
|
|
1129
1826
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
optimisticId
|
|
1135
|
-
} = {}) {
|
|
1136
|
-
if (typeof apiName !== "string") {
|
|
1137
|
-
apiName = apiName.apiName;
|
|
1827
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1828
|
+
this.logger?.child({
|
|
1829
|
+
methodName: "invalidateObjectType"
|
|
1830
|
+
}).info(changes ? DEBUG_ONLY__changesToString(changes) : undefined);
|
|
1138
1831
|
}
|
|
1139
|
-
const
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
}) {
|
|
1151
|
-
if (typeof apiName !== "string") {
|
|
1152
|
-
apiName = apiName.apiName;
|
|
1832
|
+
const promises = [];
|
|
1833
|
+
for (const cacheKey of this.#truthLayer.keys()) {
|
|
1834
|
+
if (isListCacheKey(cacheKey)) {
|
|
1835
|
+
if (!changes || !changes.modified.has(cacheKey)) {
|
|
1836
|
+
const promise = this.peekQuery(cacheKey)?.revalidate(true);
|
|
1837
|
+
if (promise) {
|
|
1838
|
+
promises.push(promise);
|
|
1839
|
+
changes?.modified.add(cacheKey);
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1153
1843
|
}
|
|
1154
|
-
|
|
1155
|
-
this.batch({
|
|
1156
|
-
optimisticId
|
|
1157
|
-
}, (b) => {
|
|
1158
|
-
query.updateList(values, false, "loaded", b);
|
|
1159
|
-
});
|
|
1844
|
+
return Promise.all(promises).then(() => undefined);
|
|
1160
1845
|
}
|
|
1161
1846
|
retain(cacheKey) {
|
|
1162
1847
|
this.#refCounts.retain(cacheKey);
|
|
@@ -1165,74 +1850,6 @@ var Store = class {
|
|
|
1165
1850
|
this.#refCounts.release(cacheKey);
|
|
1166
1851
|
}
|
|
1167
1852
|
};
|
|
1168
|
-
var ActionApplication = class {
|
|
1169
|
-
constructor(store) {
|
|
1170
|
-
this.store = store;
|
|
1171
|
-
}
|
|
1172
|
-
applyAction = (action, args, {
|
|
1173
|
-
optimisticUpdate
|
|
1174
|
-
} = {}) => {
|
|
1175
|
-
const removeOptimisticResult = runOptimisticJob(this.store, optimisticUpdate);
|
|
1176
|
-
return (async () => {
|
|
1177
|
-
try {
|
|
1178
|
-
const actionResults = await this.store.client(action).applyAction(args, {
|
|
1179
|
-
$returnEdits: true
|
|
1180
|
-
});
|
|
1181
|
-
if (ACTION_DELAY > 0) {
|
|
1182
|
-
console.log("action done, pausing");
|
|
1183
|
-
await delay(ACTION_DELAY);
|
|
1184
|
-
console.log("action done, pausing done");
|
|
1185
|
-
}
|
|
1186
|
-
await this.#invalidateActionEditResponse(actionResults);
|
|
1187
|
-
return actionResults;
|
|
1188
|
-
} finally {
|
|
1189
|
-
await removeOptimisticResult();
|
|
1190
|
-
}
|
|
1191
|
-
})();
|
|
1192
|
-
};
|
|
1193
|
-
#invalidateActionEditResponse = (value) => {
|
|
1194
|
-
const typesToInvalidate = /* @__PURE__ */ new Set();
|
|
1195
|
-
let promisesToWait = [];
|
|
1196
|
-
if (value.type === "edits") {
|
|
1197
|
-
for (const obj of value.modifiedObjects) {
|
|
1198
|
-
promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
|
|
1199
|
-
}
|
|
1200
|
-
for (const obj of value.addedObjects) {
|
|
1201
|
-
promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
|
|
1202
|
-
typesToInvalidate.add(obj.objectType);
|
|
1203
|
-
}
|
|
1204
|
-
promisesToWait = [Promise.allSettled(promisesToWait).then(() => {
|
|
1205
|
-
const changes2 = this.#changesFromActionEditResponse(value);
|
|
1206
|
-
this.store.maybeRevalidateLists(changes2);
|
|
1207
|
-
})];
|
|
1208
|
-
} else {
|
|
1209
|
-
for (const apiName of value.editedObjectTypes) {
|
|
1210
|
-
typesToInvalidate.add(apiName.toString());
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
return Promise.allSettled(promisesToWait).then(() => {
|
|
1214
|
-
for (const objectType of typesToInvalidate) {
|
|
1215
|
-
this.store.invalidateObjectType(objectType);
|
|
1216
|
-
}
|
|
1217
|
-
return value;
|
|
1218
|
-
});
|
|
1219
|
-
};
|
|
1220
|
-
#changesFromActionEditResponse = (value) => {
|
|
1221
|
-
const changes = createChangedObjects();
|
|
1222
|
-
for (const changeType of ["addedObjects", "modifiedObjects"]) {
|
|
1223
|
-
for (const {
|
|
1224
|
-
objectType,
|
|
1225
|
-
primaryKey
|
|
1226
|
-
} of value[changeType] ?? []) {
|
|
1227
|
-
const obj = this.store.getObject(objectType, primaryKey);
|
|
1228
|
-
if (obj) {
|
|
1229
|
-
changes[changeType].set(objectType, obj);
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
return changes;
|
|
1234
|
-
};
|
|
1235
|
-
};
|
|
1236
1853
|
|
|
1237
1854
|
// src/observable/ObservableClient.ts
|
|
1238
1855
|
function createObservableClient(client) {
|
|
@@ -1241,7 +1858,7 @@ function createObservableClient(client) {
|
|
|
1241
1858
|
|
|
1242
1859
|
Object.defineProperty(exports, "augment", {
|
|
1243
1860
|
enumerable: true,
|
|
1244
|
-
get: function () { return
|
|
1861
|
+
get: function () { return chunkEY52J5Z4_cjs.augment; }
|
|
1245
1862
|
});
|
|
1246
1863
|
exports.createObservableClient = createObservableClient;
|
|
1247
1864
|
//# sourceMappingURL=unstable-do-not-use.cjs.map
|