@moneypot/hub 1.6.1 → 1.6.2

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.
@@ -15,8 +15,9 @@ export const NODE_ENV = getEnvVariable("NODE_ENV", (value) => {
15
15
  export const PORT = getEnvVariable("PORT", (value) => {
16
16
  const parsed = Number.parseInt(value, 10);
17
17
  if (!parsed || parsed <= 0 || !Number.isSafeInteger(parsed)) {
18
- logger.warn("Warning: PORT missing or invalid, defaulting to ", parsed);
19
- return 4000;
18
+ const DEFAULT_PORT = 4000;
19
+ logger.warn(`Warning: PORT missing or invalid, defaulting to ${DEFAULT_PORT}`);
20
+ return DEFAULT_PORT;
20
21
  }
21
22
  return parsed;
22
23
  });
@@ -23,7 +23,7 @@ export type ServerOptions = {
23
23
  configureApp?: (app: Express) => void;
24
24
  plugins?: readonly GraphileConfig.Plugin[];
25
25
  extraPgSchemas?: string[];
26
- exportSchemaSDLPath: string;
26
+ exportSchemaSDLPath?: string;
27
27
  userDatabaseMigrationsPath?: string;
28
28
  logger?: Logger;
29
29
  };
package/dist/src/index.js CHANGED
@@ -62,7 +62,8 @@ export async function startAndListen(options) {
62
62
  !options.userDatabaseMigrationsPath.startsWith("/")) {
63
63
  throw new Error(`userDatabaseMigrationsPath must be an absolute path, got ${options.userDatabaseMigrationsPath}`);
64
64
  }
65
- if (!options.exportSchemaSDLPath.startsWith("/")) {
65
+ if (options.exportSchemaSDLPath &&
66
+ !options.exportSchemaSDLPath.startsWith("/")) {
66
67
  throw new Error(`exportSchemaSDLPath must be an absolute path, got ${options.exportSchemaSDLPath}`);
67
68
  }
68
69
  const abortController = new AbortController();
@@ -17,7 +17,7 @@ export declare const requiredPlugins: readonly GraphileConfig.Plugin[];
17
17
  export declare const defaultPlugins: readonly GraphileConfig.Plugin[];
18
18
  export declare function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, }: {
19
19
  plugins: readonly GraphileConfig.Plugin[];
20
- exportSchemaSDLPath: string;
20
+ exportSchemaSDLPath?: string;
21
21
  extraPgSchemas: string[];
22
22
  abortSignal: AbortSignal;
23
23
  }): GraphileConfig.Preset;
@@ -49,11 +49,13 @@ export const defaultPlugins = [
49
49
  customPgOmitArchivedPlugin("deleted"),
50
50
  ];
51
51
  export function createPreset({ plugins, exportSchemaSDLPath, extraPgSchemas, abortSignal, }) {
52
- if (!exportSchemaSDLPath.startsWith("/")) {
53
- throw new Error("exportSchemaSDLPath must be an absolute path");
54
- }
55
- if (!exportSchemaSDLPath.endsWith(".graphql")) {
56
- throw new Error("exportSchemaSDLPath must end with .graphql");
52
+ if (exportSchemaSDLPath) {
53
+ if (!exportSchemaSDLPath.startsWith("/")) {
54
+ throw new Error("exportSchemaSDLPath must be an absolute path");
55
+ }
56
+ if (!exportSchemaSDLPath.endsWith(".graphql")) {
57
+ throw new Error("exportSchemaSDLPath must end with .graphql");
58
+ }
57
59
  }
58
60
  const mutablePlugins = [...plugins];
59
61
  for (const requiredPlugin of requiredPlugins) {
@@ -0,0 +1,2 @@
1
+ import "dotenv/config";
2
+ export declare const MeaningOfLifePlugin: GraphileConfig.Plugin;
@@ -0,0 +1,31 @@
1
+ import "dotenv/config";
2
+ import { startAndListen, defaultPlugins } from "./index.js";
3
+ import { gql, makeExtendSchemaPlugin } from "./graphile.js";
4
+ import { constant } from "./grafast.js";
5
+ export const MeaningOfLifePlugin = makeExtendSchemaPlugin(() => {
6
+ return {
7
+ typeDefs: gql `
8
+ extend type Query {
9
+ meaningOfLife: Int!
10
+ }
11
+ `,
12
+ plans: {
13
+ Query: {
14
+ meaningOfLife: () => constant(42),
15
+ },
16
+ },
17
+ };
18
+ });
19
+ const options = {
20
+ extraPgSchemas: ["app"],
21
+ plugins: [...defaultPlugins, MeaningOfLifePlugin],
22
+ };
23
+ startAndListen(options)
24
+ .then(({ port }) => {
25
+ console.log(`✅ Migrated and listening on ${port}`);
26
+ process.exit(0);
27
+ })
28
+ .catch((e) => {
29
+ console.error(e);
30
+ process.exit(1);
31
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneypot/hub",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "author": "moneypot.com",
5
5
  "homepage": "https://moneypot.com/hub",
6
6
  "keywords": [
@@ -38,7 +38,8 @@
38
38
  "prepublishOnly": "npm run build",
39
39
  "codegen": "npx graphql-codegen",
40
40
  "codegen-watch": "graphql-codegen --watch",
41
- "build-dashboard": "cd ./dashboard && npm run build && rm -rf ../dist/dashboard && cp -Rv dist ../dist/dashboard"
41
+ "build-dashboard": "cd ./dashboard && npm run build && rm -rf ../dist/dashboard && cp -Rv dist ../dist/dashboard",
42
+ "test:startup": "dropdb --if-exists hub-test && createdb hub-test && SUPERUSER_DATABASE_URL=postgres://localhost:5432/hub-test DATABASE_URL=postgres://localhost:5432/hub-test tsx src/test-startup.ts"
42
43
  },
43
44
  "dependencies": {
44
45
  "@graphile-contrib/pg-omit-archived": "^4.0.0-beta.4",
@@ -68,6 +69,7 @@
68
69
  "@types/pg": "^8.11.5",
69
70
  "eslint": "^9.8.0",
70
71
  "globals": "^16.0.0",
72
+ "tsx": "^4.20.3",
71
73
  "typescript": "^5.4.5",
72
74
  "typescript-eslint": "^8.0.1"
73
75
  },