mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-09-11 19:47:35 +03:00
feat: use SafeInt
replace Float
(#5613)
This commit is contained in:
parent
b9f20877d0
commit
ee8ec47a4f
@ -63,6 +63,7 @@
|
|||||||
"file-type": "^19.0.0",
|
"file-type": "^19.0.0",
|
||||||
"get-stream": "^8.0.1",
|
"get-stream": "^8.0.1",
|
||||||
"graphql": "^16.8.1",
|
"graphql": "^16.8.1",
|
||||||
|
"graphql-scalars": "^1.22.4",
|
||||||
"graphql-type-json": "^0.3.2",
|
"graphql-type-json": "^0.3.2",
|
||||||
"graphql-upload": "^16.0.2",
|
"graphql-upload": "^16.0.2",
|
||||||
"ioredis": "^5.3.2",
|
"ioredis": "^5.3.2",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { createUnionType, Field, Float, ID, ObjectType } from '@nestjs/graphql';
|
import { createUnionType, Field, ID, ObjectType } from '@nestjs/graphql';
|
||||||
import type { User } from '@prisma/client';
|
import type { User } from '@prisma/client';
|
||||||
|
import { SafeIntResolver } from 'graphql-scalars';
|
||||||
|
|
||||||
@ObjectType('UserQuotaHumanReadable')
|
@ObjectType('UserQuotaHumanReadable')
|
||||||
export class UserQuotaHumanReadableType {
|
export class UserQuotaHumanReadableType {
|
||||||
@ -24,13 +25,13 @@ export class UserQuotaType {
|
|||||||
@Field({ name: 'name' })
|
@Field({ name: 'name' })
|
||||||
name!: string;
|
name!: string;
|
||||||
|
|
||||||
@Field(() => Float, { name: 'blobLimit' })
|
@Field(() => SafeIntResolver, { name: 'blobLimit' })
|
||||||
blobLimit!: number;
|
blobLimit!: number;
|
||||||
|
|
||||||
@Field(() => Float, { name: 'storageQuota' })
|
@Field(() => SafeIntResolver, { name: 'storageQuota' })
|
||||||
storageQuota!: number;
|
storageQuota!: number;
|
||||||
|
|
||||||
@Field(() => Float, { name: 'historyPeriod' })
|
@Field(() => SafeIntResolver, { name: 'historyPeriod' })
|
||||||
historyPeriod!: number;
|
historyPeriod!: number;
|
||||||
|
|
||||||
@Field({ name: 'memberLimit' })
|
@Field({ name: 'memberLimit' })
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { HttpStatus, Logger, UseGuards } from '@nestjs/common';
|
import { HttpStatus, Logger, UseGuards } from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
Args,
|
Args,
|
||||||
Float,
|
|
||||||
Int,
|
Int,
|
||||||
Mutation,
|
Mutation,
|
||||||
Parent,
|
Parent,
|
||||||
@ -10,6 +9,7 @@ import {
|
|||||||
Resolver,
|
Resolver,
|
||||||
} from '@nestjs/graphql';
|
} from '@nestjs/graphql';
|
||||||
import { GraphQLError } from 'graphql';
|
import { GraphQLError } from 'graphql';
|
||||||
|
import { SafeIntResolver } from 'graphql-scalars';
|
||||||
import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
|
import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -100,7 +100,7 @@ export class WorkspaceBlobResolver {
|
|||||||
async checkBlobSize(
|
async checkBlobSize(
|
||||||
@CurrentUser() user: UserType,
|
@CurrentUser() user: UserType,
|
||||||
@Args('workspaceId') workspaceId: string,
|
@Args('workspaceId') workspaceId: string,
|
||||||
@Args('size', { type: () => Float }) blobSize: number
|
@Args('size', { type: () => SafeIntResolver }) blobSize: number
|
||||||
) {
|
) {
|
||||||
const canWrite = await this.permissions.tryCheckWorkspace(
|
const canWrite = await this.permissions.tryCheckWorkspace(
|
||||||
workspaceId,
|
workspaceId,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
Field,
|
Field,
|
||||||
Float,
|
|
||||||
ID,
|
ID,
|
||||||
InputType,
|
InputType,
|
||||||
ObjectType,
|
ObjectType,
|
||||||
@ -10,6 +9,7 @@ import {
|
|||||||
registerEnumType,
|
registerEnumType,
|
||||||
} from '@nestjs/graphql';
|
} from '@nestjs/graphql';
|
||||||
import type { Workspace } from '@prisma/client';
|
import type { Workspace } from '@prisma/client';
|
||||||
|
import { SafeIntResolver } from 'graphql-scalars';
|
||||||
|
|
||||||
import { UserType } from '../users/types';
|
import { UserType } from '../users/types';
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ export class InvitationWorkspaceType {
|
|||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class WorkspaceBlobSizes {
|
export class WorkspaceBlobSizes {
|
||||||
@Field(() => Float)
|
@Field(() => SafeIntResolver)
|
||||||
size!: number;
|
size!: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,13 +23,18 @@ type UserQuotaHumanReadable {
|
|||||||
|
|
||||||
type UserQuota {
|
type UserQuota {
|
||||||
name: String!
|
name: String!
|
||||||
blobLimit: Float!
|
blobLimit: SafeInt!
|
||||||
storageQuota: Float!
|
storageQuota: SafeInt!
|
||||||
historyPeriod: Float!
|
historyPeriod: SafeInt!
|
||||||
memberLimit: Int!
|
memberLimit: Int!
|
||||||
humanReadable: UserQuotaHumanReadable!
|
humanReadable: UserQuotaHumanReadable!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
The `SafeInt` scalar type represents non-fractional signed whole numeric values that are considered safe as defined by the ECMAScript specification.
|
||||||
|
"""
|
||||||
|
scalar SafeInt @specifiedBy(url: "https://www.ecma-international.org/ecma-262/#sec-number.issafeinteger")
|
||||||
|
|
||||||
type UserType {
|
type UserType {
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
||||||
@ -172,7 +177,7 @@ type InvitationWorkspaceType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type WorkspaceBlobSizes {
|
type WorkspaceBlobSizes {
|
||||||
size: Float!
|
size: SafeInt!
|
||||||
}
|
}
|
||||||
|
|
||||||
type InvitationType {
|
type InvitationType {
|
||||||
@ -309,7 +314,7 @@ type Query {
|
|||||||
"""List blobs of workspace"""
|
"""List blobs of workspace"""
|
||||||
listBlobs(workspaceId: String!): [String!]! @deprecated(reason: "use `workspace.blobs` instead")
|
listBlobs(workspaceId: String!): [String!]! @deprecated(reason: "use `workspace.blobs` instead")
|
||||||
collectAllBlobSizes: WorkspaceBlobSizes! @deprecated(reason: "use `user.storageUsage` instead")
|
collectAllBlobSizes: WorkspaceBlobSizes! @deprecated(reason: "use `user.storageUsage` instead")
|
||||||
checkBlobSize(workspaceId: String!, size: Float!): WorkspaceBlobSizes! @deprecated(reason: "no more needed")
|
checkBlobSize(workspaceId: String!, size: SafeInt!): WorkspaceBlobSizes! @deprecated(reason: "no more needed")
|
||||||
|
|
||||||
"""Get current user"""
|
"""Get current user"""
|
||||||
currentUser: UserType
|
currentUser: UserType
|
||||||
|
@ -74,7 +74,7 @@ export async function checkBlobSize(
|
|||||||
.post(gql)
|
.post(gql)
|
||||||
.auth(token, { type: 'bearer' })
|
.auth(token, { type: 'bearer' })
|
||||||
.send({
|
.send({
|
||||||
query: `query checkBlobSize($workspaceId: String!, $size: Float!) {
|
query: `query checkBlobSize($workspaceId: String!, $size: SafeInt!) {
|
||||||
checkBlobSize(workspaceId: $workspaceId, size: $size) {
|
checkBlobSize(workspaceId: $workspaceId, size: $size) {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,9 @@ config:
|
|||||||
Decimal: number
|
Decimal: number
|
||||||
UUID: string
|
UUID: string
|
||||||
ID: string
|
ID: string
|
||||||
JSON: any
|
JSON: string
|
||||||
Upload: File
|
Upload: File
|
||||||
|
SafeInt: number
|
||||||
overwrite: true
|
overwrite: true
|
||||||
schema: ../../backend/server/src/schema.gql
|
schema: ../../backend/server/src/schema.gql
|
||||||
documents: ./src/**/*.gql
|
documents: ./src/**/*.gql
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
query checkBlobSizes($workspaceId: String!, $size: Float!) {
|
query checkBlobSizes($workspaceId: String!, $size: SafeInt!) {
|
||||||
checkBlobSize(workspaceId: $workspaceId, size: $size) {
|
checkBlobSize(workspaceId: $workspaceId, size: $size) {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ export const checkBlobSizesQuery = {
|
|||||||
definitionName: 'checkBlobSize',
|
definitionName: 'checkBlobSize',
|
||||||
containsFile: false,
|
containsFile: false,
|
||||||
query: `
|
query: `
|
||||||
query checkBlobSizes($workspaceId: String!, $size: Float!) {
|
query checkBlobSizes($workspaceId: String!, $size: SafeInt!) {
|
||||||
checkBlobSize(workspaceId: $workspaceId, size: $size) {
|
checkBlobSize(workspaceId: $workspaceId, size: $size) {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ export interface Scalars {
|
|||||||
Float: { input: number; output: number };
|
Float: { input: number; output: number };
|
||||||
/** A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date-time format. */
|
/** A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date-time format. */
|
||||||
DateTime: { input: string; output: string };
|
DateTime: { input: string; output: string };
|
||||||
|
/** The `SafeInt` scalar type represents non-fractional signed whole numeric values that are considered safe as defined by the ECMAScript specification. */
|
||||||
|
SafeInt: { input: number; output: number };
|
||||||
/** The `Upload` scalar type represents a file upload. */
|
/** The `Upload` scalar type represents a file upload. */
|
||||||
Upload: { input: File; output: File };
|
Upload: { input: File; output: File };
|
||||||
}
|
}
|
||||||
@ -93,7 +95,7 @@ export interface UpdateWorkspaceInput {
|
|||||||
|
|
||||||
export type CheckBlobSizesQueryVariables = Exact<{
|
export type CheckBlobSizesQueryVariables = Exact<{
|
||||||
workspaceId: Scalars['String']['input'];
|
workspaceId: Scalars['String']['input'];
|
||||||
size: Scalars['Float']['input'];
|
size: Scalars['SafeInt']['input'];
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export type CheckBlobSizesQuery = {
|
export type CheckBlobSizesQuery = {
|
||||||
|
12
yarn.lock
12
yarn.lock
@ -689,6 +689,7 @@ __metadata:
|
|||||||
file-type: "npm:^19.0.0"
|
file-type: "npm:^19.0.0"
|
||||||
get-stream: "npm:^8.0.1"
|
get-stream: "npm:^8.0.1"
|
||||||
graphql: "npm:^16.8.1"
|
graphql: "npm:^16.8.1"
|
||||||
|
graphql-scalars: "npm:^1.22.4"
|
||||||
graphql-type-json: "npm:^0.3.2"
|
graphql-type-json: "npm:^0.3.2"
|
||||||
graphql-upload: "npm:^16.0.2"
|
graphql-upload: "npm:^16.0.2"
|
||||||
ioredis: "npm:^5.3.2"
|
ioredis: "npm:^5.3.2"
|
||||||
@ -21878,6 +21879,17 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"graphql-scalars@npm:^1.22.4":
|
||||||
|
version: 1.22.4
|
||||||
|
resolution: "graphql-scalars@npm:1.22.4"
|
||||||
|
dependencies:
|
||||||
|
tslib: "npm:^2.5.0"
|
||||||
|
peerDependencies:
|
||||||
|
graphql: ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0
|
||||||
|
checksum: 110c1fa29d7564d9967c974de2df08c99d7ed43af98097e5a5729f952c064b21f66a9f5a68143c50eeac6a4ce14f0999aed2ce8f043d02331d133b0c59a9c1ec
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"graphql-tag@npm:2.12.6, graphql-tag@npm:^2.11.0":
|
"graphql-tag@npm:2.12.6, graphql-tag@npm:^2.11.0":
|
||||||
version: 2.12.6
|
version: 2.12.6
|
||||||
resolution: "graphql-tag@npm:2.12.6"
|
resolution: "graphql-tag@npm:2.12.6"
|
||||||
|
Loading…
Reference in New Issue
Block a user