@jbrowse/plugin-rdf 3.7.0 → 4.0.1

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.
@@ -1,11 +1,11 @@
1
1
  import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
2
- import type MyConfigSchema from './configSchema';
2
+ import type MyConfigSchema from './configSchema.ts';
3
3
  import type PluginManager from '@jbrowse/core/PluginManager';
4
4
  import type { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter';
5
5
  import type { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache';
6
6
  import type { Feature } from '@jbrowse/core/util/simpleFeature';
7
7
  import type { NoAssemblyRegion } from '@jbrowse/core/util/types';
8
- import type { Instance } from 'mobx-state-tree';
8
+ import type { Instance } from '@jbrowse/mobx-state-tree';
9
9
  export default class SPARQLAdapter extends BaseFeatureDataAdapter {
10
10
  private endpoint;
11
11
  private queryTemplate;
@@ -4,6 +4,12 @@ import { ObservableCreate } from '@jbrowse/core/util/rxjs';
4
4
  import SimpleFeature from '@jbrowse/core/util/simpleFeature';
5
5
  import format from 'string-template';
6
6
  export default class SPARQLAdapter extends BaseFeatureDataAdapter {
7
+ endpoint;
8
+ queryTemplate;
9
+ refNamesQueryTemplate;
10
+ additionalQueryParams;
11
+ configRefNames;
12
+ refNames;
7
13
  constructor(config, getSubAdapter, pluginManager) {
8
14
  super(config, getSubAdapter, pluginManager);
9
15
  this.endpoint = readConfObject(config, 'endpoint').uri;
@@ -137,7 +143,9 @@ export default class SPARQLAdapter extends BaseFeatureDataAdapter {
137
143
  break;
138
144
  }
139
145
  if (subfeature.subfeatures) {
140
- subfeatures.push(...subfeature.subfeatures);
146
+ for (const sf of subfeature.subfeatures) {
147
+ subfeatures.push(sf);
148
+ }
141
149
  }
142
150
  }
143
151
  if (!found) {
@@ -1,4 +1,4 @@
1
- declare const _default: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
1
+ declare const _default: import("node_modules/@jbrowse/core/src/configuration/configurationSchema").ConfigurationSchemaType<{
2
2
  endpoint: {
3
3
  type: string;
4
4
  defaultValue: {
@@ -27,5 +27,5 @@ declare const _default: import("@jbrowse/core/configuration/configurationSchema"
27
27
  defaultValue: never[];
28
28
  description: string;
29
29
  };
30
- }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, undefined>>;
30
+ }, import("node_modules/@jbrowse/core/src/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, undefined>>;
31
31
  export default _default;
@@ -1,5 +1,5 @@
1
1
  import { AdapterType } from '@jbrowse/core/pluggableElementTypes';
2
- import configSchema from './configSchema';
2
+ import configSchema from "./configSchema.js";
3
3
  export default function SPARQLAdapterF(pluginManager) {
4
4
  pluginManager.addAdapterType(() => new AdapterType({
5
5
  name: 'SPARQLAdapter',
@@ -8,6 +8,6 @@ export default function SPARQLAdapterF(pluginManager) {
8
8
  adapterMetadata: {
9
9
  category: 'Uncommon',
10
10
  },
11
- getAdapterClass: () => import('./SPARQLAdapter').then(r => r.default),
11
+ getAdapterClass: () => import("./SPARQLAdapter.js").then(r => r.default),
12
12
  }));
13
13
  }
package/esm/index.js CHANGED
@@ -1,11 +1,8 @@
1
1
  import Plugin from '@jbrowse/core/Plugin';
2
2
  import { getFileName } from '@jbrowse/core/util/tracks';
3
- import SPARQLAdapterF from './SPARQLAdapter';
3
+ import SPARQLAdapterF from "./SPARQLAdapter/index.js";
4
4
  export default class RdfPlugin extends Plugin {
5
- constructor() {
6
- super(...arguments);
7
- this.name = 'RdfPlugin';
8
- }
5
+ name = 'RdfPlugin';
9
6
  install(pluginManager) {
10
7
  SPARQLAdapterF(pluginManager);
11
8
  pluginManager.addToExtensionPoint('Core-guessAdapterForLocation', (adapterGuesser) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbrowse/plugin-rdf",
3
- "version": "3.7.0",
3
+ "version": "4.0.1",
4
4
  "description": "JBrowse 2 RDF resources",
5
5
  "keywords": [
6
6
  "jbrowse",
@@ -15,39 +15,33 @@
15
15
  "directory": "plugins/rdf"
16
16
  },
17
17
  "author": "JBrowse Team",
18
- "distMain": "dist/index.js",
19
- "srcMain": "src/index.ts",
20
- "main": "dist/index.js",
18
+ "main": "esm/index.js",
21
19
  "files": [
22
- "dist",
23
20
  "esm"
24
21
  ],
25
- "scripts": {
26
- "build": "npm-run-all build:*",
27
- "test": "cd ../..; jest --passWithNoTests plugins/rdf",
28
- "prepublishOnly": "yarn test",
29
- "prepack": "yarn build && yarn useDist",
30
- "postpack": "yarn useSrc",
31
- "useDist": "node ../../scripts/useDist.js",
32
- "useSrc": "node ../../scripts/useSrc.js",
33
- "prebuild": "npm run clean",
34
- "build:esm": "tsc --build tsconfig.build.esm.json",
35
- "build:commonjs": "tsc --build tsconfig.build.commonjs.json",
36
- "clean": "rimraf dist esm *.tsbuildinfo"
37
- },
38
22
  "dependencies": {
39
- "@jbrowse/core": "^3.7.0",
40
- "mobx": "^6.0.0",
41
- "mobx-react": "^9.0.0",
42
- "mobx-state-tree": "^5.0.0",
43
- "rxjs": "^7.0.0",
44
- "string-template": "^1.0.0"
23
+ "@jbrowse/mobx-state-tree": "^5.5.0",
24
+ "mobx": "^6.15.0",
25
+ "rxjs": "^7.8.2",
26
+ "string-template": "^1.0.0",
27
+ "@jbrowse/core": "^4.0.1"
45
28
  },
46
- "distModule": "esm/index.js",
47
- "srcModule": "src/index.ts",
48
- "module": "esm/index.js",
49
29
  "publishConfig": {
50
30
  "access": "public"
51
31
  },
52
- "gitHead": "85bdd0d58286b7adbfd408146b15847676317635"
53
- }
32
+ "sideEffects": false,
33
+ "scripts": {
34
+ "build": "pnpm run /^build:/",
35
+ "test": "cd ../..; jest --passWithNoTests plugins/rdf",
36
+ "prebuild": "pnpm clean",
37
+ "build:esm": "tsc -p tsconfig.build.esm.json",
38
+ "clean": "rimraf esm *.tsbuildinfo"
39
+ },
40
+ "types": "esm/index.d.ts",
41
+ "exports": {
42
+ ".": {
43
+ "types": "./esm/index.d.ts",
44
+ "import": "./esm/index.js"
45
+ }
46
+ }
47
+ }
@@ -1,23 +0,0 @@
1
- import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter';
2
- import type MyConfigSchema from './configSchema';
3
- import type PluginManager from '@jbrowse/core/PluginManager';
4
- import type { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter';
5
- import type { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache';
6
- import type { Feature } from '@jbrowse/core/util/simpleFeature';
7
- import type { NoAssemblyRegion } from '@jbrowse/core/util/types';
8
- import type { Instance } from 'mobx-state-tree';
9
- export default class SPARQLAdapter extends BaseFeatureDataAdapter {
10
- private endpoint;
11
- private queryTemplate;
12
- private refNamesQueryTemplate;
13
- private additionalQueryParams;
14
- private configRefNames;
15
- private refNames;
16
- constructor(config: Instance<typeof MyConfigSchema>, getSubAdapter?: getSubAdapterType, pluginManager?: PluginManager);
17
- getRefNames(opts?: BaseOptions): Promise<string[]>;
18
- getFeatures(query: NoAssemblyRegion, opts?: BaseOptions): import("rxjs").Observable<Feature>;
19
- private querySparql;
20
- private resultsToRefNames;
21
- private resultsToFeatures;
22
- hasDataForRefName(refName: string, opts?: BaseOptions): Promise<boolean>;
23
- }
@@ -1,168 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const configuration_1 = require("@jbrowse/core/configuration");
7
- const BaseAdapter_1 = require("@jbrowse/core/data_adapters/BaseAdapter");
8
- const rxjs_1 = require("@jbrowse/core/util/rxjs");
9
- const simpleFeature_1 = __importDefault(require("@jbrowse/core/util/simpleFeature"));
10
- const string_template_1 = __importDefault(require("string-template"));
11
- class SPARQLAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
12
- constructor(config, getSubAdapter, pluginManager) {
13
- super(config, getSubAdapter, pluginManager);
14
- this.endpoint = (0, configuration_1.readConfObject)(config, 'endpoint').uri;
15
- this.queryTemplate = (0, configuration_1.readConfObject)(config, 'queryTemplate');
16
- this.additionalQueryParams = (0, configuration_1.readConfObject)(config, 'additionalQueryParams');
17
- this.refNamesQueryTemplate = (0, configuration_1.readConfObject)(config, 'refNamesQueryTemplate');
18
- this.configRefNames = (0, configuration_1.readConfObject)(config, 'refNames');
19
- }
20
- async getRefNames(opts) {
21
- if (this.refNames) {
22
- return this.refNames;
23
- }
24
- if (this.refNamesQueryTemplate) {
25
- const queryTemplate = encodeURIComponent(this.refNamesQueryTemplate);
26
- const results = await this.querySparql(queryTemplate, opts);
27
- this.refNames = this.resultsToRefNames(results);
28
- }
29
- else {
30
- this.refNames = this.configRefNames;
31
- }
32
- return this.refNames;
33
- }
34
- getFeatures(query, opts = {}) {
35
- return (0, rxjs_1.ObservableCreate)(async (observer) => {
36
- const filledTemplate = encodeURIComponent((0, string_template_1.default)(this.queryTemplate, query));
37
- const { refName } = query;
38
- const results = await this.querySparql(filledTemplate, opts);
39
- const features = this.resultsToFeatures(results, refName);
40
- for (const feature of features) {
41
- observer.next(feature);
42
- }
43
- observer.complete();
44
- }, opts.stopToken);
45
- }
46
- async querySparql(query, _opts) {
47
- let additionalQueryParams = '';
48
- if (this.additionalQueryParams.length) {
49
- additionalQueryParams = `&${this.additionalQueryParams.join('&')}`;
50
- }
51
- const url = `${this.endpoint}?query=${query}${additionalQueryParams}`;
52
- const response = await fetch(url, {
53
- headers: {
54
- accept: 'application/json,application/sparql-results+json',
55
- },
56
- });
57
- return response.json();
58
- }
59
- resultsToRefNames(response) {
60
- const rows = response.results.bindings || [];
61
- const fields = response.head.vars;
62
- if (!fields.includes('refName')) {
63
- throw new Error('"refName" not found in refNamesQueryTemplate response');
64
- }
65
- return rows.map(row => row.refName.value);
66
- }
67
- resultsToFeatures(results, refName) {
68
- const rows = results.results.bindings || [];
69
- const fields = results.head.vars;
70
- const requiredFields = ['start', 'end', 'uniqueId'];
71
- for (const requiredField of requiredFields) {
72
- if (!fields.includes(requiredField)) {
73
- console.error(`Required field ${requiredField} missing from feature data`);
74
- }
75
- }
76
- const seenFeatures = {};
77
- for (const row of rows) {
78
- const rawData = [{}];
79
- for (let field of fields) {
80
- if (field in row) {
81
- const { value } = row[field];
82
- let idx = 0;
83
- while (field.startsWith('sub_')) {
84
- field = field.slice(4);
85
- idx += 1;
86
- }
87
- while (idx > rawData.length - 1) {
88
- rawData.push({});
89
- }
90
- rawData[idx][field] = value;
91
- }
92
- }
93
- for (const [idx, rd] of rawData.entries()) {
94
- const { uniqueId, start, end, strand } = rd;
95
- if (idx < rawData.length - 1) {
96
- rawData[idx + 1].parentUniqueId = uniqueId;
97
- }
98
- seenFeatures[uniqueId] = {
99
- data: {
100
- ...rd,
101
- uniqueId: uniqueId,
102
- refName,
103
- start: Number.parseInt(start, 10),
104
- end: Number.parseInt(end, 10),
105
- strand: Number.parseInt(strand, 10) || 0,
106
- },
107
- };
108
- }
109
- }
110
- for (const [uniqueId, f] of Object.entries(seenFeatures)) {
111
- const pid = f.data.parentUniqueId;
112
- f.data.parentUniqueId = undefined;
113
- if (pid) {
114
- const p = seenFeatures[pid];
115
- if (p) {
116
- if (!p.data.subfeatures) {
117
- p.data.subfeatures = [];
118
- }
119
- p.data.subfeatures.push({
120
- ...f.data,
121
- uniqueId,
122
- });
123
- delete seenFeatures[uniqueId];
124
- }
125
- else {
126
- const subfeatures = Object.values(seenFeatures)
127
- .map(sf => sf.data.subfeatures)
128
- .filter(sf => !!sf)
129
- .flat();
130
- let found = false;
131
- for (const subfeature of subfeatures) {
132
- if (subfeature.uniqueId === pid) {
133
- if (!subfeature.subfeatures) {
134
- subfeature.subfeatures = [];
135
- }
136
- subfeature.subfeatures.push({
137
- ...f.data,
138
- uniqueId,
139
- });
140
- delete seenFeatures[uniqueId];
141
- found = true;
142
- break;
143
- }
144
- if (subfeature.subfeatures) {
145
- subfeatures.push(...subfeature.subfeatures);
146
- }
147
- }
148
- if (!found) {
149
- console.error(`Could not find parentID ${pid}`);
150
- }
151
- }
152
- }
153
- }
154
- return Object.keys(seenFeatures).map(seenFeature => new simpleFeature_1.default({
155
- ...seenFeatures[seenFeature].data,
156
- uniqueId: seenFeature,
157
- subfeatures: seenFeatures[seenFeature].data.subfeatures,
158
- }));
159
- }
160
- async hasDataForRefName(refName, opts = {}) {
161
- const refNames = await this.getRefNames(opts);
162
- if (refNames.length && !refNames.includes(refName)) {
163
- return false;
164
- }
165
- return true;
166
- }
167
- }
168
- exports.default = SPARQLAdapter;
@@ -1,31 +0,0 @@
1
- declare const _default: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
2
- endpoint: {
3
- type: string;
4
- defaultValue: {
5
- uri: string;
6
- locationType: string;
7
- };
8
- description: string;
9
- };
10
- queryTemplate: {
11
- type: string;
12
- defaultValue: string;
13
- description: string;
14
- };
15
- refNamesQueryTemplate: {
16
- type: string;
17
- defaultValue: string;
18
- description: string;
19
- };
20
- refNames: {
21
- type: string;
22
- defaultValue: never[];
23
- description: string;
24
- };
25
- additionalQueryParams: {
26
- type: string;
27
- defaultValue: never[];
28
- description: string;
29
- };
30
- }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, undefined>>;
31
- export default _default;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const configuration_1 = require("@jbrowse/core/configuration");
4
- exports.default = (0, configuration_1.ConfigurationSchema)('SPARQLAdapter', {
5
- endpoint: {
6
- type: 'fileLocation',
7
- defaultValue: {
8
- uri: 'https://somesite.com/sparql',
9
- locationType: 'UriLocation',
10
- },
11
- description: 'URL of the SPARQL endpoint',
12
- },
13
- queryTemplate: {
14
- type: 'text',
15
- defaultValue: '',
16
- description: 'SPARQL query where {start} {end} and {refName} will get replaced for each call',
17
- },
18
- refNamesQueryTemplate: {
19
- type: 'text',
20
- defaultValue: '',
21
- description: 'SPARQL query that returns the possible refNames in a ?refName column',
22
- },
23
- refNames: {
24
- type: 'stringArray',
25
- defaultValue: [],
26
- description: 'Possible refNames used by the SPARQL endpoint (ignored if "refNamesQueryTemplate" is provided)',
27
- },
28
- additionalQueryParams: {
29
- type: 'stringArray',
30
- defaultValue: [],
31
- description: 'Additional parameters to add to the query, e.g. "format=JSON"',
32
- },
33
- }, { explicitlyTyped: true });
@@ -1,2 +0,0 @@
1
- import type PluginManager from '@jbrowse/core/PluginManager';
2
- export default function SPARQLAdapterF(pluginManager: PluginManager): void;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.default = SPARQLAdapterF;
40
- const pluggableElementTypes_1 = require("@jbrowse/core/pluggableElementTypes");
41
- const configSchema_1 = __importDefault(require("./configSchema"));
42
- function SPARQLAdapterF(pluginManager) {
43
- pluginManager.addAdapterType(() => new pluggableElementTypes_1.AdapterType({
44
- name: 'SPARQLAdapter',
45
- displayName: 'SPARQL adapter',
46
- configSchema: configSchema_1.default,
47
- adapterMetadata: {
48
- category: 'Uncommon',
49
- },
50
- getAdapterClass: () => Promise.resolve().then(() => __importStar(require('./SPARQLAdapter'))).then(r => r.default),
51
- }));
52
- }
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import Plugin from '@jbrowse/core/Plugin';
2
- import type PluginManager from '@jbrowse/core/PluginManager';
3
- export default class RdfPlugin extends Plugin {
4
- name: string;
5
- install(pluginManager: PluginManager): void;
6
- }
package/dist/index.js DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const Plugin_1 = __importDefault(require("@jbrowse/core/Plugin"));
7
- const tracks_1 = require("@jbrowse/core/util/tracks");
8
- const SPARQLAdapter_1 = __importDefault(require("./SPARQLAdapter"));
9
- class RdfPlugin extends Plugin_1.default {
10
- constructor() {
11
- super(...arguments);
12
- this.name = 'RdfPlugin';
13
- }
14
- install(pluginManager) {
15
- (0, SPARQLAdapter_1.default)(pluginManager);
16
- pluginManager.addToExtensionPoint('Core-guessAdapterForLocation', (adapterGuesser) => {
17
- return (file, index, adapterHint) => {
18
- const regexGuess = /\/sparql$/i;
19
- const adapterName = 'SPARQLAdapter';
20
- const fileName = (0, tracks_1.getFileName)(file);
21
- if (regexGuess.test(fileName) || adapterHint === adapterName) {
22
- return {
23
- type: adapterName,
24
- endpoint: file,
25
- };
26
- }
27
- return adapterGuesser(file, index, adapterHint);
28
- };
29
- });
30
- }
31
- }
32
- exports.default = RdfPlugin;