From 02717f445033802e340a3abf3a147770241c2251 Mon Sep 17 00:00:00 2001 From: Andrey Platov Date: Sun, 29 Aug 2021 09:47:17 +0200 Subject: [PATCH] update workspace tooling Signed-off-by: Andrey Platov --- common/config/rush/pnpm-lock.yaml | 5 ++--- server/workspace/Dockerfile | 2 ++ server/workspace/package.json | 4 +++- server/workspace/src/__create.ts | 16 +++++++++++----- server/workspace/src/index.ts | 31 +++++++++++++++++++++++-------- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index ff704f6854..935feac4f3 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -85,7 +85,6 @@ specifiers: cross-env: ^7.0.3 css-loader: ^5.2.1 dotenv-webpack: ^7.0.2 - esbuild: ^0.12.24 eslint: ^7.32.0 eslint-config-standard-with-typescript: ^20.0.0 eslint-plugin-import: '2' @@ -201,7 +200,6 @@ dependencies: cross-env: 7.0.3 css-loader: 5.2.7_webpack@5.48.0 dotenv-webpack: 7.0.3_webpack@5.48.0 - esbuild: 0.12.24 eslint: 7.32.0 eslint-config-standard-with-typescript: 20.0.0_2e482f375e273d762fe67cbd5e194b49 eslint-plugin-import: 2.23.4_eslint@7.32.0 @@ -10000,7 +9998,7 @@ packages: dev: false file:projects/workspace.tgz_6c259fadfeb3a4b20890aefe87070b8b: - resolution: {integrity: sha512-Ircelx/9snTrdceAfj7OBTqmR1tZ/cTtPtdf3zcmTJ+EwFh0rhWQJgd80CSeny6I8wMC+UXcKUk5mGHDqcmKcw==, tarball: file:projects/workspace.tgz} + resolution: {integrity: sha512-8vO7UTqdUdxIPbiMIKXV54zDnFD63L75+7Z9mTnVO5Ln6Nb5rf+ZfYloA2pDauRKp0Rf7ItIYPhjmEpp8QE+Ow==, tarball: file:projects/workspace.tgz} id: file:projects/workspace.tgz name: '@rush-temp/workspace' version: 0.0.0 @@ -10013,6 +10011,7 @@ packages: eslint-plugin-import: 2.23.4_eslint@7.32.0 eslint-plugin-node: 11.1.0_eslint@7.32.0 eslint-plugin-promise: 4.3.1 + jwt-simple: 0.5.6 mongodb: 4.1.1 ts-node: 10.2.1_typescript@4.3.5 transitivePeerDependencies: diff --git a/server/workspace/Dockerfile b/server/workspace/Dockerfile index fdb9340372..481e05948e 100644 --- a/server/workspace/Dockerfile +++ b/server/workspace/Dockerfile @@ -4,5 +4,7 @@ WORKDIR /usr/src/app COPY bundle.js ./ +ENV TRANSACTOR_URL ws://transactor/ + EXPOSE 8080 CMD [ "bash" ] diff --git a/server/workspace/package.json b/server/workspace/package.json index be38331deb..22e46b73fe 100644 --- a/server/workspace/package.json +++ b/server/workspace/package.json @@ -25,6 +25,8 @@ }, "dependencies": { "@anticrm/core": "~0.6.11", - "mongodb": "^4.1.0" + "mongodb": "^4.1.0", + "@anticrm/contrib": "~0.6.0", + "jwt-simple": "~0.5.6" } } diff --git a/server/workspace/src/__create.ts b/server/workspace/src/__create.ts index 2390e7ba7f..3ff2a6ec28 100644 --- a/server/workspace/src/__create.ts +++ b/server/workspace/src/__create.ts @@ -14,14 +14,20 @@ // limitations under the License. // -import { createModel } from '.' +import { createWorkspace } from '.' -const url = process.env.MONGO_URL -if (url === undefined) { +const mongoUrl = process.env.MONGO_URL +if (mongoUrl === undefined) { console.error('please provide mongodb url.') process.exit(1) } +const transactorUrl = process.env.TRANSACTOR_URL +if (transactorUrl === undefined) { + console.error('please provide transactor url.') + process.exit(1) +} + const db = process.argv[2] if (db === undefined) { console.error('Please specify the database.') @@ -29,6 +35,6 @@ if (db === undefined) { } console.log('creating model...') -createModel(url, db).then(rows => { - console.log(`done, ${rows} rows inserted.`) +createWorkspace(mongoUrl, db, transactorUrl).then(() => { + console.log(`done.`) }).catch(error => { console.error(error) }) diff --git a/server/workspace/src/index.ts b/server/workspace/src/index.ts index ed0bc13f93..dea730871a 100644 --- a/server/workspace/src/index.ts +++ b/server/workspace/src/index.ts @@ -15,25 +15,40 @@ // import { MongoClient, Document } from 'mongodb' -import { DOMAIN_TX } from '@anticrm/core' +import core, { DOMAIN_TX, Tx } from '@anticrm/core' +import { createContributingClient } from '@anticrm/contrib' +import { encode } from 'jwt-simple' import * as txJson from './model.tx.json' -const txes = (txJson as any).default - -console.log(txes) +const txes = (txJson as any).default as Tx[] /** * @public */ -export async function createModel (url: string, dbName: string): Promise { - const client = new MongoClient(url) +export async function createWorkspace (mongoUrl: string, dbName: string, clientUrl: string): Promise { + const client = new MongoClient(mongoUrl) try { await client.connect() const db = client.db(dbName) + + console.log('dropping database...') await db.dropDatabase() - const result = await db.collection(DOMAIN_TX).insertMany(txes as Document[]) - return result.insertedCount + + console.log('creating model...') + const model = txes.filter(tx => tx.objectSpace === core.space.Model) + const result = await db.collection(DOMAIN_TX).insertMany(model as Document[]) + console.log(`${result.insertedCount} model transactions inserted.`) + + console.log('creating data...') + const data = txes.filter(tx => tx.objectSpace !== core.space.Model) + const token = encode({ email: 'anticrm@hc.engineering', workspace: dbName }, 'secret') + const url = new URL(`/${token}`, clientUrl) + const contrib = await createContributingClient(url.href) + for (const tx of data) { + await contrib.tx(tx) + } + contrib.close() } finally { await client.close() }