@deephaven/jsapi-bootstrap 0.60.1-beta.0 → 0.60.1-object-fetcher.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.
- package/dist/DeferredApiBootstrap.d.ts +3 -2
- package/dist/DeferredApiBootstrap.d.ts.map +1 -1
- package/dist/DeferredApiBootstrap.js +2 -2
- package/dist/DeferredApiBootstrap.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/useDeferredApi.d.ts +5 -5
- package/dist/useDeferredApi.d.ts.map +1 -1
- package/dist/useDeferredApi.js +5 -5
- package/dist/useDeferredApi.js.map +1 -1
- package/dist/useObjectFetcher.d.ts +17 -0
- package/dist/useObjectFetcher.d.ts.map +1 -0
- package/dist/useObjectFetcher.js +41 -0
- package/dist/useObjectFetcher.js.map +1 -0
- package/package.json +6 -6
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ObjectMetadata } from './useObjectFetcher';
|
|
2
3
|
type DeferredApiBootstrapProps = React.PropsWithChildren<{
|
|
3
4
|
onError?: (error: unknown) => void;
|
|
4
5
|
/**
|
|
5
6
|
* Options to use when fetching the deferred API.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
metadata: ObjectMetadata;
|
|
8
9
|
}>;
|
|
9
10
|
/**
|
|
10
11
|
* Does not render children until the deferred API is resolved.
|
|
11
12
|
*/
|
|
12
|
-
export declare const DeferredApiBootstrap: React.MemoExoticComponent<({ children, onError,
|
|
13
|
+
export declare const DeferredApiBootstrap: React.MemoExoticComponent<({ children, onError, metadata, }: DeferredApiBootstrapProps) => JSX.Element | null>;
|
|
13
14
|
export default DeferredApiBootstrap;
|
|
14
15
|
//# sourceMappingURL=DeferredApiBootstrap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeferredApiBootstrap.d.ts","sourceRoot":"","sources":["../src/DeferredApiBootstrap.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"DeferredApiBootstrap.d.ts","sourceRoot":"","sources":["../src/DeferredApiBootstrap.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,KAAK,yBAAyB,GAAG,KAAK,CAAC,iBAAiB,CAAC;IACvD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC;;OAEG;IACH,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,oBAAoB,+DAK5B,yBAAyB,KAAG,WAAW,GAAG,IAAI,CAYlD,CAAC;AAIF,eAAe,oBAAoB,CAAC"}
|
|
@@ -9,9 +9,9 @@ export var DeferredApiBootstrap = /*#__PURE__*/React.memo(_ref => {
|
|
|
9
9
|
var {
|
|
10
10
|
children,
|
|
11
11
|
onError,
|
|
12
|
-
|
|
12
|
+
metadata
|
|
13
13
|
} = _ref;
|
|
14
|
-
var [api, apiError] = useDeferredApi(
|
|
14
|
+
var [api, apiError] = useDeferredApi(metadata);
|
|
15
15
|
if (apiError != null) {
|
|
16
16
|
onError === null || onError === void 0 ? void 0 : onError(apiError);
|
|
17
17
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeferredApiBootstrap.js","names":["React","useDeferredApi","ApiContext","jsx","_jsx","DeferredApiBootstrap","memo","_ref","children","onError","
|
|
1
|
+
{"version":3,"file":"DeferredApiBootstrap.js","names":["React","useDeferredApi","ApiContext","jsx","_jsx","DeferredApiBootstrap","memo","_ref","children","onError","metadata","api","apiError","Provider","value","displayName"],"sources":["../src/DeferredApiBootstrap.tsx"],"sourcesContent":["import React from 'react';\nimport useDeferredApi from './useDeferredApi';\nimport { ApiContext } from './ApiBootstrap';\nimport { ObjectMetadata } from './useObjectFetcher';\n\ntype DeferredApiBootstrapProps = React.PropsWithChildren<{\n onError?: (error: unknown) => void;\n /**\n * Options to use when fetching the deferred API.\n */\n metadata: ObjectMetadata;\n}>;\n\n/**\n * Does not render children until the deferred API is resolved.\n */\nexport const DeferredApiBootstrap = React.memo(\n ({\n children,\n onError,\n metadata,\n }: DeferredApiBootstrapProps): JSX.Element | null => {\n const [api, apiError] = useDeferredApi(metadata);\n if (apiError != null) {\n onError?.(apiError);\n return null;\n }\n if (api == null) {\n // Still waiting for the API to load\n return null;\n }\n return <ApiContext.Provider value={api}>{children}</ApiContext.Provider>;\n }\n);\n\nDeferredApiBootstrap.displayName = 'DeferredApiBootstrap';\n\nexport default DeferredApiBootstrap;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAAC,OACnBC,cAAc;AAAA,SACZC,UAAU;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAWnB;AACA;AACA;AACA,OAAO,IAAMC,oBAAoB,gBAAGL,KAAK,CAACM,IAAI,CAC5CC,IAAA,IAIqD;EAAA,IAJpD;IACCC,QAAQ;IACRC,OAAO;IACPC;EACyB,CAAC,GAAAH,IAAA;EAC1B,IAAM,CAACI,GAAG,EAAEC,QAAQ,CAAC,GAAGX,cAAc,CAACS,QAAQ,CAAC;EAChD,IAAIE,QAAQ,IAAI,IAAI,EAAE;IACpBH,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAGG,QAAQ,CAAC;IACnB,OAAO,IAAI;EACb;EACA,IAAID,GAAG,IAAI,IAAI,EAAE;IACf;IACA,OAAO,IAAI;EACb;EACA,oBAAOP,IAAA,CAACF,UAAU,CAACW,QAAQ;IAACC,KAAK,EAAEH,GAAI;IAAAH,QAAA,EAAEA;EAAQ,CAAsB,CAAC;AAC1E,CACF,CAAC;AAEDH,oBAAoB,CAACU,WAAW,GAAG,sBAAsB;AAEzD,eAAeV,oBAAoB"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './ApiBootstrap';\nexport * from './ClientBootstrap';\nexport * from './DeferredApiBootstrap';\nexport * from './useApi';\nexport * from './useClient';\nexport * from './useDeferredApi';\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './ApiBootstrap';\nexport * from './ClientBootstrap';\nexport * from './DeferredApiBootstrap';\nexport * from './useApi';\nexport * from './useClient';\nexport * from './useDeferredApi';\nexport * from './useObjectFetcher';\n"],"mappings":""}
|
package/dist/useDeferredApi.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { dh as DhType } from '@deephaven/jsapi-types';
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
export type DeferredApiFetcher = (options?: DeferredApiOptions) => Promise<DhType>;
|
|
3
|
+
import { ObjectMetadata } from './useObjectFetcher';
|
|
4
|
+
export type DeferredApiFetcher = (metadata?: ObjectMetadata) => Promise<DhType>;
|
|
6
5
|
export declare const DeferredApiContext: import("react").Context<DhType | DeferredApiFetcher | null>;
|
|
7
6
|
/**
|
|
8
|
-
* Retrieve the API for the current context, given the metadata provided.
|
|
7
|
+
* Retrieve the API for the current context, given the object metadata provided.
|
|
9
8
|
* The API may need to be loaded, and will return `null` until it is ready.
|
|
9
|
+
* @param metadata The object metadata to use to fetch the API
|
|
10
10
|
* @returns A tuple with the API instance, and an error if one occurred.
|
|
11
11
|
*/
|
|
12
|
-
export declare function useDeferredApi(
|
|
12
|
+
export declare function useDeferredApi(metadata: ObjectMetadata): [DhType | null, unknown | null];
|
|
13
13
|
export default useDeferredApi;
|
|
14
14
|
//# sourceMappingURL=useDeferredApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeferredApi.d.ts","sourceRoot":"","sources":["../src/useDeferredApi.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"useDeferredApi.d.ts","sourceRoot":"","sources":["../src/useDeferredApi.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,MAAM,kBAAkB,GAAG,CAAC,QAAQ,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAEhF,eAAO,MAAM,kBAAkB,6DAExB,CAAC;AAER;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,cAAc,GACvB,CAAC,MAAM,GAAG,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC,CAkDjC;AAED,eAAe,cAAc,CAAC"}
|
package/dist/useDeferredApi.js
CHANGED
|
@@ -2,15 +2,15 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
2
2
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
3
3
|
import { createContext, useContext, useEffect, useState } from 'react';
|
|
4
4
|
import { ApiContext } from "./ApiBootstrap.js";
|
|
5
|
-
/** Options for retrieving the deferred */
|
|
6
5
|
export var DeferredApiContext = /*#__PURE__*/createContext(null);
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
|
-
* Retrieve the API for the current context, given the metadata provided.
|
|
8
|
+
* Retrieve the API for the current context, given the object metadata provided.
|
|
10
9
|
* The API may need to be loaded, and will return `null` until it is ready.
|
|
10
|
+
* @param metadata The object metadata to use to fetch the API
|
|
11
11
|
* @returns A tuple with the API instance, and an error if one occurred.
|
|
12
12
|
*/
|
|
13
|
-
export function useDeferredApi(
|
|
13
|
+
export function useDeferredApi(metadata) {
|
|
14
14
|
var [api, setApi] = useState(null);
|
|
15
15
|
var [error, setError] = useState(null);
|
|
16
16
|
var deferredApi = useContext(DeferredApiContext);
|
|
@@ -34,7 +34,7 @@ export function useDeferredApi(options) {
|
|
|
34
34
|
_loadApi = _asyncToGenerator(function* () {
|
|
35
35
|
if (typeof deferredApi === 'function') {
|
|
36
36
|
try {
|
|
37
|
-
var newApi = yield deferredApi(
|
|
37
|
+
var newApi = yield deferredApi(metadata);
|
|
38
38
|
if (!isCancelled) {
|
|
39
39
|
setApi(newApi);
|
|
40
40
|
setError(null);
|
|
@@ -55,7 +55,7 @@ export function useDeferredApi(options) {
|
|
|
55
55
|
return () => {
|
|
56
56
|
isCancelled = true;
|
|
57
57
|
};
|
|
58
|
-
}, [contextApi, deferredApi,
|
|
58
|
+
}, [contextApi, deferredApi, metadata]);
|
|
59
59
|
return [api, error];
|
|
60
60
|
}
|
|
61
61
|
export default useDeferredApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeferredApi.js","names":["createContext","useContext","useEffect","useState","ApiContext","DeferredApiContext","useDeferredApi","
|
|
1
|
+
{"version":3,"file":"useDeferredApi.js","names":["createContext","useContext","useEffect","useState","ApiContext","DeferredApiContext","useDeferredApi","metadata","api","setApi","error","setError","deferredApi","contextApi","Error","isCancelled","loadApi","_loadApi","apply","arguments","_asyncToGenerator","newApi","e"],"sources":["../src/useDeferredApi.ts"],"sourcesContent":["import { createContext, useContext, useEffect, useState } from 'react';\nimport type { dh as DhType } from '@deephaven/jsapi-types';\nimport { ApiContext } from './ApiBootstrap';\nimport { ObjectMetadata } from './useObjectFetcher';\n\nexport type DeferredApiFetcher = (metadata?: ObjectMetadata) => Promise<DhType>;\n\nexport const DeferredApiContext = createContext<\n DhType | DeferredApiFetcher | null\n>(null);\n\n/**\n * Retrieve the API for the current context, given the object metadata provided.\n * The API may need to be loaded, and will return `null` until it is ready.\n * @param metadata The object metadata to use to fetch the API\n * @returns A tuple with the API instance, and an error if one occurred.\n */\nexport function useDeferredApi(\n metadata: ObjectMetadata\n): [DhType | null, unknown | null] {\n const [api, setApi] = useState<DhType | null>(null);\n const [error, setError] = useState<unknown | null>(null);\n const deferredApi = useContext(DeferredApiContext);\n const contextApi = useContext(ApiContext);\n\n useEffect(() => {\n if (deferredApi == null) {\n if (contextApi != null) {\n setApi(contextApi);\n setError(null);\n return;\n }\n setApi(null);\n setError(\n new Error(\n 'No API available in useDeferredApi. Was code wrapped in ApiBootstrap or DeferredApiContext.Provider?'\n )\n );\n return;\n }\n let isCancelled = false;\n\n async function loadApi() {\n if (typeof deferredApi === 'function') {\n try {\n const newApi = await deferredApi(metadata);\n if (!isCancelled) {\n setApi(newApi);\n setError(null);\n }\n } catch (e) {\n if (!isCancelled) {\n setApi(null);\n setError(e);\n }\n }\n } else {\n setApi(deferredApi);\n }\n }\n\n loadApi();\n\n return () => {\n isCancelled = true;\n };\n }, [contextApi, deferredApi, metadata]);\n\n return [api, error];\n}\n\nexport default useDeferredApi;\n"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAAC,SAE9DC,UAAU;AAKnB,OAAO,IAAMC,kBAAkB,gBAAGL,aAAa,CAE7C,IAAI,CAAC;;AAEP;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,cAAcA,CAC5BC,QAAwB,EACS;EACjC,IAAM,CAACC,GAAG,EAAEC,MAAM,CAAC,GAAGN,QAAQ,CAAgB,IAAI,CAAC;EACnD,IAAM,CAACO,KAAK,EAAEC,QAAQ,CAAC,GAAGR,QAAQ,CAAiB,IAAI,CAAC;EACxD,IAAMS,WAAW,GAAGX,UAAU,CAACI,kBAAkB,CAAC;EAClD,IAAMQ,UAAU,GAAGZ,UAAU,CAACG,UAAU,CAAC;EAEzCF,SAAS,CAAC,MAAM;IACd,IAAIU,WAAW,IAAI,IAAI,EAAE;MACvB,IAAIC,UAAU,IAAI,IAAI,EAAE;QACtBJ,MAAM,CAACI,UAAU,CAAC;QAClBF,QAAQ,CAAC,IAAI,CAAC;QACd;MACF;MACAF,MAAM,CAAC,IAAI,CAAC;MACZE,QAAQ,CACN,IAAIG,KAAK,CACP,sGACF,CACF,CAAC;MACD;IACF;IACA,IAAIC,WAAW,GAAG,KAAK;IAAC,SAETC,OAAOA,CAAA;MAAA,OAAAC,QAAA,CAAAC,KAAA,OAAAC,SAAA;IAAA;IAAA,SAAAF,SAAA;MAAAA,QAAA,GAAAG,iBAAA,CAAtB,aAAyB;QACvB,IAAI,OAAOR,WAAW,KAAK,UAAU,EAAE;UACrC,IAAI;YACF,IAAMS,MAAM,SAAST,WAAW,CAACL,QAAQ,CAAC;YAC1C,IAAI,CAACQ,WAAW,EAAE;cAChBN,MAAM,CAACY,MAAM,CAAC;cACdV,QAAQ,CAAC,IAAI,CAAC;YAChB;UACF,CAAC,CAAC,OAAOW,CAAC,EAAE;YACV,IAAI,CAACP,WAAW,EAAE;cAChBN,MAAM,CAAC,IAAI,CAAC;cACZE,QAAQ,CAACW,CAAC,CAAC;YACb;UACF;QACF,CAAC,MAAM;UACLb,MAAM,CAACG,WAAW,CAAC;QACrB;MACF,CAAC;MAAA,OAAAK,QAAA,CAAAC,KAAA,OAAAC,SAAA;IAAA;IAEDH,OAAO,CAAC,CAAC;IAET,OAAO,MAAM;MACXD,WAAW,GAAG,IAAI;IACpB,CAAC;EACH,CAAC,EAAE,CAACF,UAAU,EAAED,WAAW,EAAEL,QAAQ,CAAC,CAAC;EAEvC,OAAO,CAACC,GAAG,EAAEE,KAAK,CAAC;AACrB;AAEA,eAAeJ,cAAc"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { VariableDefinition } from '@deephaven/jsapi-types';
|
|
3
|
+
/**
|
|
4
|
+
* Metadata for an object. Used when needing to fetch an object.
|
|
5
|
+
*/
|
|
6
|
+
export type ObjectMetadata = Record<string, unknown> & VariableDefinition;
|
|
7
|
+
export type ObjectFetcher<T = unknown> = (metadata: ObjectMetadata) => Promise<T>;
|
|
8
|
+
export declare const ObjectFetcherContext: import("react").Context<ObjectFetcher<unknown> | null>;
|
|
9
|
+
/**
|
|
10
|
+
* Get the metadata for an object definition that is serializable.
|
|
11
|
+
* @param definition Object definition to get the metadata for
|
|
12
|
+
* @returns Metadata object that is serializable
|
|
13
|
+
*/
|
|
14
|
+
export declare function getObjectMetadata(definition: VariableDefinition): ObjectMetadata;
|
|
15
|
+
export declare function getVariableDefinition(metadata: ObjectMetadata): VariableDefinition;
|
|
16
|
+
export declare function useObjectFetcher(): ObjectFetcher;
|
|
17
|
+
//# sourceMappingURL=useObjectFetcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useObjectFetcher.d.ts","sourceRoot":"","sources":["../src/useObjectFetcher.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAI5D;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,kBAAkB,CAAC;AAE1E,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI,CACvC,QAAQ,EAAE,cAAc,KACrB,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhB,eAAO,MAAM,oBAAoB,wDAA4C,CAAC;AAE9E;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,kBAAkB,GAC7B,cAAc,CAQhB;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,cAAc,GACvB,kBAAkB,CAYpB;AAED,wBAAgB,gBAAgB,IAAI,aAAa,CAKhD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useContextOrThrow } from '@deephaven/react-hooks';
|
|
2
|
+
import { createContext } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Metadata for an object. Used when needing to fetch an object.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export var ObjectFetcherContext = /*#__PURE__*/createContext(null);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get the metadata for an object definition that is serializable.
|
|
12
|
+
* @param definition Object definition to get the metadata for
|
|
13
|
+
* @returns Metadata object that is serializable
|
|
14
|
+
*/
|
|
15
|
+
export function getObjectMetadata(definition) {
|
|
16
|
+
// Can't use a spread operator because the VariableDefinition JS API object uses property accessors
|
|
17
|
+
return {
|
|
18
|
+
id: definition.id,
|
|
19
|
+
name: definition.name,
|
|
20
|
+
type: definition.type,
|
|
21
|
+
title: definition.title
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function getVariableDefinition(metadata) {
|
|
25
|
+
var _metadata$title;
|
|
26
|
+
if (metadata.id != null) {
|
|
27
|
+
return {
|
|
28
|
+
type: metadata.type,
|
|
29
|
+
id: metadata.id
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
type: metadata.type,
|
|
34
|
+
name: metadata.name,
|
|
35
|
+
title: (_metadata$title = metadata.title) !== null && _metadata$title !== void 0 ? _metadata$title : metadata.name
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function useObjectFetcher() {
|
|
39
|
+
return useContextOrThrow(ObjectFetcherContext, 'No ObjectFetcher available in useObjectFetcher. Was code wrapped in ObjectFetcherContext.Provider?');
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=useObjectFetcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useObjectFetcher.js","names":["useContextOrThrow","createContext","ObjectFetcherContext","getObjectMetadata","definition","id","name","type","title","getVariableDefinition","metadata","_metadata$title","useObjectFetcher"],"sources":["../src/useObjectFetcher.ts"],"sourcesContent":["import { VariableDefinition } from '@deephaven/jsapi-types';\nimport { useContextOrThrow } from '@deephaven/react-hooks';\nimport { createContext } from 'react';\n\n/**\n * Metadata for an object. Used when needing to fetch an object.\n */\nexport type ObjectMetadata = Record<string, unknown> & VariableDefinition;\n\nexport type ObjectFetcher<T = unknown> = (\n metadata: ObjectMetadata\n) => Promise<T>;\n\nexport const ObjectFetcherContext = createContext<ObjectFetcher | null>(null);\n\n/**\n * Get the metadata for an object definition that is serializable.\n * @param definition Object definition to get the metadata for\n * @returns Metadata object that is serializable\n */\nexport function getObjectMetadata(\n definition: VariableDefinition\n): ObjectMetadata {\n // Can't use a spread operator because the VariableDefinition JS API object uses property accessors\n return {\n id: definition.id,\n name: definition.name,\n type: definition.type,\n title: definition.title,\n };\n}\n\nexport function getVariableDefinition(\n metadata: ObjectMetadata\n): VariableDefinition {\n if (metadata.id != null) {\n return {\n type: metadata.type,\n id: metadata.id,\n };\n }\n return {\n type: metadata.type,\n name: metadata.name,\n title: metadata.title ?? metadata.name,\n };\n}\n\nexport function useObjectFetcher(): ObjectFetcher {\n return useContextOrThrow(\n ObjectFetcherContext,\n 'No ObjectFetcher available in useObjectFetcher. Was code wrapped in ObjectFetcherContext.Provider?'\n );\n}\n"],"mappings":"AACA,SAASA,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,aAAa,QAAQ,OAAO;;AAErC;AACA;AACA;;AAOA,OAAO,IAAMC,oBAAoB,gBAAGD,aAAa,CAAuB,IAAI,CAAC;;AAE7E;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,iBAAiBA,CAC/BC,UAA8B,EACd;EAChB;EACA,OAAO;IACLC,EAAE,EAAED,UAAU,CAACC,EAAE;IACjBC,IAAI,EAAEF,UAAU,CAACE,IAAI;IACrBC,IAAI,EAAEH,UAAU,CAACG,IAAI;IACrBC,KAAK,EAAEJ,UAAU,CAACI;EACpB,CAAC;AACH;AAEA,OAAO,SAASC,qBAAqBA,CACnCC,QAAwB,EACJ;EAAA,IAAAC,eAAA;EACpB,IAAID,QAAQ,CAACL,EAAE,IAAI,IAAI,EAAE;IACvB,OAAO;MACLE,IAAI,EAAEG,QAAQ,CAACH,IAAI;MACnBF,EAAE,EAAEK,QAAQ,CAACL;IACf,CAAC;EACH;EACA,OAAO;IACLE,IAAI,EAAEG,QAAQ,CAACH,IAAI;IACnBD,IAAI,EAAEI,QAAQ,CAACJ,IAAI;IACnBE,KAAK,GAAAG,eAAA,GAAED,QAAQ,CAACF,KAAK,cAAAG,eAAA,cAAAA,eAAA,GAAID,QAAQ,CAACJ;EACpC,CAAC;AACH;AAEA,OAAO,SAASM,gBAAgBA,CAAA,EAAkB;EAChD,OAAOZ,iBAAiB,CACtBE,oBAAoB,EACpB,oGACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deephaven/jsapi-bootstrap",
|
|
3
|
-
"version": "0.60.1-
|
|
3
|
+
"version": "0.60.1-object-fetcher.0+7fe24cdd",
|
|
4
4
|
"description": "Deephaven JSAPI Bootstrap",
|
|
5
5
|
"author": "Deephaven Data Labs LLC",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"build:sass": "sass --embed-sources --load-path=../../node_modules ./src:./dist"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@deephaven/components": "^0.60.1-
|
|
26
|
-
"@deephaven/jsapi-types": "^0.60.1-
|
|
27
|
-
"@deephaven/log": "^0.60.1-
|
|
28
|
-
"@deephaven/react-hooks": "^0.60.1-
|
|
25
|
+
"@deephaven/components": "^0.60.1-object-fetcher.0+7fe24cdd",
|
|
26
|
+
"@deephaven/jsapi-types": "^0.60.1-object-fetcher.0+7fe24cdd",
|
|
27
|
+
"@deephaven/log": "^0.60.1-object-fetcher.0+7fe24cdd",
|
|
28
|
+
"@deephaven/react-hooks": "^0.60.1-object-fetcher.0+7fe24cdd"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"react": "^17.x"
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "7fe24cddd638b5b922b609693756ecbf5a989094"
|
|
44
44
|
}
|