nesoi 3.4.0 → 3.4.1
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.
- package/lib/compiler/elements/bucket.element.js +3 -3
- package/lib/elements/entities/bucket/adapters/memory.nql.js +12 -18
- package/lib/elements/entities/bucket/bucket.d.ts +6 -2
- package/lib/elements/entities/bucket/bucket.js +4 -4
- package/lib/elements/entities/bucket/graph/bucket_graph.js +13 -3
- package/lib/elements/entities/bucket/model/bucket_model.convert.js +9 -17
- package/lib/elements/entities/bucket/model/bucket_model.d.ts +6 -1
- package/lib/elements/entities/bucket/model/bucket_model.js +182 -33
- package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +1 -1
- package/lib/elements/entities/bucket/model/bucket_model.schema.js +2 -2
- package/lib/elements/entities/bucket/query/nql.schema.d.ts +1 -0
- package/lib/elements/entities/bucket/query/nql_compiler.js +5 -4
- package/lib/elements/entities/bucket/query/nql_engine.js +0 -2
- package/lib/elements/entities/bucket/view/bucket_view.d.ts +5 -4
- package/lib/elements/entities/bucket/view/bucket_view.js +300 -188
- package/lib/elements/entities/bucket/view/bucket_view.schema.d.ts +5 -3
- package/lib/elements/entities/bucket/view/bucket_view.schema.js +3 -1
- package/lib/elements/entities/bucket/view/bucket_view_field.builder.d.ts +15 -5
- package/lib/elements/entities/bucket/view/bucket_view_field.builder.js +82 -28
- package/lib/engine/data/error.d.ts +12 -0
- package/lib/engine/data/error.js +12 -0
- package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +6 -2
- package/lib/engine/transaction/nodes/bucket.trx_node.js +4 -4
- package/lib/engine/transaction/nodes/external.trx_node.d.ts +4 -1
- package/lib/engine/transaction/nodes/external.trx_node.js +5 -2
- package/lib/engine/transaction/nodes/job.trx_node.js +0 -1
- package/lib/engine/transaction/trx_engine.js +8 -10
- package/package.json +1 -1
- package/tools/joaquin/bucket.d.ts +6 -2
- package/tools/joaquin/bucket.js +4 -4
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { $Bucket } from '../bucket.schema';
|
|
2
2
|
import { AnyTrxNode } from "../../../../engine/transaction/trx_node";
|
|
3
|
-
export type $BucketViewFieldFn<TrxNode extends AnyTrxNode, B extends $Bucket,
|
|
3
|
+
export type $BucketViewFieldFn<TrxNode extends AnyTrxNode, B extends $Bucket, Parent, Value, Return = any> = (ctx: {
|
|
4
4
|
trx: TrxNode;
|
|
5
|
-
|
|
5
|
+
root: B['#data'];
|
|
6
|
+
parent: Parent;
|
|
6
7
|
value: Value;
|
|
7
8
|
bucket: $Bucket;
|
|
8
9
|
}) => any | Promise<any>;
|
|
@@ -37,9 +38,10 @@ export declare class $BucketViewField {
|
|
|
37
38
|
prop?: string | undefined;
|
|
38
39
|
children?: $BucketViewFields | undefined;
|
|
39
40
|
chain?: $BucketViewField | undefined;
|
|
41
|
+
as_dict?: number[] | undefined;
|
|
40
42
|
$t: string;
|
|
41
43
|
'#data': unknown;
|
|
42
|
-
constructor(name: string, scope: 'model' | 'graph' | 'computed' | 'group' | 'view' | 'drive', alias: string, meta: $BucketViewFieldMeta, prop?: string | undefined, children?: $BucketViewFields | undefined, chain?: $BucketViewField | undefined);
|
|
44
|
+
constructor(name: string, scope: 'model' | 'graph' | 'computed' | 'group' | 'view' | 'drive', alias: string, meta: $BucketViewFieldMeta, prop?: string | undefined, children?: $BucketViewFields | undefined, chain?: $BucketViewField | undefined, as_dict?: number[] | undefined);
|
|
43
45
|
}
|
|
44
46
|
export type $BucketViewFields = {
|
|
45
47
|
[x: string]: $BucketViewField;
|
|
@@ -13,9 +13,10 @@ class $BucketViewField {
|
|
|
13
13
|
prop;
|
|
14
14
|
children;
|
|
15
15
|
chain;
|
|
16
|
+
as_dict;
|
|
16
17
|
$t = 'bucket.view.field';
|
|
17
18
|
'#data';
|
|
18
|
-
constructor(name, scope, alias, meta, prop, children, chain) {
|
|
19
|
+
constructor(name, scope, alias, meta, prop, children, chain, as_dict) {
|
|
19
20
|
this.name = name;
|
|
20
21
|
this.scope = scope;
|
|
21
22
|
this.alias = alias;
|
|
@@ -23,6 +24,7 @@ class $BucketViewField {
|
|
|
23
24
|
this.prop = prop;
|
|
24
25
|
this.children = children;
|
|
25
26
|
this.chain = chain;
|
|
27
|
+
this.as_dict = as_dict;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
exports.$BucketViewField = $BucketViewField;
|
|
@@ -19,11 +19,15 @@ type ComputedData<Fn extends $BucketViewFieldFn<any, any, any, any>, R = ReturnT
|
|
|
19
19
|
export declare class BucketViewFieldFactory<Space extends $Space, Module extends $Module, Bucket extends $Bucket> {
|
|
20
20
|
protected scope: $BucketViewField['scope'];
|
|
21
21
|
protected meta: $BucketViewField['meta'];
|
|
22
|
-
|
|
23
|
-
[K in keyof Bucket[
|
|
22
|
+
get inject(): {
|
|
23
|
+
readonly root: { [K in keyof Bucket["#data"]]: BucketViewFieldBuilder<Module, Bucket, Bucket, Bucket["#data"][K], "model">; };
|
|
24
|
+
readonly parent: { [K in keyof Bucket["#data"]]: BucketViewFieldBuilder<Module, Bucket, Bucket, Bucket["#data"][K], "model">; };
|
|
25
|
+
readonly value: { [K in keyof Bucket["#data"]]: BucketViewFieldBuilder<Module, Bucket, Bucket, Bucket["#data"][K], "model">; };
|
|
24
26
|
};
|
|
27
|
+
get root(): BucketViewFieldBuilder<Module, Bucket, Bucket, any, "model", never>;
|
|
28
|
+
get parent(): BucketViewFieldBuilder<Module, Bucket, Bucket, any, "model", never>;
|
|
29
|
+
get value(): BucketViewFieldBuilder<Module, Bucket, Bucket, any, "model", never>;
|
|
25
30
|
model<K extends keyof Bucket['#modelpath']>(path: K): BucketViewFieldBuilder<Module, Bucket, Bucket, Bucket["#modelpath"][K], "model", never>;
|
|
26
|
-
value(): BucketViewFieldBuilder<Module, Bucket, Bucket, any, "model", never>;
|
|
27
31
|
computed<Fn extends $BucketViewFieldFn<TrxNode<Space, Module, Space['authnUsers']>, Bucket, Bucket['#data'], Bucket['#data']>>(fn: Fn): BucketViewFieldBuilder<Module, Bucket, Bucket, ComputedData<Fn, ReturnType<Fn>>, "computed", never>;
|
|
28
32
|
graph<L extends keyof Bucket['graph']['links'], V extends (keyof Bucket['graph']['links'][L]['#bucket']['views']) | undefined>(link: L, view?: V): BucketViewFieldBuilder<Module, Bucket, Bucket["graph"]["links"][L]["#bucket"], Bucket["graph"]["links"][L]["#many"] extends true ? (undefined extends V ? Bucket["graph"]["links"][L]["#bucket"]["#data"] : ViewObj<Bucket["graph"]["links"][L]["#bucket"], NonNullable<V>>)[] : undefined extends V ? Bucket["graph"]["links"][L]["#bucket"]["#data"] : ViewObj<Bucket["graph"]["links"][L]["#bucket"], NonNullable<V>>, "graph", `${Bucket["graph"]["links"][L]["#bucket"]["name"]}.${V & string}`>;
|
|
29
33
|
drive<F extends DriveFieldpath<Bucket>>(path: F): BucketViewFieldBuilder<Module, Bucket, Bucket, string, "drive", never>;
|
|
@@ -41,11 +45,17 @@ export declare class BucketViewFieldBuilder<Module extends $Module, Bucket exten
|
|
|
41
45
|
protected subview?: (BucketViewFieldBuilders<any> | BucketViewDef<any, any, any>) | undefined;
|
|
42
46
|
$b: "view.field";
|
|
43
47
|
protected _prop?: string;
|
|
44
|
-
protected _chain?:
|
|
48
|
+
protected _chain?: ($: BucketViewFieldFactory<any, Module, Bucket>) => BucketViewFieldBuilder<Module, Bucket, any, any, any>;
|
|
49
|
+
protected _as_dict?: number[];
|
|
45
50
|
constructor(scope: $BucketViewField['scope'], meta: $BucketViewFieldMeta, subview?: (BucketViewFieldBuilders<any> | BucketViewDef<any, any, any>) | undefined);
|
|
46
51
|
prop<Obj extends Data extends any[] ? Data[number] : Data, K extends keyof Obj>(prop: K): BucketViewFieldBuilder<Module, Bucket, ChainBucket, Obj[K], Scope, GraphLink>;
|
|
47
52
|
map<Def extends BucketViewDef<any, Module, ChainBucket>>(def: Def): BucketViewFieldBuilder<Module, Bucket, ChainBucket, { [K in keyof Def]: Def extends BucketViewFieldBuilder<any, any, infer X, any, any> ? X : never; }, Scope, GraphLink>;
|
|
48
|
-
chain<
|
|
53
|
+
chain<Def extends ($: BucketViewFieldFactory<any, Module, Bucket>) => BucketViewFieldBuilder<Module, Bucket, any, any, any>>(def: Def): BucketViewFieldBuilder<Module, Bucket, ChainBucket, Data, Scope, GraphLink>;
|
|
54
|
+
dict(indexes?: number[]): BucketViewFieldBuilder<Module, Bucket, ChainBucket, Data extends any[] ? {
|
|
55
|
+
[x: string]: Data[number];
|
|
56
|
+
} : {
|
|
57
|
+
[x: string]: Data;
|
|
58
|
+
}, Scope, GraphLink>;
|
|
49
59
|
static build(builder: BucketViewFieldBuilder<any, any, any, any, any>, model: $BucketModel, graph: $BucketGraph, views: $BucketViews, name: string, n_indexes: number, tree?: ModuleTree): $BucketViewField;
|
|
50
60
|
static buildFields(fields: BucketViewFieldBuilders<any>, model: $BucketModel, graph: $BucketGraph, views: $BucketViews, n_indexes?: number, tree?: ModuleTree): $BucketViewFields;
|
|
51
61
|
}
|
|
@@ -14,22 +14,50 @@ const bucket_model_schema_1 = require("../model/bucket_model.schema");
|
|
|
14
14
|
class BucketViewFieldFactory {
|
|
15
15
|
scope;
|
|
16
16
|
meta;
|
|
17
|
-
|
|
17
|
+
get inject() {
|
|
18
18
|
return {
|
|
19
|
-
|
|
19
|
+
get root() {
|
|
20
|
+
return {
|
|
21
|
+
__root: {}
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
get parent() {
|
|
25
|
+
return {
|
|
26
|
+
__parent: {}
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
get value() {
|
|
30
|
+
return {
|
|
31
|
+
__value: {}
|
|
32
|
+
};
|
|
33
|
+
},
|
|
20
34
|
};
|
|
21
35
|
}
|
|
22
|
-
|
|
36
|
+
get root() {
|
|
23
37
|
return new BucketViewFieldBuilder('model', {
|
|
24
38
|
model: {
|
|
25
|
-
path:
|
|
39
|
+
path: '__root'
|
|
26
40
|
}
|
|
27
41
|
});
|
|
28
42
|
}
|
|
29
|
-
|
|
43
|
+
get parent() {
|
|
30
44
|
return new BucketViewFieldBuilder('model', {
|
|
31
45
|
model: {
|
|
32
|
-
path: '
|
|
46
|
+
path: '__parent'
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
get value() {
|
|
51
|
+
return new BucketViewFieldBuilder('model', {
|
|
52
|
+
model: {
|
|
53
|
+
path: '__value'
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
model(path) {
|
|
58
|
+
return new BucketViewFieldBuilder('model', {
|
|
59
|
+
model: {
|
|
60
|
+
path: path
|
|
33
61
|
}
|
|
34
62
|
});
|
|
35
63
|
}
|
|
@@ -63,10 +91,6 @@ class BucketViewFieldFactory {
|
|
|
63
91
|
}
|
|
64
92
|
});
|
|
65
93
|
}
|
|
66
|
-
// from<
|
|
67
|
-
// >(
|
|
68
|
-
// ) {
|
|
69
|
-
// }
|
|
70
94
|
extend(view, fields) {
|
|
71
95
|
return {
|
|
72
96
|
__ext: view,
|
|
@@ -92,6 +116,7 @@ class BucketViewFieldBuilder {
|
|
|
92
116
|
$b = 'view.field';
|
|
93
117
|
_prop;
|
|
94
118
|
_chain;
|
|
119
|
+
_as_dict;
|
|
95
120
|
constructor(scope, meta, subview) {
|
|
96
121
|
this.scope = scope;
|
|
97
122
|
this.meta = meta;
|
|
@@ -108,21 +133,37 @@ class BucketViewFieldBuilder {
|
|
|
108
133
|
if (this._prop) {
|
|
109
134
|
throw new Error('Subview not allowed for view field which picks a prop');
|
|
110
135
|
}
|
|
136
|
+
if (this._chain) {
|
|
137
|
+
throw new Error('Subview not allowed on field with chain');
|
|
138
|
+
}
|
|
139
|
+
if (this.subview) {
|
|
140
|
+
throw new Error('Cannot map the same field more than once');
|
|
141
|
+
}
|
|
111
142
|
this.subview = def;
|
|
112
143
|
return this;
|
|
113
144
|
}
|
|
114
|
-
chain(
|
|
115
|
-
this.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
145
|
+
chain(def) {
|
|
146
|
+
if (this.subview) {
|
|
147
|
+
throw new Error('Chain not allowed on field with subiew (map)');
|
|
148
|
+
}
|
|
149
|
+
if (this._chain) {
|
|
150
|
+
throw new Error('Cannot chain the same field more than once');
|
|
151
|
+
}
|
|
152
|
+
this._chain = def;
|
|
153
|
+
// TODO
|
|
154
|
+
// type CData = ComputedData<Fn>
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
dict(indexes) {
|
|
158
|
+
if (!this.meta.model || !this.meta.model.path.split('.').includes('*')) {
|
|
159
|
+
throw new Error('Dict can only be used on model fields containing at least one \'*\'');
|
|
160
|
+
}
|
|
161
|
+
this._as_dict = indexes ?? [-1];
|
|
120
162
|
return this;
|
|
121
163
|
}
|
|
122
164
|
// Build
|
|
123
165
|
static build(builder, model, graph, views, name, n_indexes, tree) {
|
|
124
166
|
let children = undefined;
|
|
125
|
-
const chainBuilder = builder._chain;
|
|
126
167
|
let spread_n = 0;
|
|
127
168
|
let graphLink = undefined;
|
|
128
169
|
if (builder.scope === 'model') {
|
|
@@ -140,12 +181,14 @@ class BucketViewFieldBuilder {
|
|
|
140
181
|
}
|
|
141
182
|
throw new Error(`Maximum index allowed: $${n_indexes - 1}`);
|
|
142
183
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
184
|
+
if (path !== '__root' && path !== '__parent' && path !== '__value') {
|
|
185
|
+
// Retrieve one or more BucketModelFields referenced by a modelpath.
|
|
186
|
+
// (It's only more than one when using unions)
|
|
187
|
+
// The field itself is not used, but serves to validate that the modelpath exists.
|
|
188
|
+
const modelFields = bucket_model_schema_1.$BucketModel.getFields(model, path);
|
|
189
|
+
if (!modelFields.length) {
|
|
190
|
+
throw error_1.NesoiError.Builder.Bucket.UnknownModelField(builder.meta.model.path);
|
|
191
|
+
}
|
|
149
192
|
}
|
|
150
193
|
}
|
|
151
194
|
else if (builder.scope === 'graph') {
|
|
@@ -184,10 +227,12 @@ class BucketViewFieldBuilder {
|
|
|
184
227
|
children = Object.assign({}, children, overrides);
|
|
185
228
|
}
|
|
186
229
|
let chain;
|
|
187
|
-
if (
|
|
188
|
-
|
|
230
|
+
if (builder._chain) {
|
|
231
|
+
const factory = new BucketViewFieldFactory();
|
|
232
|
+
const subview = builder._chain(factory);
|
|
233
|
+
chain = BucketViewFieldBuilder.build(subview, model, graph, views, name, n_indexes + spread_n, tree);
|
|
189
234
|
}
|
|
190
|
-
return new bucket_view_schema_1.$BucketViewField(name, builder.scope, name, builder.meta, builder._prop, children, chain);
|
|
235
|
+
return new bucket_view_schema_1.$BucketViewField(name, builder.scope, name, builder.meta, builder._prop, children, chain, builder._as_dict);
|
|
191
236
|
}
|
|
192
237
|
static buildFields(fields, model, graph, views, n_indexes = 0, tree) {
|
|
193
238
|
const schema = {};
|
|
@@ -200,8 +245,17 @@ class BucketViewFieldBuilder {
|
|
|
200
245
|
if (f === '__ext') {
|
|
201
246
|
continue;
|
|
202
247
|
}
|
|
203
|
-
if (f === '
|
|
204
|
-
schema['
|
|
248
|
+
if (f === '__root') {
|
|
249
|
+
schema['__root'] = {};
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (f === '__parent') {
|
|
253
|
+
schema['__parent'] = {};
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (f === '__value') {
|
|
257
|
+
schema['__value'] = {};
|
|
258
|
+
continue;
|
|
205
259
|
}
|
|
206
260
|
const field = fields[f];
|
|
207
261
|
schema[f] = BucketViewFieldBuilder.build(field, model, graph, views, f, n_indexes, tree);
|
|
@@ -158,6 +158,10 @@ export declare namespace NesoiError {
|
|
|
158
158
|
}): BaseError;
|
|
159
159
|
}
|
|
160
160
|
namespace Model {
|
|
161
|
+
function InvalidModelpath($: {
|
|
162
|
+
bucket: string;
|
|
163
|
+
modelpath: string;
|
|
164
|
+
}): BaseError;
|
|
161
165
|
function InvalidEnum($: {
|
|
162
166
|
bucket: string;
|
|
163
167
|
value: string;
|
|
@@ -179,6 +183,14 @@ export declare namespace NesoiError {
|
|
|
179
183
|
bucket: string;
|
|
180
184
|
value: string;
|
|
181
185
|
}): BaseError;
|
|
186
|
+
function InvalidNesoiDuration($: {
|
|
187
|
+
bucket: string;
|
|
188
|
+
value: string;
|
|
189
|
+
}): BaseError;
|
|
190
|
+
function InvalidNesoiDecimal($: {
|
|
191
|
+
bucket: string;
|
|
192
|
+
value: string;
|
|
193
|
+
}): BaseError;
|
|
182
194
|
}
|
|
183
195
|
namespace Drive {
|
|
184
196
|
function NoAdapter($: {
|
package/lib/engine/data/error.js
CHANGED
|
@@ -296,6 +296,10 @@ var NesoiError;
|
|
|
296
296
|
})(Fieldpath = Bucket.Fieldpath || (Bucket.Fieldpath = {}));
|
|
297
297
|
let Model;
|
|
298
298
|
(function (Model) {
|
|
299
|
+
function InvalidModelpath($) {
|
|
300
|
+
return new BaseError('Bucket.Model.InvalidModelpath', `Modelpath '${$.modelpath}' not found on bucket '${$.bucket}'`, Status.BAD_REQUEST, $);
|
|
301
|
+
}
|
|
302
|
+
Model.InvalidModelpath = InvalidModelpath;
|
|
299
303
|
function InvalidEnum($) {
|
|
300
304
|
return new BaseError('Bucket.Model.InvalidEnum', `Value '${$.value}' for bucket '${$.bucket}' doesn't match the options: ${$.options}.`, Status.BAD_REQUEST, $);
|
|
301
305
|
}
|
|
@@ -316,6 +320,14 @@ var NesoiError;
|
|
|
316
320
|
return new BaseError('Bucket.Model.InvalidNesoiDatetime', `Value '${$.value}' for bucket '${$.bucket}' is not a Nesoi datetime.`, Status.BAD_REQUEST, $);
|
|
317
321
|
}
|
|
318
322
|
Model.InvalidNesoiDatetime = InvalidNesoiDatetime;
|
|
323
|
+
function InvalidNesoiDuration($) {
|
|
324
|
+
return new BaseError('Bucket.Model.InvalidNesoiDuration', `Value '${$.value}' for bucket '${$.bucket}' is not a Nesoi duration.`, Status.BAD_REQUEST, $);
|
|
325
|
+
}
|
|
326
|
+
Model.InvalidNesoiDuration = InvalidNesoiDuration;
|
|
327
|
+
function InvalidNesoiDecimal($) {
|
|
328
|
+
return new BaseError('Bucket.Model.InvalidNesoiDecimal', `Value '${$.value}' for bucket '${$.bucket}' is not a Nesoi decimal.`, Status.BAD_REQUEST, $);
|
|
329
|
+
}
|
|
330
|
+
Model.InvalidNesoiDecimal = InvalidNesoiDecimal;
|
|
319
331
|
})(Model = Bucket.Model || (Bucket.Model = {}));
|
|
320
332
|
let Drive;
|
|
321
333
|
(function (Drive) {
|
|
@@ -165,8 +165,12 @@ export declare class BucketTrxNode<M extends $Module, $ extends $Bucket> {
|
|
|
165
165
|
* so the behavior depends on the bucket used.
|
|
166
166
|
*/
|
|
167
167
|
deleteMany(ids: $['#data']['id'][]): Promise<void>;
|
|
168
|
-
buildOne<V extends ViewName<$>, Obj extends ViewObj<$, V>>(obj: $['#data'], view: V
|
|
169
|
-
|
|
168
|
+
buildOne<V extends ViewName<$>, Obj extends ViewObj<$, V>>(obj: $['#data'], view: V, flags?: {
|
|
169
|
+
serialize: boolean;
|
|
170
|
+
}): Promise<Obj>;
|
|
171
|
+
buildMany<V extends ViewName<$>, Obj extends ViewObj<$, V>>(objs: $['#data'][], view: V, flags?: {
|
|
172
|
+
serialize: boolean;
|
|
173
|
+
}): Promise<Obj[]>;
|
|
170
174
|
/**
|
|
171
175
|
* Methods to use the Bucket's drive (file storage).
|
|
172
176
|
*/
|
|
@@ -330,11 +330,11 @@ class BucketTrxNode {
|
|
|
330
330
|
/*
|
|
331
331
|
Build
|
|
332
332
|
*/
|
|
333
|
-
async buildOne(obj, view) {
|
|
334
|
-
return this.wrap('buildOne', { obj }, (trx, bucket) => bucket.buildOne(trx, obj, view), () => undefined);
|
|
333
|
+
async buildOne(obj, view, flags) {
|
|
334
|
+
return this.wrap('buildOne', { obj }, (trx, bucket) => bucket.buildOne(trx, obj, view, flags), () => undefined);
|
|
335
335
|
}
|
|
336
|
-
async buildMany(objs, view) {
|
|
337
|
-
return this.wrap('buildMany', { objs }, (trx, bucket) => bucket.buildMany(trx, objs, view), () => undefined);
|
|
336
|
+
async buildMany(objs, view, flags) {
|
|
337
|
+
return this.wrap('buildMany', { objs }, (trx, bucket) => bucket.buildMany(trx, objs, view, flags), () => undefined);
|
|
338
338
|
}
|
|
339
339
|
/*
|
|
340
340
|
Drive
|
|
@@ -13,5 +13,8 @@ export declare class ExternalTrxNode<M extends $Module, $ extends $Topic> {
|
|
|
13
13
|
private daemon;
|
|
14
14
|
constructor(trx: TrxNode<any, M, any>, tag: Tag, idempotent?: boolean);
|
|
15
15
|
run_and_hold(element: (trx: AnyTrxNode) => any, fn: (trx: AnyTrxNode, element: any) => Promise<any>): Promise<any>;
|
|
16
|
-
|
|
16
|
+
run_isolated(element: (trx: AnyTrxNode) => any, fn: (trx: AnyTrxNode, element: any) => Promise<any>): Promise<any>;
|
|
17
|
+
run(element: (trx: AnyTrxNode) => any, fn: (trx: AnyTrxNode, element: any) => Promise<any>, options?: {
|
|
18
|
+
isolated?: boolean;
|
|
19
|
+
}): Promise<any>;
|
|
17
20
|
}
|
|
@@ -67,7 +67,10 @@ class ExternalTrxNode {
|
|
|
67
67
|
trx_node_1.TrxNode.ok(trx, out);
|
|
68
68
|
return out;
|
|
69
69
|
}
|
|
70
|
-
async
|
|
70
|
+
async run_isolated(element, fn) {
|
|
71
|
+
return this.run(element, fn, { isolated: true });
|
|
72
|
+
}
|
|
73
|
+
async run(element, fn, options) {
|
|
71
74
|
const parent = this.trx.trx;
|
|
72
75
|
const module = trx_node_1.TrxNode.getModule(this.trx);
|
|
73
76
|
const trx = trx_node_1.TrxNode.makeChildNode(this.trx, module.name, 'externals', this.tag.full);
|
|
@@ -90,7 +93,7 @@ class ExternalTrxNode {
|
|
|
90
93
|
finally {
|
|
91
94
|
trx_node_1.TrxNode.merge(trx, extTrx);
|
|
92
95
|
}
|
|
93
|
-
}, parent.id, this.idempotent);
|
|
96
|
+
}, options?.isolated ? undefined : parent.id, this.idempotent);
|
|
94
97
|
if (res.state === 'error') {
|
|
95
98
|
throw res.error;
|
|
96
99
|
}
|
|
@@ -51,7 +51,6 @@ class JobTrxNode {
|
|
|
51
51
|
return out;
|
|
52
52
|
};
|
|
53
53
|
if (this.external) {
|
|
54
|
-
const root = this.trx.trx;
|
|
55
54
|
const ext = new external_trx_node_1.ExternalTrxNode(this.trx, this.tag, this._idempotent);
|
|
56
55
|
return ext.run_and_hold(trx => dependency_1.Tag.element(this.tag, trx), wrapped);
|
|
57
56
|
}
|
|
@@ -56,7 +56,7 @@ class TrxEngine {
|
|
|
56
56
|
// New transaction
|
|
57
57
|
if (!id) {
|
|
58
58
|
trx = new trx_1.Trx(this, this.module, _origin, req_idempotent);
|
|
59
|
-
log_1.Log.
|
|
59
|
+
log_1.Log.debug('module', this.module.name, `Begin${req_idempotent ? '*' : ''} ${(0, log_1.scopeTag)('trx', trx.root.globalId)} @ ${(0, log_1.anyScopeTag)(_origin)}`);
|
|
60
60
|
for (const wrap of this.config?.wrap || []) {
|
|
61
61
|
// The wrappers decide how to begin a db transaction, based on the trx idempotent flag.
|
|
62
62
|
await wrap.begin(trx, this.services);
|
|
@@ -99,7 +99,7 @@ class TrxEngine {
|
|
|
99
99
|
// A non-idempotent transaction with the same id exists on this module.
|
|
100
100
|
// so it's being continued as an idempotent transaction.
|
|
101
101
|
if (trxData) {
|
|
102
|
-
log_1.Log.
|
|
102
|
+
log_1.Log.debug('module', this.module.name, `Continue* ${(0, log_1.scopeTag)('trx', trx.root.globalId)} @ ${(0, log_1.anyScopeTag)(_origin)}`);
|
|
103
103
|
if (trxData.state !== 'hold') {
|
|
104
104
|
throw new Error(`Attempt to continue transaction ${trxData.id}, currently at '${trxData.state}', failed. Should be at 'hold'. This might mean there are parallel attempts to continue a transaction, which must be handled with a queue.`);
|
|
105
105
|
}
|
|
@@ -111,7 +111,7 @@ class TrxEngine {
|
|
|
111
111
|
// No transaction with the same id exists on this module.
|
|
112
112
|
// so it's starting as an idempotent transaction.
|
|
113
113
|
else {
|
|
114
|
-
log_1.Log.
|
|
114
|
+
log_1.Log.debug('module', this.module.name, `Begin* ${(0, log_1.scopeTag)('trx', trx.root.globalId)} @ ${(0, log_1.anyScopeTag)(_origin)}`);
|
|
115
115
|
for (const wrap of this.config?.wrap || []) {
|
|
116
116
|
// The wrappers decide how to begin a db transaction, based on the trx idempotent flag.
|
|
117
117
|
await wrap.begin(trx, this.services);
|
|
@@ -123,7 +123,7 @@ class TrxEngine {
|
|
|
123
123
|
// A non-idempotent transaction with the same id exists on this module,
|
|
124
124
|
// so it's being continued.
|
|
125
125
|
if (trxData) {
|
|
126
|
-
log_1.Log.
|
|
126
|
+
log_1.Log.debug('module', this.module.name, `Continue ${(0, log_1.scopeTag)('trx', trx.root.globalId)} @ ${(0, log_1.anyScopeTag)(_origin)}`);
|
|
127
127
|
if (trxData.state !== 'hold') {
|
|
128
128
|
throw new Error(`Attempt to continue transaction ${trxData.id}, currently at '${trxData.state}', failed. Should be at 'hold'. This might mean there are parallel attempts to continue a transaction, which must be handled with a queue.`);
|
|
129
129
|
}
|
|
@@ -140,7 +140,7 @@ class TrxEngine {
|
|
|
140
140
|
// so it's starting as a "chained" transaction - a new one with
|
|
141
141
|
// the same ID as the one from some module.
|
|
142
142
|
else {
|
|
143
|
-
log_1.Log.
|
|
143
|
+
log_1.Log.debug('module', this.module.name, `Chain${trx.idempotent ? '*' : ''} ${(0, log_1.scopeTag)('trx', trx.root.globalId)} @ ${(0, log_1.anyScopeTag)(_origin)}`);
|
|
144
144
|
for (const wrap of this.config?.wrap || []) {
|
|
145
145
|
// The wrappers decide how to begin a db transaction, based on the trx idempotent flag.
|
|
146
146
|
await wrap.begin(trx, this.services);
|
|
@@ -225,7 +225,7 @@ class TrxEngine {
|
|
|
225
225
|
}
|
|
226
226
|
//
|
|
227
227
|
async hold(trx, output) {
|
|
228
|
-
log_1.Log.
|
|
228
|
+
log_1.Log.debug('module', this.module.name, `Hold ${(0, log_1.scopeTag)('trx', trx.root.globalId)}`);
|
|
229
229
|
trx_node_1.TrxNode.hold(trx.root, output);
|
|
230
230
|
await this.adapter.put(this.innerTrx.root, {
|
|
231
231
|
id: trx.id,
|
|
@@ -238,9 +238,7 @@ class TrxEngine {
|
|
|
238
238
|
return trx;
|
|
239
239
|
}
|
|
240
240
|
async ok(trx, output, idempotent) {
|
|
241
|
-
|
|
242
|
-
log_1.Log.info('module', this.module.name, `Ok* ${(0, log_1.scopeTag)('trx', trx.root.globalId)}`);
|
|
243
|
-
}
|
|
241
|
+
log_1.Log.debug('module', this.module.name, `Ok${idempotent ? '*' : ''} ${(0, log_1.scopeTag)('trx', trx.root.globalId)}`);
|
|
244
242
|
trx_node_1.TrxNode.ok(trx.root, output);
|
|
245
243
|
trx.end = datetime_1.NesoiDatetime.now();
|
|
246
244
|
const held_children = Object.keys(trx.holds).length;
|
|
@@ -253,7 +251,7 @@ class TrxEngine {
|
|
|
253
251
|
return this.commit(trx);
|
|
254
252
|
}
|
|
255
253
|
async commit(trx) {
|
|
256
|
-
log_1.Log.
|
|
254
|
+
log_1.Log.debug('module', this.module.name, `Commit ${(0, log_1.scopeTag)('trx', trx.root.globalId)}`);
|
|
257
255
|
await this.log_adapter?.put(this.innerTrx.root, {
|
|
258
256
|
id: trx.id,
|
|
259
257
|
state: 'ok',
|
package/package.json
CHANGED
|
@@ -18,11 +18,15 @@ export declare function expectBucket(def: (builder: AnyBucketBuilder) => any, in
|
|
|
18
18
|
builder: AnyBucketBuilder;
|
|
19
19
|
data: Record<string, any>;
|
|
20
20
|
})[]): {
|
|
21
|
-
toBuildOne(raw: Record<string, any>, view: string
|
|
21
|
+
toBuildOne(raw: Record<string, any>, view: string, flags?: {
|
|
22
|
+
serialize: boolean;
|
|
23
|
+
}): {
|
|
22
24
|
as(parsed: Record<string, any> | Record<string, any>[]): Promise<void>;
|
|
23
25
|
butFail(error: (...args: any[]) => NesoiError.BaseError): Promise<void>;
|
|
24
26
|
};
|
|
25
|
-
toBuildMany(raws: Record<string, any>[], view: string
|
|
27
|
+
toBuildMany(raws: Record<string, any>[], view: string, flags?: {
|
|
28
|
+
serialize: boolean;
|
|
29
|
+
}): {
|
|
26
30
|
as(parsed: Record<string, any> | Record<string, any>[]): Promise<void>;
|
|
27
31
|
butFail(error: (...args: any[]) => NesoiError.BaseError): Promise<void>;
|
|
28
32
|
};
|
package/tools/joaquin/bucket.js
CHANGED
|
@@ -37,12 +37,12 @@ function expectBucket(def, inject = []) {
|
|
|
37
37
|
});
|
|
38
38
|
let promise;
|
|
39
39
|
const step1 = {
|
|
40
|
-
toBuildOne(raw, view) {
|
|
41
|
-
promise = () => app.daemon().then(daemon => daemon.trx('test').run(trx => trx.bucket('test').buildOne(raw, view)));
|
|
40
|
+
toBuildOne(raw, view, flags) {
|
|
41
|
+
promise = () => app.daemon().then(daemon => daemon.trx('test').run(trx => trx.bucket('test').buildOne(raw, view, flags)));
|
|
42
42
|
return step2;
|
|
43
43
|
},
|
|
44
|
-
toBuildMany(raws, view) {
|
|
45
|
-
promise = () => app.daemon().then(daemon => daemon.trx('test').run(trx => trx.bucket('test').buildMany(raws, view)));
|
|
44
|
+
toBuildMany(raws, view, flags) {
|
|
45
|
+
promise = () => app.daemon().then(daemon => daemon.trx('test').run(trx => trx.bucket('test').buildMany(raws, view, flags)));
|
|
46
46
|
return step2;
|
|
47
47
|
}
|
|
48
48
|
};
|