nesoi 3.2.4 → 3.2.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/lib/compiler/treeshake.js +4 -4
- package/lib/elements/blocks/job/internal/resource_job.builder.d.ts +1 -1
- package/lib/elements/blocks/job/internal/resource_job.builder.js +4 -1
- package/lib/elements/blocks/resource/resource.builder.js +6 -4
- package/lib/elements/entities/bucket/adapters/json.bucket_adapter.d.ts +44 -0
- package/lib/elements/entities/bucket/adapters/json.bucket_adapter.js +151 -0
- package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.js +6 -4
- package/lib/elements/entities/bucket/adapters/memory.nql.js +2 -2
- package/lib/elements/entities/bucket/model/bucket_model.convert.d.ts +1 -1
- package/lib/elements/entities/bucket/model/bucket_model.convert.js +4 -4
- package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +7 -1
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +5 -0
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +7 -0
- package/lib/elements/entities/bucket/query/nql_compiler.js +3 -2
- package/lib/elements/entities/bucket/view/bucket_view.js +12 -6
- package/lib/elements/entities/message/template/message_template.schema.d.ts +3 -0
- package/lib/elements/entities/message/template/message_template_field.builder.d.ts +1 -0
- package/lib/elements/entities/message/template/message_template_field.builder.js +7 -0
- package/lib/elements/entities/message/template/message_template_parser.js +2 -0
- package/lib/engine/apps/distributed/distributed.app.d.ts +6 -0
- package/lib/engine/apps/distributed/distributed.app.js +10 -0
- package/lib/engine/apps/inline.app.d.ts +6 -1
- package/lib/engine/apps/inline.app.js +10 -0
- package/lib/engine/apps/monolyth/monolyth.app.d.ts +6 -0
- package/lib/engine/apps/monolyth/monolyth.app.js +10 -0
- package/lib/engine/cli/cli.d.ts +2 -1
- package/lib/engine/cli/cli.js +79 -1
- package/lib/engine/daemon.d.ts +23 -1
- package/lib/engine/daemon.js +10 -0
- package/lib/engine/data/error.d.ts +6 -0
- package/lib/engine/data/error.js +4 -0
- package/lib/engine/dependency.d.ts +4 -1
- package/lib/engine/util/parse.d.ts +4 -0
- package/lib/engine/util/parse.js +11 -0
- package/package.json +1 -1
- package/tools/joaquin/mock.js +3 -0
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -90,11 +90,11 @@ class Treeshake {
|
|
|
90
90
|
}
|
|
91
91
|
static messageFieldTree(node, tree) {
|
|
92
92
|
const dependencies = [];
|
|
93
|
-
|
|
93
|
+
if (tree.__ext) {
|
|
94
|
+
dependencies.push(tree.__ext);
|
|
95
|
+
}
|
|
96
|
+
Object.entries(tree).forEach(child => {
|
|
94
97
|
const c = child;
|
|
95
|
-
if (c.__ext) {
|
|
96
|
-
dependencies.push(c.__ext);
|
|
97
|
-
}
|
|
98
98
|
if (c.type === 'enum') {
|
|
99
99
|
if (typeof c.value.enum.options === 'string') {
|
|
100
100
|
dependencies.push(c.value.enum.dep);
|
|
@@ -40,7 +40,7 @@ export declare class ResourceJobBuilder<Space extends $Space, Module extends $Mo
|
|
|
40
40
|
private _extrasAndAsserts;
|
|
41
41
|
private _prepareMethod;
|
|
42
42
|
private _afterMethod?;
|
|
43
|
-
constructor(module: string, name: Name, bucket: string, method: 'view' | 'query' | 'create' | 'update' | 'delete', alias: string, execMethod?: $JobMethod<any, any, any, any> | undefined, _authn?: string[], implicitFields?: Record<string, [string, any]>);
|
|
43
|
+
constructor(module: string, name: Name, bucket: string, method: 'view' | 'query' | 'create' | 'update' | 'delete', alias: string, execMethod?: $JobMethod<any, any, any, any> | undefined, _authn?: string[], implicitFields?: Record<string, [string, any, boolean]>);
|
|
44
44
|
/**
|
|
45
45
|
* The input message accepted by the job.
|
|
46
46
|
*
|
|
@@ -50,10 +50,13 @@ class ResourceJobBuilder extends block_builder_1.BlockBuilder {
|
|
|
50
50
|
this._msg.template($ => {
|
|
51
51
|
const fields = def($);
|
|
52
52
|
for (const f in this.implicitFields || []) {
|
|
53
|
-
const [type, arg] = this.implicitFields[f];
|
|
53
|
+
const [type, arg, required] = this.implicitFields[f];
|
|
54
54
|
fields[f] = arg
|
|
55
55
|
? $[type](arg)
|
|
56
56
|
: $[type];
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
58
|
+
if (!required)
|
|
59
|
+
fields[f].optional;
|
|
57
60
|
}
|
|
58
61
|
return fields;
|
|
59
62
|
});
|
|
@@ -84,7 +84,9 @@ class ResourceBuilder extends block_builder_1.BlockBuilder {
|
|
|
84
84
|
create($) {
|
|
85
85
|
const name = `${this.name}.create`;
|
|
86
86
|
const alias = `Create ${this._alias || this.name}`;
|
|
87
|
-
const jobBuilder = new resource_job_builder_1.ResourceJobBuilder(this.module, name, this._bucket.refName, 'create', alias, resource_1.Resource.create, this._authn
|
|
87
|
+
const jobBuilder = new resource_job_builder_1.ResourceJobBuilder(this.module, name, this._bucket.refName, 'create', alias, resource_1.Resource.create, this._authn, {
|
|
88
|
+
id: ['string_or_number', undefined, false]
|
|
89
|
+
})
|
|
88
90
|
.prepare(resource_job_1.ResourceJob.prepareMsgData);
|
|
89
91
|
$(jobBuilder);
|
|
90
92
|
this._inlineNodes.push(new dependency_1.BuilderNode({
|
|
@@ -103,7 +105,7 @@ class ResourceBuilder extends block_builder_1.BlockBuilder {
|
|
|
103
105
|
const name = `${this.name}.update`;
|
|
104
106
|
const alias = `Update ${this._alias || this.name}`;
|
|
105
107
|
const jobBuilder = new resource_job_builder_1.ResourceJobBuilder(this.module, name, this._bucket.refName, 'update', alias, resource_1.Resource.update, this._authn, {
|
|
106
|
-
id: ['string_or_number', undefined]
|
|
108
|
+
id: ['string_or_number', undefined, true]
|
|
107
109
|
})
|
|
108
110
|
.prepare(resource_job_1.ResourceJob.prepareMsgData);
|
|
109
111
|
$(jobBuilder);
|
|
@@ -123,7 +125,7 @@ class ResourceBuilder extends block_builder_1.BlockBuilder {
|
|
|
123
125
|
const name = `${this.name}.delete`;
|
|
124
126
|
const alias = `Delete ${this._alias || this.name}`;
|
|
125
127
|
const jobBuilder = new resource_job_builder_1.ResourceJobBuilder(this.module, name, this._bucket.refName, 'delete', alias, resource_1.Resource.delete, this._authn, {
|
|
126
|
-
id: ['string_or_number', undefined]
|
|
128
|
+
id: ['string_or_number', undefined, true]
|
|
127
129
|
})
|
|
128
130
|
.prepare(resource_job_1.ResourceJob.prepareTrue);
|
|
129
131
|
$(jobBuilder);
|
|
@@ -174,7 +176,7 @@ class ResourceBuilder extends block_builder_1.BlockBuilder {
|
|
|
174
176
|
// create
|
|
175
177
|
const createDep = node.builder._jobs.create;
|
|
176
178
|
if (createDep) {
|
|
177
|
-
const defaultTrigger = (0, bucket_model_convert_1.convertToMessage)(module.name, model, createDep.name, `Create ${node.builder._alias || node.builder.name}`, [], ['id']);
|
|
179
|
+
const defaultTrigger = (0, bucket_model_convert_1.convertToMessage)(module.name, model, createDep.name, `Create ${node.builder._alias || node.builder.name}`, [], [], ['id']);
|
|
178
180
|
inlineJobsConfig[createDep.name] = {
|
|
179
181
|
ResourceJob: {
|
|
180
182
|
idType: null,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BucketAdapterConfig } from './bucket_adapter';
|
|
2
|
+
import { ObjWithOptionalId } from "../../../../engine/data/obj";
|
|
3
|
+
import { AnyTrxNode } from "../../../../engine/transaction/trx_node";
|
|
4
|
+
import { $Bucket } from "../../..";
|
|
5
|
+
import { BucketCacheSync } from '../cache/bucket_cache';
|
|
6
|
+
import { MemoryBucketAdapter } from './memory.bucket_adapter';
|
|
7
|
+
/**
|
|
8
|
+
* @category Adapters
|
|
9
|
+
* @subcategory Entity
|
|
10
|
+
* */
|
|
11
|
+
export declare class JSONBucketAdapter<B extends $Bucket, Obj extends B['#data']> extends MemoryBucketAdapter<B, Obj> {
|
|
12
|
+
schema: B;
|
|
13
|
+
file: string;
|
|
14
|
+
private refName;
|
|
15
|
+
constructor(schema: B, file: string, config?: BucketAdapterConfig);
|
|
16
|
+
getQueryMeta(): {
|
|
17
|
+
scope: string;
|
|
18
|
+
avgTime: number;
|
|
19
|
+
};
|
|
20
|
+
private parse;
|
|
21
|
+
private dump;
|
|
22
|
+
protected deleteEverything(trx: AnyTrxNode): Promise<void>;
|
|
23
|
+
index(trx: AnyTrxNode): Promise<Obj[]>;
|
|
24
|
+
get(trx: AnyTrxNode, id: Obj['id']): Promise<Obj | undefined>;
|
|
25
|
+
create(trx: AnyTrxNode, obj: ObjWithOptionalId<Obj>): Promise<Obj>;
|
|
26
|
+
createMany(trx: AnyTrxNode, objs: ObjWithOptionalId<Obj>[]): Promise<Obj[]>;
|
|
27
|
+
replace(trx: AnyTrxNode, obj: ObjWithOptionalId<Obj>): Promise<Obj>;
|
|
28
|
+
replaceMany(trx: AnyTrxNode, objs: ObjWithOptionalId<Obj>[]): Promise<Obj[]>;
|
|
29
|
+
patch(trx: AnyTrxNode, obj: ObjWithOptionalId<Obj>): Promise<Obj>;
|
|
30
|
+
patchMany(trx: AnyTrxNode, objs: ObjWithOptionalId<Obj>[]): Promise<Obj[]>;
|
|
31
|
+
put(trx: AnyTrxNode, obj: ObjWithOptionalId<Obj>): Promise<Obj>;
|
|
32
|
+
putMany(trx: AnyTrxNode, objs: ObjWithOptionalId<Obj>[]): Promise<Obj[]>;
|
|
33
|
+
delete(trx: AnyTrxNode, id: Obj['id']): Promise<void>;
|
|
34
|
+
deleteMany(trx: AnyTrxNode, ids: Obj['id'][]): Promise<void>;
|
|
35
|
+
syncOne(trx: AnyTrxNode, id: Obj['id'], lastObjUpdateEpoch: number): Promise<null | 'deleted' | BucketCacheSync<Obj>>;
|
|
36
|
+
syncOneAndPast(trx: AnyTrxNode, id: Obj['id'], lastUpdateEpoch: number): Promise<null | 'deleted' | BucketCacheSync<Obj>[]>;
|
|
37
|
+
syncAll(trx: AnyTrxNode, lastHash?: string, lastUpdateEpoch?: number): Promise<null | {
|
|
38
|
+
sync: BucketCacheSync<Obj>[];
|
|
39
|
+
hash: string;
|
|
40
|
+
updateEpoch: number;
|
|
41
|
+
reset: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
export type AnyMemoryBucketAdapter = JSONBucketAdapter<any, any>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.JSONBucketAdapter = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const memory_bucket_adapter_1 = require("./memory.bucket_adapter");
|
|
39
|
+
/**
|
|
40
|
+
* @category Adapters
|
|
41
|
+
* @subcategory Entity
|
|
42
|
+
* */
|
|
43
|
+
class JSONBucketAdapter extends memory_bucket_adapter_1.MemoryBucketAdapter {
|
|
44
|
+
constructor(schema, file, config) {
|
|
45
|
+
super(schema, undefined, config);
|
|
46
|
+
this.schema = schema;
|
|
47
|
+
this.file = file;
|
|
48
|
+
this.refName = `${schema.module}::${schema.name}`;
|
|
49
|
+
this.parse();
|
|
50
|
+
}
|
|
51
|
+
getQueryMeta() {
|
|
52
|
+
return {
|
|
53
|
+
scope: `json.${this.schema.name}`,
|
|
54
|
+
avgTime: 100
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/* */
|
|
58
|
+
parse() {
|
|
59
|
+
this.data = {};
|
|
60
|
+
if (fs.existsSync(this.file)) {
|
|
61
|
+
const file = fs.readFileSync(this.file);
|
|
62
|
+
const fileData = JSON.parse(file.toString());
|
|
63
|
+
this.data = fileData[this.refName] || {};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
dump() {
|
|
67
|
+
var _a;
|
|
68
|
+
let data = {
|
|
69
|
+
[this.refName]: {}
|
|
70
|
+
};
|
|
71
|
+
if (fs.existsSync(this.file)) {
|
|
72
|
+
const file = fs.readFileSync(this.file);
|
|
73
|
+
data = JSON.parse(file.toString());
|
|
74
|
+
}
|
|
75
|
+
data[_a = this.refName] ?? (data[_a] = {});
|
|
76
|
+
Object.assign(data[this.refName], this.data);
|
|
77
|
+
fs.writeFileSync(this.file, JSON.stringify(data));
|
|
78
|
+
}
|
|
79
|
+
/* Dangerous, used on cache only */
|
|
80
|
+
deleteEverything(trx) {
|
|
81
|
+
this.data = {};
|
|
82
|
+
return Promise.resolve();
|
|
83
|
+
}
|
|
84
|
+
/* Read operations */
|
|
85
|
+
index(trx) {
|
|
86
|
+
return super.index(trx);
|
|
87
|
+
}
|
|
88
|
+
get(trx, id) {
|
|
89
|
+
return super.get(trx, id);
|
|
90
|
+
}
|
|
91
|
+
/* Write Operations */
|
|
92
|
+
async create(trx, obj) {
|
|
93
|
+
const res = await super.create(trx, obj);
|
|
94
|
+
this.dump();
|
|
95
|
+
return res;
|
|
96
|
+
}
|
|
97
|
+
async createMany(trx, objs) {
|
|
98
|
+
const res = await super.createMany(trx, objs);
|
|
99
|
+
this.dump();
|
|
100
|
+
return res;
|
|
101
|
+
}
|
|
102
|
+
async replace(trx, obj) {
|
|
103
|
+
const res = await super.replace(trx, obj);
|
|
104
|
+
this.dump();
|
|
105
|
+
return res;
|
|
106
|
+
}
|
|
107
|
+
async replaceMany(trx, objs) {
|
|
108
|
+
const res = await super.replaceMany(trx, objs);
|
|
109
|
+
this.dump();
|
|
110
|
+
return res;
|
|
111
|
+
}
|
|
112
|
+
async patch(trx, obj) {
|
|
113
|
+
const res = await super.patch(trx, obj);
|
|
114
|
+
this.dump();
|
|
115
|
+
return res;
|
|
116
|
+
}
|
|
117
|
+
async patchMany(trx, objs) {
|
|
118
|
+
const res = await super.patchMany(trx, objs);
|
|
119
|
+
this.dump();
|
|
120
|
+
return res;
|
|
121
|
+
}
|
|
122
|
+
async put(trx, obj) {
|
|
123
|
+
const res = await super.put(trx, obj);
|
|
124
|
+
this.dump();
|
|
125
|
+
return res;
|
|
126
|
+
}
|
|
127
|
+
async putMany(trx, objs) {
|
|
128
|
+
const res = await super.putMany(trx, objs);
|
|
129
|
+
this.dump();
|
|
130
|
+
return res;
|
|
131
|
+
}
|
|
132
|
+
async delete(trx, id) {
|
|
133
|
+
await super.delete(trx, id);
|
|
134
|
+
this.dump();
|
|
135
|
+
}
|
|
136
|
+
async deleteMany(trx, ids) {
|
|
137
|
+
await super.deleteMany(trx, ids);
|
|
138
|
+
this.dump();
|
|
139
|
+
}
|
|
140
|
+
/* Cache Operations */
|
|
141
|
+
async syncOne(trx, id, lastObjUpdateEpoch) {
|
|
142
|
+
return super.syncOne(trx, id, lastObjUpdateEpoch);
|
|
143
|
+
}
|
|
144
|
+
async syncOneAndPast(trx, id, lastUpdateEpoch) {
|
|
145
|
+
return super.syncOneAndPast(trx, id, lastUpdateEpoch);
|
|
146
|
+
}
|
|
147
|
+
async syncAll(trx, lastHash, lastUpdateEpoch = 0) {
|
|
148
|
+
return super.syncAll(trx, lastHash, lastUpdateEpoch);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.JSONBucketAdapter = JSONBucketAdapter;
|
|
@@ -46,10 +46,12 @@ class MemoryBucketAdapter extends bucket_adapter_1.BucketAdapter {
|
|
|
46
46
|
/* Write Operations */
|
|
47
47
|
async create(trx, obj) {
|
|
48
48
|
const input = bucket_model_schema_1.$BucketModel.copy(this.schema.model, obj, this.config.meta);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
if (!input.id) {
|
|
50
|
+
const lastId = (await this.index(trx))
|
|
51
|
+
.map((_obj) => parseInt(_obj.id))
|
|
52
|
+
.sort((a, b) => b - a)[0] || 0;
|
|
53
|
+
input.id = lastId + 1;
|
|
54
|
+
}
|
|
53
55
|
this.data[input.id] = input;
|
|
54
56
|
const output = bucket_model_schema_1.$BucketModel.copy(this.schema.model, input, this.config.meta);
|
|
55
57
|
return Promise.resolve(output);
|
|
@@ -211,10 +211,10 @@ class MemoryNQLRunner extends nql_engine_1.NQLRunner {
|
|
|
211
211
|
}
|
|
212
212
|
if (rule.op === '==') {
|
|
213
213
|
if (rule.case_i) {
|
|
214
|
-
return fieldValue
|
|
214
|
+
return fieldValue?.toLowerCase() === queryValue?.toLowerCase();
|
|
215
215
|
}
|
|
216
216
|
else {
|
|
217
|
-
return fieldValue === queryValue;
|
|
217
|
+
return fieldValue?.toString() === queryValue?.toString();
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
if (rule.op === '>') {
|
|
@@ -10,4 +10,4 @@ export declare function convertToView<Model extends $BucketModel>(model: Model,
|
|
|
10
10
|
* @category Elements
|
|
11
11
|
* @subcategory Entity
|
|
12
12
|
* */
|
|
13
|
-
export declare function convertToMessage<Model extends $BucketModel>(module: string, model: Model, name: string, alias: string, include?: string[], exclude?: string[]): $Message;
|
|
13
|
+
export declare function convertToMessage<Model extends $BucketModel>(module: string, model: Model, name: string, alias: string, include?: string[], exclude?: string[], optional?: string[]): $Message;
|
|
@@ -34,16 +34,16 @@ function convertToView(model, name, fields = model.fields, path, depth = 0) {
|
|
|
34
34
|
* @category Elements
|
|
35
35
|
* @subcategory Entity
|
|
36
36
|
* */
|
|
37
|
-
function convertToMessage(module, model, name, alias, include = [], exclude = []) {
|
|
37
|
+
function convertToMessage(module, model, name, alias, include = [], exclude = [], optional = []) {
|
|
38
38
|
const convertField = (field) => {
|
|
39
|
-
return new message_template_schema_1.$MessageTemplateField(field.type, field.name, field.alias, field.path, field.path, field.required, undefined, false, [], {
|
|
39
|
+
return new message_template_schema_1.$MessageTemplateField(field.type, field.name, field.alias, field.path, field.path, optional.includes(field.path) ? false : field.required, undefined, false, [], {
|
|
40
40
|
enum: field.meta?.enum ? {
|
|
41
41
|
options: field.meta.enum.options,
|
|
42
42
|
dep: field.meta.enum.dep ? new dependency_1.$Dependency(module, 'constants', `${field.meta.enum.dep.module}::${field.meta.enum.dep.name}`) : undefined
|
|
43
43
|
} : undefined
|
|
44
|
-
}, field.children ? convertFields(field.children, include, exclude) : undefined);
|
|
44
|
+
}, field.children ? convertFields(field.children, include, exclude, optional) : undefined);
|
|
45
45
|
};
|
|
46
|
-
const convertFields = (fields, include = [], exclude = [], root = '') => {
|
|
46
|
+
const convertFields = (fields, include = [], exclude = [], optional = [], root = '') => {
|
|
47
47
|
const msgFields = {};
|
|
48
48
|
for (const f in fields) {
|
|
49
49
|
const field = fields[f];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { $Dependency } from "../../../../engine/dependency";
|
|
2
2
|
import { BucketAdapterConfig } from '../adapters/bucket_adapter';
|
|
3
|
-
export type $BucketModelFieldType = 'boolean' | 'date' | 'datetime' | 'duration' | 'decimal' | 'enum' | 'file' | 'float' | 'int' | 'string' | 'obj' | 'unknown' | 'dict' | 'list' | 'union';
|
|
3
|
+
export type $BucketModelFieldType = 'boolean' | 'date' | 'datetime' | 'duration' | 'decimal' | 'enum' | 'file' | 'float' | 'int' | 'string' | 'obj' | 'unknown' | 'dict' | 'list' | 'union' | 'literal';
|
|
4
4
|
export type $BucketModelFieldCrypto = {
|
|
5
5
|
algorithm: string;
|
|
6
6
|
key: string;
|
|
@@ -16,6 +16,9 @@ export declare class $BucketModelField {
|
|
|
16
16
|
alias: string;
|
|
17
17
|
required: boolean;
|
|
18
18
|
meta?: {
|
|
19
|
+
literal?: {
|
|
20
|
+
template: string;
|
|
21
|
+
};
|
|
19
22
|
enum?: {
|
|
20
23
|
options: string | string[];
|
|
21
24
|
dep?: $Dependency;
|
|
@@ -34,6 +37,9 @@ export declare class $BucketModelField {
|
|
|
34
37
|
crypto?: $BucketModelFieldCrypto | undefined;
|
|
35
38
|
$t: string;
|
|
36
39
|
constructor(name: string, path: string, type: $BucketModelFieldType, alias: string, required: boolean, meta?: {
|
|
40
|
+
literal?: {
|
|
41
|
+
template: string;
|
|
42
|
+
};
|
|
37
43
|
enum?: {
|
|
38
44
|
options: string | string[];
|
|
39
45
|
dep?: $Dependency;
|
|
@@ -68,6 +68,11 @@ export declare class BucketModelFieldFactory<Space extends $Space, Module extend
|
|
|
68
68
|
}, {
|
|
69
69
|
'': string;
|
|
70
70
|
}>;
|
|
71
|
+
literal<T extends string>(template: RegExp): BucketModelFieldBuilder<Module, T, T, [false, false], {
|
|
72
|
+
'': T;
|
|
73
|
+
}, {
|
|
74
|
+
'': T;
|
|
75
|
+
}>;
|
|
71
76
|
file(def?: {
|
|
72
77
|
extnames?: string[];
|
|
73
78
|
maxsize?: number;
|
|
@@ -65,6 +65,13 @@ class BucketModelFieldFactory {
|
|
|
65
65
|
get string() {
|
|
66
66
|
return new BucketModelFieldBuilder(this.module, 'string', this.alias);
|
|
67
67
|
}
|
|
68
|
+
literal(template) {
|
|
69
|
+
return new BucketModelFieldBuilder(this.module, 'literal', this.alias, {
|
|
70
|
+
literal: {
|
|
71
|
+
template: template.toString().slice(1, -1)
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
68
75
|
file(def) {
|
|
69
76
|
return new BucketModelFieldBuilder(this.module, 'file', this.alias, {
|
|
70
77
|
file: def
|
|
@@ -99,7 +99,7 @@ class NQL_RuleTree {
|
|
|
99
99
|
}
|
|
100
100
|
for (const field of fields) {
|
|
101
101
|
if (![
|
|
102
|
-
'date', 'datetime', 'duration', 'decimal', 'enum', 'float', 'int', 'string'
|
|
102
|
+
'date', 'datetime', 'duration', 'decimal', 'enum', 'float', 'int', 'string', 'literal', 'boolean'
|
|
103
103
|
].includes(field.type)) {
|
|
104
104
|
throw new Error(`Field '${key}' is not sortable`);
|
|
105
105
|
}
|
|
@@ -477,10 +477,11 @@ NQL_RuleTree.OpByType = {
|
|
|
477
477
|
'float': ['<', '<=', '==', '>', '>=', 'in', 'present'],
|
|
478
478
|
'int': ['<', '<=', '==', '>', '>=', 'in', 'present'],
|
|
479
479
|
'string': ['==', 'contains', 'contains_any', 'in', 'present'],
|
|
480
|
+
'literal': ['==', 'contains', 'contains_any', 'in', 'present'],
|
|
480
481
|
'obj': ['contains_any', 'in', 'present'],
|
|
481
482
|
'list': ['contains', 'contains_any', 'present'],
|
|
482
483
|
'union': [],
|
|
483
|
-
'unknown': ['present']
|
|
484
|
+
'unknown': ['==', 'contains', 'contains_any', 'in', 'present']
|
|
484
485
|
};
|
|
485
486
|
/**
|
|
486
487
|
* Builds a NQL_CompiledQuery by splitting it into multiple parts
|
|
@@ -8,7 +8,7 @@ const trx_node_1 = require("../../../../engine/transaction/trx_node");
|
|
|
8
8
|
const promise_1 = __importDefault(require("../../../../engine/util/promise"));
|
|
9
9
|
const error_1 = require("../../../../engine/data/error");
|
|
10
10
|
const tree_1 = require("../../../../engine/data/tree");
|
|
11
|
-
const
|
|
11
|
+
const daemon_1 = require("../../../../engine/daemon");
|
|
12
12
|
class ViewValue {
|
|
13
13
|
constructor() {
|
|
14
14
|
this.value = undefined;
|
|
@@ -268,7 +268,9 @@ class BucketView {
|
|
|
268
268
|
for (let i = 0; i < links.length; i++) {
|
|
269
269
|
if (meta.view) {
|
|
270
270
|
const link = node.bucket.schema.graph.links[meta.link];
|
|
271
|
-
node.data[i].target[node.field.name] = link.many
|
|
271
|
+
node.data[i].target[node.field.name] = link.many
|
|
272
|
+
? []
|
|
273
|
+
: (links[i] ? {} : undefined);
|
|
272
274
|
}
|
|
273
275
|
else {
|
|
274
276
|
node.data[i].target[node.field.name] = links[i];
|
|
@@ -279,7 +281,8 @@ class BucketView {
|
|
|
279
281
|
const schema = node.bucket.schema;
|
|
280
282
|
const otherBucketDep = schema.graph.links[meta.link].bucket;
|
|
281
283
|
const module = trx_node_1.TrxNode.getModule(trx);
|
|
282
|
-
const
|
|
284
|
+
const daemon = module.daemon;
|
|
285
|
+
const otherBucket = await daemon_1.Daemon.getSchema(daemon, otherBucketDep);
|
|
283
286
|
const view = otherBucket.views[meta.view];
|
|
284
287
|
const { __raw, ...v } = view.fields;
|
|
285
288
|
const link = node.bucket.schema.graph.links[meta.link];
|
|
@@ -297,16 +300,19 @@ class BucketView {
|
|
|
297
300
|
}
|
|
298
301
|
else {
|
|
299
302
|
const _links = links;
|
|
303
|
+
nextData = [];
|
|
300
304
|
for (let i = 0; i < _links.length; i++) {
|
|
305
|
+
if (!_links[i])
|
|
306
|
+
continue;
|
|
301
307
|
const target = node.data[i].target[node.field.name];
|
|
302
308
|
if (__raw) {
|
|
303
309
|
Object.assign(target, _links[i]);
|
|
304
310
|
}
|
|
305
311
|
target.$v = meta.view;
|
|
312
|
+
nextData.push({
|
|
313
|
+
value: _links[i], target: node.data[i].target[node.field.name]
|
|
314
|
+
});
|
|
306
315
|
}
|
|
307
|
-
nextData = _links.map((l, i) => ({
|
|
308
|
-
value: l, target: node.data[i].target[node.field.name]
|
|
309
|
-
}));
|
|
310
316
|
}
|
|
311
317
|
next = Object.values(v).map(field => ({
|
|
312
318
|
bucket: module.buckets[otherBucketDep.refName],
|
|
@@ -34,6 +34,7 @@ export declare class MessageTemplateFieldFactory<Space extends $Space, Module ex
|
|
|
34
34
|
id<Name extends BucketName<Module>, View extends ViewName<Module['buckets'][Name]> | undefined>(bucket: Name, view?: View): MessageTemplateFieldBuilder<Module, Message, Module["buckets"][Name]["#data"]["id"], undefined extends View ? Module["buckets"][Name]["#data"] : Module["buckets"][Name]["views"][NonNullable<View>]["#data"], {}, [false, false], "_id">;
|
|
35
35
|
get int(): MessageTemplateFieldBuilder<Module, Message, number, number, {}, [false, false], "">;
|
|
36
36
|
get string(): MessageTemplateFieldBuilder<Module, Message, string, string, {}, [false, false], "">;
|
|
37
|
+
literal<T extends string>(template: RegExp): MessageTemplateFieldBuilder<Module, Message, T, T, {}, [false, false], "">;
|
|
37
38
|
get string_or_number(): MessageTemplateFieldBuilder<Module, Message, string | number, string | number, {}, [false, false], "">;
|
|
38
39
|
obj<Builders extends MessageTemplateFieldBuilders>(children: Builders): MessageTemplateFieldBuilder<Module, Message, $MessageInputInfer<Builders>, $MessageOutputInfer<Builders>, Builders, [false, false], "">;
|
|
39
40
|
dict<Builder extends MessageTemplateFieldBuilder<Module, Message, any, any, any, any, any>>(item: Builder): MessageTemplateFieldBuilder<Module, Message, Record<string, Builder["#input"]>, Record<string, Builder["#output"]>, {
|
|
@@ -71,6 +71,13 @@ class MessageTemplateFieldFactory {
|
|
|
71
71
|
get string() {
|
|
72
72
|
return new MessageTemplateFieldBuilder('string', {}, this.alias);
|
|
73
73
|
}
|
|
74
|
+
literal(template) {
|
|
75
|
+
return new MessageTemplateFieldBuilder('literal', {
|
|
76
|
+
literal: {
|
|
77
|
+
template: template.toString().slice(1, -1)
|
|
78
|
+
}
|
|
79
|
+
}, this.alias);
|
|
80
|
+
}
|
|
74
81
|
get string_or_number() {
|
|
75
82
|
return new MessageTemplateFieldBuilder('string_or_number', {}, this.alias);
|
|
76
83
|
}
|
|
@@ -114,6 +114,8 @@ async function _runParseMethod(trx, field, path, raw, value, inject) {
|
|
|
114
114
|
return (0, parse_1.parseInt_)(field, path, value);
|
|
115
115
|
case 'string':
|
|
116
116
|
return (0, parse_1.parseString)(field, path, value);
|
|
117
|
+
case 'literal':
|
|
118
|
+
return (0, parse_1.parseLiteral)(field, path, value, field.meta.literal.template);
|
|
117
119
|
case 'string_or_number':
|
|
118
120
|
return (0, parse_1.parseStringOrNumber)(field, path, value);
|
|
119
121
|
case 'id':
|
|
@@ -4,6 +4,7 @@ import { Daemon } from "../../daemon";
|
|
|
4
4
|
import { DistributedAppConfig } from './distributed.app.config';
|
|
5
5
|
import { App } from '../app';
|
|
6
6
|
import { DistributedAppNode, DistributedAppNodeDef, DistributedNodeDaemon } from './distributed_node.app';
|
|
7
|
+
import { AnyElementSchema } from "../../module";
|
|
7
8
|
/**
|
|
8
9
|
* @category App
|
|
9
10
|
* @subcategory Distributed
|
|
@@ -22,6 +23,11 @@ export declare class DistributedApp<S extends $Space, Name extends string, Nodes
|
|
|
22
23
|
* @subcategory Distributed
|
|
23
24
|
*/
|
|
24
25
|
export declare class DistributedDaemon<S extends $Space, Nodes extends Record<string, DistributedAppNode<any, any, any, any>>> extends Daemon<S, never> {
|
|
26
|
+
protected getSchema(tag: {
|
|
27
|
+
module: keyof S['modules'];
|
|
28
|
+
type: string;
|
|
29
|
+
name: string;
|
|
30
|
+
}): Promise<AnyElementSchema>;
|
|
25
31
|
nodes: {
|
|
26
32
|
[K in keyof Nodes]: DistributedNodeDaemon<S, Nodes[K] extends DistributedAppNode<any, any, infer X, any> ? X : never>;
|
|
27
33
|
};
|
|
@@ -39,6 +39,16 @@ exports.DistributedApp = DistributedApp;
|
|
|
39
39
|
* @subcategory Distributed
|
|
40
40
|
*/
|
|
41
41
|
class DistributedDaemon extends daemon_1.Daemon {
|
|
42
|
+
async getSchema(tag) {
|
|
43
|
+
// const trxEngine = this.trxEngines[tag.module as keyof typeof this.trxEngines];
|
|
44
|
+
// const _module = trxEngine.getModule();
|
|
45
|
+
// const schema = $Dependency.resolve(_module.schema, tag);
|
|
46
|
+
// if (!schema) {
|
|
47
|
+
// throw new Error(`Unable to reach schema '${tag}'`)
|
|
48
|
+
// }
|
|
49
|
+
// return Promise.resolve(schema);
|
|
50
|
+
throw new Error('Not implemented yet');
|
|
51
|
+
}
|
|
42
52
|
constructor(name, config) {
|
|
43
53
|
super(name, {}, {}, config);
|
|
44
54
|
this.nodes = {};
|
|
@@ -2,7 +2,7 @@ import { $Module, $Space, ModuleName } from "../../schema";
|
|
|
2
2
|
import { App } from './app';
|
|
3
3
|
import { IService } from './service';
|
|
4
4
|
import { AnyTrxEngine } from '../transaction/trx_engine';
|
|
5
|
-
import { AnyBuilder, AnyModule, Module } from '../module';
|
|
5
|
+
import { AnyBuilder, AnyElementSchema, AnyModule, Module } from '../module';
|
|
6
6
|
import { AnyDaemon, Daemon } from '../daemon';
|
|
7
7
|
import { AppConfigBuilder } from './app.config';
|
|
8
8
|
/**
|
|
@@ -56,4 +56,9 @@ export declare class InlineApp<S extends $Space, ModuleNames extends string = Mo
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
export declare class InlineDaemon<S extends $Space, Modules extends ModuleName<S>> extends Daemon<S, Modules> {
|
|
59
|
+
protected getSchema(tag: {
|
|
60
|
+
module: Modules;
|
|
61
|
+
type: string;
|
|
62
|
+
name: string;
|
|
63
|
+
}): Promise<AnyElementSchema>;
|
|
59
64
|
}
|
|
@@ -11,6 +11,7 @@ const tree_1 = require("../tree");
|
|
|
11
11
|
const daemon_1 = require("../daemon");
|
|
12
12
|
const app_config_1 = require("./app.config");
|
|
13
13
|
const promise_1 = __importDefault(require("../util/promise"));
|
|
14
|
+
const dependency_1 = require("../dependency");
|
|
14
15
|
/**
|
|
15
16
|
* @category App
|
|
16
17
|
*/
|
|
@@ -176,5 +177,14 @@ class InlineApp extends app_1.App {
|
|
|
176
177
|
}
|
|
177
178
|
exports.InlineApp = InlineApp;
|
|
178
179
|
class InlineDaemon extends daemon_1.Daemon {
|
|
180
|
+
async getSchema(tag) {
|
|
181
|
+
const trxEngine = this.trxEngines[tag.module];
|
|
182
|
+
const _module = trxEngine.getModule();
|
|
183
|
+
const schema = dependency_1.$Dependency.resolve(_module.schema, tag);
|
|
184
|
+
if (!schema) {
|
|
185
|
+
throw new Error(`Unable to reach schema '${tag}'`);
|
|
186
|
+
}
|
|
187
|
+
return Promise.resolve(schema);
|
|
188
|
+
}
|
|
179
189
|
}
|
|
180
190
|
exports.InlineDaemon = InlineDaemon;
|
|
@@ -5,6 +5,7 @@ import { AnyTrxEngine } from '../../transaction/trx_engine';
|
|
|
5
5
|
import { Space } from '../../space';
|
|
6
6
|
import { Daemon } from "../../daemon";
|
|
7
7
|
import { AppConfigBuilder } from '../app.config';
|
|
8
|
+
import { AnyElementSchema } from "../../module";
|
|
8
9
|
/**
|
|
9
10
|
* @category App
|
|
10
11
|
* @subcategory Monolyth
|
|
@@ -27,4 +28,9 @@ export declare class MonolythApp<S extends $Space, ModuleNames extends string =
|
|
|
27
28
|
* @subcategory Monolyth
|
|
28
29
|
*/
|
|
29
30
|
export declare class MonolythDaemon<S extends $Space, Modules extends ModuleName<S>> extends Daemon<S, Modules> {
|
|
31
|
+
protected getSchema(tag: {
|
|
32
|
+
module: Modules;
|
|
33
|
+
type: string;
|
|
34
|
+
name: string;
|
|
35
|
+
}): Promise<AnyElementSchema>;
|
|
30
36
|
}
|
|
@@ -39,6 +39,7 @@ const space_1 = require("../../space");
|
|
|
39
39
|
const daemon_1 = require("../../daemon");
|
|
40
40
|
const log_1 = require("../../util/log");
|
|
41
41
|
const app_config_1 = require("../app.config");
|
|
42
|
+
const dependency_1 = require("../../dependency");
|
|
42
43
|
/**
|
|
43
44
|
* @category App
|
|
44
45
|
* @subcategory Monolyth
|
|
@@ -110,5 +111,14 @@ exports.MonolythApp = MonolythApp;
|
|
|
110
111
|
* @subcategory Monolyth
|
|
111
112
|
*/
|
|
112
113
|
class MonolythDaemon extends daemon_1.Daemon {
|
|
114
|
+
async getSchema(tag) {
|
|
115
|
+
const trxEngine = this.trxEngines[tag.module];
|
|
116
|
+
const _module = trxEngine.getModule();
|
|
117
|
+
const schema = dependency_1.$Dependency.resolve(_module.schema, tag);
|
|
118
|
+
if (!schema) {
|
|
119
|
+
throw new Error(`Unable to reach schema '${tag}'`);
|
|
120
|
+
}
|
|
121
|
+
return Promise.resolve(schema);
|
|
122
|
+
}
|
|
113
123
|
}
|
|
114
124
|
exports.MonolythDaemon = MonolythDaemon;
|