@galaxyproject/galaxy-api-client 25.0.0-dev.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/index.js ADDED
@@ -0,0 +1,87 @@
1
+ import createClient from 'openapi-fetch';
2
+
3
+ // src/client.ts
4
+
5
+ // src/api-types.ts
6
+ function isHDA(entry) {
7
+ return entry !== void 0 && "history_content_type" in entry && entry.history_content_type === "dataset";
8
+ }
9
+ function isHDCA(entry) {
10
+ return entry !== void 0 && "history_content_type" in entry && entry.history_content_type === "dataset_collection";
11
+ }
12
+ function isDCE(item) {
13
+ return item && "element_type" in item;
14
+ }
15
+ function isCollectionElement(element) {
16
+ return element.element_type === "dataset_collection";
17
+ }
18
+ function isDatasetElement(element) {
19
+ return element.element_type === "hda";
20
+ }
21
+ function hasDetails(entry) {
22
+ return "peek" in entry;
23
+ }
24
+ function isInaccessible(entry) {
25
+ return "accessible" in entry && !entry.accessible;
26
+ }
27
+
28
+ // src/client.ts
29
+ function createGalaxyApi(options = {}) {
30
+ const opts = typeof options === "string" ? { baseUrl: options } : options;
31
+ const baseUrl = opts.baseUrl || window.location.origin;
32
+ const normalizedBaseUrl = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
33
+ const headers = {
34
+ ...opts.headers || {}
35
+ };
36
+ if (opts.apiKey) {
37
+ headers["x-api-key"] = opts.apiKey;
38
+ }
39
+ return createClient({
40
+ baseUrl: normalizedBaseUrl,
41
+ headers,
42
+ // Pass any custom fetchOptions directly to createClient
43
+ ...opts.fetchOptions ? { fetchOptions: opts.fetchOptions } : {}
44
+ });
45
+ }
46
+
47
+ // src/utils/error.ts
48
+ function errorMessageAsString(error) {
49
+ if (typeof error === "string") {
50
+ return error;
51
+ }
52
+ if (error instanceof Error) {
53
+ return error.message;
54
+ }
55
+ if (error && typeof error === "object") {
56
+ if (error.status && error.error) {
57
+ return `API Error (${error.status}): ${error.error}`;
58
+ }
59
+ if (error.message) {
60
+ return error.message;
61
+ }
62
+ try {
63
+ return JSON.stringify(error);
64
+ } catch (e) {
65
+ return String(error);
66
+ }
67
+ }
68
+ return "Unknown error";
69
+ }
70
+
71
+ // src/index.ts
72
+ var SimpleError = class extends Error {
73
+ constructor(message) {
74
+ super(message);
75
+ this.name = "GalaxyApiError";
76
+ }
77
+ };
78
+ function GalaxyApi() {
79
+ return createGalaxyApi();
80
+ }
81
+ function formatErrorMessage(error) {
82
+ return errorMessageAsString(error);
83
+ }
84
+
85
+ export { GalaxyApi, SimpleError, createGalaxyApi, formatErrorMessage, hasDetails, isCollectionElement, isDCE, isDatasetElement, isHDA, isHDCA, isInaccessible };
86
+ //# sourceMappingURL=index.js.map
87
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/api-types.ts","../src/client.ts","../src/utils/error.ts","../src/index.ts"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["/**\n * This file re-exports the types we want to use from the Galaxy API.\n * It serves as a compatibility layer to avoid importing directly from the\n * symlinked files, which would require all of Galaxy's dependencies.\n */\n\n// Import types from the symlinked files\nimport { type components, type GalaxyApiPaths } from \"./api/schema\";\n\n// We only need the types, not the code that depends on Galaxy's implementation\nexport type { components, GalaxyApiPaths };\n\n// Re-export specific types\nexport type HistorySummary = components[\"schemas\"][\"HistorySummary\"];\nexport type HistoryDetailed = components[\"schemas\"][\"HistoryDetailed\"];\nexport type HDASummary = components[\"schemas\"][\"HDASummary\"];\nexport type HDADetailed = components[\"schemas\"][\"HDADetailed\"];\nexport type DCESummary = components[\"schemas\"][\"DCESummary\"];\nexport type HDCASummary = components[\"schemas\"][\"HDCASummary\"];\nexport type HDCADetailed = components[\"schemas\"][\"HDCADetailed\"];\nexport type DCObject = components[\"schemas\"][\"DCObject\"];\nexport type HDAObject = components[\"schemas\"][\"HDAObject\"];\nexport type HDAInaccessible = components[\"schemas\"][\"HDAInaccessible\"];\nexport type DatasetTextContentDetails = components[\"schemas\"][\"DatasetTextContentDetails\"];\nexport type DatasetStorageDetails = components[\"schemas\"][\"DatasetStorageDetails\"];\nexport type DatasetCollectionAttributes = components[\"schemas\"][\"DatasetCollectionAttributesResult\"];\nexport type ConcreteObjectStoreModel = components[\"schemas\"][\"ConcreteObjectStoreModel\"];\nexport type MessageException = components[\"schemas\"][\"MessageExceptionModel\"];\nexport type DatasetHash = components[\"schemas\"][\"DatasetHash\"];\nexport type DatasetSource = components[\"schemas\"][\"DatasetSource\"];\nexport type DatasetTransform = components[\"schemas\"][\"DatasetSourceTransform\"];\nexport type StoreExportPayload = components[\"schemas\"][\"StoreExportPayload\"];\nexport type ModelStoreFormat = components[\"schemas\"][\"ModelStoreFormat\"];\nexport type ObjectExportTaskResponse = components[\"schemas\"][\"ObjectExportTaskResponse\"];\nexport type ExportObjectRequestMetadata = components[\"schemas\"][\"ExportObjectRequestMetadata\"];\nexport type ExportObjectResultMetadata = components[\"schemas\"][\"ExportObjectResultMetadata\"];\nexport type AsyncTaskResultSummary = components[\"schemas\"][\"AsyncTaskResultSummary\"];\n\n// Define utility types that may be used in the client\nexport type HistorySortByLiteral = \"create_time\" | \"name\" | \"update_time\" | \"username\" | undefined;\n\nexport interface HistoryContentsStats {\n id: string;\n update_time: string;\n size: number;\n contents_active: components[\"schemas\"][\"HistoryActiveContentCounts\"];\n}\n\nexport interface HistorySummaryExtended extends HistorySummary, HistoryContentsStats {\n user_id: string | null;\n}\n\nexport interface SelectableObjectStore extends ConcreteObjectStoreModel {\n object_store_id: string;\n}\n\nexport type DatasetEntry = HDASummary | HDADetailed | HDAInaccessible;\n\nexport interface DCECollection extends DCESummary {\n element_type: \"dataset_collection\";\n object: DCObject;\n}\n\nexport interface DCEDataset extends DCESummary {\n element_type: \"hda\";\n object: HDAObject;\n}\n\nexport interface SubCollection extends DCObject {\n name: string;\n hdca_id: string;\n}\n\nexport type CollectionEntry = HDCASummary | SubCollection;\nexport type HistoryItemSummary = HDASummary | HDCASummary;\n\n// Utility functions\nexport function isHDA(entry?: HistoryItemSummary): entry is HDASummary {\n return entry !== undefined && \"history_content_type\" in entry && entry.history_content_type === \"dataset\";\n}\n\nexport function isHDCA(entry?: HistoryItemSummary | CollectionEntry): entry is HDCASummary {\n return (\n entry !== undefined && \"history_content_type\" in entry && entry.history_content_type === \"dataset_collection\"\n );\n}\n\nexport function isDCE(item: object): item is DCESummary {\n return item && \"element_type\" in item;\n}\n\nexport function isCollectionElement(element: DCESummary): element is DCECollection {\n return element.element_type === \"dataset_collection\";\n}\n\nexport function isDatasetElement(element: DCESummary): element is DCEDataset {\n return element.element_type === \"hda\";\n}\n\nexport function hasDetails(entry: DatasetEntry): entry is HDADetailed {\n return \"peek\" in entry;\n}\n\nexport function isInaccessible(entry: DatasetEntry): entry is HDAInaccessible {\n return \"accessible\" in entry && !entry.accessible;\n}\n","import createClient from \"openapi-fetch\";\nimport { type GalaxyApiPaths } from \"./api-types\";\n\n/**\n * Options for creating a Galaxy API client\n */\nexport interface GalaxyApiOptions {\n /**\n * The base URL of the Galaxy server (e.g., \"https://usegalaxy.org\")\n * @default window.location.origin\n */\n baseUrl?: string;\n\n /**\n * API key for authentication\n */\n apiKey?: string;\n\n /**\n * Custom headers to include with each request\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch options that will be passed to all requests\n */\n fetchOptions?: RequestInit;\n}\n\n/**\n * Creates a Galaxy API client with the specified options\n * @param options Configuration options for the Galaxy API client\n * @returns The Galaxy API client\n */\nexport function createGalaxyApi(options: GalaxyApiOptions | string = {}) {\n // Handle the case where baseUrl is passed as a string for backward compatibility\n const opts = typeof options === \"string\" ? { baseUrl: options } : options;\n\n // Default to window.location.origin if no baseUrl is provided\n const baseUrl = opts.baseUrl || window.location.origin;\n const normalizedBaseUrl = baseUrl.endsWith(\"/\") ? baseUrl.slice(0, -1) : baseUrl;\n\n // Build headers object\n const headers: Record<string, string> = {\n ...(opts.headers || {}),\n };\n\n // Add API key header if provided\n if (opts.apiKey) {\n headers[\"x-api-key\"] = opts.apiKey;\n }\n\n // Create the client with all options\n return createClient<GalaxyApiPaths>({\n baseUrl: normalizedBaseUrl,\n headers,\n // Pass any custom fetchOptions directly to createClient\n ...(opts.fetchOptions ? { fetchOptions: opts.fetchOptions } : {}),\n });\n}\n\nexport type GalaxyApiClient = ReturnType<typeof createGalaxyApi>;\n","/**\n * Simple error handling utilities for Galaxy Client API\n */\n\n/**\n * Convert various error formats to a readable string message\n */\nexport function errorMessageAsString(error: any): string {\n if (typeof error === \"string\") {\n return error;\n }\n\n if (error instanceof Error) {\n return error.message;\n }\n\n if (error && typeof error === \"object\") {\n // Handle API response errors\n if (error.status && error.error) {\n return `API Error (${error.status}): ${error.error}`;\n }\n\n // Handle response objects with error message\n if (error.message) {\n return error.message;\n }\n\n // Try to stringify the error object\n try {\n return JSON.stringify(error);\n } catch (e) {\n // Fall back to object inspection\n return String(error);\n }\n }\n\n return \"Unknown error\";\n}\n","/**\n * Galaxy Client API\n * A client library for the Galaxy API\n */\n\nimport { createGalaxyApi, type GalaxyApiClient } from \"./client\";\nimport { errorMessageAsString } from \"./utils/error\";\n\n// Re-export all the types from our type compatibility layer\nexport * from \"./api-types\";\n\n// SimpleError class for error handling\nexport class SimpleError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"GalaxyApiError\";\n }\n}\n\n// Re-export the client functions\nexport { createGalaxyApi, type GalaxyApiClient };\n\n// For backward compatibility - creates a client with default settings\nexport function GalaxyApi() {\n return createGalaxyApi();\n}\n\n// Utility function to format error messages\nexport function formatErrorMessage(error: any): string {\n return errorMessageAsString(error);\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@galaxyproject/galaxy-api-client",
3
+ "version": "25.0.0-dev.0",
4
+ "description": "A client library for the Galaxy API",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "src"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsup",
22
+ "dev": "tsup --watch",
23
+ "clean": "rimraf dist",
24
+ "prepublishOnly": "npm run clean && npm run build",
25
+ "test": "vitest run",
26
+ "test:watch": "vitest",
27
+ "test:coverage": "vitest run --coverage",
28
+ "sync-version": "node scripts/sync-version.js"
29
+ },
30
+ "keywords": [
31
+ "galaxy",
32
+ "api",
33
+ "client"
34
+ ],
35
+ "author": "Galaxy Community",
36
+ "license": "MIT",
37
+ "dependencies": {
38
+ "openapi-fetch": "^0.12.0"
39
+ },
40
+ "peerDependencies": {
41
+ "typescript": ">=4.5.0"
42
+ },
43
+ "devDependencies": {
44
+ "jsdom": "^26.1.0",
45
+ "rimraf": "^6.0.1",
46
+ "ts-node": "^10.9.2",
47
+ "tsup": "^8.4.0",
48
+ "typescript": "^5.8.3",
49
+ "vitest": "^3.1.3"
50
+ }
51
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * This file re-exports the types we want to use from the Galaxy API.
3
+ * It serves as a compatibility layer to avoid importing directly from the
4
+ * symlinked files, which would require all of Galaxy's dependencies.
5
+ */
6
+
7
+ // Import types from the symlinked files
8
+ import { type components, type GalaxyApiPaths } from "./api/schema";
9
+
10
+ // We only need the types, not the code that depends on Galaxy's implementation
11
+ export type { components, GalaxyApiPaths };
12
+
13
+ // Re-export specific types
14
+ export type HistorySummary = components["schemas"]["HistorySummary"];
15
+ export type HistoryDetailed = components["schemas"]["HistoryDetailed"];
16
+ export type HDASummary = components["schemas"]["HDASummary"];
17
+ export type HDADetailed = components["schemas"]["HDADetailed"];
18
+ export type DCESummary = components["schemas"]["DCESummary"];
19
+ export type HDCASummary = components["schemas"]["HDCASummary"];
20
+ export type HDCADetailed = components["schemas"]["HDCADetailed"];
21
+ export type DCObject = components["schemas"]["DCObject"];
22
+ export type HDAObject = components["schemas"]["HDAObject"];
23
+ export type HDAInaccessible = components["schemas"]["HDAInaccessible"];
24
+ export type DatasetTextContentDetails = components["schemas"]["DatasetTextContentDetails"];
25
+ export type DatasetStorageDetails = components["schemas"]["DatasetStorageDetails"];
26
+ export type DatasetCollectionAttributes = components["schemas"]["DatasetCollectionAttributesResult"];
27
+ export type ConcreteObjectStoreModel = components["schemas"]["ConcreteObjectStoreModel"];
28
+ export type MessageException = components["schemas"]["MessageExceptionModel"];
29
+ export type DatasetHash = components["schemas"]["DatasetHash"];
30
+ export type DatasetSource = components["schemas"]["DatasetSource"];
31
+ export type DatasetTransform = components["schemas"]["DatasetSourceTransform"];
32
+ export type StoreExportPayload = components["schemas"]["StoreExportPayload"];
33
+ export type ModelStoreFormat = components["schemas"]["ModelStoreFormat"];
34
+ export type ObjectExportTaskResponse = components["schemas"]["ObjectExportTaskResponse"];
35
+ export type ExportObjectRequestMetadata = components["schemas"]["ExportObjectRequestMetadata"];
36
+ export type ExportObjectResultMetadata = components["schemas"]["ExportObjectResultMetadata"];
37
+ export type AsyncTaskResultSummary = components["schemas"]["AsyncTaskResultSummary"];
38
+
39
+ // Define utility types that may be used in the client
40
+ export type HistorySortByLiteral = "create_time" | "name" | "update_time" | "username" | undefined;
41
+
42
+ export interface HistoryContentsStats {
43
+ id: string;
44
+ update_time: string;
45
+ size: number;
46
+ contents_active: components["schemas"]["HistoryActiveContentCounts"];
47
+ }
48
+
49
+ export interface HistorySummaryExtended extends HistorySummary, HistoryContentsStats {
50
+ user_id: string | null;
51
+ }
52
+
53
+ export interface SelectableObjectStore extends ConcreteObjectStoreModel {
54
+ object_store_id: string;
55
+ }
56
+
57
+ export type DatasetEntry = HDASummary | HDADetailed | HDAInaccessible;
58
+
59
+ export interface DCECollection extends DCESummary {
60
+ element_type: "dataset_collection";
61
+ object: DCObject;
62
+ }
63
+
64
+ export interface DCEDataset extends DCESummary {
65
+ element_type: "hda";
66
+ object: HDAObject;
67
+ }
68
+
69
+ export interface SubCollection extends DCObject {
70
+ name: string;
71
+ hdca_id: string;
72
+ }
73
+
74
+ export type CollectionEntry = HDCASummary | SubCollection;
75
+ export type HistoryItemSummary = HDASummary | HDCASummary;
76
+
77
+ // Utility functions
78
+ export function isHDA(entry?: HistoryItemSummary): entry is HDASummary {
79
+ return entry !== undefined && "history_content_type" in entry && entry.history_content_type === "dataset";
80
+ }
81
+
82
+ export function isHDCA(entry?: HistoryItemSummary | CollectionEntry): entry is HDCASummary {
83
+ return (
84
+ entry !== undefined && "history_content_type" in entry && entry.history_content_type === "dataset_collection"
85
+ );
86
+ }
87
+
88
+ export function isDCE(item: object): item is DCESummary {
89
+ return item && "element_type" in item;
90
+ }
91
+
92
+ export function isCollectionElement(element: DCESummary): element is DCECollection {
93
+ return element.element_type === "dataset_collection";
94
+ }
95
+
96
+ export function isDatasetElement(element: DCESummary): element is DCEDataset {
97
+ return element.element_type === "hda";
98
+ }
99
+
100
+ export function hasDetails(entry: DatasetEntry): entry is HDADetailed {
101
+ return "peek" in entry;
102
+ }
103
+
104
+ export function isInaccessible(entry: DatasetEntry): entry is HDAInaccessible {
105
+ return "accessible" in entry && !entry.accessible;
106
+ }
@@ -0,0 +1,68 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { createGalaxyApi } from "./client";
3
+
4
+ // Create a mock API client for testing
5
+ const mockApiClient = {
6
+ GET: vi.fn(),
7
+ POST: vi.fn(),
8
+ PUT: vi.fn(),
9
+ DELETE: vi.fn(),
10
+ PATCH: vi.fn(),
11
+ };
12
+
13
+ // Mock createClient before importing
14
+ vi.mock("openapi-fetch", () => {
15
+ return {
16
+ default: vi.fn().mockImplementation(() => mockApiClient),
17
+ };
18
+ });
19
+
20
+ import createClient from "openapi-fetch";
21
+
22
+ describe("Galaxy API Client", () => {
23
+ beforeEach(() => {
24
+ // Reset mock function calls before each test
25
+ vi.clearAllMocks();
26
+ });
27
+
28
+ it("creates a client with the default base URL", () => {
29
+ // Set up window.location.origin for testing
30
+ const originalLocation = window.location;
31
+ delete (window as any).location;
32
+ window.location = { ...originalLocation, origin: "https://test-galaxy.org" } as any;
33
+
34
+ const api = createGalaxyApi();
35
+
36
+ expect(createClient).toHaveBeenCalledWith({ baseUrl: "https://test-galaxy.org" });
37
+
38
+ // Restore window.location
39
+ window.location = originalLocation;
40
+ });
41
+
42
+ it("creates a client with a custom base URL", () => {
43
+ const customUrl = "https://usegalaxy.org";
44
+ const api = createGalaxyApi(customUrl);
45
+
46
+ expect(createClient).toHaveBeenCalledWith({ baseUrl: customUrl });
47
+ });
48
+
49
+ it("strips trailing slash from base URL", () => {
50
+ const customUrl = "https://usegalaxy.org/";
51
+ const expectedUrl = "https://usegalaxy.org";
52
+ const api = createGalaxyApi(customUrl);
53
+
54
+ expect(createClient).toHaveBeenCalledWith({ baseUrl: expectedUrl });
55
+ });
56
+
57
+ it("returns the configured client", () => {
58
+ const api = createGalaxyApi();
59
+
60
+ // Should have all the HTTP methods
61
+ expect(api).toEqual(mockApiClient);
62
+ expect(api).toHaveProperty("GET");
63
+ expect(api).toHaveProperty("POST");
64
+ expect(api).toHaveProperty("PUT");
65
+ expect(api).toHaveProperty("DELETE");
66
+ expect(api).toHaveProperty("PATCH");
67
+ });
68
+ });
package/src/client.ts ADDED
@@ -0,0 +1,62 @@
1
+ import createClient from "openapi-fetch";
2
+ import { type GalaxyApiPaths } from "./api-types";
3
+
4
+ /**
5
+ * Options for creating a Galaxy API client
6
+ */
7
+ export interface GalaxyApiOptions {
8
+ /**
9
+ * The base URL of the Galaxy server (e.g., "https://usegalaxy.org")
10
+ * @default window.location.origin
11
+ */
12
+ baseUrl?: string;
13
+
14
+ /**
15
+ * API key for authentication
16
+ */
17
+ apiKey?: string;
18
+
19
+ /**
20
+ * Custom headers to include with each request
21
+ */
22
+ headers?: Record<string, string>;
23
+
24
+ /**
25
+ * Custom fetch options that will be passed to all requests
26
+ */
27
+ fetchOptions?: RequestInit;
28
+ }
29
+
30
+ /**
31
+ * Creates a Galaxy API client with the specified options
32
+ * @param options Configuration options for the Galaxy API client
33
+ * @returns The Galaxy API client
34
+ */
35
+ export function createGalaxyApi(options: GalaxyApiOptions | string = {}) {
36
+ // Handle the case where baseUrl is passed as a string for backward compatibility
37
+ const opts = typeof options === "string" ? { baseUrl: options } : options;
38
+
39
+ // Default to window.location.origin if no baseUrl is provided
40
+ const baseUrl = opts.baseUrl || window.location.origin;
41
+ const normalizedBaseUrl = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
42
+
43
+ // Build headers object
44
+ const headers: Record<string, string> = {
45
+ ...(opts.headers || {}),
46
+ };
47
+
48
+ // Add API key header if provided
49
+ if (opts.apiKey) {
50
+ headers["x-api-key"] = opts.apiKey;
51
+ }
52
+
53
+ // Create the client with all options
54
+ return createClient<GalaxyApiPaths>({
55
+ baseUrl: normalizedBaseUrl,
56
+ headers,
57
+ // Pass any custom fetchOptions directly to createClient
58
+ ...(opts.fetchOptions ? { fetchOptions: opts.fetchOptions } : {}),
59
+ });
60
+ }
61
+
62
+ export type GalaxyApiClient = ReturnType<typeof createGalaxyApi>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * This file re-exports the types we want to use from the Galaxy API.
4
+ * It serves as a compatibility layer to avoid importing directly from the
5
+ * symlinked files, which would require all of Galaxy's dependencies.
6
+ */
7
+ exports.__esModule = true;
8
+ exports.isInaccessible =
9
+ exports.hasDetails =
10
+ exports.isDatasetElement =
11
+ exports.isCollectionElement =
12
+ exports.isDCE =
13
+ exports.isHDCA =
14
+ exports.isHDA =
15
+ void 0;
16
+ // Utility functions
17
+ function isHDA(entry) {
18
+ return entry !== undefined && "history_content_type" in entry && entry.history_content_type === "dataset";
19
+ }
20
+ exports.isHDA = isHDA;
21
+ function isHDCA(entry) {
22
+ return (
23
+ entry !== undefined && "history_content_type" in entry && entry.history_content_type === "dataset_collection"
24
+ );
25
+ }
26
+ exports.isHDCA = isHDCA;
27
+ function isDCE(item) {
28
+ return item && "element_type" in item;
29
+ }
30
+ exports.isDCE = isDCE;
31
+ function isCollectionElement(element) {
32
+ return element.element_type === "dataset_collection";
33
+ }
34
+ exports.isCollectionElement = isCollectionElement;
35
+ function isDatasetElement(element) {
36
+ return element.element_type === "hda";
37
+ }
38
+ exports.isDatasetElement = isDatasetElement;
39
+ function hasDetails(entry) {
40
+ return "peek" in entry;
41
+ }
42
+ exports.hasDetails = hasDetails;
43
+ function isInaccessible(entry) {
44
+ return "accessible" in entry && !entry.accessible;
45
+ }
46
+ exports.isInaccessible = isInaccessible;