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

chore: complete Prisma 6 upgrade #9133

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion packages/backend/native/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ export declare function mergeUpdatesInApplyWay(updates: Array<Buffer>): Buffer
export declare function mintChallengeResponse(resource: string, bits?: number | undefined | null): Promise<string>

export declare function verifyChallengeResponse(response: string, bits: number, resource: string): Promise<boolean>

6 changes: 3 additions & 3 deletions packages/backend/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"@opentelemetry/sdk-node": "^0.55.0",
"@opentelemetry/sdk-trace-node": "^1.25.0",
"@opentelemetry/semantic-conventions": "^1.25.0",
"@prisma/client": "^5.15.0",
"@prisma/instrumentation": "^5.15.0",
"@prisma/client": "^6.0.0",
"@prisma/instrumentation": "^6.0.0",
"@socket.io/redis-adapter": "^8.3.0",
"cookie-parser": "^1.4.6",
"dotenv": "^16.4.5",
Expand All @@ -79,7 +79,7 @@
"on-headers": "^1.0.2",
"openai": "^4.33.0",
"piscina": "^4.5.1",
"prisma": "^5.12.1",
"prisma": "^6.0.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"ses": "^1.4.1",
Expand Down
26 changes: 18 additions & 8 deletions packages/backend/server/src/core/doc/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import { PermissionService } from '../permission';
import { QuotaService } from '../quota';
import { DocStorageOptions as IDocStorageOptions } from './storage';

function compare(yBinary: Buffer, jwstBinary: Buffer, strict = false): boolean {
if (yBinary.equals(jwstBinary)) {
function compare(
yBinary: Uint8Array,
jwstBinary: Uint8Array,
strict = false
): boolean {
if (Buffer.from(yBinary).equals(Buffer.from(jwstBinary))) {
return true;
}

Expand All @@ -24,7 +28,7 @@ function compare(yBinary: Buffer, jwstBinary: Buffer, strict = false): boolean {
const doc = new Y.Doc();
Y.applyUpdate(doc, jwstBinary);

const yBinary2 = Buffer.from(Y.encodeStateAsUpdate(doc));
const yBinary2 = new Uint8Array(Y.encodeStateAsUpdate(doc));

return compare(yBinary, yBinary2, true);
}
Expand All @@ -41,7 +45,7 @@ export class DocStorageOptions implements IDocStorageOptions {

mergeUpdates = async (updates: Uint8Array[]) => {
const doc = await this.recoverDoc(updates);
const yjsResult = Buffer.from(Y.encodeStateAsUpdate(doc));
const yjsResult = new Uint8Array(Y.encodeStateAsUpdate(doc));

const useYocto = await this.config.runtime.fetch(
'doc/experimentalMergeWithYOcto'
Expand All @@ -50,16 +54,22 @@ export class DocStorageOptions implements IDocStorageOptions {
if (useYocto) {
metrics.jwst.counter('codec_merge_counter').add(1);
let log = false;
let yoctoResult: Buffer | null = null;
let yoctoResult: Uint8Array | null = null;
try {
yoctoResult = yotcoMergeUpdates(updates.map(Buffer.from));
yoctoResult = new Uint8Array(
yotcoMergeUpdates(updates.map(u => Buffer.from(u)))
);
if (!compare(yjsResult, yoctoResult)) {
metrics.jwst.counter('codec_not_match').add(1);
this.logger.warn(`yocto codec result doesn't match yjs codec result`);
log = true;
if (this.config.node.dev) {
this.logger.warn(`Expected:\n ${yjsResult.toString('hex')}`);
this.logger.warn(`Result:\n ${yoctoResult.toString('hex')}`);
this.logger.warn(
`Expected:\n ${Buffer.from(yjsResult).toString('hex')}`
);
this.logger.warn(
`Result:\n ${Buffer.from(yoctoResult).toString('hex')}`
);
}
}
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/server/src/core/storage/wrappers/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class WorkspaceBlobStorage {
this.provider = this.storageFactory.create(this.config.storages.blob);
}

async put(workspaceId: string, key: string, blob: Buffer) {
async put(workspaceId: string, key: string, blob: Uint8Array) {
const meta: PutObjectMetadata = autoMetadata(blob);

await this.provider.put(`${workspaceId}/${key}`, blob, meta);
Expand Down
21 changes: 14 additions & 7 deletions packages/backend/server/src/core/sync/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ export class SpaceSyncGateway
const doc = await adapter.diff(
spaceId,
docId,
stateVector ? Buffer.from(stateVector, 'base64') : undefined
stateVector
? new Uint8Array(Buffer.from(stateVector, 'base64'))
: undefined
);

if (!doc) {
Expand All @@ -246,8 +248,8 @@ export class SpaceSyncGateway

return {
data: {
missing: Buffer.from(doc.missing).toString('base64'),
state: Buffer.from(doc.state).toString('base64'),
missing: Buffer.from(new Uint8Array(doc.missing)).toString('base64'),
state: Buffer.from(new Uint8Array(doc.state)).toString('base64'),
timestamp: doc.timestamp,
},
};
Expand Down Expand Up @@ -279,7 +281,7 @@ export class SpaceSyncGateway
const timestamp = await adapter.push(
spaceId,
docId,
updates.map(update => Buffer.from(update, 'base64')),
updates.map(update => new Uint8Array(Buffer.from(update, 'base64'))),
user.id
);

Expand Down Expand Up @@ -323,7 +325,7 @@ export class SpaceSyncGateway
const timestamp = await adapter.push(
spaceId,
docId,
[Buffer.from(update, 'base64')],
[new Uint8Array(Buffer.from(update, 'base64'))],
user.id
);

Expand Down Expand Up @@ -642,7 +644,12 @@ abstract class SyncSocketAdapter {
permission?: Permission
): Promise<void>;

push(spaceId: string, docId: string, updates: Buffer[], editorId: string) {
push(
spaceId: string,
docId: string,
updates: Uint8Array[],
editorId: string
) {
this.assertIn(spaceId);
return this.storage.pushDocUpdates(spaceId, docId, updates, editorId);
}
Expand Down Expand Up @@ -675,7 +682,7 @@ class WorkspaceSyncAdapter extends SyncSocketAdapter {
override push(
spaceId: string,
docId: string,
updates: Buffer[],
updates: Uint8Array[],
editorId: string
) {
const id = new DocID(docId, spaceId);
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/server/src/core/workspaces/resolvers/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class WorkspaceBlobResolver {
if (checkExceeded(0)) {
throw new BlobQuotaExceeded();
}
const buffer = await new Promise<Buffer>((resolve, reject) => {
const buffer = await new Promise<Uint8Array>((resolve, reject) => {
const stream = blob.createReadStream();
const chunks: Uint8Array[] = [];
stream.on('data', chunk => {
Expand All @@ -126,7 +126,7 @@ export class WorkspaceBlobResolver {
});
stream.on('error', reject);
stream.on('end', () => {
const buffer = Buffer.concat(chunks);
const buffer = new Uint8Array(Buffer.concat(chunks));

if (checkExceeded(buffer.length)) {
reject(new BlobQuotaExceeded());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,17 @@ export class WorkspaceResolver {

if (init) {
// convert stream to buffer
const buffer = await new Promise<Buffer>(resolve => {
const buffer = await new Promise<Uint8Array>(resolve => {
const stream = init.createReadStream();
const chunks: Uint8Array[] = [];
stream.on('data', chunk => {
chunks.push(chunk);
});
stream.on('error', () => {
resolve(Buffer.from([]));
resolve(new Uint8Array());
});
stream.on('end', () => {
resolve(Buffer.concat(chunks));
resolve(new Uint8Array(Buffer.concat(chunks)));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ListObjectsMetadata {
contentLength: number;
}

export type BlobInputType = Buffer | Readable | string;
export type BlobInputType = Buffer | Uint8Array | Readable | string;
export type BlobOutputType = Readable;

export interface StorageProvider {
Expand Down
39 changes: 28 additions & 11 deletions packages/backend/server/src/fundamentals/storage/providers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,51 @@ import { getMime } from '../../../native';
import { BlobInputType, PutObjectMetadata } from './provider';

export async function toBuffer(input: BlobInputType): Promise<Buffer> {
return input instanceof Readable
? await getStreamAsBuffer(input)
: input instanceof Buffer
? input
: Buffer.from(input);
if (input instanceof Readable) {
return await getStreamAsBuffer(input);
}
if (input instanceof Buffer) {
return input;
}
return Buffer.from(input);
}

export function autoMetadata(
blob: Buffer,
blob: BlobInputType,
raw: PutObjectMetadata = {}
): PutObjectMetadata {
const metadata = {
...raw,
};

if (!metadata.contentLength) {
metadata.contentLength = blob.byteLength;
metadata.contentLength =
blob instanceof Buffer || blob instanceof Uint8Array
? blob.byteLength
: blob instanceof Readable
? 0
: Buffer.from(blob).byteLength;
}

try {
// checksum
if (!metadata.checksumCRC32) {
metadata.checksumCRC32 = crc32(blob).toString(16);
metadata.checksumCRC32 =
blob instanceof Buffer
? crc32(blob).toString(16)
: blob instanceof Uint8Array
? crc32(Buffer.from(blob)).toString(16)
: blob instanceof Readable
? undefined
: crc32(Buffer.from(blob)).toString(16);
}

// mime type
if (!metadata.contentType) {
metadata.contentType = getMime(blob);
metadata.contentType =
blob instanceof Buffer || blob instanceof Uint8Array
? getMime(Buffer.from(blob))
: blob instanceof Readable
? 'application/octet-stream'
: getMime(Buffer.from(blob));
}
} catch {
// noop
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/native/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ export declare enum ValidationResult {
}

export declare function verifyChallengeResponse(response: string, bits: number, resource: string): Promise<boolean>

5 changes: 4 additions & 1 deletion packages/frontend/native/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// prettier-ignore
/* eslint-disable */
// @ts-nocheck
/* auto-generated by NAPI-RS */

const { readFileSync } = require('fs')
const { createRequire } = require('node:module')
require = createRequire(__filename)

const { readFileSync } = require('node:fs')
let nativeBinding = null
const loadErrors = []

Expand Down
Loading
Loading