@lunora/bindings 1.0.0-alpha.1 → 1.0.0-alpha.10
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.md +6 -0
- package/dist/analytics/index.d.mts +73 -73
- package/dist/analytics/index.d.ts +73 -73
- package/dist/analytics/index.mjs +1 -1
- package/dist/images/index.d.mts +147 -147
- package/dist/images/index.d.ts +147 -147
- package/dist/images/index.mjs +3 -3
- package/dist/kv/index.d.mts +146 -52
- package/dist/kv/index.d.ts +146 -52
- package/dist/kv/index.mjs +2 -1
- package/dist/packem_shared/{AnalyticsSqlError-CGTdsi4H.mjs → AnalyticsSqlError-C2nz3jpH.mjs} +4 -5
- package/dist/packem_shared/{R2SqlError-DkQZ4Omg.mjs → R2SqlError-drPKSCZ3.mjs} +9 -9
- package/dist/packem_shared/{SelectBuilder-BGXfCF0J.mjs → SelectBuilder-BOqJQHEv.mjs} +6 -5
- package/dist/packem_shared/{SetOperation-CGRu681M.mjs → SetOperation-DmPgUL8W.mjs} +3 -2
- package/dist/packem_shared/{Sql-CkDyJ_Sc.mjs → Sql-B3zq2YGx.mjs} +21 -1
- package/dist/packem_shared/{WindowExpression-C2vj7oNX.mjs → WindowExpression-BT_uA6g1.mjs} +1 -1
- package/dist/packem_shared/{WindowFunction-CuKHfZX3.mjs → WindowFunction-DrnuZUF6.mjs} +3 -3
- package/dist/packem_shared/{asc-C6Jbaa6R.mjs → asc-DZbQCxh1.mjs} +1 -1
- package/dist/packem_shared/{buildImageDeliveryUrl-D1sVfIOP.mjs → buildImageDeliveryUrl-qZ7XbqTL.mjs} +9 -4
- package/dist/packem_shared/{buildSignedImageUrl-Otdgc_jO.mjs → buildSignedImageUrl-DNUFfyGP.mjs} +47 -30
- package/dist/packem_shared/{concurrent-Dj5sOibv.mjs → concurrent-CkCEVwqP.mjs} +17 -1
- package/dist/packem_shared/{createContextVectors-BSizpmu5.mjs → createContextVectors-DwZtnPeC.mjs} +1 -1
- package/dist/packem_shared/{createImages-CJrvqX0u.mjs → createImages-BzRnsz3H.mjs} +8 -3
- package/dist/packem_shared/{createKv-DTiSt216.mjs → createKv-C8Iyu5hD.mjs} +18 -14
- package/dist/packem_shared/createKvIntrospector-Byk4GfsY.mjs +77 -0
- package/dist/packem_shared/{createVectorAdminIntrospector-BJUOM6VW.mjs → createVectorAdminIntrospector-DuSvcBa5.mjs} +6 -4
- package/dist/packem_shared/{createVectors-LSpGoKCd.mjs → createVectors-CTSrctiK.mjs} +10 -6
- package/dist/pipelines/index.d.mts +24 -24
- package/dist/pipelines/index.d.ts +24 -24
- package/dist/r2sql/index.d.mts +122 -122
- package/dist/r2sql/index.d.ts +122 -122
- package/dist/r2sql/index.mjs +7 -7
- package/dist/vectors/index.d.mts +83 -83
- package/dist/vectors/index.d.ts +83 -83
- package/dist/vectors/index.mjs +3 -3
- package/package.json +4 -1
package/LICENSE.md
CHANGED
|
@@ -103,3 +103,9 @@ Unless required by applicable law or agreed to in writing, software distributed
|
|
|
103
103
|
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
104
|
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
105
|
specific language governing permissions and limitations under the License.
|
|
106
|
+
|
|
107
|
+
<!-- DEPENDENCIES -->
|
|
108
|
+
<!-- /DEPENDENCIES -->
|
|
109
|
+
|
|
110
|
+
<!-- TYPE_DEPENDENCIES -->
|
|
111
|
+
<!-- /TYPE_DEPENDENCIES -->
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { LunoraError } from '@lunora/errors';
|
|
1
2
|
/**
|
|
2
|
-
* Structural types for the Analytics Engine write path.
|
|
3
|
-
*
|
|
4
|
-
* The real binding is workers-types' `AnalyticsEngineDataset`. We mirror it
|
|
5
|
-
* **structurally** (`AnalyticsEngineDatasetLike`) so plain-object test doubles
|
|
6
|
-
* satisfy the contract without pulling workerd into a unit test — the same
|
|
7
|
-
* approach `@lunora/d1` takes with `D1DatabaseLike`
|
|
8
|
-
* (`packages/d1/src/d1-client.ts`).
|
|
9
|
-
*/
|
|
3
|
+
* Structural types for the Analytics Engine write path.
|
|
4
|
+
*
|
|
5
|
+
* The real binding is workers-types' `AnalyticsEngineDataset`. We mirror it
|
|
6
|
+
* **structurally** (`AnalyticsEngineDatasetLike`) so plain-object test doubles
|
|
7
|
+
* satisfy the contract without pulling workerd into a unit test — the same
|
|
8
|
+
* approach `@lunora/d1` takes with `D1DatabaseLike`
|
|
9
|
+
* (`packages/d1/src/d1-client.ts`).
|
|
10
|
+
*/
|
|
10
11
|
/**
|
|
11
|
-
* One Analytics Engine data point, mirroring the positional shape
|
|
12
|
-
* `writeDataPoint` accepts. AE stores up to 20 string `blobs`, up to 20 numeric
|
|
13
|
-
* `doubles`, and exactly **one** `index` (the high-cardinality sampling key) per
|
|
14
|
-
* data point — the SQL API later exposes them as `blob1..blob20`,
|
|
15
|
-
* `double1..double20`, and `index1`.
|
|
16
|
-
*/
|
|
12
|
+
* One Analytics Engine data point, mirroring the positional shape
|
|
13
|
+
* `writeDataPoint` accepts. AE stores up to 20 string `blobs`, up to 20 numeric
|
|
14
|
+
* `doubles`, and exactly **one** `index` (the high-cardinality sampling key) per
|
|
15
|
+
* data point — the SQL API later exposes them as `blob1..blob20`,
|
|
16
|
+
* `double1..double20`, and `index1`.
|
|
17
|
+
*/
|
|
17
18
|
interface AnalyticsEngineDataPoint {
|
|
18
19
|
/** String columns, mapped positionally to `blob1..blob20`. */
|
|
19
20
|
blobs?: (ArrayBuffer | null | string)[];
|
|
@@ -23,19 +24,19 @@ interface AnalyticsEngineDataPoint {
|
|
|
23
24
|
indexes?: (ArrayBuffer | string)[];
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
|
-
* Minimal structural projection of workers-types' `AnalyticsEngineDataset`,
|
|
27
|
-
* kept loose enough for a plain-object fake in unit tests. `writeDataPoint` is
|
|
28
|
-
* fire-and-forget: it returns `void` and never throws on the hot path.
|
|
29
|
-
*/
|
|
27
|
+
* Minimal structural projection of workers-types' `AnalyticsEngineDataset`,
|
|
28
|
+
* kept loose enough for a plain-object fake in unit tests. `writeDataPoint` is
|
|
29
|
+
* fire-and-forget: it returns `void` and never throws on the hot path.
|
|
30
|
+
*/
|
|
30
31
|
interface AnalyticsEngineDatasetLike {
|
|
31
32
|
writeDataPoint: (event: AnalyticsEngineDataPoint) => void;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
|
-
* Named-field event handed to {@link AnalyticsClient.track}. Each field is
|
|
35
|
-
* mapped to a positional AE column and the mapping recorded in a returned
|
|
36
|
-
* {@link TrackSchema}, so the read side can reconstruct named columns from the
|
|
37
|
-
* SQL API's positional `blobN`/`doubleN`/`index1` output.
|
|
38
|
-
*/
|
|
35
|
+
* Named-field event handed to {@link AnalyticsClient.track}. Each field is
|
|
36
|
+
* mapped to a positional AE column and the mapping recorded in a returned
|
|
37
|
+
* {@link TrackSchema}, so the read side can reconstruct named columns from the
|
|
38
|
+
* SQL API's positional `blobN`/`doubleN`/`index1` output.
|
|
39
|
+
*/
|
|
39
40
|
interface TrackEvent {
|
|
40
41
|
/** String dimensions → `blobs` (`blob1..blob20`), in object key order. */
|
|
41
42
|
dimensions?: Record<string, string>;
|
|
@@ -52,11 +53,11 @@ interface TrackColumn {
|
|
|
52
53
|
field: string;
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
|
-
* The field→column mapping {@link AnalyticsClient.track} records for one event
|
|
56
|
-
* shape, so the read side can project the SQL API's positional columns back to
|
|
57
|
-
* named fields. `name` is the logical event name; the column arrays are in the
|
|
58
|
-
* same order the dimensions/metrics were written.
|
|
59
|
-
*/
|
|
56
|
+
* The field→column mapping {@link AnalyticsClient.track} records for one event
|
|
57
|
+
* shape, so the read side can project the SQL API's positional columns back to
|
|
58
|
+
* named fields. `name` is the logical event name; the column arrays are in the
|
|
59
|
+
* same order the dimensions/metrics were written.
|
|
60
|
+
*/
|
|
60
61
|
interface TrackSchema {
|
|
61
62
|
dimensions: TrackColumn[];
|
|
62
63
|
index: TrackColumn | null;
|
|
@@ -64,41 +65,41 @@ interface TrackSchema {
|
|
|
64
65
|
name: string;
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
|
-
* The write-side client bound to `ctx.analytics` (the generated context imports
|
|
68
|
-
* this exact type as `import("@lunora/bindings/analytics").AnalyticsClient`). Telemetry
|
|
69
|
-
* is fire-and-forget and sampled — never read a data point back in-handler.
|
|
70
|
-
*/
|
|
68
|
+
* The write-side client bound to `ctx.analytics` (the generated context imports
|
|
69
|
+
* this exact type as `import("@lunora/bindings/analytics").AnalyticsClient`). Telemetry
|
|
70
|
+
* is fire-and-forget and sampled — never read a data point back in-handler.
|
|
71
|
+
*/
|
|
71
72
|
interface AnalyticsClient {
|
|
72
73
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
* Ergonomic named-field write: maps `{ dimensions, metrics, index }` to the
|
|
75
|
+
* positional layout, writes it, and returns the {@link TrackSchema} mapping
|
|
76
|
+
* (the logical `name` is recorded as the first blob, `blob1`).
|
|
77
|
+
*/
|
|
77
78
|
track: (name: string, event?: TrackEvent) => TrackSchema;
|
|
78
79
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
* Write a raw positional data point. Enforces AE's per-data-point count
|
|
81
|
+
* caps (≤20 blobs, ≤20 doubles, ≤1 index) and byte budget (combined blobs
|
|
82
|
+
* ≤16 KiB, index ≤96 bytes, measured as UTF-8); overflow throws so a misuse
|
|
83
|
+
* surfaces in dev rather than being silently rejected by the platform.
|
|
84
|
+
*/
|
|
84
85
|
writeDataPoint: (event: AnalyticsEngineDataPoint) => void;
|
|
85
86
|
}
|
|
86
87
|
/**
|
|
87
|
-
* Wrap an Analytics Engine dataset binding in the write-side
|
|
88
|
-
* {@link AnalyticsClient} bound to `ctx.analytics`.
|
|
89
|
-
*
|
|
90
|
-
* The binding is `env.ANALYTICS` (the self-describing
|
|
91
|
-
* `analytics_engine_datasets` binding the config layer reconciles). Writes are
|
|
92
|
-
* fire-and-forget and sampled — there is no return value to read in-handler.
|
|
93
|
-
*
|
|
94
|
-
* `writeDataPoint` enforces AE's per-data-point caps eagerly — both the count
|
|
95
|
-
* caps (≤20 blobs, ≤20 doubles, ≤1 index) and the byte budget (combined blobs
|
|
96
|
-
* ≤16 KiB, index ≤96 bytes, measured as UTF-8) — so a misuse throws in dev
|
|
97
|
-
* instead of being silently rejected by the platform at the edge. `track` is
|
|
98
|
-
* the ergonomic named-field path: it maps a
|
|
99
|
-
* `{ dimensions, metrics, index }` object to the positional layout and returns
|
|
100
|
-
* the field→column mapping the read side uses to reconstruct named columns.
|
|
101
|
-
*/
|
|
88
|
+
* Wrap an Analytics Engine dataset binding in the write-side
|
|
89
|
+
* {@link AnalyticsClient} bound to `ctx.analytics`.
|
|
90
|
+
*
|
|
91
|
+
* The binding is `env.ANALYTICS` (the self-describing
|
|
92
|
+
* `analytics_engine_datasets` binding the config layer reconciles). Writes are
|
|
93
|
+
* fire-and-forget and sampled — there is no return value to read in-handler.
|
|
94
|
+
*
|
|
95
|
+
* `writeDataPoint` enforces AE's per-data-point caps eagerly — both the count
|
|
96
|
+
* caps (≤20 blobs, ≤20 doubles, ≤1 index) and the byte budget (combined blobs
|
|
97
|
+
* ≤16 KiB, index ≤96 bytes, measured as UTF-8) — so a misuse throws in dev
|
|
98
|
+
* instead of being silently rejected by the platform at the edge. `track` is
|
|
99
|
+
* the ergonomic named-field path: it maps a
|
|
100
|
+
* `{ dimensions, metrics, index }` object to the positional layout and returns
|
|
101
|
+
* the field→column mapping the read side uses to reconstruct named columns.
|
|
102
|
+
*/
|
|
102
103
|
declare const createAnalytics: (binding: AnalyticsEngineDatasetLike) => AnalyticsClient;
|
|
103
104
|
/** Configuration for an {@link AnalyticsSqlClient}. */
|
|
104
105
|
interface AnalyticsSqlConfig {
|
|
@@ -107,32 +108,31 @@ interface AnalyticsSqlConfig {
|
|
|
107
108
|
/** API token with Analytics Engine read scope. A secret — never a binding. */
|
|
108
109
|
apiToken: string;
|
|
109
110
|
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
* `fetch` implementation. Defaults to the global `fetch`; injected in tests
|
|
112
|
+
* so the SQL path never touches the network.
|
|
113
|
+
*/
|
|
113
114
|
fetch?: typeof globalThis.fetch;
|
|
114
115
|
}
|
|
115
116
|
/**
|
|
116
|
-
* One column descriptor in a SQL-API response's `meta` array: the column `name`
|
|
117
|
-
* and the AE storage `type` (`String`, `Float64`, `DateTime`, …).
|
|
118
|
-
*/
|
|
117
|
+
* One column descriptor in a SQL-API response's `meta` array: the column `name`
|
|
118
|
+
* and the AE storage `type` (`String`, `Float64`, `DateTime`, …).
|
|
119
|
+
*/
|
|
119
120
|
interface AnalyticsSqlColumnMeta {
|
|
120
121
|
name: string;
|
|
121
122
|
type: string;
|
|
122
123
|
}
|
|
123
124
|
/**
|
|
124
|
-
* Parsed SQL-API result. AE returns `{ meta, data, rows, rows_before_limit_at_least }`;
|
|
125
|
-
* we surface `columns` (from `meta`), the `rows` array of column→value records,
|
|
126
|
-
* and the total `rowCount`.
|
|
127
|
-
*/
|
|
125
|
+
* Parsed SQL-API result. AE returns `{ meta, data, rows, rows_before_limit_at_least }`;
|
|
126
|
+
* we surface `columns` (from `meta`), the `rows` array of column→value records,
|
|
127
|
+
* and the total `rowCount`.
|
|
128
|
+
*/
|
|
128
129
|
interface AnalyticsSqlResult {
|
|
129
130
|
columns: AnalyticsSqlColumnMeta[];
|
|
130
131
|
rowCount: number;
|
|
131
132
|
rows: Record<string, unknown>[];
|
|
132
133
|
}
|
|
133
|
-
/** Thrown when the SQL API responds with a non-2xx status;
|
|
134
|
-
declare class AnalyticsSqlError extends
|
|
135
|
-
readonly status: number;
|
|
134
|
+
/** Thrown when the SQL API responds with a non-2xx status; a `LunoraError` subclass carrying the HTTP `status` + body for the caller to surface. */
|
|
135
|
+
declare class AnalyticsSqlError extends LunoraError {
|
|
136
136
|
constructor(status: number, body: string);
|
|
137
137
|
}
|
|
138
138
|
/** The read client: a single `query(sql)` over the AE SQL API. */
|
|
@@ -140,9 +140,9 @@ interface AnalyticsSqlClient {
|
|
|
140
140
|
query: (sql: string) => Promise<AnalyticsSqlResult>;
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
|
-
* Build an {@link AnalyticsSqlClient}. Each `query` POSTs the raw SQL text to
|
|
144
|
-
* the account's `analytics_engine/sql` endpoint with the bearer token, then
|
|
145
|
-
* normalises AE's `{ meta, data, rows }` body into {@link AnalyticsSqlResult}.
|
|
146
|
-
*/
|
|
143
|
+
* Build an {@link AnalyticsSqlClient}. Each `query` POSTs the raw SQL text to
|
|
144
|
+
* the account's `analytics_engine/sql` endpoint with the bearer token, then
|
|
145
|
+
* normalises AE's `{ meta, data, rows }` body into {@link AnalyticsSqlResult}.
|
|
146
|
+
*/
|
|
147
147
|
declare const createAnalyticsSqlClient: (config: AnalyticsSqlConfig) => AnalyticsSqlClient;
|
|
148
148
|
export { type AnalyticsClient, type AnalyticsEngineDataPoint, type AnalyticsEngineDatasetLike, type AnalyticsSqlClient, type AnalyticsSqlColumnMeta, type AnalyticsSqlConfig, AnalyticsSqlError, type AnalyticsSqlResult, type TrackColumn, type TrackEvent, type TrackSchema, createAnalytics, createAnalyticsSqlClient };
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { LunoraError } from '@lunora/errors';
|
|
1
2
|
/**
|
|
2
|
-
* Structural types for the Analytics Engine write path.
|
|
3
|
-
*
|
|
4
|
-
* The real binding is workers-types' `AnalyticsEngineDataset`. We mirror it
|
|
5
|
-
* **structurally** (`AnalyticsEngineDatasetLike`) so plain-object test doubles
|
|
6
|
-
* satisfy the contract without pulling workerd into a unit test — the same
|
|
7
|
-
* approach `@lunora/d1` takes with `D1DatabaseLike`
|
|
8
|
-
* (`packages/d1/src/d1-client.ts`).
|
|
9
|
-
*/
|
|
3
|
+
* Structural types for the Analytics Engine write path.
|
|
4
|
+
*
|
|
5
|
+
* The real binding is workers-types' `AnalyticsEngineDataset`. We mirror it
|
|
6
|
+
* **structurally** (`AnalyticsEngineDatasetLike`) so plain-object test doubles
|
|
7
|
+
* satisfy the contract without pulling workerd into a unit test — the same
|
|
8
|
+
* approach `@lunora/d1` takes with `D1DatabaseLike`
|
|
9
|
+
* (`packages/d1/src/d1-client.ts`).
|
|
10
|
+
*/
|
|
10
11
|
/**
|
|
11
|
-
* One Analytics Engine data point, mirroring the positional shape
|
|
12
|
-
* `writeDataPoint` accepts. AE stores up to 20 string `blobs`, up to 20 numeric
|
|
13
|
-
* `doubles`, and exactly **one** `index` (the high-cardinality sampling key) per
|
|
14
|
-
* data point — the SQL API later exposes them as `blob1..blob20`,
|
|
15
|
-
* `double1..double20`, and `index1`.
|
|
16
|
-
*/
|
|
12
|
+
* One Analytics Engine data point, mirroring the positional shape
|
|
13
|
+
* `writeDataPoint` accepts. AE stores up to 20 string `blobs`, up to 20 numeric
|
|
14
|
+
* `doubles`, and exactly **one** `index` (the high-cardinality sampling key) per
|
|
15
|
+
* data point — the SQL API later exposes them as `blob1..blob20`,
|
|
16
|
+
* `double1..double20`, and `index1`.
|
|
17
|
+
*/
|
|
17
18
|
interface AnalyticsEngineDataPoint {
|
|
18
19
|
/** String columns, mapped positionally to `blob1..blob20`. */
|
|
19
20
|
blobs?: (ArrayBuffer | null | string)[];
|
|
@@ -23,19 +24,19 @@ interface AnalyticsEngineDataPoint {
|
|
|
23
24
|
indexes?: (ArrayBuffer | string)[];
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
|
-
* Minimal structural projection of workers-types' `AnalyticsEngineDataset`,
|
|
27
|
-
* kept loose enough for a plain-object fake in unit tests. `writeDataPoint` is
|
|
28
|
-
* fire-and-forget: it returns `void` and never throws on the hot path.
|
|
29
|
-
*/
|
|
27
|
+
* Minimal structural projection of workers-types' `AnalyticsEngineDataset`,
|
|
28
|
+
* kept loose enough for a plain-object fake in unit tests. `writeDataPoint` is
|
|
29
|
+
* fire-and-forget: it returns `void` and never throws on the hot path.
|
|
30
|
+
*/
|
|
30
31
|
interface AnalyticsEngineDatasetLike {
|
|
31
32
|
writeDataPoint: (event: AnalyticsEngineDataPoint) => void;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
|
-
* Named-field event handed to {@link AnalyticsClient.track}. Each field is
|
|
35
|
-
* mapped to a positional AE column and the mapping recorded in a returned
|
|
36
|
-
* {@link TrackSchema}, so the read side can reconstruct named columns from the
|
|
37
|
-
* SQL API's positional `blobN`/`doubleN`/`index1` output.
|
|
38
|
-
*/
|
|
35
|
+
* Named-field event handed to {@link AnalyticsClient.track}. Each field is
|
|
36
|
+
* mapped to a positional AE column and the mapping recorded in a returned
|
|
37
|
+
* {@link TrackSchema}, so the read side can reconstruct named columns from the
|
|
38
|
+
* SQL API's positional `blobN`/`doubleN`/`index1` output.
|
|
39
|
+
*/
|
|
39
40
|
interface TrackEvent {
|
|
40
41
|
/** String dimensions → `blobs` (`blob1..blob20`), in object key order. */
|
|
41
42
|
dimensions?: Record<string, string>;
|
|
@@ -52,11 +53,11 @@ interface TrackColumn {
|
|
|
52
53
|
field: string;
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
|
-
* The field→column mapping {@link AnalyticsClient.track} records for one event
|
|
56
|
-
* shape, so the read side can project the SQL API's positional columns back to
|
|
57
|
-
* named fields. `name` is the logical event name; the column arrays are in the
|
|
58
|
-
* same order the dimensions/metrics were written.
|
|
59
|
-
*/
|
|
56
|
+
* The field→column mapping {@link AnalyticsClient.track} records for one event
|
|
57
|
+
* shape, so the read side can project the SQL API's positional columns back to
|
|
58
|
+
* named fields. `name` is the logical event name; the column arrays are in the
|
|
59
|
+
* same order the dimensions/metrics were written.
|
|
60
|
+
*/
|
|
60
61
|
interface TrackSchema {
|
|
61
62
|
dimensions: TrackColumn[];
|
|
62
63
|
index: TrackColumn | null;
|
|
@@ -64,41 +65,41 @@ interface TrackSchema {
|
|
|
64
65
|
name: string;
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
|
-
* The write-side client bound to `ctx.analytics` (the generated context imports
|
|
68
|
-
* this exact type as `import("@lunora/bindings/analytics").AnalyticsClient`). Telemetry
|
|
69
|
-
* is fire-and-forget and sampled — never read a data point back in-handler.
|
|
70
|
-
*/
|
|
68
|
+
* The write-side client bound to `ctx.analytics` (the generated context imports
|
|
69
|
+
* this exact type as `import("@lunora/bindings/analytics").AnalyticsClient`). Telemetry
|
|
70
|
+
* is fire-and-forget and sampled — never read a data point back in-handler.
|
|
71
|
+
*/
|
|
71
72
|
interface AnalyticsClient {
|
|
72
73
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
* Ergonomic named-field write: maps `{ dimensions, metrics, index }` to the
|
|
75
|
+
* positional layout, writes it, and returns the {@link TrackSchema} mapping
|
|
76
|
+
* (the logical `name` is recorded as the first blob, `blob1`).
|
|
77
|
+
*/
|
|
77
78
|
track: (name: string, event?: TrackEvent) => TrackSchema;
|
|
78
79
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
* Write a raw positional data point. Enforces AE's per-data-point count
|
|
81
|
+
* caps (≤20 blobs, ≤20 doubles, ≤1 index) and byte budget (combined blobs
|
|
82
|
+
* ≤16 KiB, index ≤96 bytes, measured as UTF-8); overflow throws so a misuse
|
|
83
|
+
* surfaces in dev rather than being silently rejected by the platform.
|
|
84
|
+
*/
|
|
84
85
|
writeDataPoint: (event: AnalyticsEngineDataPoint) => void;
|
|
85
86
|
}
|
|
86
87
|
/**
|
|
87
|
-
* Wrap an Analytics Engine dataset binding in the write-side
|
|
88
|
-
* {@link AnalyticsClient} bound to `ctx.analytics`.
|
|
89
|
-
*
|
|
90
|
-
* The binding is `env.ANALYTICS` (the self-describing
|
|
91
|
-
* `analytics_engine_datasets` binding the config layer reconciles). Writes are
|
|
92
|
-
* fire-and-forget and sampled — there is no return value to read in-handler.
|
|
93
|
-
*
|
|
94
|
-
* `writeDataPoint` enforces AE's per-data-point caps eagerly — both the count
|
|
95
|
-
* caps (≤20 blobs, ≤20 doubles, ≤1 index) and the byte budget (combined blobs
|
|
96
|
-
* ≤16 KiB, index ≤96 bytes, measured as UTF-8) — so a misuse throws in dev
|
|
97
|
-
* instead of being silently rejected by the platform at the edge. `track` is
|
|
98
|
-
* the ergonomic named-field path: it maps a
|
|
99
|
-
* `{ dimensions, metrics, index }` object to the positional layout and returns
|
|
100
|
-
* the field→column mapping the read side uses to reconstruct named columns.
|
|
101
|
-
*/
|
|
88
|
+
* Wrap an Analytics Engine dataset binding in the write-side
|
|
89
|
+
* {@link AnalyticsClient} bound to `ctx.analytics`.
|
|
90
|
+
*
|
|
91
|
+
* The binding is `env.ANALYTICS` (the self-describing
|
|
92
|
+
* `analytics_engine_datasets` binding the config layer reconciles). Writes are
|
|
93
|
+
* fire-and-forget and sampled — there is no return value to read in-handler.
|
|
94
|
+
*
|
|
95
|
+
* `writeDataPoint` enforces AE's per-data-point caps eagerly — both the count
|
|
96
|
+
* caps (≤20 blobs, ≤20 doubles, ≤1 index) and the byte budget (combined blobs
|
|
97
|
+
* ≤16 KiB, index ≤96 bytes, measured as UTF-8) — so a misuse throws in dev
|
|
98
|
+
* instead of being silently rejected by the platform at the edge. `track` is
|
|
99
|
+
* the ergonomic named-field path: it maps a
|
|
100
|
+
* `{ dimensions, metrics, index }` object to the positional layout and returns
|
|
101
|
+
* the field→column mapping the read side uses to reconstruct named columns.
|
|
102
|
+
*/
|
|
102
103
|
declare const createAnalytics: (binding: AnalyticsEngineDatasetLike) => AnalyticsClient;
|
|
103
104
|
/** Configuration for an {@link AnalyticsSqlClient}. */
|
|
104
105
|
interface AnalyticsSqlConfig {
|
|
@@ -107,32 +108,31 @@ interface AnalyticsSqlConfig {
|
|
|
107
108
|
/** API token with Analytics Engine read scope. A secret — never a binding. */
|
|
108
109
|
apiToken: string;
|
|
109
110
|
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
* `fetch` implementation. Defaults to the global `fetch`; injected in tests
|
|
112
|
+
* so the SQL path never touches the network.
|
|
113
|
+
*/
|
|
113
114
|
fetch?: typeof globalThis.fetch;
|
|
114
115
|
}
|
|
115
116
|
/**
|
|
116
|
-
* One column descriptor in a SQL-API response's `meta` array: the column `name`
|
|
117
|
-
* and the AE storage `type` (`String`, `Float64`, `DateTime`, …).
|
|
118
|
-
*/
|
|
117
|
+
* One column descriptor in a SQL-API response's `meta` array: the column `name`
|
|
118
|
+
* and the AE storage `type` (`String`, `Float64`, `DateTime`, …).
|
|
119
|
+
*/
|
|
119
120
|
interface AnalyticsSqlColumnMeta {
|
|
120
121
|
name: string;
|
|
121
122
|
type: string;
|
|
122
123
|
}
|
|
123
124
|
/**
|
|
124
|
-
* Parsed SQL-API result. AE returns `{ meta, data, rows, rows_before_limit_at_least }`;
|
|
125
|
-
* we surface `columns` (from `meta`), the `rows` array of column→value records,
|
|
126
|
-
* and the total `rowCount`.
|
|
127
|
-
*/
|
|
125
|
+
* Parsed SQL-API result. AE returns `{ meta, data, rows, rows_before_limit_at_least }`;
|
|
126
|
+
* we surface `columns` (from `meta`), the `rows` array of column→value records,
|
|
127
|
+
* and the total `rowCount`.
|
|
128
|
+
*/
|
|
128
129
|
interface AnalyticsSqlResult {
|
|
129
130
|
columns: AnalyticsSqlColumnMeta[];
|
|
130
131
|
rowCount: number;
|
|
131
132
|
rows: Record<string, unknown>[];
|
|
132
133
|
}
|
|
133
|
-
/** Thrown when the SQL API responds with a non-2xx status;
|
|
134
|
-
declare class AnalyticsSqlError extends
|
|
135
|
-
readonly status: number;
|
|
134
|
+
/** Thrown when the SQL API responds with a non-2xx status; a `LunoraError` subclass carrying the HTTP `status` + body for the caller to surface. */
|
|
135
|
+
declare class AnalyticsSqlError extends LunoraError {
|
|
136
136
|
constructor(status: number, body: string);
|
|
137
137
|
}
|
|
138
138
|
/** The read client: a single `query(sql)` over the AE SQL API. */
|
|
@@ -140,9 +140,9 @@ interface AnalyticsSqlClient {
|
|
|
140
140
|
query: (sql: string) => Promise<AnalyticsSqlResult>;
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
|
-
* Build an {@link AnalyticsSqlClient}. Each `query` POSTs the raw SQL text to
|
|
144
|
-
* the account's `analytics_engine/sql` endpoint with the bearer token, then
|
|
145
|
-
* normalises AE's `{ meta, data, rows }` body into {@link AnalyticsSqlResult}.
|
|
146
|
-
*/
|
|
143
|
+
* Build an {@link AnalyticsSqlClient}. Each `query` POSTs the raw SQL text to
|
|
144
|
+
* the account's `analytics_engine/sql` endpoint with the bearer token, then
|
|
145
|
+
* normalises AE's `{ meta, data, rows }` body into {@link AnalyticsSqlResult}.
|
|
146
|
+
*/
|
|
147
147
|
declare const createAnalyticsSqlClient: (config: AnalyticsSqlConfig) => AnalyticsSqlClient;
|
|
148
148
|
export { type AnalyticsClient, type AnalyticsEngineDataPoint, type AnalyticsEngineDatasetLike, type AnalyticsSqlClient, type AnalyticsSqlColumnMeta, type AnalyticsSqlConfig, AnalyticsSqlError, type AnalyticsSqlResult, type TrackColumn, type TrackEvent, type TrackSchema, createAnalytics, createAnalyticsSqlClient };
|
package/dist/analytics/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { createAnalytics } from '../packem_shared/createAnalytics-CEEI69o9.mjs';
|
|
2
|
-
export { AnalyticsSqlError, createAnalyticsSqlClient } from '../packem_shared/AnalyticsSqlError-
|
|
2
|
+
export { AnalyticsSqlError, createAnalyticsSqlClient } from '../packem_shared/AnalyticsSqlError-C2nz3jpH.mjs';
|