inferred-types 0.54.6 → 0.54.8
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/modules/inferred-types/dist/index.cjs +192 -79
- package/modules/inferred-types/dist/index.cjs.map +1 -1
- package/modules/inferred-types/dist/index.d.ts +466 -117
- package/modules/inferred-types/dist/index.js +186 -79
- package/modules/inferred-types/dist/index.js.map +1 -1
- package/modules/runtime/dist/index.cjs +210 -91
- package/modules/runtime/dist/index.cjs.map +1 -1
- package/modules/runtime/dist/index.d.ts +270 -45
- package/modules/runtime/dist/index.js +204 -91
- package/modules/runtime/dist/index.js.map +1 -1
- package/modules/types/dist/index.cjs.map +1 -1
- package/modules/types/dist/index.d.ts +195 -71
- package/modules/types/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -248,12 +248,15 @@ __export(src_exports, {
|
|
|
248
248
|
createFnWithProps: () => createFnWithProps,
|
|
249
249
|
createFnWithPropsExplicit: () => createFnWithPropsExplicit,
|
|
250
250
|
createLifoQueue: () => createLifoQueue,
|
|
251
|
+
createMapper: () => createMapper,
|
|
252
|
+
createObjectMap: () => createObjectMap,
|
|
251
253
|
createTypeToken: () => createTypeToken,
|
|
252
254
|
cssColor: () => cssColor,
|
|
253
255
|
csv: () => csv,
|
|
254
256
|
defineCss: () => defineCss,
|
|
255
257
|
defineObj: () => defineObj,
|
|
256
258
|
defineObject: () => defineObject,
|
|
259
|
+
defineObjectApi: () => defineObjectApi,
|
|
257
260
|
defineTuple: () => defineTuple,
|
|
258
261
|
endsWith: () => endsWith,
|
|
259
262
|
ensureLeading: () => ensureLeading,
|
|
@@ -572,7 +575,10 @@ __export(src_exports, {
|
|
|
572
575
|
mergeTuples: () => mergeTuples,
|
|
573
576
|
nameLiteral: () => nameLiteral,
|
|
574
577
|
narrow: () => narrow,
|
|
578
|
+
narrowObjectTo: () => narrowObjectTo,
|
|
579
|
+
narrowObjectToType: () => narrowObjectToType,
|
|
575
580
|
never: () => never,
|
|
581
|
+
objectToApi: () => objectToApi,
|
|
576
582
|
omit: () => omit,
|
|
577
583
|
optional: () => optional,
|
|
578
584
|
optionalOrNull: () => optionalOrNull,
|
|
@@ -3165,6 +3171,101 @@ function asApi(api2) {
|
|
|
3165
3171
|
function handleDoneFn(val, call_bare_fn = false) {
|
|
3166
3172
|
return isObject(val) || isFunction(val) ? isDoneFn(val) ? val.done() : isFunction(val) ? call_bare_fn ? val() : val : val : isFunction(val) ? call_bare_fn ? val() : val : val;
|
|
3167
3173
|
}
|
|
3174
|
+
function addPropsToFn(fn2, clone_fn) {
|
|
3175
|
+
const localFn = clone_fn ? (...args) => fn2(args) : fn2;
|
|
3176
|
+
return (obj) => {
|
|
3177
|
+
for (const k in obj) {
|
|
3178
|
+
localFn[k] = obj[k];
|
|
3179
|
+
}
|
|
3180
|
+
return localFn;
|
|
3181
|
+
};
|
|
3182
|
+
}
|
|
3183
|
+
function addFnToProps(props, _clone_fn) {
|
|
3184
|
+
return (fn2) => {
|
|
3185
|
+
const localFn = (...args) => fn2(args);
|
|
3186
|
+
for (const k in props) {
|
|
3187
|
+
localFn[k] = props[k];
|
|
3188
|
+
}
|
|
3189
|
+
return localFn;
|
|
3190
|
+
};
|
|
3191
|
+
}
|
|
3192
|
+
function createCssSelector(_opt) {
|
|
3193
|
+
return (...selectors) => {
|
|
3194
|
+
return selectors.join(" ");
|
|
3195
|
+
};
|
|
3196
|
+
}
|
|
3197
|
+
function createFnWithProps(fn2, props, narrowing = false) {
|
|
3198
|
+
const fnWithProps = fn2;
|
|
3199
|
+
for (const prop of Object.keys(props)) {
|
|
3200
|
+
fnWithProps[prop] = props[prop];
|
|
3201
|
+
}
|
|
3202
|
+
return isTrue(narrowing) ? fnWithProps : fnWithProps;
|
|
3203
|
+
}
|
|
3204
|
+
function createFnWithPropsExplicit(fn2, props) {
|
|
3205
|
+
const fnWithProps = fn2;
|
|
3206
|
+
for (const prop of Object.keys(props)) {
|
|
3207
|
+
fnWithProps[prop] = props[prop];
|
|
3208
|
+
}
|
|
3209
|
+
return fnWithProps;
|
|
3210
|
+
}
|
|
3211
|
+
function defineObj(literal2 = {}) {
|
|
3212
|
+
return (wide22 = {}) => {
|
|
3213
|
+
const obj = literal2 ? { ...literal2, ...wide22 } : wide22;
|
|
3214
|
+
return obj;
|
|
3215
|
+
};
|
|
3216
|
+
}
|
|
3217
|
+
function defineTuple(...values) {
|
|
3218
|
+
return values.map(
|
|
3219
|
+
(i) => isFunction(i) ? handleDoneFn(i(ShapeApiImplementation)) : i
|
|
3220
|
+
);
|
|
3221
|
+
}
|
|
3222
|
+
function objectToApi(obj, def = null) {
|
|
3223
|
+
const transformed = Object.keys(obj).reduce(
|
|
3224
|
+
(acc, key) => {
|
|
3225
|
+
const val = obj[key];
|
|
3226
|
+
return {
|
|
3227
|
+
...acc,
|
|
3228
|
+
[key]: () => val
|
|
3229
|
+
};
|
|
3230
|
+
},
|
|
3231
|
+
{}
|
|
3232
|
+
);
|
|
3233
|
+
const api2 = {
|
|
3234
|
+
__kind: "ObjectApi",
|
|
3235
|
+
done: () => def,
|
|
3236
|
+
...transformed
|
|
3237
|
+
};
|
|
3238
|
+
return api2;
|
|
3239
|
+
}
|
|
3240
|
+
function mapper() {
|
|
3241
|
+
return (map2) => {
|
|
3242
|
+
return (input) => {
|
|
3243
|
+
const api2 = objectToApi(input);
|
|
3244
|
+
const rtn = map2(api2);
|
|
3245
|
+
return handleDoneFn(rtn);
|
|
3246
|
+
};
|
|
3247
|
+
};
|
|
3248
|
+
}
|
|
3249
|
+
function objectApi() {
|
|
3250
|
+
return {
|
|
3251
|
+
mapTo: (_defn) => ({
|
|
3252
|
+
mapper: mapper()
|
|
3253
|
+
}),
|
|
3254
|
+
mapToWithType: () => mapper()
|
|
3255
|
+
};
|
|
3256
|
+
}
|
|
3257
|
+
function defineObjectApi__Fn(_inputDefn) {
|
|
3258
|
+
return objectApi();
|
|
3259
|
+
}
|
|
3260
|
+
var defineObjectApi__Prop = {
|
|
3261
|
+
withType: () => {
|
|
3262
|
+
return objectApi();
|
|
3263
|
+
}
|
|
3264
|
+
};
|
|
3265
|
+
var defineObjectApi = createFnWithProps(
|
|
3266
|
+
defineObjectApi__Fn,
|
|
3267
|
+
defineObjectApi__Prop
|
|
3268
|
+
);
|
|
3168
3269
|
function ifArray(val, isAnArray, isNotAnArray) {
|
|
3169
3270
|
return Array.isArray(val) ? isAnArray(val) : isNotAnArray(val);
|
|
3170
3271
|
}
|
|
@@ -5132,6 +5233,31 @@ function keysOf(container) {
|
|
|
5132
5233
|
const keys = Array.isArray(container) ? Object.keys(container).map((i) => Number(i)) : isObject(container) ? isRef(container) ? ["value"] : Object.keys(container) : [];
|
|
5133
5234
|
return keys;
|
|
5134
5235
|
}
|
|
5236
|
+
function callback() {
|
|
5237
|
+
return (cb) => {
|
|
5238
|
+
return (input) => cb(input);
|
|
5239
|
+
};
|
|
5240
|
+
}
|
|
5241
|
+
function narrowFn() {
|
|
5242
|
+
const fn2 = (obj) => obj;
|
|
5243
|
+
return fn2;
|
|
5244
|
+
}
|
|
5245
|
+
function narrowObjectTo(_defn) {
|
|
5246
|
+
return createFnWithPropsExplicit(
|
|
5247
|
+
narrowFn(),
|
|
5248
|
+
{
|
|
5249
|
+
asCallback: callback()
|
|
5250
|
+
}
|
|
5251
|
+
);
|
|
5252
|
+
}
|
|
5253
|
+
function narrowObjectToType() {
|
|
5254
|
+
return createFnWithPropsExplicit(
|
|
5255
|
+
narrowFn(),
|
|
5256
|
+
{
|
|
5257
|
+
asCallback: callback()
|
|
5258
|
+
}
|
|
5259
|
+
);
|
|
5260
|
+
}
|
|
5135
5261
|
function omit(obj, ...removeKeys) {
|
|
5136
5262
|
const keys = Object.keys(obj);
|
|
5137
5263
|
return keys.reduce(
|
|
@@ -5218,75 +5344,27 @@ function fnMeta(func) {
|
|
|
5218
5344
|
};
|
|
5219
5345
|
}
|
|
5220
5346
|
var wrapFn = "NOT IMPLEMENTED";
|
|
5221
|
-
function addPropsToFn(fn2, clone_fn) {
|
|
5222
|
-
const localFn = clone_fn ? (...args) => fn2(args) : fn2;
|
|
5223
|
-
return (obj) => {
|
|
5224
|
-
for (const k in obj) {
|
|
5225
|
-
localFn[k] = obj[k];
|
|
5226
|
-
}
|
|
5227
|
-
return localFn;
|
|
5228
|
-
};
|
|
5229
|
-
}
|
|
5230
|
-
function addFnToProps(props, _clone_fn) {
|
|
5231
|
-
return (fn2) => {
|
|
5232
|
-
const localFn = (...args) => fn2(args);
|
|
5233
|
-
for (const k in props) {
|
|
5234
|
-
localFn[k] = props[k];
|
|
5235
|
-
}
|
|
5236
|
-
return localFn;
|
|
5237
|
-
};
|
|
5238
|
-
}
|
|
5239
|
-
function createCssSelector(_opt) {
|
|
5240
|
-
return (...selectors) => {
|
|
5241
|
-
return selectors.join(" ");
|
|
5242
|
-
};
|
|
5243
|
-
}
|
|
5244
|
-
function createFnWithProps(fn2, props, narrowing = false) {
|
|
5245
|
-
const fnWithProps = fn2;
|
|
5246
|
-
for (const prop of Object.keys(props)) {
|
|
5247
|
-
fnWithProps[prop] = props[prop];
|
|
5248
|
-
}
|
|
5249
|
-
return isTrue(narrowing) ? fnWithProps : fnWithProps;
|
|
5250
|
-
}
|
|
5251
|
-
function createFnWithPropsExplicit(fn2, props) {
|
|
5252
|
-
const fnWithProps = fn2;
|
|
5253
|
-
for (const prop of Object.keys(props)) {
|
|
5254
|
-
fnWithProps[prop] = props[prop];
|
|
5255
|
-
}
|
|
5256
|
-
return fnWithProps;
|
|
5257
|
-
}
|
|
5258
|
-
function defineObj(literal2 = {}) {
|
|
5259
|
-
return (wide22 = {}) => {
|
|
5260
|
-
const obj = literal2 ? { ...literal2, ...wide22 } : wide22;
|
|
5261
|
-
return obj;
|
|
5262
|
-
};
|
|
5263
|
-
}
|
|
5264
|
-
function defineTuple(...values) {
|
|
5265
|
-
return values.map(
|
|
5266
|
-
(i) => isFunction(i) ? handleDoneFn(i(ShapeApiImplementation)) : i
|
|
5267
|
-
);
|
|
5268
|
-
}
|
|
5269
5347
|
function asArray(thing) {
|
|
5270
5348
|
return Array.isArray(thing) === true ? thing : typeof thing === "undefined" ? [] : [thing];
|
|
5271
5349
|
}
|
|
5272
|
-
function createConverter(
|
|
5350
|
+
function createConverter(mapper2) {
|
|
5273
5351
|
return (input) => {
|
|
5274
5352
|
let result2;
|
|
5275
5353
|
if (isNothing(input)) {
|
|
5276
|
-
result2 =
|
|
5354
|
+
result2 = mapper2.nothing ? mapper2.nothing(input) : Never2;
|
|
5277
5355
|
} else if (isObject(input)) {
|
|
5278
|
-
result2 =
|
|
5356
|
+
result2 = mapper2.object ? mapper2.object(input) : Never2;
|
|
5279
5357
|
} else {
|
|
5280
5358
|
switch (typeof input) {
|
|
5281
5359
|
case "string":
|
|
5282
|
-
result2 =
|
|
5360
|
+
result2 = mapper2.string ? mapper2.string(input) : Never2;
|
|
5283
5361
|
break;
|
|
5284
5362
|
case "number":
|
|
5285
5363
|
case "bigint":
|
|
5286
|
-
result2 =
|
|
5364
|
+
result2 = mapper2.number ? mapper2.number(input) : Never2;
|
|
5287
5365
|
break;
|
|
5288
5366
|
case "boolean":
|
|
5289
|
-
result2 =
|
|
5367
|
+
result2 = mapper2.boolean ? mapper2.boolean(input) : Never2;
|
|
5290
5368
|
break;
|
|
5291
5369
|
default:
|
|
5292
5370
|
throw new Error(`Unhandled type: ${typeof input}`);
|
|
@@ -5806,6 +5884,37 @@ function lookupCountryCode(token) {
|
|
|
5806
5884
|
const uc = uppercase(token);
|
|
5807
5885
|
return isNumberLike(token) ? lookupNumericCode(token, "countryCode") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "countryCode") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "countryCode") : isIso3166CountryName(token) ? lookupName(token, "countryCode") : void 0;
|
|
5808
5886
|
}
|
|
5887
|
+
function asMapper(fn2) {
|
|
5888
|
+
const props = {
|
|
5889
|
+
kind: "Mapper",
|
|
5890
|
+
map: (from) => {
|
|
5891
|
+
return from.map(fn2);
|
|
5892
|
+
}
|
|
5893
|
+
};
|
|
5894
|
+
return createFnWithPropsExplicit(fn2, props);
|
|
5895
|
+
}
|
|
5896
|
+
function createObjectMap() {
|
|
5897
|
+
return (map2) => {
|
|
5898
|
+
const fn2 = (input) => {
|
|
5899
|
+
return Object.keys(map2).reduce(
|
|
5900
|
+
(acc, key) => {
|
|
5901
|
+
const val = map2[key];
|
|
5902
|
+
return {
|
|
5903
|
+
...acc,
|
|
5904
|
+
[key]: isFunction(val) ? val(input) : val
|
|
5905
|
+
};
|
|
5906
|
+
},
|
|
5907
|
+
{}
|
|
5908
|
+
);
|
|
5909
|
+
};
|
|
5910
|
+
return fn2;
|
|
5911
|
+
};
|
|
5912
|
+
}
|
|
5913
|
+
function createMapper() {
|
|
5914
|
+
return (fn2) => {
|
|
5915
|
+
return asMapper(fn2);
|
|
5916
|
+
};
|
|
5917
|
+
}
|
|
5809
5918
|
function mergeObjects(defVal, override) {
|
|
5810
5919
|
const intersectingKeys = sharedKeys(defVal, override);
|
|
5811
5920
|
const defUnique = withoutKeys(defVal, ...intersectingKeys);
|
|
@@ -6633,26 +6742,23 @@ function ifUppercaseChar(ch, callbackForMatch, callbackForNoMatch) {
|
|
|
6633
6742
|
return LOWER_ALPHA_CHARS2.includes(ch) ? callbackForMatch(ch) : callbackForNoMatch(ch);
|
|
6634
6743
|
}
|
|
6635
6744
|
function parseTemplate(template) {
|
|
6636
|
-
const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:as\s+(string|number|boolean)\s*)?\}\}/g;
|
|
6745
|
+
const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:(?:extends|as)\s+(string|number|boolean)\s*)?\}\}/g;
|
|
6637
6746
|
let lastIndex = 0;
|
|
6638
6747
|
let match;
|
|
6639
6748
|
const segments = [];
|
|
6640
|
-
|
|
6641
|
-
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
if (staticPart) {
|
|
6646
|
-
segments.push({ dynamic: false, text: staticPart });
|
|
6647
|
-
}
|
|
6648
|
-
segments.push({
|
|
6649
|
-
dynamic: true,
|
|
6650
|
-
varName,
|
|
6651
|
-
type: asType2 ? asType2 : "string"
|
|
6652
|
-
});
|
|
6653
|
-
lastIndex = match.index + fullMatch.length;
|
|
6749
|
+
while (match = pattern.exec(template)) {
|
|
6750
|
+
const [fullMatch, varName, asType2] = match;
|
|
6751
|
+
const staticPart = template.slice(lastIndex, match.index);
|
|
6752
|
+
if (staticPart) {
|
|
6753
|
+
segments.push({ dynamic: false, text: staticPart });
|
|
6654
6754
|
}
|
|
6655
|
-
|
|
6755
|
+
segments.push({
|
|
6756
|
+
dynamic: true,
|
|
6757
|
+
varName,
|
|
6758
|
+
type: asType2 ? asType2 : "string"
|
|
6759
|
+
});
|
|
6760
|
+
lastIndex = match.index + fullMatch.length;
|
|
6761
|
+
}
|
|
6656
6762
|
const remainder = template.slice(lastIndex);
|
|
6657
6763
|
if (remainder) {
|
|
6658
6764
|
segments.push({ dynamic: false, text: remainder });
|
|
@@ -6670,19 +6776,19 @@ function buildRegexPattern(segments) {
|
|
|
6670
6776
|
} else {
|
|
6671
6777
|
switch (seg.type) {
|
|
6672
6778
|
case "string":
|
|
6673
|
-
regexStr +=
|
|
6779
|
+
regexStr += "(.*?)";
|
|
6674
6780
|
break;
|
|
6675
6781
|
case "number":
|
|
6676
|
-
regexStr +=
|
|
6782
|
+
regexStr += "(\\d+)";
|
|
6677
6783
|
break;
|
|
6678
6784
|
case "boolean":
|
|
6679
|
-
regexStr +=
|
|
6785
|
+
regexStr += "(true|false)";
|
|
6680
6786
|
break;
|
|
6681
6787
|
}
|
|
6682
6788
|
}
|
|
6683
6789
|
}
|
|
6684
6790
|
regexStr += "$";
|
|
6685
|
-
return new RegExp(regexStr
|
|
6791
|
+
return new RegExp(regexStr);
|
|
6686
6792
|
}
|
|
6687
6793
|
function convertValue(type, value) {
|
|
6688
6794
|
switch (type) {
|
|
@@ -6694,19 +6800,20 @@ function convertValue(type, value) {
|
|
|
6694
6800
|
return value === "true";
|
|
6695
6801
|
}
|
|
6696
6802
|
}
|
|
6697
|
-
function matchTemplate(
|
|
6698
|
-
const segments = parseTemplate(
|
|
6803
|
+
function matchTemplate(template, test) {
|
|
6804
|
+
const segments = parseTemplate(template);
|
|
6699
6805
|
const regex = buildRegexPattern(segments);
|
|
6700
|
-
const match =
|
|
6806
|
+
const match = regex.exec(test);
|
|
6701
6807
|
if (!match)
|
|
6702
6808
|
return false;
|
|
6809
|
+
let captureIndex = 1;
|
|
6703
6810
|
const result2 = {};
|
|
6704
6811
|
for (const seg of segments) {
|
|
6705
6812
|
if (seg.dynamic) {
|
|
6706
|
-
const rawVal = match
|
|
6813
|
+
const rawVal = match[captureIndex++];
|
|
6707
6814
|
if (rawVal === void 0)
|
|
6708
6815
|
return false;
|
|
6709
|
-
result2[seg.varName
|
|
6816
|
+
result2[seg.varName] = convertValue(seg.type, rawVal);
|
|
6710
6817
|
}
|
|
6711
6818
|
}
|
|
6712
6819
|
return result2;
|
|
@@ -7854,12 +7961,15 @@ var ExifSaturation = /* @__PURE__ */ ((ExifSaturation2) => {
|
|
|
7854
7961
|
createFnWithProps,
|
|
7855
7962
|
createFnWithPropsExplicit,
|
|
7856
7963
|
createLifoQueue,
|
|
7964
|
+
createMapper,
|
|
7965
|
+
createObjectMap,
|
|
7857
7966
|
createTypeToken,
|
|
7858
7967
|
cssColor,
|
|
7859
7968
|
csv,
|
|
7860
7969
|
defineCss,
|
|
7861
7970
|
defineObj,
|
|
7862
7971
|
defineObject,
|
|
7972
|
+
defineObjectApi,
|
|
7863
7973
|
defineTuple,
|
|
7864
7974
|
endsWith,
|
|
7865
7975
|
ensureLeading,
|
|
@@ -8178,7 +8288,10 @@ var ExifSaturation = /* @__PURE__ */ ((ExifSaturation2) => {
|
|
|
8178
8288
|
mergeTuples,
|
|
8179
8289
|
nameLiteral,
|
|
8180
8290
|
narrow,
|
|
8291
|
+
narrowObjectTo,
|
|
8292
|
+
narrowObjectToType,
|
|
8181
8293
|
never,
|
|
8294
|
+
objectToApi,
|
|
8182
8295
|
omit,
|
|
8183
8296
|
optional,
|
|
8184
8297
|
optionalOrNull,
|