@med1802/repository-manager 3.0.2 → 3.1.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/README.md +214 -247
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/{workspace/modules → core}/index.js +1 -0
- package/dist/core/middleware.d.ts.map +1 -0
- package/dist/core/repository.d.ts +10 -0
- package/dist/core/repository.d.ts.map +1 -0
- package/dist/core/repository.js +83 -0
- package/dist/{workspace/modules/repository → core}/types.d.ts +2 -2
- package/dist/core/types.d.ts.map +1 -0
- package/dist/{workspace/infrastructure → infrastructure}/index.d.ts +1 -0
- package/dist/infrastructure/index.d.ts.map +1 -0
- package/dist/{workspace/infrastructure → infrastructure}/index.js +1 -0
- package/dist/{workspace/infrastructure → infrastructure}/logger.d.ts +2 -2
- package/dist/infrastructure/logger.d.ts.map +1 -0
- package/dist/infrastructure/observer/EventScope.d.ts +14 -0
- package/dist/infrastructure/observer/EventScope.d.ts.map +1 -0
- package/dist/infrastructure/observer/EventScope.js +38 -0
- package/dist/infrastructure/observer/index.d.ts +16 -0
- package/dist/infrastructure/observer/index.d.ts.map +1 -0
- package/dist/infrastructure/observer/index.js +52 -0
- package/dist/infrastructure/observer/types.d.ts +18 -0
- package/dist/infrastructure/observer/types.d.ts.map +1 -0
- package/dist/infrastructure/observer/types.js +1 -0
- package/dist/infrastructure/scope/index.d.ts.map +1 -0
- package/dist/infrastructure/scope/scope.d.ts.map +1 -0
- package/dist/{workspace/infrastructure → infrastructure}/scope/scope.js +3 -8
- package/dist/infrastructure/scope/types.d.ts +4 -0
- package/dist/infrastructure/scope/types.d.ts.map +1 -0
- package/dist/infrastructure/store.d.ts.map +1 -0
- package/dist/manager.d.ts +3 -5
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +8 -11
- package/dist/workspace/{modules/repository/createRepositoryModule.d.ts → client.d.ts} +5 -5
- package/dist/workspace/client.d.ts.map +1 -0
- package/dist/workspace/{modules/repository/createRepositoryModule.js → client.js} +7 -8
- package/dist/workspace/context.d.ts +13 -0
- package/dist/workspace/context.d.ts.map +1 -0
- package/dist/workspace/context.js +32 -0
- package/dist/workspace/index.d.ts +2 -12
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +2 -30
- package/dist/workspace/types/configuration.types.d.ts +6 -0
- package/dist/workspace/types/configuration.types.d.ts.map +1 -0
- package/dist/workspace/types/index.d.ts +3 -0
- package/dist/workspace/types/index.d.ts.map +1 -0
- package/dist/workspace/types/index.js +2 -0
- package/dist/workspace/types/observer.types.d.ts +15 -0
- package/dist/workspace/types/observer.types.d.ts.map +1 -0
- package/dist/workspace/types/observer.types.js +1 -0
- package/package.json +1 -1
- package/src/{workspace/modules → core}/index.ts +1 -0
- package/src/core/repository.ts +90 -0
- package/src/{workspace/modules/repository → core}/types.ts +2 -2
- package/src/{workspace/infrastructure → infrastructure}/index.ts +1 -0
- package/src/{workspace/infrastructure → infrastructure}/logger.ts +2 -2
- package/src/infrastructure/observer/EventScope.ts +51 -0
- package/src/infrastructure/observer/index.ts +91 -0
- package/src/infrastructure/observer/types.ts +23 -0
- package/src/{workspace/infrastructure → infrastructure}/scope/scope.ts +4 -9
- package/src/infrastructure/scope/types.ts +3 -0
- package/src/manager.ts +8 -15
- package/src/workspace/{modules/repository/createRepositoryModule.ts → client.ts} +11 -9
- package/src/workspace/context.ts +58 -0
- package/src/workspace/index.ts +2 -38
- package/src/workspace/types/configuration.types.ts +5 -0
- package/src/workspace/types/index.ts +2 -0
- package/src/workspace/types/observer.types.ts +18 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/workspace/infrastructure/index.d.ts.map +0 -1
- package/dist/workspace/infrastructure/logger.d.ts.map +0 -1
- package/dist/workspace/infrastructure/scope/index.d.ts.map +0 -1
- package/dist/workspace/infrastructure/scope/scope.d.ts.map +0 -1
- package/dist/workspace/infrastructure/scope/types.d.ts +0 -8
- package/dist/workspace/infrastructure/scope/types.d.ts.map +0 -1
- package/dist/workspace/infrastructure/store.d.ts.map +0 -1
- package/dist/workspace/modules/index.d.ts +0 -2
- package/dist/workspace/modules/index.d.ts.map +0 -1
- package/dist/workspace/modules/repository/createRepositoryModule.d.ts.map +0 -1
- package/dist/workspace/modules/repository/index.d.ts +0 -3
- package/dist/workspace/modules/repository/index.d.ts.map +0 -1
- package/dist/workspace/modules/repository/index.js +0 -2
- package/dist/workspace/modules/repository/middleware.d.ts.map +0 -1
- package/dist/workspace/modules/repository/repositoryAccessor.d.ts +0 -9
- package/dist/workspace/modules/repository/repositoryAccessor.d.ts.map +0 -1
- package/dist/workspace/modules/repository/repositoryAccessor.js +0 -42
- package/dist/workspace/modules/repository/types.d.ts.map +0 -1
- package/dist/workspace/providers/index.d.ts +0 -5
- package/dist/workspace/providers/index.d.ts.map +0 -1
- package/dist/workspace/providers/index.js +0 -3
- package/dist/workspace/types.d.ts +0 -5
- package/dist/workspace/types.d.ts.map +0 -1
- package/src/workspace/infrastructure/scope/types.ts +0 -8
- package/src/workspace/modules/repository/index.ts +0 -2
- package/src/workspace/modules/repository/repositoryAccessor.ts +0 -48
- package/src/workspace/providers/index.ts +0 -5
- package/src/workspace/types.ts +0 -4
- /package/dist/{workspace/modules/repository → core}/middleware.d.ts +0 -0
- /package/dist/{workspace/modules/repository → core}/middleware.js +0 -0
- /package/dist/{workspace/infrastructure/scope → core}/types.js +0 -0
- /package/dist/{workspace/infrastructure → infrastructure}/logger.js +0 -0
- /package/dist/{workspace/infrastructure → infrastructure}/scope/index.d.ts +0 -0
- /package/dist/{workspace/infrastructure → infrastructure}/scope/index.js +0 -0
- /package/dist/{workspace/infrastructure → infrastructure}/scope/scope.d.ts +0 -0
- /package/dist/{workspace/modules/repository → infrastructure/scope}/types.js +0 -0
- /package/dist/{workspace/infrastructure → infrastructure}/store.d.ts +0 -0
- /package/dist/{workspace/infrastructure → infrastructure}/store.js +0 -0
- /package/dist/workspace/{types.js → types/configuration.types.js} +0 -0
- /package/src/{workspace/modules/repository → core}/middleware.ts +0 -0
- /package/src/{workspace/infrastructure → infrastructure}/scope/index.ts +0 -0
- /package/src/{workspace/infrastructure → infrastructure}/store.ts +0 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { applyMiddleware } from "./middleware";
|
|
2
|
+
function createRepository(infrastructure, repositoryPlugin, observer) {
|
|
3
|
+
const { install, middlewares, onConnect, onDisconnect } = repositoryPlugin;
|
|
4
|
+
let repository = undefined;
|
|
5
|
+
let connections = 0;
|
|
6
|
+
let subscriptions = [];
|
|
7
|
+
return {
|
|
8
|
+
get repository() {
|
|
9
|
+
return repository;
|
|
10
|
+
},
|
|
11
|
+
get connections() {
|
|
12
|
+
return connections;
|
|
13
|
+
},
|
|
14
|
+
connect() {
|
|
15
|
+
if (connections === 0) {
|
|
16
|
+
const rawRepository = install({
|
|
17
|
+
instance: {
|
|
18
|
+
infrastructure,
|
|
19
|
+
observer: (() => {
|
|
20
|
+
return {
|
|
21
|
+
dispatch: ({ repositoryId, type, message }) => {
|
|
22
|
+
if (repository === repositoryPlugin.id) {
|
|
23
|
+
console.warn("WARNING: DISPATCHING TO SELF");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
observer.dispatch({
|
|
27
|
+
scope: repositoryId,
|
|
28
|
+
eventName: "dispatch",
|
|
29
|
+
payload: {
|
|
30
|
+
type,
|
|
31
|
+
message,
|
|
32
|
+
source: repositoryPlugin.id,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
subscribe: (handler) => {
|
|
37
|
+
if (subscriptions.length > 0) {
|
|
38
|
+
console.warn("WARNING: SUBSCRIBED ALREADY");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const unsubscribe = observer.subscribe({
|
|
42
|
+
scope: repositoryPlugin.id,
|
|
43
|
+
eventName: "dispatch",
|
|
44
|
+
callback({ payload }) {
|
|
45
|
+
const { type, message, source } = payload;
|
|
46
|
+
handler({
|
|
47
|
+
type,
|
|
48
|
+
message: message !== null && message !== void 0 ? message : undefined,
|
|
49
|
+
source,
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
subscriptions.push(unsubscribe);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
})(),
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
repository = middlewares
|
|
60
|
+
? applyMiddleware(rawRepository, middlewares)
|
|
61
|
+
: rawRepository;
|
|
62
|
+
if (onConnect) {
|
|
63
|
+
onConnect();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
connections += 1;
|
|
67
|
+
},
|
|
68
|
+
disconnect() {
|
|
69
|
+
if (connections === 0)
|
|
70
|
+
return;
|
|
71
|
+
connections -= 1;
|
|
72
|
+
if (connections === 0) {
|
|
73
|
+
repository = undefined;
|
|
74
|
+
subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
75
|
+
subscriptions = [];
|
|
76
|
+
if (onDisconnect) {
|
|
77
|
+
onDisconnect();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export { createRepository };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IObserver } from "../workspace";
|
|
2
2
|
export type repositoryType<I = any, R = any> = (obj: {
|
|
3
3
|
instance: {
|
|
4
4
|
infrastructure: I;
|
|
5
|
-
|
|
5
|
+
observer: IObserver;
|
|
6
6
|
};
|
|
7
7
|
}) => R;
|
|
8
8
|
export interface IRepositoryPlugin<I = any, R = any> {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;IACnD,QAAQ,EAAE;QACR,cAAc,EAAE,CAAC,CAAC;QAClB,QAAQ,EAAE,SAAS,CAAC;KACrB,CAAC;CACH,KAAK,CAAC,CAAC;AAER,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9B,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,GAAG,GAAG;IAC1C,OAAO,IAAI,IAAI,CAAC;IAChB,UAAU,IAAI,IAAI,CAAC;IACnB,UAAU,EAAE,UAAU,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAC3D,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,UAAU,GAAG,CACvB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,EAAE,EACX,IAAI,EAAE,CAAC,GAAG,QAAQ,EAAE,GAAG,EAAE,KAAK,GAAG,KAC9B,GAAG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/infrastructure/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAChD,cAAc,YAAY,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IConfiguration } from "../
|
|
2
|
-
declare const createLogger: (config: IConfiguration) => {
|
|
1
|
+
import type { IConfiguration } from "../workspace";
|
|
2
|
+
declare const createLogger: (config: Omit<IConfiguration, "infrastructure">) => {
|
|
3
3
|
log: (callback: () => void, { type, scope, metadata, }: {
|
|
4
4
|
type: string;
|
|
5
5
|
scope: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/infrastructure/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,QAAA,MAAM,YAAY,GAAI,QAAQ,IAAI,CAAC,cAAc,EAAE,gBAAgB,CAAC;oBAIpD,MAAM,IAAI,8BAKjB;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,CAAA;KAAE;CAgC5D,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare class EventScope extends EventTarget {
|
|
2
|
+
scopeName: string;
|
|
3
|
+
subScopes: Map<string, EventScope>;
|
|
4
|
+
lastEventPayloads: Map<string, any>;
|
|
5
|
+
constructor(scopeName: string);
|
|
6
|
+
private formatEventData;
|
|
7
|
+
dispatch: ({ eventName, payload, }: {
|
|
8
|
+
eventName: string;
|
|
9
|
+
payload?: any;
|
|
10
|
+
}) => void;
|
|
11
|
+
subscribe: (eventName: string, callback: (e: any) => void) => () => void;
|
|
12
|
+
}
|
|
13
|
+
export { EventScope };
|
|
14
|
+
//# sourceMappingURL=EventScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventScope.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/observer/EventScope.ts"],"names":[],"mappings":"AAAA,cAAM,UAAW,SAAQ,WAAW;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAa;IAC/C,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAa;gBAEpC,SAAS,EAAE,MAAM;IAK7B,OAAO,CAAC,eAAe;IAQvB,QAAQ,GAAI,yBAGT;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,GAAG,CAAC;KACf,UASC;IACF,SAAS,GAAI,WAAW,MAAM,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,gBAaxD;CACH;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class EventScope extends EventTarget {
|
|
2
|
+
constructor(scopeName) {
|
|
3
|
+
super();
|
|
4
|
+
this.subScopes = new Map();
|
|
5
|
+
this.lastEventPayloads = new Map();
|
|
6
|
+
this.dispatch = ({ eventName, payload = undefined, }) => {
|
|
7
|
+
this.lastEventPayloads.set(eventName, payload);
|
|
8
|
+
const event = new CustomEvent(eventName, {
|
|
9
|
+
detail: {
|
|
10
|
+
payload,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
this.dispatchEvent(event);
|
|
14
|
+
};
|
|
15
|
+
this.subscribe = (eventName, callback) => {
|
|
16
|
+
if (this.lastEventPayloads.has(eventName)) {
|
|
17
|
+
const lastPayload = this.lastEventPayloads.get(eventName);
|
|
18
|
+
callback(this.formatEventData(eventName, lastPayload));
|
|
19
|
+
}
|
|
20
|
+
const callbackWrapper = (e) => {
|
|
21
|
+
callback(this.formatEventData(eventName, e.detail.payload));
|
|
22
|
+
};
|
|
23
|
+
this.addEventListener(eventName, callbackWrapper);
|
|
24
|
+
return () => {
|
|
25
|
+
this.removeEventListener(eventName, callbackWrapper);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
this.scopeName = scopeName;
|
|
29
|
+
}
|
|
30
|
+
formatEventData(eventName, payload) {
|
|
31
|
+
return {
|
|
32
|
+
payload,
|
|
33
|
+
eventName,
|
|
34
|
+
scope: this.scopeName,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export { EventScope };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ScopeNode, type scopedObserverDispatchType, type scopedObserverSubscribeType } from "./types";
|
|
2
|
+
declare const createScopedObserver: (props?: ScopeNode[]) => {
|
|
3
|
+
dispatch: ({ scope, eventName, payload, }: {
|
|
4
|
+
scope?: string;
|
|
5
|
+
eventName: string;
|
|
6
|
+
payload?: any;
|
|
7
|
+
}) => void;
|
|
8
|
+
subscribe: ({ scope, eventName, callback, }: {
|
|
9
|
+
scope?: string;
|
|
10
|
+
eventName: string;
|
|
11
|
+
callback: (payload: any) => void;
|
|
12
|
+
}) => (() => void);
|
|
13
|
+
};
|
|
14
|
+
type scopedObserverType = ReturnType<typeof createScopedObserver>;
|
|
15
|
+
export { createScopedObserver, type scopedObserverType, type scopedObserverDispatchType, type scopedObserverSubscribeType, type ScopeNode, };
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/observer/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EACjC,MAAM,SAAS,CAAC;AAEjB,QAAA,MAAM,oBAAoB,GAAI,QAAQ,SAAS,EAAE;+CA0C1C;QACD,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,GAAG,CAAC;KACf;iDASE;QACD,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;KAClC,KAAG,CAAC,MAAM,IAAI,CAAC;CAcnB,CAAC;AAEF,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,OAAO,EACL,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EAChC,KAAK,SAAS,GACf,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { EventScope } from "./EventScope";
|
|
2
|
+
import { ROOT_SCOPE, } from "./types";
|
|
3
|
+
const createScopedObserver = (props) => {
|
|
4
|
+
const root = new EventScope(ROOT_SCOPE);
|
|
5
|
+
props === null || props === void 0 ? void 0 : props.forEach((node) => {
|
|
6
|
+
const scope = buildScopeHierarchy(node);
|
|
7
|
+
root.subScopes.set(node.scope, scope);
|
|
8
|
+
});
|
|
9
|
+
function buildScopeHierarchy(node) {
|
|
10
|
+
const eventScope = new EventScope(node.scope);
|
|
11
|
+
if (node.subScopes && node.subScopes.length > 0) {
|
|
12
|
+
node.subScopes.forEach((subNode) => {
|
|
13
|
+
const subScope = buildScopeHierarchy(subNode);
|
|
14
|
+
eventScope.subScopes.set(subNode.scope, subScope);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return eventScope;
|
|
18
|
+
}
|
|
19
|
+
function find(scope) {
|
|
20
|
+
if (!scope || scope.trim() === "") {
|
|
21
|
+
return root;
|
|
22
|
+
}
|
|
23
|
+
const scopeParts = scope.split(":").filter(Boolean);
|
|
24
|
+
let current = root;
|
|
25
|
+
for (const part of scopeParts) {
|
|
26
|
+
const next = current.subScopes.get(part);
|
|
27
|
+
if (!next) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
current = next;
|
|
31
|
+
}
|
|
32
|
+
return current;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
dispatch: ({ scope, eventName, payload = undefined, }) => {
|
|
36
|
+
const scopeEntity = find(scope);
|
|
37
|
+
if (!scopeEntity)
|
|
38
|
+
return;
|
|
39
|
+
scopeEntity.dispatch({ eventName, payload });
|
|
40
|
+
},
|
|
41
|
+
subscribe: ({ scope, eventName, callback, }) => {
|
|
42
|
+
const scopeEntity = find(scope);
|
|
43
|
+
if (!scopeEntity) {
|
|
44
|
+
console.warn(`[ScopedObserver] Scope "${scope || "root"}" not found. Returning no-op unsubscribe.`);
|
|
45
|
+
return () => { };
|
|
46
|
+
}
|
|
47
|
+
const unsubscribe = scopeEntity.subscribe(eventName, callback);
|
|
48
|
+
return unsubscribe;
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export { createScopedObserver, };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type ScopeNodeType = ScopeNode[];
|
|
2
|
+
type scopedObserverDispatchType = {
|
|
3
|
+
scope?: string;
|
|
4
|
+
eventName: string;
|
|
5
|
+
payload?: any;
|
|
6
|
+
};
|
|
7
|
+
type scopedObserverSubscribeType = {
|
|
8
|
+
scope?: string;
|
|
9
|
+
eventName: string;
|
|
10
|
+
callback: (payload: any) => void;
|
|
11
|
+
};
|
|
12
|
+
export type ScopeNode = {
|
|
13
|
+
scope: string;
|
|
14
|
+
subScopes?: ScopeNode[];
|
|
15
|
+
};
|
|
16
|
+
export declare const ROOT_SCOPE = "root";
|
|
17
|
+
export { type ScopeNodeType, type scopedObserverDispatchType, type scopedObserverSubscribeType, };
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/observer/types.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG,SAAS,EAAE,CAAC;AAEjC,KAAK,0BAA0B,GAAG;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AACF,KAAK,2BAA2B,GAAG;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;CAClC,CAAC;AACF,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,UAAU,SAAS,CAAC;AACjC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,GACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ROOT_SCOPE = "root";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/scope/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAChD,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/scope/scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,iBAAS,WAAW,CAAC,CAAC,GAAG,GAAG,EAC1B,YAAY,EAAE,CAAC,GACd,MAAM,CAAC,CAAC,CAAC,GAAG;IAAE,YAAY,EAAE,CAAC,CAAA;CAAE,CAoBjC;AACD,iBAAS,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,KAGxC;AACD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import { createStore } from "../store";
|
|
2
1
|
function createScope(defaultValue) {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const stack = store.getState("stack");
|
|
6
|
-
function provider(options) {
|
|
7
|
-
const { value, children } = options;
|
|
8
|
-
const stack = store.getState("stack");
|
|
2
|
+
const stack = [];
|
|
3
|
+
function provider(initialValue, children) {
|
|
9
4
|
if (!stack) {
|
|
10
5
|
throw new Error("Scope stack not found");
|
|
11
6
|
}
|
|
12
7
|
try {
|
|
13
|
-
stack.push(
|
|
8
|
+
stack.push(initialValue ? initialValue : defaultValue);
|
|
14
9
|
children();
|
|
15
10
|
}
|
|
16
11
|
finally {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/scope/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM,CAAC,CAAC,GAAG,GAAG;IAC7B,QAAQ,CAAC,YAAY,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CACvD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/infrastructure/store.ts"],"names":[],"mappings":"AAAA,iBAAS,WAAW,CAAC,CAAC;iBAGL,MAAM,QAAQ,CAAC;iBAGf,MAAM;iBAGN,MAAM;oBAGH,MAAM;;EAOzB;AACD,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/manager.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { IScope } from "./workspace/infrastructure/scope";
|
|
1
|
+
import { type IConfiguration } from "./workspace";
|
|
3
2
|
declare const repositoryManager: () => {
|
|
4
|
-
|
|
5
|
-
defineRepository: <R = any>(repositoryPlugin: import("./
|
|
3
|
+
createWorkspace<I>(config: IConfiguration<I>): {
|
|
4
|
+
defineRepository: <R = any>(repositoryPlugin: import("./core").IRepositoryPlugin<I, R>) => void;
|
|
6
5
|
queryRepository: <R = any>(id: string) => {
|
|
7
6
|
repository: R;
|
|
8
7
|
disconnect(): void;
|
|
9
8
|
};
|
|
10
|
-
createScope: <V = any>(defaultValue: V) => IScope<V>;
|
|
11
9
|
};
|
|
12
10
|
};
|
|
13
11
|
export { repositoryManager };
|
package/dist/manager.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAG1E,QAAA,MAAM,iBAAiB;oBAEH,CAAC,UAAU,cAAc,CAAC,CAAC,CAAC;;;;;;;CAQ/C,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
package/dist/manager.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createWorkspaceContext } from "./workspace";
|
|
2
|
+
import { createWorkspaceClient } from "./workspace/client";
|
|
3
3
|
const repositoryManager = () => {
|
|
4
|
-
const store = createStore();
|
|
5
4
|
return {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
createScope: workspace.createScope,
|
|
13
|
-
};
|
|
5
|
+
createWorkspace(config) {
|
|
6
|
+
let client = undefined;
|
|
7
|
+
createWorkspaceContext(config, () => {
|
|
8
|
+
client = createWorkspaceClient();
|
|
9
|
+
});
|
|
10
|
+
return client;
|
|
14
11
|
},
|
|
15
12
|
};
|
|
16
13
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type
|
|
2
|
-
declare function
|
|
1
|
+
import { type IRepositoryPlugin, type repositoryType } from "../core";
|
|
2
|
+
declare function createWorkspaceClient<I>(): {
|
|
3
|
+
defineRepository: <R = any>(repositoryPlugin: IRepositoryPlugin<I, R>) => void;
|
|
3
4
|
queryRepository: <R = any>(id: string) => {
|
|
4
5
|
repository: ReturnType<repositoryType<I, R>>;
|
|
5
6
|
disconnect(): void;
|
|
6
7
|
};
|
|
7
|
-
defineRepository: <R = any>(repositoryPlugin: IRepositoryPlugin<I, R>) => void;
|
|
8
8
|
};
|
|
9
|
-
export {
|
|
10
|
-
//# sourceMappingURL=
|
|
9
|
+
export { createWorkspaceClient };
|
|
10
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/workspace/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAGjB,iBAAS,qBAAqB,CAAC,CAAC;uBAYJ,CAAC,0BACP,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC;sBAyBlB,CAAC,YAAY,MAAM;oBAgBd,UAAU,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;;;EAU/D;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { store, logger, infrastructure } = useScope(repositoryScope);
|
|
1
|
+
import { createRepository, } from "../core";
|
|
2
|
+
import { workspace } from "../workspace";
|
|
3
|
+
function createWorkspaceClient() {
|
|
4
|
+
const { store, logger, infrastructure, observer } = workspace();
|
|
6
5
|
function hasRepository(id) {
|
|
7
6
|
return store.hasState(id);
|
|
8
7
|
}
|
|
@@ -17,7 +16,7 @@ function createRepositoryModule() {
|
|
|
17
16
|
if (hasRepository(id))
|
|
18
17
|
return;
|
|
19
18
|
logger.log(() => {
|
|
20
|
-
store.setState(id,
|
|
19
|
+
store.setState(id, createRepository(infrastructure, repositoryPlugin, observer));
|
|
21
20
|
}, {
|
|
22
21
|
type: "repository.define",
|
|
23
22
|
scope: id,
|
|
@@ -53,8 +52,8 @@ function createRepositoryModule() {
|
|
|
53
52
|
};
|
|
54
53
|
}
|
|
55
54
|
return {
|
|
56
|
-
queryRepository,
|
|
57
55
|
defineRepository,
|
|
56
|
+
queryRepository,
|
|
58
57
|
};
|
|
59
58
|
}
|
|
60
|
-
export {
|
|
59
|
+
export { createWorkspaceClient };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createLogger, createScopedObserver, createStore } from "../infrastructure";
|
|
2
|
+
import type { IRepositoryInstance } from "../core";
|
|
3
|
+
import type { IConfiguration } from "./types/configuration.types";
|
|
4
|
+
interface IWorkspaceContext<I = any> {
|
|
5
|
+
store: ReturnType<typeof createStore<IRepositoryInstance<any>>>;
|
|
6
|
+
logger: ReturnType<typeof createLogger>;
|
|
7
|
+
observer: ReturnType<typeof createScopedObserver>;
|
|
8
|
+
infrastructure: I;
|
|
9
|
+
}
|
|
10
|
+
declare function createWorkspaceContext<I>(params: IConfiguration<I>, child: () => void): void;
|
|
11
|
+
declare function workspace<I>(): IWorkspaceContext<I>;
|
|
12
|
+
export { createWorkspaceContext, workspace };
|
|
13
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/workspace/context.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAEZ,oBAAoB,EACpB,WAAW,EAEZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,UAAU,iBAAiB,CAAC,CAAC,GAAG,GAAG;IACjC,KAAK,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAChE,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;IACxC,QAAQ,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;IAClD,cAAc,EAAE,CAAC,CAAC;CACnB;AAID,iBAAS,sBAAsB,CAAC,CAAC,EAC/B,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EACzB,KAAK,EAAE,MAAM,IAAI,QA4BlB;AAED,iBAAS,SAAS,CAAC,CAAC,0BAGnB;AAED,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createLogger, createScope, createScopedObserver, createStore, useScope, } from "../infrastructure";
|
|
2
|
+
const workspaceScope = createScope(undefined);
|
|
3
|
+
function createWorkspaceContext(params, child) {
|
|
4
|
+
const { id, logging, infrastructure } = params;
|
|
5
|
+
const defaultConfig = {
|
|
6
|
+
id,
|
|
7
|
+
logging: logging !== null && logging !== void 0 ? logging : false,
|
|
8
|
+
};
|
|
9
|
+
const logger = createLogger(defaultConfig);
|
|
10
|
+
const store = createStore();
|
|
11
|
+
const observer = createScopedObserver([
|
|
12
|
+
{
|
|
13
|
+
scope: "user-repo",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
scope: "company-repo",
|
|
17
|
+
},
|
|
18
|
+
]);
|
|
19
|
+
workspaceScope.provider({
|
|
20
|
+
store,
|
|
21
|
+
logger,
|
|
22
|
+
observer,
|
|
23
|
+
infrastructure,
|
|
24
|
+
}, () => {
|
|
25
|
+
child();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function workspace() {
|
|
29
|
+
const context = useScope(workspaceScope);
|
|
30
|
+
return context;
|
|
31
|
+
}
|
|
32
|
+
export { createWorkspaceContext, workspace };
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare function createWorkspace<I>(infrastructure: I, config: IConfiguration): {
|
|
4
|
-
defineRepository: <R = any>(repositoryPlugin: import("./modules").IRepositoryPlugin<I, R>) => void;
|
|
5
|
-
queryRepository: <R = any>(id: string) => {
|
|
6
|
-
repository: R;
|
|
7
|
-
disconnect(): void;
|
|
8
|
-
};
|
|
9
|
-
createScope: typeof createScope;
|
|
10
|
-
useScope: typeof useScope;
|
|
11
|
-
};
|
|
12
|
-
export { createWorkspace };
|
|
1
|
+
export * from "./context";
|
|
2
|
+
export * from "./types";
|
|
13
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workspace/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workspace/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/dist/workspace/index.js
CHANGED
|
@@ -1,30 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { repositoryScope } from "./providers";
|
|
4
|
-
function createWorkspace(infrastructure, config) {
|
|
5
|
-
var _a;
|
|
6
|
-
const defaultConfig = {
|
|
7
|
-
id: config.id,
|
|
8
|
-
logging: (_a = config.logging) !== null && _a !== void 0 ? _a : false,
|
|
9
|
-
};
|
|
10
|
-
const logger = createLogger(defaultConfig);
|
|
11
|
-
const store = createStore();
|
|
12
|
-
let repositoryModule;
|
|
13
|
-
repositoryScope.provider({
|
|
14
|
-
value: {
|
|
15
|
-
store,
|
|
16
|
-
logger,
|
|
17
|
-
infrastructure,
|
|
18
|
-
},
|
|
19
|
-
children: () => {
|
|
20
|
-
repositoryModule = createRepositoryModule();
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
return {
|
|
24
|
-
defineRepository: repositoryModule.defineRepository,
|
|
25
|
-
queryRepository: repositoryModule.queryRepository,
|
|
26
|
-
createScope,
|
|
27
|
-
useScope,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
export { createWorkspace };
|
|
1
|
+
export * from "./context";
|
|
2
|
+
export * from "./types";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.types.d.ts","sourceRoot":"","sources":["../../../src/workspace/types/configuration.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,GAAG;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,EAAE,CAAC,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/workspace/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type IObserverDispatch<P = any> = {
|
|
2
|
+
type: string;
|
|
3
|
+
repositoryId: string;
|
|
4
|
+
message?: P;
|
|
5
|
+
};
|
|
6
|
+
export type IObserverSubscribePayload<P = any> = {
|
|
7
|
+
type: string;
|
|
8
|
+
source: string;
|
|
9
|
+
message: P;
|
|
10
|
+
};
|
|
11
|
+
export type IObserver = {
|
|
12
|
+
dispatch<P = any>(payload: IObserverDispatch<P>): void;
|
|
13
|
+
subscribe<P = any>(callback: (payload: IObserverSubscribePayload<P>) => void): void;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=observer.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer.types.d.ts","sourceRoot":"","sources":["../../../src/workspace/types/observer.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,CAAC,CAAC,GAAG,GAAG,IAAI;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,GAAG,IAAI;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,CAAC,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACvD,SAAS,CAAC,CAAC,GAAG,GAAG,EACf,QAAQ,EAAE,CAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC,CAAC,KAAK,IAAI,GACxD,IAAI,CAAC;CACT,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED