@akanjs/signal 0.0.40 → 0.0.41

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.
@@ -1,420 +0,0 @@
1
- import { Dayjs } from 'dayjs';
2
- import { ReadStream } from 'fs';
3
- import { Readable } from 'stream';
4
- import { T as Type, G as GraphQLJSON, a as GraphQLUpload } from './types-b-U-yQib.js';
5
- import { Job as Job$1 } from 'bull';
6
- import { Request, Response } from 'express';
7
- import { Socket } from 'socket.io';
8
-
9
- declare class Enum<T> {
10
- readonly values: T[];
11
- readonly value: T;
12
- readonly valueMap: Map<T, number>;
13
- constructor(values: T[]);
14
- has(value: T): boolean;
15
- indexOf(value: T): number;
16
- find(callback: (value: T, index: number, array: T[]) => boolean): T;
17
- findIndex(callback: (value: T, index: number, array: T[]) => boolean): number;
18
- filter(callback: (value: T, index: number, array: T[]) => boolean): T[];
19
- map<R>(callback: (value: T, index: number, array: T[]) => R): R[];
20
- forEach(callback: (value: T, index: number, array: T[]) => void): void;
21
- }
22
- declare class DataList<Light extends {
23
- id: string;
24
- }> {
25
- #private;
26
- length: number;
27
- values: Light[];
28
- constructor(data?: Light[] | DataList<Light>);
29
- indexOf(id: string): number;
30
- set(value: Light): this;
31
- delete(id: string): this;
32
- get(id: string): Light | undefined;
33
- at(idx: number): Light | undefined;
34
- pickAt(idx: number): Light;
35
- pick(id: string): Light;
36
- has(id: string): boolean;
37
- find(fn: (value: Light, idx: number) => boolean): Light | undefined;
38
- findIndex(fn: (value: Light, idx: number) => boolean): number;
39
- some(fn: (value: Light, idx: number) => boolean): boolean;
40
- every(fn: (value: Light, idx: number) => boolean): boolean;
41
- forEach(fn: (value: Light, idx: number) => void): void;
42
- map<T>(fn: (value: Light, idx: number) => T): T[];
43
- flatMap<T>(fn: (value: Light, idx: number, array: Light[]) => T | readonly T[]): T[];
44
- sort(fn: (a: Light, b: Light) => number): DataList<Light>;
45
- filter(fn: (value: Light, idx: number) => boolean): DataList<Light>;
46
- reduce<T>(fn: (acc: T, value: Light, idx: number) => T, initialValue: T): T;
47
- slice(start: number, end?: number): DataList<Light>;
48
- save(): DataList<Light>;
49
- [Symbol.iterator](): ArrayIterator<Light>;
50
- }
51
-
52
- type Environment = "testing" | "debug" | "develop" | "main";
53
-
54
- declare class BaseObject {
55
- id: string;
56
- createdAt: Dayjs;
57
- updatedAt: Dayjs;
58
- removedAt: Dayjs | null;
59
- }
60
- declare class Int {
61
- __Scalar__: "int";
62
- }
63
- declare class Upload {
64
- __Scalar__: "upload";
65
- filename: string;
66
- mimetype: string;
67
- encoding: string;
68
- createReadStream: () => ReadStream | Readable;
69
- }
70
- declare class Float {
71
- __Scalar__: "float";
72
- }
73
- declare class ID {
74
- __Scalar__: "id";
75
- }
76
- declare class JSON {
77
- __Scalar__: "json";
78
- }
79
- type SingleFieldType = Int | Float | StringConstructor | BooleanConstructor | ID | DateConstructor | JSON | Type | GraphQLJSON | GraphQLUpload;
80
-
81
- type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
82
- type OptionalKeys<T> = T extends {
83
- [key: string]: any;
84
- } ? {
85
- [K in keyof T]-?: null extends T[K] ? K : never;
86
- }[keyof T] : never;
87
- type ObjectToId<O, D = Dayjs> = O extends BaseObject ? string : O extends BaseObject[] ? string[] : O extends Dayjs ? D : O extends {
88
- [key: string]: any;
89
- } ? DocumentModel<O> : O;
90
- type SortOf<Filter> = keyof GetStateObject<Filter>;
91
- type FilterType = Record<string, any>;
92
- type DocumentModel<T, D = Dayjs> = T extends (infer S)[] ? DocumentModel<S>[] : T extends string ? T : T extends number ? T : T extends boolean ? T : T extends Dayjs ? T : T extends Map<infer K, infer V> ? Map<K, DocumentModel<V, D>> : Optional<{
93
- [K in keyof GetStateObject<T>]: T[K] extends infer S ? S extends null ? undefined : ObjectToId<T[K], D> : never;
94
- }, OptionalKeys<GetStateObject<T>>>;
95
- type GetStateObject<T> = Omit<{
96
- [K in keyof T as T[K] extends (...args: any) => any ? never : K]: T[K];
97
- }, "prototype">;
98
- type GetActionObject<T> = Omit<{
99
- [K in keyof T as T[K] extends (...args: any) => any ? K : never]: T[K];
100
- }, "prototype">;
101
- interface ProtoFile {
102
- id: string;
103
- filename: string;
104
- abstractData: string | null;
105
- imageSize: [number, number];
106
- progress: number | null;
107
- url: string;
108
- size: number;
109
- status: string;
110
- createdAt: Dayjs;
111
- updatedAt: Dayjs;
112
- removedAt: Dayjs | null;
113
- mimetype: string;
114
- encoding: string;
115
- origin: string | null;
116
- lastModifiedAt: Dayjs;
117
- }
118
-
119
- type ReturnType<T extends SingleFieldType = SingleFieldType> = (of?: any) => T | [T] | [[T]] | Map<string, any>;
120
-
121
- interface ConstantModel<T extends string, Input, Full, Light, Insight, Filter extends FilterType, Summary = any> {
122
- refName: T;
123
- Input: Type<Input>;
124
- Full: Type<Full>;
125
- Light: Type<Light>;
126
- Insight: Type<Insight>;
127
- Filter: Type<Filter>;
128
- Summary?: Type<Summary>;
129
- }
130
-
131
- declare const ssoTypes: readonly ["github", "google", "facebook", "apple", "naver", "kakao"];
132
- type SSOType = (typeof ssoTypes)[number];
133
- declare class SignalStorage {
134
- }
135
- declare const getAllSignalRefs: () => Type[];
136
- declare const getSignalRefsOnStorage: (refName: string) => Type[];
137
- type Resolve<T> = T;
138
- declare const resolve: <T>(data: any) => Resolve<T>;
139
- declare const emit: <T>(data: any) => Resolve<T> & {
140
- __Returns__: "Emit";
141
- };
142
- declare const done: <T>(data: any) => Resolve<T> & {
143
- __Returns__: "Done";
144
- };
145
- declare const subscribe: <T>() => Resolve<T> & {
146
- __Returns__: "Subscribe";
147
- };
148
- interface SignalOption<Response = any> {
149
- nullable?: boolean;
150
- name?: string;
151
- default?: boolean;
152
- path?: string;
153
- onlyFor?: "graphql" | "restapi";
154
- sso?: SSOType;
155
- serverType?: "federation" | "batch" | "all";
156
- timeout?: number;
157
- partial?: (keyof Response)[] | readonly (keyof Response)[];
158
- cache?: number;
159
- }
160
- interface ResolveFieldMeta {
161
- returns: ReturnType;
162
- argsOption: ArgsOption;
163
- key: string;
164
- descriptor: PropertyDescriptor;
165
- }
166
- declare const signalTypes: readonly ["graphql", "restapi"];
167
- type SignalType = (typeof signalTypes)[number];
168
- declare const endpointTypes: readonly ["Query", "Mutation", "Message", "Pubsub", "Process"];
169
- type EndpointType = (typeof endpointTypes)[number];
170
- declare const guardTypes: readonly ["Public", "None", "User", "Admin", "SuperAdmin", "Every", "Owner"];
171
- type GuardType = (typeof guardTypes)[number];
172
- declare const roleTypes: readonly ["Public", "User", "Admin", "SuperAdmin"];
173
- type RoleType = (typeof roleTypes)[number];
174
- declare const argTypes: readonly ["Body", "Param", "Query", "Upload", "Msg", "Room"];
175
- type ArgType = (typeof argTypes)[number];
176
- declare const internalArgTypes: readonly ["Account", "Me", "Self", "UserIp", "Access", "Parent", "Req", "Res", "Ws", "Job"];
177
- type InternalArgType = (typeof internalArgTypes)[number];
178
- interface GqlMeta {
179
- returns: (of?: any) => Type;
180
- signalOption: SignalOption;
181
- key: string;
182
- descriptor: PropertyDescriptor;
183
- guards: GuardType[];
184
- type: EndpointType;
185
- }
186
- interface ArgsOption {
187
- nullable?: boolean;
188
- example?: string | number | boolean | Dayjs;
189
- enum?: Enum<string | number>;
190
- }
191
- interface ArgMeta {
192
- name: string;
193
- returns: ReturnType;
194
- argsOption: ArgsOption;
195
- key: string;
196
- idx: number;
197
- type: ArgType;
198
- }
199
- interface InternalArgMeta {
200
- key: string;
201
- idx: number;
202
- type: InternalArgType;
203
- option?: {
204
- nullable?: boolean;
205
- };
206
- }
207
- interface SliceMeta {
208
- refName: string;
209
- sliceName: string;
210
- argLength: number;
211
- defaultArgs: any[];
212
- }
213
- interface SignalMeta {
214
- refName: string;
215
- slices: SliceMeta[];
216
- returns?: (of?: any) => Type;
217
- prefix?: string;
218
- }
219
- interface SignalDecoratorInput {
220
- name: string;
221
- prefix?: string;
222
- }
223
- declare function Signal(returnsOrObj: (() => Type) | SignalDecoratorInput): (target: Type) => void;
224
- declare const createArgMetaDecorator: (type: InternalArgType) => (option?: {
225
- nullable?: boolean;
226
- }) => (prototype: object, key: string, idx: number) => void;
227
- declare const Account: (option?: {
228
- nullable?: boolean;
229
- }) => (prototype: object, key: string, idx: number) => void;
230
- type Account<AddData = unknown> = {
231
- __InternalArg__: "Account";
232
- self?: Self;
233
- me?: Me;
234
- appName: string;
235
- environment: Environment;
236
- } & AddData;
237
- declare const defaultAccount: Account;
238
- declare const Self: (option?: {
239
- nullable?: boolean;
240
- }) => (prototype: object, key: string, idx: number) => void;
241
- interface Self {
242
- __InternalArg__: "Self";
243
- id: string;
244
- nickname: string;
245
- roles: string[];
246
- image: {
247
- url: string;
248
- imageSize: [number, number];
249
- } | null;
250
- profileStatus: "active" | "prepare" | "applied" | "approved" | "reapplied" | "featured" | "reserved" | "rejected";
251
- status: "prepare" | "active" | "restricted" | "dormant";
252
- removedAt: Dayjs | null;
253
- }
254
- declare const Me: (option?: {
255
- nullable?: boolean;
256
- }) => (prototype: object, key: string, idx: number) => void;
257
- interface Me {
258
- __InternalArg__: "Me";
259
- id: string;
260
- accountId: string;
261
- roles: string[];
262
- status: "active";
263
- removedAt: Dayjs | null;
264
- }
265
- declare const UserIp: (option?: {
266
- nullable?: boolean;
267
- }) => (prototype: object, key: string, idx: number) => void;
268
- interface UserIp {
269
- ip: string;
270
- __InternalArg__: "UserIp";
271
- }
272
- declare const Access: (option?: {
273
- nullable?: boolean;
274
- }) => (prototype: object, key: string, idx: number) => void;
275
- interface Access {
276
- __InternalArg__: "Access";
277
- period: number;
278
- countryCode?: string;
279
- countryName?: string;
280
- city?: string;
281
- postal?: number;
282
- location?: {
283
- type: "Point";
284
- coordinates: [number, number];
285
- };
286
- ipv4?: string;
287
- state?: string;
288
- userAgent?: string;
289
- at: Dayjs;
290
- }
291
- declare const Req: (option?: {
292
- nullable?: boolean;
293
- }) => (prototype: object, key: string, idx: number) => void;
294
- type Req = {
295
- __InternalArg__: "Req";
296
- account: Account;
297
- user: any;
298
- } & Request;
299
- declare const Res: (option?: {
300
- nullable?: boolean;
301
- }) => (prototype: object, key: string, idx: number) => void;
302
- type Res = {
303
- __InternalArg__: "Res";
304
- } & Response;
305
- declare const Ws: (option?: {
306
- nullable?: boolean;
307
- }) => (prototype: object, key: string, idx: number) => void;
308
- type Ws = {
309
- __InternalArg__: "Ws";
310
- } & {
311
- socket: Socket;
312
- subscribe: boolean;
313
- onSubscribe: (handler: () => void | Promise<void>) => void;
314
- onUnsubscribe: (handler: () => void | Promise<void>) => void;
315
- onDisconnect: (handler: () => void | Promise<void>) => void;
316
- };
317
- declare const Job: (option?: {
318
- nullable?: boolean;
319
- }) => (prototype: object, key: string, idx: number) => void;
320
- type Job = {
321
- __InternalArg__: "Job";
322
- } & Job$1;
323
- type Guard = <Response extends SingleFieldType>(returns: ReturnType<Response>, signalOption?: SignalOption<UnType<Response>>, guards?: GuardType[]) => MethodDecorator;
324
- declare const Query: {
325
- Public: Guard;
326
- Every: Guard;
327
- Admin: Guard;
328
- User: Guard;
329
- SuperAdmin: Guard;
330
- None: Guard;
331
- Owner: Guard;
332
- };
333
- declare const Mutation: {
334
- Public: Guard;
335
- Every: Guard;
336
- Admin: Guard;
337
- User: Guard;
338
- SuperAdmin: Guard;
339
- None: Guard;
340
- Owner: Guard;
341
- };
342
- declare const Message: {
343
- Public: Guard;
344
- Every: Guard;
345
- Admin: Guard;
346
- User: Guard;
347
- SuperAdmin: Guard;
348
- None: Guard;
349
- Owner: Guard;
350
- };
351
- declare const Pubsub: {
352
- Public: Guard;
353
- Every: Guard;
354
- Admin: Guard;
355
- User: Guard;
356
- SuperAdmin: Guard;
357
- None: Guard;
358
- Owner: Guard;
359
- };
360
- declare const Process: {
361
- Federation: Guard;
362
- Batch: Guard;
363
- All: Guard;
364
- };
365
- declare function ResolveField(returns: ReturnType, argsOption?: ArgsOption): (target: any, key: string, descriptor: PropertyDescriptor) => void;
366
- declare const Arg: {
367
- Body: (name: string, returns: ReturnType, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
368
- Param: (name: string, returns: ReturnType, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
369
- Query: (name: string, returns: ReturnType, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
370
- Upload: (name: string, returns: ReturnType, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
371
- Msg: (name: string, returns: ReturnType, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
372
- Room: (name: string, returns: ReturnType, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
373
- };
374
- declare function Parent(): (prototype: object, key: string, idx: number) => void;
375
- declare function LogSignal<Srv>(srv: Srv): Type<{ [K in keyof Srv as K extends string ? Uncapitalize<K> : never]: Srv[K]; }>;
376
- type UnType<Class> = Class extends Type<infer T> ? T : never;
377
- type DefaultSignal<T extends string, Input, Full, Light, Insight, Filter extends FilterType> = DefaultSignalWithQuerySort<T, Input, Full, Light, Insight, GetActionObject<Filter>, SortOf<Filter>>;
378
- type DefaultSignalWithQuerySort<T extends string, Input, Full, Light, Insight, Query, Sort> = {
379
- [K in Uncapitalize<T>]: (id: string) => Promise<Full>;
380
- } & {
381
- [K in `light${Capitalize<T>}`]: (id: string) => Promise<Light>;
382
- } & {
383
- [K in `${Uncapitalize<T>}List`]: (...args: [query: Query, skip: number | null, limit: number | null, sort: Sort | null]) => Promise<Full[]>;
384
- } & {
385
- [K in `${Uncapitalize<T>}Insight`]: (query: Query) => Promise<Insight>;
386
- } & {
387
- [K in `${Uncapitalize<T>}Exists`]: (query: Query) => Promise<boolean>;
388
- } & {
389
- [K in `create${Capitalize<T>}`]: (data: DocumentModel<Input>, account: Account) => Promise<Full>;
390
- } & {
391
- [K in `update${Capitalize<T>}`]: (id: string, data: DocumentModel<Input>, account: Account) => Promise<Full>;
392
- } & {
393
- [K in `remove${Capitalize<T>}`]: (id: string, account: Account) => Promise<Full>;
394
- };
395
- declare function DbSignal<Srv>(constant: ConstantModel<string, any, BaseObject & {
396
- status: string;
397
- }, BaseObject, {
398
- count: number;
399
- }, any>, srv: Srv, option: {
400
- guards: {
401
- get: Guard;
402
- cru: Guard;
403
- };
404
- omit?: ("get" | "list" | "insight" | "exist" | "create" | "update" | "remove")[];
405
- }): Type<{ [K in keyof Srv as K extends string ? Uncapitalize<K> : never]: Srv[K]; }>;
406
- declare const getSigMeta: (sigRef: Type) => SignalMeta;
407
- declare const getGqlMeta: (sigRef: Type, key: string) => GqlMeta;
408
- declare const getGqlMetaMapOnPrototype: (prototype: object) => Map<string, GqlMeta>;
409
- declare const getGqlMetas: (sigRef: Type) => GqlMeta[];
410
- declare const setGqlMetaMapOnPrototype: (prototype: object, gqlMetaMap: Map<string, GqlMeta>) => void;
411
- declare const getArgMetas: (sigRef: Type, key: string) => [ArgMeta[], InternalArgMeta[]];
412
- declare const setArgMetas: (sigRef: Type, key: string, argMetas: ArgMeta[], internalArgMetas: InternalArgMeta[]) => void;
413
- declare const getResolveFieldMetas: (sigRef: Type) => ResolveFieldMeta[];
414
- declare const getControllerPrefix: (sigMeta: SignalMeta) => string | undefined;
415
- declare const getControllerPath: (gqlMeta: GqlMeta, paramArgMetas: ArgMeta[]) => string;
416
- declare const copySignal: (sigRef: Type) => {
417
- new (): {};
418
- };
419
-
420
- export { getSigMeta as $, type ArgType as A, Account as B, defaultAccount as C, Self as D, type EndpointType as E, Access as F, type GuardType as G, Req as H, type InternalArgType as I, Res as J, Job as K, Mutation as L, Me as M, Message as N, Process as O, Pubsub as P, Query as Q, type Resolve as R, type SSOType as S, ResolveField as T, UserIp as U, Arg as V, Ws as W, Parent as X, LogSignal as Y, type DefaultSignal as Z, DbSignal as _, SignalStorage as a, getGqlMeta as a0, getGqlMetaMapOnPrototype as a1, getGqlMetas as a2, setGqlMetaMapOnPrototype as a3, getArgMetas as a4, setArgMetas as a5, getResolveFieldMetas as a6, getControllerPrefix as a7, getControllerPath as a8, copySignal as a9, type DocumentModel as aa, type FilterType as ab, type SortOf as ac, Upload as ad, type ProtoFile as ae, DataList as af, type ConstantModel as ag, getSignalRefsOnStorage as b, subscribe as c, done as d, emit as e, type SignalOption as f, getAllSignalRefs as g, type ResolveFieldMeta as h, signalTypes as i, type SignalType as j, endpointTypes as k, guardTypes as l, roleTypes as m, type RoleType as n, argTypes as o, internalArgTypes as p, type GqlMeta as q, resolve as r, ssoTypes as s, type ArgsOption as t, type ArgMeta as u, type InternalArgMeta as v, type SliceMeta as w, type SignalMeta as x, Signal as y, createArgMetaDecorator as z };
package/src/baseFetch.js DELETED
@@ -1,39 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var baseFetch_exports = {};
20
- __export(baseFetch_exports, {
21
- baseFetch: () => baseFetch
22
- });
23
- module.exports = __toCommonJS(baseFetch_exports);
24
- var import_client = require("./client");
25
- const nativeFetch = fetch;
26
- const baseFetch = Object.assign(nativeFetch, {
27
- client: import_client.client,
28
- clone: /* @__PURE__ */ __name(function(option = {}) {
29
- return {
30
- ...this,
31
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
32
- client: this.client.clone(option)
33
- };
34
- }, "clone")
35
- });
36
- // Annotate the CommonJS export names for ESM import in node:
37
- 0 && (module.exports = {
38
- baseFetch
39
- });
package/src/client.js DELETED
@@ -1,198 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var client_exports = {};
20
- __export(client_exports, {
21
- client: () => client
22
- });
23
- module.exports = __toCommonJS(client_exports);
24
- var import_base = require("@akanjs/base");
25
- var import_common = require("@akanjs/common");
26
- var import_core = require("@urql/core");
27
- var import_socket = require("socket.io-client");
28
- let SocketIo = class SocketIo2 {
29
- static {
30
- __name(this, "SocketIo");
31
- }
32
- socket;
33
- roomSubscribeMap = /* @__PURE__ */ new Map();
34
- constructor(uri) {
35
- this.socket = (0, import_socket.io)(uri, {
36
- transports: [
37
- "websocket"
38
- ]
39
- });
40
- this.socket.on("connect", () => {
41
- this.roomSubscribeMap.forEach((option) => {
42
- this.socket.emit(option.key, {
43
- ...option.message,
44
- __subscribe__: true
45
- });
46
- });
47
- });
48
- }
49
- on(event, callback) {
50
- this.socket.on(event, callback);
51
- }
52
- removeListener(event, callback) {
53
- this.socket.removeListener(event, callback);
54
- }
55
- removeAllListeners() {
56
- this.socket.removeAllListeners();
57
- }
58
- hasListeners(event) {
59
- return this.socket.hasListeners(event);
60
- }
61
- emit(key, data) {
62
- this.socket.emit(key, data);
63
- }
64
- subscribe(option) {
65
- if (!this.roomSubscribeMap.has(option.roomId)) {
66
- this.roomSubscribeMap.set(option.roomId, option);
67
- this.socket.emit(option.key, {
68
- ...option.message,
69
- __subscribe__: true
70
- });
71
- }
72
- this.socket.on(option.roomId, option.handleEvent);
73
- }
74
- unsubscribe(roomId, handleEvent) {
75
- this.socket.removeListener(roomId, handleEvent);
76
- const option = this.roomSubscribeMap.get(roomId);
77
- if (this.hasListeners(roomId) || !option) return;
78
- this.roomSubscribeMap.delete(roomId);
79
- this.socket.emit(option.key, {
80
- ...option.message,
81
- __subscribe__: false
82
- });
83
- }
84
- disconnect() {
85
- this.socket.disconnect();
86
- return this;
87
- }
88
- };
89
- let Client = class Client2 {
90
- static {
91
- __name(this, "Client");
92
- }
93
- static globalIoMap = /* @__PURE__ */ new Map();
94
- static tokenStore = /* @__PURE__ */ new Map();
95
- async waitUntilWebSocketConnected(ws = import_base.baseClientEnv.serverWsUri) {
96
- if (import_base.baseClientEnv.side === "server") return true;
97
- while (!this.getIo(ws).socket.connected) {
98
- import_common.Logger.verbose("waiting for websocket to initialize...");
99
- await (0, import_common.sleep)(300);
100
- }
101
- }
102
- isInitialized = false;
103
- uri = import_base.baseClientEnv.serverGraphqlUri;
104
- ws = import_base.baseClientEnv.serverWsUri;
105
- udp = null;
106
- gql = (0, import_core.createClient)({
107
- url: this.uri,
108
- fetch,
109
- exchanges: [
110
- import_core.cacheExchange,
111
- import_core.fetchExchange
112
- ]
113
- });
114
- jwt = null;
115
- async getJwt() {
116
- const isNextServer = import_base.baseClientEnv.side === "server" && import_base.baseEnv.operationType === "client";
117
- if (isNextServer) {
118
- const nextHeaders = require("next/headers");
119
- return (await nextHeaders.cookies?.())?.get("jwt")?.value ?? (await nextHeaders.headers?.())?.get("jwt") ?? this.jwt ?? null;
120
- } else return Client2.tokenStore.get(this) ?? null;
121
- }
122
- io = null;
123
- init(data = {}) {
124
- Object.assign(this, data);
125
- this.setLink(data.uri);
126
- this.setIo(data.ws);
127
- this.isInitialized = true;
128
- }
129
- setIo(ws = import_base.baseClientEnv.serverWsUri) {
130
- this.ws = ws;
131
- const existingIo = Client2.globalIoMap.get(ws);
132
- if (existingIo) {
133
- this.io = existingIo;
134
- return;
135
- }
136
- this.io = new SocketIo(ws);
137
- Client2.globalIoMap.set(ws, this.io);
138
- }
139
- getIo(ws = import_base.baseClientEnv.serverWsUri) {
140
- const existingIo = Client2.globalIoMap.get(ws);
141
- if (existingIo) return existingIo;
142
- const io2 = new SocketIo(ws);
143
- Client2.globalIoMap.set(ws, io2);
144
- return io2;
145
- }
146
- setLink(uri = import_base.baseClientEnv.serverGraphqlUri) {
147
- this.uri = uri;
148
- this.gql = (0, import_core.createClient)({
149
- url: this.uri,
150
- fetch,
151
- exchanges: [
152
- import_core.cacheExchange,
153
- import_core.fetchExchange
154
- ],
155
- // requestPolicy: "network-only",
156
- fetchOptions: /* @__PURE__ */ __name(() => {
157
- return {
158
- headers: {
159
- "apollo-require-preflight": "true",
160
- ...this.jwt ? {
161
- authorization: `Bearer ${this.jwt}`
162
- } : {}
163
- }
164
- };
165
- }, "fetchOptions")
166
- });
167
- }
168
- setJwt(jwt) {
169
- Client2.tokenStore.set(this, jwt);
170
- }
171
- reset() {
172
- this.io?.disconnect();
173
- this.io = null;
174
- this.jwt = null;
175
- }
176
- clone(data = {}) {
177
- const newClient = new Client2();
178
- newClient.init({
179
- ...this,
180
- ...data
181
- });
182
- if (data.jwt) Client2.tokenStore.set(newClient, data.jwt);
183
- return newClient;
184
- }
185
- terminate() {
186
- this.reset();
187
- Client2.globalIoMap.forEach((io2) => io2.disconnect());
188
- this.isInitialized = false;
189
- }
190
- setUdp(udp) {
191
- this.udp = udp;
192
- }
193
- };
194
- const client = new Client();
195
- // Annotate the CommonJS export names for ESM import in node:
196
- 0 && (module.exports = {
197
- client
198
- });