ru.Bee 1.3.3 → 1.5.0

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 (182) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rubee +36 -4
  3. data/lib/app/views/app.tsx +27 -0
  4. data/lib/app/views/apples_.erb +1 -0
  5. data/lib/app/views/index.html +47 -0
  6. data/lib/app/views/layout.erb +3 -3
  7. data/lib/app/views/utils/redirectToBackend.tsx +9 -0
  8. data/lib/app/views/welcome_show.erb +1 -1
  9. data/lib/config/base_configuration.rb +9 -0
  10. data/lib/config/routes.rb +1 -0
  11. data/lib/esbuild.config.js +33 -0
  12. data/lib/js/app.js +13 -0
  13. data/lib/js/app.js.map +7 -0
  14. data/lib/js/bundle.js +26157 -0
  15. data/lib/js/bundle.js.map +7 -0
  16. data/lib/node_modules/@types/cookie/LICENSE +21 -0
  17. data/lib/node_modules/@types/cookie/README.md +15 -0
  18. data/lib/node_modules/@types/cookie/index.d.ts +154 -0
  19. data/lib/node_modules/@types/cookie/package.json +30 -0
  20. data/lib/node_modules/cookie/LICENSE +24 -0
  21. data/lib/node_modules/cookie/README.md +248 -0
  22. data/lib/node_modules/cookie/dist/index.d.ts +114 -0
  23. data/lib/node_modules/cookie/dist/index.js +239 -0
  24. data/lib/node_modules/cookie/dist/index.js.map +1 -0
  25. data/lib/node_modules/cookie/package.json +42 -0
  26. data/lib/node_modules/js-tokens/CHANGELOG.md +151 -0
  27. data/lib/node_modules/js-tokens/LICENSE +21 -0
  28. data/lib/node_modules/js-tokens/README.md +240 -0
  29. data/lib/node_modules/js-tokens/index.js +23 -0
  30. data/lib/node_modules/js-tokens/package.json +30 -0
  31. data/lib/node_modules/loose-envify/LICENSE +21 -0
  32. data/lib/node_modules/loose-envify/README.md +45 -0
  33. data/lib/node_modules/loose-envify/cli.js +16 -0
  34. data/lib/node_modules/loose-envify/custom.js +4 -0
  35. data/lib/node_modules/loose-envify/index.js +3 -0
  36. data/lib/node_modules/loose-envify/loose-envify.js +36 -0
  37. data/lib/node_modules/loose-envify/package.json +36 -0
  38. data/lib/node_modules/loose-envify/replace.js +65 -0
  39. data/lib/node_modules/react/LICENSE +21 -0
  40. data/lib/node_modules/react/README.md +37 -0
  41. data/lib/node_modules/react/cjs/react-jsx-dev-runtime.development.js +1315 -0
  42. data/lib/node_modules/react/cjs/react-jsx-dev-runtime.production.min.js +10 -0
  43. data/lib/node_modules/react/cjs/react-jsx-dev-runtime.profiling.min.js +10 -0
  44. data/lib/node_modules/react/cjs/react-jsx-runtime.development.js +1333 -0
  45. data/lib/node_modules/react/cjs/react-jsx-runtime.production.min.js +11 -0
  46. data/lib/node_modules/react/cjs/react-jsx-runtime.profiling.min.js +11 -0
  47. data/lib/node_modules/react/cjs/react.development.js +2740 -0
  48. data/lib/node_modules/react/cjs/react.production.min.js +26 -0
  49. data/lib/node_modules/react/cjs/react.shared-subset.development.js +20 -0
  50. data/lib/node_modules/react/cjs/react.shared-subset.production.min.js +10 -0
  51. data/lib/node_modules/react/index.js +7 -0
  52. data/lib/node_modules/react/jsx-dev-runtime.js +7 -0
  53. data/lib/node_modules/react/jsx-runtime.js +7 -0
  54. data/lib/node_modules/react/package.json +47 -0
  55. data/lib/node_modules/react/react.shared-subset.js +7 -0
  56. data/lib/node_modules/react/umd/react.development.js +3343 -0
  57. data/lib/node_modules/react/umd/react.production.min.js +31 -0
  58. data/lib/node_modules/react/umd/react.profiling.min.js +31 -0
  59. data/lib/node_modules/react-dom/LICENSE +21 -0
  60. data/lib/node_modules/react-dom/README.md +60 -0
  61. data/lib/node_modules/react-dom/cjs/react-dom-server-legacy.browser.development.js +7029 -0
  62. data/lib/node_modules/react-dom/cjs/react-dom-server-legacy.browser.production.min.js +93 -0
  63. data/lib/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js +7093 -0
  64. data/lib/node_modules/react-dom/cjs/react-dom-server-legacy.node.production.min.js +101 -0
  65. data/lib/node_modules/react-dom/cjs/react-dom-server.browser.development.js +7014 -0
  66. data/lib/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js +96 -0
  67. data/lib/node_modules/react-dom/cjs/react-dom-server.node.development.js +7070 -0
  68. data/lib/node_modules/react-dom/cjs/react-dom-server.node.production.min.js +102 -0
  69. data/lib/node_modules/react-dom/cjs/react-dom-test-utils.development.js +1763 -0
  70. data/lib/node_modules/react-dom/cjs/react-dom-test-utils.production.min.js +40 -0
  71. data/lib/node_modules/react-dom/cjs/react-dom.development.js +29923 -0
  72. data/lib/node_modules/react-dom/cjs/react-dom.production.min.js +322 -0
  73. data/lib/node_modules/react-dom/cjs/react-dom.profiling.min.js +366 -0
  74. data/lib/node_modules/react-dom/client.js +25 -0
  75. data/lib/node_modules/react-dom/index.js +38 -0
  76. data/lib/node_modules/react-dom/package.json +62 -0
  77. data/lib/node_modules/react-dom/profiling.js +38 -0
  78. data/lib/node_modules/react-dom/server.browser.js +17 -0
  79. data/lib/node_modules/react-dom/server.js +3 -0
  80. data/lib/node_modules/react-dom/server.node.js +17 -0
  81. data/lib/node_modules/react-dom/test-utils.js +7 -0
  82. data/lib/node_modules/react-dom/umd/react-dom-server-legacy.browser.development.js +7026 -0
  83. data/lib/node_modules/react-dom/umd/react-dom-server-legacy.browser.production.min.js +75 -0
  84. data/lib/node_modules/react-dom/umd/react-dom-server.browser.development.js +7011 -0
  85. data/lib/node_modules/react-dom/umd/react-dom-server.browser.production.min.js +76 -0
  86. data/lib/node_modules/react-dom/umd/react-dom-test-utils.development.js +1759 -0
  87. data/lib/node_modules/react-dom/umd/react-dom-test-utils.production.min.js +33 -0
  88. data/lib/node_modules/react-dom/umd/react-dom.development.js +29924 -0
  89. data/lib/node_modules/react-dom/umd/react-dom.production.min.js +267 -0
  90. data/lib/node_modules/react-dom/umd/react-dom.profiling.min.js +285 -0
  91. data/lib/node_modules/react-router/CHANGELOG.md +1526 -0
  92. data/lib/node_modules/react-router/LICENSE.md +23 -0
  93. data/lib/node_modules/react-router/README.md +7 -0
  94. data/lib/node_modules/react-router/dist/development/chunk-KNED5TY2.mjs +10476 -0
  95. data/lib/node_modules/react-router/dist/development/dom-export.d.mts +23 -0
  96. data/lib/node_modules/react-router/dist/development/dom-export.d.ts +23 -0
  97. data/lib/node_modules/react-router/dist/development/dom-export.js +6111 -0
  98. data/lib/node_modules/react-router/dist/development/dom-export.mjs +234 -0
  99. data/lib/node_modules/react-router/dist/development/fog-of-war-1hWhK5ey.d.mts +1690 -0
  100. data/lib/node_modules/react-router/dist/development/fog-of-war-oa9CGk10.d.ts +1690 -0
  101. data/lib/node_modules/react-router/dist/development/future-ldDp5FKH.d.mts +21 -0
  102. data/lib/node_modules/react-router/dist/development/future-ldDp5FKH.d.ts +21 -0
  103. data/lib/node_modules/react-router/dist/development/index.d.mts +841 -0
  104. data/lib/node_modules/react-router/dist/development/index.d.ts +841 -0
  105. data/lib/node_modules/react-router/dist/development/index.js +10624 -0
  106. data/lib/node_modules/react-router/dist/development/index.mjs +242 -0
  107. data/lib/node_modules/react-router/dist/development/lib/types/route-module.d.mts +209 -0
  108. data/lib/node_modules/react-router/dist/development/lib/types/route-module.d.ts +209 -0
  109. data/lib/node_modules/react-router/dist/development/lib/types/route-module.js +28 -0
  110. data/lib/node_modules/react-router/dist/development/lib/types/route-module.mjs +10 -0
  111. data/lib/node_modules/react-router/dist/development/route-data-5OzAzQtT.d.mts +1716 -0
  112. data/lib/node_modules/react-router/dist/development/route-data-5OzAzQtT.d.ts +1716 -0
  113. data/lib/node_modules/react-router/dist/production/chunk-ZIM7OIE3.mjs +10476 -0
  114. data/lib/node_modules/react-router/dist/production/dom-export.d.mts +23 -0
  115. data/lib/node_modules/react-router/dist/production/dom-export.d.ts +23 -0
  116. data/lib/node_modules/react-router/dist/production/dom-export.js +6111 -0
  117. data/lib/node_modules/react-router/dist/production/dom-export.mjs +234 -0
  118. data/lib/node_modules/react-router/dist/production/fog-of-war-1hWhK5ey.d.mts +1690 -0
  119. data/lib/node_modules/react-router/dist/production/fog-of-war-oa9CGk10.d.ts +1690 -0
  120. data/lib/node_modules/react-router/dist/production/future-ldDp5FKH.d.mts +21 -0
  121. data/lib/node_modules/react-router/dist/production/future-ldDp5FKH.d.ts +21 -0
  122. data/lib/node_modules/react-router/dist/production/index.d.mts +841 -0
  123. data/lib/node_modules/react-router/dist/production/index.d.ts +841 -0
  124. data/lib/node_modules/react-router/dist/production/index.js +10624 -0
  125. data/lib/node_modules/react-router/dist/production/index.mjs +242 -0
  126. data/lib/node_modules/react-router/dist/production/lib/types/route-module.d.mts +209 -0
  127. data/lib/node_modules/react-router/dist/production/lib/types/route-module.d.ts +209 -0
  128. data/lib/node_modules/react-router/dist/production/lib/types/route-module.js +28 -0
  129. data/lib/node_modules/react-router/dist/production/lib/types/route-module.mjs +10 -0
  130. data/lib/node_modules/react-router/dist/production/route-data-5OzAzQtT.d.mts +1716 -0
  131. data/lib/node_modules/react-router/dist/production/route-data-5OzAzQtT.d.ts +1716 -0
  132. data/lib/node_modules/react-router/package.json +116 -0
  133. data/lib/node_modules/react-router-dom/LICENSE.md +23 -0
  134. data/lib/node_modules/react-router-dom/README.md +6 -0
  135. data/lib/node_modules/react-router-dom/dist/index.d.mts +2 -0
  136. data/lib/node_modules/react-router-dom/dist/index.d.ts +2 -0
  137. data/lib/node_modules/react-router-dom/dist/index.js +45 -0
  138. data/lib/node_modules/react-router-dom/dist/index.mjs +18 -0
  139. data/lib/node_modules/react-router-dom/package.json +82 -0
  140. data/lib/node_modules/scheduler/LICENSE +21 -0
  141. data/lib/node_modules/scheduler/README.md +9 -0
  142. data/lib/node_modules/scheduler/cjs/scheduler-unstable_mock.development.js +700 -0
  143. data/lib/node_modules/scheduler/cjs/scheduler-unstable_mock.production.min.js +20 -0
  144. data/lib/node_modules/scheduler/cjs/scheduler-unstable_post_task.development.js +207 -0
  145. data/lib/node_modules/scheduler/cjs/scheduler-unstable_post_task.production.min.js +14 -0
  146. data/lib/node_modules/scheduler/cjs/scheduler.development.js +634 -0
  147. data/lib/node_modules/scheduler/cjs/scheduler.production.min.js +19 -0
  148. data/lib/node_modules/scheduler/index.js +7 -0
  149. data/lib/node_modules/scheduler/package.json +36 -0
  150. data/lib/node_modules/scheduler/umd/scheduler-unstable_mock.development.js +699 -0
  151. data/lib/node_modules/scheduler/umd/scheduler-unstable_mock.production.min.js +19 -0
  152. data/lib/node_modules/scheduler/umd/scheduler.development.js +152 -0
  153. data/lib/node_modules/scheduler/umd/scheduler.production.min.js +146 -0
  154. data/lib/node_modules/scheduler/umd/scheduler.profiling.min.js +146 -0
  155. data/lib/node_modules/scheduler/unstable_mock.js +7 -0
  156. data/lib/node_modules/scheduler/unstable_post_task.js +7 -0
  157. data/lib/node_modules/set-cookie-parser/LICENSE +21 -0
  158. data/lib/node_modules/set-cookie-parser/README.md +202 -0
  159. data/lib/node_modules/set-cookie-parser/lib/set-cookie.js +224 -0
  160. data/lib/node_modules/set-cookie-parser/package.json +45 -0
  161. data/lib/node_modules/turbo-stream/LICENSE +7 -0
  162. data/lib/node_modules/turbo-stream/README.md +31 -0
  163. data/lib/node_modules/turbo-stream/dist/flatten.d.ts +2 -0
  164. data/lib/node_modules/turbo-stream/dist/flatten.js +203 -0
  165. data/lib/node_modules/turbo-stream/dist/turbo-stream.d.ts +13 -0
  166. data/lib/node_modules/turbo-stream/dist/turbo-stream.js +207 -0
  167. data/lib/node_modules/turbo-stream/dist/turbo-stream.mjs +673 -0
  168. data/lib/node_modules/turbo-stream/dist/unflatten.d.ts +2 -0
  169. data/lib/node_modules/turbo-stream/dist/unflatten.js +243 -0
  170. data/lib/node_modules/turbo-stream/dist/utils.d.ts +44 -0
  171. data/lib/node_modules/turbo-stream/dist/utils.js +55 -0
  172. data/lib/node_modules/turbo-stream/package.json +50 -0
  173. data/lib/package-lock.json +133 -0
  174. data/lib/package.json +12 -0
  175. data/lib/rubee/controllers/base_controller.rb +14 -0
  176. data/lib/rubee.rb +100 -21
  177. data/lib/tests/rubee_generator_test.rb +190 -0
  178. data/lib/tests/rubeeapp_test.rb +12 -0
  179. data/lib/tests/test.db +0 -0
  180. data/lib/tests/user_model_test.rb +5 -0
  181. data/readme.md +288 -64
  182. metadata +172 -3
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flatten = void 0;
4
+ const utils_js_1 = require("./utils.js");
5
+ function flatten(input) {
6
+ const { indices } = this;
7
+ const existing = indices.get(input);
8
+ if (existing)
9
+ return [existing];
10
+ if (input === undefined)
11
+ return utils_js_1.UNDEFINED;
12
+ if (input === null)
13
+ return utils_js_1.NULL;
14
+ if (Number.isNaN(input))
15
+ return utils_js_1.NAN;
16
+ if (input === Number.POSITIVE_INFINITY)
17
+ return utils_js_1.POSITIVE_INFINITY;
18
+ if (input === Number.NEGATIVE_INFINITY)
19
+ return utils_js_1.NEGATIVE_INFINITY;
20
+ if (input === 0 && 1 / input < 0)
21
+ return utils_js_1.NEGATIVE_ZERO;
22
+ const index = this.index++;
23
+ indices.set(input, index);
24
+ stringify.call(this, input, index);
25
+ return index;
26
+ }
27
+ exports.flatten = flatten;
28
+ function stringify(input, index) {
29
+ const { deferred, plugins, postPlugins } = this;
30
+ const str = this.stringified;
31
+ const stack = [[input, index]];
32
+ while (stack.length > 0) {
33
+ const [input, index] = stack.pop();
34
+ const partsForObj = (obj) => Object.keys(obj)
35
+ .map((k) => `"_${flatten.call(this, k)}":${flatten.call(this, obj[k])}`)
36
+ .join(",");
37
+ let error = null;
38
+ switch (typeof input) {
39
+ case "boolean":
40
+ case "number":
41
+ case "string":
42
+ str[index] = JSON.stringify(input);
43
+ break;
44
+ case "bigint":
45
+ str[index] = `["${utils_js_1.TYPE_BIGINT}","${input}"]`;
46
+ break;
47
+ case "symbol": {
48
+ const keyFor = Symbol.keyFor(input);
49
+ if (!keyFor) {
50
+ error = new Error("Cannot encode symbol unless created with Symbol.for()");
51
+ }
52
+ else {
53
+ str[index] = `["${utils_js_1.TYPE_SYMBOL}",${JSON.stringify(keyFor)}]`;
54
+ }
55
+ break;
56
+ }
57
+ case "object": {
58
+ if (!input) {
59
+ str[index] = `${utils_js_1.NULL}`;
60
+ break;
61
+ }
62
+ const isArray = Array.isArray(input);
63
+ let pluginHandled = false;
64
+ if (!isArray && plugins) {
65
+ for (const plugin of plugins) {
66
+ const pluginResult = plugin(input);
67
+ if (Array.isArray(pluginResult)) {
68
+ pluginHandled = true;
69
+ const [pluginIdentifier, ...rest] = pluginResult;
70
+ str[index] = `[${JSON.stringify(pluginIdentifier)}`;
71
+ if (rest.length > 0) {
72
+ str[index] += `,${rest
73
+ .map((v) => flatten.call(this, v))
74
+ .join(",")}`;
75
+ }
76
+ str[index] += "]";
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ if (!pluginHandled) {
82
+ let result = isArray ? "[" : "{";
83
+ if (isArray) {
84
+ for (let i = 0; i < input.length; i++)
85
+ result +=
86
+ (i ? "," : "") +
87
+ (i in input ? flatten.call(this, input[i]) : utils_js_1.HOLE);
88
+ str[index] = `${result}]`;
89
+ }
90
+ else if (input instanceof Date) {
91
+ str[index] = `["${utils_js_1.TYPE_DATE}",${input.getTime()}]`;
92
+ }
93
+ else if (input instanceof URL) {
94
+ str[index] = `["${utils_js_1.TYPE_URL}",${JSON.stringify(input.href)}]`;
95
+ }
96
+ else if (input instanceof RegExp) {
97
+ str[index] = `["${utils_js_1.TYPE_REGEXP}",${JSON.stringify(input.source)},${JSON.stringify(input.flags)}]`;
98
+ }
99
+ else if (input instanceof Set) {
100
+ if (input.size > 0) {
101
+ str[index] = `["${utils_js_1.TYPE_SET}",${[...input]
102
+ .map((val) => flatten.call(this, val))
103
+ .join(",")}]`;
104
+ }
105
+ else {
106
+ str[index] = `["${utils_js_1.TYPE_SET}"]`;
107
+ }
108
+ }
109
+ else if (input instanceof Map) {
110
+ if (input.size > 0) {
111
+ str[index] = `["${utils_js_1.TYPE_MAP}",${[...input]
112
+ .flatMap(([k, v]) => [
113
+ flatten.call(this, k),
114
+ flatten.call(this, v),
115
+ ])
116
+ .join(",")}]`;
117
+ }
118
+ else {
119
+ str[index] = `["${utils_js_1.TYPE_MAP}"]`;
120
+ }
121
+ }
122
+ else if (input instanceof Promise) {
123
+ str[index] = `["${utils_js_1.TYPE_PROMISE}",${index}]`;
124
+ deferred[index] = input;
125
+ }
126
+ else if (input instanceof Error) {
127
+ str[index] = `["${utils_js_1.TYPE_ERROR}",${JSON.stringify(input.message)}`;
128
+ if (input.name !== "Error") {
129
+ str[index] += `,${JSON.stringify(input.name)}`;
130
+ }
131
+ str[index] += "]";
132
+ }
133
+ else if (Object.getPrototypeOf(input) === null) {
134
+ str[index] = `["${utils_js_1.TYPE_NULL_OBJECT}",{${partsForObj(input)}}]`;
135
+ }
136
+ else if (isPlainObject(input)) {
137
+ str[index] = `{${partsForObj(input)}}`;
138
+ }
139
+ else {
140
+ error = new Error("Cannot encode object with prototype");
141
+ }
142
+ }
143
+ break;
144
+ }
145
+ default: {
146
+ const isArray = Array.isArray(input);
147
+ let pluginHandled = false;
148
+ if (!isArray && plugins) {
149
+ for (const plugin of plugins) {
150
+ const pluginResult = plugin(input);
151
+ if (Array.isArray(pluginResult)) {
152
+ pluginHandled = true;
153
+ const [pluginIdentifier, ...rest] = pluginResult;
154
+ str[index] = `[${JSON.stringify(pluginIdentifier)}`;
155
+ if (rest.length > 0) {
156
+ str[index] += `,${rest
157
+ .map((v) => flatten.call(this, v))
158
+ .join(",")}`;
159
+ }
160
+ str[index] += "]";
161
+ break;
162
+ }
163
+ }
164
+ }
165
+ if (!pluginHandled) {
166
+ error = new Error("Cannot encode function or unexpected type");
167
+ }
168
+ }
169
+ }
170
+ if (error) {
171
+ let pluginHandled = false;
172
+ if (postPlugins) {
173
+ for (const plugin of postPlugins) {
174
+ const pluginResult = plugin(input);
175
+ if (Array.isArray(pluginResult)) {
176
+ pluginHandled = true;
177
+ const [pluginIdentifier, ...rest] = pluginResult;
178
+ str[index] = `[${JSON.stringify(pluginIdentifier)}`;
179
+ if (rest.length > 0) {
180
+ str[index] += `,${rest
181
+ .map((v) => flatten.call(this, v))
182
+ .join(",")}`;
183
+ }
184
+ str[index] += "]";
185
+ break;
186
+ }
187
+ }
188
+ }
189
+ if (!pluginHandled) {
190
+ throw error;
191
+ }
192
+ }
193
+ }
194
+ }
195
+ const objectProtoNames = Object.getOwnPropertyNames(Object.prototype)
196
+ .sort()
197
+ .join("\0");
198
+ function isPlainObject(thing) {
199
+ const proto = Object.getPrototypeOf(thing);
200
+ return (proto === Object.prototype ||
201
+ proto === null ||
202
+ Object.getOwnPropertyNames(proto).sort().join("\0") === objectProtoNames);
203
+ }
@@ -0,0 +1,13 @@
1
+ import { type DecodePlugin, type EncodePlugin } from "./utils.js";
2
+ export type { DecodePlugin, EncodePlugin };
3
+ export declare function decode(readable: ReadableStream<Uint8Array>, options?: {
4
+ plugins?: DecodePlugin[];
5
+ }): Promise<{
6
+ done: Promise<undefined>;
7
+ value: unknown;
8
+ }>;
9
+ export declare function encode(input: unknown, options?: {
10
+ plugins?: EncodePlugin[];
11
+ postPlugins?: EncodePlugin[];
12
+ signal?: AbortSignal;
13
+ }): ReadableStream<Uint8Array>;
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encode = exports.decode = void 0;
4
+ const flatten_js_1 = require("./flatten.js");
5
+ const unflatten_js_1 = require("./unflatten.js");
6
+ const utils_js_1 = require("./utils.js");
7
+ async function decode(readable, options) {
8
+ const { plugins } = options ?? {};
9
+ const done = new utils_js_1.Deferred();
10
+ const reader = readable
11
+ .pipeThrough((0, utils_js_1.createLineSplittingTransform)())
12
+ .getReader();
13
+ const decoder = {
14
+ values: [],
15
+ hydrated: [],
16
+ deferred: {},
17
+ plugins,
18
+ };
19
+ const decoded = await decodeInitial.call(decoder, reader);
20
+ let donePromise = done.promise;
21
+ if (decoded.done) {
22
+ done.resolve();
23
+ }
24
+ else {
25
+ donePromise = decodeDeferred
26
+ .call(decoder, reader)
27
+ .then(done.resolve)
28
+ .catch((reason) => {
29
+ for (const deferred of Object.values(decoder.deferred)) {
30
+ deferred.reject(reason);
31
+ }
32
+ done.reject(reason);
33
+ });
34
+ }
35
+ return {
36
+ done: donePromise.then(() => reader.closed),
37
+ value: decoded.value,
38
+ };
39
+ }
40
+ exports.decode = decode;
41
+ async function decodeInitial(reader) {
42
+ const read = await reader.read();
43
+ if (!read.value) {
44
+ throw new SyntaxError();
45
+ }
46
+ let line;
47
+ try {
48
+ line = JSON.parse(read.value);
49
+ }
50
+ catch (reason) {
51
+ throw new SyntaxError();
52
+ }
53
+ return {
54
+ done: read.done,
55
+ value: unflatten_js_1.unflatten.call(this, line),
56
+ };
57
+ }
58
+ async function decodeDeferred(reader) {
59
+ let read = await reader.read();
60
+ while (!read.done) {
61
+ if (!read.value)
62
+ continue;
63
+ const line = read.value;
64
+ switch (line[0]) {
65
+ case utils_js_1.TYPE_PROMISE: {
66
+ const colonIndex = line.indexOf(":");
67
+ const deferredId = Number(line.slice(1, colonIndex));
68
+ const deferred = this.deferred[deferredId];
69
+ if (!deferred) {
70
+ throw new Error(`Deferred ID ${deferredId} not found in stream`);
71
+ }
72
+ const lineData = line.slice(colonIndex + 1);
73
+ let jsonLine;
74
+ try {
75
+ jsonLine = JSON.parse(lineData);
76
+ }
77
+ catch (reason) {
78
+ throw new SyntaxError();
79
+ }
80
+ const value = unflatten_js_1.unflatten.call(this, jsonLine);
81
+ deferred.resolve(value);
82
+ break;
83
+ }
84
+ case utils_js_1.TYPE_ERROR: {
85
+ const colonIndex = line.indexOf(":");
86
+ const deferredId = Number(line.slice(1, colonIndex));
87
+ const deferred = this.deferred[deferredId];
88
+ if (!deferred) {
89
+ throw new Error(`Deferred ID ${deferredId} not found in stream`);
90
+ }
91
+ const lineData = line.slice(colonIndex + 1);
92
+ let jsonLine;
93
+ try {
94
+ jsonLine = JSON.parse(lineData);
95
+ }
96
+ catch (reason) {
97
+ throw new SyntaxError();
98
+ }
99
+ const value = unflatten_js_1.unflatten.call(this, jsonLine);
100
+ deferred.reject(value);
101
+ break;
102
+ }
103
+ default:
104
+ throw new SyntaxError();
105
+ }
106
+ read = await reader.read();
107
+ }
108
+ }
109
+ function encode(input, options) {
110
+ const { plugins, postPlugins, signal } = options ?? {};
111
+ const encoder = {
112
+ deferred: {},
113
+ index: 0,
114
+ indices: new Map(),
115
+ stringified: [],
116
+ plugins,
117
+ postPlugins,
118
+ signal,
119
+ };
120
+ const textEncoder = new TextEncoder();
121
+ let lastSentIndex = 0;
122
+ const readable = new ReadableStream({
123
+ async start(controller) {
124
+ const id = flatten_js_1.flatten.call(encoder, input);
125
+ if (Array.isArray(id)) {
126
+ throw new Error("This should never happen");
127
+ }
128
+ if (id < 0) {
129
+ controller.enqueue(textEncoder.encode(`${id}\n`));
130
+ }
131
+ else {
132
+ controller.enqueue(textEncoder.encode(`[${encoder.stringified.join(",")}]\n`));
133
+ lastSentIndex = encoder.stringified.length - 1;
134
+ }
135
+ const seenPromises = new WeakSet();
136
+ while (Object.keys(encoder.deferred).length > 0) {
137
+ for (const [deferredId, deferred] of Object.entries(encoder.deferred)) {
138
+ if (seenPromises.has(deferred))
139
+ continue;
140
+ seenPromises.add((encoder.deferred[Number(deferredId)] = raceSignal(deferred, encoder.signal)
141
+ .then((resolved) => {
142
+ const id = flatten_js_1.flatten.call(encoder, resolved);
143
+ if (Array.isArray(id)) {
144
+ controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_PROMISE}${deferredId}:[["${utils_js_1.TYPE_PREVIOUS_RESOLVED}",${id[0]}]]\n`));
145
+ encoder.index++;
146
+ lastSentIndex++;
147
+ }
148
+ else if (id < 0) {
149
+ controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_PROMISE}${deferredId}:${id}\n`));
150
+ }
151
+ else {
152
+ const values = encoder.stringified
153
+ .slice(lastSentIndex + 1)
154
+ .join(",");
155
+ controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_PROMISE}${deferredId}:[${values}]\n`));
156
+ lastSentIndex = encoder.stringified.length - 1;
157
+ }
158
+ }, (reason) => {
159
+ if (!reason ||
160
+ typeof reason !== "object" ||
161
+ !(reason instanceof Error)) {
162
+ reason = new Error("An unknown error occurred");
163
+ }
164
+ const id = flatten_js_1.flatten.call(encoder, reason);
165
+ if (Array.isArray(id)) {
166
+ controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_ERROR}${deferredId}:[["${utils_js_1.TYPE_PREVIOUS_RESOLVED}",${id[0]}]]\n`));
167
+ encoder.index++;
168
+ lastSentIndex++;
169
+ }
170
+ else if (id < 0) {
171
+ controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_ERROR}${deferredId}:${id}\n`));
172
+ }
173
+ else {
174
+ const values = encoder.stringified
175
+ .slice(lastSentIndex + 1)
176
+ .join(",");
177
+ controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_ERROR}${deferredId}:[${values}]\n`));
178
+ lastSentIndex = encoder.stringified.length - 1;
179
+ }
180
+ })
181
+ .finally(() => {
182
+ delete encoder.deferred[Number(deferredId)];
183
+ })));
184
+ }
185
+ await Promise.race(Object.values(encoder.deferred));
186
+ }
187
+ await Promise.all(Object.values(encoder.deferred));
188
+ controller.close();
189
+ },
190
+ });
191
+ return readable;
192
+ }
193
+ exports.encode = encode;
194
+ function raceSignal(promise, signal) {
195
+ if (!signal)
196
+ return promise;
197
+ if (signal.aborted)
198
+ return Promise.reject(signal.reason || new Error("Signal was aborted."));
199
+ const abort = new Promise((resolve, reject) => {
200
+ signal.addEventListener("abort", (event) => {
201
+ reject(signal.reason || new Error("Signal was aborted."));
202
+ });
203
+ promise.then(resolve).catch(reject);
204
+ });
205
+ abort.catch(() => { });
206
+ return Promise.race([abort, promise]);
207
+ }