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.
- package/README.md +10 -0
- package/lib/adapters/postgres/src/migrator/bucket.d.ts +20 -0
- package/lib/adapters/postgres/src/migrator/bucket.js +184 -0
- package/lib/adapters/postgres/src/migrator/csv.d.ts +7 -0
- package/lib/adapters/postgres/src/migrator/csv.js +72 -0
- package/lib/adapters/postgres/src/migrator/migration.d.ts +2 -18
- package/lib/adapters/postgres/src/migrator/migration.js +10 -158
- package/lib/adapters/postgres/src/migrator/migrator.js +8 -5
- package/lib/adapters/postgres/src/migrator/runner.d.ts +16 -6
- package/lib/adapters/postgres/src/migrator/runner.js +103 -34
- package/lib/adapters/postgres/src/postgres.bucket_adapter.d.ts +19 -22
- package/lib/adapters/postgres/src/postgres.bucket_adapter.js +116 -100
- package/lib/adapters/postgres/src/postgres.cli.d.ts +23 -3
- package/lib/adapters/postgres/src/postgres.cli.js +70 -10
- package/lib/adapters/postgres/src/postgres.config.d.ts +5 -0
- package/lib/adapters/postgres/src/postgres.config.js +2 -0
- package/lib/adapters/postgres/src/postgres.nql.d.ts +7 -3
- package/lib/adapters/postgres/src/postgres.nql.js +86 -32
- package/lib/adapters/postgres/src/postgres.provider.d.ts +18 -0
- package/lib/adapters/postgres/src/postgres.provider.js +77 -0
- package/lib/adapters/postgres/test/postgres.bucket_adapter.test.js +76 -39
- package/lib/compiler/apps/monolyth/monolyth_compiler.d.ts +3 -0
- package/lib/compiler/apps/monolyth/monolyth_compiler.js +24 -0
- package/lib/compiler/apps/monolyth/stages/2_build_typescript_stage.js +2 -1
- package/lib/compiler/apps/monolyth/stages/5_dump_cli_stage.js +1 -1
- package/lib/compiler/elements/bucket.element.js +26 -11
- package/lib/compiler/elements/constants.element.js +1 -1
- package/lib/compiler/elements/element.d.ts +2 -0
- package/lib/compiler/elements/message.element.js +4 -4
- package/lib/compiler/helpers/dump_helpers.js +5 -2
- package/lib/compiler/stages/7_dump_stage.js +2 -0
- package/lib/compiler/treeshake.js +9 -37
- package/lib/compiler/typescript/bridge/extract.js +12 -0
- package/lib/compiler/typescript/bridge/inject.js +3 -0
- package/lib/compiler/typescript/bridge/organize.js +3 -3
- package/lib/elements/blocks/block.builder.js +4 -2
- package/lib/elements/blocks/job/internal/resource_job.builder.d.ts +22 -20
- package/lib/elements/blocks/job/internal/resource_job.d.ts +2 -1
- package/lib/elements/blocks/job/internal/resource_job.js +17 -4
- package/lib/elements/blocks/job/job.js +3 -0
- package/lib/elements/blocks/job/job.types.d.ts +7 -0
- package/lib/elements/blocks/job/job.types.js +2 -0
- package/lib/elements/blocks/machine/machine.js +3 -2
- package/lib/elements/blocks/resource/resource.builder.js +2 -4
- package/lib/elements/blocks/resource/resource.d.ts +5 -3
- package/lib/elements/blocks/resource/resource.js +26 -17
- package/lib/elements/edge/controller/adapters/controller_adapter.d.ts +2 -1
- package/lib/elements/edge/controller/adapters/controller_adapter.js +11 -2
- package/lib/elements/edge/controller/controller.builder.d.ts +4 -5
- package/lib/elements/edge/controller/controller.builder.js +7 -7
- package/lib/elements/edge/controller/controller.d.ts +2 -1
- package/lib/elements/edge/controller/controller.js +8 -6
- package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +61 -23
- package/lib/elements/entities/bucket/adapters/bucket_adapter.js +22 -13
- package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.d.ts +21 -22
- package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.js +68 -2
- package/lib/elements/entities/bucket/adapters/memory.nql.d.ts +10 -6
- package/lib/elements/entities/bucket/adapters/memory.nql.js +38 -3
- package/lib/elements/entities/bucket/adapters/slow_memory.bucket_adapter.d.ts +0 -20
- package/lib/elements/entities/bucket/adapters/slow_memory.bucket_adapter.js +46 -30
- package/lib/elements/entities/bucket/bucket.builder.d.ts +8 -2
- package/lib/elements/entities/bucket/bucket.builder.js +13 -19
- package/lib/elements/entities/bucket/bucket.config.d.ts +5 -1
- package/lib/elements/entities/bucket/bucket.d.ts +180 -19
- package/lib/elements/entities/bucket/bucket.js +658 -48
- package/lib/elements/entities/bucket/bucket.schema.d.ts +7 -1
- package/lib/elements/entities/bucket/bucket.schema.js +2 -1
- package/lib/elements/entities/bucket/bucket.types.d.ts +2 -7
- package/lib/elements/entities/bucket/cache/bucket_cache.d.ts +6 -2
- package/lib/elements/entities/bucket/cache/bucket_cache.js +12 -12
- package/lib/elements/entities/bucket/graph/bucket_graph.d.ts +32 -5
- package/lib/elements/entities/bucket/graph/bucket_graph.js +80 -111
- package/lib/elements/entities/bucket/graph/bucket_graph.schema.d.ts +3 -6
- package/lib/elements/entities/bucket/graph/bucket_graph.schema.js +1 -4
- package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.d.ts +3 -7
- package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.js +6 -2
- package/lib/elements/entities/bucket/model/bucket_model.builder.js +1 -1
- package/lib/elements/entities/bucket/model/bucket_model.convert.js +3 -3
- package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +37 -8
- package/lib/elements/entities/bucket/model/bucket_model.schema.js +25 -4
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +33 -14
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +56 -13
- package/lib/elements/entities/bucket/query/nql.schema.d.ts +1 -0
- package/lib/elements/entities/bucket/query/nql_compiler.js +13 -2
- package/lib/elements/entities/bucket/query/nql_engine.d.ts +11 -4
- package/lib/elements/entities/bucket/query/nql_engine.js +20 -11
- package/lib/elements/entities/bucket/view/bucket_view.js +63 -35
- package/lib/elements/entities/bucket/view/bucket_view.schema.d.ts +5 -2
- package/lib/elements/entities/bucket/view/bucket_view_field.builder.d.ts +6 -2
- package/lib/elements/entities/bucket/view/bucket_view_field.builder.js +21 -15
- package/lib/elements/entities/constants/constants.schema.d.ts +1 -1
- package/lib/elements/entities/drive/drive_adapter.d.ts +36 -0
- package/lib/elements/entities/drive/drive_adapter.js +10 -0
- package/lib/elements/entities/drive/local.drive_adapter.d.ts +8 -0
- package/lib/elements/entities/drive/local.drive_adapter.js +28 -0
- package/lib/elements/entities/message/message.schema.d.ts +1 -0
- package/lib/elements/entities/message/message.schema.js +33 -0
- package/lib/elements/entities/message/message_parser.d.ts +5 -1
- package/lib/elements/entities/message/message_parser.js +56 -35
- package/lib/elements/entities/message/template/message_template.schema.d.ts +10 -8
- package/lib/elements/entities/message/template/message_template_field.builder.d.ts +16 -6
- package/lib/elements/entities/message/template/message_template_field.builder.js +25 -0
- package/lib/elements/entities/message/template/message_template_parser.js +2 -1
- package/lib/engine/apps/app.config.d.ts +32 -11
- package/lib/engine/apps/app.config.js +12 -0
- package/lib/engine/apps/app.d.ts +2 -0
- package/lib/engine/apps/app.js +3 -0
- package/lib/engine/apps/inline.app.d.ts +5 -3
- package/lib/engine/apps/inline.app.js +27 -12
- package/lib/engine/apps/monolyth/monolyth.app.d.ts +4 -2
- package/lib/engine/apps/monolyth/monolyth.app.js +22 -10
- package/lib/engine/auth/authn.d.ts +5 -1
- package/lib/engine/auth/zero.authn_provider.d.ts +4 -2
- package/lib/engine/auth/zero.authn_provider.js +2 -2
- package/lib/engine/cli/cli.d.ts +3 -1
- package/lib/engine/cli/cli.js +22 -3
- package/lib/engine/cli/cli_adapter.d.ts +2 -1
- package/lib/engine/cli/cli_adapter.js +2 -1
- package/lib/engine/cli/cli_input.d.ts +19 -0
- package/lib/engine/cli/cli_input.js +207 -0
- package/lib/engine/cli/ui.d.ts +1 -1
- package/lib/engine/cli/ui.js +2 -2
- package/lib/engine/daemon.d.ts +3 -2
- package/lib/engine/daemon.js +14 -2
- package/lib/engine/data/date.js +2 -2
- package/lib/engine/data/datetime.d.ts +40 -4
- package/lib/engine/data/datetime.js +70 -11
- package/lib/engine/data/decimal.d.ts +1 -1
- package/lib/engine/data/decimal.js +3 -3
- package/lib/engine/data/error.d.ts +21 -4
- package/lib/engine/data/error.js +23 -7
- package/lib/engine/data/file.d.ts +23 -0
- package/lib/engine/data/file.js +53 -0
- package/lib/engine/data/json.d.ts +6 -0
- package/lib/engine/data/json.js +26 -0
- package/lib/engine/data/obj.d.ts +1 -1
- package/lib/engine/data/trash.d.ts +14 -0
- package/lib/engine/data/trash.js +2 -0
- package/lib/engine/data/tree.d.ts +7 -12
- package/lib/engine/data/tree.js +101 -49
- package/lib/engine/module.d.ts +2 -1
- package/lib/engine/module.js +2 -5
- package/lib/engine/space.d.ts +1 -0
- package/lib/engine/space.js +6 -0
- package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +156 -24
- package/lib/engine/transaction/nodes/bucket.trx_node.js +297 -467
- package/lib/engine/transaction/nodes/bucket_query.trx_node.d.ts +4 -2
- package/lib/engine/transaction/nodes/bucket_query.trx_node.js +27 -15
- package/lib/engine/transaction/nodes/job.trx_node.d.ts +2 -1
- package/lib/engine/transaction/nodes/job.trx_node.js +6 -0
- package/lib/engine/transaction/trx.d.ts +5 -2
- package/lib/engine/transaction/trx.js +2 -2
- package/lib/engine/transaction/trx_engine.config.d.ts +1 -3
- package/lib/engine/transaction/trx_engine.d.ts +2 -2
- package/lib/engine/transaction/trx_engine.js +14 -11
- package/lib/engine/transaction/trx_node.d.ts +14 -4
- package/lib/engine/transaction/trx_node.js +50 -8
- package/lib/engine/tree.d.ts +1 -1
- package/lib/engine/util/crypto.d.ts +50 -0
- package/lib/engine/util/crypto.js +89 -0
- package/lib/engine/util/deep.d.ts +5 -0
- package/lib/engine/util/deep.js +46 -0
- package/lib/engine/util/dotenv.d.ts +2 -8
- package/lib/engine/util/dotenv.js +14 -36
- package/lib/engine/util/hash.d.ts +3 -0
- package/lib/engine/util/hash.js +23 -0
- package/lib/engine/util/log.js +1 -1
- package/lib/engine/util/mime.d.ts +10 -0
- package/lib/engine/util/mime.js +389 -0
- package/lib/engine/util/parse.d.ts +6 -5
- package/lib/engine/util/parse.js +16 -15
- package/lib/engine/util/path.d.ts +3 -0
- package/lib/engine/util/path.js +92 -0
- package/lib/engine/util/rules.d.ts +4 -0
- package/lib/engine/util/rules.js +12 -0
- package/package.json +1 -1
- package/tools/compile.js +2 -2
- package/tools/dotenv.d.ts +1 -0
- package/tools/dotenv.js +4 -0
- package/tools/joaquin/job.d.ts +5 -5
- package/tools/joaquin/mock.d.ts +23 -2
- package/tools/joaquin/mock.js +127 -21
- package/tsconfig.build.tsbuildinfo +1 -1
- package/lib/adapters/postgres/test/postgres.bucket_query.test.d.ts +0 -0
- package/lib/adapters/postgres/test/postgres.bucket_query.test.js +0 -136
|
@@ -1,522 +1,352 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BucketTrxNode = void 0;
|
|
4
|
-
const error_1 = require("../../data/error");
|
|
3
|
+
exports.BucketUnsafeTrxNode = exports.BucketTrxNode = void 0;
|
|
5
4
|
const trx_node_1 = require("../trx_node");
|
|
6
5
|
const bucket_query_trx_node_1 = require("./bucket_query.trx_node");
|
|
7
6
|
class BucketTrxNode {
|
|
8
7
|
constructor(parentTrx, bucket) {
|
|
9
8
|
this.parentTrx = parentTrx;
|
|
10
9
|
this.bucket = bucket;
|
|
10
|
+
this.enableTenancy = true;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/*
|
|
13
|
+
Modifiers
|
|
14
|
+
*/
|
|
15
|
+
get no_tenancy() {
|
|
16
|
+
this.enableTenancy = false;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
/*
|
|
20
|
+
Wrap
|
|
21
|
+
*/
|
|
22
|
+
async wrap(action, input, fn, fmtTrxOut) {
|
|
14
23
|
const trx = trx_node_1.TrxNode.makeChildNode(this.parentTrx, this.bucket.schema.module, 'bucket', this.bucket.schema.name);
|
|
15
|
-
await trx_node_1.TrxNode.open(trx,
|
|
16
|
-
let
|
|
24
|
+
await trx_node_1.TrxNode.open(trx, action, input);
|
|
25
|
+
let out;
|
|
17
26
|
try {
|
|
18
|
-
|
|
27
|
+
out = await fn(trx);
|
|
19
28
|
}
|
|
20
29
|
catch (e) {
|
|
21
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
30
|
+
await trx_node_1.TrxNode.error(trx, e);
|
|
22
31
|
throw e;
|
|
23
32
|
}
|
|
24
|
-
await trx_node_1.TrxNode.ok(trx,
|
|
25
|
-
return
|
|
33
|
+
await trx_node_1.TrxNode.ok(trx, fmtTrxOut ? fmtTrxOut(out) : out);
|
|
34
|
+
return out;
|
|
26
35
|
}
|
|
36
|
+
/*
|
|
37
|
+
Read/View One
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Returns one object by `id`, without pre-formatting,
|
|
41
|
+
* or `undefined` if the object was not found.
|
|
42
|
+
*/
|
|
43
|
+
async readOne(id) {
|
|
44
|
+
return this.wrap('readOne', { id }, trx => this.bucket.readOne(trx, id, {
|
|
45
|
+
silent: true,
|
|
46
|
+
no_tenancy: !this.enableTenancy
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns one object by `id` formated with the specified view,
|
|
51
|
+
* or `undefined` if the object was not found.
|
|
52
|
+
* - The formating process can impact performance. If you just need
|
|
53
|
+
* the raw obj, it's recommended to use `readOne` instead.
|
|
54
|
+
*/
|
|
27
55
|
async viewOne(id, view = 'default') {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
obj = await this.bucket.viewOne(trx, id, view);
|
|
33
|
-
}
|
|
34
|
-
catch (e) {
|
|
35
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
36
|
-
throw e;
|
|
37
|
-
}
|
|
38
|
-
await trx_node_1.TrxNode.ok(trx, obj);
|
|
39
|
-
return obj;
|
|
56
|
+
return this.wrap('viewOne', { id }, trx => this.bucket.viewOne(trx, id, view, {
|
|
57
|
+
silent: true,
|
|
58
|
+
no_tenancy: !this.enableTenancy
|
|
59
|
+
}));
|
|
40
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns one object by `id`, without pre-formatting,
|
|
63
|
+
* or **throws an exception** if the object was not found.
|
|
64
|
+
*/
|
|
41
65
|
async readOneOrFail(id) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
obj = await this.bucket.readOne(trx, id);
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
50
|
-
throw e;
|
|
51
|
-
}
|
|
52
|
-
if (!obj) {
|
|
53
|
-
const e = error_1.NesoiError.Bucket.ObjNotFound({ bucket: this.bucket.schema.alias, id: id });
|
|
54
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
55
|
-
throw e;
|
|
56
|
-
}
|
|
57
|
-
await trx_node_1.TrxNode.ok(trx, obj);
|
|
58
|
-
return obj;
|
|
66
|
+
return this.wrap('readOneOrFail', { id }, trx => this.bucket.readOne(trx, id, {
|
|
67
|
+
no_tenancy: !this.enableTenancy
|
|
68
|
+
}));
|
|
59
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns one object by `id`, without pre-formatting,
|
|
72
|
+
* or **throws an exception** if the object was not found.
|
|
73
|
+
* - The formating process can impact performance. If you just need
|
|
74
|
+
* the raw obj, it's recommended to use `readOneOrFail` instead.
|
|
75
|
+
*/
|
|
60
76
|
async viewOneOrFail(id, view = 'default') {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
obj = await this.bucket.viewOne(trx, id, view);
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
69
|
-
throw e;
|
|
70
|
-
}
|
|
71
|
-
if (!obj) {
|
|
72
|
-
const e = error_1.NesoiError.Bucket.ObjNotFound({ bucket: this.bucket.schema.alias, id: id });
|
|
73
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
74
|
-
throw e;
|
|
75
|
-
}
|
|
76
|
-
await trx_node_1.TrxNode.ok(trx, obj);
|
|
77
|
-
return obj;
|
|
77
|
+
return this.wrap('viewOneOrFail', { id }, trx => this.bucket.viewOne(trx, id, view, {
|
|
78
|
+
no_tenancy: !this.enableTenancy
|
|
79
|
+
}));
|
|
78
80
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
throw e;
|
|
90
|
-
}
|
|
91
|
-
await trx_node_1.TrxNode.ok(trx, { length: objs.length });
|
|
92
|
-
return objs;
|
|
81
|
+
/*
|
|
82
|
+
Read/View All
|
|
83
|
+
*/
|
|
84
|
+
/**
|
|
85
|
+
* Returns a list of all objects, without pre-formatting.
|
|
86
|
+
*/
|
|
87
|
+
async readAll() {
|
|
88
|
+
return this.wrap('readAll', {}, trx => this.bucket.readAll(trx, {
|
|
89
|
+
no_tenancy: !this.enableTenancy
|
|
90
|
+
}), objs => ({ length: objs.length }));
|
|
93
91
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
throw e;
|
|
104
|
-
}
|
|
105
|
-
await trx_node_1.TrxNode.ok(trx, { length: objs.length });
|
|
106
|
-
return objs;
|
|
92
|
+
/**
|
|
93
|
+
* Returns a list of all objects formated with the specified view.
|
|
94
|
+
* - The formating process can impact performance. If you just need
|
|
95
|
+
* the raw obj, it's recommended to use `readAll` instead.
|
|
96
|
+
*/
|
|
97
|
+
async viewAll(view = 'default') {
|
|
98
|
+
return this.wrap('viewAll', {}, trx => this.bucket.viewAll(trx, view, {
|
|
99
|
+
no_tenancy: !this.enableTenancy
|
|
100
|
+
}), objs => ({ length: objs.length }));
|
|
107
101
|
}
|
|
108
|
-
|
|
102
|
+
/*
|
|
103
|
+
Query
|
|
104
|
+
*/
|
|
105
|
+
/**
|
|
106
|
+
* Returns a list containing the results of the query.
|
|
107
|
+
*/
|
|
109
108
|
query(query, view = 'default') {
|
|
110
109
|
const trx = trx_node_1.TrxNode.makeChildNode(this.parentTrx, this.bucket.schema.module, 'bucket', this.bucket.schema.name);
|
|
111
|
-
return new bucket_query_trx_node_1.BucketQueryTrxNode(trx, this.bucket, query, view);
|
|
110
|
+
return new bucket_query_trx_node_1.BucketQueryTrxNode(trx, this.bucket, query, view, this.enableTenancy);
|
|
112
111
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
return undefined;
|
|
127
|
-
}
|
|
128
|
-
linkObj = await this.bucket.graph.readLink(trx, link, obj, view);
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
132
|
-
throw e;
|
|
133
|
-
}
|
|
134
|
-
await trx_node_1.TrxNode.ok(trx, linkObj);
|
|
135
|
-
return linkObj;
|
|
112
|
+
/*
|
|
113
|
+
Graph
|
|
114
|
+
*/
|
|
115
|
+
/**
|
|
116
|
+
* Returns one or more objects referenced by the graph link,
|
|
117
|
+
* or `undefined` if the graph link doesn't resolve.
|
|
118
|
+
*/
|
|
119
|
+
async readLink(id, link) {
|
|
120
|
+
return this.wrap('readLink', { id, link }, trx => this.bucket.readLink(trx, id, link, {
|
|
121
|
+
silent: true,
|
|
122
|
+
no_tenancy: !this.enableTenancy
|
|
123
|
+
}));
|
|
136
124
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
147
|
-
throw e;
|
|
148
|
-
}
|
|
149
|
-
linkObj = await this.bucket.graph.readLink(trx, link, obj, view);
|
|
150
|
-
if (!linkObj) {
|
|
151
|
-
const e = error_1.NesoiError.Bucket.Graph.LinkNotFound({ bucket: this.bucket.schema.alias, link: link });
|
|
152
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
153
|
-
throw e;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
catch (e) {
|
|
157
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
158
|
-
throw e;
|
|
159
|
-
}
|
|
160
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
161
|
-
return linkObj;
|
|
125
|
+
/**
|
|
126
|
+
* Returns one or more objects referenced by the graph link built with a view,
|
|
127
|
+
* or `undefined` if the graph link doesn't resolve.
|
|
128
|
+
*/
|
|
129
|
+
async viewLink(id, link, view = 'default') {
|
|
130
|
+
return this.wrap('viewLink', { id, link, view }, trx => this.bucket.viewLink(trx, id, link, view, {
|
|
131
|
+
silent: true,
|
|
132
|
+
no_tenancy: !this.enableTenancy
|
|
133
|
+
}));
|
|
162
134
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return undefined;
|
|
172
|
-
}
|
|
173
|
-
result = await this.bucket.graph.hasLink(trx, id, obj);
|
|
174
|
-
}
|
|
175
|
-
catch (e) {
|
|
176
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
177
|
-
throw e;
|
|
178
|
-
}
|
|
179
|
-
await trx_node_1.TrxNode.ok(trx, { result });
|
|
180
|
-
return result;
|
|
135
|
+
/**
|
|
136
|
+
* Returns one or more objects referenced by the graph link,
|
|
137
|
+
* or **throws an exception** if the graph link doesn't resolve.
|
|
138
|
+
*/
|
|
139
|
+
async readLinkOrFail(id, link) {
|
|
140
|
+
return this.wrap('readLinkOrFail', { id, link }, trx => this.bucket.readLink(trx, id, link, {
|
|
141
|
+
no_tenancy: !this.enableTenancy
|
|
142
|
+
}));
|
|
181
143
|
}
|
|
182
|
-
// Put / Create / Update
|
|
183
144
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* id is passed.
|
|
145
|
+
* Returns one or more objects referenced by the graph link built with a view,
|
|
146
|
+
* or **throws an exception** if the graph link doesn't resolve.
|
|
187
147
|
*/
|
|
188
|
-
async
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return _obj;
|
|
148
|
+
async viewLinkOrFail(id, link, view = 'default') {
|
|
149
|
+
return this.wrap('viewLinkOrFail', { id, link, view }, trx => this.bucket.viewLink(trx, id, link, view, {
|
|
150
|
+
no_tenancy: !this.enableTenancy
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns `true` if the graph link resolves to at least 1 object.
|
|
155
|
+
*/
|
|
156
|
+
async hasLink(id, link) {
|
|
157
|
+
return this.wrap('hasLink', { id, link }, trx => this.bucket.hasLink(trx, id, link, {
|
|
158
|
+
no_tenancy: !this.enableTenancy
|
|
159
|
+
}));
|
|
201
160
|
}
|
|
161
|
+
/*
|
|
162
|
+
Create
|
|
163
|
+
*/
|
|
202
164
|
/**
|
|
203
|
-
* Creates an object by passing it to the bucket adapter
|
|
204
|
-
*
|
|
205
|
-
*
|
|
165
|
+
* Creates an object by passing it to the bucket adapter.
|
|
166
|
+
* Also creates the compositions of this bucket, from the
|
|
167
|
+
* `#composition` field passed in the message.
|
|
168
|
+
*
|
|
169
|
+
* - If `#composition` is wrong, this will throw an exception
|
|
206
170
|
*/
|
|
207
171
|
async create(obj) {
|
|
208
|
-
|
|
209
|
-
const trx = trx_node_1.TrxNode.makeChildNode(this.parentTrx, this.bucket.schema.module, 'bucket', this.bucket.schema.name);
|
|
210
|
-
await trx_node_1.TrxNode.open(trx, 'create', { obj });
|
|
211
|
-
const composition = obj['#composition'] || {};
|
|
212
|
-
delete obj['#composition'];
|
|
213
|
-
const input = Object.assign({}, this.bucket.schema.model.defaults, obj);
|
|
214
|
-
let _obj;
|
|
215
|
-
try {
|
|
216
|
-
_obj = await this.bucket.put(trx, input);
|
|
217
|
-
// Composition
|
|
218
|
-
for (const link of Object.values(this.bucket.schema.graph.links)) {
|
|
219
|
-
if (link.rel !== 'composition')
|
|
220
|
-
continue;
|
|
221
|
-
const linkObj = composition[link.name];
|
|
222
|
-
if (!linkObj) {
|
|
223
|
-
const e = error_1.NesoiError.Bucket.MissingComposition({ method: 'create', bucket: this.bucket.schema.name, link: link.name });
|
|
224
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
225
|
-
throw e;
|
|
226
|
-
}
|
|
227
|
-
if (link.many) {
|
|
228
|
-
if (!Array.isArray(linkObj)) {
|
|
229
|
-
const e = error_1.NesoiError.Bucket.CompositionValueShouldBeArray({ method: 'create', bucket: this.bucket.schema.name, link: link.name });
|
|
230
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
231
|
-
throw e;
|
|
232
|
-
}
|
|
233
|
-
for (const linkObjItem of linkObj) {
|
|
234
|
-
await trx.bucket(link.bucket.refName).create(linkObjItem);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
await trx.bucket(link.bucket.refName).create(linkObj);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
catch (e) {
|
|
243
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
244
|
-
throw e;
|
|
245
|
-
}
|
|
246
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
247
|
-
return _obj;
|
|
172
|
+
return this.wrap('create', { obj }, trx => this.bucket.create(trx, obj), () => undefined);
|
|
248
173
|
}
|
|
174
|
+
/*
|
|
175
|
+
Update (Patch, Replace)
|
|
176
|
+
*/
|
|
249
177
|
/**
|
|
250
|
-
* Reads
|
|
251
|
-
*
|
|
252
|
-
*
|
|
178
|
+
* Reads one object by `id` and `patch` (modify) it based on the one passed as an argument.
|
|
179
|
+
* Also patches the compositions of this bucket, from the
|
|
180
|
+
* `#composition` field passed in the message.
|
|
181
|
+
*
|
|
182
|
+
* - If the object is not found, this will throw an exception
|
|
183
|
+
* - If `#composition` is wrong, this will throw an exception
|
|
184
|
+
* - The read query before updating might impact performance and be unnecessary
|
|
185
|
+
* when you're updating from code that's sure the object exists. In that case,
|
|
186
|
+
* you can use `unsafe.patch`, which doesn't read prior to writing.
|
|
187
|
+
*/
|
|
188
|
+
async patch(obj) {
|
|
189
|
+
return this.wrap('patch', { obj }, trx => this.bucket.update(trx, obj, {
|
|
190
|
+
mode: 'patch',
|
|
191
|
+
no_tenancy: !this.enableTenancy
|
|
192
|
+
}), () => undefined);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Reads one object by `id` and `replace` it with the one passed as an argument.
|
|
196
|
+
* Also patches the compositions of this bucket, from the
|
|
197
|
+
* `#composition` field passed in the message.
|
|
198
|
+
*
|
|
199
|
+
* - If the object is not found, this will throw an exception
|
|
200
|
+
* - If `#composition` is wrong, this will throw an exception
|
|
201
|
+
* - The read query before updating might impact performance and be unnecessary
|
|
202
|
+
* when you're updating from code that's sure the object exists. In that case,
|
|
203
|
+
* you can use `unsafe.replace`, which doesn't read prior to writing.
|
|
253
204
|
*/
|
|
254
205
|
async replace(obj) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
let newObj;
|
|
260
|
-
try {
|
|
261
|
-
const oldObj = await this.bucket.readOne(trx, obj['id']);
|
|
262
|
-
if (!oldObj) {
|
|
263
|
-
const e = error_1.NesoiError.Bucket.ObjNotFound({ bucket: this.bucket.schema.alias, id: obj['id'] });
|
|
264
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
265
|
-
throw e;
|
|
266
|
-
}
|
|
267
|
-
newObj = await this.bucket.put(trx, obj);
|
|
268
|
-
// Composition
|
|
269
|
-
for (const link of Object.values(this.bucket.schema.graph.links)) {
|
|
270
|
-
if (link.rel !== 'composition')
|
|
271
|
-
continue;
|
|
272
|
-
const linkObj = composition[link.name];
|
|
273
|
-
if (!linkObj) {
|
|
274
|
-
const e = error_1.NesoiError.Bucket.MissingComposition({ method: 'replace', bucket: this.bucket.schema.name, link: link.name });
|
|
275
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
276
|
-
throw e;
|
|
277
|
-
}
|
|
278
|
-
if (link.many) {
|
|
279
|
-
if (!Array.isArray(linkObj)) {
|
|
280
|
-
const e = error_1.NesoiError.Bucket.CompositionValueShouldBeArray({ method: 'replace', bucket: this.bucket.schema.name, link: link.name });
|
|
281
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
282
|
-
throw e;
|
|
283
|
-
}
|
|
284
|
-
for (const linkObjItem of linkObj) {
|
|
285
|
-
await trx.bucket(link.bucket.refName).replace(linkObjItem);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
await trx.bucket(link.bucket.refName).replace(linkObj);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
catch (e) {
|
|
294
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
295
|
-
throw e;
|
|
296
|
-
}
|
|
297
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
298
|
-
return newObj;
|
|
206
|
+
return this.wrap('replace', { obj }, trx => this.bucket.update(trx, obj, {
|
|
207
|
+
mode: 'replace',
|
|
208
|
+
no_tenancy: !this.enableTenancy
|
|
209
|
+
}), () => undefined);
|
|
299
210
|
}
|
|
211
|
+
/*
|
|
212
|
+
Put
|
|
213
|
+
*/
|
|
300
214
|
/**
|
|
301
|
-
*
|
|
302
|
-
*
|
|
215
|
+
* Creates or replaces (by `id`) the object passed as an argument.
|
|
216
|
+
* Does the same for compositions of this bucket, from the
|
|
217
|
+
* `#composition` field passed in the message.
|
|
218
|
+
*
|
|
219
|
+
* - If `#composition` is wrong, this will throw an exception.
|
|
220
|
+
* - This will **REPLACE** objects and it's compositions if they already exist,
|
|
221
|
+
* so there might be unexpected data loss, use it carefully.
|
|
222
|
+
*
|
|
223
|
+
* **WARNING** Tenancy currently not implemented for put.
|
|
303
224
|
*/
|
|
304
|
-
async
|
|
305
|
-
|
|
306
|
-
await trx_node_1.TrxNode.open(trx, 'patch', { obj });
|
|
307
|
-
const composition = obj['#composition'] || {};
|
|
308
|
-
delete obj['#composition'];
|
|
309
|
-
let newObj;
|
|
310
|
-
try {
|
|
311
|
-
const oldObj = await this.bucket.readOne(trx, obj['id']);
|
|
312
|
-
if (!oldObj) {
|
|
313
|
-
const e = error_1.NesoiError.Bucket.ObjNotFound({ bucket: this.bucket.schema.alias, id: obj['id'] });
|
|
314
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
315
|
-
throw e;
|
|
316
|
-
}
|
|
317
|
-
// TODO: deep merge
|
|
318
|
-
const putObj = Object.assign({}, oldObj, obj);
|
|
319
|
-
newObj = await this.bucket.put(trx, putObj);
|
|
320
|
-
// Composition
|
|
321
|
-
for (const link of Object.values(this.bucket.schema.graph.links)) {
|
|
322
|
-
if (link.rel !== 'composition')
|
|
323
|
-
continue;
|
|
324
|
-
const linkObj = composition[link.name];
|
|
325
|
-
if (!linkObj) {
|
|
326
|
-
const e = error_1.NesoiError.Bucket.MissingComposition({ method: 'patch', bucket: this.bucket.schema.name, link: link.name });
|
|
327
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
328
|
-
throw e;
|
|
329
|
-
}
|
|
330
|
-
if (link.many) {
|
|
331
|
-
if (!Array.isArray(linkObj)) {
|
|
332
|
-
const e = error_1.NesoiError.Bucket.CompositionValueShouldBeArray({ method: 'patch', bucket: this.bucket.schema.name, link: link.name });
|
|
333
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
334
|
-
throw e;
|
|
335
|
-
}
|
|
336
|
-
for (const linkObjItem of linkObj) {
|
|
337
|
-
await trx.bucket(link.bucket.refName).patch(linkObjItem);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
await trx.bucket(link.bucket.refName).patch(linkObj);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
catch (e) {
|
|
346
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
347
|
-
throw e;
|
|
348
|
-
}
|
|
349
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
350
|
-
return newObj;
|
|
225
|
+
async put(obj) {
|
|
226
|
+
return this.wrap('put', { obj }, trx => this.bucket.put(trx, obj), () => undefined);
|
|
351
227
|
}
|
|
352
|
-
|
|
228
|
+
/*
|
|
229
|
+
Delete
|
|
230
|
+
*/
|
|
231
|
+
/**
|
|
232
|
+
* Attempts to read an object by `id`, if found, deletes it.
|
|
233
|
+
*
|
|
234
|
+
* - If you want to skip the read query, use the `unsafe.delete` method,
|
|
235
|
+
* so the behavior depends on the bucket used.
|
|
236
|
+
*/
|
|
353
237
|
async delete(id) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
// Composition (with other key)
|
|
358
|
-
for (const link of Object.values(this.bucket.schema.graph.links)) {
|
|
359
|
-
if (link.rel !== 'composition')
|
|
360
|
-
continue;
|
|
361
|
-
if (link.keyOwner !== 'other')
|
|
362
|
-
continue;
|
|
363
|
-
const linked = await this.readLink(id, link.name);
|
|
364
|
-
if (link.many) {
|
|
365
|
-
for (const linkedItem of linked) {
|
|
366
|
-
await trx.bucket(link.bucket.refName).delete(linkedItem.id);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
else {
|
|
370
|
-
await trx.bucket(link.bucket.refName).delete(linked.id);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
// The object itself
|
|
374
|
-
await this.bucket.delete(trx, id);
|
|
375
|
-
// Composition (with self key)
|
|
376
|
-
for (const link of Object.values(this.bucket.schema.graph.links)) {
|
|
377
|
-
if (link.rel !== 'composition')
|
|
378
|
-
continue;
|
|
379
|
-
if (link.keyOwner !== 'self')
|
|
380
|
-
continue;
|
|
381
|
-
const linked = await this.readLink(id, link.name);
|
|
382
|
-
if (link.many) {
|
|
383
|
-
await trx.bucket(link.bucket.refName).deleteMany(linked.map((l) => l.id));
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
await trx.bucket(link.bucket.refName).delete(linked.id);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
catch (e) {
|
|
391
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
392
|
-
throw e;
|
|
393
|
-
}
|
|
394
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
238
|
+
return this.wrap('delete', { id }, trx => this.bucket.delete(trx, id, {
|
|
239
|
+
no_tenancy: !this.enableTenancy
|
|
240
|
+
}), () => undefined);
|
|
395
241
|
}
|
|
396
242
|
/**
|
|
397
|
-
*
|
|
243
|
+
* Attempts to read an object by `id`, if found, deletes it.
|
|
244
|
+
*
|
|
245
|
+
* - If you want to skip the read query, use the `unsafe.delete` method,
|
|
246
|
+
* so the behavior depends on the bucket used.
|
|
398
247
|
*/
|
|
399
248
|
async deleteMany(ids) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
// Composition (with other key)
|
|
404
|
-
for (const link of Object.values(this.bucket.schema.graph.links)) {
|
|
405
|
-
if (link.rel !== 'composition')
|
|
406
|
-
continue;
|
|
407
|
-
if (link.keyOwner !== 'other')
|
|
408
|
-
continue;
|
|
409
|
-
for (const id of ids) {
|
|
410
|
-
const linked = await this.readLink(id, link.name);
|
|
411
|
-
if (link.many) {
|
|
412
|
-
await trx.bucket(link.bucket.refName).deleteMany(linked.map((l) => l.id));
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
await trx.bucket(link.bucket.refName).delete(linked.id);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
await this.bucket.deleteMany(trx, ids);
|
|
420
|
-
// Composition (with self key)
|
|
421
|
-
for (const link of Object.values(this.bucket.schema.graph.links)) {
|
|
422
|
-
if (link.rel !== 'composition')
|
|
423
|
-
continue;
|
|
424
|
-
if (link.keyOwner !== 'self')
|
|
425
|
-
continue;
|
|
426
|
-
for (const id of ids) {
|
|
427
|
-
const linked = await this.readLink(id, link.name);
|
|
428
|
-
if (link.many) {
|
|
429
|
-
await trx.bucket(link.bucket.refName).deleteMany(linked.map((l) => l.id));
|
|
430
|
-
}
|
|
431
|
-
else {
|
|
432
|
-
await trx.bucket(link.bucket.refName).delete(linked.id);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
catch (e) {
|
|
438
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
439
|
-
throw e;
|
|
440
|
-
}
|
|
441
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
442
|
-
}
|
|
443
|
-
async deleteOrFail(id) {
|
|
444
|
-
const trx = trx_node_1.TrxNode.makeChildNode(this.parentTrx, this.bucket.schema.module, 'bucket', this.bucket.schema.name);
|
|
445
|
-
await trx_node_1.TrxNode.open(trx, 'deleteOrFail', { id });
|
|
446
|
-
try {
|
|
447
|
-
// Composition (with other key)
|
|
448
|
-
for (const link of Object.values(this.bucket.schema.graph.links)) {
|
|
449
|
-
if (link.rel !== 'composition')
|
|
450
|
-
continue;
|
|
451
|
-
if (link.keyOwner !== 'other')
|
|
452
|
-
continue;
|
|
453
|
-
const linked = await this.readLink(id, link.name);
|
|
454
|
-
if (link.many) {
|
|
455
|
-
for (const linkedItem of linked) {
|
|
456
|
-
await trx.bucket(link.bucket.refName).deleteOrFail(linkedItem.id);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
else {
|
|
460
|
-
await trx.bucket(link.bucket.refName).deleteOrFail(linked.id);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
const obj = await this.bucket.readOne(trx, id);
|
|
464
|
-
if (!obj) {
|
|
465
|
-
const e = error_1.NesoiError.Bucket.ObjNotFound({ bucket: this.bucket.schema.alias, id: id });
|
|
466
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
467
|
-
throw e;
|
|
468
|
-
}
|
|
469
|
-
await this.bucket.delete(trx, id);
|
|
470
|
-
// Composition (with self key)
|
|
471
|
-
for (const link of Object.values(this.bucket.schema.graph.links)) {
|
|
472
|
-
if (link.rel !== 'composition')
|
|
473
|
-
continue;
|
|
474
|
-
if (link.keyOwner !== 'self')
|
|
475
|
-
continue;
|
|
476
|
-
const linked = await this.readLink(id, link.name);
|
|
477
|
-
if (link.many) {
|
|
478
|
-
for (const linkedItem of linked) {
|
|
479
|
-
await trx.bucket(link.bucket.refName).deleteOrFail(linkedItem.id);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
else {
|
|
483
|
-
await trx.bucket(link.bucket.refName).deleteOrFail(linked.id);
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
catch (e) {
|
|
488
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
489
|
-
throw e;
|
|
490
|
-
}
|
|
491
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
249
|
+
return this.wrap('deleteMany', { ids }, trx => this.bucket.deleteMany(trx, ids, {
|
|
250
|
+
no_tenancy: !this.enableTenancy
|
|
251
|
+
}), () => undefined);
|
|
492
252
|
}
|
|
253
|
+
/*
|
|
254
|
+
Build
|
|
255
|
+
*/
|
|
493
256
|
async buildOne(obj, view) {
|
|
494
|
-
|
|
495
|
-
await trx_node_1.TrxNode.open(trx, 'buildOne', { obj });
|
|
496
|
-
let result;
|
|
497
|
-
try {
|
|
498
|
-
result = await this.bucket.buildOne(trx, obj, view);
|
|
499
|
-
}
|
|
500
|
-
catch (e) {
|
|
501
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
502
|
-
throw e;
|
|
503
|
-
}
|
|
504
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
505
|
-
return result;
|
|
257
|
+
return this.wrap('buildOne', { obj }, trx => this.bucket.buildOne(trx, obj, view), () => undefined);
|
|
506
258
|
}
|
|
507
|
-
async
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
259
|
+
async buildMany(objs, view) {
|
|
260
|
+
return this.wrap('buildMany', { objs }, trx => this.bucket.buildMany(trx, objs, view), () => undefined);
|
|
261
|
+
}
|
|
262
|
+
/*
|
|
263
|
+
Unsafe
|
|
264
|
+
*/
|
|
265
|
+
/**
|
|
266
|
+
* Unsafe versions of methods, which improve performance
|
|
267
|
+
* by avoiding some validations and queries.
|
|
268
|
+
*
|
|
269
|
+
* **Use it carefully.**
|
|
270
|
+
*/
|
|
271
|
+
get unsafe() {
|
|
272
|
+
return new BucketUnsafeTrxNode(this, this.bucket, this.enableTenancy);
|
|
520
273
|
}
|
|
521
274
|
}
|
|
522
275
|
exports.BucketTrxNode = BucketTrxNode;
|
|
276
|
+
class BucketUnsafeTrxNode {
|
|
277
|
+
constructor(bucketTrx, bucket, enableTenancy) {
|
|
278
|
+
this.bucketTrx = bucketTrx;
|
|
279
|
+
this.bucket = bucket;
|
|
280
|
+
this.enableTenancy = enableTenancy;
|
|
281
|
+
}
|
|
282
|
+
/*
|
|
283
|
+
Modifiers
|
|
284
|
+
*/
|
|
285
|
+
get no_tenancy() {
|
|
286
|
+
this.enableTenancy = false;
|
|
287
|
+
return this;
|
|
288
|
+
}
|
|
289
|
+
/*
|
|
290
|
+
Update (Patch, Replace)
|
|
291
|
+
*/
|
|
292
|
+
/**
|
|
293
|
+
* Directly `patch` (modify) an object based on the one passed as an argument.
|
|
294
|
+
* Also patches the compositions of this bucket, from the
|
|
295
|
+
* `#composition` field passed in the message.
|
|
296
|
+
*
|
|
297
|
+
* > This unsafe version does not check if the object exists prior to patching.
|
|
298
|
+
*
|
|
299
|
+
* - If the object is not found, this will throw an exception
|
|
300
|
+
* - If `#composition` is wrong, this will throw an exception
|
|
301
|
+
*/
|
|
302
|
+
async patch(obj) {
|
|
303
|
+
return this.bucketTrx.wrap('patch', { obj }, trx => this.bucket.update(trx, obj, {
|
|
304
|
+
mode: 'patch',
|
|
305
|
+
unsafe: true,
|
|
306
|
+
no_tenancy: !this.enableTenancy
|
|
307
|
+
}), () => undefined);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Directly `replace` on object with the one passed as an argument.
|
|
311
|
+
* Also replaces the compositions of this bucket, from the
|
|
312
|
+
* `#composition` field passed in the message.
|
|
313
|
+
*
|
|
314
|
+
* > This unsafe version does not check if the object exists prior to replacing.
|
|
315
|
+
*
|
|
316
|
+
* - If the object is not found, this will throw an exception
|
|
317
|
+
* - If `#composition` is wrong, this will throw an exception
|
|
318
|
+
*/
|
|
319
|
+
async replace(obj) {
|
|
320
|
+
return this.bucketTrx.wrap('replace', { obj }, trx => this.bucket.update(trx, obj, {
|
|
321
|
+
mode: 'replace',
|
|
322
|
+
unsafe: true,
|
|
323
|
+
no_tenancy: !this.enableTenancy
|
|
324
|
+
}), () => undefined);
|
|
325
|
+
}
|
|
326
|
+
/*
|
|
327
|
+
Delete
|
|
328
|
+
*/
|
|
329
|
+
/**
|
|
330
|
+
* Deletes an object
|
|
331
|
+
*
|
|
332
|
+
* > This unsafe version does not check if the object exists prior to deleting.
|
|
333
|
+
*/
|
|
334
|
+
async delete(id) {
|
|
335
|
+
return this.bucketTrx.wrap('delete', { id }, trx => this.bucket.delete(trx, id, {
|
|
336
|
+
unsafe: true,
|
|
337
|
+
no_tenancy: !this.enableTenancy
|
|
338
|
+
}), () => undefined);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Attempts to read an object by `id`, if found, deletes it.
|
|
342
|
+
*
|
|
343
|
+
* > This unsafe version does not check if the objects exist prior to deleting.
|
|
344
|
+
*/
|
|
345
|
+
async deleteMany(ids) {
|
|
346
|
+
return this.bucketTrx.wrap('deleteMany', { ids }, trx => this.bucket.deleteMany(trx, ids, {
|
|
347
|
+
unsafe: true,
|
|
348
|
+
no_tenancy: !this.enableTenancy
|
|
349
|
+
}), () => undefined);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
exports.BucketUnsafeTrxNode = BucketUnsafeTrxNode;
|