@google-cloud/kcmd 0.0.0-stage → 0.1.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 (150) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +266 -2
  3. package/build/ts/kcmd/cli.js +19578 -0
  4. package/build/ts/kcmd/gcp/alloydb.d.ts +12 -0
  5. package/build/ts/kcmd/gcp/alloydb.js +70 -0
  6. package/build/ts/kcmd/gcp/api.d.ts +29 -0
  7. package/build/ts/kcmd/gcp/api.js +162 -0
  8. package/build/ts/kcmd/gcp/biglake.d.ts +16 -0
  9. package/build/ts/kcmd/gcp/biglake.js +50 -0
  10. package/build/ts/kcmd/gcp/bigquery.d.ts +57 -0
  11. package/build/ts/kcmd/gcp/bigquery.js +134 -0
  12. package/build/ts/kcmd/gcp/context.d.ts +10 -0
  13. package/build/ts/kcmd/gcp/context.js +74 -0
  14. package/build/ts/kcmd/gcp/crm.d.ts +13 -0
  15. package/build/ts/kcmd/gcp/crm.js +91 -0
  16. package/build/ts/kcmd/gcp/dataplex.d.ts +147 -0
  17. package/build/ts/kcmd/gcp/dataplex.js +406 -0
  18. package/build/ts/kcmd/gcp/index.d.ts +3 -0
  19. package/build/ts/kcmd/gcp/index.js +21 -0
  20. package/build/ts/kcmd/gcp/spanner.d.ts +63 -0
  21. package/build/ts/kcmd/gcp/spanner.js +123 -0
  22. package/build/ts/kcmd/index.d.ts +7 -0
  23. package/build/ts/kcmd/index.js +46 -0
  24. package/build/ts/kcmd/layout.d.ts +16 -0
  25. package/build/ts/kcmd/layout.js +31 -0
  26. package/build/ts/kcmd/layouts/documents.d.ts +24 -0
  27. package/build/ts/kcmd/layouts/documents.js +264 -0
  28. package/build/ts/kcmd/layouts/okf.d.ts +31 -0
  29. package/build/ts/kcmd/layouts/okf.js +344 -0
  30. package/build/ts/kcmd/layouts/semantic-model.d.ts +61 -0
  31. package/build/ts/kcmd/layouts/semantic-model.js +542 -0
  32. package/build/ts/kcmd/layouts/standard.d.ts +13 -0
  33. package/build/ts/kcmd/layouts/standard.js +108 -0
  34. package/build/ts/kcmd/manifest.d.ts +34 -0
  35. package/build/ts/kcmd/manifest.js +262 -0
  36. package/build/ts/kcmd/metadata.d.ts +25 -0
  37. package/build/ts/kcmd/metadata.js +8 -0
  38. package/build/ts/kcmd/okf/catalog_residue.d.ts +14 -0
  39. package/build/ts/kcmd/okf/catalog_residue.js +124 -0
  40. package/build/ts/kcmd/okf/concept.d.ts +14 -0
  41. package/build/ts/kcmd/okf/concept.js +104 -0
  42. package/build/ts/kcmd/okf/concept_to_entry.d.ts +8 -0
  43. package/build/ts/kcmd/okf/concept_to_entry.js +254 -0
  44. package/build/ts/kcmd/okf/init_okf_workspace.d.ts +15 -0
  45. package/build/ts/kcmd/okf/init_okf_workspace.js +115 -0
  46. package/build/ts/kcmd/okf/links.d.ts +23 -0
  47. package/build/ts/kcmd/okf/links.js +468 -0
  48. package/build/ts/kcmd/okf/okf_metadata.d.ts +12 -0
  49. package/build/ts/kcmd/okf/okf_metadata.js +82 -0
  50. package/build/ts/kcmd/semantic/bigquery.d.ts +22 -0
  51. package/build/ts/kcmd/semantic/bigquery.js +525 -0
  52. package/build/ts/kcmd/semantic/binding.d.ts +3 -0
  53. package/build/ts/kcmd/semantic/binding.js +97 -0
  54. package/build/ts/kcmd/semantic/catalog_entry.d.ts +24 -0
  55. package/build/ts/kcmd/semantic/catalog_entry.js +35 -0
  56. package/build/ts/kcmd/semantic/converters/owl/convert.d.ts +26 -0
  57. package/build/ts/kcmd/semantic/converters/owl/convert.js +41 -0
  58. package/build/ts/kcmd/semantic/converters/owl/model.d.ts +98 -0
  59. package/build/ts/kcmd/semantic/converters/owl/model.js +30 -0
  60. package/build/ts/kcmd/semantic/converters/owl/parse.d.ts +11 -0
  61. package/build/ts/kcmd/semantic/converters/owl/parse.js +634 -0
  62. package/build/ts/kcmd/semantic/converters/owl/to_ir.d.ts +19 -0
  63. package/build/ts/kcmd/semantic/converters/owl/to_ir.js +390 -0
  64. package/build/ts/kcmd/semantic/deploy_bigquery.d.ts +20 -0
  65. package/build/ts/kcmd/semantic/deploy_bigquery.js +226 -0
  66. package/build/ts/kcmd/semantic/deploy_knowledge_catalog.d.ts +129 -0
  67. package/build/ts/kcmd/semantic/deploy_knowledge_catalog.js +1396 -0
  68. package/build/ts/kcmd/semantic/deploy_spanner.d.ts +15 -0
  69. package/build/ts/kcmd/semantic/deploy_spanner.js +150 -0
  70. package/build/ts/kcmd/semantic/deployment_target.d.ts +93 -0
  71. package/build/ts/kcmd/semantic/deployment_target.js +379 -0
  72. package/build/ts/kcmd/semantic/graph_ddl.d.ts +34 -0
  73. package/build/ts/kcmd/semantic/graph_ddl.js +563 -0
  74. package/build/ts/kcmd/semantic/import_model.d.ts +50 -0
  75. package/build/ts/kcmd/semantic/import_model.js +1275 -0
  76. package/build/ts/kcmd/semantic/ir.d.ts +589 -0
  77. package/build/ts/kcmd/semantic/ir.js +247 -0
  78. package/build/ts/kcmd/semantic/kc_actions.d.ts +45 -0
  79. package/build/ts/kcmd/semantic/kc_actions.js +531 -0
  80. package/build/ts/kcmd/semantic/kc_constraints.d.ts +44 -0
  81. package/build/ts/kcmd/semantic/kc_constraints.js +279 -0
  82. package/build/ts/kcmd/semantic/kc_converter.d.ts +31 -0
  83. package/build/ts/kcmd/semantic/kc_converter.js +824 -0
  84. package/build/ts/kcmd/semantic/kc_custom_types.d.ts +70 -0
  85. package/build/ts/kcmd/semantic/kc_custom_types.js +828 -0
  86. package/build/ts/kcmd/semantic/kc_entries.d.ts +155 -0
  87. package/build/ts/kcmd/semantic/kc_entries.js +284 -0
  88. package/build/ts/kcmd/semantic/kc_ids.d.ts +103 -0
  89. package/build/ts/kcmd/semantic/kc_ids.js +191 -0
  90. package/build/ts/kcmd/semantic/knowledge_catalog.d.ts +32 -0
  91. package/build/ts/kcmd/semantic/knowledge_catalog.js +1043 -0
  92. package/build/ts/kcmd/semantic/loader.d.ts +262 -0
  93. package/build/ts/kcmd/semantic/loader.js +3440 -0
  94. package/build/ts/kcmd/semantic/names.d.ts +10 -0
  95. package/build/ts/kcmd/semantic/names.js +85 -0
  96. package/build/ts/kcmd/semantic/osi_converter.d.ts +60 -0
  97. package/build/ts/kcmd/semantic/osi_converter.js +911 -0
  98. package/build/ts/kcmd/semantic/parameters.d.ts +18 -0
  99. package/build/ts/kcmd/semantic/parameters.js +152 -0
  100. package/build/ts/kcmd/semantic/pull_kc.d.ts +14 -0
  101. package/build/ts/kcmd/semantic/pull_kc.js +346 -0
  102. package/build/ts/kcmd/semantic/resolve_inheritance.d.ts +54 -0
  103. package/build/ts/kcmd/semantic/resolve_inheritance.js +330 -0
  104. package/build/ts/kcmd/semantic/resolve_profiles.d.ts +250 -0
  105. package/build/ts/kcmd/semantic/resolve_profiles.js +1822 -0
  106. package/build/ts/kcmd/semantic/runtime/agent_tools.d.ts +93 -0
  107. package/build/ts/kcmd/semantic/runtime/agent_tools.js +243 -0
  108. package/build/ts/kcmd/semantic/runtime/dialect.d.ts +13 -0
  109. package/build/ts/kcmd/semantic/runtime/dialect.js +39 -0
  110. package/build/ts/kcmd/semantic/runtime/runtime.d.ts +94 -0
  111. package/build/ts/kcmd/semantic/runtime/runtime.js +318 -0
  112. package/build/ts/kcmd/semantic/runtime/store.d.ts +112 -0
  113. package/build/ts/kcmd/semantic/runtime/store.js +344 -0
  114. package/build/ts/kcmd/semantic/skills.d.ts +110 -0
  115. package/build/ts/kcmd/semantic/skills.js +697 -0
  116. package/build/ts/kcmd/semantic/source_dialect.d.ts +10 -0
  117. package/build/ts/kcmd/semantic/source_dialect.js +261 -0
  118. package/build/ts/kcmd/semantic/source_entries.d.ts +12 -0
  119. package/build/ts/kcmd/semantic/source_entries.js +282 -0
  120. package/build/ts/kcmd/semantic/spanner.d.ts +18 -0
  121. package/build/ts/kcmd/semantic/spanner.js +60 -0
  122. package/build/ts/kcmd/semantic/sql_expr_utils.d.ts +17 -0
  123. package/build/ts/kcmd/semantic/sql_expr_utils.js +221 -0
  124. package/build/ts/kcmd/semantic/sql_identifiers.d.ts +6 -0
  125. package/build/ts/kcmd/semantic/sql_identifiers.js +267 -0
  126. package/build/ts/kcmd/semantic/sql_parser.d.ts +44 -0
  127. package/build/ts/kcmd/semantic/sql_parser.js +378 -0
  128. package/build/ts/kcmd/semantic/transpile.d.ts +74 -0
  129. package/build/ts/kcmd/semantic/transpile.js +563 -0
  130. package/build/ts/kcmd/semantic/validate.d.ts +35 -0
  131. package/build/ts/kcmd/semantic/validate.js +1899 -0
  132. package/build/ts/kcmd/semantic/yaml_options.d.ts +6 -0
  133. package/build/ts/kcmd/semantic/yaml_options.js +58 -0
  134. package/build/ts/kcmd/semantic/yaml_update.d.ts +26 -0
  135. package/build/ts/kcmd/semantic/yaml_update.js +782 -0
  136. package/build/ts/kcmd/snapshot.d.ts +33 -0
  137. package/build/ts/kcmd/snapshot.js +379 -0
  138. package/build/ts/kcmd/source.d.ts +31 -0
  139. package/build/ts/kcmd/source.js +119 -0
  140. package/build/ts/kcmd/sources/bq-dataset.d.ts +17 -0
  141. package/build/ts/kcmd/sources/bq-dataset.js +131 -0
  142. package/build/ts/kcmd/sources/entrygroup.d.ts +21 -0
  143. package/build/ts/kcmd/sources/entrygroup.js +83 -0
  144. package/build/ts/kcmd/sources/kb.d.ts +21 -0
  145. package/build/ts/kcmd/sources/kb.js +82 -0
  146. package/build/ts/kcmd/sources/semantic-model.d.ts +18 -0
  147. package/build/ts/kcmd/sources/semantic-model.js +48 -0
  148. package/build/ts/kcmd/sync.d.ts +35 -0
  149. package/build/ts/kcmd/sync.js +697 -0
  150. package/package.json +62 -4
@@ -0,0 +1,12 @@
1
+ import * as api from './api';
2
+ import * as context from './context';
3
+ export interface Instance {
4
+ name?: string;
5
+ instanceType?: string;
6
+ state?: string;
7
+ [key: string]: any;
8
+ }
9
+ export declare class AlloyDbClient extends api.ApiClient {
10
+ constructor(ctx: context.ApiContext);
11
+ listInstances(project: string, location: string, cluster: string): Promise<api.ApiResult<Instance[]>>;
12
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ // API client for AlloyDB, covering the one call the semantic runtime needs:
3
+ // listing a cluster's instances, to find the primary instance a connection to
4
+ // one of the cluster's databases goes through.
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.AlloyDbClient = void 0;
40
+ const api = __importStar(require("./api"));
41
+ class AlloyDbClient extends api.ApiClient {
42
+ constructor(ctx) {
43
+ super('https://alloydb.googleapis.com', 'v1', ctx);
44
+ }
45
+ // Lists every instance in a cluster. Follows nextPageToken until exhausted
46
+ // and returns the flat list. A non-200 on any page aborts and is returned
47
+ // as-is. Throws when the server repeats a page token, which would otherwise
48
+ // never end.
49
+ async listInstances(project, location, cluster) {
50
+ const parent = `projects/${project}/locations/${location}/clusters/${cluster}/instances`;
51
+ const instances = [];
52
+ let pageToken = undefined;
53
+ const seen = new Set();
54
+ do {
55
+ const res = await this._get(parent, { pageToken });
56
+ if (res.status != 200) {
57
+ return { status: res.status, message: res.message, body: res.body };
58
+ }
59
+ instances.push(...(res.result?.instances ?? []));
60
+ pageToken = res.result?.nextPageToken;
61
+ if (pageToken && seen.has(pageToken)) {
62
+ throw new Error(`the AlloyDB API returned page token '${pageToken}' twice`);
63
+ }
64
+ if (pageToken)
65
+ seen.add(pageToken);
66
+ } while (pageToken);
67
+ return { status: 200, result: instances };
68
+ }
69
+ }
70
+ exports.AlloyDbClient = AlloyDbClient;
@@ -0,0 +1,29 @@
1
+ import * as context from './context';
2
+ export interface ApiResult<T> {
3
+ status: number;
4
+ result?: T;
5
+ message?: string;
6
+ body?: string;
7
+ }
8
+ export interface ApiClientOptions {
9
+ retryDelayMs?: number;
10
+ }
11
+ export interface RequestOptions {
12
+ retry?: boolean;
13
+ }
14
+ export declare function errorMessage(body: string): string;
15
+ export declare function isTransientStatus(status: number): boolean;
16
+ export declare class ApiClient {
17
+ private readonly _endpoint;
18
+ private readonly _pathPrefix;
19
+ private readonly _context;
20
+ private readonly _retryDelayMs?;
21
+ constructor(endpoint: string, pathPrefix: string, context: context.ApiContext, options?: ApiClientOptions);
22
+ get context(): context.ApiContext;
23
+ _get<T>(resourceName: string, queryParams?: Record<string, any>, options?: RequestOptions): Promise<ApiResult<T>>;
24
+ _post<T>(resourceName: string, body: any, queryParams?: Record<string, any>): Promise<ApiResult<T>>;
25
+ _patch<T>(resourceName: string, body: any, queryParams?: Record<string, any>): Promise<ApiResult<T>>;
26
+ _delete<T>(resourceName: string, queryParams?: Record<string, any>): Promise<ApiResult<T>>;
27
+ private _requestRetry;
28
+ private _requestCore;
29
+ }
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ // API Client base class
3
+ //
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.ApiClient = void 0;
6
+ exports.errorMessage = errorMessage;
7
+ exports.isTransientStatus = isTransientStatus;
8
+ const TRANSIENT_TRIES = 4;
9
+ const TRANSIENT_DELAY_CAP_MS = 5000;
10
+ const MAX_MESSAGE_LENGTH = 2000;
11
+ // The message in a failed response's body. For a Google API error it is the
12
+ // LocalizedMessage detail, which Spanner leaves unescaped, or else
13
+ // `error.message`. Each BadRequest field violation that the message does not
14
+ // state is appended, with its line breaks replaced by semicolons. Any other
15
+ // body comes back trimmed and cut to 2,000 characters. An HTML page comes back
16
+ // as its text.
17
+ function errorMessage(body) {
18
+ const text = body.trim();
19
+ try {
20
+ const error = JSON.parse(text)?.error;
21
+ const details = Array.isArray(error?.details) ? error.details : [];
22
+ const localized = details.find((d) => d?.['@type']?.endsWith('LocalizedMessage') && isText(d.message));
23
+ const message = localized?.message ?? error?.message;
24
+ if (isText(message)) {
25
+ // Spanner states what is wrong with a name, such as an uppercase
26
+ // database ID, only in a field violation.
27
+ const violations = details
28
+ .filter((d) => d?.['@type']?.endsWith('BadRequest'))
29
+ .flatMap((d) => Array.isArray(d.fieldViolations) ? d.fieldViolations : [])
30
+ .map((v) => v?.description)
31
+ .filter((v) => isText(v) && !message.includes(v.trim()))
32
+ .map((v) => v.trim().replace(/\s*\n\s*/g, '; '));
33
+ return [message.trim(), ...violations].join(' ');
34
+ }
35
+ }
36
+ catch {
37
+ // Not JSON, such as a proxy's HTML error page.
38
+ }
39
+ const plain = text.startsWith('<') ?
40
+ text.replace(/<(style|script)\b[\s\S]*?<\/\1>/gi, ' ')
41
+ .replace(/<[^>]*>/g, ' ')
42
+ .replace(/\s+/g, ' ')
43
+ .trim() :
44
+ text;
45
+ return plain.length > MAX_MESSAGE_LENGTH ?
46
+ `${plain.slice(0, MAX_MESSAGE_LENGTH)}...` : plain;
47
+ }
48
+ function isText(value) {
49
+ return typeof value === 'string' && value.trim() !== '';
50
+ }
51
+ function isTransientStatus(status) {
52
+ return status >= 500 || status === 429;
53
+ }
54
+ function transientDelayMs(configured) {
55
+ if (configured !== undefined && Number.isFinite(configured) && configured >= 0) {
56
+ return configured;
57
+ }
58
+ const raw = process.env.GCP_RETRY_DELAY_MS;
59
+ if (raw !== undefined && raw.trim() !== '') {
60
+ const parsed = Number(raw);
61
+ if (Number.isFinite(parsed) && parsed >= 0)
62
+ return parsed;
63
+ }
64
+ return 500;
65
+ }
66
+ function jitteredDelay(delayMs) {
67
+ return delayMs > 0 ? Math.round(delayMs * (0.5 + Math.random() * 0.5)) : 0;
68
+ }
69
+ function sleep(ms) {
70
+ return new Promise(resolve => setTimeout(resolve, ms));
71
+ }
72
+ class ApiClient {
73
+ _endpoint;
74
+ _pathPrefix;
75
+ _context;
76
+ _retryDelayMs;
77
+ constructor(endpoint, pathPrefix, context, options = {}) {
78
+ this._endpoint = endpoint;
79
+ this._pathPrefix = pathPrefix;
80
+ this._context = context;
81
+ this._retryDelayMs = options.retryDelayMs;
82
+ }
83
+ get context() {
84
+ return this._context;
85
+ }
86
+ // Only reads retry: a write that 5xxs may still have landed on the server.
87
+ async _get(resourceName, queryParams, options) {
88
+ const url = `${this._endpoint}/${this._pathPrefix}/${resourceName}`;
89
+ return this._requestRetry('GET', url, queryParams, undefined, options?.retry !== false);
90
+ }
91
+ async _post(resourceName, body, queryParams) {
92
+ const url = `${this._endpoint}/${this._pathPrefix}/${resourceName}`;
93
+ return this._requestRetry('POST', url, queryParams, body);
94
+ }
95
+ async _patch(resourceName, body, queryParams) {
96
+ const url = `${this._endpoint}/${this._pathPrefix}/${resourceName}`;
97
+ return this._requestRetry('PATCH', url, queryParams, body);
98
+ }
99
+ async _delete(resourceName, queryParams) {
100
+ const url = `${this._endpoint}/${this._pathPrefix}/${resourceName}`;
101
+ return this._requestRetry('DELETE', url, queryParams);
102
+ }
103
+ async _requestRetry(method, url, queryParams, body, retryTransient = false) {
104
+ if (queryParams) {
105
+ const params = new URLSearchParams();
106
+ for (const [key, value] of Object.entries(queryParams)) {
107
+ if (value !== undefined) {
108
+ if (Array.isArray(value)) {
109
+ value.forEach(v => params.append(key, String(v)));
110
+ }
111
+ else {
112
+ params.append(key, String(value));
113
+ }
114
+ }
115
+ }
116
+ const queryString = params.toString();
117
+ if (queryString) {
118
+ url += `?${queryString}`;
119
+ }
120
+ }
121
+ const tries = retryTransient ? TRANSIENT_TRIES : 1;
122
+ let delayMs = transientDelayMs(this._retryDelayMs);
123
+ let response;
124
+ for (let attempt = 0; attempt < tries; attempt++) {
125
+ if (attempt > 0) {
126
+ await sleep(jitteredDelay(delayMs));
127
+ delayMs = Math.min(delayMs * 2, TRANSIENT_DELAY_CAP_MS);
128
+ }
129
+ this._context.log(`${method} ${url}${body ? '\n' : ''}`, body);
130
+ response = await this._requestCore(url, { method, body });
131
+ if (response.status === 401) {
132
+ this.context.refresh();
133
+ response = await this._requestCore(url, { method, body });
134
+ }
135
+ if (!isTransientStatus(response.status))
136
+ break;
137
+ }
138
+ const result = { status: response.status };
139
+ if (!response.ok) {
140
+ result.body = await response.text();
141
+ result.message = errorMessage(result.body);
142
+ }
143
+ else {
144
+ result.result = await response.json();
145
+ }
146
+ this._context.log(`${response.status}:${result.body ?? ''}\n`, result.result);
147
+ return result;
148
+ }
149
+ async _requestCore(url, options) {
150
+ const headers = {
151
+ ...options.headers,
152
+ 'Authorization': `Bearer ${this._context.token}`,
153
+ 'Content-Type': 'application/json'
154
+ };
155
+ return fetch(url, {
156
+ ...options,
157
+ headers,
158
+ body: options.body ? JSON.stringify(options.body) : undefined,
159
+ });
160
+ }
161
+ }
162
+ exports.ApiClient = ApiClient;
@@ -0,0 +1,16 @@
1
+ import * as api from './api';
2
+ import * as context from './context';
3
+ export interface Catalog {
4
+ name?: string;
5
+ 'catalog-type'?: string;
6
+ replicas?: Array<{
7
+ region?: string;
8
+ state?: string;
9
+ }>;
10
+ 'storage-regions'?: string[];
11
+ [key: string]: any;
12
+ }
13
+ export declare class BigLakeClient extends api.ApiClient {
14
+ constructor(ctx: context.ApiContext);
15
+ getCatalog(project: string, catalog: string): Promise<api.ApiResult<Catalog>>;
16
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ // API client for BigLake, covering the one call the source check needs:
3
+ // reading an Iceberg REST catalog, whose region decides where Knowledge
4
+ // Catalog keeps the entries of its tables.
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.BigLakeClient = void 0;
40
+ const api = __importStar(require("./api"));
41
+ class BigLakeClient extends api.ApiClient {
42
+ constructor(ctx) {
43
+ super('https://biglake.googleapis.com', 'iceberg/v1/restcatalog/extensions', ctx);
44
+ }
45
+ // Fetches a catalog. A catalog that does not exist answers 404.
46
+ async getCatalog(project, catalog) {
47
+ return await this._get(`projects/${project}/catalogs/${catalog}`);
48
+ }
49
+ }
50
+ exports.BigLakeClient = BigLakeClient;
@@ -0,0 +1,57 @@
1
+ import * as api from './api';
2
+ import * as context from './context';
3
+ export interface Dataset {
4
+ id: string;
5
+ datasetReference: {
6
+ projectId: string;
7
+ datasetId: string;
8
+ };
9
+ location: string;
10
+ [key: string]: any;
11
+ }
12
+ export interface Table {
13
+ id: string;
14
+ tableReference: {
15
+ projectId: string;
16
+ datasetId: string;
17
+ tableId: string;
18
+ };
19
+ location?: string;
20
+ [key: string]: any;
21
+ }
22
+ export interface QueryResponse {
23
+ jobComplete?: boolean;
24
+ jobReference?: {
25
+ projectId?: string;
26
+ jobId?: string;
27
+ location?: string;
28
+ };
29
+ errors?: {
30
+ reason?: string;
31
+ message: string;
32
+ }[];
33
+ [key: string]: any;
34
+ }
35
+ export interface Job {
36
+ status?: {
37
+ state?: string;
38
+ errorResult?: {
39
+ reason?: string;
40
+ message: string;
41
+ };
42
+ errors?: {
43
+ reason?: string;
44
+ message: string;
45
+ }[];
46
+ };
47
+ [key: string]: any;
48
+ }
49
+ export declare class BigQueryClient extends api.ApiClient {
50
+ constructor(ctx: context.ApiContext);
51
+ getDataset(project: string, dataset: string): Promise<api.ApiResult<Dataset>>;
52
+ getTable(project: string, dataset: string, table: string): Promise<api.ApiResult<Table>>;
53
+ listTables(project: string, dataset: string): AsyncGenerator<Table>;
54
+ query(project: string, sql: string, location?: string, dryRun?: boolean, namedParameterTypes?: Record<string, string>): Promise<api.ApiResult<QueryResponse>>;
55
+ getQueryResults(project: string, jobId: string, location?: string): Promise<api.ApiResult<QueryResponse>>;
56
+ getJob(project: string, jobId: string, location?: string): Promise<api.ApiResult<Job>>;
57
+ }
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ // API client for BigQuery
3
+ //
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || (function () {
21
+ var ownKeys = function(o) {
22
+ ownKeys = Object.getOwnPropertyNames || function (o) {
23
+ var ar = [];
24
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
25
+ return ar;
26
+ };
27
+ return ownKeys(o);
28
+ };
29
+ return function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ })();
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.BigQueryClient = void 0;
39
+ const api = __importStar(require("./api"));
40
+ class BigQueryClient extends api.ApiClient {
41
+ constructor(ctx) {
42
+ super('https://bigquery.googleapis.com', 'bigquery/v2', ctx);
43
+ }
44
+ async getDataset(project, dataset) {
45
+ const name = `projects/${project}/datasets/${dataset}`;
46
+ const params = { datasetView: 'METADATA' };
47
+ return await this._get(name, params);
48
+ }
49
+ // Fetches a single table's metadata, with its location. A table or dataset
50
+ // that does not exist answers 404 (live, 2026-11-03). The BASIC view leaves
51
+ // out the storage statistics. (`selectedFields` picks schema columns, not
52
+ // fields: `selectedFields=tableReference` answers 400.)
53
+ async getTable(project, dataset, table) {
54
+ const name = `projects/${project}/datasets/${dataset}/tables/${table}`;
55
+ const params = { view: 'BASIC' };
56
+ return await this._get(name, params);
57
+ }
58
+ async *listTables(project, dataset) {
59
+ const name = `projects/${project}/datasets/${dataset}/tables`;
60
+ let pageToken = undefined;
61
+ do {
62
+ const params = { maxResults: 500 };
63
+ if (pageToken) {
64
+ params.pageToken = pageToken;
65
+ }
66
+ const res = await this._get(name, params);
67
+ if (res.status !== 200) {
68
+ throw new Error(`Failed to list tables: ${res.message || res.status}`);
69
+ }
70
+ const tables = res.result?.tables || [];
71
+ for (const table of tables) {
72
+ yield table;
73
+ }
74
+ pageToken = res.result?.nextPageToken;
75
+ } while (pageToken);
76
+ }
77
+ // Executes a SQL statement (including DDL) synchronously via jobs.query.
78
+ // When `location` is set it pins the job's processing location so it agrees
79
+ // with getQueryResults/getJob; otherwise BigQuery infers it from the
80
+ // referenced tables. With `dryRun` the statement is validated -- name
81
+ // resolution, table existence and access -- but not executed, so it serves as
82
+ // a cheap pre-flight probe over any reference form BigQuery can resolve.
83
+ //
84
+ // `namedParameterTypes` maps a `@name` reference to its BigQuery type code
85
+ // (`INT64`, `STRING`, ...) and is only useful with `dryRun`: a dry run
86
+ // resolves an unbound `@name` on its own, so the types are not required to
87
+ // make one pass -- supplying them is what makes BigQuery type-check each
88
+ // parameter against the column it is used with. The values sent are empty
89
+ // (`parameterValue: {}`, an unset value), because a dry run never evaluates
90
+ // them.
91
+ async query(project, sql, location, dryRun, namedParameterTypes) {
92
+ const name = `projects/${project}/queries`;
93
+ const body = { query: sql, useLegacySql: false };
94
+ if (location) {
95
+ body.location = location;
96
+ }
97
+ if (dryRun) {
98
+ body.dryRun = true;
99
+ }
100
+ const parameterNames = Object.keys(namedParameterTypes ?? {});
101
+ if (parameterNames.length) {
102
+ body.parameterMode = 'NAMED';
103
+ body.queryParameters = parameterNames.map(name => ({
104
+ name,
105
+ parameterType: { type: namedParameterTypes[name] },
106
+ parameterValue: {},
107
+ }));
108
+ }
109
+ return await this._post(name, body);
110
+ }
111
+ // Fetches the status/results of a running query job. Used to poll until the
112
+ // job reports `jobComplete`, since jobs.query can return before a slow DDL
113
+ // statement has finished executing.
114
+ async getQueryResults(project, jobId, location) {
115
+ const name = `projects/${project}/queries/${jobId}`;
116
+ const params = { maxResults: 0, timeoutMs: 10000 };
117
+ if (location) {
118
+ params.location = location;
119
+ }
120
+ return await this._get(name, params);
121
+ }
122
+ // Fetches a job's full status. status.errorResult is the definitive fatal
123
+ // error for a completed job; the query response's errors[] also includes
124
+ // non-fatal warnings, so it cannot decide success on its own.
125
+ async getJob(project, jobId, location) {
126
+ const name = `projects/${project}/jobs/${jobId}`;
127
+ const params = {};
128
+ if (location) {
129
+ params.location = location;
130
+ }
131
+ return await this._get(name, params);
132
+ }
133
+ }
134
+ exports.BigQueryClient = BigQueryClient;
@@ -0,0 +1,10 @@
1
+ export declare class ApiContext {
2
+ readonly project: string;
3
+ readonly location: string;
4
+ private _token;
5
+ constructor(project: string, location: string, token: string);
6
+ get token(): string;
7
+ log(message: string, data?: any): void;
8
+ static default(): ApiContext;
9
+ refresh(): void;
10
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ // Context variables for GCP API requests
3
+ //
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || (function () {
21
+ var ownKeys = function(o) {
22
+ ownKeys = Object.getOwnPropertyNames || function (o) {
23
+ var ar = [];
24
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
25
+ return ar;
26
+ };
27
+ return ownKeys(o);
28
+ };
29
+ return function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ })();
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.ApiContext = void 0;
39
+ const cp = __importStar(require("child_process"));
40
+ const GCLOUD_PROJECT_CMD = 'gcloud -q config get-value project';
41
+ const GCLOUD_LOCATION_CMD = 'gcloud -q config get-value compute/region';
42
+ const GCLOUD_TOKEN_CMD = 'gcloud -q auth application-default print-access-token';
43
+ class ApiContext {
44
+ project;
45
+ location;
46
+ _token;
47
+ constructor(project, location, token) {
48
+ this.project = project;
49
+ this.location = location;
50
+ this._token = token;
51
+ }
52
+ get token() {
53
+ return this._token;
54
+ }
55
+ log(message, data) {
56
+ if (process.env.GCP_LOG) {
57
+ console.log(`[GCP_LOG] ${message}`, data ? JSON.stringify(data) : '');
58
+ }
59
+ }
60
+ static default() {
61
+ // Creates an ApiContext instance using gcloud configuration
62
+ const project = cp.execSync(GCLOUD_PROJECT_CMD).toString().trim();
63
+ const location = cp.execSync(GCLOUD_LOCATION_CMD).toString().trim();
64
+ const token = cp.execSync(GCLOUD_TOKEN_CMD).toString().trim();
65
+ if (!project || !location || !token) {
66
+ throw new Error('Unable to retrieve project, location, or token. Ensure gcloud is configured.');
67
+ }
68
+ return new ApiContext(project, location, token);
69
+ }
70
+ refresh() {
71
+ this._token = cp.execSync(GCLOUD_TOKEN_CMD).toString().trim();
72
+ }
73
+ }
74
+ exports.ApiContext = ApiContext;
@@ -0,0 +1,13 @@
1
+ import * as api from './api';
2
+ import * as context from './context';
3
+ export interface Project {
4
+ name: string;
5
+ projectId: string;
6
+ [key: string]: any;
7
+ }
8
+ export declare class ResourceManagerClient extends api.ApiClient {
9
+ constructor(ctx: context.ApiContext);
10
+ getProject(project: string): Promise<api.ApiResult<Project>>;
11
+ }
12
+ export declare function projectNumber(project: string, ctx: context.ApiContext): Promise<string | undefined>;
13
+ export declare function fixProject(resource: string, ctx: context.ApiContext): Promise<string>;