@platformatic/db 3.4.1 → 3.5.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.
Files changed (61) hide show
  1. package/README.md +1 -1
  2. package/config.d.ts +442 -107
  3. package/eslint.config.js +9 -5
  4. package/index.d.ts +53 -31
  5. package/index.js +30 -139
  6. package/lib/application.js +102 -0
  7. package/lib/capability.js +35 -0
  8. package/lib/commands/index.js +59 -0
  9. package/lib/commands/migrations-apply.js +63 -0
  10. package/lib/commands/migrations-create.js +48 -0
  11. package/lib/commands/print-schema.js +31 -0
  12. package/lib/commands/seed.js +74 -0
  13. package/lib/commands/types.js +22 -0
  14. package/lib/config.js +52 -0
  15. package/lib/errors.js +16 -12
  16. package/lib/generator.js +229 -0
  17. package/lib/{migrator.mjs → migrator.js} +46 -38
  18. package/lib/{root-endpoint/index.js → root.js} +6 -7
  19. package/lib/schema.js +41 -20
  20. package/lib/{generator/code-templates.js → templates.js} +57 -16
  21. package/lib/types.js +161 -0
  22. package/lib/upgrade.js +8 -12
  23. package/lib/utils.js +12 -23
  24. package/lib/versions/0.18.0.js +3 -5
  25. package/lib/versions/{from-zero-twenty-height-to-will-see.js → 0.28.0.js} +3 -5
  26. package/lib/versions/2.0.0.js +3 -5
  27. package/lib/versions/3.0.0.js +14 -0
  28. package/package.json +32 -40
  29. package/schema.json +1385 -164
  30. package/tsconfig.json +16 -6
  31. package/db.mjs +0 -86
  32. package/help/compile.txt +0 -17
  33. package/help/create.txt +0 -13
  34. package/help/help.txt +0 -11
  35. package/help/migrations apply.txt +0 -45
  36. package/help/migrations create.txt +0 -27
  37. package/help/migrations.txt +0 -4
  38. package/help/schema.txt +0 -25
  39. package/help/seed.txt +0 -36
  40. package/help/start.txt +0 -47
  41. package/help/types.txt +0 -40
  42. package/index.test-d.ts +0 -43
  43. package/lib/adjust-config.js +0 -42
  44. package/lib/create.mjs +0 -89
  45. package/lib/gen-migration.mjs +0 -53
  46. package/lib/gen-schema.mjs +0 -68
  47. package/lib/gen-types.mjs +0 -202
  48. package/lib/generator/README.md +0 -38
  49. package/lib/generator/db-generator.js +0 -260
  50. package/lib/generator.d.ts +0 -7
  51. package/lib/migrate.mjs +0 -81
  52. package/lib/seed.mjs +0 -90
  53. package/lib/stackable.js +0 -49
  54. /package/{lib/root-endpoint/public → public}/images/dark_mode.svg +0 -0
  55. /package/{lib/root-endpoint/public → public}/images/favicon.ico +0 -0
  56. /package/{lib/root-endpoint/public → public}/images/light_mode.svg +0 -0
  57. /package/{lib/root-endpoint/public → public}/images/platformatic-logo-dark.svg +0 -0
  58. /package/{lib/root-endpoint/public → public}/images/platformatic-logo-light.svg +0 -0
  59. /package/{lib/root-endpoint/public → public}/images/triangle_dark.svg +0 -0
  60. /package/{lib/root-endpoint/public → public}/images/triangle_light.svg +0 -0
  61. /package/{lib/root-endpoint/public → public}/index.html +0 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @platformatic/db
2
2
 
3
- Check out the full documentation for Platformatic DB on [our website](https://docs.platformatic.dev/docs/db/overview).
3
+ Check out the full documentation for Platformatic DB on [our website](https://docs.platformatic.dev/docs/reference/db/overview).
4
4
 
5
5
  ## Install
6
6
 
package/config.d.ts CHANGED
@@ -22,7 +22,7 @@ export type CrudOperationAuth =
22
22
  }
23
23
  | boolean;
24
24
 
25
- export interface PlatformaticDB {
25
+ export interface PlatformaticDatabaseConfig {
26
26
  basePath?: string;
27
27
  server?: {
28
28
  hostname?: string;
@@ -70,8 +70,6 @@ export interface PlatformaticDB {
70
70
  [k: string]: unknown;
71
71
  };
72
72
  level?: string;
73
- additionalProperties?: never;
74
- [k: string]: unknown;
75
73
  }[];
76
74
  options?: {
77
75
  [k: string]: unknown;
@@ -83,6 +81,21 @@ export interface PlatformaticDB {
83
81
  [k: string]: unknown;
84
82
  };
85
83
  };
84
+ formatters?: {
85
+ path: string;
86
+ };
87
+ timestamp?: "epochTime" | "unixTime" | "nullTime" | "isoTime";
88
+ redact?: {
89
+ paths: string[];
90
+ censor?: string;
91
+ };
92
+ base?: {
93
+ [k: string]: unknown;
94
+ } | null;
95
+ messageKey?: string;
96
+ customLevels?: {
97
+ [k: string]: unknown;
98
+ };
86
99
  [k: string]: unknown;
87
100
  };
88
101
  loggerInstance?: {
@@ -327,6 +340,7 @@ export interface PlatformaticDB {
327
340
  find?: CrudOperationAuth;
328
341
  save?: CrudOperationAuth;
329
342
  delete?: CrudOperationAuth;
343
+ updateMany?: CrudOperationAuth;
330
344
  }
331
345
  | {
332
346
  /**
@@ -346,6 +360,7 @@ export interface PlatformaticDB {
346
360
  find?: CrudOperationAuth;
347
361
  save?: CrudOperationAuth;
348
362
  delete?: CrudOperationAuth;
363
+ updateMany?: CrudOperationAuth;
349
364
  }
350
365
  )[];
351
366
  };
@@ -372,24 +387,6 @@ export interface PlatformaticDB {
372
387
  */
373
388
  currentSchema?: string;
374
389
  };
375
- metrics?:
376
- | boolean
377
- | {
378
- port?: number | string;
379
- hostname?: string;
380
- endpoint?: string;
381
- server?: "own" | "parent" | "hide";
382
- defaultMetrics?: {
383
- enabled: boolean;
384
- };
385
- auth?: {
386
- username: string;
387
- password: string;
388
- };
389
- labels?: {
390
- [k: string]: string;
391
- };
392
- };
393
390
  types?: {
394
391
  /**
395
392
  * Should types be auto generated.
@@ -403,18 +400,403 @@ export interface PlatformaticDB {
403
400
  plugins?: {
404
401
  [k: string]: unknown;
405
402
  };
406
- telemetry?: OpenTelemetry;
407
- clients?: {
408
- serviceId?: string;
409
- name?: string;
410
- type?: "openapi" | "graphql";
411
- path?: string;
412
- schema?: string;
413
- url?: string;
414
- fullResponse?: boolean;
415
- fullRequest?: boolean;
416
- validateResponse?: boolean;
417
- }[];
403
+ application?: {};
404
+ telemetry?: {
405
+ enabled?: boolean | string;
406
+ /**
407
+ * The name of the application. Defaults to the folder name if not specified.
408
+ */
409
+ applicationName: string;
410
+ /**
411
+ * The version of the application (optional)
412
+ */
413
+ version?: string;
414
+ /**
415
+ * An array of paths to skip when creating spans. Useful for health checks and other endpoints that do not need to be traced.
416
+ */
417
+ skip?: {
418
+ /**
419
+ * The path to skip. Can be a string or a regex.
420
+ */
421
+ path?: string;
422
+ /**
423
+ * HTTP method to skip
424
+ */
425
+ method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
426
+ [k: string]: unknown;
427
+ }[];
428
+ exporter?:
429
+ | {
430
+ type?: "console" | "otlp" | "zipkin" | "memory" | "file";
431
+ /**
432
+ * Options for the exporter. These are passed directly to the exporter.
433
+ */
434
+ options?: {
435
+ /**
436
+ * The URL to send the traces to. Not used for console or memory exporters.
437
+ */
438
+ url?: string;
439
+ /**
440
+ * Headers to send to the exporter. Not used for console or memory exporters.
441
+ */
442
+ headers?: {
443
+ [k: string]: unknown;
444
+ };
445
+ /**
446
+ * The path to write the traces to. Only for file exporter.
447
+ */
448
+ path?: string;
449
+ [k: string]: unknown;
450
+ };
451
+ additionalProperties?: never;
452
+ [k: string]: unknown;
453
+ }[]
454
+ | {
455
+ type?: "console" | "otlp" | "zipkin" | "memory" | "file";
456
+ /**
457
+ * Options for the exporter. These are passed directly to the exporter.
458
+ */
459
+ options?: {
460
+ /**
461
+ * The URL to send the traces to. Not used for console or memory exporters.
462
+ */
463
+ url?: string;
464
+ /**
465
+ * Headers to send to the exporter. Not used for console or memory exporters.
466
+ */
467
+ headers?: {
468
+ [k: string]: unknown;
469
+ };
470
+ /**
471
+ * The path to write the traces to. Only for file exporter.
472
+ */
473
+ path?: string;
474
+ [k: string]: unknown;
475
+ };
476
+ additionalProperties?: never;
477
+ [k: string]: unknown;
478
+ };
479
+ };
480
+ runtime?: {
481
+ preload?: string | string[];
482
+ basePath?: string;
483
+ services?: {
484
+ [k: string]: unknown;
485
+ }[];
486
+ workers?: number | string;
487
+ logger?: {
488
+ level: (
489
+ | ("fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent")
490
+ | {
491
+ [k: string]: unknown;
492
+ }
493
+ ) &
494
+ string;
495
+ transport?:
496
+ | {
497
+ target?: string;
498
+ options?: {
499
+ [k: string]: unknown;
500
+ };
501
+ }
502
+ | {
503
+ targets?: {
504
+ target?: string;
505
+ options?: {
506
+ [k: string]: unknown;
507
+ };
508
+ level?: string;
509
+ }[];
510
+ options?: {
511
+ [k: string]: unknown;
512
+ };
513
+ };
514
+ pipeline?: {
515
+ target?: string;
516
+ options?: {
517
+ [k: string]: unknown;
518
+ };
519
+ };
520
+ formatters?: {
521
+ path: string;
522
+ };
523
+ timestamp?: "epochTime" | "unixTime" | "nullTime" | "isoTime";
524
+ redact?: {
525
+ paths: string[];
526
+ censor?: string;
527
+ };
528
+ base?: {
529
+ [k: string]: unknown;
530
+ } | null;
531
+ messageKey?: string;
532
+ customLevels?: {
533
+ [k: string]: unknown;
534
+ };
535
+ [k: string]: unknown;
536
+ };
537
+ server?: {
538
+ hostname?: string;
539
+ port?: number | string;
540
+ http2?: boolean;
541
+ https?: {
542
+ allowHTTP1?: boolean;
543
+ key:
544
+ | string
545
+ | {
546
+ path?: string;
547
+ }
548
+ | (
549
+ | string
550
+ | {
551
+ path?: string;
552
+ }
553
+ )[];
554
+ cert:
555
+ | string
556
+ | {
557
+ path?: string;
558
+ }
559
+ | (
560
+ | string
561
+ | {
562
+ path?: string;
563
+ }
564
+ )[];
565
+ requestCert?: boolean;
566
+ rejectUnauthorized?: boolean;
567
+ };
568
+ };
569
+ startTimeout?: number;
570
+ restartOnError?: boolean | number;
571
+ exitOnUnhandledErrors?: boolean;
572
+ gracefulShutdown?: {
573
+ runtime: number | string;
574
+ application: number | string;
575
+ };
576
+ health?: {
577
+ enabled?: boolean | string;
578
+ interval?: number | string;
579
+ gracePeriod?: number | string;
580
+ maxUnhealthyChecks?: number | string;
581
+ maxELU?: number | string;
582
+ maxHeapUsed?: number | string;
583
+ maxHeapTotal?: number | string;
584
+ maxYoungGeneration?: number | string;
585
+ };
586
+ undici?: {
587
+ agentOptions?: {
588
+ [k: string]: unknown;
589
+ };
590
+ interceptors?:
591
+ | {
592
+ module: string;
593
+ options: {
594
+ [k: string]: unknown;
595
+ };
596
+ [k: string]: unknown;
597
+ }[]
598
+ | {
599
+ Client?: {
600
+ module: string;
601
+ options: {
602
+ [k: string]: unknown;
603
+ };
604
+ [k: string]: unknown;
605
+ }[];
606
+ Pool?: {
607
+ module: string;
608
+ options: {
609
+ [k: string]: unknown;
610
+ };
611
+ [k: string]: unknown;
612
+ }[];
613
+ Agent?: {
614
+ module: string;
615
+ options: {
616
+ [k: string]: unknown;
617
+ };
618
+ [k: string]: unknown;
619
+ }[];
620
+ [k: string]: unknown;
621
+ };
622
+ [k: string]: unknown;
623
+ };
624
+ httpCache?:
625
+ | boolean
626
+ | {
627
+ store?: string;
628
+ /**
629
+ * @minItems 1
630
+ */
631
+ methods?: [string, ...string[]];
632
+ cacheTagsHeader?: string;
633
+ maxSize?: number;
634
+ maxEntrySize?: number;
635
+ maxCount?: number;
636
+ [k: string]: unknown;
637
+ };
638
+ watch?: boolean | string;
639
+ managementApi?:
640
+ | boolean
641
+ | string
642
+ | {
643
+ logs?: {
644
+ maxSize?: number;
645
+ };
646
+ };
647
+ metrics?:
648
+ | boolean
649
+ | {
650
+ port?: number | string;
651
+ enabled?: boolean | string;
652
+ hostname?: string;
653
+ endpoint?: string;
654
+ auth?: {
655
+ username: string;
656
+ password: string;
657
+ };
658
+ labels?: {
659
+ [k: string]: string;
660
+ };
661
+ /**
662
+ * The label name to use for the application identifier in metrics (e.g., applicationId, serviceId)
663
+ */
664
+ applicationLabel?: string;
665
+ readiness?:
666
+ | boolean
667
+ | {
668
+ endpoint?: string;
669
+ success?: {
670
+ statusCode?: number;
671
+ body?: string;
672
+ };
673
+ fail?: {
674
+ statusCode?: number;
675
+ body?: string;
676
+ };
677
+ };
678
+ liveness?:
679
+ | boolean
680
+ | {
681
+ endpoint?: string;
682
+ success?: {
683
+ statusCode?: number;
684
+ body?: string;
685
+ };
686
+ fail?: {
687
+ statusCode?: number;
688
+ body?: string;
689
+ };
690
+ };
691
+ plugins?: string[];
692
+ };
693
+ telemetry?: {
694
+ enabled?: boolean | string;
695
+ /**
696
+ * The name of the application. Defaults to the folder name if not specified.
697
+ */
698
+ applicationName: string;
699
+ /**
700
+ * The version of the application (optional)
701
+ */
702
+ version?: string;
703
+ /**
704
+ * An array of paths to skip when creating spans. Useful for health checks and other endpoints that do not need to be traced.
705
+ */
706
+ skip?: {
707
+ /**
708
+ * The path to skip. Can be a string or a regex.
709
+ */
710
+ path?: string;
711
+ /**
712
+ * HTTP method to skip
713
+ */
714
+ method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
715
+ [k: string]: unknown;
716
+ }[];
717
+ exporter?:
718
+ | {
719
+ type?: "console" | "otlp" | "zipkin" | "memory" | "file";
720
+ /**
721
+ * Options for the exporter. These are passed directly to the exporter.
722
+ */
723
+ options?: {
724
+ /**
725
+ * The URL to send the traces to. Not used for console or memory exporters.
726
+ */
727
+ url?: string;
728
+ /**
729
+ * Headers to send to the exporter. Not used for console or memory exporters.
730
+ */
731
+ headers?: {
732
+ [k: string]: unknown;
733
+ };
734
+ /**
735
+ * The path to write the traces to. Only for file exporter.
736
+ */
737
+ path?: string;
738
+ [k: string]: unknown;
739
+ };
740
+ additionalProperties?: never;
741
+ [k: string]: unknown;
742
+ }[]
743
+ | {
744
+ type?: "console" | "otlp" | "zipkin" | "memory" | "file";
745
+ /**
746
+ * Options for the exporter. These are passed directly to the exporter.
747
+ */
748
+ options?: {
749
+ /**
750
+ * The URL to send the traces to. Not used for console or memory exporters.
751
+ */
752
+ url?: string;
753
+ /**
754
+ * Headers to send to the exporter. Not used for console or memory exporters.
755
+ */
756
+ headers?: {
757
+ [k: string]: unknown;
758
+ };
759
+ /**
760
+ * The path to write the traces to. Only for file exporter.
761
+ */
762
+ path?: string;
763
+ [k: string]: unknown;
764
+ };
765
+ additionalProperties?: never;
766
+ [k: string]: unknown;
767
+ };
768
+ };
769
+ inspectorOptions?: {
770
+ host?: string;
771
+ port?: number;
772
+ breakFirstLine?: boolean;
773
+ watchDisabled?: boolean;
774
+ [k: string]: unknown;
775
+ };
776
+ applicationTimeout?: number | string;
777
+ messagingTimeout?: number | string;
778
+ env?: {
779
+ [k: string]: string;
780
+ };
781
+ sourceMaps?: boolean;
782
+ scheduler?: {
783
+ enabled?: boolean | string;
784
+ name: string;
785
+ cron: string;
786
+ callbackUrl: string;
787
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
788
+ headers?: {
789
+ [k: string]: string;
790
+ };
791
+ body?:
792
+ | string
793
+ | {
794
+ [k: string]: unknown;
795
+ };
796
+ maxRetries?: number;
797
+ [k: string]: unknown;
798
+ }[];
799
+ };
418
800
  watch?:
419
801
  | {
420
802
  enabled?: boolean | string;
@@ -501,13 +883,13 @@ export interface PathItem {
501
883
  servers?: Server[];
502
884
  parameters?: ParameterOrReference[];
503
885
  get?: Operation;
504
- put?: Operation;
505
- post?: Operation;
506
- delete?: Operation;
507
- options?: Operation;
508
- head?: Operation;
509
- patch?: Operation;
510
- trace?: Operation;
886
+ put?: Operation1;
887
+ post?: Operation1;
888
+ delete?: Operation1;
889
+ options?: Operation1;
890
+ head?: Operation1;
891
+ patch?: Operation1;
892
+ trace?: Operation1;
511
893
  /**
512
894
  * This interface was referenced by `PathItem`'s JSON-Schema definition
513
895
  * via the `patternProperty` "^x-".
@@ -561,6 +943,26 @@ export interface CallbacksOrReference {
561
943
  export interface SecurityRequirement {
562
944
  [k: string]: string[];
563
945
  }
946
+ export interface Operation1 {
947
+ tags?: string[];
948
+ summary?: string;
949
+ description?: string;
950
+ externalDocs?: ExternalDocumentation;
951
+ operationId?: string;
952
+ parameters?: ParameterOrReference[];
953
+ requestBody?: RequestBodyOrReference;
954
+ responses?: Responses;
955
+ callbacks?: {
956
+ [k: string]: CallbacksOrReference;
957
+ };
958
+ security?: SecurityRequirement[];
959
+ servers?: Server[];
960
+ /**
961
+ * This interface was referenced by `Operation1`'s JSON-Schema definition
962
+ * via the `patternProperty` "^x-".
963
+ */
964
+ [k: string]: unknown;
965
+ }
564
966
  export interface PathItemOrReference {
565
967
  [k: string]: unknown;
566
968
  }
@@ -623,70 +1025,3 @@ export interface Tag {
623
1025
  */
624
1026
  [k: string]: unknown;
625
1027
  }
626
- export interface OpenTelemetry {
627
- /**
628
- * The name of the service. Defaults to the folder name if not specified.
629
- */
630
- serviceName: string;
631
- /**
632
- * The version of the service (optional)
633
- */
634
- version?: string;
635
- /**
636
- * An array of paths to skip when creating spans. Useful for health checks and other endpoints that do not need to be traced.
637
- */
638
- skip?: {
639
- /**
640
- * The path to skip. Can be a string or a regex.
641
- */
642
- path?: string;
643
- /**
644
- * HTTP method to skip
645
- */
646
- method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
647
- [k: string]: unknown;
648
- }[];
649
- exporter?:
650
- | {
651
- type?: "console" | "otlp" | "zipkin" | "memory";
652
- /**
653
- * Options for the exporter. These are passed directly to the exporter.
654
- */
655
- options?: {
656
- /**
657
- * The URL to send the traces to. Not used for console or memory exporters.
658
- */
659
- url?: string;
660
- /**
661
- * Headers to send to the exporter. Not used for console or memory exporters.
662
- */
663
- headers?: {
664
- [k: string]: unknown;
665
- };
666
- [k: string]: unknown;
667
- };
668
- additionalProperties?: never;
669
- [k: string]: unknown;
670
- }[]
671
- | {
672
- type?: "console" | "otlp" | "zipkin" | "memory";
673
- /**
674
- * Options for the exporter. These are passed directly to the exporter.
675
- */
676
- options?: {
677
- /**
678
- * The URL to send the traces to. Not used for console or memory exporters.
679
- */
680
- url?: string;
681
- /**
682
- * Headers to send to the exporter. Not used for console or memory exporters.
683
- */
684
- headers?: {
685
- [k: string]: unknown;
686
- };
687
- [k: string]: unknown;
688
- };
689
- additionalProperties?: never;
690
- [k: string]: unknown;
691
- };
692
- }
package/eslint.config.js CHANGED
@@ -1,8 +1,12 @@
1
- 'use strict'
1
+ import neostandard from 'neostandard'
2
2
 
3
- const neostandard = require('neostandard')
4
-
5
- module.exports = neostandard({
3
+ export default neostandard({
6
4
  ts: true,
7
- ignores: [...neostandard.resolveIgnoresFromGitignore(), 'test/tmp/**/*'],
5
+ ignores: [
6
+ ...neostandard.resolveIgnoresFromGitignore(),
7
+ 'test/tmp/**/*',
8
+ 'test/fixtures/*/dist/**/*',
9
+ '**/dist/*',
10
+ 'tmp/**/*'
11
+ ]
8
12
  })