@treenity/core 1.0.13

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/CHANGELOG.md ADDED
@@ -0,0 +1,56 @@
1
+ # @treenity/core
2
+
3
+ ## 1.0.13
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated packages version
8
+ - Updated dependencies
9
+ - @treenity/js-shared@1.0.12
10
+
11
+ ## 1.0.12
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated libs
16
+ - Updated dependencies
17
+ - @treenity/js-shared@1.0.11
18
+
19
+ ## 1.0.11
20
+
21
+ ### Patch Changes
22
+
23
+ - Changed version
24
+ - Updated dependencies
25
+ - @treenity/js-shared@1.0.10
26
+
27
+ ## 1.0.10
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated libs
32
+ - Updated dependencies
33
+ - @treenity/js-shared@1.0.9
34
+
35
+ ## 1.0.9
36
+
37
+ ### Patch Changes
38
+
39
+ - Updated dependencies
40
+ - @treenity/js-shared@1.0.8
41
+
42
+ ## 1.0.8
43
+
44
+ ### Patch Changes
45
+
46
+ - Updated versions
47
+ - Updated dependencies
48
+ - @treenity/js-shared@1.0.5
49
+
50
+ ## 1.0.7
51
+
52
+ ### Patch Changes
53
+
54
+ - Updated version to update new front-proxy
55
+ - Updated dependencies
56
+ - @treenity/js-shared@1.0.4
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # @treenity/core docs
2
+ ### Installation
3
+ Create token with "api" **scope** [here](https://gitlab.com/-/profile/personal_access_tokens).
4
+ Add private registry info to .npmrc file in root of project
5
+ ```
6
+ @cluster:registry=https://gitlab.com/api/v4/projects/35830151/packages/npm/
7
+ //gitlab.com/api/v4/projects/35830151/packages/npm/:_authToken=${TOKEN}
8
+ ```
9
+ Install:
10
+ ```
11
+ TOKEN=<access_token> npm i @cluster/protocol
12
+ ```
13
+
14
+ ### Publish new version
15
+ To publish new version you need gilab api access key:
16
+ ```bash
17
+ MY_TOKEN=<access_token> npm publish
18
+ ```
@@ -0,0 +1,84 @@
1
+ import { Obj } from '@treenity/js-shared';
2
+ import * as React from 'react';
3
+ import { PropsWithChildren } from 'react';
4
+ import { JsonObjectSchema } from './contexts/json-schema/types';
5
+ import { PortTypeData } from './contexts/react/types';
6
+ import { Meta, Node } from './meta';
7
+ export interface TypeContextInfo<C, O> {
8
+ id: string;
9
+ context: string;
10
+ subContext: string;
11
+ component: C;
12
+ options: O;
13
+ }
14
+ export interface Context<C, O> {
15
+ name: string;
16
+ add(typeName: string, component: C, options: O): TypeContextInfo<C, O>;
17
+ add(subContext: string, typeName: string, component: C, options: O): TypeContextInfo<C, O>;
18
+ get(typeName: string): Promise<[C, O]>;
19
+ get(subContext: string, typeName: string): Promise<[C, O]>;
20
+ getInfo(typeName: string): Promise<TypeContextInfo<C, O>>;
21
+ getInfo(subContext: string, typeName: string): Promise<TypeContextInfo<C, O>>;
22
+ search(query: string): TypeContextInfo<C, O>[];
23
+ }
24
+ export declare class ContextImpl<C, O> implements Context<C, O> {
25
+ name: string;
26
+ items: Map<string, TypeContextInfo<C, O>>;
27
+ constructor(name: string);
28
+ add(...args: any[]): TypeContextInfo<C, O>;
29
+ getInfo(subContext: string, typeName?: string): Promise<TypeContextInfo<C, O>>;
30
+ get(subContext: string, typeName?: string): Promise<[C, O]>;
31
+ search(query: string): TypeContextInfo<C, O>[];
32
+ }
33
+ export interface ReactContextOptions {
34
+ props?: Obj<any>;
35
+ ports?: PortTypeData;
36
+ }
37
+ export interface IReactContextProps<T extends Meta = Meta> extends PropsWithChildren {
38
+ value: T;
39
+ node: Node;
40
+ onChange(setter: (m: T) => T | void): void;
41
+ onChangeNode(setter: (node: Node) => Node | void): void;
42
+ }
43
+ export type ReactTypeContextInfo = TypeContextInfo<React.FC<IReactContextProps>, ReactContextOptions>;
44
+ export interface ReactTypeContext extends Context<React.FC<IReactContextProps>, ReactContextOptions> {
45
+ }
46
+ export interface Service {
47
+ run(params: {
48
+ meta: Meta;
49
+ node: Node;
50
+ }): Promise<void>;
51
+ }
52
+ export interface ServiceContextOptions {
53
+ }
54
+ export interface ServiceTypeContext extends Context<Service, ServiceContextOptions> {
55
+ }
56
+ export type ScriptNode = (...params: any[]) => any;
57
+ export interface NodeEngineContextOptions {
58
+ ports: PortTypeData;
59
+ }
60
+ export type NodeEngineTypeContextInfo = TypeContextInfo<ScriptNode, NodeEngineContextOptions>;
61
+ export interface NodeEngineTypeContext extends Context<ScriptNode, NodeEngineContextOptions> {
62
+ }
63
+ export interface MetaContextOptions {
64
+ }
65
+ export interface MetaTypeContext extends Context<JsonObjectSchema, MetaContextOptions> {
66
+ }
67
+ export interface ProtoTypeContextOptions {
68
+ }
69
+ export interface Protocol {
70
+ fetch(url: string): Promise<any>;
71
+ }
72
+ export interface ProtoTypeContext extends Context<Protocol, ProtoTypeContextOptions> {
73
+ }
74
+ export interface ContextTypes {
75
+ react: ReactTypeContext;
76
+ jsSrv: ServiceTypeContext;
77
+ meta: MetaTypeContext;
78
+ proto: ProtoTypeContext;
79
+ noflo: NodeEngineTypeContext;
80
+ }
81
+ export declare const types: ContextTypes;
82
+ export interface Process {
83
+ createChild(): void;
84
+ }
@@ -0,0 +1,90 @@
1
+ import { capitalize } from '@treenity/js-shared/utils';
2
+ import { SynchronousPromise } from 'synchronous-promise';
3
+
4
+ class ContextImpl {
5
+ name;
6
+ items = new Map();
7
+ constructor(name) {
8
+ this.name = name;
9
+ // @ts-ignore
10
+ types[name] = this;
11
+ }
12
+ // add(...args: Pro<Context<C, O>['add']>): TypeContextInfo<C, O>;
13
+ // add(...args: ArgumentTypes<Context<C, O>['add']>): TypeContextInfo<C, O> {
14
+ add(...args) {
15
+ if (args.length < 3)
16
+ args.unshift('');
17
+ const [subContext, typeName, component, options] = args;
18
+ const contextType = subContext ? subContext + ':' + typeName : typeName;
19
+ const t = {
20
+ id: contextType,
21
+ context: this.name,
22
+ subContext,
23
+ component,
24
+ options,
25
+ };
26
+ this.items.set(contextType, t);
27
+ return t;
28
+ }
29
+ // get(typeName: string): Promise<TypeContextInfo<C, O>>;
30
+ // get(subContext: string, typeName: string): Promise<TypeContextInfo<C, O>>;
31
+ getInfo(subContext, typeName) {
32
+ if (!typeName) {
33
+ typeName = subContext;
34
+ subContext = '';
35
+ }
36
+ const contextType = subContext ? subContext + ':' + typeName : typeName;
37
+ const item = this.items.get(contextType);
38
+ if (!item) {
39
+ return SynchronousPromise.reject(new Error('not found: ' + contextType));
40
+ }
41
+ return SynchronousPromise.resolve(item);
42
+ }
43
+ get(subContext, typeName) {
44
+ return this.getInfo(subContext, typeName).then(({ component, options }) => [
45
+ component,
46
+ options,
47
+ ]);
48
+ }
49
+ search(query) {
50
+ const result = [];
51
+ for (let t of this.items.values()) {
52
+ if (!t.subContext && (!query || t.id.includes(query)))
53
+ result.push(t);
54
+ }
55
+ return result;
56
+ }
57
+ }
58
+ class ReactTypeContextImpl extends ContextImpl {
59
+ add(...args) {
60
+ if (args.length === 4) {
61
+ const [, typeName, component] = args;
62
+ if (!component.displayName && !component.name)
63
+ component.displayName = capitalize(typeName);
64
+ }
65
+ else {
66
+ const [typeName, component] = args;
67
+ if (!component.displayName && !component.name)
68
+ component.displayName = capitalize(typeName);
69
+ }
70
+ return super.add(...args);
71
+ }
72
+ }
73
+ class ServiceTypeContextImpl extends ContextImpl {
74
+ }
75
+ class NodeEngineTypeContextImpl extends ContextImpl {
76
+ }
77
+ class MetaTypeContextImpl extends ContextImpl {
78
+ }
79
+ class ProtoTypeContextImpl extends ContextImpl {
80
+ }
81
+ // @ts-ignore
82
+ const types = {};
83
+ new ReactTypeContextImpl('react');
84
+ new MetaTypeContextImpl('meta');
85
+ new ProtoTypeContextImpl('proto');
86
+ new ServiceTypeContextImpl('jsSrv');
87
+ new NodeEngineTypeContextImpl('noflo');
88
+
89
+ export { ContextImpl, types };
90
+ //# sourceMappingURL=context.mjs.map
@@ -0,0 +1,3 @@
1
+ import { SomeJSONSchema } from 'ajv/lib/types/json-schema';
2
+ import { JSONSchema } from 'json-schema-to-ts';
3
+ export type JsonObjectSchema = SomeJSONSchema & JSONSchema;
@@ -0,0 +1,18 @@
1
+ export interface PortTypeData {
2
+ in: Record<string, Omit<ISocket, 'name'> | string>;
3
+ out: Record<string, Omit<ISocket, 'name'> | string>;
4
+ }
5
+ export interface ISocket<D extends any = {}> {
6
+ id?: string;
7
+ name: string;
8
+ label?: string;
9
+ type: string;
10
+ dynamic?: boolean;
11
+ value?: D;
12
+ isComplex?: boolean;
13
+ }
14
+ export interface ISocketType {
15
+ name?: string;
16
+ label: string;
17
+ type: string;
18
+ }
@@ -0,0 +1,4 @@
1
+ export * from './context';
2
+ export * from './contexts/json-schema/types';
3
+ export * from './contexts/react/types';
4
+ export type { Node, NodeRef, NodeLink, Meta } from './meta';
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export { ContextImpl, types } from './context.mjs';
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * How we're loading the system
3
+ * 1. Loading root json object, containing root node - from db, or fs, or something
4
+ * 2. Start current context: node, or browser, or go, or deno, python...
5
+ * 3. load components for metas in node
6
+ * 4. run components one by one
7
+ */
8
+ export {};
package/dist/meta.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ export interface Meta {
2
+ $id: string;
3
+ $name: string;
4
+ $anchor?: string;
5
+ $type: string;
6
+ $perm?: MetaPermission;
7
+ $tg?: string[];
8
+ }
9
+ export type MetaPermission = Record<string, Array<string>>;
10
+ export interface NodeRef {
11
+ ref: string;
12
+ url: string;
13
+ }
14
+ export interface NodeLink {
15
+ p: string;
16
+ v: string;
17
+ }
18
+ export interface Node extends Meta {
19
+ $parid: string;
20
+ /**
21
+ * if ref exists in $refs, then field value will be replaced with value pointed by NodeRef.url
22
+ */
23
+ $refs: NodeRef[];
24
+ path: string;
25
+ links?: NodeLink[];
26
+ defaultMeta?: string;
27
+ title: string;
28
+ metas: {
29
+ [name: string]: Meta;
30
+ };
31
+ }