Skip to content

Commit

Permalink
[migrate] Model Type package
Browse files Browse the repository at this point in the history
[optimize] upgrade Upstream packages
  • Loading branch information
TechQuery committed Oct 3, 2023
1 parent f4cfcd5 commit 6f18284
Show file tree
Hide file tree
Showing 25 changed files with 1,134 additions and 2,579 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ jobs:

- name: Inject Environment variables
run: |
cat >> .npmrc <<EOF
//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}
@ideamall:registry=https://npm.pkg.github.com
always-auth=true
EOF
cat > .env.local <<EOF
${{ secrets.ENV_FILE }}
EOF
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto-install-peers = false
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN npm i pnpm -g
RUN mkdir /home/node/app
WORKDIR /home/node/app

COPY package.json pnpm-lock.yaml /home/node/app/
COPY package.json pnpm-lock.yaml .npmrc /home/node/app/
RUN pnpm i --frozen-lockfile

COPY . /home/node/app
Expand Down
10 changes: 5 additions & 5 deletions components/Address/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AddressOutput } from '@ideamall/data-model';
import { Address } from '@ideamall/data-service';
import { FC, PropsWithChildren } from 'react';
import { Card, CardProps } from 'react-bootstrap';

export interface AddressProps
extends Pick<
AddressOutput,
Address,
| 'country'
| 'province'
| 'city'
Expand All @@ -18,7 +18,7 @@ export interface AddressProps
className?: string;
}

export const Address: FC<AddressProps> = ({
export const AddressText: FC<AddressProps> = ({
className = 'm-0',
country,
province,
Expand All @@ -44,7 +44,7 @@ export const Address: FC<AddressProps> = ({
);

export type AddressCardProps = PropsWithChildren<
AddressOutput & Pick<CardProps, 'as'>
Address & Pick<CardProps, 'as'>
>;

export const AddressCard: FC<AddressCardProps> = ({
Expand All @@ -65,7 +65,7 @@ export const AddressCard: FC<AddressCardProps> = ({
</a>
</Card.Title>
<div className="d-flex justify-content-between align-items-center">
<Address {...address} />
<AddressText {...address} />
{children}
</div>
</Card.Body>
Expand Down
6 changes: 3 additions & 3 deletions components/Address/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AddressOutput } from '@ideamall/data-model';
import { Address } from '@ideamall/data-service';
import { makeObservable, observable } from 'mobx';
import { observer } from 'mobx-react';
import {
Expand All @@ -16,7 +16,7 @@ import { AddressCard } from './Card';
const { t } = i18n;

export interface AddressListProps
extends Omit<ScrollListProps<AddressOutput>, 'translator' | 'renderList'> {
extends Omit<ScrollListProps<Address>, 'translator' | 'renderList'> {
name: string;
defaultValue?: number;
}
Expand All @@ -31,7 +31,7 @@ export class AddressList extends PureComponent<AddressListProps> {
@observable
creating = false;

get fields(): Field<AddressOutput>[] {
get fields(): Field<Address>[] {
return [
{ key: 'signature' },
{ key: 'mobilePhone', type: 'tel' },
Expand Down
2 changes: 1 addition & 1 deletion components/AdminFrame.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Role } from '@ideamall/data-model';
import { Role } from '@ideamall/data-service';
import { Icon } from 'idea-react';
import { observer } from 'mobx-react';
import dynamic from 'next/dynamic';
Expand Down
4 changes: 2 additions & 2 deletions components/Goods/ItemTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GoodsItemOutput, GoodsStyle } from '@ideamall/data-model';
import { GoodsItem, GoodsStyle } from '@ideamall/data-service';
import { text2color } from 'idea-react';
import { observer } from 'mobx-react';
import {
Expand All @@ -24,7 +24,7 @@ export interface GoodsItemTableProps {

@observer
export class GoodsItemTable extends PureComponent<GoodsItemTableProps> {
get columns(): Column<GoodsItemOutput>[] {
get columns(): Column<GoodsItem>[] {
const { goodsId } = this.props;

return [
Expand Down
2 changes: 1 addition & 1 deletion components/Goods/StyleEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GoodsStyle } from '@ideamall/data-model';
import { GoodsStyle } from '@ideamall/data-service';
import { computed, makeObservable, observable } from 'mobx';
import { observer } from 'mobx-react';
import { observePropsState } from 'mobx-react-helper';
Expand Down
2 changes: 1 addition & 1 deletion components/SessionBox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Role } from '@ideamall/data-model';
import { Role } from '@ideamall/data-service';
import { computed } from 'mobx';
import { observer } from 'mobx-react';
import { observePropsState } from 'mobx-react-helper';
Expand Down
2 changes: 1 addition & 1 deletion components/UserMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Role } from '@ideamall/data-model';
import { Role } from '@ideamall/data-service';
import { observer } from 'mobx-react';
import dynamic from 'next/dynamic';
import { FC } from 'react';
Expand Down
2 changes: 1 addition & 1 deletion components/data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Gender, Role } from '@ideamall/data-model';
import { Gender, Role } from '@ideamall/data-service';

import { i18n } from '../models/Translation';

Expand Down
6 changes: 3 additions & 3 deletions models/Address.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AddressOutput, AddressOwner } from '@ideamall/data-model';
import { Address, AddressOwner } from '@ideamall/data-service';
import { NewData } from 'mobx-restful';

import { TableModel } from './Base';
import userStore from './User';

export class AddressModel extends TableModel<AddressOutput> {
export class AddressModel extends TableModel<Address> {
client = userStore.client;
baseURI = '';

Expand All @@ -13,7 +13,7 @@ export class AddressModel extends TableModel<AddressOutput> {
this.baseURI = ownership ? 'user/session/address' : 'address';
}

updateOne(data: Partial<NewData<AddressOutput>>, id?: number) {
updateOne(data: Partial<NewData<Address>>, id?: number) {
return super.updateOne({ ...data, ownership: this.ownership }, id);
}
}
4 changes: 2 additions & 2 deletions models/Base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseOutput, ListChunk } from '@ideamall/data-model';
import { Base, ListChunk } from '@ideamall/data-service';
import { HTTPClient } from 'koajax';
import { ListModel, NewData, toggle } from 'mobx-restful';
import { buildURLData } from 'web-utility';
Expand Down Expand Up @@ -28,7 +28,7 @@ export const githubClient = new HTTPClient({
});

export abstract class TableModel<
D extends BaseOutput,
D extends Base,
F extends NewData<D> = NewData<D>,
> extends ListModel<D, F> {
async loadPage(pageIndex: number, pageSize: number, filter: F) {
Expand Down
6 changes: 3 additions & 3 deletions models/Category.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { CategoryOutput } from '@ideamall/data-model';
import { Category } from '@ideamall/data-service';
import { computed } from 'mobx';

import { TableModel } from './Base';
import userStore from './User';

export interface CategoryNode extends CategoryOutput {
export interface CategoryNode extends Category {
subs?: CategoryNode[];
}

export class CategoryModel extends TableModel<CategoryOutput> {
export class CategoryModel extends TableModel<Category> {
client = userStore.client;
baseURI = 'category';

Expand Down
19 changes: 4 additions & 15 deletions models/File.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { HTTPError, request } from 'koajax';
import { toggle } from 'mobx-restful';
import { FileModel } from 'mobx-restful-table';

Expand All @@ -11,20 +10,10 @@ export class OwnFileModel extends FileModel {

form.append('data', file);

const response = await request<{ path: string }>({
method: 'POST',
path: userStore.client.baseURI + 'file',
headers: {
Authorization: `Bearer ${userStore.session?.token}`,
},
body: form,
responseType: 'json',
}).response;

const { status, statusText, body } = response;

if (status > 299) throw new HTTPError(statusText, response);

const { body } = await userStore.client.post<{ path: string }>(
'file',
form,
);
return super.upload(body!.path);
}
}
Expand Down
6 changes: 3 additions & 3 deletions models/Goods.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { GoodsItemOutput, GoodsOutput } from '@ideamall/data-model';
import { Goods, GoodsItem } from '@ideamall/data-service';
import { makeObservable, observable } from 'mobx';

import { TableModel } from './Base';
import userStore from './User';

export class GoodsModel extends TableModel<GoodsOutput> {
export class GoodsModel extends TableModel<Goods> {
constructor() {
super();
makeObservable(this);
Expand All @@ -29,7 +29,7 @@ export class GoodsModel extends TableModel<GoodsOutput> {
}
}

export class GoodsItemModel extends TableModel<GoodsItemOutput> {
export class GoodsItemModel extends TableModel<GoodsItem> {
client = userStore.client;
baseURI = '';

Expand Down
2 changes: 1 addition & 1 deletion models/Statistic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StatisticSummary } from '@ideamall/data-model';
import { StatisticSummary } from '@ideamall/data-service';
import { makeObservable, observable } from 'mobx';
import { BaseModel, toggle } from 'mobx-restful';

Expand Down
11 changes: 5 additions & 6 deletions models/User.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Guard } from '@authing/guard';
import { UserOutput } from '@ideamall/data-model';
import { User } from '@ideamall/data-service';
import { HTTPClient } from 'koajax';
import { makeObservable, observable } from 'mobx';
import { toggle } from 'mobx-restful';
Expand All @@ -13,7 +13,7 @@ export const guard = new Guard({
appId: process.env.NEXT_PUBLIC_AUTHING_APP_ID!,
});

export class UserModel extends TableModel<UserOutput> {
export class UserModel extends TableModel<User> {
constructor() {
super();
makeObservable(this);
Expand All @@ -22,8 +22,7 @@ export class UserModel extends TableModel<UserOutput> {
baseURI = 'user';

@observable
session?: UserOutput =
localStorage?.session && JSON.parse(localStorage.session);
session?: User = localStorage?.session && JSON.parse(localStorage.session);

client = new HTTPClient({
baseURI: API_Host,
Expand All @@ -37,15 +36,15 @@ export class UserModel extends TableModel<UserOutput> {
return next();
});

saveSession(user: UserOutput) {
saveSession(user: User) {
localStorage.session = JSON.stringify(user);

return (this.session = user);
}

@toggle('uploading')
async signInAuthing(token: string) {
const { body } = await this.client.post<UserOutput>(
const { body } = await this.client.post<User>(
`${this.baseURI}/session/authing`,
{},
{ Authorization: `Bearer ${token}` },
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@
"description": "React project scaffold based on TypeScript, Next.js, Bootstrap & Workbox.",
"private": true,
"dependencies": {
"@authing/guard": "^5.2.4",
"@ideamall/data-model": "1.0.0-rc.2",
"idea-react": "^1.0.0-rc.22",
"koajax": "^0.8.6",
"@authing/guard": "^5.3.0",
"@ideamall/data-service": "^1.0.0-alpha.1",
"idea-react": "^1.0.0-rc.30",
"koajax": "^0.9.4",
"less": "^4.2.0",
"less-loader": "^11.1.3",
"lodash": "^4.17.21",
"mobx": "^6.10.2",
"mobx-i18n": "^0.4.1",
"mobx-react": "^9.0.1",
"mobx-react-helper": "^0.2.7",
"mobx-restful": "^0.6.11",
"mobx-restful-table": "^1.1.2",
"next": "^13.4.19",
"mobx-restful": "^0.6.12",
"mobx-restful-table": "^1.2.0",
"next": "^13.5.3",
"next-pwa": "~5.6.0",
"next-ssr-middleware": "^0.5.1",
"next-with-less": "^3.0.1",
"react": "^18.2.0",
"react-bootstrap": "^2.8.0",
"react-bootstrap": "^2.9.0",
"react-bootstrap-editor": "^1.0.5",
"react-dom": "^18.2.0",
"web-utility": "^4.1.0"
"web-utility": "^4.1.3"
},
"devDependencies": {
"@octokit/openapi-types": "^18.0.0",
"@types/lodash": "^4.14.197",
"@types/node": "^18.17.12",
"@types/react": "^18.2.21",
"eslint": "^8.48.0",
"eslint-config-next": "^13.4.19",
"@octokit/openapi-types": "^19.0.0",
"@types/lodash": "^4.14.199",
"@types/node": "^18.18.3",
"@types/react": "^18.2.24",
"eslint": "^8.50.0",
"eslint-config-next": "^13.5.3",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"husky": "^8.0.3",
Expand Down
4 changes: 2 additions & 2 deletions pages/admin/category.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CategoryInput } from '@ideamall/data-model';
import { Category, UserInputData } from '@ideamall/data-service';
import { ClickBoundary, Loading, SpinnerButton } from 'idea-react';
import { computed, makeObservable, observable } from 'mobx';
import { observer } from 'mobx-react';
Expand All @@ -21,7 +21,7 @@ export default function CategoryAdminPage() {
);
}

interface CategoryMeta extends CategoryInput {
interface CategoryMeta extends UserInputData<Category> {
id?: number;
}

Expand Down
4 changes: 2 additions & 2 deletions pages/admin/goods/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GoodsInput } from '@ideamall/data-model';
import { Goods } from '@ideamall/data-service';
import { Loading, SpinnerButton } from 'idea-react';
import { observer } from 'mobx-react';
import { FormField } from 'mobx-restful-table';
Expand Down Expand Up @@ -62,7 +62,7 @@ class GoodsEditor extends PureComponent<{ id: string }> {
handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();

const { styles, ...data } = formToJSON<GoodsInput>(event.currentTarget);
const { styles, ...data } = formToJSON<Goods>(event.currentTarget);

await this.goodsStore.updateOne(
{
Expand Down
Loading

1 comment on commit 6f18284

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for idea-mall ready!

✅ Preview
https://idea-mall-7x9dj4fzs-techquery.vercel.app

Built with commit 6f18284.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.