@query-farm/vgi 0.48.2 → 0.48.4
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/README.md +27 -0
- package/dist/arrow/impl-arrowjs/iterate.d.ts +7 -3
- package/dist/arrow/impl-flechette/iterate.d.ts +2 -1
- package/dist/catalog/descriptors.d.ts +30 -0
- package/dist/catalog/interface.d.ts +28 -0
- package/dist/catalog/read-only.d.ts +16 -2
- package/dist/client-entry.js +9 -25
- package/dist/client-entry.js.map +4 -4
- package/dist/functions/aggregate.d.ts +2 -1
- package/dist/functions/copy-from.d.ts +2 -1
- package/dist/functions/copy-to.d.ts +2 -1
- package/dist/functions/scalar.d.ts +2 -1
- package/dist/functions/table-buffering.d.ts +2 -1
- package/dist/functions/table-in-out.d.ts +3 -2
- package/dist/functions/table.d.ts +2 -1
- package/dist/functions/types.d.ts +2 -1
- package/dist/index.core.d.ts +4 -1
- package/dist/index.js +360 -72
- package/dist/index.js.map +25 -23
- package/dist/metadata/types.d.ts +3 -1
- package/dist/protocol/handlers/catalog/shared.d.ts +8 -0
- package/dist/secrets/helpers.d.ts +31 -3
- package/dist/secrets/requirements.d.ts +38 -0
- package/dist/serve-entry.js +51 -33
- package/dist/serve-entry.js.map +9 -9
- package/dist/worker-cf-entry.d.ts +2 -2
- package/dist/worker-cf-entry.js +296 -50
- package/dist/worker-cf-entry.js.map +21 -18
- package/dist/write-results.d.ts +57 -0
- package/package.json +1 -1
- package/src/arrow/impl-arrowjs/iterate.ts +17 -40
- package/src/arrow/impl-flechette/iterate.ts +5 -24
- package/src/catalog/descriptors.ts +30 -0
- package/src/catalog/interface.ts +51 -0
- package/src/catalog/read-only.ts +129 -21
- package/src/functions/aggregate.ts +3 -2
- package/src/functions/copy-from.ts +3 -2
- package/src/functions/copy-to.ts +2 -1
- package/src/functions/scalar.ts +3 -2
- package/src/functions/table-buffering.ts +3 -2
- package/src/functions/table-in-out.ts +5 -4
- package/src/functions/table.ts +3 -2
- package/src/functions/types.ts +2 -1
- package/src/index.core.ts +33 -0
- package/src/metadata/resolve.ts +2 -1
- package/src/metadata/serialize.ts +25 -5
- package/src/metadata/types.ts +3 -1
- package/src/protocol/handlers/catalog/shared.ts +17 -0
- package/src/protocol/handlers/catalog/table.ts +37 -0
- package/src/protocol/handlers/function.ts +42 -14
- package/src/secrets/helpers.ts +96 -9
- package/src/secrets/requirements.ts +121 -0
- package/src/worker-cf-entry.ts +14 -0
- package/src/write-results.ts +174 -0
package/dist/metadata/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SecretRequirement } from "../secrets/requirements.js";
|
|
1
2
|
import { FunctionStability, NullHandling, ArgumentMonotonicity, OrderPreservation, OrderDependence, DistinctDependence } from "../types.js";
|
|
2
3
|
export declare enum CatalogFunctionType {
|
|
3
4
|
SCALAR = "SCALAR",
|
|
@@ -45,7 +46,8 @@ export interface ResolvedMetadata {
|
|
|
45
46
|
nullHandling: NullHandling;
|
|
46
47
|
argumentMonotonicity: ArgumentMonotonicity[] | null;
|
|
47
48
|
requiredSettings: string[];
|
|
48
|
-
|
|
49
|
+
/** Validated static secret requirements (FunctionInfo `required_secrets`). */
|
|
50
|
+
requiredSecrets: SecretRequirement[];
|
|
49
51
|
projectionPushdown: boolean;
|
|
50
52
|
filterPushdown: boolean;
|
|
51
53
|
samplingPushdown: boolean;
|
|
@@ -38,6 +38,14 @@ export declare function shardKeyForAttach(sealed: Uint8Array | undefined, auth:
|
|
|
38
38
|
* to the caller's identity and the parent attach envelope it was minted under.
|
|
39
39
|
*/
|
|
40
40
|
export declare function sealTransaction(plaintext: Uint8Array, attachEnvelope: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined): Promise<Uint8Array>;
|
|
41
|
+
/**
|
|
42
|
+
* Open a transaction_opaque_data envelope (sealed on HTTP only, no UUID prefix).
|
|
43
|
+
* `attachEnvelope` is the request's *sealed* attach, which the transaction
|
|
44
|
+
* envelope's AAD binds. A pass-through without a signing key or for an empty
|
|
45
|
+
* value. Catalog hooks and function bodies must see the same plaintext, or a
|
|
46
|
+
* worker cannot tie a function call to its transaction's commit/rollback.
|
|
47
|
+
*/
|
|
48
|
+
export declare function openTransaction(envelope: Uint8Array, attachEnvelope: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined): Promise<Uint8Array>;
|
|
41
49
|
/**
|
|
42
50
|
* Wrap a catalog unary handler so its request opaque-data fields are unwrapped
|
|
43
51
|
* before the body runs. Used for every catalog_* method except catalog_attach
|
|
@@ -2,14 +2,42 @@ export type SecretFields = Record<string, any>;
|
|
|
2
2
|
export type SecretsDict = Record<string, SecretFields>;
|
|
3
3
|
/** The DuckDB secret type of the named secret (its serialized `type` field). */
|
|
4
4
|
export declare function secretType(secrets: SecretsDict, name: string): string | undefined;
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Every resolved secret whose serialized `type` field matches `type`, in
|
|
7
|
+
* delivery order. Falls back to an untyped secret keyed by `type` only when no
|
|
8
|
+
* secret carries the type.
|
|
9
|
+
*/
|
|
6
10
|
export declare function secretsOfType(secrets: SecretsDict, type: string): SecretFields[];
|
|
11
|
+
/**
|
|
12
|
+
* The secret a by-TYPE request refers to: a secret of `type` with an empty
|
|
13
|
+
* scope, else the first secret of `type`, else undefined. This is the rule the
|
|
14
|
+
* client applies to a `requiredSecrets: ["<type>"]` declaration, so it picks the
|
|
15
|
+
* secret that declaration resolved even when other same-type secrets (from
|
|
16
|
+
* scoped declarations) were delivered alongside it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function secretOfType(secrets: SecretsDict, type: string): SecretFields | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Like {@link secretOfType}, but throws when no secret of `type` was resolved.
|
|
21
|
+
* Call it from `onBind` to fail the bind of a function that cannot run without
|
|
22
|
+
* credentials. The message names the type and never includes a secret value.
|
|
23
|
+
*/
|
|
24
|
+
export declare function requireSecretOfType(secrets: SecretsDict, type: string): SecretFields;
|
|
25
|
+
/**
|
|
26
|
+
* The secret with DuckDB name `name` (its key in the resolved batch). With
|
|
27
|
+
* `type`, only if that secret's `type` field is `type` (or absent, for a bare
|
|
28
|
+
* key/value struct) — the rule the client applies to a by-name request.
|
|
29
|
+
*/
|
|
30
|
+
export declare function secretByName(secrets: SecretsDict, name: string, type?: string): SecretFields | undefined;
|
|
7
31
|
/**
|
|
8
32
|
* The secret whose `scope` is the longest prefix of `path`. The connector
|
|
9
33
|
* serializes each secret's scope as a newline-joined list of prefixes; a secret
|
|
10
34
|
* with no (or empty) scope matches as a last-resort fallback. Returns undefined
|
|
11
|
-
*
|
|
35
|
+
* when no scope is a prefix of `path` and no unscoped secret was delivered.
|
|
12
36
|
*/
|
|
13
37
|
export declare function secretForScope(secrets: SecretsDict, path: string): SecretFields | undefined;
|
|
14
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Like {@link secretForScope} but only over secrets of `type`: the one whose
|
|
40
|
+
* scope is the longest prefix of `path`, else one of `type` with an empty scope,
|
|
41
|
+
* else undefined.
|
|
42
|
+
*/
|
|
15
43
|
export declare function secretForScopeOfType(secrets: SecretsDict, path: string, type: string): SecretFields | undefined;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A secret requirement in object form. `scope` asks the client for the secret of
|
|
3
|
+
* `secretType` whose scope is the longest prefix of it; `secretName` asks for one
|
|
4
|
+
* secret by its DuckDB name (and takes precedence over `scope`, as it does on
|
|
5
|
+
* the client). Neither means "a secret of this type with an empty scope".
|
|
6
|
+
*
|
|
7
|
+
* The snake_case spelling of the wire entry (`secret_type` / `secret_name`) is
|
|
8
|
+
* accepted too.
|
|
9
|
+
*/
|
|
10
|
+
export interface SecretRequirementSpec {
|
|
11
|
+
secretType?: string;
|
|
12
|
+
scope?: string | null;
|
|
13
|
+
secretName?: string | null;
|
|
14
|
+
secret_type?: string;
|
|
15
|
+
secret_name?: string | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* One `requiredSecrets` entry: a bare secret type (the simplest form — "a secret
|
|
19
|
+
* of this type"), or a {@link SecretRequirementSpec} with a scope or a name.
|
|
20
|
+
*/
|
|
21
|
+
export type RequiredSecret = string | SecretRequirementSpec;
|
|
22
|
+
/** A validated, normalized requirement — the shape sent on the wire. */
|
|
23
|
+
export interface SecretRequirement {
|
|
24
|
+
secretType: string;
|
|
25
|
+
scope: string | null;
|
|
26
|
+
secretName: string | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validate and normalize a `requiredSecrets` declaration. Throws on anything
|
|
30
|
+
* that is not a list of bare type strings / requirement objects, on an empty
|
|
31
|
+
* type, on unknown object keys (a typo such as `{ type: "s3" }` would otherwise
|
|
32
|
+
* declare nothing), and on conflicting camelCase/snake_case spellings.
|
|
33
|
+
* Duplicate requirements (same type, scope and name) are collapsed.
|
|
34
|
+
*
|
|
35
|
+
* @param value The declared `requiredSecrets` (undefined → no requirements).
|
|
36
|
+
* @param functionName Used in error messages.
|
|
37
|
+
*/
|
|
38
|
+
export declare function normalizeRequiredSecrets(value: unknown, functionName?: string): SecretRequirement[];
|
package/dist/serve-entry.js
CHANGED
|
@@ -2133,30 +2133,14 @@ function batchToSecretDict(batch) {
|
|
|
2133
2133
|
const result = {};
|
|
2134
2134
|
for (const field of a.schema.fields) {
|
|
2135
2135
|
const col = a.getChild(field.name);
|
|
2136
|
-
if (col)
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
key = secretType;
|
|
2145
|
-
scope = field.metadata?.get?.("scope") ?? undefined;
|
|
2146
|
-
}
|
|
2147
|
-
}
|
|
2148
|
-
if (val && typeof val === "object" && !ArrayBuffer.isView(val)) {
|
|
2149
|
-
const dict = { ...val };
|
|
2150
|
-
if (key in result) {
|
|
2151
|
-
throw new Error(`batchToSecretDict: duplicate secret_type '${key}' (scope=${scope ?? "none"}). ` + `Use scoped secrets with distinct scopes to avoid collisions.`);
|
|
2152
|
-
}
|
|
2153
|
-
result[key] = dict;
|
|
2154
|
-
if (scope) {
|
|
2155
|
-
result[`${key}:${scope}`] = dict;
|
|
2156
|
-
}
|
|
2157
|
-
} else if (val === null || val === undefined) {} else {
|
|
2158
|
-
result[key] = {};
|
|
2159
|
-
}
|
|
2136
|
+
if (!col)
|
|
2137
|
+
continue;
|
|
2138
|
+
const type = field.type;
|
|
2139
|
+
const val = codecFor(type).canonicalToRich(readCanonicalValue(type, col, 0));
|
|
2140
|
+
if (val && typeof val === "object" && !ArrayBuffer.isView(val)) {
|
|
2141
|
+
result[field.name] = { ...val };
|
|
2142
|
+
} else if (val !== null && val !== undefined) {
|
|
2143
|
+
result[field.name] = {};
|
|
2160
2144
|
}
|
|
2161
2145
|
}
|
|
2162
2146
|
return result;
|
|
@@ -8311,6 +8295,11 @@ async function sealTransaction(plaintext, attachEnvelope, auth, signingKey) {
|
|
|
8311
8295
|
return plaintext;
|
|
8312
8296
|
return sealBytes(plaintext, signingKey, transactionAad(auth, attachEnvelope), TRANSACTION_ENVELOPE_VERSION);
|
|
8313
8297
|
}
|
|
8298
|
+
async function openTransaction(envelope, attachEnvelope, auth, signingKey) {
|
|
8299
|
+
if (!signingKey || envelope.length === 0)
|
|
8300
|
+
return envelope;
|
|
8301
|
+
return openBytes(envelope, signingKey, transactionAad(auth, attachEnvelope), TRANSACTION_ENVELOPE_VERSION, "transaction_opaque_data");
|
|
8302
|
+
}
|
|
8314
8303
|
async function unwrapParamsOpaque(params, ctx, signingKey) {
|
|
8315
8304
|
const auth = ctx?.auth;
|
|
8316
8305
|
let sealedAttach = new Uint8Array(0);
|
|
@@ -8591,7 +8580,12 @@ async function liveSplitAnchor(catalogInterface, bindCall, auth, signingKey) {
|
|
|
8591
8580
|
if (!catalogInterface?.version || bindCall.attach_opaque_data == null)
|
|
8592
8581
|
return;
|
|
8593
8582
|
const raw = toUint8Array(bindCall.attach_opaque_data);
|
|
8594
|
-
|
|
8583
|
+
let txn = bindCall.transaction_opaque_data ? toUint8Array(bindCall.transaction_opaque_data) : undefined;
|
|
8584
|
+
if (txn && txn.length > 0 && signingKey) {
|
|
8585
|
+
try {
|
|
8586
|
+
txn = await openTransaction(txn, raw, auth, signingKey);
|
|
8587
|
+
} catch {}
|
|
8588
|
+
}
|
|
8595
8589
|
const forms = [
|
|
8596
8590
|
async () => raw,
|
|
8597
8591
|
async () => openAttach(raw, auth, signingKey)
|
|
@@ -8629,14 +8623,22 @@ function functionHandlers(config) {
|
|
|
8629
8623
|
return env;
|
|
8630
8624
|
return openAttach(env, ctx?.auth ?? currentRequestAuth(), signingKey);
|
|
8631
8625
|
}
|
|
8626
|
+
async function openOpaque(bindCall, ctx) {
|
|
8627
|
+
const sealedAttach = bindCall.attach_opaque_data != null ? toUint8Array(bindCall.attach_opaque_data) : new Uint8Array(0);
|
|
8628
|
+
if (bindCall.transaction_opaque_data != null) {
|
|
8629
|
+
bindCall.transaction_opaque_data = await openTransaction(toUint8Array(bindCall.transaction_opaque_data), sealedAttach, ctx?.auth ?? currentRequestAuth(), signingKey);
|
|
8630
|
+
}
|
|
8631
|
+
bindCall.attach_opaque_data = await stripAttach(bindCall.attach_opaque_data, ctx);
|
|
8632
|
+
}
|
|
8632
8633
|
async function strippedContext(bindCall, ctx) {
|
|
8633
|
-
|
|
8634
|
+
const copy = { ...bindCall };
|
|
8634
8635
|
try {
|
|
8635
|
-
|
|
8636
|
+
await openOpaque(copy, ctx);
|
|
8636
8637
|
} catch {
|
|
8637
|
-
|
|
8638
|
+
copy.attach_opaque_data = null;
|
|
8639
|
+
copy.transaction_opaque_data = null;
|
|
8638
8640
|
}
|
|
8639
|
-
return overloadContext(
|
|
8641
|
+
return overloadContext(copy, catalogInterface);
|
|
8640
8642
|
}
|
|
8641
8643
|
const emptySchema = schema2([]);
|
|
8642
8644
|
const dummyInputSchema = schema2([
|
|
@@ -8645,7 +8647,7 @@ function functionHandlers(config) {
|
|
|
8645
8647
|
const bind = async (params, ctx) => {
|
|
8646
8648
|
const innerParams = unwrapRequest(params.request);
|
|
8647
8649
|
const request = deserializeBindRequest(innerParams);
|
|
8648
|
-
|
|
8650
|
+
await openOpaque(request, ctx);
|
|
8649
8651
|
const func = registry.get(request.function_name, overloadContext(request, catalogInterface));
|
|
8650
8652
|
const response = await func.bind(request);
|
|
8651
8653
|
validateProjectionOffer(response);
|
|
@@ -8660,7 +8662,7 @@ function functionHandlers(config) {
|
|
|
8660
8662
|
const innerParams = unwrapRequest(params.request);
|
|
8661
8663
|
const request = deserializeInitRequest(innerParams);
|
|
8662
8664
|
const auth = ctx?.auth ?? currentRequestAuth();
|
|
8663
|
-
|
|
8665
|
+
await openOpaque(request.bind_call, ctx);
|
|
8664
8666
|
await resolveSplitPayloads(request, innerParams, {
|
|
8665
8667
|
auth,
|
|
8666
8668
|
signingKey,
|
|
@@ -8705,7 +8707,7 @@ function functionHandlers(config) {
|
|
|
8705
8707
|
} else {
|
|
8706
8708
|
const carried = parseCarriedInitRequest(state.initRequestPacked);
|
|
8707
8709
|
const request = carried.request;
|
|
8708
|
-
|
|
8710
|
+
await openOpaque(request.bind_call, undefined);
|
|
8709
8711
|
await resolveSplitPayloads(request, { bind_call: carried.bindCallIpc }, {
|
|
8710
8712
|
auth: currentRequestAuth(),
|
|
8711
8713
|
signingKey,
|
|
@@ -11266,6 +11268,19 @@ function catalogTableHandlers(getCatalog, signingKey) {
|
|
|
11266
11268
|
const scanResult = await cat.tableScanFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.at_unit, params.at_value, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
11267
11269
|
return wrapResult(scanResult, ScanFunctionResultSchema);
|
|
11268
11270
|
});
|
|
11271
|
+
const optionalTx = (params) => params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined;
|
|
11272
|
+
const catalogTableInsertFunctionGet = catalogHandler(signingKey, async (params) => {
|
|
11273
|
+
const result = await getCatalog().tableInsertFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params), params.writable_branch_function_name ?? null);
|
|
11274
|
+
return wrapResult(result, ScanFunctionResultSchema);
|
|
11275
|
+
});
|
|
11276
|
+
const catalogTableUpdateFunctionGet = catalogHandler(signingKey, async (params) => {
|
|
11277
|
+
const result = await getCatalog().tableUpdateFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params));
|
|
11278
|
+
return wrapResult(result, ScanFunctionResultSchema);
|
|
11279
|
+
});
|
|
11280
|
+
const catalogTableDeleteFunctionGet = catalogHandler(signingKey, async (params) => {
|
|
11281
|
+
const result = await getCatalog().tableDeleteFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params));
|
|
11282
|
+
return wrapResult(result, ScanFunctionResultSchema);
|
|
11283
|
+
});
|
|
11269
11284
|
const catalogTableScanBranchesGet = catalogHandler(signingKey, async (params) => {
|
|
11270
11285
|
const cat = getCatalog();
|
|
11271
11286
|
const branchesResult = await cat.tableScanBranchesGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.at_unit, params.at_value, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
|
|
@@ -11344,6 +11359,9 @@ function catalogTableHandlers(getCatalog, signingKey) {
|
|
|
11344
11359
|
catalogTableDrop,
|
|
11345
11360
|
catalogTableColumnStatisticsGet,
|
|
11346
11361
|
catalogTableScanFunctionGet,
|
|
11362
|
+
catalogTableInsertFunctionGet,
|
|
11363
|
+
catalogTableUpdateFunctionGet,
|
|
11364
|
+
catalogTableDeleteFunctionGet,
|
|
11347
11365
|
catalogTableScanBranchesGet,
|
|
11348
11366
|
catalogTableCommentSet,
|
|
11349
11367
|
catalogTableRename,
|
|
@@ -11925,4 +11943,4 @@ export {
|
|
|
11925
11943
|
serveVgiWorker
|
|
11926
11944
|
};
|
|
11927
11945
|
|
|
11928
|
-
//# debugId=
|
|
11946
|
+
//# debugId=448535FCB65D277D64756E2164756E21
|