nesoi 3.0.0 → 3.0.6

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 (186) hide show
  1. package/README.md +10 -0
  2. package/lib/adapters/postgres/src/migrator/bucket.d.ts +20 -0
  3. package/lib/adapters/postgres/src/migrator/bucket.js +184 -0
  4. package/lib/adapters/postgres/src/migrator/csv.d.ts +7 -0
  5. package/lib/adapters/postgres/src/migrator/csv.js +72 -0
  6. package/lib/adapters/postgres/src/migrator/migration.d.ts +2 -18
  7. package/lib/adapters/postgres/src/migrator/migration.js +10 -158
  8. package/lib/adapters/postgres/src/migrator/migrator.js +8 -5
  9. package/lib/adapters/postgres/src/migrator/runner.d.ts +16 -6
  10. package/lib/adapters/postgres/src/migrator/runner.js +103 -34
  11. package/lib/adapters/postgres/src/postgres.bucket_adapter.d.ts +19 -22
  12. package/lib/adapters/postgres/src/postgres.bucket_adapter.js +116 -100
  13. package/lib/adapters/postgres/src/postgres.cli.d.ts +23 -3
  14. package/lib/adapters/postgres/src/postgres.cli.js +70 -10
  15. package/lib/adapters/postgres/src/postgres.config.d.ts +5 -0
  16. package/lib/adapters/postgres/src/postgres.config.js +2 -0
  17. package/lib/adapters/postgres/src/postgres.nql.d.ts +7 -3
  18. package/lib/adapters/postgres/src/postgres.nql.js +86 -32
  19. package/lib/adapters/postgres/src/postgres.provider.d.ts +18 -0
  20. package/lib/adapters/postgres/src/postgres.provider.js +77 -0
  21. package/lib/adapters/postgres/test/postgres.bucket_adapter.test.js +76 -39
  22. package/lib/compiler/apps/monolyth/monolyth_compiler.d.ts +3 -0
  23. package/lib/compiler/apps/monolyth/monolyth_compiler.js +24 -0
  24. package/lib/compiler/apps/monolyth/stages/2_build_typescript_stage.js +2 -1
  25. package/lib/compiler/apps/monolyth/stages/5_dump_cli_stage.js +1 -1
  26. package/lib/compiler/apps/monolyth/stages/6_dump_package_json_stage.js +1 -1
  27. package/lib/compiler/elements/bucket.element.js +26 -11
  28. package/lib/compiler/elements/constants.element.js +1 -1
  29. package/lib/compiler/elements/element.d.ts +2 -0
  30. package/lib/compiler/elements/message.element.js +4 -4
  31. package/lib/compiler/helpers/dump_helpers.js +5 -2
  32. package/lib/compiler/stages/7_dump_stage.js +2 -0
  33. package/lib/compiler/treeshake.js +9 -37
  34. package/lib/compiler/typescript/bridge/extract.js +12 -0
  35. package/lib/compiler/typescript/bridge/inject.js +3 -0
  36. package/lib/compiler/typescript/bridge/organize.js +3 -3
  37. package/lib/elements/blocks/block.builder.js +4 -2
  38. package/lib/elements/blocks/job/internal/resource_job.builder.d.ts +22 -20
  39. package/lib/elements/blocks/job/internal/resource_job.d.ts +2 -1
  40. package/lib/elements/blocks/job/internal/resource_job.js +17 -4
  41. package/lib/elements/blocks/job/job.js +3 -0
  42. package/lib/elements/blocks/job/job.types.d.ts +7 -0
  43. package/lib/elements/blocks/job/job.types.js +2 -0
  44. package/lib/elements/blocks/machine/machine.js +3 -2
  45. package/lib/elements/blocks/resource/resource.builder.js +2 -4
  46. package/lib/elements/blocks/resource/resource.d.ts +5 -3
  47. package/lib/elements/blocks/resource/resource.js +26 -17
  48. package/lib/elements/edge/controller/adapters/controller_adapter.d.ts +2 -1
  49. package/lib/elements/edge/controller/adapters/controller_adapter.js +11 -2
  50. package/lib/elements/edge/controller/controller.builder.d.ts +4 -5
  51. package/lib/elements/edge/controller/controller.builder.js +7 -7
  52. package/lib/elements/edge/controller/controller.d.ts +2 -1
  53. package/lib/elements/edge/controller/controller.js +8 -6
  54. package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +61 -23
  55. package/lib/elements/entities/bucket/adapters/bucket_adapter.js +22 -13
  56. package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.d.ts +21 -22
  57. package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.js +68 -2
  58. package/lib/elements/entities/bucket/adapters/memory.nql.d.ts +10 -6
  59. package/lib/elements/entities/bucket/adapters/memory.nql.js +38 -3
  60. package/lib/elements/entities/bucket/adapters/slow_memory.bucket_adapter.d.ts +0 -20
  61. package/lib/elements/entities/bucket/adapters/slow_memory.bucket_adapter.js +46 -30
  62. package/lib/elements/entities/bucket/bucket.builder.d.ts +8 -2
  63. package/lib/elements/entities/bucket/bucket.builder.js +13 -19
  64. package/lib/elements/entities/bucket/bucket.config.d.ts +5 -1
  65. package/lib/elements/entities/bucket/bucket.d.ts +180 -19
  66. package/lib/elements/entities/bucket/bucket.js +662 -48
  67. package/lib/elements/entities/bucket/bucket.schema.d.ts +7 -1
  68. package/lib/elements/entities/bucket/bucket.schema.js +2 -1
  69. package/lib/elements/entities/bucket/bucket.types.d.ts +2 -7
  70. package/lib/elements/entities/bucket/cache/bucket_cache.d.ts +6 -2
  71. package/lib/elements/entities/bucket/cache/bucket_cache.js +12 -12
  72. package/lib/elements/entities/bucket/graph/bucket_graph.d.ts +32 -5
  73. package/lib/elements/entities/bucket/graph/bucket_graph.js +80 -111
  74. package/lib/elements/entities/bucket/graph/bucket_graph.schema.d.ts +3 -6
  75. package/lib/elements/entities/bucket/graph/bucket_graph.schema.js +1 -4
  76. package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.d.ts +3 -7
  77. package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.js +6 -2
  78. package/lib/elements/entities/bucket/model/bucket_model.builder.js +1 -1
  79. package/lib/elements/entities/bucket/model/bucket_model.convert.js +3 -3
  80. package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +37 -8
  81. package/lib/elements/entities/bucket/model/bucket_model.schema.js +25 -4
  82. package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +33 -14
  83. package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +56 -13
  84. package/lib/elements/entities/bucket/query/nql.schema.d.ts +1 -0
  85. package/lib/elements/entities/bucket/query/nql_compiler.js +13 -2
  86. package/lib/elements/entities/bucket/query/nql_engine.d.ts +11 -4
  87. package/lib/elements/entities/bucket/query/nql_engine.js +20 -11
  88. package/lib/elements/entities/bucket/view/bucket_view.js +63 -35
  89. package/lib/elements/entities/bucket/view/bucket_view.schema.d.ts +5 -2
  90. package/lib/elements/entities/bucket/view/bucket_view_field.builder.d.ts +6 -2
  91. package/lib/elements/entities/bucket/view/bucket_view_field.builder.js +22 -16
  92. package/lib/elements/entities/constants/constants.schema.d.ts +1 -1
  93. package/lib/elements/entities/drive/drive_adapter.d.ts +44 -0
  94. package/lib/elements/entities/drive/drive_adapter.js +10 -0
  95. package/lib/elements/entities/drive/local.drive_adapter.d.ts +10 -0
  96. package/lib/elements/entities/drive/local.drive_adapter.js +34 -0
  97. package/lib/elements/entities/message/message.schema.d.ts +1 -0
  98. package/lib/elements/entities/message/message.schema.js +33 -0
  99. package/lib/elements/entities/message/message_parser.d.ts +5 -1
  100. package/lib/elements/entities/message/message_parser.js +56 -35
  101. package/lib/elements/entities/message/template/message_template.schema.d.ts +10 -8
  102. package/lib/elements/entities/message/template/message_template_field.builder.d.ts +16 -6
  103. package/lib/elements/entities/message/template/message_template_field.builder.js +25 -0
  104. package/lib/elements/entities/message/template/message_template_parser.js +2 -1
  105. package/lib/engine/apps/app.config.d.ts +32 -11
  106. package/lib/engine/apps/app.config.js +12 -0
  107. package/lib/engine/apps/app.d.ts +2 -0
  108. package/lib/engine/apps/app.js +3 -0
  109. package/lib/engine/apps/inline.app.d.ts +5 -3
  110. package/lib/engine/apps/inline.app.js +27 -12
  111. package/lib/engine/apps/monolyth/monolyth.app.d.ts +4 -2
  112. package/lib/engine/apps/monolyth/monolyth.app.js +22 -10
  113. package/lib/engine/auth/authn.d.ts +5 -1
  114. package/lib/engine/auth/zero.authn_provider.d.ts +4 -2
  115. package/lib/engine/auth/zero.authn_provider.js +2 -2
  116. package/lib/engine/cli/cli.d.ts +3 -1
  117. package/lib/engine/cli/cli.js +22 -3
  118. package/lib/engine/cli/cli_adapter.d.ts +2 -1
  119. package/lib/engine/cli/cli_adapter.js +2 -1
  120. package/lib/engine/cli/cli_input.d.ts +19 -0
  121. package/lib/engine/cli/cli_input.js +207 -0
  122. package/lib/engine/cli/ui.d.ts +1 -1
  123. package/lib/engine/cli/ui.js +2 -2
  124. package/lib/engine/daemon.d.ts +3 -2
  125. package/lib/engine/daemon.js +14 -2
  126. package/lib/engine/data/date.js +2 -2
  127. package/lib/engine/data/datetime.d.ts +40 -4
  128. package/lib/engine/data/datetime.js +70 -11
  129. package/lib/engine/data/decimal.d.ts +1 -1
  130. package/lib/engine/data/decimal.js +3 -3
  131. package/lib/engine/data/error.d.ts +21 -4
  132. package/lib/engine/data/error.js +23 -7
  133. package/lib/engine/data/file.d.ts +38 -0
  134. package/lib/engine/data/file.js +54 -0
  135. package/lib/engine/data/json.d.ts +6 -0
  136. package/lib/engine/data/json.js +26 -0
  137. package/lib/engine/data/obj.d.ts +1 -1
  138. package/lib/engine/data/trash.d.ts +14 -0
  139. package/lib/engine/data/trash.js +2 -0
  140. package/lib/engine/data/tree.d.ts +7 -12
  141. package/lib/engine/data/tree.js +101 -49
  142. package/lib/engine/module.d.ts +2 -1
  143. package/lib/engine/module.js +2 -5
  144. package/lib/engine/space.d.ts +1 -0
  145. package/lib/engine/space.js +6 -0
  146. package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +184 -24
  147. package/lib/engine/transaction/nodes/bucket.trx_node.js +346 -451
  148. package/lib/engine/transaction/nodes/bucket_query.trx_node.d.ts +4 -2
  149. package/lib/engine/transaction/nodes/bucket_query.trx_node.js +27 -15
  150. package/lib/engine/transaction/nodes/job.trx_node.d.ts +2 -1
  151. package/lib/engine/transaction/nodes/job.trx_node.js +6 -0
  152. package/lib/engine/transaction/trx.d.ts +5 -2
  153. package/lib/engine/transaction/trx.js +2 -2
  154. package/lib/engine/transaction/trx_engine.config.d.ts +1 -3
  155. package/lib/engine/transaction/trx_engine.d.ts +2 -2
  156. package/lib/engine/transaction/trx_engine.js +14 -11
  157. package/lib/engine/transaction/trx_node.d.ts +14 -4
  158. package/lib/engine/transaction/trx_node.js +50 -8
  159. package/lib/engine/tree.d.ts +1 -1
  160. package/lib/engine/util/crypto.d.ts +50 -0
  161. package/lib/engine/util/crypto.js +89 -0
  162. package/lib/engine/util/deep.d.ts +5 -0
  163. package/lib/engine/util/deep.js +46 -0
  164. package/lib/engine/util/dotenv.d.ts +2 -8
  165. package/lib/engine/util/dotenv.js +14 -36
  166. package/lib/engine/util/hash.d.ts +3 -0
  167. package/lib/engine/util/hash.js +23 -0
  168. package/lib/engine/util/log.js +1 -1
  169. package/lib/engine/util/mime.d.ts +10 -0
  170. package/lib/engine/util/mime.js +389 -0
  171. package/lib/engine/util/parse.d.ts +6 -5
  172. package/lib/engine/util/parse.js +16 -15
  173. package/lib/engine/util/path.d.ts +3 -0
  174. package/lib/engine/util/path.js +92 -0
  175. package/lib/engine/util/rules.d.ts +4 -0
  176. package/lib/engine/util/rules.js +12 -0
  177. package/package.json +2 -2
  178. package/tools/compile.js +2 -2
  179. package/tools/dotenv.d.ts +1 -0
  180. package/tools/dotenv.js +4 -0
  181. package/tools/joaquin/job.d.ts +5 -5
  182. package/tools/joaquin/mock.d.ts +23 -2
  183. package/tools/joaquin/mock.js +127 -21
  184. package/tsconfig.build.tsbuildinfo +1 -1
  185. package/lib/adapters/postgres/test/postgres.bucket_query.test.d.ts +0 -0
  186. package/lib/adapters/postgres/test/postgres.bucket_query.test.js +0 -136
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.CLIInputHandler = void 0;
37
+ const stream_1 = require("stream");
38
+ const readline = __importStar(require("readline"));
39
+ class CLIInputHandler {
40
+ constructor(suggestions = []) {
41
+ this.suggestions = suggestions;
42
+ this.items = [];
43
+ this.history = 0;
44
+ this.buffer = '';
45
+ this.cursor = 0;
46
+ }
47
+ /**
48
+ * Wait for user input:
49
+ * - Some text + Enter
50
+ * - Special Keys: Up/Down/Tab
51
+ */
52
+ async input(ctx) {
53
+ return new Promise(resolve => {
54
+ const mutableStdout = new stream_1.Writable({
55
+ write: function (chunk, encoding, callback) {
56
+ }
57
+ });
58
+ this.buffer = '';
59
+ this.cursor = 0;
60
+ this.suggestion = undefined;
61
+ const rl = readline.createInterface({
62
+ input: process.stdin,
63
+ output: mutableStdout,
64
+ terminal: true
65
+ });
66
+ const print = () => {
67
+ process.stdout.clearLine(0);
68
+ process.stdout.cursorTo(0);
69
+ process.stdout.write(ctx + ' ' + this.buffer);
70
+ process.stdout.moveCursor(this.cursor - this.buffer.length, 0);
71
+ };
72
+ print();
73
+ const onKeypress = (ch, key) => {
74
+ // History
75
+ if (key.name === 'up') {
76
+ this.buffer = this.up() || this.buffer;
77
+ this.cursor = this.buffer.length;
78
+ print();
79
+ return;
80
+ }
81
+ if (key.name === 'down') {
82
+ this.buffer = this.down() || '';
83
+ this.cursor = this.buffer.length;
84
+ print();
85
+ return;
86
+ }
87
+ // Suggestion
88
+ if (key.name === 'tab') {
89
+ this.buffer = this.suggest(this.buffer) || this.buffer;
90
+ this.cursor = this.buffer.length;
91
+ print();
92
+ return;
93
+ }
94
+ this.suggestion = undefined;
95
+ // Text Editing
96
+ if (key.name === 'left') {
97
+ if (this.cursor > 0) {
98
+ process.stdout.moveCursor(-1, 0);
99
+ this.cursor -= 1;
100
+ }
101
+ print();
102
+ return;
103
+ }
104
+ if (key.name === 'right') {
105
+ if (this.cursor < this.buffer.length) {
106
+ process.stdout.moveCursor(1, 0);
107
+ this.cursor += 1;
108
+ }
109
+ print();
110
+ return;
111
+ }
112
+ if (key.name === 'backspace') {
113
+ if (this.buffer.length == 0) {
114
+ return;
115
+ }
116
+ this.buffer = this.buffer.slice(0, this.cursor - 1)
117
+ + this.buffer.slice(this.cursor);
118
+ this.cursor -= 1;
119
+ print();
120
+ return;
121
+ }
122
+ if (key.name === 'delete') {
123
+ if (this.buffer.length == 0) {
124
+ return;
125
+ }
126
+ this.buffer = this.buffer.slice(0, this.cursor)
127
+ + this.buffer.slice(this.cursor + 1);
128
+ print();
129
+ return;
130
+ }
131
+ // Submit
132
+ if (key.name === 'return') {
133
+ submit(this.buffer);
134
+ return;
135
+ }
136
+ // Text Characters
137
+ else {
138
+ this.buffer = this.buffer.slice(0, this.cursor)
139
+ + ch
140
+ + this.buffer.slice(this.cursor);
141
+ this.cursor += 1;
142
+ print();
143
+ }
144
+ };
145
+ const onCancel = () => {
146
+ if (!this.buffer.length) {
147
+ process.stdout.clearLine(0);
148
+ process.stdout.cursorTo(0);
149
+ process.exit();
150
+ }
151
+ submit(undefined);
152
+ };
153
+ const submit = (value) => {
154
+ process.stdout.write('\n');
155
+ rl.close();
156
+ process.stdin.off('keypress', onKeypress);
157
+ rl.off('SIGINT', onCancel);
158
+ this.buffer = '';
159
+ if (value !== undefined) {
160
+ this.add(value);
161
+ }
162
+ resolve(value);
163
+ };
164
+ process.stdin.on('keypress', onKeypress);
165
+ rl.on('SIGINT', onCancel);
166
+ });
167
+ }
168
+ add(item) {
169
+ this.history = 0;
170
+ this.suggestion = undefined;
171
+ if (this.items[0] === item) {
172
+ return;
173
+ }
174
+ this.items.unshift(item);
175
+ }
176
+ up() {
177
+ if (this.history >= this.items.length)
178
+ return;
179
+ const item = this.items[this.history];
180
+ this.history += 1;
181
+ return item;
182
+ }
183
+ down() {
184
+ if (this.history <= 0)
185
+ return;
186
+ const item = this.items[this.history];
187
+ this.history -= 1;
188
+ return item;
189
+ }
190
+ suggest(_seed) {
191
+ const idx = this.suggestion?.idx || 0;
192
+ const seed = this.suggestion?.seed || _seed;
193
+ for (let i = idx; i < this.suggestions.length; i++) {
194
+ const sugg = this.suggestions[i];
195
+ if (sugg.startsWith(seed)) {
196
+ this.suggestion = {
197
+ seed,
198
+ idx: i + 1
199
+ };
200
+ return sugg;
201
+ }
202
+ }
203
+ this.suggestion = undefined;
204
+ return seed;
205
+ }
206
+ }
207
+ exports.CLIInputHandler = CLIInputHandler;
@@ -2,7 +2,7 @@ export default class UI {
2
2
  /**
3
3
  * Show a list of options and let the user pick with up/down + enter
4
4
  */
5
- static select(title: string, options: string[], defaul?: number): Promise<string>;
5
+ static select<T>(title: string, options: T[], val?: NoInfer<(o: T) => string>, defaul?: number): Promise<T>;
6
6
  /**
7
7
  * Ask a question and wait for the answer
8
8
  */
@@ -40,7 +40,7 @@ class UI {
40
40
  /**
41
41
  * Show a list of options and let the user pick with up/down + enter
42
42
  */
43
- static async select(title, options, defaul = 0) {
43
+ static async select(title, options, val = (o => o), defaul = 0) {
44
44
  return new Promise(resolve => {
45
45
  UI.step(title);
46
46
  let mute = true;
@@ -61,7 +61,7 @@ class UI {
61
61
  const print = () => {
62
62
  mute = false;
63
63
  for (let i = 0; i < options.length; i++) {
64
- rl.write((0, string_1.colored)(`${i === selected ? '» ' : ' '}` + options[i] + '\n', i === selected ? 'lightgreen' : 'lightgray'));
64
+ rl.write((0, string_1.colored)(`${i === selected ? '» ' : ' '}` + val(options[i]) + '\n', i === selected ? 'lightgreen' : 'lightgray'));
65
65
  }
66
66
  mute = true;
67
67
  };
@@ -14,8 +14,9 @@ export declare abstract class Daemon<S extends $Space, Modules extends ModuleNam
14
14
  private _cli?;
15
15
  constructor(name: string, trxEngines: Record<Modules, AnyTrxEngine>, providers: Record<string, any>, app?: AnyAppConfig | undefined);
16
16
  trx<K extends Modules & keyof S['modules']>(moduleName: K): DaemonTrx<S, S["modules"][K], {}>;
17
- cli(): Promise<void>;
17
+ cli(cmd?: string): Promise<void>;
18
18
  private bindControllers;
19
+ static destroy(daemon: AnyDaemon): Promise<void>;
19
20
  static reload(daemon: AnyDaemon, trxEngines: Record<string, AnyTrxEngine>, providers: Record<string, any>): void;
20
21
  static get<T extends {
21
22
  name: string;
@@ -29,7 +30,7 @@ export declare class DaemonTrx<S extends $Space, M extends $Module, Authn extend
29
30
  private trxEngine;
30
31
  private _authn?;
31
32
  constructor(trxEngine: AnyTrxEngine);
32
- authn<Authn extends AuthnRequest<keyof S['authnUsers']>>(authn: Authn): DaemonTrx<S, M, { [K in keyof Authn]: S["authnUsers"][K & keyof S["authnUsers"]]; }>;
33
+ authn<Authn extends AuthnRequest<keyof S['authnUsers']>>(authn?: Authn): DaemonTrx<S, M, { [K in keyof Authn]: S["authnUsers"][K & keyof S["authnUsers"]]; }>;
33
34
  run<Output>(fn: (trx: TrxNode<S, M, Authn>) => Promise<Output>): Promise<TrxStatus<Output>>;
34
35
  }
35
36
  export type AnyDaemon = Daemon<any, any>;
@@ -20,9 +20,9 @@ class Daemon {
20
20
  }
21
21
  return new DaemonTrx(trxEngine);
22
22
  }
23
- async cli() {
23
+ async cli(cmd) {
24
24
  this._cli = new cli_1.CLI(this, this.app?.cli);
25
- await this._cli.run();
25
+ await this._cli.run(cmd);
26
26
  }
27
27
  bindControllers() {
28
28
  log_1.Log.info('daemon', this.name, 'Binding controllers');
@@ -34,10 +34,22 @@ class Daemon {
34
34
  }
35
35
  }
36
36
  }
37
+ static async destroy(daemon) {
38
+ log_1.Log.info('daemon', this.name, 'Stop');
39
+ for (const key in daemon.providers) {
40
+ const provider = daemon.providers[key];
41
+ await provider.__down(provider);
42
+ delete daemon.providers[key];
43
+ }
44
+ for (const key in daemon.trxEngines) {
45
+ delete daemon.trxEngines[key];
46
+ }
47
+ }
37
48
  static reload(daemon, trxEngines, providers) {
38
49
  log_1.Log.info('daemon', this.name, 'Reloaded');
39
50
  daemon.trxEngines = trxEngines;
40
51
  daemon.providers = providers;
52
+ daemon.bindControllers();
41
53
  }
42
54
  static get(daemon, key) {
43
55
  return daemon?.[key];
@@ -9,8 +9,8 @@ class NesoiDate {
9
9
  this.year = year;
10
10
  }
11
11
  static fromISO(iso) {
12
- // TODO: Check invalid ISO
13
- const match = iso.match(/(\d{4})-([01]\d)-([0-3]\d)/);
12
+ const match = iso.match(/(\d{4})-(\d{2})-(\d{2})/);
13
+ // TODO: Check invalid date
14
14
  if (!match) {
15
15
  throw error_1.NesoiError.Data.InvalidISOString({ value: iso });
16
16
  }
@@ -1,12 +1,48 @@
1
1
  export declare class NesoiDatetime {
2
+ static tz: {
3
+ '-12:00': string;
4
+ '-11:00': string;
5
+ '-10:00': string;
6
+ '-07:00': string;
7
+ '-06:00': string;
8
+ '-05:00': string;
9
+ '-04:00': string;
10
+ '-03:00': string;
11
+ '-02:00': string;
12
+ '-01:00': string;
13
+ Z: string;
14
+ '+01:00': string;
15
+ '+02:00': string;
16
+ '+03:00': string;
17
+ '+04:00': string;
18
+ '+05:00': string;
19
+ '+06:00': string;
20
+ '+07:00': string;
21
+ '+08:00': string;
22
+ '+09:00': string;
23
+ '+10:00': string;
24
+ '+11:00': string;
25
+ '+12:00': string;
26
+ '+13:00': string;
27
+ };
2
28
  /**
3
- * Time in milliseconds since 1970-01-01
29
+ * Time in milliseconds since 1970-01-01T00:00:00.000Z
4
30
  */
5
31
  epoch: number;
6
- constructor(jsDate?: Date);
32
+ /**
33
+ * Timezone represented as string (Z, -03, +05, ...)
34
+ */
35
+ tz: keyof typeof NesoiDatetime.tz;
36
+ constructor(epoch?: number, tz?: keyof typeof NesoiDatetime.tz);
37
+ toISO(): string;
38
+ /**
39
+ * Parse a timestamp from ISO 8601 format.
40
+ *
41
+ * Example: `2025-04-16T23:04:42.000-03:00`
42
+ */
7
43
  static fromISO(iso: string): NesoiDatetime;
8
44
  static now(): NesoiDatetime;
9
45
  static isoNow(): string;
10
- static shortNow(): string;
11
- toISO(): string;
46
+ static shortIsoNow(): string;
47
+ plus(period: `${number} ${'second' | 'minute' | 'hour' | 'day' | 'week' | 'month'}${'s' | ''}`): this;
12
48
  }
@@ -3,29 +3,88 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NesoiDatetime = void 0;
4
4
  const error_1 = require("./error");
5
5
  class NesoiDatetime {
6
- constructor(jsDate) {
7
- this.epoch = (jsDate || new Date()).getTime();
6
+ constructor(epoch, tz = 'Z') {
7
+ this.epoch = epoch || new Date().getTime();
8
+ this.tz = tz;
8
9
  }
10
+ // Dump
11
+ toISO() {
12
+ return new Date(this.epoch).toLocaleString('sv-SE', {
13
+ timeZone: NesoiDatetime.tz[this.tz],
14
+ year: 'numeric',
15
+ month: 'numeric',
16
+ day: 'numeric',
17
+ hour: 'numeric',
18
+ minute: 'numeric',
19
+ second: 'numeric',
20
+ fractionalSecondDigits: 3
21
+ })
22
+ .replace(' ', 'T')
23
+ .replace(',', '.')
24
+ + this.tz;
25
+ }
26
+ /**
27
+ * Parse a timestamp from ISO 8601 format.
28
+ *
29
+ * Example: `2025-04-16T23:04:42.000-03:00`
30
+ */
9
31
  static fromISO(iso) {
10
- // TODO: Check invalid ISO
11
- const match = iso.match(/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/);
32
+ const match = iso.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(([-+]\d{2})|Z)?(:00)?$/);
33
+ // TODO: Check invalid datetimes
12
34
  if (!match) {
13
35
  throw error_1.NesoiError.Data.InvalidISOString({ value: iso });
14
36
  }
15
- const jsDate = new Date(iso);
16
- return new NesoiDatetime(jsDate);
37
+ let tz = match[8];
38
+ if (!tz) {
39
+ iso += 'Z';
40
+ tz = 'Z';
41
+ }
42
+ if (tz !== 'Z') {
43
+ if (!match[10]) {
44
+ iso += ':00';
45
+ }
46
+ tz += ':00';
47
+ }
48
+ const jsDate = Date.parse(iso);
49
+ return new NesoiDatetime(jsDate, tz);
17
50
  }
18
51
  static now() {
19
52
  return new NesoiDatetime();
20
53
  }
21
54
  static isoNow() {
22
- return new Date().toISOString();
55
+ return new NesoiDatetime().toISO();
23
56
  }
24
- static shortNow() {
25
- return new Date().toISOString().slice(5, 19);
57
+ static shortIsoNow() {
58
+ return new NesoiDatetime().toISO().slice(5, 19);
26
59
  }
27
- toISO() {
28
- return new Date(this.epoch).toISOString();
60
+ plus(period) {
61
+ return this;
29
62
  }
30
63
  }
31
64
  exports.NesoiDatetime = NesoiDatetime;
65
+ NesoiDatetime.tz = {
66
+ '-12:00': 'Etc/GMT+12',
67
+ '-11:00': 'Etc/GMT+11',
68
+ '-10:00': 'Etc/GMT+10',
69
+ '-07:00': 'Etc/GMT+7',
70
+ '-06:00': 'Etc/GMT+6',
71
+ '-05:00': 'Etc/GMT+5',
72
+ '-04:00': 'Etc/GMT+4',
73
+ '-03:00': 'Etc/GMT+3',
74
+ '-02:00': 'Etc/GMT+2',
75
+ '-01:00': 'Etc/GMT+1',
76
+ 'Z': 'Etc/GMT',
77
+ '+01:00': 'Etc/GMT-1',
78
+ '+02:00': 'Etc/GMT-2',
79
+ '+03:00': 'Etc/GMT-3',
80
+ '+04:00': 'Etc/GMT-4',
81
+ '+05:00': 'Etc/GMT-5',
82
+ '+06:00': 'Etc/GMT-6',
83
+ '+07:00': 'Etc/GMT-7',
84
+ '+08:00': 'Etc/GMT-8',
85
+ '+09:00': 'Etc/GMT-9',
86
+ '+10:00': 'Etc/GMT-10',
87
+ '+11:00': 'Etc/GMT-11',
88
+ '+12:00': 'Etc/GMT-12',
89
+ '+13:00': 'Etc/GMT-13',
90
+ };
@@ -1,4 +1,4 @@
1
- export declare class Decimal {
1
+ export declare class NesoiDecimal {
2
2
  private neg;
3
3
  private left;
4
4
  private right;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Decimal = void 0;
3
+ exports.NesoiDecimal = void 0;
4
4
  const error_1 = require("./error");
5
- class Decimal {
5
+ class NesoiDecimal {
6
6
  constructor(value, pLeft = 12, pRight = 12) {
7
7
  this.neg = false;
8
8
  let payload = value.trim();
@@ -67,4 +67,4 @@ class Decimal {
67
67
  return (this.neg ? -1 : 1) * (this.left + this.right * this.r_exp);
68
68
  }
69
69
  }
70
- exports.Decimal = Decimal;
70
+ exports.NesoiDecimal = NesoiDecimal;
@@ -22,7 +22,10 @@ export declare namespace NesoiError {
22
22
  function UnknownGraphLink(name: string): BaseError;
23
23
  function UnknownViewName(name: string): BaseError;
24
24
  function NoChildrenOnViewGroup(name: string): BaseError;
25
- function CompositionWithPivotNotAllowed(): BaseError;
25
+ function CompositionThroughPivotNotAllowed($: {
26
+ bucket: string;
27
+ link: string;
28
+ }): BaseError;
26
29
  }
27
30
  namespace Message {
28
31
  function UnknownTemplateFieldType(type: string): BaseError;
@@ -55,6 +58,7 @@ export declare namespace NesoiError {
55
58
  namespace Trx {
56
59
  function ModuleNotFound(module: string): BaseError;
57
60
  function NodeNotFound(node: string, trx: string): BaseError;
61
+ function NotAuthenticated($: {}): BaseError;
58
62
  }
59
63
  namespace Bucket {
60
64
  function InvalidId($: {
@@ -84,6 +88,10 @@ export declare namespace NesoiError {
84
88
  bucket: string;
85
89
  link: string;
86
90
  }): BaseError;
91
+ function FieldNotFound($: {
92
+ path: string;
93
+ bucket: string;
94
+ }): BaseError;
87
95
  namespace Graph {
88
96
  function LinkNotFound($: {
89
97
  bucket: string;
@@ -93,7 +101,11 @@ export declare namespace NesoiError {
93
101
  function LinkManyRefOffSelfWithArrayValue(link: string): BaseError;
94
102
  function LinkOneWithArrayValue(link: string): BaseError;
95
103
  function PivotValueIsUndefined(link: string): BaseError;
96
- function RequiredLinkNotFound(link: string, value: any): BaseError;
104
+ function RequiredLinkNotFound($: {
105
+ bucket: string;
106
+ link: string;
107
+ id: number | string;
108
+ }): BaseError;
97
109
  }
98
110
  namespace Query {
99
111
  function NoResults($: {
@@ -112,6 +124,11 @@ export declare namespace NesoiError {
112
124
  index: (string | number)[];
113
125
  }): BaseError;
114
126
  }
127
+ namespace Drive {
128
+ function NoAdapter($: {
129
+ bucket: string;
130
+ }): BaseError;
131
+ }
115
132
  }
116
133
  namespace Data {
117
134
  function InvalidISOString($: {
@@ -167,11 +184,11 @@ export declare namespace NesoiError {
167
184
  path: string;
168
185
  value: any;
169
186
  }): BaseError;
170
- function RuleFailed(rule: $MessageTemplateRule<any, any>, error: string): BaseError;
187
+ function RuleFailed(rule: $MessageTemplateRule, error: string): BaseError;
171
188
  function FileTooBig(prop: {
172
189
  name: string;
173
190
  alias?: string;
174
- }, maxSize: number): BaseError;
191
+ }, maxsize: number): BaseError;
175
192
  function FileExtNotAllowed(prop: {
176
193
  name: string;
177
194
  alias?: string;
@@ -20,6 +20,7 @@ var NesoiError;
20
20
  Status[Status["BAD_REQUEST"] = 400] = "BAD_REQUEST";
21
21
  Status[Status["NOT_FOUND"] = 404] = "NOT_FOUND";
22
22
  Status[Status["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
23
+ Status[Status["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
23
24
  Status[Status["INTERNAL_ERROR"] = 500] = "INTERNAL_ERROR";
24
25
  })(Status || (Status = {}));
25
26
  let Builder;
@@ -49,10 +50,10 @@ var NesoiError;
49
50
  return new BaseError('Builder.Bucket.NoChildrenOnViewGroup', `Bucket view group ${name} has no children`, Status.NOT_FOUND);
50
51
  }
51
52
  Bucket.NoChildrenOnViewGroup = NoChildrenOnViewGroup;
52
- function CompositionWithPivotNotAllowed() {
53
- return new BaseError('Builder.Bucket.CompositionWithPivotNotAllowed', 'Composition with pivot is not allowed', Status.NOT_FOUND);
53
+ function CompositionThroughPivotNotAllowed($) {
54
+ return new BaseError('Builder.Bucket.CompositionThroughPivotNotAllowed', `Link '${$.link}' on bucket '${$.bucket}' passes through pivot, so it cannot be a composition`, Status.INTERNAL_ERROR);
54
55
  }
55
- Bucket.CompositionWithPivotNotAllowed = CompositionWithPivotNotAllowed;
56
+ Bucket.CompositionThroughPivotNotAllowed = CompositionThroughPivotNotAllowed;
56
57
  })(Bucket = Builder.Bucket || (Builder.Bucket = {}));
57
58
  let Message;
58
59
  (function (Message) {
@@ -148,6 +149,10 @@ var NesoiError;
148
149
  return new BaseError('Trx.NodeNotFoundOnTrx', `Node ${node} not found on transaction ${trx}`, Status.NOT_FOUND);
149
150
  }
150
151
  Trx.NodeNotFound = NodeNotFound;
152
+ function NotAuthenticated($) {
153
+ return new BaseError('Trx.NotAuthenticated', 'Unauthorized', Status.UNAUTHORIZED, $);
154
+ }
155
+ Trx.NotAuthenticated = NotAuthenticated;
151
156
  })(Trx = NesoiError.Trx || (NesoiError.Trx = {}));
152
157
  /*
153
158
  Elements / Entities
@@ -178,6 +183,10 @@ var NesoiError;
178
183
  return new BaseError('Bucket.CompositionValueShouldBeArray', `Request to ${$.method} bucket '${$.bucket}' failed, composition for link ${$.link} should be an array`, Status.BAD_REQUEST, $);
179
184
  }
180
185
  Bucket.CompositionValueShouldBeArray = CompositionValueShouldBeArray;
186
+ function FieldNotFound($) {
187
+ return new BaseError('Bucket.FieldNotFound', `Field '${$.path}' not found on bucket '${$.bucket}'`, Status.NOT_FOUND, $);
188
+ }
189
+ Bucket.FieldNotFound = FieldNotFound;
181
190
  let Graph;
182
191
  (function (Graph) {
183
192
  function LinkNotFound($) {
@@ -200,8 +209,8 @@ var NesoiError;
200
209
  return new BaseError('Bucket.Graph.PivotValueIsUndefined', `Link ${link} has a pivot value with undefined/null on the other id`, Status.NOT_FOUND);
201
210
  }
202
211
  Graph.PivotValueIsUndefined = PivotValueIsUndefined;
203
- function RequiredLinkNotFound(link, value) {
204
- return new BaseError('Bucket.Graph.RequiredLinkNotFound', `Link ${link} value not found for value ${value}`, Status.NOT_FOUND);
212
+ function RequiredLinkNotFound($) {
213
+ return new BaseError('Bucket.Graph.RequiredLinkNotFound', `Link '${$.link}' of '${$.bucket}' not found for object with id ${$.id}`, Status.PRECONDITION_FAILED, $);
205
214
  }
206
215
  Graph.RequiredLinkNotFound = RequiredLinkNotFound;
207
216
  })(Graph = Bucket.Graph || (Bucket.Graph = {}));
@@ -239,6 +248,13 @@ var NesoiError;
239
248
  }
240
249
  Fieldpath.InvalidIndexLength = InvalidIndexLength;
241
250
  })(Fieldpath = Bucket.Fieldpath || (Bucket.Fieldpath = {}));
251
+ let Drive;
252
+ (function (Drive) {
253
+ function NoAdapter($) {
254
+ return new BaseError('Bucket.Drive.NoAdapter', `Bucket '${$.bucket}' needs a DriveAdapter configured to handle files.`, Status.BAD_REQUEST, $);
255
+ }
256
+ Drive.NoAdapter = NoAdapter;
257
+ })(Drive = Bucket.Drive || (Bucket.Drive = {}));
242
258
  })(Bucket = NesoiError.Bucket || (NesoiError.Bucket = {}));
243
259
  let Data;
244
260
  (function (Data) {
@@ -301,8 +317,8 @@ var NesoiError;
301
317
  return new BaseError('Message.RuleFailed', error);
302
318
  }
303
319
  Message.RuleFailed = RuleFailed;
304
- function FileTooBig(prop, maxSize) {
305
- return new BaseError('Message.FileTooBig', `${prop.alias || prop.name} size exceeds max (${maxSize})`);
320
+ function FileTooBig(prop, maxsize) {
321
+ return new BaseError('Message.FileTooBig', `${prop.alias || prop.name} size exceeds max (${maxsize})`);
306
322
  }
307
323
  Message.FileTooBig = FileTooBig;
308
324
  function FileExtNotAllowed(prop, options) {
@@ -0,0 +1,38 @@
1
+ import { TrxNode } from '../transaction/trx_node';
2
+ import { $Module } from "../../elements";
3
+ export declare class NesoiFile {
4
+ __nesoi_file: boolean;
5
+ filepath: string;
6
+ filename: string;
7
+ extname: string;
8
+ mimetype: string | null;
9
+ size: number;
10
+ originalFilename: string | null;
11
+ newFilename: string;
12
+ mtime: Date | null;
13
+ hashAlgorithm: false | 'sha1' | 'md5' | 'sha256';
14
+ private _hash;
15
+ constructor(filepath: string, extra?: {
16
+ originalFilename?: string | null;
17
+ newFilename?: string | null;
18
+ });
19
+ static hash(file: NesoiFile, hashAlgorithm: 'sha1' | 'md5' | 'sha256'): Promise<{
20
+ algorithm: "sha1" | "sha256" | "md5";
21
+ hash: string | object;
22
+ }>;
23
+ static delete<M extends $Module>($: {
24
+ trx: TrxNode<any, M, any>;
25
+ }, bucket: keyof M['buckets'], file: NesoiFile, options?: {
26
+ silent?: boolean;
27
+ }): Promise<void> | undefined;
28
+ static move<M extends $Module>($: {
29
+ trx: TrxNode<any, M, any>;
30
+ }, bucket: keyof M['buckets'], file: NesoiFile, to: string, options?: {
31
+ silent?: boolean;
32
+ }): Promise<void>;
33
+ static read<M extends $Module>($: {
34
+ trx: TrxNode<any, M, any>;
35
+ }, bucket: keyof M['buckets'], file: NesoiFile, options?: {
36
+ silent?: boolean;
37
+ }): Promise<void>;
38
+ }