@pc-nexus/internal 0.5.0-next.10

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 ADDED
@@ -0,0 +1,3 @@
1
+ # Nexus Internal Definitions
2
+
3
+ Shared runtime and server definitions for Nexus packages.
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./lib/common.js";
2
+ export * from "./lib/context.js";
3
+ export * from "./lib/handler.js";
4
+ export * from "./lib/resolver.js";
5
+ export * from "./lib/error.js";
6
+ export * from "./lib/code.js";
7
+ export * from "./lib/error-type.js";
8
+ export * from "./lib/gateway.js";
9
+ export * from "./lib/event.js";
10
+ //# sourceMappingURL=index.d.ts.map
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;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * from "./lib/common.js";
2
+ export * from "./lib/context.js";
3
+ export * from "./lib/handler.js";
4
+ export * from "./lib/resolver.js";
5
+ export * from "./lib/error.js";
6
+ export * from "./lib/code.js";
7
+ export * from "./lib/error-type.js";
8
+ export * from "./lib/gateway.js";
9
+ export * from "./lib/event.js";
package/lib/code.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ declare enum NexusCode {
2
+ ok = 200,
3
+ notFound = 404,
4
+ methodNotAllowed = 405,
5
+ invalidInput = 400,
6
+ unauthorized = 401,
7
+ forbidden = 403,
8
+ internalError = 500
9
+ }
10
+ export declare enum NexusHttpStatusCode {
11
+ ok = 200,
12
+ badRequest = 400,
13
+ unauthorized = 401,
14
+ notFound = 404,
15
+ methodNotAllowed = 405,
16
+ internalError = 500,
17
+ noContent = 204
18
+ }
19
+ export { NexusCode };
20
+ //# sourceMappingURL=code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/lib/code.ts"],"names":[],"mappings":"AAAA,aAAK,SAAS;IACV,EAAE,MAAM;IACR,QAAQ,MAAM;IACd,gBAAgB,MAAM;IACtB,YAAY,MAAM;IAClB,YAAY,MAAM;IAClB,SAAS,MAAM;IACf,aAAa,MAAM;CACtB;AAED,oBAAY,mBAAmB;IAC3B,EAAE,MAAM;IACR,UAAU,MAAM;IAChB,YAAY,MAAM;IAClB,QAAQ,MAAM;IACd,gBAAgB,MAAM;IACtB,aAAa,MAAM;IACnB,SAAS,MAAM;CAClB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
package/lib/code.js ADDED
@@ -0,0 +1,21 @@
1
+ var NexusCode;
2
+ (function (NexusCode) {
3
+ NexusCode[NexusCode["ok"] = 200] = "ok";
4
+ NexusCode[NexusCode["notFound"] = 404] = "notFound";
5
+ NexusCode[NexusCode["methodNotAllowed"] = 405] = "methodNotAllowed";
6
+ NexusCode[NexusCode["invalidInput"] = 400] = "invalidInput";
7
+ NexusCode[NexusCode["unauthorized"] = 401] = "unauthorized";
8
+ NexusCode[NexusCode["forbidden"] = 403] = "forbidden";
9
+ NexusCode[NexusCode["internalError"] = 500] = "internalError";
10
+ })(NexusCode || (NexusCode = {}));
11
+ export var NexusHttpStatusCode;
12
+ (function (NexusHttpStatusCode) {
13
+ NexusHttpStatusCode[NexusHttpStatusCode["ok"] = 200] = "ok";
14
+ NexusHttpStatusCode[NexusHttpStatusCode["badRequest"] = 400] = "badRequest";
15
+ NexusHttpStatusCode[NexusHttpStatusCode["unauthorized"] = 401] = "unauthorized";
16
+ NexusHttpStatusCode[NexusHttpStatusCode["notFound"] = 404] = "notFound";
17
+ NexusHttpStatusCode[NexusHttpStatusCode["methodNotAllowed"] = 405] = "methodNotAllowed";
18
+ NexusHttpStatusCode[NexusHttpStatusCode["internalError"] = 500] = "internalError";
19
+ NexusHttpStatusCode[NexusHttpStatusCode["noContent"] = 204] = "noContent";
20
+ })(NexusHttpStatusCode || (NexusHttpStatusCode = {}));
21
+ export { NexusCode };
@@ -0,0 +1,4 @@
1
+ export declare const NEXUS_CONTEXT_TOKEN_HEADER_KEY = "x-nexus-context-token";
2
+ export declare const GLOBAL_KEY_NEXUS_RUNTIME = "__nexus_runtime__";
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;AAEtE,eAAO,MAAM,wBAAwB,sBAAsB,CAAC;AAE5D,eAAO,MAAM,MAAM,GAAI,SAAS,MAAM,EAAE,UAAU,MAAM,EAAE,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CACb,CAAC"}
package/lib/common.js ADDED
@@ -0,0 +1,3 @@
1
+ export const NEXUS_CONTEXT_TOKEN_HEADER_KEY = "x-nexus-context-token";
2
+ export const GLOBAL_KEY_NEXUS_RUNTIME = "__nexus_runtime__";
3
+ export const invoke = (gateway, endpoint, payload) => global[GLOBAL_KEY_NEXUS_RUNTIME].invoke(gateway, endpoint, payload);
@@ -0,0 +1,53 @@
1
+ export interface Team {
2
+ id: string;
3
+ url: string;
4
+ locale: string;
5
+ timezone: string;
6
+ }
7
+ export interface User {
8
+ id: string;
9
+ locale: string;
10
+ timezone: string;
11
+ }
12
+ export interface Extension {
13
+ key: string;
14
+ local_id: string;
15
+ target: string;
16
+ location: string;
17
+ data?: Record<string, unknown>;
18
+ }
19
+ export declare enum EnvironmentType {
20
+ development = "development",
21
+ production = "production"
22
+ }
23
+ export interface NexusAppContext {
24
+ app: {
25
+ id: string;
26
+ version: string;
27
+ };
28
+ environment: {
29
+ id: string;
30
+ type: EnvironmentType;
31
+ };
32
+ team: Team;
33
+ installation: {
34
+ id: string;
35
+ };
36
+ invocation: {
37
+ id: string;
38
+ };
39
+ user?: User;
40
+ extension?: Extension;
41
+ event?: {
42
+ trigger: {
43
+ key: string;
44
+ type: string;
45
+ };
46
+ };
47
+ }
48
+ export interface NexusRequestContext extends NexusAppContext {
49
+ functionsKeyHandlerMap: Record<string, string>;
50
+ }
51
+ export type NexusRequestContextRaw = NexusRequestContext;
52
+ export type NexusRequestEventContextRaw = Omit<NexusRequestContextRaw, "extension">;
53
+ //# 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,EAAE,EAAE,MAAM,CAAC;IAEX,GAAG,EAAE,MAAM,CAAC;IAEZ,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,IAAI;IACjB,EAAE,EAAE,MAAM,CAAC;IAEX,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,oBAAY,eAAe;IACvB,WAAW,gBAAgB;IAE3B,UAAU,eAAe;CAC5B;AAED,MAAM,WAAW,eAAe;IAC5B,GAAG,EAAE;QACD,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,WAAW,EAAE;QACT,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,eAAe,CAAC;KACzB,CAAC;IACF,IAAI,EAAE,IAAI,CAAC;IACX,YAAY,EAAE;QACV,EAAE,EAAE,MAAM,CAAC;KACd,CAAC;IACF,UAAU,EAAE;QACR,EAAE,EAAE,MAAM,CAAC;KACd,CAAC;IAEF,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,KAAK,CAAC,EAAE;QACJ,OAAO,EAAE;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;KAC1C,CAAC;CACL;AAED,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IACxD,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClD;AAED,MAAM,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAEzD,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAAC,sBAAsB,EAAE,WAAW,CAAC,CAAC"}
package/lib/context.js ADDED
@@ -0,0 +1,5 @@
1
+ export var EnvironmentType;
2
+ (function (EnvironmentType) {
3
+ EnvironmentType["development"] = "development";
4
+ EnvironmentType["production"] = "production";
5
+ })(EnvironmentType || (EnvironmentType = {}));
@@ -0,0 +1,12 @@
1
+ /**
2
+ * SDK 内部的错误类型码
3
+ */
4
+ export declare enum NexusInnerErrorType {
5
+ invalidInput = "NEXUS_INNER_ERROR_TYPE_INVALID_INPUT",
6
+ networkInvalidInput = "NEXUS_INNER_ERROR_TYPE_NETWORK_INVALID_INPUT",
7
+ storageConditionBuilder = "NEXUS_INNER_ERROR_TYPE_STORAGE_CONDITION_BUILDER",
8
+ i18nTranslationLoaderError = "NEXUS_INNER_ERROR_TYPE_TRANSLATION_GETTER",
9
+ i18nTranslationLocaleInvalid = "NEXUS_INNER_ERROR_TYPE_TRANSLATION_LOCALE_INVALID",
10
+ eventPayloadInvalid = "NEXUS_INNER_ERROR_TYPE_EVENT_PAYLOAD_INVALID"
11
+ }
12
+ //# sourceMappingURL=error-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-type.d.ts","sourceRoot":"","sources":["../../src/lib/error-type.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,mBAAmB;IAC3B,YAAY,yCAAyC;IACrD,mBAAmB,iDAAiD;IACpE,uBAAuB,qDAAqD;IAC5E,0BAA0B,8CAA8C;IACxE,4BAA4B,sDAAsD;IAClF,mBAAmB,iDAAiD;CACvE"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * SDK 内部的错误类型码
3
+ */
4
+ export var NexusInnerErrorType;
5
+ (function (NexusInnerErrorType) {
6
+ NexusInnerErrorType["invalidInput"] = "NEXUS_INNER_ERROR_TYPE_INVALID_INPUT";
7
+ NexusInnerErrorType["networkInvalidInput"] = "NEXUS_INNER_ERROR_TYPE_NETWORK_INVALID_INPUT";
8
+ NexusInnerErrorType["storageConditionBuilder"] = "NEXUS_INNER_ERROR_TYPE_STORAGE_CONDITION_BUILDER";
9
+ NexusInnerErrorType["i18nTranslationLoaderError"] = "NEXUS_INNER_ERROR_TYPE_TRANSLATION_GETTER";
10
+ NexusInnerErrorType["i18nTranslationLocaleInvalid"] = "NEXUS_INNER_ERROR_TYPE_TRANSLATION_LOCALE_INVALID";
11
+ NexusInnerErrorType["eventPayloadInvalid"] = "NEXUS_INNER_ERROR_TYPE_EVENT_PAYLOAD_INVALID";
12
+ })(NexusInnerErrorType || (NexusInnerErrorType = {}));
package/lib/error.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { NexusCode } from "./code.js";
2
+ import { NexusInnerErrorType } from "./error-type.js";
3
+ /**
4
+ * NexusError 异常类
5
+ */
6
+ export declare class NexusError extends Error {
7
+ #private;
8
+ get code(): NexusCode;
9
+ get type(): string;
10
+ constructor(code: NexusCode, type: string, message: string);
11
+ }
12
+ export declare class NexusInnerError extends NexusError {
13
+ constructor(code: NexusCode, type: NexusInnerErrorType, message: string);
14
+ }
15
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/lib/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;;IAEjC,IAAW,IAAI,IAAI,SAAS,CAE3B;IAGD,IAAW,IAAI,IAAI,MAAM,CAExB;gBAEkB,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAKpE;AAED,qBAAa,eAAgB,SAAQ,UAAU;gBACxB,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM;CAGjF"}
package/lib/error.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * NexusError 异常类
3
+ */
4
+ export class NexusError extends Error {
5
+ #code;
6
+ get code() {
7
+ return this.#code;
8
+ }
9
+ #type;
10
+ get type() {
11
+ return this.#type;
12
+ }
13
+ constructor(code, type, message) {
14
+ super(message);
15
+ this.#code = code;
16
+ this.#type = type;
17
+ }
18
+ }
19
+ export class NexusInnerError extends NexusError {
20
+ constructor(code, type, message) {
21
+ super(code, type, message);
22
+ }
23
+ }
package/lib/event.d.ts ADDED
@@ -0,0 +1,82 @@
1
+ import { IncomingHttpHeaders } from "node:http";
2
+ import { HandlerFunctionEvent } from "./handler.js";
3
+ export interface AppEventPayload {
4
+ key: string;
5
+ }
6
+ export interface AppEventResult {
7
+ }
8
+ export interface EventPayload {
9
+ }
10
+ export interface LifecycleEventPayload extends EventPayload {
11
+ installation_id: string;
12
+ app: {
13
+ id: string;
14
+ version: string;
15
+ name: string;
16
+ publisher: string;
17
+ };
18
+ environment: {
19
+ id: string;
20
+ type: string;
21
+ name: string;
22
+ };
23
+ }
24
+ export interface LifecycleInstallEventPayload extends LifecycleEventPayload {
25
+ installed_by: string;
26
+ }
27
+ export interface LifecycleUninstallEventPayload extends LifecycleEventPayload {
28
+ uninstalled_by: string;
29
+ }
30
+ export interface LifecycleUpgradeEventPayload extends LifecycleEventPayload {
31
+ upgraded_by: string;
32
+ }
33
+ export declare enum SystemEventSource {
34
+ system = "system"
35
+ }
36
+ export interface SystemEventPayload extends EventPayload {
37
+ data: unknown;
38
+ source?: SystemEventSource;
39
+ }
40
+ export interface CreatedEventPayload extends SystemEventPayload {
41
+ }
42
+ export interface DeletedEventPayload extends SystemEventPayload {
43
+ }
44
+ export interface ViewedEventPayload extends SystemEventPayload {
45
+ }
46
+ export interface RestoredEventPayload extends SystemEventPayload {
47
+ }
48
+ export interface ArchivedEventPayload extends SystemEventPayload {
49
+ }
50
+ export interface ActivatedEventPayload extends SystemEventPayload {
51
+ }
52
+ export interface ChangedEventPayload extends SystemEventPayload {
53
+ changelog: {
54
+ origin?: unknown;
55
+ target?: unknown;
56
+ property?: {
57
+ id?: string;
58
+ key?: string;
59
+ name?: string;
60
+ };
61
+ };
62
+ }
63
+ export interface ScheduledEventPayload extends EventPayload {
64
+ }
65
+ export interface WebhookPayload extends EventPayload {
66
+ method: string;
67
+ path: string;
68
+ headers: IncomingHttpHeaders;
69
+ body: unknown;
70
+ queryParameters: Record<string, string | string[]>;
71
+ }
72
+ export interface NexusEventInvocation<TPayload extends EventPayload = EventPayload> extends HandlerFunctionEvent<TPayload> {
73
+ trigger: {
74
+ type: string;
75
+ key: string;
76
+ };
77
+ handler: {
78
+ function?: string;
79
+ endpoint?: string;
80
+ };
81
+ }
82
+ //# sourceMappingURL=event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/lib/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,WAAW,eAAe;IAC5B,GAAG,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;CAAG;AAElC,MAAM,WAAW,YAAY;CAAG;AAEhC,MAAM,WAAW,qBAAsB,SAAQ,YAAY;IACvD,eAAe,EAAE,MAAM,CAAC;IACxB,GAAG,EAAE;QACD,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,WAAW,EAAE;QACT,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KAChB,CAAC;CACL;AAED,MAAM,WAAW,4BAA6B,SAAQ,qBAAqB;IACvE,YAAY,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,8BAA+B,SAAQ,qBAAqB;IACzE,cAAc,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,4BAA6B,SAAQ,qBAAqB;IACvE,WAAW,EAAE,MAAM,CAAC;CACvB;AAED,oBAAY,iBAAiB;IACzB,MAAM,WAAW;CACpB;AAED,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACpD,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC9B;AAED,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;CAAG;AAClE,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;CAAG;AAClE,MAAM,WAAW,kBAAmB,SAAQ,kBAAkB;CAAG;AACjE,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;CAAG;AACnE,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;CAAG;AACnE,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;CAAG;AAEpE,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;IAC3D,SAAS,EAAE;QACP,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,QAAQ,CAAC,EAAE;YACP,EAAE,CAAC,EAAE,MAAM,CAAC;YACZ,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,IAAI,CAAC,EAAE,MAAM,CAAC;SACjB,CAAC;KACL,CAAC;CACL;AAED,MAAM,WAAW,qBAAsB,SAAQ,YAAY;CAAG;AAE9D,MAAM,WAAW,cAAe,SAAQ,YAAY;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,mBAAmB,CAAC;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,oBAAoB,CAAC,QAAQ,SAAS,YAAY,GAAG,YAAY,CAAE,SAAQ,oBAAoB,CAAC,QAAQ,CAAC;IACtH,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,OAAO,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACrD"}
package/lib/event.js ADDED
@@ -0,0 +1,4 @@
1
+ export var SystemEventSource;
2
+ (function (SystemEventSource) {
3
+ SystemEventSource["system"] = "system";
4
+ })(SystemEventSource || (SystemEventSource = {}));
@@ -0,0 +1,15 @@
1
+ export interface NexusGatewayEndpointError {
2
+ code: number;
3
+ message: string;
4
+ type: string;
5
+ }
6
+ export declare class NexusGatewayEndpointResponse<TValue = unknown, TReference = Record<string, unknown>> {
7
+ success: boolean;
8
+ value: TValue | null;
9
+ references?: TReference | undefined;
10
+ error?: NexusGatewayEndpointError | undefined;
11
+ constructor(success: boolean, value: TValue | null, references?: TReference | undefined, error?: NexusGatewayEndpointError | undefined);
12
+ static from<TValue = unknown, TReference = Record<string, unknown>>(value: TValue, references?: TReference): NexusGatewayEndpointResponse<TValue, TReference>;
13
+ static fromError(error: NexusGatewayEndpointError): NexusGatewayEndpointResponse<null, void>;
14
+ }
15
+ //# sourceMappingURL=gateway.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/lib/gateway.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,yBAAyB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,4BAA4B,CAAC,MAAM,GAAG,OAAO,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAEjF,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI;IACpB,UAAU,CAAC,EAAE,UAAU;IACvB,KAAK,CAAC,EAAE,yBAAyB;gBAHjC,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,UAAU,CAAC,EAAE,UAAU,YAAA,EACvB,KAAK,CAAC,EAAE,yBAAyB,YAAA;WAG9B,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrE,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,UAAU,GACxB,4BAA4B,CAAC,MAAM,EAAE,UAAU,CAAC;WAIrC,SAAS,CAAC,KAAK,EAAE,yBAAyB,GAAG,4BAA4B,CAAC,IAAI,EAAE,IAAI,CAAC;CAGtG"}
package/lib/gateway.js ADDED
@@ -0,0 +1,18 @@
1
+ export class NexusGatewayEndpointResponse {
2
+ success;
3
+ value;
4
+ references;
5
+ error;
6
+ constructor(success, value, references, error) {
7
+ this.success = success;
8
+ this.value = value;
9
+ this.references = references;
10
+ this.error = error;
11
+ }
12
+ static from(value, references) {
13
+ return new this(true, value, references);
14
+ }
15
+ static fromError(error) {
16
+ return new this(false, null, undefined, error);
17
+ }
18
+ }
@@ -0,0 +1,15 @@
1
+ import { OutgoingHttpHeaders } from "http";
2
+ import type { NexusAppContext } from "./context.js";
3
+ export interface HandlerFunctionEvent<T = unknown> {
4
+ event_type?: string;
5
+ payload: T;
6
+ }
7
+ export interface WebHookHandlerFunctionReturn {
8
+ statusCode: number;
9
+ headers: OutgoingHttpHeaders;
10
+ body: unknown;
11
+ }
12
+ export interface HandlerFunction<TPayload = unknown, TReturn = void> {
13
+ (context: NexusAppContext, event: HandlerFunctionEvent<TPayload>): Promise<TReturn>;
14
+ }
15
+ //# 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,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,OAAO;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,OAAO,EAAE,CAAC,CAAC;CACd;AAED,MAAM,WAAW,4BAA4B;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,IAAI,EAAE,OAAO,CAAC;CACjB;AACD,MAAM,WAAW,eAAe,CAAC,QAAQ,GAAG,OAAO,EAAE,OAAO,GAAG,IAAI;IAC/D,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACvF"}
package/lib/handler.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { NexusAppContext } from "./context.js";
2
+ export interface ResolverFunction<P, R> {
3
+ (context: NexusAppContext, payload: P): Promise<R>;
4
+ }
5
+ export declare class Resolver {
6
+ #private;
7
+ constructor();
8
+ define<P, R = unknown>(key: string, fn: ResolverFunction<P, R>): this;
9
+ invoke<P, R>(key: string, context: NexusAppContext, 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":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIpD,MAAM,WAAW,gBAAgB,CAAC,CAAC,EAAE,CAAC;IAClC,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACtD;AAQD,qBAAa,QAAQ;;;IAOV,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI;IAK/D,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAQ3F"}
@@ -0,0 +1,26 @@
1
+ import { NexusCode } from "./code.js";
2
+ import { NexusError } from "./error.js";
3
+ import { NexusInnerErrorType } from "./error-type.js";
4
+ class ResolverError extends NexusError {
5
+ constructor(message) {
6
+ super(NexusCode.invalidInput, NexusInnerErrorType.invalidInput, message);
7
+ }
8
+ }
9
+ export class Resolver {
10
+ #functions;
11
+ constructor() {
12
+ this.#functions = {};
13
+ }
14
+ define(key, fn) {
15
+ this.#functions[key] = fn;
16
+ return this;
17
+ }
18
+ async invoke(key, context, payload) {
19
+ const fn = this.#functions[key];
20
+ if (!fn) {
21
+ throw new ResolverError(`Cannot find function by key "${key}"`);
22
+ }
23
+ const result = await fn(context, payload);
24
+ return result;
25
+ }
26
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@pc-nexus/internal",
3
+ "version": "0.5.0-next.10",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "pub:alpha": "cd dist && npm publish --access public --tag alpha",
9
+ "pub": "cd dist && npm publish --access public --tag latest",
10
+ "pub-next": "cd dist && npm publish --access public --tag next"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/atinc/pc-nexus.git"
15
+ },
16
+ "author": "",
17
+ "license": "ISC",
18
+ "directories": {
19
+ "test": "test",
20
+ "lib": "dist"
21
+ },
22
+ "types": "index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "default": "./index.js",
26
+ "types": "./index.d.ts"
27
+ }
28
+ },
29
+ "type": "module",
30
+ "dependencies": {},
31
+ "devDependencies": {},
32
+ "peerDependencies": {}
33
+ }