nesoi 3.0.0 → 3.0.3

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 (185) 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/elements/bucket.element.js +26 -11
  27. package/lib/compiler/elements/constants.element.js +1 -1
  28. package/lib/compiler/elements/element.d.ts +2 -0
  29. package/lib/compiler/elements/message.element.js +4 -4
  30. package/lib/compiler/helpers/dump_helpers.js +5 -2
  31. package/lib/compiler/stages/7_dump_stage.js +2 -0
  32. package/lib/compiler/treeshake.js +9 -37
  33. package/lib/compiler/typescript/bridge/extract.js +12 -0
  34. package/lib/compiler/typescript/bridge/inject.js +3 -0
  35. package/lib/compiler/typescript/bridge/organize.js +3 -3
  36. package/lib/elements/blocks/block.builder.js +4 -2
  37. package/lib/elements/blocks/job/internal/resource_job.builder.d.ts +22 -20
  38. package/lib/elements/blocks/job/internal/resource_job.d.ts +2 -1
  39. package/lib/elements/blocks/job/internal/resource_job.js +17 -4
  40. package/lib/elements/blocks/job/job.js +3 -0
  41. package/lib/elements/blocks/job/job.types.d.ts +7 -0
  42. package/lib/elements/blocks/job/job.types.js +2 -0
  43. package/lib/elements/blocks/machine/machine.js +3 -2
  44. package/lib/elements/blocks/resource/resource.builder.js +2 -4
  45. package/lib/elements/blocks/resource/resource.d.ts +5 -3
  46. package/lib/elements/blocks/resource/resource.js +26 -17
  47. package/lib/elements/edge/controller/adapters/controller_adapter.d.ts +2 -1
  48. package/lib/elements/edge/controller/adapters/controller_adapter.js +11 -2
  49. package/lib/elements/edge/controller/controller.builder.d.ts +4 -5
  50. package/lib/elements/edge/controller/controller.builder.js +7 -7
  51. package/lib/elements/edge/controller/controller.d.ts +2 -1
  52. package/lib/elements/edge/controller/controller.js +8 -6
  53. package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +61 -23
  54. package/lib/elements/entities/bucket/adapters/bucket_adapter.js +22 -13
  55. package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.d.ts +21 -22
  56. package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.js +68 -2
  57. package/lib/elements/entities/bucket/adapters/memory.nql.d.ts +10 -6
  58. package/lib/elements/entities/bucket/adapters/memory.nql.js +38 -3
  59. package/lib/elements/entities/bucket/adapters/slow_memory.bucket_adapter.d.ts +0 -20
  60. package/lib/elements/entities/bucket/adapters/slow_memory.bucket_adapter.js +46 -30
  61. package/lib/elements/entities/bucket/bucket.builder.d.ts +8 -2
  62. package/lib/elements/entities/bucket/bucket.builder.js +13 -19
  63. package/lib/elements/entities/bucket/bucket.config.d.ts +5 -1
  64. package/lib/elements/entities/bucket/bucket.d.ts +180 -19
  65. package/lib/elements/entities/bucket/bucket.js +658 -48
  66. package/lib/elements/entities/bucket/bucket.schema.d.ts +7 -1
  67. package/lib/elements/entities/bucket/bucket.schema.js +2 -1
  68. package/lib/elements/entities/bucket/bucket.types.d.ts +2 -7
  69. package/lib/elements/entities/bucket/cache/bucket_cache.d.ts +6 -2
  70. package/lib/elements/entities/bucket/cache/bucket_cache.js +12 -12
  71. package/lib/elements/entities/bucket/graph/bucket_graph.d.ts +32 -5
  72. package/lib/elements/entities/bucket/graph/bucket_graph.js +80 -111
  73. package/lib/elements/entities/bucket/graph/bucket_graph.schema.d.ts +3 -6
  74. package/lib/elements/entities/bucket/graph/bucket_graph.schema.js +1 -4
  75. package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.d.ts +3 -7
  76. package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.js +6 -2
  77. package/lib/elements/entities/bucket/model/bucket_model.builder.js +1 -1
  78. package/lib/elements/entities/bucket/model/bucket_model.convert.js +3 -3
  79. package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +37 -8
  80. package/lib/elements/entities/bucket/model/bucket_model.schema.js +25 -4
  81. package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +33 -14
  82. package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +56 -13
  83. package/lib/elements/entities/bucket/query/nql.schema.d.ts +1 -0
  84. package/lib/elements/entities/bucket/query/nql_compiler.js +13 -2
  85. package/lib/elements/entities/bucket/query/nql_engine.d.ts +11 -4
  86. package/lib/elements/entities/bucket/query/nql_engine.js +20 -11
  87. package/lib/elements/entities/bucket/view/bucket_view.js +63 -35
  88. package/lib/elements/entities/bucket/view/bucket_view.schema.d.ts +5 -2
  89. package/lib/elements/entities/bucket/view/bucket_view_field.builder.d.ts +6 -2
  90. package/lib/elements/entities/bucket/view/bucket_view_field.builder.js +21 -15
  91. package/lib/elements/entities/constants/constants.schema.d.ts +1 -1
  92. package/lib/elements/entities/drive/drive_adapter.d.ts +36 -0
  93. package/lib/elements/entities/drive/drive_adapter.js +10 -0
  94. package/lib/elements/entities/drive/local.drive_adapter.d.ts +8 -0
  95. package/lib/elements/entities/drive/local.drive_adapter.js +28 -0
  96. package/lib/elements/entities/message/message.schema.d.ts +1 -0
  97. package/lib/elements/entities/message/message.schema.js +33 -0
  98. package/lib/elements/entities/message/message_parser.d.ts +5 -1
  99. package/lib/elements/entities/message/message_parser.js +56 -35
  100. package/lib/elements/entities/message/template/message_template.schema.d.ts +10 -8
  101. package/lib/elements/entities/message/template/message_template_field.builder.d.ts +16 -6
  102. package/lib/elements/entities/message/template/message_template_field.builder.js +25 -0
  103. package/lib/elements/entities/message/template/message_template_parser.js +2 -1
  104. package/lib/engine/apps/app.config.d.ts +32 -11
  105. package/lib/engine/apps/app.config.js +12 -0
  106. package/lib/engine/apps/app.d.ts +2 -0
  107. package/lib/engine/apps/app.js +3 -0
  108. package/lib/engine/apps/inline.app.d.ts +5 -3
  109. package/lib/engine/apps/inline.app.js +27 -12
  110. package/lib/engine/apps/monolyth/monolyth.app.d.ts +4 -2
  111. package/lib/engine/apps/monolyth/monolyth.app.js +22 -10
  112. package/lib/engine/auth/authn.d.ts +5 -1
  113. package/lib/engine/auth/zero.authn_provider.d.ts +4 -2
  114. package/lib/engine/auth/zero.authn_provider.js +2 -2
  115. package/lib/engine/cli/cli.d.ts +3 -1
  116. package/lib/engine/cli/cli.js +22 -3
  117. package/lib/engine/cli/cli_adapter.d.ts +2 -1
  118. package/lib/engine/cli/cli_adapter.js +2 -1
  119. package/lib/engine/cli/cli_input.d.ts +19 -0
  120. package/lib/engine/cli/cli_input.js +207 -0
  121. package/lib/engine/cli/ui.d.ts +1 -1
  122. package/lib/engine/cli/ui.js +2 -2
  123. package/lib/engine/daemon.d.ts +3 -2
  124. package/lib/engine/daemon.js +14 -2
  125. package/lib/engine/data/date.js +2 -2
  126. package/lib/engine/data/datetime.d.ts +40 -4
  127. package/lib/engine/data/datetime.js +70 -11
  128. package/lib/engine/data/decimal.d.ts +1 -1
  129. package/lib/engine/data/decimal.js +3 -3
  130. package/lib/engine/data/error.d.ts +21 -4
  131. package/lib/engine/data/error.js +23 -7
  132. package/lib/engine/data/file.d.ts +23 -0
  133. package/lib/engine/data/file.js +53 -0
  134. package/lib/engine/data/json.d.ts +6 -0
  135. package/lib/engine/data/json.js +26 -0
  136. package/lib/engine/data/obj.d.ts +1 -1
  137. package/lib/engine/data/trash.d.ts +14 -0
  138. package/lib/engine/data/trash.js +2 -0
  139. package/lib/engine/data/tree.d.ts +7 -12
  140. package/lib/engine/data/tree.js +101 -49
  141. package/lib/engine/module.d.ts +2 -1
  142. package/lib/engine/module.js +2 -5
  143. package/lib/engine/space.d.ts +1 -0
  144. package/lib/engine/space.js +6 -0
  145. package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +156 -24
  146. package/lib/engine/transaction/nodes/bucket.trx_node.js +297 -467
  147. package/lib/engine/transaction/nodes/bucket_query.trx_node.d.ts +4 -2
  148. package/lib/engine/transaction/nodes/bucket_query.trx_node.js +27 -15
  149. package/lib/engine/transaction/nodes/job.trx_node.d.ts +2 -1
  150. package/lib/engine/transaction/nodes/job.trx_node.js +6 -0
  151. package/lib/engine/transaction/trx.d.ts +5 -2
  152. package/lib/engine/transaction/trx.js +2 -2
  153. package/lib/engine/transaction/trx_engine.config.d.ts +1 -3
  154. package/lib/engine/transaction/trx_engine.d.ts +2 -2
  155. package/lib/engine/transaction/trx_engine.js +14 -11
  156. package/lib/engine/transaction/trx_node.d.ts +14 -4
  157. package/lib/engine/transaction/trx_node.js +50 -8
  158. package/lib/engine/tree.d.ts +1 -1
  159. package/lib/engine/util/crypto.d.ts +50 -0
  160. package/lib/engine/util/crypto.js +89 -0
  161. package/lib/engine/util/deep.d.ts +5 -0
  162. package/lib/engine/util/deep.js +46 -0
  163. package/lib/engine/util/dotenv.d.ts +2 -8
  164. package/lib/engine/util/dotenv.js +14 -36
  165. package/lib/engine/util/hash.d.ts +3 -0
  166. package/lib/engine/util/hash.js +23 -0
  167. package/lib/engine/util/log.js +1 -1
  168. package/lib/engine/util/mime.d.ts +10 -0
  169. package/lib/engine/util/mime.js +389 -0
  170. package/lib/engine/util/parse.d.ts +6 -5
  171. package/lib/engine/util/parse.js +16 -15
  172. package/lib/engine/util/path.d.ts +3 -0
  173. package/lib/engine/util/path.js +92 -0
  174. package/lib/engine/util/rules.d.ts +4 -0
  175. package/lib/engine/util/rules.js +12 -0
  176. package/package.json +1 -1
  177. package/tools/compile.js +2 -2
  178. package/tools/dotenv.d.ts +1 -0
  179. package/tools/dotenv.js +4 -0
  180. package/tools/joaquin/job.d.ts +5 -5
  181. package/tools/joaquin/mock.d.ts +23 -2
  182. package/tools/joaquin/mock.js +127 -21
  183. package/tsconfig.build.tsbuildinfo +1 -1
  184. package/lib/adapters/postgres/test/postgres.bucket_query.test.d.ts +0 -0
  185. package/lib/adapters/postgres/test/postgres.bucket_query.test.js +0 -136
@@ -7,45 +7,61 @@ exports.Tree = void 0;
7
7
  const error_1 = require("./error");
8
8
  class Tree {
9
9
  /**
10
- * When the fieldpath contains a `.*.`, which refers to a item in a list:
11
- * - If the `index` parameter is null, returns nested lists
12
- * - If the `index` parameter is a list of indices, returns the target object
10
+ * Read one or more values from the object, from a _fieldpath_.
13
11
  *
12
+ * The `index` argument is only relevant if the fieldpath contains a spread (`.#`):
13
+ * - `*`: Return all values of the matched array or dict
14
+ * - `0`: Return the first value of an array or dict (dict ordering is unstable)
15
+ * - `(number|string)[]`: Sequence of values to replace the `#`s on the fieldpath
14
16
  */
15
- static get(obj, fieldpath, index = []) {
17
+ static get(obj, fieldpath, index = '*') {
16
18
  index = (!Array.isArray(index)) ? index : [...index];
17
19
  const paths = fieldpath.split('.');
18
- const pathIndexCount = paths.filter(p => p === '*').length;
20
+ const pathIndexCount = paths.filter(p => p === '#').length;
19
21
  if (Array.isArray(index) && pathIndexCount > index.length) {
20
22
  throw error_1.NesoiError.Bucket.Fieldpath.InvalidIndexLength({ fieldpath, index });
21
23
  }
22
24
  let ref = obj;
23
25
  for (let i = 0; i < paths.length; i++) {
24
26
  const path = paths[i];
25
- if (path === '*') {
27
+ if (path === '#') {
26
28
  // 0 index, read the first item from the list
27
29
  if (index === 0) {
28
- // This is a ObjTypeAsObj, stay on the node
29
- if ('__array' in ref) {
30
+ // This is a TypeAsObj, stay on the node
31
+ if (typeof ref === 'object' && '__array' in ref) {
30
32
  //
31
33
  }
32
34
  else {
33
- if (!Array.isArray(ref)) {
35
+ if (typeof ref !== 'object') {
34
36
  return undefined;
35
37
  }
36
- ref = ref[0];
38
+ if (Array.isArray(ref)) {
39
+ ref = ref[0];
40
+ }
41
+ else {
42
+ ref = ref[Object.keys(ref)[0]];
43
+ }
37
44
  }
38
45
  }
39
46
  // Null index, return a list of all items
40
- else if (index === null) {
41
- if (!Array.isArray(ref)) {
47
+ else if (index === '*') {
48
+ if (typeof ref !== 'object') {
42
49
  return undefined;
43
50
  }
51
+ if (!Array.isArray(ref)) {
52
+ ref = Object.values(ref);
53
+ }
44
54
  const childPath = paths.slice(i + 1);
45
55
  if (childPath.length === 0) {
46
56
  return ref;
47
57
  }
48
- return ref.map(v => this.get(v, childPath.join('.'), null));
58
+ const out = [];
59
+ ref.forEach((v) => {
60
+ const deep = this.get(v, childPath.join('.'), '*');
61
+ if (deep !== undefined)
62
+ out.push(deep);
63
+ });
64
+ return out.flat(1);
49
65
  }
50
66
  // List of indices, advance on it
51
67
  else {
@@ -57,55 +73,91 @@ class Tree {
57
73
  }
58
74
  }
59
75
  else {
60
- ref = ref[path];
76
+ ref = ref?.[path];
61
77
  }
62
78
  if (ref === undefined) {
63
- return undefined;
79
+ return ref;
64
80
  }
65
81
  }
82
+ // When reading from a TypeAsObj,
83
+ // advance on unions
84
+ if (!ref && '__or' in obj) {
85
+ return this.get(obj.__or, fieldpath, index);
86
+ }
66
87
  return ref;
67
88
  }
68
- static find(obj, fn, link, _prefix) {
69
- const root = link ? obj[link] : obj;
70
- for (const key in root) {
71
- const prop = root[key];
72
- const path = (_prefix ? _prefix + '.' : '') + key;
73
- if (fn(path, prop)) {
74
- return {
75
- path,
76
- key,
77
- value: prop
78
- };
89
+ static set(obj, fieldpath, replacer, __index = []) {
90
+ const paths = fieldpath.split('.');
91
+ class Ptr {
92
+ constructor(obj) {
93
+ this.obj = obj;
79
94
  }
80
- if (typeof prop === 'object'
81
- && !Array.isArray(prop)
82
- && !prop['__type']) {
83
- const inner = this.find(prop, fn, link, path);
84
- if (inner) {
85
- return inner;
95
+ walk(key) {
96
+ if (this.key) {
97
+ this.obj = this.obj[this.key];
86
98
  }
99
+ this.key = key;
100
+ }
101
+ get() {
102
+ if (!this.key)
103
+ return this.obj;
104
+ return this.obj?.[this.key];
105
+ }
106
+ replace(replacer, i) {
107
+ this.obj ?? (this.obj = {});
108
+ this.obj[this.key] = replacer(this.obj?.[this.key], i);
87
109
  }
88
110
  }
89
- }
90
- static findAll(obj, fn, _prefix) {
91
- const nodes = [];
92
- for (const key in obj) {
93
- const prop = obj[key];
94
- const path = (_prefix ? _prefix + '.' : '') + key;
95
- if (typeof prop === 'object'
96
- && !Array.isArray(prop)
97
- && !prop['__type']) {
98
- nodes.push(...this.findAll(prop, fn, key));
111
+ const ref = new Ptr(obj);
112
+ for (let i = 0; i < paths.length; i++) {
113
+ const path = paths[i];
114
+ if (path === '#') {
115
+ const arr = ref.get();
116
+ if (typeof arr !== 'object') {
117
+ return;
118
+ }
119
+ const childPath = paths.slice(i + 1);
120
+ if (childPath.length === 0) {
121
+ if (Array.isArray(arr)) {
122
+ for (let i = 0; i < arr.length; i++) {
123
+ arr[i] = replacer(arr[i], [...__index, i]);
124
+ }
125
+ }
126
+ else {
127
+ for (const key in arr) {
128
+ arr[key] = replacer(arr[key], [...__index, key]);
129
+ }
130
+ }
131
+ return;
132
+ }
133
+ if (Array.isArray(arr)) {
134
+ for (let i = 0; i < arr.length; i++) {
135
+ if (typeof arr[i] === 'object') {
136
+ this.set(arr[i], childPath.join('.'), replacer, [...__index, i]);
137
+ }
138
+ }
139
+ }
140
+ else {
141
+ for (const key in arr) {
142
+ if (typeof arr[key] === 'object') {
143
+ this.set(arr[key], childPath.join('.'), replacer, [...__index, key]);
144
+ }
145
+ }
146
+ }
147
+ return;
99
148
  }
100
- if (fn(path, prop)) {
101
- nodes.push({
102
- path,
103
- key,
104
- value: prop
105
- });
149
+ else {
150
+ ref.walk(path);
151
+ }
152
+ if (ref.get() === undefined) {
153
+ ref.replace(replacer, __index);
154
+ return;
106
155
  }
107
156
  }
108
- return nodes;
157
+ if ('__or' in obj) {
158
+ this.set(obj.__or, fieldpath, replacer, __index);
159
+ }
160
+ ref.replace(replacer, __index);
109
161
  }
110
162
  }
111
163
  exports.Tree = Tree;
@@ -41,6 +41,7 @@ export type VirtualModuleDef = {
41
41
  machines?: $Machine[];
42
42
  };
43
43
  externals?: {
44
+ messages?: $Dependency[];
44
45
  buckets?: $Dependency[];
45
46
  jobs?: $Dependency[];
46
47
  };
@@ -92,6 +93,6 @@ export declare class Module<S extends $Space, $ extends $Module> {
92
93
  start(app: AnyApp, providers: Record<string, any>): void;
93
94
  destroy(): void;
94
95
  private destroyBlock;
95
- static virtual(module: AnyModule, def: VirtualModuleDef): Promise<Module<$Space, $Module>>;
96
+ static virtual(daemon: AnyDaemon, def: VirtualModuleDef): Promise<Module<$Space, $Module>>;
96
97
  }
97
98
  export type AnyModule = Module<any, any>;
@@ -314,10 +314,7 @@ class Module {
314
314
  delete this[t][name];
315
315
  }
316
316
  // Virtual
317
- static async virtual(module, def) {
318
- if (!module.daemon) {
319
- throw new Error(`Internal Error: unable to reach nesoi daemon when building virtual module '${def.name}'`);
320
- }
317
+ static async virtual(daemon, def) {
321
318
  const virtualModule = new Module(def.name, { builders: [] });
322
319
  // Inject schemas
323
320
  if (def.schemas) {
@@ -327,7 +324,7 @@ class Module {
327
324
  await virtualModule.start({ config: {} }, {});
328
325
  // Inject externals
329
326
  if (def.externals) {
330
- virtualModule.injectDependencies(module.daemon, def.externals);
327
+ virtualModule.injectDependencies(daemon, def.externals);
331
328
  }
332
329
  return virtualModule;
333
330
  }
@@ -49,6 +49,7 @@ export declare class Space<$ extends $Space> {
49
49
  *
50
50
  */
51
51
  static path(space: Space<any>, ...relPath: string[]): string;
52
+ static relPath(space: Space<any>, absPath: string): string;
52
53
  static scan(space: Space<any>, buildFn: (name: string, path: string) => void): void;
53
54
  }
54
55
  export type AnySpace = Space<$Space>;
@@ -120,6 +120,12 @@ class Space {
120
120
  }
121
121
  return path.resolve(space.dirname, ...relPath);
122
122
  }
123
+ static relPath(space, absPath) {
124
+ if (!space.dirname) {
125
+ throw new Error('Cant use .path() on virtual space');
126
+ }
127
+ return path.relative(space.dirname, absPath);
128
+ }
123
129
  static scan(space, buildFn) {
124
130
  if (!fs.existsSync(space.dirname)) {
125
131
  throw error_1.CompilerError.DirectoryDoesntExists(space.dirname);
@@ -1,53 +1,185 @@
1
1
  import { $Module, ViewName, ViewObj } from "../../../schema";
2
- import { TrxNode } from '../trx_node';
2
+ import { AnyTrxNode, TrxNode } from '../trx_node';
3
3
  import { BucketQueryTrxNode } from './bucket_query.trx_node';
4
4
  import { $Bucket } from "../../../elements/entities/bucket/bucket.schema";
5
5
  import { Bucket } from "../../../elements/entities/bucket/bucket";
6
- import { CreateObj, PatchObj, PutObj, ReplaceObj } from "../../../elements/entities/bucket/bucket.types";
7
- import { NQL_Query, NQL_Order, NQL_Pagination } from "../../../elements/entities/bucket/query/nql.schema";
6
+ import { CreateObj, PatchObj, PutObj } from "../../../elements/entities/bucket/bucket.types";
7
+ import { NQL_Query } from "../../../elements/entities/bucket/query/nql.schema";
8
8
  export declare class BucketTrxNode<M extends $Module, $ extends $Bucket> {
9
9
  private parentTrx;
10
10
  private bucket;
11
+ private enableTenancy;
11
12
  constructor(parentTrx: TrxNode<any, M, any>, bucket: Bucket<M, $>);
13
+ get no_tenancy(): this;
14
+ wrap(action: string, input: Record<string, any>, fn: (trx: AnyTrxNode) => Promise<any>, fmtTrxOut?: (out: any) => any): Promise<any>;
15
+ /**
16
+ * Returns one object by `id`, without pre-formatting,
17
+ * or `undefined` if the object was not found.
18
+ */
12
19
  readOne(id: $['#data']['id']): Promise<$['#data'] | undefined>;
20
+ /**
21
+ * Returns one object by `id` formated with the specified view,
22
+ * or `undefined` if the object was not found.
23
+ * - The formating process can impact performance. If you just need
24
+ * the raw obj, it's recommended to use `readOne` instead.
25
+ */
13
26
  viewOne<V extends ViewName<$>>(id: $['#data']['id'], view?: V): Promise<ViewObj<$, V> | undefined>;
27
+ /**
28
+ * Returns one object by `id`, without pre-formatting,
29
+ * or **throws an exception** if the object was not found.
30
+ */
14
31
  readOneOrFail(id: $['#data']['id']): Promise<$['#data']>;
32
+ /**
33
+ * Returns one object by `id`, without pre-formatting,
34
+ * or **throws an exception** if the object was not found.
35
+ * - The formating process can impact performance. If you just need
36
+ * the raw obj, it's recommended to use `readOneOrFail` instead.
37
+ */
15
38
  viewOneOrFail<V extends ViewName<$>>(id: $['#data']['id'], view?: V): Promise<ViewObj<$, V>>;
16
- readAll(pagination?: NQL_Pagination, order?: NQL_Order<$['#fieldpath']>): Promise<$['#data'][]>;
17
- viewAll<V extends ViewName<$>>(view?: V, pagination?: NQL_Pagination, order?: NQL_Order<$['#fieldpath']>): Promise<ViewObj<$, V>[]>;
39
+ /**
40
+ * Returns a list of all objects, without pre-formatting.
41
+ */
42
+ readAll(): Promise<$['#data'][]>;
43
+ /**
44
+ * Returns a list of all objects formated with the specified view.
45
+ * - The formating process can impact performance. If you just need
46
+ * the raw obj, it's recommended to use `readAll` instead.
47
+ */
48
+ viewAll<V extends ViewName<$>>(view?: V): Promise<ViewObj<$, V>[]>;
49
+ /**
50
+ * Returns a list containing the results of the query.
51
+ */
18
52
  query<V extends ViewName<$> = 'default'>(query: NQL_Query<M, $>, view?: V): BucketQueryTrxNode<M, $, V>;
19
- readLink<LinkName extends keyof $['graph']['links'], Link extends $['graph']['links'][LinkName], LinkBucket extends Link['#bucket'], V extends ViewName<LinkBucket>, Obj extends ViewObj<LinkBucket, V>>(id: $['#data']['id'], link: LinkName, view?: V): Promise<Link['#many'] extends true ? Obj[] : (Obj | undefined)>;
20
- readLinkOrFail<LinkName extends keyof $['graph']['links'], Link extends $['graph']['links'][LinkName], LinkBucket extends Link['#bucket'], V extends ViewName<LinkBucket>, Obj extends ViewObj<LinkBucket, V>>(id: $['#data']['id'], link: LinkName, view?: V): Promise<Link['#many'] extends true ? Obj[] : Obj>;
53
+ /**
54
+ * Returns one or more objects referenced by the graph link,
55
+ * or `undefined` if the graph link doesn't resolve.
56
+ */
57
+ readLink<LinkName extends keyof $['graph']['links'], Link extends $['graph']['links'][LinkName], Obj extends Link['#bucket']['#data']>(id: $['#data']['id'], link: LinkName): Promise<Link['#many'] extends true ? Obj[] : (Obj | undefined)>;
58
+ /**
59
+ * Returns one or more objects referenced by the graph link built with a view,
60
+ * or `undefined` if the graph link doesn't resolve.
61
+ */
62
+ viewLink<LinkName extends keyof $['graph']['links'], Link extends $['graph']['links'][LinkName], LinkBucket extends Link['#bucket'], V extends ViewName<LinkBucket>, Obj extends ViewObj<LinkBucket, V>>(id: $['#data']['id'], link: LinkName, view?: V): Promise<Link['#many'] extends true ? Obj[] : (Obj | undefined)>;
63
+ /**
64
+ * Returns one or more objects referenced by the graph link,
65
+ * or **throws an exception** if the graph link doesn't resolve.
66
+ */
67
+ readLinkOrFail<LinkName extends keyof $['graph']['links'], Link extends $['graph']['links'][LinkName], Obj extends Link['#bucket']['#data']>(id: $['#data']['id'], link: LinkName): Promise<Link['#many'] extends true ? Obj[] : Obj>;
68
+ /**
69
+ * Returns one or more objects referenced by the graph link built with a view,
70
+ * or **throws an exception** if the graph link doesn't resolve.
71
+ */
72
+ viewLinkOrFail<LinkName extends keyof $['graph']['links'], Link extends $['graph']['links'][LinkName], LinkBucket extends Link['#bucket'], V extends ViewName<LinkBucket>, Obj extends ViewObj<LinkBucket, V>>(id: $['#data']['id'], link: LinkName, view?: V): Promise<Link['#many'] extends true ? Obj[] : Obj>;
73
+ /**
74
+ * Returns `true` if the graph link resolves to at least 1 object.
75
+ */
21
76
  hasLink<LinkName extends keyof $['graph']['links']>(id: $['#data']['id'], link: LinkName): Promise<boolean | undefined>;
22
77
  /**
23
- * Updates an object by passing it directly to the bucket adapter,
24
- * without checking if it exists. This creates an object if a new
25
- * id is passed.
78
+ * Creates an object by passing it to the bucket adapter.
79
+ * Also creates the compositions of this bucket, from the
80
+ * `#composition` field passed in the message.
81
+ *
82
+ * - If `#composition` is wrong, this will throw an exception
83
+ */
84
+ create(obj: CreateObj<$>): Promise<$['#data']>;
85
+ /**
86
+ * Reads one object by `id` and `patch` (modify) it based on the one passed as an argument.
87
+ * Also patches the compositions of this bucket, from the
88
+ * `#composition` field passed in the message.
89
+ *
90
+ * - If the object is not found, this will throw an exception
91
+ * - If `#composition` is wrong, this will throw an exception
92
+ * - The read query before updating might impact performance and be unnecessary
93
+ * when you're updating from code that's sure the object exists. In that case,
94
+ * you can use `unsafe.patch`, which doesn't read prior to writing.
95
+ */
96
+ patch(obj: PatchObj<$>): Promise<$['#data']>;
97
+ /**
98
+ * Reads one object by `id` and `replace` it with the one passed as an argument.
99
+ * Also patches the compositions of this bucket, from the
100
+ * `#composition` field passed in the message.
101
+ *
102
+ * - If the object is not found, this will throw an exception
103
+ * - If `#composition` is wrong, this will throw an exception
104
+ * - The read query before updating might impact performance and be unnecessary
105
+ * when you're updating from code that's sure the object exists. In that case,
106
+ * you can use `unsafe.replace`, which doesn't read prior to writing.
107
+ */
108
+ replace(obj: PatchObj<$>): Promise<$['#data']>;
109
+ /**
110
+ * Creates or replaces (by `id`) the object passed as an argument.
111
+ * Does the same for compositions of this bucket, from the
112
+ * `#composition` field passed in the message.
113
+ *
114
+ * - If `#composition` is wrong, this will throw an exception.
115
+ * - This will **REPLACE** objects and it's compositions if they already exist,
116
+ * so there might be unexpected data loss, use it carefully.
117
+ *
118
+ * **WARNING** Tenancy currently not implemented for put.
26
119
  */
27
120
  put(obj: PutObj<$>): Promise<$['#data']>;
28
121
  /**
29
- * Creates an object by passing it to the bucket adapter,
30
- * without an ID (it's removed if passed).
31
- * This is a safer version of `put`, which ensures no update will happen.
122
+ * Attempts to read an object by `id`, if found, deletes it.
123
+ *
124
+ * - If you want to skip the read query, use the `unsafe.delete` method,
125
+ * so the behavior depends on the bucket used.
32
126
  */
33
- create(obj: CreateObj<$>): Promise<$['#data']>;
127
+ delete(id: $['#data']['id']): Promise<void>;
34
128
  /**
35
- * Reads the id from the bucket adapter to ensure the object exists
36
- * before updating.
37
- * This is a safer version of `put`, suited for updating data.
129
+ * Attempts to read an object by `id`, if found, deletes it.
130
+ *
131
+ * - If you want to skip the read query, use the `unsafe.delete` method,
132
+ * so the behavior depends on the bucket used.
38
133
  */
39
- replace(obj: ReplaceObj<$>): Promise<$['#data']>;
134
+ deleteMany(ids: $['#data']['id'][]): Promise<void>;
135
+ buildOne<V extends ViewName<$>, Obj extends ViewObj<$, V>>(obj: $['#data'], view: V): Promise<Obj>;
136
+ buildMany<V extends ViewName<$>, Obj extends ViewObj<$, V>>(objs: $['#data'][], view: V): Promise<Obj[]>;
137
+ /**
138
+ * Unsafe versions of methods, which improve performance
139
+ * by avoiding some validations and queries.
140
+ *
141
+ * **Use it carefully.**
142
+ */
143
+ get unsafe(): BucketUnsafeTrxNode<M, $>;
144
+ }
145
+ export declare class BucketUnsafeTrxNode<M extends $Module, $ extends $Bucket> {
146
+ private bucketTrx;
147
+ private bucket;
148
+ private enableTenancy;
149
+ constructor(bucketTrx: BucketTrxNode<M, $>, bucket: Bucket<M, $>, enableTenancy: boolean);
150
+ get no_tenancy(): this;
40
151
  /**
41
- * Reads the id from the bucket adapter to ensure the object exists
42
- * before updating. Applies changes to the object instead of replacing it.
152
+ * Directly `patch` (modify) an object based on the one passed as an argument.
153
+ * Also patches the compositions of this bucket, from the
154
+ * `#composition` field passed in the message.
155
+ *
156
+ * > This unsafe version does not check if the object exists prior to patching.
157
+ *
158
+ * - If the object is not found, this will throw an exception
159
+ * - If `#composition` is wrong, this will throw an exception
43
160
  */
44
161
  patch(obj: PatchObj<$>): Promise<$['#data']>;
162
+ /**
163
+ * Directly `replace` on object with the one passed as an argument.
164
+ * Also replaces the compositions of this bucket, from the
165
+ * `#composition` field passed in the message.
166
+ *
167
+ * > This unsafe version does not check if the object exists prior to replacing.
168
+ *
169
+ * - If the object is not found, this will throw an exception
170
+ * - If `#composition` is wrong, this will throw an exception
171
+ */
172
+ replace(obj: PatchObj<$>): Promise<$['#data']>;
173
+ /**
174
+ * Deletes an object
175
+ *
176
+ * > This unsafe version does not check if the object exists prior to deleting.
177
+ */
45
178
  delete(id: $['#data']['id']): Promise<void>;
46
179
  /**
47
- * **WARNING**: This does not currently implement composition
180
+ * Attempts to read an object by `id`, if found, deletes it.
181
+ *
182
+ * > This unsafe version does not check if the objects exist prior to deleting.
48
183
  */
49
184
  deleteMany(ids: $['#data']['id'][]): Promise<void>;
50
- deleteOrFail(id: $['#data']['id']): Promise<void>;
51
- buildOne<V extends ViewName<$>, Obj extends ViewObj<$, V>>(obj: $['#data'], view: V): Promise<Obj>;
52
- buildAll<V extends ViewName<$>, Obj extends ViewObj<$, V>>(objs: $['#data'][], view: V): Promise<Obj[]>;
53
185
  }