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.
@@ -2506,6 +2506,101 @@ function asApi(api2) {
2506
2506
  function handleDoneFn(val, call_bare_fn = false) {
2507
2507
  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;
2508
2508
  }
2509
+ function addPropsToFn(fn2, clone_fn) {
2510
+ const localFn = clone_fn ? (...args) => fn2(args) : fn2;
2511
+ return (obj) => {
2512
+ for (const k in obj) {
2513
+ localFn[k] = obj[k];
2514
+ }
2515
+ return localFn;
2516
+ };
2517
+ }
2518
+ function addFnToProps(props, _clone_fn) {
2519
+ return (fn2) => {
2520
+ const localFn = (...args) => fn2(args);
2521
+ for (const k in props) {
2522
+ localFn[k] = props[k];
2523
+ }
2524
+ return localFn;
2525
+ };
2526
+ }
2527
+ function createCssSelector(_opt) {
2528
+ return (...selectors) => {
2529
+ return selectors.join(" ");
2530
+ };
2531
+ }
2532
+ function createFnWithProps(fn2, props, narrowing = false) {
2533
+ const fnWithProps = fn2;
2534
+ for (const prop of Object.keys(props)) {
2535
+ fnWithProps[prop] = props[prop];
2536
+ }
2537
+ return isTrue(narrowing) ? fnWithProps : fnWithProps;
2538
+ }
2539
+ function createFnWithPropsExplicit(fn2, props) {
2540
+ const fnWithProps = fn2;
2541
+ for (const prop of Object.keys(props)) {
2542
+ fnWithProps[prop] = props[prop];
2543
+ }
2544
+ return fnWithProps;
2545
+ }
2546
+ function defineObj(literal2 = {}) {
2547
+ return (wide22 = {}) => {
2548
+ const obj = literal2 ? { ...literal2, ...wide22 } : wide22;
2549
+ return obj;
2550
+ };
2551
+ }
2552
+ function defineTuple(...values) {
2553
+ return values.map(
2554
+ (i) => isFunction(i) ? handleDoneFn(i(ShapeApiImplementation)) : i
2555
+ );
2556
+ }
2557
+ function objectToApi(obj, def = null) {
2558
+ const transformed = Object.keys(obj).reduce(
2559
+ (acc, key) => {
2560
+ const val = obj[key];
2561
+ return {
2562
+ ...acc,
2563
+ [key]: () => val
2564
+ };
2565
+ },
2566
+ {}
2567
+ );
2568
+ const api2 = {
2569
+ __kind: "ObjectApi",
2570
+ done: () => def,
2571
+ ...transformed
2572
+ };
2573
+ return api2;
2574
+ }
2575
+ function mapper() {
2576
+ return (map2) => {
2577
+ return (input) => {
2578
+ const api2 = objectToApi(input);
2579
+ const rtn = map2(api2);
2580
+ return handleDoneFn(rtn);
2581
+ };
2582
+ };
2583
+ }
2584
+ function objectApi() {
2585
+ return {
2586
+ mapTo: (_defn) => ({
2587
+ mapper: mapper()
2588
+ }),
2589
+ mapToWithType: () => mapper()
2590
+ };
2591
+ }
2592
+ function defineObjectApi__Fn(_inputDefn) {
2593
+ return objectApi();
2594
+ }
2595
+ var defineObjectApi__Prop = {
2596
+ withType: () => {
2597
+ return objectApi();
2598
+ }
2599
+ };
2600
+ var defineObjectApi = createFnWithProps(
2601
+ defineObjectApi__Fn,
2602
+ defineObjectApi__Prop
2603
+ );
2509
2604
  function ifArray(val, isAnArray, isNotAnArray) {
2510
2605
  return Array.isArray(val) ? isAnArray(val) : isNotAnArray(val);
2511
2606
  }
@@ -4473,6 +4568,31 @@ function keysOf(container) {
4473
4568
  const keys = Array.isArray(container) ? Object.keys(container).map((i) => Number(i)) : isObject(container) ? isRef(container) ? ["value"] : Object.keys(container) : [];
4474
4569
  return keys;
4475
4570
  }
4571
+ function callback() {
4572
+ return (cb) => {
4573
+ return (input) => cb(input);
4574
+ };
4575
+ }
4576
+ function narrowFn() {
4577
+ const fn2 = (obj) => obj;
4578
+ return fn2;
4579
+ }
4580
+ function narrowObjectTo(_defn) {
4581
+ return createFnWithPropsExplicit(
4582
+ narrowFn(),
4583
+ {
4584
+ asCallback: callback()
4585
+ }
4586
+ );
4587
+ }
4588
+ function narrowObjectToType() {
4589
+ return createFnWithPropsExplicit(
4590
+ narrowFn(),
4591
+ {
4592
+ asCallback: callback()
4593
+ }
4594
+ );
4595
+ }
4476
4596
  function omit(obj, ...removeKeys) {
4477
4597
  const keys = Object.keys(obj);
4478
4598
  return keys.reduce(
@@ -4559,75 +4679,27 @@ function fnMeta(func) {
4559
4679
  };
4560
4680
  }
4561
4681
  var wrapFn = "NOT IMPLEMENTED";
4562
- function addPropsToFn(fn2, clone_fn) {
4563
- const localFn = clone_fn ? (...args) => fn2(args) : fn2;
4564
- return (obj) => {
4565
- for (const k in obj) {
4566
- localFn[k] = obj[k];
4567
- }
4568
- return localFn;
4569
- };
4570
- }
4571
- function addFnToProps(props, _clone_fn) {
4572
- return (fn2) => {
4573
- const localFn = (...args) => fn2(args);
4574
- for (const k in props) {
4575
- localFn[k] = props[k];
4576
- }
4577
- return localFn;
4578
- };
4579
- }
4580
- function createCssSelector(_opt) {
4581
- return (...selectors) => {
4582
- return selectors.join(" ");
4583
- };
4584
- }
4585
- function createFnWithProps(fn2, props, narrowing = false) {
4586
- const fnWithProps = fn2;
4587
- for (const prop of Object.keys(props)) {
4588
- fnWithProps[prop] = props[prop];
4589
- }
4590
- return isTrue(narrowing) ? fnWithProps : fnWithProps;
4591
- }
4592
- function createFnWithPropsExplicit(fn2, props) {
4593
- const fnWithProps = fn2;
4594
- for (const prop of Object.keys(props)) {
4595
- fnWithProps[prop] = props[prop];
4596
- }
4597
- return fnWithProps;
4598
- }
4599
- function defineObj(literal2 = {}) {
4600
- return (wide22 = {}) => {
4601
- const obj = literal2 ? { ...literal2, ...wide22 } : wide22;
4602
- return obj;
4603
- };
4604
- }
4605
- function defineTuple(...values) {
4606
- return values.map(
4607
- (i) => isFunction(i) ? handleDoneFn(i(ShapeApiImplementation)) : i
4608
- );
4609
- }
4610
4682
  function asArray(thing) {
4611
4683
  return Array.isArray(thing) === true ? thing : typeof thing === "undefined" ? [] : [thing];
4612
4684
  }
4613
- function createConverter(mapper) {
4685
+ function createConverter(mapper2) {
4614
4686
  return (input) => {
4615
4687
  let result2;
4616
4688
  if (isNothing(input)) {
4617
- result2 = mapper.nothing ? mapper.nothing(input) : Never2;
4689
+ result2 = mapper2.nothing ? mapper2.nothing(input) : Never2;
4618
4690
  } else if (isObject(input)) {
4619
- result2 = mapper.object ? mapper.object(input) : Never2;
4691
+ result2 = mapper2.object ? mapper2.object(input) : Never2;
4620
4692
  } else {
4621
4693
  switch (typeof input) {
4622
4694
  case "string":
4623
- result2 = mapper.string ? mapper.string(input) : Never2;
4695
+ result2 = mapper2.string ? mapper2.string(input) : Never2;
4624
4696
  break;
4625
4697
  case "number":
4626
4698
  case "bigint":
4627
- result2 = mapper.number ? mapper.number(input) : Never2;
4699
+ result2 = mapper2.number ? mapper2.number(input) : Never2;
4628
4700
  break;
4629
4701
  case "boolean":
4630
- result2 = mapper.boolean ? mapper.boolean(input) : Never2;
4702
+ result2 = mapper2.boolean ? mapper2.boolean(input) : Never2;
4631
4703
  break;
4632
4704
  default:
4633
4705
  throw new Error(`Unhandled type: ${typeof input}`);
@@ -5147,6 +5219,37 @@ function lookupCountryCode(token) {
5147
5219
  const uc = uppercase(token);
5148
5220
  return isNumberLike(token) ? lookupNumericCode(token, "countryCode") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "countryCode") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "countryCode") : isIso3166CountryName(token) ? lookupName(token, "countryCode") : void 0;
5149
5221
  }
5222
+ function asMapper(fn2) {
5223
+ const props = {
5224
+ kind: "Mapper",
5225
+ map: (from) => {
5226
+ return from.map(fn2);
5227
+ }
5228
+ };
5229
+ return createFnWithPropsExplicit(fn2, props);
5230
+ }
5231
+ function createObjectMap() {
5232
+ return (map2) => {
5233
+ const fn2 = (input) => {
5234
+ return Object.keys(map2).reduce(
5235
+ (acc, key) => {
5236
+ const val = map2[key];
5237
+ return {
5238
+ ...acc,
5239
+ [key]: isFunction(val) ? val(input) : val
5240
+ };
5241
+ },
5242
+ {}
5243
+ );
5244
+ };
5245
+ return fn2;
5246
+ };
5247
+ }
5248
+ function createMapper() {
5249
+ return (fn2) => {
5250
+ return asMapper(fn2);
5251
+ };
5252
+ }
5150
5253
  function mergeObjects(defVal, override) {
5151
5254
  const intersectingKeys = sharedKeys(defVal, override);
5152
5255
  const defUnique = withoutKeys(defVal, ...intersectingKeys);
@@ -5974,26 +6077,23 @@ function ifUppercaseChar(ch, callbackForMatch, callbackForNoMatch) {
5974
6077
  return LOWER_ALPHA_CHARS2.includes(ch) ? callbackForMatch(ch) : callbackForNoMatch(ch);
5975
6078
  }
5976
6079
  function parseTemplate(template) {
5977
- const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:as\s+(string|number|boolean)\s*)?\}\}/g;
6080
+ const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:(?:extends|as)\s+(string|number|boolean)\s*)?\}\}/g;
5978
6081
  let lastIndex = 0;
5979
6082
  let match;
5980
6083
  const segments = [];
5981
- do {
5982
- match = pattern.exec(template);
5983
- if (match) {
5984
- const [fullMatch, varName, asType2] = match;
5985
- const staticPart = template.slice(lastIndex, match.index);
5986
- if (staticPart) {
5987
- segments.push({ dynamic: false, text: staticPart });
5988
- }
5989
- segments.push({
5990
- dynamic: true,
5991
- varName,
5992
- type: asType2 ? asType2 : "string"
5993
- });
5994
- lastIndex = match.index + fullMatch.length;
6084
+ while (match = pattern.exec(template)) {
6085
+ const [fullMatch, varName, asType2] = match;
6086
+ const staticPart = template.slice(lastIndex, match.index);
6087
+ if (staticPart) {
6088
+ segments.push({ dynamic: false, text: staticPart });
5995
6089
  }
5996
- } while (match);
6090
+ segments.push({
6091
+ dynamic: true,
6092
+ varName,
6093
+ type: asType2 ? asType2 : "string"
6094
+ });
6095
+ lastIndex = match.index + fullMatch.length;
6096
+ }
5997
6097
  const remainder = template.slice(lastIndex);
5998
6098
  if (remainder) {
5999
6099
  segments.push({ dynamic: false, text: remainder });
@@ -6011,19 +6111,19 @@ function buildRegexPattern(segments) {
6011
6111
  } else {
6012
6112
  switch (seg.type) {
6013
6113
  case "string":
6014
- regexStr += `(?<${seg.varName}>.*?)`;
6114
+ regexStr += "(.*?)";
6015
6115
  break;
6016
6116
  case "number":
6017
- regexStr += `(?<${seg.varName}>\\d+)`;
6117
+ regexStr += "(\\d+)";
6018
6118
  break;
6019
6119
  case "boolean":
6020
- regexStr += `(?<${seg.varName}>(?:true|false))`;
6120
+ regexStr += "(true|false)";
6021
6121
  break;
6022
6122
  }
6023
6123
  }
6024
6124
  }
6025
6125
  regexStr += "$";
6026
- return new RegExp(regexStr, "s");
6126
+ return new RegExp(regexStr);
6027
6127
  }
6028
6128
  function convertValue(type, value) {
6029
6129
  switch (type) {
@@ -6035,19 +6135,20 @@ function convertValue(type, value) {
6035
6135
  return value === "true";
6036
6136
  }
6037
6137
  }
6038
- function matchTemplate(inference, test) {
6039
- const segments = parseTemplate(inference);
6138
+ function matchTemplate(template, test) {
6139
+ const segments = parseTemplate(template);
6040
6140
  const regex = buildRegexPattern(segments);
6041
- const match = test.match(regex);
6141
+ const match = regex.exec(test);
6042
6142
  if (!match)
6043
6143
  return false;
6144
+ let captureIndex = 1;
6044
6145
  const result2 = {};
6045
6146
  for (const seg of segments) {
6046
6147
  if (seg.dynamic) {
6047
- const rawVal = match.groups?.[seg.varName];
6148
+ const rawVal = match[captureIndex++];
6048
6149
  if (rawVal === void 0)
6049
6150
  return false;
6050
- result2[seg.varName.toLowerCase()] = convertValue(seg.type, rawVal);
6151
+ result2[seg.varName] = convertValue(seg.type, rawVal);
6051
6152
  }
6052
6153
  }
6053
6154
  return result2;
@@ -7194,12 +7295,15 @@ export {
7194
7295
  createFnWithProps,
7195
7296
  createFnWithPropsExplicit,
7196
7297
  createLifoQueue,
7298
+ createMapper,
7299
+ createObjectMap,
7197
7300
  createTypeToken,
7198
7301
  cssColor,
7199
7302
  csv,
7200
7303
  defineCss,
7201
7304
  defineObj,
7202
7305
  defineObject,
7306
+ defineObjectApi,
7203
7307
  defineTuple,
7204
7308
  endsWith,
7205
7309
  ensureLeading,
@@ -7518,7 +7622,10 @@ export {
7518
7622
  mergeTuples,
7519
7623
  nameLiteral,
7520
7624
  narrow,
7625
+ narrowObjectTo,
7626
+ narrowObjectToType,
7521
7627
  never,
7628
+ objectToApi,
7522
7629
  omit,
7523
7630
  optional,
7524
7631
  optionalOrNull,