@dalgo/bigquery 0.0.0-stage → 0.2.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 (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +472 -2
  3. package/dist/analytical/canonical.d.ts +10 -0
  4. package/dist/analytical/canonical.d.ts.map +1 -0
  5. package/dist/analytical/canonical.js +50 -0
  6. package/dist/analytical/client.d.ts +84 -0
  7. package/dist/analytical/client.d.ts.map +1 -0
  8. package/dist/analytical/client.js +730 -0
  9. package/dist/analytical/deadline.d.ts +13 -0
  10. package/dist/analytical/deadline.d.ts.map +1 -0
  11. package/dist/analytical/deadline.js +23 -0
  12. package/dist/analytical/google-identity.d.ts +40 -0
  13. package/dist/analytical/google-identity.d.ts.map +1 -0
  14. package/dist/analytical/google-identity.js +158 -0
  15. package/dist/analytical/ledger.d.ts +80 -0
  16. package/dist/analytical/ledger.d.ts.map +1 -0
  17. package/dist/analytical/ledger.js +89 -0
  18. package/dist/analytical/metadata-client.d.ts +66 -0
  19. package/dist/analytical/metadata-client.d.ts.map +1 -0
  20. package/dist/analytical/metadata-client.js +247 -0
  21. package/dist/analytical/metadata-harness.d.ts +28 -0
  22. package/dist/analytical/metadata-harness.d.ts.map +1 -0
  23. package/dist/analytical/metadata-harness.js +127 -0
  24. package/dist/analytical/metadata.d.ts +8 -0
  25. package/dist/analytical/metadata.d.ts.map +1 -0
  26. package/dist/analytical/metadata.js +155 -0
  27. package/dist/analytical/protocol.d.ts +157 -0
  28. package/dist/analytical/protocol.d.ts.map +1 -0
  29. package/dist/analytical/protocol.js +320 -0
  30. package/dist/analytical/public-metadata.d.ts +29 -0
  31. package/dist/analytical/public-metadata.d.ts.map +1 -0
  32. package/dist/analytical/public-metadata.js +70 -0
  33. package/dist/analytical/transport.d.ts +39 -0
  34. package/dist/analytical/transport.d.ts.map +1 -0
  35. package/dist/analytical/transport.js +224 -0
  36. package/dist/analytical/values.d.ts +18 -0
  37. package/dist/analytical/values.d.ts.map +1 -0
  38. package/dist/analytical/values.js +157 -0
  39. package/dist/analytical/wire.d.ts +26 -0
  40. package/dist/analytical/wire.d.ts.map +1 -0
  41. package/dist/analytical/wire.js +141 -0
  42. package/dist/analytical.d.ts +27 -0
  43. package/dist/analytical.d.ts.map +1 -0
  44. package/dist/analytical.js +14 -0
  45. package/dist/database.d.ts +35 -0
  46. package/dist/database.d.ts.map +1 -0
  47. package/dist/database.js +437 -0
  48. package/dist/index.d.ts +4 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +2 -0
  51. package/dist/sql.d.ts +29 -0
  52. package/dist/sql.d.ts.map +1 -0
  53. package/dist/sql.js +198 -0
  54. package/dist/types.d.ts +49 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/types.js +1 -0
  57. package/package.json +58 -4
@@ -0,0 +1,157 @@
1
+ import { fail } from "./wire.js";
2
+ import { hashPayload } from "./canonical.js";
3
+ import { type AnalyticalField } from "./values.js";
4
+ export interface SchemaField extends AnalyticalField {
5
+ readonly name: string;
6
+ readonly fields?: readonly SchemaField[];
7
+ readonly precision?: string;
8
+ readonly scale?: string;
9
+ }
10
+ export interface SourceProfile {
11
+ readonly version: 1;
12
+ readonly sourceId: string;
13
+ readonly descriptorDigest: string;
14
+ readonly logicalCollection: string;
15
+ readonly sourceProject: string;
16
+ readonly datasetId: string;
17
+ readonly tableId: string;
18
+ readonly location: string;
19
+ readonly schema: readonly SchemaField[];
20
+ readonly publisherReviewRef: string;
21
+ readonly rightsReviewRef: string;
22
+ readonly use: "connection-test" | "admitted";
23
+ }
24
+ export interface Principal {
25
+ readonly kind: "google-user" | "workload";
26
+ readonly subject: string;
27
+ readonly generation: string;
28
+ }
29
+ export interface Execution {
30
+ readonly jobProject: string;
31
+ readonly principal: Principal;
32
+ readonly maximumBytesBilled: string;
33
+ readonly sessionBudgetBytes: string;
34
+ }
35
+ export interface Bounds {
36
+ readonly pageSize: number;
37
+ readonly maxRows: number;
38
+ readonly maxPages: number;
39
+ readonly responseBytes: number;
40
+ readonly totalResponseBytes: number;
41
+ readonly wallMs: number;
42
+ readonly httpMs: number;
43
+ readonly concurrency: 1;
44
+ }
45
+ export interface Predicate {
46
+ readonly op: string;
47
+ readonly column?: string;
48
+ readonly value?: unknown;
49
+ readonly items?: readonly Predicate[];
50
+ }
51
+ export interface ReadQuery {
52
+ readonly from: string;
53
+ readonly projection: readonly string[];
54
+ readonly where: Predicate | null;
55
+ readonly order: readonly {
56
+ readonly column: string;
57
+ readonly direction: "ASC" | "DESC";
58
+ }[];
59
+ readonly limit: number;
60
+ }
61
+ export interface Parameter {
62
+ readonly name: string;
63
+ readonly type: string;
64
+ readonly value: string | boolean | null | readonly (string | boolean)[];
65
+ }
66
+ export interface CompiledPredicate {
67
+ readonly op: string;
68
+ readonly column?: string;
69
+ readonly parameter?: string;
70
+ readonly children?: readonly CompiledPredicate[];
71
+ }
72
+ export interface ReadPlan {
73
+ readonly version: 1;
74
+ readonly sourceDigest: string;
75
+ readonly projection: readonly string[];
76
+ readonly where: CompiledPredicate | null;
77
+ readonly order: ReadQuery["order"];
78
+ readonly limit: number;
79
+ readonly parameters: readonly Parameter[];
80
+ readonly sql: string;
81
+ readonly digest: string;
82
+ }
83
+ export interface JobRef {
84
+ readonly projectId: string;
85
+ readonly jobId: string;
86
+ readonly location: string;
87
+ }
88
+ export interface Observation {
89
+ readonly table: {
90
+ readonly projectId: string;
91
+ readonly datasetId: string;
92
+ readonly tableId: string;
93
+ };
94
+ readonly location: string;
95
+ readonly type: "TABLE";
96
+ readonly config: Readonly<Record<string, unknown>>;
97
+ readonly schema: readonly SchemaField[];
98
+ readonly digest: string;
99
+ readonly observedAt: string;
100
+ }
101
+ export type RunState = "reserved" | "submitting" | "submission_unknown" | "running" | "completed" | "failed" | "cancelled" | "cancel_requested";
102
+ export interface Counters {
103
+ bytes: number;
104
+ rows: number;
105
+ pages: number;
106
+ }
107
+ export interface Receipt {
108
+ readonly version: 1;
109
+ readonly runId: string;
110
+ readonly approvalDigest: string;
111
+ readonly sourceDigest: string;
112
+ readonly observationDigest: string;
113
+ readonly schemaDigest: string;
114
+ readonly principal: Principal;
115
+ readonly job?: JobRef;
116
+ readonly state: RunState;
117
+ readonly runStartedAt: string;
118
+ readonly executionDeadline: string;
119
+ readonly bounds: Bounds;
120
+ readonly counters: Counters;
121
+ readonly localStopped: boolean;
122
+ readonly reason?: string;
123
+ readonly processedBytes?: string;
124
+ readonly billedBytes?: string;
125
+ readonly cacheHit?: boolean;
126
+ readonly warnings: readonly string[];
127
+ readonly residualSourceReplacementRace: true;
128
+ }
129
+ export interface Page {
130
+ readonly schema: readonly SchemaField[];
131
+ readonly rows: readonly (readonly import("./values.js").AnalyticalCell[])[];
132
+ readonly cursor?: string;
133
+ readonly receipt: Receipt;
134
+ }
135
+ export declare function cloneFrozen<T>(value: T): T;
136
+ export declare function timestamp(now: number): string;
137
+ export declare function encoded(value: unknown): Uint8Array;
138
+ export declare function digest(name: Parameters<typeof hashPayload>[0], value: unknown): Promise<string>;
139
+ export declare function exactKeys(value: unknown, required: readonly string[], optional?: readonly string[], code?: Parameters<typeof fail>[0]): void;
140
+ export declare function nonempty(value: unknown, maximum?: number): asserts value is string;
141
+ export declare function identifier(value: unknown): asserts value is string;
142
+ export declare function project(value: unknown): asserts value is string;
143
+ export declare function positiveBytes(value: unknown): string;
144
+ export declare function integerText(value: unknown, code?: Parameters<typeof fail>[0]): string;
145
+ export declare function validatePrincipal(value: Principal): void;
146
+ export declare function validateExecution(value: Execution): void;
147
+ export declare function bounds(value?: Partial<Bounds>): Bounds;
148
+ export declare function validateSchema(value: readonly SchemaField[], depth?: number, counter?: {
149
+ count: number;
150
+ }): void;
151
+ export declare function validateSource(source: SourceProfile): void;
152
+ export declare function supportedField(field: SchemaField): void;
153
+ export declare function normalizeParameter(field: SchemaField, value: unknown): string | boolean | null;
154
+ export declare function checkDecimalConstraints(field: SchemaField, value: string): void;
155
+ export declare function compileReadPlan(source: SourceProfile, query: ReadQuery): Promise<ReadPlan>;
156
+ export declare function wireParameters(parameters: readonly Parameter[]): readonly unknown[];
157
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/analytical/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACpE,MAAM,WAAW,WAAY,SAAQ,eAAe;IAClD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IACzC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AACD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;IACxC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG,UAAU,CAAC;CAC9C;AACD,MAAM,WAAW,SAAS;IACxB,QA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I,CAQ/E;AACD,wBAAsB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwFhG;AACD,wBAAgB,cAAc,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,OAAO,EAAE,CAgBnF"}
@@ -0,0 +1,320 @@
1
+ import { fail } from "./wire.js";
2
+ import { hashPayload } from "./canonical.js";
3
+ import { normalizeScalar } from "./values.js";
4
+ export function cloneFrozen(value) {
5
+ let copy;
6
+ try {
7
+ copy = structuredClone(value);
8
+ }
9
+ catch {
10
+ return fail("invalid_input");
11
+ }
12
+ function freeze(value) {
13
+ if (value !== null && typeof value === "object") {
14
+ for (const child of Object.values(value))
15
+ freeze(child);
16
+ Object.freeze(value);
17
+ }
18
+ }
19
+ freeze(copy);
20
+ return copy;
21
+ }
22
+ export function timestamp(now) {
23
+ if (!Number.isSafeInteger(now))
24
+ fail("invalid_input");
25
+ return new Date(now).toISOString().replace(/\.000Z$/u, "Z").replace(/(\.\d*?[1-9])0+Z$/u, "$1Z");
26
+ }
27
+ export function encoded(value) { return new TextEncoder().encode(JSON.stringify(value)); }
28
+ export async function digest(name, value) { return (await hashPayload(name, encoded(value))).digest; }
29
+ export function exactKeys(value, required, optional = [], code = "invalid_input") {
30
+ if (value === null || typeof value !== "object" || Array.isArray(value))
31
+ fail(code);
32
+ if (required.some(key => !Object.hasOwn(value, key)) || Object.keys(value).some(key => !required.includes(key) && !optional.includes(key)))
33
+ fail(code);
34
+ }
35
+ export function nonempty(value, maximum = 1024) {
36
+ if (typeof value !== "string" || value.length === 0 || value.length > maximum)
37
+ fail("invalid_input");
38
+ normalizeScalar({
39
+ type: "STRING"
40
+ }, value);
41
+ }
42
+ export function identifier(value) {
43
+ if (typeof value !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/u.test(value) || value.length > 128)
44
+ fail("invalid_input");
45
+ }
46
+ export function project(value) {
47
+ if (typeof value !== "string" || !/^[a-z][a-z0-9-]{4,61}[a-z0-9]$/u.test(value))
48
+ fail("invalid_input");
49
+ }
50
+ export function positiveBytes(value) {
51
+ if (typeof value !== "string" || !/^[1-9][0-9]*$/u.test(value) || value.length > 19 || BigInt(value) > 9223372036854775807n)
52
+ fail("invalid_input");
53
+ return value;
54
+ }
55
+ export function integerText(value, code = "malformed_wire") {
56
+ if (typeof value !== "string" || !/^(0|[1-9][0-9]*)$/u.test(value) || value.length > 19 || BigInt(value) > 9223372036854775807n)
57
+ fail(code);
58
+ return value;
59
+ }
60
+ export function validatePrincipal(value) {
61
+ exactKeys(value, ["kind", "subject", "generation"]);
62
+ if (value.kind !== "google-user" && value.kind !== "workload")
63
+ fail("invalid_input");
64
+ nonempty(value.subject);
65
+ nonempty(value.generation);
66
+ }
67
+ export function validateExecution(value) { exactKeys(value, ["jobProject", "principal", "maximumBytesBilled", "sessionBudgetBytes"]); project(value.jobProject); validatePrincipal(value.principal); positiveBytes(value.maximumBytesBilled); positiveBytes(value.sessionBudgetBytes); }
68
+ export function bounds(value = {}) {
69
+ exactKeys(value, [], ["pageSize", "maxRows", "maxPages", "responseBytes", "totalResponseBytes", "wallMs", "httpMs", "concurrency"]);
70
+ const defaults = {
71
+ pageSize: 100, maxRows: 1000, maxPages: 100, responseBytes: 4 * 1024 * 1024, totalResponseBytes: 32 * 1024 * 1024, wallMs: 120000, httpMs: 15000, concurrency: 1
72
+ };
73
+ const maxima = {
74
+ ...defaults, pageSize: 1000, maxRows: 10000, responseBytes: 10 * 1024 * 1024
75
+ };
76
+ const result = {
77
+ ...defaults, ...value
78
+ };
79
+ for (const key of Object.keys(defaults))
80
+ if (!Number.isSafeInteger(result[key]) || result[key] < 1 || result[key] > maxima[key])
81
+ fail("invalid_input");
82
+ return cloneFrozen(result);
83
+ }
84
+ export function validateSchema(value, depth = 0, counter = {
85
+ count: 0
86
+ }) {
87
+ if (!Array.isArray(value) || value.length === 0 || depth > 32)
88
+ fail("malformed_wire");
89
+ const seen = new Set();
90
+ for (const field of value) {
91
+ exactKeys(field, ["name", "type"], ["mode", "fields", "precision", "scale"], "malformed_wire");
92
+ identifier(field.name);
93
+ if (seen.has(field.name))
94
+ fail("malformed_wire");
95
+ seen.add(field.name);
96
+ if (++counter.count > 1024)
97
+ fail("response_limit");
98
+ if (typeof field.type !== "string" || !/^[A-Z][A-Z0-9_]*$/u.test(field.type) || ![undefined, "NULLABLE", "REQUIRED", "REPEATED"].includes(field.mode))
99
+ fail("malformed_wire");
100
+ for (const key of ["precision", "scale"])
101
+ if (field[key] !== undefined)
102
+ integerText(field[key]);
103
+ if (field.fields !== undefined)
104
+ validateSchema(field.fields, depth + 1, counter);
105
+ if ((field.type === "RECORD" || field.type === "STRUCT") !== (field.fields !== undefined))
106
+ fail("malformed_wire");
107
+ if (field.scale !== undefined && field.precision === undefined)
108
+ fail("malformed_wire");
109
+ if (field.precision !== undefined || field.scale !== undefined) {
110
+ if (!["NUMERIC", "BIGNUMERIC"].includes(field.type))
111
+ fail("malformed_wire");
112
+ const precision = Number(field.precision ?? (field.type === "NUMERIC" ? "38" : "76"));
113
+ const scale = Number(field.scale ?? "0");
114
+ if (precision < 1 || precision > (field.type === "NUMERIC" ? 38 : 76) || scale > (field.type === "NUMERIC" ? 9 : 38) || scale > precision || precision - scale > (field.type === "NUMERIC" ? 29 : 38))
115
+ fail("malformed_wire");
116
+ }
117
+ }
118
+ }
119
+ export function validateSource(source) {
120
+ exactKeys(source, "version sourceId descriptorDigest logicalCollection sourceProject datasetId tableId location schema publisherReviewRef rightsReviewRef use".split(" "));
121
+ if (source.version !== 1 || !["connection-test", "admitted"].includes(source.use))
122
+ fail("invalid_input");
123
+ for (const key of ["sourceId", "descriptorDigest", "location", "publisherReviewRef", "rightsReviewRef"])
124
+ nonempty(source[key]);
125
+ if (!/^[A-Za-z][A-Za-z0-9-]{0,63}$/u.test(source.location))
126
+ fail("invalid_input");
127
+ project(source.sourceProject);
128
+ for (const key of ["logicalCollection", "datasetId", "tableId"])
129
+ identifier(source[key]);
130
+ validateSchema(source.schema);
131
+ const reviewedModes = (fields) => {
132
+ for (const field of fields) {
133
+ if (field.mode === undefined)
134
+ fail("invalid_input");
135
+ if (field.fields !== undefined)
136
+ reviewedModes(field.fields);
137
+ }
138
+ };
139
+ reviewedModes(source.schema);
140
+ }
141
+ export function supportedField(field) {
142
+ normalizeScalar(field, field.mode === "REQUIRED" ? sample(field.type) : null);
143
+ if (field.fields !== undefined || field.mode === "REPEATED")
144
+ fail("unsupported_type");
145
+ }
146
+ function sample(type) {
147
+ return {
148
+ BOOL: "true", BOOLEAN: "true", DATE: "2000-01-01", TIME: "00:00:00", DATETIME: "2000-01-01T00:00:00", BYTES: "", JSON: "null", STRING: ""
149
+ }[type] ?? "0";
150
+ }
151
+ export function normalizeParameter(field, value) {
152
+ if (value === null)
153
+ return null; // Parameters have declared type; column nullability is not parameter nullability.
154
+ let wire = value;
155
+ if (field.type === "BOOL" || field.type === "BOOLEAN") {
156
+ if (typeof value !== "boolean")
157
+ fail("invalid_input");
158
+ wire = value ? "true" : "false";
159
+ }
160
+ const cell = normalizeScalar({
161
+ type: field.type
162
+ }, wire);
163
+ if (typeof cell.value === "string" && ["NUMERIC", "BIGNUMERIC"].includes(cell.type))
164
+ checkDecimalConstraints(field, cell.value);
165
+ return cell.value;
166
+ }
167
+ export function checkDecimalConstraints(field, value) {
168
+ if (field.precision === undefined && field.scale === undefined)
169
+ return;
170
+ const [whole = "", fraction = ""] = value.replace(/^-/, "").split(".");
171
+ const precision = Number(field.precision ?? (field.type === "NUMERIC" ? "38" : "76"));
172
+ const scale = Number(field.scale ?? "0");
173
+ if (fraction.length > scale || (whole === "0" ? 0 : whole.length) > precision - scale)
174
+ fail("unsupported_value");
175
+ }
176
+ export async function compileReadPlan(source, query) {
177
+ validateSource(source);
178
+ exactKeys(query, ["from", "projection", "where", "order", "limit"], [], "unsupported_query");
179
+ if (query.from !== source.logicalCollection || !Array.isArray(query.projection) || query.projection.length < 1 || query.projection.length > 128 || new Set(query.projection).size !== query.projection.length || !Number.isSafeInteger(query.limit) || query.limit < 1 || query.limit > 10000 || !Array.isArray(query.order) || query.order.length > 16)
180
+ fail("unsupported_query");
181
+ const fields = new Map(source.schema.map(field => [field.name, field]));
182
+ const column = (name) => {
183
+ identifier(name);
184
+ const field = fields.get(name);
185
+ if (field === undefined)
186
+ fail("unsupported_query");
187
+ supportedField(field);
188
+ return field;
189
+ };
190
+ query.projection.forEach(column);
191
+ const parameters = [];
192
+ let nodes = 0;
193
+ const predicate = (p, depth) => {
194
+ if (++nodes > 128 || depth >= 8)
195
+ fail("unsupported_query");
196
+ if (p === null || typeof p !== "object")
197
+ fail("unsupported_query");
198
+ if (p.op === "AND" || p.op === "OR") {
199
+ exactKeys(p, ["op", "items"], [], "unsupported_query");
200
+ if (!Array.isArray(p.items) || p.items.length === 0)
201
+ fail("unsupported_query");
202
+ const children = p.items.map(item => predicate(item, depth + 1));
203
+ return {
204
+ sql: `(${children.map(child => child.sql).join(` ${p.op} `)})`, condition: {
205
+ op: p.op, children: children.map(child => child.condition)
206
+ }
207
+ };
208
+ }
209
+ exactKeys(p, ["op", "column"], ["value"], "unsupported_query");
210
+ const field = column(p.column);
211
+ if (["JSON", "BYTES"].includes(field.type) && !["IS NULL", "IS NOT NULL"].includes(p.op))
212
+ fail("unsupported_type");
213
+ const expression = `\`${field.name}\``;
214
+ if (p.op === "IS NULL" || p.op === "IS NOT NULL") {
215
+ if (Object.hasOwn(p, "value"))
216
+ fail("unsupported_query");
217
+ return {
218
+ sql: `${expression} ${p.op}`, condition: {
219
+ op: p.op, column: field.name
220
+ }
221
+ };
222
+ }
223
+ if (!["=", "!=", "<", "<=", ">", ">=", "IN"].includes(p.op) || !Object.hasOwn(p, "value"))
224
+ fail("unsupported_query");
225
+ if (["BOOL", "BOOLEAN"].includes(field.type) && !["=", "!=", "IN"].includes(p.op))
226
+ fail("unsupported_query");
227
+ if (p.value === null)
228
+ fail("unsupported_query");
229
+ const name = `p${parameters.length}`;
230
+ if (p.op === "IN") {
231
+ if (!Array.isArray(p.value) || p.value.length > 1000 || p.value.some(value => value === null))
232
+ fail("unsupported_query");
233
+ parameters.push({
234
+ name, type: `ARRAY<${normalizeScalar({
235
+ type: field.type
236
+ }, null).type}>`, value: p.value.map(value => normalizeParameter(field, value))
237
+ });
238
+ return {
239
+ sql: p.value.length === 0 ? "FALSE" : `${expression} IN UNNEST(@${name})`, condition: {
240
+ op: p.op, column: field.name, parameter: name
241
+ }
242
+ };
243
+ }
244
+ parameters.push({
245
+ name, type: normalizeScalar({
246
+ type: field.type
247
+ }, null).type, value: normalizeParameter(field, p.value)
248
+ });
249
+ return {
250
+ sql: `${expression} ${p.op} @${name}`, condition: {
251
+ op: p.op, column: field.name, parameter: name
252
+ }
253
+ };
254
+ };
255
+ const normalizedWhere = query.where === null ? null : predicate(query.where, 0);
256
+ const where = normalizedWhere === null ? "" : ` WHERE ${normalizedWhere.sql}`;
257
+ const orderNames = new Set();
258
+ const ordering = query.order.map(item => {
259
+ exactKeys(item, ["column", "direction"], [], "unsupported_query");
260
+ const field = column(item.column);
261
+ if (["BOOL", "BOOLEAN", "JSON", "BYTES"].includes(field.type) || !["ASC", "DESC"].includes(item.direction) || orderNames.has(item.column))
262
+ fail("unsupported_query");
263
+ orderNames.add(item.column);
264
+ return `\`${item.column}\` ${item.direction}`;
265
+ });
266
+ const sourceDigest = await digest("SourceProfile", source);
267
+ const payload = {
268
+ version: 1, sourceDigest, projection: [...query.projection], where: normalizedWhere?.condition ?? null, order: query.order, limit: query.limit, parameters, sql: `SELECT ${query.projection.map(name => `\`${name}\``).join(", ")} FROM \`${source.sourceProject}.${source.datasetId}.${source.tableId}\`${where}${ordering.length === 0 ? "" : ` ORDER BY ${ordering.join(", ")}`} LIMIT ${query.limit}`
269
+ };
270
+ return cloneFrozen({
271
+ ...payload, digest: await digest("ReadPlan", payload)
272
+ });
273
+ }
274
+ export function wireParameters(parameters) {
275
+ return parameters.map(parameter => ({
276
+ name: parameter.name, parameterType: Array.isArray(parameter.value) ? {
277
+ type: "ARRAY", arrayType: {
278
+ type: parameter.type.slice(6, -1)
279
+ }
280
+ } : {
281
+ type: parameter.type
282
+ }, parameterValue: Array.isArray(parameter.value) ? {
283
+ arrayValues: parameter.value.map(value => ({
284
+ value: wireParameterValue(parameter.type.slice(6, -1), value)
285
+ }))
286
+ } : {
287
+ value: wireParameterValue(parameter.type, parameter.value)
288
+ }
289
+ }));
290
+ }
291
+ /** Keep canonical epoch microseconds in plans/cells; REST TIMESTAMP parameters
292
+ * require UTC calendar text. All calendar arithmetic is exact BigInt, including
293
+ * negative fractional instants. No JS Date or floating-point timestamp conversion.
294
+ */
295
+ function wireParameterValue(type, value) {
296
+ if (value === null)
297
+ return null;
298
+ if (type !== "TIMESTAMP")
299
+ return typeof value === "boolean" ? String(value) : value;
300
+ const micros = BigInt(normalizeScalar({ type: "TIMESTAMP" }, value).value);
301
+ const floorDivide = (a, b) => a / b - (a % b < 0n ? 1n : 0n);
302
+ const seconds = floorDivide(micros, 1000000n);
303
+ const fraction = micros - seconds * 1000000n;
304
+ const days = floorDivide(seconds, 86400n);
305
+ const clockSeconds = seconds - days * 86400n;
306
+ // Gregorian civil date from days since 1970-01-01; March-based 400-year eras.
307
+ const shifted = days + 719468n;
308
+ const era = floorDivide(shifted, 146097n);
309
+ const dayOfEra = shifted - era * 146097n;
310
+ const yearOfEra = (dayOfEra - dayOfEra / 1460n + dayOfEra / 36524n - dayOfEra / 146096n) / 365n;
311
+ let year = yearOfEra + era * 400n;
312
+ const dayOfYear = dayOfEra - (365n * yearOfEra + yearOfEra / 4n - yearOfEra / 100n);
313
+ const monthOfYear = (5n * dayOfYear + 2n) / 153n;
314
+ const day = dayOfYear - (153n * monthOfYear + 2n) / 5n + 1n;
315
+ const month = monthOfYear + (monthOfYear < 10n ? 3n : -9n);
316
+ if (month <= 2n)
317
+ year += 1n;
318
+ const pad = (part, width = 2) => part.toString().padStart(width, "0");
319
+ return `${pad(year, 4)}-${pad(month)}-${pad(day)} ${pad(clockSeconds / 3600n)}:${pad(clockSeconds % 3600n / 60n)}:${pad(clockSeconds % 60n)}.${pad(fraction, 6)} UTC`;
320
+ }
@@ -0,0 +1,29 @@
1
+ import type { MetadataDiscovery } from "./metadata-client.js";
2
+ export interface PublicMetadataField {
3
+ readonly name: string;
4
+ readonly type: string;
5
+ readonly mode: string;
6
+ readonly fields?: readonly PublicMetadataField[];
7
+ }
8
+ export interface PublicMetadataObservation {
9
+ readonly format: "ovdb-bigquery-observation/draft-1";
10
+ readonly source_id: string;
11
+ readonly source_project: string;
12
+ readonly dataset_id: string;
13
+ readonly table_id: string;
14
+ readonly location: string;
15
+ readonly object_type: string;
16
+ readonly observed_at: string;
17
+ readonly projection: "partial-public-schema";
18
+ readonly provenance: {
19
+ readonly kind: "synthetic-fixture";
20
+ readonly method: "datasets.get+tables.get";
21
+ readonly verifier: "public-projection-review-v1";
22
+ };
23
+ readonly schema: readonly PublicMetadataField[];
24
+ readonly sha256: string;
25
+ }
26
+ /** Fixture-only public projection. Publication rights and provider authenticity
27
+ * require a separate operator review; this never labels fixtures as observed. */
28
+ export declare function projectFixtureMetadata(discovery: MetadataDiscovery): Promise<PublicMetadataObservation>;
29
+ //# sourceMappingURL=public-metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-metadata.d.ts","sourceRoot":"","sources":["../../src/analytical/public-metadata.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;CAClD;AACD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,MAAM,EAAE,mCAAmC,CAAC;IACrD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,uBAAuB,CAAC;IAC7C,QAAQ,CAAC,UAAU,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,yBAAyB,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,6BAA6B,CAAA;KAAE,CAAC;IAC1J,QAAQ,CAAC,MAAM,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAKD;iFACiF;AACjF,wBAAsB,sBAAsB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CA+C7G"}
@@ -0,0 +1,70 @@
1
+ import { canonicalJSON } from "./canonical.js";
2
+ import { object } from "./metadata.js";
3
+ import { cloneFrozen } from "./protocol.js";
4
+ import { fail } from "./wire.js";
5
+ const types = new Set(["STRING", "BYTES", "INTEGER", "INT64", "FLOAT", "FLOAT64", "BOOLEAN", "BOOL", "TIMESTAMP", "DATE", "TIME", "DATETIME", "GEOGRAPHY", "NUMERIC", "BIGNUMERIC", "JSON", "RECORD", "STRUCT", "RANGE"]);
6
+ function matches(value, pattern, maximum) {
7
+ if (typeof value !== "string" || value.length > maximum || !pattern.test(value))
8
+ fail("malformed_wire");
9
+ }
10
+ /** Fixture-only public projection. Publication rights and provider authenticity
11
+ * require a separate operator review; this never labels fixtures as observed. */
12
+ export async function projectFixtureMetadata(discovery) {
13
+ const s = discovery.source;
14
+ matches(s.sourceId, /^[a-z0-9]+(?:-[a-z0-9]+)*$/u, 80);
15
+ matches(s.sourceProject, /^[a-z][a-z0-9-]{4,61}[a-z0-9]$/u, 63);
16
+ for (const id of [s.datasetId, s.tableId])
17
+ matches(id, /^[A-Za-z_][A-Za-z0-9_]*$/u, 1024);
18
+ const location = discovery.dataset.location;
19
+ matches(location, /^(?:US|EU|[a-z][a-z0-9]*(?:-[a-z0-9]+)+)$/u, 64);
20
+ const type = discovery.table.type;
21
+ if (typeof type !== "string" || !["TABLE", "VIEW", "EXTERNAL", "MATERIALIZED_VIEW", "SNAPSHOT"].includes(type))
22
+ fail("malformed_wire");
23
+ let count = 0;
24
+ const fields = (raw, depth) => {
25
+ if (!Array.isArray(raw) || raw.length === 0 || depth > 8)
26
+ fail("response_limit");
27
+ const names = new Set();
28
+ return raw.map(value => {
29
+ if (++count > 500)
30
+ fail("response_limit");
31
+ const f = object(value);
32
+ matches(f.name, /^[A-Za-z_][A-Za-z0-9_]*$/u, 300);
33
+ if (names.has(f.name.toLowerCase()))
34
+ fail("malformed_wire");
35
+ names.add(f.name.toLowerCase());
36
+ if (typeof f.type !== "string" || !types.has(f.type))
37
+ fail("malformed_wire");
38
+ const mode = f.mode ?? "NULLABLE";
39
+ if (typeof mode !== "string" || !["NULLABLE", "REQUIRED", "REPEATED"].includes(mode))
40
+ fail("malformed_wire");
41
+ const nested = f.type === "RECORD" || f.type === "STRUCT";
42
+ if (!nested && Object.hasOwn(f, "fields"))
43
+ fail("malformed_wire");
44
+ // Copy only individually admitted properties, at every depth. Descriptions,
45
+ // policy tags, descriptors, expressions and provider config are excluded.
46
+ return { name: f.name, type: f.type, mode, ...(nested ? { fields: fields(f.fields, depth + 1) } : {}) };
47
+ });
48
+ };
49
+ const at = new Date(discovery.observedAt);
50
+ if (!Number.isFinite(at.getTime()))
51
+ fail("malformed_wire");
52
+ const observedAt = at.toISOString().replace(/\.\d{3}Z$/u, "Z");
53
+ matches(observedAt, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/u, 20);
54
+ const value = {
55
+ format: "ovdb-bigquery-observation/draft-1",
56
+ source_id: s.sourceId, source_project: s.sourceProject, dataset_id: s.datasetId, table_id: s.tableId,
57
+ location, object_type: type, observed_at: observedAt,
58
+ projection: "partial-public-schema",
59
+ provenance: { kind: "synthetic-fixture", method: "datasets.get+tables.get", verifier: "public-projection-review-v1" },
60
+ schema: fields(object(discovery.table.schema).fields, 1),
61
+ };
62
+ const input = new TextEncoder().encode(JSON.stringify(value));
63
+ if (input.length > 65536)
64
+ fail("response_limit");
65
+ const digest = new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", Uint8Array.from(canonicalJSON(input))));
66
+ const result = { ...value, sha256: `sha256:${Array.from(digest, v => v.toString(16).padStart(2, "0")).join("")}` };
67
+ if (new TextEncoder().encode(JSON.stringify(result)).length > 65536)
68
+ fail("response_limit");
69
+ return cloneFrozen(result);
70
+ }
@@ -0,0 +1,39 @@
1
+ import { type JsonValue } from "./wire.js";
2
+ import { type Bounds, type Principal } from "./protocol.js";
3
+ export interface TrustedIdentity {
4
+ readonly principal: Principal;
5
+ readonly accessToken: string;
6
+ readonly expiresAt: number;
7
+ readonly read: boolean;
8
+ readonly cancel: boolean;
9
+ }
10
+ /** For google-user the consumer attests same-token verified sub/grants, for
11
+ * workload the operator attests the configured subject. Never caller JSON.
12
+ */
13
+ export interface IdentityProvider {
14
+ authorize(signal: AbortSignal): Promise<TrustedIdentity>;
15
+ }
16
+ export interface Clock {
17
+ now(): number;
18
+ sleep(ms: number, signal?: AbortSignal): Promise<void>;
19
+ }
20
+ export declare const realClock: Clock;
21
+ export interface OperationScope {
22
+ readonly bounds: Bounds;
23
+ readonly executionDeadline: number;
24
+ readonly principal: Principal;
25
+ readonly callerDeadline?: number;
26
+ readonly signal?: AbortSignal;
27
+ beforeDispatch?(): Promise<void>;
28
+ remaining(): Promise<number>;
29
+ debit(bytes: number): Promise<void>;
30
+ }
31
+ export declare function abortable<T>(promise: Promise<T>, signal: AbortSignal): Promise<T>;
32
+ export type SafeFetch = (input: string, init: RequestInit) => Promise<Response>;
33
+ export declare class Transport {
34
+ #private;
35
+ constructor(provider: IdentityProvider, fetcher: SafeFetch, clock: Clock);
36
+ verify(principal: Principal, deadline: number, signal?: AbortSignal, rebind?: boolean): Promise<Principal>;
37
+ call(scope: OperationScope, method: "GET" | "POST", path: string, query: Record<string, string>, body?: unknown, control?: boolean, cancel?: boolean, beforeDispatch?: () => void): Promise<JsonValue>;
38
+ }
39
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/analytical/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAG7E,OAAO,EAAqB,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AACD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC1D;AACD,MAAM,WAAW,KAAK;IACpB,GAAG,IAAI,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AACD,eAAO,MAAM,SAAS,EAAE,KAYvB,CAAC;AACF,MAAM,WAAW,cAAc;IAC7B,QA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