@declaro/core 2.0.0-beta.99 → 2.1.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 (60) hide show
  1. package/dist/browser/index.js +21 -27
  2. package/dist/browser/index.js.map +37 -27
  3. package/dist/browser/scope/index.js +1 -2
  4. package/dist/browser/scope/index.js.map +1 -1
  5. package/dist/bun/index.js +19011 -0
  6. package/dist/bun/index.js.map +132 -0
  7. package/dist/bun/scope/index.js +4 -0
  8. package/dist/bun/scope/index.js.map +9 -0
  9. package/dist/node/index.cjs +2581 -874
  10. package/dist/node/index.cjs.map +36 -27
  11. package/dist/node/index.js +2572 -868
  12. package/dist/node/index.js.map +36 -27
  13. package/dist/node/scope/index.cjs +31 -10
  14. package/dist/node/scope/index.cjs.map +1 -1
  15. package/dist/node/scope/index.js +1 -27
  16. package/dist/node/scope/index.js.map +1 -1
  17. package/dist/ts/context/async-context.d.ts +54 -0
  18. package/dist/ts/context/async-context.d.ts.map +1 -0
  19. package/dist/ts/context/async-context.test.d.ts +2 -0
  20. package/dist/ts/context/async-context.test.d.ts.map +1 -0
  21. package/dist/ts/context/context.circular-deps.test.d.ts +2 -0
  22. package/dist/ts/context/context.circular-deps.test.d.ts.map +1 -0
  23. package/dist/ts/context/context.d.ts +297 -38
  24. package/dist/ts/context/context.d.ts.map +1 -1
  25. package/dist/ts/http/request-context.d.ts.map +1 -1
  26. package/dist/ts/index.d.ts +2 -0
  27. package/dist/ts/index.d.ts.map +1 -1
  28. package/dist/ts/schema/json-schema.d.ts +9 -1
  29. package/dist/ts/schema/json-schema.d.ts.map +1 -1
  30. package/dist/ts/schema/model.d.ts +6 -1
  31. package/dist/ts/schema/model.d.ts.map +1 -1
  32. package/dist/ts/schema/test/mock-model.d.ts +2 -2
  33. package/dist/ts/schema/test/mock-model.d.ts.map +1 -1
  34. package/dist/ts/shared/utils/schema-utils.d.ts +3 -0
  35. package/dist/ts/shared/utils/schema-utils.d.ts.map +1 -0
  36. package/dist/ts/shared/utils/schema-utils.test.d.ts +2 -0
  37. package/dist/ts/shared/utils/schema-utils.test.d.ts.map +1 -0
  38. package/dist/ts/shims/async-local-storage.d.ts +36 -0
  39. package/dist/ts/shims/async-local-storage.d.ts.map +1 -0
  40. package/dist/ts/shims/async-local-storage.test.d.ts +2 -0
  41. package/dist/ts/shims/async-local-storage.test.d.ts.map +1 -0
  42. package/package.json +17 -9
  43. package/src/context/async-context.test.ts +348 -0
  44. package/src/context/async-context.ts +129 -0
  45. package/src/context/context.circular-deps.test.ts +1047 -0
  46. package/src/context/context.test.ts +150 -0
  47. package/src/context/context.ts +493 -55
  48. package/src/http/request-context.ts +1 -3
  49. package/src/index.ts +2 -0
  50. package/src/schema/json-schema.ts +14 -1
  51. package/src/schema/model-schema.test.ts +155 -1
  52. package/src/schema/model.ts +34 -3
  53. package/src/schema/test/mock-model.ts +6 -2
  54. package/src/shared/utils/schema-utils.test.ts +33 -0
  55. package/src/shared/utils/schema-utils.ts +17 -0
  56. package/src/shims/async-local-storage.test.ts +258 -0
  57. package/src/shims/async-local-storage.ts +82 -0
  58. package/dist/ts/schema/entity-schema.test.d.ts +0 -1
  59. package/dist/ts/schema/entity-schema.test.d.ts.map +0 -1
  60. package/src/schema/entity-schema.test.ts +0 -0
@@ -4,39 +4,60 @@ var __defProp = Object.defineProperty;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
7
12
  var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
8
20
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
21
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
22
  for (let key of __getOwnPropNames(mod))
11
23
  if (!__hasOwnProp.call(to, key))
12
24
  __defProp(to, key, {
13
- get: () => mod[key],
25
+ get: __accessProp.bind(mod, key),
14
26
  enumerable: true
15
27
  });
28
+ if (canCache)
29
+ cache.set(mod, to);
16
30
  return to;
17
31
  };
18
- var __moduleCache = /* @__PURE__ */ new WeakMap;
19
32
  var __toCommonJS = (from) => {
20
- var entry = __moduleCache.get(from), desc;
33
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
21
34
  if (entry)
22
35
  return entry;
23
36
  entry = __defProp({}, "__esModule", { value: true });
24
- if (from && typeof from === "object" || typeof from === "function")
25
- __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
26
- get: () => from[key],
27
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
28
- }));
37
+ if (from && typeof from === "object" || typeof from === "function") {
38
+ for (var key of __getOwnPropNames(from))
39
+ if (!__hasOwnProp.call(entry, key))
40
+ __defProp(entry, key, {
41
+ get: __accessProp.bind(from, key),
42
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
43
+ });
44
+ }
29
45
  __moduleCache.set(from, entry);
30
46
  return entry;
31
47
  };
48
+ var __moduleCache;
32
49
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
50
+ var __returnValue = (v) => v;
51
+ function __exportSetter(name, newValue) {
52
+ this[name] = __returnValue.bind(null, newValue);
53
+ }
33
54
  var __export = (target, all) => {
34
55
  for (var name in all)
35
56
  __defProp(target, name, {
36
57
  get: all[name],
37
58
  enumerable: true,
38
59
  configurable: true,
39
- set: (newValue) => all[name] = () => newValue
60
+ set: __exportSetter.bind(all, name)
40
61
  });
41
62
  };
42
63
 
@@ -44,5 +65,5 @@ var __export = (target, all) => {
44
65
  var exports_scope = {};
45
66
  module.exports = __toCommonJS(exports_scope);
46
67
 
47
- //# debugId=DA373C2316A93B6E64756E2164756E21
68
+ //# debugId=CF57D37C2EF99C7064756E2164756E21
48
69
  //# sourceMappingURL=index.cjs.map
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "DA373C2316A93B6E64756E2164756E21",
7
+ "debugId": "CF57D37C2EF99C7064756E2164756E21",
8
8
  "names": []
9
9
  }
@@ -1,29 +1,3 @@
1
- var __create = Object.create;
2
- var __getProtoOf = Object.getPrototypeOf;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __toESM = (mod, isNodeMode, target) => {
7
- target = mod != null ? __create(__getProtoOf(mod)) : {};
8
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
9
- for (let key of __getOwnPropNames(mod))
10
- if (!__hasOwnProp.call(to, key))
11
- __defProp(to, key, {
12
- get: () => mod[key],
13
- enumerable: true
14
- });
15
- return to;
16
- };
17
- var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
18
- var __export = (target, all) => {
19
- for (var name in all)
20
- __defProp(target, name, {
21
- get: all[name],
22
- enumerable: true,
23
- configurable: true,
24
- set: (newValue) => all[name] = () => newValue
25
- });
26
- };
27
1
 
28
- //# debugId=AD244C47FB0713B764756E2164756E21
2
+ //# debugId=136023E5B7D33CB064756E2164756E21
29
3
  //# sourceMappingURL=index.js.map
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "AD244C47FB0713B764756E2164756E21",
7
+ "debugId": "136023E5B7D33CB064756E2164756E21",
8
8
  "names": []
9
9
  }
@@ -0,0 +1,54 @@
1
+ import type { Context } from './context';
2
+ /**
3
+ * Minimal interface for the storage backing `withContext` / `useContext`.
4
+ * Satisfied by Node's native `AsyncLocalStorage` and by the browser shim.
5
+ */
6
+ export interface AsyncContextStorage<C extends Context = Context> {
7
+ run<R>(store: C, fn: (...args: any[]) => R, ...args: any[]): R;
8
+ getStore(): C | undefined;
9
+ }
10
+ export interface UseContextOptions {
11
+ strict?: boolean;
12
+ }
13
+ /**
14
+ * Create a `withContext` / `useContext` pair backed by the given storage.
15
+ *
16
+ * The generic type parameter `C` fixes the context type enforced by both
17
+ * functions, keeping the pair consistent. If no storage is provided, a new
18
+ * `AsyncLocalStorage<C>` is created automatically — in browser builds this
19
+ * resolves to the synchronous shim, so callers don't need to think about it.
20
+ *
21
+ * Pass a custom storage explicitly when you need an alternative
22
+ * implementation (e.g. a test spy or the browser shim in a test environment):
23
+ *
24
+ * @example Default (auto-polyfilled in browser builds)
25
+ * ```ts
26
+ * const { withContext, useContext } = createContextAPI<MyContext>()
27
+ * ```
28
+ *
29
+ * @example Custom storage (for testing or advanced use)
30
+ * ```ts
31
+ * import { AsyncLocalStorage } from '../shims/async-local-storage'
32
+ * const { withContext, useContext } = createContextAPI<MyContext>(new AsyncLocalStorage())
33
+ * ```
34
+ */
35
+ export declare function createContextAPI<C extends Context = Context>(storage?: AsyncContextStorage<C>): {
36
+ withContext: <T = unknown>(context: C, fn: () => T) => T;
37
+ useContext: {
38
+ <U extends C = C>(options?: {
39
+ strict?: false;
40
+ }): U | null;
41
+ <U extends C = C>(options: {
42
+ strict: true;
43
+ }): U;
44
+ };
45
+ };
46
+ export declare const withContext: <T = unknown>(context: Context<any>, fn: () => T) => T, useContext: {
47
+ <U extends Context<any> = Context<any>>(options?: {
48
+ strict?: false;
49
+ } | undefined): U | null;
50
+ <U extends Context<any> = Context<any>>(options: {
51
+ strict: true;
52
+ }): U;
53
+ };
54
+ //# sourceMappingURL=async-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-context.d.ts","sourceRoot":"","sources":["../../../src/context/async-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC;;;GAGG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IAC5D,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;IAC9D,QAAQ,IAAI,CAAC,GAAG,SAAS,CAAA;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC;kBA6CrE,CAAC,qBAAqB,CAAC,MAAM,MAAM,CAAC,KAAG,CAAC;;SA2BzC,CAAC,SAAS,CAAC,gBAAgB;YAAE,MAAM,CAAC,EAAE,KAAK,CAAA;SAAE,GAAG,CAAC,GAAG,IAAI;SACxD,CAAC,SAAS,CAAC,eAAe;YAAE,MAAM,EAAE,IAAI,CAAA;SAAE,GAAG,CAAC;;EAYrE;AAKD,eAAO,MAAQ,WAAW,GA7CD,CAAC,sDA6CE,UAAU;KAlBd,CAAC;iBAAqC,KAAK;;KAC3C,CAAC;gBAAmC,IAAI;;CAiBM,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=async-context.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-context.test.d.ts","sourceRoot":"","sources":["../../../src/context/async-context.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=context.circular-deps.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.circular-deps.test.d.ts","sourceRoot":"","sources":["../../../src/context/context.circular-deps.test.ts"],"names":[],"mappings":""}