@deephaven/jsapi-utils 1.12.1 → 1.15.2-alpha-fetch-variable-def.0

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.
@@ -2,11 +2,26 @@ import type { dh } from '@deephaven/jsapi-types';
2
2
  /** Default timeout for fetching a variable definition */
3
3
  export declare const FETCH_TIMEOUT = 10000;
4
4
  /**
5
- * Fetch the definition for a variable given a connection. Subscribes to field updates and triggers when the variable is found.
5
+ * Fetch the definition for a variable given a connection. Waits for the next
6
+ * field update event and resolves if the variable is found in the created
7
+ * variables.
6
8
  * @param connection Connection to get the variable from
7
9
  * @param name Name of the definition to fetch
8
10
  * @param timeout Timeout for the fetch
9
- * @returns Promise the resolves to the variable definition if found, or rejects if there's an error or the timeout has exceeded
11
+ * @returns Promise that resolves to the variable definition if found in the next field update,
12
+ * or rejects if the variable is not found in that update or if the timeout is exceeded
10
13
  */
11
14
  export declare function fetchVariableDefinition(connection: dh.IdeConnection, name: string, timeout?: number): Promise<dh.ide.VariableDefinition>;
15
+ /**
16
+ * Fetch the definition for a variable given a connection. Waits for the next
17
+ * field update event and resolves if a variable matching the predicate is found
18
+ * in the created variables.
19
+ * @param connection Connection to get the variable from
20
+ * @param predicate Predicate function to test each variable definition
21
+ * @param timeout Timeout for the fetch
22
+ * @param errorMessage Optional error message for timeout and not found errors
23
+ * @returns Promise that resolves to the variable definition if found in the next field update,
24
+ * or rejects if no matching variable is found in that update or if the timeout is exceeded
25
+ */
26
+ export declare function fetchVariableDefinitionByPredicate(connection: dh.IdeConnection, predicate: (definition: dh.ide.VariableDefinition) => boolean, timeout?: number, errorMessage?: string): Promise<dh.ide.VariableDefinition>;
12
27
  //# sourceMappingURL=ConnectionUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConnectionUtils.d.ts","sourceRoot":"","sources":["../src/ConnectionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAGjD,yDAAyD;AACzD,eAAO,MAAM,aAAa,QAAS,CAAC;AAEpC;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,EAAE,CAAC,aAAa,EAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,SAAgB,GACtB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,CA0BpC"}
1
+ {"version":3,"file":"ConnectionUtils.d.ts","sourceRoot":"","sources":["../src/ConnectionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAGjD,yDAAyD;AACzD,eAAO,MAAM,aAAa,QAAS,CAAC;AAEpC;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,EAAE,CAAC,aAAa,EAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,SAAgB,GACtB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAOpC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kCAAkC,CAChD,UAAU,EAAE,EAAE,CAAC,aAAa,EAC5B,SAAS,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,KAAK,OAAO,EAC7D,OAAO,SAAgB,EACvB,YAAY,SAAuB,GAClC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,CA0BpC"}
@@ -4,35 +4,55 @@ import { TimeoutError } from '@deephaven/utils';
4
4
  export var FETCH_TIMEOUT = 10000;
5
5
 
6
6
  /**
7
- * Fetch the definition for a variable given a connection. Subscribes to field updates and triggers when the variable is found.
7
+ * Fetch the definition for a variable given a connection. Waits for the next
8
+ * field update event and resolves if the variable is found in the created
9
+ * variables.
8
10
  * @param connection Connection to get the variable from
9
11
  * @param name Name of the definition to fetch
10
12
  * @param timeout Timeout for the fetch
11
- * @returns Promise the resolves to the variable definition if found, or rejects if there's an error or the timeout has exceeded
13
+ * @returns Promise that resolves to the variable definition if found in the next field update,
14
+ * or rejects if the variable is not found in that update or if the timeout is exceeded
12
15
  */
13
16
  export function fetchVariableDefinition(connection, name) {
14
17
  var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : FETCH_TIMEOUT;
18
+ return fetchVariableDefinitionByPredicate(connection, def => def.title === name, timeout, "Variable ".concat(name, " not found"));
19
+ }
20
+
21
+ /**
22
+ * Fetch the definition for a variable given a connection. Waits for the next
23
+ * field update event and resolves if a variable matching the predicate is found
24
+ * in the created variables.
25
+ * @param connection Connection to get the variable from
26
+ * @param predicate Predicate function to test each variable definition
27
+ * @param timeout Timeout for the fetch
28
+ * @param errorMessage Optional error message for timeout and not found errors
29
+ * @returns Promise that resolves to the variable definition if found in the next field update,
30
+ * or rejects if no matching variable is found in that update or if the timeout is exceeded
31
+ */
32
+ export function fetchVariableDefinitionByPredicate(connection, predicate) {
33
+ var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : FETCH_TIMEOUT;
34
+ var errorMessage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'Variable not found';
15
35
  return new Promise((resolve, reject) => {
16
36
  var removeListener;
17
37
  var timeoutId = setTimeout(() => {
18
38
  var _removeListener;
19
39
  (_removeListener = removeListener) === null || _removeListener === void 0 || _removeListener();
20
- reject(new TimeoutError("Timeout looking for variable ".concat(name)));
40
+ reject(new TimeoutError("Timeout: ".concat(errorMessage)));
21
41
  }, timeout);
22
42
 
23
43
  /**
24
- * Checks if the variable we're looking for is in the changes, and resolves the promise if it does
44
+ * Checks if a variable matching the predicate is in the changes, and resolves the promise if it does
25
45
  * @param changes Variables changes that have occurred
26
46
  */
27
47
  function handleFieldUpdates(changes) {
28
48
  var _removeListener2;
29
- var definition = changes.created.find(def => def.title === name);
49
+ var definition = changes.created.find(predicate);
30
50
  clearTimeout(timeoutId);
31
51
  (_removeListener2 = removeListener) === null || _removeListener2 === void 0 || _removeListener2();
32
52
  if (definition != null) {
33
53
  resolve(definition);
34
54
  } else {
35
- reject(new Error("Variable ".concat(name, " not found")));
55
+ reject(new Error(errorMessage));
36
56
  }
37
57
  }
38
58
  removeListener = connection.subscribeToFieldUpdates(handleFieldUpdates);
@@ -1 +1 @@
1
- {"version":3,"file":"ConnectionUtils.js","names":["TimeoutError","FETCH_TIMEOUT","fetchVariableDefinition","connection","name","timeout","arguments","length","undefined","Promise","resolve","reject","removeListener","timeoutId","setTimeout","_removeListener","concat","handleFieldUpdates","changes","_removeListener2","definition","created","find","def","title","clearTimeout","Error","subscribeToFieldUpdates"],"sources":["../src/ConnectionUtils.ts"],"sourcesContent":["import type { dh } from '@deephaven/jsapi-types';\nimport { TimeoutError } from '@deephaven/utils';\n\n/** Default timeout for fetching a variable definition */\nexport const FETCH_TIMEOUT = 10_000;\n\n/**\n * Fetch the definition for a variable given a connection. Subscribes to field updates and triggers when the variable is found.\n * @param connection Connection to get the variable from\n * @param name Name of the definition to fetch\n * @param timeout Timeout for the fetch\n * @returns Promise the resolves to the variable definition if found, or rejects if there's an error or the timeout has exceeded\n */\nexport function fetchVariableDefinition(\n connection: dh.IdeConnection,\n name: string,\n timeout = FETCH_TIMEOUT\n): Promise<dh.ide.VariableDefinition> {\n return new Promise<dh.ide.VariableDefinition>((resolve, reject) => {\n let removeListener: () => void;\n\n const timeoutId = setTimeout(() => {\n removeListener?.();\n reject(new TimeoutError(`Timeout looking for variable ${name}`));\n }, timeout);\n\n /**\n * Checks if the variable we're looking for is in the changes, and resolves the promise if it does\n * @param changes Variables changes that have occurred\n */\n function handleFieldUpdates(changes: dh.ide.VariableChanges): void {\n const definition = changes.created.find(def => def.title === name);\n clearTimeout(timeoutId);\n removeListener?.();\n if (definition != null) {\n resolve(definition);\n } else {\n reject(new Error(`Variable ${name} not found`));\n }\n }\n\n removeListener = connection.subscribeToFieldUpdates(handleFieldUpdates);\n });\n}\n"],"mappings":"AACA,SAASA,YAAY,QAAQ,kBAAkB;;AAE/C;AACA,OAAO,IAAMC,aAAa,GAAG,KAAM;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CACrCC,UAA4B,EAC5BC,IAAY,EAEwB;EAAA,IADpCC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGL,aAAa;EAEvB,OAAO,IAAIQ,OAAO,CAA4B,CAACC,OAAO,EAAEC,MAAM,KAAK;IACjE,IAAIC,cAA0B;IAE9B,IAAMC,SAAS,GAAGC,UAAU,CAAC,MAAM;MAAA,IAAAC,eAAA;MACjC,CAAAA,eAAA,GAAAH,cAAc,cAAAG,eAAA,eAAdA,eAAA,CAAiB,CAAC;MAClBJ,MAAM,CAAC,IAAIX,YAAY,iCAAAgB,MAAA,CAAiCZ,IAAI,CAAE,CAAC,CAAC;IAClE,CAAC,EAAEC,OAAO,CAAC;;IAEX;AACJ;AACA;AACA;IACI,SAASY,kBAAkBA,CAACC,OAA+B,EAAQ;MAAA,IAAAC,gBAAA;MACjE,IAAMC,UAAU,GAAGF,OAAO,CAACG,OAAO,CAACC,IAAI,CAACC,GAAG,IAAIA,GAAG,CAACC,KAAK,KAAKpB,IAAI,CAAC;MAClEqB,YAAY,CAACZ,SAAS,CAAC;MACvB,CAAAM,gBAAA,GAAAP,cAAc,cAAAO,gBAAA,eAAdA,gBAAA,CAAiB,CAAC;MAClB,IAAIC,UAAU,IAAI,IAAI,EAAE;QACtBV,OAAO,CAACU,UAAU,CAAC;MACrB,CAAC,MAAM;QACLT,MAAM,CAAC,IAAIe,KAAK,aAAAV,MAAA,CAAaZ,IAAI,eAAY,CAAC,CAAC;MACjD;IACF;IAEAQ,cAAc,GAAGT,UAAU,CAACwB,uBAAuB,CAACV,kBAAkB,CAAC;EACzE,CAAC,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"ConnectionUtils.js","names":["TimeoutError","FETCH_TIMEOUT","fetchVariableDefinition","connection","name","timeout","arguments","length","undefined","fetchVariableDefinitionByPredicate","def","title","concat","predicate","errorMessage","Promise","resolve","reject","removeListener","timeoutId","setTimeout","_removeListener","handleFieldUpdates","changes","_removeListener2","definition","created","find","clearTimeout","Error","subscribeToFieldUpdates"],"sources":["../src/ConnectionUtils.ts"],"sourcesContent":["import type { dh } from '@deephaven/jsapi-types';\nimport { TimeoutError } from '@deephaven/utils';\n\n/** Default timeout for fetching a variable definition */\nexport const FETCH_TIMEOUT = 10_000;\n\n/**\n * Fetch the definition for a variable given a connection. Waits for the next\n * field update event and resolves if the variable is found in the created\n * variables.\n * @param connection Connection to get the variable from\n * @param name Name of the definition to fetch\n * @param timeout Timeout for the fetch\n * @returns Promise that resolves to the variable definition if found in the next field update,\n * or rejects if the variable is not found in that update or if the timeout is exceeded\n */\nexport function fetchVariableDefinition(\n connection: dh.IdeConnection,\n name: string,\n timeout = FETCH_TIMEOUT\n): Promise<dh.ide.VariableDefinition> {\n return fetchVariableDefinitionByPredicate(\n connection,\n def => def.title === name,\n timeout,\n `Variable ${name} not found`\n );\n}\n\n/**\n * Fetch the definition for a variable given a connection. Waits for the next\n * field update event and resolves if a variable matching the predicate is found\n * in the created variables.\n * @param connection Connection to get the variable from\n * @param predicate Predicate function to test each variable definition\n * @param timeout Timeout for the fetch\n * @param errorMessage Optional error message for timeout and not found errors\n * @returns Promise that resolves to the variable definition if found in the next field update,\n * or rejects if no matching variable is found in that update or if the timeout is exceeded\n */\nexport function fetchVariableDefinitionByPredicate(\n connection: dh.IdeConnection,\n predicate: (definition: dh.ide.VariableDefinition) => boolean,\n timeout = FETCH_TIMEOUT,\n errorMessage = 'Variable not found'\n): Promise<dh.ide.VariableDefinition> {\n return new Promise<dh.ide.VariableDefinition>((resolve, reject) => {\n let removeListener: () => void;\n\n const timeoutId = setTimeout(() => {\n removeListener?.();\n reject(new TimeoutError(`Timeout: ${errorMessage}`));\n }, timeout);\n\n /**\n * Checks if a variable matching the predicate is in the changes, and resolves the promise if it does\n * @param changes Variables changes that have occurred\n */\n function handleFieldUpdates(changes: dh.ide.VariableChanges): void {\n const definition = changes.created.find(predicate);\n clearTimeout(timeoutId);\n removeListener?.();\n if (definition != null) {\n resolve(definition);\n } else {\n reject(new Error(errorMessage));\n }\n }\n\n removeListener = connection.subscribeToFieldUpdates(handleFieldUpdates);\n });\n}\n"],"mappings":"AACA,SAASA,YAAY,QAAQ,kBAAkB;;AAE/C;AACA,OAAO,IAAMC,aAAa,GAAG,KAAM;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CACrCC,UAA4B,EAC5BC,IAAY,EAEwB;EAAA,IADpCC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGL,aAAa;EAEvB,OAAOQ,kCAAkC,CACvCN,UAAU,EACVO,GAAG,IAAIA,GAAG,CAACC,KAAK,KAAKP,IAAI,EACzBC,OAAO,cAAAO,MAAA,CACKR,IAAI,eAClB,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,kCAAkCA,CAChDN,UAA4B,EAC5BU,SAA6D,EAGzB;EAAA,IAFpCR,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGL,aAAa;EAAA,IACvBa,YAAY,GAAAR,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,oBAAoB;EAEnC,OAAO,IAAIS,OAAO,CAA4B,CAACC,OAAO,EAAEC,MAAM,KAAK;IACjE,IAAIC,cAA0B;IAE9B,IAAMC,SAAS,GAAGC,UAAU,CAAC,MAAM;MAAA,IAAAC,eAAA;MACjC,CAAAA,eAAA,GAAAH,cAAc,cAAAG,eAAA,eAAdA,eAAA,CAAiB,CAAC;MAClBJ,MAAM,CAAC,IAAIjB,YAAY,aAAAY,MAAA,CAAaE,YAAY,CAAE,CAAC,CAAC;IACtD,CAAC,EAAET,OAAO,CAAC;;IAEX;AACJ;AACA;AACA;IACI,SAASiB,kBAAkBA,CAACC,OAA+B,EAAQ;MAAA,IAAAC,gBAAA;MACjE,IAAMC,UAAU,GAAGF,OAAO,CAACG,OAAO,CAACC,IAAI,CAACd,SAAS,CAAC;MAClDe,YAAY,CAACT,SAAS,CAAC;MACvB,CAAAK,gBAAA,GAAAN,cAAc,cAAAM,gBAAA,eAAdA,gBAAA,CAAiB,CAAC;MAClB,IAAIC,UAAU,IAAI,IAAI,EAAE;QACtBT,OAAO,CAACS,UAAU,CAAC;MACrB,CAAC,MAAM;QACLR,MAAM,CAAC,IAAIY,KAAK,CAACf,YAAY,CAAC,CAAC;MACjC;IACF;IAEAI,cAAc,GAAGf,UAAU,CAAC2B,uBAAuB,CAACR,kBAAkB,CAAC;EACzE,CAAC,CAAC;AACJ","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deephaven/jsapi-utils",
3
- "version": "1.12.1",
3
+ "version": "1.15.2-alpha-fetch-variable-def.0+a515247",
4
4
  "description": "Deephaven JSAPI Utils",
5
5
  "author": "Deephaven Data Labs LLC",
6
6
  "license": "Apache-2.0",
@@ -21,16 +21,16 @@
21
21
  "build:babel": "babel ./src --out-dir ./dist --extensions \".ts,.tsx,.js,.jsx\" --source-maps --root-mode upward"
22
22
  },
23
23
  "dependencies": {
24
- "@deephaven/filters": "^1.1.0",
24
+ "@deephaven/filters": "^1.15.2-alpha-fetch-variable-def.0+a515247",
25
25
  "@deephaven/jsapi-types": "^1.0.0-dev0.40.4",
26
- "@deephaven/log": "^1.8.0",
27
- "@deephaven/utils": "^1.10.0",
26
+ "@deephaven/log": "^1.15.2-alpha-fetch-variable-def.0+a515247",
27
+ "@deephaven/utils": "^1.15.2-alpha-fetch-variable-def.0+a515247",
28
28
  "lodash.clamp": "^4.0.3",
29
29
  "nanoid": "^5.0.7"
30
30
  },
31
31
  "devDependencies": {
32
- "@deephaven/jsapi-shim": "^1.9.0",
33
- "@deephaven/test-utils": "^1.8.0"
32
+ "@deephaven/jsapi-shim": "^1.15.2-alpha-fetch-variable-def.0+a515247",
33
+ "@deephaven/test-utils": "^1.15.2-alpha-fetch-variable-def.0+a515247"
34
34
  },
35
35
  "files": [
36
36
  "dist"
@@ -39,5 +39,5 @@
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "596cbf468ab8d8222872bf620493f12dc75e7d0a"
42
+ "gitHead": "a515247ca8627695fe42d8e64423e898a8d07a88"
43
43
  }