@amritk/helpers 0.1.0

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.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Converts a PascalCase or camelCase string to kebab-case.
3
+ * Handles consecutive uppercase sequences (e.g. "APIKey" → "api-key") and
4
+ * known mixed-case acronyms like "OAuth" that would otherwise split incorrectly.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * toKebabCase('ServerVariable') // 'server-variable'
9
+ * toKebabCase('APIKeySecurityScheme') // 'api-key-security-scheme'
10
+ * toKebabCase('OAuthFlows') // 'oauth-flows'
11
+ * toKebabCase('already-kebab') // 'already-kebab'
12
+ * ```
13
+ */
14
+ export declare const toKebabCase: (value: string) => string;
15
+ /**
16
+ * Converts a JSON Schema $ref to a filename.
17
+ *
18
+ * Handles three ref forms:
19
+ * - Internal `#/$defs/contact` → `contact`
20
+ * - Internal `#/definitions/ServerVariable` → `server-variable`
21
+ * - URI `http://example.com/definitions/3.1.0/channel.json` → `channel`
22
+ * - URI with fragment `http://example.com/channel.json#/definitions/queue` → `channel-queue`
23
+ *
24
+ * @param ref - The $ref string
25
+ * @returns The filename without extension
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * refToFilename('#/$defs/contact') // 'contact'
30
+ * refToFilename('#/$defs/server-variable') // 'server-variable'
31
+ * refToFilename('#/definitions/ServerVariable') // 'server-variable'
32
+ * refToFilename('#/definitions/APIKeySecurityScheme') // 'api-key-security-scheme'
33
+ * refToFilename('http://asyncapi.com/definitions/3.1.0/channel.json') // 'channel'
34
+ * ```
35
+ */
36
+ export declare const refToFilename: (ref: string) => string;
@@ -0,0 +1,44 @@
1
+ // src/ref-to-filename.ts
2
+ var toKebabCase = (value) => value.replace(/OAuth/g, "Oauth").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").replace(/([a-z\d])([A-Z])/g, "$1-$2").toLowerCase();
3
+ var uriRefToFilename = (uri) => {
4
+ const hashIndex = uri.indexOf("#");
5
+ const baseUri = hashIndex === -1 ? uri : uri.slice(0, hashIndex);
6
+ const fragment = hashIndex === -1 ? "" : uri.slice(hashIndex + 1);
7
+ const withoutProtocol = baseUri.replace(/^https?:\/\/[^/]+\//, "");
8
+ const withoutExt = withoutProtocol.replace(/\.json$/, "");
9
+ const rawSegments = withoutExt.split("/");
10
+ const SKIP_KEYS = new Set(["definitions", "$defs"]);
11
+ const segments = [];
12
+ for (let i = 0;i < rawSegments.length; i++) {
13
+ const s = rawSegments[i];
14
+ if (SKIP_KEYS.has(s))
15
+ continue;
16
+ const prevRaw = rawSegments[i - 1];
17
+ if (/^\d+\.\d+/.test(s) && prevRaw !== undefined && SKIP_KEYS.has(prevRaw))
18
+ continue;
19
+ segments.push(s);
20
+ }
21
+ const baseName = segments.map((s) => toKebabCase(s).replace(/\./g, "-")).join("-");
22
+ if (!fragment)
23
+ return baseName;
24
+ const fragSegments = fragment.split("/").filter((s) => s && !SKIP_KEYS.has(s) && s !== "properties");
25
+ const fragLast = fragSegments[fragSegments.length - 1];
26
+ if (!fragLast)
27
+ return baseName;
28
+ return `${baseName}-${toKebabCase(fragLast)}`;
29
+ };
30
+ var refToFilename = (ref) => {
31
+ if (ref.startsWith("http://") || ref.startsWith("https://")) {
32
+ return uriRefToFilename(ref);
33
+ }
34
+ const segments = ref.split("/");
35
+ let filename = segments[segments.length - 1];
36
+ if (/[A-Z]/.test(filename)) {
37
+ filename = toKebabCase(filename);
38
+ }
39
+ return filename;
40
+ };
41
+ export {
42
+ toKebabCase,
43
+ refToFilename
44
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Converts a JSON Schema $ref to a type name.
3
+ * Derives the filename via `refToFilename` then converts to PascalCase with
4
+ * an "Object" suffix.
5
+ *
6
+ * Handles all ref forms: internal `#/$defs/...`, `#/definitions/...`, and URI refs.
7
+ *
8
+ * @param ref - The $ref string
9
+ * @returns The type name in PascalCase with "Object" suffix
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * refToName('#/$defs/contact') // 'ContactObject'
14
+ * refToName('#/$defs/server-variable') // 'ServerVariableObject'
15
+ * refToName('http://asyncapi.com/definitions/3.1.0/channel.json') // 'ChannelObject'
16
+ * ```
17
+ */
18
+ export declare const refToName: (ref: string) => string;
@@ -0,0 +1,54 @@
1
+ // src/ref-to-filename.ts
2
+ var toKebabCase = (value) => value.replace(/OAuth/g, "Oauth").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").replace(/([a-z\d])([A-Z])/g, "$1-$2").toLowerCase();
3
+ var uriRefToFilename = (uri) => {
4
+ const hashIndex = uri.indexOf("#");
5
+ const baseUri = hashIndex === -1 ? uri : uri.slice(0, hashIndex);
6
+ const fragment = hashIndex === -1 ? "" : uri.slice(hashIndex + 1);
7
+ const withoutProtocol = baseUri.replace(/^https?:\/\/[^/]+\//, "");
8
+ const withoutExt = withoutProtocol.replace(/\.json$/, "");
9
+ const rawSegments = withoutExt.split("/");
10
+ const SKIP_KEYS = new Set(["definitions", "$defs"]);
11
+ const segments = [];
12
+ for (let i = 0;i < rawSegments.length; i++) {
13
+ const s = rawSegments[i];
14
+ if (SKIP_KEYS.has(s))
15
+ continue;
16
+ const prevRaw = rawSegments[i - 1];
17
+ if (/^\d+\.\d+/.test(s) && prevRaw !== undefined && SKIP_KEYS.has(prevRaw))
18
+ continue;
19
+ segments.push(s);
20
+ }
21
+ const baseName = segments.map((s) => toKebabCase(s).replace(/\./g, "-")).join("-");
22
+ if (!fragment)
23
+ return baseName;
24
+ const fragSegments = fragment.split("/").filter((s) => s && !SKIP_KEYS.has(s) && s !== "properties");
25
+ const fragLast = fragSegments[fragSegments.length - 1];
26
+ if (!fragLast)
27
+ return baseName;
28
+ return `${baseName}-${toKebabCase(fragLast)}`;
29
+ };
30
+ var refToFilename = (ref) => {
31
+ if (ref.startsWith("http://") || ref.startsWith("https://")) {
32
+ return uriRefToFilename(ref);
33
+ }
34
+ const segments = ref.split("/");
35
+ let filename = segments[segments.length - 1];
36
+ if (/[A-Z]/.test(filename)) {
37
+ filename = toKebabCase(filename);
38
+ }
39
+ return filename;
40
+ };
41
+
42
+ // src/ref-to-name.ts
43
+ var kebabToPascal = (kebab) => {
44
+ const words = kebab.split("-");
45
+ let pascalCase = "";
46
+ for (const word of words) {
47
+ pascalCase += word.charAt(0).toUpperCase() + word.slice(1);
48
+ }
49
+ return pascalCase + "Object";
50
+ };
51
+ var refToName = (ref) => kebabToPascal(refToFilename(ref));
52
+ export {
53
+ refToName
54
+ };
@@ -0,0 +1,13 @@
1
+ import type { JSONSchema } from 'json-schema-typed/draft-2020-12';
2
+ /**
3
+ * Replaces $dynamicRef with $ref in a schema using the provided anchor-to-path map.
4
+ *
5
+ * This creates a deep clone of the schema to avoid mutating the original, then walks
6
+ * the clone and converts any { $dynamicRef: "#meta" } to { $ref: "#/$defs/schema" }
7
+ * (or whatever the dynamicRefMap dictates).
8
+ *
9
+ * Only the direct properties and their nested schemas are walked — this does not need
10
+ * to be infinitely deep because the build system generates separate files for each $def,
11
+ * so each schema is relatively shallow.
12
+ */
13
+ export declare const resolveDynamicRefs: (schema: JSONSchema, dynamicRefMap: Record<string, string>) => JSONSchema;
@@ -0,0 +1,31 @@
1
+ // src/resolve-dynamic-refs.ts
2
+ var resolveDynamicRefs = (schema, dynamicRefMap) => {
3
+ if (typeof schema !== "object" || schema === null) {
4
+ return schema;
5
+ }
6
+ if (Object.keys(dynamicRefMap).length === 0) {
7
+ return schema;
8
+ }
9
+ const clone = JSON.parse(JSON.stringify(schema));
10
+ const walk = (obj) => {
11
+ if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
12
+ return;
13
+ }
14
+ const record = obj;
15
+ if ("$dynamicRef" in record && typeof record["$dynamicRef"] === "string") {
16
+ const resolved = dynamicRefMap[record["$dynamicRef"]];
17
+ if (resolved) {
18
+ record["$ref"] = resolved;
19
+ delete record["$dynamicRef"];
20
+ }
21
+ }
22
+ for (const key in record) {
23
+ walk(record[key]);
24
+ }
25
+ };
26
+ walk(clone);
27
+ return clone;
28
+ };
29
+ export {
30
+ resolveDynamicRefs
31
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Resolves a JSON Schema $ref pointer to the actual schema definition.
3
+ *
4
+ * Supports three ref forms:
5
+ * - Internal: `#/$defs/contact` — navigates the root schema by JSON Pointer
6
+ * - URI key: `http://example.com/foo.json` — looks up the key directly in `$defs`
7
+ * - URI with fragment: `http://example.com/foo.json#/definitions/bar` — looks up
8
+ * the base URI in `$defs`, then navigates the fragment within that definition
9
+ *
10
+ * @param ref - The $ref string
11
+ * @param rootSchema - The root schema containing the definitions
12
+ * @returns The resolved schema or undefined if not found
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const rootSchema = {
17
+ * $defs: {
18
+ * contact: { type: 'object', properties: { email: { type: 'string' } } },
19
+ * 'http://example.com/server.json': { type: 'object' },
20
+ * }
21
+ * }
22
+ * resolveRef('#/$defs/contact', rootSchema)
23
+ * resolveRef('http://example.com/server.json', rootSchema)
24
+ * ```
25
+ */
26
+ export declare const resolveRef: (ref: string, rootSchema: Record<string, unknown>) => Record<string, unknown> | undefined;
@@ -0,0 +1,42 @@
1
+ // src/resolve-ref.ts
2
+ var navigatePointer = (pointer, schema) => {
3
+ const parts = pointer.split("/").filter(Boolean);
4
+ let current = schema;
5
+ for (const part of parts) {
6
+ const decodedPart = part.replace(/~1/g, "/").replace(/~0/g, "~");
7
+ if (current && typeof current === "object" && decodedPart in current) {
8
+ const next = current[decodedPart];
9
+ if (typeof next === "object" && next !== null) {
10
+ current = next;
11
+ } else {
12
+ return;
13
+ }
14
+ } else {
15
+ return;
16
+ }
17
+ }
18
+ return current;
19
+ };
20
+ var resolveRef = (ref, rootSchema) => {
21
+ if (ref.startsWith("#")) {
22
+ return navigatePointer(ref.slice(1), rootSchema);
23
+ }
24
+ const hashIndex = ref.indexOf("#");
25
+ const baseUri = hashIndex === -1 ? ref : ref.slice(0, hashIndex);
26
+ const rawFragment = hashIndex === -1 ? "" : ref.slice(hashIndex + 1);
27
+ const fragment = rawFragment === "" || rawFragment === "/" ? "" : rawFragment;
28
+ const defs = rootSchema["$defs"];
29
+ if (typeof defs !== "object" || defs === null)
30
+ return;
31
+ const defsRecord = defs;
32
+ const base = defsRecord[baseUri];
33
+ if (typeof base !== "object" || base === null)
34
+ return;
35
+ if (!fragment)
36
+ return base;
37
+ const normalizedFragment = fragment.replace(/^\/definitions\//, "/$defs/");
38
+ return navigatePointer(normalizedFragment, base);
39
+ };
40
+ export {
41
+ resolveRef
42
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Generates a safe property accessor for a given key on an object variable.
3
+ * Uses dot notation for simple identifiers and bracket notation for keys
4
+ * that contain special characters like hyphens.
5
+ *
6
+ * @param variable - The variable name (e.g., "input", "input?")
7
+ * @param key - The property name to access
8
+ * @returns A valid JS property access expression
9
+ *
10
+ * @example
11
+ * safeAccessor("input", "name") // "input.name"
12
+ * safeAccessor("input?", "x-linkedin") // "input?.['x-linkedin']"
13
+ * safeAccessor("input", "x-linkedin") // "input['x-linkedin']"
14
+ */
15
+ export declare const safeAccessor: (variable: string, key: string) => string;
16
+ /**
17
+ * Generates a safe property key for use in object literals.
18
+ * Wraps keys that are not valid identifiers in quotes.
19
+ *
20
+ * @example
21
+ * safeKey("name") // "name"
22
+ * safeKey("x-linkedin") // "'x-linkedin'"
23
+ */
24
+ export declare const safeKey: (key: string) => string;
@@ -0,0 +1,21 @@
1
+ // src/safe-accessor.ts
2
+ var JS_IDENTIFIER = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
3
+ var safeAccessor = (variable, key) => {
4
+ if (JS_IDENTIFIER.test(key)) {
5
+ return `${variable}.${key}`;
6
+ }
7
+ if (variable.endsWith("?")) {
8
+ return `${variable}.['${key}']`;
9
+ }
10
+ return `${variable}['${key}']`;
11
+ };
12
+ var safeKey = (key) => {
13
+ if (JS_IDENTIFIER.test(key)) {
14
+ return key;
15
+ }
16
+ return `'${key}'`;
17
+ };
18
+ export {
19
+ safeKey,
20
+ safeAccessor
21
+ };
@@ -0,0 +1,115 @@
1
+ import type { JSONSchema } from 'json-schema-typed/draft-2020-12';
2
+ type SchemaObject = Exclude<JSONSchema, false | boolean>;
3
+ /** Type guard to check if schema is not false */
4
+ export declare const isSchemaObject: (schema: JSONSchema) => schema is SchemaObject;
5
+ /** Type guard to check if schema has a type property */
6
+ export declare const hasType: (schema: JSONSchema) => schema is SchemaObject & {
7
+ type: string;
8
+ };
9
+ /** Type guard to check if schema is an object schema */
10
+ export declare const isObjectSchema: (schema: JSONSchema) => schema is JSONSchema.Object;
11
+ /** Type guard to check if schema has properties */
12
+ export declare const hasProperties: (schema: JSONSchema) => schema is SchemaObject & {
13
+ properties: Record<string, JSONSchema>;
14
+ };
15
+ /** Type guard to check if schema has enum */
16
+ export declare const hasEnum: (schema: JSONSchema) => schema is SchemaObject & {
17
+ enum: readonly unknown[];
18
+ };
19
+ /** Type guard to check if schema has const */
20
+ export declare const hasConst: (schema: JSONSchema) => schema is SchemaObject & {
21
+ const: unknown;
22
+ };
23
+ /** Type guard to check if schema has pattern */
24
+ export declare const hasPattern: (schema: JSONSchema) => schema is SchemaObject & {
25
+ pattern: string;
26
+ };
27
+ /** Type guard to check if schema has format */
28
+ export declare const hasFormat: (schema: JSONSchema) => schema is SchemaObject & {
29
+ format: string;
30
+ };
31
+ /** Type guard to check if schema has default */
32
+ export declare const hasDefault: (schema: JSONSchema) => schema is SchemaObject & {
33
+ default: unknown;
34
+ };
35
+ /** Type guard to check if schema has examples */
36
+ export declare const hasExamples: (schema: JSONSchema) => schema is SchemaObject & {
37
+ examples: readonly unknown[];
38
+ };
39
+ /** Type guard to check if schema has oneOf */
40
+ export declare const hasOneOf: (schema: JSONSchema) => schema is SchemaObject & {
41
+ oneOf: readonly JSONSchema[];
42
+ };
43
+ /** Type guard to check if schema has anyOf */
44
+ export declare const hasAnyOf: (schema: JSONSchema) => schema is SchemaObject & {
45
+ anyOf: readonly JSONSchema[];
46
+ };
47
+ /** Type guard to check if schema has allOf */
48
+ export declare const hasAllOf: (schema: JSONSchema) => schema is SchemaObject & {
49
+ allOf: readonly JSONSchema[];
50
+ };
51
+ /** Type guard to check if schema has required */
52
+ export declare const hasRequired: (schema: JSONSchema) => schema is SchemaObject & {
53
+ required: readonly string[];
54
+ };
55
+ /** Type guard to check if schema has items (and it's not just boolean) */
56
+ export declare const hasItems: (schema: JSONSchema) => schema is SchemaObject & {
57
+ items: SchemaObject;
58
+ };
59
+ /** Type guard to check if schema has additionalProperties */
60
+ export declare const hasAdditionalProperties: (schema: JSONSchema) => schema is SchemaObject & {
61
+ additionalProperties: JSONSchema | boolean;
62
+ };
63
+ /** Type guard to check if schema has minLength */
64
+ export declare const hasMinLength: (schema: JSONSchema) => schema is SchemaObject & {
65
+ minLength: number;
66
+ };
67
+ /** Type guard to check if schema has maxLength */
68
+ export declare const hasMaxLength: (schema: JSONSchema) => schema is SchemaObject & {
69
+ maxLength: number;
70
+ };
71
+ /** Type guard to check if schema has minimum */
72
+ export declare const hasMinimum: (schema: JSONSchema) => schema is SchemaObject & {
73
+ minimum: number;
74
+ };
75
+ /** Type guard to check if schema has maximum */
76
+ export declare const hasMaximum: (schema: JSONSchema) => schema is SchemaObject & {
77
+ maximum: number;
78
+ };
79
+ /** Type guard to check if schema has exclusiveMinimum */
80
+ export declare const hasExclusiveMinimum: (schema: JSONSchema) => schema is SchemaObject & {
81
+ exclusiveMinimum: number;
82
+ };
83
+ /** Type guard to check if schema has exclusiveMaximum */
84
+ export declare const hasExclusiveMaximum: (schema: JSONSchema) => schema is SchemaObject & {
85
+ exclusiveMaximum: number;
86
+ };
87
+ /** Type guard to check if schema has multipleOf */
88
+ export declare const hasMultipleOf: (schema: JSONSchema) => schema is SchemaObject & {
89
+ multipleOf: number;
90
+ };
91
+ /** Type guard to check if schema has minItems */
92
+ export declare const hasMinItems: (schema: JSONSchema) => schema is SchemaObject & {
93
+ minItems: number;
94
+ };
95
+ /** Type guard to check if schema has maxItems */
96
+ export declare const hasMaxItems: (schema: JSONSchema) => schema is SchemaObject & {
97
+ maxItems: number;
98
+ };
99
+ /** Type guard to check if schema has uniqueItems */
100
+ export declare const hasUniqueItems: (schema: JSONSchema) => schema is SchemaObject & {
101
+ uniqueItems: boolean;
102
+ };
103
+ /** Type guard to check if schema has minProperties */
104
+ export declare const hasMinProperties: (schema: JSONSchema) => schema is SchemaObject & {
105
+ minProperties: number;
106
+ };
107
+ /** Type guard to check if schema has maxProperties */
108
+ export declare const hasMaxProperties: (schema: JSONSchema) => schema is SchemaObject & {
109
+ maxProperties: number;
110
+ };
111
+ /** Type guard to check if schema has $ref */
112
+ export declare const hasRef: (schema: JSONSchema) => schema is SchemaObject & {
113
+ $ref: string;
114
+ };
115
+ export {};
@@ -0,0 +1,119 @@
1
+ // src/schema-guards.ts
2
+ var isSchemaObject = (schema) => {
3
+ return typeof schema === "object" && schema !== null && typeof schema !== "boolean";
4
+ };
5
+ var hasType = (schema) => {
6
+ return isSchemaObject(schema) && "type" in schema && typeof schema.type === "string";
7
+ };
8
+ var isObjectSchema = (schema) => {
9
+ return isSchemaObject(schema) && (("type" in schema) && schema.type === "object" || ("properties" in schema));
10
+ };
11
+ var hasProperties = (schema) => {
12
+ return isSchemaObject(schema) && "properties" in schema && typeof schema.properties === "object" && schema.properties !== null;
13
+ };
14
+ var hasEnum = (schema) => {
15
+ return isSchemaObject(schema) && "enum" in schema && Array.isArray(schema.enum);
16
+ };
17
+ var hasConst = (schema) => {
18
+ return isSchemaObject(schema) && "const" in schema;
19
+ };
20
+ var hasPattern = (schema) => {
21
+ return isSchemaObject(schema) && "pattern" in schema && typeof schema.pattern === "string";
22
+ };
23
+ var hasFormat = (schema) => {
24
+ return isSchemaObject(schema) && "format" in schema && typeof schema.format === "string";
25
+ };
26
+ var hasDefault = (schema) => {
27
+ return isSchemaObject(schema) && "default" in schema;
28
+ };
29
+ var hasExamples = (schema) => {
30
+ return isSchemaObject(schema) && "examples" in schema && Array.isArray(schema.examples);
31
+ };
32
+ var hasOneOf = (schema) => {
33
+ return isSchemaObject(schema) && "oneOf" in schema && Array.isArray(schema.oneOf);
34
+ };
35
+ var hasAnyOf = (schema) => {
36
+ return isSchemaObject(schema) && "anyOf" in schema && Array.isArray(schema.anyOf);
37
+ };
38
+ var hasAllOf = (schema) => {
39
+ return isSchemaObject(schema) && "allOf" in schema && Array.isArray(schema.allOf);
40
+ };
41
+ var hasRequired = (schema) => {
42
+ return isSchemaObject(schema) && "required" in schema && Array.isArray(schema.required);
43
+ };
44
+ var hasItems = (schema) => {
45
+ return isSchemaObject(schema) && "items" in schema && typeof schema.items === "object" && schema.items !== null && typeof schema.items !== "boolean";
46
+ };
47
+ var hasAdditionalProperties = (schema) => {
48
+ return isSchemaObject(schema) && "additionalProperties" in schema;
49
+ };
50
+ var hasMinLength = (schema) => {
51
+ return isSchemaObject(schema) && "minLength" in schema && typeof schema.minLength === "number";
52
+ };
53
+ var hasMaxLength = (schema) => {
54
+ return isSchemaObject(schema) && "maxLength" in schema && typeof schema.maxLength === "number";
55
+ };
56
+ var hasMinimum = (schema) => {
57
+ return isSchemaObject(schema) && "minimum" in schema && typeof schema.minimum === "number";
58
+ };
59
+ var hasMaximum = (schema) => {
60
+ return isSchemaObject(schema) && "maximum" in schema && typeof schema.maximum === "number";
61
+ };
62
+ var hasExclusiveMinimum = (schema) => {
63
+ return isSchemaObject(schema) && "exclusiveMinimum" in schema && typeof schema.exclusiveMinimum === "number";
64
+ };
65
+ var hasExclusiveMaximum = (schema) => {
66
+ return isSchemaObject(schema) && "exclusiveMaximum" in schema && typeof schema.exclusiveMaximum === "number";
67
+ };
68
+ var hasMultipleOf = (schema) => {
69
+ return isSchemaObject(schema) && "multipleOf" in schema && typeof schema.multipleOf === "number";
70
+ };
71
+ var hasMinItems = (schema) => {
72
+ return isSchemaObject(schema) && "minItems" in schema && typeof schema.minItems === "number";
73
+ };
74
+ var hasMaxItems = (schema) => {
75
+ return isSchemaObject(schema) && "maxItems" in schema && typeof schema.maxItems === "number";
76
+ };
77
+ var hasUniqueItems = (schema) => {
78
+ return isSchemaObject(schema) && "uniqueItems" in schema && typeof schema.uniqueItems === "boolean";
79
+ };
80
+ var hasMinProperties = (schema) => {
81
+ return isSchemaObject(schema) && "minProperties" in schema && typeof schema.minProperties === "number";
82
+ };
83
+ var hasMaxProperties = (schema) => {
84
+ return isSchemaObject(schema) && "maxProperties" in schema && typeof schema.maxProperties === "number";
85
+ };
86
+ var hasRef = (schema) => {
87
+ return isSchemaObject(schema) && "$ref" in schema && typeof schema.$ref === "string";
88
+ };
89
+ export {
90
+ isSchemaObject,
91
+ isObjectSchema,
92
+ hasUniqueItems,
93
+ hasType,
94
+ hasRequired,
95
+ hasRef,
96
+ hasProperties,
97
+ hasPattern,
98
+ hasOneOf,
99
+ hasMultipleOf,
100
+ hasMinimum,
101
+ hasMinProperties,
102
+ hasMinLength,
103
+ hasMinItems,
104
+ hasMaximum,
105
+ hasMaxProperties,
106
+ hasMaxLength,
107
+ hasMaxItems,
108
+ hasItems,
109
+ hasFormat,
110
+ hasExclusiveMinimum,
111
+ hasExclusiveMaximum,
112
+ hasExamples,
113
+ hasEnum,
114
+ hasDefault,
115
+ hasConst,
116
+ hasAnyOf,
117
+ hasAllOf,
118
+ hasAdditionalProperties
119
+ };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Upgrades a JSON Schema draft-07 document to be compatible with the
3
+ * draft 2020-12 conventions used by the build pipeline.
4
+ *
5
+ * Draft-07 schemas differ from 2020-12 in two ways that affect our pipeline:
6
+ * - They use `definitions` instead of `$defs`
7
+ * - Their `definitions` keys (and `$ref` values) may be full URIs
8
+ * (e.g. `http://asyncapi.com/definitions/3.1.0/channel.json`) rather than
9
+ * short names (e.g. `channel`)
10
+ *
11
+ * This function:
12
+ * 1. Renames `definitions` → `$defs` at the root level only
13
+ * 2. Hoists any nested `$defs` (originally `definitions` inside sub-schemas)
14
+ * up to the root `$defs` with a prefixed name, rewriting internal refs
15
+ * so they resolve correctly from the root
16
+ * 3. Rewrites bare `$ref: "#"` self-references within each definition to
17
+ * point back to that definition's root-level `$defs` entry
18
+ *
19
+ * Only applied when the schema declares `$schema: http://json-schema.org/draft-07/schema`.
20
+ */
21
+ /**
22
+ * Returns true if the schema is a draft-07 document that needs upgrading.
23
+ */
24
+ export declare const isDraft07Schema: (schema: Record<string, unknown>) => boolean;
25
+ /**
26
+ * Upgrades a draft-07 schema so it is compatible with the build pipeline.
27
+ * If the schema is not draft-07, it is returned unchanged.
28
+ *
29
+ * @param schema - The raw JSON Schema (any draft)
30
+ * @returns The schema with `definitions` renamed to `$defs` at the root,
31
+ * nested defs hoisted to the root, and internal refs rewritten
32
+ */
33
+ export declare const upgradeDraft07Schema: (schema: Record<string, unknown>) => Record<string, unknown>;