jsonbadger 0.5.0 → 0.6.0
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 +36 -18
- package/docs/api/connection.md +144 -0
- package/docs/api/delta-tracker.md +106 -0
- package/docs/api/document.md +77 -0
- package/docs/api/field-types.md +329 -0
- package/docs/api/index.md +35 -0
- package/docs/api/model.md +392 -0
- package/docs/api/query-builder.md +81 -0
- package/docs/api/schema.md +204 -0
- package/docs/architecture-flow.md +397 -0
- package/docs/examples.md +495 -218
- package/docs/jsonb-ops.md +171 -0
- package/docs/lifecycle/model-compilation.md +111 -0
- package/docs/lifecycle.md +146 -0
- package/docs/query-translation.md +11 -10
- package/package.json +10 -3
- package/src/connection/connect.js +12 -17
- package/src/connection/connection.js +128 -0
- package/src/connection/server-capabilities.js +60 -59
- package/src/constants/defaults.js +32 -19
- package/src/constants/{id-strategies.js → id-strategy.js} +28 -29
- package/src/constants/intake-mode.js +8 -0
- package/src/debug/debug-logger.js +17 -15
- package/src/errors/model-overwrite-error.js +25 -0
- package/src/errors/query-error.js +25 -23
- package/src/errors/validation-error.js +25 -23
- package/src/field-types/base-field-type.js +137 -140
- package/src/field-types/builtins/advanced.js +365 -365
- package/src/field-types/builtins/index.js +579 -585
- package/src/field-types/field-type-namespace.js +9 -0
- package/src/field-types/registry.js +149 -122
- package/src/index.js +26 -36
- package/src/migration/ensure-index.js +157 -154
- package/src/migration/ensure-schema.js +27 -15
- package/src/migration/ensure-table.js +44 -31
- package/src/migration/schema-indexes-resolver.js +8 -6
- package/src/model/document-instance.js +29 -540
- package/src/model/document.js +60 -0
- package/src/model/factory/constants.js +36 -0
- package/src/model/factory/index.js +58 -0
- package/src/model/model.js +875 -0
- package/src/model/operations/delete-one.js +39 -0
- package/src/model/operations/insert-one.js +35 -0
- package/src/model/operations/query-builder.js +132 -0
- package/src/model/operations/update-one.js +333 -0
- package/src/model/state.js +34 -0
- package/src/schema/field-definition-parser.js +213 -218
- package/src/schema/path-introspection.js +87 -82
- package/src/schema/schema-compiler.js +126 -212
- package/src/schema/schema.js +621 -138
- package/src/sql/index.js +17 -0
- package/src/sql/jsonb/ops.js +153 -0
- package/src/{query → sql/jsonb}/path-parser.js +54 -43
- package/src/sql/jsonb/read/elem-match.js +133 -0
- package/src/{query → sql/jsonb/read}/operators/contains.js +13 -7
- package/src/sql/jsonb/read/operators/elem-match.js +9 -0
- package/src/{query → sql/jsonb/read}/operators/has-all-keys.js +17 -11
- package/src/{query → sql/jsonb/read}/operators/has-any-keys.js +18 -11
- package/src/sql/jsonb/read/operators/has-key.js +12 -0
- package/src/{query → sql/jsonb/read}/operators/jsonpath-exists.js +22 -15
- package/src/{query → sql/jsonb/read}/operators/jsonpath-match.js +22 -15
- package/src/{query → sql/jsonb/read}/operators/size.js +23 -16
- package/src/sql/parameter-binder.js +18 -13
- package/src/sql/read/build-count-query.js +12 -0
- package/src/sql/read/build-find-query.js +25 -0
- package/src/sql/read/limit-skip.js +21 -0
- package/src/sql/read/sort.js +85 -0
- package/src/sql/read/where/base-fields.js +310 -0
- package/src/sql/read/where/casting.js +90 -0
- package/src/sql/read/where/context.js +79 -0
- package/src/sql/read/where/field-clause.js +58 -0
- package/src/sql/read/where/index.js +38 -0
- package/src/sql/read/where/operator-entries.js +29 -0
- package/src/{query → sql/read/where}/operators/all.js +16 -10
- package/src/sql/read/where/operators/eq.js +12 -0
- package/src/{query → sql/read/where}/operators/gt.js +23 -16
- package/src/{query → sql/read/where}/operators/gte.js +23 -16
- package/src/{query → sql/read/where}/operators/in.js +18 -12
- package/src/sql/read/where/operators/index.js +40 -0
- package/src/{query → sql/read/where}/operators/lt.js +23 -16
- package/src/{query → sql/read/where}/operators/lte.js +23 -16
- package/src/sql/read/where/operators/ne.js +12 -0
- package/src/{query → sql/read/where}/operators/nin.js +18 -12
- package/src/{query → sql/read/where}/operators/regex.js +14 -8
- package/src/sql/read/where/operators.js +126 -0
- package/src/sql/read/where/text-operators.js +83 -0
- package/src/sql/run.js +46 -0
- package/src/sql/write/build-delete-query.js +33 -0
- package/src/sql/write/build-insert-query.js +42 -0
- package/src/sql/write/build-update-query.js +65 -0
- package/src/utils/assert.js +34 -27
- package/src/utils/delta-tracker/.archive/1 tracker-redesign-codex-v2.md +250 -0
- package/src/utils/delta-tracker/.archive/1 tracker-redesign-gemini.md +101 -0
- package/src/utils/delta-tracker/.archive/2 evaluation by gemini.txt +65 -0
- package/src/utils/delta-tracker/.archive/2 evaluation by grok.txt +39 -0
- package/src/utils/delta-tracker/.archive/3 gemini evaluate grok.txt +37 -0
- package/src/utils/delta-tracker/.archive/3 grok evaluate gemini.txt +63 -0
- package/src/utils/delta-tracker/.archive/4 gemini veredict.txt +16 -0
- package/src/utils/delta-tracker/.archive/index.1.js +587 -0
- package/src/utils/delta-tracker/.archive/index.2.js +612 -0
- package/src/utils/delta-tracker/index.js +592 -0
- package/src/utils/dirty-tracker/inline.js +335 -0
- package/src/utils/dirty-tracker/instance.js +414 -0
- package/src/utils/dirty-tracker/static.js +343 -0
- package/src/utils/json-safe.js +13 -9
- package/src/utils/object-path.js +227 -33
- package/src/utils/object.js +408 -168
- package/src/utils/string.js +55 -0
- package/src/utils/value.js +169 -30
- package/docs/api.md +0 -152
- package/src/connection/disconnect.js +0 -16
- package/src/connection/pool-store.js +0 -46
- package/src/model/model-factory.js +0 -555
- package/src/query/limit-skip-compiler.js +0 -31
- package/src/query/operators/elem-match.js +0 -3
- package/src/query/operators/eq.js +0 -6
- package/src/query/operators/has-key.js +0 -6
- package/src/query/operators/index.js +0 -60
- package/src/query/operators/ne.js +0 -6
- package/src/query/query-builder.js +0 -93
- package/src/query/sort-compiler.js +0 -30
- package/src/query/where-compiler.js +0 -477
- package/src/sql/sql-runner.js +0 -31
|
@@ -1,140 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
field_error
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
export default BaseFieldType;
|
|
1
|
+
import {is_function} from '#src/utils/value.js';
|
|
2
|
+
|
|
3
|
+
function BaseFieldType(path_value, options) {
|
|
4
|
+
this.path = path_value;
|
|
5
|
+
this.options = options || {};
|
|
6
|
+
this.instance = 'Mixed';
|
|
7
|
+
this.validators = [];
|
|
8
|
+
this.regExp = null;
|
|
9
|
+
this.enum_values = null;
|
|
10
|
+
this.register_universal_validators();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
BaseFieldType.prototype.register_universal_validators = function () {
|
|
14
|
+
if(this.options.required !== undefined) {
|
|
15
|
+
this.validators.push({
|
|
16
|
+
kind: 'required'
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if(is_function(this.options.validate)) {
|
|
21
|
+
this.validators.push({
|
|
22
|
+
kind: 'custom'
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
BaseFieldType.prototype.create_field_error = function (code_value, message, value) {
|
|
28
|
+
const field_error = new Error(message);
|
|
29
|
+
field_error.code = code_value;
|
|
30
|
+
field_error.path = this.path;
|
|
31
|
+
field_error.value = value;
|
|
32
|
+
return field_error;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
BaseFieldType.prototype.is_required = function (context_value) {
|
|
36
|
+
const required_option = this.options.required;
|
|
37
|
+
|
|
38
|
+
if(is_function(required_option)) {
|
|
39
|
+
return Boolean(required_option.call(null, context_value || {}));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return required_option === true;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
BaseFieldType.prototype.resolve_default = function (context_value) {
|
|
46
|
+
if(this.options.default === undefined) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if(is_function(this.options.default)) {
|
|
51
|
+
return this.options.default.call(null, context_value || {});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return this.options.default;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
BaseFieldType.prototype.apply_set = function (value, context_value) {
|
|
58
|
+
if(!is_function(this.options.set)) {
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return this.options.set.call(null, value, context_value || {});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
BaseFieldType.prototype.apply_get = function (value, context_value) {
|
|
66
|
+
if(!is_function(this.options.get)) {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return this.options.get.call(null, value, context_value || {});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
BaseFieldType.prototype.cast = function (value) {
|
|
74
|
+
return value;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
BaseFieldType.prototype.run_custom_validator = function (value, context_value) {
|
|
78
|
+
if(!is_function(this.options.validate)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let validator_result = false;
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
validator_result = this.options.validate.call(null, value, context_value || {});
|
|
86
|
+
} catch(error) {
|
|
87
|
+
const message_value = error && error.message ? error.message : 'Custom validator failed for path "' + this.path + '"';
|
|
88
|
+
throw this.create_field_error('validator_error', message_value, value);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if(!validator_result) {
|
|
92
|
+
throw this.create_field_error('validator_error', 'Custom validator failed for path "' + this.path + '"', value);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
BaseFieldType.prototype.run_type_validators = function () {
|
|
97
|
+
return;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
BaseFieldType.prototype.validate = function (value, context_value) {
|
|
101
|
+
this.run_custom_validator(value, context_value || {});
|
|
102
|
+
this.run_type_validators(value, context_value || {});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
BaseFieldType.prototype.normalize = function (value, context_value) {
|
|
106
|
+
const normalized_context = context_value || {};
|
|
107
|
+
let current_value = value;
|
|
108
|
+
|
|
109
|
+
if(current_value === undefined) {
|
|
110
|
+
current_value = this.resolve_default(normalized_context);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if(current_value === undefined || current_value === null) {
|
|
114
|
+
if(this.is_required(normalized_context)) {
|
|
115
|
+
throw this.create_field_error('required_error', 'Path "' + this.path + '" is required', current_value);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return current_value;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
current_value = this.apply_set(current_value, normalized_context);
|
|
122
|
+
current_value = this.cast(current_value, normalized_context);
|
|
123
|
+
this.validate(current_value, normalized_context);
|
|
124
|
+
return current_value;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
BaseFieldType.prototype.to_introspection = function () {
|
|
128
|
+
return {
|
|
129
|
+
path: this.path,
|
|
130
|
+
instance: this.instance,
|
|
131
|
+
validators: this.validators,
|
|
132
|
+
regExp: this.regExp || null,
|
|
133
|
+
enum_values: this.enum_values || null
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export default BaseFieldType;
|