@map-colonies/config 1.0.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 (50) hide show
  1. package/README.md +291 -0
  2. package/dist/avi.d.ts +2 -0
  3. package/dist/avi.d.ts.map +1 -0
  4. package/dist/avi.js +16 -0
  5. package/dist/avi.js.map +1 -0
  6. package/dist/config.d.ts +14 -0
  7. package/dist/config.d.ts.map +1 -0
  8. package/dist/config.js +102 -0
  9. package/dist/config.js.map +1 -0
  10. package/dist/constants.d.ts +5 -0
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/constants.js +14 -0
  13. package/dist/constants.js.map +1 -0
  14. package/dist/env.d.ts +3 -0
  15. package/dist/env.d.ts.map +1 -0
  16. package/dist/env.js +90 -0
  17. package/dist/env.js.map +1 -0
  18. package/dist/errors.d.ts +74 -0
  19. package/dist/errors.d.ts.map +1 -0
  20. package/dist/errors.js +55 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/httpClient.d.ts +4 -0
  23. package/dist/httpClient.d.ts.map +1 -0
  24. package/dist/httpClient.js +64 -0
  25. package/dist/httpClient.js.map +1 -0
  26. package/dist/index.d.ts +4 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +9 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/options.d.ts +4 -0
  31. package/dist/options.d.ts.map +1 -0
  32. package/dist/options.js +50 -0
  33. package/dist/options.js.map +1 -0
  34. package/dist/schemas.d.ts +296 -0
  35. package/dist/schemas.d.ts.map +1 -0
  36. package/dist/schemas.js +41 -0
  37. package/dist/schemas.js.map +1 -0
  38. package/dist/types.d.ts +105 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +23 -0
  41. package/dist/types.js.map +1 -0
  42. package/dist/utils/debug.d.ts +3 -0
  43. package/dist/utils/debug.d.ts.map +1 -0
  44. package/dist/utils/debug.js +12 -0
  45. package/dist/utils/debug.js.map +1 -0
  46. package/dist/validator.d.ts +7 -0
  47. package/dist/validator.d.ts.map +1 -0
  48. package/dist/validator.js +43 -0
  49. package/dist/validator.js.map +1 -0
  50. package/package.json +85 -0
package/dist/errors.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isConfigError = exports.createConfigError = exports.ConfigError = void 0;
4
+ const configErrors = {
5
+ optionValidationError: { code: 1, payload: [] },
6
+ configValidationError: { code: 2, payload: [] },
7
+ httpResponseError: { code: 3, payload: {} },
8
+ httpGeneralError: { code: 4, payload: {} },
9
+ schemaNotFoundError: { code: 5, payload: {} },
10
+ schemasPackageVersionMismatchError: { code: 6, payload: {} },
11
+ schemaVersionMismatchError: { code: 7, payload: {} },
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ };
14
+ /**
15
+ * Represents an error specific to the configuration module.
16
+ *
17
+ * @template ErrorName - The name of the error.
18
+ * @template Payload - The payload type associated with the error.
19
+ */
20
+ class ConfigError extends Error {
21
+ payload;
22
+ code;
23
+ /**
24
+ * Creates a new instance of the ConfigError class.
25
+ *
26
+ * @param name - The name of the error.
27
+ * @param message - The error message.
28
+ * @param payload - The payload associated with the error.
29
+ */
30
+ constructor(name, message, payload) {
31
+ super(message);
32
+ this.payload = payload;
33
+ this.name = name;
34
+ this.code = configErrors[name].code;
35
+ }
36
+ }
37
+ exports.ConfigError = ConfigError;
38
+ function createConfigError(name, message, payload) {
39
+ return new ConfigError(name, message, payload);
40
+ }
41
+ exports.createConfigError = createConfigError;
42
+ /**
43
+ * Checks if the given error is an instance of `ConfigError` with the specified error type.
44
+ * @param error - The error to check.
45
+ * @param errorName - The name of the error to check against.
46
+ * @returns `true` if the error is an instance of `ConfigError` with the specified error name, `false` otherwise.
47
+ */
48
+ function isConfigError(error, errorName) {
49
+ if (!(error instanceof ConfigError)) {
50
+ return false;
51
+ }
52
+ return error.name === errorName && error.code === configErrors[errorName].code;
53
+ }
54
+ exports.isConfigError = isConfig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a,CAAuC,KAAc,EAAE,SAAoB;IACtG,IAAI,CAAC,CAAC,KAAK,YAAY,WAAW,CAAC,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;AACjF,CAAC;AAND,sCAMC"}
@@ -0,0 +1,4 @@
1
+ import { Config, ServerCapabilities } from './types';
2
+ export declare function getRemoteConfig(configName: string, version: number | 'latest'): Promise<Config>;
3
+ export declare function getServerCapabilities(): Promise<ServerCapabilities>;
4
+ //# sourceMappingURL=httpClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpClient.d.ts","sourceRoot":"","sources":["../src/httpClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAgCrD,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAkBrG;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAQzE"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getServerCapabilities = exports.getRemoteConfig = void 0;
7
+ const undici_1 = require("undici");
8
+ const http_status_codes_1 = __importDefault(require("http-status-codes"));
9
+ const options_1 = require("./options");
10
+ const debug_1 = require("./utils/debug");
11
+ const errors_1 = require("./errors");
12
+ const debug = (0, debug_1.createDebug)('http');
13
+ async function createHttpErrorPayload(res) {
14
+ return {
15
+ body: await res.body.text(),
16
+ headers: res.headers,
17
+ statusCode: res.statusCode,
18
+ };
19
+ }
20
+ async function requestWrapper(url, query) {
21
+ debug('Making request to %s', url);
22
+ try {
23
+ const res = await (0, undici_1.request)(url, { query });
24
+ if (res.statusCode > http_status_codes_1.default.NOT_FOUND) {
25
+ debug('Failed to fetch config. Status code: %d', res.statusCode);
26
+ throw (0, errors_1.createConfigError)('httpResponseError', 'Failed to fetch', await createHttpErrorPayload(res));
27
+ }
28
+ return res;
29
+ }
30
+ catch (error) {
31
+ if (error instanceof errors_1.ConfigError) {
32
+ throw error;
33
+ }
34
+ debug('An error occurred while making the request: %s', error.message);
35
+ throw (0, errors_1.createConfigError)('httpGeneralError', 'An error occurred while making the request', error);
36
+ }
37
+ }
38
+ async function getRemoteConfig(configName, version) {
39
+ debug('Fetching remote config %s@%s', configName, version);
40
+ const { configServerUrl } = (0, options_1.getOptions)();
41
+ const url = `${configServerUrl}/config/${configName}/${version}`;
42
+ const res = await requestWrapper(url, { shouldDereference: true });
43
+ if (res.statusCode === http_status_codes_1.default.BAD_REQUEST) {
44
+ debug('Invalid request to getConfig');
45
+ throw (0, errors_1.createConfigError)('httpResponseError', 'Invalid request to getConfig', await createHttpErrorPayload(res));
46
+ }
47
+ if (res.statusCode === http_status_codes_1.default.NOT_FOUND) {
48
+ debug('Config with given name and version was not found');
49
+ throw (0, errors_1.createConfigError)('httpResponseError', 'Config with given name and version was not found', await createHttpErrorPayload(res));
50
+ }
51
+ debug('Config fetched successfully');
52
+ return (await res.body.json());
53
+ }
54
+ exports.getRemoteConfig = getRemoteConfig;
55
+ async function getServerCapabilities() {
56
+ debug('Fetching server capabilities');
57
+ const { configServerUrl } = (0, options_1.getOptions)();
58
+ const url = `${configServerUrl}/capabilities`;
59
+ const { body } = await requestWrapper(url);
60
+ debug('Server capabilities fetched successfully');
61
+ return (await body.json());
62
+ }
63
+ exports.getServerCapabilities = getServerCapabilities;
64
+ //# sourceMappingURL=httpClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpClient.js","sourceRoot":"","sources":["../src/httpClient.ts"],"names":[],"mappings":";;;;;;A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ance } from './types';
2
+ export { config } from './config';
3
+ export { ConfigErrors, isConfigError, ConfigError } from './errors';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigError = exports.isConfigError = exports.config = void 0;
4
+ var config_1 = require("./config");
5
+ Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
6
+ var errors_1 = require("./errors");
7
+ Object.defineProperty(exports, "isConfigError", { enumerable: true, get: function () { return errors_1.isConfigError; } });
8
+ Object.defineProperty(exports, "ConfigError", { enumerable: true, get: function () { return errors_1.ConfigError; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,mCAAoE;AAA7C,uGAAA,aAAa,OAAA;AAAE,qGAAA,WAAW,OAAA"}
@@ -0,0 +1,4 @@
1
+ import { BaseOptions } from './types';
2
+ export declare function initializeOptions(options: Partial<BaseOptions>): BaseOptions;
3
+ export declare function getOptions(): BaseOptions;
4
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAiB,MAAM,SAAS,CAAC;AAwBrD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CAoB5E;AAED,wBAAgB,UAAU,IAAI,WAAW,CAQxC"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getOptions = exports.initializeOptions = void 0;
7
+ const deepmerge_1 = __importDefault(require("deepmerge"));
8
+ const types_1 = require("./types");
9
+ const validator_1 = require("./validator");
10
+ const debug_1 = require("./utils/debug");
11
+ const errors_1 = require("./errors");
12
+ const debug = (0, debug_1.createDebug)('options');
13
+ const envOptions = {
14
+ configName: process.env.CONFIG_NAME,
15
+ configServerUrl: process.env.CONFIG_SERVER_URL,
16
+ version: process.env.CONFIG_VERSION,
17
+ offlineMode: process.env.CONFIG_OFFLINE_MODE,
18
+ ignoreServerIsOlderVersionError: process.env.CONFIG_IGNORE_SERVER_IS_OLDER_VERSION_ERROR,
19
+ };
20
+ // in order to merge correctly the keys should not exist, undefined is not enough
21
+ for (const key in envOptions) {
22
+ if (envOptions[key] === undefined) {
23
+ delete envOptions[key];
24
+ }
25
+ }
26
+ let baseOptions = undefined;
27
+ function initializeOptions(options) {
28
+ debug('initializing options with %j and env %j', options, envOptions);
29
+ const mergedOptions = (0, deepmerge_1.default)(options, envOptions);
30
+ debug('merged options: %j', mergedOptions);
31
+ const [errors, validatedOptions] = (0, validator_1.validate)(validator_1.ajvOptionsValidator, types_1.optionsSchema, mergedOptions);
32
+ if (errors) {
33
+ debug('error validating options: %s', errors[0].message);
34
+ throw (0, errors_1.createConfigError)('optionValidationError', 'An error occurred while validating the given options. please check both arguments and environment variables', errors);
35
+ }
36
+ debug('options validated successfully');
37
+ baseOptions = validatedOptions;
38
+ return baseOptions;
39
+ }
40
+ exports.initializeOptions = initializeOptions;
41
+ function getOptions() {
42
+ if (baseOptions === undefined) {
43
+ debug('Options were requested before being initialized');
44
+ throw new Error('Options not initialized');
45
+ }
46
+ debug('returning options');
47
+ return baseOptions;
48
+ }
49
+ exports.getOptions = getOptions;
50
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAkC;AAClC,mCAAqD;AACrD,2CAA4D;AAC5D,yCAA4C;AAC5C,qCAA6C;AAE7C,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,SAAS,CAAC,CAAC;AAErC,MAAM,UAAU,GAA+C;IAC7D,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;IACnC,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;IAC9C,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;IACnC,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB;IAC5C,+BAA+B,EAAE,OAAO,CAAC,GAAG,CAAC,2CAA2C;CACzF,CAAC;AAEF,iFAAiF;AACjF,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;IAC7B,IAAI,UAAU,CAAC,GAAwB,CAAC,KAAK,SAAS,EAAE,CAAC;QACvD,OAAO,UAAU,CAAC,GAAwB,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC;AAED,IAAI,WAAW,GAA4B,SAAS,CAAC;AAErD,SAAgB,iBAAiB,CAAC,OAA6B;IAC7D,KAAK,CAAC,yCAAyC,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;IACtE,MAAM,aAAa,GAAG,IAAA,mBAAS,EAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAErD,KAAK,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAC;IAE3C,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAAG,IAAA,oBAAQ,EAAC,+BAAmB,EAAE,qBAAa,EAAE,aAAa,CAAC,CAAC;IAE/F,IAAI,MAAM,EAAE,CAAC;QACX,KAAK,CAAC,8BAA8B,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACzD,MAAM,IAAA,0BAAiB,EACrB,uBAAuB,EACvB,6GAA6G,EAC7G,MAAM,CACP,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACxC,WAAW,GAAG,gBAA+B,CAAC;IAC9C,OAAO,WAAW,CAAC;AACrB,CAAC;AApBD,8CAoBC;AAED,SAAgB,UAAU;IACxB,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAC3B,OAAO,WAAW,CAAC;AACrB,CAAC;AARD,gCAQC"}
@@ -0,0 +1,296 @@
1
+ /// <reference types="node" />
2
+ import $RefParser, { JSONSchema } from '@apidevtools/json-schema-ref-parser';
3
+ declare const refParser: $RefParser<JSONSchema, {
4
+ parse?: {
5
+ [x: string]: boolean | {
6
+ name?: string | undefined;
7
+ order?: number | undefined;
8
+ allowEmpty?: boolean | undefined;
9
+ allowBOM?: boolean | undefined;
10
+ encoding?: BufferEncoding | undefined;
11
+ canParse?: string | boolean | {
12
+ exec?: {} | undefined;
13
+ test?: {} | undefined;
14
+ readonly source?: string | undefined;
15
+ readonly global?: boolean | undefined;
16
+ readonly ignoreCase?: boolean | undefined;
17
+ readonly multiline?: boolean | undefined;
18
+ lastIndex?: number | undefined;
19
+ compile?: {} | undefined;
20
+ readonly flags?: string | undefined;
21
+ readonly sticky?: boolean | undefined;
22
+ readonly unicode?: boolean | undefined;
23
+ readonly dotAll?: boolean | undefined;
24
+ readonly hasIndices?: boolean | undefined;
25
+ [Symbol.match]?: {} | undefined;
26
+ [Symbol.replace]?: {} | undefined;
27
+ [Symbol.search]?: {} | undefined;
28
+ [Symbol.split]?: {} | undefined;
29
+ [Symbol.matchAll]?: {} | undefined;
30
+ } | (string | undefined)[] | {} | undefined;
31
+ parse?: string | number | {} | undefined;
32
+ } | undefined;
33
+ json?: boolean | {
34
+ name?: string | undefined;
35
+ order?: number | undefined;
36
+ allowEmpty?: boolean | undefined;
37
+ allowBOM?: boolean | undefined;
38
+ encoding?: BufferEncoding | undefined;
39
+ canParse?: string | boolean | {
40
+ exec?: {} | undefined;
41
+ test?: {} | undefined;
42
+ readonly source?: string | undefined;
43
+ readonly global?: boolean | undefined;
44
+ readonly ignoreCase?: boolean | undefined;
45
+ readonly multiline?: boolean | undefined;
46
+ lastIndex?: number | undefined;
47
+ compile?: {} | undefined;
48
+ readonly flags?: string | undefined;
49
+ readonly sticky?: boolean | undefined;
50
+ readonly unicode?: boolean | undefined;
51
+ readonly dotAll?: boolean | undefined;
52
+ readonly hasIndices?: boolean | undefined;
53
+ [Symbol.match]?: {} | undefined;
54
+ [Symbol.replace]?: {} | undefined;
55
+ [Symbol.search]?: {} | undefined;
56
+ [Symbol.split]?: {} | undefined;
57
+ [Symbol.matchAll]?: {} | undefined;
58
+ } | (string | undefined)[] | {} | undefined;
59
+ parse?: string | number | {} | undefined;
60
+ } | undefined;
61
+ yaml?: boolean | {
62
+ name?: string | undefined;
63
+ order?: number | undefined;
64
+ allowEmpty?: boolean | undefined;
65
+ allowBOM?: boolean | undefined;
66
+ encoding?: BufferEncoding | undefined;
67
+ canParse?: string | boolean | {
68
+ exec?: {} | undefined;
69
+ test?: {} | undefined;
70
+ readonly source?: string | undefined;
71
+ readonly global?: boolean | undefined;
72
+ readonly ignoreCase?: boolean | undefined;
73
+ readonly multiline?: boolean | undefined;
74
+ lastIndex?: number | undefined;
75
+ compile?: {} | undefined;
76
+ readonly flags?: string | undefined;
77
+ readonly sticky?: boolean | undefined;
78
+ readonly unicode?: boolean | undefined;
79
+ readonly dotAll?: boolean | undefined;
80
+ readonly hasIndices?: boolean | undefined;
81
+ [Symbol.match]?: {} | undefined;
82
+ [Symbol.replace]?: {} | undefined;
83
+ [Symbol.search]?: {} | undefined;
84
+ [Symbol.split]?: {} | undefined;
85
+ [Symbol.matchAll]?: {} | undefined;
86
+ } | (string | undefined)[] | {} | undefined;
87
+ parse?: string | number | {} | undefined;
88
+ } | undefined;
89
+ binary?: boolean | {
90
+ name?: string | undefined;
91
+ order?: number | undefined;
92
+ allowEmpty?: boolean | undefined;
93
+ allowBOM?: boolean | undefined;
94
+ encoding?: BufferEncoding | undefined;
95
+ canParse?: string | boolean | {
96
+ exec?: {} | undefined;
97
+ test?: {} | undefined;
98
+ readonly source?: string | undefined;
99
+ readonly global?: boolean | undefined;
100
+ readonly ignoreCase?: boolean | undefined;
101
+ readonly multiline?: boolean | undefined;
102
+ lastIndex?: number | undefined;
103
+ compile?: {} | undefined;
104
+ readonly flags?: string | undefined;
105
+ readonly sticky?: boolean | undefined;
106
+ readonly unicode?: boolean | undefined;
107
+ readonly dotAll?: boolean | undefined;
108
+ readonly hasIndices?: boolean | undefined;
109
+ [Symbol.match]?: {} | undefined;
110
+ [Symbol.replace]?: {} | undefined;
111
+ [Symbol.search]?: {} | undefined;
112
+ [Symbol.split]?: {} | undefined;
113
+ [Symbol.matchAll]?: {} | undefined;
114
+ } | (string | undefined)[] | {} | undefined;
115
+ parse?: string | number | {} | undefined;
116
+ } | undefined;
117
+ text?: boolean | {
118
+ name?: string | undefined;
119
+ order?: number | undefined;
120
+ allowEmpty?: boolean | undefined;
121
+ allowBOM?: boolean | undefined;
122
+ encoding?: BufferEncoding | undefined;
123
+ canParse?: string | boolean | {
124
+ exec?: {} | undefined;
125
+ test?: {} | undefined;
126
+ readonly source?: string | undefined;
127
+ readonly global?: boolean | undefined;
128
+ readonly ignoreCase?: boolean | undefined;
129
+ readonly multiline?: boolean | undefined;
130
+ lastIndex?: number | undefined;
131
+ compile?: {} | undefined;
132
+ readonly flags?: string | undefined;
133
+ readonly sticky?: boolean | undefined;
134
+ readonly unicode?: boolean | undefined;
135
+ readonly dotAll?: boolean | undefined;
136
+ readonly hasIndices?: boolean | undefined;
137
+ [Symbol.match]?: {} | undefined;
138
+ [Symbol.replace]?: {} | undefined;
139
+ [Symbol.search]?: {} | undefined;
140
+ [Symbol.split]?: {} | undefined;
141
+ [Symbol.matchAll]?: {} | undefined;
142
+ } | (string | undefined)[] | {} | undefined;
143
+ parse?: string | number | {} | undefined;
144
+ } | undefined;
145
+ } | undefined;
146
+ resolve?: {
147
+ [x: string]: boolean | {
148
+ name?: string | undefined;
149
+ order?: number | undefined;
150
+ canRead?: string | boolean | {
151
+ exec?: {} | undefined;
152
+ test?: {} | undefined;
153
+ readonly source?: string | undefined;
154
+ readonly global?: boolean | undefined;
155
+ readonly ignoreCase?: boolean | undefined;
156
+ readonly multiline?: boolean | undefined;
157
+ lastIndex?: number | undefined;
158
+ compile?: {} | undefined;
159
+ readonly flags?: string | undefined;
160
+ readonly sticky?: boolean | undefined;
161
+ readonly unicode?: boolean | undefined;
162
+ readonly dotAll?: boolean | undefined;
163
+ readonly hasIndices?: boolean | undefined;
164
+ [Symbol.match]?: {} | undefined;
165
+ [Symbol.replace]?: {} | undefined;
166
+ [Symbol.search]?: {} | undefined;
167
+ [Symbol.split]?: {} | undefined;
168
+ [Symbol.matchAll]?: {} | undefined;
169
+ } | (string | undefined)[] | {} | undefined;
170
+ read?: string | object | {} | undefined;
171
+ } | {
172
+ headers?: ([(string | undefined)?, (string | undefined)?] | undefined)[] | {
173
+ [x: string]: string | undefined;
174
+ } | {
175
+ append?: {} | undefined;
176
+ delete?: {} | undefined;
177
+ get?: {} | undefined;
178
+ getSetCookie?: {} | undefined;
179
+ has?: {} | undefined;
180
+ set?: {} | undefined;
181
+ forEach?: {} | undefined;
182
+ entries?: {} | undefined;
183
+ keys?: {} | undefined;
184
+ values?: {} | undefined;
185
+ [Symbol.iterator]?: {} | undefined;
186
+ } | null | undefined;
187
+ timeout?: number | undefined;
188
+ redirects?: number | undefined;
189
+ withCredentials?: boolean | undefined;
190
+ name?: string | undefined;
191
+ order?: number | undefined;
192
+ canRead?: string | boolean | {
193
+ exec?: {} | undefined;
194
+ test?: {} | undefined;
195
+ readonly source?: string | undefined;
196
+ readonly global?: boolean | undefined;
197
+ readonly ignoreCase?: boolean | undefined;
198
+ readonly multiline?: boolean | undefined;
199
+ lastIndex?: number | undefined;
200
+ compile?: {} | undefined;
201
+ readonly flags?: string | undefined;
202
+ readonly sticky?: boolean | undefined;
203
+ readonly unicode?: boolean | undefined;
204
+ readonly dotAll?: boolean | undefined;
205
+ readonly hasIndices?: boolean | undefined;
206
+ [Symbol.match]?: {} | undefined;
207
+ [Symbol.replace]?: {} | undefined;
208
+ [Symbol.search]?: {} | undefined;
209
+ [Symbol.split]?: {} | undefined;
210
+ [Symbol.matchAll]?: {} | undefined;
211
+ } | (string | undefined)[] | {} | undefined;
212
+ read?: string | object | {} | undefined;
213
+ } | undefined;
214
+ external?: boolean | undefined;
215
+ file?: boolean | {
216
+ name?: string | undefined;
217
+ order?: number | undefined;
218
+ canRead?: string | boolean | {
219
+ exec?: {} | undefined;
220
+ test?: {} | undefined;
221
+ readonly source?: string | undefined;
222
+ readonly global?: boolean | undefined;
223
+ readonly ignoreCase?: boolean | undefined;
224
+ readonly multiline?: boolean | undefined;
225
+ lastIndex?: number | undefined;
226
+ compile?: {} | undefined;
227
+ readonly flags?: string | undefined;
228
+ readonly sticky?: boolean | undefined;
229
+ readonly unicode?: boolean | undefined;
230
+ readonly dotAll?: boolean | undefined;
231
+ readonly hasIndices?: boolean | undefined;
232
+ [Symbol.match]?: {} | undefined;
233
+ [Symbol.replace]?: {} | undefined;
234
+ [Symbol.search]?: {} | undefined;
235
+ [Symbol.split]?: {} | undefined;
236
+ [Symbol.matchAll]?: {} | undefined;
237
+ } | (string | undefined)[] | {} | undefined;
238
+ read?: string | object | {} | undefined;
239
+ } | undefined;
240
+ http?: boolean | {
241
+ headers?: ([(string | undefined)?, (string | undefined)?] | undefined)[] | {
242
+ [x: string]: string | undefined;
243
+ } | {
244
+ append?: {} | undefined;
245
+ delete?: {} | undefined;
246
+ get?: {} | undefined;
247
+ getSetCookie?: {} | undefined;
248
+ has?: {} | undefined;
249
+ set?: {} | undefined;
250
+ forEach?: {} | undefined;
251
+ entries?: {} | undefined;
252
+ keys?: {} | undefined;
253
+ values?: {} | undefined;
254
+ [Symbol.iterator]?: {} | undefined;
255
+ } | null | undefined;
256
+ timeout?: number | undefined;
257
+ redirects?: number | undefined;
258
+ withCredentials?: boolean | undefined;
259
+ name?: string | undefined;
260
+ order?: number | undefined;
261
+ canRead?: string | boolean | {
262
+ exec?: {} | undefined;
263
+ test?: {} | undefined;
264
+ readonly source?: string | undefined;
265
+ readonly global?: boolean | undefined;
266
+ readonly ignoreCase?: boolean | undefined;
267
+ readonly multiline?: boolean | undefined;
268
+ lastIndex?: number | undefined;
269
+ compile?: {} | undefined;
270
+ readonly flags?: string | undefined;
271
+ readonly sticky?: boolean | undefined;
272
+ readonly unicode?: boolean | undefined;
273
+ readonly dotAll?: boolean | undefined;
274
+ readonly hasIndices?: boolean | undefined;
275
+ [Symbol.match]?: {} | undefined;
276
+ [Symbol.replace]?: {} | undefined;
277
+ [Symbol.search]?: {} | undefined;
278
+ [Symbol.split]?: {} | undefined;
279
+ [Symbol.matchAll]?: {} | undefined;
280
+ } | (string | undefined)[] | {} | undefined;
281
+ read?: string | object | {} | undefined;
282
+ } | undefined;
283
+ } | undefined;
284
+ continueOnError?: boolean | undefined;
285
+ dereference?: {
286
+ circular?: boolean | "ignore" | undefined;
287
+ excludedPathMatcher?: {} | undefined;
288
+ onDereference?: {} | undefined;
289
+ externalReferenceResolution?: "relative" | "root" | undefined;
290
+ } | undefined;
291
+ mutateInputSchema?: boolean | undefined;
292
+ timeoutMs?: number | undefined;
293
+ }>;
294
+ export declare function loadSchema(schema: JSONSchema): ReturnType<typeof refParser.dereference>;
295
+ export {};
296
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":";AAEA,OAAO,UAAU,EAAE,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAO7E,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAmB,CAAC;AAanC,wBAAsB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,WAAW,CAAC,CAiB7F"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadSchema = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const json_schema_ref_parser_1 = __importDefault(require("@apidevtools/json-schema-ref-parser"));
10
+ const constants_1 = require("./constants");
11
+ const debug_1 = require("./utils/debug");
12
+ const errors_1 = require("./errors");
13
+ const debug = (0, debug_1.createDebug)('schemas');
14
+ const refParser = new json_schema_ref_parser_1.default();
15
+ function loadSpecificSchema(relativePath) {
16
+ debug('loading specific schema at path %s', relativePath);
17
+ const fullPath = node_path_1.default.join(constants_1.SCHEMA_BASE_PATH, relativePath + '.schema.json');
18
+ if (!node_fs_1.default.existsSync(fullPath)) {
19
+ throw (0, errors_1.createConfigError)(`schemaNotFoundError`, `Schema not found at path`, { schemaPath: fullPath });
20
+ }
21
+ return JSON.parse(node_fs_1.default.readFileSync(fullPath, { encoding: 'utf-8' }));
22
+ }
23
+ async function loadSchema(schema) {
24
+ debug('loading schema id %s', schema.$id);
25
+ const dereferencedSchema = await refParser.dereference(schema, {
26
+ dereference: { circular: false },
27
+ resolve: {
28
+ mapcolonies: {
29
+ canRead: /^https:\/\/mapcolonies.com\/.*/,
30
+ order: 1,
31
+ read: (file) => {
32
+ const subPath = file.url.split(constants_1.SCHEMA_DOMAIN)[1];
33
+ return loadSpecificSchema(subPath);
34
+ },
35
+ },
36
+ },
37
+ });
38
+ return dereferencedSchema;
39
+ }
40
+ exports.loadSchema = loadSchema;
41
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA6B;AAC7B,sDAAyB;AACzB,iGAA6E;AAC7E,2CAA8D;AAC9D,yCAA4C;AAC5C,qCAA6C;AAE7C,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,SAAS,CAAC,CAAC;AAErC,MAAM,SAAS,GAAG,IAAI,gCAAU,EAAE,CAAC;AAEnC,SAAS,kBAAkB,CAAC,YAAoB;IAC9C,KAAK,CAAC,oCAAoC,EAAE,YAAY,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,mBAAI,CAAC,IAAI,CAAC,4BAAgB,EAAE,YAAY,GAAG,cAAc,CAAC,CAAC;IAE5E,IAAI,CAAC,iBAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAA,0BAAiB,EAAC,qBAAqB,EAAE,0BAA0B,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC;IACvG,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAe,CAAC;AACpF,CAAC;AAEM,KAAK,UAAU,UAAU,CAAC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