Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create packages/product-core containing shared code between the various products #3661

Merged
merged 44 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7de3662
wip
rbuels Apr 24, 2023
a0c2eb3
wip
rbuels Apr 24, 2023
30349d9
wip
rbuels Apr 24, 2023
a63fe4f
wip
rbuels Apr 24, 2023
075f788
wip
rbuels Apr 24, 2023
f3f977b
wip
rbuels Apr 25, 2023
7a23b3d
wip
rbuels Apr 25, 2023
e77ba9b
wip
rbuels Apr 25, 2023
efb8ac7
fix tests
rbuels Apr 25, 2023
7b59ce9
factor out drawer widgets
rbuels Apr 25, 2023
e9d1e42
wip
rbuels Apr 26, 2023
63e6b52
wip
rbuels Apr 27, 2023
cb9a206
wip
rbuels Apr 27, 2023
3eeb219
wip
rbuels Apr 28, 2023
3361fe8
wip
rbuels Apr 28, 2023
8a52815
wip
rbuels Apr 28, 2023
063fd5d
wip
rbuels Apr 28, 2023
dcd135c
queueOfDialogs actually does need to be observable
rbuels Apr 29, 2023
c2952c9
wip
rbuels Apr 29, 2023
4b9e5ba
pass more tests
rbuels Apr 29, 2023
9695755
update snaps, tests now passing
rbuels Apr 29, 2023
373bbfa
wip
rbuels May 1, 2023
249c49c
wip
rbuels May 1, 2023
6fe456e
break up jb desktop root model more
rbuels May 1, 2023
bfa7beb
wip
rbuels May 4, 2023
a790584
remove session management from desktop session model
rbuels May 4, 2023
433e700
fixup
rbuels May 4, 2023
746f06d
wip
rbuels May 5, 2023
4fb58dc
wip
rbuels May 5, 2023
e2bc30f
rework root and session model instantiation
rbuels May 5, 2023
bdcece8
fix last ts errors
rbuels May 6, 2023
b9b8704
fix lint
rbuels May 6, 2023
b5a0b64
ts-ify web rootmodel test
rbuels May 6, 2023
801b8cb
rootmodel tests fixed
rbuels May 6, 2023
856cd69
some simple test fixes
rbuels May 7, 2023
d81ad43
fix jbweb internet account tests
rbuels May 7, 2023
f41b88f
update snap
rbuels May 7, 2023
24431d4
snaps
rbuels May 7, 2023
19d0848
fix build, make session type names and guards consistent
rbuels May 8, 2023
9e329d8
add type guard for jb root model
rbuels May 8, 2023
f0f8d58
lint
rbuels May 8, 2023
eb66f7f
fix product-core version
rbuels May 8, 2023
5f9e9d8
add built-package resolutions for product-core
rbuels May 8, 2023
acec95e
remove unused getJBrowseRoot
rbuels May 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@
"test": true
},
"rules": {
"import/no-extraneous-dependencies": "off"
"import/no-extraneous-dependencies": "off",
"@typescript-eslint/no-non-null-assertion": "off"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this allows non-null assertions in test code

}
},
{
Expand Down
1 change: 1 addition & 0 deletions component_tests/cgv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@jbrowse/plugin-trix": "file:./packed/jbrowse-plugin-trix.tgz",
"@jbrowse/plugin-variants": "file:./packed/jbrowse-plugin-variants.tgz",
"@jbrowse/plugin-wiggle": "file:./packed/jbrowse-plugin-wiggle.tgz",
"@jbrowse/product-core": "file:./packed/jbrowse-product-core.tgz",
"@jbrowse/react-linear-genome-view": "file:./packed/jbrowse-react-linear-genome-view.tgz",
"@jbrowse/react-circular-genome-view": "file:./packed/jbrowse-react-circular-genome-view.tgz"
},
Expand Down
1 change: 1 addition & 0 deletions component_tests/lgv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@jbrowse/plugin-trix": "file:./packed/jbrowse-plugin-trix.tgz",
"@jbrowse/plugin-variants": "file:./packed/jbrowse-plugin-variants.tgz",
"@jbrowse/plugin-wiggle": "file:./packed/jbrowse-plugin-wiggle.tgz",
"@jbrowse/product-core": "file:./packed/jbrowse-product-core.tgz",
"@jbrowse/react-linear-genome-view": "file:./packed/jbrowse-react-linear-genome-view.tgz"
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions packages/core/assemblyManager/assemblyConfigSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ function assemblyConfigSchema(pluginManager: PluginManager) {
}

export default assemblyConfigSchema
export type BaseAssemblyConfigSchema = ReturnType<typeof assemblyConfigSchema>
1 change: 1 addition & 0 deletions packages/core/assemblyManager/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default } from './assemblyManager'
export { default as assemblyConfigSchemaFactory } from './assemblyConfigSchema'
export type { BaseAssemblyConfigSchema } from './assemblyConfigSchema'
1 change: 1 addition & 0 deletions packages/core/configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type {
AnyConfigurationModel,
AnyConfigurationSlot,
AnyConfigurationSlotType,
AnyConfiguration,
} from './types'

export * from './util'
7 changes: 6 additions & 1 deletion packages/core/configuration/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { IStateTreeNode, Instance } from 'mobx-state-tree'
import type { IStateTreeNode, Instance, SnapshotOut } from 'mobx-state-tree'
import type {
ConfigurationSchemaType,
ConfigurationSchemaOptions,
Expand Down Expand Up @@ -61,5 +61,10 @@ export type AnyConfigurationModel = Instance<AnyConfigurationSchemaType>
export type AnyConfigurationSlotType = ReturnType<typeof ConfigSlot>
export type AnyConfigurationSlot = Instance<AnyConfigurationSlotType>

/** any configuration model, or snapshot thereof */
export type AnyConfiguration =
| AnyConfigurationModel
| SnapshotOut<AnyConfigurationModel>

export type ConfigurationModel<SCHEMA extends AnyConfigurationSchemaType> =
Instance<SCHEMA>
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { cast, types } from 'mobx-state-tree'
import { AnyConfigurationModel } from '../../configuration'
import {
AnyConfigurationModel,
ConfigurationReference,
} from '../../configuration'
import PluginManager from '../../PluginManager'

import configSchema from './baseConnectionConfig'
/**
* #stateModel BaseConnectionModel
*/
Expand All @@ -16,6 +20,11 @@ function stateModelFactory(pluginManager: PluginManager) {
* #property
*/
tracks: types.array(pluginManager.pluggableConfigSchemaType('track')),

/**
* #property
*/
configuration: ConfigurationReference(configSchema),
})
.actions(self => ({
afterAttach() {
Expand Down Expand Up @@ -52,4 +61,5 @@ function stateModelFactory(pluginManager: PluginManager) {
}))
}

export type BaseConnectionModel = ReturnType<typeof stateModelFactory>
export default stateModelFactory
12 changes: 10 additions & 2 deletions packages/core/pluggableElementTypes/models/BaseViewModel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { types, Instance } from 'mobx-state-tree'
import { ElementId } from '../../util/types/mst'
import { MenuItem } from '../../ui'
import { Region } from '../../util/types/mst'

/**
* #stateModel BaseViewModel
Expand Down Expand Up @@ -69,5 +70,12 @@ const BaseViewModel = types
}))

export default BaseViewModel
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface IBaseViewModel extends Instance<typeof BaseViewModel> {}

export type IBaseViewModel = Instance<typeof BaseViewModel>

export const BaseViewModelWithDisplayedRegions = BaseViewModel.props({
displayedRegions: types.array(Region),
})
export type IBaseViewModelWithDisplayedRegions = Instance<
typeof BaseViewModelWithDisplayedRegions
>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { Instance } from 'mobx-state-tree'
import { ConfigurationSchema } from '../../configuration'

/**
* #config BaseConnection
*/
function x() {} // eslint-disable-line @typescript-eslint/no-unused-vars

export default ConfigurationSchema(
const BaseConnectionConfig = ConfigurationSchema(
'BaseConnection',
{
/**
Expand Down Expand Up @@ -33,3 +34,7 @@ export default ConfigurationSchema(
explicitIdentifier: 'connectionId',
},
)

export default BaseConnectionConfig
export type BaseConnectionConfigSchema = typeof BaseConnectionConfig
export type BaseConnectionConfigModel = Instance<BaseConnectionConfigSchema>
4 changes: 2 additions & 2 deletions packages/core/pluggableElementTypes/models/baseTrackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ export function createBaseTrackConfig(pluginManager: PluginManager) {
)
}

export type BaseTrackConfigModel = ReturnType<typeof createBaseTrackConfig>
export type BaseTrackConfig = Instance<BaseTrackConfigModel>
export type BaseTrackConfigSchema = ReturnType<typeof createBaseTrackConfig>
export type BaseTrackConfig = Instance<BaseTrackConfigSchema>
5 changes: 4 additions & 1 deletion packages/core/pluggableElementTypes/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ export { BaseInternetAccountConfig } from './baseInternetAccountConfig'
export { createBaseTrackModel } from './BaseTrackModel'
export type { BaseTrackModel, BaseTrackStateModel } from './BaseTrackModel'
export { createBaseTrackConfig } from './baseTrackConfig'
export type { BaseTrackConfig, BaseTrackConfigModel } from './baseTrackConfig'
export type {
BaseTrackConfig,
BaseTrackConfigSchema as BaseTrackConfigModel,
} from './baseTrackConfig'
1 change: 0 additions & 1 deletion packages/core/util/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export interface AbstractSessionModel extends AbstractViewContainer {
sessionConnections?: AnyConfigurationModel[]
connectionInstances?: {
name: string
connectionId: string
tracks: AnyConfigurationModel[]
configuration: AnyConfigurationModel
}[]
Expand Down
6 changes: 0 additions & 6 deletions packages/core/util/types/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react'
import { IAnyModelType, Instance } from 'mobx-state-tree'
import PluginManager from '../../PluginManager'

/**
Expand All @@ -21,8 +20,3 @@ export type AnyReactComponentType = React.ComponentType<any>
/** get the type that a predicate asserts */
export type TypeTestedByPredicate<PREDICATE extends (thing: any) => boolean> =
PREDICATE extends (thing: any) => thing is infer TYPE ? TYPE : never

/** get the type for an instance of an MST model in a PM factory function */
export type InstanceOfModelReturnedBy<
FACTORY extends (pm: PluginManager) => IAnyModelType,
> = Instance<ReturnType<FACTORY>>
58 changes: 58 additions & 0 deletions packages/product-core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@jbrowse/product-core",
"version": "2.5.0",
"description": "JBrowse 2 code shared between products but not used by plugins",
"keywords": [
"jbrowse",
"jbrowse2",
"bionode",
"biojs",
"genomics"
],
"license": "Apache-2.0",
"homepage": "https://jbrowse.org",
"bugs": "https://github.com/GMOD/jbrowse-components/issues",
"repository": {
"type": "git",
"url": "https://github.com/GMOD/jbrowse-components.git",
"directory": "packages/text-indexing"
},
"author": "JBrowse Team",
"distMain": "dist/index.js",
"distModule": "esm/index.js",
"srcMain": "src/index.ts",
"srcModule": "src/index.ts",
"main": "src/index.ts",
"module": "",
"files": [
"dist",
"esm",
"src"
],
"scripts": {
"build:esm": "tsc --build tsconfig.build.esm.json",
"build:es5": "tsc --build tsconfig.build.es5.json",
"build": "npm run build:esm && npm run build:es5",
"test": "cd ../..; jest packages/text-indexing",
"clean": "rimraf dist esm *.tsbuildinfo",
"prebuild": "yarn clean",
"prepack": "yarn build && yarn useDist",
"postpack": "yarn useSrc",
"useDist": "node ../../scripts/useDist.js",
"useSrc": "node ../../scripts/useSrc.js"
},
"dependencies": {
"@babel/runtime": "^7.16.3",
"@mui/material": "^5.10.17",
"shortid": "^2.2.15"
},
"peerDependencies": {
"mobx": "^6.0.0",
"mobx-react": "^7.0.0",
"mobx-state-tree": "^5.0.0",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"rxjs": "^7.0.0"
},
"private": true
}
131 changes: 131 additions & 0 deletions packages/product-core/src/RootModel/Base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import PluginManager from '@jbrowse/core/PluginManager'
import assemblyManagerFactory, {
BaseAssemblyConfigSchema,
} from '@jbrowse/core/assemblyManager'
import RpcManager from '@jbrowse/core/rpc/RpcManager'
import {
IAnyType,
Instance,
SnapshotIn,
cast,
getSnapshot,
isStateTreeNode,
types,
} from 'mobx-state-tree'
import TextSearchManager from '@jbrowse/core/TextSearch/TextSearchManager'

/**
* factory function for the Base-level root model shared by all products
*/
export default function BaseRootModelTypeF(
pluginManager: PluginManager,
jbrowseModelType: IAnyType,
sessionModelType: IAnyType,
assemblyConfigSchema: BaseAssemblyConfigSchema,
) {
return types
.model('BaseRootModel', {
/**
* #property
* `jbrowse` is a mapping of the config.json into the in-memory state tree
*/
jbrowse: jbrowseModelType,
/**
* #property
*/
version: 'development',

/**
* #property
* `session` encompasses the currently active state of the app, including
* views open, tracks open in those views, etc.
*/
session: types.maybe(sessionModelType),
/**
* #property
*/
sessionPath: types.optional(types.string, ''),

/**
* #property
*/
assemblyManager: types.optional(
assemblyManagerFactory(assemblyConfigSchema, pluginManager),
{},
),
})
.volatile(self => ({
rpcManager: new RpcManager(
pluginManager,
self.jbrowse.configuration.rpc,
{
MainThreadRpcDriver: {},
},
),

/**
* #volatile
* Boolean indicating whether the session is in admin mode or not
*/
adminMode: true,
isAssemblyEditing: false,
error: undefined as unknown,
textSearchManager: new TextSearchManager(pluginManager),
pluginManager,
}))
.actions(self => ({
/**
* #action
*/
setError(error: unknown) {
self.error = error
},
/**
* #action
*/
setSession(sessionSnapshot?: SnapshotIn<IAnyType>) {
self.session = cast(sessionSnapshot)
},
/**
* #action
*/
setDefaultSession() {
this.setSession(self.jbrowse.defaultSession)
},
/**
* #action
*/
setSessionPath(path: string) {
self.sessionPath = path
},
/**
* #action
*/
async renameCurrentSession(newName: string) {
if (self.session) {
const snapshot = JSON.parse(JSON.stringify(getSnapshot(self.session)))
snapshot.name = newName
this.setSession(snapshot)
}
},
/**
* #action
*/
setAssemblyEditing(flag: boolean) {
self.isAssemblyEditing = flag
},
}))
}

export type BaseRootModelType = ReturnType<typeof BaseRootModelTypeF>
export type BaseRootModel = Instance<BaseRootModelType>

/** Type guard for checking if something is a JB root model */
export function isRootModel(thing: unknown): thing is BaseRootModelType {
return (
isStateTreeNode(thing) &&
'session' in thing &&
'jbrowse' in thing &&
'assemblyManager' in thing
)
}
Loading