@qwik.dev/devtools 0.0.3 → 0.0.5

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 (134) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +49 -30
  3. package/dist/component/_virtual/_commonjsHelpers.qwik.cjs +6 -0
  4. package/dist/component/_virtual/_commonjsHelpers.qwik.mjs +6 -0
  5. package/{lib → dist/component}/devtools.qwik.cjs +19 -20
  6. package/{lib → dist/component}/devtools.qwik.mjs +11 -12
  7. package/{lib → dist/component}/index.qwik.cjs +0 -2
  8. package/dist/component/index.qwik.mjs +4 -0
  9. package/{lib-types → dist/component/lib-types/devtools/src}/index.d.ts +0 -1
  10. package/dist/component/node_modules/.pnpm/@qwikest_icons@0.0.13_@builder.io_qwik@1.11.0_vite@5.4.10_@types_node@20.14.11__/node_modules/@qwikest/icons/lib/hi.qwik.qwik.cjs +60 -0
  11. package/dist/component/node_modules/.pnpm/@qwikest_icons@0.0.13_@builder.io_qwik@1.11.0_vite@5.4.10_@types_node@20.14.11__/node_modules/@qwikest/icons/lib/hi.qwik.qwik.mjs +60 -0
  12. package/dist/component/node_modules/.pnpm/@qwikest_icons@0.0.13_@builder.io_qwik@1.11.0_vite@5.4.10_@types_node@20.14.11__/node_modules/@qwikest/icons/lib/lu.qwik.qwik.cjs +32 -0
  13. package/dist/component/node_modules/.pnpm/@qwikest_icons@0.0.13_@builder.io_qwik@1.11.0_vite@5.4.10_@types_node@20.14.11__/node_modules/@qwikest/icons/lib/lu.qwik.qwik.mjs +32 -0
  14. package/dist/component/node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.qwik.cjs +54 -0
  15. package/dist/component/node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.qwik.mjs +54 -0
  16. package/dist/component/node_modules/.pnpm/birpc@0.2.19/node_modules/birpc/dist/index.qwik.cjs +128 -0
  17. package/dist/component/node_modules/.pnpm/birpc@0.2.19/node_modules/birpc/dist/index.qwik.mjs +128 -0
  18. package/dist/component/node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.qwik.cjs +149 -0
  19. package/dist/component/node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.qwik.mjs +150 -0
  20. package/dist/component/node_modules/.pnpm/copy-anything@3.0.5/node_modules/copy-anything/dist/index.qwik.cjs +36 -0
  21. package/dist/component/node_modules/.pnpm/copy-anything@3.0.5/node_modules/copy-anything/dist/index.qwik.mjs +36 -0
  22. package/dist/component/node_modules/.pnpm/dree@5.1.5/node_modules/dree/bundled/lib/esm/index.esm.qwik.cjs +12 -0
  23. package/dist/component/node_modules/.pnpm/dree@5.1.5/node_modules/dree/bundled/lib/esm/index.esm.qwik.mjs +12 -0
  24. package/dist/component/node_modules/.pnpm/is-what@4.1.16/node_modules/is-what/dist/index.qwik.cjs +17 -0
  25. package/dist/component/node_modules/.pnpm/is-what@4.1.16/node_modules/is-what/dist/index.qwik.mjs +17 -0
  26. package/dist/component/node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/assert-valid-pattern.qwik.cjs +12 -0
  27. package/dist/component/node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/assert-valid-pattern.qwik.mjs +12 -0
  28. package/dist/component/node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/ast.qwik.cjs +513 -0
  29. package/dist/component/node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/ast.qwik.mjs +513 -0
  30. package/dist/component/node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/brace-expressions.qwik.cjs +110 -0
  31. package/dist/component/node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/brace-expressions.qwik.mjs +110 -0
  32. package/dist/component/node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/escape.qwik.cjs +6 -0
  33. package/dist/component/node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/escape.qwik.mjs +6 -0
  34. package/dist/component/node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/index.qwik.cjs +738 -0
  35. package/dist/component/node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/index.qwik.mjs +738 -0
  36. package/dist/component/node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/unescape.qwik.cjs +6 -0
  37. package/dist/component/node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/unescape.qwik.mjs +6 -0
  38. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/accessDeep.qwik.cjs +120 -0
  39. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/accessDeep.qwik.mjs +120 -0
  40. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/class-registry.qwik.cjs +23 -0
  41. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/class-registry.qwik.mjs +23 -0
  42. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/custom-transformer-registry.qwik.cjs +18 -0
  43. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/custom-transformer-registry.qwik.mjs +18 -0
  44. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/double-indexed-kv.qwik.cjs +23 -0
  45. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/double-indexed-kv.qwik.mjs +23 -0
  46. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/index.qwik.cjs +91 -0
  47. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/index.qwik.mjs +91 -0
  48. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/is.qwik.cjs +51 -0
  49. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/is.qwik.mjs +51 -0
  50. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/pathstringifier.qwik.cjs +30 -0
  51. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/pathstringifier.qwik.mjs +30 -0
  52. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/plainer.qwik.cjs +148 -0
  53. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/plainer.qwik.mjs +148 -0
  54. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/registry.qwik.cjs +28 -0
  55. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/registry.qwik.mjs +28 -0
  56. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/transformer.qwik.cjs +203 -0
  57. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/transformer.qwik.mjs +203 -0
  58. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/util.qwik.cjs +47 -0
  59. package/dist/component/node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/util.qwik.mjs +47 -0
  60. package/dist/component/node_modules/.pnpm/vite-hot-client@0.2.4_vite@5.4.10_@types_node@20.14.11_/node_modules/vite-hot-client/dist/index.qwik.cjs +35 -0
  61. package/dist/component/node_modules/.pnpm/vite-hot-client@0.2.4_vite@5.4.10_@types_node@20.14.11_/node_modules/vite-hot-client/dist/index.qwik.mjs +35 -0
  62. package/{lib/kit → dist/component/packages/kit/src}/client.qwik.cjs +5 -5
  63. package/{lib/kit → dist/component/packages/kit/src}/client.qwik.mjs +2 -2
  64. package/{lib/kit → dist/component/packages/kit/src}/context.qwik.cjs +0 -12
  65. package/{lib/kit → dist/component/packages/kit/src}/context.qwik.mjs +2 -14
  66. package/{lib/kit → dist/component/packages/kit/src}/globals.qwik.cjs +0 -4
  67. package/dist/component/packages/kit/src/globals.qwik.mjs +6 -0
  68. package/dist/plugin/index.cjs +10504 -0
  69. package/dist/plugin/index.mjs +10492 -0
  70. package/package.json +34 -41
  71. package/lib/index.qwik.mjs +0 -6
  72. package/lib/kit/globals.qwik.mjs +0 -10
  73. package/lib/kit/server.qwik.cjs +0 -18
  74. package/lib/kit/server.qwik.mjs +0 -18
  75. package/lib/plugin/assets/index.qwik.cjs +0 -67
  76. package/lib/plugin/assets/index.qwik.mjs +0 -67
  77. package/lib/plugin/index.qwik.cjs +0 -49
  78. package/lib/plugin/index.qwik.mjs +0 -49
  79. package/lib/plugin/npm/index.qwik.cjs +0 -19
  80. package/lib/plugin/npm/index.qwik.mjs +0 -19
  81. package/lib/plugin/routes/index.qwik.cjs +0 -17
  82. package/lib/plugin/routes/index.qwik.mjs +0 -17
  83. package/lib/plugin/rpc/index.qwik.cjs +0 -14
  84. package/lib/plugin/rpc/index.qwik.mjs +0 -14
  85. package/lib/utils/location.qwik.cjs +0 -9
  86. package/lib/utils/location.qwik.mjs +0 -9
  87. package/lib-types/plugin/assets/index.d.ts +0 -5
  88. package/lib-types/plugin/components/index.d.ts +0 -0
  89. package/lib-types/plugin/index.d.ts +0 -2
  90. package/lib-types/plugin/npm/index.d.ts +0 -5
  91. package/lib-types/plugin/routes/index.d.ts +0 -5
  92. package/lib-types/plugin/rpc/index.d.ts +0 -3
  93. package/lib-types/plugin/types/index.d.ts +0 -5
  94. package/src/devtools.css +0 -558
  95. package/src/devtools.tsx +0 -404
  96. package/src/entry.dev.tsx +0 -17
  97. package/src/entry.ssr.tsx +0 -25
  98. package/src/index.ts +0 -2
  99. package/src/kit/client.ts +0 -21
  100. package/src/kit/constants.ts +0 -1
  101. package/src/kit/context.ts +0 -42
  102. package/src/kit/globals.ts +0 -22
  103. package/src/kit/index.ts +0 -4
  104. package/src/kit/server.ts +0 -21
  105. package/src/kit/shared.ts +0 -11
  106. package/src/kit/types.ts +0 -48
  107. package/src/plugin/assets/index.ts +0 -126
  108. package/src/plugin/components/index.ts +0 -0
  109. package/src/plugin/index.ts +0 -50
  110. package/src/plugin/npm/index.ts +0 -24
  111. package/src/plugin/routes/index.ts +0 -16
  112. package/src/plugin/rpc/index.ts +0 -14
  113. package/src/plugin/types/index.ts +0 -6
  114. package/src/root.tsx +0 -15
  115. package/src/utils/location.ts +0 -9
  116. /package/{lib → dist/component}/devtools.css.qwik.cjs +0 -0
  117. /package/{lib → dist/component}/devtools.css.qwik.mjs +0 -0
  118. /package/{lib-types → dist/component/lib-types/devtools/src}/devtools.d.ts +0 -0
  119. /package/{lib-types → dist/component/lib-types/devtools/src}/entry.dev.d.ts +0 -0
  120. /package/{lib-types → dist/component/lib-types/devtools/src}/entry.ssr.d.ts +0 -0
  121. /package/{lib-types → dist/component/lib-types/devtools/src}/root.d.ts +0 -0
  122. /package/{lib-types → dist/component/lib-types/devtools/src}/utils/location.d.ts +0 -0
  123. /package/{lib-types/kit → dist/component/lib-types/kit/src}/client.d.ts +0 -0
  124. /package/{lib-types/kit → dist/component/lib-types/kit/src}/constants.d.ts +0 -0
  125. /package/{lib-types/kit → dist/component/lib-types/kit/src}/context.d.ts +0 -0
  126. /package/{lib-types/kit → dist/component/lib-types/kit/src}/globals.d.ts +0 -0
  127. /package/{lib-types/kit → dist/component/lib-types/kit/src}/index.d.ts +0 -0
  128. /package/{lib-types/kit → dist/component/lib-types/kit/src}/server.d.ts +0 -0
  129. /package/{lib-types/kit → dist/component/lib-types/kit/src}/shared.d.ts +0 -0
  130. /package/{lib-types/kit → dist/component/lib-types/kit/src}/types.d.ts +0 -0
  131. /package/{lib/kit → dist/component/packages/kit/src}/constants.qwik.cjs +0 -0
  132. /package/{lib/kit → dist/component/packages/kit/src}/constants.qwik.mjs +0 -0
  133. /package/{lib/kit → dist/component/packages/kit/src}/shared.qwik.cjs +0 -0
  134. /package/{lib/kit → dist/component/packages/kit/src}/shared.qwik.mjs +0 -0
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const escapeKey = (key) => key.replace(/\./g, "\\.");
4
+ const stringifyPath = (path) => path.map(String).map(escapeKey).join(".");
5
+ const parsePath = (string) => {
6
+ const result = [];
7
+ let segment = "";
8
+ for (let i = 0; i < string.length; i++) {
9
+ let char = string.charAt(i);
10
+ const isEscapedDot = char === "\\" && string.charAt(i + 1) === ".";
11
+ if (isEscapedDot) {
12
+ segment += ".";
13
+ i++;
14
+ continue;
15
+ }
16
+ const isEndOfSegment = char === ".";
17
+ if (isEndOfSegment) {
18
+ result.push(segment);
19
+ segment = "";
20
+ continue;
21
+ }
22
+ segment += char;
23
+ }
24
+ const lastSegment = segment;
25
+ result.push(lastSegment);
26
+ return result;
27
+ };
28
+ exports.escapeKey = escapeKey;
29
+ exports.parsePath = parsePath;
30
+ exports.stringifyPath = stringifyPath;
@@ -0,0 +1,30 @@
1
+ const escapeKey = (key) => key.replace(/\./g, "\\.");
2
+ const stringifyPath = (path) => path.map(String).map(escapeKey).join(".");
3
+ const parsePath = (string) => {
4
+ const result = [];
5
+ let segment = "";
6
+ for (let i = 0; i < string.length; i++) {
7
+ let char = string.charAt(i);
8
+ const isEscapedDot = char === "\\" && string.charAt(i + 1) === ".";
9
+ if (isEscapedDot) {
10
+ segment += ".";
11
+ i++;
12
+ continue;
13
+ }
14
+ const isEndOfSegment = char === ".";
15
+ if (isEndOfSegment) {
16
+ result.push(segment);
17
+ segment = "";
18
+ continue;
19
+ }
20
+ segment += char;
21
+ }
22
+ const lastSegment = segment;
23
+ result.push(lastSegment);
24
+ return result;
25
+ };
26
+ export {
27
+ escapeKey,
28
+ parsePath,
29
+ stringifyPath
30
+ };
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const is = require("./is.qwik.cjs");
4
+ const pathstringifier = require("./pathstringifier.qwik.cjs");
5
+ const transformer = require("./transformer.qwik.cjs");
6
+ const util = require("./util.qwik.cjs");
7
+ const accessDeep = require("./accessDeep.qwik.cjs");
8
+ function traverse(tree, walker2, origin = []) {
9
+ if (!tree) {
10
+ return;
11
+ }
12
+ if (!is.isArray(tree)) {
13
+ util.forEach(tree, (subtree, key) => traverse(subtree, walker2, [...origin, ...pathstringifier.parsePath(key)]));
14
+ return;
15
+ }
16
+ const [nodeValue, children] = tree;
17
+ if (children) {
18
+ util.forEach(children, (child, key) => {
19
+ traverse(child, walker2, [...origin, ...pathstringifier.parsePath(key)]);
20
+ });
21
+ }
22
+ walker2(nodeValue, origin);
23
+ }
24
+ function applyValueAnnotations(plain, annotations, superJson) {
25
+ traverse(annotations, (type, path) => {
26
+ plain = accessDeep.setDeep(plain, path, (v) => transformer.untransformValue(v, type, superJson));
27
+ });
28
+ return plain;
29
+ }
30
+ function applyReferentialEqualityAnnotations(plain, annotations) {
31
+ function apply(identicalPaths, path) {
32
+ const object = accessDeep.getDeep(plain, pathstringifier.parsePath(path));
33
+ identicalPaths.map(pathstringifier.parsePath).forEach((identicalObjectPath) => {
34
+ plain = accessDeep.setDeep(plain, identicalObjectPath, () => object);
35
+ });
36
+ }
37
+ if (is.isArray(annotations)) {
38
+ const [root, other] = annotations;
39
+ root.forEach((identicalPath) => {
40
+ plain = accessDeep.setDeep(plain, pathstringifier.parsePath(identicalPath), () => plain);
41
+ });
42
+ if (other) {
43
+ util.forEach(other, apply);
44
+ }
45
+ } else {
46
+ util.forEach(annotations, apply);
47
+ }
48
+ return plain;
49
+ }
50
+ const isDeep = (object, superJson) => is.isPlainObject(object) || is.isArray(object) || is.isMap(object) || is.isSet(object) || transformer.isInstanceOfRegisteredClass(object, superJson);
51
+ function addIdentity(object, path, identities) {
52
+ const existingSet = identities.get(object);
53
+ if (existingSet) {
54
+ existingSet.push(path);
55
+ } else {
56
+ identities.set(object, [path]);
57
+ }
58
+ }
59
+ function generateReferentialEqualityAnnotations(identitites, dedupe) {
60
+ const result = {};
61
+ let rootEqualityPaths = void 0;
62
+ identitites.forEach((paths) => {
63
+ if (paths.length <= 1) {
64
+ return;
65
+ }
66
+ if (!dedupe) {
67
+ paths = paths.map((path) => path.map(String)).sort((a, b) => a.length - b.length);
68
+ }
69
+ const [representativePath, ...identicalPaths] = paths;
70
+ if (representativePath.length === 0) {
71
+ rootEqualityPaths = identicalPaths.map(pathstringifier.stringifyPath);
72
+ } else {
73
+ result[pathstringifier.stringifyPath(representativePath)] = identicalPaths.map(pathstringifier.stringifyPath);
74
+ }
75
+ });
76
+ if (rootEqualityPaths) {
77
+ if (is.isEmptyObject(result)) {
78
+ return [rootEqualityPaths];
79
+ } else {
80
+ return [rootEqualityPaths, result];
81
+ }
82
+ } else {
83
+ return is.isEmptyObject(result) ? void 0 : result;
84
+ }
85
+ }
86
+ const walker = (object, identities, superJson, dedupe, path = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
87
+ const primitive = is.isPrimitive(object);
88
+ if (!primitive) {
89
+ addIdentity(object, path, identities);
90
+ const seen = seenObjects.get(object);
91
+ if (seen) {
92
+ return dedupe ? {
93
+ transformedValue: null
94
+ } : seen;
95
+ }
96
+ }
97
+ if (!isDeep(object, superJson)) {
98
+ const transformed2 = transformer.transformValue(object, superJson);
99
+ const result2 = transformed2 ? {
100
+ transformedValue: transformed2.value,
101
+ annotations: [transformed2.type]
102
+ } : {
103
+ transformedValue: object
104
+ };
105
+ if (!primitive) {
106
+ seenObjects.set(object, result2);
107
+ }
108
+ return result2;
109
+ }
110
+ if (util.includes(objectsInThisPath, object)) {
111
+ return {
112
+ transformedValue: null
113
+ };
114
+ }
115
+ const transformationResult = transformer.transformValue(object, superJson);
116
+ const transformed = transformationResult?.value ?? object;
117
+ const transformedValue = is.isArray(transformed) ? [] : {};
118
+ const innerAnnotations = {};
119
+ util.forEach(transformed, (value, index) => {
120
+ if (index === "__proto__" || index === "constructor" || index === "prototype") {
121
+ throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
122
+ }
123
+ const recursiveResult = walker(value, identities, superJson, dedupe, [...path, index], [...objectsInThisPath, object], seenObjects);
124
+ transformedValue[index] = recursiveResult.transformedValue;
125
+ if (is.isArray(recursiveResult.annotations)) {
126
+ innerAnnotations[index] = recursiveResult.annotations;
127
+ } else if (is.isPlainObject(recursiveResult.annotations)) {
128
+ util.forEach(recursiveResult.annotations, (tree, key) => {
129
+ innerAnnotations[pathstringifier.escapeKey(index) + "." + key] = tree;
130
+ });
131
+ }
132
+ });
133
+ const result = is.isEmptyObject(innerAnnotations) ? {
134
+ transformedValue,
135
+ annotations: !!transformationResult ? [transformationResult.type] : void 0
136
+ } : {
137
+ transformedValue,
138
+ annotations: !!transformationResult ? [transformationResult.type, innerAnnotations] : innerAnnotations
139
+ };
140
+ if (!primitive) {
141
+ seenObjects.set(object, result);
142
+ }
143
+ return result;
144
+ };
145
+ exports.applyReferentialEqualityAnnotations = applyReferentialEqualityAnnotations;
146
+ exports.applyValueAnnotations = applyValueAnnotations;
147
+ exports.generateReferentialEqualityAnnotations = generateReferentialEqualityAnnotations;
148
+ exports.walker = walker;
@@ -0,0 +1,148 @@
1
+ import { isArray, isEmptyObject, isPrimitive, isPlainObject, isMap, isSet } from "./is.qwik.mjs";
2
+ import { parsePath, stringifyPath, escapeKey } from "./pathstringifier.qwik.mjs";
3
+ import { transformValue, untransformValue, isInstanceOfRegisteredClass } from "./transformer.qwik.mjs";
4
+ import { forEach, includes } from "./util.qwik.mjs";
5
+ import { setDeep, getDeep } from "./accessDeep.qwik.mjs";
6
+ function traverse(tree, walker2, origin = []) {
7
+ if (!tree) {
8
+ return;
9
+ }
10
+ if (!isArray(tree)) {
11
+ forEach(tree, (subtree, key) => traverse(subtree, walker2, [...origin, ...parsePath(key)]));
12
+ return;
13
+ }
14
+ const [nodeValue, children] = tree;
15
+ if (children) {
16
+ forEach(children, (child, key) => {
17
+ traverse(child, walker2, [...origin, ...parsePath(key)]);
18
+ });
19
+ }
20
+ walker2(nodeValue, origin);
21
+ }
22
+ function applyValueAnnotations(plain, annotations, superJson) {
23
+ traverse(annotations, (type, path) => {
24
+ plain = setDeep(plain, path, (v) => untransformValue(v, type, superJson));
25
+ });
26
+ return plain;
27
+ }
28
+ function applyReferentialEqualityAnnotations(plain, annotations) {
29
+ function apply(identicalPaths, path) {
30
+ const object = getDeep(plain, parsePath(path));
31
+ identicalPaths.map(parsePath).forEach((identicalObjectPath) => {
32
+ plain = setDeep(plain, identicalObjectPath, () => object);
33
+ });
34
+ }
35
+ if (isArray(annotations)) {
36
+ const [root, other] = annotations;
37
+ root.forEach((identicalPath) => {
38
+ plain = setDeep(plain, parsePath(identicalPath), () => plain);
39
+ });
40
+ if (other) {
41
+ forEach(other, apply);
42
+ }
43
+ } else {
44
+ forEach(annotations, apply);
45
+ }
46
+ return plain;
47
+ }
48
+ const isDeep = (object, superJson) => isPlainObject(object) || isArray(object) || isMap(object) || isSet(object) || isInstanceOfRegisteredClass(object, superJson);
49
+ function addIdentity(object, path, identities) {
50
+ const existingSet = identities.get(object);
51
+ if (existingSet) {
52
+ existingSet.push(path);
53
+ } else {
54
+ identities.set(object, [path]);
55
+ }
56
+ }
57
+ function generateReferentialEqualityAnnotations(identitites, dedupe) {
58
+ const result = {};
59
+ let rootEqualityPaths = void 0;
60
+ identitites.forEach((paths) => {
61
+ if (paths.length <= 1) {
62
+ return;
63
+ }
64
+ if (!dedupe) {
65
+ paths = paths.map((path) => path.map(String)).sort((a, b) => a.length - b.length);
66
+ }
67
+ const [representativePath, ...identicalPaths] = paths;
68
+ if (representativePath.length === 0) {
69
+ rootEqualityPaths = identicalPaths.map(stringifyPath);
70
+ } else {
71
+ result[stringifyPath(representativePath)] = identicalPaths.map(stringifyPath);
72
+ }
73
+ });
74
+ if (rootEqualityPaths) {
75
+ if (isEmptyObject(result)) {
76
+ return [rootEqualityPaths];
77
+ } else {
78
+ return [rootEqualityPaths, result];
79
+ }
80
+ } else {
81
+ return isEmptyObject(result) ? void 0 : result;
82
+ }
83
+ }
84
+ const walker = (object, identities, superJson, dedupe, path = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
85
+ const primitive = isPrimitive(object);
86
+ if (!primitive) {
87
+ addIdentity(object, path, identities);
88
+ const seen = seenObjects.get(object);
89
+ if (seen) {
90
+ return dedupe ? {
91
+ transformedValue: null
92
+ } : seen;
93
+ }
94
+ }
95
+ if (!isDeep(object, superJson)) {
96
+ const transformed2 = transformValue(object, superJson);
97
+ const result2 = transformed2 ? {
98
+ transformedValue: transformed2.value,
99
+ annotations: [transformed2.type]
100
+ } : {
101
+ transformedValue: object
102
+ };
103
+ if (!primitive) {
104
+ seenObjects.set(object, result2);
105
+ }
106
+ return result2;
107
+ }
108
+ if (includes(objectsInThisPath, object)) {
109
+ return {
110
+ transformedValue: null
111
+ };
112
+ }
113
+ const transformationResult = transformValue(object, superJson);
114
+ const transformed = transformationResult?.value ?? object;
115
+ const transformedValue = isArray(transformed) ? [] : {};
116
+ const innerAnnotations = {};
117
+ forEach(transformed, (value, index) => {
118
+ if (index === "__proto__" || index === "constructor" || index === "prototype") {
119
+ throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
120
+ }
121
+ const recursiveResult = walker(value, identities, superJson, dedupe, [...path, index], [...objectsInThisPath, object], seenObjects);
122
+ transformedValue[index] = recursiveResult.transformedValue;
123
+ if (isArray(recursiveResult.annotations)) {
124
+ innerAnnotations[index] = recursiveResult.annotations;
125
+ } else if (isPlainObject(recursiveResult.annotations)) {
126
+ forEach(recursiveResult.annotations, (tree, key) => {
127
+ innerAnnotations[escapeKey(index) + "." + key] = tree;
128
+ });
129
+ }
130
+ });
131
+ const result = isEmptyObject(innerAnnotations) ? {
132
+ transformedValue,
133
+ annotations: !!transformationResult ? [transformationResult.type] : void 0
134
+ } : {
135
+ transformedValue,
136
+ annotations: !!transformationResult ? [transformationResult.type, innerAnnotations] : innerAnnotations
137
+ };
138
+ if (!primitive) {
139
+ seenObjects.set(object, result);
140
+ }
141
+ return result;
142
+ };
143
+ export {
144
+ applyReferentialEqualityAnnotations,
145
+ applyValueAnnotations,
146
+ generateReferentialEqualityAnnotations,
147
+ walker
148
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const doubleIndexedKv = require("./double-indexed-kv.qwik.cjs");
4
+ class Registry {
5
+ constructor(generateIdentifier) {
6
+ this.generateIdentifier = generateIdentifier;
7
+ this.kv = new doubleIndexedKv.DoubleIndexedKV();
8
+ }
9
+ register(value, identifier) {
10
+ if (this.kv.getByValue(value)) {
11
+ return;
12
+ }
13
+ if (!identifier) {
14
+ identifier = this.generateIdentifier(value);
15
+ }
16
+ this.kv.set(identifier, value);
17
+ }
18
+ clear() {
19
+ this.kv.clear();
20
+ }
21
+ getIdentifier(value) {
22
+ return this.kv.getByValue(value);
23
+ }
24
+ getValue(identifier) {
25
+ return this.kv.getByKey(identifier);
26
+ }
27
+ }
28
+ exports.Registry = Registry;
@@ -0,0 +1,28 @@
1
+ import { DoubleIndexedKV } from "./double-indexed-kv.qwik.mjs";
2
+ class Registry {
3
+ constructor(generateIdentifier) {
4
+ this.generateIdentifier = generateIdentifier;
5
+ this.kv = new DoubleIndexedKV();
6
+ }
7
+ register(value, identifier) {
8
+ if (this.kv.getByValue(value)) {
9
+ return;
10
+ }
11
+ if (!identifier) {
12
+ identifier = this.generateIdentifier(value);
13
+ }
14
+ this.kv.set(identifier, value);
15
+ }
16
+ clear() {
17
+ this.kv.clear();
18
+ }
19
+ getIdentifier(value) {
20
+ return this.kv.getByValue(value);
21
+ }
22
+ getValue(identifier) {
23
+ return this.kv.getByKey(identifier);
24
+ }
25
+ }
26
+ export {
27
+ Registry
28
+ };
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const is = require("./is.qwik.cjs");
4
+ const util = require("./util.qwik.cjs");
5
+ function simpleTransformation(isApplicable, annotation, transform, untransform) {
6
+ return {
7
+ isApplicable,
8
+ annotation,
9
+ transform,
10
+ untransform
11
+ };
12
+ }
13
+ const simpleRules = [
14
+ simpleTransformation(is.isUndefined, "undefined", () => null, () => void 0),
15
+ simpleTransformation(is.isBigint, "bigint", (v) => v.toString(), (v) => {
16
+ if (typeof BigInt !== "undefined") {
17
+ return BigInt(v);
18
+ }
19
+ console.error("Please add a BigInt polyfill.");
20
+ return v;
21
+ }),
22
+ simpleTransformation(is.isDate, "Date", (v) => v.toISOString(), (v) => new Date(v)),
23
+ simpleTransformation(is.isError, "Error", (v, superJson) => {
24
+ const baseError = {
25
+ name: v.name,
26
+ message: v.message
27
+ };
28
+ superJson.allowedErrorProps.forEach((prop) => {
29
+ baseError[prop] = v[prop];
30
+ });
31
+ return baseError;
32
+ }, (v, superJson) => {
33
+ const e = new Error(v.message);
34
+ e.name = v.name;
35
+ e.stack = v.stack;
36
+ superJson.allowedErrorProps.forEach((prop) => {
37
+ e[prop] = v[prop];
38
+ });
39
+ return e;
40
+ }),
41
+ simpleTransformation(is.isRegExp, "regexp", (v) => "" + v, (regex) => {
42
+ const body = regex.slice(1, regex.lastIndexOf("/"));
43
+ const flags = regex.slice(regex.lastIndexOf("/") + 1);
44
+ return new RegExp(body, flags);
45
+ }),
46
+ simpleTransformation(
47
+ is.isSet,
48
+ "set",
49
+ // (sets only exist in es6+)
50
+ // eslint-disable-next-line es5/no-es6-methods
51
+ (v) => [...v.values()],
52
+ (v) => new Set(v)
53
+ ),
54
+ simpleTransformation(is.isMap, "map", (v) => [...v.entries()], (v) => new Map(v)),
55
+ simpleTransformation((v) => is.isNaNValue(v) || is.isInfinite(v), "number", (v) => {
56
+ if (is.isNaNValue(v)) {
57
+ return "NaN";
58
+ }
59
+ if (v > 0) {
60
+ return "Infinity";
61
+ } else {
62
+ return "-Infinity";
63
+ }
64
+ }, Number),
65
+ simpleTransformation((v) => v === 0 && 1 / v === -Infinity, "number", () => {
66
+ return "-0";
67
+ }, Number),
68
+ simpleTransformation(is.isURL, "URL", (v) => v.toString(), (v) => new URL(v))
69
+ ];
70
+ function compositeTransformation(isApplicable, annotation, transform, untransform) {
71
+ return {
72
+ isApplicable,
73
+ annotation,
74
+ transform,
75
+ untransform
76
+ };
77
+ }
78
+ const symbolRule = compositeTransformation((s, superJson) => {
79
+ if (is.isSymbol(s)) {
80
+ const isRegistered = !!superJson.symbolRegistry.getIdentifier(s);
81
+ return isRegistered;
82
+ }
83
+ return false;
84
+ }, (s, superJson) => {
85
+ const identifier = superJson.symbolRegistry.getIdentifier(s);
86
+ return ["symbol", identifier];
87
+ }, (v) => v.description, (_, a, superJson) => {
88
+ const value = superJson.symbolRegistry.getValue(a[1]);
89
+ if (!value) {
90
+ throw new Error("Trying to deserialize unknown symbol");
91
+ }
92
+ return value;
93
+ });
94
+ const constructorToName = [
95
+ Int8Array,
96
+ Uint8Array,
97
+ Int16Array,
98
+ Uint16Array,
99
+ Int32Array,
100
+ Uint32Array,
101
+ Float32Array,
102
+ Float64Array,
103
+ Uint8ClampedArray
104
+ ].reduce((obj, ctor) => {
105
+ obj[ctor.name] = ctor;
106
+ return obj;
107
+ }, {});
108
+ const typedArrayRule = compositeTransformation(is.isTypedArray, (v) => ["typed-array", v.constructor.name], (v) => [...v], (v, a) => {
109
+ const ctor = constructorToName[a[1]];
110
+ if (!ctor) {
111
+ throw new Error("Trying to deserialize unknown typed array");
112
+ }
113
+ return new ctor(v);
114
+ });
115
+ function isInstanceOfRegisteredClass(potentialClass, superJson) {
116
+ if (potentialClass?.constructor) {
117
+ const isRegistered = !!superJson.classRegistry.getIdentifier(potentialClass.constructor);
118
+ return isRegistered;
119
+ }
120
+ return false;
121
+ }
122
+ const classRule = compositeTransformation(isInstanceOfRegisteredClass, (clazz, superJson) => {
123
+ const identifier = superJson.classRegistry.getIdentifier(clazz.constructor);
124
+ return ["class", identifier];
125
+ }, (clazz, superJson) => {
126
+ const allowedProps = superJson.classRegistry.getAllowedProps(clazz.constructor);
127
+ if (!allowedProps) {
128
+ return { ...clazz };
129
+ }
130
+ const result = {};
131
+ allowedProps.forEach((prop) => {
132
+ result[prop] = clazz[prop];
133
+ });
134
+ return result;
135
+ }, (v, a, superJson) => {
136
+ const clazz = superJson.classRegistry.getValue(a[1]);
137
+ if (!clazz) {
138
+ throw new Error(`Trying to deserialize unknown class '${a[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);
139
+ }
140
+ return Object.assign(Object.create(clazz.prototype), v);
141
+ });
142
+ const customRule = compositeTransformation((value, superJson) => {
143
+ return !!superJson.customTransformerRegistry.findApplicable(value);
144
+ }, (value, superJson) => {
145
+ const transformer = superJson.customTransformerRegistry.findApplicable(value);
146
+ return ["custom", transformer.name];
147
+ }, (value, superJson) => {
148
+ const transformer = superJson.customTransformerRegistry.findApplicable(value);
149
+ return transformer.serialize(value);
150
+ }, (v, a, superJson) => {
151
+ const transformer = superJson.customTransformerRegistry.findByName(a[1]);
152
+ if (!transformer) {
153
+ throw new Error("Trying to deserialize unknown custom value");
154
+ }
155
+ return transformer.deserialize(v);
156
+ });
157
+ const compositeRules = [classRule, symbolRule, customRule, typedArrayRule];
158
+ const transformValue = (value, superJson) => {
159
+ const applicableCompositeRule = util.findArr(compositeRules, (rule) => rule.isApplicable(value, superJson));
160
+ if (applicableCompositeRule) {
161
+ return {
162
+ value: applicableCompositeRule.transform(value, superJson),
163
+ type: applicableCompositeRule.annotation(value, superJson)
164
+ };
165
+ }
166
+ const applicableSimpleRule = util.findArr(simpleRules, (rule) => rule.isApplicable(value, superJson));
167
+ if (applicableSimpleRule) {
168
+ return {
169
+ value: applicableSimpleRule.transform(value, superJson),
170
+ type: applicableSimpleRule.annotation
171
+ };
172
+ }
173
+ return void 0;
174
+ };
175
+ const simpleRulesByAnnotation = {};
176
+ simpleRules.forEach((rule) => {
177
+ simpleRulesByAnnotation[rule.annotation] = rule;
178
+ });
179
+ const untransformValue = (json, type, superJson) => {
180
+ if (is.isArray(type)) {
181
+ switch (type[0]) {
182
+ case "symbol":
183
+ return symbolRule.untransform(json, type, superJson);
184
+ case "class":
185
+ return classRule.untransform(json, type, superJson);
186
+ case "custom":
187
+ return customRule.untransform(json, type, superJson);
188
+ case "typed-array":
189
+ return typedArrayRule.untransform(json, type, superJson);
190
+ default:
191
+ throw new Error("Unknown transformation: " + type);
192
+ }
193
+ } else {
194
+ const transformation = simpleRulesByAnnotation[type];
195
+ if (!transformation) {
196
+ throw new Error("Unknown transformation: " + type);
197
+ }
198
+ return transformation.untransform(json, superJson);
199
+ }
200
+ };
201
+ exports.isInstanceOfRegisteredClass = isInstanceOfRegisteredClass;
202
+ exports.transformValue = transformValue;
203
+ exports.untransformValue = untransformValue;