piral-configs 1.6.0-beta.7240 → 1.6.0-beta.7244
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/lib/create.js +3 -7
- package/lib/create.js.map +1 -1
- package/lib/index.js +2 -5
- package/lib/index.js.map +1 -1
- package/lib/types.js +1 -2
- package/package.json +9 -20
- package/esm/create.d.ts +0 -13
- package/esm/create.js +0 -46
- package/esm/create.js.map +0 -1
- package/esm/index.d.ts +0 -2
- package/esm/index.js +0 -3
- package/esm/index.js.map +0 -1
- package/esm/types.d.ts +0 -29
- package/esm/types.js +0 -2
- package/esm/types.js.map +0 -1
package/lib/create.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.createConfigsApi = void 0;
|
|
4
|
-
const jsonschema_1 = require("jsonschema");
|
|
5
|
-
function createConfigsApi(config = {}) {
|
|
1
|
+
import { Validator } from 'jsonschema';
|
|
2
|
+
export function createConfigsApi(config = {}) {
|
|
6
3
|
const readConfig = (name, defaultConfig) => {
|
|
7
4
|
const key = `config-${name}`;
|
|
8
5
|
const current = config.retrieve?.(key);
|
|
@@ -20,7 +17,7 @@ function createConfigsApi(config = {}) {
|
|
|
20
17
|
}
|
|
21
18
|
};
|
|
22
19
|
const validate = (schema, proposedConfig, defaultConfig) => {
|
|
23
|
-
const validator = new
|
|
20
|
+
const validator = new Validator();
|
|
24
21
|
const result = validator.validate(proposedConfig, schema);
|
|
25
22
|
if (!result.valid) {
|
|
26
23
|
console.warn(`The given configuration does not match the provided schema. Taking the default configuration.`, proposedConfig, result);
|
|
@@ -46,5 +43,4 @@ function createConfigsApi(config = {}) {
|
|
|
46
43
|
},
|
|
47
44
|
});
|
|
48
45
|
}
|
|
49
|
-
exports.createConfigsApi = createConfigsApi;
|
|
50
46
|
//# sourceMappingURL=create.js.map
|
package/lib/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAU,MAAM,YAAY,CAAC;AAc/C,MAAM,UAAU,gBAAgB,CAAC,SAAwB,EAAE;IACzD,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,aAAkB,EAAE,EAAE;QACtD,MAAM,GAAG,GAAG,UAAU,IAAI,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;QAEvC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,OAAO;gBACL,GAAG,aAAa;gBAChB,GAAG,OAAO;aACX,CAAC;SACH;aAAM,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;YACzC,OAAO,OAAO,CAAC;SAChB;aAAM;YACL,OAAO,SAAS,CAAC;SAClB;IACH,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,cAAmB,EAAE,aAAkB,EAAE,EAAE;QAC3E,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QAE1D,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;YACjB,OAAO,CAAC,IAAI,CACV,+FAA+F,EAC/F,cAAc,EACd,MAAM,CACP,CAAC;YACF,OAAO,aAAa,CAAC;SACtB;QAED,OAAO,cAAc,CAAC;IACxB,CAAC,CAAC;IAEF,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAC5B,kBAAkB,CAAC,MAAM,EAAE,aAAa;YACtC,MAAM,cAAc,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;YAC5D,MAAM,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;YAEjG,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBACvB,GAAG,KAAK;gBACR,OAAO,EAAE;oBACP,GAAG,KAAK,CAAC,OAAO;oBAChB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO;iBACrB;aACF,CAAC,CAAC,CAAC;YAEJ,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,gBAAgB;YACd,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1D,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./create"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
1
|
+
export * from './create';
|
|
2
|
+
export * from './types';
|
|
6
3
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/lib/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-configs",
|
|
3
|
-
"version": "1.6.0-beta.
|
|
3
|
+
"version": "1.6.0-beta.7244",
|
|
4
4
|
"description": "Plugin for dynamic configurations of pilets in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -16,29 +16,19 @@
|
|
|
16
16
|
"author": "smapiot",
|
|
17
17
|
"homepage": "https://piral.io",
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"module": "
|
|
19
|
+
"module": "lib/index.js",
|
|
20
20
|
"main": "lib/index.js",
|
|
21
21
|
"typings": "lib/index.d.ts",
|
|
22
22
|
"exports": {
|
|
23
|
-
".":
|
|
24
|
-
"import": "./esm/index.js",
|
|
25
|
-
"require": "./lib/index.js"
|
|
26
|
-
},
|
|
27
|
-
"./esm/*": {
|
|
28
|
-
"import": "./esm/*"
|
|
29
|
-
},
|
|
23
|
+
".": "./lib/index.js",
|
|
30
24
|
"./lib/*": {
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
"./_/*": {
|
|
34
|
-
"import": "./esm/*.js",
|
|
35
|
-
"require": "./lib/*.js"
|
|
25
|
+
"import": "./lib/*",
|
|
26
|
+
"types": "./lib/*.d.ts"
|
|
36
27
|
},
|
|
37
28
|
"./package.json": "./package.json"
|
|
38
29
|
},
|
|
39
30
|
"sideEffects": false,
|
|
40
31
|
"files": [
|
|
41
|
-
"esm",
|
|
42
32
|
"lib",
|
|
43
33
|
"src",
|
|
44
34
|
"piral-configs.min.js"
|
|
@@ -52,10 +42,9 @@
|
|
|
52
42
|
},
|
|
53
43
|
"scripts": {
|
|
54
44
|
"cleanup": "rimraf esm lib piral-configs.min.js",
|
|
55
|
-
"build": "yarn build:bundle && yarn build:
|
|
45
|
+
"build": "yarn build:bundle && yarn build:esnext",
|
|
56
46
|
"build:bundle": "esbuild src/index.ts --outfile=piral-configs.min.js --bundle --external:piral-core --minify --global-name=piralConfigs",
|
|
57
|
-
"build:
|
|
58
|
-
"build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
|
|
47
|
+
"build:esnext": "tsc --project tsconfig.json --outDir lib --module esnext",
|
|
59
48
|
"typedoc": "typedoc --json ../../../docs/types/piral-configs.json src --exclude \"src/**/*.test.*\"",
|
|
60
49
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
61
50
|
},
|
|
@@ -64,7 +53,7 @@
|
|
|
64
53
|
"url": "^0.11.0"
|
|
65
54
|
},
|
|
66
55
|
"devDependencies": {
|
|
67
|
-
"piral-core": "1.6.0-beta.
|
|
56
|
+
"piral-core": "1.6.0-beta.7244"
|
|
68
57
|
},
|
|
69
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "65ac1291c3429dbf16079b4deb6138b24c5719f7"
|
|
70
59
|
}
|
package/esm/create.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { PiralPlugin } from 'piral-core';
|
|
2
|
-
import { PiletConfigsApi } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Available configuration options for the configs plugin.
|
|
5
|
-
*/
|
|
6
|
-
export interface ConfigsConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Sets the retriever function for getting the app or user configuration.
|
|
9
|
-
* @default undefined
|
|
10
|
-
*/
|
|
11
|
-
retrieve?<T>(configName: string): T | undefined;
|
|
12
|
-
}
|
|
13
|
-
export declare function createConfigsApi(config?: ConfigsConfig): PiralPlugin<PiletConfigsApi>;
|
package/esm/create.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Validator } from 'jsonschema';
|
|
2
|
-
export function createConfigsApi(config = {}) {
|
|
3
|
-
const readConfig = (name, defaultConfig) => {
|
|
4
|
-
const key = `config-${name}`;
|
|
5
|
-
const current = config.retrieve?.(key);
|
|
6
|
-
if (typeof current === 'object') {
|
|
7
|
-
return {
|
|
8
|
-
...defaultConfig,
|
|
9
|
-
...current,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
else if (typeof current !== 'undefined') {
|
|
13
|
-
return current;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
const validate = (schema, proposedConfig, defaultConfig) => {
|
|
20
|
-
const validator = new Validator();
|
|
21
|
-
const result = validator.validate(proposedConfig, schema);
|
|
22
|
-
if (!result.valid) {
|
|
23
|
-
console.warn(`The given configuration does not match the provided schema. Taking the default configuration.`, proposedConfig, result);
|
|
24
|
-
return defaultConfig;
|
|
25
|
-
}
|
|
26
|
-
return proposedConfig;
|
|
27
|
-
};
|
|
28
|
-
return (ctx) => (_, meta) => ({
|
|
29
|
-
defineConfigSchema(schema, defaultConfig) {
|
|
30
|
-
const proposedConfig = readConfig(meta.name, defaultConfig);
|
|
31
|
-
const current = proposedConfig ? validate(schema, proposedConfig, defaultConfig) : defaultConfig;
|
|
32
|
-
ctx.dispatch((state) => ({
|
|
33
|
-
...state,
|
|
34
|
-
configs: {
|
|
35
|
-
...state.configs,
|
|
36
|
-
[meta.name]: current,
|
|
37
|
-
},
|
|
38
|
-
}));
|
|
39
|
-
return current;
|
|
40
|
-
},
|
|
41
|
-
getCurrentConfig() {
|
|
42
|
-
return ctx.readState((s) => s.configs[meta.name]) ?? {};
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=create.js.map
|
package/esm/create.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAU,MAAM,YAAY,CAAC;AAc/C,MAAM,UAAU,gBAAgB,CAAC,SAAwB,EAAE;IACzD,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,aAAkB,EAAE,EAAE;QACtD,MAAM,GAAG,GAAG,UAAU,IAAI,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;QAEvC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,OAAO;gBACL,GAAG,aAAa;gBAChB,GAAG,OAAO;aACX,CAAC;SACH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AAC,IAAI,EAAE,CAAC;QAC1D,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/esm/index.d.ts
DELETED
package/esm/index.js
DELETED
package/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/esm/types.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Dict } from 'piral-core';
|
|
2
|
-
import type { Schema } from 'jsonschema';
|
|
3
|
-
declare module 'piral-core/lib/types/custom' {
|
|
4
|
-
interface PiletCustomApi extends PiletConfigsApi {
|
|
5
|
-
}
|
|
6
|
-
interface PiralCustomState {
|
|
7
|
-
/**
|
|
8
|
-
* The relevant state for the available configurations.
|
|
9
|
-
*/
|
|
10
|
-
configs: Dict<any>;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Defines the provided set of Pilet API extensions for configuration.
|
|
15
|
-
*/
|
|
16
|
-
export interface PiletConfigsApi {
|
|
17
|
-
/**
|
|
18
|
-
* Defines the available configuration options for the pilet.
|
|
19
|
-
* @param schema The schema to use for allowing configurations.
|
|
20
|
-
* @param defaultConfig The default configuration to use.
|
|
21
|
-
* @returns The current configuration, which may be either the
|
|
22
|
-
* default configuration or an override.
|
|
23
|
-
*/
|
|
24
|
-
defineConfigSchema<T = any>(schema: Schema, defaultConfig?: T): T;
|
|
25
|
-
/**
|
|
26
|
-
* Gets the currently available configuration.
|
|
27
|
-
*/
|
|
28
|
-
getCurrentConfig<T = any>(): T;
|
|
29
|
-
}
|
package/esm/types.js
DELETED
package/esm/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|