Skip to content

Commit b686c60

Browse files
authored
fix autocompletion and protected methods (#53)
* fix autocompletion and private methods * fix for replacing all occurences * delete commented code
1 parent 8aade8b commit b686c60

File tree

5 files changed

+114
-115
lines changed

5 files changed

+114
-115
lines changed

doc/api.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ Cloud State Management
5454
* *[.get(key)](#StateStore+get)[<code>Promise.&lt;StateStoreGetReturnValue&gt;</code>](#StateStoreGetReturnValue)*
5555
* *[.put(key, value, [options])](#StateStore+put) ⇒ <code>Promise.&lt;string&gt;</code>*
5656
* *[.delete(key)](#StateStore+delete) ⇒ <code>Promise.&lt;string&gt;</code>*
57+
* *[._get(key)](#StateStore+_get)[<code>Promise.&lt;StateStoreGetReturnValue&gt;</code>](#StateStoreGetReturnValue)*
58+
* *[._put(key, value, options)](#StateStore+_put) ⇒ <code>Promise.&lt;string&gt;</code>*
59+
* *[._delete(key)](#StateStore+_delete) ⇒ <code>Promise.&lt;string&gt;</code>*
5760

5861
<a name="StateStore+get"></a>
5962

@@ -94,6 +97,41 @@ Deletes a state key-value pair
9497
| --- | --- | --- |
9598
| key | <code>string</code> | state key identifier |
9699

100+
<a name="StateStore+_get"></a>
101+
102+
### *stateStore.\_get(key) ⇒ [<code>Promise.&lt;StateStoreGetReturnValue&gt;</code>](#StateStoreGetReturnValue)*
103+
**Kind**: instance method of [<code>StateStore</code>](#StateStore)
104+
**Returns**: [<code>Promise.&lt;StateStoreGetReturnValue&gt;</code>](#StateStoreGetReturnValue) - get response holding value and additional info
105+
**Access**: protected
106+
107+
| Param | Type | Description |
108+
| --- | --- | --- |
109+
| key | <code>string</code> | state key identifier |
110+
111+
<a name="StateStore+_put"></a>
112+
113+
### *stateStore.\_put(key, value, options) ⇒ <code>Promise.&lt;string&gt;</code>*
114+
**Kind**: instance method of [<code>StateStore</code>](#StateStore)
115+
**Returns**: <code>Promise.&lt;string&gt;</code> - key
116+
**Access**: protected
117+
118+
| Param | Type | Description |
119+
| --- | --- | --- |
120+
| key | <code>string</code> | state key identifier |
121+
| value | <code>any</code> | state value |
122+
| options | <code>object</code> | state put options |
123+
124+
<a name="StateStore+_delete"></a>
125+
126+
### *stateStore.\_delete(key) ⇒ <code>Promise.&lt;string&gt;</code>*
127+
**Kind**: instance method of [<code>StateStore</code>](#StateStore)
128+
**Returns**: <code>Promise.&lt;string&gt;</code> - key of deleted state or `null` if state does not exists
129+
**Access**: protected
130+
131+
| Param | Type | Description |
132+
| --- | --- | --- |
133+
| key | <code>string</code> | state key identifier |
134+
97135
<a name="init"></a>
98136

99137
## init([config]) ⇒ [<code>Promise.&lt;StateStore&gt;</code>](#StateStore)

lib/StateStore.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,27 @@ class StateStore {
142142
return this._delete(key)
143143
}
144144

145-
// /**
146-
// * List all existing state keys.
147-
// *
148-
// * Use wisely as this is a slow operation => o(n)
149-
// *
150-
// * @returns {Promise<Array<string>>} list of keys
151-
// * @memberof StateStore
152-
// */
153-
// async keys () {
154-
// return this._keys()
155-
// }
156-
157145
/* **************************** PRIVATE METHODS TO IMPLEMENT ***************************** */
146+
/**
147+
* @param {string} key state key identifier
148+
* @returns {Promise<StateStoreGetReturnValue>} get response holding value and additional info
149+
* @protected
150+
*/
158151
async _get (key) { throwNotImplemented('_get') }
152+
/**
153+
* @param {string} key state key identifier
154+
* @param {any} value state value
155+
* @param {object} options state put options
156+
* @returns {Promise<string>} key
157+
* @protected
158+
*/
159159
async _put (key, value, options) { throwNotImplemented('_put') }
160+
/**
161+
* @param {string} key state key identifier
162+
* @returns {Promise<string>} key of deleted state or `null` if state does not exists
163+
* @protected
164+
*/
160165
async _delete (key) { throwNotImplemented('_delete') }
161-
// async _keys () { throwNotImplemented('_keys') }
162166
}
163167

164168
StateStore.DefaultTTL = 86400 // 24hours

lib/impl/CosmosStateStore.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,6 @@ class CosmosStateStore extends StateStore {
148148
const ret = await _wrap(this._cosmos.container.item(key, this._cosmos.partitionKey).delete(), { key })
149149
return ret && key
150150
}
151-
152-
// /**
153-
// * @memberof CosmosStateStore
154-
// * @override
155-
// * @private
156-
// */
157-
// async _keys () {
158-
// // TODO
159-
// }
160151
}
161152

162153
module.exports = { CosmosStateStore }

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
"directories": {
77
"lib": "lib"
88
},
9+
"types": "types.d.ts",
910
"scripts": {
1011
"lint": "eslint index.js lib test",
1112
"beautify": "npm run lint -- --fix",
1213
"test": "npm run unit && npm run lint",
1314
"unit": "jest -c jest.config.js",
1415
"e2e": "jest -c jest.e2e.config.js",
1516
"jsdoc": "jsdoc2md -f index.js 'lib/**/*.js' > doc/api.md",
16-
"typings": "jsdoc -t node_modules/tsd-jsdoc/dist -r lib -d .",
17+
"typings": "jsdoc -t node_modules/tsd-jsdoc/dist -r lib -d . && replace-in-file /declare/g export types.d.ts --isRegex",
1718
"generate-docs": "npm run jsdoc && npm run typings"
1819
},
1920
"author": "Adobe Inc.",
@@ -46,6 +47,7 @@
4647
"eslint-plugin-standard": "^4.0.1",
4748
"jest": "^24.9.0",
4849
"jsdoc-to-markdown": "^5.0.2",
50+
"replace-in-file": "^6.1.0",
4951
"tsd-jsdoc": "^2.4.0"
5052
},
5153
"dependencies": {

types.d.ts

Lines changed: 56 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,88 @@
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

Comments
 (0)