@aeriajs/core 0.0.214 → 0.0.216

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.
@@ -33,8 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- const path = __importStar(require("path"));
37
- const fs = __importStar(require("fs"));
36
+ const path = __importStar(require("node:path"));
37
+ const fs = __importStar(require("node:fs"));
38
38
  const DTS_FILENAME = 'aeria.d.ts';
39
39
  const makeDts = (typesPath) => `// this file will be overwritten
40
40
  import type {} from '@aeriajs/types'
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- import * as path from "path";
3
- import * as fs from "fs";
2
+ import * as path from "node:path";
3
+ import * as fs from "node:fs";
4
4
  const DTS_FILENAME = "aeria.d.ts";
5
5
  const makeDts = (typesPath) => `// this file will be overwritten
6
6
  import type {} from '@aeriajs/types'
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makePagination = void 0;
4
- const count_js_1 = require("../functions/count.js");
5
4
  const common_1 = require("@aeriajs/common");
5
+ const count_js_1 = require("../functions/count.js");
6
6
  const makePagination = async (payload, documents, context) => {
7
7
  const { offset = 0, limit = context.config.defaultPaginationLimit, } = payload;
8
8
  const recordsTotal = typeof context.collection.functions.count === 'function'
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- import { count } from "../functions/count.mjs";
3
2
  import { throwIfError } from "@aeriajs/common";
3
+ import { count } from "../functions/count.mjs";
4
4
  export const makePagination = async (payload, documents, context) => {
5
5
  const {
6
6
  offset = 0,
@@ -34,6 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.traverseDocument = void 0;
37
+ const path = __importStar(require("node:path"));
38
+ const fs = __importStar(require("node:fs/promises"));
37
39
  const types_1 = require("@aeriajs/types");
38
40
  const common_1 = require("@aeriajs/common");
39
41
  const validation_1 = require("@aeriajs/validation");
@@ -44,8 +46,6 @@ const context_js_1 = require("../context.js");
44
46
  const preload_js_1 = require("./preload.js");
45
47
  const reference_js_1 = require("./reference.js");
46
48
  const cascadingRemove_js_1 = require("./cascadingRemove.js");
47
- const path = __importStar(require("path"));
48
- const fs = __importStar(require("fs/promises"));
49
49
  const escapeRegExp = (text) => {
50
50
  return text.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
51
51
  };
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ import * as path from "node:path";
3
+ import * as fs from "node:fs/promises";
2
4
  import { Result, ACError, ValidationErrorCode, TraverseError } from "@aeriajs/types";
3
5
  import { throwIfError, pipe, isReference, getReferenceProperty, getValueFromPath, isError } from "@aeriajs/common";
4
6
  import { makeValidationError, validateProperty, validateWholeness } from "@aeriajs/validation";
@@ -9,8 +11,6 @@ import { createContext } from "../context.mjs";
9
11
  import { preloadDescription } from "./preload.mjs";
10
12
  import { getReferences } from "./reference.mjs";
11
13
  import { preferredRemove } from "./cascadingRemove.mjs";
12
- import * as path from "path";
13
- import * as fs from "fs/promises";
14
14
  const escapeRegExp = (text) => {
15
15
  return text.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
16
16
  };
package/dist/database.js CHANGED
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.getDatabaseCollection = exports.getDatabaseSync = exports.getDatabase = exports.ObjectId = void 0;
37
37
  const entrypoint_1 = require("@aeriajs/entrypoint");
38
- const util_1 = require("util");
38
+ const node_util_1 = require("node:util");
39
39
  const mongodb_1 = require("mongodb");
40
40
  var mongodb_2 = require("mongodb");
41
41
  Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return mongodb_2.ObjectId; } });
@@ -59,7 +59,7 @@ const getDatabase = async () => {
59
59
  });
60
60
  if (logQueries) {
61
61
  client.on('commandStarted', (event) => {
62
- console.debug((0, util_1.inspect)(event, {
62
+ console.debug((0, node_util_1.inspect)(event, {
63
63
  colors: true,
64
64
  compact: false,
65
65
  depth: Infinity,
package/dist/database.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  import { getConfig } from "@aeriajs/entrypoint";
3
- import { inspect } from "util";
3
+ import { inspect } from "node:util";
4
4
  import { MongoClient } from "mongodb";
5
5
  export {
6
6
  ObjectId
@@ -36,19 +36,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.upload = void 0;
37
37
  const types_1 = require("@aeriajs/types");
38
38
  const validation_1 = require("@aeriajs/validation");
39
- const path = __importStar(require("path"));
40
- const fs_1 = require("fs");
41
- const crypto_1 = require("crypto");
39
+ const path = __importStar(require("node:path"));
40
+ const node_fs_1 = require("node:fs");
41
+ const node_crypto_1 = require("node:crypto");
42
42
  const [FileMetadata, validateFileMetadata] = (0, validation_1.validator)({
43
43
  type: 'object',
44
+ required: ['name'],
44
45
  properties: {
45
46
  name: {
46
47
  type: 'string',
47
48
  },
49
+ format: {
50
+ enum: [
51
+ 'raw',
52
+ 'base64',
53
+ ],
54
+ },
48
55
  },
49
56
  });
50
57
  const streamToFs = (metadata, context) => {
51
- const nameHash = (0, crypto_1.createHash)('sha1')
58
+ const nameHash = (0, node_crypto_1.createHash)('sha1')
52
59
  .update(metadata.name + Date.now())
53
60
  .digest('hex');
54
61
  const extension = metadata.name.includes('.')
@@ -61,17 +68,32 @@ const streamToFs = (metadata, context) => {
61
68
  throw new Error();
62
69
  }
63
70
  const absolutePath = path.join(tmpPath, `${nameHash}.${extension}`);
64
- return new Promise((resolve, reject) => {
65
- const stream = (0, fs_1.createWriteStream)(absolutePath);
66
- stream.on('open', () => context.request.pipe(stream));
71
+ return new Promise(async (resolve, reject) => {
72
+ const stream = (0, node_fs_1.createWriteStream)(absolutePath);
67
73
  stream.on('close', () => resolve(absolutePath));
68
74
  stream.on('error', (error) => reject(error));
75
+ switch (metadata.format) {
76
+ case undefined:
77
+ case 'raw': {
78
+ stream.on('open', () => context.request.pipe(stream));
79
+ break;
80
+ }
81
+ case 'base64': {
82
+ stream.write(Buffer.from(Buffer.concat(await Array.fromAsync(context.request)).toString(), 'base64'));
83
+ stream.close();
84
+ break;
85
+ }
86
+ }
69
87
  });
70
88
  };
71
89
  const upload = async (_props, context) => {
72
90
  const { error: headersError } = (0, validation_1.validate)(context.request.headers, {
73
91
  type: 'object',
74
92
  additionalProperties: true,
93
+ required: [
94
+ 'x-stream-request',
95
+ 'content-type',
96
+ ],
75
97
  properties: {
76
98
  'x-stream-request': {
77
99
  const: '1',
@@ -1,14 +1,21 @@
1
1
  "use strict";
2
2
  import { Result, ACError, HTTPStatus } from "@aeriajs/types";
3
3
  import { validate, validator } from "@aeriajs/validation";
4
- import * as path from "path";
5
- import { createWriteStream } from "fs";
6
- import { createHash } from "crypto";
4
+ import * as path from "node:path";
5
+ import { createWriteStream } from "node:fs";
6
+ import { createHash } from "node:crypto";
7
7
  const [FileMetadata, validateFileMetadata] = validator({
8
8
  type: "object",
9
+ required: ["name"],
9
10
  properties: {
10
11
  name: {
11
12
  type: "string"
13
+ },
14
+ format: {
15
+ enum: [
16
+ "raw",
17
+ "base64"
18
+ ]
12
19
  }
13
20
  }
14
21
  });
@@ -20,17 +27,32 @@ const streamToFs = (metadata, context) => {
20
27
  throw new Error();
21
28
  }
22
29
  const absolutePath = path.join(tmpPath, `${nameHash}.${extension}`);
23
- return new Promise((resolve, reject) => {
30
+ return new Promise(async (resolve, reject) => {
24
31
  const stream = createWriteStream(absolutePath);
25
- stream.on("open", () => context.request.pipe(stream));
26
32
  stream.on("close", () => resolve(absolutePath));
27
33
  stream.on("error", (error) => reject(error));
34
+ switch (metadata.format) {
35
+ case void 0:
36
+ case "raw": {
37
+ stream.on("open", () => context.request.pipe(stream));
38
+ break;
39
+ }
40
+ case "base64": {
41
+ stream.write(Buffer.from(Buffer.concat(await Array.fromAsync(context.request)).toString(), "base64"));
42
+ stream.close();
43
+ break;
44
+ }
45
+ }
28
46
  });
29
47
  };
30
48
  export const upload = async (_props, context) => {
31
49
  const { error: headersError } = validate(context.request.headers, {
32
50
  type: "object",
33
51
  additionalProperties: true,
52
+ required: [
53
+ "x-stream-request",
54
+ "content-type"
55
+ ],
34
56
  properties: {
35
57
  "x-stream-request": {
36
58
  const: "1"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.214",
3
+ "version": "0.0.216",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "aeriaMain": "tests/fixtures/aeriaMain.js",
@@ -42,13 +42,13 @@
42
42
  "mongodb-memory-server": "^9.2.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@aeriajs/builtins": "^0.0.214",
45
+ "@aeriajs/builtins": "^0.0.216",
46
46
  "@aeriajs/common": "^0.0.125",
47
47
  "@aeriajs/entrypoint": "^0.0.128",
48
- "@aeriajs/http": "^0.0.150",
49
- "@aeriajs/security": "^0.0.214",
48
+ "@aeriajs/http": "^0.0.151",
49
+ "@aeriajs/security": "^0.0.216",
50
50
  "@aeriajs/types": "^0.0.107",
51
- "@aeriajs/validation": "^0.0.139"
51
+ "@aeriajs/validation": "^0.0.140"
52
52
  },
53
53
  "dependencies": {
54
54
  "mongodb": "^6.5.0",