@dnax/core 0.69.21 → 0.69.23

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/app/index.ts CHANGED
@@ -44,10 +44,6 @@ async function runApp(config?: configRunApp, clb?: Function): Promise<Server> {
44
44
  }
45
45
 
46
46
  if (available) {
47
- console.log("\n");
48
- let spinner = ora("Initializing...").start();
49
- spinner.color = "green";
50
-
51
47
  // Load all ressouce
52
48
  await init();
53
49
  const HonoApp = HonoInstance();
@@ -78,10 +74,8 @@ async function runApp(config?: configRunApp, clb?: Function): Promise<Server> {
78
74
  process.env.SERVER_NAME || Cfg?.server?.name || "SERVER";
79
75
 
80
76
  let envName = process.env?.NODE_ENV || "dev";
81
- spinner.clear();
82
- spinner.stop();
83
- await sleep(250);
84
77
 
78
+ await sleep(150);
85
79
  let info = "";
86
80
 
87
81
  info += `${serverName}`.gray.underline.bold;
package/define/index.ts CHANGED
@@ -13,6 +13,7 @@ import type {
13
13
  routeCtx,
14
14
  sessionCtx,
15
15
  Script,
16
+ TimeSeriesCollection,
16
17
  } from "../types";
17
18
  import { Cfg } from "../config/";
18
19
  import { deepMerge, freeze } from "../utils";
@@ -36,6 +37,18 @@ function Config(
36
37
  return config;
37
38
  }
38
39
 
40
+ function TimeSeriesCollection(col: TimeSeriesCollection) {
41
+ col.timestamps = col?.timestamps ?? true;
42
+ if (!col?.timeseries?.granularity) {
43
+ col.timeseries.granularity = "seconds";
44
+ }
45
+ if (!col?.type) {
46
+ col.type = "timeseries";
47
+ }
48
+ if (!col?.fields) col.fields = [];
49
+ return col;
50
+ }
51
+
39
52
  function Collection(col: Collection) {
40
53
  col.timestamps = col?.timestamps ?? true;
41
54
  if (!col?.fields) col.fields = [];
@@ -21,7 +21,10 @@ async function connectToMongo(t: Tenant) {
21
21
  resolve(t);
22
22
  })
23
23
  .catch((error) => {
24
- console.error(`Failed to connect Tenant ${t.id} : `, error?.message);
24
+ consola.error(
25
+ `Tenant: ${t.id} ,Database connection failed ❌`,
26
+ error?.message
27
+ );
25
28
  t.database.isConnected = false;
26
29
  });
27
30
 
@@ -2454,7 +2454,7 @@ class useRest {
2454
2454
  watch(
2455
2455
  collection: string,
2456
2456
  pipeline: Array<any>,
2457
- options: ChangeStreamOptions
2457
+ options?: ChangeStreamOptions
2458
2458
  ): ChangeStream {
2459
2459
  return this.#tenant.database.db?.collection(collection).watch(pipeline, {
2460
2460
  allowDiskUse: true,
package/lib/collection.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import cleanDeep from "clean-deep";
2
2
  import { omit } from "radash";
3
3
  import { deepEqual } from "json-joy/lib/json-equal/deepEqual";
4
- import type { Collection, Field } from "./../types/index";
4
+ import type { Collection, Field, TimeSeriesCollection } from "./../types/index";
5
5
  import { Glob } from "bun";
6
6
  import { Cfg } from "../config";
7
7
  import { useRest } from "../driver/mongo/rest";
8
8
  import { buildSchema } from "./schema";
9
9
  import { cleanPath, resolvePath } from "../utils";
10
10
  import { hookDatabase } from "../lib/database";
11
+ type combinedCollection = Collection & TimeSeriesCollection;
11
12
 
12
13
  import path from "path";
13
14
  import consola from "consola";
@@ -68,63 +69,11 @@ async function syncCollectionDatabase() {
68
69
  //t.database.db.
69
70
 
70
71
  if (t.database.driver == "mongodb") {
71
- const collections: Collection[] | undefined = Cfg.collections?.filter(
72
- (cn) => cn.tenant_id == t.id
73
- );
72
+ const collections: (Collection & TimeSeriesCollection[]) | undefined =
73
+ Cfg.collections?.filter((cn) => cn.tenant_id == t.id);
74
74
  if (collections?.length) {
75
75
  // searchEngine Section
76
- if (t?.searchEngine?.meilisearch?.enabled) {
77
- let allIndex_ = await t?.searchEngine?.meilisearch?.client
78
- ?.getIndexes()
79
- .then((e) => e.results)
80
- .catch((err) => []);
81
76
 
82
- for await (let c of collections) {
83
- if (c?.searchEngine?.meilisearch?.index) {
84
- if (c?.searchEngine?.meilisearch?.dispatchAction) {
85
- c.searchEngine.meilisearch.dispatchAction = "auto";
86
- }
87
-
88
- let indexExist = allIndex_?.find(
89
- (index) => index?.uid == c?.searchEngine?.meilisearch?.index
90
- );
91
- if (!indexExist) {
92
- await t.searchEngine.meilisearch.client
93
- ?.createIndex(c?.searchEngine?.meilisearch?.index, {
94
- primaryKey:
95
- c?.searchEngine?.meilisearch?.primaryKey || "_id",
96
- })
97
- .catch((err) => {
98
- //consola.error(err?.message);
99
- });
100
- }
101
-
102
- let attributes = await t?.searchEngine?.meilisearch?.client
103
- ?.index(c?.searchEngine?.meilisearch?.index)
104
- .getFilterableAttributes()
105
- .catch();
106
-
107
- if (
108
- c?.searchEngine?.meilisearch?.filterableAttributes?.length
109
- ) {
110
- let s = false;
111
- if (
112
- !deepEqual(
113
- attributes,
114
- c?.searchEngine?.meilisearch?.filterableAttributes
115
- )
116
- ) {
117
- await t?.searchEngine?.meilisearch?.client
118
- ?.index(c?.searchEngine?.meilisearch?.index)
119
- .updateFilterableAttributes(
120
- c?.searchEngine?.meilisearch?.filterableAttributes
121
- )
122
- .catch();
123
- }
124
- }
125
- }
126
- }
127
- }
128
77
  // DatabaseSection
129
78
  for await (let c of collections) {
130
79
  // boucle sur les collections
@@ -138,25 +87,23 @@ async function syncCollectionDatabase() {
138
87
  });
139
88
  }
140
89
 
141
- if (c?.cache?.enabled && c?.cache?.init) {
142
- c?.cache?.init({
143
- rest: new useRest({
144
- tenant_id: t.id,
145
- }),
146
- state: c?.cache?.state || {},
147
- });
148
- }
149
-
150
90
  let collectionExist = collectionsInDatabase?.find(
151
91
  (col) => col?.name == c.slug
152
92
  );
153
93
 
154
94
  //console.log(c.slug, collectionExist);
155
95
 
156
- if (!collectionExist) {
96
+ if (!collectionExist && c?.type != "timeseries") {
157
97
  await t.database.db?.createCollection(c.slug);
158
98
  }
159
99
 
100
+ if (!collectionExist && c?.type == "timeseries") {
101
+ await t.database.db?.createCollection(c.slug, {
102
+ timeseries: c?.timeseries,
103
+ expireAfterSeconds: c?.expireAfterSeconds,
104
+ });
105
+ }
106
+
160
107
  // suppression d'index
161
108
  c?.fields?.map((f) => {
162
109
  if (f?.unique === false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.69.21",
3
+ "version": "0.69.23",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {},
package/types/index.ts CHANGED
@@ -423,6 +423,133 @@ export type Collection = {
423
423
  }; */
424
424
  };
425
425
 
426
+ export type TimeSeriesCollection = {
427
+ type: "timeseries";
428
+ init?: (ctx: {
429
+ rest: InstanceType<typeof useRest>;
430
+ collection: string;
431
+ }) => void;
432
+ customApi?: {
433
+ aggregate?: (ctx: ctxApi) => Array<object> | null | undefined | typeof fn.error;
434
+ insertOne?: (ctx: ctxApi) => object | null | undefined | typeof fn.error;
435
+ insertMany?: (ctx: ctxApi) => Array<any> | null | undefined | typeof fn.error;
436
+ updateOne?: (ctx: ctxApi) => object | null | undefined | typeof fn.error;
437
+ updateMany?: (ctx: ctxApi) => object | null | undefined | typeof fn.error;
438
+ deleteOne?: (ctx: ctxApi) => object | null | undefined | typeof fn.error;
439
+ deleteMany?: (ctx: ctxApi) => object | null | undefined | typeof fn.error;
440
+ find?: (ctx: ctxApi) => Array<object> | null | undefined | typeof fn.error;
441
+ findWithMeta?: (ctx: ctxApi) => { meta: object; data: Array<object> } | null | undefined | typeof fn.error;
442
+ findOne?: (ctx: ctxApi) => object | null | undefined | typeof fn.error;
443
+ count?: (ctx: ctxApi) => number | null | undefined | typeof fn.error;
444
+ };
445
+
446
+ schema?: object;
447
+ auth?: {
448
+ enabled?: boolean;
449
+ handler?: (ctx: {
450
+ data: {
451
+ payload: any;
452
+ };
453
+ error: typeof fn.error;
454
+ c: Context;
455
+ rest: InstanceType<typeof useRest>;
456
+ session: sessionCtx;
457
+ }) => boolean | any;
458
+ };
459
+ middlewares?: Array<middlewareCtx>;
460
+ hooks?: {
461
+ beforeOperation?: hooksCtx;
462
+ beforeFind?: hooksCtx;
463
+ afterFind?: hooksCtx;
464
+ beforeUpdate?: hooksCtx;
465
+ afterUpdate?: hooksCtx;
466
+ beforeDelete?: hooksCtx;
467
+ afterDelete?: hooksCtx;
468
+ beforeInsert?: hooksCtx;
469
+ afterInsert?: hooksCtx;
470
+ beforeFindWithMeta?: hooksCtx;
471
+ afterFindWithMeta?: hooksCtx;
472
+ beforeAggregate?: hooksCtx;
473
+ afterAggregate?: hooksCtx;
474
+ beforeCount?: hooksCtx;
475
+ afterCount?: hooksCtx;
476
+ beforeUpload?: hooksCtx;
477
+ afterUpload?: hooksCtx;
478
+ beforeSearch?: hooksCtx;
479
+ afterSearch?: hooksCtx;
480
+ beforeListActivity?: hooksCtx;
481
+ afterListActivity?: hooksCtx;
482
+ };
483
+ access?: {
484
+ "*"?: accessCtx;
485
+ beforeAction?: accessCtx;
486
+ allAction?: accessCtx;
487
+ find?: accessCtx;
488
+ findOne?: accessCtx;
489
+ findOneAndUpdate?: accessCtx;
490
+ insertOne?: accessCtx;
491
+ insertMany?: accessCtx;
492
+ updateMany?: accessCtx;
493
+ updateOne?: accessCtx;
494
+ deleteOne?: accessCtx;
495
+ deleteMany?: accessCtx;
496
+ aggregate?: accessCtx;
497
+ upload?: accessCtx;
498
+ count?: accessCtx;
499
+ search?: accessCtx;
500
+ listActivity?: accessCtx;
501
+ findWithMeta?: accessCtx;
502
+ };
503
+ tenant_id?: string;
504
+ slug: string;
505
+ privateFields?: string[];
506
+ timestamps?: boolean;
507
+ description?: string;
508
+ timeseries:{
509
+ timeField:string;
510
+ metaField:string;
511
+ granularity:'seconds'|'minutes'|'hours';
512
+ };
513
+ fields?: Field[];
514
+ api?: {
515
+ //privateFields?: string[];
516
+ fields: {
517
+ readOnly?:string[];
518
+ select?:
519
+ | string[]
520
+ | ((ctx: {
521
+ action: Actions;
522
+ c: Context;
523
+ rest: InstanceType<typeof useRest>;
524
+ session: sessionCtx;
525
+ }) => string[]);
526
+ hidden?:
527
+ | string[]
528
+ | ((ctx: {
529
+ action: Actions;
530
+ c: Context;
531
+ rest: InstanceType<typeof useRest>;
532
+ session: sessionCtx;
533
+ }) => string[]);
534
+ };
535
+ };
536
+ allow?: ["dropCollection", "renameCollection"];
537
+ expireAfterSeconds?:number;
538
+ indexes?: Array<{
539
+ [key: string]: any;
540
+ unique?: Boolean;
541
+ expireAfterSeconds?: number;
542
+ partialFilterExpression?: any;
543
+ }>;
544
+ autoRemoveIndexes?: Array<{
545
+ [key: string]: any;
546
+ }>;
547
+ /* validate?:{
548
+ updateSchema?:AnySchema;
549
+ }; */
550
+ };
551
+
552
+
426
553
  interface ApiError {
427
554
  code: number;
428
555
  message: string;