@pc-nexus/core 0.0.1-next.1 → 0.0.1-next.3
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 +3 -0
- package/index.d.ts +5 -0
- package/index.d.ts.map +1 -0
- package/lib/common.d.ts +4 -0
- package/lib/common.d.ts.map +1 -0
- package/lib/common.js +5 -0
- package/lib/context.d.ts +36 -0
- package/lib/context.d.ts.map +1 -0
- package/lib/context.js +4 -0
- package/lib/handler.d.ts +16 -0
- package/lib/handler.d.ts.map +1 -0
- package/lib/handler.js +17 -0
- package/lib/resolver.d.ts +11 -0
- package/lib/resolver.d.ts.map +1 -0
- package/lib/resolver.js +18 -0
- package/package.json +1 -4
package/README.md
ADDED
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC"}
|
package/lib/common.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const NEXUS_CONTEXT_TOKEN_HEADER_KEY = "x-nexus-context-token";
|
|
2
|
+
export declare const NEXUS_GATEWAY_ENDPOINT_HEADER_KEY = "x-nexus-gateway-endpoint";
|
|
3
|
+
export declare const invoke: (gateway: string, endpoint: string, payload: unknown) => Promise<Response>;
|
|
4
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/lib/common.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,8BAA8B,0BAA0B,CAAC;AACtE,eAAO,MAAM,iCAAiC,6BAA6B,CAAC;AAC5E,eAAO,MAAM,MAAM,GAAI,SAAS,MAAM,EAAE,UAAU,MAAM,EAAE,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAClB,CAAC"}
|
package/lib/common.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const NEXUS_CONTEXT_TOKEN_HEADER_KEY = "x-nexus-context-token";
|
|
2
|
+
export const NEXUS_GATEWAY_ENDPOINT_HEADER_KEY = "x-nexus-gateway-endpoint";
|
|
3
|
+
export const invoke = (gateway, endpoint, payload) => global["__nexus_runtime__"].invoke(gateway, endpoint, payload);
|
|
4
|
+
// const hook = (name: string): any => (global as any)[NEXUS_RUNTIME][name];
|
|
5
|
+
// export { invoke, NEXUS_CONTEXT_TOKEN_HEADER_KEY, NEXUS_GATEWAY_ENDPOINT_HEADER_KEY };
|
package/lib/context.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface Team {
|
|
2
|
+
_id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
domain: string;
|
|
5
|
+
locale: string;
|
|
6
|
+
timezone: string;
|
|
7
|
+
}
|
|
8
|
+
export interface User {
|
|
9
|
+
uid: string;
|
|
10
|
+
name: string;
|
|
11
|
+
display_name: string;
|
|
12
|
+
locale: string;
|
|
13
|
+
timezone: string;
|
|
14
|
+
}
|
|
15
|
+
export interface Extension {
|
|
16
|
+
id: string;
|
|
17
|
+
environment_id: string;
|
|
18
|
+
environment_type: string;
|
|
19
|
+
installation_id: string;
|
|
20
|
+
}
|
|
21
|
+
export declare enum ExtensionType {
|
|
22
|
+
pjmProjectPage = "pjm:project-page"
|
|
23
|
+
}
|
|
24
|
+
export interface ExtensionData {
|
|
25
|
+
type: ExtensionType;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
export interface NexusContext {
|
|
29
|
+
appId: string;
|
|
30
|
+
appVersion: string;
|
|
31
|
+
team: Team;
|
|
32
|
+
user: User;
|
|
33
|
+
extension: Extension;
|
|
34
|
+
extensionData: ExtensionData;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/lib/context.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACjB,GAAG,EAAE,MAAM,CAAC;IAEZ,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,MAAM,CAAC;IAEf,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,IAAI;IACjB,GAAG,EAAE,MAAM,CAAC;IAEZ,IAAI,EAAE,MAAM,CAAC;IAEb,YAAY,EAAE,MAAM,CAAC;IAErB,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,CAAC;IAEX,cAAc,EAAE,MAAM,CAAC;IAEvB,gBAAgB,EAAE,MAAM,CAAC;IAEzB,eAAe,EAAE,MAAM,CAAC;CAC3B;AAED,oBAAY,aAAa;IACrB,cAAc,qBAAqB;CACtC;AAED,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,aAAa,CAAC;IAEpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,MAAM,CAAC;IAEd,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,EAAE,IAAI,CAAC;IAEX,IAAI,EAAE,IAAI,CAAC;IAEX,SAAS,EAAE,SAAS,CAAC;IAErB,aAAa,EAAE,aAAa,CAAC;CAChC"}
|
package/lib/context.js
ADDED
package/lib/handler.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { NexusContext } from "./context.js";
|
|
2
|
+
export interface HandlerFunctionEvent {
|
|
3
|
+
id: string;
|
|
4
|
+
type: string;
|
|
5
|
+
payload: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface HandlerFunction {
|
|
8
|
+
(context: NexusContext, event: HandlerFunctionEvent): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare class Handler {
|
|
11
|
+
#private;
|
|
12
|
+
constructor();
|
|
13
|
+
define(key: string, fn: HandlerFunction): this;
|
|
14
|
+
invoke(key: string, context: NexusContext, event: HandlerFunctionEvent): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/lib/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,WAAW,oBAAoB;IACjC,EAAE,EAAE,MAAM,CAAC;IAEX,IAAI,EAAE,MAAM,CAAC;IAEb,OAAO,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC5B,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE;AAED,qBAAa,OAAO;;;IAOT,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,eAAe,GAAG,IAAI;IAKxC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CAOtG"}
|
package/lib/handler.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class Handler {
|
|
2
|
+
#handlers;
|
|
3
|
+
constructor() {
|
|
4
|
+
this.#handlers = {};
|
|
5
|
+
}
|
|
6
|
+
define(key, fn) {
|
|
7
|
+
this.#handlers[key] = fn;
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
async invoke(key, context, event) {
|
|
11
|
+
const fn = this.#handlers[key];
|
|
12
|
+
if (!fn) {
|
|
13
|
+
throw new Error(`Cannot find function by key "${key}"`);
|
|
14
|
+
}
|
|
15
|
+
await fn(context, event);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { NexusContext } from "./context.js";
|
|
2
|
+
export interface ResolverFunction<P, R> {
|
|
3
|
+
(context: NexusContext, payload: P): Promise<R>;
|
|
4
|
+
}
|
|
5
|
+
export declare class Resolver {
|
|
6
|
+
#private;
|
|
7
|
+
constructor();
|
|
8
|
+
define<P, R>(key: string, fn: ResolverFunction<P, R>): this;
|
|
9
|
+
invoke<P, R>(key: string, context: NexusContext, payload: P): Promise<R>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/lib/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,WAAW,gBAAgB,CAAC,CAAC,EAAE,CAAC;IAClC,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACnD;AAED,qBAAa,QAAQ;;;IAOV,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI;IAKrD,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAQxF"}
|
package/lib/resolver.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class Resolver {
|
|
2
|
+
#functions;
|
|
3
|
+
constructor() {
|
|
4
|
+
this.#functions = {};
|
|
5
|
+
}
|
|
6
|
+
define(key, fn) {
|
|
7
|
+
this.#functions[key] = fn;
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
async invoke(key, context, payload) {
|
|
11
|
+
const fn = this.#functions[key];
|
|
12
|
+
if (!fn) {
|
|
13
|
+
throw new Error(`Cannot find function by key "${key}"`);
|
|
14
|
+
}
|
|
15
|
+
const result = await fn(context, payload);
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pc-nexus/core",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,9 +19,6 @@
|
|
|
19
19
|
"test": "test",
|
|
20
20
|
"lib": "dist"
|
|
21
21
|
},
|
|
22
|
-
"files": [
|
|
23
|
-
"dist"
|
|
24
|
-
],
|
|
25
22
|
"types": "index.d.ts",
|
|
26
23
|
"exports": {
|
|
27
24
|
".": {
|