prostgles-server 3.0.134 → 3.0.135

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.
@@ -1 +1 @@
1
- {"version":3,"file":"validate_jsonb_schema_sql.d.ts","sourceRoot":"","sources":["../../lib/JSONBValidation/validate_jsonb_schema_sql.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,wBAAwB,yBAAmC,CAAC;AACzE,eAAO,MAAM,yBAAyB,QA6ZrC,CAAC"}
1
+ {"version":3,"file":"validate_jsonb_schema_sql.d.ts","sourceRoot":"","sources":["../../lib/JSONBValidation/validate_jsonb_schema_sql.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,wBAAwB,yBAAmC,CAAC;AACzE,eAAO,MAAM,yBAAyB,QAscrC,CAAC"}
@@ -51,6 +51,15 @@ DECLARE
51
51
  $d$;
52
52
 
53
53
  extra_keys TEXT[];
54
+
55
+ /* Used for oneOf schema errors */
56
+ v_state TEXT;
57
+ v_msg TEXT;
58
+ v_detail TEXT;
59
+ v_hint TEXT;
60
+ v_context TEXT;
61
+ v_one_of_errors TEXT;
62
+
54
63
  BEGIN
55
64
  path = concat_ws(', ',
56
65
  'Path: ' || array_to_string(checked_path, '.'),
@@ -63,6 +72,9 @@ BEGIN
63
72
  RAISE EXCEPTION 'Empty schema. %', path USING HINT = path, COLUMN = colname;
64
73
  END IF;
65
74
 
75
+ /* Sometimes text comes double quoted from jsonb, e.g.: '"string"' */
76
+ jsonb_schema = CASE WHEN jsonb_schema::text ilike '"%"' THEN LEFT(RIGHT(jsonb_schema::text, -1), -1) ELSE jsonb_schema END;
77
+
66
78
  /* 'string' */
67
79
  IF ARRAY[jsonb_schema] <@ allowed_types THEN
68
80
  schema = jsonb_build_object('type', jsonb_schema);
@@ -250,7 +262,8 @@ BEGIN
250
262
  END IF;
251
263
 
252
264
  FOR sub_schema IN
253
- SELECT CASE WHEN schema ? 'oneOfType' THEN jsonb_build_object('type', value) ELSE value END as value
265
+ SELECT CASE WHEN schema ? 'oneOfType' THEN jsonb_build_object('type', value) ELSE value END as value,
266
+ row_number() over() - 1 as idx
254
267
  FROM jsonb_array_elements(oneof)
255
268
  LOOP
256
269
 
@@ -266,10 +279,35 @@ BEGIN
266
279
 
267
280
  /* Ignore exceptions in case the last schema will match */
268
281
  EXCEPTION WHEN others THEN
282
+
283
+ GET STACKED DIAGNOSTICS
284
+ v_state = returned_sqlstate,
285
+ v_msg = message_text,
286
+ v_detail = pg_exception_detail,
287
+ v_hint = pg_exception_hint,
288
+ v_context = pg_exception_context;
289
+
290
+ /* Ignore duplicate errors */
291
+ IF v_one_of_errors IS NULL OR v_one_of_errors NOT ilike '%' || v_msg || '%' THEN
292
+ v_one_of_errors = concat_ws(
293
+ E'\n',
294
+ v_one_of_errors,
295
+ concat_ws(
296
+ ', ',
297
+ 'Schema index ' || sub_schema.idx::TEXT || ' error:',
298
+ 'state: ' || v_state,
299
+ 'message: ' || v_msg,
300
+ 'detail: ' || v_detail,
301
+ 'hint: ' || v_hint
302
+ -- 'context: ' || v_context
303
+ )
304
+ );
305
+ END IF;
269
306
  END;
307
+
270
308
  END LOOP;
271
309
 
272
- RAISE EXCEPTION 'Could not validate against any oneOf schemas ( % ), %', oneof::TEXT, path USING HINT = path, COLUMN = colname;
310
+ RAISE EXCEPTION 'Could not validate against any oneOf schemas ( % ), %', v_one_of_errors, path;-- USING HINT = path, COLUMN = colname;
273
311
 
274
312
  /* arrayOfType: { key_name: { type: "string" } } */
275
313
  ELSIF (schema ? 'arrayOf' OR schema ? 'arrayOfType') THEN
@@ -416,5 +454,8 @@ SELECT ${exports.VALIDATE_SCHEMA_FUNCNAME}('{ "lookup": { "type": "schema", "obj
416
454
 
417
455
  SELECT ${exports.VALIDATE_SCHEMA_FUNCNAME}('{ "type": "time"}', '"22:22"');
418
456
  SELECT ${exports.VALIDATE_SCHEMA_FUNCNAME}('{ "type": "Date"}', '"2222-22-22"');
457
+
458
+
459
+ SELECT ${exports.VALIDATE_SCHEMA_FUNCNAME}('{ "oneOf": ["number"]}','2');
419
460
  `;
420
461
  //# sourceMappingURL=validate_jsonb_schema_sql.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate_jsonb_schema_sql.js","sourceRoot":"","sources":["../../lib/JSONBValidation/validate_jsonb_schema_sql.ts"],"names":[],"mappings":";;;AAAA,kEAA+D;AAGlD,QAAA,wBAAwB,GAAG,uBAAgC,CAAC;AAC5D,QAAA,yBAAyB,GAAG;;;IAGrC,6BAAa,CAAC,kCAAkC;;;4BAGxB,gCAAwB;;6BAEvB,gCAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAsFxC,gCAAwB;;;;;;;;;;aAUxB,gCAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAuClB,gCAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBA8EvB,gCAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAgC/B,gCAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA4BtB,gCAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6EAgCsC,gCAAwB;;;;;;oEAMjC,gCAAwB;;;;;;;;;;;;;;;sBAetE,gCAAwB,QAAQ,6BAAa,CAAC,kCAAkC;;;;;;;;;;;;SAY7F,gCAAwB;;;;;;SAMxB,gCAAwB;;;;;SAKxB,gCAAwB;;;;SAIxB,gCAAwB;;;;;SAKxB,gCAAwB;;;;;;;;;;;;;;;;SAgBxB,gCAAwB;;;;;SAKxB,gCAAwB;;;;;SAKxB,gCAAwB;;;;;SAKxB,gCAAwB;;SAExB,gCAAwB;;SAExB,gCAAwB;;;SAGxB,gCAAwB;SACxB,gCAAwB;SACxB,gCAAwB;SACxB,gCAAwB;SACxB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;SACxB,gCAAwB;SACxB,gCAAwB;;SAExB,gCAAwB;SACxB,gCAAwB;;;SAGxB,gCAAwB;CAChC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"validate_jsonb_schema_sql.d.ts","sourceRoot":"","sources":["validate_jsonb_schema_sql.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,wBAAwB,yBAAmC,CAAC;AACzE,eAAO,MAAM,yBAAyB,QA6ZrC,CAAC"}
1
+ {"version":3,"file":"validate_jsonb_schema_sql.d.ts","sourceRoot":"","sources":["validate_jsonb_schema_sql.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,wBAAwB,yBAAmC,CAAC;AACzE,eAAO,MAAM,yBAAyB,QAscrC,CAAC"}
@@ -51,6 +51,15 @@ DECLARE
51
51
  $d$;
52
52
 
53
53
  extra_keys TEXT[];
54
+
55
+ /* Used for oneOf schema errors */
56
+ v_state TEXT;
57
+ v_msg TEXT;
58
+ v_detail TEXT;
59
+ v_hint TEXT;
60
+ v_context TEXT;
61
+ v_one_of_errors TEXT;
62
+
54
63
  BEGIN
55
64
  path = concat_ws(', ',
56
65
  'Path: ' || array_to_string(checked_path, '.'),
@@ -63,6 +72,9 @@ BEGIN
63
72
  RAISE EXCEPTION 'Empty schema. %', path USING HINT = path, COLUMN = colname;
64
73
  END IF;
65
74
 
75
+ /* Sometimes text comes double quoted from jsonb, e.g.: '"string"' */
76
+ jsonb_schema = CASE WHEN jsonb_schema::text ilike '"%"' THEN LEFT(RIGHT(jsonb_schema::text, -1), -1) ELSE jsonb_schema END;
77
+
66
78
  /* 'string' */
67
79
  IF ARRAY[jsonb_schema] <@ allowed_types THEN
68
80
  schema = jsonb_build_object('type', jsonb_schema);
@@ -250,7 +262,8 @@ BEGIN
250
262
  END IF;
251
263
 
252
264
  FOR sub_schema IN
253
- SELECT CASE WHEN schema ? 'oneOfType' THEN jsonb_build_object('type', value) ELSE value END as value
265
+ SELECT CASE WHEN schema ? 'oneOfType' THEN jsonb_build_object('type', value) ELSE value END as value,
266
+ row_number() over() - 1 as idx
254
267
  FROM jsonb_array_elements(oneof)
255
268
  LOOP
256
269
 
@@ -266,10 +279,35 @@ BEGIN
266
279
 
267
280
  /* Ignore exceptions in case the last schema will match */
268
281
  EXCEPTION WHEN others THEN
282
+
283
+ GET STACKED DIAGNOSTICS
284
+ v_state = returned_sqlstate,
285
+ v_msg = message_text,
286
+ v_detail = pg_exception_detail,
287
+ v_hint = pg_exception_hint,
288
+ v_context = pg_exception_context;
289
+
290
+ /* Ignore duplicate errors */
291
+ IF v_one_of_errors IS NULL OR v_one_of_errors NOT ilike '%' || v_msg || '%' THEN
292
+ v_one_of_errors = concat_ws(
293
+ E'\n',
294
+ v_one_of_errors,
295
+ concat_ws(
296
+ ', ',
297
+ 'Schema index ' || sub_schema.idx::TEXT || ' error:',
298
+ 'state: ' || v_state,
299
+ 'message: ' || v_msg,
300
+ 'detail: ' || v_detail,
301
+ 'hint: ' || v_hint
302
+ -- 'context: ' || v_context
303
+ )
304
+ );
305
+ END IF;
269
306
  END;
307
+
270
308
  END LOOP;
271
309
 
272
- RAISE EXCEPTION 'Could not validate against any oneOf schemas ( % ), %', oneof::TEXT, path USING HINT = path, COLUMN = colname;
310
+ RAISE EXCEPTION 'Could not validate against any oneOf schemas ( % ), %', v_one_of_errors, path;-- USING HINT = path, COLUMN = colname;
273
311
 
274
312
  /* arrayOfType: { key_name: { type: "string" } } */
275
313
  ELSIF (schema ? 'arrayOf' OR schema ? 'arrayOfType') THEN
@@ -416,4 +454,7 @@ SELECT ${exports.VALIDATE_SCHEMA_FUNCNAME}('{ "lookup": { "type": "schema", "obj
416
454
 
417
455
  SELECT ${exports.VALIDATE_SCHEMA_FUNCNAME}('{ "type": "time"}', '"22:22"');
418
456
  SELECT ${exports.VALIDATE_SCHEMA_FUNCNAME}('{ "type": "Date"}', '"2222-22-22"');
457
+
458
+
459
+ SELECT ${exports.VALIDATE_SCHEMA_FUNCNAME}('{ "oneOf": ["number"]}','2');
419
460
  `;
@@ -50,6 +50,15 @@ DECLARE
50
50
  $d$;
51
51
 
52
52
  extra_keys TEXT[];
53
+
54
+ /* Used for oneOf schema errors */
55
+ v_state TEXT;
56
+ v_msg TEXT;
57
+ v_detail TEXT;
58
+ v_hint TEXT;
59
+ v_context TEXT;
60
+ v_one_of_errors TEXT;
61
+
53
62
  BEGIN
54
63
  path = concat_ws(', ',
55
64
  'Path: ' || array_to_string(checked_path, '.'),
@@ -62,6 +71,9 @@ BEGIN
62
71
  RAISE EXCEPTION 'Empty schema. %', path USING HINT = path, COLUMN = colname;
63
72
  END IF;
64
73
 
74
+ /* Sometimes text comes double quoted from jsonb, e.g.: '"string"' */
75
+ jsonb_schema = CASE WHEN jsonb_schema::text ilike '"%"' THEN LEFT(RIGHT(jsonb_schema::text, -1), -1) ELSE jsonb_schema END;
76
+
65
77
  /* 'string' */
66
78
  IF ARRAY[jsonb_schema] <@ allowed_types THEN
67
79
  schema = jsonb_build_object('type', jsonb_schema);
@@ -249,7 +261,8 @@ BEGIN
249
261
  END IF;
250
262
 
251
263
  FOR sub_schema IN
252
- SELECT CASE WHEN schema ? 'oneOfType' THEN jsonb_build_object('type', value) ELSE value END as value
264
+ SELECT CASE WHEN schema ? 'oneOfType' THEN jsonb_build_object('type', value) ELSE value END as value,
265
+ row_number() over() - 1 as idx
253
266
  FROM jsonb_array_elements(oneof)
254
267
  LOOP
255
268
 
@@ -265,10 +278,35 @@ BEGIN
265
278
 
266
279
  /* Ignore exceptions in case the last schema will match */
267
280
  EXCEPTION WHEN others THEN
281
+
282
+ GET STACKED DIAGNOSTICS
283
+ v_state = returned_sqlstate,
284
+ v_msg = message_text,
285
+ v_detail = pg_exception_detail,
286
+ v_hint = pg_exception_hint,
287
+ v_context = pg_exception_context;
288
+
289
+ /* Ignore duplicate errors */
290
+ IF v_one_of_errors IS NULL OR v_one_of_errors NOT ilike '%' || v_msg || '%' THEN
291
+ v_one_of_errors = concat_ws(
292
+ E'\n',
293
+ v_one_of_errors,
294
+ concat_ws(
295
+ ', ',
296
+ 'Schema index ' || sub_schema.idx::TEXT || ' error:',
297
+ 'state: ' || v_state,
298
+ 'message: ' || v_msg,
299
+ 'detail: ' || v_detail,
300
+ 'hint: ' || v_hint
301
+ -- 'context: ' || v_context
302
+ )
303
+ );
304
+ END IF;
268
305
  END;
306
+
269
307
  END LOOP;
270
308
 
271
- RAISE EXCEPTION 'Could not validate against any oneOf schemas ( % ), %', oneof::TEXT, path USING HINT = path, COLUMN = colname;
309
+ RAISE EXCEPTION 'Could not validate against any oneOf schemas ( % ), %', v_one_of_errors, path;-- USING HINT = path, COLUMN = colname;
272
310
 
273
311
  /* arrayOfType: { key_name: { type: "string" } } */
274
312
  ELSIF (schema ? 'arrayOf' OR schema ? 'arrayOfType') THEN
@@ -415,5 +453,8 @@ SELECT ${VALIDATE_SCHEMA_FUNCNAME}('{ "lookup": { "type": "schema", "object": "c
415
453
 
416
454
  SELECT ${VALIDATE_SCHEMA_FUNCNAME}('{ "type": "time"}', '"22:22"');
417
455
  SELECT ${VALIDATE_SCHEMA_FUNCNAME}('{ "type": "Date"}', '"2222-22-22"');
456
+
457
+
458
+ SELECT ${VALIDATE_SCHEMA_FUNCNAME}('{ "oneOf": ["number"]}','2');
418
459
  `;
419
460
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prostgles-server",
3
- "version": "3.0.134",
3
+ "version": "3.0.135",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1 +1 @@
1
- 104759
1
+ 13103
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "../..": {
23
23
  "name": "prostgles-server",
24
- "version": "3.0.133",
24
+ "version": "3.0.134",
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
27
  "@aws-sdk/client-s3": "^3.272.0",