@eik/common 2.0.3 → 3.0.1

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 +88 -0
  2. package/README.md +13 -11
  3. package/eikjson.d.ts +41 -0
  4. package/lib/classes/custom-error.js +3 -0
  5. package/lib/classes/eik-config.js +108 -47
  6. package/lib/classes/file-mapping.js +40 -0
  7. package/lib/classes/invalid-config-error.js +3 -0
  8. package/lib/classes/local-file-location.js +59 -0
  9. package/lib/classes/missing-config-error.js +3 -0
  10. package/lib/classes/no-files-matched-error.js +3 -0
  11. package/lib/classes/read-file.js +4 -8
  12. package/lib/classes/remote-file-location.js +41 -0
  13. package/lib/classes/resolved-files.js +56 -0
  14. package/lib/classes/single-dest-multiple-source-error.js +3 -0
  15. package/lib/helpers/config-store.js +22 -5
  16. package/lib/helpers/get-defaults.js +4 -2
  17. package/lib/helpers/index.js +21 -2
  18. package/lib/helpers/local-assets.js +44 -48
  19. package/lib/helpers/path-slashes.js +43 -0
  20. package/lib/helpers/resolve-files.js +81 -0
  21. package/lib/helpers/type-slug.js +6 -0
  22. package/lib/helpers/type-title.js +7 -0
  23. package/lib/schemas/assert.js +11 -9
  24. package/lib/schemas/eikjson.schema.json +10 -5
  25. package/lib/schemas/index.js +1 -1
  26. package/lib/schemas/validate.js +1 -2
  27. package/lib/schemas/validation-error.js +6 -2
  28. package/lib/stream.js +9 -2
  29. package/lib/validators/index.js +8 -8
  30. package/package.json +33 -23
  31. package/types/classes/custom-error.d.ts +7 -0
  32. package/types/classes/eik-config.d.ts +58 -0
  33. package/types/classes/file-mapping.d.ts +21 -0
  34. package/types/classes/invalid-config-error.d.ts +4 -0
  35. package/types/classes/local-file-location.d.ts +36 -0
  36. package/types/classes/missing-config-error.d.ts +4 -0
  37. package/types/classes/multiple-config-sources-error.d.ts +5 -0
  38. package/types/classes/no-files-matched-error.d.ts +4 -0
  39. package/types/classes/read-file.d.ts +15 -0
  40. package/types/classes/remote-file-location.d.ts +21 -0
  41. package/types/classes/resolved-files.d.ts +20 -0
  42. package/types/classes/single-dest-multiple-source-error.d.ts +4 -0
  43. package/types/helpers/config-store.d.ts +31 -0
  44. package/types/helpers/get-defaults.d.ts +2 -0
  45. package/types/helpers/index.d.ts +11 -0
  46. package/types/helpers/local-assets.d.ts +8 -0
  47. package/types/helpers/path-slashes.d.ts +32 -0
  48. package/types/helpers/resolve-files.d.ts +13 -0
  49. package/types/helpers/type-slug.d.ts +2 -0
  50. package/types/helpers/type-title.d.ts +2 -0
  51. package/types/index.d.ts +7 -0
  52. package/types/schemas/assert.d.ts +8 -0
  53. package/types/schemas/index.d.ts +71 -0
  54. package/types/schemas/validate.d.ts +26 -0
  55. package/types/schemas/validation-error.d.ts +8 -0
  56. package/types/stream.d.ts +2 -0
  57. package/types/validators/index.d.ts +8 -0
  58. package/lib/helpers/package-url.js +0 -20
package/package.json CHANGED
@@ -1,17 +1,26 @@
1
1
  {
2
2
  "name": "@eik/common",
3
- "version": "2.0.3",
3
+ "version": "3.0.1",
4
4
  "description": "Common utilities for Eik modules",
5
5
  "main": "lib/index.js",
6
+ "types": "types/index.d.ts",
6
7
  "files": [
7
8
  "CHANGELOG.md",
8
9
  "package.json",
9
- "lib"
10
+ "lib",
11
+ "types",
12
+ "eikjson.d.ts"
10
13
  ],
11
14
  "scripts": {
12
- "test": "tap",
15
+ "test": "tap --no-check-coverage",
13
16
  "lint:fix": "eslint --fix .",
14
- "lint": "eslint ."
17
+ "lint": "eslint .",
18
+ "schema:types": "json2ts lib/schemas/eikjson.schema.json > eikjson.d.ts",
19
+ "schema:outdated": "npm run schema:types && git diff --exit-code HEAD:eikjson.d.ts eikjson.d.ts",
20
+ "style:check": "prettier -c .",
21
+ "style:format": "prettier -w .",
22
+ "typecheck": "tsc",
23
+ "prepublish": "npm run typecheck"
15
24
  },
16
25
  "repository": {
17
26
  "type": "git",
@@ -25,30 +34,31 @@
25
34
  },
26
35
  "homepage": "https://github.com/eik-lib/common#readme",
27
36
  "dependencies": {
28
- "ajv": "^7.0.0",
29
- "ajv-formats": "^1.5.1",
30
- "glob": "^7.1.6",
37
+ "ajv": "^8.6.2",
38
+ "ajv-formats": "^2.1.0",
39
+ "glob": "^8.0.0",
40
+ "is-glob": "^4.0.1",
41
+ "mime-types": "^2.1.29",
31
42
  "node-fetch": "^2.6.1",
32
43
  "semver": "^7.0.0",
33
- "validate-npm-package-name": "^3.0.0"
44
+ "validate-npm-package-name": "^4.0.0"
34
45
  },
35
46
  "devDependencies": {
36
- "@semantic-release/changelog": "5.0.1",
37
- "@semantic-release/commit-analyzer": "8.0.1",
38
- "@semantic-release/git": "9.0.0",
39
- "@semantic-release/github": "7.2.0",
40
- "@semantic-release/npm": "7.0.10",
41
- "@semantic-release/release-notes-generator": "9.0.1",
42
- "eslint": "7.19.0",
47
+ "@hapi/hapi": "20.2.2",
48
+ "@semantic-release/changelog": "6.0.1",
49
+ "@semantic-release/git": "10.0.1",
50
+ "eslint": "7.32.0",
43
51
  "eslint-config-airbnb-base": "14.2.1",
44
- "eslint-config-prettier": "7.2.0",
45
- "eslint-plugin-import": "2.22.1",
46
- "eslint-plugin-prettier": "3.3.1",
47
- "express": "4.17.1",
48
- "fastify": "3.11.0",
49
- "prettier": "2.2.1",
50
- "semantic-release": "17.3.7",
52
+ "eslint-config-prettier": "8.4.0",
53
+ "eslint-plugin-import": "2.25.4",
54
+ "eslint-plugin-prettier": "4.0.0",
55
+ "express": "4.18.1",
56
+ "fastify": "3.29.0",
57
+ "json-schema-to-typescript": "10.1.5",
58
+ "prettier": "2.5.1",
59
+ "semantic-release": "18.0.1",
51
60
  "stoppable": "1.1.0",
52
- "tap": "14.11.0"
61
+ "tap": "15.1.6",
62
+ "typescript": "4.6.4"
53
63
  }
54
64
  }
@@ -0,0 +1,7 @@
1
+ export = CustomError;
2
+ declare class CustomError extends Error {
3
+ /**
4
+ * @param {string} message
5
+ */
6
+ constructor(message: string);
7
+ }
@@ -0,0 +1,58 @@
1
+ export = EikConfig;
2
+ declare class EikConfig {
3
+ /**
4
+ * @param {EikjsonSchema?} configHash
5
+ * @param {[string, string][]?} tokens
6
+ * @param {string?} configRootDir
7
+ */
8
+ constructor(configHash: EikjsonSchema | null, tokens?: [string, string][] | null, configRootDir?: string | null);
9
+ cwd: string;
10
+ /** @type {string[]} */
11
+ map: string[];
12
+ /** @type {EikjsonSchema["name"]} */
13
+ get name(): string;
14
+ set version(arg: string);
15
+ /** @type {EikjsonSchema["version"]} */
16
+ get version(): string;
17
+ /** @type {EikjsonSchema["type"]} */
18
+ get type(): "map" | "npm" | "package";
19
+ /** @type {string} */
20
+ get server(): string;
21
+ /** @type {[string, string][]} */
22
+ get token(): [string, string][];
23
+ /** @type {EikjsonSchema["files"]} */
24
+ get files(): string | {
25
+ [k: string]: string;
26
+ };
27
+ /**
28
+ * Normalized relative directory path with any leading ./ or
29
+ * trailing / characters stripped. Defaults to .eik
30
+ *
31
+ * @returns {string} out path string
32
+ */
33
+ get out(): string;
34
+ /**
35
+ * Serializes internal values to an object
36
+ *
37
+ * @returns {EikjsonSchema} object consistent with EikjsonSchema
38
+ */
39
+ toJSON(): EikjsonSchema;
40
+ /**
41
+ * Validates config values against the eik JSON schema
42
+ *
43
+ * @return {void}
44
+ */
45
+ validate(): void;
46
+ /**
47
+ * Resolves file locations on disk based on values defined in files property
48
+ * of config object.
49
+ *
50
+ * @returns {Promise<FileMapping[]>}
51
+ */
52
+ mappings(): Promise<FileMapping[]>;
53
+ }
54
+ declare namespace EikConfig {
55
+ export { EikjsonSchema };
56
+ }
57
+ type EikjsonSchema = import("../../eikjson").EikjsonSchema;
58
+ import FileMapping = require("./file-mapping");
@@ -0,0 +1,21 @@
1
+ export = FileMapping;
2
+ /**
3
+ * Class containing a local file system source location and remote server destination location for a file.
4
+ */
5
+ declare class FileMapping {
6
+ /**
7
+ * @param {LocalFileLocation} source
8
+ * @param {RemoteFileLocation} destination
9
+ */
10
+ constructor(source: LocalFileLocation, destination: RemoteFileLocation);
11
+ /**
12
+ * @type {LocalFileLocation} source
13
+ */
14
+ source: LocalFileLocation;
15
+ /**
16
+ * @type {RemoteFileLocation} destination
17
+ */
18
+ destination: RemoteFileLocation;
19
+ }
20
+ import LocalFileLocation = require("./local-file-location");
21
+ import RemoteFileLocation = require("./remote-file-location");
@@ -0,0 +1,4 @@
1
+ export = InvalidConfigError;
2
+ declare class InvalidConfigError extends CustomError {
3
+ }
4
+ import CustomError = require("./custom-error");
@@ -0,0 +1,36 @@
1
+ export = LocalFileLocation;
2
+ /**
3
+ * Class containing information about a local file
4
+ */
5
+ declare class LocalFileLocation {
6
+ /**
7
+ * @param {string} path path to file on disk relative to basePath
8
+ * @param {string} basePath basePath to the file's location on disk
9
+ */
10
+ constructor(path: string, basePath: string);
11
+ /**
12
+ * @type {string} path to file on disk relative to this.basePath
13
+ */
14
+ relative: string;
15
+ /**
16
+ * @type {string} absolute path to root files location on disk
17
+ */
18
+ basePath: string;
19
+ /**
20
+ * @type {string} absolute path to file on disk,
21
+ * this is a concatentation of this.basePath and this.relative
22
+ */
23
+ absolute: string;
24
+ /**
25
+ * @type {string} file extension with "." character included. (eg. ".json")
26
+ */
27
+ extension: string;
28
+ /**
29
+ * @type {string} full content-type header value for file
30
+ */
31
+ contentType: string;
32
+ /**
33
+ * @type {string} mime type of file
34
+ */
35
+ mimeType: string;
36
+ }
@@ -0,0 +1,4 @@
1
+ export = MissingConfigError;
2
+ declare class MissingConfigError extends CustomError {
3
+ }
4
+ import CustomError = require("./custom-error");
@@ -0,0 +1,5 @@
1
+ export = MultipleConfigSourcesError;
2
+ declare class MultipleConfigSourcesError extends CustomError {
3
+ constructor();
4
+ }
5
+ import CustomError = require("./custom-error");
@@ -0,0 +1,4 @@
1
+ export = NoFilesMatchedError;
2
+ declare class NoFilesMatchedError extends CustomError {
3
+ }
4
+ import CustomError = require("./custom-error");
@@ -0,0 +1,15 @@
1
+ export = ReadFile;
2
+ declare const ReadFile: {
3
+ new ({ mimeType, etag }?: {
4
+ mimeType?: string;
5
+ etag?: string;
6
+ }): {
7
+ _mimeType: string;
8
+ _stream: any;
9
+ _etag: string;
10
+ readonly mimeType: string;
11
+ stream: any;
12
+ readonly etag: string;
13
+ readonly [Symbol.toStringTag]: string;
14
+ };
15
+ };
@@ -0,0 +1,21 @@
1
+ export = RemoteFileLocation;
2
+ declare class RemoteFileLocation {
3
+ /**
4
+ * @param {string} filePathname pathname for file relative to package root eg. /folder/client.js
5
+ * @param {string} packagePathname pathname for package root eg. /pkg/my-pack/1.0.0
6
+ * @param {string} origin server origin eg. https://server.com
7
+ */
8
+ constructor(filePathname: string, packagePathname: string, origin: string);
9
+ /**
10
+ * @type {string} pathname to package root
11
+ */
12
+ packagePathname: string;
13
+ /**
14
+ * @type {string} pathname to file relative to package root
15
+ */
16
+ filePathname: string;
17
+ /**
18
+ * @type {URL} WHATWG URL object containing the full remote URL for the file
19
+ */
20
+ url: URL;
21
+ }
@@ -0,0 +1,20 @@
1
+ export = ResolvedFiles;
2
+ declare class ResolvedFiles {
3
+ /**
4
+ * @param {string[]} files
5
+ * @param {{definition: [string, string], basePath: string, pattern: string}} meta
6
+ */
7
+ constructor(files: string[], meta: {
8
+ definition: [string, string];
9
+ basePath: string;
10
+ pattern: string;
11
+ });
12
+ destination: string;
13
+ source: string;
14
+ basePath: string;
15
+ pattern: string;
16
+ [Symbol.iterator](): Generator<LocalFileLocation, void, unknown>;
17
+ [originalFiles]: string[];
18
+ }
19
+ import LocalFileLocation = require("./local-file-location");
20
+ declare const originalFiles: unique symbol;
@@ -0,0 +1,4 @@
1
+ export = SingleDestMultipleSourcesError;
2
+ declare class SingleDestMultipleSourcesError extends CustomError {
3
+ }
4
+ import CustomError = require("./custom-error");
@@ -0,0 +1,31 @@
1
+ import EikConfig = require("../classes/eik-config");
2
+ /**
3
+ * Tries to find the configuration for eik in the provided directory.
4
+ *
5
+ * @param {string} configRootDir The base directory for the eik project.
6
+ * @param {function} [loadJSONFromDisk] The function to use to load the file from disk.
7
+ *
8
+ * @returns {EikConfig}
9
+ */
10
+ export function findInDirectory(configRootDir: string, loadJSONFromDisk?: Function): EikConfig;
11
+ /**
12
+ * Tries to find the configuration for eik in the provided directory.
13
+ *
14
+ * @param {string} configRootDir The base directory for the eik project.
15
+ * @param {function} [loadJSONFromDisk] The function to use to load the file from disk.
16
+ *
17
+ * @returns {EikConfig}
18
+ */
19
+ export function findInDirectory(configRootDir: string, loadJSONFromDisk?: Function): EikConfig;
20
+ /**
21
+ * Persist config changes to disk as <cwd>/eik.json
22
+ *
23
+ * @param {import('../classes/eik-config')} config
24
+ */
25
+ export function persistToDisk(config: EikConfig): void;
26
+ /**
27
+ * Persist config changes to disk as <cwd>/eik.json
28
+ *
29
+ * @param {import('../classes/eik-config')} config
30
+ */
31
+ export function persistToDisk(config: EikConfig): void;
@@ -0,0 +1,2 @@
1
+ declare function _exports(cwd: string): import("../classes/eik-config");
2
+ export = _exports;
@@ -0,0 +1,11 @@
1
+ import localAssets = require("./local-assets");
2
+ import getDefaults = require("./get-defaults");
3
+ import configStore = require("./config-store");
4
+ import typeSlug = require("./type-slug");
5
+ import typeTitle = require("./type-title");
6
+ import { addTrailingSlash } from "./path-slashes";
7
+ import { removeTrailingSlash } from "./path-slashes";
8
+ import { addLeadingSlash } from "./path-slashes";
9
+ import { removeLeadingSlash } from "./path-slashes";
10
+ import resolveFiles = require("./resolve-files");
11
+ export { localAssets, getDefaults, configStore, typeSlug, typeTitle, addTrailingSlash, removeTrailingSlash, addLeadingSlash, removeLeadingSlash, resolveFiles };
@@ -0,0 +1,8 @@
1
+ export = localAssets;
2
+ /**
3
+ * Sets up asset routes for local development. Mounted paths match those on Eik server and values are read from projects eik.json file.
4
+ *
5
+ * @param {object} app - express js or fastify app instance
6
+ * @param {string} rootEikDirectory - (optional) path to folder where eik configuration file can be found
7
+ */
8
+ declare function localAssets(app: object, rootEikDirectory?: string): Promise<void>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Add a trailing slash to a path if necessary
3
+ *
4
+ * @param {string} val
5
+ *
6
+ * @returns {string}
7
+ */
8
+ export function addTrailingSlash(val: string): string;
9
+ /**
10
+ * Remove a trailing slash from a path if necessary
11
+ *
12
+ * @param {string} val
13
+ *
14
+ * @returns {string}
15
+ */
16
+ export function removeTrailingSlash(val: string): string;
17
+ /**
18
+ * Add a leading slash to a path if necessary
19
+ *
20
+ * @param {string} val
21
+ *
22
+ * @returns {string}
23
+ */
24
+ export function addLeadingSlash(val: string): string;
25
+ /**
26
+ * Remove a leading slash from a path if necessary
27
+ *
28
+ * @param {string} val
29
+ *
30
+ * @returns {string}
31
+ */
32
+ export function removeLeadingSlash(val: string): string;
@@ -0,0 +1,13 @@
1
+ export = resolveFiles;
2
+ /**
3
+ * Uses an Eik JSON "files" definition to resolve files on disk into a data structure
4
+ *
5
+ * @param {{[k: string]: string;}} files
6
+ * @param {string} cwd
7
+ *
8
+ * @returns {Promise<ResolvedFiles[]>}
9
+ */
10
+ declare function resolveFiles(files: {
11
+ [k: string]: string;
12
+ }, cwd: string): Promise<ResolvedFiles[]>;
13
+ import ResolvedFiles = require("../classes/resolved-files");
@@ -0,0 +1,2 @@
1
+ declare function _exports(type: any): any;
2
+ export = _exports;
@@ -0,0 +1,2 @@
1
+ declare function _exports(type: any): "PACKAGE" | "NPM" | "MAP";
2
+ export = _exports;
@@ -0,0 +1,7 @@
1
+ import validators = require("./validators");
2
+ import ReadFile = require("./classes/read-file");
3
+ import EikConfig = require("./classes/eik-config");
4
+ import schemas = require("./schemas");
5
+ import stream = require("./stream");
6
+ import helpers = require("./helpers");
7
+ export { validators, ReadFile, EikConfig, schemas, stream, helpers };
@@ -0,0 +1,8 @@
1
+ export function eikJSON(value: any): void;
2
+ export function name(value: any): void;
3
+ export function type(value: any): void;
4
+ export function version(value: any): void;
5
+ export function server(value: any): void;
6
+ export function files(value: any): void;
7
+ export function importMap(value: any): void;
8
+ export function out(value: any): void;
@@ -0,0 +1,71 @@
1
+ export const schema: {
2
+ $schema: string;
3
+ additionalProperties: boolean;
4
+ type: string;
5
+ properties: {
6
+ server: {
7
+ description: string;
8
+ type: string;
9
+ format: string;
10
+ };
11
+ name: {
12
+ description: string;
13
+ type: string;
14
+ maxLength: number;
15
+ minLength: number;
16
+ };
17
+ version: {
18
+ description: string;
19
+ type: string;
20
+ minLength: number;
21
+ };
22
+ type: {
23
+ description: string;
24
+ type: string;
25
+ enum: string[];
26
+ default: string;
27
+ };
28
+ files: {
29
+ description: string;
30
+ oneOf: ({
31
+ type: string;
32
+ minProperties: number;
33
+ additionalProperties: {
34
+ type: string;
35
+ };
36
+ minLength?: undefined;
37
+ } | {
38
+ type: string;
39
+ minLength: number;
40
+ minProperties?: undefined;
41
+ additionalProperties?: undefined;
42
+ })[];
43
+ };
44
+ "import-map": {
45
+ description: string;
46
+ oneOf: ({
47
+ type: string;
48
+ format: string;
49
+ items?: undefined;
50
+ } | {
51
+ type: string;
52
+ items: {
53
+ type: string;
54
+ format: string;
55
+ };
56
+ format?: undefined;
57
+ })[];
58
+ };
59
+ out: {
60
+ description: string;
61
+ type: string;
62
+ format: string;
63
+ minLength: number;
64
+ };
65
+ };
66
+ required: string[];
67
+ };
68
+ import validate = require("./validate");
69
+ import assert = require("./assert");
70
+ import ValidationError = require("./validation-error");
71
+ export { validate, assert, ValidationError };
@@ -0,0 +1,26 @@
1
+ export function eikJSON(data: any): {
2
+ value: any;
3
+ error: import("ajv").ErrorObject<string, Record<string, any>, unknown>[];
4
+ };
5
+ export function name(value: any): any;
6
+ export function version(value: any): any;
7
+ export function type(data: any): {
8
+ value: any;
9
+ error: import("ajv").ErrorObject<string, Record<string, any>, unknown>[];
10
+ };
11
+ export function server(data: any): {
12
+ value: any;
13
+ error: import("ajv").ErrorObject<string, Record<string, any>, unknown>[];
14
+ };
15
+ export function files(data: any): {
16
+ value: any;
17
+ error: import("ajv").ErrorObject<string, Record<string, any>, unknown>[];
18
+ };
19
+ export function importMap(data: any): {
20
+ value: any;
21
+ error: import("ajv").ErrorObject<string, Record<string, any>, unknown>[];
22
+ };
23
+ export function out(data: any): {
24
+ value: any;
25
+ error: import("ajv").ErrorObject<string, Record<string, any>, unknown>[];
26
+ };
@@ -0,0 +1,8 @@
1
+ export = ValidationError;
2
+ declare class ValidationError extends Error {
3
+ /**
4
+ * @param {string} message
5
+ * @param {Error} err
6
+ */
7
+ constructor(message: string, err: Error);
8
+ }
@@ -0,0 +1,2 @@
1
+ export function isStream(stream: any): boolean;
2
+ export function isReadableStream(stream: any): boolean;
@@ -0,0 +1,8 @@
1
+ export function origin(value: any): any;
2
+ export function org(value: any): any;
3
+ export function name(value: any): any;
4
+ export function version(value: any): any;
5
+ export function alias(value: any): any;
6
+ export function type(value: any): any;
7
+ export function extra(value: any): any;
8
+ export function semverType(value: any): any;
@@ -1,20 +0,0 @@
1
- const { join } = require('path');
2
- const configStore = require('./config-store');
3
-
4
- async function packageURL(key, { configRootDir = process.cwd() } = {}) {
5
- const eik = configStore.findInDirectory(configRootDir);
6
- const mappingList = (await eik.pathsAndFiles()).filter(
7
- ([, , originalDest]) => originalDest === key,
8
- );
9
-
10
- if (mappingList.length === 0) throw new Error('No files specified');
11
-
12
- const result = mappingList.map(
13
- ([destPath]) =>
14
- new URL(join(`pkg`, eik.name, eik.version, destPath), eik.server),
15
- );
16
-
17
- if (result.length === 1) return result[0];
18
- return result;
19
- }
20
- module.exports = packageURL;