@protobase/schema 0.9.0 → 0.11.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.
@@ -13,28 +13,28 @@ export declare const webhookResources: (schema: string, { deliveryLog }?: {
13
13
  }) => {
14
14
  webhookDeliveryLog?: ResourceBuilder<{
15
15
  readonly id: Field<string>;
16
- readonly subscriptionId: Field<string | number>;
17
- readonly tenantId: Field<string | null>;
18
- readonly eventId: Field<string>;
19
- readonly eventType: Field<string>;
16
+ readonly subscription_id: Field<string | number>;
17
+ readonly tenant_id: Field<string | null>;
18
+ readonly event_id: Field<string>;
19
+ readonly event_type: Field<string>;
20
20
  readonly status: Field<"failed" | "delivered">;
21
21
  readonly attempt: Field<number>;
22
- readonly statusCode: Field<number | null>;
22
+ readonly status_code: Field<number | null>;
23
23
  readonly response: Field<string | null>;
24
- readonly durationMs: Field<number>;
24
+ readonly duration_ms: Field<number>;
25
25
  readonly at: Field<string>;
26
26
  }, Ref<"id", string>> | undefined;
27
27
  webhookDeliveryLogView?: ViewBuilder<ResourceBuilder<{
28
28
  readonly id: Field<string>;
29
- readonly subscriptionId: Field<string | number>;
30
- readonly tenantId: Field<string | null>;
31
- readonly eventId: Field<string>;
32
- readonly eventType: Field<string>;
29
+ readonly subscription_id: Field<string | number>;
30
+ readonly tenant_id: Field<string | null>;
31
+ readonly event_id: Field<string>;
32
+ readonly event_type: Field<string>;
33
33
  readonly status: Field<"failed" | "delivered">;
34
34
  readonly attempt: Field<number>;
35
- readonly statusCode: Field<number | null>;
35
+ readonly status_code: Field<number | null>;
36
36
  readonly response: Field<string | null>;
37
- readonly durationMs: Field<number>;
37
+ readonly duration_ms: Field<number>;
38
38
  readonly at: Field<string>;
39
39
  }, Ref<"id", string>>> | undefined;
40
40
  webhookSubscriptions: ResourceBuilder<{
@@ -47,18 +47,18 @@ export declare const webhookResources: (schema: string, { deliveryLog }?: {
47
47
  readonly payload: Field<"full" | "thin">;
48
48
  readonly enabled: Field<boolean>;
49
49
  readonly secret: Field<string>;
50
- readonly previousSecret: null;
51
- readonly previousSecretUntil: null;
52
- readonly tenantId: Field<string | null>;
53
- readonly ownerId: Field<string | null>;
54
- readonly disabledReason: Field<string | null>;
55
- readonly lastSuccessAt: Field<string | null>;
56
- readonly failingSince: Field<string | null>;
57
- readonly createdAt: Field<string>;
58
- readonly updatedAt: Field<string>;
59
- readonly rotateSecret: Field<boolean>;
60
- readonly sendTest: Field<boolean>;
61
- readonly resendFailed: Field<boolean>;
50
+ readonly previous_secret: null;
51
+ readonly previous_secret_until: null;
52
+ readonly tenant_id: Field<string | null>;
53
+ readonly owner_id: Field<string | null>;
54
+ readonly disabled_reason: Field<string | null>;
55
+ readonly last_success_at: Field<string | null>;
56
+ readonly failing_since: Field<string | null>;
57
+ readonly created_at: Field<string>;
58
+ readonly updated_at: Field<string>;
59
+ readonly rotate_secret: Field<boolean>;
60
+ readonly send_test: Field<boolean>;
61
+ readonly resend_failed: Field<boolean>;
62
62
  }, Ref<"id", string>>;
63
63
  webhookSubscriptionsView: ViewBuilder<ResourceBuilder<{
64
64
  readonly id: Field<string>;
@@ -70,43 +70,43 @@ export declare const webhookResources: (schema: string, { deliveryLog }?: {
70
70
  readonly payload: Field<"full" | "thin">;
71
71
  readonly enabled: Field<boolean>;
72
72
  readonly secret: Field<string>;
73
- readonly previousSecret: null;
74
- readonly previousSecretUntil: null;
75
- readonly tenantId: Field<string | null>;
76
- readonly ownerId: Field<string | null>;
77
- readonly disabledReason: Field<string | null>;
78
- readonly lastSuccessAt: Field<string | null>;
79
- readonly failingSince: Field<string | null>;
80
- readonly createdAt: Field<string>;
81
- readonly updatedAt: Field<string>;
82
- readonly rotateSecret: Field<boolean>;
83
- readonly sendTest: Field<boolean>;
84
- readonly resendFailed: Field<boolean>;
73
+ readonly previous_secret: null;
74
+ readonly previous_secret_until: null;
75
+ readonly tenant_id: Field<string | null>;
76
+ readonly owner_id: Field<string | null>;
77
+ readonly disabled_reason: Field<string | null>;
78
+ readonly last_success_at: Field<string | null>;
79
+ readonly failing_since: Field<string | null>;
80
+ readonly created_at: Field<string>;
81
+ readonly updated_at: Field<string>;
82
+ readonly rotate_secret: Field<boolean>;
83
+ readonly send_test: Field<boolean>;
84
+ readonly resend_failed: Field<boolean>;
85
85
  }, Ref<"id", string>>>;
86
86
  webhookDeliveries: ResourceBuilder<{
87
87
  readonly id: Field<string>;
88
- readonly subscriptionId: Field<string | number>;
89
- readonly tenantId: Field<string | null>;
90
- readonly eventType: Field<string>;
91
- readonly eventId: Field<string>;
88
+ readonly subscription_id: Field<string | number>;
89
+ readonly tenant_id: Field<string | null>;
90
+ readonly event_type: Field<string>;
91
+ readonly event_id: Field<string>;
92
92
  readonly status: Field<"waiting" | "failed">;
93
93
  readonly attempt: Field<number>;
94
- readonly nextAttempt: Field<string | null>;
95
- readonly lastError: Field<string | null>;
96
- readonly createdAt: Field<string>;
94
+ readonly next_attempt: Field<string | null>;
95
+ readonly last_error: Field<string | null>;
96
+ readonly created_at: Field<string>;
97
97
  readonly resend: Field<boolean>;
98
98
  }, Ref<"id", string>>;
99
99
  webhookDeliveriesView: ViewBuilder<ResourceBuilder<{
100
100
  readonly id: Field<string>;
101
- readonly subscriptionId: Field<string | number>;
102
- readonly tenantId: Field<string | null>;
103
- readonly eventType: Field<string>;
104
- readonly eventId: Field<string>;
101
+ readonly subscription_id: Field<string | number>;
102
+ readonly tenant_id: Field<string | null>;
103
+ readonly event_type: Field<string>;
104
+ readonly event_id: Field<string>;
105
105
  readonly status: Field<"waiting" | "failed">;
106
106
  readonly attempt: Field<number>;
107
- readonly nextAttempt: Field<string | null>;
108
- readonly lastError: Field<string | null>;
109
- readonly createdAt: Field<string>;
107
+ readonly next_attempt: Field<string | null>;
108
+ readonly last_error: Field<string | null>;
109
+ readonly created_at: Field<string>;
110
110
  readonly resend: Field<boolean>;
111
111
  }, Ref<"id", string>>>;
112
112
  };
@@ -4,7 +4,7 @@ import { layout } from "../layout.js";
4
4
  import { view } from "../view.js";
5
5
  //#region src/webhooks/webhook-resources.ts
6
6
  /** Webhook subscriptions: a row per subscription someone made in the admin app, scoped to their tenant. */
7
- const subscriptionsResource = (schema) => resource("webhookSubscriptions").table(`${schema}.subscriptions`).fields({
7
+ const subscriptionsResource = (schema) => resource("webhook_subscriptions").table(`${schema}.subscriptions`).fields({
8
8
  id: f.uuid().readOnly().dbDefault(),
9
9
  name: f.text().min(1).max(100).filterable().sortable(),
10
10
  events: f.text().min(1).max(2e3),
@@ -14,20 +14,20 @@ const subscriptionsResource = (schema) => resource("webhookSubscriptions").table
14
14
  payload: f.enum(["full", "thin"]).default("full"),
15
15
  enabled: f.boolean().default(true).filterable(),
16
16
  secret: f.text().sensitive().readOnly().dbDefault(),
17
- previousSecret: null,
18
- previousSecretUntil: null,
19
- tenantId: f.text().optional().readOnly(),
20
- ownerId: f.text().optional().readOnly().dbDefault(),
21
- disabledReason: f.text().optional().readOnly(),
22
- lastSuccessAt: f.timestamp().optional().readOnly().sortable(),
23
- failingSince: f.timestamp().optional().readOnly(),
24
- createdAt: f.timestamp().readOnly().dbDefault().sortable(),
25
- updatedAt: f.timestamp().readOnly().dbDefault(),
26
- rotateSecret: f.boolean().default(false),
27
- sendTest: f.boolean().default(false),
28
- resendFailed: f.boolean().default(false)
29
- }).primaryKey((r) => r.id).tenant((r) => r.tenantId).owner((r) => r.ownerId).search((r) => [r.name, r.url]);
30
- const subscriptionsView = view("webhookSubscriptions").names({
17
+ previous_secret: null,
18
+ previous_secret_until: null,
19
+ tenant_id: f.text().optional().readOnly(),
20
+ owner_id: f.text().optional().readOnly().dbDefault(),
21
+ disabled_reason: f.text().optional().readOnly(),
22
+ last_success_at: f.timestamp().optional().readOnly().sortable(),
23
+ failing_since: f.timestamp().optional().readOnly(),
24
+ created_at: f.timestamp().readOnly().dbDefault().sortable(),
25
+ updated_at: f.timestamp().readOnly().dbDefault(),
26
+ rotate_secret: f.boolean().default(false),
27
+ send_test: f.boolean().default(false),
28
+ resend_failed: f.boolean().default(false)
29
+ }).primaryKey((r) => r.id).tenant((r) => r.tenant_id).owner((r) => r.owner_id).search((r) => [r.name, r.url]);
30
+ const subscriptionsView = view("webhook_subscriptions").names({
31
31
  singular: "Webhook subscription",
32
32
  plural: "Webhook subscriptions"
33
33
  }).icon("webhook").title((r) => r.name).help("Sends the app's events to a URL as they happen, signed with Standard Webhooks. It delivers as its owner: only the records and fields they may read.").fields((r) => ({
@@ -40,18 +40,18 @@ const subscriptionsView = view("webhookSubscriptions").names({
40
40
  thin: "Thin"
41
41
  }),
42
42
  secret: r.secret.help("Receivers check the webhook-signature header with it"),
43
- disabledReason: r.disabledReason.label("Disabled because"),
44
- lastSuccessAt: r.lastSuccessAt.label("Last success"),
45
- failingSince: r.failingSince.label("Failing since")
43
+ disabled_reason: r.disabled_reason.label("Disabled because"),
44
+ last_success_at: r.last_success_at.label("Last success"),
45
+ failing_since: r.failing_since.label("Failing since")
46
46
  })).list((r) => ({
47
47
  columns: [
48
48
  r.name,
49
49
  r.events,
50
50
  r.url,
51
51
  r.enabled,
52
- r.lastSuccessAt
52
+ r.last_success_at
53
53
  ],
54
- sort: [[r.createdAt, "desc"]]
54
+ sort: [[r.created_at, "desc"]]
55
55
  })).layout((r) => [
56
56
  layout.section("Subscription", [
57
57
  r.name,
@@ -64,38 +64,38 @@ const subscriptionsView = view("webhookSubscriptions").names({
64
64
  ]),
65
65
  layout.section("Signing", [r.secret]),
66
66
  layout.sidebar([
67
- r.lastSuccessAt,
68
- r.failingSince,
69
- r.disabledReason,
70
- r.createdAt
67
+ r.last_success_at,
68
+ r.failing_since,
69
+ r.disabled_reason,
70
+ r.created_at
71
71
  ]),
72
72
  layout.related("Waiting and failed deliveries", {
73
- resource: "webhookDeliveries",
74
- field: "subscriptionId",
73
+ resource: "webhook_deliveries",
74
+ field: "subscription_id",
75
75
  columns: [
76
- "eventType",
76
+ "event_type",
77
77
  "status",
78
78
  "attempt",
79
- "nextAttempt",
80
- "lastError"
79
+ "next_attempt",
80
+ "last_error"
81
81
  ]
82
82
  })
83
83
  ]).actions((a) => [
84
- a.update("sendTest", {
84
+ a.update("send_test", {
85
85
  label: "Send test event",
86
86
  icon: "send",
87
- set: { sendTest: true }
87
+ set: { send_test: true }
88
88
  }),
89
- a.update("resendFailed", {
89
+ a.update("resend_failed", {
90
90
  label: "Resend failed",
91
91
  icon: "rotate-ccw",
92
- set: { resendFailed: true },
92
+ set: { resend_failed: true },
93
93
  confirm: "Try every failed delivery of this subscription once more?"
94
94
  }),
95
- a.update("rotateSecret", {
95
+ a.update("rotate_secret", {
96
96
  label: "Rotate secret",
97
97
  icon: "key-round",
98
- set: { rotateSecret: true },
98
+ set: { rotate_secret: true },
99
99
  confirm: "Make a new secret? The old one keeps signing too for 24 hours."
100
100
  }),
101
101
  a.update("disable", {
@@ -105,51 +105,51 @@ const subscriptionsView = view("webhookSubscriptions").names({
105
105
  })
106
106
  ]);
107
107
  /** The deliveries of webhook subscriptions that wait for a retry or failed for good: delivery jobs, not a table. */
108
- const deliveriesResource = (schema) => resource("webhookDeliveries").table(`${schema}.deliveries`).fields({
108
+ const deliveriesResource = (schema) => resource("webhook_deliveries").table(`${schema}.deliveries`).fields({
109
109
  id: f.uuid().readOnly(),
110
- subscriptionId: f.relation("webhookSubscriptions").readOnly().filterable(),
111
- tenantId: f.text().optional().readOnly(),
112
- eventType: f.text().readOnly().filterable().sortable(),
113
- eventId: f.text().readOnly().filterable(),
110
+ subscription_id: f.relation("webhook_subscriptions").readOnly().filterable(),
111
+ tenant_id: f.text().optional().readOnly(),
112
+ event_type: f.text().readOnly().filterable().sortable(),
113
+ event_id: f.text().readOnly().filterable(),
114
114
  status: f.enum(["waiting", "failed"]).readOnly().filterable(),
115
115
  attempt: f.integer().readOnly(),
116
- nextAttempt: f.timestamp().optional().readOnly().sortable(),
117
- lastError: f.text().optional().readOnly(),
118
- createdAt: f.timestamp().readOnly().sortable(),
116
+ next_attempt: f.timestamp().optional().readOnly().sortable(),
117
+ last_error: f.text().optional().readOnly(),
118
+ created_at: f.timestamp().readOnly().sortable(),
119
119
  resend: f.boolean()
120
- }).primaryKey((r) => r.id).tenant((r) => r.tenantId).access({
120
+ }).primaryKey((r) => r.id).tenant((r) => r.tenant_id).access({
121
121
  create: () => false,
122
122
  delete: () => false
123
123
  });
124
- const deliveriesView = view("webhookDeliveries").names({
124
+ const deliveriesView = view("webhook_deliveries").names({
125
125
  singular: "Webhook delivery",
126
126
  plural: "Webhook deliveries"
127
- }).icon("send").title((r) => r.eventType).help("Deliveries that wait for their next try or failed for good. A delivery leaves the list once it succeeds.").fields((r) => ({
128
- eventType: r.eventType.label("Event"),
129
- eventId: r.eventId.label("Event id").format("code"),
130
- nextAttempt: r.nextAttempt.label("Next try"),
131
- lastError: r.lastError.label("Last error"),
127
+ }).icon("send").title((r) => r.event_type).help("Deliveries that wait for their next try or failed for good. A delivery leaves the list once it succeeds.").fields((r) => ({
128
+ event_type: r.event_type.label("Event"),
129
+ event_id: r.event_id.label("Event id").format("code"),
130
+ next_attempt: r.next_attempt.label("Next try"),
131
+ last_error: r.last_error.label("Last error"),
132
132
  attempt: r.attempt.label("Tries")
133
133
  })).list((r) => ({
134
134
  columns: [
135
- r.eventType,
136
- r.subscriptionId,
135
+ r.event_type,
136
+ r.subscription_id,
137
137
  r.status,
138
138
  r.attempt,
139
- r.nextAttempt,
140
- r.lastError
139
+ r.next_attempt,
140
+ r.last_error
141
141
  ],
142
- sort: [[r.createdAt, "desc"]]
142
+ sort: [[r.created_at, "desc"]]
143
143
  })).layout((r) => [layout.section("Delivery", [
144
- r.subscriptionId,
145
- r.eventType,
146
- r.eventId,
147
- r.lastError
144
+ r.subscription_id,
145
+ r.event_type,
146
+ r.event_id,
147
+ r.last_error
148
148
  ]), layout.sidebar([
149
149
  r.status,
150
150
  r.attempt,
151
- r.nextAttempt,
152
- r.createdAt
151
+ r.next_attempt,
152
+ r.created_at
153
153
  ])]).actions((a) => [a.update("resend", {
154
154
  label: "Resend",
155
155
  icon: "rotate-ccw",
@@ -157,39 +157,39 @@ const deliveriesView = view("webhookDeliveries").names({
157
157
  confirm: "Try this delivery once more, from now?"
158
158
  })]);
159
159
  /** Every try of every webhook subscription's deliveries, for 30 days (`deliveryLog: true`). */
160
- const deliveryLogResource = (schema) => resource("webhookDeliveryLog").table(`${schema}.delivery_log`).fields({
160
+ const deliveryLogResource = (schema) => resource("webhook_delivery_log").table(`${schema}.delivery_log`).fields({
161
161
  id: f.bigint().readOnly(),
162
- subscriptionId: f.relation("webhookSubscriptions").readOnly().filterable(),
163
- tenantId: f.text().optional().readOnly(),
164
- eventId: f.text().readOnly().filterable(),
165
- eventType: f.text().readOnly().filterable().sortable(),
162
+ subscription_id: f.relation("webhook_subscriptions").readOnly().filterable(),
163
+ tenant_id: f.text().optional().readOnly(),
164
+ event_id: f.text().readOnly().filterable(),
165
+ event_type: f.text().readOnly().filterable().sortable(),
166
166
  status: f.enum(["delivered", "failed"]).readOnly().filterable(),
167
167
  attempt: f.integer().readOnly(),
168
- statusCode: f.integer().optional().readOnly().filterable(),
168
+ status_code: f.integer().optional().readOnly().filterable(),
169
169
  response: f.text().optional().readOnly(),
170
- durationMs: f.integer().readOnly(),
170
+ duration_ms: f.integer().readOnly(),
171
171
  at: f.timestamp().readOnly().filterable().sortable()
172
- }).primaryKey((r) => r.id).tenant((r) => r.tenantId).access({
172
+ }).primaryKey((r) => r.id).tenant((r) => r.tenant_id).access({
173
173
  create: () => false,
174
174
  update: () => false,
175
175
  delete: () => false
176
176
  });
177
- const deliveryLogView = view("webhookDeliveryLog").names({
177
+ const deliveryLogView = view("webhook_delivery_log").names({
178
178
  singular: "Webhook delivery log entry",
179
179
  plural: "Webhook delivery log"
180
- }).icon("scroll-text").title((r) => r.eventType).fields((r) => ({
181
- eventType: r.eventType.label("Event"),
182
- statusCode: r.statusCode.label("Status code"),
183
- durationMs: r.durationMs.label("Duration (ms)"),
180
+ }).icon("scroll-text").title((r) => r.event_type).fields((r) => ({
181
+ event_type: r.event_type.label("Event"),
182
+ status_code: r.status_code.label("Status code"),
183
+ duration_ms: r.duration_ms.label("Duration (ms)"),
184
184
  at: r.at.label("When")
185
185
  })).list((r) => ({
186
186
  columns: [
187
187
  r.at,
188
- r.eventType,
189
- r.subscriptionId,
188
+ r.event_type,
189
+ r.subscription_id,
190
190
  r.status,
191
- r.statusCode,
192
- r.durationMs
191
+ r.status_code,
192
+ r.duration_ms
193
193
  ],
194
194
  sort: [[r.at, "desc"]]
195
195
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/schema",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "Resource, field, view and access definitions for Protobase configs.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {