@toa.io/extensions.configuration 1.0.0-alpha.31 → 1.0.0-alpha.310

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 (104) hide show
  1. package/components/configuration.values/manifest.toa.yaml +151 -0
  2. package/components/configuration.values/migrations/0002-indexes.yaml +7 -0
  3. package/components/configuration.values/operations/create.js +32 -0
  4. package/components/configuration.values/operations/fetch.js +13 -0
  5. package/components/configuration.values/operations/get.js +19 -0
  6. package/components/configuration.values/operations/lib/map.js +22 -0
  7. package/components/configuration.values/operations/lib/resolve.js +24 -0
  8. package/components/configuration.values/operations/list.js +11 -0
  9. package/components/configuration.values/source/create.ts +56 -0
  10. package/components/configuration.values/source/fetch.ts +26 -0
  11. package/components/configuration.values/source/get.ts +32 -0
  12. package/components/configuration.values/source/lib/map.ts +36 -0
  13. package/components/configuration.values/source/lib/resolve.ts +57 -0
  14. package/components/configuration.values/source/list.ts +21 -0
  15. package/components/configuration.values/tsconfig.json +10 -0
  16. package/components/configuration.values/types/index.d.ts +3 -0
  17. package/components/configuration.values/types/toa.d.ts +69 -0
  18. package/package.json +21 -10
  19. package/readme.md +178 -50
  20. package/transpiled/Aspect.d.ts +19 -4
  21. package/transpiled/Aspect.js +62 -9
  22. package/transpiled/Aspect.js.map +1 -1
  23. package/transpiled/Client.d.ts +59 -0
  24. package/transpiled/Client.js +171 -0
  25. package/transpiled/Client.js.map +1 -0
  26. package/transpiled/Composition.d.ts +14 -0
  27. package/transpiled/Composition.js +38 -0
  28. package/transpiled/Composition.js.map +1 -0
  29. package/transpiled/Factory.d.ts +9 -2
  30. package/transpiled/Factory.js +21 -9
  31. package/transpiled/Factory.js.map +1 -1
  32. package/transpiled/Secret.d.ts +15 -0
  33. package/transpiled/Secret.js +26 -0
  34. package/transpiled/Secret.js.map +1 -0
  35. package/transpiled/UI.d.ts +25 -0
  36. package/transpiled/UI.js +173 -0
  37. package/transpiled/UI.js.map +1 -0
  38. package/transpiled/configuration.d.ts +7 -2
  39. package/transpiled/configuration.js +33 -43
  40. package/transpiled/configuration.js.map +1 -1
  41. package/transpiled/index.d.ts +3 -3
  42. package/transpiled/index.js +4 -9
  43. package/transpiled/index.js.map +1 -1
  44. package/ui/dist/_app/env.js +1 -0
  45. package/ui/dist/_app/immutable/assets/0.BGFdDICE.css +2 -0
  46. package/ui/dist/_app/immutable/assets/ui.BghF56l_.css +1 -0
  47. package/ui/dist/_app/immutable/chunks/Bjy-W4x2.js +81 -0
  48. package/ui/dist/_app/immutable/chunks/BkLAzDsj.js +1 -0
  49. package/ui/dist/_app/immutable/chunks/C_aaOW6e.js +1 -0
  50. package/ui/dist/_app/immutable/chunks/CcD_ISxM.js +3 -0
  51. package/ui/dist/_app/immutable/chunks/Ccdp29n0.js +6 -0
  52. package/ui/dist/_app/immutable/chunks/Dw75U_Lh.js +50 -0
  53. package/ui/dist/_app/immutable/chunks/sXOccAdQ.js +8 -0
  54. package/ui/dist/_app/immutable/chunks/xihTtKlq.js +1 -0
  55. package/ui/dist/_app/immutable/entry/app.DgOXi1S4.js +2 -0
  56. package/ui/dist/_app/immutable/entry/start.C5YMpV87.js +1 -0
  57. package/ui/dist/_app/immutable/nodes/0.BGAo0V8q.js +1 -0
  58. package/ui/dist/_app/immutable/nodes/1.DYGSbNvw.js +1 -0
  59. package/ui/dist/_app/immutable/nodes/2.nR_WPY04.js +1 -0
  60. package/ui/dist/_app/immutable/nodes/3.p9Hd9gcE.js +1 -0
  61. package/ui/dist/_app/immutable/nodes/4.Chf5nqMR.js +1 -0
  62. package/ui/dist/_app/version.json +1 -0
  63. package/ui/dist/apple-touch-icon.png +0 -0
  64. package/ui/dist/favicon-96x96.png +0 -0
  65. package/ui/dist/favicon.ico +0 -0
  66. package/ui/dist/index.html +57 -0
  67. package/ui/dist/robots.txt +3 -0
  68. package/notes/consistency.md +0 -69
  69. package/schemas/annotation.cos.yaml +0 -1
  70. package/schemas/manifest.cos.yaml +0 -2
  71. package/source/Aspect.test.ts +0 -15
  72. package/source/Aspect.ts +0 -23
  73. package/source/Factory.ts +0 -12
  74. package/source/configuration.test.ts +0 -90
  75. package/source/configuration.ts +0 -59
  76. package/source/deployment.test.ts +0 -21
  77. package/source/deployment.ts +0 -86
  78. package/source/index.ts +0 -3
  79. package/source/manifest.test.ts +0 -15
  80. package/source/manifest.ts +0 -15
  81. package/source/schemas.ts +0 -9
  82. package/transpiled/Aspect.test.d.ts +0 -1
  83. package/transpiled/Aspect.test.js +0 -15
  84. package/transpiled/Aspect.test.js.map +0 -1
  85. package/transpiled/configuration.test.d.ts +0 -1
  86. package/transpiled/configuration.test.js +0 -64
  87. package/transpiled/configuration.test.js.map +0 -1
  88. package/transpiled/deployment.d.ts +0 -8
  89. package/transpiled/deployment.js +0 -88
  90. package/transpiled/deployment.js.map +0 -1
  91. package/transpiled/deployment.test.d.ts +0 -1
  92. package/transpiled/deployment.test.js +0 -18
  93. package/transpiled/deployment.test.js.map +0 -1
  94. package/transpiled/manifest.d.ts +0 -6
  95. package/transpiled/manifest.js +0 -35
  96. package/transpiled/manifest.js.map +0 -1
  97. package/transpiled/manifest.test.d.ts +0 -1
  98. package/transpiled/manifest.test.js +0 -14
  99. package/transpiled/manifest.test.js.map +0 -1
  100. package/transpiled/schemas.d.ts +0 -3
  101. package/transpiled/schemas.js +0 -33
  102. package/transpiled/schemas.js.map +0 -1
  103. package/transpiled/tsconfig.tsbuildinfo +0 -1
  104. package/tsconfig.json +0 -9
@@ -1,21 +0,0 @@
1
- import { type Annotation, deployment, type Instance } from './deployment'
2
- import { type Manifest } from './manifest'
3
-
4
- it('should validate annotation', async () => {
5
- const wrongType = 'not ok' as unknown as Annotation
6
-
7
- expect(() => deployment([], wrongType)).toThrow('object')
8
- })
9
-
10
- it('should validate values', async () => {
11
- const manifest: Manifest = {
12
- schema: { foo: 'string', bar: 'number' },
13
- defaults: { foo: 'ok', bar: 0 }
14
- }
15
-
16
- const locator = { id: 'component' }
17
- const instances = [{ manifest, locator }] as unknown as Instance[]
18
- const annotation: Annotation = { [locator.id]: { bar: 'not a number' } }
19
-
20
- expect(() => deployment(instances, annotation)).toThrow('number')
21
- })
@@ -1,86 +0,0 @@
1
- import assert from 'node:assert'
2
- import { type Dependency, type Variable, type Variables } from '@toa.io/operations'
3
- import * as schemas from '@toa.io/schemas'
4
- import { encode, overwrite } from '@toa.io/generic'
5
- import { type Manifest } from './manifest'
6
- import * as validators from './schemas'
7
- import type { Schema } from '@toa.io/schemas'
8
- import type { context } from '@toa.io/norm'
9
-
10
- export function deployment (instances: Instance[], annotation: Annotation = {}): Dependency {
11
- validate(annotation, instances)
12
-
13
- const variables: Variables = {}
14
-
15
- for (const instance of instances) {
16
- const values = annotation[instance.locator.id]
17
-
18
- validateInstance(instance, values)
19
-
20
- if (values === undefined) continue
21
-
22
- variables[instance.locator.label] = [{
23
- name: PREFIX + instance.locator.uppercase,
24
- value: encode(values)
25
- }]
26
-
27
- const secrets = createSecrets(values)
28
-
29
- variables[instance.locator.label].push(...secrets)
30
- }
31
-
32
- return { variables }
33
- }
34
-
35
- function createSecrets (values: object): Variable[] {
36
- const secrets: Variable[] = []
37
-
38
- for (const value of Object.values(values)) {
39
- if (typeof value === 'object' && value !== null)
40
- secrets.push(...createSecrets(value as object))
41
-
42
- if (typeof value !== 'string') continue
43
-
44
- const match = value.match(SECRET_RX)
45
-
46
- if (match === null) continue
47
-
48
- const name = match.groups?.variable
49
-
50
- assert.ok(name !== undefined)
51
-
52
- secrets.push({
53
- name: PREFIX + '_' + name,
54
- secret: {
55
- name: 'toa-configuration',
56
- key: name
57
- }
58
- })
59
- }
60
-
61
- return secrets
62
- }
63
-
64
- function validate (annotation: Annotation, instances: Instance[]): void {
65
- validators.annotation.validate(annotation)
66
-
67
- const requested = instances.map((instance) => instance.locator.id)
68
-
69
- for (const id of Object.keys(annotation))
70
- assert.ok(requested.includes(id),
71
- `Component '${id}' does not request configuration or does not exist.`)
72
- }
73
-
74
- function validateInstance (instace: Instance, values: object = {}): void {
75
- const defaults = instace.manifest.defaults ?? {}
76
- const configuration = overwrite(defaults, values)
77
- const schema: Schema<any> = schemas.schema(instace.manifest.schema)
78
-
79
- schema.validate(configuration)
80
- }
81
-
82
- export const SECRET_RX = /^\$(?<variable>[A-Z0-9_]{1,32})$/
83
- export const PREFIX = 'TOA_CONFIGURATION_'
84
-
85
- export type Annotation = Record<string, object>
86
- export type Instance = context.Dependency<Manifest>
package/source/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export { manifest } from './manifest'
2
- export { deployment } from './deployment'
3
- export { Factory } from './Factory'
@@ -1,15 +0,0 @@
1
- import { type Manifest, manifest } from './manifest'
2
-
3
- it('should validate', async () => {
4
- const additional = { schema: {}, foo: 'bar' } as unknown as Manifest
5
-
6
- expect(() => {
7
- manifest(additional)
8
- }).toThrow('not expected')
9
-
10
- const wrongType = { schema: 'not ok' } as unknown as Manifest
11
-
12
- expect(() => {
13
- manifest(wrongType)
14
- }).toThrow('object')
15
- })
@@ -1,15 +0,0 @@
1
- import * as schemas from './schemas'
2
- import { type Node } from './configuration'
3
-
4
- export function manifest (manifest: Manifest): Manifest {
5
- if (manifest.schema === undefined) manifest = { schema: manifest }
6
-
7
- schemas.manifest.validate(manifest)
8
-
9
- return manifest
10
- }
11
-
12
- export interface Manifest {
13
- schema: object
14
- defaults?: Node
15
- }
package/source/schemas.ts DELETED
@@ -1,9 +0,0 @@
1
- import { resolve } from 'node:path'
2
- import * as schemas from '@toa.io/schemas'
3
- import type { Schema } from '@toa.io/schemas'
4
-
5
- const path = resolve(__dirname, '../schemas')
6
- const namespace = schemas.namespace(path)
7
-
8
- export const manifest: Schema<any> = namespace.schema('manifest')
9
- export const annotation: Schema<any> = namespace.schema('annotation')
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Aspect_1 = require("./Aspect");
4
- it('should return value', async () => {
5
- const configuration = {
6
- foo: 'bar',
7
- bar: {
8
- baz: 'quux'
9
- }
10
- };
11
- const aspect = new Aspect_1.Aspect(configuration);
12
- expect(aspect.invoke(['foo'])).toStrictEqual(configuration.foo);
13
- expect(aspect.invoke(['bar', 'baz'])).toStrictEqual(configuration.bar.baz);
14
- });
15
- //# sourceMappingURL=Aspect.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Aspect.test.js","sourceRoot":"","sources":["../source/Aspect.test.ts"],"names":[],"mappings":";;AAAA,qCAAiC;AAEjC,EAAE,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;IACnC,MAAM,aAAa,GAAG;QACpB,GAAG,EAAE,KAAK;QACV,GAAG,EAAE;YACH,GAAG,EAAE,MAAM;SACZ;KACF,CAAA;IAED,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,aAAa,CAAC,CAAA;IAExC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;IAC/D,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAC5E,CAAC,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const generic_1 = require("@toa.io/generic");
4
- const core_1 = require("@toa.io/core");
5
- const randomstring_1 = require("randomstring");
6
- const configuration_1 = require("./configuration");
7
- let locator;
8
- let manifest;
9
- beforeEach(() => {
10
- locator = new core_1.Locator((0, randomstring_1.generate)(), (0, randomstring_1.generate)());
11
- manifest = { schema: { foo: 'string' } };
12
- });
13
- afterEach(() => {
14
- for (const name of used)
15
- delete process.env[name];
16
- used = [];
17
- });
18
- it('should read value', async () => {
19
- manifest.schema = { foo: 'string' };
20
- const value = { foo: (0, randomstring_1.generate)() };
21
- set(value);
22
- const result = (0, configuration_1.get)(locator, manifest);
23
- expect(result).toStrictEqual(value);
24
- });
25
- it('should return empty object if no value set', async () => {
26
- expect((0, configuration_1.get)(locator, manifest)).toStrictEqual({});
27
- });
28
- it('should substitute secrets', async () => {
29
- const value = { foo: '$BAR' };
30
- set(value);
31
- set('bar', '_BAR');
32
- const result = (0, configuration_1.get)(locator, manifest);
33
- expect(result).toStrictEqual({ foo: 'bar' });
34
- });
35
- it('should use defaults', async () => {
36
- manifest.schema = { foo: 'string', bar: ['number'], 'baz?': 'string' };
37
- manifest.defaults = { foo: 'bar', bar: [1] };
38
- const values = { bar: [2], baz: 'foo' };
39
- set(values);
40
- const result = (0, configuration_1.get)(locator, manifest);
41
- expect(result).toStrictEqual({
42
- foo: 'bar',
43
- bar: [2],
44
- baz: 'foo'
45
- });
46
- });
47
- it('should validate', async () => {
48
- manifest.schema = { foo: 'hello', bar: 'number' };
49
- const values = { bar: 5 };
50
- set(values);
51
- const result = (0, configuration_1.get)(locator, manifest);
52
- expect(result).toStrictEqual({
53
- foo: 'hello',
54
- bar: 5
55
- });
56
- });
57
- function set(value, key = locator.uppercase) {
58
- const string = typeof value === 'string' ? value : (0, generic_1.encode)(value);
59
- const name = 'TOA_CONFIGURATION_' + key;
60
- process.env[name] = string;
61
- used.push(name);
62
- }
63
- let used = [];
64
- //# sourceMappingURL=configuration.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"configuration.test.js","sourceRoot":"","sources":["../source/configuration.test.ts"],"names":[],"mappings":";;AAAA,6CAAwC;AACxC,uCAAsC;AACtC,+CAAuC;AACvC,mDAAqC;AAGrC,IAAI,OAAgB,CAAA;AACpB,IAAI,QAAkB,CAAA;AAEtB,UAAU,CAAC,GAAG,EAAE;IACd,OAAO,GAAG,IAAI,cAAO,CAAC,IAAA,uBAAQ,GAAE,EAAE,IAAA,uBAAQ,GAAE,CAAC,CAAA;IAC7C,QAAQ,GAAG,EAAE,MAAM,EAAE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KAAK,CAAC,CAAC,CAAC,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAA;IAChE,MAAM,IAAI,GAAG,oBAAoB,GAAG,GAAG,CAAA;IAEvC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAA;IAE1B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACjB,CAAC;AAED,IAAI,IAAI,GAAa,EAAE,CAAA"}
@@ -1,8 +0,0 @@
1
- import { type Dependency } from '@toa.io/operations';
2
- import { type Manifest } from './manifest';
3
- import type { context } from '@toa.io/norm';
4
- export declare function deployment(instances: Instance[], annotation?: Annotation): Dependency;
5
- export declare const SECRET_RX: RegExp;
6
- export declare const PREFIX = "TOA_CONFIGURATION_";
7
- export type Annotation = Record<string, object>;
8
- export type Instance = context.Dependency<Manifest>;
@@ -1,88 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.PREFIX = exports.SECRET_RX = exports.deployment = void 0;
30
- const node_assert_1 = __importDefault(require("node:assert"));
31
- const schemas = __importStar(require("@toa.io/schemas"));
32
- const generic_1 = require("@toa.io/generic");
33
- const validators = __importStar(require("./schemas"));
34
- function deployment(instances, annotation = {}) {
35
- validate(annotation, instances);
36
- const variables = {};
37
- for (const instance of instances) {
38
- const values = annotation[instance.locator.id];
39
- validateInstance(instance, values);
40
- if (values === undefined)
41
- continue;
42
- variables[instance.locator.label] = [{
43
- name: exports.PREFIX + instance.locator.uppercase,
44
- value: (0, generic_1.encode)(values)
45
- }];
46
- const secrets = createSecrets(values);
47
- variables[instance.locator.label].push(...secrets);
48
- }
49
- return { variables };
50
- }
51
- exports.deployment = deployment;
52
- function createSecrets(values) {
53
- const secrets = [];
54
- for (const value of Object.values(values)) {
55
- if (typeof value === 'object' && value !== null)
56
- secrets.push(...createSecrets(value));
57
- if (typeof value !== 'string')
58
- continue;
59
- const match = value.match(exports.SECRET_RX);
60
- if (match === null)
61
- continue;
62
- const name = match.groups?.variable;
63
- node_assert_1.default.ok(name !== undefined);
64
- secrets.push({
65
- name: exports.PREFIX + '_' + name,
66
- secret: {
67
- name: 'toa-configuration',
68
- key: name
69
- }
70
- });
71
- }
72
- return secrets;
73
- }
74
- function validate(annotation, instances) {
75
- validators.annotation.validate(annotation);
76
- const requested = instances.map((instance) => instance.locator.id);
77
- for (const id of Object.keys(annotation))
78
- node_assert_1.default.ok(requested.includes(id), `Component '${id}' does not request configuration or does not exist.`);
79
- }
80
- function validateInstance(instace, values = {}) {
81
- const defaults = instace.manifest.defaults ?? {};
82
- const configuration = (0, generic_1.overwrite)(defaults, values);
83
- const schema = schemas.schema(instace.manifest.schema);
84
- schema.validate(configuration);
85
- }
86
- exports.SECRET_RX = /^\$(?<variable>[A-Z0-9_]{1,32})$/;
87
- exports.PREFIX = 'TOA_CONFIGURATION_';
88
- //# sourceMappingURL=deployment.js.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C,CAAA;IAEnE,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAA;AAChC,CAAC;AAEY,QAAA,SAAS,GAAG,kCAAkC,CAAA;AAC9C,QAAA,MAAM,GAAG,oBAAoB,CAAA"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const deployment_1 = require("./deployment");
4
- it('should validate annotation', async () => {
5
- const wrongType = 'not ok';
6
- expect(() => (0, deployment_1.deployment)([], wrongType)).toThrow('object');
7
- });
8
- it('should validate values', async () => {
9
- const manifest = {
10
- schema: { foo: 'string', bar: 'number' },
11
- defaults: { foo: 'ok', bar: 0 }
12
- };
13
- const locator = { id: 'component' };
14
- const instances = [{ manifest, locator }];
15
- const annotation = { [locator.id]: { bar: 'not a number' } };
16
- expect(() => (0, deployment_1.deployment)(instances, annotation)).toThrow('number');
17
- });
18
- //# sourceMappingURL=deployment.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deployment.test.js","sourceRoot":"","sources":["../source/deployment.test.ts"],"names":[],"mappings":";;AAAA,6CAAyE;AAGzE,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;IAC1C,MAAM,SAAS,GAAG,QAAiC,CAAA;IAEnD,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,uBAAU,EAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;AAC3D,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,wBAAwB,EAAE,KAAK,IAAI,EAAE;IACtC,MAAM,QAAQ,GAAa;QACzB,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE;QACxC,QAAQ,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE;KAChC,CAAA;IAED,MAAM,OAAO,GAAG,EAAE,EAAE,EAAE,WAAW,EAAE,CAAA;IACnC,MAAM,SAAS,GAAG,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAA0B,CAAA;IAClE,MAAM,UAAU,GAAe,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,CAAA;IAExE,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,uBAAU,EAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;AACnE,CAAC,CAAC,CAAA"}
@@ -1,6 +0,0 @@
1
- import { type Node } from './configuration';
2
- export declare function manifest(manifest: Manifest): Manifest;
3
- export interface Manifest {
4
- schema: object;
5
- defaults?: Node;
6
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.manifest = void 0;
27
- const schemas = __importStar(require("./schemas"));
28
- function manifest(manifest) {
29
- if (manifest.schema === undefined)
30
- manifest = { schema: manifest };
31
- schemas.manifest.validate(manifest);
32
- return manifest;
33
- }
34
- exports.manifest = manifest;
35
- //# sourceMappingURL=manifest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../source/manifest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAoC;AAGpC,SAAgB,QAAQ,CAAE,QAAkB;IAC1C,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS;QAAE,QAAQ,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;IAElE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAEnC,OAAO,QAAQ,CAAA;AACjB,CAAC;AAND,4BAMC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const manifest_1 = require("./manifest");
4
- it('should validate', async () => {
5
- const additional = { schema: {}, foo: 'bar' };
6
- expect(() => {
7
- (0, manifest_1.manifest)(additional);
8
- }).toThrow('not expected');
9
- const wrongType = { schema: 'not ok' };
10
- expect(() => {
11
- (0, manifest_1.manifest)(wrongType);
12
- }).toThrow('object');
13
- });
14
- //# sourceMappingURL=manifest.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifest.test.js","sourceRoot":"","sources":["../source/manifest.test.ts"],"names":[],"mappings":";;AAAA,yCAAoD;AAEpD,EAAE,CAAC,iBAAiB,EAAE,KAAK,IAAI,EAAE;IAC/B,MAAM,UAAU,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAyB,CAAA;IAEpE,MAAM,CAAC,GAAG,EAAE;QACV,IAAA,mBAAQ,EAAC,UAAU,CAAC,CAAA;IACtB,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;IAE1B,MAAM,SAAS,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAyB,CAAA;IAE7D,MAAM,CAAC,GAAG,EAAE;QACV,IAAA,mBAAQ,EAAC,SAAS,CAAC,CAAA;IACrB,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;AACtB,CAAC,CAAC,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { Schema } from '@toa.io/schemas';
2
- export declare const manifest: Schema<any>;
3
- export declare const annotation: Schema<any>;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.annotation = exports.manifest = void 0;
27
- const node_path_1 = require("node:path");
28
- const schemas = __importStar(require("@toa.io/schemas"));
29
- const path = (0, node_path_1.resolve)(__dirname, '../schemas');
30
- const namespace = schemas.namespace(path);
31
- exports.manifest = namespace.schema('manifest');
32
- exports.annotation = namespace.schema('annotation');
33
- //# sourceMappingURL=schemas.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAmC;AACnC,yDAA0C;AAG1C,MAAM,IAAI,GAAG,IAAA,mBAAO,EAAC,SAAS,EAAE,YAAY,CAAC,CAAA;AAC7C,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;AAE5B,QAAA,QAAQ,GAAgB,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;AACpD,QAAA,UAAU,GAAgB,SAAS,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA"}