@milaboratories/pl-model-common 1.25.1 → 1.25.3
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/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/author_marker.d.ts +9 -6
- package/dist/base32_encode.cjs +40 -46
- package/dist/base32_encode.cjs.map +1 -1
- package/dist/base32_encode.js +40 -45
- package/dist/base32_encode.js.map +1 -1
- package/dist/base64.cjs +5 -4
- package/dist/base64.cjs.map +1 -1
- package/dist/base64.d.ts +10 -6
- package/dist/base64.js +5 -3
- package/dist/base64.js.map +1 -1
- package/dist/block_state.d.ts +21 -23
- package/dist/bmodel/block_config.cjs +9 -10
- package/dist/bmodel/block_config.cjs.map +1 -1
- package/dist/bmodel/block_config.d.ts +53 -72
- package/dist/bmodel/block_config.js +9 -9
- package/dist/bmodel/block_config.js.map +1 -1
- package/dist/bmodel/code.cjs +7 -6
- package/dist/bmodel/code.cjs.map +1 -1
- package/dist/bmodel/code.d.ts +17 -13
- package/dist/bmodel/code.js +6 -4
- package/dist/bmodel/code.js.map +1 -1
- package/dist/bmodel/container.d.ts +46 -44
- package/dist/bmodel/index.cjs +3 -0
- package/dist/bmodel/index.d.ts +5 -6
- package/dist/bmodel/index.js +3 -0
- package/dist/bmodel/normalization.cjs +90 -106
- package/dist/bmodel/normalization.cjs.map +1 -1
- package/dist/bmodel/normalization.d.ts +7 -3
- package/dist/bmodel/normalization.js +90 -105
- package/dist/bmodel/normalization.js.map +1 -1
- package/dist/bmodel/types.d.ts +4 -1
- package/dist/branding.d.ts +5 -5
- package/dist/common_types.d.ts +19 -15
- package/dist/driver_kit.d.ts +25 -17
- package/dist/drivers/ChunkedStreamReader.cjs +168 -203
- package/dist/drivers/ChunkedStreamReader.cjs.map +1 -1
- package/dist/drivers/ChunkedStreamReader.d.ts +104 -100
- package/dist/drivers/ChunkedStreamReader.js +168 -202
- package/dist/drivers/ChunkedStreamReader.js.map +1 -1
- package/dist/drivers/blob.cjs +15 -17
- package/dist/drivers/blob.cjs.map +1 -1
- package/dist/drivers/blob.d.ts +35 -35
- package/dist/drivers/blob.js +14 -15
- package/dist/drivers/blob.js.map +1 -1
- package/dist/drivers/index.cjs +18 -0
- package/dist/drivers/index.d.ts +29 -9
- package/dist/drivers/index.js +18 -0
- package/dist/drivers/interfaces.d.ts +17 -14
- package/dist/drivers/log.cjs +4 -3
- package/dist/drivers/log.cjs.map +1 -1
- package/dist/drivers/log.d.ts +52 -49
- package/dist/drivers/log.js +4 -2
- package/dist/drivers/log.js.map +1 -1
- package/dist/drivers/ls.cjs +16 -19
- package/dist/drivers/ls.cjs.map +1 -1
- package/dist/drivers/ls.d.ts +73 -76
- package/dist/drivers/ls.js +16 -17
- package/dist/drivers/ls.js.map +1 -1
- package/dist/drivers/pframe/column_filter.d.ts +19 -15
- package/dist/drivers/pframe/data_info.cjs +201 -252
- package/dist/drivers/pframe/data_info.cjs.map +1 -1
- package/dist/drivers/pframe/data_info.d.ts +84 -109
- package/dist/drivers/pframe/data_info.js +201 -250
- package/dist/drivers/pframe/data_info.js.map +1 -1
- package/dist/drivers/pframe/data_types.cjs +38 -63
- package/dist/drivers/pframe/data_types.cjs.map +1 -1
- package/dist/drivers/pframe/data_types.d.ts +91 -93
- package/dist/drivers/pframe/data_types.js +38 -61
- package/dist/drivers/pframe/data_types.js.map +1 -1
- package/dist/drivers/pframe/driver.cjs +7 -0
- package/dist/drivers/pframe/driver.cjs.map +1 -0
- package/dist/drivers/pframe/driver.d.ts +50 -45
- package/dist/drivers/pframe/driver.js +6 -0
- package/dist/drivers/pframe/driver.js.map +1 -0
- package/dist/drivers/pframe/filter_spec.d.ts +127 -123
- package/dist/drivers/pframe/find_columns.d.ts +21 -17
- package/dist/drivers/pframe/index.cjs +15 -0
- package/dist/drivers/pframe/index.d.ts +23 -16
- package/dist/drivers/pframe/index.js +15 -0
- package/dist/drivers/pframe/linker_columns.cjs +184 -238
- package/dist/drivers/pframe/linker_columns.cjs.map +1 -1
- package/dist/drivers/pframe/linker_columns.d.ts +45 -38
- package/dist/drivers/pframe/linker_columns.js +184 -236
- package/dist/drivers/pframe/linker_columns.js.map +1 -1
- package/dist/drivers/pframe/pframe.d.ts +26 -21
- package/dist/drivers/pframe/query/index.cjs +1 -0
- package/dist/drivers/pframe/query/index.d.ts +3 -4
- package/dist/drivers/pframe/query/index.js +1 -0
- package/dist/drivers/pframe/query/query_common.d.ts +205 -247
- package/dist/drivers/pframe/query/query_data.d.ts +25 -23
- package/dist/drivers/pframe/query/query_spec.d.ts +30 -29
- package/dist/drivers/pframe/query/utils.cjs +164 -183
- package/dist/drivers/pframe/query/utils.cjs.map +1 -1
- package/dist/drivers/pframe/query/utils.d.ts +13 -12
- package/dist/drivers/pframe/query/utils.js +164 -181
- package/dist/drivers/pframe/query/utils.js.map +1 -1
- package/dist/drivers/pframe/spec/anchored.cjs +178 -216
- package/dist/drivers/pframe/spec/anchored.cjs.map +1 -1
- package/dist/drivers/pframe/spec/anchored.d.ts +53 -49
- package/dist/drivers/pframe/spec/anchored.js +176 -214
- package/dist/drivers/pframe/spec/anchored.js.map +1 -1
- package/dist/drivers/pframe/spec/filtered_column.cjs +8 -7
- package/dist/drivers/pframe/spec/filtered_column.cjs.map +1 -1
- package/dist/drivers/pframe/spec/filtered_column.d.ts +20 -17
- package/dist/drivers/pframe/spec/filtered_column.js +8 -6
- package/dist/drivers/pframe/spec/filtered_column.js.map +1 -1
- package/dist/drivers/pframe/spec/ids.cjs +16 -14
- package/dist/drivers/pframe/spec/ids.cjs.map +1 -1
- package/dist/drivers/pframe/spec/ids.d.ts +13 -8
- package/dist/drivers/pframe/spec/ids.js +14 -12
- package/dist/drivers/pframe/spec/ids.js.map +1 -1
- package/dist/drivers/pframe/spec/index.cjs +6 -0
- package/dist/drivers/pframe/spec/index.d.ts +6 -7
- package/dist/drivers/pframe/spec/index.js +6 -0
- package/dist/drivers/pframe/spec/native_id.cjs +16 -16
- package/dist/drivers/pframe/spec/native_id.cjs.map +1 -1
- package/dist/drivers/pframe/spec/native_id.d.ts +9 -4
- package/dist/drivers/pframe/spec/native_id.js +13 -13
- package/dist/drivers/pframe/spec/native_id.js.map +1 -1
- package/dist/drivers/pframe/spec/selectors.cjs +72 -112
- package/dist/drivers/pframe/spec/selectors.cjs.map +1 -1
- package/dist/drivers/pframe/spec/selectors.d.ts +99 -94
- package/dist/drivers/pframe/spec/selectors.js +72 -110
- package/dist/drivers/pframe/spec/selectors.js.map +1 -1
- package/dist/drivers/pframe/spec/spec.cjs +282 -324
- package/dist/drivers/pframe/spec/spec.cjs.map +1 -1
- package/dist/drivers/pframe/spec/spec.d.ts +263 -272
- package/dist/drivers/pframe/spec/spec.js +281 -322
- package/dist/drivers/pframe/spec/spec.js.map +1 -1
- package/dist/drivers/pframe/table.d.ts +28 -24
- package/dist/drivers/pframe/table_calculate.cjs +117 -147
- package/dist/drivers/pframe/table_calculate.cjs.map +1 -1
- package/dist/drivers/pframe/table_calculate.d.ts +219 -220
- package/dist/drivers/pframe/table_calculate.js +117 -145
- package/dist/drivers/pframe/table_calculate.js.map +1 -1
- package/dist/drivers/pframe/table_common.cjs +13 -14
- package/dist/drivers/pframe/table_common.cjs.map +1 -1
- package/dist/drivers/pframe/table_common.d.ts +24 -19
- package/dist/drivers/pframe/table_common.js +13 -13
- package/dist/drivers/pframe/table_common.js.map +1 -1
- package/dist/drivers/pframe/unique_values.d.ts +23 -18
- package/dist/drivers/upload.d.ts +21 -18
- package/dist/drivers/urls.cjs +5 -6
- package/dist/drivers/urls.cjs.map +1 -1
- package/dist/drivers/urls.d.ts +12 -9
- package/dist/drivers/urls.js +5 -5
- package/dist/drivers/urls.js.map +1 -1
- package/dist/errors.cjs +65 -86
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +36 -33
- package/dist/errors.js +65 -85
- package/dist/errors.js.map +1 -1
- package/dist/flags/block_flags.cjs +7 -6
- package/dist/flags/block_flags.cjs.map +1 -1
- package/dist/flags/block_flags.d.ts +12 -8
- package/dist/flags/block_flags.js +7 -5
- package/dist/flags/block_flags.js.map +1 -1
- package/dist/flags/flag_utils.cjs +69 -108
- package/dist/flags/flag_utils.cjs.map +1 -1
- package/dist/flags/flag_utils.d.ts +40 -42
- package/dist/flags/flag_utils.js +70 -107
- package/dist/flags/flag_utils.js.map +1 -1
- package/dist/flags/type_utils.d.ts +12 -11
- package/dist/httpAuth.cjs +16 -20
- package/dist/httpAuth.cjs.map +1 -1
- package/dist/httpAuth.d.ts +10 -7
- package/dist/httpAuth.js +16 -19
- package/dist/httpAuth.js.map +1 -1
- package/dist/index.cjs +176 -179
- package/dist/index.d.ts +58 -20
- package/dist/index.js +37 -34
- package/dist/json.cjs +10 -8
- package/dist/json.cjs.map +1 -1
- package/dist/json.d.ts +18 -18
- package/dist/json.js +8 -6
- package/dist/json.js.map +1 -1
- package/dist/navigation.cjs +3 -2
- package/dist/navigation.cjs.map +1 -1
- package/dist/navigation.d.ts +18 -21
- package/dist/navigation.js +3 -1
- package/dist/navigation.js.map +1 -1
- package/dist/plid.cjs +16 -20
- package/dist/plid.cjs.map +1 -1
- package/dist/plid.d.ts +11 -7
- package/dist/plid.js +15 -18
- package/dist/plid.js.map +1 -1
- package/dist/pool/entry.d.ts +11 -11
- package/dist/pool/index.d.ts +3 -4
- package/dist/pool/query.cjs +21 -43
- package/dist/pool/query.cjs.map +1 -1
- package/dist/pool/query.d.ts +25 -20
- package/dist/pool/query.js +20 -40
- package/dist/pool/query.js.map +1 -1
- package/dist/pool/spec.cjs +40 -47
- package/dist/pool/spec.cjs.map +1 -1
- package/dist/pool/spec.d.ts +33 -31
- package/dist/pool/spec.js +40 -45
- package/dist/pool/spec.js.map +1 -1
- package/dist/ref.cjs +51 -71
- package/dist/ref.cjs.map +1 -1
- package/dist/ref.d.ts +36 -33
- package/dist/ref.js +50 -69
- package/dist/ref.js.map +1 -1
- package/dist/utag.d.ts +18 -14
- package/dist/util.cjs +8 -7
- package/dist/util.cjs.map +1 -1
- package/dist/util.d.ts +5 -2
- package/dist/util.js +8 -6
- package/dist/util.js.map +1 -1
- package/dist/value_or_error.cjs +7 -3
- package/dist/value_or_error.cjs.map +1 -1
- package/dist/value_or_error.d.ts +9 -6
- package/dist/value_or_error.js +7 -2
- package/dist/value_or_error.js.map +1 -1
- package/package.json +6 -6
- package/src/flags/block_flags.ts +2 -1
- package/src/flags/flag_utils.ts +0 -22
- package/dist/author_marker.d.ts.map +0 -1
- package/dist/base32_encode.d.ts +0 -8
- package/dist/base32_encode.d.ts.map +0 -1
- package/dist/base64.d.ts.map +0 -1
- package/dist/block_state.d.ts.map +0 -1
- package/dist/bmodel/block_config.d.ts.map +0 -1
- package/dist/bmodel/code.d.ts.map +0 -1
- package/dist/bmodel/container.d.ts.map +0 -1
- package/dist/bmodel/index.d.ts.map +0 -1
- package/dist/bmodel/normalization.d.ts.map +0 -1
- package/dist/bmodel/types.d.ts.map +0 -1
- package/dist/branding.d.ts.map +0 -1
- package/dist/common_types.d.ts.map +0 -1
- package/dist/driver_kit.d.ts.map +0 -1
- package/dist/drivers/ChunkedStreamReader.d.ts.map +0 -1
- package/dist/drivers/blob.d.ts.map +0 -1
- package/dist/drivers/index.d.ts.map +0 -1
- package/dist/drivers/interfaces.d.ts.map +0 -1
- package/dist/drivers/log.d.ts.map +0 -1
- package/dist/drivers/ls.d.ts.map +0 -1
- package/dist/drivers/pframe/column_filter.d.ts.map +0 -1
- package/dist/drivers/pframe/data_info.d.ts.map +0 -1
- package/dist/drivers/pframe/data_types.d.ts.map +0 -1
- package/dist/drivers/pframe/driver.d.ts.map +0 -1
- package/dist/drivers/pframe/filter_spec.d.ts.map +0 -1
- package/dist/drivers/pframe/find_columns.d.ts.map +0 -1
- package/dist/drivers/pframe/index.d.ts.map +0 -1
- package/dist/drivers/pframe/linker_columns.d.ts.map +0 -1
- package/dist/drivers/pframe/pframe.d.ts.map +0 -1
- package/dist/drivers/pframe/query/index.d.ts.map +0 -1
- package/dist/drivers/pframe/query/query_common.d.ts.map +0 -1
- package/dist/drivers/pframe/query/query_data.d.ts.map +0 -1
- package/dist/drivers/pframe/query/query_spec.d.ts.map +0 -1
- package/dist/drivers/pframe/query/utils.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/anchored.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/filtered_column.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/ids.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/index.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/native_id.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/selectors.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/spec.d.ts.map +0 -1
- package/dist/drivers/pframe/table.d.ts.map +0 -1
- package/dist/drivers/pframe/table_calculate.d.ts.map +0 -1
- package/dist/drivers/pframe/table_common.d.ts.map +0 -1
- package/dist/drivers/pframe/type_util.d.ts +0 -5
- package/dist/drivers/pframe/type_util.d.ts.map +0 -1
- package/dist/drivers/pframe/unique_values.d.ts.map +0 -1
- package/dist/drivers/upload.d.ts.map +0 -1
- package/dist/drivers/urls.d.ts.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/flags/block_flags.d.ts.map +0 -1
- package/dist/flags/flag_utils.d.ts.map +0 -1
- package/dist/flags/index.d.ts +0 -4
- package/dist/flags/index.d.ts.map +0 -1
- package/dist/flags/type_utils.d.ts.map +0 -1
- package/dist/httpAuth.d.ts.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/json.d.ts.map +0 -1
- package/dist/navigation.d.ts.map +0 -1
- package/dist/plid.d.ts.map +0 -1
- package/dist/pool/entry.d.ts.map +0 -1
- package/dist/pool/index.d.ts.map +0 -1
- package/dist/pool/query.d.ts.map +0 -1
- package/dist/pool/spec.d.ts.map +0 -1
- package/dist/ref.d.ts.map +0 -1
- package/dist/utag.d.ts.map +0 -1
- package/dist/util.d.ts.map +0 -1
- package/dist/value_or_error.d.ts.map +0 -1
package/dist/flags/flag_utils.js
CHANGED
|
@@ -1,116 +1,79 @@
|
|
|
1
|
+
//#region src/flags/flag_utils.ts
|
|
1
2
|
function checkBlockFlag(flags, flag, flagValue = true) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return flags[flag] === flagValue;
|
|
3
|
+
if (flags === void 0) return false;
|
|
4
|
+
return flags[flag] === flagValue;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
* Extracts all requirements from the feature flags.
|
|
8
|
+
* @param flags - The feature flags.
|
|
9
|
+
* @returns A set of requirements.
|
|
10
|
+
*/
|
|
11
11
|
function extractAllRequirements(flags) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return new Set(Object.entries(flags)
|
|
15
|
-
.filter(([key, value]) => key.startsWith("requires") && value === true)
|
|
16
|
-
.map(([key]) => key));
|
|
12
|
+
if (flags === void 0) return /* @__PURE__ */ new Set();
|
|
13
|
+
return new Set(Object.entries(flags).filter(([key, value]) => key.startsWith("requires") && value === true).map(([key]) => key));
|
|
17
14
|
}
|
|
18
15
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
* Extracts all supports from the feature flags.
|
|
17
|
+
* @param flags - The feature flags.
|
|
18
|
+
* @returns A set of supports.
|
|
19
|
+
*/
|
|
23
20
|
function extractAllSupports(flags) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return new Set(Object.entries(flags)
|
|
27
|
-
.filter(([key, value]) => key.startsWith("supports") && value === true)
|
|
28
|
-
.map(([key]) => key));
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Merges two feature flag objects with type-aware logic:
|
|
32
|
-
* - `supports*` (boolean): OR — `true` if either side is `true`
|
|
33
|
-
* - `requires*` (numeric): MAX — take the higher version requirement
|
|
34
|
-
*/
|
|
35
|
-
function mergeFeatureFlags(base, override) {
|
|
36
|
-
const result = { ...base };
|
|
37
|
-
for (const [key, value] of Object.entries(override)) {
|
|
38
|
-
if (value === undefined)
|
|
39
|
-
continue;
|
|
40
|
-
const existing = result[key];
|
|
41
|
-
if (typeof value === "boolean") {
|
|
42
|
-
result[key] = existing || value;
|
|
43
|
-
}
|
|
44
|
-
else if (typeof value === "number") {
|
|
45
|
-
result[key] = Math.max(existing ?? 0, value);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
class IncompatibleFlagsError extends Error {
|
|
51
|
-
incompatibleFlags;
|
|
52
|
-
name = "IncompatibleFlagsError";
|
|
53
|
-
constructor(incompatibleFlags) {
|
|
54
|
-
super(`Some of the block requirements are not supported by the runtime: ${Array.from(incompatibleFlags.entries())
|
|
55
|
-
.map(([key, value]) => `${key}: ${value}`)
|
|
56
|
-
.join(", ")}`);
|
|
57
|
-
this.incompatibleFlags = incompatibleFlags;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
class RuntimeCapabilities {
|
|
61
|
-
supportedRequirements = new Map();
|
|
62
|
-
/**
|
|
63
|
-
* Adds a supported requirement to the runtime capabilities.
|
|
64
|
-
* @param requirement - The requirement.
|
|
65
|
-
* @param value - The value of the requirement. If not provided, defaults to true.
|
|
66
|
-
*/
|
|
67
|
-
addSupportedRequirement(requirement, value = true) {
|
|
68
|
-
if (!this.supportedRequirements.has(requirement)) {
|
|
69
|
-
this.supportedRequirements.set(requirement, new Set());
|
|
70
|
-
}
|
|
71
|
-
this.supportedRequirements.get(requirement).add(value);
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Returns a map of incompatible flags. If the block flags are compatible, returns undefined.
|
|
76
|
-
* @param blockFlags - The block flags.
|
|
77
|
-
* @returns A map of incompatible flags, or undefined if the block flags are compatible.
|
|
78
|
-
*/
|
|
79
|
-
getIncompatibleFlags(blockFlags) {
|
|
80
|
-
if (blockFlags === undefined)
|
|
81
|
-
return undefined;
|
|
82
|
-
const incompatibleFlags = new Map();
|
|
83
|
-
for (const [key, value] of Object.entries(blockFlags)) {
|
|
84
|
-
if (key.startsWith("requires")) {
|
|
85
|
-
if (value === undefined)
|
|
86
|
-
continue;
|
|
87
|
-
const supportedValues = this.supportedRequirements.get(key);
|
|
88
|
-
if (supportedValues === undefined || !supportedValues.has(value)) {
|
|
89
|
-
incompatibleFlags.set(key, value);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return incompatibleFlags.size === 0 ? undefined : incompatibleFlags;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Checks if the block flags are compatible with the runtime capabilities.
|
|
97
|
-
* @param blockFlags - The block flags.
|
|
98
|
-
* @returns True if the block flags are compatible, false otherwise.
|
|
99
|
-
*/
|
|
100
|
-
checkCompatibility(blockFlags) {
|
|
101
|
-
return this.getIncompatibleFlags(blockFlags) === undefined;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Throws an error if the block flags are incompatible with the runtime capabilities.
|
|
105
|
-
* @param blockFlags - The block flags.
|
|
106
|
-
* @throws IncompatibleFlagsError if the block flags are incompatible with the runtime capabilities.
|
|
107
|
-
*/
|
|
108
|
-
throwIfIncompatible(blockFlags) {
|
|
109
|
-
const incompatibleFlags = this.getIncompatibleFlags(blockFlags);
|
|
110
|
-
if (incompatibleFlags !== undefined)
|
|
111
|
-
throw new IncompatibleFlagsError(incompatibleFlags);
|
|
112
|
-
}
|
|
21
|
+
if (flags === void 0) return /* @__PURE__ */ new Set();
|
|
22
|
+
return new Set(Object.entries(flags).filter(([key, value]) => key.startsWith("supports") && value === true).map(([key]) => key));
|
|
113
23
|
}
|
|
24
|
+
var IncompatibleFlagsError = class extends Error {
|
|
25
|
+
name = "IncompatibleFlagsError";
|
|
26
|
+
constructor(incompatibleFlags) {
|
|
27
|
+
super(`Some of the block requirements are not supported by the runtime: ${Array.from(incompatibleFlags.entries()).map(([key, value]) => `${key}: ${value}`).join(", ")}`);
|
|
28
|
+
this.incompatibleFlags = incompatibleFlags;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var RuntimeCapabilities = class {
|
|
32
|
+
supportedRequirements = /* @__PURE__ */ new Map();
|
|
33
|
+
/**
|
|
34
|
+
* Adds a supported requirement to the runtime capabilities.
|
|
35
|
+
* @param requirement - The requirement.
|
|
36
|
+
* @param value - The value of the requirement. If not provided, defaults to true.
|
|
37
|
+
*/
|
|
38
|
+
addSupportedRequirement(requirement, value = true) {
|
|
39
|
+
if (!this.supportedRequirements.has(requirement)) this.supportedRequirements.set(requirement, /* @__PURE__ */ new Set());
|
|
40
|
+
this.supportedRequirements.get(requirement).add(value);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns a map of incompatible flags. If the block flags are compatible, returns undefined.
|
|
45
|
+
* @param blockFlags - The block flags.
|
|
46
|
+
* @returns A map of incompatible flags, or undefined if the block flags are compatible.
|
|
47
|
+
*/
|
|
48
|
+
getIncompatibleFlags(blockFlags) {
|
|
49
|
+
if (blockFlags === void 0) return void 0;
|
|
50
|
+
const incompatibleFlags = /* @__PURE__ */ new Map();
|
|
51
|
+
for (const [key, value] of Object.entries(blockFlags)) if (key.startsWith("requires")) {
|
|
52
|
+
if (value === void 0) continue;
|
|
53
|
+
const supportedValues = this.supportedRequirements.get(key);
|
|
54
|
+
if (supportedValues === void 0 || !supportedValues.has(value)) incompatibleFlags.set(key, value);
|
|
55
|
+
}
|
|
56
|
+
return incompatibleFlags.size === 0 ? void 0 : incompatibleFlags;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Checks if the block flags are compatible with the runtime capabilities.
|
|
60
|
+
* @param blockFlags - The block flags.
|
|
61
|
+
* @returns True if the block flags are compatible, false otherwise.
|
|
62
|
+
*/
|
|
63
|
+
checkCompatibility(blockFlags) {
|
|
64
|
+
return this.getIncompatibleFlags(blockFlags) === void 0;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Throws an error if the block flags are incompatible with the runtime capabilities.
|
|
68
|
+
* @param blockFlags - The block flags.
|
|
69
|
+
* @throws IncompatibleFlagsError if the block flags are incompatible with the runtime capabilities.
|
|
70
|
+
*/
|
|
71
|
+
throwIfIncompatible(blockFlags) {
|
|
72
|
+
const incompatibleFlags = this.getIncompatibleFlags(blockFlags);
|
|
73
|
+
if (incompatibleFlags !== void 0) throw new IncompatibleFlagsError(incompatibleFlags);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
114
76
|
|
|
115
|
-
|
|
116
|
-
|
|
77
|
+
//#endregion
|
|
78
|
+
export { IncompatibleFlagsError, RuntimeCapabilities, checkBlockFlag, extractAllRequirements, extractAllSupports };
|
|
79
|
+
//# sourceMappingURL=flag_utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flag_utils.js","sources":["../../src/flags/flag_utils.ts"],"sourcesContent":["import type { BlockCodeFeatureFlags, BlockCodeKnownFeatureFlags } from \"./block_flags\";\nimport type { FilterKeysByPrefix } from \"./type_utils\";\n\nexport function checkBlockFlag(\n flags: BlockCodeFeatureFlags | undefined,\n flag: keyof BlockCodeKnownFeatureFlags,\n flagValue: boolean | number = true,\n): boolean {\n if (flags === undefined) return false;\n return flags[flag] === flagValue;\n}\n\n/**\n * Extracts all requirements from the feature flags.\n * @param flags - The feature flags.\n * @returns A set of requirements.\n */\nexport function extractAllRequirements(\n flags: BlockCodeFeatureFlags | undefined,\n): Set<`requires${string}`> {\n if (flags === undefined) return new Set();\n return new Set(\n Object.entries(flags)\n .filter(([key, value]) => key.startsWith(\"requires\") && value === true)\n .map(([key]) => key as `requires${string}`),\n );\n}\n\n/**\n * Extracts all supports from the feature flags.\n * @param flags - The feature flags.\n * @returns A set of supports.\n */\nexport function extractAllSupports(\n flags: BlockCodeFeatureFlags | undefined,\n): Set<`supports${string}`> {\n if (flags === undefined) return new Set();\n return new Set(\n Object.entries(flags)\n .filter(([key, value]) => key.startsWith(\"supports\") && value === true)\n .map(([key]) => key as `supports${string}`),\n );\n}\n\
|
|
1
|
+
{"version":3,"file":"flag_utils.js","names":[],"sources":["../../src/flags/flag_utils.ts"],"sourcesContent":["import type { BlockCodeFeatureFlags, BlockCodeKnownFeatureFlags } from \"./block_flags\";\nimport type { FilterKeysByPrefix } from \"./type_utils\";\n\nexport function checkBlockFlag(\n flags: BlockCodeFeatureFlags | undefined,\n flag: keyof BlockCodeKnownFeatureFlags,\n flagValue: boolean | number = true,\n): boolean {\n if (flags === undefined) return false;\n return flags[flag] === flagValue;\n}\n\n/**\n * Extracts all requirements from the feature flags.\n * @param flags - The feature flags.\n * @returns A set of requirements.\n */\nexport function extractAllRequirements(\n flags: BlockCodeFeatureFlags | undefined,\n): Set<`requires${string}`> {\n if (flags === undefined) return new Set();\n return new Set(\n Object.entries(flags)\n .filter(([key, value]) => key.startsWith(\"requires\") && value === true)\n .map(([key]) => key as `requires${string}`),\n );\n}\n\n/**\n * Extracts all supports from the feature flags.\n * @param flags - The feature flags.\n * @returns A set of supports.\n */\nexport function extractAllSupports(\n flags: BlockCodeFeatureFlags | undefined,\n): Set<`supports${string}`> {\n if (flags === undefined) return new Set();\n return new Set(\n Object.entries(flags)\n .filter(([key, value]) => key.startsWith(\"supports\") && value === true)\n .map(([key]) => key as `supports${string}`),\n );\n}\n\nexport class IncompatibleFlagsError extends Error {\n name = \"IncompatibleFlagsError\";\n constructor(public readonly incompatibleFlags: Map<`requires${string}`, number | boolean>) {\n super(\n `Some of the block requirements are not supported by the runtime: ${Array.from(\n incompatibleFlags.entries(),\n )\n .map(([key, value]) => `${key}: ${value}`)\n .join(\", \")}`,\n );\n }\n}\n\n/**\n * A type that represents a supported requirement.\n * @remarks\n * This type is used to represent a supported requirement.\n * It is a subtype of `BlockCodeKnownFeatureFlags` and is used to represent a supported requirement.\n * It is used to represent a supported requirement.\n */\nexport type SupportedRequirement = FilterKeysByPrefix<BlockCodeKnownFeatureFlags, \"requires\">;\n\nexport class RuntimeCapabilities {\n private readonly supportedRequirements: Map<`requires${string}`, Set<number | boolean>> =\n new Map();\n\n /**\n * Adds a supported requirement to the runtime capabilities.\n * @param requirement - The requirement.\n * @param value - The value of the requirement. If not provided, defaults to true.\n */\n public addSupportedRequirement(\n requirement: SupportedRequirement,\n value: number | boolean = true,\n ): this {\n if (!this.supportedRequirements.has(requirement)) {\n this.supportedRequirements.set(requirement, new Set());\n }\n this.supportedRequirements.get(requirement)!.add(value);\n return this;\n }\n\n /**\n * Returns a map of incompatible flags. If the block flags are compatible, returns undefined.\n * @param blockFlags - The block flags.\n * @returns A map of incompatible flags, or undefined if the block flags are compatible.\n */\n public getIncompatibleFlags(\n blockFlags: BlockCodeFeatureFlags | undefined,\n ): Map<`requires${string}`, number | boolean> | undefined {\n if (blockFlags === undefined) return undefined;\n const incompatibleFlags = new Map<`requires${string}`, number | boolean>();\n for (const [key, value] of Object.entries(blockFlags)) {\n if (key.startsWith(\"requires\")) {\n if (value === undefined) continue;\n const supportedValues = this.supportedRequirements.get(key as `requires${string}`);\n if (supportedValues === undefined || !supportedValues.has(value as number | boolean)) {\n incompatibleFlags.set(key as `requires${string}`, value as number | boolean);\n }\n }\n }\n return incompatibleFlags.size === 0 ? undefined : incompatibleFlags;\n }\n\n /**\n * Checks if the block flags are compatible with the runtime capabilities.\n * @param blockFlags - The block flags.\n * @returns True if the block flags are compatible, false otherwise.\n */\n public checkCompatibility(blockFlags: BlockCodeFeatureFlags | undefined): boolean {\n return this.getIncompatibleFlags(blockFlags) === undefined;\n }\n\n /**\n * Throws an error if the block flags are incompatible with the runtime capabilities.\n * @param blockFlags - The block flags.\n * @throws IncompatibleFlagsError if the block flags are incompatible with the runtime capabilities.\n */\n public throwIfIncompatible(blockFlags: BlockCodeFeatureFlags | undefined) {\n const incompatibleFlags = this.getIncompatibleFlags(blockFlags);\n if (incompatibleFlags !== undefined) throw new IncompatibleFlagsError(incompatibleFlags);\n }\n}\n"],"mappings":";AAGA,SAAgB,eACd,OACA,MACA,YAA8B,MACrB;AACT,KAAI,UAAU,OAAW,QAAO;AAChC,QAAO,MAAM,UAAU;;;;;;;AAQzB,SAAgB,uBACd,OAC0B;AAC1B,KAAI,UAAU,OAAW,wBAAO,IAAI,KAAK;AACzC,QAAO,IAAI,IACT,OAAO,QAAQ,MAAM,CAClB,QAAQ,CAAC,KAAK,WAAW,IAAI,WAAW,WAAW,IAAI,UAAU,KAAK,CACtE,KAAK,CAAC,SAAS,IAA2B,CAC9C;;;;;;;AAQH,SAAgB,mBACd,OAC0B;AAC1B,KAAI,UAAU,OAAW,wBAAO,IAAI,KAAK;AACzC,QAAO,IAAI,IACT,OAAO,QAAQ,MAAM,CAClB,QAAQ,CAAC,KAAK,WAAW,IAAI,WAAW,WAAW,IAAI,UAAU,KAAK,CACtE,KAAK,CAAC,SAAS,IAA2B,CAC9C;;AAGH,IAAa,yBAAb,cAA4C,MAAM;CAChD,OAAO;CACP,YAAY,AAAgB,mBAA+D;AACzF,QACE,oEAAoE,MAAM,KACxE,kBAAkB,SAAS,CAC5B,CACE,KAAK,CAAC,KAAK,WAAW,GAAG,IAAI,IAAI,QAAQ,CACzC,KAAK,KAAK,GACd;EAPyB;;;AAoB9B,IAAa,sBAAb,MAAiC;CAC/B,AAAiB,wCACf,IAAI,KAAK;;;;;;CAOX,AAAO,wBACL,aACA,QAA0B,MACpB;AACN,MAAI,CAAC,KAAK,sBAAsB,IAAI,YAAY,CAC9C,MAAK,sBAAsB,IAAI,6BAAa,IAAI,KAAK,CAAC;AAExD,OAAK,sBAAsB,IAAI,YAAY,CAAE,IAAI,MAAM;AACvD,SAAO;;;;;;;CAQT,AAAO,qBACL,YACwD;AACxD,MAAI,eAAe,OAAW,QAAO;EACrC,MAAM,oCAAoB,IAAI,KAA4C;AAC1E,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,WAAW,CACnD,KAAI,IAAI,WAAW,WAAW,EAAE;AAC9B,OAAI,UAAU,OAAW;GACzB,MAAM,kBAAkB,KAAK,sBAAsB,IAAI,IAA2B;AAClF,OAAI,oBAAoB,UAAa,CAAC,gBAAgB,IAAI,MAA0B,CAClF,mBAAkB,IAAI,KAA4B,MAA0B;;AAIlF,SAAO,kBAAkB,SAAS,IAAI,SAAY;;;;;;;CAQpD,AAAO,mBAAmB,YAAwD;AAChF,SAAO,KAAK,qBAAqB,WAAW,KAAK;;;;;;;CAQnD,AAAO,oBAAoB,YAA+C;EACxE,MAAM,oBAAoB,KAAK,qBAAqB,WAAW;AAC/D,MAAI,sBAAsB,OAAW,OAAM,IAAI,uBAAuB,kBAAkB"}
|
|
@@ -1,35 +1,36 @@
|
|
|
1
|
+
//#region src/flags/type_utils.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Helper to filter keys of a type by a prefix.
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
[K in keyof T as K extends `${P}${string}` ? K : never]: T[K];
|
|
6
|
-
};
|
|
5
|
+
type FilterKeysByPrefix<T, P extends string> = keyof { [K in keyof T as K extends `${P}${string}` ? K : never]: T[K] };
|
|
7
6
|
/**
|
|
8
7
|
* Helper to assert that two types are equal. This will cause a compile-time error if they are not.
|
|
9
8
|
* We use this to ensure all feature flags are accounted for in the arrays below.
|
|
10
9
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
type AssertKeysEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends (<V>() => V extends U ? 1 : 2) ? unknown : {
|
|
11
|
+
error: "Feature flag definitions are out of sync";
|
|
12
|
+
expected: T;
|
|
13
|
+
actual: U;
|
|
15
14
|
};
|
|
16
15
|
/**
|
|
17
16
|
* Checks if two types are exactly equal.
|
|
18
17
|
* Returns 'true' if they are, 'false' otherwise.
|
|
19
18
|
*/
|
|
20
|
-
|
|
19
|
+
type Is<T, U> = (<G>() => G extends T ? 1 : 2) extends (<G>() => G extends U ? 1 : 2) ? true : false;
|
|
21
20
|
/**
|
|
22
21
|
* Checks if T is a subtype of U.
|
|
23
22
|
* Returns 'true' if it is, 'false' otherwise.
|
|
24
23
|
*/
|
|
25
|
-
|
|
24
|
+
type IsSubtypeOf<T, U> = T extends U ? true : false;
|
|
26
25
|
/**
|
|
27
26
|
* Asserts that a condition is true at compile time.
|
|
28
27
|
* Causes a compile error if T is not 'true'.
|
|
29
28
|
*/
|
|
30
|
-
|
|
29
|
+
type Assert<T extends true> = T;
|
|
31
30
|
/**
|
|
32
31
|
* Helper to create a union type of two array value types.
|
|
33
32
|
*/
|
|
34
|
-
|
|
33
|
+
type ArrayTypeUnion<T extends readonly any[], U extends readonly any[]> = T[number] extends never ? U[number] : U[number] extends never ? T[number] : T[number] | U[number];
|
|
34
|
+
//#endregion
|
|
35
|
+
export { ArrayTypeUnion, Assert, AssertKeysEqual, FilterKeysByPrefix, Is, IsSubtypeOf };
|
|
35
36
|
//# sourceMappingURL=type_utils.d.ts.map
|
package/dist/httpAuth.cjs
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
//#region src/httpAuth.ts
|
|
4
3
|
function parseHttpAuth(input) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);
|
|
4
|
+
const match = /(?<scheme>.*?) (?<parameters>.*)/.exec(input);
|
|
5
|
+
if (match?.groups?.scheme === "Basic") {
|
|
6
|
+
const credentialsMatch = /(?<username>.*?):(?<password>.*)/.exec(atob(match.groups.parameters));
|
|
7
|
+
if (!credentialsMatch?.groups) throw new Error(`Malformed credentials.`);
|
|
8
|
+
return {
|
|
9
|
+
scheme: "Basic",
|
|
10
|
+
username: credentialsMatch.groups.username,
|
|
11
|
+
password: credentialsMatch.groups.password
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);
|
|
18
15
|
}
|
|
19
16
|
function serializeHttpAuth(input) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
throw new Error(`Unsupported auth scheme: ${input.scheme}.`);
|
|
17
|
+
if (input.scheme === "Basic") return `Basic ${btoa(`${input.username}:${input.password}`)}`;
|
|
18
|
+
throw new Error(`Unsupported auth scheme: ${input.scheme}.`);
|
|
24
19
|
}
|
|
25
20
|
|
|
21
|
+
//#endregion
|
|
26
22
|
exports.parseHttpAuth = parseHttpAuth;
|
|
27
23
|
exports.serializeHttpAuth = serializeHttpAuth;
|
|
28
|
-
//# sourceMappingURL=httpAuth.cjs.map
|
|
24
|
+
//# sourceMappingURL=httpAuth.cjs.map
|
package/dist/httpAuth.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpAuth.cjs","sources":["../src/httpAuth.ts"],"sourcesContent":["/* TODO: replace atob/btoa with Uint8Array.toBase64/fromBase64 in the future */\n\nexport function parseHttpAuth(input: string): HttpAuth {\n const match = /(?<scheme>.*?) (?<parameters>.*)/.exec(input);\n if (match?.groups?.scheme === \"Basic\") {\n const credentialsMatch = /(?<username>.*?):(?<password>.*)/.exec(atob(match.groups.parameters));\n if (!credentialsMatch?.groups) {\n throw new Error(`Malformed credentials.`);\n }\n return {\n scheme: \"Basic\",\n username: credentialsMatch.groups.username,\n password: credentialsMatch.groups.password,\n };\n }\n throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);\n}\n\nexport function serializeHttpAuth(input: HttpAuth): string {\n if (input.scheme === \"Basic\") {\n return `Basic ${btoa(`${input.username}:${input.password}`)}`;\n }\n throw new Error(`Unsupported auth scheme: ${input.scheme as string}.`);\n}\n\nexport type HttpAuth = BasicHttpAuth;\n\nexport interface BasicHttpAuth {\n scheme: \"Basic\";\n username: string;\n password: string;\n}\n"],"
|
|
1
|
+
{"version":3,"file":"httpAuth.cjs","names":[],"sources":["../src/httpAuth.ts"],"sourcesContent":["/* TODO: replace atob/btoa with Uint8Array.toBase64/fromBase64 in the future */\n\nexport function parseHttpAuth(input: string): HttpAuth {\n const match = /(?<scheme>.*?) (?<parameters>.*)/.exec(input);\n if (match?.groups?.scheme === \"Basic\") {\n const credentialsMatch = /(?<username>.*?):(?<password>.*)/.exec(atob(match.groups.parameters));\n if (!credentialsMatch?.groups) {\n throw new Error(`Malformed credentials.`);\n }\n return {\n scheme: \"Basic\",\n username: credentialsMatch.groups.username,\n password: credentialsMatch.groups.password,\n };\n }\n throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);\n}\n\nexport function serializeHttpAuth(input: HttpAuth): string {\n if (input.scheme === \"Basic\") {\n return `Basic ${btoa(`${input.username}:${input.password}`)}`;\n }\n throw new Error(`Unsupported auth scheme: ${input.scheme as string}.`);\n}\n\nexport type HttpAuth = BasicHttpAuth;\n\nexport interface BasicHttpAuth {\n scheme: \"Basic\";\n username: string;\n password: string;\n}\n"],"mappings":";;AAEA,SAAgB,cAAc,OAAyB;CACrD,MAAM,QAAQ,mCAAmC,KAAK,MAAM;AAC5D,KAAI,OAAO,QAAQ,WAAW,SAAS;EACrC,MAAM,mBAAmB,mCAAmC,KAAK,KAAK,MAAM,OAAO,WAAW,CAAC;AAC/F,MAAI,CAAC,kBAAkB,OACrB,OAAM,IAAI,MAAM,yBAAyB;AAE3C,SAAO;GACL,QAAQ;GACR,UAAU,iBAAiB,OAAO;GAClC,UAAU,iBAAiB,OAAO;GACnC;;AAEH,OAAM,IAAI,MAAM,4BAA4B,OAAO,QAAQ,OAAO,GAAG;;AAGvE,SAAgB,kBAAkB,OAAyB;AACzD,KAAI,MAAM,WAAW,QACnB,QAAO,SAAS,KAAK,GAAG,MAAM,SAAS,GAAG,MAAM,WAAW;AAE7D,OAAM,IAAI,MAAM,4BAA4B,MAAM,OAAiB,GAAG"}
|
package/dist/httpAuth.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
//#region src/httpAuth.d.ts
|
|
2
|
+
declare function parseHttpAuth(input: string): HttpAuth;
|
|
3
|
+
declare function serializeHttpAuth(input: HttpAuth): string;
|
|
4
|
+
type HttpAuth = BasicHttpAuth;
|
|
5
|
+
interface BasicHttpAuth {
|
|
6
|
+
scheme: "Basic";
|
|
7
|
+
username: string;
|
|
8
|
+
password: string;
|
|
8
9
|
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { BasicHttpAuth, HttpAuth, parseHttpAuth, serializeHttpAuth };
|
|
9
12
|
//# sourceMappingURL=httpAuth.d.ts.map
|
package/dist/httpAuth.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/httpAuth.ts
|
|
2
2
|
function parseHttpAuth(input) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);
|
|
3
|
+
const match = /(?<scheme>.*?) (?<parameters>.*)/.exec(input);
|
|
4
|
+
if (match?.groups?.scheme === "Basic") {
|
|
5
|
+
const credentialsMatch = /(?<username>.*?):(?<password>.*)/.exec(atob(match.groups.parameters));
|
|
6
|
+
if (!credentialsMatch?.groups) throw new Error(`Malformed credentials.`);
|
|
7
|
+
return {
|
|
8
|
+
scheme: "Basic",
|
|
9
|
+
username: credentialsMatch.groups.username,
|
|
10
|
+
password: credentialsMatch.groups.password
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);
|
|
16
14
|
}
|
|
17
15
|
function serializeHttpAuth(input) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
throw new Error(`Unsupported auth scheme: ${input.scheme}.`);
|
|
16
|
+
if (input.scheme === "Basic") return `Basic ${btoa(`${input.username}:${input.password}`)}`;
|
|
17
|
+
throw new Error(`Unsupported auth scheme: ${input.scheme}.`);
|
|
22
18
|
}
|
|
23
19
|
|
|
20
|
+
//#endregion
|
|
24
21
|
export { parseHttpAuth, serializeHttpAuth };
|
|
25
|
-
//# sourceMappingURL=httpAuth.js.map
|
|
22
|
+
//# sourceMappingURL=httpAuth.js.map
|
package/dist/httpAuth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpAuth.js","sources":["../src/httpAuth.ts"],"sourcesContent":["/* TODO: replace atob/btoa with Uint8Array.toBase64/fromBase64 in the future */\n\nexport function parseHttpAuth(input: string): HttpAuth {\n const match = /(?<scheme>.*?) (?<parameters>.*)/.exec(input);\n if (match?.groups?.scheme === \"Basic\") {\n const credentialsMatch = /(?<username>.*?):(?<password>.*)/.exec(atob(match.groups.parameters));\n if (!credentialsMatch?.groups) {\n throw new Error(`Malformed credentials.`);\n }\n return {\n scheme: \"Basic\",\n username: credentialsMatch.groups.username,\n password: credentialsMatch.groups.password,\n };\n }\n throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);\n}\n\nexport function serializeHttpAuth(input: HttpAuth): string {\n if (input.scheme === \"Basic\") {\n return `Basic ${btoa(`${input.username}:${input.password}`)}`;\n }\n throw new Error(`Unsupported auth scheme: ${input.scheme as string}.`);\n}\n\nexport type HttpAuth = BasicHttpAuth;\n\nexport interface BasicHttpAuth {\n scheme: \"Basic\";\n username: string;\n password: string;\n}\n"],"
|
|
1
|
+
{"version":3,"file":"httpAuth.js","names":[],"sources":["../src/httpAuth.ts"],"sourcesContent":["/* TODO: replace atob/btoa with Uint8Array.toBase64/fromBase64 in the future */\n\nexport function parseHttpAuth(input: string): HttpAuth {\n const match = /(?<scheme>.*?) (?<parameters>.*)/.exec(input);\n if (match?.groups?.scheme === \"Basic\") {\n const credentialsMatch = /(?<username>.*?):(?<password>.*)/.exec(atob(match.groups.parameters));\n if (!credentialsMatch?.groups) {\n throw new Error(`Malformed credentials.`);\n }\n return {\n scheme: \"Basic\",\n username: credentialsMatch.groups.username,\n password: credentialsMatch.groups.password,\n };\n }\n throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);\n}\n\nexport function serializeHttpAuth(input: HttpAuth): string {\n if (input.scheme === \"Basic\") {\n return `Basic ${btoa(`${input.username}:${input.password}`)}`;\n }\n throw new Error(`Unsupported auth scheme: ${input.scheme as string}.`);\n}\n\nexport type HttpAuth = BasicHttpAuth;\n\nexport interface BasicHttpAuth {\n scheme: \"Basic\";\n username: string;\n password: string;\n}\n"],"mappings":";AAEA,SAAgB,cAAc,OAAyB;CACrD,MAAM,QAAQ,mCAAmC,KAAK,MAAM;AAC5D,KAAI,OAAO,QAAQ,WAAW,SAAS;EACrC,MAAM,mBAAmB,mCAAmC,KAAK,KAAK,MAAM,OAAO,WAAW,CAAC;AAC/F,MAAI,CAAC,kBAAkB,OACrB,OAAM,IAAI,MAAM,yBAAyB;AAE3C,SAAO;GACL,QAAQ;GACR,UAAU,iBAAiB,OAAO;GAClC,UAAU,iBAAiB,OAAO;GACnC;;AAEH,OAAM,IAAI,MAAM,4BAA4B,OAAO,QAAQ,OAAO,GAAG;;AAGvE,SAAgB,kBAAkB,OAAyB;AACzD,KAAI,MAAM,WAAW,QACnB,QAAO,SAAS,KAAK,GAAG,MAAM,SAAS,GAAG,MAAM,WAAW;AAE7D,OAAM,IAAI,MAAM,4BAA4B,MAAM,OAAiB,GAAG"}
|