remult 0.27.21 → 0.27.22-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/remult-sveltekit.js +2 -10
- package/esm/server/initAsyncHooks.js +0 -49
- package/esm/server/remult-api-server.js +4 -3
- package/esm/src/context.js +5 -0
- package/esm/src/remult-proxy.js +3 -0
- package/package.json +1 -1
- package/remult-sveltekit.js +7 -26
- package/server/initAsyncHooks.d.ts +0 -7
- package/server/initAsyncHooks.js +1 -73
- package/server/remult-api-server.js +4 -3
- package/src/context.d.ts +1 -0
- package/src/context.js +5 -0
- package/src/remult-proxy.js +3 -0
package/esm/remult-sveltekit.js
CHANGED
|
@@ -71,16 +71,7 @@ export function remultSveltekit(options) {
|
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
73
|
const handler = async ({ event, resolve }) => {
|
|
74
|
-
|
|
75
|
-
const result = await serverHandler(event);
|
|
76
|
-
if (result != null && result?.status != 404)
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
return new Promise((res) => {
|
|
80
|
-
result.withRemult(event, undefined, async () => {
|
|
81
|
-
res(await resolve(event));
|
|
82
|
-
});
|
|
83
|
-
});
|
|
74
|
+
return result.withRemultAsync(event, async () => await resolve(event));
|
|
84
75
|
};
|
|
85
76
|
return Object.assign(handler, {
|
|
86
77
|
getRemult: (req) => result.getRemult(req),
|
|
@@ -88,6 +79,7 @@ export function remultSveltekit(options) {
|
|
|
88
79
|
withRemult(request, what) {
|
|
89
80
|
return result.withRemultAsync(request, what);
|
|
90
81
|
},
|
|
82
|
+
hookHandler: handler,
|
|
91
83
|
GET: serverHandler,
|
|
92
84
|
PUT: serverHandler,
|
|
93
85
|
POST: serverHandler,
|
|
@@ -37,55 +37,6 @@ export class AsyncLocalStorageBridgeToRemultAsyncLocalStorageCoreImpl {
|
|
|
37
37
|
return this.asyncLocalStorage.getStore();
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
const ignoreInStack = [
|
|
41
|
-
'AsyncLocalStorageBridgeToRemultAsyncLocalStorageCore.run',
|
|
42
|
-
'RemultAsyncLocalStorage.run',
|
|
43
|
-
'Module.withRemult',
|
|
44
|
-
'RemultServerImplementation.runWithRemult',
|
|
45
|
-
];
|
|
46
|
-
export class SequentialRemultAsyncLocalStorageCore {
|
|
47
|
-
wasImplemented = 'yes';
|
|
48
|
-
async run(store, callback) {
|
|
49
|
-
let log = (msg) => { };
|
|
50
|
-
if (false) {
|
|
51
|
-
let stack = new Error().stack;
|
|
52
|
-
let y = stack.split('\n');
|
|
53
|
-
while (y.length > 0 &&
|
|
54
|
-
(y[0].trim().startsWith('Error') ||
|
|
55
|
-
ignoreInStack.includes(y[0].trim().split(' ')[1]))) {
|
|
56
|
-
y.splice(0, 1);
|
|
57
|
-
}
|
|
58
|
-
stack = y.join('\n');
|
|
59
|
-
log = (msg) => {
|
|
60
|
-
console.log(msg, stack);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
log('waiting on ');
|
|
64
|
-
const nextPromise = this.lastPromise.then(async () => {
|
|
65
|
-
log('executing ');
|
|
66
|
-
const previousValue = this.currentValue;
|
|
67
|
-
this.currentValue = store;
|
|
68
|
-
const result = await callback();
|
|
69
|
-
this.currentValue = previousValue;
|
|
70
|
-
return result;
|
|
71
|
-
});
|
|
72
|
-
this.lastPromise = nextPromise.catch(() => {
|
|
73
|
-
log('Error on ');
|
|
74
|
-
return undefined;
|
|
75
|
-
});
|
|
76
|
-
try {
|
|
77
|
-
return await nextPromise;
|
|
78
|
-
}
|
|
79
|
-
finally {
|
|
80
|
-
log('completed ');
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
getStore() {
|
|
84
|
-
return this.currentValue;
|
|
85
|
-
}
|
|
86
|
-
lastPromise = Promise.resolve(undefined);
|
|
87
|
-
currentValue;
|
|
88
|
-
}
|
|
89
40
|
export class StubRemultAsyncLocalStorageCore {
|
|
90
41
|
isStub = true;
|
|
91
42
|
wasImplemented = 'yes';
|
|
@@ -154,7 +154,7 @@ export class RemultServerImplementation {
|
|
|
154
154
|
withRemult = async (req, res, next) => {
|
|
155
155
|
await this.process(async () => {
|
|
156
156
|
await next();
|
|
157
|
-
})(req, res);
|
|
157
|
+
}, true)(req, res);
|
|
158
158
|
};
|
|
159
159
|
routeImpl;
|
|
160
160
|
getRouteImpl() {
|
|
@@ -293,7 +293,7 @@ export class RemultServerImplementation {
|
|
|
293
293
|
dataProvider: dataProvider,
|
|
294
294
|
});
|
|
295
295
|
}
|
|
296
|
-
process(what) {
|
|
296
|
+
process(what, doNotReuseInitRequest) {
|
|
297
297
|
return async (req, origRes) => {
|
|
298
298
|
const genReq = req ? this.coreOptions.buildGenericRequestInfo(req) : {};
|
|
299
299
|
if (req) {
|
|
@@ -306,7 +306,8 @@ export class RemultServerImplementation {
|
|
|
306
306
|
let myReq = new RequestBridgeToDataApiRequest(genReq);
|
|
307
307
|
let myRes = new ResponseBridgeToDataApiResponse(origRes, req, genReq, this.options.error);
|
|
308
308
|
try {
|
|
309
|
-
if (remultStatic.asyncContext.isInInitRequest()
|
|
309
|
+
if (remultStatic.asyncContext.isInInitRequest() &&
|
|
310
|
+
!doNotReuseInitRequest)
|
|
310
311
|
return await what(remultStatic.asyncContext.getStore().remult, myReq, myRes, genReq, origRes, req);
|
|
311
312
|
else
|
|
312
313
|
await this.runWithRemult(async (remult) => {
|
package/esm/src/context.js
CHANGED
|
@@ -140,6 +140,11 @@ export class Remult {
|
|
|
140
140
|
return this.isAllowed(allowed);
|
|
141
141
|
return undefined;
|
|
142
142
|
}
|
|
143
|
+
useFetch(fetch) {
|
|
144
|
+
this.dataProvider = new RestDataProvider(() => ({
|
|
145
|
+
httpClient: fetch,
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
143
148
|
/** The current data provider */
|
|
144
149
|
dataProvider = new RestDataProvider(() => this.apiClient);
|
|
145
150
|
/* @internal */
|
package/esm/src/remult-proxy.js
CHANGED
package/package.json
CHANGED
package/remult-sveltekit.js
CHANGED
|
@@ -95,35 +95,15 @@ function remultSveltekit(options) {
|
|
|
95
95
|
});
|
|
96
96
|
}); };
|
|
97
97
|
var handler = function (_a) { return tslib_1.__awaiter(_this, [_a], void 0, function (_b) {
|
|
98
|
-
var result_1;
|
|
99
98
|
var _this = this;
|
|
100
99
|
var event = _b.event, resolve = _b.resolve;
|
|
101
100
|
return tslib_1.__generator(this, function (_c) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (result_1 != null && (result_1 === null || result_1 === void 0 ? void 0 : result_1.status) != 404)
|
|
109
|
-
return [2 /*return*/, result_1];
|
|
110
|
-
_c.label = 2;
|
|
111
|
-
case 2: return [2 /*return*/, new Promise(function (res) {
|
|
112
|
-
result.withRemult(event, undefined, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
113
|
-
var _a;
|
|
114
|
-
return tslib_1.__generator(this, function (_b) {
|
|
115
|
-
switch (_b.label) {
|
|
116
|
-
case 0:
|
|
117
|
-
_a = res;
|
|
118
|
-
return [4 /*yield*/, resolve(event)];
|
|
119
|
-
case 1:
|
|
120
|
-
_a.apply(void 0, [_b.sent()]);
|
|
121
|
-
return [2 /*return*/];
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}); });
|
|
125
|
-
})];
|
|
126
|
-
}
|
|
101
|
+
return [2 /*return*/, result.withRemultAsync(event, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
102
|
+
switch (_a.label) {
|
|
103
|
+
case 0: return [4 /*yield*/, resolve(event)];
|
|
104
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
105
|
+
}
|
|
106
|
+
}); }); })];
|
|
127
107
|
});
|
|
128
108
|
}); };
|
|
129
109
|
return Object.assign(handler, {
|
|
@@ -132,6 +112,7 @@ function remultSveltekit(options) {
|
|
|
132
112
|
withRemult: function (request, what) {
|
|
133
113
|
return result.withRemultAsync(request, what);
|
|
134
114
|
},
|
|
115
|
+
hookHandler: handler,
|
|
135
116
|
GET: serverHandler,
|
|
136
117
|
PUT: serverHandler,
|
|
137
118
|
POST: serverHandler,
|
|
@@ -6,13 +6,6 @@ export declare class AsyncLocalStorageBridgeToRemultAsyncLocalStorageCoreImpl<T>
|
|
|
6
6
|
run<R>(store: T, callback: () => Promise<R>): Promise<R>;
|
|
7
7
|
getStore(): T | undefined;
|
|
8
8
|
}
|
|
9
|
-
export declare class SequentialRemultAsyncLocalStorageCore<T> implements RemultAsyncLocalStorageCore<T> {
|
|
10
|
-
wasImplemented: "yes";
|
|
11
|
-
run<R>(store: T, callback: () => Promise<R>): Promise<R>;
|
|
12
|
-
getStore(): T | undefined;
|
|
13
|
-
lastPromise: Promise<T | undefined>;
|
|
14
|
-
currentValue?: T;
|
|
15
|
-
}
|
|
16
9
|
export declare class StubRemultAsyncLocalStorageCore<T> implements RemultAsyncLocalStorageCore<T> {
|
|
17
10
|
isStub: boolean;
|
|
18
11
|
wasImplemented: "yes";
|
package/server/initAsyncHooks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AsyncLocalStorageBridgeToRemultAsyncLocalStorageCore = exports.StubRemultAsyncLocalStorageCore = exports.
|
|
3
|
+
exports.AsyncLocalStorageBridgeToRemultAsyncLocalStorageCore = exports.StubRemultAsyncLocalStorageCore = exports.AsyncLocalStorageBridgeToRemultAsyncLocalStorageCoreImpl = void 0;
|
|
4
4
|
exports.initAsyncHooks = initAsyncHooks;
|
|
5
5
|
var tslib_1 = require("tslib");
|
|
6
6
|
var async_hooks_1 = require("async_hooks");
|
|
@@ -66,78 +66,6 @@ var AsyncLocalStorageBridgeToRemultAsyncLocalStorageCoreImpl = /** @class */ (fu
|
|
|
66
66
|
return AsyncLocalStorageBridgeToRemultAsyncLocalStorageCoreImpl;
|
|
67
67
|
}());
|
|
68
68
|
exports.AsyncLocalStorageBridgeToRemultAsyncLocalStorageCoreImpl = AsyncLocalStorageBridgeToRemultAsyncLocalStorageCoreImpl;
|
|
69
|
-
var ignoreInStack = [
|
|
70
|
-
'AsyncLocalStorageBridgeToRemultAsyncLocalStorageCore.run',
|
|
71
|
-
'RemultAsyncLocalStorage.run',
|
|
72
|
-
'Module.withRemult',
|
|
73
|
-
'RemultServerImplementation.runWithRemult',
|
|
74
|
-
];
|
|
75
|
-
var SequentialRemultAsyncLocalStorageCore = /** @class */ (function () {
|
|
76
|
-
function SequentialRemultAsyncLocalStorageCore() {
|
|
77
|
-
this.wasImplemented = 'yes';
|
|
78
|
-
this.lastPromise = Promise.resolve(undefined);
|
|
79
|
-
}
|
|
80
|
-
SequentialRemultAsyncLocalStorageCore.prototype.run = function (store, callback) {
|
|
81
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
82
|
-
var log, stack_1, y, nextPromise;
|
|
83
|
-
var _this = this;
|
|
84
|
-
return tslib_1.__generator(this, function (_a) {
|
|
85
|
-
switch (_a.label) {
|
|
86
|
-
case 0:
|
|
87
|
-
log = function (msg) { };
|
|
88
|
-
if (false) {
|
|
89
|
-
stack_1 = new Error().stack;
|
|
90
|
-
y = stack_1.split('\n');
|
|
91
|
-
while (y.length > 0 &&
|
|
92
|
-
(y[0].trim().startsWith('Error') ||
|
|
93
|
-
ignoreInStack.includes(y[0].trim().split(' ')[1]))) {
|
|
94
|
-
y.splice(0, 1);
|
|
95
|
-
}
|
|
96
|
-
stack_1 = y.join('\n');
|
|
97
|
-
log = function (msg) {
|
|
98
|
-
console.log(msg, stack_1);
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
log('waiting on ');
|
|
102
|
-
nextPromise = this.lastPromise.then(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
103
|
-
var previousValue, result;
|
|
104
|
-
return tslib_1.__generator(this, function (_a) {
|
|
105
|
-
switch (_a.label) {
|
|
106
|
-
case 0:
|
|
107
|
-
log('executing ');
|
|
108
|
-
previousValue = this.currentValue;
|
|
109
|
-
this.currentValue = store;
|
|
110
|
-
return [4 /*yield*/, callback()];
|
|
111
|
-
case 1:
|
|
112
|
-
result = _a.sent();
|
|
113
|
-
this.currentValue = previousValue;
|
|
114
|
-
return [2 /*return*/, result];
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}); });
|
|
118
|
-
this.lastPromise = nextPromise.catch(function () {
|
|
119
|
-
log('Error on ');
|
|
120
|
-
return undefined;
|
|
121
|
-
});
|
|
122
|
-
_a.label = 1;
|
|
123
|
-
case 1:
|
|
124
|
-
_a.trys.push([1, , 3, 4]);
|
|
125
|
-
return [4 /*yield*/, nextPromise];
|
|
126
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
127
|
-
case 3:
|
|
128
|
-
log('completed ');
|
|
129
|
-
return [7 /*endfinally*/];
|
|
130
|
-
case 4: return [2 /*return*/];
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
SequentialRemultAsyncLocalStorageCore.prototype.getStore = function () {
|
|
136
|
-
return this.currentValue;
|
|
137
|
-
};
|
|
138
|
-
return SequentialRemultAsyncLocalStorageCore;
|
|
139
|
-
}());
|
|
140
|
-
exports.SequentialRemultAsyncLocalStorageCore = SequentialRemultAsyncLocalStorageCore;
|
|
141
69
|
var StubRemultAsyncLocalStorageCore = /** @class */ (function () {
|
|
142
70
|
function StubRemultAsyncLocalStorageCore() {
|
|
143
71
|
this.isStub = true;
|
|
@@ -155,7 +155,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
155
155
|
return [2 /*return*/];
|
|
156
156
|
}
|
|
157
157
|
});
|
|
158
|
-
}); })(req, res)];
|
|
158
|
+
}); }, true)(req, res)];
|
|
159
159
|
case 1:
|
|
160
160
|
_a.sent();
|
|
161
161
|
return [2 /*return*/];
|
|
@@ -574,7 +574,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
574
574
|
});
|
|
575
575
|
});
|
|
576
576
|
};
|
|
577
|
-
RemultServerImplementation.prototype.process = function (what) {
|
|
577
|
+
RemultServerImplementation.prototype.process = function (what, doNotReuseInitRequest) {
|
|
578
578
|
var _this = this;
|
|
579
579
|
return function (req, origRes) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
580
580
|
var genReq, myReq, myRes, err_2;
|
|
@@ -595,7 +595,8 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
595
595
|
_a.label = 1;
|
|
596
596
|
case 1:
|
|
597
597
|
_a.trys.push([1, 6, , 7]);
|
|
598
|
-
if (!remult_static_js_1.remultStatic.asyncContext.isInInitRequest()
|
|
598
|
+
if (!(remult_static_js_1.remultStatic.asyncContext.isInInitRequest() &&
|
|
599
|
+
!doNotReuseInitRequest)) return [3 /*break*/, 3];
|
|
599
600
|
return [4 /*yield*/, what(remult_static_js_1.remultStatic.asyncContext.getStore().remult, myReq, myRes, genReq, origRes, req)];
|
|
600
601
|
case 2: return [2 /*return*/, _a.sent()];
|
|
601
602
|
case 3: return [4 /*yield*/, this.runWithRemult(function (remult) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
package/src/context.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export declare class Remult {
|
|
|
59
59
|
* [Allowed](https://remult.dev/docs/allowed.html)
|
|
60
60
|
*/
|
|
61
61
|
isAllowedForInstance(instance: any, allowed?: AllowedForInstance<any>): boolean;
|
|
62
|
+
useFetch(fetch: ApiClient['httpClient']): void;
|
|
62
63
|
/** The current data provider */
|
|
63
64
|
dataProvider: DataProvider;
|
|
64
65
|
/** Creates a new instance of the `remult` object.
|
package/src/context.js
CHANGED
|
@@ -230,6 +230,11 @@ var Remult = /** @class */ (function () {
|
|
|
230
230
|
return this.isAllowed(allowed);
|
|
231
231
|
return undefined;
|
|
232
232
|
};
|
|
233
|
+
Remult.prototype.useFetch = function (fetch) {
|
|
234
|
+
this.dataProvider = new rest_data_provider_js_1.RestDataProvider(function () { return ({
|
|
235
|
+
httpClient: fetch,
|
|
236
|
+
}); });
|
|
237
|
+
};
|
|
233
238
|
//@ts-ignore // type error of typescript regarding args that doesn't appear in my normal development
|
|
234
239
|
/** Used to call a `backendMethod` using a specific `remult` object
|
|
235
240
|
* @example
|
package/src/remult-proxy.js
CHANGED
|
@@ -333,6 +333,9 @@ var RemultProxy = /** @class */ (function () {
|
|
|
333
333
|
RemultProxy.prototype.clearAllCache = function () {
|
|
334
334
|
return remult_static_js_1.remultStatic.remultFactory().clearAllCache();
|
|
335
335
|
};
|
|
336
|
+
RemultProxy.prototype.useFetch = function (args) {
|
|
337
|
+
return remult_static_js_1.remultStatic.remultFactory().useFetch(args);
|
|
338
|
+
};
|
|
336
339
|
Object.defineProperty(RemultProxy.prototype, "user", {
|
|
337
340
|
get: function () {
|
|
338
341
|
return remult_static_js_1.remultStatic.remultFactory().user;
|