@percepta/utils 0.1.7 → 0.1.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.
Files changed (35) hide show
  1. package/dist/cjs/config/getEnvConfig.d.ts +26 -26
  2. package/dist/cjs/config/getEnvConfig.d.ts.map +1 -1
  3. package/dist/cjs/config/getEnvConfig.js +5 -1
  4. package/dist/cjs/config/getEnvConfig.js.map +1 -1
  5. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  6. package/dist/cjs/utils/index.d.ts +2 -0
  7. package/dist/cjs/utils/index.d.ts.map +1 -1
  8. package/dist/cjs/utils/index.js +2 -0
  9. package/dist/cjs/utils/index.js.map +1 -1
  10. package/dist/cjs/utils/replaceAt.d.ts +10 -0
  11. package/dist/cjs/utils/replaceAt.d.ts.map +1 -0
  12. package/dist/cjs/utils/replaceAt.js +17 -0
  13. package/dist/cjs/utils/replaceAt.js.map +1 -0
  14. package/dist/cjs/utils/zodKeyedTypeUnion.d.ts +17 -0
  15. package/dist/cjs/utils/zodKeyedTypeUnion.d.ts.map +1 -0
  16. package/dist/cjs/utils/zodKeyedTypeUnion.js +15 -0
  17. package/dist/cjs/utils/zodKeyedTypeUnion.js.map +1 -0
  18. package/dist/esnext/config/getEnvConfig.d.ts +26 -26
  19. package/dist/esnext/config/getEnvConfig.d.ts.map +1 -1
  20. package/dist/esnext/config/getEnvConfig.js +5 -1
  21. package/dist/esnext/config/getEnvConfig.js.map +1 -1
  22. package/dist/esnext/tsconfig.tsbuildinfo +1 -1
  23. package/dist/esnext/utils/index.d.ts +2 -0
  24. package/dist/esnext/utils/index.d.ts.map +1 -1
  25. package/dist/esnext/utils/index.js +2 -0
  26. package/dist/esnext/utils/index.js.map +1 -1
  27. package/dist/esnext/utils/replaceAt.d.ts +10 -0
  28. package/dist/esnext/utils/replaceAt.d.ts.map +1 -0
  29. package/dist/esnext/utils/replaceAt.js +14 -0
  30. package/dist/esnext/utils/replaceAt.js.map +1 -0
  31. package/dist/esnext/utils/zodKeyedTypeUnion.d.ts +17 -0
  32. package/dist/esnext/utils/zodKeyedTypeUnion.d.ts.map +1 -0
  33. package/dist/esnext/utils/zodKeyedTypeUnion.js +12 -0
  34. package/dist/esnext/utils/zodKeyedTypeUnion.js.map +1 -0
  35. package/package.json +2 -1
@@ -1,4 +1,6 @@
1
1
  export * from "./assertNever";
2
2
  export * from "./logNever";
3
3
  export * from "./promiseAllValues";
4
+ export * from "./replaceAt";
5
+ export * from "./zodKeyedTypeUnion";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
@@ -1,4 +1,6 @@
1
1
  export * from "./assertNever";
2
2
  export * from "./logNever";
3
3
  export * from "./promiseAllValues";
4
+ export * from "./replaceAt";
5
+ export * from "./zodKeyedTypeUnion";
4
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns a new array with the element at the specified index replaced.
3
+ *
4
+ * @param array The source array
5
+ * @param index The index of the element to replace
6
+ * @param value The new value to insert at the index
7
+ * @returns A new array with the replacement applied
8
+ */
9
+ export declare function replaceAt<T>(array: T[], index: number, value: T): T[];
10
+ //# sourceMappingURL=replaceAt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceAt.d.ts","sourceRoot":"","sources":["../../../src/utils/replaceAt.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAIrE"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Returns a new array with the element at the specified index replaced.
3
+ *
4
+ * @param array The source array
5
+ * @param index The index of the element to replace
6
+ * @param value The new value to insert at the index
7
+ * @returns A new array with the replacement applied
8
+ */
9
+ export function replaceAt(array, index, value) {
10
+ const newArray = [...array];
11
+ newArray[index] = value;
12
+ return newArray;
13
+ }
14
+ //# sourceMappingURL=replaceAt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceAt.js","sourceRoot":"","sources":["../../../src/utils/replaceAt.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAI,KAAU,EAAE,KAAa,EAAE,KAAQ;IAC9D,MAAM,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;IACxB,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type KeyedTypeUnion, type ValueForTypeKey } from "keyed-type-union";
2
+ import { z } from "zod";
3
+ type SchemasByType<TTypeUnion extends KeyedTypeUnion<Record<string, unknown>, TTypeKey>, TTypeKey extends string = "type"> = {
4
+ [TType in TTypeUnion[TTypeKey]]: z.ZodType<ValueForTypeKey<TTypeUnion, TType, TTypeKey>>;
5
+ };
6
+ /**
7
+ * Creates a Zod schema for a discriminated union of type-union types.
8
+ * We can use this util alongside keyed-type-union for stricter type union patterns.
9
+ *
10
+ * @param schemasByType A record of type keys to their corresponding Zod schemas.
11
+ * @param typeKey The optional key used to discriminate between the different types in the union.
12
+ * @returns A Zod schema for the discriminated union.
13
+ */
14
+ export declare function zodKeyedTypeUnion<TTypeUnion extends KeyedTypeUnion<Record<string, unknown>>>(schemasByType: SchemasByType<TTypeUnion>): z.ZodType<TTypeUnion>;
15
+ export declare function zodKeyedTypeUnion<TTypeUnion extends KeyedTypeUnion<Record<string, unknown>, TTypeKey>, TTypeKey extends string>(schemasByType: SchemasByType<TTypeUnion, TTypeKey>, typeKey: TTypeKey): z.ZodType<TTypeUnion>;
16
+ export {};
17
+ //# sourceMappingURL=zodKeyedTypeUnion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zodKeyedTypeUnion.d.ts","sourceRoot":"","sources":["../../../src/utils/zodKeyedTypeUnion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,KAAK,aAAa,CAChB,UAAU,SAAS,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,EACpE,QAAQ,SAAS,MAAM,GAAG,MAAM,IAC9B;KACD,KAAK,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,CACxC,eAAe,CAAC,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,CAC7C;CACF,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,SAAS,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC1D,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACnE,wBAAgB,iBAAiB,CAC/B,UAAU,SAAS,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,EACpE,QAAQ,SAAS,MAAM,EAEvB,aAAa,EAAE,aAAa,CAAC,UAAU,EAAE,QAAQ,CAAC,EAClD,OAAO,EAAE,QAAQ,GAChB,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+ export function zodKeyedTypeUnion(schemasByType, typeKey = "type") {
3
+ /**
4
+ * There are a lot of casts here because of our fancy generics.
5
+ * We won't worry about them for now; we'll just use our tests to ensure runtime safety.
6
+ */
7
+ return z.discriminatedUnion(typeKey, Object.entries(schemasByType).map(([type, schema]) => z.object({
8
+ [typeKey]: z.literal(type),
9
+ [type]: schema,
10
+ })));
11
+ }
12
+ //# sourceMappingURL=zodKeyedTypeUnion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zodKeyedTypeUnion.js","sourceRoot":"","sources":["../../../src/utils/zodKeyedTypeUnion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA6BxB,MAAM,UAAU,iBAAiB,CAI/B,aAAkD,EAClD,UAAoB,MAAe;IAEnC;;;OAGG;IACH,OAAO,CAAC,CAAC,kBAAkB,CACzB,OAAO,EACP,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CACnD,CAAC,CAAC,MAAM,CAAC;QACP,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QAC1B,CAAC,IAAI,CAAC,EAAE,MAAe;KACxB,CAAC,CACM,CACF,CAAC;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percepta/utils",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,6 +14,7 @@
14
14
  "dist/**/*"
15
15
  ],
16
16
  "dependencies": {
17
+ "keyed-type-union": "^0.1.0",
17
18
  "lodash-es": "^4.17.21",
18
19
  "zod": "^4.0.0"
19
20
  },