@rvoh/psychic 2.0.0-alpha.4 → 2.0.0-alpha.6
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/cli/index.js +14 -2
- package/dist/cjs/src/generate/helpers/generateResourceControllerSpecContent.js +9 -8
- package/dist/cjs/src/openapi-renderer/endpoint.js +3 -3
- package/dist/cjs/src/openapi-renderer/helpers/scrollPaginationCursorParamOpenapiProperty.js +1 -1
- package/dist/cjs/src/server/helpers/openapiParamNamesForDreamClass.js +18 -0
- package/dist/cjs/src/server/helpers/paramNamesForDreamClass.js +2 -15
- package/dist/esm/src/cli/index.js +14 -2
- package/dist/esm/src/generate/helpers/generateResourceControllerSpecContent.js +9 -8
- package/dist/esm/src/openapi-renderer/endpoint.js +3 -3
- package/dist/esm/src/openapi-renderer/helpers/scrollPaginationCursorParamOpenapiProperty.js +1 -1
- package/dist/esm/src/server/helpers/openapiParamNamesForDreamClass.js +18 -0
- package/dist/esm/src/server/helpers/paramNamesForDreamClass.js +2 -15
- package/dist/types/src/controller/index.d.ts +3 -5
- package/dist/types/src/openapi-renderer/helpers/scrollPaginationCursorParamOpenapiProperty.d.ts +1 -1
- package/dist/types/src/server/helpers/openapiParamNamesForDreamClass.d.ts +12 -0
- package/dist/types/src/server/helpers/paramNamesForDreamClass.d.ts +3 -5
- package/dist/types/src/server/params.d.ts +7 -9
- package/package.json +1 -1
|
@@ -15,25 +15,37 @@ ${INDENT} subtitle:string:optional
|
|
|
15
15
|
${INDENT}
|
|
16
16
|
${INDENT}supported types:
|
|
17
17
|
${INDENT} - citext:
|
|
18
|
+
${INDENT} - citext[]:
|
|
18
19
|
${INDENT} case insensitive text (indexes and queries are automatically case insensitive)
|
|
19
20
|
${INDENT}
|
|
20
21
|
${INDENT} - string:
|
|
22
|
+
${INDENT} - string[]:
|
|
21
23
|
${INDENT} varchar; allowed length defaults to 255, but may be customized, e.g.: subtitle:string:128 or subtitle:string:128:optional
|
|
22
24
|
${INDENT}
|
|
23
25
|
${INDENT} - text
|
|
26
|
+
${INDENT} - text[]
|
|
24
27
|
${INDENT} - date
|
|
28
|
+
${INDENT} - date[]
|
|
25
29
|
${INDENT} - datetime
|
|
30
|
+
${INDENT} - datetime[]
|
|
26
31
|
${INDENT} - integer
|
|
32
|
+
${INDENT} - integer[]
|
|
27
33
|
${INDENT}
|
|
28
34
|
${INDENT} - decimal:
|
|
35
|
+
${INDENT} - decimal[]:
|
|
29
36
|
${INDENT} scale,precision is required, e.g.: volume:decimal:3,2 or volume:decimal:3,2:optional
|
|
30
37
|
${INDENT}
|
|
38
|
+
${INDENT} leveraging arrays, add the "[]" suffix, e.g.: volume:decimal[]:3,2
|
|
39
|
+
${INDENT}
|
|
31
40
|
${INDENT} - enum:
|
|
41
|
+
${INDENT} - enum[]:
|
|
32
42
|
${INDENT} include the enum name to automatically create the enum:
|
|
33
43
|
${INDENT} type:enum:room_types:bathroom,kitchen,bedroom or type:enum:room_types:bathroom,kitchen,bedroom:optional
|
|
34
44
|
${INDENT}
|
|
35
45
|
${INDENT} omit the enum values to leverage an existing enum (omits the enum type creation):
|
|
36
|
-
${INDENT} type:enum:room_types or type:enum:room_types:optional
|
|
46
|
+
${INDENT} type:enum:room_types or type:enum:room_types:optional
|
|
47
|
+
${INDENT}
|
|
48
|
+
${INDENT} leveraging arrays, add the "[]" suffix, e.g.: type:enum[]:room_types:bathroom,kitchen,bedroom`;
|
|
37
49
|
const columnsWithTypesDescription = baseColumnsWithTypesDescription +
|
|
38
50
|
`
|
|
39
51
|
${INDENT}
|
|
@@ -63,7 +75,7 @@ export default class PsychicCLI {
|
|
|
63
75
|
- update
|
|
64
76
|
- delete`)
|
|
65
77
|
.option('--sti-base-serializer', 'omits the serializer from the dream model, but does create the serializer so it can be extended by STI children')
|
|
66
|
-
.option('--owning-model <modelName>', 'the model class of the object that `associationQuery`/`createAssociation` will be performed on in the created controller and spec (e.g., "Host", "Guest") (simply to save time making changes to the generated code). Defaults to User')
|
|
78
|
+
.option('--owning-model <modelName>', 'the model class of the object that `associationQuery`/`createAssociation` will be performed on in the created controller and spec (e.g., "Host", "Guest", "Ticketing/Ticket") (simply to save time making changes to the generated code). Defaults to User')
|
|
67
79
|
.option('--connection-name <connectionName>', 'the name of the db connection you would like to use for your model. Defaults to "default"', 'default')
|
|
68
80
|
.argument('<path>', 'URL path from root domain. Specify nesting resource with `{}`, e.g.: `tickets/{}/comments`')
|
|
69
81
|
.argument('<modelName>', 'the name of the model to create, e.g. Post or Settings/CommunicationPreferences')
|
|
@@ -33,7 +33,6 @@ export default function generateResourceControllerSpecContent({ fullyQualifiedCo
|
|
|
33
33
|
const expectEqualUpdatedValue = [];
|
|
34
34
|
const expectEqualOriginalNamedVariable = [];
|
|
35
35
|
const originalValueVariableAssignments = [];
|
|
36
|
-
const keyWithDotValue = [];
|
|
37
36
|
let dateAttributeIncluded = false;
|
|
38
37
|
let datetimeAttributeIncluded = false;
|
|
39
38
|
for (const attribute of columnsWithTypes) {
|
|
@@ -55,11 +54,13 @@ export default function generateResourceControllerSpecContent({ fullyQualifiedCo
|
|
|
55
54
|
const rawUpdatedEnumValue = (enumValues ?? '').split(',').at(-1);
|
|
56
55
|
const originalEnumValue = isArray ? [rawOriginalEnumValue] : rawOriginalEnumValue;
|
|
57
56
|
const updatedEnumValue = isArray ? [rawUpdatedEnumValue] : rawUpdatedEnumValue;
|
|
58
|
-
attributeCreationKeyValues.push(`${attributeName}: ${jsonify(originalEnumValue)},`);
|
|
59
|
-
attributeUpdateKeyValues.push(`${attributeName}: ${jsonify(updatedEnumValue)},`);
|
|
60
57
|
comparableOriginalAttributeKeyValues.push(`${attributeName}: ${dotNotationVariable},`);
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
if (attributeName !== 'type') {
|
|
59
|
+
attributeCreationKeyValues.push(`${attributeName}: ${jsonify(originalEnumValue)},`);
|
|
60
|
+
attributeUpdateKeyValues.push(`${attributeName}: ${jsonify(updatedEnumValue)},`);
|
|
61
|
+
expectEqualOriginalValue.push(`expect(${dotNotationVariable}).toEqual(${jsonify(originalEnumValue)})`);
|
|
62
|
+
expectEqualUpdatedValue.push(`expect(${dotNotationVariable}).toEqual(${jsonify(updatedEnumValue)})`);
|
|
63
|
+
}
|
|
63
64
|
break;
|
|
64
65
|
}
|
|
65
66
|
case 'string':
|
|
@@ -113,9 +114,9 @@ export default function generateResourceControllerSpecContent({ fullyQualifiedCo
|
|
|
113
114
|
default:
|
|
114
115
|
continue;
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
-
if (!
|
|
118
|
-
const originalAttributeVariableName =
|
|
117
|
+
const hardToCompareArray = (attributeType === 'date' || attributeType === 'datetime') && isArray;
|
|
118
|
+
if (!hardToCompareArray && attributeName !== 'type') {
|
|
119
|
+
const originalAttributeVariableName = `original${capitalize(attributeName)}`;
|
|
119
120
|
originalValueVariableAssignments.push(`const ${originalAttributeVariableName} = ${dotNotationVariable}`);
|
|
120
121
|
expectEqualOriginalNamedVariable.push(`expect(${dotNotationVariable}).toEqual(${originalAttributeVariableName})`);
|
|
121
122
|
}
|
|
@@ -5,7 +5,7 @@ import NonSerializerDerivedInOpenapiEndpointRenderer from '../error/openapi/NonS
|
|
|
5
5
|
import NonSerializerDerivedInToSchemaObjects from '../error/openapi/NonSerializerDerivedInToSchemaObjects.js';
|
|
6
6
|
import OpenApiSerializerForEndpointNotAFunction from '../error/openapi/SerializerForEndpointNotAFunction.js';
|
|
7
7
|
import PsychicApp from '../psychic-app/index.js';
|
|
8
|
-
import
|
|
8
|
+
import openapiParamNamesForDreamClass from '../server/helpers/openapiParamNamesForDreamClass.js';
|
|
9
9
|
import OpenapiSegmentExpander from './body-segment.js';
|
|
10
10
|
import { DEFAULT_OPENAPI_RESPONSES } from './defaults.js';
|
|
11
11
|
import { dreamColumnOpenapiShape } from './helpers/dreamAttributeOpenapiShape.js';
|
|
@@ -409,7 +409,7 @@ export default class OpenapiEndpointRenderer {
|
|
|
409
409
|
in: 'query',
|
|
410
410
|
required: false,
|
|
411
411
|
name: scrollPaginationName,
|
|
412
|
-
description: '
|
|
412
|
+
description: 'Scroll pagination cursor',
|
|
413
413
|
allowReserved: true,
|
|
414
414
|
schema: {
|
|
415
415
|
type: ['string', 'null'],
|
|
@@ -531,7 +531,7 @@ export default class OpenapiEndpointRenderer {
|
|
|
531
531
|
return this.defaultRequestBody();
|
|
532
532
|
const { only, including, combining } = (this.requestBody || {});
|
|
533
533
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
534
|
-
const paramSafeColumns =
|
|
534
|
+
const paramSafeColumns = openapiParamNamesForDreamClass(dreamClass, { only, including });
|
|
535
535
|
const paramsShape = {
|
|
536
536
|
type: 'object',
|
|
537
537
|
properties: {},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import paramNamesForDreamClass from './paramNamesForDreamClass.js';
|
|
2
|
+
export default function openapiParamNamesForDreamClass(dreamClass, { only, including } = {}) {
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
let paramSafeColumns = paramNamesForDreamClass(dreamClass, { only });
|
|
5
|
+
if (Array.isArray(including)) {
|
|
6
|
+
paramSafeColumns = [
|
|
7
|
+
...paramSafeColumns,
|
|
8
|
+
// TODO: add a method to dream which can extrapolate
|
|
9
|
+
// all of these fields from the model
|
|
10
|
+
...[
|
|
11
|
+
...dreamClass.columns(),
|
|
12
|
+
...dreamClass['virtualAttributes'].map(statement => statement.property),
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
14
|
+
].filter(columnName => including.includes(columnName)),
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
return paramSafeColumns;
|
|
18
|
+
}
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
export default function paramNamesForDreamClass(dreamClass, { only
|
|
2
|
-
|
|
1
|
+
export default function paramNamesForDreamClass(dreamClass, { only } = {}) {
|
|
2
|
+
return Array.isArray(only)
|
|
3
3
|
? dreamClass.paramSafeColumnsOrFallback().filter(column => only.includes(column))
|
|
4
4
|
: dreamClass.paramSafeColumnsOrFallback();
|
|
5
|
-
if (Array.isArray(including)) {
|
|
6
|
-
paramSafeColumns = [
|
|
7
|
-
...paramSafeColumns,
|
|
8
|
-
// TODO: add a method to dream which can extrapolate
|
|
9
|
-
// all of these fields from the model
|
|
10
|
-
...[
|
|
11
|
-
...dreamClass.columns(),
|
|
12
|
-
...dreamClass['virtualAttributes'].map(statement => statement.property),
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
14
|
-
].filter(columnName => including.includes(columnName)),
|
|
15
|
-
];
|
|
16
|
-
}
|
|
17
|
-
return paramSafeColumns;
|
|
18
5
|
}
|
|
@@ -15,25 +15,37 @@ ${INDENT} subtitle:string:optional
|
|
|
15
15
|
${INDENT}
|
|
16
16
|
${INDENT}supported types:
|
|
17
17
|
${INDENT} - citext:
|
|
18
|
+
${INDENT} - citext[]:
|
|
18
19
|
${INDENT} case insensitive text (indexes and queries are automatically case insensitive)
|
|
19
20
|
${INDENT}
|
|
20
21
|
${INDENT} - string:
|
|
22
|
+
${INDENT} - string[]:
|
|
21
23
|
${INDENT} varchar; allowed length defaults to 255, but may be customized, e.g.: subtitle:string:128 or subtitle:string:128:optional
|
|
22
24
|
${INDENT}
|
|
23
25
|
${INDENT} - text
|
|
26
|
+
${INDENT} - text[]
|
|
24
27
|
${INDENT} - date
|
|
28
|
+
${INDENT} - date[]
|
|
25
29
|
${INDENT} - datetime
|
|
30
|
+
${INDENT} - datetime[]
|
|
26
31
|
${INDENT} - integer
|
|
32
|
+
${INDENT} - integer[]
|
|
27
33
|
${INDENT}
|
|
28
34
|
${INDENT} - decimal:
|
|
35
|
+
${INDENT} - decimal[]:
|
|
29
36
|
${INDENT} scale,precision is required, e.g.: volume:decimal:3,2 or volume:decimal:3,2:optional
|
|
30
37
|
${INDENT}
|
|
38
|
+
${INDENT} leveraging arrays, add the "[]" suffix, e.g.: volume:decimal[]:3,2
|
|
39
|
+
${INDENT}
|
|
31
40
|
${INDENT} - enum:
|
|
41
|
+
${INDENT} - enum[]:
|
|
32
42
|
${INDENT} include the enum name to automatically create the enum:
|
|
33
43
|
${INDENT} type:enum:room_types:bathroom,kitchen,bedroom or type:enum:room_types:bathroom,kitchen,bedroom:optional
|
|
34
44
|
${INDENT}
|
|
35
45
|
${INDENT} omit the enum values to leverage an existing enum (omits the enum type creation):
|
|
36
|
-
${INDENT} type:enum:room_types or type:enum:room_types:optional
|
|
46
|
+
${INDENT} type:enum:room_types or type:enum:room_types:optional
|
|
47
|
+
${INDENT}
|
|
48
|
+
${INDENT} leveraging arrays, add the "[]" suffix, e.g.: type:enum[]:room_types:bathroom,kitchen,bedroom`;
|
|
37
49
|
const columnsWithTypesDescription = baseColumnsWithTypesDescription +
|
|
38
50
|
`
|
|
39
51
|
${INDENT}
|
|
@@ -63,7 +75,7 @@ export default class PsychicCLI {
|
|
|
63
75
|
- update
|
|
64
76
|
- delete`)
|
|
65
77
|
.option('--sti-base-serializer', 'omits the serializer from the dream model, but does create the serializer so it can be extended by STI children')
|
|
66
|
-
.option('--owning-model <modelName>', 'the model class of the object that `associationQuery`/`createAssociation` will be performed on in the created controller and spec (e.g., "Host", "Guest") (simply to save time making changes to the generated code). Defaults to User')
|
|
78
|
+
.option('--owning-model <modelName>', 'the model class of the object that `associationQuery`/`createAssociation` will be performed on in the created controller and spec (e.g., "Host", "Guest", "Ticketing/Ticket") (simply to save time making changes to the generated code). Defaults to User')
|
|
67
79
|
.option('--connection-name <connectionName>', 'the name of the db connection you would like to use for your model. Defaults to "default"', 'default')
|
|
68
80
|
.argument('<path>', 'URL path from root domain. Specify nesting resource with `{}`, e.g.: `tickets/{}/comments`')
|
|
69
81
|
.argument('<modelName>', 'the name of the model to create, e.g. Post or Settings/CommunicationPreferences')
|
|
@@ -33,7 +33,6 @@ export default function generateResourceControllerSpecContent({ fullyQualifiedCo
|
|
|
33
33
|
const expectEqualUpdatedValue = [];
|
|
34
34
|
const expectEqualOriginalNamedVariable = [];
|
|
35
35
|
const originalValueVariableAssignments = [];
|
|
36
|
-
const keyWithDotValue = [];
|
|
37
36
|
let dateAttributeIncluded = false;
|
|
38
37
|
let datetimeAttributeIncluded = false;
|
|
39
38
|
for (const attribute of columnsWithTypes) {
|
|
@@ -55,11 +54,13 @@ export default function generateResourceControllerSpecContent({ fullyQualifiedCo
|
|
|
55
54
|
const rawUpdatedEnumValue = (enumValues ?? '').split(',').at(-1);
|
|
56
55
|
const originalEnumValue = isArray ? [rawOriginalEnumValue] : rawOriginalEnumValue;
|
|
57
56
|
const updatedEnumValue = isArray ? [rawUpdatedEnumValue] : rawUpdatedEnumValue;
|
|
58
|
-
attributeCreationKeyValues.push(`${attributeName}: ${jsonify(originalEnumValue)},`);
|
|
59
|
-
attributeUpdateKeyValues.push(`${attributeName}: ${jsonify(updatedEnumValue)},`);
|
|
60
57
|
comparableOriginalAttributeKeyValues.push(`${attributeName}: ${dotNotationVariable},`);
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
if (attributeName !== 'type') {
|
|
59
|
+
attributeCreationKeyValues.push(`${attributeName}: ${jsonify(originalEnumValue)},`);
|
|
60
|
+
attributeUpdateKeyValues.push(`${attributeName}: ${jsonify(updatedEnumValue)},`);
|
|
61
|
+
expectEqualOriginalValue.push(`expect(${dotNotationVariable}).toEqual(${jsonify(originalEnumValue)})`);
|
|
62
|
+
expectEqualUpdatedValue.push(`expect(${dotNotationVariable}).toEqual(${jsonify(updatedEnumValue)})`);
|
|
63
|
+
}
|
|
63
64
|
break;
|
|
64
65
|
}
|
|
65
66
|
case 'string':
|
|
@@ -113,9 +114,9 @@ export default function generateResourceControllerSpecContent({ fullyQualifiedCo
|
|
|
113
114
|
default:
|
|
114
115
|
continue;
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
-
if (!
|
|
118
|
-
const originalAttributeVariableName =
|
|
117
|
+
const hardToCompareArray = (attributeType === 'date' || attributeType === 'datetime') && isArray;
|
|
118
|
+
if (!hardToCompareArray && attributeName !== 'type') {
|
|
119
|
+
const originalAttributeVariableName = `original${capitalize(attributeName)}`;
|
|
119
120
|
originalValueVariableAssignments.push(`const ${originalAttributeVariableName} = ${dotNotationVariable}`);
|
|
120
121
|
expectEqualOriginalNamedVariable.push(`expect(${dotNotationVariable}).toEqual(${originalAttributeVariableName})`);
|
|
121
122
|
}
|
|
@@ -5,7 +5,7 @@ import NonSerializerDerivedInOpenapiEndpointRenderer from '../error/openapi/NonS
|
|
|
5
5
|
import NonSerializerDerivedInToSchemaObjects from '../error/openapi/NonSerializerDerivedInToSchemaObjects.js';
|
|
6
6
|
import OpenApiSerializerForEndpointNotAFunction from '../error/openapi/SerializerForEndpointNotAFunction.js';
|
|
7
7
|
import PsychicApp from '../psychic-app/index.js';
|
|
8
|
-
import
|
|
8
|
+
import openapiParamNamesForDreamClass from '../server/helpers/openapiParamNamesForDreamClass.js';
|
|
9
9
|
import OpenapiSegmentExpander from './body-segment.js';
|
|
10
10
|
import { DEFAULT_OPENAPI_RESPONSES } from './defaults.js';
|
|
11
11
|
import { dreamColumnOpenapiShape } from './helpers/dreamAttributeOpenapiShape.js';
|
|
@@ -409,7 +409,7 @@ export default class OpenapiEndpointRenderer {
|
|
|
409
409
|
in: 'query',
|
|
410
410
|
required: false,
|
|
411
411
|
name: scrollPaginationName,
|
|
412
|
-
description: '
|
|
412
|
+
description: 'Scroll pagination cursor',
|
|
413
413
|
allowReserved: true,
|
|
414
414
|
schema: {
|
|
415
415
|
type: ['string', 'null'],
|
|
@@ -531,7 +531,7 @@ export default class OpenapiEndpointRenderer {
|
|
|
531
531
|
return this.defaultRequestBody();
|
|
532
532
|
const { only, including, combining } = (this.requestBody || {});
|
|
533
533
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
534
|
-
const paramSafeColumns =
|
|
534
|
+
const paramSafeColumns = openapiParamNamesForDreamClass(dreamClass, { only, including });
|
|
535
535
|
const paramsShape = {
|
|
536
536
|
type: 'object',
|
|
537
537
|
properties: {},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import paramNamesForDreamClass from './paramNamesForDreamClass.js';
|
|
2
|
+
export default function openapiParamNamesForDreamClass(dreamClass, { only, including } = {}) {
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
let paramSafeColumns = paramNamesForDreamClass(dreamClass, { only });
|
|
5
|
+
if (Array.isArray(including)) {
|
|
6
|
+
paramSafeColumns = [
|
|
7
|
+
...paramSafeColumns,
|
|
8
|
+
// TODO: add a method to dream which can extrapolate
|
|
9
|
+
// all of these fields from the model
|
|
10
|
+
...[
|
|
11
|
+
...dreamClass.columns(),
|
|
12
|
+
...dreamClass['virtualAttributes'].map(statement => statement.property),
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
14
|
+
].filter(columnName => including.includes(columnName)),
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
return paramSafeColumns;
|
|
18
|
+
}
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
export default function paramNamesForDreamClass(dreamClass, { only
|
|
2
|
-
|
|
1
|
+
export default function paramNamesForDreamClass(dreamClass, { only } = {}) {
|
|
2
|
+
return Array.isArray(only)
|
|
3
3
|
? dreamClass.paramSafeColumnsOrFallback().filter(column => only.includes(column))
|
|
4
4
|
: dreamClass.paramSafeColumnsOrFallback();
|
|
5
|
-
if (Array.isArray(including)) {
|
|
6
|
-
paramSafeColumns = [
|
|
7
|
-
...paramSafeColumns,
|
|
8
|
-
// TODO: add a method to dream which can extrapolate
|
|
9
|
-
// all of these fields from the model
|
|
10
|
-
...[
|
|
11
|
-
...dreamClass.columns(),
|
|
12
|
-
...dreamClass['virtualAttributes'].map(statement => statement.property),
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
14
|
-
].filter(columnName => including.includes(columnName)),
|
|
15
|
-
];
|
|
16
|
-
}
|
|
17
|
-
return paramSafeColumns;
|
|
18
5
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Dream } from '@rvoh/dream';
|
|
2
2
|
import { OpenapiSchemaBody } from '@rvoh/dream/openapi';
|
|
3
|
-
import { DreamParamSafeAttributes, DreamParamSafeColumnNames, SerializerRendererOpts
|
|
3
|
+
import { DreamParamSafeAttributes, DreamParamSafeColumnNames, SerializerRendererOpts } from '@rvoh/dream/types';
|
|
4
4
|
import { Request, Response } from 'express';
|
|
5
5
|
import { ControllerHook } from '../controller/hooks.js';
|
|
6
6
|
import { HttpStatusCodeInt, HttpStatusSymbol } from '../error/http/status-codes.js';
|
|
@@ -273,15 +273,13 @@ export default class PsychicController {
|
|
|
273
273
|
* }
|
|
274
274
|
* ```
|
|
275
275
|
*/
|
|
276
|
-
paramsFor<T extends typeof Dream, I extends InstanceType<T>, const OnlyArray extends readonly (keyof DreamParamSafeAttributes<I>)[],
|
|
276
|
+
paramsFor<T extends typeof Dream, I extends InstanceType<T>, const OnlyArray extends readonly (keyof DreamParamSafeAttributes<I>)[], ForOpts extends ParamsForOpts<OnlyArray> & {
|
|
277
277
|
key?: string;
|
|
278
278
|
}, ParamSafeColumnsOverride extends I['paramSafeColumns' & keyof I] extends never ? undefined : I['paramSafeColumns' & keyof I] & string[], ParamSafeColumns extends ParamSafeColumnsOverride extends string[] | Readonly<string[]> ? Extract<DreamParamSafeColumnNames<I>, ParamSafeColumnsOverride[number] & DreamParamSafeColumnNames<I>>[] : DreamParamSafeColumnNames<I>[], ParamSafeAttrs extends DreamParamSafeAttributes<InstanceType<T>>, ReturnPartialType extends ForOpts['only'] extends readonly (keyof DreamParamSafeAttributes<InstanceType<T>>)[] ? Partial<{
|
|
279
279
|
[K in ForOpts['only'][number] & keyof ParamSafeAttrs]: ParamSafeAttrs[K & keyof ParamSafeAttrs];
|
|
280
280
|
}> : Partial<{
|
|
281
281
|
[K in ParamSafeColumns[number & keyof ParamSafeColumns] & string]: DreamParamSafeAttributes<InstanceType<T>>[K & keyof DreamParamSafeAttributes<InstanceType<T>>];
|
|
282
|
-
}>,
|
|
283
|
-
[K in Extract<keyof UpdateableProperties<InstanceType<T>>, ForOpts['including'][number & keyof ForOpts['including']]>]: UpdateableProperties<InstanceType<T>>[K];
|
|
284
|
-
}> : ReturnPartialType, ReturnPayload extends ForOpts['array'] extends true ? ReturnPartialTypeWithIncluding[] : ReturnPartialTypeWithIncluding>(this: PsychicController, dreamClass: T, opts?: ForOpts): ReturnPayload;
|
|
282
|
+
}>, ReturnPayload extends ForOpts['array'] extends true ? ReturnPartialType[] : ReturnPartialType>(this: PsychicController, dreamClass: T, opts?: ForOpts): ReturnPayload;
|
|
285
283
|
/**
|
|
286
284
|
* Gets a cookie value from the request and casts it to the specified type.
|
|
287
285
|
*
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Dream } from '@rvoh/dream';
|
|
2
|
+
import { DreamParamSafeAttributes, DreamParamSafeColumnNames, UpdateableProperties } from '@rvoh/dream/types';
|
|
3
|
+
import { OpenAPIDreamModelRequestBodyModifications } from '../params.js';
|
|
4
|
+
export default function openapiParamNamesForDreamClass<T extends typeof Dream, I extends InstanceType<T>, const OnlyArray extends readonly (keyof DreamParamSafeAttributes<I>)[], const IncludingArray extends Exclude<keyof UpdateableProperties<I>, OnlyArray[number]>[], ForOpts extends OpenAPIDreamModelRequestBodyModifications<OnlyArray, IncludingArray> & {
|
|
5
|
+
key?: string;
|
|
6
|
+
}, ParamSafeColumnsOverride extends I['paramSafeColumns' & keyof I] extends never ? undefined : I['paramSafeColumns' & keyof I] & string[], ParamSafeColumns extends ParamSafeColumnsOverride extends string[] | Readonly<string[]> ? Extract<DreamParamSafeColumnNames<I>, ParamSafeColumnsOverride[number] & DreamParamSafeColumnNames<I>>[] : DreamParamSafeColumnNames<I>[], ParamSafeAttrs extends DreamParamSafeAttributes<InstanceType<T>>, ReturnPartialType extends ForOpts['only'] extends readonly (keyof DreamParamSafeAttributes<InstanceType<T>>)[] ? Partial<{
|
|
7
|
+
[K in ForOpts['only'][number] & keyof ParamSafeAttrs]: ParamSafeAttrs[K & keyof ParamSafeAttrs];
|
|
8
|
+
}> : Partial<{
|
|
9
|
+
[K in ParamSafeColumns[number & keyof ParamSafeColumns] & string]: DreamParamSafeAttributes<InstanceType<T>>[K & keyof DreamParamSafeAttributes<InstanceType<T>>];
|
|
10
|
+
}>, ReturnPartialTypeWithIncluding extends ForOpts['including'] extends readonly (keyof UpdateableProperties<InstanceType<T>>)[] ? ReturnPartialType & Partial<{
|
|
11
|
+
[K in Extract<keyof UpdateableProperties<InstanceType<T>>, ForOpts['including'][number & keyof ForOpts['including']]>]: UpdateableProperties<InstanceType<T>>[K];
|
|
12
|
+
}> : ReturnPartialType, RetArray = (keyof ReturnPartialTypeWithIncluding)[]>(dreamClass: T, { only, including }?: ForOpts): RetArray;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Dream } from '@rvoh/dream';
|
|
2
|
-
import { DreamParamSafeAttributes, DreamParamSafeColumnNames
|
|
2
|
+
import { DreamParamSafeAttributes, DreamParamSafeColumnNames } from '@rvoh/dream/types';
|
|
3
3
|
import { ParamsForOpts } from '../params.js';
|
|
4
|
-
export default function paramNamesForDreamClass<T extends typeof Dream, I extends InstanceType<T>, const OnlyArray extends readonly (keyof DreamParamSafeAttributes<I>)[],
|
|
4
|
+
export default function paramNamesForDreamClass<T extends typeof Dream, I extends InstanceType<T>, const OnlyArray extends readonly (keyof DreamParamSafeAttributes<I>)[], ForOpts extends ParamsForOpts<OnlyArray> & {
|
|
5
5
|
key?: string;
|
|
6
6
|
}, ParamSafeColumnsOverride extends I['paramSafeColumns' & keyof I] extends never ? undefined : I['paramSafeColumns' & keyof I] & string[], ParamSafeColumns extends ParamSafeColumnsOverride extends string[] | Readonly<string[]> ? Extract<DreamParamSafeColumnNames<I>, ParamSafeColumnsOverride[number] & DreamParamSafeColumnNames<I>>[] : DreamParamSafeColumnNames<I>[], ParamSafeAttrs extends DreamParamSafeAttributes<InstanceType<T>>, ReturnPartialType extends ForOpts['only'] extends readonly (keyof DreamParamSafeAttributes<InstanceType<T>>)[] ? Partial<{
|
|
7
7
|
[K in ForOpts['only'][number] & keyof ParamSafeAttrs]: ParamSafeAttrs[K & keyof ParamSafeAttrs];
|
|
8
8
|
}> : Partial<{
|
|
9
9
|
[K in ParamSafeColumns[number & keyof ParamSafeColumns] & string]: DreamParamSafeAttributes<InstanceType<T>>[K & keyof DreamParamSafeAttributes<InstanceType<T>>];
|
|
10
|
-
}>,
|
|
11
|
-
[K in Extract<keyof UpdateableProperties<InstanceType<T>>, ForOpts['including'][number & keyof ForOpts['including']]>]: UpdateableProperties<InstanceType<T>>[K];
|
|
12
|
-
}> : ReturnPartialType, RetArray = (keyof ReturnPartialTypeWithIncluding)[]>(dreamClass: T, { only, including }?: ForOpts): RetArray;
|
|
10
|
+
}>, RetArray = (keyof ReturnPartialType)[]>(dreamClass: T, { only }?: ForOpts): RetArray;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CalendarDate, DateTime, Dream } from '@rvoh/dream';
|
|
2
2
|
import { OpenapiSchemaArray, OpenapiSchemaBody, OpenapiSchemaInteger, OpenapiSchemaNumber, OpenapiSchemaObjectBase, OpenapiSchemaPrimitiveGeneric, OpenapiSchemaPropertiesShorthand, OpenapiSchemaString } from '@rvoh/dream/openapi';
|
|
3
|
-
import {
|
|
3
|
+
import { DreamParamSafeAttributes, DreamParamSafeColumnNames } from '@rvoh/dream/types';
|
|
4
4
|
import { PsychicParamsDictionary, PsychicParamsPrimitive, PsychicParamsPrimitiveLiteral } from '../controller/index.js';
|
|
5
5
|
import { Inc } from '../i18n/conf/types.js';
|
|
6
6
|
export default class Params {
|
|
@@ -19,13 +19,11 @@ export default class Params {
|
|
|
19
19
|
* const params = Params.for(this.params.user, User)
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
static for<T extends typeof Dream, I extends InstanceType<T>, const OnlyArray extends readonly (keyof DreamParamSafeAttributes<I>)[],
|
|
22
|
+
static for<T extends typeof Dream, I extends InstanceType<T>, const OnlyArray extends readonly (keyof DreamParamSafeAttributes<I>)[], ForOpts extends ParamsForOpts<OnlyArray>, ParamSafeColumnsOverride extends I['paramSafeColumns' & keyof I] extends never ? undefined : I['paramSafeColumns' & keyof I] & string[], ParamSafeColumns extends ParamSafeColumnsOverride extends string[] | Readonly<string[]> ? Extract<DreamParamSafeColumnNames<I>, ParamSafeColumnsOverride[number] & DreamParamSafeColumnNames<I>>[] : DreamParamSafeColumnNames<I>[], ParamSafeAttrs extends DreamParamSafeAttributes<InstanceType<T>>, ReturnPartialType extends ForOpts['only'] extends readonly (keyof DreamParamSafeAttributes<InstanceType<T>>)[] ? Partial<{
|
|
23
23
|
[K in ForOpts['only'][number] & keyof ParamSafeAttrs]: ParamSafeAttrs[K & keyof ParamSafeAttrs];
|
|
24
24
|
}> : Partial<{
|
|
25
25
|
[K in ParamSafeColumns[number & keyof ParamSafeColumns] & string & keyof ParamSafeAttrs]: ParamSafeAttrs[K & keyof ParamSafeAttrs];
|
|
26
|
-
}>,
|
|
27
|
-
[K in Extract<keyof UpdateableProperties<InstanceType<T>>, ForOpts['including'][number & keyof ForOpts['including']]>]: UpdateableProperties<InstanceType<T>>[K];
|
|
28
|
-
}> : ReturnPartialType, ReturnPayload extends ForOpts['array'] extends true ? ReturnPartialTypeWithIncluding[] : ReturnPartialTypeWithIncluding>(params: object, dreamClass: T, forOpts?: ForOpts): ReturnPayload;
|
|
26
|
+
}>, ReturnPayload extends ForOpts['array'] extends true ? ReturnPartialType[] : ReturnPartialType>(params: object, dreamClass: T, forOpts?: ForOpts): ReturnPayload;
|
|
29
27
|
static restrict<T extends typeof Params>(this: T, params: PsychicParamsPrimitive | PsychicParamsDictionary | PsychicParamsDictionary[], allowed: string[]): PsychicParamsDictionary;
|
|
30
28
|
/**
|
|
31
29
|
* ### .cast
|
|
@@ -97,12 +95,12 @@ export type ParamsCastOptions<EnumType> = {
|
|
|
97
95
|
match?: RegExp;
|
|
98
96
|
enum?: EnumType;
|
|
99
97
|
};
|
|
100
|
-
export interface ParamsForOpts<OnlyArray
|
|
98
|
+
export interface ParamsForOpts<OnlyArray> {
|
|
101
99
|
array?: boolean;
|
|
102
|
-
}
|
|
103
|
-
export interface ParamExclusionOptions<OnlyArray, IncludingArray> {
|
|
104
100
|
only?: OnlyArray;
|
|
105
|
-
|
|
101
|
+
}
|
|
102
|
+
export interface OpenAPIDreamModelRequestBodyModifications<OnlyArray, IncludingArray> extends ParamsForOpts<OnlyArray> {
|
|
106
103
|
combining?: OpenapiSchemaPropertiesShorthand;
|
|
104
|
+
including?: IncludingArray;
|
|
107
105
|
}
|
|
108
106
|
export {};
|