nesoi 3.0.0 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/apps/monolyth/stages/6_dump_package_json_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 +662 -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 +22 -16
- package/lib/elements/entities/constants/constants.schema.d.ts +1 -1
- package/lib/elements/entities/drive/drive_adapter.d.ts +44 -0
- package/lib/elements/entities/drive/drive_adapter.js +10 -0
- package/lib/elements/entities/drive/local.drive_adapter.d.ts +10 -0
- package/lib/elements/entities/drive/local.drive_adapter.js +34 -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 +38 -0
- package/lib/engine/data/file.js +54 -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 +184 -24
- package/lib/engine/transaction/nodes/bucket.trx_node.js +346 -451
- 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 +2 -2
- 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,417 @@
|
|
|
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.BucketDriveTrxNode = 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");
|
|
6
|
+
const error_1 = require("../../data/error");
|
|
7
7
|
class BucketTrxNode {
|
|
8
8
|
constructor(parentTrx, bucket) {
|
|
9
9
|
this.parentTrx = parentTrx;
|
|
10
10
|
this.bucket = bucket;
|
|
11
|
+
this.enableTenancy = true;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
/*
|
|
14
|
+
Modifiers
|
|
15
|
+
*/
|
|
16
|
+
get no_tenancy() {
|
|
17
|
+
this.enableTenancy = false;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
/*
|
|
21
|
+
Wrap
|
|
22
|
+
*/
|
|
23
|
+
async wrap(action, input, fn, fmtTrxOut) {
|
|
14
24
|
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
|
|
25
|
+
await trx_node_1.TrxNode.open(trx, action, input);
|
|
26
|
+
let out;
|
|
17
27
|
try {
|
|
18
|
-
|
|
28
|
+
out = await fn(trx);
|
|
19
29
|
}
|
|
20
30
|
catch (e) {
|
|
21
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
31
|
+
await trx_node_1.TrxNode.error(trx, e);
|
|
22
32
|
throw e;
|
|
23
33
|
}
|
|
24
|
-
await trx_node_1.TrxNode.ok(trx,
|
|
25
|
-
return
|
|
34
|
+
await trx_node_1.TrxNode.ok(trx, fmtTrxOut ? fmtTrxOut(out) : out);
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
/*
|
|
38
|
+
Read/View One
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Returns one object by `id`, without pre-formatting,
|
|
42
|
+
* or `undefined` if the object was not found.
|
|
43
|
+
*/
|
|
44
|
+
async readOne(id) {
|
|
45
|
+
return this.wrap('readOne', { id }, trx => this.bucket.readOne(trx, id, {
|
|
46
|
+
silent: true,
|
|
47
|
+
no_tenancy: !this.enableTenancy
|
|
48
|
+
}));
|
|
26
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns one object by `id` formated with the specified view,
|
|
52
|
+
* or `undefined` if the object was not found.
|
|
53
|
+
* - The formating process can impact performance. If you just need
|
|
54
|
+
* the raw obj, it's recommended to use `readOne` instead.
|
|
55
|
+
*/
|
|
27
56
|
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;
|
|
57
|
+
return this.wrap('viewOne', { id }, trx => this.bucket.viewOne(trx, id, view, {
|
|
58
|
+
silent: true,
|
|
59
|
+
no_tenancy: !this.enableTenancy
|
|
60
|
+
}));
|
|
40
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Returns one object by `id`, without pre-formatting,
|
|
64
|
+
* or **throws an exception** if the object was not found.
|
|
65
|
+
*/
|
|
41
66
|
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;
|
|
67
|
+
return this.wrap('readOneOrFail', { id }, trx => this.bucket.readOne(trx, id, {
|
|
68
|
+
no_tenancy: !this.enableTenancy
|
|
69
|
+
}));
|
|
59
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns one object by `id`, without pre-formatting,
|
|
73
|
+
* or **throws an exception** if the object was not found.
|
|
74
|
+
* - The formating process can impact performance. If you just need
|
|
75
|
+
* the raw obj, it's recommended to use `readOneOrFail` instead.
|
|
76
|
+
*/
|
|
60
77
|
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;
|
|
78
|
+
return this.wrap('viewOneOrFail', { id }, trx => this.bucket.viewOne(trx, id, view, {
|
|
79
|
+
no_tenancy: !this.enableTenancy
|
|
80
|
+
}));
|
|
78
81
|
}
|
|
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;
|
|
82
|
+
/*
|
|
83
|
+
Read/View All
|
|
84
|
+
*/
|
|
85
|
+
/**
|
|
86
|
+
* Returns a list of all objects, without pre-formatting.
|
|
87
|
+
*/
|
|
88
|
+
async readAll() {
|
|
89
|
+
return this.wrap('readAll', {}, trx => this.bucket.readAll(trx, {
|
|
90
|
+
no_tenancy: !this.enableTenancy
|
|
91
|
+
}), objs => ({ length: objs.length }));
|
|
93
92
|
}
|
|
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;
|
|
93
|
+
/**
|
|
94
|
+
* Returns a list of all objects formated with the specified view.
|
|
95
|
+
* - The formating process can impact performance. If you just need
|
|
96
|
+
* the raw obj, it's recommended to use `readAll` instead.
|
|
97
|
+
*/
|
|
98
|
+
async viewAll(view = 'default') {
|
|
99
|
+
return this.wrap('viewAll', {}, trx => this.bucket.viewAll(trx, view, {
|
|
100
|
+
no_tenancy: !this.enableTenancy
|
|
101
|
+
}), objs => ({ length: objs.length }));
|
|
107
102
|
}
|
|
108
|
-
|
|
103
|
+
/*
|
|
104
|
+
Query
|
|
105
|
+
*/
|
|
106
|
+
/**
|
|
107
|
+
* Returns a list containing the results of the query.
|
|
108
|
+
*/
|
|
109
109
|
query(query, view = 'default') {
|
|
110
110
|
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);
|
|
111
|
+
return new bucket_query_trx_node_1.BucketQueryTrxNode(trx, this.bucket, query, view, this.enableTenancy);
|
|
112
112
|
}
|
|
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;
|
|
113
|
+
/*
|
|
114
|
+
Graph
|
|
115
|
+
*/
|
|
116
|
+
/**
|
|
117
|
+
* Returns one or more objects referenced by the graph link,
|
|
118
|
+
* or `undefined` if the graph link doesn't resolve.
|
|
119
|
+
*/
|
|
120
|
+
async readLink(id, link) {
|
|
121
|
+
return this.wrap('readLink', { id, link }, trx => this.bucket.readLink(trx, id, link, {
|
|
122
|
+
silent: true,
|
|
123
|
+
no_tenancy: !this.enableTenancy
|
|
124
|
+
}));
|
|
136
125
|
}
|
|
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;
|
|
126
|
+
/**
|
|
127
|
+
* Returns one or more objects referenced by the graph link built with a view,
|
|
128
|
+
* or `undefined` if the graph link doesn't resolve.
|
|
129
|
+
*/
|
|
130
|
+
async viewLink(id, link, view = 'default') {
|
|
131
|
+
return this.wrap('viewLink', { id, link, view }, trx => this.bucket.viewLink(trx, id, link, view, {
|
|
132
|
+
silent: true,
|
|
133
|
+
no_tenancy: !this.enableTenancy
|
|
134
|
+
}));
|
|
162
135
|
}
|
|
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;
|
|
136
|
+
/**
|
|
137
|
+
* Returns one or more objects referenced by the graph link,
|
|
138
|
+
* or **throws an exception** if the graph link doesn't resolve.
|
|
139
|
+
*/
|
|
140
|
+
async readLinkOrFail(id, link) {
|
|
141
|
+
return this.wrap('readLinkOrFail', { id, link }, trx => this.bucket.readLink(trx, id, link, {
|
|
142
|
+
no_tenancy: !this.enableTenancy
|
|
143
|
+
}));
|
|
181
144
|
}
|
|
182
|
-
// Put / Create / Update
|
|
183
145
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* id is passed.
|
|
146
|
+
* Returns one or more objects referenced by the graph link built with a view,
|
|
147
|
+
* or **throws an exception** if the graph link doesn't resolve.
|
|
187
148
|
*/
|
|
188
|
-
async
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
try {
|
|
193
|
-
_obj = await this.bucket.put(trx, obj);
|
|
194
|
-
}
|
|
195
|
-
catch (e) {
|
|
196
|
-
await trx_node_1.TrxNode.error(trx, e); // Bucket unexpected error
|
|
197
|
-
throw e;
|
|
198
|
-
}
|
|
199
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
200
|
-
return _obj;
|
|
149
|
+
async viewLinkOrFail(id, link, view = 'default') {
|
|
150
|
+
return this.wrap('viewLinkOrFail', { id, link, view }, trx => this.bucket.viewLink(trx, id, link, view, {
|
|
151
|
+
no_tenancy: !this.enableTenancy
|
|
152
|
+
}));
|
|
201
153
|
}
|
|
202
154
|
/**
|
|
203
|
-
*
|
|
204
|
-
|
|
205
|
-
|
|
155
|
+
* Returns `true` if the graph link resolves to at least 1 object.
|
|
156
|
+
*/
|
|
157
|
+
async hasLink(id, link) {
|
|
158
|
+
return this.wrap('hasLink', { id, link }, trx => this.bucket.hasLink(trx, id, link, {
|
|
159
|
+
no_tenancy: !this.enableTenancy
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
/*
|
|
163
|
+
Create
|
|
164
|
+
*/
|
|
165
|
+
/**
|
|
166
|
+
* Creates an object by passing it to the bucket adapter.
|
|
167
|
+
* Also creates the compositions of this bucket, from the
|
|
168
|
+
* `#composition` field passed in the message.
|
|
169
|
+
*
|
|
170
|
+
* - If `#composition` is wrong, this will throw an exception
|
|
206
171
|
*/
|
|
207
172
|
async create(obj) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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;
|
|
173
|
+
return this.wrap('create', { obj }, trx => this.bucket.create(trx, obj), () => undefined);
|
|
174
|
+
}
|
|
175
|
+
/*
|
|
176
|
+
Update (Patch, Replace)
|
|
177
|
+
*/
|
|
178
|
+
/**
|
|
179
|
+
* Reads one object by `id` and `patch` (modify) it based on the one passed as an argument.
|
|
180
|
+
* Also patches the compositions of this bucket, from the
|
|
181
|
+
* `#composition` field passed in the message.
|
|
182
|
+
*
|
|
183
|
+
* - If the object is not found, this will throw an exception
|
|
184
|
+
* - If `#composition` is wrong, this will throw an exception
|
|
185
|
+
* - The read query before updating might impact performance and be unnecessary
|
|
186
|
+
* when you're updating from code that's sure the object exists. In that case,
|
|
187
|
+
* you can use `unsafe.patch`, which doesn't read prior to writing.
|
|
188
|
+
*/
|
|
189
|
+
async patch(obj) {
|
|
190
|
+
return this.wrap('patch', { obj }, trx => this.bucket.update(trx, obj, {
|
|
191
|
+
mode: 'patch',
|
|
192
|
+
no_tenancy: !this.enableTenancy
|
|
193
|
+
}), () => undefined);
|
|
248
194
|
}
|
|
249
195
|
/**
|
|
250
|
-
* Reads
|
|
251
|
-
*
|
|
252
|
-
*
|
|
196
|
+
* Reads one object by `id` and `replace` it with the one passed as an argument.
|
|
197
|
+
* Also patches the compositions of this bucket, from the
|
|
198
|
+
* `#composition` field passed in the message.
|
|
199
|
+
*
|
|
200
|
+
* - If the object is not found, this will throw an exception
|
|
201
|
+
* - If `#composition` is wrong, this will throw an exception
|
|
202
|
+
* - The read query before updating might impact performance and be unnecessary
|
|
203
|
+
* when you're updating from code that's sure the object exists. In that case,
|
|
204
|
+
* you can use `unsafe.replace`, which doesn't read prior to writing.
|
|
253
205
|
*/
|
|
254
206
|
async replace(obj) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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;
|
|
207
|
+
return this.wrap('replace', { obj }, trx => this.bucket.update(trx, obj, {
|
|
208
|
+
mode: 'replace',
|
|
209
|
+
no_tenancy: !this.enableTenancy
|
|
210
|
+
}), () => undefined);
|
|
211
|
+
}
|
|
212
|
+
/*
|
|
213
|
+
Put
|
|
214
|
+
*/
|
|
215
|
+
/**
|
|
216
|
+
* Creates or replaces (by `id`) the object passed as an argument.
|
|
217
|
+
* Does the same for compositions of this bucket, from the
|
|
218
|
+
* `#composition` field passed in the message.
|
|
219
|
+
*
|
|
220
|
+
* - If `#composition` is wrong, this will throw an exception.
|
|
221
|
+
* - This will **REPLACE** objects and it's compositions if they already exist,
|
|
222
|
+
* so there might be unexpected data loss, use it carefully.
|
|
223
|
+
*
|
|
224
|
+
* **WARNING** Tenancy currently not implemented for put.
|
|
225
|
+
*/
|
|
226
|
+
async put(obj) {
|
|
227
|
+
return this.wrap('put', { obj }, trx => this.bucket.put(trx, obj), () => undefined);
|
|
299
228
|
}
|
|
229
|
+
/*
|
|
230
|
+
Delete
|
|
231
|
+
*/
|
|
300
232
|
/**
|
|
301
|
-
*
|
|
302
|
-
*
|
|
233
|
+
* Attempts to read an object by `id`, if found, deletes it.
|
|
234
|
+
*
|
|
235
|
+
* - If you want to skip the read query, use the `unsafe.delete` method,
|
|
236
|
+
* so the behavior depends on the bucket used.
|
|
237
|
+
*/
|
|
238
|
+
async delete(id) {
|
|
239
|
+
return this.wrap('delete', { id }, trx => this.bucket.delete(trx, id, {
|
|
240
|
+
no_tenancy: !this.enableTenancy
|
|
241
|
+
}), () => undefined);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Attempts to read an object by `id`, if found, deletes it.
|
|
245
|
+
*
|
|
246
|
+
* - If you want to skip the read query, use the `unsafe.delete` method,
|
|
247
|
+
* so the behavior depends on the bucket used.
|
|
248
|
+
*/
|
|
249
|
+
async deleteMany(ids) {
|
|
250
|
+
return this.wrap('deleteMany', { ids }, trx => this.bucket.deleteMany(trx, ids, {
|
|
251
|
+
no_tenancy: !this.enableTenancy
|
|
252
|
+
}), () => undefined);
|
|
253
|
+
}
|
|
254
|
+
/*
|
|
255
|
+
Build
|
|
256
|
+
*/
|
|
257
|
+
async buildOne(obj, view) {
|
|
258
|
+
return this.wrap('buildOne', { obj }, trx => this.bucket.buildOne(trx, obj, view), () => undefined);
|
|
259
|
+
}
|
|
260
|
+
async buildMany(objs, view) {
|
|
261
|
+
return this.wrap('buildMany', { objs }, trx => this.bucket.buildMany(trx, objs, view), () => undefined);
|
|
262
|
+
}
|
|
263
|
+
/*
|
|
264
|
+
Drive
|
|
265
|
+
*/
|
|
266
|
+
/**
|
|
267
|
+
* Methods to use the Bucket's drive (file storage).
|
|
268
|
+
*/
|
|
269
|
+
get drive() {
|
|
270
|
+
return new BucketDriveTrxNode(this, this.bucket);
|
|
271
|
+
}
|
|
272
|
+
/*
|
|
273
|
+
Unsafe
|
|
274
|
+
*/
|
|
275
|
+
/**
|
|
276
|
+
* Unsafe versions of methods, which improve performance
|
|
277
|
+
* by avoiding some validations and queries.
|
|
278
|
+
*
|
|
279
|
+
* **Use it carefully.**
|
|
280
|
+
*/
|
|
281
|
+
get unsafe() {
|
|
282
|
+
return new BucketUnsafeTrxNode(this, this.bucket, this.enableTenancy);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
exports.BucketTrxNode = BucketTrxNode;
|
|
286
|
+
class BucketUnsafeTrxNode {
|
|
287
|
+
constructor(bucketTrx, bucket, enableTenancy) {
|
|
288
|
+
this.bucketTrx = bucketTrx;
|
|
289
|
+
this.bucket = bucket;
|
|
290
|
+
this.enableTenancy = enableTenancy;
|
|
291
|
+
}
|
|
292
|
+
/*
|
|
293
|
+
Modifiers
|
|
294
|
+
*/
|
|
295
|
+
get no_tenancy() {
|
|
296
|
+
this.enableTenancy = false;
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
299
|
+
/*
|
|
300
|
+
Update (Patch, Replace)
|
|
301
|
+
*/
|
|
302
|
+
/**
|
|
303
|
+
* Directly `patch` (modify) an object based on the one passed as an argument.
|
|
304
|
+
* Also patches the compositions of this bucket, from the
|
|
305
|
+
* `#composition` field passed in the message.
|
|
306
|
+
*
|
|
307
|
+
* > This unsafe version does not check if the object exists prior to patching.
|
|
308
|
+
*
|
|
309
|
+
* - If the object is not found, this will throw an exception
|
|
310
|
+
* - If `#composition` is wrong, this will throw an exception
|
|
303
311
|
*/
|
|
304
312
|
async patch(obj) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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;
|
|
313
|
+
return this.bucketTrx.wrap('patch', { obj }, trx => this.bucket.update(trx, obj, {
|
|
314
|
+
mode: 'patch',
|
|
315
|
+
unsafe: true,
|
|
316
|
+
no_tenancy: !this.enableTenancy
|
|
317
|
+
}), () => undefined);
|
|
351
318
|
}
|
|
352
|
-
|
|
319
|
+
/**
|
|
320
|
+
* Directly `replace` on object with the one passed as an argument.
|
|
321
|
+
* Also replaces the compositions of this bucket, from the
|
|
322
|
+
* `#composition` field passed in the message.
|
|
323
|
+
*
|
|
324
|
+
* > This unsafe version does not check if the object exists prior to replacing.
|
|
325
|
+
*
|
|
326
|
+
* - If the object is not found, this will throw an exception
|
|
327
|
+
* - If `#composition` is wrong, this will throw an exception
|
|
328
|
+
*/
|
|
329
|
+
async replace(obj) {
|
|
330
|
+
return this.bucketTrx.wrap('replace', { obj }, trx => this.bucket.update(trx, obj, {
|
|
331
|
+
mode: 'replace',
|
|
332
|
+
unsafe: true,
|
|
333
|
+
no_tenancy: !this.enableTenancy
|
|
334
|
+
}), () => undefined);
|
|
335
|
+
}
|
|
336
|
+
/*
|
|
337
|
+
Delete
|
|
338
|
+
*/
|
|
339
|
+
/**
|
|
340
|
+
* Deletes an object
|
|
341
|
+
*
|
|
342
|
+
* > This unsafe version does not check if the object exists prior to deleting.
|
|
343
|
+
*/
|
|
353
344
|
async delete(id) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
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);
|
|
345
|
+
return this.bucketTrx.wrap('delete', { id }, trx => this.bucket.delete(trx, id, {
|
|
346
|
+
unsafe: true,
|
|
347
|
+
no_tenancy: !this.enableTenancy
|
|
348
|
+
}), () => undefined);
|
|
395
349
|
}
|
|
396
350
|
/**
|
|
397
|
-
*
|
|
351
|
+
* Attempts to read an object by `id`, if found, deletes it.
|
|
352
|
+
*
|
|
353
|
+
* > This unsafe version does not check if the objects exist prior to deleting.
|
|
398
354
|
*/
|
|
399
355
|
async deleteMany(ids) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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;
|
|
356
|
+
return this.bucketTrx.wrap('deleteMany', { ids }, trx => this.bucket.deleteMany(trx, ids, {
|
|
357
|
+
unsafe: true,
|
|
358
|
+
no_tenancy: !this.enableTenancy
|
|
359
|
+
}), () => undefined);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
exports.BucketUnsafeTrxNode = BucketUnsafeTrxNode;
|
|
363
|
+
class BucketDriveTrxNode {
|
|
364
|
+
constructor(bucketTrx, bucket) {
|
|
365
|
+
this.bucketTrx = bucketTrx;
|
|
366
|
+
this.bucket = bucket;
|
|
367
|
+
if (!this.bucket.drive) {
|
|
368
|
+
throw error_1.NesoiError.Bucket.Drive.NoAdapter({ bucket: this.bucket.schema.alias });
|
|
440
369
|
}
|
|
441
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
442
370
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
371
|
+
/**
|
|
372
|
+
* Read the contents of a File of this bucket's drive
|
|
373
|
+
*/
|
|
374
|
+
read(file, options) {
|
|
446
375
|
try {
|
|
447
|
-
|
|
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
|
-
}
|
|
376
|
+
return this.bucket.drive.read(file);
|
|
486
377
|
}
|
|
487
378
|
catch (e) {
|
|
488
|
-
|
|
379
|
+
if (options?.silent) {
|
|
380
|
+
console.error(e);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
489
383
|
throw e;
|
|
490
384
|
}
|
|
491
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
492
385
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
386
|
+
/**
|
|
387
|
+
* Move the file on disk
|
|
388
|
+
*/
|
|
389
|
+
move(file, to, options) {
|
|
497
390
|
try {
|
|
498
|
-
|
|
391
|
+
return this.bucket.drive.move(file, to);
|
|
499
392
|
}
|
|
500
393
|
catch (e) {
|
|
501
|
-
|
|
394
|
+
if (options?.silent) {
|
|
395
|
+
console.error(e);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
502
398
|
throw e;
|
|
503
399
|
}
|
|
504
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
505
|
-
return result;
|
|
506
400
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
401
|
+
/**
|
|
402
|
+
* Delete a file of this bucket's drive
|
|
403
|
+
*/
|
|
404
|
+
delete(file, options) {
|
|
511
405
|
try {
|
|
512
|
-
|
|
406
|
+
return this.bucket.drive.delete(file);
|
|
513
407
|
}
|
|
514
408
|
catch (e) {
|
|
515
|
-
|
|
409
|
+
if (options?.silent) {
|
|
410
|
+
console.error(e);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
516
413
|
throw e;
|
|
517
414
|
}
|
|
518
|
-
await trx_node_1.TrxNode.ok(trx);
|
|
519
|
-
return result;
|
|
520
415
|
}
|
|
521
416
|
}
|
|
522
|
-
exports.
|
|
417
|
+
exports.BucketDriveTrxNode = BucketDriveTrxNode;
|