inferred-types 0.50.11 → 0.50.13

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 (74) hide show
  1. package/dist/constants/TypeTokens.d.ts +1 -0
  2. package/dist/constants/TypeTokens.d.ts.map +1 -1
  3. package/dist/constants/TypeTokens.js +6 -0
  4. package/dist/constants/tsconfig.tsbuildinfo +1 -1
  5. package/dist/index.cjs +133 -14
  6. package/dist/index.js +120 -13
  7. package/dist/inferred-types/tsconfig.tsbuildinfo +1 -1
  8. package/dist/runtime/literals/identity.d.ts +2 -1
  9. package/dist/runtime/literals/identity.d.ts.map +1 -1
  10. package/dist/runtime/literals/identity.js +5 -1
  11. package/dist/runtime/literals/stripChars.js +1 -1
  12. package/dist/runtime/literals/stripSurround.d.ts +2 -2
  13. package/dist/runtime/literals/stripSurround.d.ts.map +1 -1
  14. package/dist/runtime/literals/stripSurround.js +1 -1
  15. package/dist/runtime/runtime-types/asDefineObject.d.ts +4 -0
  16. package/dist/runtime/runtime-types/asDefineObject.d.ts.map +1 -0
  17. package/dist/runtime/runtime-types/asDefineObject.js +20 -0
  18. package/dist/runtime/runtime-types/asToken.d.ts +2 -3
  19. package/dist/runtime/runtime-types/asToken.d.ts.map +1 -1
  20. package/dist/runtime/runtime-types/asToken.js +18 -14
  21. package/dist/runtime/runtime-types/asType.d.ts +11 -2
  22. package/dist/runtime/runtime-types/asType.d.ts.map +1 -1
  23. package/dist/runtime/runtime-types/asType.js +22 -2
  24. package/dist/runtime/runtime-types/shape-helpers/singletons.d.ts.map +1 -1
  25. package/dist/runtime/runtime-types/shape-helpers/singletons.js +2 -0
  26. package/dist/runtime/runtime-types/tokens/createTypeToken.d.ts +1 -1
  27. package/dist/runtime/runtime-types/tokens/createTypeToken.d.ts.map +1 -1
  28. package/dist/runtime/runtime-types/tokens/createTypeToken.js +2 -2
  29. package/dist/runtime/tsconfig.tsbuildinfo +1 -1
  30. package/dist/runtime/type-guards/geo/index.d.ts +4 -0
  31. package/dist/runtime/type-guards/geo/index.d.ts.map +1 -0
  32. package/dist/runtime/type-guards/geo/index.js +3 -0
  33. package/dist/runtime/type-guards/geo/isIso3166Alpha2.d.ts +46 -0
  34. package/dist/runtime/type-guards/geo/isIso3166Alpha2.d.ts.map +1 -0
  35. package/dist/runtime/type-guards/{countries → geo}/isIso3166Alpha2.js +36 -0
  36. package/dist/runtime/type-guards/geo/isUsState.d.ts +4 -0
  37. package/dist/runtime/type-guards/geo/isUsState.d.ts.map +1 -0
  38. package/dist/runtime/type-guards/geo/isUsState.js +10 -0
  39. package/dist/runtime/type-guards/geo/isZipCode.d.ts +23 -0
  40. package/dist/runtime/type-guards/geo/isZipCode.d.ts.map +1 -0
  41. package/dist/runtime/type-guards/geo/isZipCode.js +40 -0
  42. package/dist/runtime/type-guards/index.d.ts +1 -1
  43. package/dist/runtime/type-guards/index.d.ts.map +1 -1
  44. package/dist/runtime/type-guards/index.js +1 -1
  45. package/dist/runtime/type-guards/retail.d.ts +6 -1
  46. package/dist/runtime/type-guards/retail.d.ts.map +1 -1
  47. package/dist/runtime/type-guards/retail.js +7 -0
  48. package/dist/runtime/type-guards/tokens/index.d.ts +2 -0
  49. package/dist/runtime/type-guards/tokens/index.d.ts.map +1 -1
  50. package/dist/runtime/type-guards/tokens/index.js +2 -0
  51. package/dist/runtime/type-guards/tokens/isDefineObject.d.ts +6 -0
  52. package/dist/runtime/type-guards/tokens/isDefineObject.d.ts.map +1 -0
  53. package/dist/runtime/type-guards/tokens/isDefineObject.js +12 -0
  54. package/dist/runtime/type-guards/tokens/isShapeCallback.d.ts +6 -0
  55. package/dist/runtime/type-guards/tokens/isShapeCallback.d.ts.map +1 -0
  56. package/dist/runtime/type-guards/tokens/isShapeCallback.js +7 -0
  57. package/dist/runtime/type-guards/tokens/isSimpleToken.d.ts.map +1 -1
  58. package/dist/types/literals/FromDefn.d.ts +1 -1
  59. package/dist/types/literals/FromDefn.d.ts.map +1 -1
  60. package/dist/types/runtime-types/Shape.d.ts +20 -4
  61. package/dist/types/runtime-types/Shape.d.ts.map +1 -1
  62. package/dist/types/runtime-types/TypeToken.d.ts +2 -7
  63. package/dist/types/runtime-types/TypeToken.d.ts.map +1 -1
  64. package/dist/types/string-literals/character-sets/retail-urls.d.ts +4 -0
  65. package/dist/types/string-literals/character-sets/retail-urls.d.ts.map +1 -1
  66. package/dist/types/string-literals/geo/zip.d.ts +3 -3
  67. package/dist/types/string-literals/geo/zip.d.ts.map +1 -1
  68. package/dist/types/tsconfig.tsbuildinfo +1 -1
  69. package/package.json +1 -1
  70. package/dist/runtime/type-guards/countries/index.d.ts +0 -2
  71. package/dist/runtime/type-guards/countries/index.d.ts.map +0 -1
  72. package/dist/runtime/type-guards/countries/index.js +0 -1
  73. package/dist/runtime/type-guards/countries/isIso3166Alpha2.d.ts +0 -21
  74. package/dist/runtime/type-guards/countries/isIso3166Alpha2.d.ts.map +0 -1
@@ -1,6 +1,7 @@
1
+ import { Narrowable } from "src/types/literals";
1
2
  /**
2
3
  * An identity function for any type, with the goal of preserving literal type information
3
4
  * where ever possible.
4
5
  */
5
- export declare const identity: <T>(v: T) => T;
6
+ export declare const identity: <N extends Narrowable, K extends PropertyKey, T extends readonly (Record<K, N> | N)[]>(...values: T) => T["length"] extends 1 ? T[0] : T["length"] extends 0 ? undefined : T;
6
7
  //# sourceMappingURL=identity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../src/runtime/literals/identity.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,QAAQ,GACnB,CAAC,KAEE,CAAC,MACA,CAAC"}
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../src/runtime/literals/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD;;;GAGG;AACH,eAAO,MAAM,QAAQ,GACrB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,aACzB,CAAC,KAMR,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,GACvB,CAAC,CAAC,CAAC,CAAC,GACJ,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,GACnB,SAAS,GACT,CAAC,CAAC"}
@@ -2,4 +2,8 @@
2
2
  * An identity function for any type, with the goal of preserving literal type information
3
3
  * where ever possible.
4
4
  */
5
- export const identity = (v) => v;
5
+ export const identity = (...values) => (values.length === 1
6
+ ? values[0]
7
+ : values.length === 0
8
+ ? undefined
9
+ : values);
@@ -1,4 +1,4 @@
1
- import { asChars } from "../type-conversion/asChars";
1
+ import { asChars } from "src/runtime/index";
2
2
  /**
3
3
  * **stripChars**`(content, ...strip)`
4
4
  *
@@ -1,5 +1,5 @@
1
- import { StripSurround, TupleToUnion } from "src/types/index";
2
- export type StripSurroundConfigured<TStrip extends readonly (string | number)[]> = <TInput extends string | number>(input: TInput) => StripSurround<TInput, TupleToUnion<TStrip>>;
1
+ import { StripSurround } from "src/types/index";
2
+ export type StripSurroundConfigured<TStrip extends readonly (string | number)[]> = <TInput extends string | number>(input: TInput) => StripSurround<TInput, TStrip[number]>;
3
3
  /**
4
4
  * **stripSurround**`(chars) => (input) => _stripped_`
5
5
  *
@@ -1 +1 @@
1
- {"version":3,"file":"stripSurround.d.ts","sourceRoot":"","sources":["../../../src/runtime/literals/stripSurround.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,YAAY,EACb,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,uBAAuB,CACjC,MAAM,SAAS,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,IACzC,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,aAAa,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;AAGnG;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,SAAS,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,YAEjC,MAAM,KACf,uBAAuB,CAAC,MAAM,CAmBhC,CAAA"}
1
+ {"version":3,"file":"stripSurround.d.ts","sourceRoot":"","sources":["../../../src/runtime/literals/stripSurround.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACd,MAAM,iBAAiB,CAAC;AAGzB,MAAM,MAAM,uBAAuB,CACjC,MAAM,SAAS,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,IACzC,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,aAAa,CAClE,MAAM,EACN,MAAM,CAAC,MAAM,CAAC,CACf,CAAC;AAGF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,SAAS,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,YAEjC,MAAM,KACf,uBAAuB,CAAC,MAAM,CAmBhC,CAAA"}
@@ -1,4 +1,4 @@
1
- import { isNumber, } from "src/runtime/index";
1
+ import { isNumber } from "../type-guards/isNumber";
2
2
  /**
3
3
  * **stripSurround**`(chars) => (input) => _stripped_`
4
4
  *
@@ -0,0 +1,4 @@
1
+ import { DefineObject } from "src/types/dictionary";
2
+ import { FromDefn } from "src/types/literals";
3
+ export declare const asDefineObject: <T extends DefineObject>(defn: T) => FromDefn<T>;
4
+ //# sourceMappingURL=asDefineObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asDefineObject.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime-types/asDefineObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAS9C,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,YAAY,QAAQ,CAAC,KAiB3C,QAAQ,CAAC,CAAC,CAC5B,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { isDoneFn, isFunction, isSimpleToken } from "../type-guards";
2
+ import { asType } from "./asType";
3
+ import { ShapeApiImplementation } from "./shape";
4
+ import { handleDoneFn } from "../api/handleDoneFn";
5
+ import { Never } from "src/constants/Never";
6
+ export const asDefineObject = (defn) => {
7
+ const result = Object.keys(defn).reduce((acc, i) => isSimpleToken(defn[i])
8
+ ? { ...acc, [i]: asType(defn[i]) }
9
+ : isDoneFn(defn[i])
10
+ ? { ...acc,
11
+ [i]: handleDoneFn(defn[i](ShapeApiImplementation))
12
+ }
13
+ : isFunction(defn[i])
14
+ ? {
15
+ ...acc,
16
+ [i]: handleDoneFn(defn[i](ShapeApiImplementation))
17
+ }
18
+ : Never, {});
19
+ return result;
20
+ };
@@ -1,5 +1,4 @@
1
- import { Narrowable, SimpleContainerToken, SimpleScalarToken, SimpleType, SimpleUnionToken } from "src/types/index";
2
- export declare const asSimpleToken: <T extends Narrowable>(_val: T) => string;
1
+ import { SimpleContainerToken, SimpleScalarToken, SimpleType, SimpleUnionToken, TypeToken } from "src/types/index";
3
2
  /**
4
3
  * **simpleScalarTokenToTypeToken**`(val)`
5
4
  *
@@ -31,5 +30,5 @@ export declare const simpleUnionTokenToTypeToken: <T extends SimpleUnionToken>(v
31
30
  * **Related:** `simpleScalarTokenToTypeToken`, `asTypeToken`
32
31
  */
33
32
  export declare const simpleContainerTokenToTypeToken: <T extends SimpleContainerToken>(_val: T) => void;
34
- export declare const asTypeToken: <T extends Narrowable>(_val: T) => string;
33
+ export declare const asTypeToken: <T extends TypeToken>(_val: T) => string;
35
34
  //# sourceMappingURL=asToken.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"asToken.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime-types/asToken.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AAczB,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,UAAU,QAAQ,CAAC,WAE1D,CAAA;AAoCD;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,SAAS,iBAAiB,OAAO,CAAC,KAazE,UAAU,CAAC,CAAC,CAClB,CAAA;AA6BD;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS,gBAAgB,OAAO,CAAC,KAKvE,UAAU,CAAC,CAAC,CAClB,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,+BAA+B,GAAI,CAAC,SAAS,oBAAoB,QAAQ,CAAC,SAEtF,CAAA;AAID,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,UAAU,QAAQ,CAAC,WAExD,CAAA"}
1
+ {"version":3,"file":"asToken.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime-types/asToken.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EAChB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAyDzB;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,SAAS,iBAAiB,OAAO,CAAC,KAezE,UAAU,CAAC,CAAC,CAClB,CAAA;AA6BD;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS,gBAAgB,OAAO,CAAC,KAKvE,UAAU,CAAC,CAAC,CAClB,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,+BAA+B,GAAI,CAAC,SAAS,oBAAoB,QAAQ,CAAC,SAEtF,CAAA;AAID,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,SAAS,QAAQ,CAAC,WAEvD,CAAA"}
@@ -1,10 +1,6 @@
1
- import { isBooleanLike, isNumberLike, isSimpleContainerToken, isSimpleScalarToken, simpleScalarToken, stripAfter, stripBefore, stripSurround } from "src/runtime/index";
1
+ import { identity, isBooleanLike, isNumberLike, isSimpleContainerToken, isSimpleScalarToken, simpleScalarToken, stripAfter, stripBefore, stripLeading, stripSurround, stripTrailing } from "src/runtime/index";
2
2
  import { Never } from "src/constants/Never";
3
- // TODO
4
- export const asSimpleToken = (_val) => {
5
- return "not ready";
6
- };
7
- const scalarToToken = {
3
+ const scalarToToken = identity({
8
4
  string: "<<string>>",
9
5
  number: "<<number>>",
10
6
  boolean: "<<boolean>>",
@@ -15,25 +11,31 @@ const scalarToToken = {
15
11
  unknown: "<<unknown>>",
16
12
  any: "<<any>>",
17
13
  never: "<<never>>",
18
- };
14
+ });
19
15
  const _containerToToken = {
20
16
  "array(string)": "",
21
17
  "array(boolean)": "",
22
18
  "array(number)": "",
23
19
  "array(unknown)": "",
24
20
  };
25
- // const unionToToken : Record<string, unknown> = {
26
- // "Opt<string>": "<<union::[ <<string>>, <<undefined>> ]>>" as unknown ,
27
- // "Opt<number>": "<<union::[ <<number>>, <<undefined>> ]>>" as unknown,
28
- // "Opt<unknown>": "<<union::[ <<unknown>>, <<undefined>> ]>>" as unknown,
29
- // "Opt<boolean>": "<<union::[ <<boolean>>, <<undefined>> ]>>" as unknown,
30
- // } satisfies Record<SimpleUnionToken, unknown>
31
21
  const stringLiteral = (str) => {
32
22
  return stripAfter(stripBefore(str, "string("), ")");
33
23
  };
34
24
  const numericLiteral = (str) => {
35
25
  return stripAfter(stripBefore(str, "number("), ")");
36
26
  };
27
+ const handleOptional = (token) => {
28
+ const bare = stripTrailing(stripLeading(token, "Opt<"), ">");
29
+ return bare.startsWith("string")
30
+ ? `<<union::[ <<string>>, <<undefined>> ]>>`
31
+ : bare.startsWith("number")
32
+ ? `<<union::[ <<number>>, <<undefined>> ]>>`
33
+ : bare.startsWith("boolean")
34
+ ? `<<union::[ <<boolean>>, <<undefined>> ]>>`
35
+ : bare.startsWith("unknown")
36
+ ? `<<union::[ <<unknown>>, <<undefined>> ]>>`
37
+ : `<<never>>`;
38
+ };
37
39
  /**
38
40
  * **simpleScalarTokenToTypeToken**`(val)`
39
41
  *
@@ -54,7 +56,9 @@ export const simpleScalarTokenToTypeToken = (val) => {
54
56
  ? numericLiteral(val).includes(",")
55
57
  ? `<<union::[ ${numericLiteral(val).split(/,\s{0,1}/).join(", ")} ]>>`
56
58
  : `<<number::${numericLiteral(val)}>>`
57
- : `<<never>>`);
59
+ : val.startsWith("Opt<")
60
+ ? handleOptional(val)
61
+ : `<<never>>`);
58
62
  };
59
63
  /**
60
64
  * converts a node in the union to a proper token or tokens
@@ -1,9 +1,18 @@
1
- import { SimpleScalarToken, SimpleToken, SimpleType } from "src/types/runtime-types";
1
+ import { DefineObject } from "src/types/dictionary";
2
+ import { FromDefn } from "src/types/literals";
3
+ import { ShapeCallback, SimpleScalarToken, SimpleToken, SimpleType } from "src/types/runtime-types";
2
4
  /**
3
5
  * **asType**(token)**
4
6
  *
5
7
  * Converts a `SimpleToken` into it's corresponding _type_.
8
+ *
9
+ * - also allows a `ShapeCallback` for more advanced types
10
+ * - this includes `DefineObject` key-values
11
+ * - also allows tuple generation
12
+ * - note: that tokens generated with the callback approach
13
+ * is not fully reverse engineerable at this point; this will
14
+ * be added later
6
15
  */
7
- export declare const asType: <T extends SimpleToken>(token: T) => SimpleType<T>;
16
+ export declare const asType: <T extends [SimpleToken | DefineObject] | readonly (SimpleToken | DefineObject | ShapeCallback)[]>(...token: T) => T extends [SimpleToken] ? SimpleType<T[0]> : T extends [DefineObject] ? FromDefn<T[0]> : T extends readonly (SimpleToken | DefineObject | ShapeCallback)[] ? FromDefn<T> : never;
8
17
  export declare const asStringLiteral: <T extends readonly SimpleScalarToken[]>(...values: T) => any[];
9
18
  //# sourceMappingURL=asType.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"asType.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime-types/asType.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,WAAW,EACX,UAAU,EACX,MAAM,yBAAyB,CAAC;AAEjC;;;;GAIG;AACH,eAAO,MAAM,MAAM,GACjB,CAAC,SAAS,WAAW,SACd,CAAC,KAIQ,UAAU,CAAC,CAAC,CAC7B,CAAA;AAED,eAAO,MAAM,eAAe,GAC1B,CAAC,SAAS,SAAS,iBAAiB,EAAE,aAC3B,CAAC,UAGb,CAAA"}
1
+ {"version":3,"file":"asType.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime-types/asType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAEL,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,UAAU,EACX,MAAM,yBAAyB,CAAC;AAOjC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,MAAM,GACjB,CAAC,SAAS,CAAC,WAAW,GAAG,YAAY,CAAE,GAAG,SAAS,CAAC,WAAW,GAAG,YAAY,GAAG,aAAa,CAAC,EAAE,YACvF,CAAC,KAYK,CAAC,SAAS,CAAC,WAAW,CAAC,GAClC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACjB,CAAC,SAAS,CAAC,YAAY,CAAC,GACtB,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACd,CAAC,SAAS,SAAS,CAAC,WAAW,GAAG,YAAY,GAAG,aAAa,CAAC,EAAE,GACjE,QAAQ,CAAC,CAAC,CAAC,GACX,KACP,CAAA;AAED,eAAO,MAAM,eAAe,GAC1B,CAAC,SAAS,SAAS,iBAAiB,EAAE,aAC3B,CAAC,UAGb,CAAA"}
@@ -1,10 +1,30 @@
1
+ import { isFunction } from "../type-guards/isFunction";
2
+ import { ShapeApiImplementation } from "./shape";
3
+ import { handleDoneFn } from "../api";
4
+ import { isDefineObject } from "../type-guards";
5
+ import { asDefineObject } from "./asDefineObject";
1
6
  /**
2
7
  * **asType**(token)**
3
8
  *
4
9
  * Converts a `SimpleToken` into it's corresponding _type_.
10
+ *
11
+ * - also allows a `ShapeCallback` for more advanced types
12
+ * - this includes `DefineObject` key-values
13
+ * - also allows tuple generation
14
+ * - note: that tokens generated with the callback approach
15
+ * is not fully reverse engineerable at this point; this will
16
+ * be added later
5
17
  */
6
- export const asType = (token) => {
7
- return (token);
18
+ export const asType = (...token) => {
19
+ return (isFunction(token)
20
+ ? token(ShapeApiImplementation)
21
+ : token.length === 1
22
+ ? isFunction(token[0])
23
+ ? handleDoneFn(token[0](ShapeApiImplementation))
24
+ : isDefineObject(token[0])
25
+ ? asDefineObject(token[0])
26
+ : token[0]
27
+ : token.map(i => isFunction(i) ? handleDoneFn(i(ShapeApiImplementation)) : i));
8
28
  };
9
29
  export const asStringLiteral = (...values) => {
10
30
  return values.map(i => i);
@@ -1 +1 @@
1
- {"version":3,"file":"singletons.d.ts","sourceRoot":"","sources":["../../../../src/runtime/runtime-types/shape-helpers/singletons.ts"],"names":[],"mappings":"AAAC,OAAO,EAMN,oBAAoB,EAGpB,YAAY,EAMb,MAAM,iBAAiB,CAAC;AA8EzB;;;;GAIG;AACH,eAAO,MAAM,MAAM,GApEjB,CAAC,oJAoEoD,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,MAAM,GA3EjB,CAAC,8HA2EyC,CAAC"}
1
+ {"version":3,"file":"singletons.d.ts","sourceRoot":"","sources":["../../../../src/runtime/runtime-types/shape-helpers/singletons.ts"],"names":[],"mappings":"AAAC,OAAO,EAMN,oBAAoB,EAGpB,YAAY,EAMb,MAAM,iBAAiB,CAAC;AAgFzB;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAtEjB,CAAC,oJAsEoD,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,MAAM,GA7EjB,CAAC,8HA6EyC,CAAC"}
@@ -15,6 +15,8 @@ const addSingleton = (token, api) => (...literals) => {
15
15
  .join(",")));
16
16
  };
17
17
  const stringApi = ({
18
+ startsWith: (startsWith) => addToken(`string-set`, `startsWith::${startsWith}`),
19
+ endsWith: (endsWith) => addToken(`string-set`, `endsWith::${endsWith}`),
18
20
  zip: () => addToken("string-set", "Zip5"),
19
21
  zipPlus4: () => addToken("string-set", "Zip5_4"),
20
22
  zipCode: () => addToken("string-set", "ZipCode"),
@@ -25,6 +25,6 @@ export type SingletonClosure<T extends "string" | "number"> = <TLit extends read
25
25
  * A higher order function designed to creating a valid
26
26
  * `TypeToken` simple through a compound process.
27
27
  */
28
- export declare const createTypeToken: <TBase extends TypeTokenAtomics>(base: TBase) => BaseReturn<TBase>;
28
+ export declare const createTypeToken: <TBase extends TypeTokenAtomics | TypeTokenSingletons>(base: TBase) => BaseReturn<TBase>;
29
29
  export {};
30
30
  //# sourceMappingURL=createTypeToken.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createTypeToken.d.ts","sourceRoot":"","sources":["../../../../src/runtime/runtime-types/tokens/createTypeToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,EAAE,EACF,QAAQ,EACR,IAAI,EACJ,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EAEpB,MAAM,iBAAiB,CAAC;AAOzB,KAAK,UAAU,CAAC,KAAK,SAAS,aAAa,IAAI,KAAK,SAAS,gBAAgB,GACzE,KAAK,KAAK,IAAI,GACd,KAAK,SAAS,mBAAmB,GACjC,gBAAgB,CAAC,KAAK,CAAC,GACvB,OAAO,CAAC;AAGZ,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAAE,GAAG,QAAQ,EAAE,CAAC,KACtE,WAAW,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC;AAE9B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,IACxD,CAAC,IAAI,SAAS,SAAS,UAAU,CAAC,CAAC,CAAC,EAAE,EACpC,GAAG,QAAQ,EAAE,IAAI,KAChB,EAAE,CACL,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EACjB,KAAK,CAAC,IAAI,EACV,EAAE,CACA,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EACjB,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,EACtB,KAAK,CAAC,MAAM,CACb,CACF,CAAC;AAuCF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK,SAAS,gBAAgB,QACxB,KAAK,KAAG,UAAU,CAAC,KAAK,CAQ/B,CAAA"}
1
+ {"version":3,"file":"createTypeToken.d.ts","sourceRoot":"","sources":["../../../../src/runtime/runtime-types/tokens/createTypeToken.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EACF,QAAQ,EACR,IAAI,EACJ,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EAEpB,MAAM,iBAAiB,CAAC;AAOzB,KAAK,UAAU,CACb,KAAK,SAAS,aAAa,IACvB,KAAK,SAAS,gBAAgB,GAChC,KAAK,KAAK,IAAI,GACd,KAAK,SAAS,mBAAmB,GACjC,gBAAgB,CAAC,KAAK,CAAC,GACvB,OAAO,CAAC;AAGZ,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAAE,GAAG,QAAQ,EAAE,CAAC,KACtE,WAAW,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC;AAE9B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,IACxD,CAAC,IAAI,SAAS,SAAS,UAAU,CAAC,CAAC,CAAC,EAAE,EACpC,GAAG,QAAQ,EAAE,IAAI,KAChB,EAAE,CACL,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EACjB,KAAK,CAAC,IAAI,EACV,EAAE,CACA,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EACjB,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,EACtB,KAAK,CAAC,MAAM,CACb,CACF,CAAC;AAwCF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK,SAAS,gBAAgB,GAAG,mBAAmB,QAC9C,KAAK,KAAG,UAAU,CAAC,KAAK,CAQ/B,CAAA"}
@@ -2,7 +2,7 @@ import { isAtomicToken, isSingletonToken, jsonValues } from "src/runtime/index";
2
2
  const unionToken = (...els) => {
3
3
  return `<<union::[${jsonValues(els)}]>>`;
4
4
  };
5
- const singleton = (base) => {
5
+ const singletonApi = (base) => {
6
6
  const handler = (...lits) => {
7
7
  return (lits.length === 0
8
8
  ? base === "string" ? `<<string>>` : `<<number>>`
@@ -24,6 +24,6 @@ export const createTypeToken = (base) => {
24
24
  return (isAtomicToken(base)
25
25
  ? `<<${base}>>`
26
26
  : isSingletonToken(base)
27
- ? singleton(base)
27
+ ? singletonApi(base)
28
28
  : "");
29
29
  };