micro-contracts 0.18.10 → 0.18.11
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 +7 -14
- package/cli-contract.yaml +15 -27
- package/dist/agents/context-builder.d.ts +5 -0
- package/dist/agents/context-builder.d.ts.map +1 -0
- package/dist/agents/context-builder.js +239 -0
- package/dist/agents/context-builder.js.map +1 -0
- package/dist/agents/formatter.d.ts +9 -0
- package/dist/agents/formatter.d.ts.map +1 -0
- package/dist/agents/formatter.js +124 -0
- package/dist/agents/formatter.js.map +1 -0
- package/dist/agents/index.d.ts +6 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +4 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/orchestrator.d.ts +5 -0
- package/dist/agents/orchestrator.d.ts.map +1 -0
- package/dist/agents/orchestrator.js +46 -0
- package/dist/agents/orchestrator.js.map +1 -0
- package/dist/agents/types.d.ts +29 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +7 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/cli/templates.d.ts +15 -0
- package/dist/cli/templates.d.ts.map +1 -0
- package/dist/cli/templates.js +445 -0
- package/dist/cli/templates.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +1201 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/audit-guardrails.d.ts +15 -0
- package/dist/commands/audit-guardrails.d.ts.map +1 -0
- package/dist/commands/audit-guardrails.js +33 -0
- package/dist/commands/audit-guardrails.js.map +1 -0
- package/dist/commands/audit-openapi.d.ts +15 -0
- package/dist/commands/audit-openapi.d.ts.map +1 -0
- package/dist/commands/audit-openapi.js +33 -0
- package/dist/commands/audit-openapi.js.map +1 -0
- package/dist/commands/insights.d.ts +8 -0
- package/dist/commands/insights.d.ts.map +1 -0
- package/dist/commands/insights.js +13 -0
- package/dist/commands/insights.js.map +1 -0
- package/dist/commands/propose-overlays.d.ts +15 -0
- package/dist/commands/propose-overlays.d.ts.map +1 -0
- package/dist/commands/propose-overlays.js +33 -0
- package/dist/commands/propose-overlays.js.map +1 -0
- package/dist/commands/review-published.d.ts +15 -0
- package/dist/commands/review-published.d.ts.map +1 -0
- package/dist/commands/review-published.js +33 -0
- package/dist/commands/review-published.js.map +1 -0
- package/dist/external/insight-provider.d.ts.map +1 -0
- package/dist/external/insight-provider.js.map +1 -0
- package/dist/generated/commands.d.ts +2 -0
- package/dist/generated/commands.d.ts.map +1 -0
- package/dist/generated/commands.js +2 -0
- package/dist/generated/commands.js.map +1 -0
- package/dist/generated/contract.d.ts +3 -0
- package/dist/generated/contract.d.ts.map +1 -0
- package/dist/generated/contract.js +5 -0
- package/dist/generated/contract.js.map +1 -0
- package/dist/generated/dsl/agents.d.ts +34 -0
- package/dist/generated/dsl/agents.d.ts.map +1 -0
- package/dist/generated/dsl/agents.js +98 -0
- package/dist/generated/dsl/agents.js.map +1 -0
- package/dist/generated/dsl/dsl-data.d.ts +7 -0
- package/dist/generated/dsl/dsl-data.d.ts.map +1 -0
- package/dist/generated/dsl/dsl-data.js +1041 -0
- package/dist/generated/dsl/dsl-data.js.map +1 -0
- package/dist/generated/dsl/handoffs.d.ts +457 -0
- package/dist/generated/dsl/handoffs.d.ts.map +1 -0
- package/dist/generated/dsl/handoffs.js +205 -0
- package/dist/generated/dsl/handoffs.js.map +1 -0
- package/dist/generated/dsl/index.d.ts +14 -0
- package/dist/generated/dsl/index.d.ts.map +1 -0
- package/dist/generated/dsl/index.js +11 -0
- package/dist/generated/dsl/index.js.map +1 -0
- package/dist/generated/dsl/tasks.d.ts +28 -0
- package/dist/generated/dsl/tasks.d.ts.map +1 -0
- package/dist/generated/dsl/tasks.js +137 -0
- package/dist/generated/dsl/tasks.js.map +1 -0
- package/dist/generated/dsl/workflows.d.ts +34 -0
- package/dist/generated/dsl/workflows.d.ts.map +1 -0
- package/dist/generated/dsl/workflows.js +84 -0
- package/dist/generated/dsl/workflows.js.map +1 -0
- package/dist/generated/index.d.ts +8 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +8 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/policy-runtime.d.ts +114 -0
- package/dist/generated/policy-runtime.d.ts.map +1 -0
- package/dist/generated/policy-runtime.js +195 -0
- package/dist/generated/policy-runtime.js.map +1 -0
- package/dist/generated/policy.d.ts +658 -0
- package/dist/generated/policy.d.ts.map +1 -0
- package/dist/generated/policy.js +844 -0
- package/dist/generated/policy.js.map +1 -0
- package/dist/generated/program.d.ts +120 -0
- package/dist/generated/program.d.ts.map +1 -0
- package/dist/generated/program.js +370 -0
- package/dist/generated/program.js.map +1 -0
- package/dist/generated/schemas.d.ts +779 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +1006 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/generated/types.d.ts +786 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +3 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/generator/dependencyGenerator.d.ts +16 -0
- package/dist/generator/dependencyGenerator.d.ts.map +1 -0
- package/dist/generator/dependencyGenerator.js +25 -0
- package/dist/generator/dependencyGenerator.js.map +1 -0
- package/dist/generator/index.d.ts +47 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/index.js +707 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/generator/inputHash.d.ts +23 -0
- package/dist/generator/inputHash.d.ts.map +1 -0
- package/dist/generator/inputHash.js +138 -0
- package/dist/generator/inputHash.js.map +1 -0
- package/dist/generator/linter.d.ts +26 -0
- package/dist/generator/linter.d.ts.map +1 -0
- package/dist/generator/linter.js +441 -0
- package/dist/generator/linter.js.map +1 -0
- package/dist/generator/overlayProcessor.d.ts +71 -0
- package/dist/generator/overlayProcessor.d.ts.map +1 -0
- package/dist/generator/overlayProcessor.js +500 -0
- package/dist/generator/overlayProcessor.js.map +1 -0
- package/dist/generator/schemaGenerator.d.ts +10 -0
- package/dist/generator/schemaGenerator.d.ts.map +1 -0
- package/dist/generator/schemaGenerator.js +296 -0
- package/dist/generator/schemaGenerator.js.map +1 -0
- package/dist/generator/serviceGenerator.d.ts +20 -0
- package/dist/generator/serviceGenerator.d.ts.map +1 -0
- package/dist/generator/serviceGenerator.js +293 -0
- package/dist/generator/serviceGenerator.js.map +1 -0
- package/dist/generator/templateProcessor.d.ts +208 -0
- package/dist/generator/templateProcessor.d.ts.map +1 -0
- package/dist/generator/templateProcessor.js +604 -0
- package/dist/generator/templateProcessor.js.map +1 -0
- package/dist/generator/typeGenerator.d.ts +22 -0
- package/dist/generator/typeGenerator.d.ts.map +1 -0
- package/dist/generator/typeGenerator.js +439 -0
- package/dist/generator/typeGenerator.js.map +1 -0
- package/dist/generator/typeGenerator.test.d.ts +2 -0
- package/dist/generator/typeGenerator.test.d.ts.map +1 -0
- package/dist/generator/typeGenerator.test.js +155 -0
- package/dist/generator/typeGenerator.test.js.map +1 -0
- package/dist/glob.d.ts +22 -0
- package/dist/glob.d.ts.map +1 -0
- package/dist/glob.js +103 -0
- package/dist/glob.js.map +1 -0
- package/dist/guardrails/allowlist.d.ts +30 -0
- package/dist/guardrails/allowlist.d.ts.map +1 -0
- package/dist/guardrails/allowlist.js +174 -0
- package/dist/guardrails/allowlist.js.map +1 -0
- package/dist/guardrails/config.d.ts +40 -0
- package/dist/guardrails/config.d.ts.map +1 -0
- package/dist/guardrails/config.js +177 -0
- package/dist/guardrails/config.js.map +1 -0
- package/dist/guardrails/drift.d.ts +19 -0
- package/dist/guardrails/drift.d.ts.map +1 -0
- package/dist/guardrails/drift.js +115 -0
- package/dist/guardrails/drift.js.map +1 -0
- package/dist/guardrails/index.d.ts +18 -0
- package/dist/guardrails/index.d.ts.map +1 -0
- package/dist/guardrails/index.js +21 -0
- package/dist/guardrails/index.js.map +1 -0
- package/dist/guardrails/lint.d.ts +16 -0
- package/dist/guardrails/lint.d.ts.map +1 -0
- package/dist/guardrails/lint.js +172 -0
- package/dist/guardrails/lint.js.map +1 -0
- package/dist/guardrails/manifest.d.ts +63 -0
- package/dist/guardrails/manifest.d.ts.map +1 -0
- package/dist/guardrails/manifest.js +310 -0
- package/dist/guardrails/manifest.js.map +1 -0
- package/dist/guardrails/runner.d.ts +53 -0
- package/dist/guardrails/runner.d.ts.map +1 -0
- package/dist/guardrails/runner.js +387 -0
- package/dist/guardrails/runner.js.map +1 -0
- package/dist/guardrails/types.d.ts +196 -0
- package/dist/guardrails/types.d.ts.map +1 -0
- package/dist/guardrails/types.js +8 -0
- package/dist/guardrails/types.js.map +1 -0
- package/dist/index.d.ts +21 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -4
- package/dist/index.js.map +1 -0
- package/dist/micro-contracts.bundle.mjs +349 -374
- package/dist/micro-contracts.bundle.mjs.map +3 -3
- package/dist/types.d.ts +502 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +409 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +31 -0
- package/dist/version.js.map +1 -0
- package/docs/cli-reference.md +13 -15
- package/docs/development-guardrails.md +3 -3
- package/docs/screen-spec.md +3 -3
- package/package.json +13 -12
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type generator from OpenAPI schemas
|
|
3
|
+
*/
|
|
4
|
+
import { isReference, getRefName, isTsIdentifier } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Normalize OpenAPI 3.1 type arrays into a non-null type and a nullable flag.
|
|
7
|
+
* Returns undefined for type if the schema has no type field.
|
|
8
|
+
*/
|
|
9
|
+
function normalizeType(schema) {
|
|
10
|
+
const raw = schema.type;
|
|
11
|
+
if (raw === undefined) {
|
|
12
|
+
return { types: [], nullable: !!schema.nullable };
|
|
13
|
+
}
|
|
14
|
+
const arr = Array.isArray(raw) ? raw : [raw];
|
|
15
|
+
const hasNull = arr.includes('null');
|
|
16
|
+
const nonNull = arr.filter((t) => t !== 'null');
|
|
17
|
+
return { types: nonNull, nullable: hasNull || !!schema.nullable };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generate TypeScript type definitions from OpenAPI spec
|
|
21
|
+
*/
|
|
22
|
+
export function generateTypes(spec) {
|
|
23
|
+
const lines = [];
|
|
24
|
+
lines.push('/**');
|
|
25
|
+
lines.push(' * Auto-generated TypeScript types from OpenAPI specification');
|
|
26
|
+
lines.push(` * Generated from: ${spec.info.title} v${spec.info.version}`);
|
|
27
|
+
lines.push(' * DO NOT EDIT MANUALLY');
|
|
28
|
+
lines.push(' */');
|
|
29
|
+
lines.push('');
|
|
30
|
+
// Always include ProblemDetails (RFC 9457) for error handling
|
|
31
|
+
lines.push(generateProblemDetailsType());
|
|
32
|
+
lines.push('');
|
|
33
|
+
// Generate types from components/schemas
|
|
34
|
+
if (spec.components?.schemas) {
|
|
35
|
+
for (const [name, schema] of Object.entries(spec.components.schemas)) {
|
|
36
|
+
// Skip if already generated (e.g., ProblemDetails)
|
|
37
|
+
if (name === 'ProblemDetails')
|
|
38
|
+
continue;
|
|
39
|
+
lines.push(generateSchemaType(name, schema, spec));
|
|
40
|
+
lines.push('');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Generate request/response types from paths
|
|
44
|
+
const operationTypes = generateOperationTypes(spec);
|
|
45
|
+
if (operationTypes) {
|
|
46
|
+
lines.push('// Operation-specific types');
|
|
47
|
+
lines.push(operationTypes);
|
|
48
|
+
}
|
|
49
|
+
return lines.join('\n');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Generate ProblemDetails type (RFC 9457)
|
|
53
|
+
* This is always included for standardized error handling
|
|
54
|
+
*/
|
|
55
|
+
function generateProblemDetailsType() {
|
|
56
|
+
return `/**
|
|
57
|
+
* RFC 9457 Problem Details for HTTP APIs
|
|
58
|
+
* @see https://www.rfc-editor.org/rfc/rfc9457.html
|
|
59
|
+
*/
|
|
60
|
+
export interface ProblemDetails {
|
|
61
|
+
/** A URI reference that identifies the problem type */
|
|
62
|
+
type: string;
|
|
63
|
+
/** A short, human-readable summary */
|
|
64
|
+
title: string;
|
|
65
|
+
/** The HTTP status code */
|
|
66
|
+
status: number;
|
|
67
|
+
/** A human-readable explanation specific to this occurrence */
|
|
68
|
+
detail?: string;
|
|
69
|
+
/** A URI reference to the specific occurrence */
|
|
70
|
+
instance?: string;
|
|
71
|
+
/** Application-specific error code (SCREAMING_SNAKE_CASE) */
|
|
72
|
+
code?: string;
|
|
73
|
+
/** Request trace ID for debugging */
|
|
74
|
+
traceId?: string;
|
|
75
|
+
/** Detailed validation errors */
|
|
76
|
+
errors?: ValidationError[];
|
|
77
|
+
/** Additional properties */
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Validation error detail
|
|
83
|
+
*/
|
|
84
|
+
export interface ValidationError {
|
|
85
|
+
/** JSON Pointer to the invalid field */
|
|
86
|
+
pointer: string;
|
|
87
|
+
/** Error message for this field */
|
|
88
|
+
detail: string;
|
|
89
|
+
}`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Generate TypeScript type for a single schema
|
|
93
|
+
*/
|
|
94
|
+
function generateSchemaType(name, schema, spec) {
|
|
95
|
+
if (isReference(schema)) {
|
|
96
|
+
const refName = getRefName(schema.$ref);
|
|
97
|
+
return `export type ${name} = ${refName};`;
|
|
98
|
+
}
|
|
99
|
+
// Handle allOf, oneOf, anyOf
|
|
100
|
+
if (schema.allOf) {
|
|
101
|
+
const types = schema.allOf.map(s => schemaToTypeString(s, spec)).join(' & ');
|
|
102
|
+
return `export type ${name} = ${types};`;
|
|
103
|
+
}
|
|
104
|
+
if (schema.oneOf) {
|
|
105
|
+
const types = schema.oneOf.map(s => schemaToTypeString(s, spec)).join(' | ');
|
|
106
|
+
return `export type ${name} = ${types};`;
|
|
107
|
+
}
|
|
108
|
+
if (schema.anyOf) {
|
|
109
|
+
const types = schema.anyOf.map(s => schemaToTypeString(s, spec)).join(' | ');
|
|
110
|
+
return `export type ${name} = ${types};`;
|
|
111
|
+
}
|
|
112
|
+
const { types, nullable } = normalizeType(schema);
|
|
113
|
+
// Handle object type
|
|
114
|
+
if (types.includes('object') || schema.properties) {
|
|
115
|
+
return generateInterfaceType(name, schema, spec);
|
|
116
|
+
}
|
|
117
|
+
// Handle enum
|
|
118
|
+
if (schema.enum) {
|
|
119
|
+
const enumValues = schema.enum.map(v => typeof v === 'string' ? `'${v}'` : String(v)).join(' | ');
|
|
120
|
+
const suffix = nullable ? ' | null' : '';
|
|
121
|
+
return `export type ${name} = ${enumValues}${suffix};`;
|
|
122
|
+
}
|
|
123
|
+
// Handle array
|
|
124
|
+
if (types.includes('array') && schema.items) {
|
|
125
|
+
const itemType = schemaToTypeString(schema.items, spec);
|
|
126
|
+
const suffix = nullable ? ' | null' : '';
|
|
127
|
+
return `export type ${name} = ${itemType}[]${suffix};`;
|
|
128
|
+
}
|
|
129
|
+
// Handle primitive types (including type arrays like ['string', 'null'])
|
|
130
|
+
const tsType = resolveTypeString(types, schema, nullable);
|
|
131
|
+
return `export type ${name} = ${tsType};`;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Generate interface type for object schema
|
|
135
|
+
*/
|
|
136
|
+
function generateInterfaceType(name, schema, spec) {
|
|
137
|
+
const lines = [];
|
|
138
|
+
const required = new Set(schema.required || []);
|
|
139
|
+
if (schema.description) {
|
|
140
|
+
lines.push(`/** ${schema.description} */`);
|
|
141
|
+
}
|
|
142
|
+
lines.push(`export interface ${name} {`);
|
|
143
|
+
if (schema.properties) {
|
|
144
|
+
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
|
145
|
+
const isRequired = required.has(propName);
|
|
146
|
+
const tsType = schemaToTypeString(propSchema, spec);
|
|
147
|
+
const optional = isRequired ? '' : '?';
|
|
148
|
+
// Add description as JSDoc if available
|
|
149
|
+
if (!isReference(propSchema) && propSchema.description) {
|
|
150
|
+
lines.push(` /** ${propSchema.description} */`);
|
|
151
|
+
}
|
|
152
|
+
lines.push(` ${formatPropertyKey(propName)}${optional}: ${tsType};`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Handle additionalProperties
|
|
156
|
+
if (schema.additionalProperties) {
|
|
157
|
+
if (typeof schema.additionalProperties === 'boolean') {
|
|
158
|
+
lines.push(' [key: string]: unknown;');
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
const valueType = schemaToTypeString(schema.additionalProperties, spec);
|
|
162
|
+
lines.push(` [key: string]: ${valueType};`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
lines.push('}');
|
|
166
|
+
return lines.join('\n');
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Convert schema to TypeScript type string
|
|
170
|
+
*/
|
|
171
|
+
function schemaToTypeString(schema, spec) {
|
|
172
|
+
if (isReference(schema)) {
|
|
173
|
+
return getRefName(schema.$ref);
|
|
174
|
+
}
|
|
175
|
+
const { types, nullable } = normalizeType(schema);
|
|
176
|
+
const nullSuffix = nullable ? ' | null' : '';
|
|
177
|
+
// Handle allOf, oneOf, anyOf
|
|
178
|
+
if (schema.allOf) {
|
|
179
|
+
const ts = schema.allOf.map(s => schemaToTypeString(s, spec)).join(' & ');
|
|
180
|
+
return `(${ts})${nullSuffix}`;
|
|
181
|
+
}
|
|
182
|
+
if (schema.oneOf) {
|
|
183
|
+
const ts = schema.oneOf.map(s => schemaToTypeString(s, spec)).join(' | ');
|
|
184
|
+
return `(${ts})${nullSuffix}`;
|
|
185
|
+
}
|
|
186
|
+
if (schema.anyOf) {
|
|
187
|
+
const ts = schema.anyOf.map(s => schemaToTypeString(s, spec)).join(' | ');
|
|
188
|
+
return `(${ts})${nullSuffix}`;
|
|
189
|
+
}
|
|
190
|
+
// Handle enum
|
|
191
|
+
if (schema.enum) {
|
|
192
|
+
const enumValues = schema.enum.map(v => typeof v === 'string' ? `'${v}'` : String(v)).join(' | ');
|
|
193
|
+
return `(${enumValues})${nullSuffix}`;
|
|
194
|
+
}
|
|
195
|
+
// Handle array
|
|
196
|
+
if (types.includes('array') && schema.items) {
|
|
197
|
+
const itemType = schemaToTypeString(schema.items, spec);
|
|
198
|
+
const wrappedItemType = itemType.includes(' | ') || itemType.includes(' & ')
|
|
199
|
+
? `(${itemType})`
|
|
200
|
+
: itemType;
|
|
201
|
+
return `${wrappedItemType}[]${nullSuffix}`;
|
|
202
|
+
}
|
|
203
|
+
// Handle object with inline properties
|
|
204
|
+
if (types.includes('object') || schema.properties) {
|
|
205
|
+
if (!schema.properties) {
|
|
206
|
+
if (schema.additionalProperties) {
|
|
207
|
+
if (typeof schema.additionalProperties === 'boolean') {
|
|
208
|
+
return `Record<string, unknown>${nullSuffix}`;
|
|
209
|
+
}
|
|
210
|
+
const valueType = schemaToTypeString(schema.additionalProperties, spec);
|
|
211
|
+
return `Record<string, ${valueType}>${nullSuffix}`;
|
|
212
|
+
}
|
|
213
|
+
return `Record<string, unknown>${nullSuffix}`;
|
|
214
|
+
}
|
|
215
|
+
const props = [];
|
|
216
|
+
const required = new Set(schema.required || []);
|
|
217
|
+
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
|
218
|
+
const isRequired = required.has(propName);
|
|
219
|
+
const tsType = schemaToTypeString(propSchema, spec);
|
|
220
|
+
const optional = isRequired ? '' : '?';
|
|
221
|
+
props.push(`${formatPropertyKey(propName)}${optional}: ${tsType}`);
|
|
222
|
+
}
|
|
223
|
+
return `{ ${props.join('; ')} }${nullSuffix}`;
|
|
224
|
+
}
|
|
225
|
+
// Handle primitive types (including type arrays like ['string', 'null'])
|
|
226
|
+
return resolveTypeString(types, schema, nullable);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Map a single OpenAPI type name to its TypeScript equivalent
|
|
230
|
+
*/
|
|
231
|
+
function singleTypeToTs(typeName) {
|
|
232
|
+
switch (typeName) {
|
|
233
|
+
case 'string':
|
|
234
|
+
return 'string';
|
|
235
|
+
case 'integer':
|
|
236
|
+
case 'number':
|
|
237
|
+
return 'number';
|
|
238
|
+
case 'boolean':
|
|
239
|
+
return 'boolean';
|
|
240
|
+
case 'null':
|
|
241
|
+
return 'null';
|
|
242
|
+
case 'object':
|
|
243
|
+
return 'Record<string, unknown>';
|
|
244
|
+
case 'array':
|
|
245
|
+
return 'unknown[]';
|
|
246
|
+
default:
|
|
247
|
+
return 'unknown';
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Resolve an array of OpenAPI types (with nullable flag) into a TypeScript type string.
|
|
252
|
+
* Handles both single-type and multi-type (OpenAPI 3.1 union) cases.
|
|
253
|
+
*/
|
|
254
|
+
function resolveTypeString(types, _schema, nullable) {
|
|
255
|
+
const nullSuffix = nullable ? ' | null' : '';
|
|
256
|
+
if (types.length === 0) {
|
|
257
|
+
return `unknown${nullSuffix}`;
|
|
258
|
+
}
|
|
259
|
+
const tsTypes = types.map(t => singleTypeToTs(t));
|
|
260
|
+
const unique = [...new Set(tsTypes)];
|
|
261
|
+
return unique.join(' | ') + nullSuffix;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Generate a valid TypeScript identifier from service and method
|
|
265
|
+
* e.g., "User" + "getSchema" -> "User_getSchema"
|
|
266
|
+
*/
|
|
267
|
+
function getOperationTypeName(operation) {
|
|
268
|
+
const service = operation['x-micro-contracts-service'];
|
|
269
|
+
const method = operation['x-micro-contracts-method'];
|
|
270
|
+
if (service && method) {
|
|
271
|
+
// Use x-micro-contracts-service + _ + x-micro-contracts-method for type name
|
|
272
|
+
return `${service}_${method}`;
|
|
273
|
+
}
|
|
274
|
+
// Fallback: sanitize operationId (replace dots with underscores, etc.)
|
|
275
|
+
if (operation.operationId) {
|
|
276
|
+
return operation.operationId.replace(/[^a-zA-Z0-9]/g, '_');
|
|
277
|
+
}
|
|
278
|
+
return 'Unknown';
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The type names generated for one operation.
|
|
282
|
+
*
|
|
283
|
+
* The single definition of what an operation contributes to types.ts: the
|
|
284
|
+
* emitter below and the deps/ re-exports both read it, so a re-export cannot
|
|
285
|
+
* name a type that is never generated.
|
|
286
|
+
*/
|
|
287
|
+
export function operationTypeNames(operation) {
|
|
288
|
+
const base = getOperationTypeName(operation);
|
|
289
|
+
const allParams = (operation.parameters || []).filter((p) => !isReference(p) && (p.in === 'query' || p.in === 'path'));
|
|
290
|
+
const params = allParams.length > 0 ? `${base}Params` : undefined;
|
|
291
|
+
let body;
|
|
292
|
+
if (operation.requestBody) {
|
|
293
|
+
if (isReference(operation.requestBody)) {
|
|
294
|
+
body = getRefName(operation.requestBody.$ref);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
const content = operation.requestBody.content?.['application/json'];
|
|
298
|
+
if (content?.schema) {
|
|
299
|
+
if (isReference(content.schema)) {
|
|
300
|
+
body = getRefName(content.schema.$ref);
|
|
301
|
+
}
|
|
302
|
+
else if (content.schema.properties || normalizeType(content.schema).types.includes('object')) {
|
|
303
|
+
body = `${base}Body`;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return { base, input: `${base}Input`, params, body };
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Generate parameter types for operations
|
|
312
|
+
*/
|
|
313
|
+
function generateOperationTypes(spec) {
|
|
314
|
+
const lines = [];
|
|
315
|
+
const generatedTypes = new Set();
|
|
316
|
+
for (const pathItem of Object.values(spec.paths)) {
|
|
317
|
+
for (const method of ['get', 'post', 'put', 'patch', 'delete']) {
|
|
318
|
+
const operation = pathItem[method];
|
|
319
|
+
if (!operation)
|
|
320
|
+
continue;
|
|
321
|
+
const { input: inputTypeName, params: paramsTypeName, body: bodyTypeName } = operationTypeNames(operation);
|
|
322
|
+
if (paramsTypeName && !generatedTypes.has(paramsTypeName)) {
|
|
323
|
+
const allParams = (operation.parameters || []).filter((p) => !isReference(p) && (p.in === 'query' || p.in === 'path'));
|
|
324
|
+
generatedTypes.add(paramsTypeName);
|
|
325
|
+
lines.push(generateParamsType(paramsTypeName, allParams, spec));
|
|
326
|
+
lines.push('');
|
|
327
|
+
}
|
|
328
|
+
// An inline body schema needs its interface emitted; a $ref body names an
|
|
329
|
+
// existing component schema.
|
|
330
|
+
const inlineBodySchema = operation.requestBody && !isReference(operation.requestBody)
|
|
331
|
+
? operation.requestBody.content?.['application/json']?.schema
|
|
332
|
+
: undefined;
|
|
333
|
+
if (bodyTypeName && inlineBodySchema && !isReference(inlineBodySchema) && !generatedTypes.has(bodyTypeName)) {
|
|
334
|
+
generatedTypes.add(bodyTypeName);
|
|
335
|
+
lines.push(generateRequestBodyType(bodyTypeName, inlineBodySchema, spec));
|
|
336
|
+
lines.push('');
|
|
337
|
+
}
|
|
338
|
+
// Generate Input type that combines params and body
|
|
339
|
+
// - params are flattened (path + query combined)
|
|
340
|
+
// - body becomes 'data' (not HTTP-specific)
|
|
341
|
+
// - Always generate (empty object for parameterless operations)
|
|
342
|
+
if (!generatedTypes.has(inputTypeName)) {
|
|
343
|
+
generatedTypes.add(inputTypeName);
|
|
344
|
+
lines.push(generateInputType(inputTypeName, paramsTypeName, bodyTypeName));
|
|
345
|
+
lines.push('');
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return lines.join('\n');
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Generate Input type that combines params and body
|
|
353
|
+
* - params (path + query) are flattened (HTTP details hidden)
|
|
354
|
+
* - body is renamed to 'data' (not HTTP-specific naming)
|
|
355
|
+
* - parameterless operations get empty object type
|
|
356
|
+
*
|
|
357
|
+
* Examples:
|
|
358
|
+
* - No params: type Input = Record<string, never>; (empty object)
|
|
359
|
+
* - Params only: type Input = Params;
|
|
360
|
+
* - Body only: type Input = { data: Body };
|
|
361
|
+
* - Params + Body: type Input = Params & { data: Body };
|
|
362
|
+
*/
|
|
363
|
+
function generateInputType(name, paramsType, bodyType) {
|
|
364
|
+
const parts = [];
|
|
365
|
+
// Flatten params (path + query parameters become direct properties)
|
|
366
|
+
if (paramsType) {
|
|
367
|
+
parts.push(paramsType);
|
|
368
|
+
}
|
|
369
|
+
// Body becomes 'data' property (not HTTP-specific naming)
|
|
370
|
+
if (bodyType) {
|
|
371
|
+
parts.push(`{ data: ${bodyType} }`);
|
|
372
|
+
}
|
|
373
|
+
// Generate type alias
|
|
374
|
+
if (parts.length === 0) {
|
|
375
|
+
// Parameterless operation: empty object type
|
|
376
|
+
return `export type ${name} = Record<string, never>;`;
|
|
377
|
+
}
|
|
378
|
+
else if (parts.length === 1) {
|
|
379
|
+
return `export type ${name} = ${parts[0]};`;
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
return `export type ${name} = ${parts.join(' & ')};`;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Generate request body interface
|
|
387
|
+
*/
|
|
388
|
+
function generateRequestBodyType(name, schema, spec) {
|
|
389
|
+
const lines = [];
|
|
390
|
+
lines.push(`export interface ${name} {`);
|
|
391
|
+
if (schema.properties) {
|
|
392
|
+
const required = new Set(schema.required || []);
|
|
393
|
+
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
|
394
|
+
const isRequired = required.has(propName);
|
|
395
|
+
const optional = isRequired ? '' : '?';
|
|
396
|
+
const tsType = schemaToTypeString(propSchema, spec);
|
|
397
|
+
if (isReference(propSchema)) {
|
|
398
|
+
// No description for refs
|
|
399
|
+
}
|
|
400
|
+
else if (propSchema.description) {
|
|
401
|
+
lines.push(` /** ${propSchema.description} */`);
|
|
402
|
+
}
|
|
403
|
+
lines.push(` ${formatPropertyKey(propName)}${optional}: ${tsType};`);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
lines.push('}');
|
|
407
|
+
return lines.join('\n');
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Generate params interface (combines path + query parameters)
|
|
411
|
+
*/
|
|
412
|
+
function generateParamsType(name, params, spec) {
|
|
413
|
+
const lines = [];
|
|
414
|
+
lines.push(`export interface ${name} {`);
|
|
415
|
+
for (const param of params) {
|
|
416
|
+
const optional = param.required ? '' : '?';
|
|
417
|
+
let tsType = 'unknown';
|
|
418
|
+
if (param.schema) {
|
|
419
|
+
tsType = schemaToTypeString(param.schema, spec);
|
|
420
|
+
}
|
|
421
|
+
if (param.description) {
|
|
422
|
+
lines.push(` /** ${param.description} */`);
|
|
423
|
+
}
|
|
424
|
+
lines.push(` ${formatPropertyKey(param.name)}${optional}: ${tsType};`);
|
|
425
|
+
}
|
|
426
|
+
lines.push('}');
|
|
427
|
+
return lines.join('\n');
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Render an OpenAPI property name as a TypeScript property key.
|
|
431
|
+
* Schema property names are arbitrary strings, so names that are not
|
|
432
|
+
* identifiers are emitted as quoted keys.
|
|
433
|
+
*/
|
|
434
|
+
function formatPropertyKey(name) {
|
|
435
|
+
if (isTsIdentifier(name))
|
|
436
|
+
return name;
|
|
437
|
+
return `'${name.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
|
|
438
|
+
}
|
|
439
|
+
//# sourceMappingURL=typeGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeGenerator.js","sourceRoot":"","sources":["../../src/generator/typeGenerator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEtE;;;GAGG;AACH,SAAS,aAAa,CAAC,MAAoB;IACzC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC;IACxB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC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I,CAAC,SAAS,KAAK,CAAC,WAAW,KAAK,CAAC,CAAC;QAC9C,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,KAAK,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,KAAK,MAAM,GAAG,CAAC,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;;;GAIG;AACH,SAAS,iBAAiB,CAAC,IAAY;IACrC,IAAI,cAAc,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeGenerator.test.d.ts","sourceRoot":"","sources":["../../src/generator/typeGenerator.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { generateTypes } from './typeGenerator.js';
|
|
3
|
+
function minimalSpec(schemas) {
|
|
4
|
+
return {
|
|
5
|
+
openapi: '3.1.0',
|
|
6
|
+
info: { title: 'Test', version: '1.0.0' },
|
|
7
|
+
paths: {},
|
|
8
|
+
components: { schemas: schemas },
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function extractInterface(output, name) {
|
|
12
|
+
const re = new RegExp(`export interface ${name} \\{[\\s\\S]*?\\n\\}`, 'm');
|
|
13
|
+
const match = output.match(re);
|
|
14
|
+
return match ? match[0] : '';
|
|
15
|
+
}
|
|
16
|
+
describe('OpenAPI 3.1 type array nullable syntax', () => {
|
|
17
|
+
it('generates string | null for type: [string, null]', () => {
|
|
18
|
+
const spec = minimalSpec({
|
|
19
|
+
Example: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
required: ['name'],
|
|
22
|
+
properties: {
|
|
23
|
+
name: { type: 'string' },
|
|
24
|
+
phase: { type: ['string', 'null'], description: 'nullable string' },
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const output = generateTypes(spec);
|
|
29
|
+
const iface = extractInterface(output, 'Example');
|
|
30
|
+
expect(iface).toContain('phase?: string | null;');
|
|
31
|
+
expect(iface).toContain('name: string;');
|
|
32
|
+
});
|
|
33
|
+
it('generates number | null for type: [number, null]', () => {
|
|
34
|
+
const spec = minimalSpec({
|
|
35
|
+
Example: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
properties: {
|
|
38
|
+
count: { type: ['number', 'null'] },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const output = generateTypes(spec);
|
|
43
|
+
expect(output).toContain('count?: number | null;');
|
|
44
|
+
});
|
|
45
|
+
it('generates number | null for type: [integer, null]', () => {
|
|
46
|
+
const spec = minimalSpec({
|
|
47
|
+
Example: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
properties: {
|
|
50
|
+
count: { type: ['integer', 'null'] },
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
const output = generateTypes(spec);
|
|
55
|
+
expect(output).toContain('count?: number | null;');
|
|
56
|
+
});
|
|
57
|
+
it('generates string | number for type: [string, integer]', () => {
|
|
58
|
+
const spec = minimalSpec({
|
|
59
|
+
Example: {
|
|
60
|
+
type: 'object',
|
|
61
|
+
properties: {
|
|
62
|
+
value: { type: ['string', 'integer'] },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const output = generateTypes(spec);
|
|
67
|
+
expect(output).toContain('value?: string | number;');
|
|
68
|
+
});
|
|
69
|
+
it('generates string | number | null for type: [string, integer, null]', () => {
|
|
70
|
+
const spec = minimalSpec({
|
|
71
|
+
Example: {
|
|
72
|
+
type: 'object',
|
|
73
|
+
properties: {
|
|
74
|
+
value: { type: ['string', 'integer', 'null'] },
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
const output = generateTypes(spec);
|
|
79
|
+
expect(output).toContain('value?: string | number | null;');
|
|
80
|
+
});
|
|
81
|
+
it('still supports OpenAPI 3.0 nullable: true syntax', () => {
|
|
82
|
+
const spec = minimalSpec({
|
|
83
|
+
Example: {
|
|
84
|
+
type: 'object',
|
|
85
|
+
properties: {
|
|
86
|
+
phase: { type: 'string', nullable: true },
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const output = generateTypes(spec);
|
|
91
|
+
expect(output).toContain('phase?: string | null;');
|
|
92
|
+
});
|
|
93
|
+
it('handles both 3.0 and 3.1 nullable in the same schema', () => {
|
|
94
|
+
const spec = minimalSpec({
|
|
95
|
+
Example: {
|
|
96
|
+
type: 'object',
|
|
97
|
+
required: ['name'],
|
|
98
|
+
properties: {
|
|
99
|
+
name: { type: 'string' },
|
|
100
|
+
phase_v31: { type: ['string', 'null'], description: 'Nullable string (3.1 syntax)' },
|
|
101
|
+
phase_v30: { type: 'string', nullable: true, description: 'Nullable string (3.0 syntax)' },
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
const output = generateTypes(spec);
|
|
106
|
+
const iface = extractInterface(output, 'Example');
|
|
107
|
+
expect(iface).toContain('name: string;');
|
|
108
|
+
expect(iface).toContain('phase_v31?: string | null;');
|
|
109
|
+
expect(iface).toContain('phase_v30?: string | null;');
|
|
110
|
+
expect(iface).not.toContain('unknown');
|
|
111
|
+
});
|
|
112
|
+
it('quotes property names that are not valid identifiers', () => {
|
|
113
|
+
const spec = minimalSpec({
|
|
114
|
+
Setting: {
|
|
115
|
+
type: 'object',
|
|
116
|
+
description: 'app settings',
|
|
117
|
+
properties: {
|
|
118
|
+
'{any}': { type: 'string', description: 'free-form key' },
|
|
119
|
+
'kebab-case': { type: 'number' },
|
|
120
|
+
"it's": { type: 'string' },
|
|
121
|
+
plain: { type: 'string' },
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
const iface = extractInterface(generateTypes(spec), 'Setting');
|
|
126
|
+
expect(iface).toContain("'{any}'?: string;");
|
|
127
|
+
expect(iface).toContain("'kebab-case'?: number;");
|
|
128
|
+
expect(iface).toContain("'it\\'s'?: string;");
|
|
129
|
+
expect(iface).toContain('plain?: string;');
|
|
130
|
+
});
|
|
131
|
+
it('quotes non-identifier property names in inline object types', () => {
|
|
132
|
+
const spec = minimalSpec({
|
|
133
|
+
Wrapper: {
|
|
134
|
+
type: 'object',
|
|
135
|
+
properties: {
|
|
136
|
+
nested: {
|
|
137
|
+
type: 'object',
|
|
138
|
+
properties: { 'x-header': { type: 'string' } },
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
expect(generateTypes(spec)).toContain("'x-header'?: string");
|
|
144
|
+
});
|
|
145
|
+
it('generates top-level type alias with nullable type array', () => {
|
|
146
|
+
const spec = minimalSpec({
|
|
147
|
+
NullableString: {
|
|
148
|
+
type: ['string', 'null'],
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
const output = generateTypes(spec);
|
|
152
|
+
expect(output).toContain('export type NullableString = string | null;');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
//# sourceMappingURL=typeGenerator.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeGenerator.test.js","sourceRoot":"","sources":["../../src/generator/typeGenerator.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,SAAS,WAAW,CAAC,OAAgC;IACnD,OAAO;QACL,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE,EAAE,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,QAAQ;gBACd,UAAU,EAAE;oBACV,MAAM,EAAE;wBACN,IAAI,EAAE,QAAQ;wBACd,UAAU,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;qBAC/C;iBACF;aACF;SACF,CAAC,CAAC;QACH,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;QACjE,MAAM,IAAI,GAAG,WAAW,CAAC;YACvB,cAAc,EAAE;gBACd,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC;aACzB;SACF,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,6CAA6C,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/glob.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Glob matching.
|
|
3
|
+
*
|
|
4
|
+
* The single glob implementation: used both for guardrail file allowlists and
|
|
5
|
+
* for selecting outputs by id on the command line.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Simple glob pattern matching with negation support
|
|
9
|
+
* Patterns are evaluated top-to-bottom; last match wins.
|
|
10
|
+
* - "!pattern" → if matched, result becomes false (exclude)
|
|
11
|
+
* - "pattern" → if matched, result becomes true (include)
|
|
12
|
+
*/
|
|
13
|
+
export declare function matchWithNegation(patterns: string[] | undefined, file: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Simple glob pattern matching
|
|
16
|
+
* Supports:
|
|
17
|
+
* - * matches any characters except /
|
|
18
|
+
* - ** matches any characters including / (zero or more path segments)
|
|
19
|
+
* - ? matches single character
|
|
20
|
+
*/
|
|
21
|
+
export declare function matchGlob(file: string, pattern: string): boolean;
|
|
22
|
+
//# sourceMappingURL=glob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAgBvF;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAMhE"}
|