@k8ts/metadata 0.10.3 → 0.11.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 (94) hide show
  1. package/dist/error.d.ts +1 -1
  2. package/dist/error.d.ts.map +1 -1
  3. package/dist/error.js +3 -3
  4. package/dist/error.js.map +1 -1
  5. package/dist/index.d.ts +2 -3
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -5
  8. package/dist/index.js.map +1 -1
  9. package/dist/input/dict-input.d.ts +5 -8
  10. package/dist/input/dict-input.d.ts.map +1 -1
  11. package/dist/input/index.d.ts +8 -0
  12. package/dist/input/index.d.ts.map +1 -0
  13. package/dist/input/index.js +24 -0
  14. package/dist/input/index.js.map +1 -0
  15. package/dist/input/key/base.d.ts +6 -0
  16. package/dist/input/key/base.d.ts.map +1 -0
  17. package/dist/input/key/base.js +13 -0
  18. package/dist/input/key/base.js.map +1 -0
  19. package/dist/input/key/domain-prefix.d.ts +8 -0
  20. package/dist/input/key/domain-prefix.d.ts.map +1 -0
  21. package/dist/input/key/domain-prefix.js +19 -0
  22. package/dist/input/key/domain-prefix.js.map +1 -0
  23. package/dist/input/key/metadata-key.d.ts +21 -0
  24. package/dist/input/key/metadata-key.d.ts.map +1 -0
  25. package/dist/input/key/metadata-key.js +82 -0
  26. package/dist/input/key/metadata-key.js.map +1 -0
  27. package/dist/input/key/parse-key.d.ts +10 -0
  28. package/dist/input/key/parse-key.d.ts.map +1 -0
  29. package/dist/{key → input/key}/parse-key.js +10 -8
  30. package/dist/input/key/parse-key.js.map +1 -0
  31. package/dist/input/key/string-types.d.ts +10 -0
  32. package/dist/input/key/string-types.d.ts.map +1 -0
  33. package/dist/input/key/string-types.js +3 -0
  34. package/dist/input/key/string-types.js.map +1 -0
  35. package/dist/input/parse-dict.d.ts +3 -2
  36. package/dist/input/parse-dict.d.ts.map +1 -1
  37. package/dist/input/parse-dict.js +16 -7
  38. package/dist/input/parse-dict.js.map +1 -1
  39. package/dist/meta.d.ts +243 -273
  40. package/dist/meta.d.ts.map +1 -1
  41. package/dist/meta.js +259 -297
  42. package/dist/meta.js.map +1 -1
  43. package/dist/util.d.ts +1 -22
  44. package/dist/util.d.ts.map +1 -1
  45. package/dist/util.js +15 -110
  46. package/dist/util.js.map +1 -1
  47. package/dist/utils/map.d.ts +23 -0
  48. package/dist/utils/map.d.ts.map +1 -0
  49. package/dist/utils/map.js +113 -0
  50. package/dist/utils/map.js.map +1 -0
  51. package/dist/utils/order-meta-keyed-object.d.ts.map +1 -0
  52. package/dist/{order-meta-keyed-object.js → utils/order-meta-keyed-object.js} +2 -1
  53. package/dist/utils/order-meta-keyed-object.js.map +1 -0
  54. package/dist/utils/validate.d.ts +4 -0
  55. package/dist/utils/validate.d.ts.map +1 -0
  56. package/dist/utils/validate.js +38 -0
  57. package/dist/utils/validate.js.map +1 -0
  58. package/package.json +2 -8
  59. package/src/error.ts +1 -1
  60. package/src/index.ts +2 -3
  61. package/src/input/dict-input.ts +5 -12
  62. package/src/input/index.ts +7 -0
  63. package/src/input/key/base.ts +10 -0
  64. package/src/input/key/domain-prefix.ts +14 -0
  65. package/src/input/key/metadata-key.ts +90 -0
  66. package/src/{key → input/key}/parse-key.ts +12 -8
  67. package/src/input/key/string-types.ts +15 -0
  68. package/src/input/parse-dict.ts +23 -13
  69. package/src/meta.ts +391 -417
  70. package/src/util.ts +1 -115
  71. package/src/utils/map.ts +115 -0
  72. package/src/{order-meta-keyed-object.ts → utils/order-meta-keyed-object.ts} +2 -1
  73. package/src/utils/validate.ts +32 -0
  74. package/dist/key/index.d.ts +0 -4
  75. package/dist/key/index.d.ts.map +0 -1
  76. package/dist/key/index.js +0 -11
  77. package/dist/key/index.js.map +0 -1
  78. package/dist/key/parse-key.d.ts +0 -8
  79. package/dist/key/parse-key.d.ts.map +0 -1
  80. package/dist/key/parse-key.js.map +0 -1
  81. package/dist/key/repr.d.ts +0 -36
  82. package/dist/key/repr.d.ts.map +0 -1
  83. package/dist/key/repr.js +0 -113
  84. package/dist/key/repr.js.map +0 -1
  85. package/dist/key/types.d.ts +0 -20
  86. package/dist/key/types.d.ts.map +0 -1
  87. package/dist/key/types.js +0 -11
  88. package/dist/key/types.js.map +0 -1
  89. package/dist/order-meta-keyed-object.d.ts.map +0 -1
  90. package/dist/order-meta-keyed-object.js.map +0 -1
  91. package/src/key/index.ts +0 -4
  92. package/src/key/repr.ts +0 -128
  93. package/src/key/types.ts +0 -21
  94. /package/dist/{order-meta-keyed-object.d.ts → utils/order-meta-keyed-object.d.ts} +0 -0
package/src/util.ts CHANGED
@@ -1,115 +1 @@
1
- type Pair<X> = [X, X]
2
- export function mergeWith<K1, K2, V1, V2, V3>(
3
- map1: Map<K1, V1>,
4
- map2: Map<K2, V2>,
5
- merger: (val1: V1, val2: V2, key: K1 | K2) => V3
6
- ): Map<K1 | K2, V1 | V2 | V3> {
7
- const result = new Map<K1 | K2, V1 | V2 | V3>(map1)
8
- const allKeys = new Set<K1 | K2>([...map1.keys(), ...map2.keys()])
9
- for (const k of allKeys) {
10
- const val1 = map1.get(k as K1)
11
- const val2 = map2.get(k as K2)
12
- if (val1 !== undefined && val2 !== undefined) {
13
- result.set(k, merger(val1, val2, k))
14
- } else if (val2 !== undefined) {
15
- result.set(k, val2)
16
- }
17
- }
18
- return result
19
- }
20
-
21
- export function merge<K1, K2, V1, V2>(map1: Map<K1, V1>, map2: Map<K2, V2>): Map<K1 | K2, V1 | V2> {
22
- return mergeWith(map1, map2, (_old, _new) => _new)
23
- }
24
-
25
- export function filterMap<K, V>(map: Map<K, V>, pred: (v: V, k: K) => boolean): Map<K, V> {
26
- const out = new Map<K, V>()
27
- for (const [k, v] of map.entries()) {
28
- if (pred(v, k)) out.set(k, v)
29
- }
30
- return out
31
- }
32
-
33
- export function mapKeys<K, V, NK>(map: Map<K, V>, fn: (k: K) => NK): Map<NK, V> {
34
- const out = new Map<NK, V>()
35
- for (const [k, v] of map.entries()) {
36
- out.set(fn(k), v)
37
- }
38
- return out
39
- }
40
-
41
- export function mapValues<K, V, NV>(map: Map<K, V>, fn: (v: V, k: K) => NV): Map<K, NV> {
42
- const out = new Map<K, NV>()
43
- for (const [k, v] of map.entries()) {
44
- out.set(k, fn(v, k))
45
- }
46
- return out
47
- }
48
-
49
- export function toObject<K, V>(map: Map<K, V>): { [k: string]: V } {
50
- const out: { [k: string]: V } = {}
51
- for (const [k, v] of map.entries()) {
52
- const key = (k as any)?.str ?? String(k)
53
- out[key] = v
54
- }
55
- return out
56
- }
57
-
58
- export function toJS<K, V>(map: Map<K, V>): { [k: string]: V } {
59
- return toObject(map)
60
- }
61
-
62
- export function equalsMap<K, V>(a: Map<K, V>, b: Map<K, V>): boolean {
63
- if (a.size !== b.size) return false
64
- for (const [ka, va] of a.entries()) {
65
- let found = false
66
- for (const [kb, vb] of b.entries()) {
67
- const sa = (ka as any)?.str ?? ka
68
- const sb = (kb as any)?.str ?? kb
69
- if (sa === sb) {
70
- found = true
71
- if (va !== vb) return false
72
- break
73
- }
74
- }
75
- if (!found) return false
76
- }
77
- return true
78
- }
79
-
80
- export function mapFromObject<V>(obj: { [k: string]: V }): Map<string, V> {
81
- const map = new Map<string, V>()
82
- for (const k of Object.keys(obj)) {
83
- map.set(k, obj[k])
84
- }
85
- return map
86
- }
87
-
88
- export function mapToObject<V>(map: Map<string, V>): { [k: string]: V } {
89
- const obj: { [k: string]: V } = {}
90
- for (const [k, v] of map.entries()) {
91
- obj[k] = v
92
- }
93
- return obj
94
- }
95
-
96
- export type SourcedPropertyDescriptor = PropertyDescriptor & {
97
- source: object
98
- }
99
- export function getDeepPropertyDescriptor(
100
- obj: any,
101
- propertyKey: string | symbol
102
- ): SourcedPropertyDescriptor | undefined {
103
- let current = obj
104
- while (current) {
105
- const descriptor = Object.getOwnPropertyDescriptor(current, propertyKey)
106
- if (descriptor) {
107
- return {
108
- ...descriptor,
109
- source: current
110
- }
111
- }
112
- current = Object.getPrototypeOf(current)
113
- }
114
- return undefined
115
- }
1
+ export * from "./utils/map"
@@ -0,0 +1,115 @@
1
+ type Pair<X> = [X, X]
2
+ export function mergeWith<K1, K2, V1, V2, V3>(
3
+ map1: Map<K1, V1>,
4
+ map2: Map<K2, V2>,
5
+ merger: (val1: V1, val2: V2, key: K1 | K2) => V3
6
+ ): Map<K1 | K2, V1 | V2 | V3> {
7
+ const result = new Map<K1 | K2, V1 | V2 | V3>(map1)
8
+ const allKeys = new Set<K1 | K2>([...map1.keys(), ...map2.keys()])
9
+ for (const k of allKeys) {
10
+ const val1 = map1.get(k as K1)
11
+ const val2 = map2.get(k as K2)
12
+ if (val1 !== undefined && val2 !== undefined) {
13
+ result.set(k, merger(val1, val2, k))
14
+ } else if (val2 !== undefined) {
15
+ result.set(k, val2)
16
+ }
17
+ }
18
+ return result
19
+ }
20
+
21
+ export function merge<K1, K2, V1, V2>(map1: Map<K1, V1>, map2: Map<K2, V2>): Map<K1 | K2, V1 | V2> {
22
+ return mergeWith(map1, map2, (_old, _new) => _new)
23
+ }
24
+
25
+ export function filterMap<K, V>(map: Map<K, V>, pred: (v: V, k: K) => boolean): Map<K, V> {
26
+ const out = new Map<K, V>()
27
+ for (const [k, v] of map.entries()) {
28
+ if (pred(v, k)) out.set(k, v)
29
+ }
30
+ return out
31
+ }
32
+
33
+ export function mapKeys<K, V, NK>(map: Map<K, V>, fn: (k: K) => NK): Map<NK, V> {
34
+ const out = new Map<NK, V>()
35
+ for (const [k, v] of map.entries()) {
36
+ out.set(fn(k), v)
37
+ }
38
+ return out
39
+ }
40
+
41
+ export function mapValues<K, V, NV>(map: Map<K, V>, fn: (v: V, k: K) => NV): Map<K, NV> {
42
+ const out = new Map<K, NV>()
43
+ for (const [k, v] of map.entries()) {
44
+ out.set(k, fn(v, k))
45
+ }
46
+ return out
47
+ }
48
+
49
+ export function toObject<K, V>(map: Map<K, V>): { [k: string]: V } {
50
+ const out: { [k: string]: V } = {}
51
+ for (const [k, v] of map.entries()) {
52
+ const key = (k as any)?.str ?? String(k)
53
+ out[key] = v
54
+ }
55
+ return out
56
+ }
57
+
58
+ export function toJS<K, V>(map: Map<K, V>): { [k: string]: V } {
59
+ return toObject(map)
60
+ }
61
+
62
+ export function equalsMap<K, V>(a: Map<K, V>, b: Map<K, V>): boolean {
63
+ if (a.size !== b.size) return false
64
+ for (const [ka, va] of a.entries()) {
65
+ let found = false
66
+ for (const [kb, vb] of b.entries()) {
67
+ const sa = (ka as any)?.str ?? ka
68
+ const sb = (kb as any)?.str ?? kb
69
+ if (sa === sb) {
70
+ found = true
71
+ if (va !== vb) return false
72
+ break
73
+ }
74
+ }
75
+ if (!found) return false
76
+ }
77
+ return true
78
+ }
79
+
80
+ export function mapFromObject<V>(obj: { [k: string]: V }): Map<string, V> {
81
+ const map = new Map<string, V>()
82
+ for (const k of Object.keys(obj)) {
83
+ map.set(k, obj[k])
84
+ }
85
+ return map
86
+ }
87
+
88
+ export function mapToObject<V>(map: Map<string, V>): { [k: string]: V } {
89
+ const obj: { [k: string]: V } = {}
90
+ for (const [k, v] of map.entries()) {
91
+ obj[k] = v
92
+ }
93
+ return obj
94
+ }
95
+
96
+ export type SourcedPropertyDescriptor = PropertyDescriptor & {
97
+ source: object
98
+ }
99
+ export function getDeepPropertyDescriptor(
100
+ obj: any,
101
+ propertyKey: string | symbol
102
+ ): SourcedPropertyDescriptor | undefined {
103
+ let current = obj
104
+ while (current) {
105
+ const descriptor = Object.getOwnPropertyDescriptor(current, propertyKey)
106
+ if (descriptor) {
107
+ return {
108
+ ...descriptor,
109
+ source: current
110
+ }
111
+ }
112
+ current = Object.getPrototypeOf(current)
113
+ }
114
+ return undefined
115
+ }
@@ -1,4 +1,5 @@
1
1
  import { seq } from "doddle"
2
+ import { K8tsMetadataError } from "../error"
2
3
 
3
4
  function comparisonKey(key: string) {
4
5
  const bySlash = key.split("/")
@@ -6,7 +7,7 @@ function comparisonKey(key: string) {
6
7
  return key
7
8
  }
8
9
  if (bySlash.length > 2) {
9
- throw new Error(`Invalid composed key ${key}, too many '/' characters.`)
10
+ throw new K8tsMetadataError(`Invalid composed key ${key}, too many '/' characters.`)
10
11
  }
11
12
  const [dns, name] = bySlash
12
13
  const dnsParts = dns.split(".").reverse()
@@ -0,0 +1,32 @@
1
+ import { K8tsMetadataError } from "../error"
2
+ import { Metadata_Key_Value } from "../input/key/metadata-key"
3
+ import { normalChar, parseOuterKey as parseKey, pNameValue } from "../input/key/parse-key"
4
+
5
+ export function checkMetadataValue(key: string, v: string) {
6
+ const parsed = parseKey(key)
7
+ if (!(parsed instanceof Metadata_Key_Value)) {
8
+ throw new K8tsMetadataError(`Expected value key, got section key for ${key}`)
9
+ }
10
+ if (parsed.metaType === "label") {
11
+ checkMetaString(`value of ${key}`, v, 63)
12
+ } else if (parsed.metaType === "core") {
13
+ checkNameValue(`value of ${key}`, v)
14
+ }
15
+ }
16
+ export function checkNameValue(what: string, v: string) {
17
+ if (!pNameValue.parse(v).isOk) {
18
+ throw new K8tsMetadataError(`Invalid ${what}: ${v}`)
19
+ }
20
+ checkMetaString(what, v, 63)
21
+ }
22
+ export function checkMetaString(thing: string, input: string, length: number) {
23
+ if (!normalChar.parse(input[0]!).isOk) {
24
+ throw new K8tsMetadataError(`${thing} must start with an alphanumeric character.`)
25
+ }
26
+ if (!normalChar.parse(input[input.length - 1]!).isOk) {
27
+ throw new K8tsMetadataError(`${thing} must end with an alphanumeric character.`)
28
+ }
29
+ if (thing.length > length) {
30
+ throw new K8tsMetadataError(`${thing} must be no more than ${length} characters.`)
31
+ }
32
+ }
@@ -1,4 +0,0 @@
1
- export { DomainPrefix, MetadataKey } from "./repr";
2
- export { parseMetaInput } from "../input/parse-dict";
3
- export { parseOuterKey as parseKey } from "./parse-key";
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/key/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,aAAa,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAA"}
package/dist/key/index.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseKey = exports.parseMetaInput = exports.MetadataKey = exports.DomainPrefix = void 0;
4
- var repr_1 = require("./repr");
5
- Object.defineProperty(exports, "DomainPrefix", { enumerable: true, get: function () { return repr_1.DomainPrefix; } });
6
- Object.defineProperty(exports, "MetadataKey", { enumerable: true, get: function () { return repr_1.MetadataKey; } });
7
- var parse_dict_1 = require("../input/parse-dict");
8
- Object.defineProperty(exports, "parseMetaInput", { enumerable: true, get: function () { return parse_dict_1.parseMetaInput; } });
9
- var parse_key_1 = require("./parse-key");
10
- Object.defineProperty(exports, "parseKey", { enumerable: true, get: function () { return parse_key_1.parseOuterKey; } });
11
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/key/index.ts"],"names":[],"mappings":";;;AAAA,+BAAkD;AAAzC,oGAAA,YAAY,OAAA;AAAE,mGAAA,WAAW,OAAA;AAElC,kDAAoD;AAA3C,4GAAA,cAAc,OAAA;AACvB,yCAAuD;AAA9C,qGAAA,aAAa,OAAY"}
@@ -1,8 +0,0 @@
1
- import { DomainPrefix, MetadataKey } from "./repr";
2
- export declare const normalChar: import("parjs").Parjser<string>;
3
- export declare const pNameValue: import("parjs").Parjser<string>;
4
- export declare function parseSectionKey(key: string): DomainPrefix;
5
- export declare function checkValue(value: string): string;
6
- export declare function parseInnerKey(key: string): MetadataKey;
7
- export declare function parseOuterKey(key: string): MetadataKey | DomainPrefix;
8
- //# sourceMappingURL=parse-key.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse-key.d.ts","sourceRoot":"","sources":["../../src/key/parse-key.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YA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IAAI,IAAI,EAAE,CAAC;QACP,OAAO,IAAI,kBAAW,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,CAAA;IACvD,CAAC;IACD,OAAO,IAAI,kBAAW,CAAC,MAAM,EAAE,EAAE,EAAE,aAAa,CAAC,CAAA;AACrD,CAAC,CAAC,EACF,IAAA,gBAAE,EAAC,WAAW,CAAC,CAClB,CAAA;AACD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAA,gBAAE,EAAC,WAAW,CAAC,CAAC,CAAA;AAC5C,SAAgB,eAAe,CAAC,GAAW;IACvC,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAA;AACvC,CAAC;AACD,SAAgB,UAAU,CAAC,KAAa;IACpC,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAA;AAC3D,CAAC;AACD,SAAgB,aAAa,CAAC,GAAW;IACrC,OAAO,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAA;AACrC,CAAC;AACD,SAAgB,aAAa,CAAC,GAAW;IACrC,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACnC,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,KAAK,CAAA;IACvB,CAAC;IACD,MAAM,IAAI,qBAAa,CAAC,uBAAuB,GAAG,KAAK,MAAM,CAAC,QAAQ,EAAE,EAAE,EAAE;QACxE,GAAG;QACH,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE;KAC3B,CAAC,CAAA;AACN,CAAC"}
@@ -1,36 +0,0 @@
1
- import type { Char } from "./types";
2
- interface ImmObject {
3
- equals(other: ImmObject): boolean;
4
- }
5
- declare abstract class KeyType implements ImmObject {
6
- abstract get str(): string;
7
- equals(other: ImmObject): boolean;
8
- toString(): string;
9
- }
10
- export declare function checkMetaString(thing: string, input: string, length: number): void;
11
- export declare class MetadataKey extends KeyType {
12
- private readonly _prefix;
13
- private readonly _domain;
14
- private readonly _name;
15
- type: "full";
16
- constructor(_prefix: string, _domain: string | undefined, _name: string);
17
- get metaType(): "core" | "label" | "comment" | "annotation";
18
- get suffix(): string;
19
- get str(): string;
20
- get parent(): DomainPrefix | null;
21
- prefix(): Char.Prefix.Any;
22
- prefix(prefix: Char.Prefix.Any): this;
23
- name(): string;
24
- name(name: string): this;
25
- domain(): DomainPrefix;
26
- domain(domain: string | DomainPrefix): this;
27
- }
28
- export declare class DomainPrefix extends KeyType {
29
- private readonly _domain;
30
- type: "domain";
31
- constructor(_domain: string);
32
- get str(): string;
33
- }
34
- export type SomeKey = MetadataKey | DomainPrefix;
35
- export {};
36
- //# sourceMappingURL=repr.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"repr.d.ts","sourceRoot":"","sources":["../../src/key/repr.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AACnC,UAAU,SAAS;IACf,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAA;CACpC;AAED,uBAAe,OAAQ,YAAW,SAAS;IACvC,QAAQ,KAAK,GAAG,IAAI,MAAM,CAAA;IAC1B,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO;IAIjC,QAAQ;CAGX;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAU3E;AAED,qBAAa,WAAY,SAAQ,OAAO;IAGhC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJ1B,IAAI,EAAG,MAAM,CAAS;gBAED,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,KAAK,EAAE,MAAM;IASlC,IAAI,QAAQ,gDAaX;IAED,IAAI,MAAM,WAUT;IAED,IAAI,GAAG,WAEN;IAED,IAAI,MAAM,wBAKT;IAED,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG;IACzB,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI;IAQrC,IAAI,IAAI,MAAM;IACd,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQxB,MAAM,IAAI,YAAY;IACtB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;CAW9C;AAED,qBAAa,YAAa,SAAQ,OAAO;IAEzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IADpC,IAAI,EAAG,QAAQ,CAAS;gBACK,OAAO,EAAE,MAAM;IAK5C,IAAI,GAAG,WAEN;CACJ;AAED,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,YAAY,CAAA"}
package/dist/key/repr.js DELETED
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DomainPrefix = exports.MetadataKey = void 0;
4
- exports.checkMetaString = checkMetaString;
5
- const what_are_you_1 = require("what-are-you");
6
- const error_1 = require("../error");
7
- const parse_key_1 = require("./parse-key");
8
- class KeyType {
9
- equals(other) {
10
- return this.constructor === other.constructor && this.toString() === other.toString();
11
- }
12
- toString() {
13
- return this.str;
14
- }
15
- }
16
- function checkMetaString(thing, input, length) {
17
- if (!parse_key_1.normalChar.parse(input[0]).isOk) {
18
- throw new error_1.MetadataError(`${thing} must start with an alphanumeric character.`);
19
- }
20
- if (!parse_key_1.normalChar.parse(input[input.length - 1]).isOk) {
21
- throw new error_1.MetadataError(`${thing} must end with an alphanumeric character.`);
22
- }
23
- if (thing.length > length) {
24
- throw new error_1.MetadataError(`${thing} must be no more than ${length} characters.`);
25
- }
26
- }
27
- class MetadataKey extends KeyType {
28
- _prefix;
29
- _domain;
30
- _name;
31
- type = "full";
32
- constructor(_prefix, _domain, _name) {
33
- super();
34
- this._prefix = _prefix;
35
- this._domain = _domain;
36
- this._name = _name;
37
- if (_domain) {
38
- checkMetaString(`DNS prefix for ${this.str}`, _domain, 253);
39
- }
40
- checkMetaString(`Metadata name of ${this.str}`, _name, 63);
41
- }
42
- get metaType() {
43
- switch (this._prefix) {
44
- case "":
45
- return "core";
46
- case "%":
47
- return "label";
48
- case "#":
49
- return "comment";
50
- case "^":
51
- return "annotation";
52
- default:
53
- throw new Error(`Unknown prefix ${this._prefix}`);
54
- }
55
- }
56
- get suffix() {
57
- const parts = [];
58
- if (this._domain) {
59
- parts.push(this._domain);
60
- if (!this._domain.endsWith("/")) {
61
- parts.push("/");
62
- }
63
- }
64
- parts.push(this._name);
65
- return parts.join("");
66
- }
67
- get str() {
68
- return [this._prefix, this.suffix].join("");
69
- }
70
- get parent() {
71
- if (!this._domain) {
72
- return null;
73
- }
74
- return new DomainPrefix(this._domain);
75
- }
76
- prefix(prefix) {
77
- if ((0, what_are_you_1.isNullish)(prefix)) {
78
- return this._prefix;
79
- }
80
- return new MetadataKey(prefix, this._domain, this._name);
81
- }
82
- name(name) {
83
- if ((0, what_are_you_1.isNullish)(name)) {
84
- return this._name;
85
- }
86
- return new MetadataKey(this._prefix, this._domain, name);
87
- }
88
- domain(domain) {
89
- if ((0, what_are_you_1.isNullish)(domain)) {
90
- return this._domain ? new DomainPrefix(this._domain) : null;
91
- }
92
- domain = domain instanceof DomainPrefix ? domain.str : domain;
93
- if (this._domain) {
94
- throw new Error("Already has a domain");
95
- }
96
- return new MetadataKey(this._prefix, domain, this._name);
97
- }
98
- }
99
- exports.MetadataKey = MetadataKey;
100
- class DomainPrefix extends KeyType {
101
- _domain;
102
- type = "domain";
103
- constructor(_domain) {
104
- super();
105
- this._domain = _domain;
106
- checkMetaString(`Section name ${this._domain}`, _domain, 253);
107
- }
108
- get str() {
109
- return [this._domain].join("");
110
- }
111
- }
112
- exports.DomainPrefix = DomainPrefix;
113
- //# sourceMappingURL=repr.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"repr.js","sourceRoot":"","sources":["../../src/key/repr.ts"],"names":[],"mappings":";;;AAmBA,0CAUC;AA7BD,+CAAwC;AACxC,oCAAwC;AACxC,2CAAwC;AAMxC,MAAe,OAAO;IAElB,MAAM,CAAC,KAAgB;QACnB,OAAO,IAAI,CAAC,WAAW,KAAK,KAAK,CAAC,WAAW,IAAI,IAAI,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,QAAQ,EAAE,CAAA;IACzF,CAAC;IAED,QAAQ;QACJ,OAAO,IAAI,CAAC,GAAG,CAAA;IACnB,CAAC;CACJ;AAED,SAAgB,eAAe,CAAC,KAAa,EAAE,KAAa,EAAE,MAAc;IACxE,IAAI,CAAC,sBAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACpC,MAAM,IAAI,qBAAa,CAAC,GAAG,KAAK,6CAA6C,CAAC,CAAA;IAClF,CAAC;IACD,IAAI,CAAC,sBAAU,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACnD,MAAM,IAAI,qBAAa,CAAC,GAAG,KAAK,4CAA4C,CAAC,CAAA;IACjF,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;QACxB,MAAM,IAAI,qBAAa,CAAC,GAAG,KAAK,yBAAyB,MAAM,cAAc,CAAC,CAAA;IAClF,CAAC;AACL,CAAC;AAED,MAAa,WAAY,SAAQ,OAAO;IAGf;IACA;IACA;IAJrB,IAAI,GAAG,MAAe,CAAA;IACtB,YACqB,OAAe,EACf,OAA2B,EAC3B,KAAa;QAE9B,KAAK,EAAE,CAAA;QAJU,YAAO,GAAP,OAAO,CAAQ;QACf,YAAO,GAAP,OAA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;QADkB,YAAO,GAAP,OAAO,CAAQ;QAExC,eAAe,CAAC,gBAAgB,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,CAAA;IACjE,CAAC;IAED,IAAI,GAAG;QACH,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAClC,CAAC;CACJ;AAVD,oCAUC"}
@@ -1,20 +0,0 @@
1
- export declare namespace Char {
2
- namespace Prefix {
3
- type Label = "%";
4
- type Annotation = "^";
5
- type Comment = "#";
6
- type Any = `${Label | Annotation | Comment}`;
7
- }
8
- namespace Suffix {
9
- type Domain = "/";
10
- const Domain = "/";
11
- }
12
- }
13
- export declare namespace Key {
14
- type Domain = `${string}${Char.Suffix.Domain}`;
15
- type Special = "name" | "namespace";
16
- type Value = (`${Char.Prefix.Any}${string}` & `${string}${string}`) | Special;
17
- type Key = Domain | Value;
18
- }
19
- export type Key = Key.Key;
20
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/key/types.ts"],"names":[],"mappings":"AAAA,yBAAiB,IAAI,CAAC;IAClB,UAAiB,MAAM,CAAC;QACpB,KAAY,KAAK,GAAG,GAAG,CAAA;QACvB,KAAY,UAAU,GAAG,GAAG,CAAA;QAC5B,KAAY,OAAO,GAAG,GAAG,CAAA;QACzB,KAAY,GAAG,GAAG,GAAG,KAAK,GAAG,UAAU,GAAG,OAAO,EAAE,CAAA;KACtD;IACD,UAAiB,MAAM,CAAC;QACpB,KAAY,MAAM,GAAG,GAAG,CAAA;QACjB,MAAM,MAAM,MAAM,CAAA;KAC5B;CACJ;AAED,yBAAiB,GAAG,CAAC;IACjB,KAAY,MAAM,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAA;IACrD,KAAY,OAAO,GAAG,MAAM,GAAG,WAAW,CAAA;IAC1C,KAAY,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,MAAM,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,OAAO,CAAA;IAEpF,KAAY,GAAG,GAAG,MAAM,GAAG,KAAK,CAAA;CACnC;AACD,MAAM,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAA"}
package/dist/key/types.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Char = void 0;
4
- var Char;
5
- (function (Char) {
6
- let Suffix;
7
- (function (Suffix) {
8
- Suffix.Domain = "/";
9
- })(Suffix = Char.Suffix || (Char.Suffix = {}));
10
- })(Char || (exports.Char = Char = {}));
11
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/key/types.ts"],"names":[],"mappings":";;;AAAA,IAAiB,IAAI,CAWpB;AAXD,WAAiB,IAAI;IAOjB,IAAiB,MAAM,CAGtB;IAHD,WAAiB,MAAM;QAEN,aAAM,GAAG,GAAG,CAAA;IAC7B,CAAC,EAHgB,MAAM,GAAN,WAAM,KAAN,WAAM,QAGtB;AACL,CAAC,EAXgB,IAAI,oBAAJ,IAAI,QAWpB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"order-meta-keyed-object.d.ts","sourceRoot":"","sources":["../src/order-meta-keyed-object.ts"],"names":[],"mappings":"AAeA,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAIvF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"order-meta-keyed-object.js","sourceRoot":"","sources":["../src/order-meta-keyed-object.ts"],"names":[],"mappings":";;AAeA,oDAIC;AAnBD,mCAA4B;AAE5B,SAAS,aAAa,CAAC,GAAW;IAC9B,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC9B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAA;IACd,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,4BAA4B,CAAC,CAAA;IAC5E,CAAC;IACD,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,OAAO,CAAA;IAC3B,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAA;IACzC,OAAO,CAAC,GAAG,QAAQ,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AAC7C,CAAC;AAED,SAAgB,oBAAoB,CAAC,KAA6B;IAC9D,MAAM,OAAO,GAAG,IAAA,YAAG,EAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAA;IAEjF,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;AACtC,CAAC"}
package/src/key/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export { DomainPrefix, MetadataKey } from "./repr"
2
-
3
- export { parseMetaInput } from "../input/parse-dict"
4
- export { parseOuterKey as parseKey } from "./parse-key"
package/src/key/repr.ts DELETED
@@ -1,128 +0,0 @@
1
- import { isNullish } from "what-are-you"
2
- import { MetadataError } from "../error"
3
- import { normalChar } from "./parse-key"
4
- import type { Char } from "./types"
5
- interface ImmObject {
6
- equals(other: ImmObject): boolean
7
- }
8
-
9
- abstract class KeyType implements ImmObject {
10
- abstract get str(): string
11
- equals(other: ImmObject): boolean {
12
- return this.constructor === other.constructor && this.toString() === other.toString()
13
- }
14
-
15
- toString() {
16
- return this.str
17
- }
18
- }
19
-
20
- export function checkMetaString(thing: string, input: string, length: number) {
21
- if (!normalChar.parse(input[0]!).isOk) {
22
- throw new MetadataError(`${thing} must start with an alphanumeric character.`)
23
- }
24
- if (!normalChar.parse(input[input.length - 1]!).isOk) {
25
- throw new MetadataError(`${thing} must end with an alphanumeric character.`)
26
- }
27
- if (thing.length > length) {
28
- throw new MetadataError(`${thing} must be no more than ${length} characters.`)
29
- }
30
- }
31
-
32
- export class MetadataKey extends KeyType {
33
- type = "full" as const
34
- constructor(
35
- private readonly _prefix: string,
36
- private readonly _domain: string | undefined,
37
- private readonly _name: string
38
- ) {
39
- super()
40
- if (_domain) {
41
- checkMetaString(`DNS prefix for ${this.str}`, _domain, 253)
42
- }
43
- checkMetaString(`Metadata name of ${this.str}`, _name, 63)
44
- }
45
-
46
- get metaType() {
47
- switch (this._prefix) {
48
- case "":
49
- return "core"
50
- case "%":
51
- return "label"
52
- case "#":
53
- return "comment"
54
- case "^":
55
- return "annotation"
56
- default:
57
- throw new Error(`Unknown prefix ${this._prefix}`)
58
- }
59
- }
60
-
61
- get suffix() {
62
- const parts = []
63
- if (this._domain) {
64
- parts.push(this._domain)
65
- if (!this._domain.endsWith("/")) {
66
- parts.push("/")
67
- }
68
- }
69
- parts.push(this._name)
70
- return parts.join("")
71
- }
72
-
73
- get str() {
74
- return [this._prefix, this.suffix].join("")
75
- }
76
-
77
- get parent() {
78
- if (!this._domain) {
79
- return null
80
- }
81
- return new DomainPrefix(this._domain)
82
- }
83
-
84
- prefix(): Char.Prefix.Any
85
- prefix(prefix: Char.Prefix.Any): this
86
- prefix(prefix?: any) {
87
- if (isNullish(prefix)) {
88
- return this._prefix as Char.Prefix.Any
89
- }
90
- return new MetadataKey(prefix, this._domain, this._name)
91
- }
92
-
93
- name(): string
94
- name(name: string): this
95
- name(name?: any) {
96
- if (isNullish(name)) {
97
- return this._name
98
- }
99
- return new MetadataKey(this._prefix, this._domain, name)
100
- }
101
-
102
- domain(): DomainPrefix
103
- domain(domain: string | DomainPrefix): this
104
- domain(domain?: any) {
105
- if (isNullish(domain)) {
106
- return this._domain ? new DomainPrefix(this._domain) : null
107
- }
108
- domain = domain instanceof DomainPrefix ? domain.str : domain
109
- if (this._domain) {
110
- throw new Error("Already has a domain")
111
- }
112
- return new MetadataKey(this._prefix, domain, this._name)
113
- }
114
- }
115
-
116
- export class DomainPrefix extends KeyType {
117
- type = "domain" as const
118
- constructor(private readonly _domain: string) {
119
- super()
120
- checkMetaString(`Section name ${this._domain}`, _domain, 253)
121
- }
122
-
123
- get str() {
124
- return [this._domain].join("")
125
- }
126
- }
127
-
128
- export type SomeKey = MetadataKey | DomainPrefix