-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2055 from undb-io/release/v1.0.0-84
Release version v1.0.0-84
- Loading branch information
Showing
50 changed files
with
759 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"json.schemas": [ | ||
{ | ||
"fileMatch": ["packages/template/src/templates/*.base.json"], | ||
"url": "http://localhost:3721/api/template/base/schema.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { singleton } from "@undb/di" | ||
import { baseTemplateSchema } from "@undb/template" | ||
import Elysia from "elysia" | ||
|
||
@singleton() | ||
export class TemplateModule { | ||
route() { | ||
return new Elysia().get("/api/template/base/schema.json", () => { | ||
return baseTemplateSchema | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...reate-from-template/[shareId]/+layout.gql → ...)/create-from-share/[shareId]/+layout.gql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
query GetCreateFromTemplateData($shareId: ID!) { | ||
query GetCreateFromShareData($shareId: ID!) { | ||
space { | ||
id | ||
name | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { spaceIdSchema } from "@undb/space" | ||
import { z } from "@undb/zod" | ||
import { baseIdSchema, baseNameSchema } from "../value-objects" | ||
|
||
export const uniqueBaseDTO = z | ||
.object({ | ||
baseId: baseIdSchema, | ||
baseName: baseNameSchema, | ||
spaceId: spaceIdSchema, | ||
}) | ||
.partial() | ||
|
||
export type IUniqueBaseDTO = z.infer<typeof uniqueBaseDTO> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/command-handlers/src/handlers/create-from-share.command-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { checkPermission, injectSpaceMemberService, type ISpaceMemberService } from "@undb/authz" | ||
import { BaseId, injectBaseRepository, WithBaseId, WithBaseSpaceId, type IBaseRepository } from "@undb/base" | ||
import { CreateFromShareCommand } from "@undb/commands" | ||
import { getCurrentUserId, mustGetCurrentSpaceId } from "@undb/context/server" | ||
import { commandHandler } from "@undb/cqrs" | ||
import { singleton } from "@undb/di" | ||
import { type ICommandHandler } from "@undb/domain" | ||
import { createLogger } from "@undb/logger" | ||
import { injectShareRepository, WithShareId, type IShareRepository } from "@undb/share" | ||
import { injectTableService, type ITableService } from "@undb/table" | ||
|
||
@commandHandler(CreateFromShareCommand) | ||
@singleton() | ||
export class CreateFromShareCommandHandler implements ICommandHandler<CreateFromShareCommand, any> { | ||
private readonly logger = createLogger(CreateFromShareCommandHandler.name) | ||
|
||
constructor( | ||
@injectBaseRepository() | ||
private readonly baseRepository: IBaseRepository, | ||
@injectTableService() | ||
private readonly tableService: ITableService, | ||
@injectSpaceMemberService() | ||
private readonly spaceMemberService: ISpaceMemberService, | ||
@injectShareRepository() | ||
private readonly shareRepository: IShareRepository, | ||
) {} | ||
|
||
async execute(command: CreateFromShareCommand): Promise<any> { | ||
this.logger.debug("CreateFromShareCommandHandler execute command", command) | ||
const share = (await this.shareRepository.findOne(WithShareId.fromString(command.shareId))).expect( | ||
"Share not found", | ||
) | ||
|
||
if (share.target.type !== "base") { | ||
throw new Error("Share target is not base") | ||
} | ||
|
||
const baseId = share.target.id | ||
const spaceId = share.spaceId | ||
|
||
const userId = getCurrentUserId() | ||
const targetSpaceId = command.targetSpaceId ?? mustGetCurrentSpaceId() | ||
|
||
const member = (await this.spaceMemberService.getSpaceMember(userId, targetSpaceId)).expect("Member not found") | ||
checkPermission(member.props.role, ["base:create"]) | ||
|
||
const spec = new WithBaseId(new BaseId(baseId)).and(new WithBaseSpaceId(spaceId)) | ||
const base = (await this.baseRepository.findOne(spec)).expect("Base not found") | ||
|
||
const duplicatedBase = await this.tableService.duplicateBase(base, spaceId, targetSpaceId, { | ||
id: baseId, | ||
name: command.name, | ||
includeData: command.includeData, | ||
}) | ||
|
||
return duplicatedBase.id.value | ||
} | ||
} |
55 changes: 14 additions & 41 deletions
55
packages/command-handlers/src/handlers/create-from-template.command-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,31 @@ | ||
import { checkPermission, injectSpaceMemberService, type ISpaceMemberService } from "@undb/authz" | ||
import { BaseId, injectBaseRepository, WithBaseId, WithBaseSpaceId, type IBaseRepository } from "@undb/base" | ||
import { CreateFromTemplateCommand } from "@undb/commands" | ||
import { getCurrentUserId, mustGetCurrentSpaceId } from "@undb/context/server" | ||
import { CreateFromTemplateCommand, type ICreateFromTemplateCommandOutput } from "@undb/commands" | ||
import { mustGetCurrentSpaceId } from "@undb/context/server" | ||
import { commandHandler } from "@undb/cqrs" | ||
import { singleton } from "@undb/di" | ||
import { type ICommandHandler } from "@undb/domain" | ||
import { createLogger } from "@undb/logger" | ||
import { injectShareRepository, WithShareId, type IShareRepository } from "@undb/share" | ||
import { injectTableService, type ITableService } from "@undb/table" | ||
import { injectTemplateService, type ITemplateService, templates } from "@undb/template" | ||
|
||
@commandHandler(CreateFromTemplateCommand) | ||
@singleton() | ||
export class CreateFromTemplateCommandHandler implements ICommandHandler<CreateFromTemplateCommand, any> { | ||
export class CreateFromTemplateCommandHandler | ||
implements ICommandHandler<CreateFromTemplateCommand, ICreateFromTemplateCommandOutput> | ||
{ | ||
private readonly logger = createLogger(CreateFromTemplateCommandHandler.name) | ||
|
||
constructor( | ||
@injectBaseRepository() | ||
private readonly baseRepository: IBaseRepository, | ||
@injectTableService() | ||
private readonly tableService: ITableService, | ||
@injectSpaceMemberService() | ||
private readonly spaceMemberService: ISpaceMemberService, | ||
@injectShareRepository() | ||
private readonly shareRepository: IShareRepository, | ||
@injectTemplateService() | ||
private readonly templateService: ITemplateService, | ||
) {} | ||
|
||
async execute(command: CreateFromTemplateCommand): Promise<any> { | ||
this.logger.debug("CreateFromTemplateCommandHandler execute command", command) | ||
const share = (await this.shareRepository.findOne(WithShareId.fromString(command.shareId))).expect( | ||
"Share not found", | ||
) | ||
async execute(command: CreateFromTemplateCommand): Promise<ICreateFromTemplateCommandOutput> { | ||
this.logger.info(`create from template command received: ${command.templateName}`) | ||
|
||
if (share.target.type !== "base") { | ||
throw new Error("Share target is not base") | ||
} | ||
const template = templates["test"] | ||
|
||
const baseId = share.target.id | ||
const spaceId = share.spaceId | ||
const spaceId = mustGetCurrentSpaceId() | ||
const result = await this.templateService.createBase(template, spaceId) | ||
|
||
const userId = getCurrentUserId() | ||
const targetSpaceId = command.targetSpaceId ?? mustGetCurrentSpaceId() | ||
|
||
const member = (await this.spaceMemberService.getSpaceMember(userId, targetSpaceId)).expect("Member not found") | ||
checkPermission(member.props.role, ["base:create"]) | ||
|
||
const spec = new WithBaseId(new BaseId(baseId)).and(new WithBaseSpaceId(spaceId)) | ||
const base = (await this.baseRepository.findOne(spec)).expect("Base not found") | ||
|
||
const duplicatedBase = await this.tableService.duplicateBase(base, spaceId, targetSpaceId, { | ||
id: baseId, | ||
name: command.name, | ||
includeData: command.includeData, | ||
}) | ||
|
||
return duplicatedBase.id.value | ||
return { baseIds: result.map(({ base }) => base.id.value) } | ||
} | ||
} |
Oops, something went wrong.