pockethost 1.4.0 → 1.5.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # pockethost
2
2
 
3
+ ## 1.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5e9ed51: Added `--extra-plugins` global switch to temporarily load extra plugins from CLI
8
+ - 2376b0d: Add InstanceConfig filter, fix instance logger namespace, add core instance app lib
9
+ - 737b4b8: logSettings now exported from core
10
+ - 114b1d2: Add namespace() export to core Logger service
11
+
12
+ ### Patch Changes
13
+
14
+ - 211fba6: Plugin authoring docs update
15
+ - 675e634: Added docs and updated maildev with plugin hook guards
16
+ - 3daf7f5: Fix: [INFO] logging prefixes
17
+ - 139468f: Updated documentation
18
+ - 1e5321b: Fix: improve plugin loading order
19
+ - Updated dependencies [517f602]
20
+ - @pockethost/plugin-launcher-spawn@0.3.0
21
+ - @pockethost/plugin-console-logger@0.2.1
22
+ - @pockethost/plugin-auto-admin@0.1.1
23
+
3
24
  ## 1.4.0
4
25
 
5
26
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pockethost",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "author": {
5
5
  "name": "Ben Allfree",
6
6
  "url": "https://github.com/benallfree"
@@ -26,8 +26,10 @@
26
26
  "express-async-errors": "^3.1.1",
27
27
  "get-port": "^6.1.2",
28
28
  "http-proxy": "^1.18.1",
29
+ "immer": "^10.1.1",
29
30
  "json-stringify-safe": "^5.0.1",
30
31
  "listr2": "^8.2.3",
32
+ "minimist": "^1.2.8",
31
33
  "nanoid": "^5.0.2",
32
34
  "node-fetch": "^3.3.2",
33
35
  "pocketbase": "^0.21.3",
@@ -39,14 +41,15 @@
39
41
  "typescript": "^5.4.5",
40
42
  "update-notifier": "^7.0.0",
41
43
  "url-pattern": "^1.0.3",
42
- "@pockethost/plugin-console-logger": "^0.2.0",
43
- "@pockethost/plugin-auto-admin": "^0.1.0",
44
- "@pockethost/plugin-launcher-spawn": "^0.2.0"
44
+ "@pockethost/plugin-auto-admin": "^0.1.1",
45
+ "@pockethost/plugin-console-logger": "^0.2.1",
46
+ "@pockethost/plugin-launcher-spawn": "^0.3.0"
45
47
  },
46
48
  "devDependencies": {
47
49
  "@types/express": "^4.17.21",
48
50
  "@types/http-proxy": "^1.17.13",
49
51
  "@types/json-stringify-safe": "^5.0.2",
52
+ "@types/minimist": "^1.2.5",
50
53
  "@types/node": "^20.8.10",
51
54
  "@types/semver": "^7.5.4",
52
55
  "@types/tmp": "^0.2.5",
package/readme.md CHANGED
@@ -48,11 +48,12 @@ PocketHost uses a hook architecture and features a growing list plugins. Some pl
48
48
 
49
49
  Current plugins:
50
50
 
51
- | name | description |
52
- | --------------------- | ------------------------------------------------------------------------------------------------- |
53
- | plugin-console-logger | Routes log messages to the console |
54
- | plugin-auto-admin | Auto-creates a default admin account on instance launch |
55
- | plugin-launcher-spawn | Launches PocketBase instances via `spawn()` on the local machine. PocketHost uses this by default |
51
+ | name | description |
52
+ | -------------------------------- | ------------------------------------------------------------------------------------------------- |
53
+ | plugin-console-logger | Routes log messages to the console |
54
+ | plugin-auto-admin | Auto-creates a default admin account on instance launch |
55
+ | plugin-launcher-spawn | Launches PocketBase instances via `spawn()` on the local machine. PocketHost uses this by default |
56
+ | plugin-cloudflare-request-logger | Log additional data when running behind Cloudflare |
56
57
 
57
58
  Coming soon:
58
59
  | name | description |
@@ -6,7 +6,7 @@ import {
6
6
  } from '../../../common'
7
7
 
8
8
  type Options = {
9
- isolate: boolean
9
+ only: string[]
10
10
  }
11
11
 
12
12
  export const ServeCommand = async () => {
@@ -24,12 +24,13 @@ export const ServeCommand = async () => {
24
24
  .filter((s) => serveSlugs.includes(s)),
25
25
  serveSlugs,
26
26
  )
27
- .action(async (options: Options) => {
27
+ .action(async (options: Options, cmd: Command) => {
28
28
  const logger = LoggerService().create(`ServeCommand`)
29
29
  const { dbg, error, info, warn } = logger
30
30
  info(`Starting`)
31
31
 
32
- await doServeAction({ only: serveSlugs })
32
+ const { only } = options
33
+ await doServeAction({ only })
33
34
  })
34
35
  return cmd
35
36
  }
package/src/cli/index.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  import { uniq } from '@s-libs/micro-dash'
4
4
  import { program } from 'commander'
5
5
  import { readFileSync } from 'fs'
6
+ import minimist from 'minimist'
6
7
  import updateNotifier from 'update-notifier'
7
8
  import { PH_PLUGINS, PH_PROJECT_DIR } from '../../core'
8
9
  import {
@@ -12,7 +13,7 @@ import {
12
13
  doCliCommandsFilter,
13
14
  loadPlugins,
14
15
  } from '../common'
15
- import { pockethost } from '../server'
16
+ import { pockethost } from '../plugin'
16
17
  import { ConfigCommand } from './commands/ConfigCommand'
17
18
  import { PluginCommand } from './commands/PluginCommand'
18
19
  import { ServeCommand } from './commands/ServeCommand'
@@ -21,9 +22,11 @@ export const { dbg, info, error } = LoggerService({
21
22
  level: DEBUG() ? LogLevelName.Debug : LogLevelName.Info,
22
23
  })
23
24
 
24
- export const main = async () => {
25
- await loadPlugins([pockethost, ...uniq(PH_PLUGINS())])
25
+ export type GlobalOptions = {
26
+ extraPlugins: string[]
27
+ }
26
28
 
29
+ export const main = async () => {
27
30
  const pkg = await JSON.parse(
28
31
  readFileSync(PH_PROJECT_DIR(`package.json`), 'utf8').toString(),
29
32
  )
@@ -31,10 +34,20 @@ export const main = async () => {
31
34
 
32
35
  const { version } = pkg
33
36
 
37
+ const argv = minimist<{ e: string }>(process.argv.slice(2), {
38
+ alias: { e: 'extra-plugins' },
39
+ })
40
+ const extraPlugins = argv.e
41
+ .split(/,/)
42
+ .map((s) => s.trim())
43
+ .filter((v) => !!v)
44
+ await loadPlugins([pockethost, ...uniq(PH_PLUGINS()), ...extraPlugins])
45
+
34
46
  program
35
47
  .name('pockethost')
36
48
  .description('Multitenant PocketBase hosting')
37
49
  .version(version)
50
+ .option(`-e, --extra-plugins <plugins...>`, `Extra plugins to load`, [])
38
51
 
39
52
  const commands = await doCliCommandsFilter([
40
53
  await ServeCommand(),
@@ -53,6 +53,12 @@ export const LogLevels = {
53
53
  [LogLevelName.Abort]: 6,
54
54
  } as const
55
55
 
56
+ export const namespace = (...names: string[]) =>
57
+ names
58
+ .filter((v) => !!v)
59
+ .map((p) => `[${p}]`)
60
+ .join(' ')
61
+
56
62
  export const createLogger = (config: Partial<LoggerConfig>) => {
57
63
  const _config = mergeConfig<LoggerConfig>(
58
64
  {
@@ -67,11 +73,7 @@ export const createLogger = (config: Partial<LoggerConfig>) => {
67
73
  _config.level = level
68
74
  }
69
75
 
70
- const _pfx = (s: string) =>
71
- [s, ...pfx]
72
- .filter((v) => !!v)
73
- .map((p) => `[${p}]`)
74
- .join(' ')
76
+ const _pfx = (s: string) => namespace(s, ...pfx)
75
77
 
76
78
  const _log = (levelIn: LogLevelName, ...args: any[]) => {
77
79
  doLogAction({
@@ -96,7 +98,7 @@ export const createLogger = (config: Partial<LoggerConfig>) => {
96
98
  const info = (...args: any[]) => {
97
99
  const _args = (() => {
98
100
  if (isLevelGt(LogLevelName.Info, _config.level)) {
99
- return [chalk.gray(`INFO`), ...args]
101
+ return [_pfx(chalk.gray(`INFO`)), ...args]
100
102
  }
101
103
  return [...args]
102
104
  })()
@@ -9,6 +9,7 @@ export enum CoreFilters {
9
9
  SpawnConfig = 'core_spawn_config',
10
10
  GetInstanceByRequestInfo = 'core_get_instance_by_request_info',
11
11
  GetInstanceById = 'core_get_instance_by_id',
12
+ InstanceConfig = 'core_instance_config',
12
13
  ErrorSpawningInstanceMessage = 'core_error_spawning_instance_message',
13
14
  FailedToLaunchInstanceMessage = 'core_failed_to_launch_instance_message',
14
15
  AuthenticateRequest = 'core_authenticate_request',
@@ -118,3 +119,20 @@ export const [
118
119
  export const [doServeSlugsFilter, onServeSlugsFilter] = createCustomFilter<
119
120
  string[]
120
121
  >(CoreFilters.ServeSlugs)
122
+
123
+ export type Bind = {
124
+ base: string
125
+ src: string
126
+ }
127
+ export type Binds = {
128
+ data: Bind[]
129
+ hooks: Bind[]
130
+ migrations: Bind[]
131
+ public: Bind[]
132
+ }
133
+ export type InstanceConfig = {
134
+ binds: Binds
135
+ env: { [_: string]: string }
136
+ }
137
+ export const [doInstanceConfigFilter, onInstanceConfigFilter] =
138
+ createCustomFilter<InstanceConfig>(CoreFilters.InstanceConfig)
package/src/constants.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { forEach } from '@s-libs/micro-dash'
2
1
  import { config } from 'dotenv'
3
2
  import envPaths from 'env-paths'
4
3
  import { dirname, join } from 'path'
@@ -8,6 +7,7 @@ import { mkBoolean, mkCsvString, mkNumber, mkPath, mkString } from '../core'
8
7
  import { InstanceId } from './common'
9
8
  import { DEBUG, IS_DEV } from './common/debug'
10
9
  import { Settings } from './core/Settings'
10
+ import { logSettings } from './core/logSettings'
11
11
 
12
12
  const __dirname = dirname(fileURLToPath(import.meta.url))
13
13
 
@@ -58,12 +58,6 @@ export const NODE_ENV = () => process.env.NODE_ENV
58
58
  export const INSTANCE_DATA_DIR = (id: InstanceId, ...paths: string[]) =>
59
59
  join(DATA_DIR(), id, ...paths)
60
60
 
61
- export const logConstants = () => {
62
- forEach(settings, (v, k) => {
63
- console.log(`${k}: ${v}`)
64
- })
65
- }
66
-
67
61
  if (DEBUG()) {
68
- logConstants()
62
+ logSettings(settings)
69
63
  }
package/src/core/index.ts CHANGED
@@ -3,5 +3,6 @@ export * from './Settings'
3
3
  export * from './asyncExecutionGuard'
4
4
  export * from './exit'
5
5
  export * from './internal'
6
+ export * from './logSettings'
6
7
  export * from './smartFetch'
7
8
  export * from './tryFetch'
@@ -0,0 +1,7 @@
1
+ import { forEach } from '@s-libs/micro-dash'
2
+
3
+ export const logSettings = (settings: { [_: string]: any }) => {
4
+ forEach(settings, (v, k) => {
5
+ console.log(`${k}: ${v}`)
6
+ })
7
+ }
@@ -0,0 +1,3 @@
1
+ /// <reference path="./lib.d.ts" />
2
+ /// <reference path="./goja.d.ts" />
3
+ /// <reference path="./types.d.ts" />
@@ -0,0 +1,58 @@
1
+ interface Require {
2
+ (id: string): any
3
+ }
4
+ declare var require: Require
5
+
6
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console) */
7
+ interface Console {
8
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/assert) */
9
+ assert(condition?: boolean, ...data: any[]): void
10
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/clear) */
11
+ clear(): void
12
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/count) */
13
+ count(label?: string): void
14
+ /**
15
+ * [MDN
16
+ * Reference](https://developer.mozilla.org/docs/Web/API/console/countReset)
17
+ */
18
+ countReset(label?: string): void
19
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/debug) */
20
+ debug(...data: any[]): void
21
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/dir) */
22
+ dir(item?: any, options?: any): void
23
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/dirxml) */
24
+ dirxml(...data: any[]): void
25
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/error) */
26
+ error(...data: any[]): void
27
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/group) */
28
+ group(...data: any[]): void
29
+ /**
30
+ * [MDN
31
+ * Reference](https://developer.mozilla.org/docs/Web/API/console/groupCollapsed)
32
+ */
33
+ groupCollapsed(...data: any[]): void
34
+ /**
35
+ * [MDN
36
+ * Reference](https://developer.mozilla.org/docs/Web/API/console/groupEnd)
37
+ */
38
+ groupEnd(): void
39
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/info) */
40
+ info(...data: any[]): void
41
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log) */
42
+ log(...data: any[]): void
43
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/table) */
44
+ table(tabularData?: any, properties?: string[]): void
45
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/time) */
46
+ time(label?: string): void
47
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/timeEnd) */
48
+ timeEnd(label?: string): void
49
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/timeLog) */
50
+ timeLog(label?: string, ...data: any[]): void
51
+ timeStamp(label?: string): void
52
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/trace) */
53
+ trace(...data: any[]): void
54
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/warn) */
55
+ warn(...data: any[]): void
56
+ }
57
+
58
+ declare var console: Console
@@ -0,0 +1,5 @@
1
+ type Logger = (...args: any[]) => void
2
+
3
+ interface Lib {
4
+ mkLog: (namespace: string) => Logger
5
+ }