@rvoh/psychic 0.37.6 → 0.37.8
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/server/helpers/paramNamesForDreamClass.js +7 -2
- package/dist/esm/src/server/helpers/paramNamesForDreamClass.js +7 -2
- package/dist/types/src/controller/index.d.ts +10 -6
- package/dist/types/src/openapi-renderer/endpoint.d.ts +3 -3
- package/dist/types/src/server/helpers/paramNamesForDreamClass.d.ts +9 -7
- package/dist/types/src/server/params.d.ts +8 -15
- package/package.json +5 -3
|
@@ -8,8 +8,13 @@ function paramNamesForDreamClass(dreamClass, { only, including } = {}) {
|
|
|
8
8
|
if (Array.isArray(including)) {
|
|
9
9
|
paramSafeColumns = [
|
|
10
10
|
...paramSafeColumns,
|
|
11
|
-
//
|
|
12
|
-
|
|
11
|
+
// TODO: add a method to dream which can extrapolate
|
|
12
|
+
// all of these fields from the model
|
|
13
|
+
...[
|
|
14
|
+
...dreamClass.columns(),
|
|
15
|
+
...dreamClass['virtualAttributes'].map(statement => statement.property),
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
17
|
+
].filter(columnName => including.includes(columnName)),
|
|
13
18
|
];
|
|
14
19
|
}
|
|
15
20
|
return paramSafeColumns;
|
|
@@ -5,8 +5,13 @@ export default function paramNamesForDreamClass(dreamClass, { only, including }
|
|
|
5
5
|
if (Array.isArray(including)) {
|
|
6
6
|
paramSafeColumns = [
|
|
7
7
|
...paramSafeColumns,
|
|
8
|
-
//
|
|
9
|
-
|
|
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)),
|
|
10
15
|
];
|
|
11
16
|
}
|
|
12
17
|
return paramSafeColumns;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Dream,
|
|
1
|
+
import { Dream, DreamModelSerializerType, DreamParamSafeAttributes, SerializerRendererOpts, SimpleObjectSerializerType, UpdateableProperties, DreamParamSafeColumnNames } from '@rvoh/dream';
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
3
|
import { ControllerHook } from '../controller/hooks.js';
|
|
4
4
|
import { HttpStatusCodeInt, HttpStatusSymbol } from '../error/http/status-codes.js';
|
|
5
5
|
import OpenapiEndpointRenderer from '../openapi-renderer/endpoint.js';
|
|
6
6
|
import PsychicApp from '../psychic-app/index.js';
|
|
7
|
-
import { ParamsCastOptions,
|
|
7
|
+
import { ParamsCastOptions, ParamsForOpts, ValidatedAllowsNull, ValidatedReturnType } from '../server/params.js';
|
|
8
8
|
import Session, { CustomSessionCookieOptions } from '../session/index.js';
|
|
9
9
|
type SerializerResult = {
|
|
10
10
|
[key: string]: any;
|
|
@@ -129,11 +129,15 @@ export default class PsychicController {
|
|
|
129
129
|
param<ReturnType = string>(key: string): ReturnType;
|
|
130
130
|
castParam<const EnumType extends readonly string[], OptsType extends ParamsCastOptions<EnumType>, ExpectedType extends (typeof PsychicParamsPrimitiveLiterals)[number] | RegExp>(key: string, expectedType: ExpectedType, opts?: OptsType): ValidatedAllowsNull<ExpectedType, OptsType> extends infer T ? T extends ValidatedAllowsNull<ExpectedType, OptsType> ? T extends true ? ValidatedReturnType<ExpectedType, OptsType> | null | undefined : ValidatedReturnType<ExpectedType, OptsType> : never : never;
|
|
131
131
|
private _castParam;
|
|
132
|
-
paramsFor<T extends typeof Dream, I extends InstanceType<T>, const OnlyArray extends readonly (keyof DreamParamSafeAttributes<I>)[], const IncludingArray extends Exclude<keyof
|
|
132
|
+
paramsFor<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 ParamsForOpts<OnlyArray, IncludingArray> & {
|
|
133
133
|
key?: string;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
}>
|
|
134
|
+
}, 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<{
|
|
135
|
+
[K in ForOpts['only'][number] & keyof ParamSafeAttrs]: ParamSafeAttrs[K & keyof ParamSafeAttrs];
|
|
136
|
+
}> : Partial<{
|
|
137
|
+
[K in ParamSafeColumns[number & keyof ParamSafeColumns] & string]: DreamParamSafeAttributes<InstanceType<T>>[K & keyof DreamParamSafeAttributes<InstanceType<T>>];
|
|
138
|
+
}>, ReturnPartialTypeWithIncluding extends ForOpts['including'] extends readonly (keyof UpdateableProperties<InstanceType<T>>)[] ? ReturnPartialType & Partial<{
|
|
139
|
+
[K in Extract<keyof UpdateableProperties<InstanceType<T>>, ForOpts['including'][number & keyof ForOpts['including']]>]: UpdateableProperties<InstanceType<T>>[K];
|
|
140
|
+
}> : ReturnPartialType, ReturnPayload extends ForOpts['array'] extends true ? ReturnPartialTypeWithIncluding[] : ReturnPartialTypeWithIncluding>(this: PsychicController, dreamClass: T, opts?: ForOpts): ReturnPayload;
|
|
137
141
|
getCookie<RetType>(name: string): RetType | null;
|
|
138
142
|
setCookie(name: string, data: string, opts?: CustomSessionCookieOptions): void;
|
|
139
143
|
startSession(user: Dream): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Dream, DreamAttributes, DreamOrViewModelClassSerializerKey, DreamParamSafeAttributes, DreamSerializable, DreamSerializableArray, OpenapiAllTypes, OpenapiFormats, OpenapiSchemaArray, OpenapiSchemaBody, OpenapiSchemaBodyShorthand, OpenapiSchemaExpressionAllOf, OpenapiSchemaExpressionAnyOf, OpenapiSchemaExpressionOneOf, OpenapiSchemaExpressionRef, OpenapiSchemaObject, OpenapiSchemaProperties, SerializerCasing, ViewModelClass } from '@rvoh/dream';
|
|
1
|
+
import { Dream, DreamAttributes, DreamOrViewModelClassSerializerKey, DreamParamSafeAttributes, DreamSerializable, DreamSerializableArray, OpenapiAllTypes, OpenapiFormats, OpenapiSchemaArray, OpenapiSchemaBody, OpenapiSchemaBodyShorthand, OpenapiSchemaExpressionAllOf, OpenapiSchemaExpressionAnyOf, OpenapiSchemaExpressionOneOf, OpenapiSchemaExpressionRef, OpenapiSchemaObject, OpenapiSchemaProperties, SerializerCasing, UpdateableProperties, ViewModelClass } from '@rvoh/dream';
|
|
2
2
|
import PsychicController from '../controller/index.js';
|
|
3
3
|
import { HttpStatusCode, HttpStatusCodeNumber } from '../error/http/status-codes.js';
|
|
4
4
|
import { DreamOrViewModelClassSerializerArrayKeys } from '../helpers/typeHelpers.js';
|
|
@@ -608,7 +608,7 @@ export interface OpenapiSchemaRequestBodyForDreamClass<ForOption extends typeof
|
|
|
608
608
|
* }
|
|
609
609
|
* ```
|
|
610
610
|
*/
|
|
611
|
-
including?: Exclude<keyof
|
|
611
|
+
including?: Exclude<keyof UpdateableProperties<InstanceType<ForOption>>, keyof DreamParamSafeAttributes<InstanceType<ForOption>>>[];
|
|
612
612
|
/**
|
|
613
613
|
* Specify which fields are required for your openapi
|
|
614
614
|
* request body.
|
|
@@ -633,7 +633,7 @@ export interface OpenapiSchemaRequestBodyForDreamClass<ForOption extends typeof
|
|
|
633
633
|
* }
|
|
634
634
|
* ```
|
|
635
635
|
*/
|
|
636
|
-
required?: (keyof
|
|
636
|
+
required?: (keyof UpdateableProperties<InstanceType<ForOption>>)[];
|
|
637
637
|
}
|
|
638
638
|
export interface OpenapiSchemaRequestBodyForBaseDreamClass<Serializable extends DreamSerializable | DreamSerializableArray | undefined, T extends Serializable extends typeof Dream ? Serializable : undefined = Serializable extends typeof Dream ? Serializable : undefined, I extends T extends typeof Dream ? InstanceType<T> : undefined = T extends typeof Dream ? InstanceType<T> : undefined, Only extends I extends Dream ? readonly (keyof DreamParamSafeAttributes<I>)[] : string[] = I extends Dream ? readonly (keyof DreamParamSafeAttributes<I>)[] : string[], Including extends I extends Dream ? Exclude<keyof DreamAttributes<I>, keyof DreamParamSafeAttributes<I>>[] : string[] = I extends Dream ? Exclude<keyof DreamAttributes<I>, keyof DreamParamSafeAttributes<I>>[] : string[], RequiredFields extends I extends Dream ? readonly (keyof DreamAttributes<I>)[] : string[] = I extends Dream ? readonly (keyof DreamAttributes<I>)[] : string[]> {
|
|
639
639
|
for?: never;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { Dream,
|
|
2
|
-
import {
|
|
3
|
-
export default function paramNamesForDreamClass<T extends typeof Dream, I extends InstanceType<T>, const OnlyArray extends readonly (keyof DreamParamSafeAttributes<I>)[], const IncludingArray extends Exclude<keyof
|
|
4
|
-
|
|
1
|
+
import { Dream, DreamParamSafeAttributes, DreamParamSafeColumnNames, UpdateableProperties } from '@rvoh/dream';
|
|
2
|
+
import { ParamsForOpts } from '../params.js';
|
|
3
|
+
export default function paramNamesForDreamClass<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 ParamsForOpts<OnlyArray, IncludingArray> & {
|
|
4
|
+
key?: string;
|
|
5
|
+
}, 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<{
|
|
6
|
+
[K in ForOpts['only'][number] & keyof ParamSafeAttrs]: ParamSafeAttrs[K & keyof ParamSafeAttrs];
|
|
5
7
|
}> : Partial<{
|
|
6
8
|
[K in ParamSafeColumns[number & keyof ParamSafeColumns] & string]: DreamParamSafeAttributes<InstanceType<T>>[K & keyof DreamParamSafeAttributes<InstanceType<T>>];
|
|
7
|
-
}>,
|
|
8
|
-
[K in Extract<keyof
|
|
9
|
-
}> :
|
|
9
|
+
}>, ReturnPartialTypeWithIncluding extends ForOpts['including'] extends readonly (keyof UpdateableProperties<InstanceType<T>>)[] ? ReturnPartialType & Partial<{
|
|
10
|
+
[K in Extract<keyof UpdateableProperties<InstanceType<T>>, ForOpts['including'][number & keyof ForOpts['including']]>]: UpdateableProperties<InstanceType<T>>[K];
|
|
11
|
+
}> : ReturnPartialType, RetArray = (keyof ReturnPartialTypeWithIncluding)[]>(dreamClass: T, { only, including }?: ForOpts): RetArray;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CalendarDate, DateTime, Dream, DreamAttributes, DreamParamSafeAttributes, DreamParamSafeColumnNames } from '@rvoh/dream';
|
|
1
|
+
import { CalendarDate, DateTime, Dream, DreamAttributes, DreamParamSafeAttributes, DreamParamSafeColumnNames, UpdateableProperties } from '@rvoh/dream';
|
|
2
2
|
import { PsychicParamsDictionary, PsychicParamsPrimitive, PsychicParamsPrimitiveLiterals } from '../controller/index.js';
|
|
3
3
|
export default class Params {
|
|
4
4
|
private $params;
|
|
@@ -16,7 +16,13 @@ export default class Params {
|
|
|
16
16
|
* const params = Params.for(this.params.user, User)
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
static for<T extends typeof Dream, I extends InstanceType<T>, const OnlyArray extends readonly (keyof DreamParamSafeAttributes<I>)[], const IncludingArray extends Exclude<keyof DreamAttributes<I>, OnlyArray[number]>[], ForOpts extends ParamsForOpts<OnlyArray, IncludingArray>,
|
|
19
|
+
static for<T extends typeof Dream, I extends InstanceType<T>, const OnlyArray extends readonly (keyof DreamParamSafeAttributes<I>)[], const IncludingArray extends Exclude<keyof DreamAttributes<I>, OnlyArray[number]>[], ForOpts extends ParamsForOpts<OnlyArray, IncludingArray>, 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<{
|
|
20
|
+
[K in ForOpts['only'][number] & keyof ParamSafeAttrs]: ParamSafeAttrs[K & keyof ParamSafeAttrs];
|
|
21
|
+
}> : Partial<{
|
|
22
|
+
[K in ParamSafeColumns[number & keyof ParamSafeColumns] & string & keyof ParamSafeAttrs]: ParamSafeAttrs[K & keyof ParamSafeAttrs];
|
|
23
|
+
}>, ReturnPartialTypeWithIncluding extends ForOpts['including'] extends readonly (keyof UpdateableProperties<InstanceType<T>>)[] ? ReturnPartialType & Partial<{
|
|
24
|
+
[K in Extract<keyof UpdateableProperties<InstanceType<T>>, ForOpts['including'][number & keyof ForOpts['including']]>]: UpdateableProperties<InstanceType<T>>[K];
|
|
25
|
+
}> : ReturnPartialType, ReturnPayload extends ForOpts['array'] extends true ? ReturnPartialTypeWithIncluding[] : ReturnPartialTypeWithIncluding>(params: object, dreamClass: T, forOpts?: ForOpts): ReturnPayload;
|
|
20
26
|
static restrict<T extends typeof Params>(this: T, params: PsychicParamsPrimitive | PsychicParamsDictionary | PsychicParamsDictionary[], allowed: string[]): PsychicParamsDictionary;
|
|
21
27
|
/**
|
|
22
28
|
* ### .cast
|
|
@@ -74,16 +80,3 @@ export interface ParamExclusionOptions<OnlyArray, IncludingArray> {
|
|
|
74
80
|
only?: OnlyArray;
|
|
75
81
|
including?: IncludingArray;
|
|
76
82
|
}
|
|
77
|
-
export type ParamsForDreamClass<T extends typeof Dream, OnlyArray extends readonly (keyof DreamParamSafeAttributes<I>)[], IncludingArray extends Exclude<keyof DreamAttributes<I>, OnlyArray[number]>[], I extends InstanceType<T> = InstanceType<T>, ForOpts extends ParamsForOpts<OnlyArray, IncludingArray> = ParamsForOpts<OnlyArray, IncludingArray>, ParamSafeColumnsOverride extends I['paramSafeColumns' & keyof I] extends never ? undefined : I['paramSafeColumns' & keyof I] & string[] = 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>[] = ParamSafeColumnsOverride extends string[] | Readonly<string[]> ? Extract<DreamParamSafeColumnNames<I>, ParamSafeColumnsOverride[number] & DreamParamSafeColumnNames<I>>[] : DreamParamSafeColumnNames<I>[], ReturnPartialType extends ForOpts['only'] extends readonly (keyof DreamParamSafeAttributes<InstanceType<T>>)[] ? Partial<{
|
|
78
|
-
[K in Extract<ParamSafeColumns[number], ForOpts['only'][number & keyof ForOpts['only']]>]: DreamParamSafeAttributes<InstanceType<T>>[K];
|
|
79
|
-
}> : Partial<{
|
|
80
|
-
[K in ParamSafeColumns[number & keyof ParamSafeColumns] & string]: DreamParamSafeAttributes<InstanceType<T>>[K & keyof DreamParamSafeAttributes<InstanceType<T>>];
|
|
81
|
-
}> = ForOpts['only'] extends readonly (keyof DreamParamSafeAttributes<InstanceType<T>>)[] ? Partial<{
|
|
82
|
-
[K in Extract<ParamSafeColumns[number], ForOpts['only'][number & keyof ForOpts['only']]>]: DreamParamSafeAttributes<InstanceType<T>>[K];
|
|
83
|
-
}> : Partial<{
|
|
84
|
-
[K in ParamSafeColumns[number & keyof ParamSafeColumns] & string]: DreamParamSafeAttributes<InstanceType<T>>[K & keyof DreamParamSafeAttributes<InstanceType<T>>];
|
|
85
|
-
}>, ReturnPartialTypeWithIncluding extends ForOpts['including'] extends readonly (keyof DreamAttributes<InstanceType<T>>)[] ? ReturnPartialType & Partial<{
|
|
86
|
-
[K in Extract<keyof DreamAttributes<InstanceType<T>>, ForOpts['including'][number & keyof ForOpts['including']]>]: DreamAttributes<InstanceType<T>>[K];
|
|
87
|
-
}> : ReturnPartialType = ForOpts['including'] extends readonly (keyof DreamAttributes<InstanceType<T>>)[] ? ReturnPartialType & Partial<{
|
|
88
|
-
[K in Extract<keyof DreamAttributes<InstanceType<T>>, ForOpts['including'][number & keyof ForOpts['including']]>]: DreamAttributes<InstanceType<T>>[K];
|
|
89
|
-
}> : ReturnPartialType, ReturnPayload extends ForOpts['array'] extends true ? ReturnPartialTypeWithIncluding[] : ReturnPartialTypeWithIncluding = ForOpts['array'] extends true ? ReturnPartialTypeWithIncluding[] : ReturnPartialTypeWithIncluding> = ReturnPayload;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@rvoh/psychic",
|
|
4
4
|
"description": "Typescript web framework",
|
|
5
|
-
"version": "0.37.
|
|
5
|
+
"version": "0.37.8",
|
|
6
6
|
"author": "RVOHealth",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"gpsy": "tsx ./global-cli/main.ts",
|
|
32
32
|
"build": "echo \"building cjs...\" && rm -rf dist && npx tsc -p ./tsconfig.cjs.build.json && echo \"building esm...\" && npx tsc -p ./tsconfig.esm.build.json",
|
|
33
33
|
"build:test-app": "rm -rf dist && echo \"building test app to esm...\" && npx tsc -p ./tsconfig.esm.build.test-app.json && echo \"building test app to cjs...\" && npx tsc -p ./tsconfig.cjs.build.test-app.json",
|
|
34
|
+
"types:esm:trace": "rm -rf dist && npx tsc -p ./tsconfig.esm.build.json --generateTrace ./typetrace --diagnostics && yarn analyze-trace ./typetrace --skipMillis 100 --forceMillis 300",
|
|
34
35
|
"dev": "NODE_ENV=development tsx ./test-app/main.ts",
|
|
35
36
|
"console": "tsx ./test-app/src/conf/repl.ts",
|
|
36
37
|
"uspec": "vitest --config ./spec/unit/vite.config.ts",
|
|
@@ -58,13 +59,14 @@
|
|
|
58
59
|
"devDependencies": {
|
|
59
60
|
"@eslint/js": "^9.19.0",
|
|
60
61
|
"@jest-mock/express": "^3.0.0",
|
|
61
|
-
"@rvoh/dream": "^0.
|
|
62
|
+
"@rvoh/dream": "^0.44.5",
|
|
62
63
|
"@rvoh/dream-spec-helpers": "^0.2.4",
|
|
63
64
|
"@rvoh/psychic-spec-helpers": "^0.6.0",
|
|
64
65
|
"@types/express": "^5.0.1",
|
|
65
66
|
"@types/node": "^22.5.1",
|
|
66
67
|
"@types/pg": "^8.11.8",
|
|
67
68
|
"@types/supertest": "^6.0.3",
|
|
69
|
+
"@typescript/analyze-trace": "^0.10.1",
|
|
68
70
|
"eslint": "^9.19.0",
|
|
69
71
|
"express": "^5.1.0",
|
|
70
72
|
"jsdom": "^26.0.0",
|
|
@@ -85,4 +87,4 @@
|
|
|
85
87
|
"winston": "^3.14.2"
|
|
86
88
|
},
|
|
87
89
|
"packageManager": "yarn@4.7.0"
|
|
88
|
-
}
|
|
90
|
+
}
|