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

ci: update next release workflow #391

Merged
merged 12 commits into from
Jun 22, 2024
Merged
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"access": "public",
"baseBranch": "next",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": ["@alova/client", "@alova/server"]
}
4 changes: 2 additions & 2 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"@alova/mock": "2.0.0",
"@alova/adapter-taro": "2.0.0",
"@alova/adapter-uniapp": "2.0.0",
"@alova/adapter-xhr": "1.0.1",
"@alova/adapter-xhr": "2.0.0",
"alova": "3.0.0",
"@alova/client": "2.0.0",
"@alova/psc": "1.0.0",
"@alova/server": "2.0.0",
"@alova/shared": "0.0.1",
"@alova/shared": "1.0.0",
"@alova/vue-options": "2.0.0",
"@alova/scripts": "1.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
- name: Setup PNPM
uses: pnpm/action-setup@v3
with:
version: 8
version: 9

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ name: Release next
on:
push:
branches:
- alpha
- beta
- next

jobs:
quality:
Expand All @@ -18,14 +17,14 @@ jobs:
persist-credentials: false

- name: Setup PNPM
uses: pnpm/action-setup@v3
uses: pnpm/action-setup@v4
with:
version: 8
version: 9

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'

Expand All @@ -48,14 +47,14 @@ jobs:
persist-credentials: false

- name: Setup PNPM
uses: pnpm/action-setup@v3
uses: pnpm/action-setup@v4
with:
version: 8
version: 9

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'

Expand All @@ -75,7 +74,7 @@ jobs:
with:
# Note: pnpm install after versioning is necessary to refresh lockfile
version: pnpm run changeset:version
publish: pnpm run release
publish: pnpm exec changeset publish
commit: 'ci: release next'
title: 'ci: release next'
env:
Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const config: Config = {
'<rootDir>/packages/adapter-taro',
'<rootDir>/packages/shared',
'<rootDir>/packages/client',
'<rootDir>/packages/server',
'<rootDir>/packages/vue-options',
'<rootDir>/packages/psc'
]
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"changeset": "changeset",
"changeset:alpha": "changeset pre enter alpha",
"changeset:beta": "changeset pre enter beta",
"changeset:pre.exit": "changeset pre exit",
"changeset:version": "changeset version",
"release": "pnpm changeset publish"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-xhr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alova/adapter-xhr",
"version": "1.0.1",
"version": "2.0.0",
"description": "XMLHttpRequest adapter for alova.js",
"homepage": "https://alova.js.org",
"main": "dist/alova-adapter-xhr.esm.js",
Expand Down Expand Up @@ -47,7 +47,7 @@
"typings/*.d.ts"
],
"peerDependencies": {
"alova": "^2.19.2"
"alova": "^3.0.0"
},
"dependencies": {
"@alova/shared": "workspace:*"
Expand Down
2 changes: 1 addition & 1 deletion packages/alova/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"default": "./dist/alova.esm.js"
},
"./client": {
"types": "./typings/clienthook.d.ts",
"types": "./typings/clienthook/index.d.ts",
"require": "./dist/clienthook/index.common.cjs",
"default": "./dist/clienthook/index.esm.js"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/alova/test/server/createAlova.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('createAlova', () => {
requestAdapter: GlobalFetch()
});

const errorTips = '[alova]l2Cache is not defined.';
const errorTips = 'l2Cache is not defined.';
expect(() => {
alova.l2Cache.get('1');
}).toThrow(errorTips);
Expand Down
251 changes: 251 additions & 0 deletions packages/alova/typings/clienthook/general.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { FrameworkReadableState, FrameworkState } from '@alova/shared/FrameworkState';
import { EventManager } from '@alova/shared/createEventManager';
import { IsAny } from '@alova/shared/types';
import { AlovaGenerics, FetchRequestState, FrontRequestState, Method, Progress, ReferingObject } from 'alova';
import { Readable, Writable } from 'svelte/store';
import { ComputedRef, Ref } from 'vue';

/**
* alova base event
*/
export interface AlovaEvent<AG extends AlovaGenerics> {
/**
* params from send function
*/
sendArgs: any[];
/**
* current method instance
*/
method: Method<AG>;
}
/**
* success event object
*/
export interface AlovaSuccessEvent<AG extends AlovaGenerics> extends AlovaEvent<AG> {
/** data数据是否来自缓存 */
fromCache: boolean;
data: AG['Responded'];
}
/** 错误事件对象 */
export interface AlovaErrorEvent<AG extends AlovaGenerics> extends AlovaEvent<AG> {
error: any;
}
/** 完成事件对象 */
export interface AlovaCompleteEvent<AG extends AlovaGenerics> extends AlovaEvent<AG> {
/** 响应状态 */
status: 'success' | 'error';
/** data数据是否来自缓存,当status为error时,fromCache始终为false */
fromCache: boolean;
data?: AG['Responded'];
error?: any;
}

/**
* 以支持React和Vue的方式定义类型,后续需要其他类型再在这个基础上变化
* 使用不同库的特征作为父类进行判断
*/
export type ExportedState<Responded, State> =
IsAny<Ref, unknown, Ref> extends State
? Ref<Responded>
: IsAny<Writable<any>, unknown, Writable<any>> extends State
? Writable<Responded>
: Responded;
export type ExportedComputed<Responded, Computed> =
IsAny<ComputedRef, unknown, ComputedRef> extends Computed
? ComputedRef<Responded>
: IsAny<Readable<any>, unknown, Readable<any>> extends Computed
? Readable<Responded>
: Responded;

export type StateUpdater<ExportedStates extends Record<string, any>> = (newStates: {
[K in keyof ExportedStates]?: ExportedStates[K] extends ExportedState<infer R, any> | ExportedComputed<infer R, any>
? R
: never;
}) => void;

export type AlovaMethodHandler<AG extends AlovaGenerics = any> = (...args: any[]) => Method<AG>;
export type SuccessHandler<AG extends AlovaGenerics> = (event: AlovaSuccessEvent<AG>) => void;
export type ErrorHandler<AG extends AlovaGenerics> = (event: AlovaErrorEvent<AG>) => void;
export type CompleteHandler<AG extends AlovaGenerics> = (event: AlovaCompleteEvent<AG>) => void;

/** common hook configuration */
export interface UseHookConfig<AG extends AlovaGenerics> {
/**
* force request or not
* @default false
*/
force?: boolean | ((event: AlovaEvent<AG>) => boolean);

/**
* refering object that sharing some value with this object.
*/
__referingObj?: ReferingObject;

/**
* other attributes
*/
[attr: string]: any;
}

export interface AlovaMiddlewareContext<AG extends AlovaGenerics> {
/** 当前的method对象 */
method: Method<AG>;

/** 命中的缓存数据 */
cachedResponse: AG['Responded'] | undefined;

/** 当前的usehook配置对象 */
config: any;

/** 中断函数 */
abort: UseHookExposure['abort'];
}

/** 中间件next函数 */
export interface MiddlewareNextGuardConfig<AG extends AlovaGenerics> {
force?: UseHookConfig<AG>['force'];
method?: Method<AG>;
}

/**
* useRequest和useWatcher中间件的context参数
*/
export interface AlovaFrontMiddlewareContext<AG extends AlovaGenerics> extends AlovaMiddlewareContext<AG> {
/** 发送请求函数 */
send: SendHandler<AG['Responded']>;

/** args 响应处理回调的参数,该参数由use hooks的send传入 */
args: any[];

/** 前端状态集合 */
proxyStates: FrontRequestState<
FrameworkState<boolean, 'loading'>,
FrameworkState<AG['Responded'], 'data'>,
FrameworkState<Error | undefined, 'error'>,
FrameworkState<Progress, 'downloading'>,
FrameworkState<Progress, 'uploading'>
>;

/**
* 调用后将自定义控制loading的状态,内部不再触发loading状态的变更
* 传入control为false时将取消控制
*
* @param control 是否控制loading,默认为true
*/
controlLoading: (control?: boolean) => void;
}

/**
* alova useRequest/useWatcher中间件
*/
export interface AlovaFrontMiddleware<AG extends AlovaGenerics> {
(context: AlovaFrontMiddlewareContext<AG>, next: AlovaGuardNext<AG>): any;
}

/**
* useFetcher中间件的context参数
*/
export interface AlovaFetcherMiddlewareContext<AG extends AlovaGenerics> extends AlovaMiddlewareContext<AG> {
/** 数据预加载函数 */
fetch<Transformed>(method: Method<AG>, ...args: any[]): Promise<Transformed>;

/** args 响应处理回调的参数,该参数由useFetcher的fetch传入 */
args: any[];

/** fetch状态的代理集合 */
proxyStates: FetchRequestState<
FrameworkState<boolean, 'loading'>,
FrameworkState<Error | undefined, 'error'>,
FrameworkState<Progress, 'downloading'>,
FrameworkState<Progress, 'uploading'>
>;

/**
* 调用后将自定义控制fetching的状态,内部不再触发fetching状态的变更
* 传入control为false时将取消控制
*
* @param control 是否控制fetching,默认为true
*/
controlFetching: (control?: boolean) => void;
}

/**
* alova useRequest/useWatcher中间件
*/
export interface AlovaFetcherMiddleware<AG extends AlovaGenerics> {
(context: AlovaFetcherMiddlewareContext<AG>, next: AlovaGuardNext<AG>): any;
}

export type ProxyStateGetter<HookExportedStates extends Record<string, any>> = <K extends keyof HookExportedStates>(
key: K
) => HookExportedStates[K] extends ExportedState<infer Data, any>
? FrameworkState<Data, K & string>
: HookExportedStates[K] extends ExportedComputed<infer Data, any>
? FrameworkReadableState<Data, K & string>
: never;

export interface AlovaGuardNext<AG extends AlovaGenerics> {
(guardNextConfig?: MiddlewareNextGuardConfig<AG>): Promise<AG['Responded']>;
}

export type SendHandler<R> = (...args: any[]) => Promise<R>;
export interface UseHookExportedState<AG extends AlovaGenerics>
extends FrontRequestState<
ExportedState<boolean, AG['State']>,
ExportedState<AG['Responded'], AG['State']>,
ExportedState<Error | undefined, AG['State']>,
ExportedState<Progress, AG['State']>,
ExportedState<Progress, AG['State']>
> {}
export interface UseHookExposure<AG extends AlovaGenerics = AlovaGenerics> extends UseHookExportedState<AG> {
abort: () => void;
update: StateUpdater<UseHookExportedState<AG>>;
send: SendHandler<AG['Responded']>;
onSuccess(handler: SuccessHandler<AG>): this;
onError(handler: ErrorHandler<AG>): this;
onComplete(handler: CompleteHandler<AG>): this;
__proxyState: ProxyStateGetter<UseHookExportedState<AG>>;
__referingObj: ReferingObject;
}

export const enum EnumHookType {
USE_REQUEST = 1,
USE_WATCHER = 2,
USE_FETCHER = 3
}
export interface Hook {
/** 最后一次请求的method实例 */
m?: Method;

/** saveStatesFns */
sf: ((frontStates: FrontRequestState) => void)[];

/** removeStatesFns */
rf: (() => void)[];

/** frontStates */
fs: FrontRequestState<
FrameworkState<boolean, 'loading'>,
FrameworkState<any, 'data'>,
FrameworkState<Error | undefined, 'error'>,
FrameworkState<Progress, 'downloading'>,
FrameworkState<Progress, 'uploading'>
>;

/** event manager */
em: EventManager<{
success: AlovaSuccessEvent<any>;
error: AlovaErrorEvent<any>;
complete: AlovaCompleteEvent<any>;
}>;

/** hookType, useRequest=1, useWatcher=2, useFetcher=3 */
ht: EnumHookType;

/** hook config */
c: UseHookConfig<any>;

/** refering object */
ro: ReferingObject;
}
Loading
Loading