@ddd-ts/freeze 0.0.0-improve-dx.1 → 0.0.0-improve-freeze-function-stability.1

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 (52) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_virtual/_rolldown/runtime.js +29 -0
  3. package/dist/{divergence.d.ts → divergence/divergence.d.ts} +53 -31
  4. package/dist/divergence/divergence.d.ts.map +1 -0
  5. package/dist/divergence/divergence.spec.d.ts +2 -0
  6. package/dist/divergence/divergence.spec.d.ts.map +1 -0
  7. package/dist/entrypoints/freeze-decorator.entrypoint.d.ts +2 -0
  8. package/dist/entrypoints/freeze-decorator.entrypoint.d.ts.map +1 -0
  9. package/dist/entrypoints/freeze-decorator.entrypoint.js +114 -0
  10. package/dist/entrypoints/freeze-decorator.entrypoint.mjs +113 -0
  11. package/dist/entrypoints/freeze-function.entrypoint.d.ts +2 -0
  12. package/dist/entrypoints/freeze-function.entrypoint.d.ts.map +1 -0
  13. package/dist/entrypoints/freeze-function.entrypoint.js +119 -0
  14. package/dist/entrypoints/freeze-function.entrypoint.mjs +117 -0
  15. package/dist/entrypoints/freeze.entrypoint.d.ts +4 -0
  16. package/dist/entrypoints/freeze.entrypoint.d.ts.map +1 -0
  17. package/dist/entrypoints/freeze.entrypoint.js +3 -0
  18. package/dist/entrypoints/freeze.entrypoint.mjs +5 -0
  19. package/dist/entrypoints/project.d.ts +3 -0
  20. package/dist/entrypoints/project.d.ts.map +1 -0
  21. package/dist/entrypoints/project.js +9 -0
  22. package/dist/entrypoints/project.mjs +8 -0
  23. package/dist/freeze.spec.d.ts +2 -0
  24. package/dist/freeze.spec.d.ts.map +1 -0
  25. package/dist/index.d.ts +4 -3
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +5 -2
  28. package/dist/index.mjs +4 -0
  29. package/dist/package.js +11 -0
  30. package/dist/package.mjs +5 -0
  31. package/dist/references/freeze.decorator.d.ts +8 -0
  32. package/dist/references/freeze.decorator.d.ts.map +1 -0
  33. package/dist/references/freeze.decorator.js +10 -0
  34. package/dist/references/freeze.decorator.mjs +9 -0
  35. package/dist/references/freeze.function.d.ts +10 -0
  36. package/dist/references/freeze.function.d.ts.map +1 -0
  37. package/dist/references/freeze.function.js +6 -0
  38. package/dist/references/freeze.function.mjs +5 -0
  39. package/dist/utils/explore-type.d.ts +3 -0
  40. package/dist/utils/explore-type.d.ts.map +1 -0
  41. package/dist/utils/explore-type.js +79 -0
  42. package/dist/utils/explore-type.mjs +77 -0
  43. package/dist/utils/get-pretty-type.d.ts +7 -0
  44. package/dist/utils/get-pretty-type.d.ts.map +1 -0
  45. package/dist/utils/get-pretty-type.js +31 -0
  46. package/dist/utils/get-pretty-type.mjs +30 -0
  47. package/package.json +48 -40
  48. package/dist/divergence.d.ts.map +0 -1
  49. package/dist/freeze.decorator.d.ts +0 -11
  50. package/dist/freeze.decorator.d.ts.map +0 -1
  51. package/dist/freeze.decorator.js +0 -10
  52. package/dist/freeze.decorator.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Aetherall
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,29 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -1,65 +1,87 @@
1
- //#region src/divergence.d.ts
2
- type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
3
- type PopUnion<U> = UnionToOvlds<U> extends ((a: infer A) => void) ? A : never;
4
- type UnionToArray<T, A extends unknown[] = []> = IsUnion<T> extends true ? UnionToArray<Exclude<T, PopUnion<T>>, [PopUnion<T>, ...A]> : [T, ...A];
1
+ export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
2
+ export type PopUnion<U> = UnionToOvlds<U> extends (a: infer A) => void ? A : never;
3
+ export type UnionToArray<T, A extends unknown[] = []> = IsUnion<T> extends true ? UnionToArray<Exclude<T, PopUnion<T>>, [PopUnion<T>, ...A]> : [T, ...A];
5
4
  type CountUnion<T> = UnionToArray<T> extends infer U extends any[] ? U["length"] : never;
6
5
  type UnshiftUnion<U> = UnionToArray<U> extends [infer F, ...any[]] ? F : never;
7
6
  type UnionToOvlds<U> = UnionToIntersection<U extends any ? (f: U) => void : never>;
8
7
  type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
9
8
  type IsStringLiteral<T> = T extends string ? string extends T ? false : true : false;
10
- type FindBestKeyForMatching<FromUnion, ToUnion> = UnshiftUnion<keyof FromUnion extends infer K ? K extends keyof FromUnion & keyof ToUnion ? CountUnion<Pick<FromUnion, K>[K]> extends CountUnion<FromUnion> ? [IsStringLiteral<FromUnion[K]>, IsStringLiteral<ToUnion[K]>] extends [true, true] ? K : never : never : never : never>;
11
- type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } & {} : never;
9
+ type FindBestKeyForMatching<FromUnion, ToUnion> = UnshiftUnion<keyof FromUnion extends infer K ? K extends keyof FromUnion & keyof ToUnion ? CountUnion<Pick<FromUnion, K>[K]> extends CountUnion<FromUnion> ? [IsStringLiteral<FromUnion[K]>, IsStringLiteral<ToUnion[K]>] extends [
10
+ true,
11
+ true
12
+ ] ? K : never : never : never : never>;
13
+ export type Expand<T> = T extends infer O ? {
14
+ [K in keyof O]: O[K];
15
+ } & {} : never;
12
16
  type Access<T, K> = K extends keyof T ? T[K] : never;
13
17
  type OnlyFromKeys<From, To> = Exclude<Exclude<keyof From, keyof To>, symbol>;
14
18
  type OnlyToKeys<From, To> = Exclude<Exclude<keyof To, keyof From>, symbol>;
15
- type OmitNever<T> = { [K in keyof T as T[K] extends never ? never : K]: T[K] } & {};
16
- type ObjectDivergence<From, To, Acc extends any[]> = OmitNever<{ [K in keyof From & keyof To]: Divergence<Access<From, K>, Access<To, K>, Acc> } & { [K in OnlyFromKeys<From, To> as `+${K}`]: From[K] } & { [K in OnlyToKeys<From, To> as `-${K}`]: To[K] }> extends infer Result ? {} extends Result ? never : Result : never;
17
- type IndexedTypeKey<From, To> = ({ [K in keyof From]: K } & { [K in keyof To]: K })[keyof From | keyof To];
19
+ type OmitNever<T> = {
20
+ [K in keyof T as T[K] extends never ? never : K]: T[K];
21
+ } & {};
22
+ type ObjectDivergence<From, To, Acc extends any[]> = OmitNever<{
23
+ [K in keyof From & keyof To]: Divergence<Access<From, K>, Access<To, K>, Acc>;
24
+ } & {
25
+ [K in OnlyFromKeys<From, To> as `+${K}`]: From[K];
26
+ } & {
27
+ [K in OnlyToKeys<From, To> as `-${K}`]: To[K];
28
+ }> extends infer Result ? {} extends Result ? never : Result : never;
29
+ type IndexedTypeKey<From, To> = ({
30
+ [K in keyof From]: K;
31
+ } & {
32
+ [K in keyof To]: K;
33
+ })[keyof From | keyof To];
18
34
  type IndexedTypeDiff<From, To, Acc extends any[]> = IndexedTypeKey<From, To> extends infer U extends keyof From & keyof To ? Divergence<From[U], To[U], Acc> : never;
19
35
  type IsIndexedType<T> = [T] extends [never] ? false : T extends object ? string extends keyof T ? true : number extends keyof T ? true : symbol extends keyof T ? true : false : false;
20
- type DiffBestMatchForObject<Item, Union, K, Acc extends any[]> = IsNever<K> extends false ? K extends keyof Union & keyof Item ? Extract<Union, { [P in K]: Item[P] }> extends infer BestMatch ? IsNever<BestMatch> extends false ? Divergence<Item, BestMatch, Acc> extends infer D ? IsNever<D> extends false ? Expand<{ [P in K]: Item[P] } & D> : never : never : never : never : never : never;
36
+ type DiffBestMatchForObject<Item, Union, K, Acc extends any[]> = IsNever<K> extends false ? K extends keyof Union & keyof Item ? Extract<Union, {
37
+ [P in K]: Item[P];
38
+ }> extends infer BestMatch ? IsNever<BestMatch> extends false ? Divergence<Item, BestMatch, Acc> extends infer D ? IsNever<D> extends false ? Expand<{
39
+ [P in K]: Item[P];
40
+ } & D> : never : never : never : never : never : never;
21
41
  type DiffBestMatch<Item, Union, BestKey, Acc extends any[]> = PopUnion<Item extends any[] ? ArrayDivergence<Item, Extract<Union, any[]>, Acc> : Item extends object ? DiffBestMatchForObject<Item, Extract<Union, object>, BestKey, Acc> : never>;
22
- type PerfectMatch<Item, Union, TotalUnion, Acc extends any[]> = Union extends [infer F, ...infer R] ? Divergence<Item, F, Acc> extends infer D ? IsNever<D> extends true ? F : PerfectMatch<Item, R, TotalUnion, Acc> : "!![PerfectMatch] Could not infer D" : never;
42
+ type PerfectMatch<Item, Union, TotalUnion, Acc extends any[]> = Union extends [
43
+ infer F,
44
+ ...infer R
45
+ ] ? Divergence<Item, F, Acc> extends infer D ? IsNever<D> extends true ? F : PerfectMatch<Item, R, TotalUnion, Acc> : "!![PerfectMatch] Could not infer D" : never;
23
46
  type GetChange<Item, Union, BestKey, Acc extends any[]> = PerfectMatch<Item, UnionToArray<Union>, BestKey, Acc> extends infer P ? IsNever<P> extends false ? never : DiffBestMatch<Item, Union, BestKey, Acc> extends infer D ? IsNever<D> extends false ? {
24
- "~": D;
47
+ "~": D;
25
48
  } : {
26
- "+": Item;
49
+ "+": Item;
27
50
  } : "!![GetChange] Could not infer D" : "!![GetChange] Could not infer P";
28
- type ArrayUnionDivergence<From, To, BestKey, Acc extends any[], Divergences extends {
29
- "~": unknown;
30
- "+": unknown;
51
+ export type ArrayUnionDivergence<From, To, BestKey, Acc extends any[], Divergences extends {
52
+ "~": unknown;
53
+ "+": unknown;
31
54
  } = {
32
- "~": never;
33
- "+": never;
55
+ "~": never;
56
+ "+": never;
34
57
  }> = From extends [infer F, ...infer Rest] ? GetChange<F, To, BestKey, Acc> extends infer Change ? IsNever<Change> extends true ? ArrayUnionDivergence<Rest, To, BestKey, Acc, Divergences> : Change extends {
35
- "+": infer A;
58
+ "+": infer A;
36
59
  } ? ArrayUnionDivergence<Rest, To, BestKey, Acc, {
37
- "~": Divergences["~"];
38
- "+": Divergences["+"] | A;
60
+ "~": Divergences["~"];
61
+ "+": Divergences["+"] | A;
39
62
  }> : Change extends {
40
- "~": infer C;
63
+ "~": infer C;
41
64
  } ? ArrayUnionDivergence<Rest, To, BestKey, Acc, {
42
- "~": Divergences["~"] | C;
43
- "+": Divergences["+"];
65
+ "~": Divergences["~"] | C;
66
+ "+": Divergences["+"];
44
67
  }> : never : ArrayUnionDivergence<Rest, To, BestKey, Acc, Divergences> : OmitNever<Divergences> extends infer Result ? {} extends Result ? never : Result : never;
45
- type UnionDivergence<From, To, Acc extends any[]> = ArrayUnionDivergence<UnionToArray<From>, To, FindBestKeyForMatching<Extract<To, object>, Extract<From, object>>, Acc>;
68
+ export type UnionDivergence<From, To, Acc extends any[]> = ArrayUnionDivergence<UnionToArray<From>, To, FindBestKeyForMatching<Extract<To, object>, Extract<From, object>>, Acc>;
46
69
  type IsAtLeastOneUnion<L, R> = IsUnion<L> extends true ? true : IsUnion<R> extends true ? true : false;
47
- type IsNever<T> = [T] extends [never] ? true : false;
70
+ export type IsNever<T> = [T] extends [never] ? true : false;
48
71
  type AtLeastOneEmptyObject<L, R> = {} extends Required<L> ? true : {} extends Required<R> ? true : false;
49
72
  type EmptyObjectDivergence<From, To> = [{}, {}] extends [From, To] ? never : [From, "!=", To];
50
73
  type SimpleDivergence<From, To> = From extends To ? never : [From, "!=", To];
51
74
  type AtLeastOneArray<From, To> = From extends Array<unknown> ? true : To extends Array<unknown> ? true : false;
52
75
  type ArrayDivergence<From, To, Acc extends any[]> = From extends Array<infer F> ? To extends Array<infer T> ? Divergence<F, T, Acc> extends infer D ? IsNever<D> extends true ? never : {
53
- [key: number]: D;
76
+ [key: number]: D;
54
77
  } : never : ["[]?", Divergence<F, To, Acc>] : To extends Array<infer T> ? ["[]!", Divergence<From, T, Acc>] : never;
55
78
  type Equals<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;
56
79
  type Has<Item, Array extends any[]> = Array extends [infer F, ...infer R] ? Equals<Item, F> extends true ? true : Has<Item, R> : false;
57
80
  type Primitive = string | number | boolean | null | undefined | Date;
58
81
  type AtLeastOnePrimitive<From, To> = From extends Primitive ? true : To extends Primitive ? true : false;
59
82
  type PrimitiveDivergence<From, To> = AtLeastOnePrimitive<From, To> extends true ? SimpleDivergence<From, To> : never;
60
- type Divergence<From, To, Acc extends any[] = []> = Equals<From, To> extends true ? never : Acc["length"] extends 20 ? {
61
- error: "Max depth reached";
83
+ export type Divergence<From, To, Acc extends any[] = []> = Equals<From, To> extends true ? never : Acc["length"] extends 20 ? {
84
+ error: "Max depth reached";
62
85
  } : Has<From, [To, ...Acc]> extends true ? never : [IsNever<From>, IsNever<To>] extends [false, false] ? AtLeastOneArray<From, To> extends true ? ArrayDivergence<From, To, [...Acc, From]> : [IsIndexedType<From>, IsIndexedType<To>] extends [true, true] ? IndexedTypeDiff<From, To, [...Acc, From]> : IsAtLeastOneUnion<From, To> extends true ? UnionDivergence<From, To, Acc> : AtLeastOnePrimitive<From, To> extends true ? PrimitiveDivergence<From, To> : AtLeastOneEmptyObject<From, To> extends true ? EmptyObjectDivergence<From, To> : [From, To] extends [object, object] ? ObjectDivergence<From, To, [...Acc, From]> : SimpleDivergence<From, To> : {};
63
- //#endregion
64
- export { Divergence, Expand, IsNever };
86
+ export {};
65
87
  //# sourceMappingURL=divergence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"divergence.d.ts","sourceRoot":"","sources":["../../src/divergence/divergence.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CACnC,CAAC,SAAS,OAAO,GACb,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GACd,KAAK,CACV,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,GAC1B,CAAC,GACD,KAAK,CAAC;AACV,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,GAClE,CAAC,GACD,KAAK,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a,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,GAC3D,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC,GACzC,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,IAAI,GACtC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,GAC9B,mBAAmB,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,IAAI,GACxC,mBAAmB,CAAC,IAAI,EAAE,EAAE,CAAC,GAC7B,qBAAqB,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,IAAI,GAC1C,qBAAqB,CAAC,IAAI,EAAE,EAAE,CAAC,GAC/B,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC,gBAAgB,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC,GAC1C,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,GACtC,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=divergence.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"divergence.spec.d.ts","sourceRoot":"","sources":["../../src/divergence/divergence.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=freeze-decorator.entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"freeze-decorator.entrypoint.d.ts","sourceRoot":"","sources":["../../src/entrypoints/freeze-decorator.entrypoint.ts"],"names":[],"mappings":""}
@@ -0,0 +1,114 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.js');
2
+ const require_explore_type = require('../utils/explore-type.js');
3
+ const require_project = require('./project.js');
4
+ const require_package = require('../package.js');
5
+ let ts_morph = require("ts-morph");
6
+ let node_path = require("node:path");
7
+ let node_fs = require("node:fs");
8
+ node_fs = require_runtime.__toESM(node_fs);
9
+
10
+ //#region src/entrypoints/freeze-decorator.entrypoint.ts
11
+ const cwd = process.cwd();
12
+ const resolveFromDistIndex = () => {
13
+ const decoratorFilePath = `${__dirname}/../../dist/index.d.ts`;
14
+ const decoratorFile = require_project.project.getSourceFile(decoratorFilePath);
15
+ if (!decoratorFile) throw new Error(`Cannot find index.d.ts at path ${decoratorFilePath}`);
16
+ const decoratorFunction = decoratorFile.getExportedDeclarations().get("Freeze")?.[0].asKind(ts_morph.ts.SyntaxKind.FunctionDeclaration);
17
+ if (!decoratorFunction) throw new Error(`Cannot find function for Freeze decorator in ${decoratorFilePath}`);
18
+ const references = decoratorFunction.findReferences();
19
+ if (!references) throw new Error("Cannot find declaration of the Freeze decorator");
20
+ return references;
21
+ };
22
+ const resolveFromDist = () => {
23
+ const decoratorFilePath = `${__dirname}/../references/freeze.decorator.d.ts`;
24
+ const decoratorFile = require_project.project.getSourceFile(decoratorFilePath);
25
+ if (!decoratorFile) throw new Error(`Cannot find freeze.decorator.d.ts at path ${decoratorFilePath}`);
26
+ const references = decoratorFile.getFunction("Freeze")?.findReferences();
27
+ if (!references) throw new Error("Cannot find declaration of the Freeze decorator");
28
+ return references;
29
+ };
30
+ const resolveFromSource = () => {
31
+ const decoratorFilePath = `${__dirname}/../references/freeze.decorator.ts`;
32
+ const decoratorFile = require_project.project.getSourceFile(decoratorFilePath);
33
+ if (!decoratorFile) throw new Error(`Cannot find freeze.decorator.ts at path ${decoratorFilePath}`);
34
+ const references = decoratorFile.getFunction("Freeze")?.findReferences();
35
+ if (!references) throw new Error("Cannot find declaration of the Freeze decorator");
36
+ return references;
37
+ };
38
+ let references;
39
+ try {
40
+ references = resolveFromDistIndex();
41
+ } catch (e) {
42
+ try {
43
+ references = resolveFromDist();
44
+ } catch (e) {
45
+ try {
46
+ references = resolveFromSource();
47
+ } catch (e) {
48
+ throw new Error("Cannot find declaration of the Freeze decorator in dist/index.d.ts, dist/references/freeze.decorator.d.ts or src/references/freeze.decorator.ts");
49
+ }
50
+ }
51
+ }
52
+ function lowercasefirstletter(str) {
53
+ return str.charAt(0).toLowerCase() + str.slice(1);
54
+ }
55
+ for (const ref of references) for (const refref of ref.getReferences()) {
56
+ const decorator = refref.getNode().getParent()?.getParent()?.asKind(ts_morph.ts.SyntaxKind.Decorator);
57
+ if (!decorator) continue;
58
+ const rpath = (0, node_path.relative)(cwd, decorator.getSourceFile().getFilePath());
59
+ const classDeclaration = decorator.getParentIfKind(ts_morph.ts.SyntaxKind.ClassDeclaration);
60
+ if (!classDeclaration) continue;
61
+ const typeParameter = decorator.getTypeArguments()[0];
62
+ if (typeParameter) {
63
+ console.log(`${classDeclaration.getName()}: Already frozen with <${typeParameter.getText()}>`);
64
+ continue;
65
+ }
66
+ const serializeProperty = classDeclaration.getType().getProperty("serialize");
67
+ if (!serializeProperty) {
68
+ console.log(`${rpath} - ${classDeclaration.getName()}: No serialize property`);
69
+ continue;
70
+ }
71
+ const serializeMethod = require_project.project.getTypeChecker().getTypeOfSymbolAtLocation(serializeProperty, classDeclaration).getCallSignatures()[0];
72
+ let serialized = serializeMethod.getReturnType();
73
+ if (serialized.getSymbol()?.getName() === "Promise") serialized = serialized.getTypeArguments()[0];
74
+ const version = serialized.getProperty("version")?.getTypeAtLocation(classDeclaration).getText();
75
+ if (!version || Number.isNaN(Number(version))) {
76
+ console.log(`${rpath} - ${classDeclaration.getName()}: No version property (or not a number) : ${version}`);
77
+ continue;
78
+ }
79
+ console.log(`${rpath} - ${classDeclaration.getName()}: Freezing with version ${version}`);
80
+ const other = /* @__PURE__ */ new Map();
81
+ const result = require_explore_type.exploreType(serialized.compilerType, require_project.project.getTypeChecker().compilerObject, other);
82
+ const type = serializeMethod.getParameters()[0].getTypeAtLocation(classDeclaration);
83
+ const symbol = type.getSymbol()?.getName();
84
+ const aliasSymbol = type.getAliasSymbol()?.getName();
85
+ let name$1;
86
+ if (symbol) {
87
+ name$1 = symbol;
88
+ console.log(`${rpath} - ${classDeclaration.getName()}: Using symbol ${symbol}`);
89
+ } else if (aliasSymbol) {
90
+ name$1 = aliasSymbol;
91
+ console.log(`${rpath} - ${classDeclaration.getName()}: Using aliasSymbol ${aliasSymbol}`);
92
+ }
93
+ if (!name$1) {
94
+ console.log(`${rpath} - ${classDeclaration.getName()}: Cannot find name of serialized type`);
95
+ continue;
96
+ }
97
+ const serializedName = `${name$1}Serialized${version}n`;
98
+ const serializedFilename = lowercasefirstletter(`${name$1}.serialized.${version}n`);
99
+ const directory = refref.getSourceFile().getDirectory();
100
+ decorator.getSourceFile().addImportDeclaration({
101
+ moduleSpecifier: `./${serializedFilename}`,
102
+ namedImports: [serializedName]
103
+ });
104
+ decorator.addTypeArgument(serializedName);
105
+ require_project.project.saveSync();
106
+ const output = [
107
+ `// Auto-generated by ${require_package.name}`,
108
+ ...other.values(),
109
+ `export type ${serializedName} = ${result}`
110
+ ].join("\n");
111
+ node_fs.default.writeFileSync(`${directory.getPath()}/${serializedFilename}.ts`, output);
112
+ }
113
+
114
+ //#endregion
@@ -0,0 +1,113 @@
1
+ import { exploreType } from "../utils/explore-type.mjs";
2
+ import { project } from "./project.mjs";
3
+ import { name } from "../package.mjs";
4
+ import { ts } from "ts-morph";
5
+ import { relative } from "node:path";
6
+ import fs from "node:fs";
7
+
8
+ //#region src/entrypoints/freeze-decorator.entrypoint.ts
9
+ const cwd = process.cwd();
10
+ const resolveFromDistIndex = () => {
11
+ const decoratorFilePath = `${__dirname}/../../dist/index.d.ts`;
12
+ const decoratorFile = project.getSourceFile(decoratorFilePath);
13
+ if (!decoratorFile) throw new Error(`Cannot find index.d.ts at path ${decoratorFilePath}`);
14
+ const decoratorFunction = decoratorFile.getExportedDeclarations().get("Freeze")?.[0].asKind(ts.SyntaxKind.FunctionDeclaration);
15
+ if (!decoratorFunction) throw new Error(`Cannot find function for Freeze decorator in ${decoratorFilePath}`);
16
+ const references = decoratorFunction.findReferences();
17
+ if (!references) throw new Error("Cannot find declaration of the Freeze decorator");
18
+ return references;
19
+ };
20
+ const resolveFromDist = () => {
21
+ const decoratorFilePath = `${__dirname}/../references/freeze.decorator.d.ts`;
22
+ const decoratorFile = project.getSourceFile(decoratorFilePath);
23
+ if (!decoratorFile) throw new Error(`Cannot find freeze.decorator.d.ts at path ${decoratorFilePath}`);
24
+ const references = decoratorFile.getFunction("Freeze")?.findReferences();
25
+ if (!references) throw new Error("Cannot find declaration of the Freeze decorator");
26
+ return references;
27
+ };
28
+ const resolveFromSource = () => {
29
+ const decoratorFilePath = `${__dirname}/../references/freeze.decorator.ts`;
30
+ const decoratorFile = project.getSourceFile(decoratorFilePath);
31
+ if (!decoratorFile) throw new Error(`Cannot find freeze.decorator.ts at path ${decoratorFilePath}`);
32
+ const references = decoratorFile.getFunction("Freeze")?.findReferences();
33
+ if (!references) throw new Error("Cannot find declaration of the Freeze decorator");
34
+ return references;
35
+ };
36
+ let references;
37
+ try {
38
+ references = resolveFromDistIndex();
39
+ } catch (e) {
40
+ try {
41
+ references = resolveFromDist();
42
+ } catch (e) {
43
+ try {
44
+ references = resolveFromSource();
45
+ } catch (e) {
46
+ throw new Error("Cannot find declaration of the Freeze decorator in dist/index.d.ts, dist/references/freeze.decorator.d.ts or src/references/freeze.decorator.ts");
47
+ }
48
+ }
49
+ }
50
+ function lowercasefirstletter(str) {
51
+ return str.charAt(0).toLowerCase() + str.slice(1);
52
+ }
53
+ for (const ref of references) for (const refref of ref.getReferences()) {
54
+ const decorator = refref.getNode().getParent()?.getParent()?.asKind(ts.SyntaxKind.Decorator);
55
+ if (!decorator) continue;
56
+ const rpath = relative(cwd, decorator.getSourceFile().getFilePath());
57
+ const classDeclaration = decorator.getParentIfKind(ts.SyntaxKind.ClassDeclaration);
58
+ if (!classDeclaration) continue;
59
+ const typeParameter = decorator.getTypeArguments()[0];
60
+ if (typeParameter) {
61
+ console.log(`${classDeclaration.getName()}: Already frozen with <${typeParameter.getText()}>`);
62
+ continue;
63
+ }
64
+ const serializeProperty = classDeclaration.getType().getProperty("serialize");
65
+ if (!serializeProperty) {
66
+ console.log(`${rpath} - ${classDeclaration.getName()}: No serialize property`);
67
+ continue;
68
+ }
69
+ const serializeMethod = project.getTypeChecker().getTypeOfSymbolAtLocation(serializeProperty, classDeclaration).getCallSignatures()[0];
70
+ let serialized = serializeMethod.getReturnType();
71
+ if (serialized.getSymbol()?.getName() === "Promise") serialized = serialized.getTypeArguments()[0];
72
+ const version = serialized.getProperty("version")?.getTypeAtLocation(classDeclaration).getText();
73
+ if (!version || Number.isNaN(Number(version))) {
74
+ console.log(`${rpath} - ${classDeclaration.getName()}: No version property (or not a number) : ${version}`);
75
+ continue;
76
+ }
77
+ console.log(`${rpath} - ${classDeclaration.getName()}: Freezing with version ${version}`);
78
+ const other = /* @__PURE__ */ new Map();
79
+ const result = exploreType(serialized.compilerType, project.getTypeChecker().compilerObject, other);
80
+ const type = serializeMethod.getParameters()[0].getTypeAtLocation(classDeclaration);
81
+ const symbol = type.getSymbol()?.getName();
82
+ const aliasSymbol = type.getAliasSymbol()?.getName();
83
+ let name$1;
84
+ if (symbol) {
85
+ name$1 = symbol;
86
+ console.log(`${rpath} - ${classDeclaration.getName()}: Using symbol ${symbol}`);
87
+ } else if (aliasSymbol) {
88
+ name$1 = aliasSymbol;
89
+ console.log(`${rpath} - ${classDeclaration.getName()}: Using aliasSymbol ${aliasSymbol}`);
90
+ }
91
+ if (!name$1) {
92
+ console.log(`${rpath} - ${classDeclaration.getName()}: Cannot find name of serialized type`);
93
+ continue;
94
+ }
95
+ const serializedName = `${name$1}Serialized${version}n`;
96
+ const serializedFilename = lowercasefirstletter(`${name$1}.serialized.${version}n`);
97
+ const directory = refref.getSourceFile().getDirectory();
98
+ decorator.getSourceFile().addImportDeclaration({
99
+ moduleSpecifier: `./${serializedFilename}`,
100
+ namedImports: [serializedName]
101
+ });
102
+ decorator.addTypeArgument(serializedName);
103
+ project.saveSync();
104
+ const output = [
105
+ `// Auto-generated by ${name}`,
106
+ ...other.values(),
107
+ `export type ${serializedName} = ${result}`
108
+ ].join("\n");
109
+ fs.writeFileSync(`${directory.getPath()}/${serializedFilename}.ts`, output);
110
+ }
111
+
112
+ //#endregion
113
+ export { };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=freeze-function.entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"freeze-function.entrypoint.d.ts","sourceRoot":"","sources":["../../src/entrypoints/freeze-function.entrypoint.ts"],"names":[],"mappings":""}
@@ -0,0 +1,119 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.js');
2
+ const require_explore_type = require('../utils/explore-type.js');
3
+ const require_project = require('./project.js');
4
+ const require_package = require('../package.js');
5
+ const require_get_pretty_type = require('../utils/get-pretty-type.js');
6
+ let ts_morph = require("ts-morph");
7
+ let node_path = require("node:path");
8
+ let node_fs = require("node:fs");
9
+ node_fs = require_runtime.__toESM(node_fs);
10
+ let _prettier_sync = require("@prettier/sync");
11
+ _prettier_sync = require_runtime.__toESM(_prettier_sync);
12
+
13
+ //#region src/entrypoints/freeze-function.entrypoint.ts
14
+ const cwd = process.cwd();
15
+ const resolveFromDistIndex = () => {
16
+ const functionFilePath = `${__dirname}/../../dist/index.d.ts`;
17
+ const functionFile = require_project.project.getSourceFile(functionFilePath);
18
+ if (!functionFile) throw new Error(`Cannot find index.d.ts at path ${functionFilePath}`);
19
+ const freezeFunction = functionFile.getExportedDeclarations().get("freeze")?.[0].asKind(ts_morph.ts.SyntaxKind.FunctionDeclaration);
20
+ if (!freezeFunction) throw new Error(`Cannot find function for freeze in ${functionFilePath}`);
21
+ const references = freezeFunction.findReferences();
22
+ if (!references) throw new Error("Cannot find declaration of the freeze function");
23
+ return references;
24
+ };
25
+ const resolveFromSource = () => {
26
+ const functionFilePath = `${__dirname}/../references/freeze.function.ts`;
27
+ const functionFile = require_project.project.getSourceFile(functionFilePath);
28
+ if (!functionFile) throw new Error(`Cannot find freeze.function.ts at path ${functionFilePath}`);
29
+ const references = functionFile.getFunction("freeze")?.findReferences();
30
+ if (!references) throw new Error("Cannot find declaration of the freeze function");
31
+ return references;
32
+ };
33
+ const resolveFromDist = () => {
34
+ const functionFilePath = `${__dirname}/../references/freeze.function.d.ts`;
35
+ const functionFile = require_project.project.getSourceFile(functionFilePath);
36
+ if (!functionFile) throw new Error(`Cannot find freeze.function.d.ts at path ${functionFilePath}`);
37
+ const references = functionFile.getFunction("freeze")?.findReferences();
38
+ if (!references) throw new Error("Cannot find declaration of the freeze function");
39
+ return references;
40
+ };
41
+ let references;
42
+ try {
43
+ references = resolveFromDistIndex();
44
+ } catch {
45
+ try {
46
+ references = resolveFromDist();
47
+ } catch {
48
+ try {
49
+ references = resolveFromSource();
50
+ } catch {
51
+ throw new Error("Cannot find references for freeze function in dist/index.d.ts, dist/references/freeze.function.d.ts or src/references/freeze.function.ts");
52
+ }
53
+ }
54
+ }
55
+ function lowercasefirstletter(str) {
56
+ return str.charAt(0).toLowerCase() + str.slice(1);
57
+ }
58
+ for (const ref of references) for (const refref of ref.getReferences()) {
59
+ const callExpression = refref.getNode().getParentIfKind(ts_morph.ts.SyntaxKind.CallExpression);
60
+ if (!callExpression) continue;
61
+ const rpath = (0, node_path.relative)(cwd, callExpression.getSourceFile().getFilePath());
62
+ const typeArguments = callExpression.getTypeArguments();
63
+ const freezeParameters = typeArguments[0].asKind(ts_morph.ts.SyntaxKind.TypeLiteral);
64
+ const alreadyFrozen = typeArguments[1];
65
+ if (!freezeParameters) {
66
+ console.log(`${rpath}:${callExpression.getStartLineNumber()}: No freeze parameters`);
67
+ continue;
68
+ }
69
+ const nameProperty = freezeParameters.getProperty("name");
70
+ if (!nameProperty) {
71
+ console.log(`${rpath}:${callExpression.getStartLineNumber()}: No name property`);
72
+ continue;
73
+ }
74
+ const name$1 = nameProperty.getType().getLiteralValue();
75
+ if (typeof name$1 !== "string") {
76
+ console.log(`${rpath}:${callExpression.getStartLineNumber()}: Name is not a string literal`);
77
+ continue;
78
+ }
79
+ if (alreadyFrozen) {
80
+ console.log(`${rpath} - ${name$1}: Already frozen with <${alreadyFrozen.getText()}>`);
81
+ continue;
82
+ }
83
+ const typeProperty = freezeParameters.getProperty("type");
84
+ if (!typeProperty) {
85
+ console.log(`${rpath} - ${name$1}: No type property`);
86
+ continue;
87
+ }
88
+ const prettyType = require_get_pretty_type.getPrettyType(typeProperty.getType(), callExpression);
89
+ const other = /* @__PURE__ */ new Map();
90
+ let result = require_explore_type.exploreType(prettyType.type.compilerType, require_project.project.getTypeChecker().compilerObject, other);
91
+ const aliasName = prettyType.alias.getName();
92
+ prettyType.dispose();
93
+ for (const [key, value] of other) {
94
+ if (key.name !== aliasName) continue;
95
+ result = result.replace(new RegExp(`\\b${aliasName}\\b`, "g"), value.replace(new RegExp(`^type ${aliasName} = `), ""));
96
+ other.delete(key);
97
+ }
98
+ const serializedName = name$1;
99
+ const filenamePropertyValue = freezeParameters.getProperty("filename")?.getType().getLiteralValue();
100
+ const serializedExtension = freezeParameters.getProperty("extension")?.getType().getLiteralValue() ?? ".serialized";
101
+ const serializedFilename = filenamePropertyValue ?? lowercasefirstletter(`${serializedName}${serializedExtension}`);
102
+ const directory = refref.getSourceFile().getDirectory();
103
+ callExpression.getSourceFile().addImportDeclaration({
104
+ moduleSpecifier: `./${serializedFilename}`,
105
+ namedImports: [serializedName]
106
+ });
107
+ callExpression.addTypeArgument(serializedName);
108
+ require_project.project.saveSync();
109
+ const output = [
110
+ `// Auto-generated by ${require_package.name}`,
111
+ ...other.values(),
112
+ `export type ${serializedName} = ${result}`
113
+ ].join("\n");
114
+ const formattedOutput = _prettier_sync.default.format(output, { parser: "typescript" });
115
+ node_fs.default.writeFileSync(`${directory.getPath()}/${serializedFilename}.ts`, formattedOutput);
116
+ console.log(`${rpath} - ${name$1}: Frozen as ${serializedName} in ${serializedFilename}.ts`);
117
+ }
118
+
119
+ //#endregion