prostgles-server 2.0.130 → 2.0.134

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.
@@ -176,7 +176,6 @@ async function isomorphic(db) {
176
176
  });
177
177
  await tryRun("$unnest_words", async () => {
178
178
  const res = await db.various.find({}, { returnType: "values", select: { name: "$unnest_words" } });
179
- console.trace(res);
180
179
  assert_1.strict.deepStrictEqual(res, [
181
180
  'abc9',
182
181
  'abc1',
@@ -378,238 +377,244 @@ async function isomorphic(db) {
378
377
  console.log("TODO: socket.io stringifies dates");
379
378
  });
380
379
  await tryRun("Postgis examples", async () => {
381
- await db.shapes.delete();
382
- const p1 = { ST_GeomFromText: ["POINT(-1 1)", 4326] }, p2 = { ST_GeomFromText: ["POINT(-2 2)", 4326] };
383
- await db.shapes.insert([
384
- { geom: p1, geog: p1 },
385
- { geom: p2, geog: p2 },
386
- ]);
387
- /** Basic functions and extent filters */
388
- const f = await db.shapes.findOne({ $and: [
389
- { "geom.&&.st_makeenvelope": [
390
- -3, 2,
391
- -2, 2
392
- ] },
393
- { "geog.&&.st_makeenvelope": [
394
- -3, 2,
395
- -2, 2
396
- ] }
397
- ]
398
- }, {
399
- select: {
400
- geomTxt: { "$ST_AsText": ["geom"] },
401
- geomGeo: { "$ST_AsGeoJSON": ["geom"] },
402
- },
403
- orderBy: "geom"
380
+ await tryRun("Postgis examples", async () => {
381
+ await db.shapes.delete();
382
+ const p1 = { ST_GeomFromText: ["POINT(-1 1)", 4326] }, p2 = { ST_GeomFromText: ["POINT(-2 2)", 4326] };
383
+ await db.shapes.insert([
384
+ { geom: p1, geog: p1 },
385
+ { geom: p2, geog: p2 },
386
+ ]);
387
+ /** Basic functions and extent filters */
388
+ const f = await db.shapes.findOne({ $and: [
389
+ { "geom.&&.st_makeenvelope": [
390
+ -3, 2,
391
+ -2, 2
392
+ ] },
393
+ { "geog.&&.st_makeenvelope": [
394
+ -3, 2,
395
+ -2, 2
396
+ ] }
397
+ ]
398
+ }, {
399
+ select: {
400
+ geomTxt: { "$ST_AsText": ["geom"] },
401
+ geomGeo: { "$ST_AsGeoJSON": ["geom"] },
402
+ },
403
+ orderBy: "geom"
404
+ });
405
+ assert_1.strict.deepStrictEqual(f, {
406
+ geomGeo: {
407
+ coordinates: [-2, 2],
408
+ type: 'Point'
409
+ },
410
+ geomTxt: 'POINT(-2 2)'
411
+ });
412
+ /**Aggregate functions */
413
+ const aggs = await db.shapes.findOne({}, {
414
+ select: {
415
+ xMin: { "$ST_XMin_Agg": ["geom"] },
416
+ xMax: { "$ST_XMax_Agg": ["geom"] },
417
+ yMin: { "$ST_YMin_Agg": ["geom"] },
418
+ yMax: { "$ST_YMax_Agg": ["geom"] },
419
+ zMin: { "$ST_ZMin_Agg": ["geom"] },
420
+ zMax: { "$ST_ZMax_Agg": ["geom"] },
421
+ extent: { "$ST_Extent": ["geom"] },
422
+ // extent3D: { "$ST_3DExtent": ["geom"] },
423
+ },
424
+ });
425
+ assert_1.strict.deepStrictEqual(aggs, {
426
+ xMax: -1,
427
+ xMin: -2,
428
+ yMax: 2,
429
+ yMin: 1,
430
+ zMax: 0,
431
+ zMin: 0,
432
+ extent: 'BOX(-2 1,-1 2)',
433
+ // extent3D: 'BOX3D(-2 1 0,-1 2 6.952908662134e-310)' <-- looks like a value that will fail tests at some point
434
+ });
404
435
  });
405
- assert_1.strict.deepStrictEqual(f, {
406
- geomGeo: {
407
- coordinates: [-2, 2],
408
- type: 'Point'
409
- },
410
- geomTxt: 'POINT(-2 2)'
436
+ await tryRun("Local file upload", async () => {
437
+ let str = "This is a string", data = Buffer.from(str, "utf-8"), mediaFile = { data, name: "sample_file.txt" };
438
+ const file = await db.media.insert(mediaFile, { returning: "*" });
439
+ const _data = fs.readFileSync(__dirname + "/server/media/" + file.name);
440
+ assert_1.strict.equal(str, _data.toString('utf8'));
441
+ await tryRun("Nested insert", async () => {
442
+ const { name, media: { extension, content_type, original_name } } = await db.items_with_one_media.insert({ name: "somename.txt", media: mediaFile }, { returning: "*" });
443
+ assert_1.strict.deepStrictEqual({ extension, content_type, original_name }, {
444
+ extension: 'txt',
445
+ content_type: 'text/plain',
446
+ original_name: 'sample_file.txt',
447
+ });
448
+ // const _data = fs.readFileSync(__dirname + "/server/media/"+file.name);
449
+ assert_1.strict.equal(name, "somename.txt");
450
+ });
411
451
  });
412
- /**Aggregate functions */
413
- const aggs = await db.shapes.findOne({}, {
414
- select: {
415
- xMin: { "$ST_XMin_Agg": ["geom"] },
416
- xMax: { "$ST_XMax_Agg": ["geom"] },
417
- yMin: { "$ST_YMin_Agg": ["geom"] },
418
- yMax: { "$ST_YMax_Agg": ["geom"] },
419
- zMin: { "$ST_ZMin_Agg": ["geom"] },
420
- zMax: { "$ST_ZMax_Agg": ["geom"] },
421
- extent: { "$ST_Extent": ["geom"] },
422
- // extent3D: { "$ST_3DExtent": ["geom"] },
423
- },
452
+ await tryRun("Exists filter example", async () => {
453
+ const fo = await db.items.findOne(), f = await db.items.find();
454
+ assert_1.strict.deepStrictEqual(fo, { h: null, id: 1, name: 'a' }, "findOne query failed");
455
+ assert_1.strict.deepStrictEqual(f[0], { h: null, id: 1, name: 'a' }, "findOne query failed");
424
456
  });
425
- assert_1.strict.deepStrictEqual(aggs, {
426
- xMax: -1,
427
- xMin: -2,
428
- yMax: 2,
429
- yMin: 1,
430
- zMax: 0,
431
- zMin: 0,
432
- extent: 'BOX(-2 1,-1 2)',
433
- // extent3D: 'BOX3D(-2 1 0,-1 2 6.952908662134e-310)' <-- looks like a value that will fail tests at some point
457
+ await tryRun("Result size", async () => {
458
+ const is75bits = await db.items.size({}, { select: { name: 1 } });
459
+ assert_1.strict.equal(is75bits, '75', "Result size query failed");
434
460
  });
435
- });
436
- await tryRun("Local file upload", async () => {
437
- let str = "This is a string", data = Buffer.from(str, "utf-8"), mediaFile = { data, name: "sample_file.txt" };
438
- const file = await db.media.insert(mediaFile, { returning: "*" });
439
- const _data = fs.readFileSync(__dirname + "/server/media/" + file.name);
440
- assert_1.strict.equal(str, _data.toString('utf8'));
441
- await tryRun("Nested insert", async () => {
442
- const { name, media: { extension, content_type, original_name } } = await db.items_with_one_media.insert({ name: "somename.txt", media: mediaFile }, { returning: "*" });
443
- assert_1.strict.deepStrictEqual({ extension, content_type, original_name }, {
444
- extension: 'txt',
445
- content_type: 'text/plain',
446
- original_name: 'sample_file.txt',
461
+ await tryRun("Basic exists", async () => {
462
+ const expect0 = await db.items.count({
463
+ $and: [
464
+ { $exists: { items2: { name: "a" } } },
465
+ { $exists: { items3: { name: "b" } } },
466
+ ]
447
467
  });
448
- // const _data = fs.readFileSync(__dirname + "/server/media/"+file.name);
449
- assert_1.strict.equal(name, "somename.txt");
468
+ assert_1.strict.equal(expect0, 0, "$exists query failed");
450
469
  });
451
- });
452
- await tryRun("Exists filter example", async () => {
453
- const fo = await db.items.findOne(), f = await db.items.find();
454
- assert_1.strict.deepStrictEqual(fo, { h: null, id: 1, name: 'a' }, "findOne query failed");
455
- assert_1.strict.deepStrictEqual(f[0], { h: null, id: 1, name: 'a' }, "findOne query failed");
456
- });
457
- await tryRun("Basic exists", async () => {
458
- const expect0 = await db.items.count({
459
- $and: [
460
- { $exists: { items2: { name: "a" } } },
461
- { $exists: { items3: { name: "b" } } },
462
- ]
470
+ await tryRun("Basic fts with shorthand notation", async () => {
471
+ const res = await db.items.count({
472
+ $and: [
473
+ { $exists: { items2: { "name.@@.to_tsquery": ["a"] } } },
474
+ { $exists: { items3: { "name.@@.to_tsquery": ["b"] } } },
475
+ ]
476
+ });
477
+ // assert.deepStrictEqual(res, { name: 'a'})
478
+ assert_1.strict.equal(res, 0, "FTS query failed");
463
479
  });
464
- assert_1.strict.equal(expect0, 0, "$exists query failed");
465
- });
466
- await tryRun("Basic fts with shorthand notation", async () => {
467
- const res = await db.items.count({
468
- $and: [
469
- { $exists: { items2: { "name.@@.to_tsquery": ["a"] } } },
470
- { $exists: { items3: { "name.@@.to_tsquery": ["b"] } } },
471
- ]
480
+ await tryRun("Exists with shortest path wildcard filter example", async () => {
481
+ const expect2 = await db.items.find({
482
+ $and: [
483
+ { $existsJoined: { "**.items3": { name: "a" } } },
484
+ { $existsJoined: { items2: { name: "a" } } }
485
+ ]
486
+ });
487
+ assert_1.strict.equal(expect2.length, 2, "$existsJoined query failed");
472
488
  });
473
- // assert.deepStrictEqual(res, { name: 'a'})
474
- assert_1.strict.equal(res, 0, "FTS query failed");
475
- });
476
- await tryRun("Exists with shortest path wildcard filter example", async () => {
477
- const expect2 = await db.items.find({
478
- $and: [
479
- { $existsJoined: { "**.items3": { name: "a" } } },
480
- { $existsJoined: { items2: { name: "a" } } }
481
- ]
489
+ await tryRun("Exists with exact path filter example", async () => {
490
+ const _expect2 = await db.items.find({
491
+ $and: [
492
+ // { "items2": { name: "a" } },
493
+ // { "items2.items3": { name: "a" } },
494
+ { $existsJoined: { items2: { name: "a" } } }
495
+ ]
496
+ });
497
+ assert_1.strict.equal(_expect2.length, 2, "$existsJoined query failed");
482
498
  });
483
- assert_1.strict.equal(expect2.length, 2, "$existsJoined query failed");
484
- });
485
- await tryRun("Exists with exact path filter example", async () => {
486
- const _expect2 = await db.items.find({
487
- $and: [
488
- // { "items2": { name: "a" } },
489
- // { "items2.items3": { name: "a" } },
490
- { $existsJoined: { items2: { name: "a" } } }
491
- ]
499
+ await tryRun("Not Exists with exact path filter example", async () => {
500
+ const _expect1 = await db.items.find({
501
+ $and: [
502
+ // { "items2": { name: "a" } },
503
+ // { "items2.items3": { name: "a" } },
504
+ { $notExistsJoined: { items2: { name: "a" } } }
505
+ ]
506
+ });
507
+ assert_1.strict.equal(_expect1.length, 1, "$notExistsJoined query failed");
492
508
  });
493
- assert_1.strict.equal(_expect2.length, 2, "$existsJoined query failed");
494
- });
495
- await tryRun("Not Exists with exact path filter example", async () => {
496
- const _expect1 = await db.items.find({
497
- $and: [
498
- // { "items2": { name: "a" } },
499
- // { "items2.items3": { name: "a" } },
500
- { $notExistsJoined: { items2: { name: "a" } } }
501
- ]
509
+ /* Upsert */
510
+ await tryRun("Upsert example", async () => {
511
+ await db.items.upsert({ name: "tx" }, { name: "tx" });
512
+ await db.items.upsert({ name: "tx" }, { name: "tx" });
513
+ assert_1.strict.equal(await db.items.count({ name: "tx" }), 1, "upsert command failed");
502
514
  });
503
- assert_1.strict.equal(_expect1.length, 1, "$notExistsJoined query failed");
504
- });
505
- /* Upsert */
506
- await tryRun("Upsert example", async () => {
507
- await db.items.upsert({ name: "tx" }, { name: "tx" });
508
- await db.items.upsert({ name: "tx" }, { name: "tx" });
509
- assert_1.strict.equal(await db.items.count({ name: "tx" }), 1, "upsert command failed");
510
- });
511
- /* Joins example */
512
- await tryRun("Joins example", async () => {
513
- const items = await db.items.find({}, {
514
- select: {
515
- "*": 1,
516
- items3: "*",
517
- items22: db.leftJoin.items2({}, "*")
515
+ /* Joins example */
516
+ await tryRun("Joins example", async () => {
517
+ const items = await db.items.find({}, {
518
+ select: {
519
+ "*": 1,
520
+ items3: "*",
521
+ items22: db.leftJoin.items2({}, "*")
522
+ }
523
+ });
524
+ if (!items.length || !items.every(it => Array.isArray(it.items3) && Array.isArray(it.items22))) {
525
+ console.log(items[0].items3);
526
+ throw "Joined select query failed";
518
527
  }
519
528
  });
520
- if (!items.length || !items.every(it => Array.isArray(it.items3) && Array.isArray(it.items22))) {
521
- console.log(items[0].items3);
522
- throw "Joined select query failed";
523
- }
524
- });
525
- /* Joins duplicate table example */
526
- await tryRun("Joins repeating table example", async () => {
527
- const items2 = await db.items.find({}, {
528
- select: {
529
- "*": 1,
530
- items2: "*"
531
- }
529
+ /* Joins duplicate table example */
530
+ await tryRun("Joins repeating table example", async () => {
531
+ const items2 = await db.items.find({}, {
532
+ select: {
533
+ "*": 1,
534
+ items2: "*"
535
+ }
536
+ });
537
+ const items2j = await db.items.find({}, {
538
+ select: {
539
+ "*": 1,
540
+ items2: "*",
541
+ items2j: db.leftJoin.items2({}, "*")
542
+ }
543
+ });
544
+ items2.forEach((d, i) => {
545
+ assert_1.strict.deepStrictEqual(d.items2, items2j[i].items2, "Joins duplicate aliased table query failed");
546
+ assert_1.strict.deepStrictEqual(d.items2, items2j[i].items2j, "Joins duplicate aliased table query failed");
547
+ });
532
548
  });
533
- const items2j = await db.items.find({}, {
534
- select: {
535
- "*": 1,
536
- items2: "*",
537
- items2j: db.leftJoin.items2({}, "*")
538
- }
549
+ await tryRun("Join aggregate functions example", async () => {
550
+ const singleShortHandAgg = await db.items.findOne({}, { select: { id: "$max" } });
551
+ const singleAgg = await db.items.findOne({}, { select: { id: { "$max": ["id"] } } });
552
+ assert_1.strict.deepStrictEqual(singleShortHandAgg, { id: 4 });
553
+ assert_1.strict.deepStrictEqual(singleAgg, { id: 4 });
554
+ const shortHandAggJoined = await db.items.findOne({ id: 4 }, { select: { id: 1, items2: { name: "$max" } } });
555
+ assert_1.strict.deepStrictEqual(shortHandAggJoined, { id: 4, items2: [] });
556
+ // console.log(JSON.stringify(shortHandAggJoined, null, 2));
557
+ // throw 1;
558
+ /* TODO joins & aggs */
559
+ // const aggsJoined = await db.items.find(
560
+ // {},
561
+ // {
562
+ // select: {
563
+ // id: "$count",
564
+ // name: 1,
565
+ // items2: {
566
+ // id: 1
567
+ // }
568
+ // },
569
+ // orderBy: {
570
+ // id: -1
571
+ // }
572
+ // }
573
+ // );
574
+ // console.log(JSON.stringify(aggsJoined, null, 2))
575
+ // assert.deepStrictEqual(aggsJoined, [
576
+ // {
577
+ // "name": "a",
578
+ // "items2": [
579
+ // {
580
+ // "id": 1
581
+ // },
582
+ // {
583
+ // "id": 1
584
+ // }
585
+ // ],
586
+ // "id": "2"
587
+ // },
588
+ // {
589
+ // "name": "b",
590
+ // "items2": [],
591
+ // "id": "1"
592
+ // },
593
+ // {
594
+ // "name": "tx",
595
+ // "items2": [],
596
+ // "id": "1"
597
+ // }
598
+ // ], "Joined aggregation query failed");
539
599
  });
540
- items2.forEach((d, i) => {
541
- assert_1.strict.deepStrictEqual(d.items2, items2j[i].items2, "Joins duplicate aliased table query failed");
542
- assert_1.strict.deepStrictEqual(d.items2, items2j[i].items2j, "Joins duplicate aliased table query failed");
600
+ /* $rowhash -> Custom column that returms md5(ctid + allowed select columns). Used in joins & CRUD to bypass PKey details */
601
+ await tryRun("$rowhash example", async () => {
602
+ const rowhash = await db.items.findOne({}, { select: { $rowhash: 1, "*": 1 } });
603
+ const f = { $rowhash: rowhash.$rowhash };
604
+ const rowhashView = await db.v_items.findOne({}, { select: { $rowhash: 1 } });
605
+ const rh1 = await db.items.findOne({ $rowhash: rowhash.$rowhash }, { select: { $rowhash: 1 } });
606
+ const rhView = await db.v_items.findOne({ $rowhash: rowhashView.$rowhash }, { select: { $rowhash: 1 } });
607
+ // console.log({ rowhash, f });
608
+ await db.items.update(f, { name: 'a' });
609
+ // console.log(rowhash, rh1)
610
+ // console.log(rowhashView, rhView)
611
+ if (typeof rowhash.$rowhash !== "string" ||
612
+ typeof rowhashView.$rowhash !== "string" ||
613
+ rowhash.$rowhash !== rh1.$rowhash ||
614
+ rowhashView.$rowhash !== rhView.$rowhash) {
615
+ throw "$rowhash query failed";
616
+ }
543
617
  });
544
618
  });
545
- await tryRun("Join aggregate functions example", async () => {
546
- const singleShortHandAgg = await db.items.findOne({}, { select: { id: "$max" } });
547
- const singleAgg = await db.items.findOne({}, { select: { id: { "$max": ["id"] } } });
548
- assert_1.strict.deepStrictEqual(singleShortHandAgg, { id: 4 });
549
- assert_1.strict.deepStrictEqual(singleAgg, { id: 4 });
550
- const shortHandAggJoined = await db.items.findOne({ id: 4 }, { select: { id: 1, items2: { name: "$max" } } });
551
- assert_1.strict.deepStrictEqual(shortHandAggJoined, { id: 4, items2: [] });
552
- // console.log(JSON.stringify(shortHandAggJoined, null, 2));
553
- // throw 1;
554
- /* TODO joins & aggs */
555
- // const aggsJoined = await db.items.find(
556
- // {},
557
- // {
558
- // select: {
559
- // id: "$count",
560
- // name: 1,
561
- // items2: {
562
- // id: 1
563
- // }
564
- // },
565
- // orderBy: {
566
- // id: -1
567
- // }
568
- // }
569
- // );
570
- // console.log(JSON.stringify(aggsJoined, null, 2))
571
- // assert.deepStrictEqual(aggsJoined, [
572
- // {
573
- // "name": "a",
574
- // "items2": [
575
- // {
576
- // "id": 1
577
- // },
578
- // {
579
- // "id": 1
580
- // }
581
- // ],
582
- // "id": "2"
583
- // },
584
- // {
585
- // "name": "b",
586
- // "items2": [],
587
- // "id": "1"
588
- // },
589
- // {
590
- // "name": "tx",
591
- // "items2": [],
592
- // "id": "1"
593
- // }
594
- // ], "Joined aggregation query failed");
595
- });
596
- /* $rowhash -> Custom column that returms md5(ctid + allowed select columns). Used in joins & CRUD to bypass PKey details */
597
- await tryRun("$rowhash example", async () => {
598
- const rowhash = await db.items.findOne({}, { select: { $rowhash: 1, "*": 1 } });
599
- const f = { $rowhash: rowhash.$rowhash };
600
- const rowhashView = await db.v_items.findOne({}, { select: { $rowhash: 1 } });
601
- const rh1 = await db.items.findOne({ $rowhash: rowhash.$rowhash }, { select: { $rowhash: 1 } });
602
- const rhView = await db.v_items.findOne({ $rowhash: rowhashView.$rowhash }, { select: { $rowhash: 1 } });
603
- // console.log({ rowhash, f });
604
- await db.items.update(f, { name: 'a' });
605
- // console.log(rowhash, rh1)
606
- // console.log(rowhashView, rhView)
607
- if (typeof rowhash.$rowhash !== "string" ||
608
- typeof rowhashView.$rowhash !== "string" ||
609
- rowhash.$rowhash !== rh1.$rowhash ||
610
- rowhashView.$rowhash !== rhView.$rowhash) {
611
- throw "$rowhash query failed";
612
- }
613
- });
614
619
  }
615
620
  exports.default = isomorphic;
@@ -174,7 +174,7 @@ export default async function isomorphic(db: Partial<DbHandler> | Partial<DBHand
174
174
 
175
175
  await tryRun("$unnest_words", async () => {
176
176
  const res = await db.various.find({}, { returnType: "values", select: { name: "$unnest_words" } });
177
- console.trace(res)
177
+
178
178
  assert.deepStrictEqual( res, [
179
179
  'abc9',
180
180
  'abc1',
@@ -429,6 +429,8 @@ export default async function isomorphic(db: Partial<DbHandler> | Partial<DBHand
429
429
  console.log("TODO: socket.io stringifies dates")
430
430
  });
431
431
 
432
+ await tryRun("Postgis examples", async () => {
433
+
432
434
  await tryRun("Postgis examples", async () => {
433
435
  await db.shapes.delete();
434
436
  const p1 = { ST_GeomFromText: ["POINT(-1 1)", 4326] },
@@ -525,6 +527,12 @@ export default async function isomorphic(db: Partial<DbHandler> | Partial<DBHand
525
527
  assert.deepStrictEqual(f[0], { h: null, id: 1, name: 'a' }, "findOne query failed" );
526
528
  });
527
529
 
530
+ await tryRun("Result size", async () => {
531
+ const is75bits = await db.items.size({
532
+ }, { select: { name: 1 } });
533
+ assert.equal(is75bits, '75', "Result size query failed")
534
+ });
535
+
528
536
  await tryRun("Basic exists", async () => {
529
537
  const expect0 = await db.items.count({
530
538
  $and: [
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "../..": {
25
25
  "name": "prostgles-server",
26
- "version": "2.0.129",
26
+ "version": "2.0.133",
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
29
  "@aws-sdk/client-s3": "^3.32.0",
@@ -33,7 +33,7 @@
33
33
  "i": "^0.3.7",
34
34
  "npm": "^8.1.4",
35
35
  "pg-promise": "^10.9.5",
36
- "prostgles-types": "^1.5.122",
36
+ "prostgles-types": "^1.5.123",
37
37
  "sharp": "^0.29.3"
38
38
  },
39
39
  "devDependencies": {
@@ -1456,7 +1456,7 @@
1456
1456
  "i": "^0.3.7",
1457
1457
  "npm": "^8.1.4",
1458
1458
  "pg-promise": "^10.9.5",
1459
- "prostgles-types": "^1.5.122",
1459
+ "prostgles-types": "^1.5.123",
1460
1460
  "sharp": "^0.29.3",
1461
1461
  "typescript": "^3.9.7"
1462
1462
  }