@dnax/core 0.15.0 → 0.15.2

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,11 +1,15 @@
1
1
  import type { ServerWebSocket, WebSocketHandler, Server } from "bun";
2
2
  import { EventEmitter } from "events";
3
+ import { Cfg } from "../../config";
3
4
  import { v4 } from "uuid";
4
5
  const wsClients = new Map<string, ServerWebSocket>();
5
6
  const wsEvents: optionsIo[] = [];
6
7
 
7
8
  class Io {
8
- constructor() {}
9
+ id: string | null;
10
+ constructor() {
11
+ this.id = null;
12
+ }
9
13
  on(event: string, cb: Function) {
10
14
  wsEvents.push({
11
15
  type: "on",
@@ -13,16 +17,31 @@ class Io {
13
17
  cb: cb,
14
18
  });
15
19
  }
20
+ to(id: string) {
21
+ const newInstance = new Io();
22
+ newInstance.id = id;
23
+
24
+ return newInstance;
25
+ }
16
26
  emit(event: string, data: any) {
17
- wsEvents.push({
18
- type: "emit",
19
- event: event,
20
- data: data,
27
+ if (!this?.id || this.id == null) {
28
+ console.error("No id found");
29
+ }
30
+
31
+ if (this.id) {
32
+ let client = wsClients.get(this.id);
33
+ client?.send(JSON.stringify({ type: "emit", event, data }));
34
+ }
35
+ }
36
+ broadcast(event: string, data: any) {
37
+ wsClients.forEach((client) => {
38
+ client.send(JSON.stringify({ type: "emit", event, data }));
21
39
  });
22
40
  }
23
41
  }
24
42
 
25
43
  const io = new Io();
44
+ Cfg.io = io;
26
45
  type optionsIo = {
27
46
  type: "on" | "emit";
28
47
  event: string | "connection" | "close";
@@ -41,7 +60,7 @@ export type socketIoType = {
41
60
  emit: (event: string, data: any) => void;
42
61
  }) => void
43
62
  ) => void;
44
- emit: (event: string, data: any) => void;
63
+ emit: (event: string, id: string, data: any) => void;
45
64
  broadcast: (event: string, data: any) => void;
46
65
  };
47
66
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.ts CHANGED
@@ -102,7 +102,7 @@ export type Field = {
102
102
  nullable?: boolean;
103
103
  defaultValue?: any;
104
104
  unique?: boolean;
105
- index?: boolean | "text" | "2dsphere";
105
+ index?: boolean | "text" | "2dsphere" | "2d" | -1 | 1;
106
106
  description?: string;
107
107
  relation?: {
108
108
  to: string; // collection name
@@ -190,7 +190,7 @@ export type hooksCtx = (ctx: {
190
190
  c?: Context;
191
191
  rest: InstanceType<typeof useRest>;
192
192
  session?: sessionCtx;
193
- io: Io;
193
+ io: socketIoType;
194
194
  }) => any;
195
195
 
196
196
  export type ctxApi = {
@@ -296,6 +296,7 @@ export type Collection = {
296
296
  [key: string]: any;
297
297
  unique?: Boolean;
298
298
  expireAfterSeconds?: number;
299
+ partialFilterExpression?: any;
299
300
  }>;
300
301
  autoRemoveIndexes?: Array<{
301
302
  [key: string]: any;
@@ -437,7 +438,7 @@ export type routeOption = {
437
438
  */
438
439
  base: string; // base URL
439
440
  handler: (ctx: {
440
- io: Io;
441
+ io: socketIoType;
441
442
  router: {
442
443
  post: (path: string, clb: (c: Context) => void) => {};
443
444
  get: (path: string, clb: (c: Context) => void) => {};
@@ -449,7 +450,7 @@ export type endpointCtx = {
449
450
  enabled: boolean;
450
451
  handler: (ctx: {
451
452
  rest: InstanceType<typeof useRest>;
452
- io: Io;
453
+ io: socketIoType;
453
454
  router: {
454
455
  post: (path: string, clb: (c: Context) => void) => {};
455
456
  get: (path: string, clb: (c: Context) => void) => {};
@@ -461,7 +462,7 @@ export type routeCtx = {
461
462
  enabled: boolean;
462
463
  handler: (ctx: {
463
464
  rest: InstanceType<typeof useRest>;
464
- io: Io;
465
+ io: socketIoType;
465
466
  router: {
466
467
  post: (path: string, clb: (c: Context) => void) => {};
467
468
  get: (path: string, clb: (c: Context) => void) => {};
@@ -504,7 +505,7 @@ export type Service = {
504
505
  * authenticated user or no
505
506
  */
506
507
  isAuth: boolean;
507
- io: Io;
508
+ io: socketIoType;
508
509
  }) => any;
509
510
  exec?: (ctx: {
510
511
  /**
@@ -524,7 +525,7 @@ export type Service = {
524
525
  * authenticated user or no
525
526
  */
526
527
  isAuth: boolean;
527
- io: Io;
528
+ io: socketIoType;
528
529
  }) => any;
529
530
  };
530
531