@xrystal/core 3.32.1 → 3.37.4

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 (264) hide show
  1. package/README.md +676 -136
  2. package/package.json +27 -24
  3. package/tsconfig.base.json +15 -0
  4. package/x/bin/commands/create.mjs +34 -5
  5. package/x/bin/commands/doctor.mjs +115 -25
  6. package/x/bin/commands/hooks.mjs +55 -0
  7. package/x/bin/commands/project.mjs +75 -42
  8. package/x/bin/commands/release.mjs +8 -3
  9. package/x/bin/commands/sync-toolchain.mjs +43 -0
  10. package/x/bin/commands/tmp.mjs +13 -4
  11. package/x/bin/helpers/.generated/.generated-from +1 -0
  12. package/x/bin/helpers/.generated/tmp-schema.mjs +192 -0
  13. package/x/bin/helpers/banner.mjs +66 -12
  14. package/x/bin/helpers/build-config.mjs +342 -0
  15. package/x/bin/helpers/cli-help.mjs +164 -0
  16. package/x/bin/helpers/create-target.mjs +18 -2
  17. package/x/bin/helpers/project-artifacts.mjs +142 -0
  18. package/x/bin/helpers/runtime-info.mjs +172 -0
  19. package/x/bin/helpers/tmp-config.mjs +11 -10
  20. package/x/bin/helpers/tmp-layout.mjs +10 -16
  21. package/x/bin/helpers/tmp-schema.mjs +9 -0
  22. package/x/bin/helpers/toolchain-config.mjs +233 -0
  23. package/x/bin/main-cli.js +31 -3
  24. package/x/bin/scripts/clean-source-types.mjs +19 -0
  25. package/x/bin/scripts/fix-dist-imports.mjs +80 -0
  26. package/x/bin/scripts/install-git-hooks.mjs +86 -0
  27. package/x/bin/scripts/minify-dist.mjs +50 -0
  28. package/x/bin/scripts/prepare-npm-publish.mjs +39 -0
  29. package/x/bin/scripts/publish-guard.mjs +113 -0
  30. package/x/bin/scripts/verify-npm-pack.mjs +12 -0
  31. package/x/bin/scripts/verify-publish-config.mjs +10 -0
  32. package/x/bin/scripts/verify-version-bump.mjs +27 -0
  33. package/x/bin/scripts/version-check.mjs +173 -0
  34. package/x/dist/index.js +1 -0
  35. package/x/dist/loader/clients/index.js +1 -0
  36. package/x/dist/loader/configs/index.js +1 -0
  37. package/{source → x/dist}/loader/controller/index.d.ts +20 -17
  38. package/x/dist/loader/controller/index.js +1 -0
  39. package/x/dist/loader/dto/index.js +1 -0
  40. package/x/dist/loader/events/index.js +1 -0
  41. package/x/dist/loader/index.d.ts +11 -0
  42. package/x/dist/loader/index.js +1 -0
  43. package/{source → x/dist}/loader/kafka/index.d.ts +1 -0
  44. package/x/dist/loader/kafka/index.js +1 -0
  45. package/x/dist/loader/localizations/index.js +1 -0
  46. package/{source → x/dist}/loader/logger/index.d.ts +1 -0
  47. package/x/dist/loader/logger/index.js +2 -0
  48. package/x/dist/loader/service/index.js +1 -0
  49. package/x/dist/loader/system/index.js +1 -0
  50. package/x/dist/project/index.d.ts +12 -0
  51. package/x/dist/project/index.js +1 -0
  52. package/x/dist/utils/constants/defaults.json +44 -0
  53. package/x/dist/utils/constants/index.js +1 -0
  54. package/x/dist/utils/helpers/configs/index.js +1 -0
  55. package/x/dist/utils/helpers/context/controller-store.js +1 -0
  56. package/x/dist/utils/helpers/context/index.js +1 -0
  57. package/{source → x/dist}/utils/helpers/core/index.d.ts +1 -1
  58. package/x/dist/utils/helpers/core/index.js +1 -0
  59. package/x/dist/utils/helpers/core/paths.js +1 -0
  60. package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
  61. package/x/dist/utils/helpers/date/index.js +1 -0
  62. package/x/dist/utils/helpers/dispatch/index.js +1 -0
  63. package/x/dist/utils/helpers/dto/index.js +1 -0
  64. package/x/dist/utils/helpers/filters/index.js +1 -0
  65. package/x/dist/utils/helpers/framework/index.js +1 -0
  66. package/x/dist/utils/helpers/handlers/adapters.js +1 -0
  67. package/x/dist/utils/helpers/handlers/execute.js +1 -0
  68. package/x/dist/utils/helpers/handlers/index.js +1 -0
  69. package/x/dist/utils/helpers/hash/crypto.js +1 -0
  70. package/x/dist/utils/helpers/id/index.js +1 -0
  71. package/x/dist/utils/helpers/index.js +1 -0
  72. package/x/dist/utils/helpers/ip/index.js +1 -0
  73. package/x/dist/utils/helpers/is/index.js +1 -0
  74. package/x/dist/utils/helpers/locales/index.js +1 -0
  75. package/x/dist/utils/helpers/math/index.js +1 -0
  76. package/{source → x/dist}/utils/helpers/middleware/index.d.ts +2 -2
  77. package/x/dist/utils/helpers/middleware/index.js +1 -0
  78. package/x/dist/utils/helpers/objects/index.js +1 -0
  79. package/x/dist/utils/helpers/path/index.js +1 -0
  80. package/{source → x/dist}/utils/helpers/protocol/index.d.ts +2 -10
  81. package/x/dist/utils/helpers/protocol/index.js +1 -0
  82. package/x/dist/utils/helpers/protocol/options.js +1 -0
  83. package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +1 -0
  84. package/x/dist/utils/helpers/runtime/dto-access.js +1 -0
  85. package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
  86. package/{source → x/dist}/utils/helpers/runtime/index.d.ts +1 -0
  87. package/x/dist/utils/helpers/runtime/index.js +1 -0
  88. package/x/dist/utils/helpers/runtime/shutdown.d.ts +3 -0
  89. package/x/dist/utils/helpers/runtime/shutdown.js +1 -0
  90. package/x/dist/utils/helpers/state/index.js +1 -0
  91. package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
  92. package/x/dist/utils/helpers/state/request-key-guard.js +1 -0
  93. package/x/dist/utils/helpers/state/scopes.js +1 -0
  94. package/x/dist/utils/helpers/string/index.js +1 -0
  95. package/x/dist/utils/helpers/tests/tmp-schema.test.js +1 -0
  96. package/x/dist/utils/helpers/tests/tmp-watch.test.d.ts +1 -0
  97. package/x/dist/utils/helpers/tests/tmp-watch.test.js +1 -0
  98. package/x/dist/utils/helpers/timer/index.js +1 -0
  99. package/x/dist/utils/helpers/tmp/index.d.ts +5 -0
  100. package/x/dist/utils/helpers/tmp/index.js +1 -0
  101. package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -0
  102. package/{source → x/dist}/utils/helpers/tmp/runtime-tmp.d.ts +2 -6
  103. package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
  104. package/{source → x/dist}/utils/helpers/tmp/tmp-loader.d.ts +1 -0
  105. package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -0
  106. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +47 -0
  107. package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -0
  108. package/x/dist/utils/helpers/tmp/tmp-watch.d.ts +1 -0
  109. package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -0
  110. package/x/dist/utils/helpers/validates/index.js +1 -0
  111. package/x/dist/utils/index.js +1 -0
  112. package/x/dist/utils/models/classes/class.clients.js +1 -0
  113. package/x/dist/utils/models/classes/class.interfaces.js +1 -0
  114. package/x/dist/utils/models/classes/class.service-locator.js +1 -0
  115. package/{source → x/dist}/utils/models/classes/class.tmp-file-loader.d.ts +3 -2
  116. package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -0
  117. package/x/dist/utils/models/classes/class.x.js +1 -0
  118. package/x/dist/utils/models/enums/index.js +1 -0
  119. package/x/dist/utils/models/index.js +1 -0
  120. package/x/dist/utils/models/types/index.js +1 -0
  121. package/x/dist/utils/package-root.js +1 -0
  122. package/x/tmp.yml +51 -42
  123. package/source/index.js +0 -11
  124. package/source/loader/clients/index.js +0 -22
  125. package/source/loader/configs/index.js +0 -88
  126. package/source/loader/controller/index.js +0 -236
  127. package/source/loader/dto/index.js +0 -92
  128. package/source/loader/events/index.js +0 -44
  129. package/source/loader/index.d.ts +0 -11
  130. package/source/loader/index.js +0 -11
  131. package/source/loader/kafka/index.js +0 -137
  132. package/source/loader/localizations/index.js +0 -46
  133. package/source/loader/logger/index.js +0 -217
  134. package/source/loader/service/index.js +0 -7
  135. package/source/loader/system/index.js +0 -25
  136. package/source/project/index.d.ts +0 -8
  137. package/source/project/index.js +0 -70
  138. package/source/utils/constants/defaults.json +0 -15
  139. package/source/utils/constants/defaults.mjs +0 -10
  140. package/source/utils/constants/index.js +0 -22
  141. package/source/utils/helpers/configs/index.js +0 -1
  142. package/source/utils/helpers/context/controller-store.js +0 -12
  143. package/source/utils/helpers/context/index.js +0 -24
  144. package/source/utils/helpers/core/index.js +0 -58
  145. package/source/utils/helpers/core/paths.js +0 -78
  146. package/source/utils/helpers/core/tmp-layout.js +0 -241
  147. package/source/utils/helpers/date/index.js +0 -48
  148. package/source/utils/helpers/dispatch/index.js +0 -53
  149. package/source/utils/helpers/dto/index.js +0 -10
  150. package/source/utils/helpers/filters/index.js +0 -44
  151. package/source/utils/helpers/framework/index.js +0 -17
  152. package/source/utils/helpers/handlers/adapters.js +0 -40
  153. package/source/utils/helpers/handlers/execute.js +0 -82
  154. package/source/utils/helpers/handlers/index.js +0 -31
  155. package/source/utils/helpers/hash/crypto.js +0 -22
  156. package/source/utils/helpers/id/index.js +0 -24
  157. package/source/utils/helpers/index.js +0 -26
  158. package/source/utils/helpers/ip/index.js +0 -21
  159. package/source/utils/helpers/is/index.js +0 -35
  160. package/source/utils/helpers/locales/index.js +0 -82
  161. package/source/utils/helpers/math/index.js +0 -14
  162. package/source/utils/helpers/middleware/index.js +0 -36
  163. package/source/utils/helpers/objects/index.js +0 -55
  164. package/source/utils/helpers/path/index.js +0 -4
  165. package/source/utils/helpers/protocol/index.js +0 -99
  166. package/source/utils/helpers/protocol/options.js +0 -13
  167. package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
  168. package/source/utils/helpers/runtime/dto-access.js +0 -5
  169. package/source/utils/helpers/runtime/index.js +0 -1
  170. package/source/utils/helpers/state/index.js +0 -185
  171. package/source/utils/helpers/state/props-from-tmp.js +0 -44
  172. package/source/utils/helpers/state/request-key-guard.js +0 -42
  173. package/source/utils/helpers/state/scopes.js +0 -69
  174. package/source/utils/helpers/string/index.js +0 -9
  175. package/source/utils/helpers/timer/index.js +0 -5
  176. package/source/utils/helpers/tmp/index.d.ts +0 -3
  177. package/source/utils/helpers/tmp/index.js +0 -3
  178. package/source/utils/helpers/tmp/loader-tmp-sync.js +0 -13
  179. package/source/utils/helpers/tmp/runtime-tmp.js +0 -30
  180. package/source/utils/helpers/tmp/tmp-loader.js +0 -48
  181. package/source/utils/helpers/validates/index.js +0 -20
  182. package/source/utils/index.js +0 -3
  183. package/source/utils/models/classes/class.clients.js +0 -142
  184. package/source/utils/models/classes/class.interfaces.js +0 -10
  185. package/source/utils/models/classes/class.service-locator.js +0 -16
  186. package/source/utils/models/classes/class.tmp-file-loader.js +0 -38
  187. package/source/utils/models/classes/class.x.js +0 -180
  188. package/source/utils/models/enums/index.js +0 -148
  189. package/source/utils/models/index.js +0 -9
  190. package/source/utils/models/types/index.js +0 -2
  191. package/source/utils/models/types/shims.d.ts +0 -123
  192. package/source/utils/package-root.js +0 -5
  193. package/x/tests/cli.test.ts +0 -85
  194. package/x/tests/context.test.ts +0 -25
  195. package/x/tests/dispatch.test.ts +0 -84
  196. package/x/tests/fixtures/locales/en/translation.json +0 -8
  197. package/x/tests/fixtures/locales/tr/translation.json +0 -8
  198. package/x/tests/frameworks.integration.test.ts +0 -185
  199. package/x/tests/helpers/i18n-setup.ts +0 -52
  200. package/x/tests/helpers/middleware.ts +0 -23
  201. package/x/tests/helpers/register-test-dto.ts +0 -52
  202. package/x/tests/i18n.integration.test.ts +0 -77
  203. package/x/tests/i18n.test.ts +0 -96
  204. package/x/tests/middleware.test.ts +0 -83
  205. package/x/tests/project-layout.test.ts +0 -65
  206. package/x/tests/protocol.test.ts +0 -75
  207. package/x/tests/realtime.examples.test.ts +0 -198
  208. package/x/tests/runtime-tmp.test.ts +0 -49
  209. package/x/tests/socket.integration.test.ts +0 -174
  210. package/x/tests/state.test.ts +0 -183
  211. package/x/tests/tmp-layout-guard.test.ts +0 -40
  212. /package/{source → x/dist}/index.d.ts +0 -0
  213. /package/{source → x/dist}/loader/clients/index.d.ts +0 -0
  214. /package/{source → x/dist}/loader/configs/index.d.ts +0 -0
  215. /package/{source → x/dist}/loader/dto/index.d.ts +0 -0
  216. /package/{source → x/dist}/loader/events/index.d.ts +0 -0
  217. /package/{source → x/dist}/loader/localizations/index.d.ts +0 -0
  218. /package/{source → x/dist}/loader/service/index.d.ts +0 -0
  219. /package/{source → x/dist}/loader/system/index.d.ts +0 -0
  220. /package/{source → x/dist}/utils/constants/index.d.ts +0 -0
  221. /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
  222. /package/{source → x/dist}/utils/helpers/context/controller-store.d.ts +0 -0
  223. /package/{source → x/dist}/utils/helpers/context/index.d.ts +0 -0
  224. /package/{source → x/dist}/utils/helpers/core/paths.d.ts +0 -0
  225. /package/{source → x/dist}/utils/helpers/core/tmp-layout.d.ts +0 -0
  226. /package/{source → x/dist}/utils/helpers/date/index.d.ts +0 -0
  227. /package/{source → x/dist}/utils/helpers/dispatch/index.d.ts +0 -0
  228. /package/{source → x/dist}/utils/helpers/dto/index.d.ts +0 -0
  229. /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
  230. /package/{source → x/dist}/utils/helpers/framework/index.d.ts +0 -0
  231. /package/{source → x/dist}/utils/helpers/handlers/adapters.d.ts +0 -0
  232. /package/{source → x/dist}/utils/helpers/handlers/execute.d.ts +0 -0
  233. /package/{source → x/dist}/utils/helpers/handlers/index.d.ts +0 -0
  234. /package/{source → x/dist}/utils/helpers/hash/crypto.d.ts +0 -0
  235. /package/{source → x/dist}/utils/helpers/id/index.d.ts +0 -0
  236. /package/{source → x/dist}/utils/helpers/index.d.ts +0 -0
  237. /package/{source → x/dist}/utils/helpers/ip/index.d.ts +0 -0
  238. /package/{source → x/dist}/utils/helpers/is/index.d.ts +0 -0
  239. /package/{source → x/dist}/utils/helpers/locales/index.d.ts +0 -0
  240. /package/{source → x/dist}/utils/helpers/math/index.d.ts +0 -0
  241. /package/{source → x/dist}/utils/helpers/objects/index.d.ts +0 -0
  242. /package/{source → x/dist}/utils/helpers/path/index.d.ts +0 -0
  243. /package/{source → x/dist}/utils/helpers/protocol/options.d.ts +0 -0
  244. /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
  245. /package/{source → x/dist}/utils/helpers/runtime/dto-access.d.ts +0 -0
  246. /package/{source → x/dist}/utils/helpers/runtime/dto-types.d.ts +0 -0
  247. /package/{source → x/dist}/utils/helpers/state/index.d.ts +0 -0
  248. /package/{source → x/dist}/utils/helpers/state/props-from-tmp.d.ts +0 -0
  249. /package/{source → x/dist}/utils/helpers/state/request-key-guard.d.ts +0 -0
  250. /package/{source → x/dist}/utils/helpers/state/scopes.d.ts +0 -0
  251. /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
  252. /package/{source/utils/helpers/runtime/dto-types.js → x/dist/utils/helpers/tests/tmp-schema.test.d.ts} +0 -0
  253. /package/{source → x/dist}/utils/helpers/timer/index.d.ts +0 -0
  254. /package/{source → x/dist}/utils/helpers/tmp/loader-tmp-sync.d.ts +0 -0
  255. /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
  256. /package/{source → x/dist}/utils/index.d.ts +0 -0
  257. /package/{source → x/dist}/utils/models/classes/class.clients.d.ts +0 -0
  258. /package/{source → x/dist}/utils/models/classes/class.interfaces.d.ts +0 -0
  259. /package/{source → x/dist}/utils/models/classes/class.service-locator.d.ts +0 -0
  260. /package/{source → x/dist}/utils/models/classes/class.x.d.ts +0 -0
  261. /package/{source → x/dist}/utils/models/enums/index.d.ts +0 -0
  262. /package/{source → x/dist}/utils/models/index.d.ts +0 -0
  263. /package/{source → x/dist}/utils/models/types/index.d.ts +0 -0
  264. /package/{source → x/dist}/utils/package-root.d.ts +0 -0
@@ -1,22 +0,0 @@
1
- import crypto from 'crypto';
2
- export function generateSHA256Hash(secret, payload) {
3
- return crypto
4
- .createHmac('sha256', secret)
5
- .update(payload ? payload : '')
6
- .digest('hex');
7
- }
8
- export function generateNumberAndLetter(length = 8) {
9
- const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
10
- const array = new Uint8Array(length);
11
- crypto.getRandomValues(array);
12
- return Array.from(array, byte => charset[byte % charset.length]).join('');
13
- }
14
- export function generateCodeChallenge(codeVerifier) {
15
- return crypto
16
- .createHash('sha256')
17
- .update(codeVerifier)
18
- .digest('base64')
19
- .replace(/\+/g, '-')
20
- .replace(/\//g, '_')
21
- .replace(/=+$/, '');
22
- }
@@ -1,24 +0,0 @@
1
- import crypto from 'crypto';
2
- export const serverIdNameGenerator = ({ prefix, payload, suffix }) => {
3
- return `${prefix}-${payload.toString()}-${suffix}`;
4
- };
5
- export function generateRandomKey(options) {
6
- const { length = 48, format = 'hex', prefix = '', suffix = '', separator = '-', } = options;
7
- const randomPart = crypto.randomBytes(length).toString(format);
8
- const parts = [prefix, randomPart, suffix].filter(Boolean);
9
- return parts.join(separator);
10
- }
11
- export function generateReferenceCode(length, prefix = "", middle = "", suffix = "") {
12
- const totalLength = prefix.length + length + middle.length + suffix.length;
13
- if (totalLength <= 0) {
14
- throw new Error("The total length (including prefix, middle, and suffix) must be greater than 0.");
15
- }
16
- let referenceCode = "";
17
- for (let i = 0; i < length; i++) {
18
- const randomDigit = Math.floor(Math.random() * 10);
19
- referenceCode += randomDigit.toString();
20
- }
21
- const middleIndex = Math.floor(referenceCode.length / 2);
22
- const referenceWithMiddle = referenceCode.slice(0, middleIndex) + middle + referenceCode.slice(middleIndex);
23
- return `${prefix}${referenceWithMiddle}${suffix}`;
24
- }
@@ -1,26 +0,0 @@
1
- export { default as pic } from "picocolors";
2
- export * from '../../utils/helpers/core';
3
- export * from '../../utils/helpers/path';
4
- export * from '../../utils/helpers/is';
5
- export * from '../../utils/helpers/id';
6
- export * from '../../utils/helpers/validates';
7
- export * from '../../utils/helpers/ip';
8
- export * from '../../utils/helpers/hash/crypto';
9
- export * from '../../utils/helpers/string';
10
- export * from '../../utils/helpers/objects';
11
- export * from '../../utils/helpers/locales';
12
- export * from '../../utils/helpers/timer';
13
- export * from '../../utils/helpers/date';
14
- export * from '../../utils/helpers/math';
15
- export * from '../../utils/helpers/regex/checkSpecialRegexControl';
16
- export * from '../../utils/helpers/filters';
17
- export * from '../../utils/helpers/framework';
18
- export * from '../../utils/helpers/protocol';
19
- export * from '../../utils/helpers/dto';
20
- export * from '../../utils/helpers/dispatch';
21
- export * from '../../utils/helpers/middleware';
22
- export * from '../../utils/helpers/context';
23
- export * from '../../utils/helpers/tmp';
24
- export * from '../../utils/helpers/state';
25
- export * from '../../utils/helpers/handlers';
26
- export * from '../../utils/helpers/runtime';
@@ -1,21 +0,0 @@
1
- export const getClientIp = (req, ctx = {}) => {
2
- try {
3
- const forwarded = req?.headers?.["x-forwarded-for"] || ctx?.headers?.["x-forwarded-for"];
4
- if (forwarded)
5
- return forwarded.split(",")[0].trim().replace("::ffff:", "");
6
- if (ctx?.ip)
7
- return ctx.ip.replace("::ffff:", "");
8
- if (req?.ip)
9
- return req.ip.replace("::ffff:", "");
10
- const remoteAddr = req?.socket?.remoteAddress ||
11
- ctx?.req?.socket?.remoteAddress ||
12
- req?.remoteAddress ||
13
- ctx?.address;
14
- if (remoteAddr)
15
- return remoteAddr.replace("::ffff:", "");
16
- return "127.0.0.1";
17
- }
18
- catch (e) {
19
- return "127.0.0.1";
20
- }
21
- };
@@ -1,35 +0,0 @@
1
- export function isFalsy(value, options) {
2
- if (!options.ignoreFalse && value === false)
3
- return true;
4
- if (!options.ignoreZero && value === 0)
5
- return true;
6
- if (!options.ignoreEmptyString && value === '')
7
- return true;
8
- if (!options.ignoreNull && value === null)
9
- return true;
10
- if (!options.ignoreUndefined && value === undefined)
11
- return true;
12
- if (!options.ignoreNaN && typeof value === 'number' && isNaN(value))
13
- return true;
14
- return false;
15
- }
16
- export function isType(data, type) {
17
- if (typeof data === type) {
18
- return true;
19
- }
20
- else {
21
- return false;
22
- }
23
- }
24
- export function isInstance(data, type) {
25
- if (data instanceof type) {
26
- return true;
27
- }
28
- else {
29
- return false;
30
- }
31
- }
32
- export function isBcryptHash(value) {
33
- const bcryptRegex = /^\$2[aby]\$\d{2}\$.{53}$/;
34
- return bcryptRegex.test(value);
35
- }
@@ -1,82 +0,0 @@
1
- const f = (...args) => args.filter(item => item && typeof item === 'string' && item.trim() !== '').join(' ').trim();
2
- export const coreMessages = {
3
- 'successfully': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.successfully')}.`.trim(),
4
- 'unsuccessful': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.unsuccessful')}.`.trim(),
5
- 'notFound': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.notFound')}.`.trim(),
6
- 'notMatch': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.notMatch')}.`.trim(),
7
- 'notUse': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.notUse')}.`.trim(),
8
- 'invalid': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.invalid')}.`.trim(),
9
- 'checked': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.checked')}.`.trim(),
10
- 'process': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.process')}.`.trim(),
11
- 'missingData': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.missingData')}.`.trim(),
12
- 'allreadyHave': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.allreadyHave')}.`.trim(),
13
- 'wrongFormat': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.wrongFormat')}.`.trim(),
14
- 'externalApiError': (p = '', e = '', t) => `${f(p, e)}, ${t && t('responseMessage.externalApiError')}.`.trim(),
15
- 'unauthorizedUrl': (p = '', e = '', t) => `${f(p, e)}, ${t && t('responseMessage.unauthorizedUrl')}.`.trim(),
16
- 'endpointNotWorking': (endpoint = '', t) => `${endpoint}, ${t && t('responseMessage.endpointNotWorking')}.`.trim(),
17
- 'schemaMissingDataChecks': (t) => `${t && t('responseMessage.schemaMissingDataChecks')}.`.trim(),
18
- 'schemaInvalidDataChecks': (t) => `${t && t('responseMessage.schemaInvalidDataChecks')}.`.trim(),
19
- 'schemaUnknowErrorChecks': (a, b, t) => `${t && t('responseMessage.schemaUnknowErrorChecks')}. ${a}. ${t('responseMessage.schemaErrorExtraExplanation')}: ${b}`.trim(),
20
- 'schemaUnknowErrorLogic': (a, b, t) => `${t && t('responseMessage.schemaUnknowErrorLogic')}. ${a}. ${t('responseMessage.schemaErrorExtraExplanation')}: ${b}`.trim(),
21
- 'schemaUnknowErrorResponse': (a, b, t) => `${t && t('responseMessage.schemaUnknowErrorLogic')}. ${a}. ${t('responseMessage.schemaErrorExtraExplanation')}: ${b}`.trim(),
22
- 'schemaUnknowErrorMain': (a, b, t) => `${t && t('responseMessage.schemaUnknowErrorMain')}. ${a}. ${t('responseMessage.schemaErrorExtraExplanation')}: ${b}`.trim(),
23
- 'dbQueryError': (p = '', e = '', t) => `${t && t('responseMessage.dbQueryError')}. ${f(p, e)}`.trim(),
24
- 'unknowError': (p = '', e = '', t) => `${t && t('responseMessage.unknowError')}. ${f(p, e)}`.trim(),
25
- 'serverError': (p = '', e = '', t) => `${t && t('responseMessage.serverError')}. ${f(p, e)}`.trim(),
26
- 'emailWelcomeTemplateTitle': (t) => `${t && t('responseMessage.emailWelcomeTemplateTitle')}`.trim(),
27
- 'emailWelcomeTemplateExplanation': (t) => `${t && t('responseMessage.emailWelcomeTemplateExplanation')}.`.trim(),
28
- 'emailForgotPasswordTemplateTitle': (t) => `${t && t('responseMessage.emailForgotPasswordTemplateTitle')}`.trim(),
29
- 'emailForgotPasswordTemplateExplanation': (t) => `${t && t('responseMessage.emailForgotPasswordTemplateExplanation')}.`.trim(),
30
- 'allRightsReserved': (e1 = '', e2 = '', t) => `${f(e1, e2)}, ${t && t('responseMessage.allRightsReserved')}.`.trim(),
31
- 'emailButtonText': (t) => `${t && t('responseMessage.emailButtonText')}.`.trim(),
32
- 'emailIgnoreText': (t) => `${t && t('responseMessage.emailIgnoreText')}.`.trim(),
33
- 'welcomeMessage': (username = '', t) => `@${username} - ${t && t('responseMessage.welcome')}.`.trim(),
34
- 'userIsBlocked': (extra1 = '', t) => `${extra1}, ${t && t('responseMessage.userIsBlocked')}.`.trim(),
35
- 'passwordChangeCode': (username = '', t) => `@${username} - ${t && t('responseMessage.passwordChangeCode')}.`.trim(),
36
- 'notEnoughWalletBalance': (m = '', c = '', t) => `${f(m, c)}, ${t && t('responseMessage.notEnoughWalletBalance')}.`.trim(),
37
- 'openAuthConsumerOverhang': (p1 = '', p2 = '', t) => `${f(p1, p2)}, ${t && t('responseMessage.openAuthConsumerOverhang')}.`.trim(),
38
- 'thirdPartySystemOverhang': (p1 = '', p2 = '', t) => `${f(p1, p2)}, ${t && t('responseMessage.thirdPartySystems')}.`.trim(),
39
- 'deviceOverhang': (p1 = '', p2 = '', t) => `${f(p1, p2)}, ${t && t('responseMessage.deviceOverhang')}.`.trim(),
40
- 'provisionOverhang': (m = '', c = '', t) => `${f(m, c)}, ${t && t('responseMessage.provisionOverhang')}.`.trim(),
41
- 'balanceOverhang': (m = '', c = '', t) => `${f(m, c)}, ${t && t('responseMessage.balanceOverhang')}.`.trim(),
42
- 'debtOverhang': (m = '', c = '', t) => `${f(m, c)}, ${t && t('responseMessage.debtOverhang')}.`.trim(),
43
- 'shipmentNotAccepted': (v1 = '', v2 = '', t) => `${t && t('responseMessage.shipmentNotAccepted')}. ${f(v1, v2)}`.trim(),
44
- 'optionsMethod': (m = '', t) => `${t && t('responseMessage.optionsMethod')}. ${m}`.trim(),
45
- 'notAllowedCORS': (m = '', t) => `${t && t('responseMessage.notAllowedCORS')}. ${m}`.trim(),
46
- 'missingCRSFToken': (t) => `${t && t('responseMessage.missingCSRFToken')}.`.trim(),
47
- 'invalidCRSFToken': (t) => `${t && t('responseMessage.invalidCSRFToken')}.`.trim(),
48
- 'tooManyRequest': (t) => `${t && t('responseMessage.tooManyRequest')}.`.trim(),
49
- 'endpointNotFound': (t) => `${t && t('responseMessage.endpointNotFound')}.`.trim(),
50
- 'roleAccess': (error = '', t) => `${t && t('responseMessage.roleAccess')}. ${error}`.trim(),
51
- 'authenticationRequiredTokenExpired': (t) => `${t && t('responseMessage.authenticationRequiredTokenExpired')}.`.trim(),
52
- 'authenticationRequired': (t) => `${t && t('responseMessage.authenticationRequired')}.`.trim(),
53
- };
54
- export const responseMessageHelper = new Proxy(coreMessages, {
55
- get(target, prop) {
56
- if (prop in target)
57
- return target[prop];
58
- const local = globalThis.__LOCAL_MESSAGES__;
59
- if (local && prop in local)
60
- return local[prop];
61
- return (p = '', e = '', t) => `${f(p, e)} ${prop}.`.trim();
62
- }
63
- });
64
- export function parseResponseMessage(msg, t, isError = false) {
65
- const content = String(msg || '');
66
- if (!content)
67
- return isError ? responseMessageHelper.unsuccessful('', '', t) : responseMessageHelper.successfully('', '', t);
68
- let method = isError ? 'unsuccessful' : 'successfully';
69
- let payload = content;
70
- if (content.startsWith('@')) {
71
- const parts = content.split(' ');
72
- method = parts[0].slice(1);
73
- payload = parts.slice(1).join(' ');
74
- }
75
- const params = payload ? payload.split('-').map(p => p.trim()).filter(Boolean) : [];
76
- const p1 = params[0] ?? (content.startsWith('@') ? undefined : '');
77
- const p2 = params.length > 1 ? params.slice(1).join(' ') : (content.startsWith('@') ? undefined : '');
78
- if (responseMessageHelper[method]) {
79
- return responseMessageHelper[method](p1, p2, t);
80
- }
81
- return isError ? responseMessageHelper.unsuccessful(p1 || '', p2 || '', t) : responseMessageHelper.successfully(p1 || '', p2 || '', t);
82
- }
@@ -1,14 +0,0 @@
1
- export function calcPercentace(value, percentage) {
2
- if (typeof value !== "number" || typeof percentage !== "number") {
3
- throw new Error("Değerler sayısal olmalıdır.");
4
- }
5
- return (value * percentage) / 100;
6
- }
7
- export function bankersRounding(value, decimals = 2) {
8
- const factor = Math.pow(10, decimals);
9
- const rounded = Math.round(value * factor);
10
- const isHalf = (value * factor) % 1 === 0.5;
11
- return isHalf && rounded % 2 !== 0
12
- ? (rounded - 1) / factor
13
- : rounded / factor;
14
- }
@@ -1,36 +0,0 @@
1
- import { FrameworkEnum } from '../../../utils/models';
2
- import { getFramework, parseFramework } from '../../../utils/helpers/framework';
3
- const ALIASES = {
4
- express: FrameworkEnum.EXPRESS,
5
- elysia: FrameworkEnum.ELYSIA,
6
- node: FrameworkEnum.NODE,
7
- fetch: FrameworkEnum.FETCH,
8
- websocket: FrameworkEnum.WEBSOCKET,
9
- ws: FrameworkEnum.WEBSOCKET,
10
- socketio: FrameworkEnum.SOCKETIO,
11
- };
12
- export function normalizeFrameworkKind(config) {
13
- if (config === undefined)
14
- return getFramework();
15
- const raw = typeof config === 'object' && config !== null && 'framework' in config
16
- ? config.framework
17
- : config;
18
- if (!raw)
19
- return getFramework();
20
- const key = String(raw).toLowerCase().replace(/[-_\s]/g, '');
21
- return ALIASES[key] ?? parseFramework(raw);
22
- }
23
- export function resolveDtoAdapter(runtime, framework) {
24
- switch (framework) {
25
- case FrameworkEnum.ELYSIA: return runtime.elysia();
26
- case FrameworkEnum.NODE: return runtime.node();
27
- case FrameworkEnum.SOCKETIO: return runtime.socketIo();
28
- case FrameworkEnum.WEBSOCKET: return runtime.websocket();
29
- case FrameworkEnum.FETCH: return null;
30
- case FrameworkEnum.EXPRESS: return runtime.express();
31
- default: return runtime.elysia();
32
- }
33
- }
34
- export function createDtoMiddleware(runtime, config) {
35
- return resolveDtoAdapter(runtime, normalizeFrameworkKind(config));
36
- }
@@ -1,55 +0,0 @@
1
- export function pickProps(obj, props) {
2
- if (!obj) {
3
- return {};
4
- }
5
- const negativeProps = new Set();
6
- const positiveProps = new Set();
7
- for (const p of props) {
8
- if (typeof p === 'string' && p.startsWith('-')) {
9
- negativeProps.add(p.substring(1));
10
- }
11
- else {
12
- positiveProps.add(p);
13
- }
14
- }
15
- function getNestedValue(o, path) {
16
- return path.reduce((acc, key) => (acc && acc[key] !== undefined ? acc[key] : undefined), o);
17
- }
18
- function setNestedValue(o, path, value) {
19
- let current = o;
20
- for (let i = 0; i < path.length - 1; i++) {
21
- if (!(path[i] in current))
22
- current[path[i]] = {};
23
- current = current[path[i]];
24
- }
25
- current[path[path.length - 1]] = value;
26
- }
27
- if (negativeProps.size > 0) {
28
- const result = {};
29
- function recurse(currentObj, currentPath = [], resObj) {
30
- for (const key in currentObj) {
31
- const fullPath = [...currentPath, key].join('.');
32
- if (!Array.from(negativeProps).some(neg => fullPath === neg || fullPath.startsWith(neg + '.'))) {
33
- if (typeof currentObj[key] === 'object' && currentObj[key] !== null && !Array.isArray(currentObj[key])) {
34
- resObj[key] = {};
35
- recurse(currentObj[key], [...currentPath, key], resObj[key]);
36
- }
37
- else {
38
- resObj[key] = currentObj[key];
39
- }
40
- }
41
- }
42
- }
43
- recurse(obj, [], result);
44
- return result;
45
- }
46
- const result = {};
47
- for (const p of positiveProps) {
48
- const path = p.split('.');
49
- const value = getNestedValue(obj, path);
50
- if (value !== undefined) {
51
- setNestedValue(result, path, value);
52
- }
53
- }
54
- return result;
55
- }
@@ -1,4 +0,0 @@
1
- import path from "path";
2
- import { fileURLToPath } from "url";
3
- export const __filename = (metaUrl) => fileURLToPath(metaUrl);
4
- export const __dirname = (metaUrl) => path.dirname(fileURLToPath(metaUrl));
@@ -1,99 +0,0 @@
1
- import { ProtocolEnum } from '../../../utils/models/enums';
2
- import { getRuntimeTmpConfigs } from '../../../utils/helpers/tmp/runtime-tmp';
3
- const PROTOCOL_ALIASES = {
4
- http: ProtocolEnum.HTTP,
5
- https: ProtocolEnum.HTTPS,
6
- ws: ProtocolEnum.WEBSOCKET,
7
- websocket: ProtocolEnum.WEBSOCKET,
8
- socketio: ProtocolEnum.SOCKETIO,
9
- socket: ProtocolEnum.SOCKETIO,
10
- };
11
- const REALTIME_MIDDLEWARE_HINT = '[xrystal] tmp.yml lists both ws and socketio — use realtimeMiddleware("ws") or realtimeMiddleware("socketio")';
12
- export function parseProtocol(value) {
13
- if (!value)
14
- return ProtocolEnum.HTTP;
15
- const key = String(value).toLowerCase().replace(/[-_\s.]/g, '');
16
- if (PROTOCOL_ALIASES[key])
17
- return PROTOCOL_ALIASES[key];
18
- const values = Object.values(ProtocolEnum);
19
- return values.includes(String(value)) ? value : ProtocolEnum.HTTP;
20
- }
21
- export function isRealtimeProtocol(protocol) {
22
- return protocol === ProtocolEnum.WEBSOCKET || protocol === ProtocolEnum.SOCKETIO;
23
- }
24
- export function isHttpProtocol(protocol) {
25
- return !protocol || protocol === ProtocolEnum.HTTP || protocol === ProtocolEnum.HTTPS;
26
- }
27
- function tmpConfigsFromRuntime() {
28
- return getRuntimeTmpConfigs();
29
- }
30
- export function resolveProtocolsFromConfig(configs) {
31
- const raw = configs?.protocols;
32
- if (!raw)
33
- return [ProtocolEnum.HTTP];
34
- return (Array.isArray(raw) ? raw : [raw]).map(parseProtocol);
35
- }
36
- export function getConfiguredProtocols() {
37
- try {
38
- return resolveProtocolsFromConfig(tmpConfigsFromRuntime());
39
- }
40
- catch {
41
- return [ProtocolEnum.HTTP, ProtocolEnum.WEBSOCKET];
42
- }
43
- }
44
- export function getConfiguredRealtimeProtocols(configs) {
45
- return resolveProtocolsFromConfig(configs).filter(isRealtimeProtocol);
46
- }
47
- export function defaultRealtimeProtocolFromConfig(configs) {
48
- const realtime = getConfiguredRealtimeProtocols(configs);
49
- if (realtime.length === 1)
50
- return realtime[0];
51
- if (realtime.length > 1)
52
- return undefined;
53
- return ProtocolEnum.WEBSOCKET;
54
- }
55
- export function getDefaultRealtimeProtocol() {
56
- try {
57
- return defaultRealtimeProtocolFromConfig(tmpConfigsFromRuntime());
58
- }
59
- catch {
60
- return ProtocolEnum.WEBSOCKET;
61
- }
62
- }
63
- export function resolveRealtimeMiddlewareProtocol(protocol, configs) {
64
- if (protocol !== undefined && protocol !== null && protocol !== '') {
65
- return parseProtocol(protocol);
66
- }
67
- let cfg = configs;
68
- if (!cfg) {
69
- try {
70
- cfg = tmpConfigsFromRuntime();
71
- }
72
- catch {
73
- return ProtocolEnum.WEBSOCKET;
74
- }
75
- }
76
- const realtime = getConfiguredRealtimeProtocols(cfg);
77
- if (realtime.length === 1)
78
- return realtime[0];
79
- if (realtime.length > 1)
80
- throw new Error(REALTIME_MIDDLEWARE_HINT);
81
- return ProtocolEnum.WEBSOCKET;
82
- }
83
- export function detectSocketProtocol(socket, explicit) {
84
- if (explicit)
85
- return explicit;
86
- const s = socket;
87
- if (s?.__xrystalProtocol)
88
- return s.__xrystalProtocol;
89
- return ProtocolEnum.WEBSOCKET;
90
- }
91
- export function attachSocketTransport(socket, protocol, runtime) {
92
- const s = socket;
93
- if (protocol === ProtocolEnum.SOCKETIO)
94
- runtime.attachSocketIo(socket);
95
- else
96
- runtime.attachWebSocket(socket);
97
- s.__xrystalProtocol = protocol;
98
- }
99
- export { REALTIME_MIDDLEWARE_HINT };
@@ -1,13 +0,0 @@
1
- import { FrameworkEnum, ProtocolEnum } from '../../../utils/models';
2
- import { parseProtocol } from '../../../utils/helpers/protocol';
3
- export function resolveCtrOptions(opts) {
4
- if (opts === undefined)
5
- return { protocol: ProtocolEnum.HTTP };
6
- if (typeof opts === 'string') {
7
- const fwValues = Object.values(FrameworkEnum);
8
- if (fwValues.includes(opts))
9
- return { framework: opts, protocol: ProtocolEnum.HTTP };
10
- return { protocol: parseProtocol(opts) };
11
- }
12
- return { protocol: ProtocolEnum.HTTP, ...opts };
13
- }
@@ -1,3 +0,0 @@
1
- export function checkSpecialRegexControl(str, regex) {
2
- return regex.test(str);
3
- }
@@ -1,5 +0,0 @@
1
- import { x } from '../../../utils/models';
2
- export const DTO_RUNTIME_KEY = 'dtoRuntime';
3
- export function getDtoRuntime() {
4
- return x.get(DTO_RUNTIME_KEY);
5
- }
@@ -1 +0,0 @@
1
- export { getDtoRuntime, DTO_RUNTIME_KEY } from '../../../utils/helpers/runtime/dto-access';
@@ -1,185 +0,0 @@
1
- import { createStore } from 'zustand/vanilla';
2
- import { subscribeWithSelector } from 'zustand/middleware';
3
- import { GStoreScopeEnum } from '../../../utils/models/enums';
4
- import { propsFromTmp, resolveGStoreBoot, G_PROP_NOT_ALLOWED } from '../../../utils/helpers/state/props-from-tmp';
5
- import { warnIfRequestScopedKey, G_REQUEST_KEY_WARN, looksLikeRequestScopedKey } from '../../../utils/helpers/state/request-key-guard';
6
- import { buildStoresSnapshot, patchControllerScope, patchRunScope, } from '../../../utils/helpers/state/scopes';
7
- export { propsFromTmp, resolveGStoreBoot, G_PROP_NOT_ALLOWED, G_REQUEST_KEY_WARN, looksLikeRequestScopedKey };
8
- export { GStoreScopeEnum } from '../../../utils/models/enums';
9
- export { buildStoresSnapshot, summarizeController, runContextValues, patchControllerScope, patchRunScope, } from '../../../utils/helpers/state/scopes';
10
- const cloneState = (state) => JSON.parse(JSON.stringify(state));
11
- function diffChanges(prev, next) {
12
- const keys = new Set([...Object.keys(prev), ...Object.keys(next)]);
13
- const changes = [];
14
- for (const key of keys) {
15
- if (prev[key] !== next[key]) {
16
- changes.push({ key, value: next[key], prev: prev[key] });
17
- }
18
- }
19
- return changes;
20
- }
21
- class GStoreFacade {
22
- store;
23
- baseline = {};
24
- allowedKeys = new Set();
25
- allowAutoCreateProps = true;
26
- warnOnRequestKeys = true;
27
- constructor() {
28
- this.store = createStore(subscribeWithSelector(() => ({})));
29
- }
30
- configureFromTmp(tmp = {}) {
31
- const boot = resolveGStoreBoot(tmp);
32
- this.allowAutoCreateProps = boot.allowAutoCreateProps;
33
- this.warnOnRequestKeys = boot.warnOnRequestKeys;
34
- this.allowedKeys = new Set(Object.keys(boot.vars));
35
- const next = cloneState(boot.bootstrap ? boot.vars : {});
36
- this.store.setState(next, true);
37
- this.baseline = cloneState(next);
38
- return this;
39
- }
40
- allowsAutoCreateProps() {
41
- return this.allowAutoCreateProps;
42
- }
43
- declaredKeys() {
44
- return [...this.allowedKeys];
45
- }
46
- guardRequestKey(key) {
47
- warnIfRequestScopedKey(key, this.warnOnRequestKeys);
48
- }
49
- assertPropAllowed(key) {
50
- if (this.allowAutoCreateProps)
51
- return;
52
- if (!this.allowedKeys.has(key)) {
53
- throw new Error(`${G_PROP_NOT_ALLOWED}: ${key}`);
54
- }
55
- }
56
- registerAllowedKeys(keys) {
57
- for (const key of keys)
58
- this.allowedKeys.add(key);
59
- }
60
- getState() {
61
- return this.store.getState();
62
- }
63
- select(selector) {
64
- return selector(this.getState());
65
- }
66
- get(key, fallback) {
67
- const state = this.getState();
68
- if (!(key in state))
69
- return fallback;
70
- return state[key];
71
- }
72
- set(key, value) {
73
- this.guardRequestKey(key);
74
- this.assertPropAllowed(key);
75
- const prev = this.getState();
76
- if (prev[key] === value)
77
- return this;
78
- this.store.setState({ ...prev, [key]: value });
79
- return this;
80
- }
81
- merge(record) {
82
- for (const key of Object.keys(record)) {
83
- this.guardRequestKey(key);
84
- this.assertPropAllowed(key);
85
- }
86
- const prev = this.getState();
87
- const changes = diffChanges(prev, { ...prev, ...record });
88
- if (!changes.length)
89
- return this;
90
- this.store.setState({ ...prev, ...record });
91
- return this;
92
- }
93
- has(key) {
94
- return key in this.getState();
95
- }
96
- remove(...keys) {
97
- const prev = this.getState();
98
- const next = { ...prev };
99
- let touched = false;
100
- for (const key of keys) {
101
- if (key in next) {
102
- delete next[key];
103
- touched = true;
104
- }
105
- }
106
- if (touched)
107
- this.store.setState(next, true);
108
- return this;
109
- }
110
- keys() {
111
- return Object.keys(this.getState());
112
- }
113
- entries() {
114
- return Object.entries(this.getState());
115
- }
116
- snapshot() {
117
- return { ...this.getState() };
118
- }
119
- subscribe(listener) {
120
- return this.store.subscribe((state, prev) => listener(state, prev, diffChanges(prev, state)));
121
- }
122
- subscribeKey(key, listener) {
123
- return this.store.subscribe((state) => state[key], (value, prev) => listener(value, prev, { key, value, prev }));
124
- }
125
- bootstrap(record) {
126
- if (!this.allowAutoCreateProps) {
127
- for (const key of Object.keys(record))
128
- this.assertPropAllowed(key);
129
- }
130
- else {
131
- this.registerAllowedKeys(Object.keys(record));
132
- }
133
- this.merge(record);
134
- this.baseline = cloneState(this.getState());
135
- return this;
136
- }
137
- reset() {
138
- this.store.setState(cloneState(this.baseline), true);
139
- }
140
- stores() {
141
- return buildStoresSnapshot(this.snapshot());
142
- }
143
- list() {
144
- return Object.values(this.stores());
145
- }
146
- scope(name) {
147
- const stores = this.stores();
148
- const entry = stores[name];
149
- const base = {
150
- name,
151
- active: entry.active,
152
- keys: () => entry.keys,
153
- get(key, fallback) {
154
- if (!entry.values || !(key in entry.values))
155
- return fallback;
156
- return entry.values[key];
157
- },
158
- };
159
- if (name === GStoreScopeEnum.GLOBAL) {
160
- return {
161
- ...base,
162
- set: (key, value) => {
163
- this.set(key, value);
164
- return true;
165
- },
166
- merge: (record) => {
167
- this.merge(record);
168
- return true;
169
- },
170
- };
171
- }
172
- if (name === GStoreScopeEnum.RUN) {
173
- return {
174
- ...base,
175
- patch: (record) => patchRunScope(record),
176
- };
177
- }
178
- return {
179
- ...base,
180
- patch: (record) => patchControllerScope(record),
181
- };
182
- }
183
- }
184
- export { GStoreFacade };
185
- export const G = new GStoreFacade();