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,16 +1,28 @@
|
|
|
1
|
-
import ensure_index from '#src/migration/ensure-index.js';
|
|
2
|
-
import resolve_schema_indexes from '#src/migration/schema-indexes-resolver.js';
|
|
3
|
-
import ensure_table from '#src/migration/ensure-table.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
await ensure_table(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import ensure_index from '#src/migration/ensure-index.js';
|
|
2
|
+
import resolve_schema_indexes from '#src/migration/schema-indexes-resolver.js';
|
|
3
|
+
import ensure_table from '#src/migration/ensure-table.js';
|
|
4
|
+
|
|
5
|
+
async function ensure_schema(table_name, data_column, collection_schema, id_strategy, connection) {
|
|
6
|
+
await ensure_table({
|
|
7
|
+
table_name,
|
|
8
|
+
data_column,
|
|
9
|
+
id_strategy,
|
|
10
|
+
connection
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const schema_indexes = resolve_schema_indexes(collection_schema);
|
|
14
|
+
let index_position = 0;
|
|
15
|
+
|
|
16
|
+
while(index_position < schema_indexes.length) {
|
|
17
|
+
const index_definition = schema_indexes[index_position];
|
|
18
|
+
await ensure_index({
|
|
19
|
+
table_name,
|
|
20
|
+
index_definition,
|
|
21
|
+
data_column,
|
|
22
|
+
connection
|
|
23
|
+
});
|
|
24
|
+
index_position += 1;
|
|
25
|
+
}
|
|
16
26
|
}
|
|
27
|
+
|
|
28
|
+
export default ensure_schema;
|
|
@@ -1,31 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
/*
|
|
2
|
+
* MODULE RESPONSIBILITY
|
|
3
|
+
* Ensure the model backing table exists with the expected base columns.
|
|
4
|
+
*/
|
|
5
|
+
import {assert_identifier, quote_identifier} from '#src/utils/assert.js';
|
|
6
|
+
import ID_STRATEGY, {assert_id_strategy} from '#src/constants/id-strategy.js';
|
|
7
|
+
import run from '#src/sql/run.js';
|
|
8
|
+
|
|
9
|
+
const ID_COLUMN_SQL_BY_STRATEGY = {
|
|
10
|
+
[ID_STRATEGY.bigserial]: 'id BIGSERIAL PRIMARY KEY',
|
|
11
|
+
[ID_STRATEGY.uuidv7]: 'id UUID PRIMARY KEY DEFAULT uuidv7()'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
async function ensure_table(context) {
|
|
15
|
+
const {
|
|
16
|
+
table_name,
|
|
17
|
+
data_column,
|
|
18
|
+
id_strategy,
|
|
19
|
+
connection
|
|
20
|
+
} = context;
|
|
21
|
+
|
|
22
|
+
assert_identifier(table_name, 'table_name');
|
|
23
|
+
assert_identifier(data_column, 'data_column');
|
|
24
|
+
assert_id_strategy(id_strategy);
|
|
25
|
+
|
|
26
|
+
const final_id_strategy = id_strategy;
|
|
27
|
+
const table_identifier = quote_identifier(table_name);
|
|
28
|
+
const data_identifier = quote_identifier(data_column);
|
|
29
|
+
const id_column_sql = resolve_id_column_sql(final_id_strategy);
|
|
30
|
+
const sql_text =
|
|
31
|
+
`CREATE TABLE IF NOT EXISTS ` +
|
|
32
|
+
`${table_identifier} (${id_column_sql}, ${data_identifier} JSONB NOT NULL, ` +
|
|
33
|
+
`created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), ` +
|
|
34
|
+
`updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()` +
|
|
35
|
+
`);`;
|
|
36
|
+
|
|
37
|
+
await run(sql_text, [], connection);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function resolve_id_column_sql(id_strategy) {
|
|
41
|
+
return ID_COLUMN_SQL_BY_STRATEGY[id_strategy];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default ensure_table;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {is_array} from '#src/utils/array.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const schema_indexes =
|
|
5
|
-
return is_array(schema_indexes) ? schema_indexes : [];
|
|
6
|
-
}
|
|
1
|
+
import {is_array} from '#src/utils/array.js';
|
|
2
|
+
|
|
3
|
+
function resolve_schema_indexes(schema_instance) {
|
|
4
|
+
const schema_indexes = schema_instance.get_indexes();
|
|
5
|
+
return is_array(schema_indexes) ? schema_indexes : [];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default resolve_schema_indexes;
|