From 513e9c3eb1541a9025d808b41eddbad9dc16002d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 10 Dec 2023 13:59:50 +0000 Subject: [PATCH 1/6] chore(deps): update dependency @ducanh2912/next-pwa to v10 --- web/apps/app/package.json | 2 +- web/apps/doprocess/package.json | 2 +- web/apps/web/package.json | 2 +- web/pnpm-lock.yaml | 56 +++++++++------------------------ 4 files changed, 18 insertions(+), 44 deletions(-) diff --git a/web/apps/app/package.json b/web/apps/app/package.json index 5e48a3a21a..e89ee50b30 100644 --- a/web/apps/app/package.json +++ b/web/apps/app/package.json @@ -72,7 +72,7 @@ }, "devDependencies": { "@axe-core/playwright": "4.8.2", - "@ducanh2912/next-pwa": "9.7.2", + "@ducanh2912/next-pwa": "10.0.0", "@next/bundle-analyzer": "14.0.4", "@playwright/test": "1.40.1", "@signalco/eslint-config-signalco": "workspace:*", diff --git a/web/apps/doprocess/package.json b/web/apps/doprocess/package.json index 49a942a19b..a152b03618 100644 --- a/web/apps/doprocess/package.json +++ b/web/apps/doprocess/package.json @@ -61,7 +61,7 @@ "devDependencies": { "@axe-core/playwright": "4.8.2", "@babel/core": "7.23.5", - "@ducanh2912/next-pwa": "9.7.2", + "@ducanh2912/next-pwa": "10.0.0", "@next/bundle-analyzer": "14.0.4", "@playwright/test": "1.40.1", "@signalco/eslint-config-signalco": "workspace:*", diff --git a/web/apps/web/package.json b/web/apps/web/package.json index fa362e8614..d91628531d 100644 --- a/web/apps/web/package.json +++ b/web/apps/web/package.json @@ -50,7 +50,7 @@ "devDependencies": { "@axe-core/playwright": "4.8.2", "@babel/core": "7.23.5", - "@ducanh2912/next-pwa": "9.7.2", + "@ducanh2912/next-pwa": "10.0.0", "@next/bundle-analyzer": "14.0.4", "@playwright/test": "1.40.1", "@signalco/eslint-config-signalco": "workspace:*", diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml index 3833910ed6..4084b8b955 100644 --- a/web/pnpm-lock.yaml +++ b/web/pnpm-lock.yaml @@ -172,8 +172,8 @@ importers: specifier: 4.8.2 version: 4.8.2(playwright-core@1.40.1) '@ducanh2912/next-pwa': - specifier: 9.7.2 - version: 9.7.2(next@14.0.4)(webpack@5.89.0) + specifier: 10.0.0 + version: 10.0.0(next@14.0.4)(webpack@5.89.0) '@next/bundle-analyzer': specifier: 14.0.4 version: 14.0.4 @@ -671,8 +671,8 @@ importers: specifier: 7.23.5 version: 7.23.5 '@ducanh2912/next-pwa': - specifier: 9.7.2 - version: 9.7.2(esbuild@0.19.8)(next@14.0.4)(webpack@5.89.0) + specifier: 10.0.0 + version: 10.0.0(esbuild@0.19.8)(next@14.0.4)(webpack@5.89.0) '@next/bundle-analyzer': specifier: 14.0.4 version: 14.0.4 @@ -1043,8 +1043,8 @@ importers: specifier: 7.23.5 version: 7.23.5 '@ducanh2912/next-pwa': - specifier: 9.7.2 - version: 9.7.2(next@14.0.4)(webpack@5.89.0) + specifier: 10.0.0 + version: 10.0.0(next@14.0.4)(webpack@5.89.0) '@next/bundle-analyzer': specifier: 14.0.4 version: 14.0.4 @@ -1507,13 +1507,6 @@ packages: playwright-core: 1.40.1 dev: true - /@babel/code-frame@7.22.13: - resolution: {integrity: sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/highlight': 7.22.20 - chalk: 2.4.2 - /@babel/code-frame@7.23.5: resolution: {integrity: sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA==} engines: {node: '>=6.9.0'} @@ -1754,14 +1747,6 @@ packages: transitivePeerDependencies: - supports-color - /@babel/highlight@7.22.20: - resolution: {integrity: sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/helper-validator-identifier': 7.22.20 - chalk: 2.4.2 - js-tokens: 4.0.0 - /@babel/highlight@7.23.4: resolution: {integrity: sha512-acGdbYSfp2WheJoJm/EBBBLh/ID8KDc64ISZ9DYtBmC8/Q204PZJLHyzeB5qMzJ5trcOkybd78M4x2KWsUq++A==} engines: {node: '>=6.9.0'} @@ -3549,14 +3534,14 @@ packages: superjson: 2.2.1 dev: true - /@ducanh2912/next-pwa@9.7.2(esbuild@0.19.8)(next@14.0.4)(webpack@5.89.0): - resolution: {integrity: sha512-KNdWIr8297L6TRyEeJQUzZqgP+m10GmaV6tacZ6wIcON9J+b6Nz34eLx6B5Q5mQKxqbYHTDayVoMRc2uuA/Ahg==} + /@ducanh2912/next-pwa@10.0.0(esbuild@0.19.8)(next@14.0.4)(webpack@5.89.0): + resolution: {integrity: sha512-6VWpF0IzP9Az9n0jmqL9XH8iWA6LYJrC72b8GDEn7Swfi1mR+hYPItNFKJnraqwJheIqeeZXIHAqs5/VdyDF5A==} peerDependencies: - next: '>=11.0.0' + next: '>=14.0.0' webpack: '>=5.9.0' dependencies: clean-webpack-plugin: 4.0.0(webpack@5.89.0) - fast-glob: 3.3.1 + fast-glob: 3.3.2 next: 14.0.4(@babel/core@7.23.5)(react-dom@18.2.0)(react@18.2.0)(sass@1.69.5) semver: 7.5.4 terser-webpack-plugin: 5.3.9(esbuild@0.19.8)(webpack@5.89.0) @@ -3573,14 +3558,14 @@ packages: - uglify-js dev: true - /@ducanh2912/next-pwa@9.7.2(next@14.0.4)(webpack@5.89.0): - resolution: {integrity: sha512-KNdWIr8297L6TRyEeJQUzZqgP+m10GmaV6tacZ6wIcON9J+b6Nz34eLx6B5Q5mQKxqbYHTDayVoMRc2uuA/Ahg==} + /@ducanh2912/next-pwa@10.0.0(next@14.0.4)(webpack@5.89.0): + resolution: {integrity: sha512-6VWpF0IzP9Az9n0jmqL9XH8iWA6LYJrC72b8GDEn7Swfi1mR+hYPItNFKJnraqwJheIqeeZXIHAqs5/VdyDF5A==} peerDependencies: - next: '>=11.0.0' + next: '>=14.0.0' webpack: '>=5.9.0' dependencies: clean-webpack-plugin: 4.0.0(webpack@5.89.0) - fast-glob: 3.3.1 + fast-glob: 3.3.2 next: 14.0.4(@babel/core@7.23.5)(react-dom@18.2.0)(react@18.2.0)(sass@1.69.5) semver: 7.5.4 terser-webpack-plugin: 5.3.9(webpack@5.89.0) @@ -11974,17 +11959,6 @@ packages: resolution: {integrity: sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==} dev: true - /fast-glob@3.3.1: - resolution: {integrity: sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==} - engines: {node: '>=8.6.0'} - dependencies: - '@nodelib/fs.stat': 2.0.5 - '@nodelib/fs.walk': 1.2.8 - glob-parent: 5.1.2 - merge2: 1.4.1 - micromatch: 4.0.5 - dev: true - /fast-glob@3.3.2: resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} engines: {node: '>=8.6.0'} @@ -15595,7 +15569,7 @@ packages: resolution: {integrity: sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==} engines: {node: '>=8'} dependencies: - '@babel/code-frame': 7.22.13 + '@babel/code-frame': 7.23.5 error-ex: 1.3.2 json-parse-even-better-errors: 2.3.1 lines-and-columns: 1.2.4 From cae8e6a36316e5efbc373e616aa4d19309f4a95a Mon Sep 17 00:00:00 2001 From: Aleksandar Toplek Date: Sun, 10 Dec 2023 19:07:18 +0100 Subject: [PATCH 2/6] chore(dx): Removed default nextpwa dest config --- web/apps/app/next.config.mjs | 1 - web/apps/doprocess/next.config.js | 1 - web/apps/web/next.config.mjs | 1 - 3 files changed, 3 deletions(-) diff --git a/web/apps/app/next.config.mjs b/web/apps/app/next.config.mjs index f8c9da0ab5..0a709a0d44 100644 --- a/web/apps/app/next.config.mjs +++ b/web/apps/app/next.config.mjs @@ -52,7 +52,6 @@ const componsedNextConfig = withBundleAnalyzer(nextConfig); const nextConfigFunction = async (phase) => { if (phase === PHASE_DEVELOPMENT_SERVER || phase === PHASE_PRODUCTION_BUILD) { const withPWA = (await import('@ducanh2912/next-pwa')).default({ - dest: 'public', buildExcludes: [/middleware-manifest.json$/, /chunks\/images\/.*$/], dynamicStartUrl: false, disable: isDevelopment diff --git a/web/apps/doprocess/next.config.js b/web/apps/doprocess/next.config.js index 378283d3f5..f2ed60c0b6 100644 --- a/web/apps/doprocess/next.config.js +++ b/web/apps/doprocess/next.config.js @@ -50,7 +50,6 @@ const componsedNextConfig = withBundleAnalyzer(nextConfig); const nextConfigFunction = async (phase) => { if (phase === PHASE_DEVELOPMENT_SERVER || phase === PHASE_PRODUCTION_BUILD) { const withPWA = (await import('@ducanh2912/next-pwa')).default({ - dest: 'public', buildExcludes: [/middleware-manifest.json$/, /chunks\/images\/.*$/], dynamicStartUrl: false, disable: isDevelopment, diff --git a/web/apps/web/next.config.mjs b/web/apps/web/next.config.mjs index b662459a04..28b1814398 100644 --- a/web/apps/web/next.config.mjs +++ b/web/apps/web/next.config.mjs @@ -49,7 +49,6 @@ const componsedNextConfig = withBundleAnalyzer(nextConfig); const nextConfigFunction = async (phase) => { if (phase === PHASE_DEVELOPMENT_SERVER || phase === PHASE_PRODUCTION_BUILD) { const withPWA = (await import('@ducanh2912/next-pwa')).default({ - dest: 'public', buildExcludes: [/middleware-manifest.json$/, /chunks\/images\/.*$/], disable: isDevelopment }); From f72308519b8d3f2234b1eff44e02d7dca1e20fe5 Mon Sep 17 00:00:00 2001 From: Aleksandar Toplek Date: Sun, 10 Dec 2023 19:27:03 +0100 Subject: [PATCH 3/6] feat(doprocess): Simplified in-app navigation --- .../doprocess/app/(rest)/(app)/layout.tsx | 4 +--- web/apps/doprocess/components/NavMenu.tsx | 16 +++++++------- web/apps/doprocess/components/PageNav.tsx | 4 ++-- .../doprocess/components/layouts/Sidebar.tsx | 21 ++++++++----------- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/web/apps/doprocess/app/(rest)/(app)/layout.tsx b/web/apps/doprocess/app/(rest)/(app)/layout.tsx index afa9b188dd..5a139111b3 100644 --- a/web/apps/doprocess/app/(rest)/(app)/layout.tsx +++ b/web/apps/doprocess/app/(rest)/(app)/layout.tsx @@ -1,13 +1,11 @@ import { PropsWithChildren } from 'react'; import { AppProviders } from '../../../components/providers/AppProviders'; -import { PageNav } from '../../../components/PageNav'; import { AppLayout } from '../../../components/layouts/AppLayout'; export default function RootLayout({ children }: PropsWithChildren) { return ( <> - -
+
{children} diff --git a/web/apps/doprocess/components/NavMenu.tsx b/web/apps/doprocess/components/NavMenu.tsx index 4298a4cbfe..414287bc1f 100644 --- a/web/apps/doprocess/components/NavMenu.tsx +++ b/web/apps/doprocess/components/NavMenu.tsx @@ -18,7 +18,7 @@ export const navLinks: NavLinkItem[] = [ // { href: KnownPages.Pricing, text: 'Pricing' } ]; -export function NavMenu({ cta }: { cta?: boolean; }) { +export function NavMenu() { return ( <> {navLinks.map(nl => ( @@ -31,14 +31,12 @@ export function NavMenu({ cta }: { cta?: boolean; }) { Start for free - {cta && ( - - )} + diff --git a/web/apps/doprocess/components/PageNav.tsx b/web/apps/doprocess/components/PageNav.tsx index cd78632a0f..71a2af561a 100644 --- a/web/apps/doprocess/components/PageNav.tsx +++ b/web/apps/doprocess/components/PageNav.tsx @@ -6,7 +6,7 @@ import { KnownPages } from '../src/knownPages'; import { NavMenu } from './NavMenu'; import DoProcessLogo from './brand/DoProcessLogo'; -export function PageNav({ fullWidth, cta }: { fullWidth?: boolean, cta?: boolean }) { +export function PageNav({ fullWidth }: { fullWidth?: boolean }) { return (
- + diff --git a/web/apps/doprocess/components/layouts/Sidebar.tsx b/web/apps/doprocess/components/layouts/Sidebar.tsx index 3e44f0a9f9..5dd73460b8 100644 --- a/web/apps/doprocess/components/layouts/Sidebar.tsx +++ b/web/apps/doprocess/components/layouts/Sidebar.tsx @@ -2,11 +2,12 @@ import { useEffect, useMemo } from 'react'; import { usePathname } from 'next/navigation'; +import { Typography } from '@signalco/ui-primitives/Typography'; import { ListItem } from '@signalco/ui-primitives/ListItem'; import { List } from '@signalco/ui-primitives/List'; -import { IconButton } from '@signalco/ui-primitives/IconButton'; import { cx } from '@signalco/ui-primitives/cx'; -import { FileText, ListTodo, Play, Right } from '@signalco/ui-icons'; +import { FileText, ListTodo, Play } from '@signalco/ui-icons'; +import { UserButton } from '../auth/UserButton'; import { KnownPages } from '../../src/knownPages'; export function Sidebar({ open, onOpenChange }: { open: boolean, onOpenChange?: (open: boolean) => void }) { @@ -29,16 +30,12 @@ export function Sidebar({ open, onOpenChange }: { open: boolean, onOpenChange?: 'group flex flex-row -mr-1 border-b md:h-full md:flex-col md:border-none', open && 'md:pl-2 md:gap-1' )}> - onOpenChange?.(!open)}> - - +
+ {open && Navigation} +
+ +
+
{links.map(({ href, label, Icon }) => ( Date: Sun, 10 Dec 2023 19:27:10 +0100 Subject: [PATCH 4/6] Update layout.tsx --- web/apps/doprocess/app/(rest)/(marketing)/layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/apps/doprocess/app/(rest)/(marketing)/layout.tsx b/web/apps/doprocess/app/(rest)/(marketing)/layout.tsx index 7a5397a394..73d7bce9fc 100644 --- a/web/apps/doprocess/app/(rest)/(marketing)/layout.tsx +++ b/web/apps/doprocess/app/(rest)/(marketing)/layout.tsx @@ -6,7 +6,7 @@ export default function RootMarketingLayout({ children, }: { }) { return ( <> - + {children} From 29d4089f6765d8528a13d83d858f369d417a83f0 Mon Sep 17 00:00:00 2001 From: Aleksandar Toplek Date: Mon, 11 Dec 2023 00:11:43 +0100 Subject: [PATCH 5/6] fix(doprocess): Don't show public processes, runs and documents in users list Closes #4063 --- web/apps/doprocess/src/lib/repo/documentsRepository.ts | 9 ++++++--- web/apps/doprocess/src/lib/repo/processesRepository.ts | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/web/apps/doprocess/src/lib/repo/documentsRepository.ts b/web/apps/doprocess/src/lib/repo/documentsRepository.ts index 9a6b085b09..aa6dd20fc2 100644 --- a/web/apps/doprocess/src/lib/repo/documentsRepository.ts +++ b/web/apps/doprocess/src/lib/repo/documentsRepository.ts @@ -4,10 +4,13 @@ import { document } from '../db/schema'; import { db } from '../db'; import { publicIdNext } from './shared'; -function documentSharedWithUser(userId: string | null) { - if (!userId) +function documentSharedWithUser(userId: string | null, includePublic = true) { + if (!userId && includePublic) return sql`"public" MEMBER OF(${document.sharedWithUsers})`; + if (userId && includePublic) + return sql`${userId} MEMBER OF(${document.sharedWithUsers})`; + return or( sql`${userId} MEMBER OF(${document.sharedWithUsers})`, sql`"public" MEMBER OF(${document.sharedWithUsers})`); @@ -44,7 +47,7 @@ export async function documentCreate(userId: string, name: string, basedOn?: str } export async function documentsGet(userId: string) { - return await db.select().from(document).where(documentSharedWithUser(userId)); + return await db.select().from(document).where(documentSharedWithUser(userId, false)); } export async function documentGet(userId: string | null, id: number) { diff --git a/web/apps/doprocess/src/lib/repo/processesRepository.ts b/web/apps/doprocess/src/lib/repo/processesRepository.ts index 784f5f301a..f6d0379969 100644 --- a/web/apps/doprocess/src/lib/repo/processesRepository.ts +++ b/web/apps/doprocess/src/lib/repo/processesRepository.ts @@ -5,10 +5,13 @@ import { TaskState, process, processRun, task, taskDefinition } from '../db/sche import { db } from '../db'; import { publicIdNext } from './shared'; -function processSharedWithUser(userId: string | null) { - if (userId == null) +function processSharedWithUser(userId: string | null, includePublic = true) { + if (userId == null && includePublic) return sql`"public" MEMBER OF(${process.sharedWithUsers})` + if (userId && !includePublic) + return sql`${userId} MEMBER OF(${process.sharedWithUsers})`; + return or( sql`${userId} MEMBER OF(${process.sharedWithUsers})`, sql`"public" MEMBER OF(${process.sharedWithUsers})` @@ -51,7 +54,7 @@ export async function getProcessRunTaskIdByPublicId(processPublicId: string, pro } export async function getProcesses(userId: string) { - return await db.select().from(process).where(processSharedWithUser(userId)); + return await db.select().from(process).where(processSharedWithUser(userId, false)); } export async function getProcess(userId: string | null, processId: number) { From 315c9d2c9c3bdafef9b645570f384eeac53d6291 Mon Sep 17 00:00:00 2001 From: Aleksandar Toplek Date: Mon, 11 Dec 2023 00:57:37 +0100 Subject: [PATCH 6/6] fix(doprocess): Creating new document for task definition would link to existing one Closes #4064 --- web/apps/doprocess/app/api/documents/route.ts | 2 +- .../[taskDefinitionId]/route.ts | 17 ++++++++----- web/apps/doprocess/src/lib/db/schema.ts | 14 +++++++---- .../src/lib/repo/documentsRepository.ts | 25 ++++++++++++++++--- .../src/lib/repo/processesRepository.ts | 24 +++++++++++++++--- web/apps/doprocess/src/lib/repo/shared.ts | 15 ++++++----- 6 files changed, 72 insertions(+), 25 deletions(-) diff --git a/web/apps/doprocess/app/api/documents/route.ts b/web/apps/doprocess/app/api/documents/route.ts index 47009a2378..a1c2cb5516 100644 --- a/web/apps/doprocess/app/api/documents/route.ts +++ b/web/apps/doprocess/app/api/documents/route.ts @@ -1,4 +1,4 @@ -import { documentCreate, documentGet, documentsGet, documentSetData } from '../../../src/lib/repo/documentsRepository'; +import { documentCreate, documentGet, documentsGet } from '../../../src/lib/repo/documentsRepository'; import { ensureUserId } from '../../../src/lib/auth/apiAuth'; export async function GET() { diff --git a/web/apps/doprocess/app/api/processes/[id]/task-definitions/[taskDefinitionId]/route.ts b/web/apps/doprocess/app/api/processes/[id]/task-definitions/[taskDefinitionId]/route.ts index 55b3b902ce..83b260f32e 100644 --- a/web/apps/doprocess/app/api/processes/[id]/task-definitions/[taskDefinitionId]/route.ts +++ b/web/apps/doprocess/app/api/processes/[id]/task-definitions/[taskDefinitionId]/route.ts @@ -44,30 +44,35 @@ export async function PUT(request: Request, { params }: { params: { id: string, const data = await request.json(); if (data != null && typeof data === 'object') { + // Update text (name) if ('text' in data && typeof data.text === 'string') { await changeTaskDefinitionText(userId, processId, taskDefinitionId, data.text); } + + // Update type if ('type' in data && typeof data.type === 'string') { - let typeData = 'typeData' in data && typeof data.typeData === 'string' ? data.typeData : null; - if (!typeData && data.type === 'document') { + const type = data.type; + let typeData = ('typeData' in data && typeof data.typeData === 'string') ? data.typeData : null; + if (!typeData && type === 'document') { const process = await getProcess(userId, processId); const taskDefinition = await getTaskDefinition(userId, processId, taskDefinitionId); - // TODO: Use publicId instead of internalId for dataType const documentName = [process?.name, taskDefinition?.text ?? 'New document'].filter(Boolean).join(' - '); const documentId = await documentCreate(userId, documentName); - const document = await documentGet(userId, Number(documentId)); + const document = await documentGet(userId, documentId); if (document) { typeData = document?.publicId; } - } else if (data.type === 'blank') { + } else if (type === 'blank') { typeData = 'blank'; } if (!typeData) { throw new Error('Invalid type'); } - await changeTaskDefinitionType(userId, processId, taskDefinitionId, data.type, typeData); + await changeTaskDefinitionType(userId, processId, taskDefinitionId, type, typeData); } + + // Update order if ('order' in data && typeof data.order === 'string') { await changeTaskDefinitionOrder(userId, processId, taskDefinitionId, data.order); } diff --git a/web/apps/doprocess/src/lib/db/schema.ts b/web/apps/doprocess/src/lib/db/schema.ts index 2a795b94e6..79b0bdfafd 100644 --- a/web/apps/doprocess/src/lib/db/schema.ts +++ b/web/apps/doprocess/src/lib/db/schema.ts @@ -1,9 +1,13 @@ import { datetime, index, int, json, mysqlTable, serial, text, uniqueIndex, varchar } from 'drizzle-orm/mysql-core'; import { relations, sql } from 'drizzle-orm'; +export const withPublicIdTable = { + publicId: varchar('public_id', { length: 32 }).notNull().unique(), +}; + export const process = mysqlTable('process', { id: serial('id').primaryKey(), - publicId: varchar('public_id', { length: 32 }).notNull().unique(), + ...withPublicIdTable, name: varchar('name', { length: 255 }).notNull(), sharedWithUsers: json('shared_with_users').$type().notNull(), createdBy: varchar('created_by', { length: 255 }).notNull(), @@ -18,7 +22,7 @@ export type Process = typeof process.$inferSelect; export const processRun = mysqlTable('process_run', { id: serial('id').primaryKey(), - publicId: varchar('public_id', { length: 32 }).notNull().unique(), + ...withPublicIdTable, processId: int('process_id').notNull(), name: varchar('name', { length: 255 }).notNull(), state: varchar('state', { length: 255 }).notNull(), @@ -35,7 +39,7 @@ export type ProcessRun = typeof processRun.$inferSelect; export const taskDefinition = mysqlTable('task_definition', { id: serial('id').primaryKey(), - publicId: varchar('public_id', { length: 32 }).notNull().unique(), + ...withPublicIdTable, processId: int('process_id').notNull(), text: text('text'), order: varchar('order', { length: 255 }).notNull(), @@ -54,7 +58,7 @@ export type TaskDefinition = typeof taskDefinition.$inferSelect; export const document = mysqlTable('document', { id: serial('id').primaryKey(), - publicId: varchar('public_id', { length: 32 }).notNull().unique(), + ...withPublicIdTable, name: text('name').notNull(), data: json('data'), sharedWithUsers: json('shared_with_users').$type().notNull(), @@ -81,7 +85,7 @@ export const taskDefinitionRelations = relations(taskDefinition, ({ one }) => ({ export const task = mysqlTable('task', { id: serial('id').primaryKey(), - publicId: varchar('public_id', { length: 32 }).notNull().unique(), + ...withPublicIdTable, processId: int('process_id').notNull(), runId: int('run_id').notNull(), taskDefinitionId: int('task_definition_id').notNull(), diff --git a/web/apps/doprocess/src/lib/repo/documentsRepository.ts b/web/apps/doprocess/src/lib/repo/documentsRepository.ts index aa6dd20fc2..60b3294703 100644 --- a/web/apps/doprocess/src/lib/repo/documentsRepository.ts +++ b/web/apps/doprocess/src/lib/repo/documentsRepository.ts @@ -17,11 +17,23 @@ function documentSharedWithUser(userId: string | null, includePublic = true) { } export async function getDocumentIdByPublicId(publicId: string) { - return firstOrDefault(await db.select({ id: document.id }).from(document).where(eq(document.publicId, publicId)))?.id; + return firstOrDefault(await db + .select({ id: document.id }) + .from(document) + .where( + eq(document.publicId, publicId)) + )?.id; } async function isDocumentSharedWithUser(userId: string, documentId: number) { - return (firstOrDefault(await db.select({ count: count() }).from(document).where(and(eq(document.id, documentId), documentSharedWithUser(userId))))?.count ?? 0) > 0; + return (firstOrDefault(await db + .select({ count: count() }) + .from(document) + .where( + and( + eq(document.id, documentId), + documentSharedWithUser(userId))) + )?.count ?? 0) > 0; } export async function documentCreate(userId: string, name: string, basedOn?: string) { @@ -38,6 +50,7 @@ export async function documentCreate(userId: string, name: string, basedOn?: str if (basedOnId) { const basedOnDocument = await documentGet(userId, basedOnId); if (basedOnDocument && typeof basedOnDocument.data === 'string') { + console.info('Copying document content from (public):', basedOnDocument.publicId, 'to (internal):', id); await documentSetData(userId, id, basedOnDocument.data); } } @@ -51,7 +64,13 @@ export async function documentsGet(userId: string) { } export async function documentGet(userId: string | null, id: number) { - return firstOrDefault(await db.select().from(document).where(and(eq(document.id, id), documentSharedWithUser(userId)))); + return firstOrDefault(await db + .select() + .from(document) + .where( + and( + eq(document.id, id), + documentSharedWithUser(userId)))); } export async function documentRename(userId: string, id: number, name: string) { diff --git a/web/apps/doprocess/src/lib/repo/processesRepository.ts b/web/apps/doprocess/src/lib/repo/processesRepository.ts index f6d0379969..2e4b22dbb8 100644 --- a/web/apps/doprocess/src/lib/repo/processesRepository.ts +++ b/web/apps/doprocess/src/lib/repo/processesRepository.ts @@ -22,7 +22,11 @@ async function isProcessSharedWithUser(userId: string | null, processId: number) return (firstOrDefault(await db .select({ count: count() }) .from(process) - .where(and(eq(process.id, processId), processSharedWithUser(userId))))?.count ?? 0) > 0; + .where( + and( + eq(process.id, processId), + processSharedWithUser(userId))) + )?.count ?? 0) > 0; } export async function getProcessIdByPublicId(publicId: string) { @@ -195,7 +199,13 @@ export async function getTaskDefinitions(userId: string | null, processId: numbe export async function getTaskDefinition(userId: string | null, processId: number, taskDefinitionId: number) { if (!await isProcessSharedWithUser(userId, processId)) throw new Error('Not found'); - return firstOrDefault(await db.select().from(taskDefinition).where(and(eq(taskDefinition.processId, processId), eq(taskDefinition.id, taskDefinitionId)))); + return firstOrDefault(await db + .select() + .from(taskDefinition) + .where( + and( + eq(taskDefinition.processId, processId), + eq(taskDefinition.id, taskDefinitionId)))); } async function getTaskDefinitionLastOrder(userId: string, processId: number) { @@ -226,11 +236,17 @@ export async function changeTaskDefinitionText(userId: string, processId: number await db.update(taskDefinition).set({ text, updatedBy: userId, updatedAt: new Date() }).where(and(eq(taskDefinition.processId, processId), eq(taskDefinition.id, id))); } -export async function changeTaskDefinitionType(userId: string, processId: number, id: number, type: string, typeData: string) { +export async function changeTaskDefinitionType(userId: string, processId: number, id: number, type: string, typeData: string | null) { if (!await isProcessSharedWithUser(userId, processId)) throw new Error('Not found'); // TODO: Check permissions - await db.update(taskDefinition).set({ type, typeData, updatedBy: userId, updatedAt: new Date() }).where(and(eq(taskDefinition.processId, processId), eq(taskDefinition.id, id))); + await db + .update(taskDefinition) + .set({ type: type, typeData: typeData, updatedBy: userId, updatedAt: new Date() }) + .where( + and( + eq(taskDefinition.processId, processId), + eq(taskDefinition.id, id))); } export async function changeTaskDefinitionOrder(userId: string, processId: number, id: number, order: string) { diff --git a/web/apps/doprocess/src/lib/repo/shared.ts b/web/apps/doprocess/src/lib/repo/shared.ts index 3d1bc2abab..e0e007f5d4 100644 --- a/web/apps/doprocess/src/lib/repo/shared.ts +++ b/web/apps/doprocess/src/lib/repo/shared.ts @@ -1,15 +1,18 @@ import { nanoid } from 'nanoid'; -import { sql, eq } from 'drizzle-orm'; +import { AnyMySqlTable } from 'drizzle-orm/mysql-core'; +import { count, sql } from 'drizzle-orm'; import { firstOrDefault } from '@signalco/js'; import { db } from '../db'; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export async function publicIdExists(entity: any, publicId: string) { - return (firstOrDefault(await db.select({ count: sql`count(*)` }).from(entity).where(eq(entity.publicId, publicId)))?.count ?? 0) > 0; +export async function publicIdExists(entity: AnyMySqlTable, publicId: string) { + return (firstOrDefault(await db + .select({ count: count() }) + .from(entity) + .where(sql`publicId = ${publicId}`) + )?.count ?? 0) > 0; } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export async function publicIdNext(entity: any, size = 21) { +export async function publicIdNext(entity: AnyMySqlTable, size = 21) { let publicId = undefined; while (!publicId || await publicIdExists(entity, publicId)) publicId = nanoid(size);