@nmtjs/contract 0.7.0 → 0.7.2

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,12 +1,15 @@
1
- import { t } from "@nmtjs/type";
2
- export const BlobType = (options = {}) => t.custom((value) => {
3
- if ("metadata" in value) {
4
- if (options.maxSize) {
5
- const size = value.metadata.size;
6
- if (size === -1 || size > options.maxSize) {
7
- throw new Error("Blob size unknown or exceeds maximum allowed size");
1
+ import { t, zod } from "@nmtjs/type";
2
+ export const BlobType = (options = {}) => t.custom({
3
+ decode: (value) => {
4
+ if ("metadata" in value) {
5
+ if (options.maxSize) {
6
+ const size = value.metadata.size;
7
+ if (size === -1 || size > options.maxSize) {
8
+ throw new Error("Blob size unknown or exceeds maximum allowed size");
9
+ }
8
10
  }
9
11
  }
10
- }
11
- return value;
12
- }, (value) => value);
12
+ return value;
13
+ },
14
+ encode: (value) => value
15
+ });
@@ -1 +1 @@
1
- {"mappings":"AACA,SAAS,SAAS,aAAa;AAO/B,OAAO,MAAM,WAAW,CAACA,UAAuB,CAAE,MAChD,EAAE,OACA,CAAC,UAAU;AAGT,KAAI,cAAc,OAAO;AACvB,MAAI,QAAQ,SAAS;GACnB,MAAM,OAAQ,MAAgC,SAAS;AACvD,OAAI,UAAU,KAAK,OAAO,QAAQ,SAAS;AACzC,UAAM,IAAI,MAAM;GACjB;EACF;CACF;AACD,QAAO;AACR,GACD,CAAC,UAAU,MACZ","names":["options: BlobOptions"],"sources":["src/types/blob.ts"],"sourcesContent":["import type { ProtocolBlobInterface } from '@nmtjs/protocol/common'\nimport { t } from '@nmtjs/type'\n\nexport interface BlobOptions {\n maxSize?: number\n contentType?: string\n}\n\nexport const BlobType = (options: BlobOptions = {}) =>\n t.custom<ProtocolBlobInterface>(\n (value) => {\n // TODO: this should be registered separately for server and client\n // ref: https://github.com/sinclairzx81/typebox/issues/977\n if ('metadata' in value) {\n if (options.maxSize) {\n const size = (value as ProtocolBlobInterface).metadata.size\n if (size === -1 || size > options.maxSize) {\n throw new Error('Blob size unknown or exceeds maximum allowed size')\n }\n }\n }\n return value\n },\n (value) => value,\n )\n"],"version":3}
1
+ {"mappings":"AACA,SAAS,GAAG,WAAW,aAAa;AAOpC,OAAO,MAAM,WAAW,CAACA,UAAuB,CAAE,MAChD,EAAE,OAA8B;CAC9B,QAAQ,CAAC,UAAU;AAGjB,MAAI,cAAc,OAAO;AACvB,OAAI,QAAQ,SAAS;IACnB,MAAM,OAAQ,MAAgC,SAAS;AACvD,QAAI,UAAU,KAAK,OAAO,QAAQ,SAAS;AACzC,WAAM,IAAI,MAAM;IACjB;GACF;EACF;AACD,SAAO;CACR;CACD,QAAQ,CAAC,UAAU;AACpB,EAAC","names":["options: BlobOptions"],"sources":["src/types/blob.ts"],"sourcesContent":["import type { ProtocolBlobInterface } from '@nmtjs/protocol/common'\nimport { t, zod } from '@nmtjs/type'\n\nexport interface BlobOptions {\n maxSize?: number\n contentType?: string\n}\n\nexport const BlobType = (options: BlobOptions = {}) =>\n t.custom<ProtocolBlobInterface>({\n decode: (value) => {\n // TODO: this should be registered separately for server and client\n // ref: https://github.com/sinclairzx81/typebox/issues/977\n if ('metadata' in value) {\n if (options.maxSize) {\n const size = (value as ProtocolBlobInterface).metadata.size\n if (size === -1 || size > options.maxSize) {\n throw new Error('Blob size unknown or exceeds maximum allowed size')\n }\n }\n }\n return value\n },\n encode: (value) => value,\n })\n"],"version":3}
package/package.json CHANGED
@@ -8,8 +8,8 @@
8
8
  }
9
9
  },
10
10
  "dependencies": {
11
- "@nmtjs/protocol": "0.7.0",
12
- "@nmtjs/type": "0.7.0"
11
+ "@nmtjs/protocol": "0.7.2",
12
+ "@nmtjs/type": "0.7.2"
13
13
  },
14
14
  "files": [
15
15
  "src",
@@ -17,7 +17,7 @@
17
17
  "LICENSE.md",
18
18
  "README.md"
19
19
  ],
20
- "version": "0.7.0",
20
+ "version": "0.7.2",
21
21
  "scripts": {
22
22
  "build": "neemata-build --root=./src './**/*.ts'",
23
23
  "type-check": "tsc --noEmit"
package/src/types/blob.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ProtocolBlobInterface } from '@nmtjs/protocol/common'
2
- import { t } from '@nmtjs/type'
2
+ import { t, zod } from '@nmtjs/type'
3
3
 
4
4
  export interface BlobOptions {
5
5
  maxSize?: number
@@ -7,8 +7,8 @@ export interface BlobOptions {
7
7
  }
8
8
 
9
9
  export const BlobType = (options: BlobOptions = {}) =>
10
- t.custom<ProtocolBlobInterface>(
11
- (value) => {
10
+ t.custom<ProtocolBlobInterface>({
11
+ decode: (value) => {
12
12
  // TODO: this should be registered separately for server and client
13
13
  // ref: https://github.com/sinclairzx81/typebox/issues/977
14
14
  if ('metadata' in value) {
@@ -21,5 +21,5 @@ export const BlobType = (options: BlobOptions = {}) =>
21
21
  }
22
22
  return value
23
23
  },
24
- (value) => value,
25
- )
24
+ encode: (value) => value,
25
+ })