@skmtc/core 0.57.0 → 0.58.1
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 +59 -37
- package/esm/context/GenerateContext.d.ts +0 -2
- package/esm/context/GenerateContext.js +0 -1
- package/esm/dsl/model/ModelDriver.d.ts +0 -2
- package/esm/dsl/model/ModelDriver.js +1 -9
- package/esm/dsl/model/types.d.ts +1 -2
- package/esm/types/TypeSystem.d.ts +0 -3
- package/package.json +1 -1
- package/script/context/GenerateContext.d.ts +0 -2
- package/script/context/GenerateContext.js +0 -1
- package/script/dsl/model/ModelDriver.d.ts +0 -2
- package/script/dsl/model/ModelDriver.js +1 -9
- package/script/dsl/model/types.d.ts +1 -2
- package/script/types/TypeSystem.d.ts +0 -3
package/README.md
CHANGED
|
@@ -42,60 +42,82 @@ skmtc generate petstore https://petstore3.swagger.io/api/v3/openapi.json
|
|
|
42
42
|
|
|
43
43
|
### Example generator code
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
A whole generator, in one file. It writes one `fetch` function for each
|
|
46
|
+
operation of the document. It is short on purpose: the function sends the
|
|
47
|
+
path as the document writes it, with no path parameters and no body.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
46
50
|
import {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
decapitalize,
|
|
52
|
+
type EmptyEnrichments,
|
|
53
|
+
emptyEnrichmentSchema,
|
|
54
|
+
type OasOperationProjectionConstructorArgs,
|
|
55
|
+
toEndpointName,
|
|
56
|
+
toOasOperationEntry
|
|
50
57
|
} from '@skmtc/core'
|
|
51
|
-
import {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
import { toStringLiteral, toTsOasOperationProjectionBase } from '@skmtc/lang-typescript'
|
|
59
|
+
|
|
60
|
+
const ID = '@acme/gen-fetch'
|
|
61
|
+
|
|
62
|
+
// This generator takes no settings from its consumer.
|
|
63
|
+
const toEnrichmentSchema = () => emptyEnrichmentSchema
|
|
64
|
+
|
|
65
|
+
// The name and the export path of each definition are decided here, once.
|
|
66
|
+
const FetchBase = toTsOasOperationProjectionBase<EmptyEnrichments>({
|
|
67
|
+
id: ID,
|
|
68
|
+
|
|
69
|
+
// Method and path, never operationId: `POST /search` is `createApiSearch`.
|
|
70
|
+
toIdentifierName: ({ operation }) => decapitalize(toEndpointName(operation)),
|
|
71
|
+
|
|
72
|
+
toIdentifierType: () => ({ type: 'variable' }),
|
|
73
|
+
|
|
74
|
+
toExportPath({ operation, enrichments, variant }) {
|
|
75
|
+
return `@/api/${this.toIdentifierName({ operation, enrichments, variant })}.generated.ts`
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
toEnrichmentSchema
|
|
61
79
|
})
|
|
62
80
|
|
|
63
|
-
|
|
64
|
-
|
|
81
|
+
// A producer: the constructor stores the parts, and toString() arranges them.
|
|
82
|
+
class FetchEndpoint extends FetchBase {
|
|
83
|
+
method: string
|
|
84
|
+
path: string
|
|
65
85
|
|
|
66
|
-
constructor(args:
|
|
86
|
+
constructor(args: OasOperationProjectionConstructorArgs<EmptyEnrichments>) {
|
|
67
87
|
super(args)
|
|
68
88
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const zodResponse = this.insertNormalizedModel(ZodProjection, {
|
|
72
|
-
schema: response,
|
|
73
|
-
fallbackName: `${this.operation.operationId}Response`
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
// Grab the Zod identifier so toString() can reference it.
|
|
77
|
-
this.zodName = zodResponse.identifier.name
|
|
89
|
+
this.method = toStringLiteral(this.operation.method.toUpperCase())
|
|
90
|
+
this.path = toStringLiteral(this.operation.path)
|
|
78
91
|
}
|
|
79
92
|
|
|
80
93
|
override toString(): string {
|
|
81
|
-
return `
|
|
82
|
-
const res = await fetch('${this.operation.path}')
|
|
83
|
-
const data = await res.json()
|
|
84
|
-
return ${this.zodName}.parse(data)
|
|
85
|
-
}`
|
|
94
|
+
return `() => fetch(${this.path}, { method: ${this.method} })`
|
|
86
95
|
}
|
|
87
96
|
}
|
|
88
97
|
|
|
89
|
-
//
|
|
90
|
-
export
|
|
91
|
-
id:
|
|
92
|
-
|
|
93
|
-
transform
|
|
94
|
-
context.insertOperation(
|
|
98
|
+
// The engine runs the entry once for each operation of the document.
|
|
99
|
+
export default toOasOperationEntry<EmptyEnrichments>({
|
|
100
|
+
id: ID,
|
|
101
|
+
toEnrichmentSchema,
|
|
102
|
+
transform({ context, operation, variant }) {
|
|
103
|
+
context.insertOperation({ projection: FetchEndpoint, operation, variant })
|
|
95
104
|
}
|
|
96
105
|
})
|
|
97
106
|
```
|
|
98
107
|
|
|
108
|
+
For a document with `GET /pets` and `POST /search`, it writes two files:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
// api/getApiPets.generated.ts
|
|
112
|
+
export const getApiPets = () => fetch('/pets', { method: 'GET' });
|
|
113
|
+
|
|
114
|
+
// api/createApiSearch.generated.ts
|
|
115
|
+
export const createApiSearch = () => fetch('/search', { method: 'POST' });
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`deno task verify-docs` type-checks this example against the packages in
|
|
119
|
+
this repository, so it compiles with the version you read it beside.
|
|
120
|
+
|
|
99
121
|
## 📦 Available Generators
|
|
100
122
|
|
|
101
123
|
Stock generators on JSR (under `@skmtc/`):
|
|
@@ -98,8 +98,6 @@ export type CreateAndRegisterDefinition<Schema extends SchemaType> = {
|
|
|
98
98
|
destinationPath: string;
|
|
99
99
|
/** Function to transform the schema into a generated value */
|
|
100
100
|
schemaToValueFn: SchemaToValueFn;
|
|
101
|
-
/** The ref of the model whose value tree holds the schema */
|
|
102
|
-
rootRef?: RefParts;
|
|
103
101
|
/** Whether to exclude this definition from exports */
|
|
104
102
|
noExport?: boolean;
|
|
105
103
|
};
|
|
@@ -15,7 +15,6 @@ type CreateModelArgs<V extends GeneratedValue, EnrichmentType, ProjectionOptions
|
|
|
15
15
|
projection: ModelProjection<V, EnrichmentType, ProjectionOptions>;
|
|
16
16
|
/** The model's ref; an `OasRef` fits it. */
|
|
17
17
|
ref: RefParts;
|
|
18
|
-
rootRef?: RefParts;
|
|
19
18
|
} & InsertModelOptions<ProjectionOptions>;
|
|
20
19
|
/**
|
|
21
20
|
* Driver for the model insertion lifecycle.
|
|
@@ -33,7 +32,6 @@ export declare class ModelDriver<V extends GeneratedValue, EnrichmentType, Proje
|
|
|
33
32
|
settings: ContentSettings<EnrichmentType>;
|
|
34
33
|
destinationPath?: string;
|
|
35
34
|
definition: GeneratedDefinition<V>;
|
|
36
|
-
rootRef?: RefParts;
|
|
37
35
|
noExport: boolean;
|
|
38
36
|
variant: string;
|
|
39
37
|
/** The caller's options, as passed to `insertModel`. */
|
|
@@ -57,12 +57,6 @@ export class ModelDriver {
|
|
|
57
57
|
writable: true,
|
|
58
58
|
value: void 0
|
|
59
59
|
});
|
|
60
|
-
Object.defineProperty(this, "rootRef", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
configurable: true,
|
|
63
|
-
writable: true,
|
|
64
|
-
value: void 0
|
|
65
|
-
});
|
|
66
60
|
Object.defineProperty(this, "noExport", {
|
|
67
61
|
enumerable: true,
|
|
68
62
|
configurable: true,
|
|
@@ -82,12 +76,11 @@ export class ModelDriver {
|
|
|
82
76
|
writable: true,
|
|
83
77
|
value: void 0
|
|
84
78
|
});
|
|
85
|
-
const { context, projection, ref, destinationPath,
|
|
79
|
+
const { context, projection, ref, destinationPath, noExport = false, variant = DEFAULT_VARIANT } = args;
|
|
86
80
|
this.context = context;
|
|
87
81
|
this.projection = projection;
|
|
88
82
|
this.ref = ref;
|
|
89
83
|
this.destinationPath = destinationPath;
|
|
90
|
-
this.rootRef = rootRef;
|
|
91
84
|
this.noExport = noExport;
|
|
92
85
|
this.variant = variant;
|
|
93
86
|
this.options = readProjectionOptions(args);
|
|
@@ -158,7 +151,6 @@ export class ModelDriver {
|
|
|
158
151
|
context: this.context,
|
|
159
152
|
settings: this.settings,
|
|
160
153
|
destinationPath: this.settings.exportPath,
|
|
161
|
-
rootRef: this.rootRef,
|
|
162
154
|
options: this.options
|
|
163
155
|
}));
|
|
164
156
|
const definition = this.projection.lang.toDefinition({
|
package/esm/dsl/model/types.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ export type ModelProjectionConstructorArgs<EnrichmentType = undefined, Projectio
|
|
|
20
20
|
ref: RefParts;
|
|
21
21
|
settings: ContentSettings<EnrichmentType>;
|
|
22
22
|
destinationPath: string;
|
|
23
|
-
rootRef?: RefParts;
|
|
24
23
|
} & ProjectionOptionsArg<ProjectionOptions>;
|
|
25
24
|
export type WithTransformModel = {
|
|
26
25
|
transformModel: (ref: RefParts) => void;
|
|
@@ -104,7 +103,7 @@ export type ToModelExportPathArgs<EnrichmentType = undefined, ProjectionOptions
|
|
|
104
103
|
export type ModelProjection<V extends GeneratedValue, EnrichmentType = undefined, ProjectionOptions = undefined> = {
|
|
105
104
|
prototype: V;
|
|
106
105
|
} & {
|
|
107
|
-
new ({ context, ref, settings, destinationPath,
|
|
106
|
+
new ({ context, ref, settings, destinationPath, options }: ModelProjectionConstructorArgs<EnrichmentType, ProjectionOptions>): V;
|
|
108
107
|
id: string;
|
|
109
108
|
type: 'model';
|
|
110
109
|
/**
|
|
@@ -7,7 +7,6 @@ import type { GenerateContextType } from '../context/generateTypes.js';
|
|
|
7
7
|
import type { CustomValue } from '../dsl/CustomValue.js';
|
|
8
8
|
import type { OasVoid } from '../oas/void/Void.js';
|
|
9
9
|
import type { GeneratorKey } from '../dsl/GeneratorKeys.js';
|
|
10
|
-
import type { RefParts } from '../helpers/refFns.js';
|
|
11
10
|
/**
|
|
12
11
|
* Union type representing all possible type system values in the SKMTC code generation system.
|
|
13
12
|
*
|
|
@@ -554,8 +553,6 @@ export type TypeSystemArgs<Schema extends SchemaType> = {
|
|
|
554
553
|
destinationPath: string;
|
|
555
554
|
/** The schema to transform */
|
|
556
555
|
schema: Schema;
|
|
557
|
-
/** The ref of the model whose value tree holds the schema */
|
|
558
|
-
rootRef?: RefParts;
|
|
559
556
|
/** Whether the schema field is required */
|
|
560
557
|
required: boolean | undefined;
|
|
561
558
|
};
|
package/package.json
CHANGED
|
@@ -98,8 +98,6 @@ export type CreateAndRegisterDefinition<Schema extends SchemaType> = {
|
|
|
98
98
|
destinationPath: string;
|
|
99
99
|
/** Function to transform the schema into a generated value */
|
|
100
100
|
schemaToValueFn: SchemaToValueFn;
|
|
101
|
-
/** The ref of the model whose value tree holds the schema */
|
|
102
|
-
rootRef?: RefParts;
|
|
103
101
|
/** Whether to exclude this definition from exports */
|
|
104
102
|
noExport?: boolean;
|
|
105
103
|
};
|
|
@@ -15,7 +15,6 @@ type CreateModelArgs<V extends GeneratedValue, EnrichmentType, ProjectionOptions
|
|
|
15
15
|
projection: ModelProjection<V, EnrichmentType, ProjectionOptions>;
|
|
16
16
|
/** The model's ref; an `OasRef` fits it. */
|
|
17
17
|
ref: RefParts;
|
|
18
|
-
rootRef?: RefParts;
|
|
19
18
|
} & InsertModelOptions<ProjectionOptions>;
|
|
20
19
|
/**
|
|
21
20
|
* Driver for the model insertion lifecycle.
|
|
@@ -33,7 +32,6 @@ export declare class ModelDriver<V extends GeneratedValue, EnrichmentType, Proje
|
|
|
33
32
|
settings: ContentSettings<EnrichmentType>;
|
|
34
33
|
destinationPath?: string;
|
|
35
34
|
definition: GeneratedDefinition<V>;
|
|
36
|
-
rootRef?: RefParts;
|
|
37
35
|
noExport: boolean;
|
|
38
36
|
variant: string;
|
|
39
37
|
/** The caller's options, as passed to `insertModel`. */
|
|
@@ -63,12 +63,6 @@ class ModelDriver {
|
|
|
63
63
|
writable: true,
|
|
64
64
|
value: void 0
|
|
65
65
|
});
|
|
66
|
-
Object.defineProperty(this, "rootRef", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
configurable: true,
|
|
69
|
-
writable: true,
|
|
70
|
-
value: void 0
|
|
71
|
-
});
|
|
72
66
|
Object.defineProperty(this, "noExport", {
|
|
73
67
|
enumerable: true,
|
|
74
68
|
configurable: true,
|
|
@@ -88,12 +82,11 @@ class ModelDriver {
|
|
|
88
82
|
writable: true,
|
|
89
83
|
value: void 0
|
|
90
84
|
});
|
|
91
|
-
const { context, projection, ref, destinationPath,
|
|
85
|
+
const { context, projection, ref, destinationPath, noExport = false, variant = Variant_js_1.DEFAULT_VARIANT } = args;
|
|
92
86
|
this.context = context;
|
|
93
87
|
this.projection = projection;
|
|
94
88
|
this.ref = ref;
|
|
95
89
|
this.destinationPath = destinationPath;
|
|
96
|
-
this.rootRef = rootRef;
|
|
97
90
|
this.noExport = noExport;
|
|
98
91
|
this.variant = variant;
|
|
99
92
|
this.options = (0, ProjectionOptions_js_1.readProjectionOptions)(args);
|
|
@@ -164,7 +157,6 @@ class ModelDriver {
|
|
|
164
157
|
context: this.context,
|
|
165
158
|
settings: this.settings,
|
|
166
159
|
destinationPath: this.settings.exportPath,
|
|
167
|
-
rootRef: this.rootRef,
|
|
168
160
|
options: this.options
|
|
169
161
|
}));
|
|
170
162
|
const definition = this.projection.lang.toDefinition({
|
|
@@ -20,7 +20,6 @@ export type ModelProjectionConstructorArgs<EnrichmentType = undefined, Projectio
|
|
|
20
20
|
ref: RefParts;
|
|
21
21
|
settings: ContentSettings<EnrichmentType>;
|
|
22
22
|
destinationPath: string;
|
|
23
|
-
rootRef?: RefParts;
|
|
24
23
|
} & ProjectionOptionsArg<ProjectionOptions>;
|
|
25
24
|
export type WithTransformModel = {
|
|
26
25
|
transformModel: (ref: RefParts) => void;
|
|
@@ -104,7 +103,7 @@ export type ToModelExportPathArgs<EnrichmentType = undefined, ProjectionOptions
|
|
|
104
103
|
export type ModelProjection<V extends GeneratedValue, EnrichmentType = undefined, ProjectionOptions = undefined> = {
|
|
105
104
|
prototype: V;
|
|
106
105
|
} & {
|
|
107
|
-
new ({ context, ref, settings, destinationPath,
|
|
106
|
+
new ({ context, ref, settings, destinationPath, options }: ModelProjectionConstructorArgs<EnrichmentType, ProjectionOptions>): V;
|
|
108
107
|
id: string;
|
|
109
108
|
type: 'model';
|
|
110
109
|
/**
|
|
@@ -7,7 +7,6 @@ import type { GenerateContextType } from '../context/generateTypes.js';
|
|
|
7
7
|
import type { CustomValue } from '../dsl/CustomValue.js';
|
|
8
8
|
import type { OasVoid } from '../oas/void/Void.js';
|
|
9
9
|
import type { GeneratorKey } from '../dsl/GeneratorKeys.js';
|
|
10
|
-
import type { RefParts } from '../helpers/refFns.js';
|
|
11
10
|
/**
|
|
12
11
|
* Union type representing all possible type system values in the SKMTC code generation system.
|
|
13
12
|
*
|
|
@@ -554,8 +553,6 @@ export type TypeSystemArgs<Schema extends SchemaType> = {
|
|
|
554
553
|
destinationPath: string;
|
|
555
554
|
/** The schema to transform */
|
|
556
555
|
schema: Schema;
|
|
557
|
-
/** The ref of the model whose value tree holds the schema */
|
|
558
|
-
rootRef?: RefParts;
|
|
559
556
|
/** Whether the schema field is required */
|
|
560
557
|
required: boolean | undefined;
|
|
561
558
|
};
|