@nymbalhq/platform 1.1.0 → 1.3.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 (40) hide show
  1. package/dist/chunk-2PLYK5RU.js +5861 -0
  2. package/dist/chunk-2PLYK5RU.js.map +1 -0
  3. package/dist/{chunk-PW6ILJF7.js → chunk-QN56IB4G.js} +146 -10
  4. package/dist/chunk-QN56IB4G.js.map +1 -0
  5. package/dist/db/schema/index.d.ts +3798 -2050
  6. package/dist/db/schema/index.js +1 -2
  7. package/dist/index.d.ts +423 -21
  8. package/dist/index.js +1647 -1873
  9. package/dist/index.js.map +1 -1
  10. package/dist/register-UUQ64HZP.js +8 -0
  11. package/migrations/postgres/0008_event_correlation.sql +6 -0
  12. package/migrations/postgres/0009_settings.sql +13 -0
  13. package/migrations/postgres/0010_catch_up_index.sql +2 -0
  14. package/migrations/postgres/0011_audit_entries.sql +27 -0
  15. package/migrations/postgres/0012_event_subject.sql +27 -0
  16. package/migrations/postgres/meta/0008_snapshot.json +1625 -0
  17. package/migrations/postgres/meta/0009_snapshot.json +1705 -0
  18. package/migrations/postgres/meta/0010_snapshot.json +1732 -0
  19. package/migrations/postgres/meta/0011_snapshot.json +1887 -0
  20. package/migrations/postgres/meta/0012_snapshot.json +1926 -0
  21. package/migrations/postgres/meta/_journal.json +35 -0
  22. package/migrations/sqlite/0008_event_correlation.sql +7 -0
  23. package/migrations/sqlite/0009_settings.sql +13 -0
  24. package/migrations/sqlite/0010_catch_up_index.sql +2 -0
  25. package/migrations/sqlite/0011_audit_entries.sql +26 -0
  26. package/migrations/sqlite/0012_event_subject.sql +27 -0
  27. package/migrations/sqlite/meta/0008_snapshot.json +1485 -0
  28. package/migrations/sqlite/meta/0009_snapshot.json +1571 -0
  29. package/migrations/sqlite/meta/0010_snapshot.json +1580 -0
  30. package/migrations/sqlite/meta/0011_snapshot.json +1705 -0
  31. package/migrations/sqlite/meta/0012_snapshot.json +1728 -0
  32. package/migrations/sqlite/meta/_journal.json +35 -0
  33. package/package.json +29 -23
  34. package/dist/chunk-2GFZHF5W.js +0 -2647
  35. package/dist/chunk-2GFZHF5W.js.map +0 -1
  36. package/dist/chunk-PW6ILJF7.js.map +0 -1
  37. package/dist/chunk-PZ5AY32C.js +0 -10
  38. package/dist/register-FJA7YJV3.js +0 -8
  39. package/dist/register-FJA7YJV3.js.map +0 -1
  40. /package/dist/{chunk-PZ5AY32C.js.map → register-UUQ64HZP.js.map} +0 -0
@@ -57,6 +57,41 @@
57
57
  "when": 1792550523604,
58
58
  "tag": "0007_native_search",
59
59
  "breakpoints": true
60
+ },
61
+ {
62
+ "idx": 8,
63
+ "version": "7",
64
+ "when": 1792609200206,
65
+ "tag": "0008_event_correlation",
66
+ "breakpoints": true
67
+ },
68
+ {
69
+ "idx": 9,
70
+ "version": "7",
71
+ "when": 1792617492782,
72
+ "tag": "0009_settings",
73
+ "breakpoints": true
74
+ },
75
+ {
76
+ "idx": 10,
77
+ "version": "7",
78
+ "when": 1792645028362,
79
+ "tag": "0010_catch_up_index",
80
+ "breakpoints": true
81
+ },
82
+ {
83
+ "idx": 11,
84
+ "version": "7",
85
+ "when": 1792659500377,
86
+ "tag": "0011_audit_entries",
87
+ "breakpoints": true
88
+ },
89
+ {
90
+ "idx": 12,
91
+ "version": "7",
92
+ "when": 1792853533921,
93
+ "tag": "0012_event_subject",
94
+ "breakpoints": true
60
95
  }
61
96
  ]
62
97
  }
@@ -0,0 +1,7 @@
1
+ -- The correlation id as a column, so one operation's events are an index range. SQLite adds a NOT NULL column only
2
+ -- with a default; a table rebuild instead would reset the AUTOINCREMENT high-water mark when retention has deleted the
3
+ -- newest rows, and reuse their seqs. Every existing row is backfilled from its envelope, else its own id (the builder's
4
+ -- default), so no row keeps the placeholder.
5
+ ALTER TABLE `events` ADD `correlation_id` text DEFAULT '' NOT NULL;--> statement-breakpoint
6
+ UPDATE `events` SET `correlation_id` = COALESCE(json_extract(`envelope`, '$.correlationId'), `id`);--> statement-breakpoint
7
+ CREATE INDEX `events_correlation_idx` ON `events` (`correlation_id`,`seq`);
@@ -0,0 +1,13 @@
1
+ CREATE TABLE `settings` (
2
+ `slot` text NOT NULL,
3
+ `path` text NOT NULL,
4
+ `ciphertext` blob,
5
+ `plain` text,
6
+ `iv` blob,
7
+ `tag` blob,
8
+ `key_id` text,
9
+ `updated_at` text NOT NULL,
10
+ `updated_by` text,
11
+ PRIMARY KEY(`slot`, `path`),
12
+ CONSTRAINT "settings_one_value" CHECK(("settings"."ciphertext" IS NULL) <> ("settings"."plain" IS NULL) AND ("settings"."ciphertext" IS NULL OR ("settings"."iv" IS NOT NULL AND "settings"."tag" IS NOT NULL AND "settings"."key_id" IS NOT NULL)))
13
+ );
@@ -0,0 +1,2 @@
1
+ -- What a read-model rebuild's catch-up reads: the events not dead, delivered at or after a time or not yet, by seq.
2
+ CREATE INDEX `events_catch_up_idx` ON `events` (`dead_at`,`delivered_at`,`seq`);
@@ -0,0 +1,26 @@
1
+ -- Append-only: rows are written once, in the command's transaction, and never updated, deleted or pruned.
2
+ CREATE TABLE `audit_entries` (
3
+ `id` text PRIMARY KEY NOT NULL,
4
+ `at` text NOT NULL,
5
+ `actor_kind` text NOT NULL,
6
+ `actor_id` text NOT NULL,
7
+ `command` text NOT NULL,
8
+ `subjects` text NOT NULL,
9
+ `correlation_id` text,
10
+ `idempotency_key` text,
11
+ `request_hash` text,
12
+ `outcome` text NOT NULL,
13
+ `response_status` integer,
14
+ `response_body` text,
15
+ CONSTRAINT "audit_entries_outcome" CHECK("audit_entries"."outcome" IN ('applied', 'refused', 'replayed'))
16
+ );
17
+ --> statement-breakpoint
18
+ CREATE UNIQUE INDEX `audit_entries_applied_key_unique` ON `audit_entries` (`actor_id`,`command`,`idempotency_key`) WHERE "audit_entries"."outcome" = 'applied' AND "audit_entries"."idempotency_key" IS NOT NULL;--> statement-breakpoint
19
+ CREATE INDEX `audit_entries_at_idx` ON `audit_entries` (`at`,`id`);--> statement-breakpoint
20
+ CREATE INDEX `audit_entries_correlation_idx` ON `audit_entries` (`correlation_id`);--> statement-breakpoint
21
+ CREATE TRIGGER `audit_entries_no_update` BEFORE UPDATE ON `audit_entries` BEGIN
22
+ SELECT RAISE(ABORT, 'audit_entries is append-only');
23
+ END;--> statement-breakpoint
24
+ CREATE TRIGGER `audit_entries_no_delete` BEFORE DELETE ON `audit_entries` BEGIN
25
+ SELECT RAISE(ABORT, 'audit_entries is append-only');
26
+ END;
@@ -0,0 +1,27 @@
1
+ -- Whose event each row is, so one record's history is an index range. The backfill mirrors `subjectOf`
2
+ -- (src/history/subject.ts): a subject needs a string id at the first path its type names, else the row has none.
3
+ ALTER TABLE `events` ADD `subject_type` text;--> statement-breakpoint
4
+ ALTER TABLE `events` ADD `subject_id` text;--> statement-breakpoint
5
+ UPDATE `events` SET
6
+ `subject_type` = CASE
7
+ WHEN `type` GLOB 'product.*' THEN 'product'
8
+ WHEN `type` GLOB 'order.*' OR `type` GLOB 'payment.*' THEN 'order'
9
+ WHEN `type` GLOB 'customer.*' THEN 'customer'
10
+ WHEN `type` GLOB 'inventory.*' THEN 'variant'
11
+ END,
12
+ `subject_id` = CASE
13
+ WHEN `type` GLOB 'product.*' THEN CASE
14
+ WHEN json_type(`envelope`, '$.payload.product.id') = 'text' THEN json_extract(`envelope`, '$.payload.product.id')
15
+ WHEN json_type(`envelope`, '$.payload.productId') = 'text' THEN json_extract(`envelope`, '$.payload.productId')
16
+ END
17
+ WHEN `type` GLOB 'order.*' OR `type` GLOB 'payment.*' THEN CASE
18
+ WHEN json_type(`envelope`, '$.payload.order.id') = 'text' THEN json_extract(`envelope`, '$.payload.order.id')
19
+ WHEN json_type(`envelope`, '$.payload.orderId') = 'text' THEN json_extract(`envelope`, '$.payload.orderId')
20
+ END
21
+ WHEN `type` GLOB 'customer.*' AND json_type(`envelope`, '$.payload.customerId') = 'text'
22
+ THEN json_extract(`envelope`, '$.payload.customerId')
23
+ WHEN `type` GLOB 'inventory.*' AND json_type(`envelope`, '$.payload.variantId') = 'text'
24
+ THEN json_extract(`envelope`, '$.payload.variantId')
25
+ END;--> statement-breakpoint
26
+ UPDATE `events` SET `subject_type` = NULL WHERE `subject_id` IS NULL;--> statement-breakpoint
27
+ CREATE INDEX `events_subject_idx` ON `events` (`subject_type`,`subject_id`,`seq`);