ru.Bee 1.3.2 → 1.4.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.
- checksums.yaml +4 -4
- data/bin/rubee +114 -88
- data/lib/app/views/app.tsx +27 -0
- data/lib/app/views/index.html +47 -0
- data/lib/app/views/layout.erb +3 -3
- data/lib/app/views/utils/redirectToBackend.tsx +9 -0
- data/lib/app/views/welcome_show.erb +1 -1
- data/lib/config/base_configuration.rb +15 -6
- data/lib/config/routes.rb +2 -1
- data/lib/db/create_accounts.rb +8 -8
- data/lib/db/create_comments.rb +7 -7
- data/lib/db/create_posts.rb +8 -8
- data/lib/db/create_users.rb +8 -8
- data/lib/db/structure.rb +42 -42
- data/lib/esbuild.config.js +33 -0
- data/lib/inits/print_colors.rb +1 -1
- data/lib/js/app.js +13 -0
- data/lib/js/app.js.map +7 -0
- data/lib/js/bundle.js +26157 -0
- data/lib/js/bundle.js.map +7 -0
- data/lib/node_modules/@types/cookie/LICENSE +21 -0
- data/lib/node_modules/@types/cookie/README.md +15 -0
- data/lib/node_modules/@types/cookie/index.d.ts +154 -0
- data/lib/node_modules/@types/cookie/package.json +30 -0
- data/lib/node_modules/cookie/LICENSE +24 -0
- data/lib/node_modules/cookie/README.md +248 -0
- data/lib/node_modules/cookie/dist/index.d.ts +114 -0
- data/lib/node_modules/cookie/dist/index.js +239 -0
- data/lib/node_modules/cookie/dist/index.js.map +1 -0
- data/lib/node_modules/cookie/package.json +42 -0
- data/lib/node_modules/js-tokens/CHANGELOG.md +151 -0
- data/lib/node_modules/js-tokens/LICENSE +21 -0
- data/lib/node_modules/js-tokens/README.md +240 -0
- data/lib/node_modules/js-tokens/index.js +23 -0
- data/lib/node_modules/js-tokens/package.json +30 -0
- data/lib/node_modules/loose-envify/LICENSE +21 -0
- data/lib/node_modules/loose-envify/README.md +45 -0
- data/lib/node_modules/loose-envify/cli.js +16 -0
- data/lib/node_modules/loose-envify/custom.js +4 -0
- data/lib/node_modules/loose-envify/index.js +3 -0
- data/lib/node_modules/loose-envify/loose-envify.js +36 -0
- data/lib/node_modules/loose-envify/package.json +36 -0
- data/lib/node_modules/loose-envify/replace.js +65 -0
- data/lib/node_modules/react/LICENSE +21 -0
- data/lib/node_modules/react/README.md +37 -0
- data/lib/node_modules/react/cjs/react-jsx-dev-runtime.development.js +1315 -0
- data/lib/node_modules/react/cjs/react-jsx-dev-runtime.production.min.js +10 -0
- data/lib/node_modules/react/cjs/react-jsx-dev-runtime.profiling.min.js +10 -0
- data/lib/node_modules/react/cjs/react-jsx-runtime.development.js +1333 -0
- data/lib/node_modules/react/cjs/react-jsx-runtime.production.min.js +11 -0
- data/lib/node_modules/react/cjs/react-jsx-runtime.profiling.min.js +11 -0
- data/lib/node_modules/react/cjs/react.development.js +2740 -0
- data/lib/node_modules/react/cjs/react.production.min.js +26 -0
- data/lib/node_modules/react/cjs/react.shared-subset.development.js +20 -0
- data/lib/node_modules/react/cjs/react.shared-subset.production.min.js +10 -0
- data/lib/node_modules/react/index.js +7 -0
- data/lib/node_modules/react/jsx-dev-runtime.js +7 -0
- data/lib/node_modules/react/jsx-runtime.js +7 -0
- data/lib/node_modules/react/package.json +47 -0
- data/lib/node_modules/react/react.shared-subset.js +7 -0
- data/lib/node_modules/react/umd/react.development.js +3343 -0
- data/lib/node_modules/react/umd/react.production.min.js +31 -0
- data/lib/node_modules/react/umd/react.profiling.min.js +31 -0
- data/lib/node_modules/react-dom/LICENSE +21 -0
- data/lib/node_modules/react-dom/README.md +60 -0
- data/lib/node_modules/react-dom/cjs/react-dom-server-legacy.browser.development.js +7029 -0
- data/lib/node_modules/react-dom/cjs/react-dom-server-legacy.browser.production.min.js +93 -0
- data/lib/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js +7093 -0
- data/lib/node_modules/react-dom/cjs/react-dom-server-legacy.node.production.min.js +101 -0
- data/lib/node_modules/react-dom/cjs/react-dom-server.browser.development.js +7014 -0
- data/lib/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js +96 -0
- data/lib/node_modules/react-dom/cjs/react-dom-server.node.development.js +7070 -0
- data/lib/node_modules/react-dom/cjs/react-dom-server.node.production.min.js +102 -0
- data/lib/node_modules/react-dom/cjs/react-dom-test-utils.development.js +1763 -0
- data/lib/node_modules/react-dom/cjs/react-dom-test-utils.production.min.js +40 -0
- data/lib/node_modules/react-dom/cjs/react-dom.development.js +29923 -0
- data/lib/node_modules/react-dom/cjs/react-dom.production.min.js +322 -0
- data/lib/node_modules/react-dom/cjs/react-dom.profiling.min.js +366 -0
- data/lib/node_modules/react-dom/client.js +25 -0
- data/lib/node_modules/react-dom/index.js +38 -0
- data/lib/node_modules/react-dom/package.json +62 -0
- data/lib/node_modules/react-dom/profiling.js +38 -0
- data/lib/node_modules/react-dom/server.browser.js +17 -0
- data/lib/node_modules/react-dom/server.js +3 -0
- data/lib/node_modules/react-dom/server.node.js +17 -0
- data/lib/node_modules/react-dom/test-utils.js +7 -0
- data/lib/node_modules/react-dom/umd/react-dom-server-legacy.browser.development.js +7026 -0
- data/lib/node_modules/react-dom/umd/react-dom-server-legacy.browser.production.min.js +75 -0
- data/lib/node_modules/react-dom/umd/react-dom-server.browser.development.js +7011 -0
- data/lib/node_modules/react-dom/umd/react-dom-server.browser.production.min.js +76 -0
- data/lib/node_modules/react-dom/umd/react-dom-test-utils.development.js +1759 -0
- data/lib/node_modules/react-dom/umd/react-dom-test-utils.production.min.js +33 -0
- data/lib/node_modules/react-dom/umd/react-dom.development.js +29924 -0
- data/lib/node_modules/react-dom/umd/react-dom.production.min.js +267 -0
- data/lib/node_modules/react-dom/umd/react-dom.profiling.min.js +285 -0
- data/lib/node_modules/react-router/CHANGELOG.md +1526 -0
- data/lib/node_modules/react-router/LICENSE.md +23 -0
- data/lib/node_modules/react-router/README.md +7 -0
- data/lib/node_modules/react-router/dist/development/chunk-KNED5TY2.mjs +10476 -0
- data/lib/node_modules/react-router/dist/development/dom-export.d.mts +23 -0
- data/lib/node_modules/react-router/dist/development/dom-export.d.ts +23 -0
- data/lib/node_modules/react-router/dist/development/dom-export.js +6111 -0
- data/lib/node_modules/react-router/dist/development/dom-export.mjs +234 -0
- data/lib/node_modules/react-router/dist/development/fog-of-war-1hWhK5ey.d.mts +1690 -0
- data/lib/node_modules/react-router/dist/development/fog-of-war-oa9CGk10.d.ts +1690 -0
- data/lib/node_modules/react-router/dist/development/future-ldDp5FKH.d.mts +21 -0
- data/lib/node_modules/react-router/dist/development/future-ldDp5FKH.d.ts +21 -0
- data/lib/node_modules/react-router/dist/development/index.d.mts +841 -0
- data/lib/node_modules/react-router/dist/development/index.d.ts +841 -0
- data/lib/node_modules/react-router/dist/development/index.js +10624 -0
- data/lib/node_modules/react-router/dist/development/index.mjs +242 -0
- data/lib/node_modules/react-router/dist/development/lib/types/route-module.d.mts +209 -0
- data/lib/node_modules/react-router/dist/development/lib/types/route-module.d.ts +209 -0
- data/lib/node_modules/react-router/dist/development/lib/types/route-module.js +28 -0
- data/lib/node_modules/react-router/dist/development/lib/types/route-module.mjs +10 -0
- data/lib/node_modules/react-router/dist/development/route-data-5OzAzQtT.d.mts +1716 -0
- data/lib/node_modules/react-router/dist/development/route-data-5OzAzQtT.d.ts +1716 -0
- data/lib/node_modules/react-router/dist/production/chunk-ZIM7OIE3.mjs +10476 -0
- data/lib/node_modules/react-router/dist/production/dom-export.d.mts +23 -0
- data/lib/node_modules/react-router/dist/production/dom-export.d.ts +23 -0
- data/lib/node_modules/react-router/dist/production/dom-export.js +6111 -0
- data/lib/node_modules/react-router/dist/production/dom-export.mjs +234 -0
- data/lib/node_modules/react-router/dist/production/fog-of-war-1hWhK5ey.d.mts +1690 -0
- data/lib/node_modules/react-router/dist/production/fog-of-war-oa9CGk10.d.ts +1690 -0
- data/lib/node_modules/react-router/dist/production/future-ldDp5FKH.d.mts +21 -0
- data/lib/node_modules/react-router/dist/production/future-ldDp5FKH.d.ts +21 -0
- data/lib/node_modules/react-router/dist/production/index.d.mts +841 -0
- data/lib/node_modules/react-router/dist/production/index.d.ts +841 -0
- data/lib/node_modules/react-router/dist/production/index.js +10624 -0
- data/lib/node_modules/react-router/dist/production/index.mjs +242 -0
- data/lib/node_modules/react-router/dist/production/lib/types/route-module.d.mts +209 -0
- data/lib/node_modules/react-router/dist/production/lib/types/route-module.d.ts +209 -0
- data/lib/node_modules/react-router/dist/production/lib/types/route-module.js +28 -0
- data/lib/node_modules/react-router/dist/production/lib/types/route-module.mjs +10 -0
- data/lib/node_modules/react-router/dist/production/route-data-5OzAzQtT.d.mts +1716 -0
- data/lib/node_modules/react-router/dist/production/route-data-5OzAzQtT.d.ts +1716 -0
- data/lib/node_modules/react-router/package.json +116 -0
- data/lib/node_modules/react-router-dom/LICENSE.md +23 -0
- data/lib/node_modules/react-router-dom/README.md +6 -0
- data/lib/node_modules/react-router-dom/dist/index.d.mts +2 -0
- data/lib/node_modules/react-router-dom/dist/index.d.ts +2 -0
- data/lib/node_modules/react-router-dom/dist/index.js +45 -0
- data/lib/node_modules/react-router-dom/dist/index.mjs +18 -0
- data/lib/node_modules/react-router-dom/package.json +82 -0
- data/lib/node_modules/scheduler/LICENSE +21 -0
- data/lib/node_modules/scheduler/README.md +9 -0
- data/lib/node_modules/scheduler/cjs/scheduler-unstable_mock.development.js +700 -0
- data/lib/node_modules/scheduler/cjs/scheduler-unstable_mock.production.min.js +20 -0
- data/lib/node_modules/scheduler/cjs/scheduler-unstable_post_task.development.js +207 -0
- data/lib/node_modules/scheduler/cjs/scheduler-unstable_post_task.production.min.js +14 -0
- data/lib/node_modules/scheduler/cjs/scheduler.development.js +634 -0
- data/lib/node_modules/scheduler/cjs/scheduler.production.min.js +19 -0
- data/lib/node_modules/scheduler/index.js +7 -0
- data/lib/node_modules/scheduler/package.json +36 -0
- data/lib/node_modules/scheduler/umd/scheduler-unstable_mock.development.js +699 -0
- data/lib/node_modules/scheduler/umd/scheduler-unstable_mock.production.min.js +19 -0
- data/lib/node_modules/scheduler/umd/scheduler.development.js +152 -0
- data/lib/node_modules/scheduler/umd/scheduler.production.min.js +146 -0
- data/lib/node_modules/scheduler/umd/scheduler.profiling.min.js +146 -0
- data/lib/node_modules/scheduler/unstable_mock.js +7 -0
- data/lib/node_modules/scheduler/unstable_post_task.js +7 -0
- data/lib/node_modules/set-cookie-parser/LICENSE +21 -0
- data/lib/node_modules/set-cookie-parser/README.md +202 -0
- data/lib/node_modules/set-cookie-parser/lib/set-cookie.js +224 -0
- data/lib/node_modules/set-cookie-parser/package.json +45 -0
- data/lib/node_modules/turbo-stream/LICENSE +7 -0
- data/lib/node_modules/turbo-stream/README.md +31 -0
- data/lib/node_modules/turbo-stream/dist/flatten.d.ts +2 -0
- data/lib/node_modules/turbo-stream/dist/flatten.js +203 -0
- data/lib/node_modules/turbo-stream/dist/turbo-stream.d.ts +13 -0
- data/lib/node_modules/turbo-stream/dist/turbo-stream.js +207 -0
- data/lib/node_modules/turbo-stream/dist/turbo-stream.mjs +673 -0
- data/lib/node_modules/turbo-stream/dist/unflatten.d.ts +2 -0
- data/lib/node_modules/turbo-stream/dist/unflatten.js +243 -0
- data/lib/node_modules/turbo-stream/dist/utils.d.ts +44 -0
- data/lib/node_modules/turbo-stream/dist/utils.js +55 -0
- data/lib/node_modules/turbo-stream/package.json +50 -0
- data/lib/package-lock.json +133 -0
- data/lib/package.json +12 -0
- data/lib/rubee/async/asyncable.rb +2 -2
- data/lib/rubee/async/sidekiq_async.rb +11 -11
- data/lib/rubee/async/thread_async.rb +1 -1
- data/lib/rubee/async/thread_pool.rb +2 -2
- data/lib/rubee/controllers/base_controller.rb +44 -21
- data/lib/rubee/controllers/extensions/auth_tokenable.rb +10 -8
- data/lib/rubee/controllers/extensions/middlewarable.rb +1 -1
- data/lib/rubee/controllers/middlewares/auth_token_middleware.rb +12 -8
- data/lib/rubee/extensions/hookable.rb +3 -6
- data/lib/rubee/extensions/serializable.rb +3 -3
- data/lib/rubee/models/database_objectable.rb +11 -12
- data/lib/rubee/models/sequel_object.rb +23 -24
- data/lib/rubee.rb +106 -55
- data/lib/tests/account_model_test.rb +4 -4
- data/lib/tests/auth_tokenable_test.rb +6 -6
- data/lib/tests/comment_model_test.rb +7 -7
- data/lib/tests/example_models/account.rb +1 -0
- data/lib/tests/example_models/comment.rb +1 -0
- data/lib/tests/example_models/post.rb +1 -0
- data/lib/tests/example_models/user.rb +1 -0
- data/lib/tests/rubeeapp_test.rb +21 -6
- data/lib/tests/test.db +0 -0
- data/lib/tests/test_helper.rb +3 -5
- data/lib/tests/user_model_test.rb +71 -54
- data/readme.md +104 -2
- metadata +170 -3
@@ -0,0 +1,673 @@
|
|
1
|
+
// src/utils.ts
|
2
|
+
var HOLE = -1;
|
3
|
+
var NAN = -2;
|
4
|
+
var NEGATIVE_INFINITY = -3;
|
5
|
+
var NEGATIVE_ZERO = -4;
|
6
|
+
var NULL = -5;
|
7
|
+
var POSITIVE_INFINITY = -6;
|
8
|
+
var UNDEFINED = -7;
|
9
|
+
var TYPE_BIGINT = "B";
|
10
|
+
var TYPE_DATE = "D";
|
11
|
+
var TYPE_ERROR = "E";
|
12
|
+
var TYPE_MAP = "M";
|
13
|
+
var TYPE_NULL_OBJECT = "N";
|
14
|
+
var TYPE_PROMISE = "P";
|
15
|
+
var TYPE_REGEXP = "R";
|
16
|
+
var TYPE_SET = "S";
|
17
|
+
var TYPE_SYMBOL = "Y";
|
18
|
+
var TYPE_URL = "U";
|
19
|
+
var TYPE_PREVIOUS_RESOLVED = "Z";
|
20
|
+
var Deferred = class {
|
21
|
+
promise;
|
22
|
+
resolve;
|
23
|
+
reject;
|
24
|
+
constructor() {
|
25
|
+
this.promise = new Promise((resolve, reject) => {
|
26
|
+
this.resolve = resolve;
|
27
|
+
this.reject = reject;
|
28
|
+
});
|
29
|
+
}
|
30
|
+
};
|
31
|
+
function createLineSplittingTransform() {
|
32
|
+
const decoder = new TextDecoder();
|
33
|
+
let leftover = "";
|
34
|
+
return new TransformStream({
|
35
|
+
transform(chunk, controller) {
|
36
|
+
const str = decoder.decode(chunk, { stream: true });
|
37
|
+
const parts = (leftover + str).split("\n");
|
38
|
+
leftover = parts.pop() || "";
|
39
|
+
for (const part of parts) {
|
40
|
+
controller.enqueue(part);
|
41
|
+
}
|
42
|
+
},
|
43
|
+
flush(controller) {
|
44
|
+
if (leftover) {
|
45
|
+
controller.enqueue(leftover);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
});
|
49
|
+
}
|
50
|
+
|
51
|
+
// src/flatten.ts
|
52
|
+
function flatten(input) {
|
53
|
+
const { indices } = this;
|
54
|
+
const existing = indices.get(input);
|
55
|
+
if (existing)
|
56
|
+
return [existing];
|
57
|
+
if (input === void 0)
|
58
|
+
return UNDEFINED;
|
59
|
+
if (input === null)
|
60
|
+
return NULL;
|
61
|
+
if (Number.isNaN(input))
|
62
|
+
return NAN;
|
63
|
+
if (input === Number.POSITIVE_INFINITY)
|
64
|
+
return POSITIVE_INFINITY;
|
65
|
+
if (input === Number.NEGATIVE_INFINITY)
|
66
|
+
return NEGATIVE_INFINITY;
|
67
|
+
if (input === 0 && 1 / input < 0)
|
68
|
+
return NEGATIVE_ZERO;
|
69
|
+
const index = this.index++;
|
70
|
+
indices.set(input, index);
|
71
|
+
stringify.call(this, input, index);
|
72
|
+
return index;
|
73
|
+
}
|
74
|
+
function stringify(input, index) {
|
75
|
+
const { deferred, plugins, postPlugins } = this;
|
76
|
+
const str = this.stringified;
|
77
|
+
const stack = [[input, index]];
|
78
|
+
while (stack.length > 0) {
|
79
|
+
const [input2, index2] = stack.pop();
|
80
|
+
const partsForObj = (obj) => Object.keys(obj).map((k) => `"_${flatten.call(this, k)}":${flatten.call(this, obj[k])}`).join(",");
|
81
|
+
let error = null;
|
82
|
+
switch (typeof input2) {
|
83
|
+
case "boolean":
|
84
|
+
case "number":
|
85
|
+
case "string":
|
86
|
+
str[index2] = JSON.stringify(input2);
|
87
|
+
break;
|
88
|
+
case "bigint":
|
89
|
+
str[index2] = `["${TYPE_BIGINT}","${input2}"]`;
|
90
|
+
break;
|
91
|
+
case "symbol": {
|
92
|
+
const keyFor = Symbol.keyFor(input2);
|
93
|
+
if (!keyFor) {
|
94
|
+
error = new Error(
|
95
|
+
"Cannot encode symbol unless created with Symbol.for()"
|
96
|
+
);
|
97
|
+
} else {
|
98
|
+
str[index2] = `["${TYPE_SYMBOL}",${JSON.stringify(keyFor)}]`;
|
99
|
+
}
|
100
|
+
break;
|
101
|
+
}
|
102
|
+
case "object": {
|
103
|
+
if (!input2) {
|
104
|
+
str[index2] = `${NULL}`;
|
105
|
+
break;
|
106
|
+
}
|
107
|
+
const isArray = Array.isArray(input2);
|
108
|
+
let pluginHandled = false;
|
109
|
+
if (!isArray && plugins) {
|
110
|
+
for (const plugin of plugins) {
|
111
|
+
const pluginResult = plugin(input2);
|
112
|
+
if (Array.isArray(pluginResult)) {
|
113
|
+
pluginHandled = true;
|
114
|
+
const [pluginIdentifier, ...rest] = pluginResult;
|
115
|
+
str[index2] = `[${JSON.stringify(pluginIdentifier)}`;
|
116
|
+
if (rest.length > 0) {
|
117
|
+
str[index2] += `,${rest.map((v) => flatten.call(this, v)).join(",")}`;
|
118
|
+
}
|
119
|
+
str[index2] += "]";
|
120
|
+
break;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
if (!pluginHandled) {
|
125
|
+
let result = isArray ? "[" : "{";
|
126
|
+
if (isArray) {
|
127
|
+
for (let i = 0; i < input2.length; i++)
|
128
|
+
result += (i ? "," : "") + (i in input2 ? flatten.call(this, input2[i]) : HOLE);
|
129
|
+
str[index2] = `${result}]`;
|
130
|
+
} else if (input2 instanceof Date) {
|
131
|
+
str[index2] = `["${TYPE_DATE}",${input2.getTime()}]`;
|
132
|
+
} else if (input2 instanceof URL) {
|
133
|
+
str[index2] = `["${TYPE_URL}",${JSON.stringify(input2.href)}]`;
|
134
|
+
} else if (input2 instanceof RegExp) {
|
135
|
+
str[index2] = `["${TYPE_REGEXP}",${JSON.stringify(
|
136
|
+
input2.source
|
137
|
+
)},${JSON.stringify(input2.flags)}]`;
|
138
|
+
} else if (input2 instanceof Set) {
|
139
|
+
if (input2.size > 0) {
|
140
|
+
str[index2] = `["${TYPE_SET}",${[...input2].map((val) => flatten.call(this, val)).join(",")}]`;
|
141
|
+
} else {
|
142
|
+
str[index2] = `["${TYPE_SET}"]`;
|
143
|
+
}
|
144
|
+
} else if (input2 instanceof Map) {
|
145
|
+
if (input2.size > 0) {
|
146
|
+
str[index2] = `["${TYPE_MAP}",${[...input2].flatMap(([k, v]) => [
|
147
|
+
flatten.call(this, k),
|
148
|
+
flatten.call(this, v)
|
149
|
+
]).join(",")}]`;
|
150
|
+
} else {
|
151
|
+
str[index2] = `["${TYPE_MAP}"]`;
|
152
|
+
}
|
153
|
+
} else if (input2 instanceof Promise) {
|
154
|
+
str[index2] = `["${TYPE_PROMISE}",${index2}]`;
|
155
|
+
deferred[index2] = input2;
|
156
|
+
} else if (input2 instanceof Error) {
|
157
|
+
str[index2] = `["${TYPE_ERROR}",${JSON.stringify(input2.message)}`;
|
158
|
+
if (input2.name !== "Error") {
|
159
|
+
str[index2] += `,${JSON.stringify(input2.name)}`;
|
160
|
+
}
|
161
|
+
str[index2] += "]";
|
162
|
+
} else if (Object.getPrototypeOf(input2) === null) {
|
163
|
+
str[index2] = `["${TYPE_NULL_OBJECT}",{${partsForObj(input2)}}]`;
|
164
|
+
} else if (isPlainObject(input2)) {
|
165
|
+
str[index2] = `{${partsForObj(input2)}}`;
|
166
|
+
} else {
|
167
|
+
error = new Error("Cannot encode object with prototype");
|
168
|
+
}
|
169
|
+
}
|
170
|
+
break;
|
171
|
+
}
|
172
|
+
default: {
|
173
|
+
const isArray = Array.isArray(input2);
|
174
|
+
let pluginHandled = false;
|
175
|
+
if (!isArray && plugins) {
|
176
|
+
for (const plugin of plugins) {
|
177
|
+
const pluginResult = plugin(input2);
|
178
|
+
if (Array.isArray(pluginResult)) {
|
179
|
+
pluginHandled = true;
|
180
|
+
const [pluginIdentifier, ...rest] = pluginResult;
|
181
|
+
str[index2] = `[${JSON.stringify(pluginIdentifier)}`;
|
182
|
+
if (rest.length > 0) {
|
183
|
+
str[index2] += `,${rest.map((v) => flatten.call(this, v)).join(",")}`;
|
184
|
+
}
|
185
|
+
str[index2] += "]";
|
186
|
+
break;
|
187
|
+
}
|
188
|
+
}
|
189
|
+
}
|
190
|
+
if (!pluginHandled) {
|
191
|
+
error = new Error("Cannot encode function or unexpected type");
|
192
|
+
}
|
193
|
+
}
|
194
|
+
}
|
195
|
+
if (error) {
|
196
|
+
let pluginHandled = false;
|
197
|
+
if (postPlugins) {
|
198
|
+
for (const plugin of postPlugins) {
|
199
|
+
const pluginResult = plugin(input2);
|
200
|
+
if (Array.isArray(pluginResult)) {
|
201
|
+
pluginHandled = true;
|
202
|
+
const [pluginIdentifier, ...rest] = pluginResult;
|
203
|
+
str[index2] = `[${JSON.stringify(pluginIdentifier)}`;
|
204
|
+
if (rest.length > 0) {
|
205
|
+
str[index2] += `,${rest.map((v) => flatten.call(this, v)).join(",")}`;
|
206
|
+
}
|
207
|
+
str[index2] += "]";
|
208
|
+
break;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
}
|
212
|
+
if (!pluginHandled) {
|
213
|
+
throw error;
|
214
|
+
}
|
215
|
+
}
|
216
|
+
}
|
217
|
+
}
|
218
|
+
var objectProtoNames = Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
|
219
|
+
function isPlainObject(thing) {
|
220
|
+
const proto = Object.getPrototypeOf(thing);
|
221
|
+
return proto === Object.prototype || proto === null || Object.getOwnPropertyNames(proto).sort().join("\0") === objectProtoNames;
|
222
|
+
}
|
223
|
+
|
224
|
+
// src/unflatten.ts
|
225
|
+
var globalObj = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : void 0;
|
226
|
+
function unflatten(parsed) {
|
227
|
+
const { hydrated, values } = this;
|
228
|
+
if (typeof parsed === "number")
|
229
|
+
return hydrate.call(this, parsed);
|
230
|
+
if (!Array.isArray(parsed) || !parsed.length)
|
231
|
+
throw new SyntaxError();
|
232
|
+
const startIndex = values.length;
|
233
|
+
for (const value of parsed) {
|
234
|
+
values.push(value);
|
235
|
+
}
|
236
|
+
hydrated.length = values.length;
|
237
|
+
return hydrate.call(this, startIndex);
|
238
|
+
}
|
239
|
+
function hydrate(index) {
|
240
|
+
const { hydrated, values, deferred, plugins } = this;
|
241
|
+
let result;
|
242
|
+
const stack = [
|
243
|
+
[
|
244
|
+
index,
|
245
|
+
(v) => {
|
246
|
+
result = v;
|
247
|
+
}
|
248
|
+
]
|
249
|
+
];
|
250
|
+
let postRun = [];
|
251
|
+
while (stack.length > 0) {
|
252
|
+
const [index2, set] = stack.pop();
|
253
|
+
switch (index2) {
|
254
|
+
case UNDEFINED:
|
255
|
+
set(void 0);
|
256
|
+
continue;
|
257
|
+
case NULL:
|
258
|
+
set(null);
|
259
|
+
continue;
|
260
|
+
case NAN:
|
261
|
+
set(NaN);
|
262
|
+
continue;
|
263
|
+
case POSITIVE_INFINITY:
|
264
|
+
set(Infinity);
|
265
|
+
continue;
|
266
|
+
case NEGATIVE_INFINITY:
|
267
|
+
set(-Infinity);
|
268
|
+
continue;
|
269
|
+
case NEGATIVE_ZERO:
|
270
|
+
set(-0);
|
271
|
+
continue;
|
272
|
+
}
|
273
|
+
if (hydrated[index2]) {
|
274
|
+
set(hydrated[index2]);
|
275
|
+
continue;
|
276
|
+
}
|
277
|
+
const value = values[index2];
|
278
|
+
if (!value || typeof value !== "object") {
|
279
|
+
hydrated[index2] = value;
|
280
|
+
set(value);
|
281
|
+
continue;
|
282
|
+
}
|
283
|
+
if (Array.isArray(value)) {
|
284
|
+
if (typeof value[0] === "string") {
|
285
|
+
const [type, b, c] = value;
|
286
|
+
switch (type) {
|
287
|
+
case TYPE_DATE:
|
288
|
+
set(hydrated[index2] = new Date(b));
|
289
|
+
continue;
|
290
|
+
case TYPE_URL:
|
291
|
+
set(hydrated[index2] = new URL(b));
|
292
|
+
continue;
|
293
|
+
case TYPE_BIGINT:
|
294
|
+
set(hydrated[index2] = BigInt(b));
|
295
|
+
continue;
|
296
|
+
case TYPE_REGEXP:
|
297
|
+
set(hydrated[index2] = new RegExp(b, c));
|
298
|
+
continue;
|
299
|
+
case TYPE_SYMBOL:
|
300
|
+
set(hydrated[index2] = Symbol.for(b));
|
301
|
+
continue;
|
302
|
+
case TYPE_SET:
|
303
|
+
const newSet = /* @__PURE__ */ new Set();
|
304
|
+
hydrated[index2] = newSet;
|
305
|
+
for (let i = 1; i < value.length; i++)
|
306
|
+
stack.push([
|
307
|
+
value[i],
|
308
|
+
(v) => {
|
309
|
+
newSet.add(v);
|
310
|
+
}
|
311
|
+
]);
|
312
|
+
set(newSet);
|
313
|
+
continue;
|
314
|
+
case TYPE_MAP:
|
315
|
+
const map = /* @__PURE__ */ new Map();
|
316
|
+
hydrated[index2] = map;
|
317
|
+
for (let i = 1; i < value.length; i += 2) {
|
318
|
+
const r = [];
|
319
|
+
stack.push([
|
320
|
+
value[i + 1],
|
321
|
+
(v) => {
|
322
|
+
r[1] = v;
|
323
|
+
}
|
324
|
+
]);
|
325
|
+
stack.push([
|
326
|
+
value[i],
|
327
|
+
(k) => {
|
328
|
+
r[0] = k;
|
329
|
+
}
|
330
|
+
]);
|
331
|
+
postRun.push(() => {
|
332
|
+
map.set(r[0], r[1]);
|
333
|
+
});
|
334
|
+
}
|
335
|
+
set(map);
|
336
|
+
continue;
|
337
|
+
case TYPE_NULL_OBJECT:
|
338
|
+
const obj = /* @__PURE__ */ Object.create(null);
|
339
|
+
hydrated[index2] = obj;
|
340
|
+
for (const key of Object.keys(b).reverse()) {
|
341
|
+
const r = [];
|
342
|
+
stack.push([
|
343
|
+
b[key],
|
344
|
+
(v) => {
|
345
|
+
r[1] = v;
|
346
|
+
}
|
347
|
+
]);
|
348
|
+
stack.push([
|
349
|
+
Number(key.slice(1)),
|
350
|
+
(k) => {
|
351
|
+
r[0] = k;
|
352
|
+
}
|
353
|
+
]);
|
354
|
+
postRun.push(() => {
|
355
|
+
obj[r[0]] = r[1];
|
356
|
+
});
|
357
|
+
}
|
358
|
+
set(obj);
|
359
|
+
continue;
|
360
|
+
case TYPE_PROMISE:
|
361
|
+
if (hydrated[b]) {
|
362
|
+
set(hydrated[index2] = hydrated[b]);
|
363
|
+
} else {
|
364
|
+
const d = new Deferred();
|
365
|
+
deferred[b] = d;
|
366
|
+
set(hydrated[index2] = d.promise);
|
367
|
+
}
|
368
|
+
continue;
|
369
|
+
case TYPE_ERROR:
|
370
|
+
const [, message, errorType] = value;
|
371
|
+
let error = errorType && globalObj && globalObj[errorType] ? new globalObj[errorType](message) : new Error(message);
|
372
|
+
hydrated[index2] = error;
|
373
|
+
set(error);
|
374
|
+
continue;
|
375
|
+
case TYPE_PREVIOUS_RESOLVED:
|
376
|
+
set(hydrated[index2] = hydrated[b]);
|
377
|
+
continue;
|
378
|
+
default:
|
379
|
+
if (Array.isArray(plugins)) {
|
380
|
+
const r = [];
|
381
|
+
const vals = value.slice(1);
|
382
|
+
for (let i = 0; i < vals.length; i++) {
|
383
|
+
const v = vals[i];
|
384
|
+
stack.push([
|
385
|
+
v,
|
386
|
+
(v2) => {
|
387
|
+
r[i] = v2;
|
388
|
+
}
|
389
|
+
]);
|
390
|
+
}
|
391
|
+
postRun.push(() => {
|
392
|
+
for (const plugin of plugins) {
|
393
|
+
const result2 = plugin(value[0], ...r);
|
394
|
+
if (result2) {
|
395
|
+
set(hydrated[index2] = result2.value);
|
396
|
+
return;
|
397
|
+
}
|
398
|
+
}
|
399
|
+
throw new SyntaxError();
|
400
|
+
});
|
401
|
+
continue;
|
402
|
+
}
|
403
|
+
throw new SyntaxError();
|
404
|
+
}
|
405
|
+
} else {
|
406
|
+
const array = [];
|
407
|
+
hydrated[index2] = array;
|
408
|
+
for (let i = 0; i < value.length; i++) {
|
409
|
+
const n = value[i];
|
410
|
+
if (n !== HOLE) {
|
411
|
+
stack.push([
|
412
|
+
n,
|
413
|
+
(v) => {
|
414
|
+
array[i] = v;
|
415
|
+
}
|
416
|
+
]);
|
417
|
+
}
|
418
|
+
}
|
419
|
+
set(array);
|
420
|
+
continue;
|
421
|
+
}
|
422
|
+
} else {
|
423
|
+
const object = {};
|
424
|
+
hydrated[index2] = object;
|
425
|
+
for (const key of Object.keys(value).reverse()) {
|
426
|
+
const r = [];
|
427
|
+
stack.push([
|
428
|
+
value[key],
|
429
|
+
(v) => {
|
430
|
+
r[1] = v;
|
431
|
+
}
|
432
|
+
]);
|
433
|
+
stack.push([
|
434
|
+
Number(key.slice(1)),
|
435
|
+
(k) => {
|
436
|
+
r[0] = k;
|
437
|
+
}
|
438
|
+
]);
|
439
|
+
postRun.push(() => {
|
440
|
+
object[r[0]] = r[1];
|
441
|
+
});
|
442
|
+
}
|
443
|
+
set(object);
|
444
|
+
continue;
|
445
|
+
}
|
446
|
+
}
|
447
|
+
while (postRun.length > 0) {
|
448
|
+
postRun.pop()();
|
449
|
+
}
|
450
|
+
return result;
|
451
|
+
}
|
452
|
+
|
453
|
+
// src/turbo-stream.ts
|
454
|
+
async function decode(readable, options) {
|
455
|
+
const { plugins } = options ?? {};
|
456
|
+
const done = new Deferred();
|
457
|
+
const reader = readable.pipeThrough(createLineSplittingTransform()).getReader();
|
458
|
+
const decoder = {
|
459
|
+
values: [],
|
460
|
+
hydrated: [],
|
461
|
+
deferred: {},
|
462
|
+
plugins
|
463
|
+
};
|
464
|
+
const decoded = await decodeInitial.call(decoder, reader);
|
465
|
+
let donePromise = done.promise;
|
466
|
+
if (decoded.done) {
|
467
|
+
done.resolve();
|
468
|
+
} else {
|
469
|
+
donePromise = decodeDeferred.call(decoder, reader).then(done.resolve).catch((reason) => {
|
470
|
+
for (const deferred of Object.values(decoder.deferred)) {
|
471
|
+
deferred.reject(reason);
|
472
|
+
}
|
473
|
+
done.reject(reason);
|
474
|
+
});
|
475
|
+
}
|
476
|
+
return {
|
477
|
+
done: donePromise.then(() => reader.closed),
|
478
|
+
value: decoded.value
|
479
|
+
};
|
480
|
+
}
|
481
|
+
async function decodeInitial(reader) {
|
482
|
+
const read = await reader.read();
|
483
|
+
if (!read.value) {
|
484
|
+
throw new SyntaxError();
|
485
|
+
}
|
486
|
+
let line;
|
487
|
+
try {
|
488
|
+
line = JSON.parse(read.value);
|
489
|
+
} catch (reason) {
|
490
|
+
throw new SyntaxError();
|
491
|
+
}
|
492
|
+
return {
|
493
|
+
done: read.done,
|
494
|
+
value: unflatten.call(this, line)
|
495
|
+
};
|
496
|
+
}
|
497
|
+
async function decodeDeferred(reader) {
|
498
|
+
let read = await reader.read();
|
499
|
+
while (!read.done) {
|
500
|
+
if (!read.value)
|
501
|
+
continue;
|
502
|
+
const line = read.value;
|
503
|
+
switch (line[0]) {
|
504
|
+
case TYPE_PROMISE: {
|
505
|
+
const colonIndex = line.indexOf(":");
|
506
|
+
const deferredId = Number(line.slice(1, colonIndex));
|
507
|
+
const deferred = this.deferred[deferredId];
|
508
|
+
if (!deferred) {
|
509
|
+
throw new Error(`Deferred ID ${deferredId} not found in stream`);
|
510
|
+
}
|
511
|
+
const lineData = line.slice(colonIndex + 1);
|
512
|
+
let jsonLine;
|
513
|
+
try {
|
514
|
+
jsonLine = JSON.parse(lineData);
|
515
|
+
} catch (reason) {
|
516
|
+
throw new SyntaxError();
|
517
|
+
}
|
518
|
+
const value = unflatten.call(this, jsonLine);
|
519
|
+
deferred.resolve(value);
|
520
|
+
break;
|
521
|
+
}
|
522
|
+
case TYPE_ERROR: {
|
523
|
+
const colonIndex = line.indexOf(":");
|
524
|
+
const deferredId = Number(line.slice(1, colonIndex));
|
525
|
+
const deferred = this.deferred[deferredId];
|
526
|
+
if (!deferred) {
|
527
|
+
throw new Error(`Deferred ID ${deferredId} not found in stream`);
|
528
|
+
}
|
529
|
+
const lineData = line.slice(colonIndex + 1);
|
530
|
+
let jsonLine;
|
531
|
+
try {
|
532
|
+
jsonLine = JSON.parse(lineData);
|
533
|
+
} catch (reason) {
|
534
|
+
throw new SyntaxError();
|
535
|
+
}
|
536
|
+
const value = unflatten.call(this, jsonLine);
|
537
|
+
deferred.reject(value);
|
538
|
+
break;
|
539
|
+
}
|
540
|
+
default:
|
541
|
+
throw new SyntaxError();
|
542
|
+
}
|
543
|
+
read = await reader.read();
|
544
|
+
}
|
545
|
+
}
|
546
|
+
function encode(input, options) {
|
547
|
+
const { plugins, postPlugins, signal } = options ?? {};
|
548
|
+
const encoder = {
|
549
|
+
deferred: {},
|
550
|
+
index: 0,
|
551
|
+
indices: /* @__PURE__ */ new Map(),
|
552
|
+
stringified: [],
|
553
|
+
plugins,
|
554
|
+
postPlugins,
|
555
|
+
signal
|
556
|
+
};
|
557
|
+
const textEncoder = new TextEncoder();
|
558
|
+
let lastSentIndex = 0;
|
559
|
+
const readable = new ReadableStream({
|
560
|
+
async start(controller) {
|
561
|
+
const id = flatten.call(encoder, input);
|
562
|
+
if (Array.isArray(id)) {
|
563
|
+
throw new Error("This should never happen");
|
564
|
+
}
|
565
|
+
if (id < 0) {
|
566
|
+
controller.enqueue(textEncoder.encode(`${id}
|
567
|
+
`));
|
568
|
+
} else {
|
569
|
+
controller.enqueue(
|
570
|
+
textEncoder.encode(`[${encoder.stringified.join(",")}]
|
571
|
+
`)
|
572
|
+
);
|
573
|
+
lastSentIndex = encoder.stringified.length - 1;
|
574
|
+
}
|
575
|
+
const seenPromises = /* @__PURE__ */ new WeakSet();
|
576
|
+
while (Object.keys(encoder.deferred).length > 0) {
|
577
|
+
for (const [deferredId, deferred] of Object.entries(encoder.deferred)) {
|
578
|
+
if (seenPromises.has(deferred))
|
579
|
+
continue;
|
580
|
+
seenPromises.add(
|
581
|
+
encoder.deferred[Number(deferredId)] = raceSignal(
|
582
|
+
deferred,
|
583
|
+
encoder.signal
|
584
|
+
).then(
|
585
|
+
(resolved) => {
|
586
|
+
const id2 = flatten.call(encoder, resolved);
|
587
|
+
if (Array.isArray(id2)) {
|
588
|
+
controller.enqueue(
|
589
|
+
textEncoder.encode(
|
590
|
+
`${TYPE_PROMISE}${deferredId}:[["${TYPE_PREVIOUS_RESOLVED}",${id2[0]}]]
|
591
|
+
`
|
592
|
+
)
|
593
|
+
);
|
594
|
+
encoder.index++;
|
595
|
+
lastSentIndex++;
|
596
|
+
} else if (id2 < 0) {
|
597
|
+
controller.enqueue(
|
598
|
+
textEncoder.encode(`${TYPE_PROMISE}${deferredId}:${id2}
|
599
|
+
`)
|
600
|
+
);
|
601
|
+
} else {
|
602
|
+
const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
|
603
|
+
controller.enqueue(
|
604
|
+
textEncoder.encode(
|
605
|
+
`${TYPE_PROMISE}${deferredId}:[${values}]
|
606
|
+
`
|
607
|
+
)
|
608
|
+
);
|
609
|
+
lastSentIndex = encoder.stringified.length - 1;
|
610
|
+
}
|
611
|
+
},
|
612
|
+
(reason) => {
|
613
|
+
if (!reason || typeof reason !== "object" || !(reason instanceof Error)) {
|
614
|
+
reason = new Error("An unknown error occurred");
|
615
|
+
}
|
616
|
+
const id2 = flatten.call(encoder, reason);
|
617
|
+
if (Array.isArray(id2)) {
|
618
|
+
controller.enqueue(
|
619
|
+
textEncoder.encode(
|
620
|
+
`${TYPE_ERROR}${deferredId}:[["${TYPE_PREVIOUS_RESOLVED}",${id2[0]}]]
|
621
|
+
`
|
622
|
+
)
|
623
|
+
);
|
624
|
+
encoder.index++;
|
625
|
+
lastSentIndex++;
|
626
|
+
} else if (id2 < 0) {
|
627
|
+
controller.enqueue(
|
628
|
+
textEncoder.encode(`${TYPE_ERROR}${deferredId}:${id2}
|
629
|
+
`)
|
630
|
+
);
|
631
|
+
} else {
|
632
|
+
const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
|
633
|
+
controller.enqueue(
|
634
|
+
textEncoder.encode(
|
635
|
+
`${TYPE_ERROR}${deferredId}:[${values}]
|
636
|
+
`
|
637
|
+
)
|
638
|
+
);
|
639
|
+
lastSentIndex = encoder.stringified.length - 1;
|
640
|
+
}
|
641
|
+
}
|
642
|
+
).finally(() => {
|
643
|
+
delete encoder.deferred[Number(deferredId)];
|
644
|
+
})
|
645
|
+
);
|
646
|
+
}
|
647
|
+
await Promise.race(Object.values(encoder.deferred));
|
648
|
+
}
|
649
|
+
await Promise.all(Object.values(encoder.deferred));
|
650
|
+
controller.close();
|
651
|
+
}
|
652
|
+
});
|
653
|
+
return readable;
|
654
|
+
}
|
655
|
+
function raceSignal(promise, signal) {
|
656
|
+
if (!signal)
|
657
|
+
return promise;
|
658
|
+
if (signal.aborted)
|
659
|
+
return Promise.reject(signal.reason || new Error("Signal was aborted."));
|
660
|
+
const abort = new Promise((resolve, reject) => {
|
661
|
+
signal.addEventListener("abort", (event) => {
|
662
|
+
reject(signal.reason || new Error("Signal was aborted."));
|
663
|
+
});
|
664
|
+
promise.then(resolve).catch(reject);
|
665
|
+
});
|
666
|
+
abort.catch(() => {
|
667
|
+
});
|
668
|
+
return Promise.race([abort, promise]);
|
669
|
+
}
|
670
|
+
export {
|
671
|
+
decode,
|
672
|
+
encode
|
673
|
+
};
|