chore: fix ContentType usage (#2353)

* chore: fix ContentType usage

* chore: fix specs
This commit is contained in:
Karol Sójko
2023-07-12 13:53:29 +02:00
committed by GitHub
parent d057cdff84
commit 325737bfbd
247 changed files with 1092 additions and 1060 deletions

View File

@@ -12,7 +12,6 @@ import {
FeatureIdentifier,
NoteType,
} from '@standardnotes/features'
import { ContentType } from '@standardnotes/common'
import { GenericItem, SNComponent, Environment, Platform } from '@standardnotes/models'
import {
DesktopManagerInterface,
@@ -25,6 +24,7 @@ import { ItemManager } from '@Lib/Services/Items/ItemManager'
import { SNFeaturesService } from '@Lib/Services/Features/FeaturesService'
import { SNComponentManager } from './ComponentManager'
import { SNSyncService } from '../Sync/SyncService'
import { ContentType } from '@standardnotes/domain-core'
describe('featuresService', () => {
let itemManager: ItemManager
@@ -100,7 +100,7 @@ describe('featuresService', () => {
const nativeComponent = (identifier?: FeatureIdentifier, file_type?: FeatureDescription['file_type']) => {
return new SNComponent({
uuid: '789',
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
content: {
package_info: {
hosted_url: 'https://example.com/component',
@@ -115,7 +115,7 @@ describe('featuresService', () => {
const deprecatedComponent = () => {
return new SNComponent({
uuid: '789',
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
content: {
package_info: {
hosted_url: 'https://example.com/component',
@@ -129,7 +129,7 @@ describe('featuresService', () => {
const thirdPartyComponent = () => {
return new SNComponent({
uuid: '789',
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
content: {
local_url: 'sn://Extensions/non-native-identifier/dist/index.html',
hosted_url: 'https://example.com/component',
@@ -146,7 +146,7 @@ describe('featuresService', () => {
const permissions: ComponentPermission[] = [
{
name: ComponentAction.StreamContextItem,
content_types: [ContentType.Note],
content_types: [ContentType.TYPES.Note],
},
]
@@ -160,7 +160,7 @@ describe('featuresService', () => {
const permissions: ComponentPermission[] = [
{
name: ComponentAction.StreamItems,
content_types: [ContentType.Note],
content_types: [ContentType.TYPES.Note],
},
]
@@ -172,7 +172,7 @@ describe('featuresService', () => {
const permissions: ComponentPermission[] = [
{
name: ComponentAction.StreamItems,
content_types: [ContentType.Tag],
content_types: [ContentType.TYPES.Tag],
},
]
@@ -184,7 +184,7 @@ describe('featuresService', () => {
const permissions: ComponentPermission[] = [
{
name: ComponentAction.StreamItems,
content_types: [ContentType.Tag, ContentType.Note],
content_types: [ContentType.TYPES.Tag, ContentType.TYPES.Note],
},
]
@@ -196,7 +196,7 @@ describe('featuresService', () => {
const permissions: ComponentPermission[] = [
{
name: ComponentAction.StreamItems,
content_types: [ContentType.Tag, ContentType.FilesafeFileMetadata],
content_types: [ContentType.TYPES.Tag, ContentType.TYPES.FilesafeFileMetadata],
},
]
@@ -211,9 +211,9 @@ describe('featuresService', () => {
{
name: ComponentAction.StreamItems,
content_types: [
ContentType.FilesafeFileMetadata,
ContentType.FilesafeCredentials,
ContentType.FilesafeIntegration,
ContentType.TYPES.FilesafeFileMetadata,
ContentType.TYPES.FilesafeCredentials,
ContentType.TYPES.FilesafeIntegration,
],
},
]
@@ -229,9 +229,9 @@ describe('featuresService', () => {
{
name: ComponentAction.StreamItems,
content_types: [
ContentType.FilesafeFileMetadata,
ContentType.FilesafeCredentials,
ContentType.FilesafeIntegration,
ContentType.TYPES.FilesafeFileMetadata,
ContentType.TYPES.FilesafeCredentials,
ContentType.TYPES.FilesafeIntegration,
],
},
]
@@ -247,9 +247,9 @@ describe('featuresService', () => {
{
name: ComponentAction.StreamItems,
content_types: [
ContentType.FilesafeFileMetadata,
ContentType.FilesafeCredentials,
ContentType.FilesafeIntegration,
ContentType.TYPES.FilesafeFileMetadata,
ContentType.TYPES.FilesafeCredentials,
ContentType.TYPES.FilesafeIntegration,
],
},
]
@@ -290,7 +290,7 @@ describe('featuresService', () => {
const manager = createManager(Environment.Desktop, Platform.MacDesktop)
const component = new SNComponent({
uuid: '789',
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
content: {
hosted_url: 'https://example.com/component',
package_info: {

View File

@@ -1,7 +1,6 @@
import { AllowedBatchStreaming } from './Types'
import { SNPreferencesService } from '../Preferences/PreferencesService'
import { SNFeaturesService } from '@Lib/Services/Features/FeaturesService'
import { ContentType, DisplayStringForContentType } from '@standardnotes/common'
import { ItemManager } from '@Lib/Services/Items/ItemManager'
import {
ActionObserver,
@@ -41,6 +40,7 @@ import {
isMobileDevice,
MutatorClientInterface,
} from '@standardnotes/services'
import { ContentType } from '@standardnotes/domain-core'
const DESKTOP_URL_PREFIX = 'sn://'
const LOCAL_HOST = 'localhost'
@@ -223,7 +223,7 @@ export class SNComponentManager
addItemObserver(): void {
this.removeItemObserver = this.itemManager.addObserver<SNComponent>(
[ContentType.Component, ContentType.Theme],
[ContentType.TYPES.Component, ContentType.TYPES.Theme],
({ changed, inserted, removed, source }) => {
const items = [...changed, ...inserted]
this.handleChangedComponents(items, source)
@@ -654,12 +654,17 @@ export class SNComponentManager
if (!permission.content_types) {
return
}
permission.content_types.forEach((contentType) => {
const desc = DisplayStringForContentType(contentType)
permission.content_types.forEach((contentTypeString: string) => {
const contentTypeOrError = ContentType.create(contentTypeString)
if (contentTypeOrError.isFailed()) {
return
}
const contentType = contentTypeOrError.getValue()
const desc = contentType.getDisplayName()
if (desc) {
contentTypeStrings.push(`${desc}s`)
} else {
contentTypeStrings.push(`items of type ${contentType}`)
contentTypeStrings.push(`items of type ${contentType.value}`)
}
})
break

View File

@@ -52,7 +52,6 @@ import {
import { ComponentAction, ComponentPermission, ComponentArea, FindNativeFeature } from '@standardnotes/features'
import { ItemManager } from '@Lib/Services/Items/ItemManager'
import { UuidString } from '@Lib/Types/UuidString'
import { ContentType } from '@standardnotes/common'
import {
isString,
extendArray,
@@ -65,6 +64,7 @@ import {
sureSearchArray,
isNotUndefined,
} from '@standardnotes/utils'
import { ContentType } from '@standardnotes/domain-core'
type RunWithPermissionsCallback = (
componentUuid: UuidString,
@@ -88,7 +88,7 @@ const ReadwriteActions = [
type Writeable<T> = { -readonly [P in keyof T]: T[P] }
export class ComponentViewer implements ComponentViewerInterface {
private streamItems?: ContentType[]
private streamItems?: string[]
private streamContextItemOriginalMessage?: ComponentMessage
private streamItemsOriginalMessage?: ComponentMessage
private removeItemObserver: () => void
@@ -123,7 +123,7 @@ export class ComponentViewer implements ComponentViewerInterface {
actionObserver?: ActionObserver,
) {
this.removeItemObserver = this.itemManager.addObserver(
ContentType.Any,
ContentType.TYPES.Any,
({ changed, inserted, removed, source, sourceKey }) => {
if (this.dealloced) {
return
@@ -686,7 +686,7 @@ export class ComponentViewer implements ComponentViewerInterface {
if (item.locked) {
remove(responsePayloads, { uuid: item.uuid })
lockedCount++
if (item.content_type === ContentType.Note) {
if (item.content_type === ContentType.TYPES.Note) {
lockedNoteCount++
}
}
@@ -836,7 +836,7 @@ export class ComponentViewer implements ComponentViewerInterface {
const data = message.data as DeleteItemsMessageData
const items = data.items.filter((item) => AllowedBatchContentTypes.includes(item.content_type))
const requiredContentTypes = uniq(items.map((item) => item.content_type)).sort() as ContentType[]
const requiredContentTypes = uniq(items.map((item) => item.content_type)).sort()
const requiredPermissions: ComponentPermission[] = [
{

View File

@@ -1,7 +1,7 @@
import { ComponentArea, ComponentAction, FeatureIdentifier, LegacyFileSafeIdentifier } from '@standardnotes/features'
import { ComponentMessage, MessageData, OutgoingItemMessagePayload } from '@standardnotes/models'
import { UuidString } from '@Lib/Types/UuidString'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
/**
* Extensions allowed to batch stream AllowedBatchContentTypes
@@ -16,9 +16,9 @@ export const AllowedBatchStreaming = Object.freeze([
* Content types which are allowed to be managed/streamed in bulk by a component.
*/
export const AllowedBatchContentTypes = Object.freeze([
ContentType.FilesafeCredentials,
ContentType.FilesafeFileMetadata,
ContentType.FilesafeIntegration,
ContentType.TYPES.FilesafeCredentials,
ContentType.TYPES.FilesafeFileMetadata,
ContentType.TYPES.FilesafeIntegration,
])
export type StreamObserver = {