@composable-os/cli 0.0.0-stage → 0.1.0-beta.8
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/LICENSE +109 -0
- package/README.md +24 -2
- package/dist/blocks-DEELKGDC.js +233 -0
- package/dist/chunk-2ABSVMGB.js +13 -0
- package/dist/chunk-2S7375SC.js +802 -0
- package/dist/chunk-5KSXSK7Y.js +47 -0
- package/dist/chunk-6UWRT4VM.js +220 -0
- package/dist/chunk-E5JLTLRM.js +50 -0
- package/dist/chunk-G3ORKXVP.js +1178 -0
- package/dist/chunk-HDIOVFAZ.js +544 -0
- package/dist/chunk-KGHA67HG.js +765 -0
- package/dist/chunk-KOKYDJ7Z.js +1423 -0
- package/dist/chunk-KTXGEXTY.js +358 -0
- package/dist/chunk-LTQDLCP7.js +16486 -0
- package/dist/chunk-MAXLUQKB.js +1287 -0
- package/dist/chunk-STJZJIRA.js +11378 -0
- package/dist/chunk-X6I2LWB3.js +24319 -0
- package/dist/chunk-XDDBLYKW.js +29154 -0
- package/dist/chunk-ZRWF6QZS.js +2357 -0
- package/dist/cli-BRSACHSG.js +31393 -0
- package/dist/cli-DTMGNDXN.js +121 -0
- package/dist/cli.js +25 -0
- package/dist/client-repo-ZVZ6KW5S.js +55 -0
- package/dist/create.js +25 -0
- package/dist/fields-64BQJA62.js +48 -0
- package/dist/invoke-NHHOLLF6.js +26 -0
- package/dist/person-WMWRF2HV.js +58 -0
- package/dist/platform/migrations/0001_init.sql +59 -0
- package/dist/platform/migrations/0002_users_settings.sql +34 -0
- package/dist/platform/migrations/0003_people_organisations.sql +225 -0
- package/dist/platform/migrations/0004_activities_tasks.sql +88 -0
- package/dist/platform/migrations/0005_views_audit.sql +79 -0
- package/dist/platform/migrations/0006_search.sql +223 -0
- package/dist/platform/migrations/0007_crm_views.sql +141 -0
- package/dist/platform/migrations/0008_audit_redaction.sql +116 -0
- package/dist/platform/migrations/0010_approval_queue.sql +90 -0
- package/dist/platform/migrations/0011_connected_apps.sql +36 -0
- package/dist/platform/migrations/0020_extensions.sql +373 -0
- package/dist/platform/migrations/0030_extension_proposals.sql +29 -0
- package/dist/platform/migrations/0050_live_row_indexes.sql +32 -0
- package/dist/platform/migrations/0060_audit_read_counts.sql +31 -0
- package/dist/platform/migrations/0061_audit_retention.sql +95 -0
- package/dist/platform/migrations/0062_run_history_retention.sql +6 -0
- package/dist/platform/migrations/0063_pending_action_compaction.sql +18 -0
- package/dist/platform/migrations/0064_drop_rate_limit.sql +6 -0
- package/dist/platform/migrations/0065_storage_stats.sql +13 -0
- package/dist/platform/migrations/0070_drop_proposals_ext_idx.sql +9 -0
- package/dist/platform/migrations/0080_views_dashboards.sql +46 -0
- package/dist/platform/migrations/0100_stage_history.sql +54 -0
- package/dist/platform/migrations/0110_integrations.sql +103 -0
- package/dist/platform/migrations/0111_email_calendar_sync.sql +137 -0
- package/dist/platform/migrations/0112_sync_item_occurred_at.sql +8 -0
- package/dist/platform/migrations/0130_automations.sql +113 -0
- package/dist/platform/migrations/0131_notifications.sql +29 -0
- package/dist/platform/migrations/0132_automation_runtime.sql +14 -0
- package/dist/platform/migrations/0150_ai_summaries_embeddings.sql +48 -0
- package/dist/platform/migrations/0160_releases.sql +41 -0
- package/dist/platform/migrations/0161_setup_wizard.sql +30 -0
- package/dist/platform/migrations/0170_automation_connections.sql +32 -0
- package/dist/platform/migrations/0171_automation_outbox.sql +23 -0
- package/dist/platform/migrations/0172_notification_delivery.sql +46 -0
- package/dist/platform/migrations/0200_assistant_conversations.sql +25 -0
- package/dist/platform/migrations/0205_policy_adjudicator.sql +61 -0
- package/dist/platform/migrations/0210_daily_digest.sql +33 -0
- package/dist/platform/migrations/0220_entitlements.sql +13 -0
- package/dist/platform/migrations/0221_support_grants.sql +33 -0
- package/dist/platform/migrations/0250_judge.sql +11 -0
- package/dist/platform/migrations/0251_adjudication_judgement.sql +8 -0
- package/dist/platform/migrations/0252_judge_usage.sql +14 -0
- package/dist/platform/migrations/0255_summary_checks.sql +9 -0
- package/dist/platform/migrations/0256_outbound_check.sql +9 -0
- package/dist/platform/migrations/0260_ai_usage.sql +20 -0
- package/dist/platform/migrations/0270_assistant_conversation_refs.sql +29 -0
- package/dist/platform/migrations/0310_assignment_rules.sql +54 -0
- package/dist/platform/migrations/0320_duplicates.sql +41 -0
- package/dist/platform/migrations/0330_erase_completeness.sql +54 -0
- package/dist/platform/migrations/0350_assistant_thread.sql +38 -0
- package/dist/platform/migrations/0351_assistant_model_roles.sql +26 -0
- package/dist/platform/migrations/0352_assistant_memory.sql +74 -0
- package/dist/platform/migrations/0358_ai_cache_observation.sql +24 -0
- package/dist/platform/migrations/0359_ai_compaction_decision.sql +25 -0
- package/dist/platform/migrations/0360_ai_cache_estimate.sql +35 -0
- package/dist/platform/migrations/0361_voice_preferences.sql +27 -0
- package/dist/platform/migrations/0362_voice_usage.sql +17 -0
- package/dist/platform/migrations/0365_routines.sql +38 -0
- package/dist/platform/migrations/0370_approval_execution.sql +20 -0
- package/dist/platform/migrations/0371_agent_jobs.sql +65 -0
- package/dist/platform/migrations/0380_rec_views.sql +94 -0
- package/dist/platform/migrations/0400_customer_audit_actor.sql +142 -0
- package/dist/platform/migrations/0401_customer_accounts.sql +61 -0
- package/dist/platform/migrations/0402_erase_requests.sql +34 -0
- package/dist/platform/migrations/0410_idempotency_keys.sql +45 -0
- package/dist/platform/migrations/0411_device_sessions.sql +33 -0
- package/dist/platform/migrations/0420_transition_history.sql +100 -0
- package/dist/platform/migrations/0421_orders.sql +134 -0
- package/dist/platform/migrations/0422_order_payments.sql +109 -0
- package/dist/platform/migrations/0440_capacity.sql +100 -0
- package/dist/platform/migrations/0441_capacity_views.sql +40 -0
- package/dist/platform/migrations/0450_order_grants.sql +21 -0
- package/dist/platform/migrations/0451_pack_roles.sql +18 -0
- package/dist/platform/migrations/0460_content.sql +59 -0
- package/dist/platform/migrations/0461_media.sql +52 -0
- package/dist/platform/migrations/0470_publish_versions.sql +36 -0
- package/dist/platform/migrations/0471_permission_grants.sql +18 -0
- package/dist/platform/migrations/0490_staff_invites.sql +40 -0
- package/dist/platform/migrations/0491_sign_in_mail_kind.sql +10 -0
- package/dist/platform/migrations/0492_email_confirmation_and_sign_in_confirm.sql +30 -0
- package/dist/platform/migrations/0500_published_media_field.sql +25 -0
- package/dist/platform/migrations/0501_import_keys.sql +23 -0
- package/dist/platform/migrations/0520_publish_requests.sql +20 -0
- package/dist/platform/sdk/automation-check.ts +534 -0
- package/dist/platform/sdk/automation.ts +743 -0
- package/dist/platform/sdk/behaviour.ts +215 -0
- package/dist/platform/sdk/capacity.ts +112 -0
- package/dist/platform/sdk/contract.ts +766 -0
- package/dist/platform/sdk/document.ts +788 -0
- package/dist/platform/sdk/field-types.ts +106 -0
- package/dist/platform/sdk/formula/ast.ts +72 -0
- package/dist/platform/sdk/formula/compile.ts +454 -0
- package/dist/platform/sdk/formula/index.ts +4 -0
- package/dist/platform/sdk/formula/parser.ts +417 -0
- package/dist/platform/sdk/index.ts +33 -0
- package/dist/platform/sdk/manifest.ts +1484 -0
- package/dist/platform/sdk/media.ts +46 -0
- package/dist/platform/sdk/permissions.ts +60 -0
- package/dist/platform/sdk/renamed.ts +63 -0
- package/dist/platform/sdk/rich-text-fixture.ts +68 -0
- package/dist/platform/sdk/rich-text.ts +173 -0
- package/dist/platform/sdk/runtime.ts +410 -0
- package/dist/platform/sdk/sellable.ts +396 -0
- package/dist/platform/sdk/slug.ts +25 -0
- package/dist/platform/sdk/states.ts +162 -0
- package/dist/platform/sdk/testing.ts +836 -0
- package/dist/products-2H5DR232.js +11 -0
- package/dist/run-4JNFLYXV.js +847 -0
- package/dist/src-G6OF5SKW.js +31 -0
- package/dist/src-J27WXNLY.js +270 -0
- package/dist/token-MOJUA2U6.js +70 -0
- package/dist/token-util-TENRN4V7.js +6 -0
- package/package.json +33 -4
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
-- Migration 0440: capacity counters and claims (stage 26, the `capacity` behaviour, ADR 0430).
|
|
2
|
+
--
|
|
3
|
+
-- A record of an object that declares `capacity` has one counter row: how many places it has
|
|
4
|
+
-- (NULL is unlimited), how many are held while someone pays and how many are taken. The record's
|
|
5
|
+
-- own number field is what staff edit; this row is the host's. A record may draw on one parent's
|
|
6
|
+
-- counter as well (its pool: a ticket type's event), named on the counter row. One level only.
|
|
7
|
+
--
|
|
8
|
+
-- The rule is in the database, not in a read before the write: a claim is a plain
|
|
9
|
+
-- `held = held + n` on the record's counter and on its pool's, in the same D1 batch as the write
|
|
10
|
+
-- that needs it. If either would go past its places, the statement fails, and with it the whole
|
|
11
|
+
-- batch (a batch is one transaction): the order or booking it belonged to is not created either.
|
|
12
|
+
-- D1 runs one statement at a time per database, so concurrent claims cannot both pass.
|
|
13
|
+
--
|
|
14
|
+
-- * core_capacity_within_places (CHECK) is the guarantee: no row can ever hold more than its
|
|
15
|
+
-- places, whatever writes it.
|
|
16
|
+
-- * core_capacity_refuse_* (BEFORE triggers, same condition) refuse first, with a message
|
|
17
|
+
-- carrying the numbers, so the host can say which record refused, what was asked and what was
|
|
18
|
+
-- left without reading anything (errors.ts parses `core_capacity_refused {json}`).
|
|
19
|
+
CREATE TABLE core_capacity (
|
|
20
|
+
-- The record's object (as in core_stage_history.object_type) and id.
|
|
21
|
+
object_type TEXT NOT NULL,
|
|
22
|
+
record_id TEXT NOT NULL,
|
|
23
|
+
-- How many places there are. NULL: unlimited (claims are still counted).
|
|
24
|
+
places INTEGER CHECK (places IS NULL OR places >= 0),
|
|
25
|
+
held INTEGER NOT NULL DEFAULT 0 CHECK (held >= 0),
|
|
26
|
+
taken INTEGER NOT NULL DEFAULT 0 CHECK (taken >= 0),
|
|
27
|
+
-- The parent counter this record's claims also draw on, or none.
|
|
28
|
+
pool_object_type TEXT,
|
|
29
|
+
pool_record_id TEXT,
|
|
30
|
+
updated_at TEXT NOT NULL,
|
|
31
|
+
PRIMARY KEY (object_type, record_id),
|
|
32
|
+
CONSTRAINT core_capacity_within_places CHECK (places IS NULL OR held + taken <= places),
|
|
33
|
+
CHECK ((pool_object_type IS NULL) = (pool_record_id IS NULL)),
|
|
34
|
+
CHECK (pool_object_type IS NULL OR NOT (pool_object_type = object_type AND pool_record_id = record_id)),
|
|
35
|
+
-- A pool deleted for good (its object's table dropped) leaves its records without one.
|
|
36
|
+
FOREIGN KEY (pool_object_type, pool_record_id) REFERENCES core_capacity (object_type, record_id)
|
|
37
|
+
ON DELETE SET NULL
|
|
38
|
+
) WITHOUT ROWID;
|
|
39
|
+
CREATE INDEX core_capacity_pool_idx ON core_capacity (pool_object_type, pool_record_id);
|
|
40
|
+
|
|
41
|
+
-- A claim: places taken from a counter (and its pool) for a reason. `held` while paying,
|
|
42
|
+
-- `confirmed` once paid, `released` when given back. A hold has no clock of its own: what it was
|
|
43
|
+
-- taken for (`for_type`, `for_id`: an order line, later a booking) confirms or releases it in the
|
|
44
|
+
-- batch of its own write. The pool it drew on is copied from the counter when the claim is made,
|
|
45
|
+
-- so giving it back returns the places to the same pool.
|
|
46
|
+
CREATE TABLE core_capacity_claim (
|
|
47
|
+
-- clm_… (ids.ts).
|
|
48
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
49
|
+
object_type TEXT NOT NULL,
|
|
50
|
+
record_id TEXT NOT NULL,
|
|
51
|
+
pool_object_type TEXT,
|
|
52
|
+
pool_record_id TEXT,
|
|
53
|
+
quantity INTEGER NOT NULL CHECK (quantity > 0),
|
|
54
|
+
state TEXT NOT NULL DEFAULT 'held' CHECK (state IN ('held', 'confirmed', 'released')),
|
|
55
|
+
for_type TEXT NOT NULL,
|
|
56
|
+
for_id TEXT NOT NULL,
|
|
57
|
+
created_at TEXT NOT NULL,
|
|
58
|
+
updated_at TEXT NOT NULL,
|
|
59
|
+
confirmed_at TEXT,
|
|
60
|
+
released_at TEXT,
|
|
61
|
+
-- A claim names a counter that exists: claiming on a record without one fails the batch.
|
|
62
|
+
FOREIGN KEY (object_type, record_id) REFERENCES core_capacity (object_type, record_id),
|
|
63
|
+
CHECK ((pool_object_type IS NULL) = (pool_record_id IS NULL))
|
|
64
|
+
);
|
|
65
|
+
CREATE INDEX core_capacity_claim_record_idx ON core_capacity_claim (object_type, record_id, state);
|
|
66
|
+
CREATE INDEX core_capacity_claim_for_idx ON core_capacity_claim (for_type, for_id);
|
|
67
|
+
|
|
68
|
+
-- Refuses a claim (held or taken going up) past the places, or places set below what is claimed,
|
|
69
|
+
-- with the numbers. Same condition as core_capacity_within_places.
|
|
70
|
+
CREATE TRIGGER core_capacity_refuse_update
|
|
71
|
+
BEFORE UPDATE OF places, held, taken ON core_capacity
|
|
72
|
+
WHEN NEW.places IS NOT NULL AND NEW.held + NEW.taken > NEW.places
|
|
73
|
+
BEGIN
|
|
74
|
+
SELECT RAISE(ABORT, 'core_capacity_refused ' || json_object(
|
|
75
|
+
'object', NEW.object_type,
|
|
76
|
+
'record', NEW.record_id,
|
|
77
|
+
'places', NEW.places,
|
|
78
|
+
'held', OLD.held,
|
|
79
|
+
'taken', OLD.taken,
|
|
80
|
+
'asked', (NEW.held + NEW.taken) - (OLD.held + OLD.taken),
|
|
81
|
+
'available', max(coalesce(OLD.places, NEW.places) - OLD.held - OLD.taken, 0)
|
|
82
|
+
));
|
|
83
|
+
END;
|
|
84
|
+
|
|
85
|
+
CREATE TRIGGER core_capacity_refuse_insert
|
|
86
|
+
BEFORE INSERT ON core_capacity
|
|
87
|
+
WHEN NEW.places IS NOT NULL AND NEW.held + NEW.taken > NEW.places
|
|
88
|
+
BEGIN
|
|
89
|
+
SELECT RAISE(ABORT, 'core_capacity_refused ' || json_object(
|
|
90
|
+
'object', NEW.object_type,
|
|
91
|
+
'record', NEW.record_id,
|
|
92
|
+
'places', NEW.places,
|
|
93
|
+
'held', NEW.held,
|
|
94
|
+
'taken', NEW.taken,
|
|
95
|
+
'asked', 0,
|
|
96
|
+
'available', 0
|
|
97
|
+
));
|
|
98
|
+
END;
|
|
99
|
+
|
|
100
|
+
UPDATE core_meta SET value = '440' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
-- Migration 0441: the capacity read views (stage 26, ADR 0431), for query.sql and dashboards.
|
|
2
|
+
--
|
|
3
|
+
-- rec_capacity: one row per record with a capacity. `available` is the record's own places left
|
|
4
|
+
-- (null when unlimited); a record with a pool may have fewer, see `pool_available`.
|
|
5
|
+
-- rec_capacity_claim: every claim, held, confirmed or released, and what it was taken for.
|
|
6
|
+
CREATE VIEW rec_capacity AS
|
|
7
|
+
SELECT
|
|
8
|
+
c.object_type,
|
|
9
|
+
c.record_id,
|
|
10
|
+
c.places,
|
|
11
|
+
c.held,
|
|
12
|
+
c.taken,
|
|
13
|
+
CASE WHEN c.places IS NULL THEN NULL ELSE max(c.places - c.held - c.taken, 0) END AS available,
|
|
14
|
+
c.pool_object_type,
|
|
15
|
+
c.pool_record_id,
|
|
16
|
+
CASE WHEN p.places IS NULL THEN NULL ELSE max(p.places - p.held - p.taken, 0) END
|
|
17
|
+
AS pool_available,
|
|
18
|
+
c.updated_at
|
|
19
|
+
FROM core_capacity c
|
|
20
|
+
LEFT JOIN core_capacity p
|
|
21
|
+
ON p.object_type = c.pool_object_type AND p.record_id = c.pool_record_id;
|
|
22
|
+
|
|
23
|
+
CREATE VIEW rec_capacity_claim AS
|
|
24
|
+
SELECT
|
|
25
|
+
id,
|
|
26
|
+
object_type,
|
|
27
|
+
record_id,
|
|
28
|
+
pool_object_type,
|
|
29
|
+
pool_record_id,
|
|
30
|
+
quantity,
|
|
31
|
+
state,
|
|
32
|
+
for_type,
|
|
33
|
+
for_id,
|
|
34
|
+
created_at,
|
|
35
|
+
updated_at,
|
|
36
|
+
confirmed_at,
|
|
37
|
+
released_at
|
|
38
|
+
FROM core_capacity_claim;
|
|
39
|
+
|
|
40
|
+
UPDATE core_meta SET value = '441' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-- Stage 27, the sellable behaviour (ADR 0435): what a paid order line granted.
|
|
2
|
+
--
|
|
3
|
+
-- When an order is first paid (the move to `paid`, or to `part_paid` for a deposit), the host
|
|
4
|
+
-- creates one record of the line's declared granted object per unit (a ticket per place), in the
|
|
5
|
+
-- batch that makes the move, and one row here for each. The row is how the host finds them again
|
|
6
|
+
-- (to void them when the order is refunded in full or cancelled) and, when the grant asks for a
|
|
7
|
+
-- code, how a code is kept unique across every granted record and found by its code.
|
|
8
|
+
--
|
|
9
|
+
-- Only the move hook in packages/core/src/orders/grants.ts writes here.
|
|
10
|
+
CREATE TABLE core_order_grant (
|
|
11
|
+
-- The granted record: its object's registry name and its id.
|
|
12
|
+
object_type TEXT NOT NULL,
|
|
13
|
+
record_id TEXT NOT NULL,
|
|
14
|
+
order_id TEXT NOT NULL REFERENCES core_order (id) ON DELETE CASCADE,
|
|
15
|
+
line_id TEXT NOT NULL REFERENCES core_order_line (id) ON DELETE CASCADE,
|
|
16
|
+
-- The host's unguessable code, when the grant declares one. Two equal codes fail the batch.
|
|
17
|
+
code TEXT UNIQUE,
|
|
18
|
+
created_at TEXT NOT NULL,
|
|
19
|
+
PRIMARY KEY (object_type, record_id)
|
|
20
|
+
);
|
|
21
|
+
CREATE INDEX core_order_grant_order_idx ON core_order_grant (order_id);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-- Stage 27, the door role (ADR 0436): a staff account may hold one fixed role a pack declares,
|
|
2
|
+
-- such as Ticketing's door role (`ticketing.door`: check tickets in, read events, ticket types and
|
|
3
|
+
-- tickets, and nothing else).
|
|
4
|
+
--
|
|
5
|
+
-- `pack_role` names the role as `<extension id>.<role>`. While it is set, the account may do
|
|
6
|
+
-- exactly what the role lists, whatever its `role` says: the operations pipeline reads this
|
|
7
|
+
-- column on every call by a staff account and refuses everything else. The role's definition is
|
|
8
|
+
-- in the installed extension's manifest; if the extension is not installed and active, the
|
|
9
|
+
-- account may do nothing. Only `user.setPackRole` (a human admin) writes it, and it sets `role`
|
|
10
|
+
-- to `viewer` in the same write, so code that reads `role` alone sees the least it could.
|
|
11
|
+
ALTER TABLE core_user ADD COLUMN pack_role TEXT;
|
|
12
|
+
|
|
13
|
+
-- The list of users shows the role an account holds.
|
|
14
|
+
DROP VIEW rec_user;
|
|
15
|
+
CREATE VIEW rec_user AS
|
|
16
|
+
SELECT u.id, u.name, u.email, u.role, u.pack_role, u.image, u.created_at
|
|
17
|
+
FROM core_user u
|
|
18
|
+
WHERE u.kind = 'human' AND u.support_grant_id IS NULL;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
-- Stage 28, Content (ADRs 0441 to 0443): the public half of `publishable`.
|
|
2
|
+
--
|
|
3
|
+
-- A scheduled publish. Scheduling takes the snapshot when a person schedules (it is what they
|
|
4
|
+
-- decided to publish), and the minute cron publishes it when `publish_at` passes, through the
|
|
5
|
+
-- operations pipeline (record.publishDue). At most one per record: scheduling again replaces it;
|
|
6
|
+
-- publishing now, unpublishing, or the cron publishing it removes it. Only
|
|
7
|
+
-- packages/core/src/records/publish.ts writes here.
|
|
8
|
+
CREATE TABLE core_publish_schedule (
|
|
9
|
+
object_type TEXT NOT NULL,
|
|
10
|
+
record_id TEXT NOT NULL,
|
|
11
|
+
publish_at TEXT NOT NULL,
|
|
12
|
+
-- The content fields' values when it was scheduled, as record.publish takes them.
|
|
13
|
+
content TEXT NOT NULL,
|
|
14
|
+
bytes INTEGER NOT NULL,
|
|
15
|
+
note TEXT CHECK (note IS NULL OR length(note) <= 500),
|
|
16
|
+
-- The person who scheduled it: the cron publishes in their name.
|
|
17
|
+
scheduled_by TEXT NOT NULL,
|
|
18
|
+
scheduled_at TEXT NOT NULL,
|
|
19
|
+
PRIMARY KEY (object_type, record_id)
|
|
20
|
+
);
|
|
21
|
+
CREATE INDEX core_publish_schedule_due_idx ON core_publish_schedule (publish_at);
|
|
22
|
+
|
|
23
|
+
-- An old address of a published record (ADR 0442). When the slug of a record that has been
|
|
24
|
+
-- published changes, its old slug points here to the record, and the public is told where it
|
|
25
|
+
-- now is. A record that takes a slug removes any redirect of that slug, so a live slug always
|
|
26
|
+
-- wins and a deleted record's slug can be used again.
|
|
27
|
+
CREATE TABLE core_slug_redirect (
|
|
28
|
+
object_type TEXT NOT NULL,
|
|
29
|
+
slug TEXT NOT NULL,
|
|
30
|
+
record_id TEXT NOT NULL,
|
|
31
|
+
created_at TEXT NOT NULL,
|
|
32
|
+
PRIMARY KEY (object_type, slug)
|
|
33
|
+
);
|
|
34
|
+
CREATE INDEX core_slug_redirect_record_idx ON core_slug_redirect (object_type, record_id);
|
|
35
|
+
|
|
36
|
+
-- A preview link (ADR 0443): who may read one record's working copy without signing in, until
|
|
37
|
+
-- when. The link holds a random token; only its SHA-256 is kept. It names one record and is
|
|
38
|
+
-- refused for any other, and after `expires_at`.
|
|
39
|
+
CREATE TABLE core_preview_link (
|
|
40
|
+
token_hash TEXT PRIMARY KEY NOT NULL,
|
|
41
|
+
object_type TEXT NOT NULL,
|
|
42
|
+
record_id TEXT NOT NULL,
|
|
43
|
+
expires_at TEXT NOT NULL,
|
|
44
|
+
created_by TEXT NOT NULL,
|
|
45
|
+
created_at TEXT NOT NULL
|
|
46
|
+
);
|
|
47
|
+
CREATE INDEX core_preview_link_expiry_idx ON core_preview_link (expires_at);
|
|
48
|
+
|
|
49
|
+
-- What the public reads of an object, by generation (ADR 0442): every committed change to a
|
|
50
|
+
-- record of a publishable object the public reads bumps its row in the change's own batch, so a
|
|
51
|
+
-- cached public read keyed by the generation is never served after a publish, an unpublish or a
|
|
52
|
+
-- slug change. `epoch` is random per deployment and object, so two deployments' caches never
|
|
53
|
+
-- share a key.
|
|
54
|
+
CREATE TABLE core_content_generation (
|
|
55
|
+
object_type TEXT PRIMARY KEY NOT NULL,
|
|
56
|
+
generation INTEGER NOT NULL DEFAULT 1,
|
|
57
|
+
epoch TEXT NOT NULL,
|
|
58
|
+
changed_at TEXT NOT NULL
|
|
59
|
+
);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
-- Stage 28, Media (ADR 0444): the media library, a base record.
|
|
2
|
+
--
|
|
3
|
+
-- A media item is one stored original in R2 (`key`, under `media/`), what the host found it to
|
|
4
|
+
-- be when it was uploaded (its type from its first bytes, never the name or the client's word;
|
|
5
|
+
-- its size and dimensions), its alt text and who uploaded it. Nothing executable is stored: the
|
|
6
|
+
-- upload takes only the raster image types it can recognise (no SVG).
|
|
7
|
+
--
|
|
8
|
+
-- Deleting one is a soft delete (Trash). The Trash purge deletes the row, and the trigger below
|
|
9
|
+
-- queues its R2 object on core_blob_deletion in the same batch: the existing blob deletion path
|
|
10
|
+
-- (ADR 0320) deletes it after the commit, and the 10-minute cron retries.
|
|
11
|
+
CREATE TABLE core_media (
|
|
12
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
13
|
+
key TEXT NOT NULL UNIQUE,
|
|
14
|
+
name TEXT NOT NULL CHECK (length(name) BETWEEN 1 AND 200),
|
|
15
|
+
type TEXT NOT NULL CHECK (type IN ('image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif')),
|
|
16
|
+
bytes INTEGER NOT NULL CHECK (bytes > 0),
|
|
17
|
+
width INTEGER,
|
|
18
|
+
height INTEGER,
|
|
19
|
+
alt TEXT CHECK (alt IS NULL OR length(alt) <= 500),
|
|
20
|
+
created_at TEXT NOT NULL,
|
|
21
|
+
created_by TEXT,
|
|
22
|
+
updated_at TEXT NOT NULL,
|
|
23
|
+
updated_by TEXT,
|
|
24
|
+
deleted_at TEXT,
|
|
25
|
+
deleted_by TEXT
|
|
26
|
+
);
|
|
27
|
+
CREATE INDEX core_media_live_idx ON core_media (created_at) WHERE deleted_at IS NULL;
|
|
28
|
+
CREATE INDEX core_media_deleted_idx ON core_media (deleted_at) WHERE deleted_at IS NOT NULL;
|
|
29
|
+
|
|
30
|
+
CREATE TRIGGER core_media_object_ad AFTER DELETE ON core_media
|
|
31
|
+
BEGIN
|
|
32
|
+
INSERT OR IGNORE INTO core_blob_deletion (key, queued_at)
|
|
33
|
+
VALUES (OLD.key, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
|
|
34
|
+
END;
|
|
35
|
+
|
|
36
|
+
-- The live media items, as staff list them. Outsiders read none of it: a picture reaches the
|
|
37
|
+
-- public only through media.serve, for an item published content references.
|
|
38
|
+
CREATE VIEW rec_media AS
|
|
39
|
+
SELECT id, key, name, type, bytes, width, height, alt, created_at, created_by, updated_at,
|
|
40
|
+
updated_by
|
|
41
|
+
FROM core_media WHERE deleted_at IS NULL;
|
|
42
|
+
|
|
43
|
+
-- Which media items each record's current version references (ADR 0444): written with the
|
|
44
|
+
-- version by records/publish.ts (a publish replaces a record's rows; an unpublish removes them),
|
|
45
|
+
-- so serving a picture to the public is an index read and never a scan of versions.
|
|
46
|
+
CREATE TABLE core_published_media (
|
|
47
|
+
media_id TEXT NOT NULL,
|
|
48
|
+
object_type TEXT NOT NULL,
|
|
49
|
+
record_id TEXT NOT NULL,
|
|
50
|
+
PRIMARY KEY (media_id, object_type, record_id)
|
|
51
|
+
) WITHOUT ROWID;
|
|
52
|
+
CREATE INDEX core_published_media_record_idx ON core_published_media (object_type, record_id);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
-- Stage 41, `publishable` without its public half (ADR 0446): the published versions of a
|
|
2
|
+
-- record's content.
|
|
3
|
+
--
|
|
4
|
+
-- A publishable object's records are the working copy staff edit. Publishing one snapshots its
|
|
5
|
+
-- content fields (the object's `publishable.content`) into the next version here, in the batch
|
|
6
|
+
-- of `record.publish`, and makes it the current one: the version readers are given (an
|
|
7
|
+
-- assignment pins a program's). Editing the working copy changes no row here. Restoring copies a
|
|
8
|
+
-- version back into the working copy and changes no row here either.
|
|
9
|
+
--
|
|
10
|
+
-- At most one current version per record (the partial unique index). Two publishes racing each
|
|
11
|
+
-- other compute the same next number and the second fails its batch on the primary key, so no
|
|
12
|
+
-- version is ever written twice. Stage 28 adds unpublishing (current set to 0, the versions kept)
|
|
13
|
+
-- and public reads of the current version.
|
|
14
|
+
--
|
|
15
|
+
-- Only packages/core/src/records/publish.ts writes here.
|
|
16
|
+
CREATE TABLE core_publish_version (
|
|
17
|
+
object_type TEXT NOT NULL,
|
|
18
|
+
record_id TEXT NOT NULL,
|
|
19
|
+
version INTEGER NOT NULL CHECK (version >= 1),
|
|
20
|
+
-- The content fields' values when it was published, as the record operations return them.
|
|
21
|
+
content TEXT NOT NULL,
|
|
22
|
+
bytes INTEGER NOT NULL,
|
|
23
|
+
current INTEGER NOT NULL DEFAULT 0 CHECK (current IN (0, 1)),
|
|
24
|
+
published_at TEXT NOT NULL,
|
|
25
|
+
-- The staff user who published it.
|
|
26
|
+
published_by TEXT,
|
|
27
|
+
note TEXT CHECK (note IS NULL OR length(note) <= 500),
|
|
28
|
+
PRIMARY KEY (object_type, record_id, version)
|
|
29
|
+
);
|
|
30
|
+
CREATE UNIQUE INDEX core_publish_version_current_idx
|
|
31
|
+
ON core_publish_version (object_type, record_id) WHERE current = 1;
|
|
32
|
+
|
|
33
|
+
-- For dashboards and query.sql: every version, without its content.
|
|
34
|
+
CREATE VIEW rec_publish_version AS
|
|
35
|
+
SELECT object_type, record_id, version, current, bytes, published_at, published_by, note
|
|
36
|
+
FROM core_publish_version;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-- Stage 41, permissions granted one by one (ADR 0449): a human admin grants a staff account
|
|
2
|
+
-- named permissions on top of its role, from a fixed list (`records:publish`, `orders:refund`)
|
|
3
|
+
-- and the tool permissions installed packs declare grantable. A coach who is a member publishes
|
|
4
|
+
-- programs.
|
|
5
|
+
--
|
|
6
|
+
-- `granted_permissions` is a JSON list of permission names, or null for none. The operations
|
|
7
|
+
-- pipeline reads it on every staff call, in the statement that reads `pack_role`, and a
|
|
8
|
+
-- permission there counts only if it is still grantable. While a pack role is held, it is all the
|
|
9
|
+
-- account may do and grants count for nothing (ADR 0436). Only `user.setPermissions` (a human
|
|
10
|
+
-- admin) writes it.
|
|
11
|
+
ALTER TABLE core_user ADD COLUMN granted_permissions TEXT;
|
|
12
|
+
|
|
13
|
+
-- The list of users shows what an account was granted.
|
|
14
|
+
DROP VIEW rec_user;
|
|
15
|
+
CREATE VIEW rec_user AS
|
|
16
|
+
SELECT u.id, u.name, u.email, u.role, u.pack_role, u.granted_permissions, u.image, u.created_at
|
|
17
|
+
FROM core_user u
|
|
18
|
+
WHERE u.kind = 'human' AND u.support_grant_id IS NULL;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
-- Staff invites, and native staff sign-in through the system browser (ADR 0455).
|
|
2
|
+
--
|
|
3
|
+
-- core_user_invite: a human admin invites a person by address, with the role, pack role
|
|
4
|
+
-- (ADR 0436) and grants (ADR 0449) the account will hold from the start. Accepting it is signing
|
|
5
|
+
-- in with a code emailed to that address (Better Auth), or the first request under Cloudflare
|
|
6
|
+
-- Access: either makes the account in one insert with what the invite says, after marking the
|
|
7
|
+
-- invite accepted. An invite holds no secret; the code is Better Auth's, stored hashed in
|
|
8
|
+
-- core_verification. One pending invite per address.
|
|
9
|
+
CREATE TABLE core_user_invite (
|
|
10
|
+
id TEXT PRIMARY KEY,
|
|
11
|
+
email TEXT NOT NULL,
|
|
12
|
+
role TEXT NOT NULL CHECK (role IN ('admin', 'member', 'viewer')),
|
|
13
|
+
pack_role TEXT,
|
|
14
|
+
granted_permissions TEXT,
|
|
15
|
+
invited_by TEXT NOT NULL,
|
|
16
|
+
created_at TEXT NOT NULL,
|
|
17
|
+
updated_at TEXT NOT NULL,
|
|
18
|
+
expires_at TEXT NOT NULL,
|
|
19
|
+
accepted_at TEXT,
|
|
20
|
+
accepted_user_id TEXT,
|
|
21
|
+
revoked_at TEXT,
|
|
22
|
+
revoked_by TEXT
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
CREATE UNIQUE INDEX core_user_invite_pending ON core_user_invite (email)
|
|
26
|
+
WHERE accepted_at IS NULL AND revoked_at IS NULL;
|
|
27
|
+
CREATE INDEX core_user_invite_created ON core_user_invite (created_at);
|
|
28
|
+
|
|
29
|
+
-- core_native_handoff: the one-time code /native/staff-sign-in hands a native app through the
|
|
30
|
+
-- system browser, for staff whose sign-in is browser-based (Google, Cloudflare Access). Only its
|
|
31
|
+
-- SHA-256 hash is stored. It is deleted when presented, right or wrong, and lives 60 seconds; it
|
|
32
|
+
-- is bound to the app's PKCE challenge (S256) and the redirect address it was sent to.
|
|
33
|
+
CREATE TABLE core_native_handoff (
|
|
34
|
+
code_hash TEXT PRIMARY KEY,
|
|
35
|
+
user_id TEXT NOT NULL REFERENCES core_user (id) ON DELETE CASCADE,
|
|
36
|
+
challenge TEXT NOT NULL,
|
|
37
|
+
redirect_uri TEXT NOT NULL,
|
|
38
|
+
created_at TEXT NOT NULL,
|
|
39
|
+
expires_at TEXT NOT NULL
|
|
40
|
+
);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- The host's sign-in mail (ADR 0456): email-send's sign-in kind, made known so a human admin can
|
|
2
|
+
-- let it apply without review before any code is asked for. It is auto-approvable and not
|
|
3
|
+
-- auto-approved: sign-in by code says it is not set up until an admin turns it on
|
|
4
|
+
-- (outbound.setAutoApprove). Choosing the host's mail connection makes its vendor's kind known
|
|
5
|
+
-- too (customer.settings.update), so a deployment on another vendor gets its own.
|
|
6
|
+
INSERT INTO core_outbound_kind
|
|
7
|
+
(tag, vendor, label, auto_approvable, auto_approve, first_seen_at, updated_at)
|
|
8
|
+
VALUES ('email.signin', 'email-send', 'Send sign-in codes', 1, 0,
|
|
9
|
+
strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
|
|
10
|
+
ON CONFLICT (tag) DO UPDATE SET auto_approvable = 1;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- ADR 0457: a staff member confirms their own address, and the native sign-in page asks before it
|
|
2
|
+
-- hands a code to an app.
|
|
3
|
+
--
|
|
4
|
+
-- core_email_confirmation: one pending confirmation per account. The code (six digits, sent as the
|
|
5
|
+
-- host's sign-in mail to the account's own address) is stored as a hash, bound to the address it
|
|
6
|
+
-- was sent to: if the account's address is no longer that one, the code confirms nothing. It
|
|
7
|
+
-- lives five minutes and allows three tries; confirming deletes it.
|
|
8
|
+
CREATE TABLE core_email_confirmation (
|
|
9
|
+
user_id TEXT PRIMARY KEY REFERENCES core_user (id) ON DELETE CASCADE,
|
|
10
|
+
email TEXT NOT NULL,
|
|
11
|
+
code_hash TEXT NOT NULL,
|
|
12
|
+
attempts INTEGER NOT NULL DEFAULT 0,
|
|
13
|
+
created_at TEXT NOT NULL,
|
|
14
|
+
expires_at TEXT NOT NULL
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
-- core_native_sign_in_confirm: the one-time token on /native/staff-sign-in's confirm page. It is
|
|
18
|
+
-- bound to the signed-in account and to the request's redirect address, challenge and state;
|
|
19
|
+
-- only its hash is stored, it lives five minutes, and the confirming POST deletes it, right or
|
|
20
|
+
-- wrong. Only then is a handoff code (core_native_handoff) issued.
|
|
21
|
+
CREATE TABLE core_native_sign_in_confirm (
|
|
22
|
+
token_hash TEXT PRIMARY KEY,
|
|
23
|
+
user_id TEXT NOT NULL REFERENCES core_user (id) ON DELETE CASCADE,
|
|
24
|
+
redirect_uri TEXT NOT NULL,
|
|
25
|
+
challenge TEXT NOT NULL,
|
|
26
|
+
state TEXT NOT NULL,
|
|
27
|
+
created_at TEXT NOT NULL,
|
|
28
|
+
expires_at TEXT NOT NULL
|
|
29
|
+
);
|
|
30
|
+
CREATE INDEX core_native_sign_in_confirm_expires ON core_native_sign_in_confirm (expires_at);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- Stage 28 (ADR 0444, amended for issue #181): which field of a record's current version
|
|
2
|
+
-- references each media item. A picture is served to someone outside the org only when the field
|
|
3
|
+
-- that shows it is one they may read; a picture in a field the public does not read (a staff-only
|
|
4
|
+
-- image among the content) is not theirs, though the version is published.
|
|
5
|
+
--
|
|
6
|
+
-- The table is rebuilt with the field in its key, and filled from the current versions: every
|
|
7
|
+
-- `media` key in a version's content, under the top-level field it sits in
|
|
8
|
+
-- (`$.body.blocks[2].media` is the field `body`, `$.cover.media` is `cover`).
|
|
9
|
+
CREATE TABLE core_published_media_next (
|
|
10
|
+
media_id TEXT NOT NULL,
|
|
11
|
+
object_type TEXT NOT NULL,
|
|
12
|
+
record_id TEXT NOT NULL,
|
|
13
|
+
field TEXT NOT NULL,
|
|
14
|
+
PRIMARY KEY (media_id, object_type, record_id, field)
|
|
15
|
+
) WITHOUT ROWID;
|
|
16
|
+
|
|
17
|
+
INSERT OR IGNORE INTO core_published_media_next (media_id, object_type, record_id, field)
|
|
18
|
+
SELECT j.value, v.object_type, v.record_id,
|
|
19
|
+
substr(substr(j.fullkey, 3), 1, instr(substr(j.fullkey, 3) || '.', '.') - 1)
|
|
20
|
+
FROM core_publish_version v, json_tree(v.content) j
|
|
21
|
+
WHERE v.current = 1 AND j.key = 'media' AND j.type = 'text' AND j.value LIKE 'med\_%' ESCAPE '\';
|
|
22
|
+
|
|
23
|
+
DROP TABLE core_published_media;
|
|
24
|
+
ALTER TABLE core_published_media_next RENAME TO core_published_media;
|
|
25
|
+
CREATE INDEX core_published_media_record_idx ON core_published_media (object_type, record_id);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- The import door (ADR 0470): `cos content import` and `record.import`.
|
|
2
|
+
--
|
|
3
|
+
-- A picture's SHA-256, so an upload of a file the library already has returns that item instead
|
|
4
|
+
-- of storing it twice (a re-run of an import uploads nothing). Older items have none until they
|
|
5
|
+
-- are uploaded again.
|
|
6
|
+
ALTER TABLE core_media ADD COLUMN sha256 TEXT;
|
|
7
|
+
CREATE INDEX core_media_sha256_idx ON core_media (sha256) WHERE deleted_at IS NULL AND sha256 IS NOT NULL;
|
|
8
|
+
|
|
9
|
+
-- What an import made, by the key the import gave it: the record, and the values the import last
|
|
10
|
+
-- wrote, as the record operations return them, so a re-run creates nothing twice, updates a
|
|
11
|
+
-- record only while it still holds exactly what the import wrote, and reports a record a person
|
|
12
|
+
-- has changed since as a conflict instead of overwriting it. Only record.import writes here.
|
|
13
|
+
CREATE TABLE core_import_key (
|
|
14
|
+
object_type TEXT NOT NULL,
|
|
15
|
+
import_key TEXT NOT NULL CHECK (length(import_key) BETWEEN 1 AND 200),
|
|
16
|
+
record_id TEXT NOT NULL,
|
|
17
|
+
-- JSON: field name → the value the import wrote.
|
|
18
|
+
written TEXT NOT NULL,
|
|
19
|
+
imported_at TEXT NOT NULL,
|
|
20
|
+
imported_by TEXT NOT NULL,
|
|
21
|
+
PRIMARY KEY (object_type, import_key)
|
|
22
|
+
);
|
|
23
|
+
CREATE INDEX core_import_key_record_idx ON core_import_key (object_type, record_id);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- An AI actor asks for a publish (ADR 0480, stage 28 criterion 12): its request waits for a
|
|
2
|
+
-- person, and the version history says who asked and who approved.
|
|
3
|
+
--
|
|
4
|
+
-- A version published by approving a request keeps the person who approved it in `published_by`
|
|
5
|
+
-- (or `scheduled_by`), and the request beside it: `requested_by`, the staff user the AI actor
|
|
6
|
+
-- acted for, and `requested_via`, the actor (assistant, mcp, automation, extension). A person's
|
|
7
|
+
-- own publish leaves both empty. A scheduled publish carries them to the version the minute cron
|
|
8
|
+
-- publishes. Only packages/core/src/records/publish.ts writes either table.
|
|
9
|
+
ALTER TABLE core_publish_version ADD COLUMN requested_by TEXT;
|
|
10
|
+
ALTER TABLE core_publish_version ADD COLUMN requested_via TEXT
|
|
11
|
+
CHECK (requested_via IS NULL OR requested_via IN ('human', 'assistant', 'mcp', 'automation', 'extension'));
|
|
12
|
+
ALTER TABLE core_publish_schedule ADD COLUMN requested_by TEXT;
|
|
13
|
+
ALTER TABLE core_publish_schedule ADD COLUMN requested_via TEXT
|
|
14
|
+
CHECK (requested_via IS NULL OR requested_via IN ('human', 'assistant', 'mcp', 'automation', 'extension'));
|
|
15
|
+
|
|
16
|
+
DROP VIEW rec_publish_version;
|
|
17
|
+
CREATE VIEW rec_publish_version AS
|
|
18
|
+
SELECT object_type, record_id, version, current, bytes, published_at, published_by, note,
|
|
19
|
+
requested_by, requested_via
|
|
20
|
+
FROM core_publish_version;
|