diff --git a/api/components.ts b/api/components.ts index b6d068d9..17bc402b 100644 --- a/api/components.ts +++ b/api/components.ts @@ -20,3 +20,5 @@ export type {FeaturesConfig} from '../src/components/features/types'; export {isGatewayError} from '../src/components/gateway'; export {resolvePrivatePermissions} from '../src/components/private-permissions'; + +export {setRegistryToContext} from '../src/components/app-context'; diff --git a/src/components/app-context.ts b/src/components/app-context.ts new file mode 100644 index 00000000..191c48a8 --- /dev/null +++ b/src/components/app-context.ts @@ -0,0 +1,6 @@ +import type {NodeKit} from '@gravity-ui/nodekit'; +import type {Registry} from '../registry'; + +export function setRegistryToContext(nodekit: NodeKit, registry: R) { + nodekit.ctx.set('registry', registry as any); +} diff --git a/src/db/models/entry/index.ts b/src/db/models/entry/index.ts index 3538d3e5..9dd1b701 100644 --- a/src/db/models/entry/index.ts +++ b/src/db/models/entry/index.ts @@ -8,7 +8,6 @@ import {AppError} from '@gravity-ui/nodekit'; import * as MT from '../../../types/models'; import {validateCreateEntry, validateResolveTenantIdByEntryId} from './scheme'; import {RETURN_COLUMNS, BiTrackingLogs, US_ERRORS} from '../../../const'; -import {registry} from '../../../registry'; interface Entry extends MT.EntryColumns { revisions: any; // TODO: Figure out how to type a upsertGraph @@ -188,6 +187,8 @@ class Entry extends Model { dlContext, }); + const registry = ctx.get('registry'); + const {DLS} = registry.common.classes.get(); const isDeleted = false; @@ -578,6 +579,8 @@ class Entry extends Model { isPrivateRoute, }); + const registry = ctx.get('registry'); + const {DLS} = registry.common.classes.get(); const result = await transaction(this.primary, async (trx) => { @@ -691,6 +694,8 @@ class Entry extends Model { ctx, trx, }: MT.CheckExistenceEntriesWithInsufficientPermissions): Promise { + const registry = ctx.get('registry'); + const {DLS} = registry.common.classes.get(); const entriesWithPermissionsInfo = await DLS.checkBulkPermission( diff --git a/src/db/models/favorite/index.ts b/src/db/models/favorite/index.ts index 6fb6ca28..7997232d 100644 --- a/src/db/models/favorite/index.ts +++ b/src/db/models/favorite/index.ts @@ -13,7 +13,6 @@ import { validateRenameFavorite, } from './scheme'; import {RETURN_FAVORITES_COLUMNS, US_ERRORS} from '../../../const'; -import {registry} from '../../../registry'; import {getWorkbook} from '../../../services/new/workbook'; import {filterEntriesByPermission} from '../../../services/new/entry/utils'; @@ -174,6 +173,7 @@ class Favorite extends Model { dlContext, }); + const registry = ctx.get('registry'); const {DLS} = registry.common.classes.get(); const {login} = requestedBy; diff --git a/src/db/models/lock/index.ts b/src/db/models/lock/index.ts index fee5c7fe..c90a1329 100644 --- a/src/db/models/lock/index.ts +++ b/src/db/models/lock/index.ts @@ -7,7 +7,6 @@ import {AppContext, AppError} from '@gravity-ui/nodekit'; import * as MT from '../../../types/models'; import US_ERRORS from '../../../const/us-error-constants'; import {CURRENT_TIMESTAMP} from '../../../const'; -import {registry} from '../../../registry'; import {Entry} from '../new/entry'; import {WorkbookPermission} from '../../../entities/workbook'; import {getWorkbook} from '../../../services/new/workbook'; @@ -82,6 +81,7 @@ class Lock extends Model { tenantId: string; permission: 'read' | 'edit'; }) { + const registry = ctx.get('registry'); const {accessServiceEnabled} = ctx.config; const entry = await Entry.query(Entry.replica) diff --git a/src/index.ts b/src/index.ts index 611cb9f2..263277ef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,7 +17,9 @@ import { import {AppEnv} from './const'; import {registry} from './registry'; import {getRoutes} from './routes'; +import {setRegistryToContext} from './components/app-context'; +setRegistryToContext(nodekit, registry); registerAppPlugins(); const beforeAuth: AppMiddleware[] = []; diff --git a/src/registry/index.ts b/src/registry/index.ts index f7b08dbd..e4abc6a6 100644 --- a/src/registry/index.ts +++ b/src/registry/index.ts @@ -72,3 +72,5 @@ export const registry = { }, common: commonRegistry, }; + +export type Registry = typeof registry; diff --git a/src/services/color-palettes/create-color-palette.ts b/src/services/color-palettes/create-color-palette.ts index 81948b7c..06e03cdd 100644 --- a/src/services/color-palettes/create-color-palette.ts +++ b/src/services/color-palettes/create-color-palette.ts @@ -4,7 +4,6 @@ import {ServiceArgs} from '../../services/new/types'; import {makeSchemaValidator} from '../../components/validation-schema-compiler'; import {ColorPaletteModel, ColorPaletteModelColumn} from '../../db/models/new/color-palette'; import Utils from '../../utils'; -import {registry} from '../../registry'; import {getColorPalettesCount} from './get-color-palettes-count'; import {US_ERRORS} from '../../const'; @@ -53,6 +52,7 @@ export const createColorPalette = async ( isDefault, }); + const registry = ctx.get('registry'); const {colorPalettesAdminValidator} = registry.common.functions.get(); if (!skipValidation) { diff --git a/src/services/color-palettes/delete-color-palette.ts b/src/services/color-palettes/delete-color-palette.ts index c4e3e0d1..5debd78f 100644 --- a/src/services/color-palettes/delete-color-palette.ts +++ b/src/services/color-palettes/delete-color-palette.ts @@ -1,7 +1,6 @@ import {ServiceArgs} from '../../services/new/types'; import {makeSchemaValidator} from '../../components/validation-schema-compiler'; import {ColorPaletteModel, ColorPaletteModelColumn} from '../../db/models/new/color-palette'; -import {registry} from '../../registry'; const validateArgs = makeSchemaValidator({ type: 'object', @@ -27,6 +26,7 @@ export const deleteColorPalette = async ( colorPaletteId, }); + const registry = ctx.get('registry'); const {colorPalettesAdminValidator} = registry.common.functions.get(); if (!skipValidation) { diff --git a/src/services/entry/actions/copy-to-workbook.ts b/src/services/entry/actions/copy-to-workbook.ts index 4ee32899..685d1551 100644 --- a/src/services/entry/actions/copy-to-workbook.ts +++ b/src/services/entry/actions/copy-to-workbook.ts @@ -8,7 +8,6 @@ import {WorkbookModel} from '../../../db/models/new/workbook'; import {CTX} from '../../../types/models'; import {US_ERRORS, BiTrackingLogs} from '../../../const'; import Utils, {makeUserId} from '../../../utils'; -import {registry} from '../../../registry'; import {WorkbookPermission} from '../../../entities/workbook'; import {getParentIds} from '../../new/collection/utils/get-parents'; @@ -78,6 +77,7 @@ export const copyToWorkbook = async (ctx: CTX, params: Params) => { validateParams(params); const {tenantId, user} = ctx.get('info'); + const registry = ctx.get('registry'); const createdBy = makeUserId(user.userId); const targetTenantId = tenantIdOverride ?? tenantId; diff --git a/src/services/entry/actions/delete-entry.ts b/src/services/entry/actions/delete-entry.ts index 3a7f8b1b..54fff132 100644 --- a/src/services/entry/actions/delete-entry.ts +++ b/src/services/entry/actions/delete-entry.ts @@ -12,7 +12,6 @@ import {checkWorkbookPermission} from '../../new/workbook/utils'; import {markEntryAsDeleted} from '../crud'; import {checkEntry} from './check-entry'; import {ServiceArgs} from '../../new/types'; -import {registry} from '../../../registry'; const validateArgs = makeSchemaValidator({ type: 'object', @@ -47,6 +46,7 @@ export async function deleteEntry( lockToken, }); + const registry = ctx.get('registry'); const {DLS} = registry.common.classes.get(); if (!skipValidation) { diff --git a/src/services/entry/actions/get-entry-by-key.ts b/src/services/entry/actions/get-entry-by-key.ts index 149ea825..9c949a97 100644 --- a/src/services/entry/actions/get-entry-by-key.ts +++ b/src/services/entry/actions/get-entry-by-key.ts @@ -6,7 +6,6 @@ import {RETURN_COLUMNS, DEFAULT_QUERY_TIMEOUT, US_ERRORS} from '../../../const'; import Utils from '../../../utils'; import {makeSchemaValidator} from '../../../components/validation-schema-compiler'; import {checkEntry} from './check-entry'; -import {registry} from '../../../registry'; const validateGetEntryByKey = makeSchemaValidator({ type: 'object', @@ -53,6 +52,7 @@ export async function getEntryByKey( customErrorBypassEnabled = false, }: GetEntryByKeyData, ) { + const registry = ctx.get('registry'); const {tenantId, isPrivateRoute: infoIsPrivateRoute} = ctx.get('info'); const isPrivateRoute = customIsPrivateRoute || infoIsPrivateRoute; diff --git a/src/services/entry/actions/get-entry-relations.ts b/src/services/entry/actions/get-entry-relations.ts index 491c0f21..ab0a808a 100644 --- a/src/services/entry/actions/get-entry-relations.ts +++ b/src/services/entry/actions/get-entry-relations.ts @@ -8,7 +8,6 @@ import {makeSchemaValidator} from '../../../components/validation-schema-compile import {getWorkbook} from '../../new/workbook/get-workbook'; import {getEntryPermissionsByWorkbook} from '../../new/workbook/utils'; import {getRelatedEntries, RelationDirection} from './get-related-entries'; -import {registry} from '../../../registry'; import {getReplica} from '../../new/utils'; import {EntryScope} from '../../../db/models/new/entry/types'; @@ -55,10 +54,11 @@ export async function getEntryRelations( {ctx, trx, skipValidation = false}: ServiceArgs, args: GetEntryRelationsArgs, ) { - const {DLS} = registry.common.classes.get(); - + const registry = ctx.get('registry'); const {tenantId, isPrivateRoute} = ctx.get('info'); + const {DLS} = registry.common.classes.get(); + const { entryId, scope, diff --git a/src/services/entry/actions/get-entry-revisions.ts b/src/services/entry/actions/get-entry-revisions.ts index 122e2ace..06276089 100644 --- a/src/services/entry/actions/get-entry-revisions.ts +++ b/src/services/entry/actions/get-entry-revisions.ts @@ -14,7 +14,6 @@ import Utils from '../../../utils'; import {checkEntry} from './check-entry'; import {getWorkbook} from '../../new/workbook'; import {ServiceArgs} from '../../new/types'; -import {registry} from '../../../registry'; const validateArgs = makeSchemaValidator({ type: 'object', @@ -67,6 +66,7 @@ export async function getEntryRevisions( pageSize, }); + const registry = ctx.get('registry'); const {DLS} = registry.common.classes.get(); if (!skipValidation) { diff --git a/src/services/entry/actions/rename-entry.ts b/src/services/entry/actions/rename-entry.ts index fd15d54e..85df1398 100644 --- a/src/services/entry/actions/rename-entry.ts +++ b/src/services/entry/actions/rename-entry.ts @@ -9,7 +9,6 @@ import {getWorkbook} from '../../new/workbook/get-workbook'; import {checkWorkbookPermission} from '../../new/workbook/utils'; import {WorkbookPermission} from '../../../entities/workbook'; import {checkEntry} from './check-entry'; -import {registry} from '../../../registry'; const validateRenameEntry = makeSchemaValidator({ type: 'object', @@ -40,6 +39,7 @@ export const renameEntry = async (ctx: CTX, renameEntryData: RenameEntryData) => name, }); + const registry = ctx.get('registry'); const {DLS} = registry.common.classes.get(); const {accessServiceEnabled} = ctx.config; diff --git a/src/services/entry/actions/update-entry.ts b/src/services/entry/actions/update-entry.ts index f83820e3..e52fb2a1 100644 --- a/src/services/entry/actions/update-entry.ts +++ b/src/services/entry/actions/update-entry.ts @@ -26,7 +26,6 @@ import {checkWorkbookPermission} from '../../new/workbook/utils'; import {WorkbookPermission} from '../../../entities/workbook'; import {Optional} from 'utility-types'; import {checkEntry} from './check-entry'; -import {registry} from '../../../registry'; import {EntryScope} from '../../../db/models/new/entry/types'; import {EntryColumn} from '../../../db/models/new/entry'; @@ -132,6 +131,7 @@ export async function updateEntry(ctx: CTX, updateData: UpdateEntryData) { updateRevision, }); + const registry = ctx.get('registry'); const {DLS} = registry.common.classes.get(); const {accessServiceEnabled} = ctx.config; diff --git a/src/services/new/collection/create-collection.ts b/src/services/new/collection/create-collection.ts index 0984cebb..b09c3948 100644 --- a/src/services/new/collection/create-collection.ts +++ b/src/services/new/collection/create-collection.ts @@ -8,7 +8,6 @@ import {transaction} from 'objection'; import {US_ERRORS} from '../../../const'; import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/collection'; import Utils from '../../../utils'; -import {registry} from '../../../registry'; const validateArgs = makeSchemaValidator({ type: 'object', @@ -38,6 +37,8 @@ export const createCollection = async ( ) => { const {title, description, parentId} = args; + const registry = ctx.get('registry'); + ctx.log('CREATE_COLLECTION_START', { title, description, diff --git a/src/services/new/collection/get-collection-breadcrumbs.ts b/src/services/new/collection/get-collection-breadcrumbs.ts index f728c195..98824cbc 100644 --- a/src/services/new/collection/get-collection-breadcrumbs.ts +++ b/src/services/new/collection/get-collection-breadcrumbs.ts @@ -6,7 +6,6 @@ import {US_ERRORS} from '../../../const'; import {makeSchemaValidator} from '../../../components/validation-schema-compiler'; import Utils from '../../../utils'; import {CollectionPermission} from '../../../entities/collection'; -import {registry} from '../../../registry'; import {Feature, isEnabledFeature} from '../../../components/features'; const validateArgs = makeSchemaValidator({ @@ -30,6 +29,8 @@ export const getCollectionBreadcrumbs = async ( ) => { const {collectionId, includePermissionsInfo} = args; + const registry = ctx.get('registry'); + const {accessServiceEnabled} = ctx.config; ctx.log('GET_COLLECTION_BREADCRUMBS_START', { diff --git a/src/services/new/collection/get-collection-content.ts b/src/services/new/collection/get-collection-content.ts index b46e4983..35f63b24 100644 --- a/src/services/new/collection/get-collection-content.ts +++ b/src/services/new/collection/get-collection-content.ts @@ -9,7 +9,6 @@ import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/col import Utils from '../../../utils'; import {getWorkbooksList} from '../workbook'; import {getCollection} from './get-collection'; -import {registry} from '../../../registry'; import {Feature, isEnabledFeature} from '../../../components/features'; const validateArgs = makeSchemaValidator({ @@ -99,6 +98,7 @@ export const getCollectionContent = async ( validateArgs(args); } + const registry = ctx.get('registry'); const {accessServiceEnabled} = ctx.config; const {Workbook, Collection} = registry.common.classes.get(); const {bulkFetchCollectionsAllPermissions} = registry.common.functions.get(); diff --git a/src/services/new/collection/get-collection-root-permissions.ts b/src/services/new/collection/get-collection-root-permissions.ts index 23ea7095..a45f8c6c 100644 --- a/src/services/new/collection/get-collection-root-permissions.ts +++ b/src/services/new/collection/get-collection-root-permissions.ts @@ -2,7 +2,6 @@ import {AppError, AppContext} from '@gravity-ui/nodekit'; import {ServiceArgs} from '../types'; import {US_ERRORS} from '../../../const'; import {OrganizationPermission, ProjectPermission} from '../../../components/iam'; -import {registry} from '../../../registry'; import {Feature, isEnabledFeature} from '../../../components/features'; export const getRootCollectionPermissions = async ({ctx}: ServiceArgs) => { @@ -31,6 +30,7 @@ export const getRootCollectionPermissions = async ({ctx}: ServiceArgs) => { }; async function checkCreateCollectionInRoot(ctx: AppContext) { + const registry = ctx.get('registry'); const {checkOrganizationPermission, checkProjectPermission} = registry.common.functions.get(); try { if (isEnabledFeature(ctx, Feature.ProjectsEnabled)) { @@ -56,6 +56,7 @@ async function checkCreateCollectionInRoot(ctx: AppContext) { } async function checkCreateWorkbookInRoot(ctx: AppContext) { + const registry = ctx.get('registry'); const {checkOrganizationPermission, checkProjectPermission} = registry.common.functions.get(); try { if (isEnabledFeature(ctx, Feature.ProjectsEnabled)) { diff --git a/src/services/new/collection/get-collection.ts b/src/services/new/collection/get-collection.ts index d0ba058b..43d8a554 100644 --- a/src/services/new/collection/get-collection.ts +++ b/src/services/new/collection/get-collection.ts @@ -6,7 +6,6 @@ import {US_ERRORS} from '../../../const'; import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/collection'; import {CollectionPermission} from '../../../entities/collection'; import Utils from '../../../utils'; -import {registry} from '../../../registry'; import type {CollectionInstance} from '../../../registry/common/entities/collection/types'; import {checkAndSetCollectionPermission} from './utils'; @@ -73,6 +72,7 @@ export const getCollection = async { @@ -162,6 +162,7 @@ export const makeCollectionsWithParentsMap = async ( const parentsMap = makeParentsMap(parents); + const registry = ctx.get('registry'); const {Collection} = registry.common.classes.get(); models.forEach((model) => { diff --git a/src/services/new/entry/formatters/format-get-entry-response.ts b/src/services/new/entry/formatters/format-get-entry-response.ts index d309163f..ae98fe5f 100644 --- a/src/services/new/entry/formatters/format-get-entry-response.ts +++ b/src/services/new/entry/formatters/format-get-entry-response.ts @@ -1,11 +1,11 @@ import {CTX} from '../../../../types/models'; -import {registry} from '../../../../registry'; import {GetEntryResult} from '../../../../services/new/entry/get-entry'; export const formatGetEntryResponse = async (ctx: CTX, result: GetEntryResult) => { const {joinedEntryRevisionFavorite, permissions, includePermissionsInfo, includeLinks} = result; const {privatePermissions, onlyPublic} = ctx.get('info'); + const registry = ctx.get('registry'); let isHiddenUnversionedData = false; if (!privatePermissions.ownedScopes.includes(joinedEntryRevisionFavorite?.scope!)) { diff --git a/src/services/new/entry/get-entry-by-key.ts b/src/services/new/entry/get-entry-by-key.ts index 37392518..96d2c284 100644 --- a/src/services/new/entry/get-entry-by-key.ts +++ b/src/services/new/entry/get-entry-by-key.ts @@ -14,7 +14,6 @@ import OldEntry from '../../../db/models/entry'; import {getWorkbook} from '../workbook'; import {getEntryPermissionsByWorkbook} from '../workbook/utils'; import {validateTenantId} from './validators'; -import {registry} from '../../../registry'; const validateGetEntryByKey = makeSchemaValidator({ type: 'object', @@ -71,6 +70,7 @@ export const getEntryByKey = async ( customErrorBypassEnabled, }); + const registry = ctx.get('registry'); const {DLS} = registry.common.classes.get(); const {tenantId, isPrivateRoute: infoIsPrivateRoute} = ctx.get('info'); diff --git a/src/services/new/entry/get-entry-meta-private.ts b/src/services/new/entry/get-entry-meta-private.ts index 1eb4c8c9..4912f420 100644 --- a/src/services/new/entry/get-entry-meta-private.ts +++ b/src/services/new/entry/get-entry-meta-private.ts @@ -6,7 +6,6 @@ import {DlsActions} from '../../../types/models'; import {US_ERRORS} from '../../../const'; import Utils from '../../../utils'; import {getWorkbook} from '../workbook'; -import {registry} from '../../../registry'; export type GetEntryMetaPrivateArgs = { entryId: string; @@ -22,6 +21,7 @@ export const getEntryMetaPrivate = async ( entryId: Utils.encodeId(entryId), }); + const registry = ctx.get('registry'); const {DLS} = registry.common.classes.get(); const masterTokenReal = ctx.config.masterToken; diff --git a/src/services/new/entry/get-entry-meta.ts b/src/services/new/entry/get-entry-meta.ts index 06823335..f7753b83 100644 --- a/src/services/new/entry/get-entry-meta.ts +++ b/src/services/new/entry/get-entry-meta.ts @@ -9,7 +9,6 @@ import Utils from '../../../utils'; import {makeSchemaValidator} from '../../../components/validation-schema-compiler'; import {JoinedEntryRevision} from '../../../db/presentations/joined-entry-revision'; import {getWorkbook} from '../workbook'; -import {registry} from '../../../registry'; const validateArgs = makeSchemaValidator({ type: 'object', @@ -40,6 +39,7 @@ export const getEntryMeta = async ( entryId: Utils.encodeId(entryId), }); + const registry = ctx.get('registry'); const {DLS} = registry.common.classes.get(); if (!skipValidation) { diff --git a/src/services/new/entry/get-entry.ts b/src/services/new/entry/get-entry.ts index b140cc99..96e4adb0 100644 --- a/src/services/new/entry/get-entry.ts +++ b/src/services/new/entry/get-entry.ts @@ -15,7 +15,6 @@ import {makeSchemaValidator} from '../../../components/validation-schema-compile import OldEntry from '../../../db/models/entry'; import {getWorkbook} from '../workbook'; import {getEntryPermissionsByWorkbook} from '../workbook/utils'; -import {registry} from '../../../registry'; import {Feature, isEnabledFeature} from '../../../components/features'; const validateArgs = makeSchemaValidator({ @@ -71,6 +70,7 @@ export const getEntry = async ( includeLinks, }); + const registry = ctx.get('registry'); const {DLS} = registry.common.classes.get(); const {isPrivateRoute, user, onlyPublic, onlyMirrored} = ctx.get('info'); diff --git a/src/services/new/entry/utils/filter-entries-by-permission.ts b/src/services/new/entry/utils/filter-entries-by-permission.ts index 24a7801c..38db57cc 100644 --- a/src/services/new/entry/utils/filter-entries-by-permission.ts +++ b/src/services/new/entry/utils/filter-entries-by-permission.ts @@ -1,5 +1,4 @@ import {DlsActions, EntryScope} from '../../../../types/models'; -import {registry} from '../../../../registry'; import {getWorkbooksListByIds} from '../../workbook/get-workbooks-list-by-ids'; import {EntryPermissions} from '../types'; import {WorkbookInstance} from '../../../../registry/common/entities/workbook/types'; @@ -39,6 +38,7 @@ export const filterEntriesByPermission = async ( const {entries, permission = 'read', includePermissionsInfo} = args; const {isPrivateRoute} = ctx.get('info'); + const registry = ctx.get('registry'); let result: EntryWithPermissions[] = []; diff --git a/src/services/new/structure-item/get-structure-items.ts b/src/services/new/structure-item/get-structure-items.ts index aa43cdb0..bb6e657e 100644 --- a/src/services/new/structure-item/get-structure-items.ts +++ b/src/services/new/structure-item/get-structure-items.ts @@ -4,7 +4,6 @@ import {makeSchemaValidator} from '../../../components/validation-schema-compile import {CollectionPermission} from '../../../entities/collection'; import {CollectionModel} from '../../../db/models/new/collection'; import Utils from '../../../utils'; -import {registry} from '../../../registry'; import {Feature, isEnabledFeature} from '../../../components/features'; import {getCollection} from '../collection'; import {getParentIds} from '../collection/utils'; @@ -95,6 +94,7 @@ export const getStructureItems = async ( } const {accessServiceEnabled} = ctx.config; + const registry = ctx.get('registry'); const {Workbook, Collection} = registry.common.classes.get(); const targetTrx = getReplica(trx); diff --git a/src/services/new/structure-item/utils.ts b/src/services/new/structure-item/utils.ts index 37a36220..e68ebfb8 100644 --- a/src/services/new/structure-item/utils.ts +++ b/src/services/new/structure-item/utils.ts @@ -5,7 +5,6 @@ import Utils from '../../../utils'; import {WorkbookModel, WorkbookModelColumn} from '../../../db/models/new/workbook'; import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/collection'; import {AppContext, AppError} from '@gravity-ui/nodekit'; -import {registry} from '../../../registry'; import {isWorkbookInstance} from '../../../registry/common/entities/structure-item/types'; import {Feature, isEnabledFeature} from '../../../components/features'; import {WorkbookPermission} from '../../../entities/workbook'; @@ -132,6 +131,7 @@ export const processPermissions = async ({ let result; const {accessServiceEnabled} = ctx.config; + const registry = ctx.get('registry'); const {Workbook, Collection} = registry.common.classes.get(); if (accessServiceEnabled && !skipCheckPermissions) { @@ -224,6 +224,7 @@ const bulkFetchStructureItemsAllPermissions = async ( return []; } + const registry = ctx.get('registry'); const {bulkFetchCollectionsAllPermissions, bulkFetchWorkbooksAllPermissions} = registry.common.functions.get(); diff --git a/src/services/new/workbook/copy-workbook.ts b/src/services/new/workbook/copy-workbook.ts index 5fa8cb0d..11d9a32c 100644 --- a/src/services/new/workbook/copy-workbook.ts +++ b/src/services/new/workbook/copy-workbook.ts @@ -14,7 +14,6 @@ import {WorkbookPermission} from '../../../entities/workbook'; import Utils from '../../../utils'; import {copyToWorkbook} from '../../entry/actions'; import {getCollection} from '../collection'; -import {registry} from '../../../registry'; const validateArgs = makeSchemaValidator({ type: 'object', @@ -82,6 +81,7 @@ export const copyWorkbook = async ( user: {userId}, } = ctx.get('info'); + const registry = ctx.get('registry'); const {Workbook} = registry.common.classes.get(); const originWorkbookModel: Optional = await WorkbookModel.query(getReplica(trx)) diff --git a/src/services/new/workbook/create-workbook.ts b/src/services/new/workbook/create-workbook.ts index 1bfc2c13..f56a8dd3 100644 --- a/src/services/new/workbook/create-workbook.ts +++ b/src/services/new/workbook/create-workbook.ts @@ -8,7 +8,6 @@ import {transaction} from 'objection'; import {US_ERRORS} from '../../../const'; import {WorkbookModel, WorkbookModelColumn} from '../../../db/models/new/workbook'; import Utils from '../../../utils'; -import {registry} from '../../../registry'; const validateArgs = makeSchemaValidator({ type: 'object', @@ -56,6 +55,7 @@ export const createWorkbook = async ( projectId, isPrivateRoute, } = ctx.get('info'); + const registry = ctx.get('registry'); const targetTrx = getPrimary(trx); diff --git a/src/services/new/workbook/get-workbook.ts b/src/services/new/workbook/get-workbook.ts index 15982748..ecb101e0 100644 --- a/src/services/new/workbook/get-workbook.ts +++ b/src/services/new/workbook/get-workbook.ts @@ -7,7 +7,6 @@ import {US_ERRORS} from '../../../const'; import {WorkbookModel, WorkbookModelColumn} from '../../../db/models/new/workbook'; import {WorkbookPermission} from '../../../entities/workbook'; import Utils from '../../../utils'; -import {registry} from '../../../registry'; import {Feature, isEnabledFeature} from '../../../components/features'; import type {WorkbookInstance} from '../../../registry/common/entities/workbook/types'; @@ -71,6 +70,7 @@ export const getWorkbook = async }); } + const registry = ctx.get('registry'); const {Workbook} = registry.common.classes.get(); const workbook = new Workbook({ diff --git a/src/services/new/workbook/get-workbooks-list-by-ids.ts b/src/services/new/workbook/get-workbooks-list-by-ids.ts index 3a2c312c..93de57c1 100644 --- a/src/services/new/workbook/get-workbooks-list-by-ids.ts +++ b/src/services/new/workbook/get-workbooks-list-by-ids.ts @@ -3,7 +3,6 @@ import {makeSchemaValidator} from '../../../components/validation-schema-compile import {ServiceArgs} from '../types'; import {getReplica} from '../utils'; import Utils from '../../../utils'; -import {registry} from '../../../registry'; import {makeWorkbooksWithParentsMap} from '../collection/utils'; @@ -43,6 +42,7 @@ export const getWorkbooksListByIds = async ( }); const {tenantId, isPrivateRoute, projectId} = ctx.get('info'); + const registry = ctx.get('registry'); if (!skipValidation) { validateArgs(args); diff --git a/src/services/new/workbook/get-workbooks-list.ts b/src/services/new/workbook/get-workbooks-list.ts index bf44abec..6d9bdffc 100644 --- a/src/services/new/workbook/get-workbooks-list.ts +++ b/src/services/new/workbook/get-workbooks-list.ts @@ -9,7 +9,6 @@ import Utils from '../../../utils'; import {WorkbookPermission} from '../../../entities/workbook'; import {CollectionPermission} from '../../../entities/collection'; import {getParents} from '../collection/utils'; -import {registry} from '../../../registry'; import {Feature, isEnabledFeature} from '../../../components/features'; const validateArgs = makeSchemaValidator({ @@ -89,6 +88,7 @@ export const getWorkbooksList = async ( } const {accessServiceEnabled} = ctx.config; + const registry = ctx.get('registry'); const {Workbook, Collection} = registry.common.classes.get(); const {bulkFetchWorkbooksAllPermissions} = registry.common.functions.get(); diff --git a/src/services/new/workbook/move-workbook.ts b/src/services/new/workbook/move-workbook.ts index 16cf8457..bd7b592b 100644 --- a/src/services/new/workbook/move-workbook.ts +++ b/src/services/new/workbook/move-workbook.ts @@ -13,7 +13,6 @@ import Utils from '../../../utils'; import {WorkbookPermission} from '../../../entities/workbook'; import {CollectionPermission} from '../../../entities/collection'; import {getCollection} from '../collection'; -import {registry} from '../../../registry'; import {Feature, isEnabledFeature} from '../../../components/features'; const validateArgs = makeSchemaValidator({ @@ -59,6 +58,7 @@ export const moveWorkbook = async ( const { user: {userId}, } = ctx.get('info'); + const registry = ctx.get('registry'); const targetTrx = getPrimary(trx); diff --git a/src/utils/zitadel.ts b/src/utils/zitadel.ts index ad7c7e8a..dc9f8a72 100644 --- a/src/utils/zitadel.ts +++ b/src/utils/zitadel.ts @@ -3,7 +3,6 @@ import {Utils} from './utils'; import axios from 'axios'; import axiosRetry from 'axios-retry'; import {ZitadelUserRole} from '../types/zitadel'; -import {registry} from '../registry'; type IntrospectionResult = { active: boolean; @@ -51,6 +50,7 @@ export const introspect = async (ctx: AppContext, token?: string): Promise