Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: action type #5034

Merged
merged 5 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions packages/docs/src/routes/api/qwik-city/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,6 @@
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts",
"mdFile": "qwik-city.actionconstructor.md"
},
{
"name": "ActionOptions",
"id": "actionoptions",
"hierarchy": [
{
"name": "ActionOptions",
"id": "actionoptions"
}
],
"kind": "Interface",
"content": "```typescript\nexport interface ActionOptions \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [id?](#) | <code>readonly</code> | string | _(Optional)_ |\n| [validation?](#) | <code>readonly</code> | DataValidator\\[\\] | _(Optional)_ |",
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts",
"mdFile": "qwik-city.actionoptions.md"
},
{
"name": "ActionOptionsWithValidation",
"id": "actionoptionswithvalidation",
"hierarchy": [
{
"name": "ActionOptionsWithValidation",
"id": "actionoptionswithvalidation"
}
],
"kind": "Interface",
"content": "```typescript\nexport interface ActionOptionsWithValidation<B extends TypedDataValidator = TypedDataValidator> \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [id?](#) | <code>readonly</code> | string | _(Optional)_ |\n| [validation](#) | <code>readonly</code> | \\[val: B, ...a: DataValidator\\[\\]\\] | |",
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts",
"mdFile": "qwik-city.actionoptionswithvalidation.md"
},
{
"name": "ActionStore",
"id": "actionstore",
Expand Down
26 changes: 0 additions & 26 deletions packages/docs/src/routes/api/qwik-city/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,6 @@ export interface ActionConstructor

[Edit this section](https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts)

## ActionOptions

```typescript
export interface ActionOptions
```

| Property | Modifiers | Type | Description |
| ---------------- | --------------------- | --------------- | ------------ |
| [id?](#) | <code>readonly</code> | string | _(Optional)_ |
| [validation?](#) | <code>readonly</code> | DataValidator[] | _(Optional)_ |

[Edit this section](https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts)

## ActionOptionsWithValidation

```typescript
export interface ActionOptionsWithValidation<B extends TypedDataValidator = TypedDataValidator>
```

| Property | Modifiers | Type | Description |
| --------------- | --------------------- | ------------------------------- | ------------ |
| [id?](#) | <code>readonly</code> | string | _(Optional)_ |
| [validation](#) | <code>readonly</code> | [val: B, ...a: DataValidator[]] | |

[Edit this section](https://github.com/BuilderIO/qwik/tree/main/packages/qwik-city/runtime/src/types.ts)

## ActionStore

```typescript
Expand Down
38 changes: 19 additions & 19 deletions packages/qwik-city/runtime/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,36 @@ export interface Action<RETURN, INPUT = Record<string, any>, OPTIONAL extends bo
// @public (undocumented)
export interface ActionConstructor {
// Warning: (ae-forgotten-export) The symbol "TypedDataValidator" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DataValidator" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "GetValidatorType" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "StrictUnion" needs to be exported by the entry point index.d.ts
//
// (undocumented)
<O extends Record<string, any> | void | null, B extends TypedDataValidator>(actionQrl: (data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>, options: B | ActionOptionsWithValidation<B>): Action<StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>>>, GetValidatorType<B>, false>;
// Warning: (ae-forgotten-export) The symbol "DataValidator" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "FailOfRest" needs to be exported by the entry point index.d.ts
//
// (undocumented)
<O extends Record<string, any> | void | null, B extends TypedDataValidator, REST extends DataValidator[]>(actionQrl: (data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>, options: B, ...rest: REST): Action<StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>> | FailOfRest<REST>>, GetValidatorType<B>, false>;
<O extends Record<string, any> | void | null, B extends TypedDataValidator, REST extends [DataValidator, ...DataValidator[]]>(actionQrl: (data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>, options: {
readonly id?: string;
readonly validation: [B, ...REST];
}): Action<StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>> | FailOfRest<REST>>, GetValidatorType<B>, false>;
// (undocumented)
<O>(actionQrl: (form: JSONObject, event: RequestEventAction, options: ActionOptions) => ValueOrPromise<O>, options?: ActionOptions): Action<StrictUnion<O>>;
<O extends Record<string, any> | void | null, B extends TypedDataValidator>(actionQrl: (data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>, options: {
readonly id?: string;
readonly validation: [B];
}): Action<StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>>>, GetValidatorType<B>, false>;
// (undocumented)
<O extends Record<string, any> | void | null, REST extends DataValidator[]>(actionQrl: (form: JSONObject, event: RequestEventAction) => ValueOrPromise<O>, ...rest: REST): Action<StrictUnion<O | FailReturn<FailOfRest<REST>>>>;
}

// @public (undocumented)
export interface ActionOptions {
<O extends Record<string, any> | void | null, REST extends [DataValidator, ...DataValidator[]]>(actionQrl: (data: JSONObject, event: RequestEventAction) => ValueOrPromise<O>, options: {
readonly id?: string;
readonly validation: REST;
}): Action<StrictUnion<O | FailReturn<FailOfRest<REST>>>>;
// (undocumented)
readonly id?: string;
<O extends Record<string, any> | void | null, B extends TypedDataValidator, REST extends [DataValidator, ...DataValidator[]]>(actionQrl: (data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>, options: B, ...rest: REST): Action<StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>> | FailOfRest<REST>>, GetValidatorType<B>, false>;
// (undocumented)
readonly validation?: DataValidator[];
}

// @public (undocumented)
export interface ActionOptionsWithValidation<B extends TypedDataValidator = TypedDataValidator> {
<O extends Record<string, any> | void | null, B extends TypedDataValidator>(actionQrl: (data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>, options: B): Action<StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>>>, GetValidatorType<B>, false>;
// (undocumented)
readonly id?: string;
<O extends Record<string, any> | void | null, REST extends [DataValidator, ...DataValidator[]]>(actionQrl: (form: JSONObject, event: RequestEventAction) => ValueOrPromise<O>, ...rest: REST): Action<StrictUnion<O | FailReturn<FailOfRest<REST>>>>;
// (undocumented)
readonly validation: [val: B, ...a: DataValidator[]];
<O>(actionQrl: (form: JSONObject, event: RequestEventAction) => ValueOrPromise<O>, options?: {
readonly id?: string;
}): Action<StrictUnion<O>>;
}

// @public (undocumented)
Expand Down
2 changes: 0 additions & 2 deletions packages/qwik-city/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export type {
ActionStore,
LoaderSignal,
ActionConstructor,
ActionOptions,
ActionOptionsWithValidation,
FailReturn,
ZodConstructor,
StaticGenerate,
Expand Down
148 changes: 104 additions & 44 deletions packages/qwik-city/runtime/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,22 +402,6 @@ export type GetValidatorType<B extends TypedDataValidator> = B extends TypedData
? zod.infer<TYPE>
: never;

/**
* @public
*/
export interface ActionOptions {
readonly id?: string;
readonly validation?: DataValidator[];
}

/**
* @public
*/
export interface ActionOptionsWithValidation<B extends TypedDataValidator = TypedDataValidator> {
readonly id?: string;
readonly validation: [val: B, ...a: DataValidator[]];
}

/**
* @public
*/
Expand All @@ -436,21 +420,50 @@ export type FailOfRest<REST extends readonly DataValidator[]> = REST extends rea
* @public
*/
export interface ActionConstructor {
// With validation
// Use options object, use typed data validator, use data validator
<
O extends Record<string, any> | void | null,
B extends TypedDataValidator,
REST extends [DataValidator, ...DataValidator[]],
>(
actionQrl: (data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>,
options: {
readonly id?: string;
readonly validation: [B, ...REST];
}
): Action<
StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>> | FailOfRest<REST>>,
GetValidatorType<B>,
false
>;

// Use options object, use typed data validator
<O extends Record<string, any> | void | null, B extends TypedDataValidator>(
actionQrl: (data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>,
options: B | ActionOptionsWithValidation<B>
options: {
readonly id?: string;
readonly validation: [B];
}
): Action<
StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>>>,
GetValidatorType<B>,
false
>;

// With multiple validators
// Use options object, use data validator
<O extends Record<string, any> | void | null, REST extends [DataValidator, ...DataValidator[]]>(
actionQrl: (data: JSONObject, event: RequestEventAction) => ValueOrPromise<O>,
options: {
readonly id?: string;
readonly validation: REST;
}
): Action<StrictUnion<O | FailReturn<FailOfRest<REST>>>>;

// Use typed data validator, use data validator
<
O extends Record<string, any> | void | null,
B extends TypedDataValidator,
REST extends DataValidator[],
REST extends [DataValidator, ...DataValidator[]],
>(
actionQrl: (data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>,
options: B,
Expand All @@ -461,42 +474,79 @@ export interface ActionConstructor {
false
>;

// Without validation
<O>(
actionQrl: (
form: JSONObject,
event: RequestEventAction,
options: ActionOptions
) => ValueOrPromise<O>,
options?: ActionOptions
): Action<StrictUnion<O>>;
// Use typed data validator
<O extends Record<string, any> | void | null, B extends TypedDataValidator>(
actionQrl: (data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>,
options: B
): Action<
StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>>>,
GetValidatorType<B>,
false
>;

// Without validation
<O extends Record<string, any> | void | null, REST extends DataValidator[]>(
// Use data validator
<O extends Record<string, any> | void | null, REST extends [DataValidator, ...DataValidator[]]>(
actionQrl: (form: JSONObject, event: RequestEventAction) => ValueOrPromise<O>,
...rest: REST
): Action<StrictUnion<O | FailReturn<FailOfRest<REST>>>>;

// No validators
<O>(
actionQrl: (form: JSONObject, event: RequestEventAction) => ValueOrPromise<O>,
options?: {
readonly id?: string;
}
): Action<StrictUnion<O>>;
}

/**
* @public
*/
export interface ActionConstructorQRL {
// With validation
// Use options object, use typed data validator, use data validator
<
O extends Record<string, any> | void | null,
B extends TypedDataValidator,
REST extends [DataValidator, ...DataValidator[]],
>(
actionQrl: QRL<(data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>>,
options: {
readonly id?: string;
readonly validation: [B, ...REST];
}
): Action<
StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>> | FailOfRest<REST>>,
GetValidatorType<B>,
false
>;

// Use options object, use typed data validator
<O extends Record<string, any> | void | null, B extends TypedDataValidator>(
actionQrl: QRL<(data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>>,
options: B | ActionOptionsWithValidation<B>
options: {
readonly id?: string;
readonly validation: [B];
}
): Action<
StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>>>,
GetValidatorType<B>,
false
>;

// With multiple validators
// Use options object, use data validator
<O extends Record<string, any> | void | null, REST extends [DataValidator, ...DataValidator[]]>(
actionQrl: QRL<(data: JSONObject, event: RequestEventAction) => ValueOrPromise<O>>,
options: {
readonly id?: string;
readonly validation: REST;
}
): Action<StrictUnion<O | FailReturn<FailOfRest<REST>>>>;

// Use typed data validator, use data validator
<
O extends Record<string, any> | void | null,
B extends TypedDataValidator,
REST extends DataValidator[],
REST extends [DataValidator, ...DataValidator[]],
>(
actionQrl: QRL<(data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>>,
options: B,
Expand All @@ -507,19 +557,29 @@ export interface ActionConstructorQRL {
false
>;

// Without validation
<O>(
actionQrl: QRL<
(form: JSONObject, event: RequestEventAction, options: ActionOptions) => ValueOrPromise<O>
>,
options?: ActionOptions
): Action<O>;
// Use typed data validator
<O extends Record<string, any> | void | null, B extends TypedDataValidator>(
actionQrl: QRL<(data: GetValidatorType<B>, event: RequestEventAction) => ValueOrPromise<O>>,
options: B
): Action<
StrictUnion<O | FailReturn<zod.typeToFlattenedError<GetValidatorType<B>>>>,
GetValidatorType<B>,
false
>;

// Without validation
<O extends Record<string, any> | void | null, REST extends DataValidator[]>(
// Use data validator
<O extends Record<string, any> | void | null, REST extends [DataValidator, ...DataValidator[]]>(
actionQrl: QRL<(form: JSONObject, event: RequestEventAction) => ValueOrPromise<O>>,
...rest: REST
): Action<StrictUnion<O | FailReturn<FailOfRest<REST>>>>;

// No validators
<O>(
actionQrl: QRL<(form: JSONObject, event: RequestEventAction) => ValueOrPromise<O>>,
options?: {
readonly id?: string;
}
): Action<StrictUnion<O>>;
}

/**
Expand Down
Loading
Loading