@things-factory/shell 6.2.79 → 6.2.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist-server/graphql-local-client.d.ts +19 -0
  2. package/dist-server/graphql-local-client.js +14 -0
  3. package/dist-server/graphql-local-client.js.map +1 -1
  4. package/dist-server/initializers/database.d.ts +26 -0
  5. package/dist-server/initializers/database.js +26 -0
  6. package/dist-server/initializers/database.js.map +1 -1
  7. package/dist-server/pubsub-log-transport.d.ts +27 -0
  8. package/dist-server/pubsub-log-transport.js +15 -0
  9. package/dist-server/pubsub-log-transport.js.map +1 -1
  10. package/dist-server/pubsub.d.ts +7 -0
  11. package/dist-server/pubsub.js +12 -0
  12. package/dist-server/pubsub.js.map +1 -1
  13. package/dist-server/schema.d.ts +4 -0
  14. package/dist-server/schema.js +4 -0
  15. package/dist-server/schema.js.map +1 -1
  16. package/dist-server/tsconfig.tsbuildinfo +1 -1
  17. package/dist-server/typeorm/encrypt-transform.d.ts +5 -0
  18. package/dist-server/typeorm/encrypt-transform.js +25 -0
  19. package/dist-server/typeorm/encrypt-transform.js.map +1 -1
  20. package/dist-server/utils/condition-builder.d.ts +11 -0
  21. package/dist-server/utils/condition-builder.js +11 -0
  22. package/dist-server/utils/condition-builder.js.map +1 -1
  23. package/dist-server/utils/get-domain.d.ts +46 -0
  24. package/dist-server/utils/get-domain.js +70 -0
  25. package/dist-server/utils/get-domain.js.map +1 -1
  26. package/dist-server/utils/get-query-builder-from-list-params.d.ts +12 -2
  27. package/dist-server/utils/get-query-builder-from-list-params.js +24 -8
  28. package/dist-server/utils/get-query-builder-from-list-params.js.map +1 -1
  29. package/dist-server/utils/get-times-for-period.d.ts +14 -0
  30. package/dist-server/utils/get-times-for-period.js +14 -0
  31. package/dist-server/utils/get-times-for-period.js.map +1 -1
  32. package/dist-server/utils/list-param-adjuster.d.ts +9 -0
  33. package/dist-server/utils/list-param-adjuster.js +9 -0
  34. package/dist-server/utils/list-param-adjuster.js.map +1 -1
  35. package/dist-server/utils/list-params-converter.d.ts +6 -0
  36. package/dist-server/utils/list-params-converter.js +27 -0
  37. package/dist-server/utils/list-params-converter.js.map +1 -1
  38. package/dist-server/utils/list-query-builder.d.ts +10 -1
  39. package/dist-server/utils/list-query-builder.js +10 -1
  40. package/dist-server/utils/list-query-builder.js.map +1 -1
  41. package/dist-server/utils/publish-progress.d.ts +9 -0
  42. package/dist-server/utils/publish-progress.js +9 -0
  43. package/dist-server/utils/publish-progress.js.map +1 -1
  44. package/package.json +3 -3
  45. package/server/graphql-local-client.ts +20 -0
  46. package/server/initializers/database.ts +26 -0
  47. package/server/pubsub-log-transport.ts +29 -0
  48. package/server/pubsub.ts +13 -0
  49. package/server/schema.ts +4 -0
  50. package/server/typeorm/encrypt-transform.ts +26 -0
  51. package/server/utils/condition-builder.ts +12 -8
  52. package/server/utils/get-domain.ts +70 -0
  53. package/server/utils/get-query-builder-from-list-params.ts +26 -16
  54. package/server/utils/get-times-for-period.ts +15 -4
  55. package/server/utils/list-param-adjuster.ts +9 -0
  56. package/server/utils/list-params-converter.ts +28 -4
  57. package/server/utils/list-query-builder.ts +13 -17
  58. package/server/utils/publish-progress.ts +9 -0
  59. package/dist-server/webpack/koa-webpack/client.d.ts +0 -1
  60. package/dist-server/webpack/koa-webpack/client.js +0 -24
  61. package/dist-server/webpack/koa-webpack/client.js.map +0 -1
  62. package/dist-server/webpack/koa-webpack/index.d.ts +0 -2
  63. package/dist-server/webpack/koa-webpack/index.js +0 -58
  64. package/dist-server/webpack/koa-webpack/index.js.map +0 -1
  65. package/dist-server/webpack/koa-webpack/middleware.d.ts +0 -0
  66. package/dist-server/webpack/koa-webpack/middleware.js +0 -42
  67. package/dist-server/webpack/koa-webpack/middleware.js.map +0 -1
  68. package/dist-server/webpack/koa-webpack/validate.d.ts +0 -1
  69. package/dist-server/webpack/koa-webpack/validate.js +0 -26
  70. package/dist-server/webpack/koa-webpack/validate.js.map +0 -1
  71. package/server/webpack/koa-webpack/client.ts +0 -26
  72. package/server/webpack/koa-webpack/index.ts +0 -71
  73. package/server/webpack/koa-webpack/middleware.ts +0 -47
  74. package/server/webpack/koa-webpack/validate.ts +0 -27
@@ -11,6 +11,13 @@ const protocol: string = config.get('protocol')
11
11
  const fixed = config.get('subdomain')
12
12
  const subdomainOffset = config.getNumber('subdomainOffset', 2)
13
13
 
14
+ /**
15
+ * Creates a URL based on the given context and path.
16
+ *
17
+ * @param context {Object} An object containing the current request context information.
18
+ * @param path {string} The path to be added to the created URL (optional).
19
+ * @returns {URL} The generated URL object.
20
+ */
14
21
  export function getUrlFromContext(context, path = '') {
15
22
  const { method, href, host, header } = context
16
23
  const { referer } = header || {}
@@ -44,12 +51,24 @@ export function getUrlFromContext(context, path = '') {
44
51
  return url
45
52
  }
46
53
 
54
+ /**
55
+ * Extracts subdomains from the Host header.
56
+ *
57
+ * @param context {Object} An object containing the current request context information.
58
+ * @returns {string[]} An array of extracted subdomains.
59
+ */
47
60
  function getSubdomainsFromHost(context: any) {
48
61
  const { request } = context
49
62
  var subdomains = request.headers.host.split('.').reverse()
50
63
  return subdomains.slice(subdomainOffset)
51
64
  }
52
65
 
66
+ /**
67
+ * Extracts a subdomain from the path.
68
+ *
69
+ * @param context {Object} An object containing the current request context information.
70
+ * @returns {string} The extracted subdomain.
71
+ */
53
72
  function getSubdomainFromPath(context: any) {
54
73
  var { path } = context
55
74
 
@@ -68,16 +87,34 @@ function getSubdomainFromPath(context: any) {
68
87
  }
69
88
  }
70
89
 
90
+ /**
91
+ * Extracts a subdomain based on virtual host.
92
+ *
93
+ * @param context {Object} An object containing the current request context information.
94
+ * @returns {string} The extracted subdomain.
95
+ */
71
96
  function getSubdomainFromVhost(context: any) {
72
97
  const subdomain = (context.subdomains || getSubdomainsFromHost(context)).slice(-1)[0]
73
98
 
74
99
  return subdomain
75
100
  }
76
101
 
102
+ /**
103
+ * Extracts a subdomain from the URL context.
104
+ *
105
+ * @param context {Object} An object containing the current request context information.
106
+ * @returns {string} The extracted subdomain.
107
+ */
77
108
  function getSubdomainFromURL(context) {
78
109
  return fixed || (useVirtualHostBasedDomain ? getSubdomainFromVhost(context) : getSubdomainFromPath(context))
79
110
  }
80
111
 
112
+ /**
113
+ * Asynchronously searches for a domain object based on the URL context.
114
+ *
115
+ * @param context {Object} An object containing the current request context information.
116
+ * @returns {Promise<Domain>} A promise that resolves to the domain object.
117
+ */
81
118
  export async function getDomainFromURL(context: any): Promise<Domain> {
82
119
  const { header } = context
83
120
 
@@ -88,16 +125,36 @@ export async function getDomainFromURL(context: any): Promise<Domain> {
88
125
  }
89
126
  }
90
127
 
128
+ /**
129
+ * Extracts the cookie domain from the hostname.
130
+ *
131
+ * @param hostname {string} The hostname.
132
+ * @returns {string} The extracted cookie domain.
133
+ */
91
134
  export function getCookieDomainFromHostname(hostname) {
92
135
  if (useVirtualHostBasedDomain) {
93
136
  return hostname.split('.').slice(-subdomainOffset).join('.')
94
137
  }
95
138
  }
96
139
 
140
+ /**
141
+ * Generates a context path based on the subdomain.
142
+ *
143
+ * @param subdomain {string} The subdomain.
144
+ * @returns {string} The generated context path.
145
+ */
97
146
  export function getContextPath(subdomain) {
98
147
  return fixed || useVirtualHostBasedDomain ? '' : '/domain/' + subdomain
99
148
  }
100
149
 
150
+ /**
151
+ * Generates a redirection path considering the subdomain.
152
+ *
153
+ * @param context {Object} An object containing the current request context information.
154
+ * @param subdomain {string} The subdomain.
155
+ * @param redirectTo {string} The path to redirect to (optional).
156
+ * @returns {string} The generated redirection path.
157
+ */
101
158
  export function getRedirectSubdomainPath(context, subdomain, redirectTo = '/') {
102
159
  if (fixed) {
103
160
  return redirectTo || '/'
@@ -127,6 +184,13 @@ export function getRedirectSubdomainPath(context, subdomain, redirectTo = '/') {
127
184
  return parsed.toString()
128
185
  }
129
186
 
187
+ /**
188
+ * Finds a subdomain from the given path.
189
+ *
190
+ * @param context {Object} An object containing the current request context information.
191
+ * @param path {string} The path to search in.
192
+ * @returns {string} The found subdomain.
193
+ */
130
194
  export function findSubdomainFromPath(context, path) {
131
195
  if (fixed) {
132
196
  return fixed
@@ -143,6 +207,12 @@ export function findSubdomainFromPath(context, path) {
143
207
  return match && match[1]
144
208
  }
145
209
 
210
+ /**
211
+ * Generates a site root path based on the current environment.
212
+ *
213
+ * @param context {Object} An object containing the current request context information.
214
+ * @returns {string} The generated site root path.
215
+ */
146
216
  export function getSiteRootPath(context) {
147
217
  if (useVirtualHostBasedDomain) {
148
218
  var { protocol, host } = context
@@ -5,9 +5,19 @@ import { Filter, ListParam, InheritedValueType } from '../service/common-types/l
5
5
  import { Domain } from '../service/domain/domain'
6
6
 
7
7
  /**
8
+ * Function to create a TypeORM SelectQueryBuilder for database queries.
8
9
  *
9
- * @param options
10
- * @returns
10
+ * @param options - An object containing options for querying and building.
11
+ * @param options.repository - TypeORM repository used for database operations.
12
+ * @param options.params - ListParam object for data retrieval and manipulation.
13
+ * @param [options.domain] - Optional domain object for applying domain-related filters.
14
+ * @param [options.alias] - Alias to be used in SQL queries (optional).
15
+ * @param [options.searchables] - List of searchable columns (optional).
16
+ * @param [options.filtersMap] - Mapping of filter names to their corresponding columns or relation columns (optional).
17
+ * @param [options.filtersMap.name] - Filter name.
18
+ * @param [options.filtersMap.columnName] - Name of the column where the filter is applied.
19
+ * @param [options.filtersMap.relationColumn] - If the filter is applied to a related column, the name of that relation column (optional).
20
+ * @returns {SelectQueryBuilder<Type>} - The generated SelectQueryBuilder object.
11
21
  */
12
22
  export function getQueryBuilderFromListParams<Type>(options: {
13
23
  repository: Repository<Type>
@@ -29,10 +39,7 @@ export function getQueryBuilderFromListParams<Type>(options: {
29
39
  return false
30
40
  }
31
41
  if (filter.operator.toLowerCase().includes('like') && (!searchables || !searchables.includes(filter.name))) {
32
- console.warn(
33
- '"searchables" setting is required for like searches with a heavy database query load',
34
- filter.name
35
- )
42
+ console.warn('"searchables" setting is required for like searches with a heavy database query load', filter.name)
36
43
  return false
37
44
  }
38
45
  return true
@@ -44,10 +51,7 @@ export function getQueryBuilderFromListParams<Type>(options: {
44
51
  return false
45
52
  }
46
53
  if (!searchables.includes(filter.name)) {
47
- console.warn(
48
- '"searchables" setting is required for like searches with a heavy database query load',
49
- filter.name
50
- )
54
+ console.warn('"searchables" setting is required for like searches with a heavy database query load', filter.name)
51
55
  return false
52
56
  }
53
57
  return true
@@ -107,6 +111,16 @@ export function getQueryBuilderFromListParams<Type>(options: {
107
111
  return selectQueryBuilder
108
112
  }
109
113
 
114
+ /**
115
+ * Add a condition to a TypeORM SelectQueryBuilder based on the provided filter and mapping options.
116
+ *
117
+ * @param {EntityMetadata} metadata - The EntityMetadata for the TypeORM entity.
118
+ * @param {SelectQueryBuilder<Type>} selectQueryBuilder - The SelectQueryBuilder to add the condition to.
119
+ * @param {WhereExpressionBuilder} whereExpressionBuilder - The WhereExpressionBuilder to build the condition.
120
+ * @param {Filter} filter - The filter object containing the filter conditions.
121
+ * @param {Object} filtersMap - A mapping of filter names to column names and relation column names.
122
+ * @param {boolean} andCondition - Flag indicating whether to use "AND" or "OR" for combining conditions.
123
+ */
110
124
  function addCondition<T>(
111
125
  metadata: EntityMetadata,
112
126
  selectQueryBuilder: SelectQueryBuilder<T>,
@@ -172,9 +186,7 @@ function addCondition<T>(
172
186
  if (relationIdMeta) {
173
187
  columnMeta = relationIdMeta.relation.joinColumns[0]
174
188
  } else {
175
- columnName
176
- ? console.warn(`columnName "${columnName}" in filtersMap for "${name}" is not a column`)
177
- : console.warn(`name "${name}" is not a column`)
189
+ columnName ? console.warn(`columnName "${columnName}" in filtersMap for "${name}" is not a column`) : console.warn(`name "${name}" is not a column`)
178
190
  }
179
191
  } else {
180
192
  var relation = columnMeta.relationMetadata
@@ -322,8 +334,6 @@ function addCondition<T>(
322
334
  whereExpressionBuilder.orWhere(clause, parameters)
323
335
  }
324
336
  } else {
325
- andCondition
326
- ? whereExpressionBuilder.andWhere(clause, parameters)
327
- : whereExpressionBuilder.orWhere(clause, parameters)
337
+ andCondition ? whereExpressionBuilder.andWhere(clause, parameters) : whereExpressionBuilder.orWhere(clause, parameters)
328
338
  }
329
339
  }
@@ -1,9 +1,13 @@
1
1
  import moment from 'moment-timezone'
2
2
 
3
- export async function getTimesForPeriod(
4
- period: 'today' | 'this month' | '30 days' | 'this year' | '12 months',
5
- context: any
6
- ): Promise<{ from: string; to: string }> {
3
+ /**
4
+ * Get the time range for the specified period relative to the current moment in a specific domain's timezone.
5
+ *
6
+ * @param {string} period - The time period to calculate the range for. Valid options are 'today', 'this month', '30 days', 'this year', '12 months'.
7
+ * @param {Object} context - The context object containing domain information.
8
+ * @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.
9
+ */
10
+ export async function getTimesForPeriod(period: 'today' | 'this month' | '30 days' | 'this year' | '12 months', context: any): Promise<{ from: string; to: string }> {
7
11
  const { domain } = context.state
8
12
  const theDate = moment.tz(new Date(), domain.timezone)
9
13
 
@@ -35,6 +39,13 @@ export async function getTimesForPeriod(
35
39
  }
36
40
  }
37
41
 
42
+ /**
43
+ * Get the ISO date strings for the specified period relative to the current moment in a specific domain's timezone.
44
+ *
45
+ * @param {string} period - The time period to calculate the range for. Valid options are 'today', 'this month', '30 days', 'this year', '12 months'.
46
+ * @param {Object} context - The context object containing domain information.
47
+ * @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.
48
+ */
38
49
  export async function getISOStringsForPeriod(
39
50
  period: 'today' | 'this month' | '30 days' | 'this year' | '12 months',
40
51
  context: any
@@ -1,5 +1,14 @@
1
1
  import { Filter } from '../service/common-types'
2
2
 
3
+ /**
4
+ * Adjust the given array of filters based on the provided changes.
5
+ * If a filter with the same name exists in the original array, it will be replaced with the new filter;
6
+ * otherwise, the new filter will be added to the array.
7
+ *
8
+ * @param {Filter[]} filters - The original array of filters to be adjusted.
9
+ * @param {Filter[]} filtersChange - The array of filter changes to be applied.
10
+ * @returns {Filter[]} - The adjusted array of filters.
11
+ */
3
12
  export function adjustFilters(filters: Filter[], filtersChange: Filter[]): Filter[] {
4
13
  var filtersNew = [...filters]
5
14
 
@@ -29,10 +29,20 @@ const OPERATION_FUNCTION_MAP: { [operator: string]: (value: any) => FindOperator
29
29
  between: value => Between(value[0], value[1])
30
30
  }
31
31
 
32
+ /**
33
+ * Get the TypeORM FindOperator function for a given filter.
34
+ * @param {Filter} filter - The filter object containing operator and value.
35
+ * @returns {FindOperator<any>} - The corresponding FindOperator function.
36
+ */
32
37
  function getOperatorFunction({ operator, value }: Filter): FindOperator<any> {
33
38
  return OPERATION_FUNCTION_MAP[operator](value)
34
39
  }
35
40
 
41
+ /**
42
+ * Create pagination parameters for a TypeORM query.
43
+ * @param {Pagination} pagination - The pagination object.
44
+ * @returns {{ skip?: number; take?: number }} - The pagination parameters.
45
+ */
36
46
  function makePaginationParams(pagination: Pagination): { skip?: number; take?: number } {
37
47
  var result = {} as { skip?: number; take?: number }
38
48
  if (pagination) {
@@ -53,6 +63,11 @@ function makePaginationParams(pagination: Pagination): { skip?: number; take?: n
53
63
  return result
54
64
  }
55
65
 
66
+ /**
67
+ * Create sorting parameters for a TypeORM query.
68
+ * @param {Sorting[]} sortings - The array of sorting objects.
69
+ * @returns {{ order?: { [name: string]: 'DESC' | 'ASC' } }} - The sorting parameters.
70
+ */
56
71
  function makeSortingParams(sortings: Sorting[]): { order?: { [name: string]: 'DESC' | 'ASC' } } {
57
72
  var result = {} as { order?: { [name: string]: 'DESC' | 'ASC' } }
58
73
  if (sortings) {
@@ -69,6 +84,12 @@ function makeSortingParams(sortings: Sorting[]): { order?: { [name: string]: 'DE
69
84
  return result
70
85
  }
71
86
 
87
+ /**
88
+ * Create filter parameters for a TypeORM query.
89
+ * @param {Filter[]} filters - The array of filter objects.
90
+ * @param {string[]} searchables - The array of searchable field names.
91
+ * @returns {{ where: { [name: string]: FindOperator<any> } | { [name: string]: FindOperator<any> }[] }} - The filter parameters.
92
+ */
72
93
  function makeFilterParams(
73
94
  filters: Filter[],
74
95
  searchables?: string[]
@@ -94,10 +115,7 @@ function makeFilterParams(
94
115
  return false
95
116
  }
96
117
  if (!searchables.includes(filter.name)) {
97
- console.warn(
98
- '"searchables" setting is required for like searches with a heavy database query load',
99
- filter.name
100
- )
118
+ console.warn('"searchables" setting is required for like searches with a heavy database query load', filter.name)
101
119
  return false
102
120
  }
103
121
  return true
@@ -128,6 +146,12 @@ function makeFilterParams(
128
146
  }
129
147
  }
130
148
 
149
+ /**
150
+ * Convert ListParam object to TypeORM query parameters.
151
+ * @param {ListParam} params - The ListParam object containing pagination, sorting, and filtering options.
152
+ * @param {string | { domain?: string | Domain; searchables?: string[] }} options - Optional domain and searchables parameters.
153
+ * @returns {{ where?: { [name: string]: FindOperator<any> }; order?: { [name: string]: 'DESC' | 'ASC' }; skip?: number; take?: number }} - The TypeORM query parameters.
154
+ */
131
155
  export function convertListParams(
132
156
  params: ListParam,
133
157
  options?:
@@ -4,7 +4,16 @@ import { buildCondition } from './condition-builder'
4
4
  import { Filter, ListParam, InheritedValueType } from '../service/common-types/list-param'
5
5
 
6
6
  /**
7
- * @deprecated The name of this function does not imply an exact purpose and it is not possible to correspond to a foreign key using the meta information of the table column, so it is recommended to replace it with the getQueryBuilderFromListParams function.
7
+ * @deprecated This function is recommended to be replaced with the `getQueryBuilderFromListParams` function.
8
+ *
9
+ * Builds a TypeORM query using the provided parameters to filter, paginate, and sort the data.
10
+ *
11
+ * @param {QueryBuilder} queryBuilder - The TypeORM query builder to build the query on.
12
+ * @param {ListParam} params - The list parameters to apply to the query.
13
+ * @param {Object} context - The context object, typically containing information about the user's domain.
14
+ * @param {boolean|Object} options - Additional options for the query builder.
15
+ * @param {boolean} options.domainRef - Indicates whether to include domain reference in the query.
16
+ * @param {string[]} options.searchables - An array of searchable field names.
8
17
  */
9
18
  export const buildQuery = function (
10
19
  queryBuilder: any,
@@ -31,10 +40,7 @@ export const buildQuery = function (
31
40
  return false
32
41
  }
33
42
  if (filter.operator.toLowerCase().includes('like') && (!searchables || !searchables.includes(filter.name))) {
34
- console.warn(
35
- '"searchables" setting is required for like searches with a heavy database query load',
36
- filter.name
37
- )
43
+ console.warn('"searchables" setting is required for like searches with a heavy database query load', filter.name)
38
44
  return false
39
45
  }
40
46
  return true
@@ -47,10 +53,7 @@ export const buildQuery = function (
47
53
  return false
48
54
  }
49
55
  if (!searchables.includes(filter.name)) {
50
- console.warn(
51
- '"searchables" setting is required for like searches with a heavy database query load',
52
- filter.name
53
- )
56
+ console.warn('"searchables" setting is required for like searches with a heavy database query load', filter.name)
54
57
  return false
55
58
  }
56
59
  return true
@@ -63,14 +66,7 @@ export const buildQuery = function (
63
66
 
64
67
  if (columnFilters && columnFilters.length > 0) {
65
68
  columnFilters.forEach(filter => {
66
- const condition = buildCondition(
67
- queryBuilder.alias,
68
- filter.name,
69
- filter.operator,
70
- filter.value,
71
- filter.relation,
72
- Object.keys(queryBuilder.getParameters()).length
73
- )
69
+ const condition = buildCondition(queryBuilder.alias, filter.name, filter.operator, filter.value, filter.relation, Object.keys(queryBuilder.getParameters()).length)
74
70
 
75
71
  if (condition?.clause) queryBuilder.andWhere(condition.clause)
76
72
  if (condition?.parameters) queryBuilder.setParameters(condition.parameters)
@@ -1,5 +1,14 @@
1
1
  import { pubsub } from '../pubsub'
2
2
 
3
+ /**
4
+ * Publishes a progress update message to the 'data' channel in the Pub/Sub system.
5
+ *
6
+ * @param {Object} param - The progress update parameters.
7
+ * @param {string} param.domain - The domain or category of the progress update.
8
+ * @param {string} param.tag - The tag or identifier for the progress update.
9
+ * @param {number} param.progress - The progress value indicating the completion percentage.
10
+ * @param {string} param.message - A message or description of the progress update.
11
+ */
3
12
  export function publishProgress({ domain, tag, progress, message }) {
4
13
  pubsub.publish('data', {
5
14
  data: {
@@ -1 +0,0 @@
1
- declare const webpackHotClient: any;
@@ -1,24 +0,0 @@
1
- /*
2
- Copyright © 2016 Andrew Powell
3
-
4
- This Source Code Form is subject to the terms of the Mozilla Public
5
- License, v. 2.0. If a copy of the MPL was not distributed with this
6
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
-
8
- The above copyright notice and this permission notice shall be
9
- included in all copies or substantial portions of this Source Code Form.
10
- */
11
- const webpackHotClient = require('@hatiolab/webpack-hot-client');
12
- module.exports = {
13
- getClient(compiler, options) {
14
- if (!options.hotClient) {
15
- return Promise.resolve(null);
16
- }
17
- return new Promise(resolve => {
18
- const client = webpackHotClient(compiler, options.hotClient);
19
- const { server } = client;
20
- server.on('listening', () => resolve(client));
21
- });
22
- }
23
- };
24
- //# sourceMappingURL=client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../server/webpack/koa-webpack/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AACF,MAAM,gBAAgB,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAA;AAEhE,MAAM,CAAC,OAAO,GAAG;IACf,SAAS,CAAC,QAAQ,EAAE,OAAO;QACzB,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YACtB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;SAC7B;QAED,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;YAC3B,MAAM,MAAM,GAAG,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;YAC5D,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;YAEzB,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;QAC/C,CAAC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA","sourcesContent":["/*\n Copyright © 2016 Andrew Powell\n\n This Source Code Form is subject to the terms of the Mozilla Public\n License, v. 2.0. If a copy of the MPL was not distributed with this\n file, You can obtain one at http://mozilla.org/MPL/2.0/.\n\n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of this Source Code Form.\n*/\nconst webpackHotClient = require('@hatiolab/webpack-hot-client')\n\nmodule.exports = {\n getClient(compiler, options) {\n if (!options.hotClient) {\n return Promise.resolve(null)\n }\n\n return new Promise(resolve => {\n const client = webpackHotClient(compiler, options.hotClient)\n const { server } = client\n\n server.on('listening', () => resolve(client))\n })\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- declare const _default: (opts: any) => Promise<any>;
2
- export default _default;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /*
4
- Copyright © 2016 Andrew Powell
5
-
6
- This Source Code Form is subject to the terms of the Mozilla Public
7
- License, v. 2.0. If a copy of the MPL was not distributed with this
8
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
-
10
- The above copyright notice and this permission notice shall be
11
- included in all copies or substantial portions of this Source Code Form.
12
- */
13
- const { join } = require('path');
14
- const root = require('app-root-path');
15
- const chalk = require('chalk');
16
- const webpack = require('webpack');
17
- const webpackDevMiddleware = require('webpack-dev-middleware');
18
- const { getClient } = require('./client');
19
- const { getMiddleware } = require('./middleware');
20
- const { validate } = require('./validate');
21
- const defaults = { devMiddleware: {}, hotClient: {} };
22
- exports.default = async (opts) => {
23
- const valid = validate(opts);
24
- if (valid.error) {
25
- const { error } = console;
26
- error(chalk.red('⬢ koa-webpack:'), 'An option was passed to koa-webpack that is not valid');
27
- throw valid.error;
28
- }
29
- const options = Object.assign({}, defaults, opts);
30
- let { compiler, config } = options;
31
- if (!compiler) {
32
- if (!config) {
33
- // eslint-disable-next-line import/no-dynamic-require, global-require
34
- config = require(options.configPath || join(root.path, 'webpack.config.js'));
35
- }
36
- compiler = webpack(config);
37
- }
38
- if (!options.devMiddleware.publicPath) {
39
- const { publicPath } = compiler.options.output;
40
- if (!publicPath) {
41
- throw new Error("koa-webpack: publicPath must be set on `dev` options, or in a compiler's `output` configuration.");
42
- }
43
- options.devMiddleware.publicPath = publicPath;
44
- }
45
- const hotClient = await getClient(compiler, options);
46
- const devMiddleware = webpackDevMiddleware(compiler, options.devMiddleware);
47
- const middleware = getMiddleware(compiler, devMiddleware);
48
- const close = callback => {
49
- const next = hotClient ? () => hotClient.close(callback) : callback;
50
- devMiddleware.close(next);
51
- };
52
- return Object.assign(middleware, {
53
- hotClient,
54
- devMiddleware,
55
- close
56
- });
57
- };
58
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/webpack/koa-webpack/index.ts"],"names":[],"mappings":";;AAAA;;;;;;;;;EASE;AACF,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAEhC,MAAM,IAAI,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;AACrC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAClC,MAAM,oBAAoB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAA;AAE9D,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AACzC,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AACjD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;AAE1C,MAAM,QAAQ,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAA;AAErD,kBAAe,KAAK,EAAC,IAAI,EAAC,EAAE;IAC1B,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;IAE5B,IAAI,KAAK,CAAC,KAAK,EAAE;QACf,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;QACzB,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,uDAAuD,CAAC,CAAA;QAC3F,MAAM,KAAK,CAAC,KAAK,CAAA;KAClB;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;IAEjD,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAElC,IAAI,CAAC,QAAQ,EAAE;QACb,IAAI,CAAC,MAAM,EAAE;YACX,qEAAqE;YACrE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAA;SAC7E;QAED,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;KAC3B;IAED,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,EAAE;QACrC,MAAM,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAA;QAE9C,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,KAAK,CACb,kGAAkG,CACnG,CAAA;SACF;QAED,OAAO,CAAC,aAAa,CAAC,UAAU,GAAG,UAAU,CAAA;KAC9C;IAED,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACpD,MAAM,aAAa,GAAG,oBAAoB,CAAC,QAAQ,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;IAC3E,MAAM,UAAU,GAAG,aAAa,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAA;IACzD,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAE;QACvB,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;QACnE,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC,CAAA;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;QAC/B,SAAS;QACT,aAAa;QACb,KAAK;KACN,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["/*\n Copyright © 2016 Andrew Powell\n\n This Source Code Form is subject to the terms of the Mozilla Public\n License, v. 2.0. If a copy of the MPL was not distributed with this\n file, You can obtain one at http://mozilla.org/MPL/2.0/.\n\n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of this Source Code Form.\n*/\nconst { join } = require('path')\n\nconst root = require('app-root-path')\nconst chalk = require('chalk')\nconst webpack = require('webpack')\nconst webpackDevMiddleware = require('webpack-dev-middleware')\n\nconst { getClient } = require('./client')\nconst { getMiddleware } = require('./middleware')\nconst { validate } = require('./validate')\n\nconst defaults = { devMiddleware: {}, hotClient: {} }\n\nexport default async opts => {\n const valid = validate(opts)\n\n if (valid.error) {\n const { error } = console\n error(chalk.red('⬢ koa-webpack:'), 'An option was passed to koa-webpack that is not valid')\n throw valid.error\n }\n\n const options = Object.assign({}, defaults, opts)\n\n let { compiler, config } = options\n\n if (!compiler) {\n if (!config) {\n // eslint-disable-next-line import/no-dynamic-require, global-require\n config = require(options.configPath || join(root.path, 'webpack.config.js'))\n }\n\n compiler = webpack(config)\n }\n\n if (!options.devMiddleware.publicPath) {\n const { publicPath } = compiler.options.output\n\n if (!publicPath) {\n throw new Error(\n \"koa-webpack: publicPath must be set on `dev` options, or in a compiler's `output` configuration.\"\n )\n }\n\n options.devMiddleware.publicPath = publicPath\n }\n\n const hotClient = await getClient(compiler, options)\n const devMiddleware = webpackDevMiddleware(compiler, options.devMiddleware)\n const middleware = getMiddleware(compiler, devMiddleware)\n const close = callback => {\n const next = hotClient ? () => hotClient.close(callback) : callback\n devMiddleware.close(next)\n }\n\n return Object.assign(middleware, {\n hotClient,\n devMiddleware,\n close\n })\n}\n"]}
File without changes
@@ -1,42 +0,0 @@
1
- /*
2
- Copyright © 2016 Andrew Powell
3
-
4
- This Source Code Form is subject to the terms of the Mozilla Public
5
- License, v. 2.0. If a copy of the MPL was not distributed with this
6
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
-
8
- The above copyright notice and this permission notice shall be
9
- included in all copies or substantial portions of this Source Code Form.
10
- */
11
- module.exports = {
12
- getMiddleware(compiler, devMiddleware) {
13
- return (context, next) => {
14
- // wait for webpack-dev-middleware to signal that the build is ready
15
- const ready = new Promise((resolve, reject) => {
16
- for (const comp of [].concat(compiler.compilers || compiler)) {
17
- comp.hooks.failed.tap('KoaWebpack', error => {
18
- reject(error);
19
- });
20
- }
21
- devMiddleware.waitUntilValid(() => {
22
- resolve(true);
23
- });
24
- });
25
- // tell webpack-dev-middleware to handle the request
26
- const init = new Promise(resolve => {
27
- devMiddleware(context.req, {
28
- end: content => {
29
- // eslint-disable-next-line no-param-reassign
30
- context.body = content;
31
- resolve(null);
32
- },
33
- getHeader: context.get.bind(context),
34
- setHeader: context.set.bind(context),
35
- locals: context.state
36
- }, () => resolve(next()));
37
- });
38
- return Promise.all([ready, init]);
39
- };
40
- }
41
- };
42
- //# sourceMappingURL=middleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../server/webpack/koa-webpack/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AACF,MAAM,CAAC,OAAO,GAAG;IACf,aAAa,CAAC,QAAQ,EAAE,aAAa;QACnC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;YACvB,oEAAoE;YACpE,MAAM,KAAK,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC5C,KAAK,MAAM,IAAI,IAAI,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,EAAE;oBAC5D,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE;wBAC1C,MAAM,CAAC,KAAK,CAAC,CAAA;oBACf,CAAC,CAAC,CAAA;iBACH;gBAED,aAAa,CAAC,cAAc,CAAC,GAAG,EAAE;oBAChC,OAAO,CAAC,IAAI,CAAC,CAAA;gBACf,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;YACF,oDAAoD;YACpD,MAAM,IAAI,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;gBACjC,aAAa,CACX,OAAO,CAAC,GAAG,EACX;oBACE,GAAG,EAAE,OAAO,CAAC,EAAE;wBACb,6CAA6C;wBAC7C,OAAO,CAAC,IAAI,GAAG,OAAO,CAAA;wBACtB,OAAO,CAAC,IAAI,CAAC,CAAA;oBACf,CAAC;oBACD,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;oBACpC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;oBACpC,MAAM,EAAE,OAAO,CAAC,KAAK;iBACtB,EACD,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CACtB,CAAA;YACH,CAAC,CAAC,CAAA;YAEF,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;QACnC,CAAC,CAAA;IACH,CAAC;CACF,CAAA","sourcesContent":["/*\n Copyright © 2016 Andrew Powell\n\n This Source Code Form is subject to the terms of the Mozilla Public\n License, v. 2.0. If a copy of the MPL was not distributed with this\n file, You can obtain one at http://mozilla.org/MPL/2.0/.\n\n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of this Source Code Form.\n*/\nmodule.exports = {\n getMiddleware(compiler, devMiddleware) {\n return (context, next) => {\n // wait for webpack-dev-middleware to signal that the build is ready\n const ready = new Promise((resolve, reject) => {\n for (const comp of [].concat(compiler.compilers || compiler)) {\n comp.hooks.failed.tap('KoaWebpack', error => {\n reject(error)\n })\n }\n\n devMiddleware.waitUntilValid(() => {\n resolve(true)\n })\n })\n // tell webpack-dev-middleware to handle the request\n const init = new Promise(resolve => {\n devMiddleware(\n context.req,\n {\n end: content => {\n // eslint-disable-next-line no-param-reassign\n context.body = content\n resolve(null)\n },\n getHeader: context.get.bind(context),\n setHeader: context.set.bind(context),\n locals: context.state\n },\n () => resolve(next())\n )\n })\n\n return Promise.all([ready, init])\n }\n }\n}\n"]}
@@ -1 +0,0 @@
1
- declare const Joi: any;
@@ -1,26 +0,0 @@
1
- /*
2
- Copyright © 2016 Andrew Powell
3
-
4
- This Source Code Form is subject to the terms of the Mozilla Public
5
- License, v. 2.0. If a copy of the MPL was not distributed with this
6
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
-
8
- The above copyright notice and this permission notice shall be
9
- included in all copies or substantial portions of this Source Code Form.
10
- */
11
- const Joi = require('joi');
12
- module.exports = {
13
- validate(options) {
14
- const keys = {
15
- compiler: [Joi.object().allow(null)],
16
- config: [Joi.object().allow(null)],
17
- configPath: [Joi.string().allow(null)],
18
- devMiddleware: [Joi.object()],
19
- hotClient: [Joi.boolean(), Joi.object().allow(null)]
20
- };
21
- const schema = Joi.object().keys(keys);
22
- const results = schema.validate(options);
23
- return results;
24
- }
25
- };
26
- //# sourceMappingURL=validate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../server/webpack/koa-webpack/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AACF,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;AAE3B,MAAM,CAAC,OAAO,GAAG;IACf,QAAQ,CAAC,OAAO;QACd,MAAM,IAAI,GAAG;YACX,QAAQ,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACpC,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAClC,UAAU,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACtC,aAAa,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;YAC7B,SAAS,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SACrD,CAAC;QACF,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAEzC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAC","sourcesContent":["/*\n Copyright © 2016 Andrew Powell\n\n This Source Code Form is subject to the terms of the Mozilla Public\n License, v. 2.0. If a copy of the MPL was not distributed with this\n file, You can obtain one at http://mozilla.org/MPL/2.0/.\n\n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of this Source Code Form.\n*/\nconst Joi = require('joi');\n\nmodule.exports = {\n validate(options) {\n const keys = {\n compiler: [Joi.object().allow(null)],\n config: [Joi.object().allow(null)],\n configPath: [Joi.string().allow(null)],\n devMiddleware: [Joi.object()],\n hotClient: [Joi.boolean(), Joi.object().allow(null)]\n };\n const schema = Joi.object().keys(keys);\n const results = schema.validate(options);\n\n return results;\n }\n};\n"]}
@@ -1,26 +0,0 @@
1
- /*
2
- Copyright © 2016 Andrew Powell
3
-
4
- This Source Code Form is subject to the terms of the Mozilla Public
5
- License, v. 2.0. If a copy of the MPL was not distributed with this
6
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
-
8
- The above copyright notice and this permission notice shall be
9
- included in all copies or substantial portions of this Source Code Form.
10
- */
11
- const webpackHotClient = require('@hatiolab/webpack-hot-client')
12
-
13
- module.exports = {
14
- getClient(compiler, options) {
15
- if (!options.hotClient) {
16
- return Promise.resolve(null)
17
- }
18
-
19
- return new Promise(resolve => {
20
- const client = webpackHotClient(compiler, options.hotClient)
21
- const { server } = client
22
-
23
- server.on('listening', () => resolve(client))
24
- })
25
- }
26
- }