@extk/expressive 0.2.1 → 0.3.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.
- package/dist/index.d.mts +69 -13
- package/dist/index.d.ts +69 -13
- package/dist/index.js +39 -18
- package/dist/index.mjs +39 -18
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -34,9 +34,61 @@ type Container = {
|
|
|
34
34
|
alertHandler?: AlertHandler;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
type
|
|
37
|
+
type NumericConfigs = {
|
|
38
|
+
minimum?: number;
|
|
39
|
+
maximum?: number;
|
|
40
|
+
exclusiveMinimum?: boolean;
|
|
41
|
+
exclusiveMaximum?: boolean;
|
|
42
|
+
multipleOf?: number;
|
|
43
|
+
};
|
|
44
|
+
type NumberType = {
|
|
45
|
+
type: 'number';
|
|
46
|
+
format?: 'float' | 'double';
|
|
47
|
+
} & NumericConfigs;
|
|
48
|
+
type IntegerType = {
|
|
49
|
+
type: 'integer';
|
|
50
|
+
format?: 'int32' | 'int64';
|
|
51
|
+
} & NumericConfigs;
|
|
52
|
+
type StringType = {
|
|
53
|
+
type: 'string';
|
|
54
|
+
minLength?: number;
|
|
55
|
+
maxLength?: number;
|
|
56
|
+
format?: 'date' | 'date-time' | 'password' | 'byte' | 'binary' | 'email' | 'uuid' | 'uri' | 'hostname' | 'ipv4' | 'ipv6';
|
|
57
|
+
pattern?: string;
|
|
58
|
+
};
|
|
59
|
+
type BooleanType = {
|
|
60
|
+
type: 'boolean';
|
|
61
|
+
};
|
|
62
|
+
type ArrayType = {
|
|
63
|
+
type: 'array';
|
|
64
|
+
items: Partial<Schema>;
|
|
65
|
+
minItems?: number;
|
|
66
|
+
maxItems?: number;
|
|
67
|
+
uniqueItems?: boolean;
|
|
68
|
+
};
|
|
69
|
+
type ObjectType = {
|
|
70
|
+
type: 'object';
|
|
71
|
+
properties?: Record<string, Schema>;
|
|
72
|
+
required?: string[];
|
|
73
|
+
additionalProperties?: boolean | Schema;
|
|
74
|
+
minProperties?: number;
|
|
75
|
+
maxProperties?: number;
|
|
76
|
+
};
|
|
77
|
+
type BaseSchema = ({
|
|
78
|
+
nullable?: boolean;
|
|
79
|
+
enum?: unknown[];
|
|
80
|
+
description?: string;
|
|
81
|
+
default?: unknown;
|
|
82
|
+
} & (StringType | NumberType | IntegerType | BooleanType | ArrayType | ObjectType)) | {
|
|
38
83
|
$ref: string;
|
|
39
84
|
};
|
|
85
|
+
type Schema = BaseSchema | {
|
|
86
|
+
allOf: BaseSchema[];
|
|
87
|
+
} | {
|
|
88
|
+
anyOf: BaseSchema[];
|
|
89
|
+
} | {
|
|
90
|
+
oneOf: BaseSchema[];
|
|
91
|
+
};
|
|
40
92
|
type Content = {
|
|
41
93
|
description?: string;
|
|
42
94
|
content?: Partial<Record<ContentType, {
|
|
@@ -46,7 +98,7 @@ type Content = {
|
|
|
46
98
|
type Param = {
|
|
47
99
|
in: 'path' | 'query' | 'headers';
|
|
48
100
|
name: string;
|
|
49
|
-
|
|
101
|
+
description: string;
|
|
50
102
|
required: boolean;
|
|
51
103
|
schema: Schema;
|
|
52
104
|
};
|
|
@@ -225,19 +277,23 @@ declare function bootstrap(container: Container): {
|
|
|
225
277
|
get(): SwaggerConfig;
|
|
226
278
|
};
|
|
227
279
|
expressiveServer(configs: {
|
|
228
|
-
|
|
229
|
-
|
|
280
|
+
app?: express.Express;
|
|
281
|
+
}): {
|
|
282
|
+
get(): express.Express;
|
|
283
|
+
withHelmet(options?: Readonly<helmet.HelmetOptions>): /*elided*/ any;
|
|
284
|
+
withQs(): /*elided*/ any;
|
|
285
|
+
withMorgan(format?: string, options?: Parameters<typeof morgan>[1]): /*elided*/ any;
|
|
286
|
+
withSwagger(swagger: {
|
|
287
|
+
path?: ExpressRoute;
|
|
230
288
|
doc: SwaggerConfig;
|
|
289
|
+
}, ...handlers: ExpressHandler[]): /*elided*/ any;
|
|
290
|
+
defaults: {
|
|
291
|
+
get(swagger: {
|
|
292
|
+
path?: ExpressRoute;
|
|
293
|
+
doc: SwaggerConfig;
|
|
294
|
+
}): express.Express;
|
|
231
295
|
};
|
|
232
|
-
|
|
233
|
-
helmet?: Readonly<helmet.HelmetOptions>;
|
|
234
|
-
morgan?: Readonly<{
|
|
235
|
-
format: string;
|
|
236
|
-
options?: Parameters<typeof morgan>[1];
|
|
237
|
-
}>;
|
|
238
|
-
};
|
|
239
|
-
app?: express.Express;
|
|
240
|
-
}): express.Express;
|
|
296
|
+
};
|
|
241
297
|
expressiveRouter(configs: {
|
|
242
298
|
oapi?: {
|
|
243
299
|
tags?: string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -34,9 +34,61 @@ type Container = {
|
|
|
34
34
|
alertHandler?: AlertHandler;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
type
|
|
37
|
+
type NumericConfigs = {
|
|
38
|
+
minimum?: number;
|
|
39
|
+
maximum?: number;
|
|
40
|
+
exclusiveMinimum?: boolean;
|
|
41
|
+
exclusiveMaximum?: boolean;
|
|
42
|
+
multipleOf?: number;
|
|
43
|
+
};
|
|
44
|
+
type NumberType = {
|
|
45
|
+
type: 'number';
|
|
46
|
+
format?: 'float' | 'double';
|
|
47
|
+
} & NumericConfigs;
|
|
48
|
+
type IntegerType = {
|
|
49
|
+
type: 'integer';
|
|
50
|
+
format?: 'int32' | 'int64';
|
|
51
|
+
} & NumericConfigs;
|
|
52
|
+
type StringType = {
|
|
53
|
+
type: 'string';
|
|
54
|
+
minLength?: number;
|
|
55
|
+
maxLength?: number;
|
|
56
|
+
format?: 'date' | 'date-time' | 'password' | 'byte' | 'binary' | 'email' | 'uuid' | 'uri' | 'hostname' | 'ipv4' | 'ipv6';
|
|
57
|
+
pattern?: string;
|
|
58
|
+
};
|
|
59
|
+
type BooleanType = {
|
|
60
|
+
type: 'boolean';
|
|
61
|
+
};
|
|
62
|
+
type ArrayType = {
|
|
63
|
+
type: 'array';
|
|
64
|
+
items: Partial<Schema>;
|
|
65
|
+
minItems?: number;
|
|
66
|
+
maxItems?: number;
|
|
67
|
+
uniqueItems?: boolean;
|
|
68
|
+
};
|
|
69
|
+
type ObjectType = {
|
|
70
|
+
type: 'object';
|
|
71
|
+
properties?: Record<string, Schema>;
|
|
72
|
+
required?: string[];
|
|
73
|
+
additionalProperties?: boolean | Schema;
|
|
74
|
+
minProperties?: number;
|
|
75
|
+
maxProperties?: number;
|
|
76
|
+
};
|
|
77
|
+
type BaseSchema = ({
|
|
78
|
+
nullable?: boolean;
|
|
79
|
+
enum?: unknown[];
|
|
80
|
+
description?: string;
|
|
81
|
+
default?: unknown;
|
|
82
|
+
} & (StringType | NumberType | IntegerType | BooleanType | ArrayType | ObjectType)) | {
|
|
38
83
|
$ref: string;
|
|
39
84
|
};
|
|
85
|
+
type Schema = BaseSchema | {
|
|
86
|
+
allOf: BaseSchema[];
|
|
87
|
+
} | {
|
|
88
|
+
anyOf: BaseSchema[];
|
|
89
|
+
} | {
|
|
90
|
+
oneOf: BaseSchema[];
|
|
91
|
+
};
|
|
40
92
|
type Content = {
|
|
41
93
|
description?: string;
|
|
42
94
|
content?: Partial<Record<ContentType, {
|
|
@@ -46,7 +98,7 @@ type Content = {
|
|
|
46
98
|
type Param = {
|
|
47
99
|
in: 'path' | 'query' | 'headers';
|
|
48
100
|
name: string;
|
|
49
|
-
|
|
101
|
+
description: string;
|
|
50
102
|
required: boolean;
|
|
51
103
|
schema: Schema;
|
|
52
104
|
};
|
|
@@ -225,19 +277,23 @@ declare function bootstrap(container: Container): {
|
|
|
225
277
|
get(): SwaggerConfig;
|
|
226
278
|
};
|
|
227
279
|
expressiveServer(configs: {
|
|
228
|
-
|
|
229
|
-
|
|
280
|
+
app?: express.Express;
|
|
281
|
+
}): {
|
|
282
|
+
get(): express.Express;
|
|
283
|
+
withHelmet(options?: Readonly<helmet.HelmetOptions>): /*elided*/ any;
|
|
284
|
+
withQs(): /*elided*/ any;
|
|
285
|
+
withMorgan(format?: string, options?: Parameters<typeof morgan>[1]): /*elided*/ any;
|
|
286
|
+
withSwagger(swagger: {
|
|
287
|
+
path?: ExpressRoute;
|
|
230
288
|
doc: SwaggerConfig;
|
|
289
|
+
}, ...handlers: ExpressHandler[]): /*elided*/ any;
|
|
290
|
+
defaults: {
|
|
291
|
+
get(swagger: {
|
|
292
|
+
path?: ExpressRoute;
|
|
293
|
+
doc: SwaggerConfig;
|
|
294
|
+
}): express.Express;
|
|
231
295
|
};
|
|
232
|
-
|
|
233
|
-
helmet?: Readonly<helmet.HelmetOptions>;
|
|
234
|
-
morgan?: Readonly<{
|
|
235
|
-
format: string;
|
|
236
|
-
options?: Parameters<typeof morgan>[1];
|
|
237
|
-
}>;
|
|
238
|
-
};
|
|
239
|
-
app?: express.Express;
|
|
240
|
-
}): express.Express;
|
|
296
|
+
};
|
|
241
297
|
expressiveRouter(configs: {
|
|
242
298
|
oapi?: {
|
|
243
299
|
tags?: string[];
|
package/dist/index.js
CHANGED
|
@@ -154,7 +154,7 @@ function param(inP, id, schema, required = true, description = "", name) {
|
|
|
154
154
|
return {
|
|
155
155
|
in: inP,
|
|
156
156
|
name: name ?? id,
|
|
157
|
-
|
|
157
|
+
description,
|
|
158
158
|
required,
|
|
159
159
|
schema
|
|
160
160
|
};
|
|
@@ -193,24 +193,45 @@ var SWG = {
|
|
|
193
193
|
function buildExpressive(container, swaggerDoc) {
|
|
194
194
|
return {
|
|
195
195
|
expressiveServer(configs) {
|
|
196
|
-
const { options } = configs;
|
|
197
196
|
const app = configs.app ?? (0, import_express.default)();
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
197
|
+
const result = {
|
|
198
|
+
get() {
|
|
199
|
+
return app;
|
|
200
|
+
},
|
|
201
|
+
withHelmet(options) {
|
|
202
|
+
app.use((0, import_helmet.default)(options ?? {}));
|
|
203
|
+
return this;
|
|
204
|
+
},
|
|
205
|
+
withQs() {
|
|
206
|
+
app.set("query parser", function(str) {
|
|
207
|
+
return import_qs.default.parse(str, { decoder(s) {
|
|
208
|
+
return decodeURIComponent(s);
|
|
209
|
+
} });
|
|
210
|
+
});
|
|
211
|
+
return this;
|
|
212
|
+
},
|
|
213
|
+
withMorgan(format, options) {
|
|
214
|
+
app.use((0, import_morgan.default)(
|
|
215
|
+
format ?? ":req[x-real-ip] :method :url :status :res[content-length] - :response-time ms",
|
|
216
|
+
options ?? { stream: { write(message) {
|
|
217
|
+
container.logger.info(message.trim());
|
|
218
|
+
} } }
|
|
219
|
+
));
|
|
220
|
+
return this;
|
|
221
|
+
},
|
|
222
|
+
withSwagger(swagger, ...handlers) {
|
|
223
|
+
app.use(swagger.path ?? "/api-docs", ...handlers, import_swagger_ui_express.default.serve, import_swagger_ui_express.default.setup(swagger.doc, {
|
|
224
|
+
customSiteTitle: swagger.doc.info?.title
|
|
225
|
+
}));
|
|
226
|
+
return this;
|
|
227
|
+
},
|
|
228
|
+
defaults: {
|
|
229
|
+
get(swagger) {
|
|
230
|
+
return result.withHelmet().withQs().withMorgan().withSwagger(swagger).get();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
return result;
|
|
214
235
|
},
|
|
215
236
|
expressiveRouter(configs) {
|
|
216
237
|
const router = import_express.default.Router();
|
package/dist/index.mjs
CHANGED
|
@@ -89,7 +89,7 @@ function param(inP, id, schema, required = true, description = "", name) {
|
|
|
89
89
|
return {
|
|
90
90
|
in: inP,
|
|
91
91
|
name: name ?? id,
|
|
92
|
-
|
|
92
|
+
description,
|
|
93
93
|
required,
|
|
94
94
|
schema
|
|
95
95
|
};
|
|
@@ -128,24 +128,45 @@ var SWG = {
|
|
|
128
128
|
function buildExpressive(container, swaggerDoc) {
|
|
129
129
|
return {
|
|
130
130
|
expressiveServer(configs) {
|
|
131
|
-
const { options } = configs;
|
|
132
131
|
const app = configs.app ?? express();
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
132
|
+
const result = {
|
|
133
|
+
get() {
|
|
134
|
+
return app;
|
|
135
|
+
},
|
|
136
|
+
withHelmet(options) {
|
|
137
|
+
app.use(helmet(options ?? {}));
|
|
138
|
+
return this;
|
|
139
|
+
},
|
|
140
|
+
withQs() {
|
|
141
|
+
app.set("query parser", function(str) {
|
|
142
|
+
return qs.parse(str, { decoder(s) {
|
|
143
|
+
return decodeURIComponent(s);
|
|
144
|
+
} });
|
|
145
|
+
});
|
|
146
|
+
return this;
|
|
147
|
+
},
|
|
148
|
+
withMorgan(format, options) {
|
|
149
|
+
app.use(morgan(
|
|
150
|
+
format ?? ":req[x-real-ip] :method :url :status :res[content-length] - :response-time ms",
|
|
151
|
+
options ?? { stream: { write(message) {
|
|
152
|
+
container.logger.info(message.trim());
|
|
153
|
+
} } }
|
|
154
|
+
));
|
|
155
|
+
return this;
|
|
156
|
+
},
|
|
157
|
+
withSwagger(swagger, ...handlers) {
|
|
158
|
+
app.use(swagger.path ?? "/api-docs", ...handlers, swaggerUi.serve, swaggerUi.setup(swagger.doc, {
|
|
159
|
+
customSiteTitle: swagger.doc.info?.title
|
|
160
|
+
}));
|
|
161
|
+
return this;
|
|
162
|
+
},
|
|
163
|
+
defaults: {
|
|
164
|
+
get(swagger) {
|
|
165
|
+
return result.withHelmet().withQs().withMorgan().withSwagger(swagger).get();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return result;
|
|
149
170
|
},
|
|
150
171
|
expressiveRouter(configs) {
|
|
151
172
|
const router = express.Router();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@extk/expressive",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"lint": "eslint ./"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@extk/eslint-config": "^0.2.
|
|
28
|
+
"@extk/eslint-config": "^0.2.1",
|
|
29
29
|
"@extk/tsconfig": "0.1.1",
|
|
30
30
|
"@types/chance": "^1.1.7",
|
|
31
31
|
"@types/express": "^5.0.1",
|