@journeyapps-labs/reactor-mod-data-browser 1.0.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.
Files changed (133) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +3 -0
  3. package/dist/@types/DataBrowserModule.d.ts +7 -0
  4. package/dist/@types/actions/connections/AddConnectionAction.d.ts +10 -0
  5. package/dist/@types/actions/connections/RemoveConnectionAction.d.ts +10 -0
  6. package/dist/@types/actions/schema-definitions/CreateModelAction.d.ts +9 -0
  7. package/dist/@types/actions/schema-definitions/QuerySchemaModelAction.d.ts +9 -0
  8. package/dist/@types/actions/schema-model/EditSchemaModelAction.d.ts +9 -0
  9. package/dist/@types/core/AbstractConnection.d.ts +33 -0
  10. package/dist/@types/core/AbstractConnectionFactory.d.ts +11 -0
  11. package/dist/@types/core/SchemaModelDefinition.d.ts +20 -0
  12. package/dist/@types/core/SchemaModelObject.d.ts +12 -0
  13. package/dist/@types/core/query/AbstractQuery.d.ts +22 -0
  14. package/dist/@types/core/query/Page.d.ts +24 -0
  15. package/dist/@types/core/query/SimpleQuery.d.ts +36 -0
  16. package/dist/@types/core/types/ManualConnection.d.ts +14 -0
  17. package/dist/@types/core/types/ManualConnectionFactory.d.ts +9 -0
  18. package/dist/@types/entities/ConnectionEntityDefinition.d.ts +9 -0
  19. package/dist/@types/entities/ConnectionFactoryEntityDefinition.d.ts +9 -0
  20. package/dist/@types/entities/QueryEntityDefinition.d.ts +9 -0
  21. package/dist/@types/entities/SchemaModelDefinitionEntityDefinition.d.ts +13 -0
  22. package/dist/@types/entities/SchemaModelObjectEntityDefinition.d.ts +14 -0
  23. package/dist/@types/entities.d.ts +7 -0
  24. package/dist/@types/forms/APIConnectionForm.d.ts +12 -0
  25. package/dist/@types/forms/SchemaModelForm.d.ts +11 -0
  26. package/dist/@types/index.d.ts +3 -0
  27. package/dist/@types/panels/model/ModelPanelFactory.d.ts +28 -0
  28. package/dist/@types/panels/model/ModelPanelWidget.d.ts +6 -0
  29. package/dist/@types/panels/query/PageResultsWidget.d.ts +8 -0
  30. package/dist/@types/panels/query/QueryPanelFactory.d.ts +33 -0
  31. package/dist/@types/panels/query/QueryPanelWidget.d.ts +6 -0
  32. package/dist/@types/panels/query/TableControlsWidget.d.ts +10 -0
  33. package/dist/@types/stores/ConnectionStore.d.ts +20 -0
  34. package/dist/DataBrowserModule.js +45 -0
  35. package/dist/DataBrowserModule.js.map +1 -0
  36. package/dist/actions/connections/AddConnectionAction.js +48 -0
  37. package/dist/actions/connections/AddConnectionAction.js.map +1 -0
  38. package/dist/actions/connections/RemoveConnectionAction.js +43 -0
  39. package/dist/actions/connections/RemoveConnectionAction.js.map +1 -0
  40. package/dist/actions/schema-definitions/CreateModelAction.js +45 -0
  41. package/dist/actions/schema-definitions/CreateModelAction.js.map +1 -0
  42. package/dist/actions/schema-definitions/QuerySchemaModelAction.js +47 -0
  43. package/dist/actions/schema-definitions/QuerySchemaModelAction.js.map +1 -0
  44. package/dist/actions/schema-model/EditSchemaModelAction.js +46 -0
  45. package/dist/actions/schema-model/EditSchemaModelAction.js.map +1 -0
  46. package/dist/core/AbstractConnection.js +69 -0
  47. package/dist/core/AbstractConnection.js.map +1 -0
  48. package/dist/core/AbstractConnectionFactory.js +6 -0
  49. package/dist/core/AbstractConnectionFactory.js.map +1 -0
  50. package/dist/core/SchemaModelDefinition.js +31 -0
  51. package/dist/core/SchemaModelDefinition.js.map +1 -0
  52. package/dist/core/SchemaModelObject.js +12 -0
  53. package/dist/core/SchemaModelObject.js.map +1 -0
  54. package/dist/core/query/AbstractQuery.js +18 -0
  55. package/dist/core/query/AbstractQuery.js.map +1 -0
  56. package/dist/core/query/Page.js +65 -0
  57. package/dist/core/query/Page.js.map +1 -0
  58. package/dist/core/query/SimpleQuery.js +160 -0
  59. package/dist/core/query/SimpleQuery.js.map +1 -0
  60. package/dist/core/types/ManualConnection.js +21 -0
  61. package/dist/core/types/ManualConnection.js.map +1 -0
  62. package/dist/core/types/ManualConnectionFactory.js +50 -0
  63. package/dist/core/types/ManualConnectionFactory.js.map +1 -0
  64. package/dist/entities/ConnectionEntityDefinition.js +77 -0
  65. package/dist/entities/ConnectionEntityDefinition.js.map +1 -0
  66. package/dist/entities/ConnectionFactoryEntityDefinition.js +60 -0
  67. package/dist/entities/ConnectionFactoryEntityDefinition.js.map +1 -0
  68. package/dist/entities/QueryEntityDefinition.js +60 -0
  69. package/dist/entities/QueryEntityDefinition.js.map +1 -0
  70. package/dist/entities/SchemaModelDefinitionEntityDefinition.js +76 -0
  71. package/dist/entities/SchemaModelDefinitionEntityDefinition.js.map +1 -0
  72. package/dist/entities/SchemaModelObjectEntityDefinition.js +76 -0
  73. package/dist/entities/SchemaModelObjectEntityDefinition.js.map +1 -0
  74. package/dist/entities.js +9 -0
  75. package/dist/entities.js.map +1 -0
  76. package/dist/forms/APIConnectionForm.js +31 -0
  77. package/dist/forms/APIConnectionForm.js.map +1 -0
  78. package/dist/forms/SchemaModelForm.js +72 -0
  79. package/dist/forms/SchemaModelForm.js.map +1 -0
  80. package/dist/index.js +4 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/panels/model/ModelPanelFactory.js +94 -0
  83. package/dist/panels/model/ModelPanelFactory.js.map +1 -0
  84. package/dist/panels/model/ModelPanelWidget.js +28 -0
  85. package/dist/panels/model/ModelPanelWidget.js.map +1 -0
  86. package/dist/panels/query/PageResultsWidget.js +24 -0
  87. package/dist/panels/query/PageResultsWidget.js.map +1 -0
  88. package/dist/panels/query/QueryPanelFactory.js +94 -0
  89. package/dist/panels/query/QueryPanelFactory.js.map +1 -0
  90. package/dist/panels/query/QueryPanelWidget.js +41 -0
  91. package/dist/panels/query/QueryPanelWidget.js.map +1 -0
  92. package/dist/panels/query/TableControlsWidget.js +52 -0
  93. package/dist/panels/query/TableControlsWidget.js.map +1 -0
  94. package/dist/stores/ConnectionStore.js +93 -0
  95. package/dist/stores/ConnectionStore.js.map +1 -0
  96. package/dist/tsconfig.tsbuildinfo +1 -0
  97. package/dist-module/bundle.js +31 -0
  98. package/dist-module/bundle.js.LICENSE.txt +16 -0
  99. package/dist-module/bundle.js.map +1 -0
  100. package/package.json +40 -0
  101. package/reactor.config.json +4 -0
  102. package/src/DataBrowserModule.ts +54 -0
  103. package/src/actions/connections/AddConnectionAction.tsx +33 -0
  104. package/src/actions/connections/RemoveConnectionAction.tsx +28 -0
  105. package/src/actions/schema-definitions/CreateModelAction.ts +32 -0
  106. package/src/actions/schema-definitions/QuerySchemaModelAction.ts +36 -0
  107. package/src/actions/schema-model/EditSchemaModelAction.ts +33 -0
  108. package/src/core/AbstractConnection.ts +101 -0
  109. package/src/core/AbstractConnectionFactory.ts +14 -0
  110. package/src/core/SchemaModelDefinition.ts +44 -0
  111. package/src/core/SchemaModelObject.ts +19 -0
  112. package/src/core/query/AbstractQuery.ts +43 -0
  113. package/src/core/query/Page.ts +59 -0
  114. package/src/core/query/SimpleQuery.tsx +165 -0
  115. package/src/core/types/ManualConnection.ts +32 -0
  116. package/src/core/types/ManualConnectionFactory.tsx +36 -0
  117. package/src/entities/ConnectionEntityDefinition.tsx +81 -0
  118. package/src/entities/ConnectionFactoryEntityDefinition.tsx +54 -0
  119. package/src/entities/QueryEntityDefinition.ts +46 -0
  120. package/src/entities/SchemaModelDefinitionEntityDefinition.ts +82 -0
  121. package/src/entities/SchemaModelObjectEntityDefinition.ts +78 -0
  122. package/src/entities.ts +7 -0
  123. package/src/forms/APIConnectionForm.tsx +48 -0
  124. package/src/forms/SchemaModelForm.tsx +97 -0
  125. package/src/index.ts +5 -0
  126. package/src/panels/model/ModelPanelFactory.tsx +78 -0
  127. package/src/panels/model/ModelPanelWidget.tsx +42 -0
  128. package/src/panels/query/PageResultsWidget.tsx +52 -0
  129. package/src/panels/query/QueryPanelFactory.tsx +76 -0
  130. package/src/panels/query/QueryPanelWidget.tsx +72 -0
  131. package/src/panels/query/TableControlsWidget.tsx +83 -0
  132. package/src/stores/ConnectionStore.ts +87 -0
  133. package/tsconfig.json +14 -0
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@journeyapps-labs/reactor-mod-data-browser",
3
+ "version": "1.0.0",
4
+ "main": "./dist/index.js",
5
+ "typings": "./dist/@types/index",
6
+ "publishConfig": {
7
+ "registry": "https://registry.npmjs.org/",
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/journeyapps-labs/sector.git"
13
+ },
14
+ "author": "JOURNEYAPPS",
15
+ "license": "Apache-2.0",
16
+ "dependencies": {
17
+ "@emotion/styled": "^11.14.1",
18
+ "@journeyapps-labs/common-ioc": "^1.0.0",
19
+ "@journeyapps-labs/common-utils": "^1.0.0",
20
+ "@journeyapps-labs/lib-reactor-data-layer": "^1.0.2",
21
+ "@journeyapps-labs/reactor-mod": "^1.2.0",
22
+ "@journeyapps/db": "^8.1.1",
23
+ "@journeyapps/parser-schema": "^8.2.5",
24
+ "@projectstorm/react-workspaces-core": "4.2.2",
25
+ "lodash": "^4.17.21",
26
+ "mobx": "^6.13.7",
27
+ "mobx-react": "^9.2.0",
28
+ "react": "19.1.1",
29
+ "uuid": "^11.1.0"
30
+ },
31
+ "devDependencies": {
32
+ "@journeyapps-labs/lib-reactor-builder": "^1.0.3",
33
+ "@types/lodash": "^4.17.20",
34
+ "@types/uuid": "^10.0.0"
35
+ },
36
+ "scripts": {
37
+ "build:module": "reactor build .",
38
+ "watch:module": "pnpm build:module --watch"
39
+ }
40
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "Sector Databrowser",
3
+ "slug": "module-databrowser"
4
+ }
@@ -0,0 +1,54 @@
1
+ import { AbstractReactorModule, System, WorkspaceStore } from '@journeyapps-labs/reactor-mod';
2
+ import { Container } from '@journeyapps-labs/common-ioc';
3
+ import { ConnectionStore } from './stores/ConnectionStore';
4
+ import { ConnectionEntityDefinition } from './entities/ConnectionEntityDefinition';
5
+ import { ManualConnectionFactory } from './core/types/ManualConnectionFactory';
6
+ import { ConnectionFactoryEntityDefinition } from './entities/ConnectionFactoryEntityDefinition';
7
+ import { AddConnectionAction } from './actions/connections/AddConnectionAction';
8
+ import { RemoveConnectionAction } from './actions/connections/RemoveConnectionAction';
9
+ import { SchemaModelDefinitionEntityDefinition } from './entities/SchemaModelDefinitionEntityDefinition';
10
+ import { QueryPanelFactory } from './panels/query/QueryPanelFactory';
11
+ import { QuerySchemaModelAction } from './actions/schema-definitions/QuerySchemaModelAction';
12
+ import { QueryEntityDefinition } from './entities/QueryEntityDefinition';
13
+ import { ModelPanelFactory } from './panels/model/ModelPanelFactory';
14
+ import { CreateModelAction } from './actions/schema-definitions/CreateModelAction';
15
+ import { SchemaModelObjectEntityDefinition } from './entities/SchemaModelObjectEntityDefinition';
16
+ import { EditSchemaModelAction } from './actions/schema-model/EditSchemaModelAction';
17
+
18
+ export class DataBrowserModule extends AbstractReactorModule {
19
+ constructor() {
20
+ super({
21
+ name: 'Data Browser'
22
+ });
23
+ }
24
+
25
+ register(ioc: Container) {
26
+ const system = ioc.get(System);
27
+ const workspaceStore = ioc.get(WorkspaceStore);
28
+
29
+ let connectionStore = new ConnectionStore();
30
+
31
+ connectionStore.registerConnectionFactory(new ManualConnectionFactory());
32
+
33
+ system.registerAction(new AddConnectionAction());
34
+ system.registerAction(new RemoveConnectionAction());
35
+ system.registerAction(new QuerySchemaModelAction());
36
+ system.registerAction(new CreateModelAction());
37
+ system.registerAction(new EditSchemaModelAction());
38
+
39
+ system.addStore(ConnectionStore, connectionStore);
40
+
41
+ system.registerDefinition(new ConnectionEntityDefinition());
42
+ system.registerDefinition(new ConnectionFactoryEntityDefinition());
43
+ system.registerDefinition(new SchemaModelDefinitionEntityDefinition());
44
+ system.registerDefinition(new SchemaModelObjectEntityDefinition());
45
+ system.registerDefinition(new QueryEntityDefinition());
46
+
47
+ workspaceStore.registerFactory(new QueryPanelFactory());
48
+ workspaceStore.registerFactory(new ModelPanelFactory());
49
+ }
50
+
51
+ async init(ioc: Container): Promise<any> {
52
+ await ioc.get(ConnectionStore).init();
53
+ }
54
+ }
@@ -0,0 +1,33 @@
1
+ import { EntityAction, EntityActionEvent, inject, ioc, System } from '@journeyapps-labs/reactor-mod';
2
+ import { AbstractConnectionFactory } from '../../core/AbstractConnectionFactory';
3
+ import { DataBrowserEntities } from '../../entities';
4
+ import { ConnectionStore } from '../../stores/ConnectionStore';
5
+
6
+ export class AddConnectionAction extends EntityAction<AbstractConnectionFactory> {
7
+ static ID = 'ADD_CONNECTION';
8
+
9
+ @inject(ConnectionStore)
10
+ accessor connectionStore: ConnectionStore;
11
+
12
+ constructor() {
13
+ super({
14
+ id: AddConnectionAction.ID,
15
+ name: 'Add connection',
16
+ icon: 'plus',
17
+ target: DataBrowserEntities.CONNECTION_FACTORY,
18
+ autoSelectIsolatedTarget: true
19
+ });
20
+ }
21
+
22
+ async fireEvent(event: EntityActionEvent<AbstractConnectionFactory>): Promise<any> {
23
+ let connection = await event.targetEntity.generateConnectionFromUI();
24
+ if (!connection) {
25
+ return;
26
+ }
27
+ this.connectionStore.addConnection(connection);
28
+ }
29
+
30
+ static get() {
31
+ return ioc.get(System).getActionByID<AddConnectionAction>(AddConnectionAction.ID);
32
+ }
33
+ }
@@ -0,0 +1,28 @@
1
+ import { EntityAction, EntityActionEvent, inject, ioc, System } from '@journeyapps-labs/reactor-mod';
2
+ import { DataBrowserEntities } from '../../entities';
3
+ import { ConnectionStore } from '../../stores/ConnectionStore';
4
+ import { AbstractConnection } from '../../core/AbstractConnection';
5
+
6
+ export class RemoveConnectionAction extends EntityAction<AbstractConnection> {
7
+ static ID = 'REMOVE_CONNECTION';
8
+
9
+ @inject(ConnectionStore)
10
+ accessor connectionStore: ConnectionStore;
11
+
12
+ constructor() {
13
+ super({
14
+ id: RemoveConnectionAction.ID,
15
+ name: 'Remove connection',
16
+ icon: 'trash',
17
+ target: DataBrowserEntities.CONNECTION
18
+ });
19
+ }
20
+
21
+ async fireEvent(event: EntityActionEvent<AbstractConnection>): Promise<any> {
22
+ event.targetEntity.remove();
23
+ }
24
+
25
+ static get() {
26
+ return ioc.get(System).getActionByID<RemoveConnectionAction>(RemoveConnectionAction.ID);
27
+ }
28
+ }
@@ -0,0 +1,32 @@
1
+ import { EntityAction, EntityActionEvent, inject, ioc, System, WorkspaceStore } from '@journeyapps-labs/reactor-mod';
2
+ import { DataBrowserEntities } from '../../entities';
3
+ import { SchemaModelDefinition } from '../../core/SchemaModelDefinition';
4
+ import { ModelPanelModel } from '../../panels/model/ModelPanelFactory';
5
+
6
+ export class CreateModelAction extends EntityAction<SchemaModelDefinition> {
7
+ static ID = 'CREATE_SCHEMA_MODEL';
8
+
9
+ @inject(WorkspaceStore)
10
+ accessor workspaceStore: WorkspaceStore;
11
+
12
+ constructor() {
13
+ super({
14
+ id: CreateModelAction.ID,
15
+ name: 'Create schema model',
16
+ icon: 'search',
17
+ target: DataBrowserEntities.SCHEMA_MODEL_DEFINITION
18
+ });
19
+ }
20
+
21
+ async fireEvent(event: EntityActionEvent<SchemaModelDefinition>): Promise<any> {
22
+ this.workspaceStore.addModel(
23
+ new ModelPanelModel({
24
+ definition: event.targetEntity
25
+ })
26
+ );
27
+ }
28
+
29
+ static get() {
30
+ return ioc.get(System).getActionByID<CreateModelAction>(CreateModelAction.ID);
31
+ }
32
+ }
@@ -0,0 +1,36 @@
1
+ import { EntityAction, EntityActionEvent, inject, ioc, System, WorkspaceStore } from '@journeyapps-labs/reactor-mod';
2
+ import { DataBrowserEntities } from '../../entities';
3
+ import { SchemaModelDefinition } from '../../core/SchemaModelDefinition';
4
+ import { QueryPanelModel } from '../../panels/query/QueryPanelFactory';
5
+ import { SimpleQuery } from '../../core/query/SimpleQuery';
6
+
7
+ export class QuerySchemaModelAction extends EntityAction<SchemaModelDefinition> {
8
+ static ID = 'QUERY_SCHEMA_MODEL';
9
+
10
+ @inject(WorkspaceStore)
11
+ accessor workspaceStore: WorkspaceStore;
12
+
13
+ constructor() {
14
+ super({
15
+ id: QuerySchemaModelAction.ID,
16
+ name: 'Query schema model',
17
+ icon: 'search',
18
+ target: DataBrowserEntities.SCHEMA_MODEL_DEFINITION
19
+ });
20
+ }
21
+
22
+ async fireEvent(event: EntityActionEvent<SchemaModelDefinition>): Promise<any> {
23
+ this.workspaceStore.addModel(
24
+ new QueryPanelModel(
25
+ new SimpleQuery({
26
+ definition: event.targetEntity,
27
+ limit: 30
28
+ })
29
+ )
30
+ );
31
+ }
32
+
33
+ static get() {
34
+ return ioc.get(System).getActionByID<QuerySchemaModelAction>(QuerySchemaModelAction.ID);
35
+ }
36
+ }
@@ -0,0 +1,33 @@
1
+ import { EntityAction, EntityActionEvent, inject, ioc, System, WorkspaceStore } from '@journeyapps-labs/reactor-mod';
2
+ import { DataBrowserEntities } from '../../entities';
3
+ import { SchemaModelObject } from '../../core/SchemaModelObject';
4
+ import { ModelPanelModel } from '../../panels/model/ModelPanelFactory';
5
+
6
+ export class EditSchemaModelAction extends EntityAction<SchemaModelObject> {
7
+ static ID = 'EDIT_SCHEMA_MODEL';
8
+
9
+ @inject(WorkspaceStore)
10
+ accessor workspaceStore: WorkspaceStore;
11
+
12
+ constructor() {
13
+ super({
14
+ id: EditSchemaModelAction.ID,
15
+ name: 'Edit schema model',
16
+ icon: 'edit',
17
+ target: DataBrowserEntities.SCHEMA_MODEL_OBJECT
18
+ });
19
+ }
20
+
21
+ async fireEvent(event: EntityActionEvent<SchemaModelObject>): Promise<any> {
22
+ this.workspaceStore.addModel(
23
+ new ModelPanelModel({
24
+ definition: event.targetEntity.definition,
25
+ model: event.targetEntity
26
+ })
27
+ );
28
+ }
29
+
30
+ static get() {
31
+ return ioc.get(System).getActionByID<EditSchemaModelAction>(EditSchemaModelAction.ID);
32
+ }
33
+ }
@@ -0,0 +1,101 @@
1
+ import { Database, ObjectType } from '@journeyapps/db';
2
+ import { Schema } from '@journeyapps/parser-schema';
3
+ import { AbstractConnectionFactory } from './AbstractConnectionFactory';
4
+ import * as _ from 'lodash';
5
+ import { SchemaModelDefinition } from './SchemaModelDefinition';
6
+ import { v4 } from 'uuid';
7
+ import { BaseObserver } from '@journeyapps-labs/common-utils';
8
+ import { Collection, LifecycleCollection } from '@journeyapps-labs/lib-reactor-data-layer';
9
+ import { when } from 'mobx';
10
+
11
+ export interface AbstractConnectionSerialized {
12
+ factory: string;
13
+ id: string;
14
+ payload: any;
15
+ }
16
+
17
+ export interface AbstractConnectionListener {
18
+ removed: () => any;
19
+ }
20
+
21
+ export abstract class AbstractConnection extends BaseObserver<AbstractConnectionListener> {
22
+ id: string;
23
+
24
+ schema_models_collection: Collection<ObjectType>;
25
+ schema_models: LifecycleCollection<ObjectType, SchemaModelDefinition>;
26
+
27
+ constructor(public factory: AbstractConnectionFactory) {
28
+ super();
29
+ this.id = v4();
30
+ this.schema_models_collection = new Collection();
31
+ this.schema_models = new LifecycleCollection({
32
+ collection: this.schema_models_collection,
33
+ generateModel: (o) => {
34
+ return new SchemaModelDefinition({
35
+ definition: o,
36
+ connection: this
37
+ });
38
+ },
39
+ getKeyForSerialized: (o) => {
40
+ return o.name;
41
+ }
42
+ });
43
+ }
44
+
45
+ getSchemaModelDefinitionByName(name: string) {
46
+ return this.schema_models.items.find((i) => i.definition.name === name);
47
+ }
48
+
49
+ async waitForSchemaModelDefinitionByName(name: string) {
50
+ await when(() => !!this.getSchemaModelDefinitionByName(name));
51
+ return this.getSchemaModelDefinitionByName(name);
52
+ }
53
+
54
+ abstract getConnection(): Promise<Database>;
55
+
56
+ protected async getSchema(): Promise<Schema> {
57
+ const connection = await this.getConnection();
58
+ return connection.schema;
59
+ }
60
+
61
+ async reload() {
62
+ await this.schema_models_collection.load(async () => {
63
+ const schema = await this.getSchema();
64
+ return _.values(schema.objects);
65
+ });
66
+ }
67
+
68
+ async init() {
69
+ await this.reload();
70
+ }
71
+
72
+ protected async getSchemaModelDefinitions() {
73
+ const schema = await this.getSchema();
74
+ return _.map(schema.objects, (o) => {
75
+ return new SchemaModelDefinition({
76
+ definition: o,
77
+ connection: this
78
+ });
79
+ });
80
+ }
81
+
82
+ remove() {
83
+ this.iterateListeners((cb) => cb.removed?.());
84
+ }
85
+
86
+ serialize(): AbstractConnectionSerialized {
87
+ return {
88
+ id: this.id,
89
+ factory: this.factory.options.key,
90
+ payload: this._serialize()
91
+ };
92
+ }
93
+
94
+ get name() {
95
+ return this.id;
96
+ }
97
+
98
+ abstract _serialize(): any;
99
+
100
+ abstract _deSerialize(data: ReturnType<this['_serialize']>): Promise<any>;
101
+ }
@@ -0,0 +1,14 @@
1
+ import { AbstractConnection } from './AbstractConnection';
2
+
3
+ export interface ConnectionFactoryOptions {
4
+ label: string;
5
+ key: string;
6
+ }
7
+
8
+ export abstract class AbstractConnectionFactory<T extends AbstractConnection = AbstractConnection> {
9
+ constructor(public options: ConnectionFactoryOptions) {}
10
+
11
+ abstract generateConnection(): T;
12
+
13
+ abstract generateConnectionFromUI(): Promise<T | null>;
14
+ }
@@ -0,0 +1,44 @@
1
+ import { AbstractConnection } from './AbstractConnection';
2
+ import { ObjectType } from '@journeyapps/parser-schema';
3
+ import { Collection } from '@journeyapps/db';
4
+ import { SchemaModelObject } from './SchemaModelObject';
5
+ import { LifecycleModel } from '@journeyapps-labs/lib-reactor-data-layer';
6
+
7
+ export interface SchemaModelDefinitionOptions {
8
+ connection: AbstractConnection;
9
+ definition: ObjectType;
10
+ }
11
+ export class SchemaModelDefinition implements LifecycleModel<ObjectType> {
12
+ constructor(protected options: SchemaModelDefinitionOptions) {}
13
+
14
+ get key() {
15
+ return this.definition.name;
16
+ }
17
+
18
+ dispose() {}
19
+
20
+ patch(data: ObjectType) {
21
+ this.options.definition = data;
22
+ }
23
+
24
+ get connection() {
25
+ return this.options.connection;
26
+ }
27
+
28
+ get definition() {
29
+ return this.options.definition;
30
+ }
31
+
32
+ async getCollection() {
33
+ const conn = await this.connection.getConnection();
34
+ return conn[this.definition.name] as Collection;
35
+ }
36
+
37
+ async generateNewModelObject(): Promise<SchemaModelObject> {
38
+ const collection = await this.getCollection();
39
+ return new SchemaModelObject({
40
+ definition: this,
41
+ model: collection.create()
42
+ });
43
+ }
44
+ }
@@ -0,0 +1,19 @@
1
+ import { DatabaseObject } from '@journeyapps/db';
2
+ import { SchemaModelDefinition } from './SchemaModelDefinition';
3
+
4
+ export interface SchemaModelObjectOptions {
5
+ definition: SchemaModelDefinition;
6
+ model?: DatabaseObject;
7
+ }
8
+
9
+ export class SchemaModelObject {
10
+ constructor(public options: SchemaModelObjectOptions) {}
11
+
12
+ get definition(): SchemaModelDefinition {
13
+ return this.options.definition;
14
+ }
15
+
16
+ get model() {
17
+ return this.options.model;
18
+ }
19
+ }
@@ -0,0 +1,43 @@
1
+ import { Page } from './Page';
2
+ import { AbstractConnection } from '../AbstractConnection';
3
+ import { ConnectionStore } from '../../stores/ConnectionStore';
4
+ import { v4 } from 'uuid';
5
+ import { TableColumn } from '@journeyapps-labs/reactor-mod';
6
+
7
+ export interface AbstractQueryEncoded {
8
+ type: string;
9
+ connection_id: string;
10
+ definition: string;
11
+ }
12
+
13
+ export abstract class AbstractQuery<T extends AbstractQueryEncoded = AbstractQueryEncoded> {
14
+ id: string;
15
+
16
+ constructor(
17
+ protected type: string,
18
+ protected connection: AbstractConnection
19
+ ) {
20
+ this.id = v4();
21
+ }
22
+
23
+ abstract getSimpleName(): string;
24
+
25
+ abstract load(): Promise<any>;
26
+
27
+ abstract getColumns(): TableColumn[];
28
+
29
+ abstract get totalPages(): number;
30
+
31
+ abstract getPage(number: number): Page;
32
+
33
+ serialize(): T {
34
+ return {
35
+ type: this.type,
36
+ connection_id: this.connection.id
37
+ } as T;
38
+ }
39
+
40
+ async deserialize(connectionStore: ConnectionStore, data: T) {
41
+ this.connection = await connectionStore.waitForReadyForConnection(data.connection_id);
42
+ }
43
+ }
@@ -0,0 +1,59 @@
1
+ import { SchemaModelObject } from '../SchemaModelObject';
2
+ import { TableRow } from '@journeyapps-labs/reactor-mod';
3
+ import { Collection, DatabaseObject } from '@journeyapps/db';
4
+ import { observable } from 'mobx';
5
+ import { SchemaModelDefinition } from '../SchemaModelDefinition';
6
+
7
+ export interface PageRow extends TableRow {
8
+ model: SchemaModelObject;
9
+ definition: SchemaModelDefinition;
10
+ }
11
+
12
+ export interface PageOptions {
13
+ collection: () => Promise<Collection<DatabaseObject>>;
14
+ offset: number;
15
+ limit: number;
16
+ definition: SchemaModelDefinition;
17
+ index: number;
18
+ }
19
+
20
+ export class Page {
21
+ @observable
22
+ accessor models: SchemaModelObject[];
23
+
24
+ @observable
25
+ accessor loading: boolean;
26
+
27
+ constructor(protected options: PageOptions) {
28
+ this.loading = true;
29
+ this.models = [];
30
+ }
31
+
32
+ get index() {
33
+ return this.options.index;
34
+ }
35
+
36
+ async load() {
37
+ this.loading = true;
38
+ let collection = await this.options.collection();
39
+ let models = await collection.all().limit(this.options.limit).skip(this.options.offset).toArray();
40
+ this.models = models.map((m) => {
41
+ return new SchemaModelObject({
42
+ definition: this.options.definition,
43
+ model: m
44
+ });
45
+ });
46
+ this.loading = false;
47
+ }
48
+
49
+ asRows(): PageRow[] {
50
+ return this.models.map((m) => {
51
+ return {
52
+ key: m.model.id,
53
+ cells: m.model,
54
+ definition: this.options.definition,
55
+ model: m
56
+ };
57
+ });
58
+ }
59
+ }