11/**
22 * StateStore put options
3- *
4- * @typedef StateStorePutOptions
5- * @type {object }
6- * @property {number } ttl time-to-live for key-value pair in seconds, defaults to 24 hours (86400s). Set to < 0 for no expiry. A
3+ * @property ttl - time-to-live for key-value pair in seconds, defaults to 24 hours (86400s). Set to < 0 for no expiry. A
74 * value of 0 sets default.
85 */
9- declare type StateStorePutOptions = {
6+ export type StateStorePutOptions = {
107 ttl : number ;
118} ;
129
1310/**
1411 * StateStore get return object
15- *
16- * @typedef StateStoreGetReturnValue
17- * @type {object }
18- * @property {string|null } expiration ISO date string of expiration time for the key-value pair, if the ttl is infinite
12+ * @property expiration - ISO date string of expiration time for the key-value pair, if the ttl is infinite
1913 * expiration=null
20- * @property { any } value the value set by put
14+ * @property value - the value set by put
2115 */
22- declare type StateStoreGetReturnValue = {
16+ export type StateStoreGetReturnValue = {
2317 expiration : string | null ;
2418 value : any ;
2519} ;
2620
2721/**
28- * @abstract
29- * @class StateStore
30- * @classdesc Cloud State Management
31- * @hideconstructor
22+ * Cloud State Management
3223 */
33- declare class StateStore {
24+ export class StateStore {
3425 /**
3526 * Retrieves the state value for given key.
3627 * If the key doesn't exist returns undefined.
37- *
38- * @param {string } key state key identifier
39- * @returns {Promise<StateStoreGetReturnValue> } get response holding value and additional info
40- * @memberof StateStore
28+ * @param key - state key identifier
29+ * @returns get response holding value and additional info
4130 */
4231 get ( key : string ) : Promise < StateStoreGetReturnValue > ;
4332 /**
4433 * Creates or updates a state key-value pair
45- *
46- * @param {string } key state key identifier
47- * @param {any } value state value
48- * @param {StateStorePutOptions } [options={}] put options
49- * @returns {Promise<string> } key
50- * @memberof StateStore
34+ * @param key - state key identifier
35+ * @param value - state value
36+ * @param [options = { }] - put options
37+ * @returns key
5138 */
5239 put ( key : string , value : any , options ?: StateStorePutOptions ) : Promise < string > ;
5340 /**
5441 * Deletes a state key-value pair
55- *
56- * @param {string } key state key identifier
57- * @returns {Promise<string> } key of deleted state or `null` if state does not exists
58- * @memberof StateStore
42+ * @param key - state key identifier
43+ * @returns key of deleted state or `null` if state does not exists
5944 */
6045 delete ( key : string ) : Promise < string > ;
46+ /**
47+ * @param key - state key identifier
48+ * @returns get response holding value and additional info
49+ */
50+ protected _get ( key : string ) : Promise < StateStoreGetReturnValue > ;
51+ /**
52+ * @param key - state key identifier
53+ * @param value - state value
54+ * @param options - state put options
55+ * @returns key
56+ */
57+ protected _put ( key : string , value : any , options : any ) : Promise < string > ;
58+ /**
59+ * @param key - state key identifier
60+ * @returns key of deleted state or `null` if state does not exists
61+ */
62+ protected _delete ( key : string ) : Promise < string > ;
6163}
6264
63- /**
64- * State lib custom errors.
65- * `e.sdkDetails` provides additional context for each error (e.g. function parameter)
66- *
67- * @typedef StateLibErrors
68- * @type {object }
69- * @property {StateLibError } ERROR_BAD_ARGUMENT this error is thrown when an argument is missing or has invalid type
70- * @property {StateLibError } ERROR_NOT_IMPLEMENTED this error is thrown when a method is not implemented or when calling
71- * methods directly on the abstract class (StateStore).
72- * @property {StateLibError } ERROR_PAYLOAD_TOO_LARGE this error is thrown when the state key, state value or underlying request payload size
73- * exceeds the specified limitations.
74- * @property {StateLibError } ERROR_BAD_CREDENTIALS this error is thrown when the supplied init credentials are invalid.
75- * @property {StateLibError } ERROR_INTERNAL this error is thrown when an unknown error is thrown by the underlying
76- * DB provider or TVM server for credential exchange. More details can be found in `e.sdkDetails._internal`.
77- */
78- declare type StateLibErrors = {
79- ERROR_BAD_ARGUMENT : StateLibError ;
80- ERROR_NOT_IMPLEMENTED : StateLibError ;
81- ERROR_PAYLOAD_TOO_LARGE : StateLibError ;
82- ERROR_BAD_CREDENTIALS : StateLibError ;
83- ERROR_INTERNAL : StateLibError ;
84- } ;
65+
8566
8667/**
8768 * An object holding the OpenWhisk credentials
88- *
89- * @typedef OpenWhiskCredentials
90- * @type {object }
91- * @property {string } namespace user namespace
92- * @property {string } auth auth key
69+ * @property namespace - user namespace
70+ * @property auth - auth key
9371 */
94- declare type OpenWhiskCredentials = {
72+ export type OpenWhiskCredentials = {
9573 namespace : string ;
9674 auth : string ;
9775} ;
9876
9977/**
10078 * An object holding the Azure Cosmos resource credentials with permissions on a single partition and container
101- *
102- * @typedef AzureCosmosPartitionResourceCredentials
103- * @type {object }
104- * @property {string } endpoint cosmosdb resource endpoint
105- * @property {string } resourceToken cosmosdb resource token restricted to the partitionKey
106- * @property {string } databaseId id for cosmosdb database
107- * @property {string } containerId id for cosmosdb container within database
108- * @property {string } partitionKey key for cosmosdb partition within container authorized by resource token
109- *
79+ * @property endpoint - cosmosdb resource endpoint
80+ * @property resourceToken - cosmosdb resource token restricted to the partitionKey
81+ * @property databaseId - id for cosmosdb database
82+ * @property containerId - id for cosmosdb container within database
83+ * @property partitionKey - key for cosmosdb partition within container authorized by resource token
11084 */
111- declare type AzureCosmosPartitionResourceCredentials = {
85+ export type AzureCosmosPartitionResourceCredentials = {
11286 endpoint : string ;
11387 resourceToken : string ;
11488 databaseId : string ;
@@ -118,17 +92,13 @@ declare type AzureCosmosPartitionResourceCredentials = {
11892
11993/**
12094 * An object holding the Azure Cosmos account master key
121- *
122- * @typedef AzureCosmosMasterCredentials
123- * @type {object }
124- * @property {string } endpoint cosmosdb resource endpoint
125- * @property {string } masterKey cosmosdb account masterKey
126- * @property {string } databaseId id for cosmosdb database
127- * @property {string } containerId id for cosmosdb container within database
128- * @property {string } partitionKey key for cosmosdb partition where data will be stored
129- *
95+ * @property endpoint - cosmosdb resource endpoint
96+ * @property masterKey - cosmosdb account masterKey
97+ * @property databaseId - id for cosmosdb database
98+ * @property containerId - id for cosmosdb container within database
99+ * @property partitionKey - key for cosmosdb partition where data will be stored
130100 */
131- declare type AzureCosmosMasterCredentials = {
101+ export type AzureCosmosMasterCredentials = {
132102 endpoint : string ;
133103 masterKey : string ;
134104 databaseId : string ;
@@ -145,25 +115,19 @@ declare type AzureCosmosMasterCredentials = {
145115 * [Azure Cosmos credentials]{@link AzureCosmosMasterCredentials} in `config.cosmos`.
146116 *
147117 * OpenWhisk credentials can also be read from environment variables `__OW_NAMESPACE` and `__OW_API_KEY`.
148- *
149- * @param {object } [config={}] used to init the sdk
150- *
151- * @param {OpenWhiskCredentials } [config.ow]
152- * {@link OpenWhiskCredentials}. Set those if you want
118+ * @param [config = { }] - used to init the sdk
119+ * @param [config.ow] - {@link OpenWhiskCredentials}. Set those if you want
153120 * to use ootb credentials to access the state management service. OpenWhisk
154121 * namespace and auth can also be passed through environment variables:
155122 * `__OW_NAMESPACE` and `__OW_API_KEY`
156- *
157- * @param {AzureCosmosMasterCredentials|AzureCosmosPartitionResourceCredentials } [config.cosmos]
158- * [Azure Cosmos resource credentials]{@link AzureCosmosPartitionResourceCredentials} or
123+ * @param [config.cosmos] - [Azure Cosmos resource credentials]{@link AzureCosmosPartitionResourceCredentials} or
159124 * [Azure Cosmos account credentials]{@link AzureCosmosMasterCredentials}
160- *
161- * @param {object } [config.tvm] tvm configuration, applies only when passing OpenWhisk credentials
162- * @param {string } [config.tvm.apiUrl] alternative tvm api url.
163- * @param {string } [config.tvm.cacheFile] alternative tvm cache file, set to `false` to disable caching of temporary credentials.
164- * @returns {Promise<StateStore> } A StateStore instance
125+ * @param [config.tvm] - tvm configuration, applies only when passing OpenWhisk credentials
126+ * @param [config.tvm.apiUrl] - alternative tvm api url.
127+ * @param [config.tvm.cacheFile] - alternative tvm cache file, set to `false` to disable caching of temporary credentials.
128+ * @returns A StateStore instance
165129 */
166- declare function init ( config ?: {
130+ export function init ( config ?: {
167131 ow ?: OpenWhiskCredentials ;
168132 cosmos ?: AzureCosmosMasterCredentials | AzureCosmosPartitionResourceCredentials ;
169133 tvm ?: {
0 commit comments