@aeriajs/core 0.0.111 → 0.0.113

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,2 +1,2 @@
1
1
  import type { Description } from '@aeriajs/types';
2
- export declare const fill: <TDocument extends OptionalId<any>>(doc: TDocument & Record<string, any>, description: Description) => Record<string, any> & TDocument;
2
+ export declare const fill: <TDocument extends unknown>(doc: TDocument & Record<string, any>, description: Description) => Record<string, any> & TDocument;
@@ -1,2 +1,2 @@
1
1
  import type { Description } from '@aeriajs/types';
2
- export declare const normalizeProjection: <TDescription extends Pick<Description, "properties">, TProjectedProperties extends (keyof TDescription["properties"])[]>(properties: TProjectedProperties, description: TDescription) => {} | null;
2
+ export declare const normalizeProjection: <TDescription extends Pick<Description, "properties">, TProjectedProperties extends (keyof TDescription["properties"])[]>(properties: TProjectedProperties, description: TDescription) => {} | undefined;
@@ -16,7 +16,7 @@ const normalizeProjection = (properties, description) => {
16
16
  };
17
17
  }, {});
18
18
  return Object.keys(projection).length === 0
19
- ? null
19
+ ? undefined
20
20
  : projection;
21
21
  };
22
22
  exports.normalizeProjection = normalizeProjection;
@@ -13,5 +13,5 @@ export const normalizeProjection = (properties, description) => {
13
13
  [key]: 1
14
14
  };
15
15
  }, {});
16
- return Object.keys(projection).length === 0 ? null : projection;
16
+ return Object.keys(projection).length === 0 ? void 0 : projection;
17
17
  };
@@ -1,2 +1,4 @@
1
- import type { Context, Pagination, GetAllPayload } from '@aeriajs/types';
2
- export declare const makePagination: (payload: GetAllPayload<any>, documents: any[], context: Context) => Promise<Pagination>;
1
+ import type { Context, Description, Pagination, GetAllPayload } from '@aeriajs/types';
2
+ export declare const makePagination: (payload: GetAllPayload<any>, documents: any[], context: Context<Description, {
3
+ count?: (...args: unknown[]) => unknown;
4
+ }>) => Promise<Pagination>;
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makePagination = void 0;
4
+ const common_1 = require("@aeriajs/common");
4
5
  const makePagination = async (payload, documents, context) => {
5
6
  const limit = payload.limit
6
7
  ? payload.limit
7
8
  : context.config.paginationLimit;
8
9
  const offset = payload.offset || 0;
9
- const recordsTotal = context.collection.originalFunctions.count
10
- ? await context.collection.functions.count({
10
+ const recordsTotal = typeof context.collection.functions.count === 'function'
11
+ ? (0, common_1.throwIfError)(await context.collection.functions.count({
11
12
  filters: payload.filters,
12
- })
13
+ }))
13
14
  : await context.collection.model.countDocuments(payload.filters);
14
15
  return {
15
16
  recordsCount: documents.length,
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
+ import { throwIfError } from "@aeriajs/common";
2
3
  export const makePagination = async (payload, documents, context) => {
3
4
  const limit = payload.limit ? payload.limit : context.config.paginationLimit;
4
5
  const offset = payload.offset || 0;
5
- const recordsTotal = context.collection.originalFunctions.count ? await context.collection.functions.count({
6
+ const recordsTotal = typeof context.collection.functions.count === "function" ? throwIfError(await context.collection.functions.count({
6
7
  filters: payload.filters
7
- }) : await context.collection.model.countDocuments(payload.filters);
8
+ })) : await context.collection.model.countDocuments(payload.filters);
8
9
  return {
9
10
  recordsCount: documents.length,
10
11
  recordsTotal,
@@ -9,6 +9,7 @@ export type TraverseOptions = {
9
9
  moveFiles?: boolean;
10
10
  fromProperties?: boolean;
11
11
  allowOperators?: boolean;
12
+ skipUndefined?: boolean;
12
13
  recurseDeep?: boolean;
13
14
  recurseReferences?: boolean;
14
15
  context?: Context;
@@ -250,8 +250,10 @@ const recurse = async (target, ctx) => {
250
250
  for (const propName in entrypoint) {
251
251
  const value = target[propName];
252
252
  const property = getProperty(propName, ctx.property);
253
- if (value === undefined && !(ctx.options.getters && property && 'getter' in property)) {
254
- continue;
253
+ if (ctx.options.skipUndefined) {
254
+ if (value === undefined && !(ctx.options.getters && property && 'getter' in property)) {
255
+ continue;
256
+ }
255
257
  }
256
258
  if (ctx.options.autoCast && propName === '_id') {
257
259
  entries.push([
@@ -214,8 +214,10 @@ const recurse = async (target, ctx) => {
214
214
  for (const propName in entrypoint) {
215
215
  const value = target[propName];
216
216
  const property = getProperty(propName, ctx.property);
217
- if (value === void 0 && !(ctx.options.getters && property && "getter" in property)) {
218
- continue;
217
+ if (ctx.options.skipUndefined) {
218
+ if (value === void 0 && !(ctx.options.getters && property && "getter" in property)) {
219
+ continue;
220
+ }
219
221
  }
220
222
  if (ctx.options.autoCast && propName === "_id") {
221
223
  entries.push([
@@ -30,10 +30,11 @@ const insert = async (payload, context, options) => {
30
30
  recurseDeep: true,
31
31
  autoCast: true,
32
32
  validate: true,
33
- validateRequired: payload.what._id
33
+ validateRequired: '_id' in payload.what && payload.what._id
34
34
  ? []
35
35
  : context.description.required,
36
36
  moveFiles: true,
37
+ skipUndefined: true,
37
38
  context,
38
39
  });
39
40
  if (error) {
@@ -25,8 +25,9 @@ export const insert = async (payload, context, options) => {
25
25
  recurseDeep: true,
26
26
  autoCast: true,
27
27
  validate: true,
28
- validateRequired: payload.what._id ? [] : context.description.required,
28
+ validateRequired: "_id" in payload.what && payload.what._id ? [] : context.description.required,
29
29
  moveFiles: true,
30
+ skipUndefined: true,
30
31
  context
31
32
  });
32
33
  if (error) {
@@ -1,11 +1,11 @@
1
1
  import type { Context, SchemaWithId, RemovePayload } from '@aeriajs/types';
2
2
  import { Result, HTTPStatus, ACError } from '@aeriajs/types';
3
- export declare const remove: <TContext extends Context>(payload: RemovePayload<SchemaWithId<TContext['description']>>, context: TContext) => Promise<{
4
- readonly _tag: "Result";
5
- readonly error: undefined;
6
- readonly result: any;
7
- } | Result.Error<{
3
+ export declare const remove: <TContext extends Context>(payload: RemovePayload<SchemaWithId<TContext['description']>>, context: TContext) => Promise<Result.Error<{
8
4
  readonly code: ACError.ResourceNotFound;
9
5
  } & {
10
6
  httpStatus: HTTPStatus.NotFound;
11
- }>>;
7
+ }> | {
8
+ readonly _tag: "Result";
9
+ readonly error: undefined;
10
+ readonly result: import("mongodb").WithId<Omit<import("@aeriajs/types").PackReferences<SchemaWithId<import("@aeriajs/types").Description>>, "_id">> | null;
11
+ }>;
@@ -2,5 +2,5 @@ import type { Context, RemoveAllPayload } from '@aeriajs/types';
2
2
  export declare const removeAll: <TContext extends Context>(payload: RemoveAllPayload, context: TContext) => Promise<{
3
3
  readonly _tag: "Result";
4
4
  readonly error: undefined;
5
- readonly result: any;
5
+ readonly result: import("mongodb").DeleteResult;
6
6
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.111",
3
+ "version": "0.0.113",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -41,13 +41,13 @@
41
41
  "mongodb-memory-server": "^9.2.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "@aeriajs/builtins": "^0.0.111",
45
- "@aeriajs/common": "^0.0.70",
46
- "@aeriajs/entrypoint": "^0.0.72",
47
- "@aeriajs/http": "^0.0.81",
48
- "@aeriajs/security": "^0.0.111",
49
- "@aeriajs/types": "^0.0.62",
50
- "@aeriajs/validation": "^0.0.73"
44
+ "@aeriajs/builtins": "^0.0.113",
45
+ "@aeriajs/common": "^0.0.72",
46
+ "@aeriajs/entrypoint": "^0.0.74",
47
+ "@aeriajs/http": "^0.0.83",
48
+ "@aeriajs/security": "^0.0.113",
49
+ "@aeriajs/types": "^0.0.63",
50
+ "@aeriajs/validation": "^0.0.75"
51
51
  },
52
52
  "dependencies": {
53
53
  "mongodb": "^6.5.0",