jsonbadger 0.5.0 → 0.6.1

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.
Files changed (123) hide show
  1. package/README.md +36 -18
  2. package/docs/api/connection.md +144 -0
  3. package/docs/api/delta-tracker.md +106 -0
  4. package/docs/api/document.md +77 -0
  5. package/docs/api/field-types.md +329 -0
  6. package/docs/api/index.md +35 -0
  7. package/docs/api/model.md +392 -0
  8. package/docs/api/query-builder.md +81 -0
  9. package/docs/api/schema.md +204 -0
  10. package/docs/architecture-flow.md +397 -0
  11. package/docs/examples.md +495 -218
  12. package/docs/jsonb-ops.md +171 -0
  13. package/docs/lifecycle/model-compilation.md +111 -0
  14. package/docs/lifecycle.md +146 -0
  15. package/docs/query-translation.md +11 -10
  16. package/package.json +10 -3
  17. package/src/connection/connect.js +12 -17
  18. package/src/connection/connection.js +128 -0
  19. package/src/connection/server-capabilities.js +60 -59
  20. package/src/constants/defaults.js +32 -19
  21. package/src/constants/{id-strategies.js → id-strategy.js} +28 -29
  22. package/src/constants/intake-mode.js +8 -0
  23. package/src/debug/debug-logger.js +17 -15
  24. package/src/errors/model-overwrite-error.js +25 -0
  25. package/src/errors/query-error.js +25 -23
  26. package/src/errors/validation-error.js +25 -23
  27. package/src/field-types/base-field-type.js +137 -140
  28. package/src/field-types/builtins/advanced.js +365 -365
  29. package/src/field-types/builtins/index.js +579 -585
  30. package/src/field-types/field-type-namespace.js +9 -0
  31. package/src/field-types/registry.js +149 -122
  32. package/src/index.js +26 -36
  33. package/src/migration/ensure-index.js +157 -154
  34. package/src/migration/ensure-schema.js +27 -15
  35. package/src/migration/ensure-table.js +44 -31
  36. package/src/migration/schema-indexes-resolver.js +8 -6
  37. package/src/model/document-instance.js +29 -540
  38. package/src/model/document.js +60 -0
  39. package/src/model/factory/constants.js +36 -0
  40. package/src/model/factory/index.js +58 -0
  41. package/src/model/model.js +875 -0
  42. package/src/model/operations/delete-one.js +39 -0
  43. package/src/model/operations/insert-one.js +35 -0
  44. package/src/model/operations/query-builder.js +132 -0
  45. package/src/model/operations/update-one.js +333 -0
  46. package/src/model/state.js +34 -0
  47. package/src/schema/field-definition-parser.js +213 -218
  48. package/src/schema/path-introspection.js +87 -82
  49. package/src/schema/schema-compiler.js +126 -212
  50. package/src/schema/schema.js +621 -138
  51. package/src/sql/index.js +17 -0
  52. package/src/sql/jsonb/ops.js +153 -0
  53. package/src/{query → sql/jsonb}/path-parser.js +54 -43
  54. package/src/sql/jsonb/read/elem-match.js +133 -0
  55. package/src/{query → sql/jsonb/read}/operators/contains.js +13 -7
  56. package/src/sql/jsonb/read/operators/elem-match.js +9 -0
  57. package/src/{query → sql/jsonb/read}/operators/has-all-keys.js +17 -11
  58. package/src/{query → sql/jsonb/read}/operators/has-any-keys.js +18 -11
  59. package/src/sql/jsonb/read/operators/has-key.js +12 -0
  60. package/src/{query → sql/jsonb/read}/operators/jsonpath-exists.js +22 -15
  61. package/src/{query → sql/jsonb/read}/operators/jsonpath-match.js +22 -15
  62. package/src/{query → sql/jsonb/read}/operators/size.js +23 -16
  63. package/src/sql/parameter-binder.js +18 -13
  64. package/src/sql/read/build-count-query.js +12 -0
  65. package/src/sql/read/build-find-query.js +25 -0
  66. package/src/sql/read/limit-skip.js +21 -0
  67. package/src/sql/read/sort.js +85 -0
  68. package/src/sql/read/where/base-fields.js +310 -0
  69. package/src/sql/read/where/casting.js +90 -0
  70. package/src/sql/read/where/context.js +79 -0
  71. package/src/sql/read/where/field-clause.js +58 -0
  72. package/src/sql/read/where/index.js +38 -0
  73. package/src/sql/read/where/operator-entries.js +29 -0
  74. package/src/{query → sql/read/where}/operators/all.js +16 -10
  75. package/src/sql/read/where/operators/eq.js +12 -0
  76. package/src/{query → sql/read/where}/operators/gt.js +23 -16
  77. package/src/{query → sql/read/where}/operators/gte.js +23 -16
  78. package/src/{query → sql/read/where}/operators/in.js +18 -12
  79. package/src/sql/read/where/operators/index.js +40 -0
  80. package/src/{query → sql/read/where}/operators/lt.js +23 -16
  81. package/src/{query → sql/read/where}/operators/lte.js +23 -16
  82. package/src/sql/read/where/operators/ne.js +12 -0
  83. package/src/{query → sql/read/where}/operators/nin.js +18 -12
  84. package/src/{query → sql/read/where}/operators/regex.js +14 -8
  85. package/src/sql/read/where/operators.js +126 -0
  86. package/src/sql/read/where/text-operators.js +83 -0
  87. package/src/sql/run.js +46 -0
  88. package/src/sql/write/build-delete-query.js +33 -0
  89. package/src/sql/write/build-insert-query.js +42 -0
  90. package/src/sql/write/build-update-query.js +65 -0
  91. package/src/utils/assert.js +34 -27
  92. package/src/utils/delta-tracker/.archive/1 tracker-redesign-codex-v2.md +250 -0
  93. package/src/utils/delta-tracker/.archive/1 tracker-redesign-gemini.md +101 -0
  94. package/src/utils/delta-tracker/.archive/2 evaluation by gemini.txt +65 -0
  95. package/src/utils/delta-tracker/.archive/2 evaluation by grok.txt +39 -0
  96. package/src/utils/delta-tracker/.archive/3 gemini evaluate grok.txt +37 -0
  97. package/src/utils/delta-tracker/.archive/3 grok evaluate gemini.txt +63 -0
  98. package/src/utils/delta-tracker/.archive/4 gemini veredict.txt +16 -0
  99. package/src/utils/delta-tracker/.archive/index.1.js +587 -0
  100. package/src/utils/delta-tracker/.archive/index.2.js +612 -0
  101. package/src/utils/delta-tracker/index.js +592 -0
  102. package/src/utils/dirty-tracker/inline.js +335 -0
  103. package/src/utils/dirty-tracker/instance.js +414 -0
  104. package/src/utils/dirty-tracker/static.js +343 -0
  105. package/src/utils/json-safe.js +13 -9
  106. package/src/utils/object-path.js +227 -33
  107. package/src/utils/object.js +408 -168
  108. package/src/utils/string.js +55 -0
  109. package/src/utils/value.js +169 -30
  110. package/docs/api.md +0 -152
  111. package/src/connection/disconnect.js +0 -16
  112. package/src/connection/pool-store.js +0 -46
  113. package/src/model/model-factory.js +0 -555
  114. package/src/query/limit-skip-compiler.js +0 -31
  115. package/src/query/operators/elem-match.js +0 -3
  116. package/src/query/operators/eq.js +0 -6
  117. package/src/query/operators/has-key.js +0 -6
  118. package/src/query/operators/index.js +0 -60
  119. package/src/query/operators/ne.js +0 -6
  120. package/src/query/query-builder.js +0 -93
  121. package/src/query/sort-compiler.js +0 -30
  122. package/src/query/where-compiler.js +0 -477
  123. package/src/sql/sql-runner.js +0 -31
@@ -0,0 +1,128 @@
1
+ import debug_logger from '#src/debug/debug-logger.js';
2
+ import defaults from '#src/constants/defaults.js';
3
+ import ModelOverwriteError from '#src/errors/model-overwrite-error.js';
4
+ import model_factory from '#src/model/factory/index.js';
5
+ import {assert_condition, assert_identifier} from '#src/utils/assert.js';
6
+ import {are_equal} from '#src/utils/object.js';
7
+ import {pluralize} from '#src/utils/string.js';
8
+ import {is_function, is_plain_object} from '#src/utils/value.js';
9
+
10
+ /**
11
+ * Stores connection-owned runtime state and model registration.
12
+ *
13
+ * @param {*} pool_instance Backing pg pool instance.
14
+ * @param {object} options Normalized connection options.
15
+ * @param {*} server_capabilities Capability snapshot for this pool.
16
+ * @returns {void}
17
+ */
18
+ function Connection(pool_instance, options, server_capabilities) {
19
+ this.pool_instance = pool_instance;
20
+ this.options = Object.assign({}, defaults.connection_options, options);
21
+ this.server_capabilities = server_capabilities || null;
22
+ this.models = {};
23
+ }
24
+
25
+ /**
26
+ * Registers a model on this connection.
27
+ *
28
+ * @param {object} model_definition Model registration input.
29
+ * @param {string} model_definition.name Model registry key.
30
+ * @param {*} model_definition.schema Schema instance.
31
+ * @param {string} [model_definition.table_name] Explicit table name override.
32
+ * @returns {Function}
33
+ * @throws {Error} When the definition is invalid.
34
+ * @throws {ModelOverwriteError} When an existing model is redefined with different schema/options.
35
+ */
36
+ Connection.prototype.model = function (model_definition) {
37
+ assert_condition(is_plain_object(model_definition), 'model_definition is required');
38
+
39
+ const model_name = model_definition.name;
40
+ const schema_instance = model_definition.schema;
41
+
42
+ assert_identifier(model_name, 'model_definition.name');
43
+
44
+ const existing_model = this.models[model_name];
45
+ const model_options = create_model_options(model_definition);
46
+ const requested_definition = {
47
+ name: model_name,
48
+ schema_instance,
49
+ model_options
50
+ };
51
+
52
+ if(existing_model) {
53
+ assert_model_definition_match(existing_model, requested_definition);
54
+ return existing_model;
55
+ }
56
+
57
+ const Model = model_factory(model_name, schema_instance, model_options, this);
58
+
59
+ this.models[model_name] = Model;
60
+ return Model;
61
+ };
62
+
63
+ /**
64
+ * Closes the underlying pool for this connection.
65
+ *
66
+ * @returns {Promise<void>}
67
+ */
68
+ Connection.prototype.disconnect = async function () {
69
+ const pool_instance = this.pool_instance;
70
+
71
+ if(!pool_instance || !is_function(pool_instance.end)) {
72
+ return;
73
+ }
74
+
75
+ await pool_instance.end();
76
+
77
+ debug_logger(this.options.debug, 'connection_closed', null);
78
+ };
79
+
80
+ /**
81
+ * Builds the model options passed into the existing model factory bridge.
82
+ *
83
+ * @param {object} model_definition Model registration input.
84
+ * @returns {object}
85
+ */
86
+ function create_model_options(model_definition) {
87
+ const {name, schema, ...model_options} = model_definition;
88
+ void name;
89
+ void schema;
90
+
91
+ if(!model_options.table_name) {
92
+ model_options.table_name = pluralize(model_definition.name);
93
+ }
94
+
95
+ return model_options;
96
+ }
97
+
98
+ /**
99
+ * Enforces idempotent model registration on a connection.
100
+ *
101
+ * Re-registering the same model name is allowed only when schema and
102
+ * normalized model options match the existing model.
103
+ *
104
+ * @param {Function} existing_model
105
+ * @param {object} requested_definition
106
+ * @throws {ModelOverwriteError}
107
+ */
108
+ function assert_model_definition_match(existing_model, requested_definition) {
109
+ const {
110
+ name,
111
+ schema_instance,
112
+ model_options
113
+ } = requested_definition;
114
+
115
+ if(existing_model.schema !== schema_instance) {
116
+ throw new ModelOverwriteError('model "' + name + '" is already registered with a different schema', {
117
+ name
118
+ });
119
+ }
120
+
121
+ if(!are_equal(existing_model.options, model_options)) {
122
+ throw new ModelOverwriteError('model "' + name + '" is already registered with different model options', {
123
+ name
124
+ });
125
+ }
126
+ }
127
+
128
+ export default Connection;
@@ -1,59 +1,60 @@
1
- import IdStrategies from '#src/constants/id-strategies.js';
2
- import {assert_condition} from '#src/utils/assert.js';
3
-
4
- const MIN_POSTGRES_NATIVE_UUIDV7_VERSION_NUM = 180000;
5
-
6
- async function scan_server_capabilities(pool_instance) {
7
- assert_condition(pool_instance && typeof pool_instance.query === 'function', 'pool_instance.query is required');
8
-
9
- const server_version_num_result = await pool_instance.query('SHOW server_version_num;');
10
- const server_version_result = await pool_instance.query('SHOW server_version;');
11
- const uuidv7_function_result = await pool_instance.query(
12
- "SELECT to_regprocedure('uuidv7()') IS NOT NULL AS has_uuidv7_function;"
13
- );
14
-
15
- const server_version_num_text = server_version_num_result.rows?.[0]?.server_version_num;
16
- const server_version = server_version_result.rows?.[0]?.server_version;
17
- const has_uuidv7_function = uuidv7_function_result.rows?.[0]?.has_uuidv7_function === true;
18
- const server_version_num = Number.parseInt(String(server_version_num_text), 10);
19
-
20
- assert_condition(Number.isInteger(server_version_num), 'Unable to determine PostgreSQL server_version_num');
21
- assert_condition(typeof server_version === 'string' && server_version.length > 0, 'Unable to determine PostgreSQL server_version');
22
-
23
- const supports_uuidv7 = server_version_num >= MIN_POSTGRES_NATIVE_UUIDV7_VERSION_NUM && has_uuidv7_function;
24
-
25
- return {
26
- server_version: server_version,
27
- server_version_num: server_version_num,
28
- supports_uuidv7: supports_uuidv7
29
- };
30
- }
31
-
32
- function assert_id_strategy_capability(id_strategy, server_capabilities) {
33
- if(id_strategy !== IdStrategies.uuidv7) {
34
- return;
35
- }
36
-
37
- assert_condition(
38
- server_capabilities && typeof server_capabilities === 'object',
39
- 'PostgreSQL server capabilities are unavailable. Reconnect so jsonbadger can run compatibility checks for id_strategy=uuidv7.'
40
- );
41
-
42
- assert_condition(server_capabilities.supports_uuidv7 === true, build_uuidv7_capability_error(server_capabilities));
43
- }
44
-
45
- function build_uuidv7_capability_error(server_capabilities) {
46
- const server_version = server_capabilities.server_version ?? 'unknown';
47
- const server_version_num = server_capabilities.server_version_num ?? 'unknown';
48
- const supports_uuidv7 = server_capabilities.supports_uuidv7 === true ? 'true' : 'false';
49
-
50
- return 'id_strategy=uuidv7 requires PostgreSQL native uuidv7() support (PostgreSQL 18+). ' +
51
- 'Detected server_version=' + server_version + ', server_version_num=' + server_version_num +
52
- ', supports_uuidv7=' + supports_uuidv7 + '.';
53
- }
54
-
55
- export {
56
- MIN_POSTGRES_NATIVE_UUIDV7_VERSION_NUM,
57
- scan_server_capabilities,
58
- assert_id_strategy_capability
59
- };
1
+ import ID_STRATEGY from '#src/constants/id-strategy.js';
2
+ import {assert_condition} from '#src/utils/assert.js';
3
+ import {is_function} from '#src/utils/value.js';
4
+
5
+ const MIN_POSTGRES_NATIVE_UUIDV7_VERSION_NUM = 180000;
6
+
7
+ async function scan_server_capabilities(pool_instance) {
8
+ assert_condition(pool_instance && is_function(pool_instance.query), 'pool_instance.query is required');
9
+
10
+ const server_version_num_result = await pool_instance.query('SHOW server_version_num;');
11
+ const server_version_result = await pool_instance.query('SHOW server_version;');
12
+ const uuidv7_function_result = await pool_instance.query(
13
+ "SELECT to_regprocedure('uuidv7()') IS NOT NULL AS has_uuidv7_function;"
14
+ );
15
+
16
+ const server_version_num_text = server_version_num_result.rows?.[0]?.server_version_num;
17
+ const server_version = server_version_result.rows?.[0]?.server_version;
18
+ const has_uuidv7_function = uuidv7_function_result.rows?.[0]?.has_uuidv7_function === true;
19
+ const server_version_num = Number.parseInt(String(server_version_num_text), 10);
20
+
21
+ assert_condition(Number.isInteger(server_version_num), 'Unable to determine PostgreSQL server_version_num');
22
+ assert_condition(typeof server_version === 'string' && server_version.length > 0, 'Unable to determine PostgreSQL server_version');
23
+
24
+ const supports_uuidv7 = server_version_num >= MIN_POSTGRES_NATIVE_UUIDV7_VERSION_NUM && has_uuidv7_function;
25
+
26
+ return {
27
+ server_version: server_version,
28
+ server_version_num: server_version_num,
29
+ supports_uuidv7: supports_uuidv7
30
+ };
31
+ }
32
+
33
+ function assert_id_strategy_capability(id_strategy, server_capabilities) {
34
+ if(id_strategy !== ID_STRATEGY.uuidv7) {
35
+ return;
36
+ }
37
+
38
+ assert_condition(
39
+ server_capabilities && typeof server_capabilities === 'object',
40
+ 'PostgreSQL server capabilities are unavailable. Reconnect so jsonbadger can run compatibility checks for id_strategy=uuidv7.'
41
+ );
42
+
43
+ assert_condition(server_capabilities.supports_uuidv7 === true, build_uuidv7_capability_error(server_capabilities));
44
+ }
45
+
46
+ function build_uuidv7_capability_error(server_capabilities) {
47
+ const server_version = server_capabilities.server_version ?? 'unknown';
48
+ const server_version_num = server_capabilities.server_version_num ?? 'unknown';
49
+ const supports_uuidv7 = server_capabilities.supports_uuidv7 === true ? 'true' : 'false';
50
+
51
+ return 'id_strategy=uuidv7 requires PostgreSQL native uuidv7() support (PostgreSQL 18+). ' +
52
+ 'Detected server_version=' + server_version + ', server_version_num=' + server_version_num +
53
+ ', supports_uuidv7=' + supports_uuidv7 + '.';
54
+ }
55
+
56
+ export {
57
+ MIN_POSTGRES_NATIVE_UUIDV7_VERSION_NUM,
58
+ scan_server_capabilities,
59
+ assert_id_strategy_capability
60
+ };
@@ -1,20 +1,33 @@
1
- import IdStrategies from '#src/constants/id-strategies.js';
2
-
3
- const defaults = {
4
- connection_options: {
5
- max: 10,
6
- debug: false,
7
- auto_index: true,
8
- id_strategy: IdStrategies.bigserial
9
- },
10
-
11
- schema_options: {},
12
- model_options: {
13
- table_name: null,
14
- data_column: 'data',
15
- auto_index: null,
16
- id_strategy: null
17
- }
18
- };
19
-
1
+ import ID_STRATEGY from '#src/constants/id-strategy.js';
2
+
3
+ // TODO: add `model_options.timestamps` as a real config flag and wire its behavior
4
+ // through model lifecycle defaults, docs, and update/insert timestamp handling.
5
+ const DEFAULT_SLUG = 'data';
6
+
7
+ const defaults = {
8
+ connection_options: {
9
+ max: 10,
10
+ debug: false
11
+ },
12
+
13
+ schema_options: {
14
+ id_strategy: ID_STRATEGY.uuidv7,
15
+ auto_index: true,
16
+
17
+ default_slug: DEFAULT_SLUG,
18
+ slugs: [],
19
+ /*
20
+ timestamps: true,
21
+ */
22
+ },
23
+
24
+ model_options: {
25
+ table_name: null,
26
+
27
+ // TODO: we'll deal with data_column later
28
+ data_column: DEFAULT_SLUG,
29
+
30
+ }
31
+ };
32
+
20
33
  export default defaults;
@@ -1,29 +1,28 @@
1
- import {assert_condition} from '#src/utils/assert.js';
2
-
3
- const IdStrategies = Object.freeze({
4
- bigserial: 'bigserial',
5
- uuidv7: 'uuidv7'
6
- });
7
-
8
- const id_strategy_values = Object.freeze(Object.values(IdStrategies));
9
-
10
- function is_valid(id_strategy) {
11
- return id_strategy_values.includes(id_strategy);
12
- }
13
-
14
- function id_strategy_error() {
15
- return 'id_strategy must be one of: ' + id_strategy_values.join(', ');
16
- }
17
-
18
- // TODO: consider moving this to assert file
19
- function assert_valid_id_strategy(id_strategy) {
20
- assert_condition(is_valid(id_strategy), id_strategy_error());
21
- }
22
-
23
- export {
24
- IdStrategies,
25
- is_valid,
26
- assert_valid_id_strategy
27
- };
28
-
29
- export default IdStrategies;
1
+ import {assert_condition} from '#src/utils/assert.js';
2
+
3
+ const ID_STRATEGY = Object.freeze({
4
+ bigserial: 'bigserial',
5
+ uuidv7: 'uuidv7'
6
+ });
7
+
8
+ const id_strategy_values = Object.freeze(Object.values(ID_STRATEGY));
9
+
10
+ function is_valid(id_strategy) {
11
+ return id_strategy_values.includes(id_strategy);
12
+ }
13
+
14
+ function id_strategy_error() {
15
+ return 'id_strategy must be one of: ' + id_strategy_values.join(', ');
16
+ }
17
+
18
+ function assert_id_strategy(id_strategy) {
19
+ assert_condition(is_valid(id_strategy), id_strategy_error());
20
+ }
21
+
22
+ export {
23
+ ID_STRATEGY,
24
+ is_valid,
25
+ assert_id_strategy
26
+ };
27
+
28
+ export default ID_STRATEGY;
@@ -0,0 +1,8 @@
1
+ const INTAKE_MODE = Object.freeze({
2
+ from: 'from',
3
+ hydrate: 'hydrate'
4
+ });
5
+
6
+ export {INTAKE_MODE};
7
+
8
+ export default INTAKE_MODE;
@@ -1,15 +1,17 @@
1
- import safe_json_stringify from '#src/utils/json-safe.js';
2
-
3
- export default function debug_logger(debug_mode, event_name, event_data) {
4
- if(!debug_mode) {
5
- return;
6
- }
7
-
8
- const log_entry = {
9
- event_name: event_name,
10
- event_data: event_data || null,
11
- created_at: new Date().toISOString()
12
- };
13
-
14
- console.log('[jsonbadger][debug] ' + safe_json_stringify(log_entry));
15
- }
1
+ import safe_json_stringify from '#src/utils/json-safe.js';
2
+
3
+ function debug_logger(debug_mode, event_name, event_data) {
4
+ if(!debug_mode) {
5
+ return;
6
+ }
7
+
8
+ const log_entry = {
9
+ event_name: event_name,
10
+ event_data: event_data || null,
11
+ created_at: new Date().toISOString()
12
+ };
13
+
14
+ console.log('[jsonbadger][debug] ' + safe_json_stringify(log_entry));
15
+ }
16
+
17
+ export default debug_logger;
@@ -0,0 +1,25 @@
1
+ function ModelOverwriteError(message, details) {
2
+ this.name = 'model_overwrite_error';
3
+ this.message = message || 'Model overwrite failed';
4
+ this.details = details || null;
5
+
6
+ if(Error.captureStackTrace) {
7
+ Error.captureStackTrace(this, ModelOverwriteError);
8
+ }
9
+ }
10
+
11
+ ModelOverwriteError.prototype = Object.create(Error.prototype);
12
+ ModelOverwriteError.prototype.constructor = ModelOverwriteError;
13
+
14
+ ModelOverwriteError.prototype.to_json = function () {
15
+ return {
16
+ success: false,
17
+ error: {
18
+ type: 'model_overwrite_error',
19
+ message: this.message,
20
+ details: this.details
21
+ }
22
+ };
23
+ };
24
+
25
+ export default ModelOverwriteError;
@@ -1,23 +1,25 @@
1
- export default function QueryError(message, details) {
2
- this.name = 'query_error';
3
- this.message = message || 'Query failed';
4
- this.details = details || null;
5
-
6
- if(Error.captureStackTrace) {
7
- Error.captureStackTrace(this, QueryError);
8
- }
9
- }
10
-
11
- QueryError.prototype = Object.create(Error.prototype);
12
- QueryError.prototype.constructor = QueryError;
13
-
14
- QueryError.prototype.to_json = function () {
15
- return {
16
- success: false,
17
- error: {
18
- type: 'query_error',
19
- message: this.message,
20
- details: this.details
21
- }
22
- };
23
- };
1
+ function QueryError(message, details) {
2
+ this.name = 'query_error';
3
+ this.message = message || 'Query failed';
4
+ this.details = details || null;
5
+
6
+ if(Error.captureStackTrace) {
7
+ Error.captureStackTrace(this, QueryError);
8
+ }
9
+ }
10
+
11
+ QueryError.prototype = Object.create(Error.prototype);
12
+ QueryError.prototype.constructor = QueryError;
13
+
14
+ QueryError.prototype.to_json = function () {
15
+ return {
16
+ success: false,
17
+ error: {
18
+ type: 'query_error',
19
+ message: this.message,
20
+ details: this.details
21
+ }
22
+ };
23
+ };
24
+
25
+ export default QueryError;
@@ -1,23 +1,25 @@
1
- export default function ValidationError(message, details) {
2
- this.name = 'validation_error';
3
- this.message = message || 'Validation failed';
4
- this.details = details || null;
5
-
6
- if(Error.captureStackTrace) {
7
- Error.captureStackTrace(this, ValidationError);
8
- }
9
- }
10
-
11
- ValidationError.prototype = Object.create(Error.prototype);
12
- ValidationError.prototype.constructor = ValidationError;
13
-
14
- ValidationError.prototype.to_json = function () {
15
- return {
16
- success: false,
17
- error: {
18
- type: 'validation_error',
19
- message: this.message,
20
- details: this.details
21
- }
22
- };
23
- };
1
+ function ValidationError(message, details) {
2
+ this.name = 'validation_error';
3
+ this.message = message || 'Validation failed';
4
+ this.details = details || null;
5
+
6
+ if(Error.captureStackTrace) {
7
+ Error.captureStackTrace(this, ValidationError);
8
+ }
9
+ }
10
+
11
+ ValidationError.prototype = Object.create(Error.prototype);
12
+ ValidationError.prototype.constructor = ValidationError;
13
+
14
+ ValidationError.prototype.to_json = function () {
15
+ return {
16
+ success: false,
17
+ error: {
18
+ type: 'validation_error',
19
+ message: this.message,
20
+ details: this.details
21
+ }
22
+ };
23
+ };
24
+
25
+ export default ValidationError;