Skip to content

Commit

Permalink
Merge pull request #195 from what1s1ove/task/wd-159-js-packages
Browse files Browse the repository at this point in the history
wd-159: use js packages folder approach
  • Loading branch information
what1s1ove authored Nov 17, 2023
2 parents aba876c + c13576d commit d729bde
Show file tree
Hide file tree
Showing 117 changed files with 197 additions and 207 deletions.
5 changes: 0 additions & 5 deletions source/scripts/common/enums/api/api-error-message.enum.js

This file was deleted.

3 changes: 0 additions & 3 deletions source/scripts/common/enums/api/api.js

This file was deleted.

1 change: 0 additions & 1 deletion source/scripts/common/enums/app/app.js

This file was deleted.

9 changes: 0 additions & 9 deletions source/scripts/common/enums/enums.js

This file was deleted.

1 change: 0 additions & 1 deletion source/scripts/common/enums/event/event.js

This file was deleted.

1 change: 0 additions & 1 deletion source/scripts/common/enums/exception/exception.js

This file was deleted.

1 change: 0 additions & 1 deletion source/scripts/common/enums/file/file.js

This file was deleted.

1 change: 0 additions & 1 deletion source/scripts/common/enums/notification/notification.js

This file was deleted.

6 changes: 0 additions & 6 deletions source/scripts/common/enums/timeline/skill-type.enum.js

This file was deleted.

2 changes: 0 additions & 2 deletions source/scripts/common/enums/timeline/timeline.js

This file was deleted.

1 change: 0 additions & 1 deletion source/scripts/common/maps/maps.js

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions source/scripts/form.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Form } from '~/components/form/form.js'
import { timelineApi } from '~/services/services.js'
import { timelineApi } from '~/packages/timeline/timeline.js'
import { Form } from '~/pages/form/form.js'

let form = new Form({
timelineApi,
Expand Down
2 changes: 1 addition & 1 deletion source/scripts/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WhatisloveMath } from '~/services/whatislove-math/whatislove-math.service.js'
import { WhatisloveMath } from '~/libs/packages/whatislove-math/whatislove-math.js'

declare global {
var WhatisloveMath: WhatisloveMath
Expand Down
1 change: 0 additions & 1 deletion source/scripts/helpers/api/api.js

This file was deleted.

2 changes: 0 additions & 2 deletions source/scripts/helpers/boolean/boolean.js

This file was deleted.

1 change: 0 additions & 1 deletion source/scripts/helpers/date/date.js

This file was deleted.

3 changes: 0 additions & 3 deletions source/scripts/helpers/dom/dom.js

This file was deleted.

4 changes: 0 additions & 4 deletions source/scripts/helpers/form/form.js

This file was deleted.

17 changes: 0 additions & 17 deletions source/scripts/helpers/helpers.js

This file was deleted.

1 change: 0 additions & 1 deletion source/scripts/helpers/number/number.js

This file was deleted.

1 change: 0 additions & 1 deletion source/scripts/helpers/string/string.js

This file was deleted.

2 changes: 0 additions & 2 deletions source/scripts/helpers/timeout/timeout.js

This file was deleted.

6 changes: 4 additions & 2 deletions source/scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Home } from '~/components/home/home.js'
import { storage, timelineApi, WhatisloveMath } from '~/services/services.js'
import { storage } from '~/libs/packages/storage/storage.js'
import { WhatisloveMath } from '~/libs/packages/whatislove-math/whatislove-math.package.js'
import { timelineApi } from '~/packages/timeline/timeline.js'
import { Home } from '~/pages/home/home.js'

let home = new Home({
storage,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement } from '~/helpers/helpers.js'
import { createElement } from '~/libs/helpers/helpers.js'

/** @returns {HTMLElement} */
let getLoaderElement = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getLoaderElement } from './helpers/helpers.js'
import { getLoaderElement } from './libs/helpers/helpers.js'

class Loader {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { setAsyncTimeout } from '~/helpers/helpers.js'
import { setAsyncTimeout } from '~/libs/helpers/helpers.js'

import {
CLEAN_MESSAGE_DELAY,
TOAST_DEFAULT_DURATION,
TOAST_SHOW_CLASS_NAME,
} from './common/constants.js'
} from './libs/constants/constants.js'

/** @typedef {import('~/common/types/toast/toast').ToastMessagePayload} ToastMessagePayload */
/** @typedef {import('~/libs/types/types').ToastMessagePayload} ToastMessagePayload */

class Toast {
constructor() {
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions source/scripts/libs/enums/enums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export { ApiPath } from './api-path.enum.js'
export { AppConfig } from './app-config.enum.js'
export { ContentType } from './content-type.enum.js'
export { CustomExceptionName } from './custom-exception-name.enum.js'
export { ErrorMessage } from './error-message.enum.js'
export { KeyboardKey } from './keyboard-key.enum.js'
export { NotificationMessage } from './notification-message.enum.js'
5 changes: 5 additions & 0 deletions source/scripts/libs/enums/error-message.enum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let ErrorMessage = /** @type {const} */ ({
NETWORK_ERROR: `Network Error`,
})

export { ErrorMessage }
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addSelectOptions } from '~/helpers/form/add-select-options/add-select-options.helper.js'
import { createSelectOptions } from '~/helpers/form/create-select-options/create-select-options.helper.js'
import { addSelectOptions } from '../add-select-options/add-select-options.helper.js'
import { createSelectOptions } from '../create-select-options/create-select-options.helper.js'

/**
* @param {HTMLSelectElement} selectNode
Expand Down
15 changes: 15 additions & 0 deletions source/scripts/libs/helpers/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export { addSelectOptions } from './add-select-options/add-select-options.helper.js'
export { checkIsBeforeElement } from './check-is-before-element/check-is-before-element.helper.js'
export { checkIsOneOf } from './check-is-one-of/check-is-one-of.helper.js'
export { createElement } from './create-element/create-element.helper.js'
export { createSelectOptions } from './create-select-options/create-select-options.helper.js'
export { fillSelectOptions } from './fill-select-options/fill-select-options.helper.js'
export { getCustomAttributeName } from './get-custom-attribute-name/get-custom-attribute-name.helper.js'
export { getFormattedDate } from './get-formatted-date/get-formatted-date.helper.js'
export { getRandomNumber } from './get-random-number/get-random-number.helper.js'
export { getServerApiUrl } from './get-server-api-url/get-server-api-url.helper.js'
export { getStringWitCheck } from './get-string-with-check/get-string-with-check.helper.js'
export { initDebounce } from './init-debounce/init-debounce.helper.js'
export { setAsyncTimeout } from './set-async-timeout/set-async-timeout.helper.js'
export { subscribeFocusTrap } from './subscribe-focus-trap/subscribe-focus-trap.helper.js'
export { getFormValues } from 'form-payload'
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @param {number} delay
* @returns {(...args: unknown[]) => unknown}
*/
let debounce = (callback, delay) => {
let initDebounce = (callback, delay) => {
let /** @type {undefined | number} */ timeout

return (...arguments_) => {
Expand All @@ -13,4 +13,4 @@ let debounce = (callback, delay) => {
}
}

export { debounce }
export { initDebounce }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KeyboardKey } from '~/common/enums/enums.js'
import { KeyboardKey } from '~/libs/enums/enums.js'

/**
* @param {HTMLElement[]} elements
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions source/scripts/libs/packages/http/http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Http } from './http.package.js'

let http = new Http()

export { http }
export { Http } from './http.package.js'
export { HttpMethod } from './libs/enums/enums.js'
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import {
ApiErrorMessage,
ContentType,
HttpHeader,
HttpMethod,
} from '~/common/enums/enums.js'
import { HttpError } from '~/exceptions/exceptions.js'
import { checkIsOneOf } from '~/helpers/helpers.js'
import { ContentType, ErrorMessage } from '~/libs/enums/enums.js'
import { checkIsOneOf } from '~/libs/helpers/helpers.js'

import { HttpHeader, HttpMethod } from './libs/enums/enums.js'
import { HttpError } from './libs/exceptions/exceptions.js'

class Http {
/**
Expand All @@ -17,8 +14,8 @@ class Http {
if (!response.ok) {
throw new HttpError({
message:
/** @type {(typeof ApiErrorMessage)[keyof typeof ApiErrorMessage]} */ (
response.statusText ?? ApiErrorMessage.NETWORK_ERROR
/** @type {(typeof ErrorMessage)[keyof typeof ErrorMessage]} */ (
response.statusText ?? ErrorMessage.NETWORK_ERROR
),
})
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import {
ApiErrorMessage,
CustomExceptionName,
HttpCode,
} from '~/common/enums/enums.js'
import { CustomExceptionName, ErrorMessage } from '~/libs/enums/enums.js'

import { HttpCode } from '../../enums/enums.js'

class HttpError extends Error {
/**
* @param {{
* message?: (typeof ApiErrorMessage)[keyof typeof ApiErrorMessage]
* message?: (typeof ErrorMessage)[keyof typeof ErrorMessage]
* status?: (typeof HttpCode)[keyof typeof HttpCode]
* }} [properties]
*/
constructor({
message = ApiErrorMessage.NETWORK_ERROR,
message = ErrorMessage.NETWORK_ERROR,
status = HttpCode.INTERNAL_SERVER_ERROR,
} = {}) {
super(message)
Expand Down
8 changes: 8 additions & 0 deletions source/scripts/libs/packages/storage/storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Storage } from './storage.package.js'

let storage = new Storage({
storage: localStorage,
})

export { storage }
export { Storage } from './storage.package.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { WhatisloveMath } from './whatislove-math.package.js'
File renamed without changes.
3 changes: 3 additions & 0 deletions source/scripts/packages/timeline/libs/enums/enums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { TimelineApiPath } from './timeline-api-path.enum.js'
export { TimelineSkillType } from './timeline-skill-type.enum.js'
export { TimelineType } from './timeline-type.enum.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let TimelineSkillType = /** @type {const} */ ({
HARD_SKILL: `hardSkill`,
SOFT_SKILL: `softSkill`,
})

export { TimelineSkillType }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type TimelineType, type SkillType } from '~/common/enums/enums.js'
import { type TimelineType, type TimelineSkillType } from '../enums/enums.js'

type TimelineCreatePayload = {
date: string
Expand All @@ -9,7 +9,7 @@ type TimelineCreatePayload = {
origin: string
originDesc: string
title: string
skillType: (typeof SkillType)[keyof typeof SkillType]
skillType: (typeof TimelineSkillType)[keyof typeof TimelineSkillType]
type: (typeof TimelineType)[keyof typeof TimelineType]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { type TimelineType, type TimelineSkillType } from '../enums/enums.js'

type TimelineFilter = {
skillTypes: Record<
(typeof TimelineSkillType)[keyof typeof TimelineSkillType],
boolean
>
types: Record<(typeof TimelineType)[keyof typeof TimelineType], boolean>
}

export { type TimelineFilter }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type TimelineType, type SkillType } from '~/common/enums/enums.js'
import { type TimelineType, type TimelineSkillType } from '../enums/enums.js'

type Timeline = {
id: string
Expand All @@ -10,7 +10,7 @@ type Timeline = {
origin: string
originDesc: string
title: string
skillType: (typeof SkillType)[keyof typeof SkillType]
skillType: (typeof TimelineSkillType)[keyof typeof TimelineSkillType]
type: (typeof TimelineType)[keyof typeof TimelineType]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
ApiPath,
ContentType,
HttpMethod,
TimelineApiPath,
} from '~/common/enums/enums.js'

/** @typedef {import('~/common/types/timeline/timeline').Timeline} Timeline */
/** @typedef {import('~/services/http/http.service').Http} Http */
/** @typedef {import('~/common/types/timeline/timeline')} TimelineCreatePayload */
import { ApiPath, ContentType } from '~/libs/enums/enums.js'
import { HttpMethod } from '~/libs/packages/http/http.js'

import { TimelineApiPath } from './libs/enums/enums.js'

/** @typedef {import('~/libs/packages/http/http').Http} Http */
/** @typedef {import('./libs/types/types').Timeline} Timeline */
/** @typedef {import('./libs/types/types')} TimelineCreatePayload */

class TimelineApi {
/**
Expand Down
22 changes: 22 additions & 0 deletions source/scripts/packages/timeline/timeline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { AppConfig } from '~/libs/enums/enums.js'
import { getServerApiUrl } from '~/libs/helpers/helpers.js'
import { http } from '~/libs/packages/http/http.js'

import { TimelineApi } from './timeline-api.js'

/** @typedef {import('./libs/types/types').Timeline} Timeline */
/** @typedef {import('./libs/types/types').TimelineCreatePayload} TimelineCreatePayload */
/** @typedef {import('./libs/types/types').TimelineFilter} TimelineFilter */

let timelineApi = new TimelineApi({
baseUrl: getServerApiUrl({
host: AppConfig.SERVER_HOST,
port: AppConfig.SERVER_PORT,
}),
filesApiPath: AppConfig.FILES_API_PATH,
http,
})

export { timelineApi }
export { TimelineSkillType, TimelineType } from './libs/enums/enums.js'
export { TimelineApi } from './timeline-api.js'
Loading

0 comments on commit d729bde

Please sign in to comment.