@ericminassian/platform-core 0.1.0 → 0.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 (45) hide show
  1. package/dist/api.d.ts +947 -209
  2. package/dist/api.js +335 -1
  3. package/dist/api.js.map +1 -1
  4. package/dist/auth.d.ts +19 -0
  5. package/dist/auth.js +29 -0
  6. package/dist/auth.js.map +1 -1
  7. package/dist/bindings.d.ts +8 -2
  8. package/dist/bindings.js.map +1 -1
  9. package/dist/cloudfront-function.js +6 -0
  10. package/dist/cloudfront-function.js.map +1 -1
  11. package/dist/config.d.ts +11 -1
  12. package/dist/config.js +7 -0
  13. package/dist/config.js.map +1 -1
  14. package/dist/constants.d.ts +11 -0
  15. package/dist/constants.js.map +1 -1
  16. package/dist/manifest.d.ts +203 -90
  17. package/dist/manifest.js +129 -93
  18. package/dist/manifest.js.map +1 -1
  19. package/dist/naming.d.ts +13 -2
  20. package/dist/naming.js +12 -1
  21. package/dist/naming.js.map +1 -1
  22. package/dist/platform-api.d.ts +5337 -0
  23. package/dist/platform-api.js +343 -0
  24. package/dist/platform-api.js.map +1 -0
  25. package/dist/router/decide.d.ts +5 -1
  26. package/dist/router/decide.js +7 -2
  27. package/dist/router.d.ts +1 -1
  28. package/dist/telemetry.d.ts +236 -74
  29. package/dist/telemetry.js +97 -0
  30. package/dist/telemetry.js.map +1 -1
  31. package/package.json +12 -6
  32. package/src/api.ts +427 -231
  33. package/src/auth.ts +33 -0
  34. package/src/bindings.ts +8 -2
  35. package/src/cloudfront-function.ts +6 -0
  36. package/src/config.ts +10 -2
  37. package/src/constants.ts +12 -0
  38. package/src/manifest.ts +280 -113
  39. package/src/naming.ts +13 -2
  40. package/src/platform-api.ts +504 -0
  41. package/src/router/decide.d.ts +5 -1
  42. package/src/router/decide.js +7 -2
  43. package/src/router.ts +1 -1
  44. package/src/telemetry.ts +107 -85
  45. package/platform.schema.json +0 -213
package/src/telemetry.ts CHANGED
@@ -5,100 +5,121 @@
5
5
  * aggregates rollups into the telemetry table. Logs Insights covers the rest
6
6
  * (search, traces) on demand. No CloudWatch custom metrics are ever created.
7
7
  */
8
+ import { Schema } from 'effect';
8
9
 
9
- export type TelemetryKind = 'req' | 'err' | 'job' | 'span' | 'log' | 'metric' | 'env';
10
+ export const TelemetryKind = Schema.Literals(['req', 'err', 'job', 'span', 'log', 'metric', 'env']);
11
+ export type TelemetryKind = typeof TelemetryKind.Type;
10
12
 
11
- interface Base {
13
+ const base = {
12
14
  /** Marker so the subscription filter only matches platform lines. */
13
- _p: 1;
14
- t: TelemetryKind;
15
+ _p: Schema.Literal(1),
15
16
  /** Epoch milliseconds. */
16
- ts: number;
17
- app: string;
18
- stage: string;
17
+ ts: Schema.Finite,
18
+ app: Schema.String,
19
+ stage: Schema.String,
19
20
  /** Deployment id. */
20
- rev: string;
21
- trace?: string;
22
- span?: string;
23
- parent?: string;
24
- }
25
-
26
- export interface RequestEvent extends Base {
27
- t: 'req';
28
- method: string;
21
+ rev: Schema.String,
22
+ trace: Schema.optional(Schema.String),
23
+ span: Schema.optional(Schema.String),
24
+ parent: Schema.optional(Schema.String),
25
+ };
26
+
27
+ export const RequestEvent = Schema.Struct({
28
+ ...base,
29
+ t: Schema.Literal('req'),
30
+ method: Schema.String,
29
31
  /** Route pattern when known (`/api/todos/:id`), else the raw path. */
30
- route: string;
31
- path: string;
32
- status: number;
32
+ route: Schema.String,
33
+ path: Schema.String,
34
+ status: Schema.Finite,
33
35
  /** Duration in ms. */
34
- dur: number;
35
- bytes?: number;
36
- country?: string;
36
+ dur: Schema.Finite,
37
+ bytes: Schema.optional(Schema.Finite),
38
+ country: Schema.optional(Schema.String),
37
39
  /** Hashed user id when signed in. */
38
- user?: string;
39
- cold?: boolean;
40
- }
41
-
42
- export interface ErrorEvent extends Base {
43
- t: 'err';
44
- source: 'http' | 'job' | 'unhandled' | 'log';
45
- name: string;
46
- message: string;
47
- stack?: string;
48
- route?: string;
49
- job?: string;
50
- fingerprint: string;
51
- }
52
-
53
- export interface JobEvent extends Base {
54
- t: 'job';
55
- kind: 'queue' | 'event' | 'cron' | 'invoke';
56
- name: string;
57
- status: 'ok' | 'error';
58
- dur: number;
59
- attempt?: number;
60
- }
61
-
62
- export interface SpanEvent extends Base {
63
- t: 'span';
40
+ user: Schema.optional(Schema.String),
41
+ cold: Schema.optional(Schema.Boolean),
42
+ });
43
+ export type RequestEvent = typeof RequestEvent.Type;
44
+
45
+ export const ErrorEvent = Schema.Struct({
46
+ ...base,
47
+ t: Schema.Literal('err'),
48
+ source: Schema.Literals(['http', 'job', 'unhandled', 'log']),
49
+ name: Schema.String,
50
+ message: Schema.String,
51
+ stack: Schema.optional(Schema.String),
52
+ route: Schema.optional(Schema.String),
53
+ job: Schema.optional(Schema.String),
54
+ fingerprint: Schema.String,
55
+ });
56
+ export type ErrorEvent = typeof ErrorEvent.Type;
57
+
58
+ export const JobEvent = Schema.Struct({
59
+ ...base,
60
+ t: Schema.Literal('job'),
61
+ kind: Schema.Literals(['queue', 'event', 'cron', 'invoke']),
62
+ name: Schema.String,
63
+ status: Schema.Literals(['ok', 'error']),
64
+ dur: Schema.Finite,
65
+ attempt: Schema.optional(Schema.Finite),
66
+ });
67
+ export type JobEvent = typeof JobEvent.Type;
68
+
69
+ export const SpanEvent = Schema.Struct({
70
+ ...base,
71
+ t: Schema.Literal('span'),
64
72
  /** `db.get`, `db.query`, `queue.send`, `events.publish`, `storage.put`, `fetch`, ... */
65
- op: string;
66
- name?: string;
67
- dur: number;
68
- status: 'ok' | 'error';
73
+ op: Schema.String,
74
+ name: Schema.optional(Schema.String),
75
+ dur: Schema.Finite,
76
+ status: Schema.Literals(['ok', 'error']),
69
77
  /** Start offset relative to the trace root, ms. */
70
- start?: number;
71
- }
72
-
73
- export interface LogEvent extends Base {
74
- t: 'log';
75
- level: 'debug' | 'info' | 'warn' | 'error';
76
- msg: string;
77
- [field: string]: unknown;
78
- }
79
-
80
- export interface MetricEvent extends Base {
81
- t: 'metric';
82
- name: string;
83
- value: number;
84
- unit?: string;
85
- }
86
-
87
- export interface EnvEvent extends Base {
88
- t: 'env';
89
- event: 'start' | 'stop';
90
- runtime: 'web' | 'worker';
91
- initMs?: number;
92
- }
93
-
94
- export type TelemetryEvent =
95
- | RequestEvent
96
- | ErrorEvent
97
- | JobEvent
98
- | SpanEvent
99
- | LogEvent
100
- | MetricEvent
101
- | EnvEvent;
78
+ start: Schema.optional(Schema.Finite),
79
+ });
80
+ export type SpanEvent = typeof SpanEvent.Type;
81
+
82
+ /** A log line; any other fields are the structured fields it was logged with. */
83
+ export const LogEvent = Schema.StructWithRest(
84
+ Schema.Struct({
85
+ ...base,
86
+ t: Schema.Literal('log'),
87
+ level: Schema.Literals(['debug', 'info', 'warn', 'error']),
88
+ msg: Schema.String,
89
+ }),
90
+ [Schema.Record(Schema.String, Schema.Unknown)],
91
+ );
92
+ export type LogEvent = typeof LogEvent.Type;
93
+
94
+ export const MetricEvent = Schema.Struct({
95
+ ...base,
96
+ t: Schema.Literal('metric'),
97
+ name: Schema.String,
98
+ value: Schema.Finite,
99
+ unit: Schema.optional(Schema.String),
100
+ });
101
+ export type MetricEvent = typeof MetricEvent.Type;
102
+
103
+ export const EnvEvent = Schema.Struct({
104
+ ...base,
105
+ t: Schema.Literal('env'),
106
+ event: Schema.Literals(['start', 'stop']),
107
+ runtime: Schema.Literals(['web', 'worker']),
108
+ initMs: Schema.optional(Schema.Finite),
109
+ });
110
+ export type EnvEvent = typeof EnvEvent.Type;
111
+
112
+ /** One telemetry line, as the SDK writes it and the telemetry processor reads it. */
113
+ export const TelemetryEvent = Schema.Union([
114
+ RequestEvent,
115
+ ErrorEvent,
116
+ JobEvent,
117
+ SpanEvent,
118
+ LogEvent,
119
+ MetricEvent,
120
+ EnvEvent,
121
+ ]);
122
+ export type TelemetryEvent = typeof TelemetryEvent.Type;
102
123
 
103
124
  /** Account-level subscription filter: only aggregate-worthy kinds reach the processor. */
104
125
  export const TELEMETRY_FILTER_PATTERN =
@@ -143,7 +164,8 @@ export function percentile(hist: readonly number[], p: number): number | null {
143
164
  // Rollups (telemetry table layout)
144
165
  // ---------------------------------------------------------------------------
145
166
 
146
- export type Resolution = '1m' | '1h' | '1d';
167
+ export const Resolution = Schema.Literals(['1m', '1h', '1d']);
168
+ export type Resolution = typeof Resolution.Type;
147
169
 
148
170
  export const RESOLUTION_MS: Record<Resolution, number> = { '1m': 60_000, '1h': 3_600_000, '1d': 86_400_000 };
149
171
 
@@ -1,213 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://raw.githubusercontent.com/eric-minassian/platform/main/packages/core/platform.schema.json",
4
- "title": "platform.json",
5
- "description": "What an app needs from the platform. See docs/DESIGN.md.",
6
- "type": "object",
7
- "properties": {
8
- "$schema": {
9
- "type": "string"
10
- },
11
- "name": {
12
- "type": "string",
13
- "pattern": "^[a-z](?:[a-z0-9]|-(?!-)){1,28}[a-z0-9]$"
14
- },
15
- "description": {
16
- "type": "string",
17
- "maxLength": 200
18
- },
19
- "web": {
20
- "type": "object",
21
- "properties": {
22
- "server": {
23
- "type": "string"
24
- },
25
- "static": {
26
- "type": "string"
27
- },
28
- "build": {
29
- "type": "string"
30
- },
31
- "dev": {
32
- "type": "object",
33
- "properties": {
34
- "command": {
35
- "type": "string"
36
- },
37
- "port": {
38
- "type": "integer",
39
- "exclusiveMinimum": 0,
40
- "maximum": 9007199254740991
41
- }
42
- },
43
- "required": ["command", "port"]
44
- },
45
- "spa": {
46
- "default": true,
47
- "type": "boolean"
48
- },
49
- "serverRoutes": {
50
- "default": ["/api/"],
51
- "type": "array",
52
- "items": {
53
- "type": "string",
54
- "format": "starts_with",
55
- "pattern": "^\\/.*"
56
- }
57
- },
58
- "timeoutSeconds": {
59
- "default": 30,
60
- "type": "integer",
61
- "minimum": 3,
62
- "maximum": 900
63
- },
64
- "concurrency": {
65
- "default": 64,
66
- "type": "integer",
67
- "minimum": 1,
68
- "maximum": 128
69
- }
70
- }
71
- },
72
- "worker": {
73
- "type": "object",
74
- "properties": {
75
- "entry": {
76
- "default": "src/worker.ts",
77
- "type": "string"
78
- },
79
- "timeoutSeconds": {
80
- "default": 60,
81
- "type": "integer",
82
- "minimum": 1,
83
- "maximum": 900
84
- },
85
- "memoryMb": {
86
- "default": 512,
87
- "type": "integer",
88
- "minimum": 128,
89
- "maximum": 10240
90
- }
91
- }
92
- },
93
- "auth": {
94
- "default": false,
95
- "anyOf": [
96
- {
97
- "type": "boolean"
98
- },
99
- {
100
- "type": "object",
101
- "properties": {
102
- "required": {
103
- "default": false,
104
- "type": "boolean"
105
- }
106
- }
107
- }
108
- ]
109
- },
110
- "db": {
111
- "default": false,
112
- "type": "boolean"
113
- },
114
- "queues": {
115
- "default": {},
116
- "type": "object",
117
- "propertyNames": {
118
- "type": "string",
119
- "pattern": "^(?!.*--)[a-z](?:[a-z0-9-]{0,18}[a-z0-9])?$"
120
- },
121
- "additionalProperties": {
122
- "type": "object",
123
- "properties": {
124
- "batchSize": {
125
- "default": 10,
126
- "type": "integer",
127
- "minimum": 1,
128
- "maximum": 10
129
- },
130
- "visibilityTimeoutSeconds": {
131
- "type": "integer",
132
- "minimum": 0,
133
- "maximum": 43200
134
- },
135
- "maxReceiveCount": {
136
- "default": 5,
137
- "type": "integer",
138
- "minimum": 1,
139
- "maximum": 1000
140
- },
141
- "concurrency": {
142
- "type": "integer",
143
- "minimum": 2,
144
- "maximum": 1000
145
- }
146
- }
147
- }
148
- },
149
- "events": {
150
- "default": [],
151
- "type": "array",
152
- "items": {
153
- "type": "string",
154
- "pattern": "^[a-zA-Z][a-zA-Z0-9._:-]{0,63}$"
155
- }
156
- },
157
- "crons": {
158
- "default": {},
159
- "type": "object",
160
- "propertyNames": {
161
- "type": "string",
162
- "pattern": "^(?!.*--)[a-z](?:[a-z0-9-]{0,18}[a-z0-9])?$"
163
- },
164
- "additionalProperties": {
165
- "anyOf": [
166
- {
167
- "type": "string"
168
- },
169
- {
170
- "type": "object",
171
- "properties": {
172
- "schedule": {
173
- "type": "string"
174
- },
175
- "timezone": {
176
- "type": "string"
177
- }
178
- },
179
- "required": ["schedule"]
180
- }
181
- ]
182
- }
183
- },
184
- "storage": {
185
- "default": [],
186
- "type": "array",
187
- "items": {
188
- "type": "string",
189
- "pattern": "^(?!.*--)[a-z](?:[a-z0-9-]{0,18}[a-z0-9])?$"
190
- }
191
- },
192
- "secrets": {
193
- "default": [],
194
- "type": "array",
195
- "items": {
196
- "type": "string",
197
- "pattern": "^[A-Z][A-Z0-9_]{0,63}$"
198
- }
199
- },
200
- "env": {
201
- "default": {},
202
- "type": "object",
203
- "propertyNames": {
204
- "type": "string",
205
- "pattern": "^[A-Z][A-Z0-9_]{0,63}$"
206
- },
207
- "additionalProperties": {
208
- "type": "string"
209
- }
210
- }
211
- },
212
- "required": ["name"]
213
- }