Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Implement new changes in seed script

Hakan Shehudcb16873e201
diff --git a/scripts/src/seed/index.ts b/scripts/src/seed/index.ts
index 23572de9..7a9101dc 100644
--- a/scripts/src/seed/index.ts
+++ b/scripts/src/seed/index.ts
@@ -1,6 +1,6 @@
import FormData from 'form-data';
import axios from 'axios';
-import { LoginOutput } from '@colanode/core';
+import { LoginSuccessOutput } from '@colanode/core';
import fs from 'fs';
import path from 'path';
@@ -38,14 +38,20 @@ const uploadAvatar = async (
}
};
-const createAccount = async (account: FakerAccount): Promise<LoginOutput> => {
- const url = `${SERVER_DOMAIN}/client/v1/accounts/register/email`;
- const { data } = await axios.post<LoginOutput>(url, {
+const createAccount = async (
+ account: FakerAccount
+): Promise<LoginSuccessOutput> => {
+ const url = `${SERVER_DOMAIN}/client/v1/accounts/emails/register`;
+ const { data } = await axios.post<LoginSuccessOutput>(url, {
name: account.name,
email: account.email,
password: account.password,
});
+ if (data.type !== 'success') {
+ throw new Error('Failed to create account');
+ }
+
const avatarPath = path.resolve(`src/seed/avatars/${account.avatar}`);
const avatarId = await uploadAvatar(data.token, avatarPath);
data.account.avatar = avatarId;
@@ -69,7 +75,7 @@ const createAccount = async (account: FakerAccount): Promise<LoginOutput> => {
const createMainAccountAndWorkspace = async (
account: FakerAccount
-): Promise<LoginOutput> => {
+): Promise<LoginSuccessOutput> => {
const login = await createAccount(account);
const workspace = login.workspaces[0];
if (!workspace) {
@@ -104,7 +110,7 @@ const createMainAccountAndWorkspace = async (
};
const inviteAccountsToWorkspace = async (
- mainAccount: LoginOutput,
+ mainAccount: LoginSuccessOutput,
otherFakerAccounts: FakerAccount[]
) => {
const workspace = mainAccount.workspaces[0];
diff --git a/scripts/src/seed/node-generator.ts b/scripts/src/seed/node-generator.ts
index 8d40aa80..97e55f73 100644
--- a/scripts/src/seed/node-generator.ts
+++ b/scripts/src/seed/node-generator.ts
@@ -15,14 +15,16 @@ import {
LocalCreateTransaction,
CreateMessageMutation,
entryAttributesSchema,
+ MessageType,
+ TransactionOperation,
} from '@colanode/core';
import { encodeState, YDoc } from '@colanode/crdt';
import { faker } from '@faker-js/faker';
import { User } from './types';
-const MESSAGES_PER_CONVERSATION = 2000;
-const RECORDS_PER_DATABASE = 2000;
+const MESSAGES_PER_CONVERSATION = 500;
+const RECORDS_PER_DATABASE = 500;
export class NodeGenerator {
constructor(
@@ -253,11 +255,11 @@ export class NodeGenerator {
id: generateId(IdType.Mutation),
data: {
id: messageId,
- type: 'standard',
entryId: conversationId,
parentId: conversationId,
rootId,
- content: {
+ attributes: {
+ type: MessageType.Standard,
blocks: this.buildMessageContent(messageId),
},
createdAt: new Date().toISOString(),
@@ -919,7 +921,7 @@ export class NodeGenerator {
return {
id: generateId(IdType.Transaction),
- operation: 'create',
+ operation: TransactionOperation.Create,
data: encodeState(update),
entryId,
rootId,
diff --git a/scripts/src/seed/types.ts b/scripts/src/seed/types.ts
index 7119274c..de62ecd3 100644
--- a/scripts/src/seed/types.ts
+++ b/scripts/src/seed/types.ts
@@ -1,4 +1,4 @@
-import { LoginOutput, Mutation } from '@colanode/core';
+import { LoginSuccessOutput, Mutation } from '@colanode/core';
export type FakerAccount = {
name: string;
@@ -8,7 +8,7 @@ export type FakerAccount = {
};
export type User = {
- login: LoginOutput;
+ login: LoginSuccessOutput;
userId: string;
mutations: Mutation[];
};