@decaf-ts/core 0.7.2 → 0.7.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 (246) hide show
  1. package/README.md +6 -1
  2. package/dist/core.cjs +1 -1
  3. package/dist/core.cjs.map +1 -1
  4. package/dist/core.js +1 -1
  5. package/dist/core.js.map +1 -1
  6. package/lib/esm/identity/decorators.d.ts +3 -4
  7. package/lib/esm/identity/decorators.js +5 -11
  8. package/lib/esm/identity/decorators.js.map +1 -1
  9. package/lib/esm/identity/index.d.ts +0 -1
  10. package/lib/esm/identity/index.js +0 -1
  11. package/lib/esm/identity/index.js.map +1 -1
  12. package/lib/esm/index.d.ts +1 -1
  13. package/lib/esm/index.js +1 -1
  14. package/lib/esm/interfaces/ContextuallyLogged.d.ts +8 -0
  15. package/lib/esm/interfaces/ContextuallyLogged.js +2 -0
  16. package/lib/esm/interfaces/ContextuallyLogged.js.map +1 -0
  17. package/lib/esm/interfaces/ErrorParser.d.ts +2 -2
  18. package/lib/esm/interfaces/Executor.d.ts +1 -1
  19. package/lib/esm/interfaces/Observable.d.ts +8 -8
  20. package/lib/esm/interfaces/Observer.d.ts +2 -2
  21. package/lib/esm/interfaces/RawExecutor.d.ts +1 -1
  22. package/lib/esm/model/BaseModel.d.ts +2 -2
  23. package/lib/esm/model/BaseModel.js +2 -2
  24. package/lib/esm/{ram/model/RamSequenceModel.d.ts → model/SequenceModel.d.ts} +3 -3
  25. package/lib/esm/{ram/model/RamSequenceModel.js → model/SequenceModel.js} +12 -11
  26. package/lib/esm/model/SequenceModel.js.map +1 -0
  27. package/lib/esm/model/construction.d.ts +9 -8
  28. package/lib/esm/model/construction.js +2 -2
  29. package/lib/esm/model/construction.js.map +1 -1
  30. package/lib/esm/model/decorators.d.ts +5 -4
  31. package/lib/esm/model/decorators.js +3 -3
  32. package/lib/esm/model/decorators.js.map +1 -1
  33. package/lib/esm/model/index.d.ts +1 -0
  34. package/lib/esm/model/index.js +1 -0
  35. package/lib/esm/model/index.js.map +1 -1
  36. package/lib/esm/overrides/Metadata.d.ts +1 -8
  37. package/lib/esm/overrides/Model.d.ts +75 -0
  38. package/lib/esm/overrides/Model.js +2 -0
  39. package/lib/esm/overrides/Model.js.map +1 -0
  40. package/lib/esm/overrides/index.d.ts +2 -0
  41. package/lib/esm/overrides/index.js +2 -0
  42. package/lib/esm/overrides/index.js.map +1 -1
  43. package/lib/esm/overrides/injectables.d.ts +10 -0
  44. package/lib/esm/overrides/injectables.js +2 -0
  45. package/lib/esm/overrides/injectables.js.map +1 -0
  46. package/lib/esm/overrides/overrides.js +45 -3
  47. package/lib/esm/overrides/overrides.js.map +1 -1
  48. package/lib/esm/persistence/Adapter.d.ts +55 -53
  49. package/lib/esm/persistence/Adapter.js +85 -61
  50. package/lib/esm/persistence/Adapter.js.map +1 -1
  51. package/lib/esm/persistence/Dispatch.d.ts +7 -6
  52. package/lib/esm/persistence/Dispatch.js +25 -18
  53. package/lib/esm/persistence/Dispatch.js.map +1 -1
  54. package/lib/esm/persistence/ObserverHandler.d.ts +7 -6
  55. package/lib/esm/persistence/ObserverHandler.js +5 -4
  56. package/lib/esm/persistence/ObserverHandler.js.map +1 -1
  57. package/lib/esm/persistence/Sequence.d.ts +34 -25
  58. package/lib/esm/persistence/Sequence.js +136 -15
  59. package/lib/esm/persistence/Sequence.js.map +1 -1
  60. package/lib/esm/persistence/constants.d.ts +1 -0
  61. package/lib/esm/persistence/constants.js +1 -0
  62. package/lib/esm/persistence/constants.js.map +1 -1
  63. package/lib/esm/persistence/generators.d.ts +14 -0
  64. package/lib/esm/persistence/generators.js +31 -0
  65. package/lib/esm/persistence/generators.js.map +1 -0
  66. package/lib/esm/persistence/index.d.ts +1 -0
  67. package/lib/esm/persistence/index.js +1 -0
  68. package/lib/esm/persistence/index.js.map +1 -1
  69. package/lib/esm/persistence/migrations.d.ts +8 -8
  70. package/lib/esm/persistence/migrations.js +8 -9
  71. package/lib/esm/persistence/migrations.js.map +1 -1
  72. package/lib/esm/persistence/types.d.ts +38 -20
  73. package/lib/esm/query/Paginator.d.ts +6 -5
  74. package/lib/esm/query/Paginator.js +4 -4
  75. package/lib/esm/query/Paginator.js.map +1 -1
  76. package/lib/esm/query/Statement.d.ts +9 -8
  77. package/lib/esm/query/Statement.js +23 -10
  78. package/lib/esm/query/Statement.js.map +1 -1
  79. package/lib/esm/ram/RamAdapter.d.ts +22 -31
  80. package/lib/esm/ram/RamAdapter.js +36 -34
  81. package/lib/esm/ram/RamAdapter.js.map +1 -1
  82. package/lib/esm/ram/RamPaginator.d.ts +2 -1
  83. package/lib/esm/ram/RamPaginator.js +5 -3
  84. package/lib/esm/ram/RamPaginator.js.map +1 -1
  85. package/lib/esm/ram/RamStatement.d.ts +7 -7
  86. package/lib/esm/ram/RamStatement.js.map +1 -1
  87. package/lib/esm/ram/handlers.d.ts +3 -4
  88. package/lib/esm/ram/handlers.js.map +1 -1
  89. package/lib/esm/ram/index.d.ts +0 -3
  90. package/lib/esm/ram/index.js +0 -3
  91. package/lib/esm/ram/index.js.map +1 -1
  92. package/lib/esm/ram/types.d.ts +4 -12
  93. package/lib/esm/repository/Repository.d.ts +31 -95
  94. package/lib/esm/repository/Repository.js +107 -203
  95. package/lib/esm/repository/Repository.js.map +1 -1
  96. package/lib/esm/repository/decorators.js +4 -3
  97. package/lib/esm/repository/decorators.js.map +1 -1
  98. package/lib/esm/repository/utils.d.ts +1 -1
  99. package/lib/esm/repository/utils.js +2 -3
  100. package/lib/esm/repository/utils.js.map +1 -1
  101. package/lib/esm/utils/ContextualLoggedClass.d.ts +16 -0
  102. package/lib/esm/utils/ContextualLoggedClass.js +29 -0
  103. package/lib/esm/utils/ContextualLoggedClass.js.map +1 -0
  104. package/lib/esm/utils/Services.d.ts +50 -0
  105. package/lib/esm/utils/Services.js +154 -0
  106. package/lib/esm/utils/Services.js.map +1 -0
  107. package/lib/esm/utils/decorators.d.ts +1 -9
  108. package/lib/esm/utils/decorators.js +26 -15
  109. package/lib/esm/utils/decorators.js.map +1 -1
  110. package/lib/esm/utils/index.d.ts +2 -1
  111. package/lib/esm/utils/index.js +2 -1
  112. package/lib/esm/utils/index.js.map +1 -1
  113. package/lib/identity/decorators.cjs +5 -11
  114. package/lib/identity/decorators.d.ts +3 -4
  115. package/lib/identity/decorators.js.map +1 -1
  116. package/lib/identity/index.cjs +0 -1
  117. package/lib/identity/index.d.ts +0 -1
  118. package/lib/identity/index.js.map +1 -1
  119. package/lib/index.cjs +1 -1
  120. package/lib/index.d.ts +1 -1
  121. package/lib/interfaces/ContextuallyLogged.cjs +3 -0
  122. package/lib/interfaces/ContextuallyLogged.d.ts +8 -0
  123. package/lib/interfaces/ContextuallyLogged.js.map +1 -0
  124. package/lib/interfaces/ErrorParser.d.ts +2 -2
  125. package/lib/interfaces/Executor.d.ts +1 -1
  126. package/lib/interfaces/Observable.d.ts +8 -8
  127. package/lib/interfaces/Observer.d.ts +2 -2
  128. package/lib/interfaces/RawExecutor.d.ts +1 -1
  129. package/lib/model/BaseModel.cjs +2 -2
  130. package/lib/model/BaseModel.d.ts +2 -2
  131. package/lib/{ram/model/RamSequenceModel.cjs → model/SequenceModel.cjs} +14 -13
  132. package/lib/{ram/model/RamSequenceModel.d.ts → model/SequenceModel.d.ts} +3 -3
  133. package/lib/model/SequenceModel.js.map +1 -0
  134. package/lib/model/construction.cjs +2 -2
  135. package/lib/model/construction.d.ts +9 -8
  136. package/lib/model/construction.js.map +1 -1
  137. package/lib/model/decorators.cjs +3 -3
  138. package/lib/model/decorators.d.ts +5 -4
  139. package/lib/model/decorators.js.map +1 -1
  140. package/lib/model/index.cjs +1 -0
  141. package/lib/model/index.d.ts +1 -0
  142. package/lib/model/index.js.map +1 -1
  143. package/lib/overrides/Metadata.d.ts +1 -8
  144. package/lib/overrides/Model.cjs +4 -0
  145. package/lib/overrides/Model.d.ts +75 -0
  146. package/lib/overrides/Model.js.map +1 -0
  147. package/lib/overrides/index.cjs +2 -0
  148. package/lib/overrides/index.d.ts +2 -0
  149. package/lib/overrides/index.js.map +1 -1
  150. package/lib/overrides/injectables.cjs +4 -0
  151. package/lib/overrides/injectables.d.ts +10 -0
  152. package/lib/overrides/injectables.js.map +1 -0
  153. package/lib/overrides/overrides.cjs +43 -1
  154. package/lib/overrides/overrides.js.map +1 -1
  155. package/lib/persistence/Adapter.cjs +90 -66
  156. package/lib/persistence/Adapter.d.ts +55 -53
  157. package/lib/persistence/Adapter.js.map +1 -1
  158. package/lib/persistence/Dispatch.cjs +25 -18
  159. package/lib/persistence/Dispatch.d.ts +7 -6
  160. package/lib/persistence/Dispatch.js.map +1 -1
  161. package/lib/persistence/ObserverHandler.cjs +5 -4
  162. package/lib/persistence/ObserverHandler.d.ts +7 -6
  163. package/lib/persistence/ObserverHandler.js.map +1 -1
  164. package/lib/persistence/Sequence.cjs +136 -15
  165. package/lib/persistence/Sequence.d.ts +34 -25
  166. package/lib/persistence/Sequence.js.map +1 -1
  167. package/lib/persistence/constants.cjs +1 -0
  168. package/lib/persistence/constants.d.ts +1 -0
  169. package/lib/persistence/constants.js.map +1 -1
  170. package/lib/persistence/generators.cjs +36 -0
  171. package/lib/persistence/generators.d.ts +14 -0
  172. package/lib/persistence/generators.js.map +1 -0
  173. package/lib/persistence/index.cjs +1 -0
  174. package/lib/persistence/index.d.ts +1 -0
  175. package/lib/persistence/index.js.map +1 -1
  176. package/lib/persistence/migrations.cjs +7 -8
  177. package/lib/persistence/migrations.d.ts +8 -8
  178. package/lib/persistence/migrations.js.map +1 -1
  179. package/lib/persistence/types.d.ts +38 -20
  180. package/lib/query/Paginator.cjs +4 -4
  181. package/lib/query/Paginator.d.ts +6 -5
  182. package/lib/query/Paginator.js.map +1 -1
  183. package/lib/query/Statement.cjs +34 -21
  184. package/lib/query/Statement.d.ts +9 -8
  185. package/lib/query/Statement.js.map +1 -1
  186. package/lib/ram/RamAdapter.cjs +35 -33
  187. package/lib/ram/RamAdapter.d.ts +22 -31
  188. package/lib/ram/RamAdapter.js.map +1 -1
  189. package/lib/ram/RamPaginator.cjs +5 -3
  190. package/lib/ram/RamPaginator.d.ts +2 -1
  191. package/lib/ram/RamPaginator.js.map +1 -1
  192. package/lib/ram/RamStatement.d.ts +7 -7
  193. package/lib/ram/RamStatement.js.map +1 -1
  194. package/lib/ram/handlers.d.ts +3 -4
  195. package/lib/ram/handlers.js.map +1 -1
  196. package/lib/ram/index.cjs +0 -3
  197. package/lib/ram/index.d.ts +0 -3
  198. package/lib/ram/index.js.map +1 -1
  199. package/lib/ram/types.d.ts +4 -12
  200. package/lib/repository/Repository.cjs +108 -204
  201. package/lib/repository/Repository.d.ts +31 -95
  202. package/lib/repository/Repository.js.map +1 -1
  203. package/lib/repository/decorators.cjs +2 -1
  204. package/lib/repository/decorators.js.map +1 -1
  205. package/lib/repository/utils.cjs +2 -3
  206. package/lib/repository/utils.d.ts +1 -1
  207. package/lib/repository/utils.js.map +1 -1
  208. package/lib/utils/ContextualLoggedClass.cjs +33 -0
  209. package/lib/utils/ContextualLoggedClass.d.ts +16 -0
  210. package/lib/utils/ContextualLoggedClass.js.map +1 -0
  211. package/lib/utils/Services.cjs +159 -0
  212. package/lib/utils/Services.d.ts +50 -0
  213. package/lib/utils/Services.js.map +1 -0
  214. package/lib/utils/decorators.cjs +27 -16
  215. package/lib/utils/decorators.d.ts +1 -9
  216. package/lib/utils/decorators.js.map +1 -1
  217. package/lib/utils/index.cjs +2 -1
  218. package/lib/utils/index.d.ts +2 -1
  219. package/lib/utils/index.js.map +1 -1
  220. package/package.json +1 -1
  221. package/lib/esm/identity/utils.d.ts +0 -24
  222. package/lib/esm/identity/utils.js +0 -44
  223. package/lib/esm/identity/utils.js.map +0 -1
  224. package/lib/esm/ram/RamContext.d.ts +0 -28
  225. package/lib/esm/ram/RamContext.js +0 -30
  226. package/lib/esm/ram/RamContext.js.map +0 -1
  227. package/lib/esm/ram/RamSequence.d.ts +0 -75
  228. package/lib/esm/ram/RamSequence.js +0 -145
  229. package/lib/esm/ram/RamSequence.js.map +0 -1
  230. package/lib/esm/ram/model/RamSequenceModel.js.map +0 -1
  231. package/lib/esm/ram/model/index.d.ts +0 -1
  232. package/lib/esm/ram/model/index.js +0 -2
  233. package/lib/esm/ram/model/index.js.map +0 -1
  234. package/lib/identity/utils.cjs +0 -49
  235. package/lib/identity/utils.d.ts +0 -24
  236. package/lib/identity/utils.js.map +0 -1
  237. package/lib/ram/RamContext.cjs +0 -34
  238. package/lib/ram/RamContext.d.ts +0 -28
  239. package/lib/ram/RamContext.js.map +0 -1
  240. package/lib/ram/RamSequence.cjs +0 -149
  241. package/lib/ram/RamSequence.d.ts +0 -75
  242. package/lib/ram/RamSequence.js.map +0 -1
  243. package/lib/ram/model/RamSequenceModel.js.map +0 -1
  244. package/lib/ram/model/index.cjs +0 -18
  245. package/lib/ram/model/index.d.ts +0 -1
  246. package/lib/ram/model/index.js.map +0 -1
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ClientBasedService = exports.Service = void 0;
13
+ const db_decorators_1 = require("@decaf-ts/db-decorators");
14
+ const logging_1 = require("@decaf-ts/logging");
15
+ const injectable_decorators_1 = require("@decaf-ts/injectable-decorators");
16
+ class Service {
17
+ constructor(name) {
18
+ this.name = name;
19
+ /**
20
+ * @description The context constructor for this adapter
21
+ * @summary Reference to the context class constructor used by this adapter
22
+ */
23
+ this.Context = (db_decorators_1.Context);
24
+ }
25
+ /**
26
+ * @description Creates repository flags for an operation
27
+ * @summary Generates a set of flags that describe a database operation, combining default flags with overrides
28
+ * @template F - The Repository Flags type
29
+ * @template M - The model type
30
+ * @param {OperationKeys} operation - The type of operation being performed
31
+ * @param {Constructor<M>} model - The model constructor
32
+ * @param {Partial<F>} flags - Custom flag overrides
33
+ * @param {...any[]} args - Additional arguments
34
+ * @return {Promise<F>} The complete set of flags
35
+ */
36
+ async flags(operation, flags,
37
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
38
+ ...args) {
39
+ let log = (flags.logger || logging_1.Logging.for(this.toString()));
40
+ if (flags.correlationId)
41
+ log = log.for({ correlationId: flags.correlationId });
42
+ return Object.assign({}, db_decorators_1.DefaultRepositoryFlags, flags, {
43
+ timestamp: new Date(),
44
+ operation: operation,
45
+ logger: log,
46
+ });
47
+ }
48
+ async context(operation, overrides, ...args) {
49
+ const flags = await this.flags(operation, overrides, ...args);
50
+ return new this.Context().accumulate(flags);
51
+ }
52
+ async logCtx(args, method, allowCreate = false) {
53
+ return (await Service.logCtx.bind(this)(args, method, allowCreate));
54
+ }
55
+ static async logCtx(args, operation, allowCreate = false) {
56
+ const bootCtx = async function bootCtx() {
57
+ if (!allowCreate)
58
+ throw new db_decorators_1.InternalError("No context provided");
59
+ return this.context(typeof operation === "string" ? operation : operation.name, {});
60
+ }.bind(this);
61
+ if (args.length < 1) {
62
+ args = [await bootCtx()];
63
+ }
64
+ const ctx = args.pop();
65
+ if (!(ctx instanceof db_decorators_1.Context))
66
+ args = [...args, await bootCtx()];
67
+ const log = (this
68
+ ? ctx.logger.for(this).for(operation)
69
+ : ctx.logger.clear().for(this).for(operation));
70
+ return {
71
+ ctx: ctx,
72
+ log: operation ? log.for(operation) : log,
73
+ ctxArgs: [...args, ctx],
74
+ };
75
+ }
76
+ /**
77
+ * @description Retrieves a Service instance by name/class
78
+ * @summary Looks up and returns a cached API instance by its name or constructor
79
+ * @template A Type extending Api
80
+ * @param {string | Constructor<A>} name - Name of the API or its constructor
81
+ * @return {A} The requested API instance
82
+ */
83
+ static get(name) {
84
+ if (!name)
85
+ throw new db_decorators_1.InternalError(`No name provided`);
86
+ const injectable = injectable_decorators_1.Injectables.get(name);
87
+ if (injectable)
88
+ return injectable;
89
+ throw new db_decorators_1.InternalError(`No Service found for ${typeof name === "string" ? name : typeof name === "symbol" ? name.toString() : name.name}`);
90
+ }
91
+ static async boot(...args) {
92
+ const factory = {
93
+ async context(operation) {
94
+ return new db_decorators_1.Context().accumulate(Object.assign({}, db_decorators_1.DefaultRepositoryFlags, {
95
+ timestamp: new Date(),
96
+ operation: operation,
97
+ logger: logging_1.Logging.get(),
98
+ }));
99
+ },
100
+ };
101
+ const { log, ctxArgs } = await this.logCtx.bind(factory)(args, this.boot, true);
102
+ const services = injectable_decorators_1.Injectables.services();
103
+ for (const [key, service] of Object.entries(services)) {
104
+ try {
105
+ const s = new service();
106
+ if (s instanceof ClientBasedService)
107
+ await s.boot(...ctxArgs);
108
+ }
109
+ catch (e) {
110
+ log.error(`Failed to boot ${key} service`, e);
111
+ }
112
+ }
113
+ }
114
+ }
115
+ exports.Service = Service;
116
+ class ClientBasedService extends Service {
117
+ constructor() {
118
+ super();
119
+ }
120
+ async boot(...args) {
121
+ const { log, ctxArgs } = await this.logCtx(args, this.boot, true);
122
+ log.verbose(`Initializing ${this.toString()}...`);
123
+ const { config, client } = await this.initialize(...ctxArgs);
124
+ this._config = config;
125
+ this._client = client;
126
+ }
127
+ get config() {
128
+ if (!this._config)
129
+ throw new db_decorators_1.InternalError(`Config not initialized`);
130
+ return this._config;
131
+ }
132
+ get client() {
133
+ if (!this._client)
134
+ throw new db_decorators_1.InternalError(`Client not initialized`);
135
+ return this._client;
136
+ }
137
+ async shutdown(...args) {
138
+ const { log } = await this.logCtx(args, this.shutdown, true);
139
+ log.info(`Shutting down ${this.name} service...`);
140
+ }
141
+ }
142
+ exports.ClientBasedService = ClientBasedService;
143
+ __decorate([
144
+ (0, logging_1.final)(),
145
+ __metadata("design:type", Function),
146
+ __metadata("design:paramtypes", [Object]),
147
+ __metadata("design:returntype", Promise)
148
+ ], ClientBasedService.prototype, "boot", null);
149
+ __decorate([
150
+ (0, logging_1.final)(),
151
+ __metadata("design:type", Object),
152
+ __metadata("design:paramtypes", [])
153
+ ], ClientBasedService.prototype, "config", null);
154
+ __decorate([
155
+ (0, logging_1.final)(),
156
+ __metadata("design:type", Object),
157
+ __metadata("design:paramtypes", [])
158
+ ], ClientBasedService.prototype, "client", null);
159
+ //# sourceMappingURL=Services.js.map
@@ -0,0 +1,50 @@
1
+ import { Context, Contextual, OperationKeys } from "@decaf-ts/db-decorators";
2
+ import { Constructor } from "@decaf-ts/decoration";
3
+ import { ContextualArgs, ContextualizedArgs, MaybeContextualArg } from "./ContextualLoggedClass";
4
+ import { FlagsOf } from "../persistence/index";
5
+ export declare abstract class Service<C extends Context<any> = any> implements Contextual<C> {
6
+ readonly name?: string | undefined;
7
+ protected constructor(name?: string | undefined);
8
+ /**
9
+ * @description Creates repository flags for an operation
10
+ * @summary Generates a set of flags that describe a database operation, combining default flags with overrides
11
+ * @template F - The Repository Flags type
12
+ * @template M - The model type
13
+ * @param {OperationKeys} operation - The type of operation being performed
14
+ * @param {Constructor<M>} model - The model constructor
15
+ * @param {Partial<F>} flags - Custom flag overrides
16
+ * @param {...any[]} args - Additional arguments
17
+ * @return {Promise<F>} The complete set of flags
18
+ */
19
+ protected flags(operation: OperationKeys | string, flags: Partial<FlagsOf<C>>, ...args: any[]): Promise<FlagsOf<C>>;
20
+ /**
21
+ * @description The context constructor for this adapter
22
+ * @summary Reference to the context class constructor used by this adapter
23
+ */
24
+ protected readonly Context: Constructor<C>;
25
+ context(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE | string, overrides: Partial<FlagsOf<C>>, ...args: any[]): Promise<C>;
26
+ protected logCtx<ARGS extends any[]>(args: ARGS, method: ((...args: any[]) => any) | string, allowCreate?: boolean): Promise<ContextualizedArgs<any, ARGS>>;
27
+ protected static logCtx<CONTEXT extends Context<any>, ARGS extends any[]>(this: Contextual, args: ARGS, operation: ((...args: any[]) => any) | string, allowCreate?: boolean): Promise<ContextualizedArgs<CONTEXT, ARGS>>;
28
+ /**
29
+ * @description Retrieves a Service instance by name/class
30
+ * @summary Looks up and returns a cached API instance by its name or constructor
31
+ * @template A Type extending Api
32
+ * @param {string | Constructor<A>} name - Name of the API or its constructor
33
+ * @return {A} The requested API instance
34
+ */
35
+ static get<A extends Service>(name: string | symbol | Constructor<A>): A;
36
+ static boot<C extends Context<any> = any>(...args: MaybeContextualArg<C>): Promise<void>;
37
+ }
38
+ export declare abstract class ClientBasedService<CLIENT, CONF, C extends Context<any> = any> extends Service {
39
+ protected _client?: CLIENT;
40
+ protected _config?: CONF;
41
+ protected constructor();
42
+ boot(...args: MaybeContextualArg<C>): Promise<void>;
43
+ abstract initialize(...args: ContextualArgs<C>): Promise<{
44
+ config: CONF;
45
+ client: CLIENT;
46
+ }>;
47
+ protected get config(): CONF;
48
+ get client(): CLIENT;
49
+ shutdown(...args: MaybeContextualArg<C>): Promise<void>;
50
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Services.js","sourceRoot":"","sources":["../../src/utils/Services.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAMiC;AACjC,+CAA2D;AAE3D,2EAA8D;AAQ9D,MAAsB,OAAO;IAG3B,YAA+B,IAAa;QAAb,SAAI,GAAJ,IAAI,CAAS;QA6B5C;;;WAGG;QACgB,YAAO,GAAmB,CAAA,uBAEf,CAAA,CAAC;IAnCgB,CAAC;IAEhD;;;;;;;;;;OAUG;IACO,KAAK,CAAC,KAAK,CACnB,SAAiC,EACjC,KAA0B;IAC1B,6DAA6D;IAC7D,GAAG,IAAW;QAEd,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,MAA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AAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClE,GAAG,CAAC,OAAO,CAAC,gBAAgB,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClD,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,CAAC;QAC7D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAOD,IACc,MAAM;QAClB,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,6BAAa,CAAC,wBAAwB,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IACI,MAAM;QACR,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,6BAAa,CAAC,wBAAwB,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,GAAG,IAA2B;QAC3C,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC7D,GAAG,CAAC,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,aAAa,CAAC,CAAC;IACpD,CAAC;CACF;AA3CD,gDA2CC;AA7BO;IADL,IAAA,eAAK,GAAE;;;;8CAOP;AAOD;IAAC,IAAA,eAAK,GAAE;;;gDAIP;AAED;IAAC,IAAA,eAAK,GAAE;;;gDAIP"}
@@ -1,22 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.final = final;
4
- /**
5
- * @description Creates a decorator that makes a method non-configurable
6
- * @summary This decorator prevents a method from being overridden by making it non-configurable.
7
- * It throws an error if used on anything other than a method.
8
- * @return {Function} A decorator function that can be applied to methods
9
- * @function final
10
- * @category Method Decorators
11
- */
12
- function final() {
13
- return (target, propertyKey, descriptor) => {
14
- if (!descriptor)
15
- throw new Error("final decorator can only be used on methods");
16
- if (descriptor?.configurable) {
17
- descriptor.configurable = false;
3
+ exports.service = service;
4
+ const decoration_1 = require("@decaf-ts/decoration");
5
+ const injectable_decorators_1 = require("@decaf-ts/injectable-decorators");
6
+ const index_1 = require("./../persistence/index.cjs");
7
+ function service(key) {
8
+ return function service(target, prop, descriptor) {
9
+ decoration_1.Metadata.set(index_1.PersistenceKeys.SERVICE, key, target);
10
+ const decs = [];
11
+ if (descriptor && typeof descriptor.value === "number") {
12
+ decs.push((0, injectable_decorators_1.inject)());
18
13
  }
19
- return descriptor;
14
+ else if (!descriptor && !prop) {
15
+ decs.push((0, injectable_decorators_1.injectable)({
16
+ callback: (inst) => Object.defineProperty(inst, "name", {
17
+ enumerable: true,
18
+ configurable: false,
19
+ writable: false,
20
+ value: key,
21
+ }),
22
+ }));
23
+ }
24
+ else if (!descriptor) {
25
+ decs.push((0, injectable_decorators_1.inject)());
26
+ }
27
+ else
28
+ throw new Error("Invalid decorator usage. Should be impossible");
29
+ decs.push((0, decoration_1.metadata)(index_1.PersistenceKeys.SERVICE, key));
30
+ return (0, decoration_1.apply)(...decs)(target, prop, descriptor);
20
31
  };
21
32
  }
22
33
  //# sourceMappingURL=decorators.js.map
@@ -1,9 +1 @@
1
- /**
2
- * @description Creates a decorator that makes a method non-configurable
3
- * @summary This decorator prevents a method from being overridden by making it non-configurable.
4
- * It throws an error if used on anything other than a method.
5
- * @return {Function} A decorator function that can be applied to methods
6
- * @function final
7
- * @category Method Decorators
8
- */
9
- export declare function final(): (target: object, propertyKey?: any, descriptor?: PropertyDescriptor) => PropertyDescriptor;
1
+ export declare function service(key: string): (target: any, prop?: any, descriptor?: any) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/utils/decorators.ts"],"names":[],"mappings":";;AAQA,sBAaC;AArBD;;;;;;;GAOG;AACH,SAAgB,KAAK;IACnB,OAAO,CACL,MAAc,EACd,WAAiB,EACjB,UAA+B,EAC/B,EAAE;QACF,IAAI,CAAC,UAAU;YACb,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,IAAI,UAAU,EAAE,YAAY,EAAE,CAAC;YAC7B,UAAU,CAAC,YAAY,GAAG,KAAK,CAAC;QAClC,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/utils/decorators.ts"],"names":[],"mappings":";;AAIA,0BAyBC;AA7BD,qDAAiE;AACjE,2EAAqE;AACrE,sDAAuD;AAEvD,SAAgB,OAAO,CAAC,GAAW;IACjC,OAAO,SAAS,OAAO,CAAC,MAAW,EAAE,IAAU,EAAE,UAAgB;QAC/D,qBAAQ,CAAC,GAAG,CAAC,uBAAe,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QACnD,MAAM,IAAI,GAAG,EAAE,CAAC;QAChB,IAAI,UAAU,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvD,IAAI,CAAC,IAAI,CAAC,IAAA,8BAAM,GAAE,CAAC,CAAC;QACtB,CAAC;aAAM,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,EAAE,CAAC;YAChC,IAAI,CAAC,IAAI,CACP,IAAA,kCAAU,EAAC;gBACT,QAAQ,EAAE,CAAC,IAAS,EAAE,EAAE,CACtB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE;oBAClC,UAAU,EAAE,IAAI;oBAChB,YAAY,EAAE,KAAK;oBACnB,QAAQ,EAAE,KAAK;oBACf,KAAK,EAAE,GAAG;iBACX,CAAC;aACL,CAAC,CACH,CAAC;QACJ,CAAC;aAAM,IAAI,CAAC,UAAU,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,CAAC,IAAA,8BAAM,GAAE,CAAC,CAAC;QACtB,CAAC;;YAAM,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QAExE,IAAI,CAAC,IAAI,CAAC,IAAA,qBAAQ,EAAC,uBAAe,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QAClD,OAAO,IAAA,kBAAK,EAAC,GAAG,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC"}
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./decorators.cjs"), exports);
17
+ __exportStar(require("./ContextualLoggedClass.cjs"), exports);
18
18
  __exportStar(require("./errors.cjs"), exports);
19
+ __exportStar(require("./Services.cjs"), exports);
19
20
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,3 @@
1
- export * from "./decorators";
1
+ export * from "./ContextualLoggedClass";
2
2
  export * from "./errors";
3
+ export * from "./Services";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAA6B;AAC7B,+CAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAAwC;AACxC,+CAAyB;AACzB,iDAA2B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decaf-ts/core",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Core persistence module for the decaf framework",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,24 +0,0 @@
1
- import { Model } from "@decaf-ts/decorator-validation";
2
- import { Constructor } from "@decaf-ts/decoration";
3
- /**
4
- * @description Gets the table name for a model
5
- * @summary Retrieves the table name associated with a model by checking metadata or falling back to the constructor name
6
- * @template M - Type that extends Model
7
- * @param {M | Constructor<M>} model - The model instance or constructor to get the table name for
8
- * @return {string} The table name for the model
9
- * @function getTableName
10
- * @memberOf module:core
11
- */
12
- export declare function getTableName<M extends Model>(model: M | Constructor<M>): string;
13
- export declare function getColumnName<M extends Model>(model: M | Constructor<M>, attribute: string): string;
14
- /**
15
- * @description Generates a sequence name for a model
16
- * @summary Creates a standardized sequence name by combining the table name with additional arguments
17
- * @template M - Type that extends Model
18
- * @param {M | Constructor<M>} model - The model instance or constructor to generate the sequence name for
19
- * @param {...string} args - Additional string arguments to append to the sequence name
20
- * @return {string} The generated sequence name
21
- * @function sequenceNameForModel
22
- * @memberOf module:core
23
- */
24
- export declare function sequenceNameForModel<M extends Model>(model: M | Constructor<M>, ...args: string[]): string;
@@ -1,44 +0,0 @@
1
- import { Model } from "@decaf-ts/decorator-validation";
2
- import { InternalError } from "@decaf-ts/db-decorators";
3
- import { PersistenceKeys } from "./../persistence/constants.js";
4
- import { Metadata } from "@decaf-ts/decoration";
5
- /**
6
- * @description Gets the table name for a model
7
- * @summary Retrieves the table name associated with a model by checking metadata or falling back to the constructor name
8
- * @template M - Type that extends Model
9
- * @param {M | Constructor<M>} model - The model instance or constructor to get the table name for
10
- * @return {string} The table name for the model
11
- * @function getTableName
12
- * @memberOf module:core
13
- */
14
- export function getTableName(model) {
15
- const obj = model instanceof Model ? Model.get(model.constructor.name) : model;
16
- if (!obj)
17
- throw new InternalError(`Unable to find model ${model}`);
18
- const meta = Metadata.get(model instanceof Model ? model.constructor : model, PersistenceKeys.TABLE);
19
- if (meta) {
20
- return meta;
21
- }
22
- if (model instanceof Model) {
23
- return model.constructor.name;
24
- }
25
- return model.name;
26
- }
27
- export function getColumnName(model, attribute) {
28
- const metadata = Metadata.get(model instanceof Model ? model.constructor : model, Metadata.key(PersistenceKeys.COLUMN, attribute));
29
- return metadata ? metadata : attribute;
30
- }
31
- /**
32
- * @description Generates a sequence name for a model
33
- * @summary Creates a standardized sequence name by combining the table name with additional arguments
34
- * @template M - Type that extends Model
35
- * @param {M | Constructor<M>} model - The model instance or constructor to generate the sequence name for
36
- * @param {...string} args - Additional string arguments to append to the sequence name
37
- * @return {string} The generated sequence name
38
- * @function sequenceNameForModel
39
- * @memberOf module:core
40
- */
41
- export function sequenceNameForModel(model, ...args) {
42
- return [getTableName(model), ...args].join("_");
43
- }
44
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/identity/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,sCAAiC;AAC3D,OAAO,EAAe,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAyB;IAEzB,MAAM,GAAG,GACP,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAErE,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,aAAa,CAAC,wBAAwB,KAAK,EAAE,CAAC,CAAC;IAEnE,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CACvB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAE,KAAa,EAC3D,eAAe,CAAC,KAAK,CACtB,CAAC;IAEF,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;IAChC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,KAAyB,EACzB,SAAiB;IAEjB,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAC3B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAE,KAAa,EAC3D,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,CAChD,CAAC;IACF,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;AACzC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAyB,EACzB,GAAG,IAAc;IAEjB,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC"}
@@ -1,28 +0,0 @@
1
- import { Context } from "@decaf-ts/db-decorators";
2
- import { RamFlags } from "./types";
3
- /**
4
- * @description Context class for RAM adapter operations
5
- * @summary Provides a specialized context for RAM adapter operations, extending the base Context with RAM-specific flags. This context is used to pass operation parameters and user information.
6
- * @class RamContext
7
- * @category Ram
8
- * @example
9
- * ```typescript
10
- * // Create a new RAM context
11
- * const context = new RamContext();
12
- * // Optionally set a flag
13
- * context.set('UUID', '123e4567-e89b-12d3-a456-426614174000');
14
- * // Access a flag from the context
15
- * const uuid = context.get('UUID');
16
- * ```
17
- * @mermaid
18
- * sequenceDiagram
19
- * participant Caller
20
- * participant RamContext
21
- * participant BaseContext as Context
22
- * Caller->>RamContext: new RamContext()
23
- * RamContext->>BaseContext: super()
24
- * RamContext-->>Caller: instance
25
- */
26
- export declare class RamContext extends Context<RamFlags> {
27
- constructor();
28
- }
@@ -1,30 +0,0 @@
1
- import { Context } from "@decaf-ts/db-decorators";
2
- /**
3
- * @description Context class for RAM adapter operations
4
- * @summary Provides a specialized context for RAM adapter operations, extending the base Context with RAM-specific flags. This context is used to pass operation parameters and user information.
5
- * @class RamContext
6
- * @category Ram
7
- * @example
8
- * ```typescript
9
- * // Create a new RAM context
10
- * const context = new RamContext();
11
- * // Optionally set a flag
12
- * context.set('UUID', '123e4567-e89b-12d3-a456-426614174000');
13
- * // Access a flag from the context
14
- * const uuid = context.get('UUID');
15
- * ```
16
- * @mermaid
17
- * sequenceDiagram
18
- * participant Caller
19
- * participant RamContext
20
- * participant BaseContext as Context
21
- * Caller->>RamContext: new RamContext()
22
- * RamContext->>BaseContext: super()
23
- * RamContext-->>Caller: instance
24
- */
25
- export class RamContext extends Context {
26
- constructor() {
27
- super();
28
- }
29
- }
30
- //# sourceMappingURL=RamContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RamContext.js","sourceRoot":"","sources":["../../../src/ram/RamContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGlD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,UAAW,SAAQ,OAAiB;IAC/C;QACE,KAAK,EAAE,CAAC;IACV,CAAC;CACF"}
@@ -1,75 +0,0 @@
1
- import { RamSequenceModel } from "./model/RamSequenceModel";
2
- import { Sequence } from "../persistence";
3
- import { SequenceOptions } from "../interfaces";
4
- import { RamAdapter } from "./RamAdapter";
5
- import { Repo } from "../repository";
6
- /**
7
- * @description RAM-specific sequence implementation
8
- * @summary Extends the base Sequence class to provide auto-incrementing sequence functionality
9
- * for the RAM adapter. This class manages sequences stored in memory, allowing for the generation
10
- * of sequential identifiers for entities.
11
- * @param {SequenceOptions} options - Configuration options for the sequence
12
- * @param {RamAdapter} adapter - The RAM adapter instance to use for storage
13
- * @class RamSequence
14
- * @category Ram
15
- * @example
16
- * ```typescript
17
- * // Create a new numeric sequence starting at 1
18
- * const sequence = new RamSequence({
19
- * name: 'order_sequence',
20
- * type: 'Number',
21
- * startWith: 1,
22
- * incrementBy: 1
23
- * }, ramAdapter);
24
- *
25
- * // Get the next value in the sequence
26
- * const nextId = await sequence.next();
27
- *
28
- * // Get a range of values
29
- * const idRange = await sequence.range(5); // Returns 5 sequential values
30
- * ```
31
- */
32
- export declare class RamSequence extends Sequence {
33
- protected repo: Repo<RamSequenceModel>;
34
- constructor(options: SequenceOptions, adapter: RamAdapter);
35
- /**
36
- * @description Retrieves the current value of the sequence
37
- * @summary Gets the current value of the sequence from storage. If the sequence
38
- * doesn't exist yet, it returns the configured starting value.
39
- * @return A promise that resolves to the current sequence value
40
- */
41
- current(): Promise<string | number | bigint>;
42
- /**
43
- * @description Parses a value according to the sequence type
44
- * @summary Converts a value to the appropriate type for the sequence (string, number, or bigint)
45
- * using the base Sequence class's parseValue method.
46
- * @param {string | number | bigint} value - The value to parse
47
- * @return {string | number | bigint} The parsed value in the correct type
48
- */
49
- private parse;
50
- /**
51
- * @description Increments the sequence value
52
- * @summary Increases the current sequence value by the specified amount and persists
53
- * the new value to storage. This method handles both numeric and BigInt sequence types.
54
- * @param {string | number | bigint} current - The current value of the sequence
55
- * @param {number} [count] - Optional amount to increment by, defaults to the sequence's incrementBy value
56
- * @return A promise that resolves to the new sequence value after incrementing
57
- */
58
- private increment;
59
- /**
60
- * @description Gets the next value in the sequence
61
- * @summary Retrieves the current value of the sequence and increments it by the
62
- * configured increment amount. This is the main method used to get a new sequential value.
63
- * @return A promise that resolves to the next value in the sequence
64
- */
65
- next(): Promise<number | string | bigint>;
66
- /**
67
- * @description Generates a range of sequential values
68
- * @summary Retrieves a specified number of sequential values from the sequence.
69
- * This is useful when you need to allocate multiple IDs at once.
70
- * The method increments the sequence by the total amount needed and returns all values in the range.
71
- * @param {number} count - The number of sequential values to generate
72
- * @return A promise that resolves to an array of sequential values
73
- */
74
- range(count: number): Promise<(number | string | bigint)[]>;
75
- }