@rvoh/psychic 0.37.0-beta.3 → 0.37.0-beta.4
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/cjs/src/bin/index.js +2 -2
- package/dist/cjs/src/controller/helpers/isPaginatedResult.js +5 -2
- package/dist/cjs/src/error/openapi/AttemptedToDeriveDescendentSerializersFromNonSerializer.js +16 -0
- package/dist/cjs/src/error/openapi/ExpectedSerializerForRendersOneOrManyOption.js +36 -0
- package/dist/cjs/src/error/openapi/NoSerializerFoundForRendersOneAndMany.js +16 -0
- package/dist/cjs/src/error/openapi/NonSerializerPassedToSerializerOpenapiRenderer.js +16 -0
- package/dist/cjs/src/error/openapi/NonSerializerSerializerOverrideProvided.js +23 -0
- package/dist/cjs/src/error/openapi/ObjectSerializerRendersOneAndManyRequireClassType.js +19 -0
- package/dist/cjs/src/helpers/isObject.js +12 -0
- package/dist/cjs/src/helpers/pathifyNestedObject.js +5 -2
- package/dist/cjs/src/openapi-renderer/SerializerOpenapiRenderer.js +362 -0
- package/dist/cjs/src/openapi-renderer/body-segment.js +5 -3
- package/dist/cjs/src/openapi-renderer/endpoint.js +6 -5
- package/dist/cjs/src/openapi-renderer/helpers/allSerializersFromHandWrittenOpenapi.js +34 -0
- package/dist/cjs/src/openapi-renderer/helpers/allSerializersToRefsInOpenapi.js +52 -0
- package/dist/cjs/src/openapi-renderer/helpers/dreamAttributeOpenapiShape.js +145 -0
- package/dist/cjs/src/openapi-renderer/helpers/isOpenapiShorthand.js +16 -0
- package/dist/cjs/src/openapi-renderer/helpers/maybeNullOpenapiShorthandToOpenapiShorthand.js +17 -0
- package/dist/cjs/src/openapi-renderer/helpers/openapiShorthandToOpenapi.js +111 -0
- package/dist/cjs/src/openapi-renderer/helpers/primitiveOpenapiStatementToOpenapi.js +5 -2
- package/dist/cjs/src/server/params.js +4 -4
- package/dist/esm/src/bin/index.js +1 -1
- package/dist/esm/src/controller/helpers/isPaginatedResult.js +1 -1
- package/dist/esm/src/error/openapi/AttemptedToDeriveDescendentSerializersFromNonSerializer.js +13 -0
- package/dist/esm/src/error/openapi/ExpectedSerializerForRendersOneOrManyOption.js +33 -0
- package/dist/esm/src/error/openapi/NoSerializerFoundForRendersOneAndMany.js +13 -0
- package/dist/esm/src/error/openapi/NonSerializerPassedToSerializerOpenapiRenderer.js +13 -0
- package/dist/esm/src/error/openapi/NonSerializerSerializerOverrideProvided.js +20 -0
- package/dist/esm/src/error/openapi/ObjectSerializerRendersOneAndManyRequireClassType.js +16 -0
- package/dist/esm/src/helpers/isObject.js +9 -0
- package/dist/esm/src/helpers/pathifyNestedObject.js +1 -1
- package/dist/esm/src/openapi-renderer/SerializerOpenapiRenderer.js +356 -0
- package/dist/esm/src/openapi-renderer/body-segment.js +3 -1
- package/dist/esm/src/openapi-renderer/endpoint.js +2 -1
- package/dist/esm/src/openapi-renderer/helpers/allSerializersFromHandWrittenOpenapi.js +28 -0
- package/dist/esm/src/openapi-renderer/helpers/allSerializersToRefsInOpenapi.js +46 -0
- package/dist/esm/src/openapi-renderer/helpers/dreamAttributeOpenapiShape.js +136 -0
- package/dist/esm/src/openapi-renderer/helpers/isOpenapiShorthand.js +10 -0
- package/dist/esm/src/openapi-renderer/helpers/maybeNullOpenapiShorthandToOpenapiShorthand.js +14 -0
- package/dist/esm/src/openapi-renderer/helpers/openapiShorthandToOpenapi.js +102 -0
- package/dist/esm/src/openapi-renderer/helpers/primitiveOpenapiStatementToOpenapi.js +1 -1
- package/dist/esm/src/server/params.js +3 -3
- package/dist/types/src/error/openapi/AttemptedToDeriveDescendentSerializersFromNonSerializer.d.ts +5 -0
- package/dist/types/src/error/openapi/ExpectedSerializerForRendersOneOrManyOption.d.ts +8 -0
- package/dist/types/src/error/openapi/NoSerializerFoundForRendersOneAndMany.d.ts +5 -0
- package/dist/types/src/error/openapi/NonSerializerPassedToSerializerOpenapiRenderer.d.ts +5 -0
- package/dist/types/src/error/openapi/NonSerializerSerializerOverrideProvided.d.ts +6 -0
- package/dist/types/src/error/openapi/ObjectSerializerRendersOneAndManyRequireClassType.d.ts +5 -0
- package/dist/types/src/helpers/isObject.d.ts +1 -0
- package/dist/types/src/openapi-renderer/SerializerOpenapiRenderer.d.ts +25 -0
- package/dist/types/src/openapi-renderer/helpers/allSerializersFromHandWrittenOpenapi.d.ts +2 -0
- package/dist/types/src/openapi-renderer/helpers/allSerializersToRefsInOpenapi.d.ts +2 -0
- package/dist/types/src/openapi-renderer/helpers/dreamAttributeOpenapiShape.d.ts +780 -0
- package/dist/types/src/openapi-renderer/helpers/isOpenapiShorthand.d.ts +1 -0
- package/dist/types/src/openapi-renderer/helpers/maybeNullOpenapiShorthandToOpenapiShorthand.d.ts +2 -0
- package/dist/types/src/openapi-renderer/helpers/openapiShorthandToOpenapi.d.ts +16 -0
- package/package.json +2 -2
- package/dist/cjs/src/helpers/typechecks.js +0 -20
- package/dist/esm/src/helpers/typechecks.js +0 -16
- package/dist/types/src/helpers/typechecks.d.ts +0 -2
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = allSerializersFromHandWrittenOpenapi;
|
|
7
|
+
const isObject_js_1 = __importDefault(require("../../helpers/isObject.js"));
|
|
8
|
+
function allSerializersFromHandWrittenOpenapi(openapi) {
|
|
9
|
+
const serializers = new Set();
|
|
10
|
+
extractSerializers(openapi, serializers);
|
|
11
|
+
return [...serializers];
|
|
12
|
+
}
|
|
13
|
+
function extractSerializers(
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
value, serializers) {
|
|
16
|
+
if (!value)
|
|
17
|
+
return;
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
19
|
+
if (value.$serializer) {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
|
|
21
|
+
serializers.add(value.$serializer);
|
|
22
|
+
//
|
|
23
|
+
}
|
|
24
|
+
else if ((0, isObject_js_1.default)(value)) {
|
|
25
|
+
// Recurse into objects
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
27
|
+
Object.values(value).forEach(val => extractSerializers(val, serializers));
|
|
28
|
+
//
|
|
29
|
+
}
|
|
30
|
+
else if (Array.isArray(value)) {
|
|
31
|
+
// Recurse into arrays
|
|
32
|
+
value.forEach(val => extractSerializers(val, serializers));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = allSerializersToRefsInOpenapi;
|
|
7
|
+
const isObject_js_1 = __importDefault(require("../../helpers/isObject.js"));
|
|
8
|
+
const SerializerOpenapiRenderer_js_1 = __importDefault(require("../SerializerOpenapiRenderer.js"));
|
|
9
|
+
function allSerializersToRefsInOpenapi(openapi) {
|
|
10
|
+
if (!openapi)
|
|
11
|
+
return {};
|
|
12
|
+
return transformValue(openapi);
|
|
13
|
+
}
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
function transformValue(value) {
|
|
16
|
+
if (!value)
|
|
17
|
+
return value;
|
|
18
|
+
// If this is an object with a $serializer property, replace it with $ref
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
20
|
+
if (value.$serializer) {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
22
|
+
const { $serializer, ...rest } = value;
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
24
|
+
const openapiRenderer = new SerializerOpenapiRenderer_js_1.default($serializer).serializerRef;
|
|
25
|
+
return {
|
|
26
|
+
...rest,
|
|
27
|
+
...openapiRenderer,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
else if ((0, isObject_js_1.default)(value)) {
|
|
31
|
+
// Recurse into objects
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
const transformed = {};
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
35
|
+
for (const [key, val] of Object.entries(value)) {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
37
|
+
transformed[key] = transformValue(val);
|
|
38
|
+
}
|
|
39
|
+
return transformed;
|
|
40
|
+
//
|
|
41
|
+
}
|
|
42
|
+
else if (Array.isArray(value)) {
|
|
43
|
+
// Recurse into arrays
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
45
|
+
return value.map(val => transformValue(val));
|
|
46
|
+
//
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// Return primitive values as-is
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UseCustomOpenapiForJson = exports.UseCustomOpenapiForVirtualAttributes = void 0;
|
|
7
|
+
exports.dreamColumnOpenapiShape = dreamColumnOpenapiShape;
|
|
8
|
+
const openapiShorthandToOpenapi_js_1 = __importDefault(require("./openapiShorthandToOpenapi.js"));
|
|
9
|
+
function dreamColumnOpenapiShape(dreamClass, column, openapi = undefined, { suppressResponseEnums = false } = {}) {
|
|
10
|
+
const dream = dreamClass.prototype;
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
12
|
+
const dreamColumnInfo = dream.schema[dream.table]?.columns[column];
|
|
13
|
+
if (!dreamColumnInfo) {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
15
|
+
if (openapi)
|
|
16
|
+
return (0, openapiShorthandToOpenapi_js_1.default)(openapi);
|
|
17
|
+
throw new UseCustomOpenapiForVirtualAttributes(dreamClass, column);
|
|
18
|
+
}
|
|
19
|
+
switch (baseDbType(dreamColumnInfo)) {
|
|
20
|
+
case 'json':
|
|
21
|
+
case 'jsonb':
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
23
|
+
if (openapi)
|
|
24
|
+
return (0, openapiShorthandToOpenapi_js_1.default)(openapi);
|
|
25
|
+
throw new UseCustomOpenapiForJson(dreamClass, column);
|
|
26
|
+
}
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
28
|
+
const openapiObject = (0, openapiShorthandToOpenapi_js_1.default)((openapi ?? {}));
|
|
29
|
+
const singleType = singularAttributeOpenapiShape(dreamColumnInfo, suppressResponseEnums);
|
|
30
|
+
if (dreamColumnInfo.isArray) {
|
|
31
|
+
return {
|
|
32
|
+
type: dreamColumnInfo.allowNull ? ['array', 'null'] : 'array',
|
|
33
|
+
items: singleType,
|
|
34
|
+
...openapiObject,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const existingType = singleType.type;
|
|
39
|
+
return {
|
|
40
|
+
...singleType,
|
|
41
|
+
type: dreamColumnInfo.allowNull && !Array.isArray(existingType) ? [existingType, 'null'] : existingType,
|
|
42
|
+
...openapiObject,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function baseDbType(dreamColumnInfo) {
|
|
47
|
+
return dreamColumnInfo.dbType.replace('[]', '');
|
|
48
|
+
}
|
|
49
|
+
function singularAttributeOpenapiShape(dreamColumnInfo, suppressResponseEnums) {
|
|
50
|
+
if (dreamColumnInfo.enumValues) {
|
|
51
|
+
if (suppressResponseEnums) {
|
|
52
|
+
return {
|
|
53
|
+
type: 'string',
|
|
54
|
+
description: `The following values will be allowed:\n ${dreamColumnInfo.enumValues.join(',\n ')}`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return { type: 'string', enum: dreamColumnInfo.enumValues };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
switch (baseDbType(dreamColumnInfo)) {
|
|
62
|
+
case 'boolean':
|
|
63
|
+
return { type: 'boolean' };
|
|
64
|
+
case 'bigint':
|
|
65
|
+
case 'bigserial':
|
|
66
|
+
case 'bytea':
|
|
67
|
+
case 'char':
|
|
68
|
+
case 'character varying':
|
|
69
|
+
case 'character':
|
|
70
|
+
case 'cidr':
|
|
71
|
+
case 'citext':
|
|
72
|
+
case 'inet':
|
|
73
|
+
case 'macaddr':
|
|
74
|
+
case 'money':
|
|
75
|
+
case 'path':
|
|
76
|
+
case 'text':
|
|
77
|
+
case 'uuid':
|
|
78
|
+
case 'varbit':
|
|
79
|
+
case 'varchar':
|
|
80
|
+
case 'xml':
|
|
81
|
+
return { type: 'string' };
|
|
82
|
+
case 'integer':
|
|
83
|
+
case 'serial':
|
|
84
|
+
case 'smallint':
|
|
85
|
+
case 'smallserial':
|
|
86
|
+
return { type: 'integer' };
|
|
87
|
+
case 'numeric':
|
|
88
|
+
case 'decimal':
|
|
89
|
+
return { type: 'number', format: 'decimal' };
|
|
90
|
+
case 'double':
|
|
91
|
+
case 'real':
|
|
92
|
+
return { type: 'number' };
|
|
93
|
+
case 'datetime':
|
|
94
|
+
case 'time':
|
|
95
|
+
case 'time with time zone':
|
|
96
|
+
case 'timestamp':
|
|
97
|
+
case 'timestamp with time zone':
|
|
98
|
+
case 'timestamp without time zone':
|
|
99
|
+
return { type: 'string', format: 'date-time' };
|
|
100
|
+
case 'date':
|
|
101
|
+
return { type: 'string', format: 'date' };
|
|
102
|
+
default:
|
|
103
|
+
throw new Error(`Unrecognized dbType used in serializer OpenAPI type declaration: ${dreamColumnInfo.dbType}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
class UseCustomOpenapiForVirtualAttributes extends Error {
|
|
107
|
+
dreamClass;
|
|
108
|
+
field;
|
|
109
|
+
constructor(dreamClass, field) {
|
|
110
|
+
super();
|
|
111
|
+
this.dreamClass = dreamClass;
|
|
112
|
+
this.field = field;
|
|
113
|
+
}
|
|
114
|
+
get message() {
|
|
115
|
+
return `Use custom OpenAPI declaration (OpenapiSchemaBodyShorthand) to define shape of virtual fields:
|
|
116
|
+
Dream model: ${this.dreamClass.sanitizedName}
|
|
117
|
+
Attribute: ${this.field}`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.UseCustomOpenapiForVirtualAttributes = UseCustomOpenapiForVirtualAttributes;
|
|
121
|
+
class UseCustomOpenapiForJson extends Error {
|
|
122
|
+
dreamClass;
|
|
123
|
+
field;
|
|
124
|
+
constructor(dreamClass, field) {
|
|
125
|
+
super();
|
|
126
|
+
this.dreamClass = dreamClass;
|
|
127
|
+
this.field = field;
|
|
128
|
+
}
|
|
129
|
+
get message() {
|
|
130
|
+
return `Use custom OpenAPI declaration (OpenapiSchemaBodyShorthand) to define shape of json and jsonb fields:
|
|
131
|
+
Dream model: ${this.dreamClass.sanitizedName}
|
|
132
|
+
Attribute: ${this.field}
|
|
133
|
+
|
|
134
|
+
For example:
|
|
135
|
+
|
|
136
|
+
export const MySerializer = (data: MyModel) =>
|
|
137
|
+
DreamSerializer(MyModel, data)
|
|
138
|
+
.jsonAttribute('myJson', {
|
|
139
|
+
openapi: {
|
|
140
|
+
type: 'object', properties: { hello: 'string' },
|
|
141
|
+
},
|
|
142
|
+
})`;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.UseCustomOpenapiForJson = UseCustomOpenapiForJson;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = isOpenapiShorthand;
|
|
7
|
+
const dream_1 = require("@rvoh/dream");
|
|
8
|
+
const maybeNullOpenapiShorthandToOpenapiShorthand_js_1 = __importDefault(require("./maybeNullOpenapiShorthandToOpenapiShorthand.js"));
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
function isOpenapiShorthand(openapi) {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
12
|
+
const openapiShorthand = (0, maybeNullOpenapiShorthandToOpenapiShorthand_js_1.default)(openapi);
|
|
13
|
+
if (typeof openapiShorthand !== 'string')
|
|
14
|
+
return false;
|
|
15
|
+
return dream_1.openapiShorthandPrimitiveTypes.includes(openapiShorthand);
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = maybeNullOpenapiShorthandToOpenapiShorthand;
|
|
4
|
+
function maybeNullOpenapiShorthandToOpenapiShorthand(openapi) {
|
|
5
|
+
if (openapi === undefined)
|
|
6
|
+
return undefined;
|
|
7
|
+
if (typeof openapi === 'string')
|
|
8
|
+
return openapi;
|
|
9
|
+
if (!Array.isArray(openapi))
|
|
10
|
+
return undefined;
|
|
11
|
+
if (openapi.length !== 2)
|
|
12
|
+
return undefined;
|
|
13
|
+
if (openapi[1] === 'null')
|
|
14
|
+
return openapi[0];
|
|
15
|
+
if (openapi[0] === 'null')
|
|
16
|
+
return openapi[1];
|
|
17
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UnrecognizedOpenapiShape = exports.UnrecognizedOpenapiShorthand = void 0;
|
|
7
|
+
exports.default = openapiShorthandToOpenapi;
|
|
8
|
+
const isObject_js_1 = __importDefault(require("../../helpers/isObject.js"));
|
|
9
|
+
const isOpenapiShorthand_js_1 = __importDefault(require("./isOpenapiShorthand.js"));
|
|
10
|
+
const maybeNullOpenapiShorthandToOpenapiShorthand_js_1 = __importDefault(require("./maybeNullOpenapiShorthandToOpenapiShorthand.js"));
|
|
11
|
+
function openapiShorthandToOpenapi(openapi, options = {}) {
|
|
12
|
+
if ((0, isOpenapiShorthand_js_1.default)(openapi)) {
|
|
13
|
+
return _openapiShorthandToOpenapi(openapi, options);
|
|
14
|
+
}
|
|
15
|
+
else if ((0, isObject_js_1.default)(openapi)) {
|
|
16
|
+
return openapi;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new UnrecognizedOpenapiShape(openapi);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function _openapiShorthandToOpenapi(shorthand, options) {
|
|
23
|
+
const shorthandString = (0, maybeNullOpenapiShorthandToOpenapiShorthand_js_1.default)(shorthand);
|
|
24
|
+
if (!shorthandString)
|
|
25
|
+
return { type: 'null' };
|
|
26
|
+
const openapi = simpleOpenapiShorthandToOpenapi(shorthandString);
|
|
27
|
+
if (options.maybeNull || openapiShorthandIncludesNull(shorthand))
|
|
28
|
+
return { ...openapi, type: [openapi.type, 'null'] };
|
|
29
|
+
return openapi;
|
|
30
|
+
}
|
|
31
|
+
function simpleOpenapiShorthandToOpenapi(shorthand) {
|
|
32
|
+
switch (shorthand) {
|
|
33
|
+
case 'string':
|
|
34
|
+
return { type: 'string' };
|
|
35
|
+
case 'boolean':
|
|
36
|
+
return { type: 'boolean' };
|
|
37
|
+
case 'number':
|
|
38
|
+
return { type: 'number' };
|
|
39
|
+
case 'date':
|
|
40
|
+
return { type: 'string', format: 'date' };
|
|
41
|
+
case 'date-time':
|
|
42
|
+
return { type: 'string', format: 'date-time' };
|
|
43
|
+
case 'decimal':
|
|
44
|
+
return { type: 'number', format: 'decimal' };
|
|
45
|
+
case 'integer':
|
|
46
|
+
return { type: 'integer' };
|
|
47
|
+
case 'null':
|
|
48
|
+
return { type: 'null' };
|
|
49
|
+
case 'string[]':
|
|
50
|
+
return { type: 'array', items: { type: 'string' } };
|
|
51
|
+
case 'boolean[]':
|
|
52
|
+
return { type: 'array', items: { type: 'boolean' } };
|
|
53
|
+
case 'number[]':
|
|
54
|
+
return { type: 'array', items: { type: 'number' } };
|
|
55
|
+
case 'date[]':
|
|
56
|
+
return { type: 'array', items: { type: 'string', format: 'date' } };
|
|
57
|
+
case 'date-time[]':
|
|
58
|
+
return { type: 'array', items: { type: 'string', format: 'date-time' } };
|
|
59
|
+
case 'decimal[]':
|
|
60
|
+
return { type: 'array', items: { type: 'number', format: 'decimal' } };
|
|
61
|
+
case 'integer[]':
|
|
62
|
+
return { type: 'array', items: { type: 'integer' } };
|
|
63
|
+
case 'json':
|
|
64
|
+
return { type: 'json' };
|
|
65
|
+
default: {
|
|
66
|
+
// protection so that if a new OpenapiShorthandPrimitiveBaseTypes is ever added, this will throw a type error at build time
|
|
67
|
+
const _never = shorthand;
|
|
68
|
+
throw new UnrecognizedOpenapiShorthand(_never);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function openapiShorthandIncludesNull(openapi) {
|
|
73
|
+
if (openapi === undefined)
|
|
74
|
+
return false;
|
|
75
|
+
if (typeof openapi === 'string')
|
|
76
|
+
return false;
|
|
77
|
+
if (!Array.isArray(openapi))
|
|
78
|
+
return false;
|
|
79
|
+
if (openapi.length !== 2)
|
|
80
|
+
return false;
|
|
81
|
+
if (openapi[1] === 'null')
|
|
82
|
+
return true;
|
|
83
|
+
if (openapi[0] === 'null')
|
|
84
|
+
return true;
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
class UnrecognizedOpenapiShorthand extends Error {
|
|
88
|
+
shorthand;
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
90
|
+
constructor(shorthand) {
|
|
91
|
+
super();
|
|
92
|
+
this.shorthand = shorthand;
|
|
93
|
+
}
|
|
94
|
+
get message() {
|
|
95
|
+
return `Unrecognized OpenAPI shorthand: ${JSON.stringify(this.shorthand)}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.UnrecognizedOpenapiShorthand = UnrecognizedOpenapiShorthand;
|
|
99
|
+
class UnrecognizedOpenapiShape extends Error {
|
|
100
|
+
openapi;
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
|
+
constructor(openapi) {
|
|
103
|
+
super();
|
|
104
|
+
this.openapi = openapi;
|
|
105
|
+
}
|
|
106
|
+
get message() {
|
|
107
|
+
return `Unrecognized OpenAPI shape:
|
|
108
|
+
${JSON.stringify(this.openapi)}`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.UnrecognizedOpenapiShape = UnrecognizedOpenapiShape;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.default = primitiveOpenapiStatementToOpenapi;
|
|
4
|
-
const
|
|
7
|
+
const openapiShorthandToOpenapi_js_1 = __importDefault(require("./openapiShorthandToOpenapi.js"));
|
|
5
8
|
/**
|
|
6
9
|
* @internal
|
|
7
10
|
*
|
|
8
11
|
* parses a primitive stored type
|
|
9
12
|
*/
|
|
10
13
|
function primitiveOpenapiStatementToOpenapi(data, maybeNull = false) {
|
|
11
|
-
return (0,
|
|
14
|
+
return (0, openapiShorthandToOpenapi_js_1.default)(data, { maybeNull });
|
|
12
15
|
}
|
|
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const dream_1 = require("@rvoh/dream");
|
|
7
7
|
const ParamValidationError_js_1 = __importDefault(require("../error/controller/ParamValidationError.js"));
|
|
8
8
|
const ParamValidationErrors_js_1 = __importDefault(require("../error/controller/ParamValidationErrors.js"));
|
|
9
|
-
const isUuid_js_1 = __importDefault(require("../helpers/isUuid.js"));
|
|
10
|
-
const typechecks_js_1 = require("../helpers/typechecks.js");
|
|
11
|
-
const isArrayParamName_js_1 = __importDefault(require("../helpers/isArrayParamName.js"));
|
|
12
9
|
const alternateParamName_js_1 = __importDefault(require("../helpers/alternateParamName.js"));
|
|
10
|
+
const isArrayParamName_js_1 = __importDefault(require("../helpers/isArrayParamName.js"));
|
|
11
|
+
const isObject_js_1 = __importDefault(require("../helpers/isObject.js"));
|
|
12
|
+
const isUuid_js_1 = __importDefault(require("../helpers/isUuid.js"));
|
|
13
13
|
class Params {
|
|
14
14
|
$params;
|
|
15
15
|
/**
|
|
@@ -303,7 +303,7 @@ class Params {
|
|
|
303
303
|
const permitted = {};
|
|
304
304
|
if (params === null || params === undefined)
|
|
305
305
|
return permitted;
|
|
306
|
-
if (!(0,
|
|
306
|
+
if (!(0, isObject_js_1.default)(params))
|
|
307
307
|
throw new Error(`Params.restrict expects object or null, received: ${JSON.stringify(params)}`);
|
|
308
308
|
const objectParam = params;
|
|
309
309
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -4,7 +4,7 @@ import * as path from 'node:path';
|
|
|
4
4
|
import TypesBuilder from '../cli/helpers/TypesBuilder.js';
|
|
5
5
|
import generateController from '../generate/controller.js';
|
|
6
6
|
import generateResource from '../generate/resource.js';
|
|
7
|
-
import
|
|
7
|
+
import isObject from '../helpers/isObject.js';
|
|
8
8
|
import OpenapiAppRenderer from '../openapi-renderer/app.js';
|
|
9
9
|
import PsychicApp from '../psychic-app/index.js';
|
|
10
10
|
import PsychicServer from '../server/index.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
export default class AttemptedToDeriveDescendentSerializersFromNonSerializer extends Error {
|
|
3
|
+
serializer;
|
|
4
|
+
constructor(serializer) {
|
|
5
|
+
super();
|
|
6
|
+
this.serializer = serializer;
|
|
7
|
+
}
|
|
8
|
+
get message() {
|
|
9
|
+
return `
|
|
10
|
+
Attempted to derive descendant serializers from non serializer:
|
|
11
|
+
${inspect(this.serializer)}`;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export default class ExpectedSerializerForRendersOneOrManyOption extends Error {
|
|
2
|
+
rendersOneOrMany;
|
|
3
|
+
referencingSerializerName;
|
|
4
|
+
attribute;
|
|
5
|
+
constructor(rendersOneOrMany, referencingSerializerName, attribute) {
|
|
6
|
+
super();
|
|
7
|
+
this.rendersOneOrMany = rendersOneOrMany;
|
|
8
|
+
this.referencingSerializerName = referencingSerializerName;
|
|
9
|
+
this.attribute = attribute;
|
|
10
|
+
}
|
|
11
|
+
get message() {
|
|
12
|
+
const baseString = `
|
|
13
|
+
The \`serializer\` option on the \`${this.attribute.name}\` \`${this.rendersOneOrMany}\`
|
|
14
|
+
on serializer \`${this.referencingSerializerName}\``;
|
|
15
|
+
if (this.attribute.options?.serializer) {
|
|
16
|
+
return `${baseString}
|
|
17
|
+
specifies something other than a serializer.
|
|
18
|
+
It should look something like the following:
|
|
19
|
+
|
|
20
|
+
\`\`\`
|
|
21
|
+
.${this.rendersOneOrMany}('${this.attribute.name}', {
|
|
22
|
+
serializer: MySerializer
|
|
23
|
+
})
|
|
24
|
+
\`\`\`
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return `${baseString}
|
|
29
|
+
is throwing an error.
|
|
30
|
+
`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default class NoSerializerFoundForRendersOneAndMany extends Error {
|
|
2
|
+
associationName;
|
|
3
|
+
constructor(associationName) {
|
|
4
|
+
super();
|
|
5
|
+
this.associationName = associationName;
|
|
6
|
+
}
|
|
7
|
+
get message() {
|
|
8
|
+
return `
|
|
9
|
+
Attempted to render \`rendersOne\` / \`rendersMany\`
|
|
10
|
+
\`${this.associationName}\`, but could not locate a
|
|
11
|
+
serializer.`;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
export default class NonSerializerPassedToSerializerOpenapiRenderer extends Error {
|
|
3
|
+
serializer;
|
|
4
|
+
constructor(serializer) {
|
|
5
|
+
super();
|
|
6
|
+
this.serializer = serializer;
|
|
7
|
+
}
|
|
8
|
+
get message() {
|
|
9
|
+
return `
|
|
10
|
+
Non-serializer passed to SerializerOpenapiRenderer:
|
|
11
|
+
${inspect(this.serializer)}`;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
export default class NonSerializerSerializerOverrideProvided extends Error {
|
|
3
|
+
rendersAssociation;
|
|
4
|
+
serializer;
|
|
5
|
+
constructor(rendersAssociation, serializer) {
|
|
6
|
+
super();
|
|
7
|
+
this.rendersAssociation = rendersAssociation;
|
|
8
|
+
this.serializer = serializer;
|
|
9
|
+
}
|
|
10
|
+
get message() {
|
|
11
|
+
return `
|
|
12
|
+
Non-serializer passed to \`serializerOverride\` of a rendersOne/Many declaration:
|
|
13
|
+
|
|
14
|
+
rendersOne/Many declaration:
|
|
15
|
+
${inspect(this.rendersAssociation)}
|
|
16
|
+
|
|
17
|
+
non-serializer passed to serializerOverride:
|
|
18
|
+
${inspect(this.serializer)}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default class ObjectSerializerRendersOneAndManyRequireClassType extends Error {
|
|
2
|
+
associationName;
|
|
3
|
+
constructor(associationName) {
|
|
4
|
+
super();
|
|
5
|
+
this.associationName = associationName;
|
|
6
|
+
}
|
|
7
|
+
get message() {
|
|
8
|
+
return `
|
|
9
|
+
ObjectSerializer \`rendersOne\` and \`rendersMany\`
|
|
10
|
+
options must include \`dreamClass\`, \`viewModelClass\`, or
|
|
11
|
+
\`serializer\`.
|
|
12
|
+
|
|
13
|
+
rendersOne/Many name: ${this.associationName}
|
|
14
|
+
`;
|
|
15
|
+
}
|
|
16
|
+
}
|