@standard-community/standard-json 0.3.1 → 0.3.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.
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var quansync = require('quansync');
4
- var utils = require('./utils-D7AosoZA.cjs');
4
+ var utils = require('./utils-CeR2367j.cjs');
5
5
 
6
6
  function _interopNamespaceDefaultOnly (e) { return Object.freeze({ __proto__: null, default: e }); }
7
7
 
@@ -25,9 +25,7 @@ const getToJsonSchemaFn = async (vendor) => {
25
25
  vendorFnPromise = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./vendors/zod.cjs')); })).default();
26
26
  break;
27
27
  default:
28
- throw new Error(
29
- utils.errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
30
- );
28
+ throw new utils.UnsupportedVendorError(vendor);
31
29
  }
32
30
  const vendorFn = await vendorFnPromise;
33
31
  utils.validationMapper.set(vendor, vendorFn);
@@ -36,13 +34,10 @@ const getToJsonSchemaFn = async (vendor) => {
36
34
 
37
35
  const toJsonSchema = quansync.quansync({
38
36
  sync: (schema, options) => {
39
- const fn = utils.validationMapper.get(schema["~standard"].vendor);
37
+ const vendor = schema["~standard"].vendor;
38
+ const fn = utils.validationMapper.get(vendor);
40
39
  if (!fn) {
41
- throw new Error(
42
- utils.errorMessageWrapper(
43
- `Unsupported schema vendor "${schema["~standard"].vendor}".`
44
- )
45
- );
40
+ throw new utils.UnsupportedVendorError(vendor);
46
41
  }
47
42
  return fn(schema, options);
48
43
  },
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { quansync } from 'quansync';
2
- import { v as validationMapper, e as errorMessageWrapper } from './utils-BOYKSG8-.js';
2
+ import { v as validationMapper, U as UnsupportedVendorError } from './utils-8OktpmW4.js';
3
3
 
4
4
  const getToJsonSchemaFn = async (vendor) => {
5
5
  const cached = validationMapper.get(vendor);
@@ -21,9 +21,7 @@ const getToJsonSchemaFn = async (vendor) => {
21
21
  vendorFnPromise = (await import('./vendors/zod.js')).default();
22
22
  break;
23
23
  default:
24
- throw new Error(
25
- errorMessageWrapper(`Unsupported schema vendor "${vendor}".`)
26
- );
24
+ throw new UnsupportedVendorError(vendor);
27
25
  }
28
26
  const vendorFn = await vendorFnPromise;
29
27
  validationMapper.set(vendor, vendorFn);
@@ -32,13 +30,10 @@ const getToJsonSchemaFn = async (vendor) => {
32
30
 
33
31
  const toJsonSchema = quansync({
34
32
  sync: (schema, options) => {
35
- const fn = validationMapper.get(schema["~standard"].vendor);
33
+ const vendor = schema["~standard"].vendor;
34
+ const fn = validationMapper.get(vendor);
36
35
  if (!fn) {
37
- throw new Error(
38
- errorMessageWrapper(
39
- `Unsupported schema vendor "${schema["~standard"].vendor}".`
40
- )
41
- );
36
+ throw new UnsupportedVendorError(vendor);
42
37
  }
43
38
  return fn(schema, options);
44
39
  },
@@ -0,0 +1,13 @@
1
+ const validationMapper = /* @__PURE__ */ new Map();
2
+ class UnsupportedVendorError extends Error {
3
+ constructor(vendor) {
4
+ super(`standard-json: Unsupported schema vendor "${vendor}".`);
5
+ }
6
+ }
7
+ class MissingDependencyError extends Error {
8
+ constructor(packageName) {
9
+ super(`standard-json: Missing dependencies "${packageName}".`);
10
+ }
11
+ }
12
+
13
+ export { MissingDependencyError as M, UnsupportedVendorError as U, validationMapper as v };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const validationMapper = /* @__PURE__ */ new Map();
4
+ class UnsupportedVendorError extends Error {
5
+ constructor(vendor) {
6
+ super(`standard-json: Unsupported schema vendor "${vendor}".`);
7
+ }
8
+ }
9
+ class MissingDependencyError extends Error {
10
+ constructor(packageName) {
11
+ super(`standard-json: Missing dependencies "${packageName}".`);
12
+ }
13
+ }
14
+
15
+ exports.MissingDependencyError = MissingDependencyError;
16
+ exports.UnsupportedVendorError = UnsupportedVendorError;
17
+ exports.validationMapper = validationMapper;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- async function getToJsonSchemaFn() {
3
+ function getToJsonSchemaFn() {
4
4
  return (schema, options) => schema.toJsonSchema(options);
5
5
  }
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { T as ToJsonSchemaFn } from '../utils-1JaZ8JC_.js';
2
2
  import 'json-schema';
3
3
 
4
- declare function getToJsonSchemaFn(): Promise<ToJsonSchemaFn>;
4
+ declare function getToJsonSchemaFn(): ToJsonSchemaFn;
5
5
 
6
6
  export { getToJsonSchemaFn as default };
@@ -1,6 +1,6 @@
1
1
  import { T as ToJsonSchemaFn } from '../utils-1JaZ8JC_.js';
2
2
  import 'json-schema';
3
3
 
4
- declare function getToJsonSchemaFn(): Promise<ToJsonSchemaFn>;
4
+ declare function getToJsonSchemaFn(): ToJsonSchemaFn;
5
5
 
6
6
  export { getToJsonSchemaFn as default };
@@ -1,4 +1,4 @@
1
- async function getToJsonSchemaFn() {
1
+ function getToJsonSchemaFn() {
2
2
  return (schema, options) => schema.toJsonSchema(options);
3
3
  }
4
4
 
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('../utils-D7AosoZA.cjs');
3
+ var utils = require('../utils-CeR2367j.cjs');
4
4
 
5
5
  async function getToJsonSchemaFn() {
6
6
  try {
7
7
  const { JSONSchema } = await import('effect');
8
8
  return (schema) => JSONSchema.make(schema);
9
9
  } catch {
10
- throw new Error(utils.errorMessageWrapper('Missing dependencies "effect".'));
10
+ throw new utils.MissingDependencyError("effect");
11
11
  }
12
12
  }
13
13
 
@@ -1,11 +1,11 @@
1
- import { e as errorMessageWrapper } from '../utils-BOYKSG8-.js';
1
+ import { M as MissingDependencyError } from '../utils-8OktpmW4.js';
2
2
 
3
3
  async function getToJsonSchemaFn() {
4
4
  try {
5
5
  const { JSONSchema } = await import('effect');
6
6
  return (schema) => JSONSchema.make(schema);
7
7
  } catch {
8
- throw new Error(errorMessageWrapper('Missing dependencies "effect".'));
8
+ throw new MissingDependencyError("effect");
9
9
  }
10
10
  }
11
11
 
@@ -1,15 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('../utils-D7AosoZA.cjs');
3
+ var utils = require('../utils-CeR2367j.cjs');
4
4
 
5
5
  async function getToJsonSchemaFn() {
6
6
  try {
7
7
  const { toJsonSchema } = await import('@valibot/to-json-schema');
8
8
  return toJsonSchema;
9
9
  } catch {
10
- throw new Error(
11
- utils.errorMessageWrapper('Missing dependencies "@valibot/to-json-schema".')
12
- );
10
+ throw new utils.MissingDependencyError("@valibot/to-json-schema");
13
11
  }
14
12
  }
15
13
 
@@ -1,13 +1,11 @@
1
- import { e as errorMessageWrapper } from '../utils-BOYKSG8-.js';
1
+ import { M as MissingDependencyError } from '../utils-8OktpmW4.js';
2
2
 
3
3
  async function getToJsonSchemaFn() {
4
4
  try {
5
5
  const { toJsonSchema } = await import('@valibot/to-json-schema');
6
6
  return toJsonSchema;
7
7
  } catch {
8
- throw new Error(
9
- errorMessageWrapper('Missing dependencies "@valibot/to-json-schema".')
10
- );
8
+ throw new MissingDependencyError("@valibot/to-json-schema");
11
9
  }
12
10
  }
13
11
 
@@ -1,17 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('../utils-D7AosoZA.cjs');
3
+ var utils = require('../utils-CeR2367j.cjs');
4
4
 
5
+ const zodv4Error = new utils.MissingDependencyError("zod v4");
5
6
  async function getToJsonSchemaFn() {
6
7
  return async (schema, options) => {
7
8
  let handler;
8
9
  if ("_zod" in schema) {
9
10
  try {
10
- handler = await import('zod/v4/core').then(
11
- (mod) => mod.toJSONSchema
12
- );
11
+ handler = await import('zod/v4/core').catch(() => {
12
+ throw zodv4Error;
13
+ }).then((mod) => mod.toJSONSchema);
13
14
  } catch {
14
- throw new Error(utils.errorMessageWrapper('Missing dependencies "zod v4".'));
15
+ throw zodv4Error;
15
16
  }
16
17
  } else {
17
18
  try {
@@ -19,9 +20,7 @@ async function getToJsonSchemaFn() {
19
20
  (mod) => mod.zodToJsonSchema
20
21
  );
21
22
  } catch {
22
- throw new Error(
23
- utils.errorMessageWrapper('Missing dependencies "zod-to-json-schema".')
24
- );
23
+ throw new utils.MissingDependencyError("zod-to-json-schema");
25
24
  }
26
25
  }
27
26
  return handler(schema, options);
@@ -1,15 +1,16 @@
1
- import { e as errorMessageWrapper } from '../utils-BOYKSG8-.js';
1
+ import { M as MissingDependencyError } from '../utils-8OktpmW4.js';
2
2
 
3
+ const zodv4Error = new MissingDependencyError("zod v4");
3
4
  async function getToJsonSchemaFn() {
4
5
  return async (schema, options) => {
5
6
  let handler;
6
7
  if ("_zod" in schema) {
7
8
  try {
8
- handler = await import('zod/v4/core').then(
9
- (mod) => mod.toJSONSchema
10
- );
9
+ handler = await import('zod/v4/core').catch(() => {
10
+ throw zodv4Error;
11
+ }).then((mod) => mod.toJSONSchema);
11
12
  } catch {
12
- throw new Error(errorMessageWrapper('Missing dependencies "zod v4".'));
13
+ throw zodv4Error;
13
14
  }
14
15
  } else {
15
16
  try {
@@ -17,9 +18,7 @@ async function getToJsonSchemaFn() {
17
18
  (mod) => mod.zodToJsonSchema
18
19
  );
19
20
  } catch {
20
- throw new Error(
21
- errorMessageWrapper('Missing dependencies "zod-to-json-schema".')
22
- );
21
+ throw new MissingDependencyError("zod-to-json-schema");
23
22
  }
24
23
  }
25
24
  return handler(schema, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@standard-community/standard-json",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",
@@ -1,4 +0,0 @@
1
- const errorMessageWrapper = (message) => `standard-json: ${message}`;
2
- const validationMapper = /* @__PURE__ */ new Map();
3
-
4
- export { errorMessageWrapper as e, validationMapper as v };
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- const errorMessageWrapper = (message) => `standard-json: ${message}`;
4
- const validationMapper = /* @__PURE__ */ new Map();
5
-
6
- exports.errorMessageWrapper = errorMessageWrapper;
7
- exports.validationMapper = validationMapper;