@aeriajs/core 0.0.216 → 0.0.218

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,4 +1,4 @@
1
- import type { Description, Property, ValidationError, RouteContext } from '@aeriajs/types';
1
+ import type { Description, Property, ValidationError, RouteContext, TempId } from '@aeriajs/types';
2
2
  import { ACError, TraverseError } from '@aeriajs/types';
3
3
  import { ObjectId } from 'mongodb';
4
4
  export type TraverseOptionsBase = {
@@ -27,9 +27,7 @@ export type TraverseNormalized = {
27
27
  description: Description;
28
28
  pipe: (value: unknown, phaseContext: PhaseContext) => unknown;
29
29
  };
30
- export type ValidTempFile = null | undefined | ObjectId | {
31
- tempId: string;
32
- };
30
+ export type ValidTempFile = null | undefined | ObjectId | TempId;
33
31
  type PhaseContext = {
34
32
  target: Record<string, unknown>;
35
33
  root: {
@@ -5,4 +5,4 @@ export * from './insert.js';
5
5
  export * from './remove.js';
6
6
  export * from './removeAll.js';
7
7
  export * from './removeFile.js';
8
- export * from './upload.js';
8
+ export { upload, } from './upload.js';
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.upload = void 0;
17
18
  __exportStar(require("./count.js"), exports);
18
19
  __exportStar(require("./get.js"), exports);
19
20
  __exportStar(require("./getAll.js"), exports);
@@ -21,4 +22,5 @@ __exportStar(require("./insert.js"), exports);
21
22
  __exportStar(require("./remove.js"), exports);
22
23
  __exportStar(require("./removeAll.js"), exports);
23
24
  __exportStar(require("./removeFile.js"), exports);
24
- __exportStar(require("./upload.js"), exports);
25
+ var upload_js_1 = require("./upload.js");
26
+ Object.defineProperty(exports, "upload", { enumerable: true, get: function () { return upload_js_1.upload; } });
@@ -6,4 +6,6 @@ export * from "./insert.mjs";
6
6
  export * from "./remove.mjs";
7
7
  export * from "./removeAll.mjs";
8
8
  export * from "./removeFile.mjs";
9
- export * from "./upload.mjs";
9
+ export {
10
+ upload
11
+ } from "./upload.mjs";
@@ -1,4 +1,102 @@
1
1
  import { Result, ACError, HTTPStatus, type Context } from '@aeriajs/types';
2
+ export declare const FileMetadata: Pick<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
3
+ readonly name: {
4
+ readonly type: "string";
5
+ };
6
+ readonly format: {
7
+ readonly enum: readonly ["raw", "base64"];
8
+ };
9
+ }>> & {
10
+ name: string;
11
+ format: "raw" | "base64";
12
+ }, never>, "name"> & Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
13
+ readonly name: {
14
+ readonly type: "string";
15
+ };
16
+ readonly format: {
17
+ readonly enum: readonly ["raw", "base64"];
18
+ };
19
+ }>> & {
20
+ name: string;
21
+ format: "raw" | "base64";
22
+ }, never>>, validateFileMetadata: <TWhat>(what: TWhat) => {
23
+ readonly _tag: "Error";
24
+ readonly error: import("@aeriajs/types").PropertyValidationError | import("@aeriajs/types").ValidationError;
25
+ readonly result: undefined;
26
+ } | {
27
+ readonly _tag: "Result";
28
+ readonly error: undefined;
29
+ readonly result: Pick<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
30
+ readonly name: {
31
+ readonly type: "string";
32
+ };
33
+ readonly format: {
34
+ readonly enum: readonly ["raw", "base64"];
35
+ };
36
+ }>> & {
37
+ name: string;
38
+ format: "raw" | "base64";
39
+ }, never>, "name"> & Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
40
+ readonly name: {
41
+ readonly type: "string";
42
+ };
43
+ readonly format: {
44
+ readonly enum: readonly ["raw", "base64"];
45
+ };
46
+ }>> & {
47
+ name: string;
48
+ format: "raw" | "base64";
49
+ }, never>>;
50
+ };
51
+ export declare const UploadHeaders: Pick<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
52
+ readonly 'x-stream-request': {
53
+ readonly const: "1";
54
+ };
55
+ readonly 'content-type': {
56
+ readonly type: "string";
57
+ };
58
+ }>> & {
59
+ "x-stream-request": "1";
60
+ "content-type": string;
61
+ }, never>, "x-stream-request" | "content-type"> & Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
62
+ readonly 'x-stream-request': {
63
+ readonly const: "1";
64
+ };
65
+ readonly 'content-type': {
66
+ readonly type: "string";
67
+ };
68
+ }>> & {
69
+ "x-stream-request": "1";
70
+ "content-type": string;
71
+ }, never>>, validateUploadHeaders: <TWhat>(what: TWhat) => {
72
+ readonly _tag: "Error";
73
+ readonly error: import("@aeriajs/types").PropertyValidationError | import("@aeriajs/types").ValidationError;
74
+ readonly result: undefined;
75
+ } | {
76
+ readonly _tag: "Result";
77
+ readonly error: undefined;
78
+ readonly result: Pick<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
79
+ readonly 'x-stream-request': {
80
+ readonly const: "1";
81
+ };
82
+ readonly 'content-type': {
83
+ readonly type: "string";
84
+ };
85
+ }>> & {
86
+ "x-stream-request": "1";
87
+ "content-type": string;
88
+ }, never>, "x-stream-request" | "content-type"> & Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
89
+ readonly 'x-stream-request': {
90
+ readonly const: "1";
91
+ };
92
+ readonly 'content-type': {
93
+ readonly type: "string";
94
+ };
95
+ }>> & {
96
+ "x-stream-request": "1";
97
+ "content-type": string;
98
+ }, never>>;
99
+ };
2
100
  export declare const upload: <TContext extends Context>(_props: unknown, context: TContext) => Promise<Result.Error<{
3
101
  readonly code: ACError.MalformedInput;
4
102
  readonly details: import("@aeriajs/types").ValidationError | import("@aeriajs/types").PropertyValidationError;
@@ -32,14 +32,15 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var _a, _b;
35
36
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.upload = void 0;
37
+ exports.upload = exports.validateUploadHeaders = exports.UploadHeaders = exports.validateFileMetadata = exports.FileMetadata = void 0;
37
38
  const types_1 = require("@aeriajs/types");
38
39
  const validation_1 = require("@aeriajs/validation");
39
40
  const path = __importStar(require("node:path"));
40
41
  const node_fs_1 = require("node:fs");
41
42
  const node_crypto_1 = require("node:crypto");
42
- const [FileMetadata, validateFileMetadata] = (0, validation_1.validator)({
43
+ _a = (0, validation_1.validator)({
43
44
  type: 'object',
44
45
  required: ['name'],
45
46
  properties: {
@@ -53,7 +54,23 @@ const [FileMetadata, validateFileMetadata] = (0, validation_1.validator)({
53
54
  ],
54
55
  },
55
56
  },
56
- });
57
+ }), exports.FileMetadata = _a[0], exports.validateFileMetadata = _a[1];
58
+ _b = (0, validation_1.validator)({
59
+ type: 'object',
60
+ additionalProperties: true,
61
+ required: [
62
+ 'x-stream-request',
63
+ 'content-type',
64
+ ],
65
+ properties: {
66
+ 'x-stream-request': {
67
+ const: '1',
68
+ },
69
+ 'content-type': {
70
+ type: 'string',
71
+ },
72
+ },
73
+ }), exports.UploadHeaders = _b[0], exports.validateUploadHeaders = _b[1];
57
74
  const streamToFs = (metadata, context) => {
58
75
  const nameHash = (0, node_crypto_1.createHash)('sha1')
59
76
  .update(metadata.name + Date.now())
@@ -87,29 +104,14 @@ const streamToFs = (metadata, context) => {
87
104
  });
88
105
  };
89
106
  const upload = async (_props, context) => {
90
- const { error: headersError } = (0, validation_1.validate)(context.request.headers, {
91
- type: 'object',
92
- additionalProperties: true,
93
- required: [
94
- 'x-stream-request',
95
- 'content-type',
96
- ],
97
- properties: {
98
- 'x-stream-request': {
99
- const: '1',
100
- },
101
- 'content-type': {
102
- type: 'string',
103
- },
104
- },
105
- });
107
+ const { error: headersError } = (0, exports.validateUploadHeaders)(context.request.headers);
106
108
  if (headersError) {
107
109
  return context.error(types_1.HTTPStatus.BadRequest, {
108
110
  code: types_1.ACError.MalformedInput,
109
111
  details: headersError,
110
112
  });
111
113
  }
112
- const { error, result: metadata } = validateFileMetadata(context.request.query);
114
+ const { error, result: metadata } = (0, exports.validateFileMetadata)(context.request.query);
113
115
  if (error) {
114
116
  return context.error(types_1.HTTPStatus.BadRequest, {
115
117
  code: types_1.ACError.MalformedInput,
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  import { Result, ACError, HTTPStatus } from "@aeriajs/types";
3
- import { validate, validator } from "@aeriajs/validation";
3
+ import { validator } from "@aeriajs/validation";
4
4
  import * as path from "node:path";
5
5
  import { createWriteStream } from "node:fs";
6
6
  import { createHash } from "node:crypto";
7
- const [FileMetadata, validateFileMetadata] = validator({
7
+ export const [FileMetadata, validateFileMetadata] = validator({
8
8
  type: "object",
9
9
  required: ["name"],
10
10
  properties: {
@@ -19,6 +19,22 @@ const [FileMetadata, validateFileMetadata] = validator({
19
19
  }
20
20
  }
21
21
  });
22
+ export const [UploadHeaders, validateUploadHeaders] = validator({
23
+ type: "object",
24
+ additionalProperties: true,
25
+ required: [
26
+ "x-stream-request",
27
+ "content-type"
28
+ ],
29
+ properties: {
30
+ "x-stream-request": {
31
+ const: "1"
32
+ },
33
+ "content-type": {
34
+ type: "string"
35
+ }
36
+ }
37
+ });
22
38
  const streamToFs = (metadata, context) => {
23
39
  const nameHash = createHash("sha1").update(metadata.name + Date.now()).digest("hex");
24
40
  const extension = metadata.name.includes(".") ? metadata.name.split(".").at(-1) : "bin";
@@ -46,22 +62,7 @@ const streamToFs = (metadata, context) => {
46
62
  });
47
63
  };
48
64
  export const upload = async (_props, context) => {
49
- const { error: headersError } = validate(context.request.headers, {
50
- type: "object",
51
- additionalProperties: true,
52
- required: [
53
- "x-stream-request",
54
- "content-type"
55
- ],
56
- properties: {
57
- "x-stream-request": {
58
- const: "1"
59
- },
60
- "content-type": {
61
- type: "string"
62
- }
63
- }
64
- });
65
+ const { error: headersError } = validateUploadHeaders(context.request.headers);
65
66
  if (headersError) {
66
67
  return context.error(HTTPStatus.BadRequest, {
67
68
  code: ACError.MalformedInput,
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export type { FileMetadata, UploadHeaders, } from './functions/upload.js';
1
2
  export * from './accessControl.js';
2
3
  export * from './assets.js';
3
4
  export * from './collection/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.216",
3
+ "version": "0.0.218",
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.216",
46
- "@aeriajs/common": "^0.0.125",
47
- "@aeriajs/entrypoint": "^0.0.128",
48
- "@aeriajs/http": "^0.0.151",
49
- "@aeriajs/security": "^0.0.216",
50
- "@aeriajs/types": "^0.0.107",
51
- "@aeriajs/validation": "^0.0.140"
45
+ "@aeriajs/builtins": "^0.0.218",
46
+ "@aeriajs/common": "^0.0.126",
47
+ "@aeriajs/entrypoint": "^0.0.129",
48
+ "@aeriajs/http": "^0.0.152",
49
+ "@aeriajs/security": "^0.0.218",
50
+ "@aeriajs/types": "^0.0.108",
51
+ "@aeriajs/validation": "^0.0.141"
52
52
  },
53
53
  "dependencies": {
54
54
  "mongodb": "^6.5.0",