@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.
- package/dist/chunk-2PLYK5RU.js +5861 -0
- package/dist/chunk-2PLYK5RU.js.map +1 -0
- package/dist/{chunk-PW6ILJF7.js → chunk-QN56IB4G.js} +146 -10
- package/dist/chunk-QN56IB4G.js.map +1 -0
- package/dist/db/schema/index.d.ts +3798 -2050
- package/dist/db/schema/index.js +1 -2
- package/dist/index.d.ts +423 -21
- package/dist/index.js +1647 -1873
- package/dist/index.js.map +1 -1
- package/dist/register-UUQ64HZP.js +8 -0
- package/migrations/postgres/0008_event_correlation.sql +6 -0
- package/migrations/postgres/0009_settings.sql +13 -0
- package/migrations/postgres/0010_catch_up_index.sql +2 -0
- package/migrations/postgres/0011_audit_entries.sql +27 -0
- package/migrations/postgres/0012_event_subject.sql +27 -0
- package/migrations/postgres/meta/0008_snapshot.json +1625 -0
- package/migrations/postgres/meta/0009_snapshot.json +1705 -0
- package/migrations/postgres/meta/0010_snapshot.json +1732 -0
- package/migrations/postgres/meta/0011_snapshot.json +1887 -0
- package/migrations/postgres/meta/0012_snapshot.json +1926 -0
- package/migrations/postgres/meta/_journal.json +35 -0
- package/migrations/sqlite/0008_event_correlation.sql +7 -0
- package/migrations/sqlite/0009_settings.sql +13 -0
- package/migrations/sqlite/0010_catch_up_index.sql +2 -0
- package/migrations/sqlite/0011_audit_entries.sql +26 -0
- package/migrations/sqlite/0012_event_subject.sql +27 -0
- package/migrations/sqlite/meta/0008_snapshot.json +1485 -0
- package/migrations/sqlite/meta/0009_snapshot.json +1571 -0
- package/migrations/sqlite/meta/0010_snapshot.json +1580 -0
- package/migrations/sqlite/meta/0011_snapshot.json +1705 -0
- package/migrations/sqlite/meta/0012_snapshot.json +1728 -0
- package/migrations/sqlite/meta/_journal.json +35 -0
- package/package.json +29 -23
- package/dist/chunk-2GFZHF5W.js +0 -2647
- package/dist/chunk-2GFZHF5W.js.map +0 -1
- package/dist/chunk-PW6ILJF7.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/register-FJA7YJV3.js +0 -8
- package/dist/register-FJA7YJV3.js.map +0 -1
- /package/dist/{chunk-PZ5AY32C.js.map → register-UUQ64HZP.js.map} +0 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- The correlation id as a column, so one operation's events are an index range. Every existing row is backfilled from
|
|
2
|
+
-- its envelope, else its own id (the builder's default), before the column becomes NOT NULL.
|
|
3
|
+
ALTER TABLE "events" ADD COLUMN "correlation_id" text;--> statement-breakpoint
|
|
4
|
+
UPDATE "events" SET "correlation_id" = COALESCE("envelope"->>'correlationId', "id");--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "events" ALTER COLUMN "correlation_id" SET NOT NULL;--> statement-breakpoint
|
|
6
|
+
CREATE INDEX IF NOT EXISTS "events_correlation_idx" ON "events" USING btree ("correlation_id","seq");
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS "settings" (
|
|
2
|
+
"slot" text NOT NULL,
|
|
3
|
+
"path" text NOT NULL,
|
|
4
|
+
"ciphertext" "bytea",
|
|
5
|
+
"plain" text,
|
|
6
|
+
"iv" "bytea",
|
|
7
|
+
"tag" "bytea",
|
|
8
|
+
"key_id" text,
|
|
9
|
+
"updated_at" timestamp with time zone NOT NULL,
|
|
10
|
+
"updated_by" text,
|
|
11
|
+
CONSTRAINT "settings_slot_path_pk" 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,27 @@
|
|
|
1
|
+
-- Append-only: rows are written once, in the command's transaction, and never updated, deleted or pruned.
|
|
2
|
+
CREATE TABLE IF NOT EXISTS "audit_entries" (
|
|
3
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
4
|
+
"at" timestamp with time zone NOT NULL,
|
|
5
|
+
"actor_kind" text NOT NULL,
|
|
6
|
+
"actor_id" text NOT NULL,
|
|
7
|
+
"command" text NOT NULL,
|
|
8
|
+
"subjects" jsonb 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" jsonb,
|
|
15
|
+
CONSTRAINT "audit_entries_outcome" CHECK ("audit_entries"."outcome" IN ('applied', 'refused', 'replayed'))
|
|
16
|
+
);
|
|
17
|
+
--> statement-breakpoint
|
|
18
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "audit_entries_applied_key_unique" ON "audit_entries" USING btree ("actor_id","command","idempotency_key") WHERE "audit_entries"."outcome" = 'applied' AND "audit_entries"."idempotency_key" IS NOT NULL;--> statement-breakpoint
|
|
19
|
+
CREATE INDEX IF NOT EXISTS "audit_entries_at_idx" ON "audit_entries" USING btree ("at","id");--> statement-breakpoint
|
|
20
|
+
CREATE INDEX IF NOT EXISTS "audit_entries_correlation_idx" ON "audit_entries" USING btree ("correlation_id");--> statement-breakpoint
|
|
21
|
+
CREATE OR REPLACE FUNCTION "audit_entries_append_only"() RETURNS trigger LANGUAGE plpgsql AS $$
|
|
22
|
+
BEGIN
|
|
23
|
+
RAISE EXCEPTION 'audit_entries is append-only';
|
|
24
|
+
END
|
|
25
|
+
$$;--> statement-breakpoint
|
|
26
|
+
CREATE TRIGGER "audit_entries_append_only" BEFORE UPDATE OR DELETE ON "audit_entries"
|
|
27
|
+
FOR EACH ROW EXECUTE FUNCTION "audit_entries_append_only"();
|
|
@@ -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 COLUMN "subject_type" text;--> statement-breakpoint
|
|
4
|
+
ALTER TABLE "events" ADD COLUMN "subject_id" text;--> statement-breakpoint
|
|
5
|
+
UPDATE "events" SET
|
|
6
|
+
"subject_type" = CASE
|
|
7
|
+
WHEN starts_with("type", 'product.') THEN 'product'
|
|
8
|
+
WHEN starts_with("type", 'order.') OR starts_with("type", 'payment.') THEN 'order'
|
|
9
|
+
WHEN starts_with("type", 'customer.') THEN 'customer'
|
|
10
|
+
WHEN starts_with("type", 'inventory.') THEN 'variant'
|
|
11
|
+
END,
|
|
12
|
+
"subject_id" = CASE
|
|
13
|
+
WHEN starts_with("type", 'product.') THEN CASE
|
|
14
|
+
WHEN jsonb_typeof("envelope" #> '{payload,product,id}') = 'string' THEN "envelope" #>> '{payload,product,id}'
|
|
15
|
+
WHEN jsonb_typeof("envelope" #> '{payload,productId}') = 'string' THEN "envelope" #>> '{payload,productId}'
|
|
16
|
+
END
|
|
17
|
+
WHEN starts_with("type", 'order.') OR starts_with("type", 'payment.') THEN CASE
|
|
18
|
+
WHEN jsonb_typeof("envelope" #> '{payload,order,id}') = 'string' THEN "envelope" #>> '{payload,order,id}'
|
|
19
|
+
WHEN jsonb_typeof("envelope" #> '{payload,orderId}') = 'string' THEN "envelope" #>> '{payload,orderId}'
|
|
20
|
+
END
|
|
21
|
+
WHEN starts_with("type", 'customer.') AND jsonb_typeof("envelope" #> '{payload,customerId}') = 'string'
|
|
22
|
+
THEN "envelope" #>> '{payload,customerId}'
|
|
23
|
+
WHEN starts_with("type", 'inventory.') AND jsonb_typeof("envelope" #> '{payload,variantId}') = 'string'
|
|
24
|
+
THEN "envelope" #>> '{payload,variantId}'
|
|
25
|
+
END;--> statement-breakpoint
|
|
26
|
+
UPDATE "events" SET "subject_type" = NULL WHERE "subject_id" IS NULL;--> statement-breakpoint
|
|
27
|
+
CREATE INDEX IF NOT EXISTS "events_subject_idx" ON "events" USING btree ("subject_type","subject_id","seq");
|