gruber 0.1.0 → 0.2.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +119 -1
  3. package/core/configuration.js +30 -25
  4. package/core/fetch-router.js +36 -23
  5. package/core/fetch-router.test.js +50 -22
  6. package/core/http.js +20 -21
  7. package/core/migrator.test.js +3 -4
  8. package/core/types.ts +41 -0
  9. package/core/utilities.js +10 -4
  10. package/package.json +12 -1
  11. package/source/node-router.js +8 -1
  12. package/source/package.json +9 -0
  13. package/source/postgres.js +18 -1
  14. package/tsconfig.json +17 -0
  15. package/types/core/configuration.d.ts +57 -0
  16. package/types/core/configuration.d.ts.map +1 -0
  17. package/types/core/configuration.test.d.ts +2 -0
  18. package/types/core/configuration.test.d.ts.map +1 -0
  19. package/types/core/fetch-router.d.ts +52 -0
  20. package/types/core/fetch-router.d.ts.map +1 -0
  21. package/types/core/fetch-router.test.d.ts +2 -0
  22. package/types/core/fetch-router.test.d.ts.map +1 -0
  23. package/types/core/http.d.ts +55 -0
  24. package/types/core/http.d.ts.map +1 -0
  25. package/types/core/http.test.d.ts +2 -0
  26. package/types/core/http.test.d.ts.map +1 -0
  27. package/types/core/migrator.d.ts +56 -0
  28. package/types/core/migrator.d.ts.map +1 -0
  29. package/types/core/migrator.test.d.ts +2 -0
  30. package/types/core/migrator.test.d.ts.map +1 -0
  31. package/types/core/mod.d.ts +7 -0
  32. package/types/core/mod.d.ts.map +1 -0
  33. package/types/core/postgres.d.ts +43 -0
  34. package/types/core/postgres.d.ts.map +1 -0
  35. package/types/core/test-deps.d.ts +2 -0
  36. package/types/core/test-deps.d.ts.map +1 -0
  37. package/types/core/types.d.ts +23 -0
  38. package/types/core/types.d.ts.map +1 -0
  39. package/types/core/utilities.d.ts +13 -0
  40. package/types/core/utilities.d.ts.map +1 -0
  41. package/types/core/utilities.test.d.ts +2 -0
  42. package/types/core/utilities.test.d.ts.map +1 -0
  43. package/types/source/configuration.d.ts +24 -0
  44. package/types/source/configuration.d.ts.map +1 -0
  45. package/types/source/core.d.ts +2 -0
  46. package/types/source/core.d.ts.map +1 -0
  47. package/types/source/express-router.d.ts +28 -0
  48. package/types/source/express-router.d.ts.map +1 -0
  49. package/types/source/koa-router.d.ts +33 -0
  50. package/types/source/koa-router.d.ts.map +1 -0
  51. package/types/source/mod.d.ts +7 -0
  52. package/types/source/mod.d.ts.map +1 -0
  53. package/types/source/node-router.d.ts +42 -0
  54. package/types/source/node-router.d.ts.map +1 -0
  55. package/types/source/polyfill.d.ts +2 -0
  56. package/types/source/polyfill.d.ts.map +1 -0
  57. package/types/source/postgres.d.ts +32 -0
  58. package/types/source/postgres.d.ts.map +1 -0
package/package.json CHANGED
@@ -1,6 +1,15 @@
1
1
  {
2
2
  "name": "gruber",
3
3
  "type": "module",
4
+ "license": "MIT",
5
+ "repository": "robb-j/gruber",
6
+ "author": {
7
+ "name": "Rob Anderson",
8
+ "url": "https://www.r0b.io"
9
+ },
10
+ "engines": {
11
+ "node": ">=20"
12
+ },
4
13
  "dependencies": {
5
14
  "superstruct": "^1.0.3",
6
15
  "urlpattern-polyfill": "^9.0.0"
@@ -12,11 +21,13 @@
12
21
  },
13
22
  "exports": {
14
23
  ".": {
24
+ "types": "./types/mod.d.ts",
15
25
  "import": "./source/mod.js"
16
26
  },
17
27
  "./*.js": {
28
+ "types": "./types/*.d.ts",
18
29
  "import": "./source/*.js"
19
30
  }
20
31
  },
21
- "version": "0.1.0"
32
+ "version": "0.2.0"
22
33
  }
@@ -22,7 +22,10 @@ import { FetchRouter } from "../core/fetch-router.js";
22
22
  export class NodeRouter {
23
23
  /** @param {NodeRouterOptions} options */
24
24
  constructor(options = {}) {
25
- this.router = new FetchRouter(options.routes ?? []);
25
+ this.router = new FetchRouter({
26
+ routes: options.routes,
27
+ errorHandler: (error, request) => this.onRouteError(error, request),
28
+ });
26
29
  }
27
30
 
28
31
  /** @param {Request} request */
@@ -38,6 +41,10 @@ export class NodeRouter {
38
41
  };
39
42
  }
40
43
 
44
+ onRouteError(error, request) {
45
+ console.error("Fatal Route Error", error);
46
+ }
47
+
41
48
  /**
42
49
  @param {import("node:http").ServerResponse} res
43
50
  @param {Response} response
@@ -1,6 +1,15 @@
1
1
  {
2
2
  "name": "gruber",
3
3
  "type": "module",
4
+ "license": "MIT",
5
+ "repository": "robb-j/gruber",
6
+ "author": {
7
+ "name": "Rob Anderson",
8
+ "url": "https://www.r0b.io"
9
+ },
10
+ "engines": {
11
+ "node": ">=20"
12
+ },
4
13
  "dependencies": {
5
14
  "superstruct": "^1.0.3",
6
15
  "urlpattern-polyfill": "^9.0.0"
@@ -10,10 +10,27 @@ import {
10
10
  export { Migrator, defineMigration };
11
11
 
12
12
  /** @typedef {import("postgres").Sql} Sql */
13
- /** @typedef {import("../core/migrator.js").MigratorOptions} MigratorOptions */
13
+
14
+ /**
15
+ * @template T
16
+ * @typedef {import("../core/migrator.js").MigratorOptions<T>} MigratorOptions
17
+ */
18
+
19
+ /**
20
+ * @template T
21
+ * @typedef {import("../core/migrator.js").MigrationOptions<T>} MigrationOptions
22
+ */
14
23
 
15
24
  const migrationExtensions = new Set([".ts", ".js"]);
16
25
 
26
+ /**
27
+ * TODO: this isn't documented
28
+ * @param {MigrationOptions<Sql>} options
29
+ */
30
+ export function definePostgresMigration(options) {
31
+ return defineMigration(options);
32
+ }
33
+
17
34
  /**
18
35
  * @typedef {object} NodePostgresMigratorOptions
19
36
  * @property {Sql} sql
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "include": [
3
+ "source/**/*",
4
+ "core/**/*"
5
+ ],
6
+ "compilerOptions": {
7
+ "target": "ESNext",
8
+ "module": "Node16",
9
+ "moduleResolution": "Node16",
10
+ "allowJs": true,
11
+ "declaration": true,
12
+ "emitDeclarationOnly": true,
13
+ "declarationMap": true,
14
+ "outDir": "types",
15
+ "skipLibCheck": true
16
+ }
17
+ }
@@ -0,0 +1,57 @@
1
+ /** @typedef {Record<string, import("superstruct").Struct<any, any>>} ObjectSchema */
2
+ export class Configuration {
3
+ static spec: symbol;
4
+ /** @param {ConfigurationOptions} options */
5
+ constructor(options: ConfigurationOptions);
6
+ options: ConfigurationOptions;
7
+ /**
8
+ * @template {ObjectSchema} T
9
+ * @param {T} spec
10
+ */
11
+ object<T extends ObjectSchema>(spec: T): any;
12
+ /**
13
+ * @template {SpecOptions} Spec @param {Spec} spec
14
+ * @returns {import("superstruct").Struct<string, null>}
15
+ */
16
+ string<Spec extends SpecOptions>(spec?: Spec): any;
17
+ /**
18
+ * @template {SpecOptions} Spec @param {Spec} spec
19
+ * @returns {import("superstruct").Struct<URL, null>}
20
+ */
21
+ url<Spec_1 extends SpecOptions>(spec: Spec_1): any;
22
+ /** @param {SpecOptions} spec */
23
+ _getValue(spec: SpecOptions): string;
24
+ /**
25
+ * @template T
26
+ * @param {URL} url
27
+ * @param {import("superstruct").Struct<T>} spec
28
+ * @returns {Promise<T>}
29
+ */
30
+ load<T_1>(url: URL, spec: any): Promise<T_1>;
31
+ /** @template T @param {T} config */
32
+ getUsage<T_2>(spec: any): string;
33
+ /**
34
+ * @template T @param {T} config
35
+ * @param {string} [prefix]
36
+ * @returns {{ config: any, fields: [string, string] }}
37
+ */
38
+ describeSpecification<T_3>(spec: any, prefix?: string): {
39
+ config: any;
40
+ fields: [string, string];
41
+ };
42
+ }
43
+ export type SpecOptions = {
44
+ variable?: string;
45
+ flag?: string;
46
+ fallback: string;
47
+ };
48
+ export type ConfigurationOptions = {
49
+ superstruct: typeof import("superstruct");
50
+ readTextFile: (url: URL) => Promise<string | null>;
51
+ getEnvironmentVariable: (key: string) => (string | undefined);
52
+ getCommandArgument: (key: string) => (string | undefined);
53
+ stringify: (value: any) => (string | Promise<string>);
54
+ parse: (value: string) => (any);
55
+ };
56
+ export type ObjectSchema = Record<string, import("superstruct").Struct<any, any>>;
57
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../core/configuration.js"],"names":[],"mappings":"AA4BA,qFAAqF;AAErF;IACC,oBAA2C;IAI3C,4CAA4C;IAC5C,qBADY,oBAAoB,EAM/B;IARD,8BAA4C;IAU5C;;;OAGG;IACH,6CAOC;IAED;;;OAGG;IACH,mDAUC;IAED;;;OAGG;IACH,mDAcC;IAED,gCAAgC;IAChC,gBADY,WAAW,UAWtB;IAED;;;;;OAKG;IACH,eAJW,GAAG,2BAkBb;IAED,oCAAoC;IACpC,iCAkBC;IAED;;;;OAIG;IACH,+CAHW,MAAM,GACJ;QAAE,MAAM,EAAE,GAAG,CAAC;QAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAkCrD;CACD;;eAtLa,MAAM;WACN,MAAM;cACN,MAAM;;;;wBAMA,GAAG,KAAK,QAAQ,MAAM,GAAG,IAAI,CAAC;kCAC9B,MAAM,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC;8BAC/B,MAAM,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC;uBAC7B,GAAG,KAAK,CAAC,MAAM,GAAG,QAAQ,MAAM,CAAC,CAAC;mBAClC,MAAM,KAAK,CAAC,GAAG,CAAC;;2BAYxB,OAAO,MAAM,EAAE,OAAO,aAAa,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=configuration.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.test.d.ts","sourceRoot":"","sources":["../../core/configuration.test.js"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
1
+ /** @typedef {import("./types.ts").RouteDefinition<any>} RouteDefinition */
2
+ /** @typedef {(error: unknown, request: Request) => unknown} RouteErrorHandler */
3
+ /**
4
+ * @typedef {object} MatchedRoute
5
+ * @property {RouteDefinition} route
6
+ * @property {URL} url
7
+ * @property {URLPatternResult} result
8
+ */
9
+ /**
10
+ * @typedef {object} FetchRouterOptions
11
+ * @property {RouteDefinition[]} [routes]
12
+ * @property {RouteErrorHandler} [errorHandler]
13
+ */
14
+ /** A rudimentary HTTP router using fetch Request & Responses with RouteDefinitions based on URLPattern */
15
+ export class FetchRouter {
16
+ /** @param {FetchRouterOptions} [options] */
17
+ constructor(options?: FetchRouterOptions);
18
+ /** @type {RouteDefinition} */ routes: import("./types.ts").RouteDefinition<any>;
19
+ /** @type {RouteErrorHandler | null} */ errorHandler: RouteErrorHandler | null;
20
+ /**
21
+ * Finds routes that match the request method and URLPattern
22
+ * and get's the matched parameters and parsed URL
23
+ * @param {Request} request
24
+ * @returns {Iterator<MatchedRoute>}
25
+ */
26
+ findMatchingRoutes(request: Request): Iterator<MatchedRoute>;
27
+ /**
28
+ * Go through each route match and try to get a Response
29
+ * @param {Request} request
30
+ * @param {Iterator<MatchedRoute>} matches
31
+ */
32
+ processMatches(request: Request, matches: Iterator<MatchedRoute>): Promise<Response>;
33
+ /**
34
+ * @param {Request} request
35
+ * @param {unknown} error
36
+ */
37
+ handleError(request: Request, error: unknown): Response;
38
+ /** @param {Request} request */
39
+ getResponse(request: Request): Promise<Response>;
40
+ }
41
+ export type RouteDefinition = import("./types.ts").RouteDefinition<any>;
42
+ export type RouteErrorHandler = (error: unknown, request: Request) => unknown;
43
+ export type MatchedRoute = {
44
+ route: import("./types.ts").RouteDefinition<any>;
45
+ url: URL;
46
+ result: URLPatternResult;
47
+ };
48
+ export type FetchRouterOptions = {
49
+ routes?: import("./types.ts").RouteDefinition<any>[];
50
+ errorHandler?: RouteErrorHandler;
51
+ };
52
+ //# sourceMappingURL=fetch-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-router.d.ts","sourceRoot":"","sources":["../../core/fetch-router.js"],"names":[],"mappings":"AAEA,2EAA2E;AAE3E,iFAAiF;AAEjF;;;;;GAKG;AAEH;;;;GAIG;AAEH,0GAA0G;AAC1G;IAIC,4CAA4C;IAC5C,sBADY,kBAAkB,EAI7B;IAPD,8BAA8B,CAAC,kDAAO;IACtC,uCAAuC,CAAC,cAA7B,iBAAiB,GAAG,IAAI,CAAkB;IAQrD;;;;;OAKG;IACH,4BAHW,OAAO,GACL,SAAS,YAAY,CAAC,CAalC;IAED;;;;OAIG;IACH,wBAHW,OAAO,WACP,SAAS,YAAY,CAAC,qBAehC;IAED;;;OAGG;IACH,qBAHW,OAAO,SACP,OAAO,YAUjB;IAED,+BAA+B;IAC/B,qBADY,OAAO,qBAUlB;CACD;8BA5Fa,OAAO,YAAY,EAAE,eAAe,CAAC,GAAG,CAAC;wCAEjC,OAAO,WAAW,OAAO,KAAK,OAAO;;;SAK7C,GAAG;YACH,gBAAgB;;;aAKhB,2CAAiB;mBACjB,iBAAiB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fetch-router.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-router.test.d.ts","sourceRoot":"","sources":["../../core/fetch-router.test.js"],"names":[],"mappings":""}
@@ -0,0 +1,55 @@
1
+ /** @typedef {import("./types.ts").HTTPMethod} HTTPMethod */
2
+ /** @typedef {import("./types.ts").RouteResult} RouteResult */
3
+ /**
4
+ * @template {string} T
5
+ * @typedef {import("./types.ts").ExtractRouteParams<T>} ExtractRouteParams */
6
+ /**
7
+ * @template T
8
+ * @typedef {import("./types.ts").RouteContext<T>} RouteContext
9
+ */
10
+ /**
11
+ * @template T
12
+ * @typedef {import("./types.ts").RouteHandler<T>} RouteHandler
13
+ */
14
+ /**
15
+ * @template {string} T
16
+ * @typedef {import("./types.ts").RouteOptions<T>} RouteOptions
17
+ */
18
+ /**
19
+ * @template [T]
20
+ * @typedef {import("./types.ts").RouteDefinition<T>} RouteDefinition
21
+ */
22
+ /**
23
+ * @template {string} T
24
+ * @param {RouteOptions<T>} init
25
+ * @returns {RouteDefinition<T>}
26
+ */
27
+ export function defineRoute<T extends string>(init: import("./types.ts").RouteOptions<T>): import("./types.ts").RouteDefinition<T>;
28
+ export class HTTPError extends Error {
29
+ /** https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400 */
30
+ static badRequest(): HTTPError;
31
+ /** https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 */
32
+ static unauthorized(): HTTPError;
33
+ /** https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404 */
34
+ static notFound(): HTTPError;
35
+ /** https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500 */
36
+ static internalServerError(): HTTPError;
37
+ /** https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/501 */
38
+ static notImplemented(): HTTPError;
39
+ /**
40
+ * @param {number} status
41
+ * @param {string} statusText
42
+ */
43
+ constructor(status?: number, statusText?: string);
44
+ /** @type {number} */ status: number;
45
+ /** @type {string}*/ statusText: string;
46
+ toResponse(): Response;
47
+ }
48
+ export type HTTPMethod = import("./types.ts").HTTPMethod;
49
+ export type RouteResult = import("./types.ts").RouteResult;
50
+ export type ExtractRouteParams<T extends string> = import("./types.ts").ExtractRouteParams<T>;
51
+ export type RouteContext<T> = import("./types.ts").RouteContext<T>;
52
+ export type RouteHandler<T> = import("./types.ts").RouteHandler<T>;
53
+ export type RouteOptions<T extends string> = import("./types.ts").RouteOptions<T>;
54
+ export type RouteDefinition<T = any> = import("./types.ts").RouteDefinition<T>;
55
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../core/http.js"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,8DAA8D;AAE9D;;8EAE8E;AAE9E;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;;GAIG;AACH,mIAMC;AAID;IACC,mEAAmE;IACnE,+BAEC;IAED,mEAAmE;IACnE,iCAEC;IAED,mEAAmE;IACnE,6BAEC;IAED,mEAAmE;IACnE,wCAEC;IAED,mEAAmE;IACnE,mCAEC;IAKD;;;OAGG;IACH,qBAHW,MAAM,eACN,MAAM,EAQhB;IAbD,qBAAqB,CAAC,QAAX,MAAM,CAAY;IAC7B,oBAAoB,CAAC,YAAV,MAAM,CAAe;IAchC,uBAKC;CACD;yBAzFa,OAAO,YAAY,EAAE,UAAU;0BAC/B,OAAO,YAAY,EAAE,WAAW;mDAIjC,OAAO,YAAY,EAAE,kBAAkB,CAAC,CAAC,CAAC;8BAI1C,OAAO,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC;8BAKpC,OAAO,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC;6CAKpC,OAAO,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC;uCAKpC,OAAO,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=http.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.test.d.ts","sourceRoot":"","sources":["../../core/http.test.js"],"names":[],"mappings":""}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @template [T=unknown]
3
+ * @typedef {object} MigrationOptions
4
+ * @property {(value: T) => void | Promise<void>} up
5
+ * @property {(value: T) => void | Promise<void>} down
6
+ */
7
+ /**
8
+ * @template [T=unknown]
9
+ * @typedef {object} MigrationDefinition
10
+ * @property {string} name
11
+ * @property {(value: T) => void | Promise<void>} up
12
+ * @property {(value: T) => void | Promise<void>} down
13
+ */
14
+ /**
15
+ * @typedef {object} MigrationRecord
16
+ * @property {string} name
17
+ */
18
+ /**
19
+ * @template T @param {MigrationOptions<T>} options
20
+ * @returns {MigrationOptions<T>}
21
+ */
22
+ export function defineMigration<T>(options: MigrationOptions<T>): MigrationOptions<T>;
23
+ /**
24
+ * @template T
25
+ * @typedef {object} MigratorOptions
26
+ * @property {() => Promise<MigrationDefinition<T>[]>} getDefinitions
27
+ * @property {() => Promise<MigrationRecord[]>} getRecords
28
+ * @property {(def: MigrationDefinition<T>, direction: "up"|"down") => void | Promise<void>} execute
29
+ */
30
+ /** @template T */
31
+ export class Migrator<T> {
32
+ /** @param {MigratorOptions<T>} options */
33
+ constructor(options: MigratorOptions<T>);
34
+ options: MigratorOptions<T>;
35
+ up(): Promise<void>;
36
+ down(): Promise<void>;
37
+ _getTodo(direction: any, count: any): Promise<MigrationDefinition<T>[]>;
38
+ }
39
+ export type MigrationOptions<T = unknown> = {
40
+ up: (value: T) => void | Promise<void>;
41
+ down: (value: T) => void | Promise<void>;
42
+ };
43
+ export type MigrationDefinition<T = unknown> = {
44
+ name: string;
45
+ up: (value: T) => void | Promise<void>;
46
+ down: (value: T) => void | Promise<void>;
47
+ };
48
+ export type MigrationRecord = {
49
+ name: string;
50
+ };
51
+ export type MigratorOptions<T> = {
52
+ getDefinitions: () => Promise<MigrationDefinition<T>[]>;
53
+ getRecords: () => Promise<MigrationRecord[]>;
54
+ execute: (def: MigrationDefinition<T>, direction: "up" | "down") => void | Promise<void>;
55
+ };
56
+ //# sourceMappingURL=migrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrator.d.ts","sourceRoot":"","sources":["../../core/migrator.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;GAGG;AAEH;;;GAGG;AACH,sFAKC;AAED;;;;;;GAMG;AAEH,kBAAkB;AAClB;IACC,0CAA0C;IAC1C,qBADY,gBAAgB,CAAC,CAAC,EAG7B;IADA,4BAAsB;IAGvB,oBAIC;IAED,sBAIC;IAED,wEAQC;CACD;;gBAhEqB,CAAC,KAAK,IAAI,GAAG,QAAQ,IAAI,CAAC;kBAC1B,CAAC,KAAK,IAAI,GAAG,QAAQ,IAAI,CAAC;;;UAMlC,MAAM;gBACE,CAAC,KAAK,IAAI,GAAG,QAAQ,IAAI,CAAC;kBAC1B,CAAC,KAAK,IAAI,GAAG,QAAQ,IAAI,CAAC;;;UAKlC,MAAM;;;oBAiBN,MAAM,QAAQ,oBAAoB,CAAC,CAAC,EAAE,CAAC;gBACvC,MAAM,QAAQ,eAAe,EAAE,CAAC;mBAC1B,oBAAoB,CAAC,CAAC,aAAa,IAAI,GAAC,MAAM,KAAK,IAAI,GAAG,QAAQ,IAAI,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=migrator.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrator.test.d.ts","sourceRoot":"","sources":["../../core/migrator.test.js"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ export * from "./configuration.js";
2
+ export * from "./fetch-router.js";
3
+ export * from "./http.js";
4
+ export * from "./migrator.js";
5
+ export * from "./postgres.js";
6
+ export * from "./utilities.js";
7
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../core/mod.js"],"names":[],"mappings":""}
@@ -0,0 +1,43 @@
1
+ /** @typedef {import("postgres").Sql} Sql */
2
+ /** @typedef {import("./migrator.js").MigratorOptions} MigratorOptions */
3
+ /** @typedef {import("./migrator.js").MigrationRecord} MigrationRecord */
4
+ /** @typedef {import("./migrator.js").MigrationDefinition} MigrationDefinition */
5
+ /**
6
+ @param {Sql} sql
7
+ @returns {Promise<MigrationRecord[]>}
8
+ */
9
+ export function _getMigrationRecords(sql: Sql): Promise<MigrationRecord[]>;
10
+ /**
11
+ * @param {MigrationDefinition} def
12
+ * @param {"up" | "down"} direction
13
+ * @param {Sql} sql
14
+ */
15
+ export function _execute(def: MigrationDefinition, direction: "up" | "down", sql: Sql): Promise<void>;
16
+ /**
17
+ * @param {MigrationDefinition} def
18
+ * @param {Sql} sql
19
+ */
20
+ export function _executeUp(def: MigrationDefinition, sql: Sql): Promise<void>;
21
+ /**
22
+ * @param {MigrationDefinition} def
23
+ * @param {Sql} sql
24
+ */
25
+ export function _executeDown(def: MigrationDefinition, sql: Sql): Promise<void>;
26
+ /**
27
+ * @typedef {object} PostgresMigratorOptions
28
+ * @property {Sql} sql
29
+ */
30
+ /**
31
+ * @param {PostgresMigratorOptions} options
32
+ * @returns {MigratorOptions<Sql>}
33
+ */
34
+ export function getPostgresMigratorOptions(options: PostgresMigratorOptions): any;
35
+ export const bootstrapMigration: import("./migrator.js").MigrationOptions<any>;
36
+ export type Sql = import("postgres").Sql;
37
+ export type MigratorOptions = any;
38
+ export type MigrationRecord = import("./migrator.js").MigrationRecord;
39
+ export type MigrationDefinition = import("./migrator.js").MigrationDefinition;
40
+ export type PostgresMigratorOptions = {
41
+ sql: Sql;
42
+ };
43
+ //# sourceMappingURL=postgres.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../core/postgres.js"],"names":[],"mappings":"AAEA,4CAA4C;AAC5C,yEAAyE;AACzE,yEAAyE;AACzE,iFAAiF;AAEjF;;;MAGG;AACH,0CAHS,GAAG,GACD,QAAQ,eAAe,EAAE,CAAC,CAYpC;AAED;;;;GAIG;AACH,8BAJW,mBAAmB,aACnB,IAAI,GAAG,MAAM,OACb,GAAG,iBAQb;AAED;;;GAGG;AACH,gCAHW,mBAAmB,OACnB,GAAG,iBAQb;AAED;;;GAGG;AACH,kCAHW,mBAAmB,OACnB,GAAG,iBAQb;AAkBD;;;GAGG;AAEH;;;GAGG;AACH,oDAHW,uBAAuB,OASjC;AA/BD,+EAcG;kBAxEW,OAAO,UAAU,EAAE,GAAG;;8BAEtB,OAAO,eAAe,EAAE,eAAe;kCACvC,OAAO,eAAe,EAAE,mBAAmB;;SAyE3C,GAAG"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test-deps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-deps.d.ts","sourceRoot":"","sources":["../../core/test-deps.js"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ /// <reference types="urlpattern-polyfill" />
2
+ export type HTTPMethod = "GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE" | "CONNECT";
3
+ export type RouteResult = Promise<Response | undefined> | Response | undefined;
4
+ export type ExtractRouteParams<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? Param | ExtractRouteParams<Rest> : T extends `${string}:${infer Param}` ? Param : never;
5
+ export interface RouteContext<T> {
6
+ request: Request;
7
+ params: T;
8
+ url: URL;
9
+ }
10
+ export interface RouteHandler<T> {
11
+ (context: RouteContext<T>): RouteResult;
12
+ }
13
+ export interface RouteOptions<T extends string> {
14
+ method: HTTPMethod;
15
+ pathname: T;
16
+ handler: RouteHandler<Record<ExtractRouteParams<T>, string>>;
17
+ }
18
+ export interface RouteDefinition<T> {
19
+ method: HTTPMethod;
20
+ pattern: URLPattern;
21
+ handler: RouteHandler<T>;
22
+ }
23
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../core/types.ts"],"names":[],"mappings":";AAEA,MAAM,MAAM,UAAU,GACnB,KAAK,GACL,MAAM,GACN,MAAM,GACN,KAAK,GACL,OAAO,GACP,QAAQ,GACR,SAAS,CAAC;AAEb,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE/E,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAC9C,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,GAC/C,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,GAChC,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,KAAK,EAAE,GACnC,KAAK,GACL,KAAK,CAAC;AAEX,MAAM,WAAW,YAAY,CAAC,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,CAAC,CAAC;IACV,GAAG,EAAE,GAAG,CAAC;CACT;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC9B,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;CACxC;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,MAAM;IAC7C,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,CAAC,CAAC;IACZ,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,UAAU,CAAC;IACpB,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;CACzB"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @template T @param {T} fields
3
+ * @param {(keyof T)[]} columns
4
+ * @param {string} fallback
5
+ */
6
+ export function formatMarkdownTable<T>(fields: T, columns: (keyof T)[], fallback: string): string;
7
+ /**
8
+ * @template {() => any} T
9
+ * @param {T} handler
10
+ * @returns {T}
11
+ */
12
+ export function loader<T extends () => any>(handler: T): T;
13
+ //# sourceMappingURL=utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../core/utilities.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,kFAFW,MAAM,UAmChB;AAED;;;;GAIG;AACH,uCAJoB,GAAG,iBAWtB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utilities.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.test.d.ts","sourceRoot":"","sources":["../../core/utilities.test.js"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ /**
2
+ @typedef {object} NodeConfigurationOptions
3
+ @property {import("superstruct")} superstruct
4
+ */
5
+ /** @param {NodeConfigurationOptions} options */
6
+ export function getNodeConfigOptions(options: NodeConfigurationOptions): {
7
+ superstruct: typeof import("superstruct");
8
+ readTextFile(url: any): Promise<any>;
9
+ getEnvironmentVariable(key: any): any;
10
+ getCommandArgument(key: any): any;
11
+ stringify(config: any): string;
12
+ parse(data: any): any;
13
+ };
14
+ /**
15
+ * This is a syntax sugar for `new Configuration(getNodeConfigOptions(options))`
16
+ * @param {NodeConfigurationOptions} options
17
+ */
18
+ export function getNodeConfiguration(options: NodeConfigurationOptions): Configuration;
19
+ export { Configuration };
20
+ export type NodeConfigurationOptions = {
21
+ superstruct: typeof import("superstruct");
22
+ };
23
+ import { Configuration } from "../core/configuration.js";
24
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../source/configuration.js"],"names":[],"mappings":"AAQA;;;EAGE;AAEF,gDAAgD;AAChD,8CADY,wBAAwB;;;;;;;EA4BnC;AAED;;;GAGG;AACH,8CAFW,wBAAwB,iBAIlC;;;;;8BA7C6B,0BAA0B"}
@@ -0,0 +1,2 @@
1
+ export * from "../core/mod.js";
2
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../source/core.js"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ /**
2
+ A HTTP router for Express applications
3
+
4
+ ```js
5
+ const router = new ExpressRouter(...)
6
+
7
+ const app = express()
8
+ .use(...)
9
+ .use(router.middleware());
10
+ .use(...)
11
+ ```
12
+ */
13
+ export class ExpressRouter {
14
+ /** @param {NodeRouterOptions} options */
15
+ constructor(options?: NodeRouterOptions);
16
+ router: FetchRouter;
17
+ /** @returns {import("express").RequestHandler} */
18
+ middleware(): any;
19
+ /** @param {Request} request */
20
+ getResponse(request: Request): Promise<Response>;
21
+ /**
22
+ @param {import("express").Response} res
23
+ @param {Response} response
24
+ */
25
+ respond(res: any, response: Response): void;
26
+ }
27
+ import { FetchRouter } from "../core/fetch-router.js";
28
+ //# sourceMappingURL=express-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express-router.d.ts","sourceRoot":"","sources":["../../source/express-router.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;EAWE;AACF;IACC,yCAAyC;IACzC,yCAEC;IADA,oBAAmD;IAGpD,kDAAkD;IAClD,kBAOC;IAED,+BAA+B;IAC/B,qBADY,OAAO,qBAGlB;IAED;;;OAGG;IACH,4BAFS,QAAQ,QAahB;CACD;4BApD2B,yBAAyB"}
@@ -0,0 +1,33 @@
1
+ /** @typedef {import("koa").Context} Context */
2
+ /** @typedef {import("./node-router.js").NodeRouterOptions} NodeRouterOptions */
3
+ /**
4
+ A HTTP router for Koa applications
5
+
6
+ ```js
7
+ const router = new KoaRouter(...)
8
+
9
+ const app = new Koa()
10
+ .use(koaHelmet())
11
+ .use(...)
12
+ .use(router.middleware());
13
+ .use(...)
14
+ ```
15
+ */
16
+ export class KoaRouter {
17
+ /** @param {NodeRouterOptions} options */
18
+ constructor(options?: NodeRouterOptions);
19
+ router: FetchRouter;
20
+ /** @returns {import("koa").Middleware} */
21
+ middleware(): any;
22
+ /** @param {Request} request */
23
+ getResponse(request: Request): Promise<Response>;
24
+ /**
25
+ @param {Context} ctx
26
+ @param {Response} response
27
+ */
28
+ respond(ctx: any, response: Response): void;
29
+ }
30
+ export type Context = any;
31
+ export type NodeRouterOptions = import("./node-router.js").NodeRouterOptions;
32
+ import { FetchRouter } from "../core/fetch-router.js";
33
+ //# sourceMappingURL=koa-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"koa-router.d.ts","sourceRoot":"","sources":["../../source/koa-router.js"],"names":[],"mappings":"AAKA,+CAA+C;AAC/C,gFAAgF;AAEhF;;;;;;;;;;;;EAYE;AACF;IACC,yCAAyC;IACzC,sBADY,iBAAiB,EAG5B;IADA,oBAAmD;IAGpD,0CAA0C;IAC1C,kBAOC;IAED,+BAA+B;IAC/B,qBADY,OAAO,qBAGlB;IAED;;;MAGE;IACF,4BAFS,QAAQ,QAchB;CACD;;gCArDa,OAAO,kBAAkB,EAAE,iBAAiB;4BAJ9B,yBAAyB"}
@@ -0,0 +1,7 @@
1
+ export * from "./configuration.js";
2
+ export * from "./core.js";
3
+ export * from "./express-router.js";
4
+ export * from "./koa-router.js";
5
+ export * from "./node-router.js";
6
+ export * from "./postgres.js";
7
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../source/mod.js"],"names":[],"mappings":""}