remult 3.0.5-next.0 → 3.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.
@@ -0,0 +1 @@
1
+ export { initAsyncHooks } from './server/initAsyncHooks.js';
package/async-hooks.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initAsyncHooks = void 0;
4
+ var initAsyncHooks_js_1 = require("./server/initAsyncHooks.js");
5
+ Object.defineProperty(exports, "initAsyncHooks", { enumerable: true, get: function () { return initAsyncHooks_js_1.initAsyncHooks; } });
@@ -0,0 +1 @@
1
+ export { initAsyncHooks } from './server/initAsyncHooks.js';
@@ -2,6 +2,31 @@ import { AsyncLocalStorage } from 'async_hooks';
2
2
  import { RemultAsyncLocalStorage, } from '../src/context.js';
3
3
  import { remultStatic } from '../src/remult-static.js';
4
4
  let init = false;
5
+ /**
6
+ * Initializes async context tracking for the server.
7
+ *
8
+ * This should be called before handling any incoming requests or calling `withRemult()`.
9
+ * @example
10
+ * import { remult, repo, withRemult } from 'remult';
11
+ * import { initAsyncHooks } from 'remult/async-hooks';
12
+ *
13
+ * import { Task } from './entities/Task.js';
14
+ *
15
+ * initAsyncHooks();
16
+ *
17
+ * // Thx to the `initAsyncHooks` above,
18
+ * // we have isolated async contexts with multiple `withRemult()`,
19
+ * // without needing to initialize a `remultApi` all the time!
20
+ * withRemult(async () => {
21
+ * remult.user = { id: '42' };
22
+ * repo(Task).find()
23
+ * });
24
+ *
25
+ * withRemult(async () => {
26
+ * remult.user = { id: '21' };
27
+ * repo(Task).find()
28
+ * });
29
+ */
5
30
  export function initAsyncHooks() {
6
31
  if (init)
7
32
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "3.0.5-next.0",
3
+ "version": "3.0.5",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "homepage": "https://remult.dev",
6
6
  "repository": {
@@ -41,6 +41,11 @@
41
41
  "import": "./esm/remult-next.js",
42
42
  "types": "./remult-next.d.ts"
43
43
  },
44
+ "./async-hooks": {
45
+ "require": "./async-hooks.js",
46
+ "import": "./esm/async-hooks.js",
47
+ "types": "./async-hooks.d.ts"
48
+ },
44
49
  "./server": {
45
50
  "require": "./server/index.js",
46
51
  "import": "./esm/server/index.js",
@@ -1,4 +1,29 @@
1
1
  import { type RemultAsyncLocalStorageCore } from '../src/context.js';
2
+ /**
3
+ * Initializes async context tracking for the server.
4
+ *
5
+ * This should be called before handling any incoming requests or calling `withRemult()`.
6
+ * @example
7
+ * import { remult, repo, withRemult } from 'remult';
8
+ * import { initAsyncHooks } from 'remult/async-hooks';
9
+ *
10
+ * import { Task } from './entities/Task.js';
11
+ *
12
+ * initAsyncHooks();
13
+ *
14
+ * // Thx to the `initAsyncHooks` above,
15
+ * // we have isolated async contexts with multiple `withRemult()`,
16
+ * // without needing to initialize a `remultApi` all the time!
17
+ * withRemult(async () => {
18
+ * remult.user = { id: '42' };
19
+ * repo(Task).find()
20
+ * });
21
+ *
22
+ * withRemult(async () => {
23
+ * remult.user = { id: '21' };
24
+ * repo(Task).find()
25
+ * });
26
+ */
2
27
  export declare function initAsyncHooks(): void;
3
28
  export declare class AsyncLocalStorageBridgeToRemultAsyncLocalStorageCoreImpl<T> implements RemultAsyncLocalStorageCore<T> {
4
29
  private asyncLocalStorage;
@@ -7,6 +7,31 @@ var async_hooks_1 = require("async_hooks");
7
7
  var context_js_1 = require("../src/context.js");
8
8
  var remult_static_js_1 = require("../src/remult-static.js");
9
9
  var init = false;
10
+ /**
11
+ * Initializes async context tracking for the server.
12
+ *
13
+ * This should be called before handling any incoming requests or calling `withRemult()`.
14
+ * @example
15
+ * import { remult, repo, withRemult } from 'remult';
16
+ * import { initAsyncHooks } from 'remult/async-hooks';
17
+ *
18
+ * import { Task } from './entities/Task.js';
19
+ *
20
+ * initAsyncHooks();
21
+ *
22
+ * // Thx to the `initAsyncHooks` above,
23
+ * // we have isolated async contexts with multiple `withRemult()`,
24
+ * // without needing to initialize a `remultApi` all the time!
25
+ * withRemult(async () => {
26
+ * remult.user = { id: '42' };
27
+ * repo(Task).find()
28
+ * });
29
+ *
30
+ * withRemult(async () => {
31
+ * remult.user = { id: '21' };
32
+ * repo(Task).find()
33
+ * });
34
+ */
10
35
  function initAsyncHooks() {
11
36
  var _this = this;
12
37
  if (init)