@webiny/api-core 6.6.0-alpha.1 → 6.6.0-alpha.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.
Files changed (264) hide show
  1. package/ApiCoreFeature.js +6 -2
  2. package/ApiCoreFeature.js.map +1 -1
  3. package/exports/api/tasks.d.ts +1 -0
  4. package/exports/api/tasks.js +1 -1
  5. package/exports/api.d.ts +1 -1
  6. package/exports/api.js +1 -1
  7. package/features/ai/Ai.d.ts +3 -1
  8. package/features/ai/Ai.js +36 -28
  9. package/features/ai/Ai.js.map +1 -1
  10. package/features/ai/AiModelRegistry.d.ts +14 -0
  11. package/features/ai/AiModelRegistry.js +39 -0
  12. package/features/ai/AiModelRegistry.js.map +1 -0
  13. package/features/ai/AiSdkToolHandlerResolver.d.ts +11 -0
  14. package/features/ai/AiSdkToolHandlerResolver.js +19 -0
  15. package/features/ai/AiSdkToolHandlerResolver.js.map +1 -0
  16. package/features/ai/AiSdkTools.d.ts +4 -3
  17. package/features/ai/AiSdkTools.js +11 -9
  18. package/features/ai/AiSdkTools.js.map +1 -1
  19. package/features/ai/AnthropicSdkFactory.js +12 -4
  20. package/features/ai/AnthropicSdkFactory.js.map +1 -1
  21. package/features/ai/DEVELOPERS.md +183 -0
  22. package/features/ai/GoogleSdkFactory.d.ts +10 -0
  23. package/features/ai/GoogleSdkFactory.js +65 -0
  24. package/features/ai/GoogleSdkFactory.js.map +1 -0
  25. package/features/ai/OpenAiSdkFactory.js +51 -11
  26. package/features/ai/OpenAiSdkFactory.js.map +1 -1
  27. package/features/ai/OpenRouterSdkFactory.d.ts +10 -0
  28. package/features/ai/OpenRouterSdkFactory.js +112 -0
  29. package/features/ai/OpenRouterSdkFactory.js.map +1 -0
  30. package/features/ai/RemoteAiModelCatalog.d.ts +13 -0
  31. package/features/ai/RemoteAiModelCatalog.js +74 -0
  32. package/features/ai/RemoteAiModelCatalog.js.map +1 -0
  33. package/features/ai/abstractions.d.ts +82 -6
  34. package/features/ai/abstractions.js +6 -2
  35. package/features/ai/abstractions.js.map +1 -1
  36. package/features/ai/feature.js +10 -0
  37. package/features/ai/feature.js.map +1 -1
  38. package/features/ai/index.d.ts +2 -4
  39. package/features/ai/index.js +1 -1
  40. package/features/debugger/Debugger.d.ts +30 -0
  41. package/features/debugger/Debugger.js +142 -0
  42. package/features/debugger/Debugger.js.map +1 -0
  43. package/features/debugger/DebuggerRouteDecorator.d.ts +45 -0
  44. package/features/debugger/DebuggerRouteDecorator.js +102 -0
  45. package/features/debugger/DebuggerRouteDecorator.js.map +1 -0
  46. package/features/debugger/GraphQLDebuggerTransport.d.ts +28 -0
  47. package/features/debugger/GraphQLDebuggerTransport.js +45 -0
  48. package/features/debugger/GraphQLDebuggerTransport.js.map +1 -0
  49. package/features/debugger/__tests__/matchNamespace.test.d.ts +1 -0
  50. package/features/debugger/__tests__/matchNamespace.test.js +68 -0
  51. package/features/debugger/__tests__/matchNamespace.test.js.map +1 -0
  52. package/features/debugger/__tests__/serialize.test.d.ts +1 -0
  53. package/features/debugger/__tests__/serialize.test.js +220 -0
  54. package/features/debugger/__tests__/serialize.test.js.map +1 -0
  55. package/features/debugger/abstractions.d.ts +100 -0
  56. package/features/debugger/abstractions.js +6 -0
  57. package/features/debugger/abstractions.js.map +1 -0
  58. package/features/debugger/feature.d.ts +5 -0
  59. package/features/debugger/feature.js +15 -0
  60. package/features/debugger/feature.js.map +1 -0
  61. package/features/debugger/index.d.ts +12 -0
  62. package/features/debugger/index.js +7 -0
  63. package/features/debugger/limits.d.ts +18 -0
  64. package/features/debugger/limits.js +11 -0
  65. package/features/debugger/limits.js.map +1 -0
  66. package/features/debugger/matchNamespace.d.ts +14 -0
  67. package/features/debugger/matchNamespace.js +35 -0
  68. package/features/debugger/matchNamespace.js.map +1 -0
  69. package/features/debugger/parseNamespaceHeader.d.ts +7 -0
  70. package/features/debugger/parseNamespaceHeader.js +16 -0
  71. package/features/debugger/parseNamespaceHeader.js.map +1 -0
  72. package/features/debugger/permissions.d.ts +14 -0
  73. package/features/debugger/permissions.js +8 -0
  74. package/features/debugger/permissions.js.map +1 -0
  75. package/features/debugger/permissionsSchema.d.ts +17 -0
  76. package/features/debugger/permissionsSchema.js +18 -0
  77. package/features/debugger/permissionsSchema.js.map +1 -0
  78. package/features/debugger/serialize.d.ts +11 -0
  79. package/features/debugger/serialize.js +121 -0
  80. package/features/debugger/serialize.js.map +1 -0
  81. package/features/encryption/BuildParamsEncryptionConfig.d.ts +13 -0
  82. package/features/encryption/BuildParamsEncryptionConfig.js +19 -0
  83. package/features/encryption/BuildParamsEncryptionConfig.js.map +1 -0
  84. package/features/encryption/EncryptionKeyCacheFeature.d.ts +8 -0
  85. package/features/encryption/EncryptionKeyCacheFeature.js +11 -0
  86. package/features/encryption/EncryptionKeyCacheFeature.js.map +1 -0
  87. package/features/encryption/EncryptionService.d.ts +3 -2
  88. package/features/encryption/EncryptionService.js +15 -13
  89. package/features/encryption/EncryptionService.js.map +1 -1
  90. package/features/encryption/MemoryEncryptionKeyCache.d.ts +13 -0
  91. package/features/encryption/MemoryEncryptionKeyCache.js +26 -0
  92. package/features/encryption/MemoryEncryptionKeyCache.js.map +1 -0
  93. package/features/encryption/abstractions.d.ts +26 -0
  94. package/features/encryption/abstractions.js +3 -1
  95. package/features/encryption/abstractions.js.map +1 -1
  96. package/features/encryption/feature.js +2 -0
  97. package/features/encryption/feature.js.map +1 -1
  98. package/features/encryption/index.d.ts +3 -0
  99. package/features/encryption/index.js +3 -1
  100. package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js +13 -1
  101. package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js.map +1 -1
  102. package/features/hashing/BuildParamsHashingConfig.d.ts +11 -0
  103. package/features/hashing/BuildParamsHashingConfig.js +18 -0
  104. package/features/hashing/BuildParamsHashingConfig.js.map +1 -0
  105. package/features/hashing/ScryptHasher.d.ts +2 -2
  106. package/features/hashing/ScryptHasher.js +6 -8
  107. package/features/hashing/ScryptHasher.js.map +1 -1
  108. package/features/hashing/abstractions.d.ts +15 -0
  109. package/features/hashing/abstractions.js +2 -1
  110. package/features/hashing/abstractions.js.map +1 -1
  111. package/features/hashing/feature.js +2 -0
  112. package/features/hashing/feature.js.map +1 -1
  113. package/features/hashing/index.d.ts +1 -0
  114. package/features/hashing/index.js +1 -1
  115. package/features/httpClient/HttpClient.d.ts +7 -0
  116. package/features/httpClient/HttpClient.js +72 -0
  117. package/features/httpClient/HttpClient.js.map +1 -0
  118. package/features/httpClient/HttpRequestError.d.ts +10 -0
  119. package/features/httpClient/HttpRequestError.js +13 -0
  120. package/features/httpClient/HttpRequestError.js.map +1 -0
  121. package/features/httpClient/HttpStatusError.d.ts +12 -0
  122. package/features/httpClient/HttpStatusError.js +12 -0
  123. package/features/httpClient/HttpStatusError.js.map +1 -0
  124. package/features/httpClient/abstractions.d.ts +32 -0
  125. package/features/httpClient/abstractions.js +5 -0
  126. package/features/httpClient/abstractions.js.map +1 -0
  127. package/features/{logger → httpClient}/feature.d.ts +1 -1
  128. package/features/httpClient/feature.js +11 -0
  129. package/features/httpClient/feature.js.map +1 -0
  130. package/features/httpClient/index.d.ts +3 -0
  131. package/features/httpClient/index.js +3 -0
  132. package/features/keyValueStore/GlobalKeyValueStore.d.ts +9 -3
  133. package/features/keyValueStore/GlobalKeyValueStore.js +12 -2
  134. package/features/keyValueStore/GlobalKeyValueStore.js.map +1 -1
  135. package/features/keyValueStore/KeyValueStore.d.ts +6 -2
  136. package/features/keyValueStore/KeyValueStore.js +13 -3
  137. package/features/keyValueStore/KeyValueStore.js.map +1 -1
  138. package/features/keyValueStore/KeyValueStoreRepository.d.ts +8 -2
  139. package/features/keyValueStore/KeyValueStoreRepository.js +82 -4
  140. package/features/keyValueStore/KeyValueStoreRepository.js.map +1 -1
  141. package/features/keyValueStore/abstractions.d.ts +132 -14
  142. package/features/keyValueStore/abstractions.js.map +1 -1
  143. package/features/keyValueStore/errors.d.ts +29 -0
  144. package/features/keyValueStore/errors.js +49 -1
  145. package/features/keyValueStore/errors.js.map +1 -1
  146. package/features/keyValueStore/index.d.ts +4 -1
  147. package/features/keyValueStore/index.js +1 -1
  148. package/features/logger/NullLogger.d.ts +10 -0
  149. package/features/logger/NullLogger.js +12 -0
  150. package/features/logger/NullLogger.js.map +1 -0
  151. package/features/logger/index.d.ts +1 -0
  152. package/features/logger/index.js +1 -0
  153. package/features/publicUrls/NullPublicUrls.d.ts +11 -0
  154. package/features/publicUrls/NullPublicUrls.js +17 -0
  155. package/features/publicUrls/NullPublicUrls.js.map +1 -0
  156. package/features/publicUrls/PublicUrl.d.ts +24 -0
  157. package/features/publicUrls/PublicUrl.js +43 -0
  158. package/features/publicUrls/PublicUrl.js.map +1 -0
  159. package/features/publicUrls/__tests__/PublicUrl.test.d.ts +1 -0
  160. package/features/publicUrls/__tests__/PublicUrl.test.js +38 -0
  161. package/features/publicUrls/__tests__/PublicUrl.test.js.map +1 -0
  162. package/features/publicUrls/__tests__/PublicUrls.test.d.ts +1 -0
  163. package/features/publicUrls/__tests__/PublicUrls.test.js +14 -0
  164. package/features/publicUrls/__tests__/PublicUrls.test.js.map +1 -0
  165. package/features/publicUrls/abstractions.d.ts +27 -0
  166. package/features/publicUrls/abstractions.js +5 -0
  167. package/features/publicUrls/abstractions.js.map +1 -0
  168. package/features/publicUrls/feature.d.ts +8 -0
  169. package/features/publicUrls/feature.js +11 -0
  170. package/features/publicUrls/feature.js.map +1 -0
  171. package/features/publicUrls/index.d.ts +3 -0
  172. package/features/publicUrls/index.js +3 -0
  173. package/features/requestContext/RawAssumePermissions.d.ts +14 -0
  174. package/features/requestContext/RawAssumePermissions.js +19 -0
  175. package/features/requestContext/RawAssumePermissions.js.map +1 -0
  176. package/features/requestContext/abstractions.d.ts +22 -0
  177. package/features/requestContext/abstractions.js +2 -1
  178. package/features/requestContext/abstractions.js.map +1 -1
  179. package/features/requestContext/extractAssumePermissions.d.ts +14 -0
  180. package/features/requestContext/extractAssumePermissions.js +32 -0
  181. package/features/requestContext/extractAssumePermissions.js.map +1 -0
  182. package/features/requestContext/feature.d.ts +2 -1
  183. package/features/requestContext/feature.js +2 -0
  184. package/features/requestContext/feature.js.map +1 -1
  185. package/features/requestContext/index.d.ts +3 -1
  186. package/features/requestContext/index.js +2 -1
  187. package/features/security/IdentityContext/IdentityContext.d.ts +6 -2
  188. package/features/security/IdentityContext/IdentityContext.js +24 -7
  189. package/features/security/IdentityContext/IdentityContext.js.map +1 -1
  190. package/features/security/IdentityContext/abstractions.d.ts +6 -1
  191. package/features/security/IdentityContext/abstractions.js.map +1 -1
  192. package/features/security/authorization/AuthorizationContext/AuthorizationContext.d.ts +13 -3
  193. package/features/security/authorization/AuthorizationContext/AuthorizationContext.js +35 -22
  194. package/features/security/authorization/AuthorizationContext/AuthorizationContext.js.map +1 -1
  195. package/features/security/authorization/AuthorizationContext/abstractions.d.ts +2 -0
  196. package/features/security/authorization/AuthorizationContext/abstractions.js.map +1 -1
  197. package/features/security/authorization/AuthorizationContext/feature.js +6 -1
  198. package/features/security/authorization/AuthorizationContext/feature.js.map +1 -1
  199. package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.d.ts +30 -0
  200. package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.js +60 -0
  201. package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.js.map +1 -0
  202. package/features/security/authorization/GroupsTeamsAuthorizer/feature.js +2 -0
  203. package/features/security/authorization/GroupsTeamsAuthorizer/feature.js.map +1 -1
  204. package/features/security/roles/Installer/RolesInstaller.js +1 -0
  205. package/features/security/roles/Installer/RolesInstaller.js.map +1 -1
  206. package/features/task/TaskDefinition/abstractions.d.ts +13 -20
  207. package/features/task/TaskDefinition/abstractions.js.map +1 -1
  208. package/features/tenancy/TenantContext/TenantContext.d.ts +5 -1
  209. package/features/tenancy/TenantContext/TenantContext.js +31 -23
  210. package/features/tenancy/TenantContext/TenantContext.js.map +1 -1
  211. package/features/users/shared/loaders.js.map +1 -1
  212. package/features/users/shared/types.d.ts +9 -7
  213. package/features/wcp/WcpContext/WcpContext.d.ts +6 -1
  214. package/features/wcp/WcpContext/WcpContext.js +17 -2
  215. package/features/wcp/WcpContext/WcpContext.js.map +1 -1
  216. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +9 -73
  217. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +25 -5
  218. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
  219. package/features/wcp/WcpLicenseLoader.js.map +1 -1
  220. package/features/wcp/resolveWcpProjectEnvironment.d.ts +1 -1
  221. package/features/wcp/resolveWcpProjectEnvironment.js.map +1 -1
  222. package/graphql/ApiCoreSchemaFactory.d.ts +1 -0
  223. package/graphql/ApiCoreSchemaFactory.js +7 -1
  224. package/graphql/ApiCoreSchemaFactory.js.map +1 -1
  225. package/graphql/featureFlags/FeatureFlagsSchemaFactory.d.ts +1 -0
  226. package/graphql/featureFlags/FeatureFlagsSchemaFactory.js +4 -0
  227. package/graphql/featureFlags/FeatureFlagsSchemaFactory.js.map +1 -1
  228. package/graphql/security/SecuritySchemaFactory.d.ts +1 -0
  229. package/graphql/security/SecuritySchemaFactory.js +4 -0
  230. package/graphql/security/SecuritySchemaFactory.js.map +1 -1
  231. package/graphql/system/SystemSchemaFactory.d.ts +1 -0
  232. package/graphql/system/SystemSchemaFactory.js +4 -0
  233. package/graphql/system/SystemSchemaFactory.js.map +1 -1
  234. package/graphql/users/UsersSchemaFactory.d.ts +1 -0
  235. package/graphql/users/UsersSchemaFactory.js +4 -0
  236. package/graphql/users/UsersSchemaFactory.js.map +1 -1
  237. package/graphql/wcp/WcpSchemaFactory.d.ts +1 -0
  238. package/graphql/wcp/WcpSchemaFactory.js +5 -1
  239. package/graphql/wcp/WcpSchemaFactory.js.map +1 -1
  240. package/idp/JwksCache.d.ts +14 -3
  241. package/idp/JwksCache.js +97 -17
  242. package/idp/JwksCache.js.map +1 -1
  243. package/idp/JwksStoreFeature.d.ts +8 -0
  244. package/idp/JwksStoreFeature.js +11 -0
  245. package/idp/JwksStoreFeature.js.map +1 -0
  246. package/idp/MemoryJwksStore.d.ts +14 -0
  247. package/idp/MemoryJwksStore.js +21 -0
  248. package/idp/MemoryJwksStore.js.map +1 -0
  249. package/idp/OidcJwtIdentityProvider.js +5 -1
  250. package/idp/OidcJwtIdentityProvider.js.map +1 -1
  251. package/idp/abstractions.d.ts +24 -0
  252. package/idp/abstractions.js +2 -1
  253. package/idp/abstractions.js.map +1 -1
  254. package/idp/feature.js +1 -2
  255. package/idp/feature.js.map +1 -1
  256. package/idp/index.d.ts +1 -0
  257. package/idp/index.js +1 -0
  258. package/package.json +21 -21
  259. package/types/users.d.ts +2 -3
  260. package/features/logger/LoggerService.d.ts +0 -14
  261. package/features/logger/LoggerService.js +0 -48
  262. package/features/logger/LoggerService.js.map +0 -1
  263. package/features/logger/feature.js +0 -11
  264. package/features/logger/feature.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"features/keyValueStore/KeyValueStore.js","sources":["../../../src/features/keyValueStore/KeyValueStore.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { KeyValueStore as ServiceAbstraction } from \"./abstractions.js\";\nimport { GlobalKeyValueStore } from \"./abstractions.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\n\nclass KeyValueStoreImpl implements ServiceAbstraction.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private globalStore: GlobalKeyValueStore.Interface\n ) {}\n\n async get<T = unknown>(key: string): Promise<Result<T, ServiceAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n return this.globalStore.get<T>(key, { scope: tenant.id });\n }\n\n async set(key: string, value: any): Promise<Result<void, ServiceAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n return this.globalStore.set(key, value, { scope: tenant.id });\n }\n\n async delete(key: string): Promise<Result<void, ServiceAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n return this.globalStore.delete(key, { scope: tenant.id });\n }\n}\n\nexport const KeyValueStore = ServiceAbstraction.createImplementation({\n implementation: KeyValueStoreImpl,\n dependencies: [TenantContext, GlobalKeyValueStore]\n});\n"],"names":["KeyValueStoreImpl","tenantContext","globalStore","key","tenant","value","KeyValueStore","ServiceAbstraction","TenantContext","GlobalKeyValueStore"],"mappings":";;AAKA,MAAMA;IACF,YACYC,aAAsC,EACtCC,WAA0C,CACpD;aAFUD,aAAa,GAAbA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,IAAiBC,GAAW,EAAgD;QAC9E,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAID,KAAK;YAAE,OAAOC,OAAO,EAAE;QAAC;IAC3D;IAEA,MAAM,IAAID,GAAW,EAAEE,KAAU,EAAmD;QAChF,MAAMD,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAACD,KAAKE,OAAO;YAAE,OAAOD,OAAO,EAAE;QAAC;IAC/D;IAEA,MAAM,OAAOD,GAAW,EAAmD;QACvE,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAACD,KAAK;YAAE,OAAOC,OAAO,EAAE;QAAC;IAC3D;AACJ;AAEO,MAAME,8BAAgBC,cAAAA,oBAAuC,CAAC;IACjE,gBAAgBP;IAChB,cAAc;QAACQ;QAAeC;KAAoB;AACtD"}
1
+ {"version":3,"file":"features/keyValueStore/KeyValueStore.js","sources":["../../../src/features/keyValueStore/KeyValueStore.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { KeyValueStore as ServiceAbstraction } from \"./abstractions.js\";\nimport { GlobalKeyValueStore } from \"./abstractions.js\";\nimport type { IKeyValueSetOptions } from \"./abstractions.js\";\nimport type { IKeyValueDeleteOptions } from \"./abstractions.js\";\nimport type { IKeyValueListParams } from \"./abstractions.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\n\nclass KeyValueStoreImpl implements ServiceAbstraction.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private globalStore: GlobalKeyValueStore.Interface\n ) {}\n\n async get<T = unknown>(key: string): Promise<Result<T, ServiceAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n return this.globalStore.get<T>(key, { scope: tenant.id });\n }\n\n async set(\n key: string,\n value: any,\n options?: IKeyValueSetOptions\n ): Promise<Result<void, ServiceAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n return this.globalStore.set(key, value, {\n scope: tenant.id,\n collection: options?.collection,\n condition: options?.condition\n });\n }\n\n async delete(\n key: string,\n options?: IKeyValueDeleteOptions\n ): Promise<Result<void, ServiceAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n return this.globalStore.delete(key, { scope: tenant.id, condition: options?.condition });\n }\n\n async list<T = unknown>(\n params: IKeyValueListParams\n ): Promise<Result<ServiceAbstraction.ListResult<T>, ServiceAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n return this.globalStore.list<T>({ ...params, scope: tenant.id });\n }\n}\n\nexport const KeyValueStore = ServiceAbstraction.createImplementation({\n implementation: KeyValueStoreImpl,\n dependencies: [TenantContext, GlobalKeyValueStore]\n});\n"],"names":["KeyValueStoreImpl","tenantContext","globalStore","key","tenant","value","options","params","KeyValueStore","ServiceAbstraction","TenantContext","GlobalKeyValueStore"],"mappings":";;AAQA,MAAMA;IACF,YACYC,aAAsC,EACtCC,WAA0C,CACpD;aAFUD,aAAa,GAAbA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,IAAiBC,GAAW,EAAgD;QAC9E,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAID,KAAK;YAAE,OAAOC,OAAO,EAAE;QAAC;IAC3D;IAEA,MAAM,IACFD,GAAW,EACXE,KAAU,EACVC,OAA6B,EACkB;QAC/C,MAAMF,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAACD,KAAKE,OAAO;YACpC,OAAOD,OAAO,EAAE;YAChB,YAAYE,SAAS;YACrB,WAAWA,SAAS;QACxB;IACJ;IAEA,MAAM,OACFH,GAAW,EACXG,OAAgC,EACe;QAC/C,MAAMF,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAACD,KAAK;YAAE,OAAOC,OAAO,EAAE;YAAE,WAAWE,SAAS;QAAU;IAC1F;IAEA,MAAM,KACFC,MAA2B,EACgD;QAC3E,MAAMH,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAI;YAAE,GAAGG,MAAM;YAAE,OAAOH,OAAO,EAAE;QAAC;IAClE;AACJ;AAEO,MAAMI,8BAAgBC,cAAAA,oBAAuC,CAAC;IACjE,gBAAgBT;IAChB,cAAc;QAACU;QAAeC;KAAoB;AACtD"}
@@ -1,5 +1,10 @@
1
1
  import { Result } from "@webiny/feature/api";
2
- import { KeyValueStorageOperations, KeyValueStoreRepository as RepositoryAbstraction, type IKeyValueStoreSetOptions } from "./abstractions.js";
2
+ import { KeyValueStorageOperations } from "./abstractions.js";
3
+ import { KeyValueStoreRepository as RepositoryAbstraction } from "./abstractions.js";
4
+ import type { IKeyValueListParams } from "./abstractions.js";
5
+ import type { IKeyValueListResult } from "./abstractions.js";
6
+ import type { IKeyValueStoreSetOptions } from "./abstractions.js";
7
+ import type { IKeyValueDeleteOptions } from "./abstractions.js";
3
8
  /**
4
9
  * KeyValueStoreRepository implementation.
5
10
  *
@@ -11,7 +16,8 @@ declare class KeyValueStoreRepositoryImpl implements RepositoryAbstraction.Inter
11
16
  constructor(storageOperations: KeyValueStorageOperations.Interface);
12
17
  get<T = unknown>(key: string, scope: string): Promise<Result<T, RepositoryAbstraction.Error>>;
13
18
  set(key: string, value: any, scope: string, options?: IKeyValueStoreSetOptions): Promise<Result<void, RepositoryAbstraction.Error>>;
14
- delete(key: string, scope: string): Promise<Result<void, RepositoryAbstraction.Error>>;
19
+ delete(key: string, scope: string, options?: IKeyValueDeleteOptions): Promise<Result<void, RepositoryAbstraction.Error>>;
20
+ list<T = unknown>(scope: string, params: IKeyValueListParams): Promise<Result<IKeyValueListResult<T>, RepositoryAbstraction.Error>>;
15
21
  }
16
22
  export declare const KeyValueStoreRepository: import("@webiny/di").Implementation<typeof KeyValueStoreRepositoryImpl>;
17
23
  export {};
@@ -1,6 +1,42 @@
1
1
  import { Result, createImplementation } from "@webiny/feature/api";
2
2
  import { KeyValueStorageOperations, KeyValueStoreRepository } from "./abstractions.js";
3
- import { KeyNotFoundError, KeyValueStorageError } from "./errors.js";
3
+ import { KeyNotFoundError, KeyValueConditionFailedError, KeyValueInvalidCollectionError, KeyValueInvalidConditionError, KeyValueInvalidCursorError, KeyValueKeyTooLongError, KeyValueStorageError } from "./errors.js";
4
+ const DEFAULT_LIST_LIMIT = 100;
5
+ const MAX_LIST_LIMIT = 1000;
6
+ const resolveLimit = (limit)=>{
7
+ if (!limit || !Number.isFinite(limit)) return DEFAULT_LIST_LIMIT;
8
+ const whole = Math.floor(limit);
9
+ const atLeastOne = Math.max(whole, 1);
10
+ return Math.min(atLeastOne, MAX_LIST_LIMIT);
11
+ };
12
+ const encodeCursor = (cursor)=>{
13
+ const json = JSON.stringify(cursor);
14
+ return Buffer.from(json).toString("base64url");
15
+ };
16
+ const decodeCursor = (cursor)=>{
17
+ try {
18
+ const json = Buffer.from(cursor, "base64url").toString("utf8");
19
+ const parsed = JSON.parse(json);
20
+ if ("string" != typeof parsed?.collection || "boolean" != typeof parsed.reverse || "string" != typeof parsed.after) return;
21
+ return parsed;
22
+ } catch {
23
+ return;
24
+ }
25
+ };
26
+ const isComparable = (value)=>{
27
+ const type = typeof value;
28
+ return "string" === type || "number" === type || "boolean" === type;
29
+ };
30
+ const isValidCondition = (condition, allowNotExists)=>{
31
+ if ("object" != typeof condition || null === condition) return false;
32
+ const { exists, equals } = condition;
33
+ if (void 0 !== exists && void 0 !== equals) return false;
34
+ if (void 0 !== exists) return true === exists || false === exists && allowNotExists;
35
+ return isComparable(equals);
36
+ };
37
+ const MAX_COLLECTION_BYTES = 1000;
38
+ const MAX_COLLECTION_KEY_BYTES = 1000;
39
+ const isValidCollection = (collection)=>"string" == typeof collection && collection.length > 0 && Buffer.byteLength(collection, "utf8") <= MAX_COLLECTION_BYTES;
4
40
  class KeyValueStoreRepositoryImpl {
5
41
  constructor(storageOperations){
6
42
  this.storageOperations = storageOperations;
@@ -15,21 +51,63 @@ class KeyValueStoreRepositoryImpl {
15
51
  }
16
52
  }
17
53
  async set(key, value, scope, options) {
54
+ if (options?.condition !== void 0 && !isValidCondition(options.condition, true)) return Result.fail(new KeyValueInvalidConditionError());
55
+ if (options?.collection !== void 0) {
56
+ if (!isValidCollection(options.collection)) return Result.fail(new KeyValueInvalidCollectionError(MAX_COLLECTION_BYTES));
57
+ if (Buffer.byteLength(key, "utf8") > MAX_COLLECTION_KEY_BYTES) return Result.fail(new KeyValueKeyTooLongError(key, MAX_COLLECTION_KEY_BYTES));
58
+ }
18
59
  try {
19
- await this.storageOperations.set(key, value, scope, options);
60
+ const written = await this.storageOperations.set(key, value, scope, options);
61
+ if (!written) return Result.fail(new KeyValueConditionFailedError(key));
20
62
  return Result.ok();
21
63
  } catch (error) {
22
64
  return Result.fail(new KeyValueStorageError(error));
23
65
  }
24
66
  }
25
- async delete(key, scope) {
67
+ async delete(key, scope, options) {
68
+ if (options?.condition !== void 0 && !isValidCondition(options.condition, false)) return Result.fail(new KeyValueInvalidConditionError());
26
69
  try {
27
- await this.storageOperations.delete(key, scope);
70
+ const deleted = await this.storageOperations.delete(key, scope, options);
71
+ if (!deleted) return Result.fail(new KeyValueConditionFailedError(key));
28
72
  return Result.ok();
29
73
  } catch (error) {
30
74
  return Result.fail(new KeyValueStorageError(error));
31
75
  }
32
76
  }
77
+ async list(scope, params) {
78
+ const { collection, cursor } = params;
79
+ if (!isValidCollection(collection)) return Result.fail(new KeyValueInvalidCollectionError(MAX_COLLECTION_BYTES));
80
+ let reverse = params.reverse ?? false;
81
+ let after;
82
+ if (cursor) {
83
+ const decoded = decodeCursor(cursor);
84
+ if (!decoded || decoded.collection !== collection) return Result.fail(new KeyValueInvalidCursorError(cursor));
85
+ reverse = decoded.reverse;
86
+ after = decoded.after;
87
+ }
88
+ const limit = resolveLimit(params.limit);
89
+ try {
90
+ const { items, lastKey } = await this.storageOperations.list({
91
+ collection,
92
+ scope,
93
+ limit,
94
+ reverse,
95
+ after
96
+ });
97
+ let nextCursor = null;
98
+ if (null !== lastKey) nextCursor = encodeCursor({
99
+ collection,
100
+ reverse,
101
+ after: lastKey
102
+ });
103
+ return Result.ok({
104
+ items: items,
105
+ cursor: nextCursor
106
+ });
107
+ } catch (error) {
108
+ return Result.fail(new KeyValueStorageError(error));
109
+ }
110
+ }
33
111
  }
34
112
  const KeyValueStoreRepository_KeyValueStoreRepository = createImplementation({
35
113
  abstraction: KeyValueStoreRepository,
@@ -1 +1 @@
1
- {"version":3,"file":"features/keyValueStore/KeyValueStoreRepository.js","sources":["../../../src/features/keyValueStore/KeyValueStoreRepository.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport {\n KeyValueStorageOperations,\n KeyValueStoreRepository as RepositoryAbstraction,\n type IKeyValueStoreSetOptions\n} from \"./abstractions.js\";\nimport { KeyNotFoundError, KeyValueStorageError } from \"./errors.js\";\n\n/**\n * KeyValueStoreRepository implementation.\n *\n * This repository passes key and scope separately to storage operations.\n * The storage layer is responsible for handling scope-based partitioning.\n */\nclass KeyValueStoreRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(private storageOperations: KeyValueStorageOperations.Interface) {}\n\n async get<T = unknown>(\n key: string,\n scope: string\n ): Promise<Result<T, RepositoryAbstraction.Error>> {\n try {\n const record = await this.storageOperations.get(key, scope);\n\n if (!record) {\n return Result.fail(new KeyNotFoundError(key));\n }\n\n return Result.ok(record.value as T);\n } catch (error) {\n return Result.fail(new KeyValueStorageError(error as Error));\n }\n }\n\n async set(\n key: string,\n value: any,\n scope: string,\n options?: IKeyValueStoreSetOptions\n ): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n await this.storageOperations.set(key, value, scope, options);\n return Result.ok();\n } catch (error) {\n return Result.fail(new KeyValueStorageError(error as Error));\n }\n }\n\n async delete(key: string, scope: string): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n await this.storageOperations.delete(key, scope);\n return Result.ok();\n } catch (error) {\n return Result.fail(new KeyValueStorageError(error as Error));\n }\n }\n}\n\nexport const KeyValueStoreRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: KeyValueStoreRepositoryImpl,\n dependencies: [KeyValueStorageOperations]\n});\n"],"names":["KeyValueStoreRepositoryImpl","storageOperations","key","scope","record","Result","KeyNotFoundError","error","KeyValueStorageError","value","options","KeyValueStoreRepository","createImplementation","RepositoryAbstraction","KeyValueStorageOperations"],"mappings":";;;AAeA,MAAMA;IACF,YAAoBC,iBAAsD,CAAE;aAAxDA,iBAAiB,GAAjBA;IAAyD;IAE7E,MAAM,IACFC,GAAW,EACXC,KAAa,EACkC;QAC/C,IAAI;YACA,MAAMC,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAACF,KAAKC;YAErD,IAAI,CAACC,QACD,OAAOC,OAAO,IAAI,CAAC,IAAIC,iBAAiBJ;YAG5C,OAAOG,OAAO,EAAE,CAACD,OAAO,KAAK;QACjC,EAAE,OAAOG,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIG,qBAAqBD;QAChD;IACJ;IAEA,MAAM,IACFL,GAAW,EACXO,KAAU,EACVN,KAAa,EACbO,OAAkC,EACgB;QAClD,IAAI;YACA,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAACR,KAAKO,OAAON,OAAOO;YACpD,OAAOL,OAAO,EAAE;QACpB,EAAE,OAAOE,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIG,qBAAqBD;QAChD;IACJ;IAEA,MAAM,OAAOL,GAAW,EAAEC,KAAa,EAAsD;QACzF,IAAI;YACA,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAACD,KAAKC;YACzC,OAAOE,OAAO,EAAE;QACpB,EAAE,OAAOE,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIG,qBAAqBD;QAChD;IACJ;AACJ;AAEO,MAAMI,kDAA0BC,qBAAqB;IACxD,aAAaC;IACb,gBAAgBb;IAChB,cAAc;QAACc;KAA0B;AAC7C"}
1
+ {"version":3,"file":"features/keyValueStore/KeyValueStoreRepository.js","sources":["../../../src/features/keyValueStore/KeyValueStoreRepository.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { KeyValueStorageOperations } from \"./abstractions.js\";\nimport { KeyValueStoreRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport type { IKeyValueListParams } from \"./abstractions.js\";\nimport type { IKeyValueListResult } from \"./abstractions.js\";\nimport type { IKeyValueRecord } from \"./abstractions.js\";\nimport type { IKeyValueStoreSetOptions } from \"./abstractions.js\";\nimport type { IKeyValueDeleteOptions } from \"./abstractions.js\";\nimport { KeyNotFoundError } from \"./errors.js\";\nimport { KeyValueStorageError } from \"./errors.js\";\nimport { KeyValueInvalidCursorError } from \"./errors.js\";\nimport { KeyValueInvalidCollectionError } from \"./errors.js\";\nimport { KeyValueKeyTooLongError } from \"./errors.js\";\nimport { KeyValueConditionFailedError } from \"./errors.js\";\nimport { KeyValueInvalidConditionError } from \"./errors.js\";\n\nconst DEFAULT_LIST_LIMIT = 100;\nconst MAX_LIST_LIMIT = 1000;\n\nconst resolveLimit = (limit: number | undefined): number => {\n if (!limit || !Number.isFinite(limit)) {\n return DEFAULT_LIST_LIMIT;\n }\n const whole = Math.floor(limit);\n const atLeastOne = Math.max(whole, 1);\n return Math.min(atLeastOne, MAX_LIST_LIMIT);\n};\n\ninterface ICursor {\n collection: string;\n reverse: boolean;\n after: string;\n}\n\n/*\n * The cursor carries the key the previous page stopped at, with the collection and direction it was\n * read in, so it cannot quietly continue a different listing. Encoded so callers treat it as opaque\n * and do not build one by hand, which leaves room to change what it carries.\n */\nconst encodeCursor = (cursor: ICursor): string => {\n const json = JSON.stringify(cursor);\n return Buffer.from(json).toString(\"base64url\");\n};\n\nconst decodeCursor = (cursor: string): ICursor | undefined => {\n try {\n const json = Buffer.from(cursor, \"base64url\").toString(\"utf8\");\n const parsed = JSON.parse(json);\n if (\n typeof parsed?.collection !== \"string\" ||\n typeof parsed.reverse !== \"boolean\" ||\n typeof parsed.after !== \"string\"\n ) {\n return undefined;\n }\n return parsed;\n } catch {\n return undefined;\n }\n};\n\nconst isComparable = (value: unknown): boolean => {\n const type = typeof value;\n return type === \"string\" || type === \"number\" || type === \"boolean\";\n};\n\n/*\n * The types already allow one of `exists` or `equals`, of the right kind. This holds callers the\n * types do not reach, such as plain JavaScript, to the same: a condition the stores would read\n * differently, or not at all, must not become an unconditional write.\n */\nconst isValidCondition = (condition: unknown, allowNotExists: boolean): boolean => {\n if (typeof condition !== \"object\" || condition === null) {\n return false;\n }\n const { exists, equals } = condition as { exists?: unknown; equals?: unknown };\n if (exists !== undefined && equals !== undefined) {\n return false;\n }\n if (exists !== undefined) {\n return exists === true || (exists === false && allowNotExists);\n }\n return isComparable(equals);\n};\n\n/*\n * Both limits come from DynamoDB, where a collection member's key goes into a GSI sort key (1024\n * bytes at most) and the collection name into a GSI partition key (2048 bytes, shared with the\n * scope). Checked here rather than in the DynamoDB layer so every store rejects the same writes.\n */\nconst MAX_COLLECTION_BYTES = 1000;\nconst MAX_COLLECTION_KEY_BYTES = 1000;\n\nconst isValidCollection = (collection: unknown): collection is string => {\n return (\n typeof collection === \"string\" &&\n collection.length > 0 &&\n Buffer.byteLength(collection, \"utf8\") <= MAX_COLLECTION_BYTES\n );\n};\n\n/**\n * KeyValueStoreRepository implementation.\n *\n * This repository passes key and scope separately to storage operations.\n * The storage layer is responsible for handling scope-based partitioning.\n */\nclass KeyValueStoreRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(private storageOperations: KeyValueStorageOperations.Interface) {}\n\n async get<T = unknown>(\n key: string,\n scope: string\n ): Promise<Result<T, RepositoryAbstraction.Error>> {\n try {\n const record = await this.storageOperations.get(key, scope);\n\n if (!record) {\n return Result.fail(new KeyNotFoundError(key));\n }\n\n return Result.ok(record.value as T);\n } catch (error) {\n return Result.fail(new KeyValueStorageError(error as Error));\n }\n }\n\n async set(\n key: string,\n value: any,\n scope: string,\n options?: IKeyValueStoreSetOptions\n ): Promise<Result<void, RepositoryAbstraction.Error>> {\n if (options?.condition !== undefined && !isValidCondition(options.condition, true)) {\n return Result.fail(new KeyValueInvalidConditionError());\n }\n if (options?.collection !== undefined) {\n if (!isValidCollection(options.collection)) {\n return Result.fail(new KeyValueInvalidCollectionError(MAX_COLLECTION_BYTES));\n }\n if (Buffer.byteLength(key, \"utf8\") > MAX_COLLECTION_KEY_BYTES) {\n return Result.fail(new KeyValueKeyTooLongError(key, MAX_COLLECTION_KEY_BYTES));\n }\n }\n\n try {\n const written = await this.storageOperations.set(key, value, scope, options);\n if (!written) {\n return Result.fail(new KeyValueConditionFailedError(key));\n }\n return Result.ok();\n } catch (error) {\n return Result.fail(new KeyValueStorageError(error as Error));\n }\n }\n\n async delete(\n key: string,\n scope: string,\n options?: IKeyValueDeleteOptions\n ): Promise<Result<void, RepositoryAbstraction.Error>> {\n if (options?.condition !== undefined && !isValidCondition(options.condition, false)) {\n return Result.fail(new KeyValueInvalidConditionError());\n }\n try {\n const deleted = await this.storageOperations.delete(key, scope, options);\n if (!deleted) {\n return Result.fail(new KeyValueConditionFailedError(key));\n }\n return Result.ok();\n } catch (error) {\n return Result.fail(new KeyValueStorageError(error as Error));\n }\n }\n\n async list<T = unknown>(\n scope: string,\n params: IKeyValueListParams\n ): Promise<Result<IKeyValueListResult<T>, RepositoryAbstraction.Error>> {\n const { collection, cursor } = params;\n if (!isValidCollection(collection)) {\n return Result.fail(new KeyValueInvalidCollectionError(MAX_COLLECTION_BYTES));\n }\n\n let reverse = params.reverse ?? false;\n let after: string | undefined;\n if (cursor) {\n const decoded = decodeCursor(cursor);\n if (!decoded || decoded.collection !== collection) {\n return Result.fail(new KeyValueInvalidCursorError(cursor));\n }\n reverse = decoded.reverse;\n after = decoded.after;\n }\n\n const limit = resolveLimit(params.limit);\n\n try {\n const { items, lastKey } = await this.storageOperations.list({\n collection,\n scope,\n limit,\n reverse,\n after\n });\n\n let nextCursor: string | null = null;\n if (lastKey !== null) {\n nextCursor = encodeCursor({ collection, reverse, after: lastKey });\n }\n\n return Result.ok({\n items: items as IKeyValueRecord<T>[],\n cursor: nextCursor\n });\n } catch (error) {\n return Result.fail(new KeyValueStorageError(error as Error));\n }\n }\n}\n\nexport const KeyValueStoreRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: KeyValueStoreRepositoryImpl,\n dependencies: [KeyValueStorageOperations]\n});\n"],"names":["DEFAULT_LIST_LIMIT","MAX_LIST_LIMIT","resolveLimit","limit","Number","whole","Math","atLeastOne","encodeCursor","cursor","json","JSON","Buffer","decodeCursor","parsed","isComparable","value","type","isValidCondition","condition","allowNotExists","exists","equals","undefined","MAX_COLLECTION_BYTES","MAX_COLLECTION_KEY_BYTES","isValidCollection","collection","KeyValueStoreRepositoryImpl","storageOperations","key","scope","record","Result","KeyNotFoundError","error","KeyValueStorageError","options","KeyValueInvalidConditionError","KeyValueInvalidCollectionError","KeyValueKeyTooLongError","written","KeyValueConditionFailedError","deleted","params","reverse","after","decoded","KeyValueInvalidCursorError","items","lastKey","nextCursor","KeyValueStoreRepository","createImplementation","RepositoryAbstraction","KeyValueStorageOperations"],"mappings":"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"}
@@ -1,48 +1,140 @@
1
1
  import { Result } from "@webiny/feature/api";
2
- import { KeyNotFoundError, KeyValueStorageError } from "./errors.js";
3
- export interface IKeyValueRecord {
2
+ import { KeyNotFoundError } from "./errors.js";
3
+ import { KeyValueStorageError } from "./errors.js";
4
+ import { KeyValueInvalidCursorError } from "./errors.js";
5
+ import { KeyValueInvalidCollectionError } from "./errors.js";
6
+ import { KeyValueKeyTooLongError } from "./errors.js";
7
+ import { KeyValueConditionFailedError } from "./errors.js";
8
+ import { KeyValueInvalidConditionError } from "./errors.js";
9
+ export interface IKeyValueRecord<T = any> {
4
10
  key: string;
5
- value: any;
11
+ value: T;
12
+ }
13
+ /**
14
+ * A record is listable only as a member of a collection, and only when the write that stored it
15
+ * named that collection. A write without `collection` takes the record out of the one it was in,
16
+ * since every write replaces the whole record.
17
+ *
18
+ * A collection name and the key of a record in a collection are each limited to 1000 UTF-8 bytes.
19
+ *
20
+ * Each collection is stored apart from every other, so keep one to records that are listed
21
+ * together, such as one user's chats. A collection spanning a whole tenant, like every uploaded
22
+ * file, puts all of them in one place that only ever grows.
23
+ */
24
+ export interface IKeyValueCollectionOptions {
25
+ collection?: string;
26
+ }
27
+ export type KeyValueComparable = string | number | boolean;
28
+ /**
29
+ * Makes a write conditional. The store checks the record and writes it as one step, so two callers
30
+ * racing for the same key cannot both succeed. A write whose condition does not hold changes nothing
31
+ * and fails with `KeyValueStore/ConditionFailed`.
32
+ *
33
+ * An expired record counts as absent, as for `get`. `equals` matches a live record whose whole value
34
+ * is that same string, number or boolean: DynamoDB cannot compare whole maps in a condition, so
35
+ * objects are not accepted. A condition is one of the two, never both.
36
+ */
37
+ export type IKeyValueWriteCondition = {
38
+ /** `false`: write only when there is no live record. `true`: only when there is one. */
39
+ exists: boolean;
40
+ equals?: never;
41
+ } | {
42
+ /** Write only when the live record's value equals this. */
43
+ equals: KeyValueComparable;
44
+ exists?: never;
45
+ };
46
+ /** Deleting where there is no live record has nothing to check, so `exists` can only be `true`. */
47
+ export type IKeyValueDeleteCondition = {
48
+ /** Delete only when there is a live record. */
49
+ exists: true;
50
+ equals?: never;
51
+ } | {
52
+ /** Delete only when the live record's value equals this. */
53
+ equals: KeyValueComparable;
54
+ exists?: never;
55
+ };
56
+ export interface IKeyValueWriteConditionOptions {
57
+ condition?: IKeyValueWriteCondition;
58
+ }
59
+ export interface IKeyValueDeleteOptions {
60
+ condition?: IKeyValueDeleteCondition;
61
+ }
62
+ export interface IKeyValueListParams {
63
+ collection: string;
64
+ /** Most records on one page. Defaults to 100, capped at 1000. */
65
+ limit?: number;
66
+ /** The `cursor` of the previous page. Omit it for the first page. */
67
+ cursor?: string;
68
+ /** Descending key order. A cursor continues in the order of the page that returned it. */
69
+ reverse?: boolean;
70
+ }
71
+ export interface IKeyValueListResult<T = any> {
72
+ items: IKeyValueRecord<T>[];
73
+ /**
74
+ * Pass it back as `cursor` for the next page; `null` when there is none. Opaque: it encodes
75
+ * where the page stopped, not a page number, so records written meanwhile are not skipped.
76
+ */
77
+ cursor: string | null;
6
78
  }
7
79
  export interface IGlobalKeyValueStoreOptions {
8
80
  scope?: string;
9
81
  expiresAt?: Date;
10
82
  }
83
+ export interface IGlobalKeyValueSetOptions extends IGlobalKeyValueStoreOptions, IKeyValueCollectionOptions, IKeyValueWriteConditionOptions {
84
+ }
85
+ export interface IGlobalKeyValueDeleteOptions extends IKeyValueDeleteOptions {
86
+ scope?: string;
87
+ }
88
+ export interface IGlobalKeyValueListParams extends IKeyValueListParams {
89
+ scope?: string;
90
+ }
11
91
  export interface IGlobalKeyValueStore {
12
92
  get<T = unknown>(key: string, options?: IGlobalKeyValueStoreOptions): Promise<Result<T, KeyValueStoreRepository.Error>>;
13
- set(key: string, value: any, options?: IGlobalKeyValueStoreOptions): Promise<Result<void, KeyValueStoreRepository.Error>>;
14
- delete(key: string, options?: IGlobalKeyValueStoreOptions): Promise<Result<void, KeyValueStoreRepository.Error>>;
93
+ set(key: string, value: any, options?: IGlobalKeyValueSetOptions): Promise<Result<void, KeyValueStoreRepository.Error>>;
94
+ delete(key: string, options?: IGlobalKeyValueDeleteOptions): Promise<Result<void, KeyValueStoreRepository.Error>>;
95
+ /**
96
+ * One page of a collection in the scope, ordered by key. Expired records are left out, so a
97
+ * page can hold fewer than `limit` records and still have a next one.
98
+ */
99
+ list<T = unknown>(params: IGlobalKeyValueListParams): Promise<Result<IKeyValueListResult<T>, KeyValueStoreRepository.Error>>;
15
100
  }
16
101
  /** Global (non-tenant-scoped) key-value store. */
17
102
  export declare const GlobalKeyValueStore: import("@webiny/di").Abstraction<IGlobalKeyValueStore>;
18
103
  export declare namespace GlobalKeyValueStore {
19
104
  type Interface = IGlobalKeyValueStore;
20
- type KeyValueRecord = IKeyValueRecord;
105
+ type KeyValueRecord<T = any> = IKeyValueRecord<T>;
106
+ type ListResult<T = any> = IKeyValueListResult<T>;
21
107
  type Error = KeyValueStoreRepository.Error;
22
108
  }
109
+ export interface IKeyValueSetOptions extends IKeyValueCollectionOptions, IKeyValueWriteConditionOptions {
110
+ }
23
111
  export interface IKeyValueStore {
24
112
  get<T = unknown>(key: string): Promise<Result<T, KeyValueStoreRepository.Error>>;
25
- set(key: string, value: any): Promise<Result<void, KeyValueStoreRepository.Error>>;
26
- delete(key: string): Promise<Result<void, KeyValueStoreRepository.Error>>;
113
+ set(key: string, value: any, options?: IKeyValueSetOptions): Promise<Result<void, KeyValueStoreRepository.Error>>;
114
+ delete(key: string, options?: IKeyValueDeleteOptions): Promise<Result<void, KeyValueStoreRepository.Error>>;
115
+ /** One page of a collection of the current tenant, ordered by key. */
116
+ list<T = unknown>(params: IKeyValueListParams): Promise<Result<IKeyValueListResult<T>, KeyValueStoreRepository.Error>>;
27
117
  }
28
118
  /** Tenant-scoped key-value store. */
29
119
  export declare const KeyValueStore: import("@webiny/di").Abstraction<IKeyValueStore>;
30
120
  export declare namespace KeyValueStore {
31
121
  type Interface = IKeyValueStore;
32
- type KeyValueRecord = IKeyValueRecord;
122
+ type KeyValueRecord<T = any> = IKeyValueRecord<T>;
123
+ type ListResult<T = any> = IKeyValueListResult<T>;
33
124
  type Error = KeyValueStoreRepository.Error;
34
125
  }
35
126
  export interface IKeyValueStoreRepositoryErrors {
36
- base: KeyNotFoundError | KeyValueStorageError;
127
+ base: KeyNotFoundError | KeyValueStorageError | KeyValueInvalidCursorError | KeyValueInvalidCollectionError | KeyValueKeyTooLongError | KeyValueConditionFailedError | KeyValueInvalidConditionError;
37
128
  }
38
129
  type RepositoryError = IKeyValueStoreRepositoryErrors[keyof IKeyValueStoreRepositoryErrors];
39
- export interface IKeyValueStoreSetOptions {
130
+ export interface IKeyValueStoreSetOptions extends IKeyValueCollectionOptions, IKeyValueWriteConditionOptions {
40
131
  expiresAt?: Date;
41
132
  }
42
133
  export interface IKeyValueStoreRepository {
43
134
  get<T = unknown>(key: string, scope: string): Promise<Result<T, RepositoryError>>;
44
135
  set(key: string, value: any, scope: string, options?: IKeyValueStoreSetOptions): Promise<Result<void, RepositoryError>>;
45
- delete(key: string, scope: string): Promise<Result<void, RepositoryError>>;
136
+ delete(key: string, scope: string, options?: IKeyValueDeleteOptions): Promise<Result<void, RepositoryError>>;
137
+ list<T = unknown>(scope: string, params: IKeyValueListParams): Promise<Result<IKeyValueListResult<T>, RepositoryError>>;
46
138
  }
47
139
  /** Persist and retrieve key-value pairs. */
48
140
  export declare const KeyValueStoreRepository: import("@webiny/di").Abstraction<IKeyValueStoreRepository>;
@@ -55,8 +147,34 @@ export interface IKeyValueStorageOperations {
55
147
  key: string;
56
148
  value: any;
57
149
  } | null>;
58
- set(key: string, value: any, scope: string, options?: IKeyValueStoreSetOptions): Promise<void>;
59
- delete(key: string, scope: string): Promise<void>;
150
+ /**
151
+ * Puts the record in `options.collection`, or in none when it is not given. With a condition in
152
+ * `options`, checks it and writes as one atomic step; resolves to whether it wrote.
153
+ */
154
+ set(key: string, value: any, scope: string, options?: IKeyValueStoreSetOptions): Promise<boolean>;
155
+ /** With a condition, checks it and deletes as one atomic step; resolves to whether it deleted. */
156
+ delete(key: string, scope: string, options?: IKeyValueDeleteOptions): Promise<boolean>;
157
+ /**
158
+ * Up to `limit` members of `collection` in `scope` past `after`, ordered by the key's UTF-8
159
+ * bytes (descending when `reverse`), expired ones left out.
160
+ */
161
+ list(params: IKeyValueStorageListParams): Promise<IKeyValueStorageListResult>;
162
+ }
163
+ export interface IKeyValueStorageListParams {
164
+ collection: string;
165
+ scope: string;
166
+ limit: number;
167
+ reverse: boolean;
168
+ /** Only keys past this one, in the order of the listing. */
169
+ after?: string;
170
+ }
171
+ export interface IKeyValueStorageListResult {
172
+ items: IKeyValueRecord[];
173
+ /**
174
+ * The last key this page read, expired records included, when more may follow; otherwise
175
+ * `null`. The next page starts after it.
176
+ */
177
+ lastKey: string | null;
60
178
  }
61
179
  /** Storage operations for key-value persistence. */
62
180
  export declare const KeyValueStorageOperations: import("@webiny/di").Abstraction<IKeyValueStorageOperations>;
@@ -1 +1 @@
1
- {"version":3,"file":"features/keyValueStore/abstractions.js","sources":["../../../src/features/keyValueStore/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { KeyNotFoundError, KeyValueStorageError } from \"./errors.js\";\n\nexport interface IKeyValueRecord {\n key: string;\n value: any;\n}\n\n// GlobalKeyValueStore - Non-tenant-aware service\nexport interface IGlobalKeyValueStoreOptions {\n scope?: string;\n expiresAt?: Date;\n}\n\nexport interface IGlobalKeyValueStore {\n get<T = unknown>(\n key: string,\n options?: IGlobalKeyValueStoreOptions\n ): Promise<Result<T, KeyValueStoreRepository.Error>>;\n set(\n key: string,\n value: any,\n options?: IGlobalKeyValueStoreOptions\n ): Promise<Result<void, KeyValueStoreRepository.Error>>;\n delete(\n key: string,\n options?: IGlobalKeyValueStoreOptions\n ): Promise<Result<void, KeyValueStoreRepository.Error>>;\n}\n\n/** Global (non-tenant-scoped) key-value store. */\nexport const GlobalKeyValueStore = createAbstraction<IGlobalKeyValueStore>(\"GlobalKeyValueStore\");\n\nexport namespace GlobalKeyValueStore {\n export type Interface = IGlobalKeyValueStore;\n export type KeyValueRecord = IKeyValueRecord;\n export type Error = KeyValueStoreRepository.Error;\n}\n\n// KeyValueStore - Tenant-aware service\nexport interface IKeyValueStore {\n get<T = unknown>(key: string): Promise<Result<T, KeyValueStoreRepository.Error>>;\n set(key: string, value: any): Promise<Result<void, KeyValueStoreRepository.Error>>;\n delete(key: string): Promise<Result<void, KeyValueStoreRepository.Error>>;\n}\n\n/** Tenant-scoped key-value store. */\nexport const KeyValueStore = createAbstraction<IKeyValueStore>(\"KeyValueStore\");\n\nexport namespace KeyValueStore {\n export type Interface = IKeyValueStore;\n export type KeyValueRecord = IKeyValueRecord;\n export type Error = KeyValueStoreRepository.Error;\n}\n\n// Repository\n\nexport interface IKeyValueStoreRepositoryErrors {\n base: KeyNotFoundError | KeyValueStorageError;\n}\n\ntype RepositoryError = IKeyValueStoreRepositoryErrors[keyof IKeyValueStoreRepositoryErrors];\n\nexport interface IKeyValueStoreSetOptions {\n expiresAt?: Date;\n}\n\nexport interface IKeyValueStoreRepository {\n get<T = unknown>(key: string, scope: string): Promise<Result<T, RepositoryError>>;\n set(\n key: string,\n value: any,\n scope: string,\n options?: IKeyValueStoreSetOptions\n ): Promise<Result<void, RepositoryError>>;\n delete(key: string, scope: string): Promise<Result<void, RepositoryError>>;\n}\n\n/** Persist and retrieve key-value pairs. */\nexport const KeyValueStoreRepository =\n createAbstraction<IKeyValueStoreRepository>(\"KeyValueStoreRepository\");\n\nexport namespace KeyValueStoreRepository {\n export type Interface = IKeyValueStoreRepository;\n export type Error = RepositoryError;\n}\n\n// Storage Operations\n\nexport interface IKeyValueStorageOperations {\n get(key: string, scope: string): Promise<{ key: string; value: any } | null>;\n set(key: string, value: any, scope: string, options?: IKeyValueStoreSetOptions): Promise<void>;\n delete(key: string, scope: string): Promise<void>;\n}\n\n/** Storage operations for key-value persistence. */\nexport const KeyValueStorageOperations = createAbstraction<IKeyValueStorageOperations>(\n \"KeyValueStorageOperations\"\n);\n\nexport namespace KeyValueStorageOperations {\n export type Interface = IKeyValueStorageOperations;\n}\n"],"names":["GlobalKeyValueStore","createAbstraction","KeyValueStore","KeyValueStoreRepository","KeyValueStorageOperations"],"mappings":";AAgCO,MAAMA,sBAAsBC,kBAAwC;AAgBpE,MAAMC,gBAAgBD,kBAAkC;AAgCxD,MAAME,0BACTF,kBAA4C;AAgBzC,MAAMG,4BAA4BH,kBACrC"}
1
+ {"version":3,"file":"features/keyValueStore/abstractions.js","sources":["../../../src/features/keyValueStore/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { KeyNotFoundError } from \"./errors.js\";\nimport { KeyValueStorageError } from \"./errors.js\";\nimport { KeyValueInvalidCursorError } from \"./errors.js\";\nimport { KeyValueInvalidCollectionError } from \"./errors.js\";\nimport { KeyValueKeyTooLongError } from \"./errors.js\";\nimport { KeyValueConditionFailedError } from \"./errors.js\";\nimport { KeyValueInvalidConditionError } from \"./errors.js\";\n\nexport interface IKeyValueRecord<T = any> {\n key: string;\n value: T;\n}\n\n/**\n * A record is listable only as a member of a collection, and only when the write that stored it\n * named that collection. A write without `collection` takes the record out of the one it was in,\n * since every write replaces the whole record.\n *\n * A collection name and the key of a record in a collection are each limited to 1000 UTF-8 bytes.\n *\n * Each collection is stored apart from every other, so keep one to records that are listed\n * together, such as one user's chats. A collection spanning a whole tenant, like every uploaded\n * file, puts all of them in one place that only ever grows.\n */\nexport interface IKeyValueCollectionOptions {\n collection?: string;\n}\n\nexport type KeyValueComparable = string | number | boolean;\n\n/**\n * Makes a write conditional. The store checks the record and writes it as one step, so two callers\n * racing for the same key cannot both succeed. A write whose condition does not hold changes nothing\n * and fails with `KeyValueStore/ConditionFailed`.\n *\n * An expired record counts as absent, as for `get`. `equals` matches a live record whose whole value\n * is that same string, number or boolean: DynamoDB cannot compare whole maps in a condition, so\n * objects are not accepted. A condition is one of the two, never both.\n */\nexport type IKeyValueWriteCondition =\n | {\n /** `false`: write only when there is no live record. `true`: only when there is one. */\n exists: boolean;\n equals?: never;\n }\n | {\n /** Write only when the live record's value equals this. */\n equals: KeyValueComparable;\n exists?: never;\n };\n\n/** Deleting where there is no live record has nothing to check, so `exists` can only be `true`. */\nexport type IKeyValueDeleteCondition =\n | {\n /** Delete only when there is a live record. */\n exists: true;\n equals?: never;\n }\n | {\n /** Delete only when the live record's value equals this. */\n equals: KeyValueComparable;\n exists?: never;\n };\n\nexport interface IKeyValueWriteConditionOptions {\n condition?: IKeyValueWriteCondition;\n}\n\nexport interface IKeyValueDeleteOptions {\n condition?: IKeyValueDeleteCondition;\n}\n\nexport interface IKeyValueListParams {\n collection: string;\n /** Most records on one page. Defaults to 100, capped at 1000. */\n limit?: number;\n /** The `cursor` of the previous page. Omit it for the first page. */\n cursor?: string;\n /** Descending key order. A cursor continues in the order of the page that returned it. */\n reverse?: boolean;\n}\n\nexport interface IKeyValueListResult<T = any> {\n items: IKeyValueRecord<T>[];\n /**\n * Pass it back as `cursor` for the next page; `null` when there is none. Opaque: it encodes\n * where the page stopped, not a page number, so records written meanwhile are not skipped.\n */\n cursor: string | null;\n}\n\n// GlobalKeyValueStore - Non-tenant-aware service\nexport interface IGlobalKeyValueStoreOptions {\n scope?: string;\n expiresAt?: Date;\n}\n\nexport interface IGlobalKeyValueSetOptions\n extends\n IGlobalKeyValueStoreOptions,\n IKeyValueCollectionOptions,\n IKeyValueWriteConditionOptions {}\n\nexport interface IGlobalKeyValueDeleteOptions extends IKeyValueDeleteOptions {\n scope?: string;\n}\n\nexport interface IGlobalKeyValueListParams extends IKeyValueListParams {\n scope?: string;\n}\n\nexport interface IGlobalKeyValueStore {\n get<T = unknown>(\n key: string,\n options?: IGlobalKeyValueStoreOptions\n ): Promise<Result<T, KeyValueStoreRepository.Error>>;\n set(\n key: string,\n value: any,\n options?: IGlobalKeyValueSetOptions\n ): Promise<Result<void, KeyValueStoreRepository.Error>>;\n delete(\n key: string,\n options?: IGlobalKeyValueDeleteOptions\n ): Promise<Result<void, KeyValueStoreRepository.Error>>;\n /**\n * One page of a collection in the scope, ordered by key. Expired records are left out, so a\n * page can hold fewer than `limit` records and still have a next one.\n */\n list<T = unknown>(\n params: IGlobalKeyValueListParams\n ): Promise<Result<IKeyValueListResult<T>, KeyValueStoreRepository.Error>>;\n}\n\n/** Global (non-tenant-scoped) key-value store. */\nexport const GlobalKeyValueStore = createAbstraction<IGlobalKeyValueStore>(\"GlobalKeyValueStore\");\n\nexport namespace GlobalKeyValueStore {\n export type Interface = IGlobalKeyValueStore;\n export type KeyValueRecord<T = any> = IKeyValueRecord<T>;\n export type ListResult<T = any> = IKeyValueListResult<T>;\n export type Error = KeyValueStoreRepository.Error;\n}\n\n// KeyValueStore - Tenant-aware service\nexport interface IKeyValueSetOptions\n extends IKeyValueCollectionOptions, IKeyValueWriteConditionOptions {}\n\nexport interface IKeyValueStore {\n get<T = unknown>(key: string): Promise<Result<T, KeyValueStoreRepository.Error>>;\n set(\n key: string,\n value: any,\n options?: IKeyValueSetOptions\n ): Promise<Result<void, KeyValueStoreRepository.Error>>;\n delete(\n key: string,\n options?: IKeyValueDeleteOptions\n ): Promise<Result<void, KeyValueStoreRepository.Error>>;\n /** One page of a collection of the current tenant, ordered by key. */\n list<T = unknown>(\n params: IKeyValueListParams\n ): Promise<Result<IKeyValueListResult<T>, KeyValueStoreRepository.Error>>;\n}\n\n/** Tenant-scoped key-value store. */\nexport const KeyValueStore = createAbstraction<IKeyValueStore>(\"KeyValueStore\");\n\nexport namespace KeyValueStore {\n export type Interface = IKeyValueStore;\n export type KeyValueRecord<T = any> = IKeyValueRecord<T>;\n export type ListResult<T = any> = IKeyValueListResult<T>;\n export type Error = KeyValueStoreRepository.Error;\n}\n\n// Repository\n\nexport interface IKeyValueStoreRepositoryErrors {\n base:\n | KeyNotFoundError\n | KeyValueStorageError\n | KeyValueInvalidCursorError\n | KeyValueInvalidCollectionError\n | KeyValueKeyTooLongError\n | KeyValueConditionFailedError\n | KeyValueInvalidConditionError;\n}\n\ntype RepositoryError = IKeyValueStoreRepositoryErrors[keyof IKeyValueStoreRepositoryErrors];\n\nexport interface IKeyValueStoreSetOptions\n extends IKeyValueCollectionOptions, IKeyValueWriteConditionOptions {\n expiresAt?: Date;\n}\n\nexport interface IKeyValueStoreRepository {\n get<T = unknown>(key: string, scope: string): Promise<Result<T, RepositoryError>>;\n set(\n key: string,\n value: any,\n scope: string,\n options?: IKeyValueStoreSetOptions\n ): Promise<Result<void, RepositoryError>>;\n delete(\n key: string,\n scope: string,\n options?: IKeyValueDeleteOptions\n ): Promise<Result<void, RepositoryError>>;\n list<T = unknown>(\n scope: string,\n params: IKeyValueListParams\n ): Promise<Result<IKeyValueListResult<T>, RepositoryError>>;\n}\n\n/** Persist and retrieve key-value pairs. */\nexport const KeyValueStoreRepository =\n createAbstraction<IKeyValueStoreRepository>(\"KeyValueStoreRepository\");\n\nexport namespace KeyValueStoreRepository {\n export type Interface = IKeyValueStoreRepository;\n export type Error = RepositoryError;\n}\n\n// Storage Operations\n\nexport interface IKeyValueStorageOperations {\n get(key: string, scope: string): Promise<{ key: string; value: any } | null>;\n /**\n * Puts the record in `options.collection`, or in none when it is not given. With a condition in\n * `options`, checks it and writes as one atomic step; resolves to whether it wrote.\n */\n set(\n key: string,\n value: any,\n scope: string,\n options?: IKeyValueStoreSetOptions\n ): Promise<boolean>;\n /** With a condition, checks it and deletes as one atomic step; resolves to whether it deleted. */\n delete(key: string, scope: string, options?: IKeyValueDeleteOptions): Promise<boolean>;\n /**\n * Up to `limit` members of `collection` in `scope` past `after`, ordered by the key's UTF-8\n * bytes (descending when `reverse`), expired ones left out.\n */\n list(params: IKeyValueStorageListParams): Promise<IKeyValueStorageListResult>;\n}\n\nexport interface IKeyValueStorageListParams {\n collection: string;\n scope: string;\n limit: number;\n reverse: boolean;\n /** Only keys past this one, in the order of the listing. */\n after?: string;\n}\n\nexport interface IKeyValueStorageListResult {\n items: IKeyValueRecord[];\n /**\n * The last key this page read, expired records included, when more may follow; otherwise\n * `null`. The next page starts after it.\n */\n lastKey: string | null;\n}\n\n/** Storage operations for key-value persistence. */\nexport const KeyValueStorageOperations = createAbstraction<IKeyValueStorageOperations>(\n \"KeyValueStorageOperations\"\n);\n\nexport namespace KeyValueStorageOperations {\n export type Interface = IKeyValueStorageOperations;\n}\n"],"names":["GlobalKeyValueStore","createAbstraction","KeyValueStore","KeyValueStoreRepository","KeyValueStorageOperations"],"mappings":";AAyIO,MAAMA,sBAAsBC,kBAAwC;AA+BpE,MAAMC,gBAAgBD,kBAAkC;AAiDxD,MAAME,0BACTF,kBAA4C;AAiDzC,MAAMG,4BAA4BH,kBACrC"}
@@ -9,3 +9,32 @@ export declare class KeyValueStorageError extends BaseError {
9
9
  readonly code: "KeyValueStore/Persistence";
10
10
  constructor(error: Error);
11
11
  }
12
+ export declare class KeyValueInvalidCursorError extends BaseError<{
13
+ cursor: string;
14
+ }> {
15
+ readonly code: "KeyValueStore/InvalidCursor";
16
+ constructor(cursor: string);
17
+ }
18
+ export declare class KeyValueInvalidCollectionError extends BaseError<{
19
+ maxBytes: number;
20
+ }> {
21
+ readonly code: "KeyValueStore/InvalidCollection";
22
+ constructor(maxBytes: number);
23
+ }
24
+ export declare class KeyValueKeyTooLongError extends BaseError<{
25
+ key: string;
26
+ maxBytes: number;
27
+ }> {
28
+ readonly code: "KeyValueStore/KeyTooLong";
29
+ constructor(key: string, maxBytes: number);
30
+ }
31
+ export declare class KeyValueConditionFailedError extends BaseError<{
32
+ key: string;
33
+ }> {
34
+ readonly code: "KeyValueStore/ConditionFailed";
35
+ constructor(key: string);
36
+ }
37
+ export declare class KeyValueInvalidConditionError extends BaseError {
38
+ readonly code: "KeyValueStore/InvalidCondition";
39
+ constructor();
40
+ }
@@ -16,6 +16,54 @@ class KeyValueStorageError extends BaseError {
16
16
  }), this.code = "KeyValueStore/Persistence";
17
17
  }
18
18
  }
19
- export { KeyNotFoundError, KeyValueStorageError };
19
+ class KeyValueInvalidCursorError extends BaseError {
20
+ constructor(cursor){
21
+ super({
22
+ message: "The list cursor is not one this store returned.",
23
+ data: {
24
+ cursor
25
+ }
26
+ }), this.code = "KeyValueStore/InvalidCursor";
27
+ }
28
+ }
29
+ class KeyValueInvalidCollectionError extends BaseError {
30
+ constructor(maxBytes){
31
+ super({
32
+ message: `A collection name must be a non-empty string of at most ${maxBytes} bytes.`,
33
+ data: {
34
+ maxBytes
35
+ }
36
+ }), this.code = "KeyValueStore/InvalidCollection";
37
+ }
38
+ }
39
+ class KeyValueKeyTooLongError extends BaseError {
40
+ constructor(key, maxBytes){
41
+ super({
42
+ message: `A key in a collection must be at most ${maxBytes} bytes.`,
43
+ data: {
44
+ key,
45
+ maxBytes
46
+ }
47
+ }), this.code = "KeyValueStore/KeyTooLong";
48
+ }
49
+ }
50
+ class KeyValueConditionFailedError extends BaseError {
51
+ constructor(key){
52
+ super({
53
+ message: `The record "${key}" was not in the state the write required.`,
54
+ data: {
55
+ key
56
+ }
57
+ }), this.code = "KeyValueStore/ConditionFailed";
58
+ }
59
+ }
60
+ class KeyValueInvalidConditionError extends BaseError {
61
+ constructor(){
62
+ super({
63
+ message: "A condition is `exists` or `equals`, never both. `equals` takes a string, number or boolean, and a delete takes `exists` only as `true`."
64
+ }), this.code = "KeyValueStore/InvalidCondition";
65
+ }
66
+ }
67
+ export { KeyNotFoundError, KeyValueConditionFailedError, KeyValueInvalidCollectionError, KeyValueInvalidConditionError, KeyValueInvalidCursorError, KeyValueKeyTooLongError, KeyValueStorageError };
20
68
 
21
69
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"features/keyValueStore/errors.js","sources":["../../../src/features/keyValueStore/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport class KeyNotFoundError extends BaseError<{ key: string }> {\n override readonly code = \"KeyValueStore/KeyNotFound\" as const;\n\n constructor(key: string) {\n super({\n message: `Key \"${key}\" was not found`,\n data: { key }\n });\n }\n}\n\nexport class KeyValueStorageError extends BaseError {\n override readonly code = \"KeyValueStore/Persistence\" as const;\n\n constructor(error: Error) {\n super({\n message: error.message\n });\n }\n}\n"],"names":["KeyNotFoundError","BaseError","key","KeyValueStorageError","error"],"mappings":";AAEO,MAAMA,yBAAyBC;IAGlC,YAAYC,GAAW,CAAE;QACrB,KAAK,CAAC;YACF,SAAS,CAAC,KAAK,EAAEA,IAAI,eAAe,CAAC;YACrC,MAAM;gBAAEA;YAAI;QAChB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,6BAA6BF;IAGtC,YAAYG,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAASA,MAAM,OAAO;QAC1B,SALc,IAAI,GAAG;IAMzB;AACJ"}
1
+ {"version":3,"file":"features/keyValueStore/errors.js","sources":["../../../src/features/keyValueStore/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport class KeyNotFoundError extends BaseError<{ key: string }> {\n override readonly code = \"KeyValueStore/KeyNotFound\" as const;\n\n constructor(key: string) {\n super({\n message: `Key \"${key}\" was not found`,\n data: { key }\n });\n }\n}\n\nexport class KeyValueStorageError extends BaseError {\n override readonly code = \"KeyValueStore/Persistence\" as const;\n\n constructor(error: Error) {\n super({\n message: error.message\n });\n }\n}\n\nexport class KeyValueInvalidCursorError extends BaseError<{ cursor: string }> {\n override readonly code = \"KeyValueStore/InvalidCursor\" as const;\n\n constructor(cursor: string) {\n super({\n message: \"The list cursor is not one this store returned.\",\n data: { cursor }\n });\n }\n}\n\nexport class KeyValueInvalidCollectionError extends BaseError<{ maxBytes: number }> {\n override readonly code = \"KeyValueStore/InvalidCollection\" as const;\n\n constructor(maxBytes: number) {\n super({\n message: `A collection name must be a non-empty string of at most ${maxBytes} bytes.`,\n data: { maxBytes }\n });\n }\n}\n\nexport class KeyValueKeyTooLongError extends BaseError<{ key: string; maxBytes: number }> {\n override readonly code = \"KeyValueStore/KeyTooLong\" as const;\n\n constructor(key: string, maxBytes: number) {\n super({\n message: `A key in a collection must be at most ${maxBytes} bytes.`,\n data: { key, maxBytes }\n });\n }\n}\n\nexport class KeyValueConditionFailedError extends BaseError<{ key: string }> {\n override readonly code = \"KeyValueStore/ConditionFailed\" as const;\n\n constructor(key: string) {\n super({\n message: `The record \"${key}\" was not in the state the write required.`,\n data: { key }\n });\n }\n}\n\nexport class KeyValueInvalidConditionError extends BaseError {\n override readonly code = \"KeyValueStore/InvalidCondition\" as const;\n\n constructor() {\n super({\n message:\n \"A condition is `exists` or `equals`, never both. `equals` takes a string, number or boolean, and a delete takes `exists` only as `true`.\"\n });\n }\n}\n"],"names":["KeyNotFoundError","BaseError","key","KeyValueStorageError","error","KeyValueInvalidCursorError","cursor","KeyValueInvalidCollectionError","maxBytes","KeyValueKeyTooLongError","KeyValueConditionFailedError","KeyValueInvalidConditionError"],"mappings":";AAEO,MAAMA,yBAAyBC;IAGlC,YAAYC,GAAW,CAAE;QACrB,KAAK,CAAC;YACF,SAAS,CAAC,KAAK,EAAEA,IAAI,eAAe,CAAC;YACrC,MAAM;gBAAEA;YAAI;QAChB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,6BAA6BF;IAGtC,YAAYG,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAASA,MAAM,OAAO;QAC1B,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMC,mCAAmCJ;IAG5C,YAAYK,MAAc,CAAE;QACxB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAO;QACnB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,uCAAuCN;IAGhD,YAAYO,QAAgB,CAAE;QAC1B,KAAK,CAAC;YACF,SAAS,CAAC,wDAAwD,EAAEA,SAAS,OAAO,CAAC;YACrF,MAAM;gBAAEA;YAAS;QACrB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,gCAAgCR;IAGzC,YAAYC,GAAW,EAAEM,QAAgB,CAAE;QACvC,KAAK,CAAC;YACF,SAAS,CAAC,sCAAsC,EAAEA,SAAS,OAAO,CAAC;YACnE,MAAM;gBAAEN;gBAAKM;YAAS;QAC1B,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAME,qCAAqCT;IAG9C,YAAYC,GAAW,CAAE;QACrB,KAAK,CAAC;YACF,SAAS,CAAC,YAAY,EAAEA,IAAI,0CAA0C,CAAC;YACvE,MAAM;gBAAEA;YAAI;QAChB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMS,sCAAsCV;IAG/C,aAAc;QACV,KAAK,CAAC;YACF,SACI;QACR,SANc,IAAI,GAAG;IAOzB;AACJ"}
@@ -1,2 +1,5 @@
1
1
  export { GlobalKeyValueStore, KeyValueStore, KeyValueStoreRepository, KeyValueStorageOperations } from "./abstractions.js";
2
- export { KeyNotFoundError, KeyValueStorageError } from "./errors.js";
2
+ export type { KeyValueComparable } from "./abstractions.js";
3
+ export type { IKeyValueWriteCondition } from "./abstractions.js";
4
+ export type { IKeyValueDeleteCondition } from "./abstractions.js";
5
+ export { KeyNotFoundError, KeyValueStorageError, KeyValueInvalidCursorError, KeyValueInvalidCollectionError, KeyValueKeyTooLongError, KeyValueConditionFailedError, KeyValueInvalidConditionError } from "./errors.js";
@@ -1,2 +1,2 @@
1
1
  export { GlobalKeyValueStore, KeyValueStorageOperations, KeyValueStore, KeyValueStoreRepository } from "./abstractions.js";
2
- export { KeyNotFoundError, KeyValueStorageError } from "./errors.js";
2
+ export { KeyNotFoundError, KeyValueConditionFailedError, KeyValueInvalidCollectionError, KeyValueInvalidConditionError, KeyValueInvalidCursorError, KeyValueKeyTooLongError, KeyValueStorageError } from "./errors.js";
@@ -0,0 +1,10 @@
1
+ import type { Logger } from "./abstractions.js";
2
+ export declare class NullLogger implements Logger.Interface {
3
+ trace(): void;
4
+ debug(): void;
5
+ info(): void;
6
+ warn(): void;
7
+ error(): void;
8
+ fatal(): void;
9
+ log(): void;
10
+ }
@@ -0,0 +1,12 @@
1
+ class NullLogger {
2
+ trace() {}
3
+ debug() {}
4
+ info() {}
5
+ warn() {}
6
+ error() {}
7
+ fatal() {}
8
+ log() {}
9
+ }
10
+ export { NullLogger };
11
+
12
+ //# sourceMappingURL=NullLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/logger/NullLogger.js","sources":["../../../src/features/logger/NullLogger.ts"],"sourcesContent":["import type { Logger } from \"./abstractions.js\";\n\n/*\n * A Logger that drops every line. api-core registers no Logger, the event handlers register the real\n * one at root, so containers built without a handler, such as test harnesses, register this one.\n */\nexport class NullLogger implements Logger.Interface {\n public trace(): void {}\n\n public debug(): void {}\n\n public info(): void {}\n\n public warn(): void {}\n\n public error(): void {}\n\n public fatal(): void {}\n\n public log(): void {}\n}\n"],"names":["NullLogger"],"mappings":"AAMO,MAAMA;IACF,QAAc,CAAC;IAEf,QAAc,CAAC;IAEf,OAAa,CAAC;IAEd,OAAa,CAAC;IAEd,QAAc,CAAC;IAEf,QAAc,CAAC;IAEf,MAAY,CAAC;AACxB"}
@@ -1 +1,2 @@
1
1
  export { Logger } from "./abstractions.js";
2
+ export { NullLogger } from "./NullLogger.js";
@@ -1 +1,2 @@
1
1
  export { Logger } from "./abstractions.js";
2
+ export { NullLogger } from "./NullLogger.js";
@@ -0,0 +1,11 @@
1
+ import { PublicUrls } from "./abstractions.js";
2
+ import { PublicUrl } from "./PublicUrl.js";
3
+ /** Default for hosting types (and tests) that don't supply public URLs. */
4
+ declare class NullPublicUrlsImpl implements PublicUrls.Interface {
5
+ getApiUrl(): Promise<PublicUrl>;
6
+ getAdminUrl(): Promise<PublicUrl>;
7
+ }
8
+ export declare const NullPublicUrls: typeof NullPublicUrlsImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IPublicUrls>;
10
+ };
11
+ export {};
@@ -0,0 +1,17 @@
1
+ import { PublicUrls } from "./abstractions.js";
2
+ import { PublicUrl } from "./PublicUrl.js";
3
+ class NullPublicUrlsImpl {
4
+ async getApiUrl() {
5
+ return PublicUrl.unknown();
6
+ }
7
+ async getAdminUrl() {
8
+ return PublicUrl.unknown();
9
+ }
10
+ }
11
+ const NullPublicUrls = PublicUrls.createImplementation({
12
+ implementation: NullPublicUrlsImpl,
13
+ dependencies: []
14
+ });
15
+ export { NullPublicUrls };
16
+
17
+ //# sourceMappingURL=NullPublicUrls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/publicUrls/NullPublicUrls.js","sources":["../../../src/features/publicUrls/NullPublicUrls.ts"],"sourcesContent":["import { PublicUrls } from \"./abstractions.js\";\nimport { PublicUrl } from \"./PublicUrl.js\";\n\n/** Default for hosting types (and tests) that don't supply public URLs. */\nclass NullPublicUrlsImpl implements PublicUrls.Interface {\n async getApiUrl() {\n return PublicUrl.unknown();\n }\n\n async getAdminUrl() {\n return PublicUrl.unknown();\n }\n}\n\nexport const NullPublicUrls = PublicUrls.createImplementation({\n implementation: NullPublicUrlsImpl,\n dependencies: []\n});\n"],"names":["NullPublicUrlsImpl","PublicUrl","NullPublicUrls","PublicUrls"],"mappings":";;AAIA,MAAMA;IACF,MAAM,YAAY;QACd,OAAOC,UAAU,OAAO;IAC5B;IAEA,MAAM,cAAc;QAChB,OAAOA,UAAU,OAAO;IAC5B;AACJ;AAEO,MAAMC,iBAAiBC,WAAW,oBAAoB,CAAC;IAC1D,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}