@orpc/json-schema 2.0.0-beta.50 → 2.0.0-beta.51
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/README.md +10 -8
- package/dist/composition-utils.d.ts +9 -1
- package/dist/composition-utils.js +26 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -78,13 +78,14 @@ Read the full documentation at [orpc.dev](https://orpc.dev), starting with the [
|
|
|
78
78
|
|
|
79
79
|
**Built-in features**
|
|
80
80
|
|
|
81
|
-
| Package
|
|
82
|
-
|
|
|
83
|
-
| [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher)
|
|
84
|
-
| [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit)
|
|
85
|
-
| [@orpc/experimental-lock](https://www.npmjs.com/package/@orpc/experimental-lock)
|
|
86
|
-
| [@orpc/
|
|
87
|
-
| [@orpc/
|
|
81
|
+
| Package | Purpose | Docs |
|
|
82
|
+
| ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
83
|
+
| [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher) | Pub/Sub with memory, Redis, and Upstash adapters. | [Publisher](https://orpc.dev/docs/helpers/publisher) |
|
|
84
|
+
| [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit) | Rate limiting with memory, Redis, and Upstash adapters. | [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
|
|
85
|
+
| [@orpc/experimental-lock](https://www.npmjs.com/package/@orpc/experimental-lock) | Locking with memory, Redis, and Upstash adapters. | [Lock](https://orpc.dev/docs/helpers/lock) |
|
|
86
|
+
| [@orpc/experimental-openapi-inference](https://www.npmjs.com/package/@orpc/experimental-openapi-inference) | Generate OpenAPI specs from TypeScript types, no output schemas required. | [Type Inference](https://orpc.dev/docs/openapi/specification#type-inference) |
|
|
87
|
+
| [@orpc/hibernation](https://www.npmjs.com/package/@orpc/hibernation) | Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api). | [Hibernation](https://orpc.dev/docs/integrations/hibernation) |
|
|
88
|
+
| [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema) | Smart coercion for OpenAPI requests. | [Smart Coercion](https://orpc.dev/docs/plugins/smart-coercion) |
|
|
88
89
|
|
|
89
90
|
**Framework & ecosystem integrations**
|
|
90
91
|
|
|
@@ -192,9 +193,10 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
192
193
|
<td align="center"><a href="https://kellychan.im/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&v=4" width="139" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
|
|
193
194
|
<td align="center"><a href="https://guyariely.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="139" alt="Guy Ariely"/><br />Guy Ariely</a></td>
|
|
194
195
|
<td align="center"><a href="https://paulsenon.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&v=4" width="139" alt="PaulSenon"/><br />PaulSenon</a></td>
|
|
195
|
-
<td align="center"><a href="https://
|
|
196
|
+
<td align="center"><a href="https://usagerail.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="UsageRail"><img src="https://avatars.githubusercontent.com/u/347653714?v=4" width="139" alt="UsageRail"/><br />UsageRail</a></td>
|
|
196
197
|
</tr>
|
|
197
198
|
<tr>
|
|
199
|
+
<td align="center"><a href="https://piscis.dev/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="139" alt="Alex"/><br />Alex</a></td>
|
|
198
200
|
<td align="center"><a href="https://opensource.gubanov.eu/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&v=4" width="139" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
|
|
199
201
|
</tr>
|
|
200
202
|
</table>
|
|
@@ -34,4 +34,12 @@ export declare function flattenJsonUnionSchema(schema: JsonSchema): JsonSchema[]
|
|
|
34
34
|
* Matches a union made of a single item schema and its array form.
|
|
35
35
|
*/
|
|
36
36
|
export declare function matchArrayableJsonSchema(schema: JsonSchema): undefined | [itemSchema: JsonSchema, arraySchema: JsonArraySchema];
|
|
37
|
-
export declare function deduplicateJsonSchemas(schemas: JsonSchema[]): JsonSchema[];
|
|
37
|
+
export declare function deduplicateJsonSchemas(schemas: JsonSchema[]): JsonSchema[];
|
|
38
|
+
/**
|
|
39
|
+
* Checks whether a schema accepts the empty collection: `[]` for `array`, `{}` for `object`.
|
|
40
|
+
*
|
|
41
|
+
* Understands `type`, `minItems`, `contains`, `minProperties`, `required`, `allOf`, `anyOf`,
|
|
42
|
+
* `oneOf`, and root-local `$ref`s. Schemas using `enum`, `const`, `not`, `if`,
|
|
43
|
+
* or an unresolvable `$ref` are reported as not accepting it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function doesJsonSchemaAcceptEmptyCollection(schema: JsonSchema, kind: "array" | "object"): boolean;
|
|
@@ -307,4 +307,29 @@ function withRootDefs(schema, $defs) {
|
|
|
307
307
|
$defs
|
|
308
308
|
};
|
|
309
309
|
}
|
|
310
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Checks whether a schema accepts the empty collection: `[]` for `array`, `{}` for `object`.
|
|
312
|
+
*
|
|
313
|
+
* Understands `type`, `minItems`, `contains`, `minProperties`, `required`, `allOf`, `anyOf`,
|
|
314
|
+
* `oneOf`, and root-local `$ref`s. Schemas using `enum`, `const`, `not`, `if`,
|
|
315
|
+
* or an unresolvable `$ref` are reported as not accepting it.
|
|
316
|
+
*/
|
|
317
|
+
function doesJsonSchemaAcceptEmptyCollection(schema, kind) {
|
|
318
|
+
return doesJsonSchemaAcceptEmptyCollectionInternal(schema, kind, typeof schema === "object" ? schema.$defs : void 0, /* @__PURE__ */ new Set());
|
|
319
|
+
}
|
|
320
|
+
function doesJsonSchemaAcceptEmptyCollectionInternal(schema, kind, $defs, resolvingRefs) {
|
|
321
|
+
if (typeof schema !== "object") return schema;
|
|
322
|
+
if (typeof schema.$ref === "string") {
|
|
323
|
+
const { $ref, ...siblings } = schema;
|
|
324
|
+
const resolved = resolveJsonSchemaRootLocalRef({ $ref }, $defs);
|
|
325
|
+
if (typeof resolved === "object" && resolved.$ref === $ref || resolvingRefs.has($ref) || !doesJsonSchemaAcceptEmptyCollectionInternal(resolved, kind, $defs, new Set(resolvingRefs).add($ref))) return false;
|
|
326
|
+
schema = siblings;
|
|
327
|
+
}
|
|
328
|
+
const accepts = (member) => doesJsonSchemaAcceptEmptyCollectionInternal(member, kind, $defs, resolvingRefs);
|
|
329
|
+
if (schema.enum !== void 0 || schema.const !== void 0 || schema.not !== void 0 || schema.if !== void 0 || schema.type !== void 0 && !toArray(schema.type).includes(kind)) return false;
|
|
330
|
+
if (kind === "array") {
|
|
331
|
+
if ((schema.minItems ?? 0) > 0 || schema.contains !== void 0 && schema.minContains !== 0) return false;
|
|
332
|
+
} else if ((schema.minProperties ?? 0) > 0 || schema.required?.length) return false;
|
|
333
|
+
return (schema.allOf === void 0 || schema.allOf.every(accepts)) && (schema.anyOf === void 0 || schema.anyOf.some(accepts)) && (schema.oneOf === void 0 || schema.oneOf.filter(accepts).length === 1);
|
|
334
|
+
}
|
|
335
|
+
export { combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, deduplicateJsonSchemas, doesJsonSchemaAcceptEmptyCollection, extractJsonObjectSchemaAdditionalProperties, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, isJsonObjectLikeSchema, matchArrayableJsonSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JsonSchemaCoercer, JsonSchemaCoercerOptions } from "./coercer.js";
|
|
2
|
-
import { JsonObjectSchemaEntry, combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, deduplicateJsonSchemas, extractJsonObjectSchemaAdditionalProperties, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, isJsonObjectLikeSchema, matchArrayableJsonSchema } from "./composition-utils.js";
|
|
2
|
+
import { JsonObjectSchemaEntry, combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, deduplicateJsonSchemas, doesJsonSchemaAcceptEmptyCollection, extractJsonObjectSchemaAdditionalProperties, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, isJsonObjectLikeSchema, matchArrayableJsonSchema } from "./composition-utils.js";
|
|
3
3
|
import { DelegatingJsonSchemaConverter, JsonSchemaConverter, JsonSchemaConverterDirection } from "./convert.js";
|
|
4
4
|
import { JsonSchemaKeywordKind, decodeJsonPointerSegment, encodeJsonPointerSegment, getJsonSchemaKeywordKind, hoistRecursiveRefToDef, mapJsonSchemaRefs, resolveJsonSchemaLocalPointer, resolveJsonSchemaRootLocalRef, visitJsonSchemaRefs } from "./ref-utils.js";
|
|
5
5
|
import { SmartCoercionHandlerPlugin, SmartCoercionHandlerPluginOptions } from "./smart-coercion-handler-plugin.js";
|
|
@@ -8,4 +8,4 @@ import { StandardJsonSchemaConverter, isStandardSchemaOptional } from "./standar
|
|
|
8
8
|
import { JsonSchema, JsonSchemaFormat, JsonSchemaKeywords, JsonSchemaType, JsonSchemaXNativeType } from "./types.js";
|
|
9
9
|
import { JsonArraySchema, JsonFileSchema, JsonObjectSchema, containsJsonFileSchema, ensureJsonSchemaObject, isJsonArraySchema, isJsonFileSchema, isJsonObjectSchema, isJsonPrimitiveSchema, isUnconstrainedSchema } from "./utils.js";
|
|
10
10
|
import { AnySchema, Schema } from "@orpc/contract";
|
|
11
|
-
export { type AnySchema, DelegatingJsonSchemaConverter, JsonArraySchema, JsonFileSchema, JsonObjectSchema, JsonObjectSchemaEntry, JsonSchema, JsonSchemaCoercer, JsonSchemaCoercerOptions, JsonSchemaConverter, JsonSchemaConverterDirection, JsonSchemaFormat, JsonSchemaKeywordKind, JsonSchemaKeywords, JsonSchemaType, JsonSchemaXNativeType, type Schema, SmartCoercionHandlerPlugin, SmartCoercionHandlerPluginOptions, SmartCoercionLinkPlugin, SmartCoercionLinkPluginOptions, StandardJsonSchemaConverter, combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, containsJsonFileSchema, decodeJsonPointerSegment, deduplicateJsonSchemas, encodeJsonPointerSegment, ensureJsonSchemaObject, extractJsonObjectSchemaAdditionalProperties, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, getJsonSchemaKeywordKind, hoistRecursiveRefToDef, isJsonArraySchema, isJsonFileSchema, isJsonObjectLikeSchema, isJsonObjectSchema, isJsonPrimitiveSchema, isStandardSchemaOptional, isUnconstrainedSchema, mapJsonSchemaRefs, matchArrayableJsonSchema, resolveJsonSchemaLocalPointer, resolveJsonSchemaRootLocalRef, visitJsonSchemaRefs };
|
|
11
|
+
export { type AnySchema, DelegatingJsonSchemaConverter, JsonArraySchema, JsonFileSchema, JsonObjectSchema, JsonObjectSchemaEntry, JsonSchema, JsonSchemaCoercer, JsonSchemaCoercerOptions, JsonSchemaConverter, JsonSchemaConverterDirection, JsonSchemaFormat, JsonSchemaKeywordKind, JsonSchemaKeywords, JsonSchemaType, JsonSchemaXNativeType, type Schema, SmartCoercionHandlerPlugin, SmartCoercionHandlerPluginOptions, SmartCoercionLinkPlugin, SmartCoercionLinkPluginOptions, StandardJsonSchemaConverter, combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, containsJsonFileSchema, decodeJsonPointerSegment, deduplicateJsonSchemas, doesJsonSchemaAcceptEmptyCollection, encodeJsonPointerSegment, ensureJsonSchemaObject, extractJsonObjectSchemaAdditionalProperties, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, getJsonSchemaKeywordKind, hoistRecursiveRefToDef, isJsonArraySchema, isJsonFileSchema, isJsonObjectLikeSchema, isJsonObjectSchema, isJsonPrimitiveSchema, isStandardSchemaOptional, isUnconstrainedSchema, mapJsonSchemaRefs, matchArrayableJsonSchema, resolveJsonSchemaLocalPointer, resolveJsonSchemaRootLocalRef, visitJsonSchemaRefs };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { JsonSchemaCoercer } from "./coercer.js";
|
|
2
|
-
export { combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, deduplicateJsonSchemas, extractJsonObjectSchemaAdditionalProperties, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, isJsonObjectLikeSchema, matchArrayableJsonSchema } from "./composition-utils.js";
|
|
2
|
+
export { combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, deduplicateJsonSchemas, doesJsonSchemaAcceptEmptyCollection, extractJsonObjectSchemaAdditionalProperties, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, isJsonObjectLikeSchema, matchArrayableJsonSchema } from "./composition-utils.js";
|
|
3
3
|
export { DelegatingJsonSchemaConverter } from "./convert.js";
|
|
4
4
|
export { decodeJsonPointerSegment, encodeJsonPointerSegment, getJsonSchemaKeywordKind, hoistRecursiveRefToDef, mapJsonSchemaRefs, resolveJsonSchemaLocalPointer, resolveJsonSchemaRootLocalRef, visitJsonSchemaRefs } from "./ref-utils.js";
|
|
5
5
|
export { SmartCoercionHandlerPlugin } from "./smart-coercion-handler-plugin.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/json-schema",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.51",
|
|
4
4
|
"description": "JSON Schema conversion and smart request coercion for oRPC and OpenAPI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"coercion",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@openapi-spec/types": "~0.8.0",
|
|
39
|
-
"@orpc/client": "2.0.0-beta.
|
|
40
|
-
"@orpc/contract": "2.0.0-beta.
|
|
41
|
-
"@orpc/server": "2.0.0-beta.
|
|
42
|
-
"@orpc/shared": "2.0.0-beta.
|
|
39
|
+
"@orpc/client": "2.0.0-beta.51",
|
|
40
|
+
"@orpc/contract": "2.0.0-beta.51",
|
|
41
|
+
"@orpc/server": "2.0.0-beta.51",
|
|
42
|
+
"@orpc/shared": "2.0.0-beta.51",
|
|
43
43
|
"@standard-schema/spec": "^1.1.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|