From ccb59dbdea85463626049862340d811cfe28427d Mon Sep 17 00:00:00 2001 From: Jose Varela Date: Mon, 4 Oct 2021 14:12:54 +0100 Subject: [PATCH] import/export with js extension In order to support ESM, files need to be imported and exported with file extenstions. While Jest seems to support ESM via hack config, we are using ts-jest, so in order to make file extensions to work, we need a moduleNameMapper configuration that allows to remove the file extension, so jest can resolve properly. Related links: https://github.com/kulshekhar/ts-jest/discussions/2475 https://github.com/kulshekhar/ts-jest/issues/1057 https://dev.to/antongolub/ts-and-ts-jest-meet-type-module-5chc --- packages/sdk/.eslintrc.cjs | 9 +++++ packages/sdk/jest.config.js | 8 +++-- packages/sdk/package.json | 1 + packages/sdk/src/auth.ts | 2 +- packages/sdk/src/base/auth.ts | 10 +++--- packages/sdk/src/base/directus.ts | 28 ++++++++-------- packages/sdk/src/base/index.ts | 10 +++--- packages/sdk/src/base/items.ts | 6 ++-- packages/sdk/src/base/storage/base.ts | 2 +- packages/sdk/src/base/storage/index.ts | 6 ++-- packages/sdk/src/base/storage/localstorage.ts | 2 +- packages/sdk/src/base/storage/memory.ts | 2 +- .../sdk/src/base/transport/axios-transport.ts | 4 +-- packages/sdk/src/base/transport/index.ts | 2 +- packages/sdk/src/directus.ts | 18 +++++----- packages/sdk/src/handlers/activity.ts | 8 ++--- packages/sdk/src/handlers/collections.ts | 6 ++-- packages/sdk/src/handlers/comments.ts | 6 ++-- packages/sdk/src/handlers/extensions.ts | 2 +- packages/sdk/src/handlers/fields.ts | 6 ++-- packages/sdk/src/handlers/files.ts | 6 ++-- packages/sdk/src/handlers/folders.ts | 6 ++-- packages/sdk/src/handlers/graphql.ts | 2 +- packages/sdk/src/handlers/index.ts | 33 ++++++++++--------- packages/sdk/src/handlers/invites.ts | 4 +-- packages/sdk/src/handlers/me.ts | 6 ++-- packages/sdk/src/handlers/passwords.ts | 2 +- packages/sdk/src/handlers/permissions.ts | 6 ++-- packages/sdk/src/handlers/presets.ts | 6 ++-- packages/sdk/src/handlers/relations.ts | 6 ++-- packages/sdk/src/handlers/revisions.ts | 6 ++-- packages/sdk/src/handlers/roles.ts | 6 ++-- packages/sdk/src/handlers/server.ts | 2 +- packages/sdk/src/handlers/settings.ts | 6 ++-- packages/sdk/src/handlers/singleton.ts | 6 ++-- packages/sdk/src/handlers/tfa.ts | 4 +-- packages/sdk/src/handlers/users.ts | 10 +++--- packages/sdk/src/handlers/utils.ts | 4 +-- packages/sdk/src/index.ts | 21 +++++++----- packages/sdk/src/items.ts | 2 +- packages/sdk/src/singleton.ts | 2 +- packages/sdk/src/transport.ts | 2 +- packages/sdk/tests/base/auth.browser.test.ts | 4 +-- packages/sdk/tests/base/auth.node.test.ts | 4 +-- packages/sdk/tests/base/auth.test.ts | 4 +-- .../sdk/tests/base/directus.browser.test.ts | 2 +- packages/sdk/tests/base/directus.node.ts | 2 +- packages/sdk/tests/base/directus.test.ts | 18 +++++----- .../tests/base/storage/localstorage.test.ts | 4 +-- .../sdk/tests/base/storage/memory.test.ts | 4 +-- packages/sdk/tests/base/storage/tests.ts | 2 +- .../sdk/tests/base/transport/axios.test.ts | 5 +-- packages/sdk/tests/blog.d.ts | 2 +- packages/sdk/tests/handlers/comments.test.ts | 4 +-- packages/sdk/tests/handlers/fields.test.ts | 4 +-- packages/sdk/tests/handlers/invites.test.ts | 4 +-- packages/sdk/tests/handlers/me.test.ts | 4 +-- packages/sdk/tests/handlers/passwords.test.ts | 4 +-- packages/sdk/tests/handlers/server.test.ts | 4 +-- packages/sdk/tests/handlers/tfa.test.ts | 4 +-- packages/sdk/tests/handlers/utils.test.ts | 5 ++- packages/sdk/tests/items.test.ts | 6 ++-- packages/sdk/tests/singleton.test.ts | 4 +-- packages/sdk/tests/utils.test.ts | 4 +-- packages/sdk/tsconfig.json | 6 +++- 65 files changed, 205 insertions(+), 185 deletions(-) create mode 100644 packages/sdk/.eslintrc.cjs diff --git a/packages/sdk/.eslintrc.cjs b/packages/sdk/.eslintrc.cjs new file mode 100644 index 0000000000000..b3cf69a17fa91 --- /dev/null +++ b/packages/sdk/.eslintrc.cjs @@ -0,0 +1,9 @@ +const parentConfig = require('../../.eslintrc.js'); + +module.exports = { + ...parentConfig, + parserOptions: { + ...parentConfig.parserOptions, + sourceType: 'module', + }, +}; diff --git a/packages/sdk/jest.config.js b/packages/sdk/jest.config.js index 28f2e5336b12f..918c1c0a78073 100644 --- a/packages/sdk/jest.config.js +++ b/packages/sdk/jest.config.js @@ -1,10 +1,14 @@ -require('dotenv').config(); +import { config as dotenv } from 'dotenv'; +dotenv(); -module.exports = { +export default { preset: 'ts-jest', verbose: true, setupFiles: ['dotenv/config'], testURL: process.env.TEST_URL || 'http://localhost', collectCoverageFrom: ['src/**/*.ts'], testPathIgnorePatterns: ['dist'], + moduleNameMapper: { + '^@/(.*).js$': '/$1', + }, }; diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 55aef9221705a..8fdcd9b9c03f2 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -16,6 +16,7 @@ "files": [ "dist" ], + "type": "module", "scripts": { "prebuild": "npm run cleanup", "build": "run-p build:*", diff --git a/packages/sdk/src/auth.ts b/packages/sdk/src/auth.ts index 87f225b6b80a7..271557fab3020 100644 --- a/packages/sdk/src/auth.ts +++ b/packages/sdk/src/auth.ts @@ -1,4 +1,4 @@ -import { PasswordsHandler } from './handlers/passwords'; +import { PasswordsHandler } from '@/src/handlers/passwords.js'; export type AuthCredentials = { email: string; diff --git a/packages/sdk/src/base/auth.ts b/packages/sdk/src/base/auth.ts index 1351d490cfbe7..fbfafad4daea7 100644 --- a/packages/sdk/src/base/auth.ts +++ b/packages/sdk/src/base/auth.ts @@ -1,8 +1,8 @@ -import { AuthCredentials, AuthLoginOptions, AuthRefreshOptions, AuthResult, AuthToken, IAuth } from '../auth'; -import { PasswordsHandler } from '../handlers/passwords'; -import { IStorage } from '../storage'; -import { ITransport } from '../transport'; -import { Debouncer } from '../utils'; +import { AuthCredentials, AuthLoginOptions, AuthRefreshOptions, AuthResult, AuthToken, IAuth } from '@/src/auth.js'; +import { PasswordsHandler } from '@/src/handlers/passwords.js'; +import { IStorage } from '@/src/storage.js'; +import { ITransport } from '@/src/transport.js'; +import { Debouncer } from '@/src/utils.js'; export type AuthOptions = { mode?: 'json' | 'cookie'; diff --git a/packages/sdk/src/base/directus.ts b/packages/sdk/src/base/directus.ts index cca25abc277d2..b4a5f6c2782eb 100644 --- a/packages/sdk/src/base/directus.ts +++ b/packages/sdk/src/base/directus.ts @@ -1,5 +1,5 @@ -import { IAuth } from '../auth'; -import { IDirectus } from '../directus'; +import { IAuth } from '@/src/auth.js'; +import { IDirectus } from '@/src/directus.js'; import { ActivityHandler, CollectionsHandler, @@ -15,18 +15,18 @@ import { SettingsHandler, UsersHandler, UtilsHandler, -} from '../handlers'; -import { IItems } from '../items'; -import { ITransport } from '../transport'; -import { ItemsHandler } from './items'; -import { AxiosTransport } from './transport'; -import { Auth } from './auth'; -import { IStorage } from '../storage'; -import { LocalStorage, MemoryStorage } from './storage'; -import { TypeMap, TypeOf } from '../types'; -import { GraphQLHandler } from '../handlers/graphql'; -import { ISingleton } from '../singleton'; -import { SingletonHandler } from '../handlers/singleton'; +} from '@/src/handlers/index.js'; +import { IItems } from '@/src/items.js'; +import { ITransport } from '@/src/transport.js'; +import { ItemsHandler } from '@/src/base/items.js'; +import { AxiosTransport } from '@/src/base/transport/index.js'; +import { Auth } from '@/src/base/auth.js'; +import { IStorage } from '@/src/storage.js'; +import { LocalStorage, MemoryStorage } from '@/src/base/storage/index.js'; +import { TypeMap, TypeOf } from '@/src/types.js'; +import { GraphQLHandler } from '@/src/handlers/graphql.js'; +import { ISingleton } from '@/src/singleton.js'; +import { SingletonHandler } from '@/src/handlers/singleton.js'; export type DirectusOptions = { auth?: IAuth; diff --git a/packages/sdk/src/base/index.ts b/packages/sdk/src/base/index.ts index 6bf9107f219a3..deb9cb2db2ead 100644 --- a/packages/sdk/src/base/index.ts +++ b/packages/sdk/src/base/index.ts @@ -1,6 +1,6 @@ -export * from './storage'; -export * from './transport'; +export * from '@/src/base/storage/index.js'; +export * from '@/src/base/transport/index.js'; -export * from './auth'; -export * from './directus'; -export * from './items'; +export * from '@/src/base/auth.js'; +export * from '@/src/base/directus.js'; +export * from '@/src/base/items.js'; diff --git a/packages/sdk/src/base/items.ts b/packages/sdk/src/base/items.ts index 3861dcd8a9048..6da14f02e7b33 100644 --- a/packages/sdk/src/base/items.ts +++ b/packages/sdk/src/base/items.ts @@ -1,6 +1,6 @@ -import { ITransport } from '../transport'; -import { IItems, Item, QueryOne, QueryMany, OneItem, ManyItems, PartialItem } from '../items'; -import { ID } from '../types'; +import { ITransport } from '@/src/transport.js'; +import { IItems, Item, QueryOne, QueryMany, OneItem, ManyItems, PartialItem } from '@/src/items.js'; +import { ID } from '@/src/types.js'; export class ItemsHandler implements IItems { protected transport: ITransport; diff --git a/packages/sdk/src/base/storage/base.ts b/packages/sdk/src/base/storage/base.ts index df27a23915943..fd9ab0df09601 100644 --- a/packages/sdk/src/base/storage/base.ts +++ b/packages/sdk/src/base/storage/base.ts @@ -1,4 +1,4 @@ -import { IStorage } from '../../storage'; +import { IStorage } from '@/src/storage.js'; export abstract class BaseStorage implements IStorage { get auth_token(): string | null { diff --git a/packages/sdk/src/base/storage/index.ts b/packages/sdk/src/base/storage/index.ts index 8b5add0743711..dacd7896656d9 100644 --- a/packages/sdk/src/base/storage/index.ts +++ b/packages/sdk/src/base/storage/index.ts @@ -1,3 +1,3 @@ -export * from './base'; -export * from './memory'; -export * from './localstorage'; +export * from '@/src/base/storage/base.js'; +export * from '@/src/base/storage/memory.js'; +export * from '@/src/base/storage/localstorage.js'; diff --git a/packages/sdk/src/base/storage/localstorage.ts b/packages/sdk/src/base/storage/localstorage.ts index f425852de575c..5dc2b9162dae7 100644 --- a/packages/sdk/src/base/storage/localstorage.ts +++ b/packages/sdk/src/base/storage/localstorage.ts @@ -1,4 +1,4 @@ -import { BaseStorage } from './base'; +import { BaseStorage } from '@/src/base/storage/base.js'; export class LocalStorage extends BaseStorage { private prefix: string; diff --git a/packages/sdk/src/base/storage/memory.ts b/packages/sdk/src/base/storage/memory.ts index 7f41e0d2722e9..d6a8710e4ae88 100644 --- a/packages/sdk/src/base/storage/memory.ts +++ b/packages/sdk/src/base/storage/memory.ts @@ -1,4 +1,4 @@ -import { BaseStorage } from './base'; +import { BaseStorage } from '@/src/base/storage/base.js'; export class MemoryStorage extends BaseStorage { private prefix: string; diff --git a/packages/sdk/src/base/transport/axios-transport.ts b/packages/sdk/src/base/transport/axios-transport.ts index bf653a71439b2..831b80bbbfc97 100644 --- a/packages/sdk/src/base/transport/axios-transport.ts +++ b/packages/sdk/src/base/transport/axios-transport.ts @@ -1,6 +1,6 @@ -import { IStorage } from '../../storage'; +import { IStorage } from '@/src/storage.js'; import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios'; -import { ITransport, TransportMethods, TransportResponse, TransportError, TransportOptions } from '../../transport'; +import { ITransport, TransportMethods, TransportResponse, TransportError, TransportOptions } from '@/src/transport.js'; export type AxiosTransportRefreshHandler = () => Promise; diff --git a/packages/sdk/src/base/transport/index.ts b/packages/sdk/src/base/transport/index.ts index edb55d776fcb3..dd9619601820b 100644 --- a/packages/sdk/src/base/transport/index.ts +++ b/packages/sdk/src/base/transport/index.ts @@ -1 +1 @@ -export * from './axios-transport'; +export * from '@/src/base/transport/axios-transport.js'; diff --git a/packages/sdk/src/directus.ts b/packages/sdk/src/directus.ts index e80a688b0c759..10f05c05bf77f 100644 --- a/packages/sdk/src/directus.ts +++ b/packages/sdk/src/directus.ts @@ -1,4 +1,4 @@ -import { IAuth } from './auth'; +import { IAuth } from '@/src/auth.js'; import { ActivityHandler, CollectionsHandler, @@ -13,15 +13,15 @@ import { ServerHandler, SettingsHandler, UsersHandler, -} from './handlers'; +} from '@/src/handlers/index.js'; -import { IItems } from './items'; -import { ITransport } from './transport'; -import { UtilsHandler } from './handlers/utils'; -import { IStorage } from './storage'; -import { TypeMap, TypeOf } from './types'; -import { GraphQLHandler } from './handlers/graphql'; -import { ISingleton } from './singleton'; +import { IItems } from '@/src/items.js'; +import { ITransport } from '@/src/transport.js'; +import { UtilsHandler } from '@/src/handlers/utils.js'; +import { IStorage } from '@/src/storage.js'; +import { TypeMap, TypeOf } from '@/src/types.js'; +import { GraphQLHandler } from '@/src/handlers/graphql.js'; +import { ISingleton } from '@/src/singleton.js'; export type DirectusTypes = { activity: undefined; diff --git a/packages/sdk/src/handlers/activity.ts b/packages/sdk/src/handlers/activity.ts index 32f7e0f5a6461..92767c176eaa6 100644 --- a/packages/sdk/src/handlers/activity.ts +++ b/packages/sdk/src/handlers/activity.ts @@ -2,10 +2,10 @@ * Activity handler */ -import { ItemsHandler } from '../base/items'; -import { ITransport } from '../transport'; -import { ActivityType, DefaultType } from '../types'; -import { CommentsHandler } from './comments'; +import { ItemsHandler } from '@/src/base/items.js'; +import { ITransport } from '@/src/transport.js'; +import { ActivityType, DefaultType } from '@/src/types.js'; +import { CommentsHandler } from '@/src/handlers/comments.js'; export type ActivityItem = ActivityType & T; diff --git a/packages/sdk/src/handlers/collections.ts b/packages/sdk/src/handlers/collections.ts index 34a20b051ac96..48042c2d1eea0 100644 --- a/packages/sdk/src/handlers/collections.ts +++ b/packages/sdk/src/handlers/collections.ts @@ -2,9 +2,9 @@ * Collections handler */ -import { ManyItems, OneItem, PartialItem, QueryOne } from '../items'; -import { ITransport } from '../transport'; -import { CollectionType, DefaultType } from '../types'; +import { ManyItems, OneItem, PartialItem, QueryOne } from '@/src/items.js'; +import { ITransport } from '@/src/transport.js'; +import { CollectionType, DefaultType } from '@/src/types.js'; export type CollectionItem = CollectionType & T; diff --git a/packages/sdk/src/handlers/comments.ts b/packages/sdk/src/handlers/comments.ts index 381f5eaa41b42..0c9bb1d5dd58f 100644 --- a/packages/sdk/src/handlers/comments.ts +++ b/packages/sdk/src/handlers/comments.ts @@ -1,6 +1,6 @@ -import { Comment, ID } from '../types'; -import { ITransport } from '../transport'; -import { ActivityItem } from './activity'; +import { Comment, ID } from '@/src/types.js'; +import { ITransport } from '@/src/transport.js'; +import { ActivityItem } from '@/src/handlers/activity.js'; export class CommentsHandler { private transport: ITransport; diff --git a/packages/sdk/src/handlers/extensions.ts b/packages/sdk/src/handlers/extensions.ts index 4b697b034880a..f1935e4c5e603 100644 --- a/packages/sdk/src/handlers/extensions.ts +++ b/packages/sdk/src/handlers/extensions.ts @@ -2,7 +2,7 @@ * Settings handler */ -import { ITransport, TransportOptions, TransportResponse } from '../transport'; +import { ITransport, TransportOptions, TransportResponse } from '@/src/transport.js'; export class ExtensionEndpoint implements ITransport { private name: string; diff --git a/packages/sdk/src/handlers/fields.ts b/packages/sdk/src/handlers/fields.ts index 07dd84b532eea..5e1d93994486e 100644 --- a/packages/sdk/src/handlers/fields.ts +++ b/packages/sdk/src/handlers/fields.ts @@ -2,9 +2,9 @@ * Fields handler */ -import { ManyItems, OneItem, PartialItem } from '../items'; -import { ITransport } from '../transport'; -import { FieldType, DefaultType, ID } from '../types'; +import { ManyItems, OneItem, PartialItem } from '@/src/items.js'; +import { ITransport } from '@/src/transport.js'; +import { FieldType, DefaultType, ID } from '@/src/types.js'; export type FieldItem = FieldType & T; diff --git a/packages/sdk/src/handlers/files.ts b/packages/sdk/src/handlers/files.ts index 8c1d7f9be99ea..a3387cc17d7d1 100644 --- a/packages/sdk/src/handlers/files.ts +++ b/packages/sdk/src/handlers/files.ts @@ -2,9 +2,9 @@ * Files handler */ -import { ItemsHandler } from '../base/items'; -import { ITransport } from '../transport'; -import { FileType, DefaultType } from '../types'; +import { ItemsHandler } from '@/src/base/items.js'; +import { ITransport } from '@/src/transport.js'; +import { FileType, DefaultType } from '@/src/types.js'; export type FileItem = FileType & T; diff --git a/packages/sdk/src/handlers/folders.ts b/packages/sdk/src/handlers/folders.ts index 585a14708349f..b00f57c1c28e2 100644 --- a/packages/sdk/src/handlers/folders.ts +++ b/packages/sdk/src/handlers/folders.ts @@ -2,9 +2,9 @@ * Folders handler */ -import { ItemsHandler } from '../base/items'; -import { ITransport } from '../transport'; -import { FolderType, DefaultType } from '../types'; +import { ItemsHandler } from '@/src/base/items.js'; +import { ITransport } from '@/src/transport.js'; +import { FolderType, DefaultType } from '@/src/types.js'; export type FolderItem = FolderType & T; diff --git a/packages/sdk/src/handlers/graphql.ts b/packages/sdk/src/handlers/graphql.ts index 96033b7596c77..349fb5b4e24e4 100644 --- a/packages/sdk/src/handlers/graphql.ts +++ b/packages/sdk/src/handlers/graphql.ts @@ -1,4 +1,4 @@ -import { ITransport, TransportResponse } from '../transport'; +import { ITransport, TransportResponse } from '@/src/transport.js'; export class GraphQLHandler { private transport: ITransport; diff --git a/packages/sdk/src/handlers/index.ts b/packages/sdk/src/handlers/index.ts index b55f71eb611f5..b8b8045ed9ce3 100644 --- a/packages/sdk/src/handlers/index.ts +++ b/packages/sdk/src/handlers/index.ts @@ -1,15 +1,18 @@ -export * from './activity'; -export * from './comments'; -export * from './collections'; -export * from './fields'; -export * from './files'; -export * from './folders'; -export * from './permissions'; -export * from './presets'; -export * from './relations'; -export * from './revisions'; -export * from './roles'; -export * from './server'; -export * from './settings'; -export * from './users'; -export * from './utils'; +export * from '@/src/handlers/activity.js'; +export * from '@/src/handlers/collections.js'; +export * from '@/src/handlers/comments.js'; +export * from '@/src/handlers/fields.js'; +export * from '@/src/handlers/files.js'; +export * from '@/src/handlers/folders.js'; +export * from '@/src/handlers/invites.js'; +export * from '@/src/handlers/me.js'; +export * from '@/src/handlers/permissions.js'; +export * from '@/src/handlers/presets.js'; +export * from '@/src/handlers/relations.js'; +export * from '@/src/handlers/revisions.js'; +export * from '@/src/handlers/roles.js'; +export * from '@/src/handlers/server.js'; +export * from '@/src/handlers/settings.js'; +export * from '@/src/handlers/tfa.js'; +export * from '@/src/handlers/users.js'; +export * from '@/src/handlers/utils.js'; diff --git a/packages/sdk/src/handlers/invites.ts b/packages/sdk/src/handlers/invites.ts index ac0c5d0f37cbc..400781c21d1db 100644 --- a/packages/sdk/src/handlers/invites.ts +++ b/packages/sdk/src/handlers/invites.ts @@ -1,5 +1,5 @@ -import { ITransport } from '../transport'; -import { ID } from '../types'; +import { ITransport } from '@/src/transport.js'; +import { ID } from '@/src/types.js'; export class InvitesHandler { private transport: ITransport; diff --git a/packages/sdk/src/handlers/me.ts b/packages/sdk/src/handlers/me.ts index 3d36d379e957c..9246ce14dae7e 100644 --- a/packages/sdk/src/handlers/me.ts +++ b/packages/sdk/src/handlers/me.ts @@ -1,6 +1,6 @@ -import { PartialItem, QueryOne } from '../items'; -import { ITransport } from '../transport'; -import { TFAHandler } from './tfa'; +import { PartialItem, QueryOne } from '@/src/items.js'; +import { ITransport } from '@/src/transport.js'; +import { TFAHandler } from '@/src/handlers/tfa.js'; export class MeHandler { private _transport: ITransport; diff --git a/packages/sdk/src/handlers/passwords.ts b/packages/sdk/src/handlers/passwords.ts index 096b333ee6273..7800fe4471f9c 100644 --- a/packages/sdk/src/handlers/passwords.ts +++ b/packages/sdk/src/handlers/passwords.ts @@ -1,4 +1,4 @@ -import { ITransport } from '../transport'; +import { ITransport } from '@/src/transport.js'; export class PasswordsHandler { private transport: ITransport; diff --git a/packages/sdk/src/handlers/permissions.ts b/packages/sdk/src/handlers/permissions.ts index 42ab2efe51367..a9fc44e2576f5 100644 --- a/packages/sdk/src/handlers/permissions.ts +++ b/packages/sdk/src/handlers/permissions.ts @@ -2,9 +2,9 @@ * Permissions handler */ -import { ItemsHandler } from '../base/items'; -import { ITransport } from '../transport'; -import { PermissionType, DefaultType } from '../types'; +import { ItemsHandler } from '@/src/base/items.js'; +import { ITransport } from '@/src/transport.js'; +import { PermissionType, DefaultType } from '@/src/types.js'; export type PermissionItem = PermissionType & T; diff --git a/packages/sdk/src/handlers/presets.ts b/packages/sdk/src/handlers/presets.ts index 17b7f568a44f7..bc63974b25a82 100644 --- a/packages/sdk/src/handlers/presets.ts +++ b/packages/sdk/src/handlers/presets.ts @@ -2,9 +2,9 @@ * Presets handler */ -import { ItemsHandler } from '../base/items'; -import { ITransport } from '../transport'; -import { PresetType, DefaultType } from '../types'; +import { ItemsHandler } from '@/src/base/items.js'; +import { ITransport } from '@/src/transport.js'; +import { PresetType, DefaultType } from '@/src/types.js'; export type PresetItem = PresetType & T; diff --git a/packages/sdk/src/handlers/relations.ts b/packages/sdk/src/handlers/relations.ts index 3b064985dc5de..d9f5ef14bebfc 100644 --- a/packages/sdk/src/handlers/relations.ts +++ b/packages/sdk/src/handlers/relations.ts @@ -1,9 +1,9 @@ /** * Relations handler */ -import { ManyItems, OneItem, PartialItem } from '../items'; -import { ITransport } from '../transport'; -import { RelationType, DefaultType, ID } from '../types'; +import { ManyItems, OneItem, PartialItem } from '@/src/items.js'; +import { ITransport } from '@/src/transport.js'; +import { RelationType, DefaultType, ID } from '@/src/types.js'; export type RelationItem = RelationType & T; export class RelationsHandler { diff --git a/packages/sdk/src/handlers/revisions.ts b/packages/sdk/src/handlers/revisions.ts index edf8b7c0d9ba1..d17ef94c88e31 100644 --- a/packages/sdk/src/handlers/revisions.ts +++ b/packages/sdk/src/handlers/revisions.ts @@ -2,9 +2,9 @@ * Revisions handler */ -import { ItemsHandler } from '../base/items'; -import { ITransport } from '../transport'; -import { RevisionType, DefaultType } from '../types'; +import { ItemsHandler } from '@/src/base/items.js'; +import { ITransport } from '@/src/transport.js'; +import { RevisionType, DefaultType } from '@/src/types.js'; export type RevisionItem = RevisionType & T; diff --git a/packages/sdk/src/handlers/roles.ts b/packages/sdk/src/handlers/roles.ts index 3c1606a94c5d4..7e667d7cace85 100644 --- a/packages/sdk/src/handlers/roles.ts +++ b/packages/sdk/src/handlers/roles.ts @@ -2,9 +2,9 @@ * Roles handler */ -import { ItemsHandler } from '../base/items'; -import { ITransport } from '../transport'; -import { RoleType, DefaultType } from '../types'; +import { ItemsHandler } from '@/src/base/items.js'; +import { ITransport } from '@/src/transport.js'; +import { RoleType, DefaultType } from '@/src/types.js'; export type RoleItem = RoleType & T; diff --git a/packages/sdk/src/handlers/server.ts b/packages/sdk/src/handlers/server.ts index 775d727c363fd..ad776ae834537 100644 --- a/packages/sdk/src/handlers/server.ts +++ b/packages/sdk/src/handlers/server.ts @@ -2,7 +2,7 @@ * Server handler */ -import { ITransport } from '../transport'; +import { ITransport } from '@/src/transport.js'; export type ServerInfo = { project: { diff --git a/packages/sdk/src/handlers/settings.ts b/packages/sdk/src/handlers/settings.ts index bbc487600c005..dedcce95ccc4a 100644 --- a/packages/sdk/src/handlers/settings.ts +++ b/packages/sdk/src/handlers/settings.ts @@ -1,9 +1,9 @@ /** * Settings handler */ -import { ITransport } from '../transport'; -import { SettingType, DefaultType } from '../types'; -import { SingletonHandler } from './singleton'; +import { ITransport } from '@/src/transport.js'; +import { SettingType, DefaultType } from '@/src/types.js'; +import { SingletonHandler } from '@/src/handlers/singleton.js'; export type SettingItem = SettingType & T; diff --git a/packages/sdk/src/handlers/singleton.ts b/packages/sdk/src/handlers/singleton.ts index 4ab1d3a1d5bf9..b0d1f84f30951 100644 --- a/packages/sdk/src/handlers/singleton.ts +++ b/packages/sdk/src/handlers/singleton.ts @@ -1,6 +1,6 @@ -import { ITransport } from '../transport'; -import { QueryOne, OneItem, PartialItem } from '../items'; -import { ISingleton } from '../singleton'; +import { ITransport } from '@/src/transport.js'; +import { QueryOne, OneItem, PartialItem } from '@/src/items.js'; +import { ISingleton } from '@/src/singleton.js'; export class SingletonHandler implements ISingleton { protected collection: string; diff --git a/packages/sdk/src/handlers/tfa.ts b/packages/sdk/src/handlers/tfa.ts index 6418dd2d5ebe8..b347c938c1d79 100644 --- a/packages/sdk/src/handlers/tfa.ts +++ b/packages/sdk/src/handlers/tfa.ts @@ -1,5 +1,5 @@ -import { ITransport } from '../transport'; -import { TfaType, DefaultType } from '../types'; +import { ITransport } from '@/src/transport.js'; +import { TfaType, DefaultType } from '@/src/types.js'; type TfaItem = TfaType & T; export class TFAHandler { diff --git a/packages/sdk/src/handlers/users.ts b/packages/sdk/src/handlers/users.ts index 4709bd1e51830..fa5ac48b7e7e1 100644 --- a/packages/sdk/src/handlers/users.ts +++ b/packages/sdk/src/handlers/users.ts @@ -2,11 +2,11 @@ * Users handler */ -import { ItemsHandler } from '../base/items'; -import { ITransport } from '../transport'; -import { DefaultType, UserType } from '../types'; -import { InvitesHandler } from './invites'; -import { MeHandler } from './me'; +import { ItemsHandler } from '@/src/base/items.js'; +import { ITransport } from '@/src/transport.js'; +import { DefaultType, UserType } from '@/src/types.js'; +import { InvitesHandler } from '@/src/handlers/invites.js'; +import { MeHandler } from '@/src/handlers/me.js'; export type UserItem = UserType & T; diff --git a/packages/sdk/src/handlers/utils.ts b/packages/sdk/src/handlers/utils.ts index b703ad91402d6..fc876dd6fa466 100644 --- a/packages/sdk/src/handlers/utils.ts +++ b/packages/sdk/src/handlers/utils.ts @@ -2,8 +2,8 @@ * Utils handler */ -import { ITransport } from '../transport'; -import { ID } from '../types'; +import { ITransport } from '@/src/transport.js'; +import { ID } from '@/src/types.js'; export class UtilsHandler { private transport: ITransport; diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 180bb1ce9458e..7512163ffcd69 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -1,14 +1,17 @@ // Interfaces -export * from './auth'; -export * from './directus'; -export * from './handlers'; -export * from './items'; -export * from './singleton'; -export * from './storage'; -export * from './transport'; +export * from '@/src/auth.js'; +export * from '@/src/directus.js'; +export * from '@/src/handlers/index.js'; +export * from '@/src/items.js'; +export * from '@/src/singleton.js'; +export * from '@/src/storage.js'; +export * from '@/src/transport.js'; // Implementations -export * from './base'; +export * from '@/src/base/index.js'; // Types -export * from './types'; +export * from '@/src/types.js'; + +// Utils +export * from '@/src/utils.js'; diff --git a/packages/sdk/src/items.ts b/packages/sdk/src/items.ts index a5cae960cff2a..2dab0f95a1e68 100644 --- a/packages/sdk/src/items.ts +++ b/packages/sdk/src/items.ts @@ -1,4 +1,4 @@ -import { ID } from './types'; +import { ID } from '@/src/types.js'; export type Field = string; diff --git a/packages/sdk/src/singleton.ts b/packages/sdk/src/singleton.ts index 7e1add8ecd134..7fe05f6bce494 100644 --- a/packages/sdk/src/singleton.ts +++ b/packages/sdk/src/singleton.ts @@ -1,4 +1,4 @@ -import { Item, OneItem, PartialItem, QueryOne } from './items'; +import { Item, OneItem, PartialItem, QueryOne } from '@/src/items.js'; /** * CRUD at its finest diff --git a/packages/sdk/src/transport.ts b/packages/sdk/src/transport.ts index be4c6842c7bb0..e38ea58b9ac76 100644 --- a/packages/sdk/src/transport.ts +++ b/packages/sdk/src/transport.ts @@ -1,4 +1,4 @@ -import { ItemMetadata } from './items'; +import { ItemMetadata } from '@/src/items.js'; export type TransportErrorDescription = { message?: string; diff --git a/packages/sdk/tests/base/auth.browser.test.ts b/packages/sdk/tests/base/auth.browser.test.ts index f6fa2b40133c3..f4511bbae66e5 100644 --- a/packages/sdk/tests/base/auth.browser.test.ts +++ b/packages/sdk/tests/base/auth.browser.test.ts @@ -2,8 +2,8 @@ * @jest-environment jsdom */ -import { Auth, AxiosTransport, Directus, MemoryStorage } from '../../src'; -import { test, timers } from '../utils'; +import { Auth, AxiosTransport, Directus, MemoryStorage } from '@/src/index.js'; +import { test, timers } from '@/tests/utils.js'; describe('auth (browser)', function () { beforeEach(() => { diff --git a/packages/sdk/tests/base/auth.node.test.ts b/packages/sdk/tests/base/auth.node.test.ts index 6cc35f2db25d0..b9a8f1b42fdee 100644 --- a/packages/sdk/tests/base/auth.node.test.ts +++ b/packages/sdk/tests/base/auth.node.test.ts @@ -2,8 +2,8 @@ * @jest-environment node */ -import { Auth, AxiosTransport, Directus, MemoryStorage } from '../../src'; -import { test, timers } from '../utils'; +import { Auth, AxiosTransport, Directus, MemoryStorage } from '@/src/index.js'; +import { test, timers } from '@/tests/utils.js'; describe('auth (node)', function () { test(`sets default auth mode to json`, async (url) => { diff --git a/packages/sdk/tests/base/auth.test.ts b/packages/sdk/tests/base/auth.test.ts index 2700f2eaa4042..d332c11847bb2 100644 --- a/packages/sdk/tests/base/auth.test.ts +++ b/packages/sdk/tests/base/auth.test.ts @@ -2,8 +2,8 @@ * @jest-environment node */ -import { Directus } from '../../src'; -import { test } from '../utils'; +import { Directus } from '@/src/index.js'; +import { test } from '@/tests/utils.js'; describe('auth', function () { test(`static auth should validate token`, async (url, nock) => { diff --git a/packages/sdk/tests/base/directus.browser.test.ts b/packages/sdk/tests/base/directus.browser.test.ts index ee6764acbd68a..e02711d24b04d 100644 --- a/packages/sdk/tests/base/directus.browser.test.ts +++ b/packages/sdk/tests/base/directus.browser.test.ts @@ -2,7 +2,7 @@ * @jest-environment jsdom */ -import { Directus, LocalStorage } from '../../src/base'; +import { Directus, LocalStorage } from '@/src/index.js'; describe('browser sdk', function () { const sdk = new Directus('http://example.com'); diff --git a/packages/sdk/tests/base/directus.node.ts b/packages/sdk/tests/base/directus.node.ts index 37cafa52e6db2..0dc9131cd2fc9 100644 --- a/packages/sdk/tests/base/directus.node.ts +++ b/packages/sdk/tests/base/directus.node.ts @@ -2,7 +2,7 @@ * @jest-environment node */ -import { Directus, MemoryStorage } from '../../src/base'; +import { Directus, MemoryStorage } from '@/src/index.js'; describe('node sdk', function () { const sdk = new Directus('http://example.com'); diff --git a/packages/sdk/tests/base/directus.test.ts b/packages/sdk/tests/base/directus.test.ts index 58fccb32983c8..61f68f648d1be 100644 --- a/packages/sdk/tests/base/directus.test.ts +++ b/packages/sdk/tests/base/directus.test.ts @@ -2,17 +2,19 @@ * @jest-environment node */ -import { Auth } from '../../src/base/auth'; -import { ItemsHandler } from '../../src/base/items'; -import { AxiosTransport } from '../../src/base/transport/axios-transport'; -import { Directus } from '../../src/base'; import { ActivityHandler, + Auth, + AxiosTransport, CollectionsHandler, CommentsHandler, + Directus, FieldsHandler, FilesHandler, FoldersHandler, + InvitesHandler, + ItemsHandler, + MeHandler, PermissionsHandler, PresetsHandler, RelationsHandler, @@ -20,13 +22,11 @@ import { RolesHandler, ServerHandler, SettingsHandler, + TFAHandler, UsersHandler, UtilsHandler, -} from '../../src/handlers'; -import { test } from '../utils'; -import { InvitesHandler } from '../../src/handlers/invites'; -import { TFAHandler } from '../../src/handlers/tfa'; -import { MeHandler } from '../../src/handlers/me'; +} from '@/src/index.js'; +import { test } from '@/tests/utils.js'; describe('sdk', function () { const sdk = new Directus('http://example.com'); diff --git a/packages/sdk/tests/base/storage/localstorage.test.ts b/packages/sdk/tests/base/storage/localstorage.test.ts index 33f3e6a9f60ef..25dcbf7ff877a 100644 --- a/packages/sdk/tests/base/storage/localstorage.test.ts +++ b/packages/sdk/tests/base/storage/localstorage.test.ts @@ -2,8 +2,8 @@ * @jest-environment jsdom */ -import { LocalStorage } from '../../../src/base/storage'; -import { createStorageTests } from './tests'; +import { LocalStorage } from '@/src/index.js'; +import { createStorageTests } from '@/tests/base/storage/tests.js'; describe( 'localstorage storage', diff --git a/packages/sdk/tests/base/storage/memory.test.ts b/packages/sdk/tests/base/storage/memory.test.ts index 1b4c64827ec88..677a246b6056a 100644 --- a/packages/sdk/tests/base/storage/memory.test.ts +++ b/packages/sdk/tests/base/storage/memory.test.ts @@ -2,8 +2,8 @@ * @jest-environment node */ -import { MemoryStorage } from '../../../src/base/storage'; -import { createStorageTests } from './tests'; +import { MemoryStorage } from '@/src/index.js'; +import { createStorageTests } from '@/tests/base/storage/tests.js'; describe( 'memory storage', diff --git a/packages/sdk/tests/base/storage/tests.ts b/packages/sdk/tests/base/storage/tests.ts index 416d65fd36eef..36369bdf49adf 100644 --- a/packages/sdk/tests/base/storage/tests.ts +++ b/packages/sdk/tests/base/storage/tests.ts @@ -1,4 +1,4 @@ -import { IStorage } from '../../../src/storage'; +import { IStorage } from '@/src/index.js'; export function createStorageTests(createStorage: () => IStorage) { return function (): void { diff --git a/packages/sdk/tests/base/transport/axios.test.ts b/packages/sdk/tests/base/transport/axios.test.ts index fbe66e7e18a7a..69942b56a8777 100644 --- a/packages/sdk/tests/base/transport/axios.test.ts +++ b/packages/sdk/tests/base/transport/axios.test.ts @@ -3,10 +3,7 @@ */ import nock from 'nock'; -import { MemoryStorage } from '../../../src'; - -import { AxiosTransport } from '../../../src/base/transport/axios-transport'; -import { TransportResponse, TransportError } from '../../../src/transport'; +import { MemoryStorage, AxiosTransport, TransportResponse, TransportError } from '@/src/index.js'; describe('axios transport', function () { const URL = 'http://localhost'; diff --git a/packages/sdk/tests/blog.d.ts b/packages/sdk/tests/blog.d.ts index 78bf9a608a335..b1a46cfe5fd37 100644 --- a/packages/sdk/tests/blog.d.ts +++ b/packages/sdk/tests/blog.d.ts @@ -1,4 +1,4 @@ -import { ID } from '../src/types'; +import { ID } from '@/src/types.js'; export type Post = { id: ID; diff --git a/packages/sdk/tests/handlers/comments.test.ts b/packages/sdk/tests/handlers/comments.test.ts index ef27879362ffd..0cca29ff2cb85 100644 --- a/packages/sdk/tests/handlers/comments.test.ts +++ b/packages/sdk/tests/handlers/comments.test.ts @@ -2,8 +2,8 @@ * @jest-environment node */ -import { Directus } from '../../src'; -import { test } from '../utils'; +import { Directus } from '@/src/index.js'; +import { test } from '@/tests/utils.js'; describe('comments', function () { test(`creates comments`, async (url, nock) => { diff --git a/packages/sdk/tests/handlers/fields.test.ts b/packages/sdk/tests/handlers/fields.test.ts index dd1fd1dce0a90..499e0f2646d23 100644 --- a/packages/sdk/tests/handlers/fields.test.ts +++ b/packages/sdk/tests/handlers/fields.test.ts @@ -2,8 +2,8 @@ * @jest-environment node */ -import { Directus } from '../../src'; -import { test } from '../utils'; +import { Directus } from '@/src/index.js'; +import { test } from '@/tests/utils.js'; describe('fields', function () { test(`update one`, async (url, nock) => { diff --git a/packages/sdk/tests/handlers/invites.test.ts b/packages/sdk/tests/handlers/invites.test.ts index 1d3f7cadb3e0c..67ef4191077c7 100644 --- a/packages/sdk/tests/handlers/invites.test.ts +++ b/packages/sdk/tests/handlers/invites.test.ts @@ -2,8 +2,8 @@ * @jest-environment node */ -import { Directus } from '../../src'; -import { test } from '../utils'; +import { Directus } from '@/src/index.js'; +import { test } from '@/tests/utils.js'; describe('invites', function () { test('send', async (url, nock) => { diff --git a/packages/sdk/tests/handlers/me.test.ts b/packages/sdk/tests/handlers/me.test.ts index 49ff192745987..abc7156451d1d 100644 --- a/packages/sdk/tests/handlers/me.test.ts +++ b/packages/sdk/tests/handlers/me.test.ts @@ -2,8 +2,8 @@ * @jest-environment node */ -import { Directus } from '../../src'; -import { test } from '../utils'; +import { Directus } from '@/src/index.js'; +import { test } from '@/tests/utils.js'; describe('profile', function () { test(`read`, async (url, nock) => { diff --git a/packages/sdk/tests/handlers/passwords.test.ts b/packages/sdk/tests/handlers/passwords.test.ts index d3311a484d860..58e10125d636e 100644 --- a/packages/sdk/tests/handlers/passwords.test.ts +++ b/packages/sdk/tests/handlers/passwords.test.ts @@ -2,8 +2,8 @@ * @jest-environment node */ -import { Directus } from '../../src'; -import { test } from '../utils'; +import { Directus } from '@/src/index.js'; +import { test } from '@/tests/utils.js'; describe('password', function () { test(`request`, async (url, nock) => { diff --git a/packages/sdk/tests/handlers/server.test.ts b/packages/sdk/tests/handlers/server.test.ts index 059bbe2d14c28..76e66b55131bd 100644 --- a/packages/sdk/tests/handlers/server.test.ts +++ b/packages/sdk/tests/handlers/server.test.ts @@ -2,8 +2,8 @@ * @jest-environment node */ -import { Directus } from '../../src'; -import { test } from '../utils'; +import { Directus } from '@/src/index.js'; +import { test } from '@/tests/utils.js'; describe('server', function () { test(`ping the server`, async (url, nock) => { diff --git a/packages/sdk/tests/handlers/tfa.test.ts b/packages/sdk/tests/handlers/tfa.test.ts index 3b999d68eb0f0..f258b880572c6 100644 --- a/packages/sdk/tests/handlers/tfa.test.ts +++ b/packages/sdk/tests/handlers/tfa.test.ts @@ -2,8 +2,8 @@ * @jest-environment node */ -import { Directus } from '../../src'; -import { test } from '../utils'; +import { Directus } from '@/src/index.js'; +import { test } from '@/tests/utils.js'; describe('tfa', function () { test(`generate`, async (url, nock) => { diff --git a/packages/sdk/tests/handlers/utils.test.ts b/packages/sdk/tests/handlers/utils.test.ts index 329275fd5f1b0..6ffeb20c7a2dc 100644 --- a/packages/sdk/tests/handlers/utils.test.ts +++ b/packages/sdk/tests/handlers/utils.test.ts @@ -3,9 +3,8 @@ */ import argon2 from 'argon2'; -import { Directus } from '../../src'; -import { test } from '../utils'; -import { generateHash } from '../utils'; +import { Directus } from '@/src/index.js'; +import { test, generateHash } from '@/tests/utils.js'; describe('utils', function () { test(`generates random string`, async (url, nock) => { diff --git a/packages/sdk/tests/items.test.ts b/packages/sdk/tests/items.test.ts index bf462e890f71e..b4e568a24b19a 100644 --- a/packages/sdk/tests/items.test.ts +++ b/packages/sdk/tests/items.test.ts @@ -2,9 +2,9 @@ * @jest-environment node */ -import { Blog } from './blog.d'; -import { Directus } from '../src'; -import { test } from './utils'; +import { Blog } from '@/tests/blog.d.js'; +import { Directus } from '@/src/index.js'; +import { test } from '@/tests/utils.js'; describe('items', function () { test(`can get an item by id`, async (url, nock) => { diff --git a/packages/sdk/tests/singleton.test.ts b/packages/sdk/tests/singleton.test.ts index adc5d061bdcf5..be8f604040d06 100644 --- a/packages/sdk/tests/singleton.test.ts +++ b/packages/sdk/tests/singleton.test.ts @@ -2,8 +2,8 @@ * @jest-environment node */ -import { Directus } from '../src'; -import { test } from './utils'; +import { Directus } from '@/src/index.js'; +import { test } from '@/tests/utils.js'; type Settings = { url: string; diff --git a/packages/sdk/tests/utils.test.ts b/packages/sdk/tests/utils.test.ts index a7b268c8679f0..c5af5610f843d 100644 --- a/packages/sdk/tests/utils.test.ts +++ b/packages/sdk/tests/utils.test.ts @@ -2,8 +2,8 @@ * @jest-environment node */ -import { Debouncer } from '../src/utils'; -import { timers } from './utils'; +import { Debouncer } from '@/src/index.js'; +import { timers } from '@/tests/utils.js'; describe('debouncer', function () { test(`concurrent calls should return with the error from the first call`, async () => { diff --git a/packages/sdk/tsconfig.json b/packages/sdk/tsconfig.json index b83ff8a9b9bc1..eb8128bb35556 100644 --- a/packages/sdk/tsconfig.json +++ b/packages/sdk/tsconfig.json @@ -26,7 +26,11 @@ "allowSyntheticDefaultImports": true, "isolatedModules": true, "rootDir": "./src", - "outDir": "./dist" + "outDir": "./dist", + "baseUrl": ".", + "paths": { + "@/*": ["./*"] + } }, "include": ["./src/**/*.ts"] }