@dnax/core 0.65.3 → 0.65.5

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/hono.ts CHANGED
@@ -198,7 +198,7 @@ function HonoInstance(): typeof app {
198
198
  action: action,
199
199
  c: c,
200
200
  isAuth: sessionStorage()?.get()?.isAuth ?? false,
201
- rest: new useRest({ tenant_id: tenant_id }),
201
+ rest: new useRest({ tenant_id: tenant_id, c: c }),
202
202
  session: session as any,
203
203
  });
204
204
  }
@@ -223,7 +223,7 @@ function HonoInstance(): typeof app {
223
223
  action: action,
224
224
  c: c,
225
225
  isAuth: sessionStorage()?.get()?.isAuth ?? false,
226
- rest: new useRest({ tenant_id: tenant_id }),
226
+ rest: new useRest({ tenant_id: tenant_id, c: c }),
227
227
  session: sessionStorage(),
228
228
  });
229
229
  } else {
@@ -251,7 +251,7 @@ function HonoInstance(): typeof app {
251
251
  action: action,
252
252
  c: c,
253
253
  isAuth: sessionStorage()?.get()?.isAuth ?? false,
254
- rest: new useRest({ tenant_id: tenant_id }),
254
+ rest: new useRest({ tenant_id: tenant_id, c: c }),
255
255
  });
256
256
  }
257
257
  }
@@ -26,8 +26,8 @@ export type findParam = {
26
26
 
27
27
  export type findOneParam = {
28
28
  $match: object;
29
- $include: Array<object>;
30
- $matchInclude: object;
29
+ $include?: Array<object>;
30
+ $matchInclude?: object;
31
31
  };
32
32
 
33
33
  export type updateParams = {
@@ -3,7 +3,8 @@ import { sessionStorage } from "../../lib/asyncLocalStorage";
3
3
  import { getCollection, getKeyFields } from "../../lib/collection";
4
4
  import { getTenant } from "../../lib/tenant";
5
5
  import type { Actions, Collection, Tenant } from "./../../types/index";
6
- import { isArray, omit } from "radash";
6
+ import { isArray } from "radash";
7
+ import { omit } from "../../utils";
7
8
  import {
8
9
  ChangeStream,
9
10
  ClientSession,
@@ -1066,6 +1067,7 @@ class useRest {
1066
1067
  options?: Omit<optionCb, "withMeta" | "elementAt" | "withMeta"> & {
1067
1068
  arrayFilters?: Array<object>;
1068
1069
  upsert?: boolean;
1070
+ disableReadOnlyFields?: string[];
1069
1071
  }
1070
1072
  ): Promise<object> {
1071
1073
  return new Promise(async (resolve, reject) => {
@@ -1078,6 +1080,7 @@ class useRest {
1078
1080
  let useHook = options?.useHook ?? this.#useHook;
1079
1081
  let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
1080
1082
  let col = getCollection(collection, this.#tenant_id);
1083
+
1081
1084
  if (!col) return;
1082
1085
  let allFieldKeys = getKeyFields(col);
1083
1086
 
@@ -1153,7 +1156,12 @@ class useRest {
1153
1156
 
1154
1157
  update.$set = deepSetId(
1155
1158
  col,
1156
- omit(update.$set, ["createdAt", "updatedAt", "_id"])
1159
+ omit(
1160
+ update.$set,
1161
+ ["createdAt", "updatedAt", "_id"].concat(
1162
+ options?.disableReadOnlyFields || []
1163
+ )
1164
+ )
1157
1165
  );
1158
1166
  update.$set = transformAllDate(update.$set);
1159
1167
  update.$set = await hashPasswordAuto(update.$set, col);
@@ -1268,6 +1276,7 @@ class useRest {
1268
1276
  options?: Omit<
1269
1277
  optionCb & {
1270
1278
  upsert: boolean;
1279
+ disableReadOnlyFields?: string[];
1271
1280
  },
1272
1281
  "useHook" | "useCustomApi" | "elementAt" | "withMeta"
1273
1282
  >
@@ -1285,7 +1294,15 @@ class useRest {
1285
1294
  update = omit(update, omitUpdate);
1286
1295
  if (update.$set) {
1287
1296
  // update.$set = deepSetId(col, update.$set);
1288
- update.$set = deepSetId(col, update.$set);
1297
+ update.$set = deepSetId(
1298
+ col,
1299
+ omit(
1300
+ update.$set,
1301
+ ["createdAt", "updatedAt", "_id"].concat(
1302
+ options?.disableReadOnlyFields || []
1303
+ )
1304
+ )
1305
+ );
1289
1306
  update.$set = transformAllDate(update.$set);
1290
1307
  update.$set = await hashPasswordAuto(update.$set, col);
1291
1308
  var { valid, output, error } = this.validator(
@@ -1377,6 +1394,7 @@ class useRest {
1377
1394
  options?: Omit<
1378
1395
  optionCb & {
1379
1396
  upsert: boolean;
1397
+ disableReadOnlyFields?: string[];
1380
1398
  },
1381
1399
  "useHook" | "useCustomApi" | "elementAt" | "withMeta"
1382
1400
  >
@@ -1396,7 +1414,15 @@ class useRest {
1396
1414
 
1397
1415
  if (update.$set) {
1398
1416
  // update.$set = deepSetId(col, update.$set);
1399
- update.$set = deepSetId(col, update.$set);
1417
+ update.$set = deepSetId(
1418
+ col,
1419
+ omit(
1420
+ update.$set,
1421
+ ["createdAt", "updatedAt", "_id"].concat(
1422
+ options?.disableReadOnlyFields || []
1423
+ )
1424
+ )
1425
+ );
1400
1426
  update.$set = transformAllDate(update.$set);
1401
1427
  update.$set = await hashPasswordAuto(update.$set, col);
1402
1428
  var { valid, output, error } = this.validator(
@@ -1513,7 +1539,9 @@ class useRest {
1513
1539
  collection: string,
1514
1540
  ids: Array<string>,
1515
1541
  update: updateParams,
1516
- options?: optionCb
1542
+ options?: optionCb & {
1543
+ disableReadOnlyFields?: string[];
1544
+ }
1517
1545
  ): Promise<object> {
1518
1546
  return new Promise(async (resolve, reject) => {
1519
1547
  try {
@@ -1590,7 +1618,12 @@ class useRest {
1590
1618
 
1591
1619
  update.$set = deepSetId(
1592
1620
  col,
1593
- omit(update.$set, ["createdAt", "updatedAt", "_id"])
1621
+ omit(
1622
+ update.$set,
1623
+ ["createdAt", "updatedAt", "_id"].concat(
1624
+ options?.disableReadOnlyFields || []
1625
+ )
1626
+ )
1594
1627
  );
1595
1628
  update.$set = transformAllDate(update.$set);
1596
1629
  update.$set = await hashPasswordAuto(update.$set, col);
@@ -2024,7 +2057,10 @@ class useRest {
2024
2057
  .dropIndex(indexName);
2025
2058
  }
2026
2059
 
2027
- startTransaction() {
2060
+ startTransaction(options?: { forceNew?: boolean }) {
2061
+ if (options?.forceNew) {
2062
+ this.#session = null;
2063
+ }
2028
2064
  if (!this.#session) {
2029
2065
  this.#session = this.#tenant.database.client?.startSession();
2030
2066
  this.#session?.startTransaction();
package/lib/schema.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Schema } from "hono";
2
2
  import type { Collection } from "../types";
3
3
  import v, { type AnySchema } from "joi";
4
- function buildSchema(col: Collection) {
4
+ function buildSchema(col: Collection): AnySchema {
5
5
  let propertySchema = {} as { [key: string]: AnySchema };
6
6
 
7
7
  if (col?.timestamps) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.65.3",
3
+ "version": "0.65.5",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.ts CHANGED
@@ -139,14 +139,13 @@ export type Field = {
139
139
  */
140
140
  injectAutoId?: boolean;
141
141
  sparse?: boolean;
142
- // relationType?: "ref-to-one" | "ref-to-many";
143
142
  /**
144
143
  * Overwrite custom validation schema
145
144
  * use {v} from "@dnax/core"} to build your own validation
146
145
  *
147
146
  */
148
147
  validate?: {
149
- schema?: AnySchema;
148
+ schema?: AnySchema; // Basic Schema validation
150
149
  };
151
150
  //relationTo?: string;
152
151
  };
@@ -445,6 +444,7 @@ export type Collection = {
445
444
  api?: {
446
445
  //privateFields?: string[];
447
446
  fields: {
447
+ readOnly?:string[];
448
448
  select?:
449
449
  | string[]
450
450
  | ((ctx: {
@@ -473,6 +473,9 @@ export type Collection = {
473
473
  autoRemoveIndexes?: Array<{
474
474
  [key: string]: any;
475
475
  }>;
476
+ /* validate?:{
477
+ updateSchema?:AnySchema;
478
+ }; */
476
479
  };
477
480
 
478
481
  interface ApiError {