@activepieces/piece-google-bigquery 0.0.1
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/package.json +18 -0
- package/src/index.d.ts +8 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +60 -0
- package/src/index.js.map +1 -0
- package/src/lib/actions/create-row.d.ts +22 -0
- package/src/lib/actions/create-row.d.ts.map +1 -0
- package/src/lib/actions/create-row.js +75 -0
- package/src/lib/actions/create-row.js.map +1 -0
- package/src/lib/actions/create-rows.d.ts +21 -0
- package/src/lib/actions/create-rows.d.ts.map +1 -0
- package/src/lib/actions/create-rows.js +84 -0
- package/src/lib/actions/create-rows.js.map +1 -0
- package/src/lib/actions/delete-rows.d.ts +20 -0
- package/src/lib/actions/delete-rows.d.ts.map +1 -0
- package/src/lib/actions/delete-rows.js +43 -0
- package/src/lib/actions/delete-rows.js.map +1 -0
- package/src/lib/actions/find-one-row.d.ts +21 -0
- package/src/lib/actions/find-one-row.d.ts.map +1 -0
- package/src/lib/actions/find-one-row.js +60 -0
- package/src/lib/actions/find-one-row.js.map +1 -0
- package/src/lib/actions/find-or-create-row.d.ts +21 -0
- package/src/lib/actions/find-or-create-row.d.ts.map +1 -0
- package/src/lib/actions/find-or-create-row.js +79 -0
- package/src/lib/actions/find-or-create-row.js.map +1 -0
- package/src/lib/actions/get-rows-for-job.d.ts +13 -0
- package/src/lib/actions/get-rows-for-job.d.ts.map +1 -0
- package/src/lib/actions/get-rows-for-job.js +76 -0
- package/src/lib/actions/get-rows-for-job.js.map +1 -0
- package/src/lib/actions/import-data.d.ts +21 -0
- package/src/lib/actions/import-data.d.ts.map +1 -0
- package/src/lib/actions/import-data.js +111 -0
- package/src/lib/actions/import-data.js.map +1 -0
- package/src/lib/actions/run-query.d.ts +14 -0
- package/src/lib/actions/run-query.d.ts.map +1 -0
- package/src/lib/actions/run-query.js +86 -0
- package/src/lib/actions/run-query.js.map +1 -0
- package/src/lib/actions/update-rows.d.ts +21 -0
- package/src/lib/actions/update-rows.d.ts.map +1 -0
- package/src/lib/actions/update-rows.js +48 -0
- package/src/lib/actions/update-rows.js.map +1 -0
- package/src/lib/common/index.d.ts +73 -0
- package/src/lib/common/index.d.ts.map +1 -0
- package/src/lib/common/index.js +343 -0
- package/src/lib/common/index.js.map +1 -0
- package/src/lib/triggers/new-job-completed.d.ts +39 -0
- package/src/lib/triggers/new-job-completed.d.ts.map +1 -0
- package/src/lib/triggers/new-job-completed.js +118 -0
- package/src/lib/triggers/new-job-completed.js.map +1 -0
- package/src/lib/triggers/new-row.d.ts +75 -0
- package/src/lib/triggers/new-row.d.ts.map +1 -0
- package/src/lib/triggers/new-row.js +109 -0
- package/src/lib/triggers/new-row.js.map +1 -0
- package/src/lib/triggers/query-job-completed.d.ts +39 -0
- package/src/lib/triggers/query-job-completed.d.ts.map +1 -0
- package/src/lib/triggers/query-job-completed.js +127 -0
- package/src/lib/triggers/query-job-completed.js.map +1 -0
- package/src/lib/triggers/updated-row.d.ts +79 -0
- package/src/lib/triggers/updated-row.d.ts.map +1 -0
- package/src/lib/triggers/updated-row.js +118 -0
- package/src/lib/triggers/updated-row.js.map +1 -0
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@activepieces/piece-google-bigquery",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./src/index.js",
|
|
5
|
+
"types": "./src/index.d.ts",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@activepieces/pieces-common": "0.12.0",
|
|
8
|
+
"@activepieces/pieces-framework": "0.26.0",
|
|
9
|
+
"@activepieces/shared": "0.50.0",
|
|
10
|
+
"googleapis": "129.0.0",
|
|
11
|
+
"googleapis-common": "7.2.0",
|
|
12
|
+
"tslib": "2.6.2"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.lib.json && cp package.json dist/",
|
|
16
|
+
"lint": "eslint 'src/**/*.ts'"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { bigQueryAuth, BigQueryAuthValue } from './lib/common';
|
|
2
|
+
export { bigQueryAuth };
|
|
3
|
+
export type { BigQueryAuthValue };
|
|
4
|
+
export declare const googleBigQuery: import("@activepieces/pieces-framework").Piece<(import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
5
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
6
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
7
|
+
}>)[]>;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EACZ,iBAAiB,EAGlB,MAAM,cAAc,CAAC;AAmBtB,OAAO,EAAE,YAAY,EAAE,CAAC;AACxB,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAElC,eAAO,MAAM,cAAc;;;MAmCzB,CAAC"}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.googleBigQuery = exports.bigQueryAuth = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
6
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
7
|
+
const shared_1 = require("@activepieces/shared");
|
|
8
|
+
const common_1 = require("./lib/common");
|
|
9
|
+
Object.defineProperty(exports, "bigQueryAuth", { enumerable: true, get: function () { return common_1.bigQueryAuth; } });
|
|
10
|
+
// Actions
|
|
11
|
+
const run_query_1 = require("./lib/actions/run-query");
|
|
12
|
+
const create_row_1 = require("./lib/actions/create-row");
|
|
13
|
+
const create_rows_1 = require("./lib/actions/create-rows");
|
|
14
|
+
const delete_rows_1 = require("./lib/actions/delete-rows");
|
|
15
|
+
const update_rows_1 = require("./lib/actions/update-rows");
|
|
16
|
+
const find_one_row_1 = require("./lib/actions/find-one-row");
|
|
17
|
+
const find_or_create_row_1 = require("./lib/actions/find-or-create-row");
|
|
18
|
+
const get_rows_for_job_1 = require("./lib/actions/get-rows-for-job");
|
|
19
|
+
const import_data_1 = require("./lib/actions/import-data");
|
|
20
|
+
// Triggers
|
|
21
|
+
const new_row_1 = require("./lib/triggers/new-row");
|
|
22
|
+
const updated_row_1 = require("./lib/triggers/updated-row");
|
|
23
|
+
const query_job_completed_1 = require("./lib/triggers/query-job-completed");
|
|
24
|
+
const new_job_completed_1 = require("./lib/triggers/new-job-completed");
|
|
25
|
+
exports.googleBigQuery = (0, pieces_framework_1.createPiece)({
|
|
26
|
+
displayName: 'Google BigQuery',
|
|
27
|
+
description: 'Query, analyze, and stream data into Google BigQuery — the fully managed, serverless data warehouse',
|
|
28
|
+
minimumSupportedRelease: '0.36.1',
|
|
29
|
+
logoUrl: 'https://cdn.activepieces.com/pieces/google-bigquery.png',
|
|
30
|
+
categories: [shared_1.PieceCategory.BUSINESS_INTELLIGENCE],
|
|
31
|
+
authors: ['AhmadTash'],
|
|
32
|
+
auth: common_1.bigQueryAuth,
|
|
33
|
+
actions: [
|
|
34
|
+
run_query_1.runQueryAction,
|
|
35
|
+
create_row_1.createRowAction,
|
|
36
|
+
create_rows_1.createRowsAction,
|
|
37
|
+
delete_rows_1.deleteRowsAction,
|
|
38
|
+
update_rows_1.updateRowsAction,
|
|
39
|
+
find_one_row_1.findOneRowAction,
|
|
40
|
+
find_or_create_row_1.findOrCreateRowAction,
|
|
41
|
+
get_rows_for_job_1.getRowsForJobAction,
|
|
42
|
+
import_data_1.importDataAction,
|
|
43
|
+
(0, pieces_common_1.createCustomApiCallAction)({
|
|
44
|
+
baseUrl: () => common_1.BASE_URL,
|
|
45
|
+
auth: common_1.bigQueryAuth,
|
|
46
|
+
authMapping: (auth) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
return ({
|
|
48
|
+
Authorization: `Bearer ${yield (0, common_1.getAccessToken)(auth)}`,
|
|
49
|
+
});
|
|
50
|
+
}),
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
triggers: [
|
|
54
|
+
new_row_1.newRowTrigger,
|
|
55
|
+
updated_row_1.updatedRowTrigger,
|
|
56
|
+
query_job_completed_1.queryJobCompletedTrigger,
|
|
57
|
+
new_job_completed_1.newJobCompletedTrigger,
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,+DAAwE;AACxE,qEAA6D;AAC7D,iDAAqD;AACrD,yCAKsB;AAmBb,6FAvBP,qBAAY,OAuBO;AAjBrB,UAAU;AACV,uDAAyD;AACzD,yDAA2D;AAC3D,2DAA6D;AAC7D,2DAA6D;AAC7D,2DAA6D;AAC7D,6DAA8D;AAC9D,yEAAyE;AACzE,qEAAqE;AACrE,2DAA6D;AAE7D,WAAW;AACX,oDAAuD;AACvD,4DAA+D;AAC/D,4EAA8E;AAC9E,wEAA0E;AAK7D,QAAA,cAAc,GAAG,IAAA,8BAAW,EAAC;IACxC,WAAW,EAAE,iBAAiB;IAC9B,WAAW,EACT,qGAAqG;IACvG,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EAAE,yDAAyD;IAClE,UAAU,EAAE,CAAC,sBAAa,CAAC,qBAAqB,CAAC;IACjD,OAAO,EAAE,CAAC,WAAW,CAAC;IACtB,IAAI,EAAE,qBAAY;IAClB,OAAO,EAAE;QACP,0BAAc;QACd,4BAAe;QACf,8BAAgB;QAChB,8BAAgB;QAChB,8BAAgB;QAChB,+BAAgB;QAChB,0CAAqB;QACrB,sCAAmB;QACnB,8BAAgB;QAChB,IAAA,yCAAyB,EAAC;YACxB,OAAO,EAAE,GAAG,EAAE,CAAC,iBAAQ;YACvB,IAAI,EAAE,qBAAY;YAClB,WAAW,EAAE,CAAO,IAAI,EAAE,EAAE;gBAAC,OAAA,CAAC;oBAC5B,aAAa,EAAE,UAAU,MAAM,IAAA,uBAAc,EAC3C,IAAyB,CAC1B,EAAE;iBACJ,CAAC,CAAA;cAAA;SACH,CAAC;KACH;IACD,QAAQ,EAAE;QACR,uBAAa;QACb,+BAAiB;QACjB,8CAAwB;QACxB,0CAAsB;KACvB;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const createRowAction: import("@activepieces/pieces-framework").IAction<(import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
3
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
4
|
+
}>)[], {
|
|
5
|
+
project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
6
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
7
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
}>)[]>;
|
|
9
|
+
dataset_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
10
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
11
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
12
|
+
}>)[]>;
|
|
13
|
+
table_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
14
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
15
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
16
|
+
}>)[]>;
|
|
17
|
+
values: import("@activepieces/pieces-framework").DynamicProperties<true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
18
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
19
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
20
|
+
}>)[]>;
|
|
21
|
+
}>;
|
|
22
|
+
//# sourceMappingURL=create-row.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-row.d.ts","sourceRoot":"","sources":["../../../../src/lib/actions/create-row.ts"],"names":[],"mappings":"AAgCA,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;EA+E1B,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRowAction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
function fieldToProperty(field) {
|
|
9
|
+
const description = `Type: ${field.type}${field.mode ? ` · Mode: ${field.mode}` : ''}`;
|
|
10
|
+
return pieces_framework_1.Property.ShortText({
|
|
11
|
+
displayName: field.name,
|
|
12
|
+
description,
|
|
13
|
+
required: field.mode === 'REQUIRED',
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
exports.createRowAction = (0, pieces_framework_1.createAction)({
|
|
17
|
+
auth: common_1.bigQueryAuth,
|
|
18
|
+
name: 'create_row',
|
|
19
|
+
displayName: 'Create Row',
|
|
20
|
+
description: 'Creates a single new row in a BigQuery table. Column fields are loaded from the table schema.',
|
|
21
|
+
props: {
|
|
22
|
+
project_id: common_1.projectIdProp,
|
|
23
|
+
dataset_id: common_1.datasetIdProp,
|
|
24
|
+
table_id: common_1.tableIdProp,
|
|
25
|
+
values: pieces_framework_1.Property.DynamicProperties({
|
|
26
|
+
displayName: 'Row Values',
|
|
27
|
+
description: 'Enter a value for each column. Fields are loaded from the table schema.',
|
|
28
|
+
required: true,
|
|
29
|
+
auth: common_1.bigQueryAuth,
|
|
30
|
+
refreshers: ['project_id', 'dataset_id', 'table_id'],
|
|
31
|
+
props: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, project_id, dataset_id, table_id }) {
|
|
32
|
+
if (!auth || !project_id || !dataset_id || !table_id)
|
|
33
|
+
return {};
|
|
34
|
+
try {
|
|
35
|
+
const token = yield (0, common_1.getAccessToken)(auth);
|
|
36
|
+
const fields = yield (0, common_1.getTableSchema)(token, project_id, dataset_id, table_id);
|
|
37
|
+
// Only expose simple (non-RECORD) fields as individual inputs
|
|
38
|
+
return Object.fromEntries(fields
|
|
39
|
+
.filter((f) => f.type !== 'RECORD')
|
|
40
|
+
.map((f) => [f.name, fieldToProperty(f)]));
|
|
41
|
+
}
|
|
42
|
+
catch (_b) {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
}),
|
|
46
|
+
}),
|
|
47
|
+
},
|
|
48
|
+
run(context) {
|
|
49
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
var _a, _b, _c, _d, _e;
|
|
51
|
+
const { project_id, dataset_id, table_id, values } = context.propsValue;
|
|
52
|
+
const token = yield (0, common_1.getAccessToken)(context.auth);
|
|
53
|
+
const rowData = values;
|
|
54
|
+
// Strip empty strings so we don't overwrite nullable columns with ''
|
|
55
|
+
const cleanRow = Object.fromEntries(Object.entries(rowData).filter(([, v]) => v !== '' && v !== null && v !== undefined));
|
|
56
|
+
const insertId = `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
57
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
58
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
59
|
+
url: `${common_1.BASE_URL}/projects/${project_id}/datasets/${dataset_id}/tables/${table_id}/insertAll`,
|
|
60
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
61
|
+
body: {
|
|
62
|
+
kind: 'bigquery#tableDataInsertAllRequest',
|
|
63
|
+
rows: [{ insertId, json: cleanRow }],
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const errors = (_a = response.body.insertErrors) !== null && _a !== void 0 ? _a : [];
|
|
67
|
+
if (errors.length > 0) {
|
|
68
|
+
const first = (_b = errors[0]) === null || _b === void 0 ? void 0 : _b.errors[0];
|
|
69
|
+
throw new Error(`Row insert failed: ${(_c = first === null || first === void 0 ? void 0 : first.message) !== null && _c !== void 0 ? _c : 'Unknown error'} (reason: ${(_d = first === null || first === void 0 ? void 0 : first.reason) !== null && _d !== void 0 ? _d : 'unknown'}, field: ${(_e = first === null || first === void 0 ? void 0 : first.location) !== null && _e !== void 0 ? _e : 'unknown'})`);
|
|
70
|
+
}
|
|
71
|
+
return Object.assign({ success: true, insert_id: insertId }, cleanRow);
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=create-row.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-row.js","sourceRoot":"","s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a,UAAU,WAAW,QAAQ,YAAY;gBAC7F,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE;gBAC7C,IAAI,EAAE;oBACJ,IAAI,EAAE,oCAAoC;oBAC1C,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;iBACrC;aACF,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,MAAA,QAAQ,CAAC,IAAI,CAAC,YAAY,mCAAI,EAAE,CAAC;YAChD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACtB,MAAM,KAAK,GAAG,MAAA,MAAM,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC,CAAC,CAAC;gBACnC,MAAM,IAAI,KAAK,CACb,sBAAsB,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,mCAAI,eAAe,aACrD,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,mCAAI,SACnB,YAAY,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,mCAAI,SAAS,GAAG,CAC5C,CAAC;YACJ,CAAC;YAED,uBACE,OAAO,EAAE,IAAI,EACb,SAAS,EAAE,QAAQ,IAChB,QAAQ,EACX;QACJ,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const createRowsAction: import("@activepieces/pieces-framework").IAction<(import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
3
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
4
|
+
}>)[], {
|
|
5
|
+
project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
6
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
7
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
}>)[]>;
|
|
9
|
+
dataset_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
10
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
11
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
12
|
+
}>)[]>;
|
|
13
|
+
table_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
14
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
15
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
16
|
+
}>)[]>;
|
|
17
|
+
rows: import("@activepieces/pieces-framework").JsonProperty<true>;
|
|
18
|
+
skip_invalid_rows: import("@activepieces/pieces-framework").CheckboxProperty<false>;
|
|
19
|
+
ignore_unknown_values: import("@activepieces/pieces-framework").CheckboxProperty<false>;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=create-rows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-rows.d.ts","sourceRoot":"","sources":["../../../../src/lib/actions/create-rows.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;EA8F3B,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRowsAction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
exports.createRowsAction = (0, pieces_framework_1.createAction)({
|
|
9
|
+
auth: common_1.bigQueryAuth,
|
|
10
|
+
name: 'create_rows',
|
|
11
|
+
displayName: 'Create Rows',
|
|
12
|
+
description: 'Creates new rows of data in a BigQuery table (accepts an array of row objects). Rows are available to query within seconds.',
|
|
13
|
+
props: {
|
|
14
|
+
project_id: common_1.projectIdProp,
|
|
15
|
+
dataset_id: common_1.datasetIdProp,
|
|
16
|
+
table_id: common_1.tableIdProp,
|
|
17
|
+
rows: pieces_framework_1.Property.Json({
|
|
18
|
+
displayName: 'Rows',
|
|
19
|
+
description: 'An array of row objects to insert. Keys must match the table column names. Example: `[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]`',
|
|
20
|
+
required: true,
|
|
21
|
+
}),
|
|
22
|
+
skip_invalid_rows: pieces_framework_1.Property.Checkbox({
|
|
23
|
+
displayName: 'Skip Invalid Rows',
|
|
24
|
+
description: 'If enabled, valid rows are inserted even when some rows in the batch are invalid. If disabled (default), the entire batch fails if any row is invalid.',
|
|
25
|
+
required: false,
|
|
26
|
+
defaultValue: false,
|
|
27
|
+
}),
|
|
28
|
+
ignore_unknown_values: pieces_framework_1.Property.Checkbox({
|
|
29
|
+
displayName: 'Ignore Unknown Fields',
|
|
30
|
+
description: 'If enabled, fields not in the table schema are silently discarded. If disabled (default), unknown fields cause the row to fail.',
|
|
31
|
+
required: false,
|
|
32
|
+
defaultValue: false,
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
run(context) {
|
|
36
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
var _a, _b, _c, _d, _e;
|
|
38
|
+
const { project_id, dataset_id, table_id, rows, skip_invalid_rows, ignore_unknown_values, } = context.propsValue;
|
|
39
|
+
if (!Array.isArray(rows) || rows.length === 0) {
|
|
40
|
+
throw new Error('Rows must be a non-empty JSON array of objects, e.g. [{"column": "value"}]');
|
|
41
|
+
}
|
|
42
|
+
const token = yield (0, common_1.getAccessToken)(context.auth);
|
|
43
|
+
const now = Date.now();
|
|
44
|
+
const bqRows = rows.map((row, index) => ({
|
|
45
|
+
insertId: `${now}-${index}-${Math.random().toString(36).slice(2, 9)}`,
|
|
46
|
+
json: row,
|
|
47
|
+
}));
|
|
48
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
49
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
50
|
+
url: `${common_1.BASE_URL}/projects/${project_id}/datasets/${dataset_id}/tables/${table_id}/insertAll`,
|
|
51
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
52
|
+
body: {
|
|
53
|
+
kind: 'bigquery#tableDataInsertAllRequest',
|
|
54
|
+
skipInvalidRows: skip_invalid_rows !== null && skip_invalid_rows !== void 0 ? skip_invalid_rows : false,
|
|
55
|
+
ignoreUnknownValues: ignore_unknown_values !== null && ignore_unknown_values !== void 0 ? ignore_unknown_values : false,
|
|
56
|
+
rows: bqRows,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const insertErrors = (_a = response.body.insertErrors) !== null && _a !== void 0 ? _a : [];
|
|
60
|
+
if (insertErrors.length > 0 && !(skip_invalid_rows !== null && skip_invalid_rows !== void 0 ? skip_invalid_rows : false)) {
|
|
61
|
+
const firstError = (_b = insertErrors[0]) === null || _b === void 0 ? void 0 : _b.errors[0];
|
|
62
|
+
throw new Error(`Insert failed on row ${(_c = insertErrors[0]) === null || _c === void 0 ? void 0 : _c.index}: ${(_d = firstError === null || firstError === void 0 ? void 0 : firstError.message) !== null && _d !== void 0 ? _d : 'Unknown error'} (reason: ${(_e = firstError === null || firstError === void 0 ? void 0 : firstError.reason) !== null && _e !== void 0 ? _e : 'unknown'})`);
|
|
63
|
+
}
|
|
64
|
+
const flatErrors = insertErrors.map((e) => {
|
|
65
|
+
var _a, _b, _c, _d, _e, _f;
|
|
66
|
+
return ({
|
|
67
|
+
row_index: e.index,
|
|
68
|
+
error_count: e.errors.length,
|
|
69
|
+
first_error_reason: (_b = (_a = e.errors[0]) === null || _a === void 0 ? void 0 : _a.reason) !== null && _b !== void 0 ? _b : null,
|
|
70
|
+
first_error_location: (_d = (_c = e.errors[0]) === null || _c === void 0 ? void 0 : _c.location) !== null && _d !== void 0 ? _d : null,
|
|
71
|
+
first_error_message: (_f = (_e = e.errors[0]) === null || _e === void 0 ? void 0 : _e.message) !== null && _f !== void 0 ? _f : null,
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
success: insertErrors.length === 0,
|
|
76
|
+
rows_attempted: rows.length,
|
|
77
|
+
rows_inserted: rows.length - insertErrors.length,
|
|
78
|
+
error_count: insertErrors.length,
|
|
79
|
+
errors: flatErrors,
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=create-rows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-rows.js","sourceRoot":"","sources":["../../../../src/lib/actions/create-rows.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,+DAAqE;AACrE,sCAQmB;AAYN,QAAA,gBAAgB,GAAG,IAAA,+BAAY,EAAC;IAC3C,IAAI,EAAE,qBAAY;IAClB,IAAI,EAAE,aAAa;IACnB,WAAW,EAAE,aAAa;IAC1B,WAAW,EACT,6HAA6H;IAC/H,KAAK,EAAE;QACL,UAAU,EAAE,sBAAa;QACzB,UAAU,EAAE,sBAAa;QACzB,QAAQ,EAAE,oBAAW;QACrB,IAAI,EAAE,2BAAQ,CAAC,IAAI,CAAC;YAClB,WAAW,EAAE,MAAM;YACnB,WAAW,EACT,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AAA,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,0CAAE,QAAQ,mCAAI,IAAI;oBACnD,mBAAmB,EAAE,MAAA,MAAA,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,0CAAE,OAAO,mCAAI,IAAI;iBAClD,CAAC,CAAA;aAAA,CAAC,CAAC;YAEJ,OAAO;gBACL,OAAO,EAAE,YAAY,CAAC,MAAM,KAAK,CAAC;gBAClC,cAAc,EAAE,IAAI,CAAC,MAAM;gBAC3B,aAAa,EAAE,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM;gBAChD,WAAW,EAAE,YAAY,CAAC,MAAM;gBAChC,MAAM,EAAE,UAAU;aACnB,CAAC;QACJ,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const deleteRowsAction: import("@activepieces/pieces-framework").IAction<(import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
3
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
4
|
+
}>)[], {
|
|
5
|
+
project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
6
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
7
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
}>)[]>;
|
|
9
|
+
dataset_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
10
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
11
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
12
|
+
}>)[]>;
|
|
13
|
+
table_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
14
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
15
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
16
|
+
}>)[]>;
|
|
17
|
+
where_clause: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
18
|
+
location: import("@activepieces/pieces-framework").ShortTextProperty<false>;
|
|
19
|
+
}>;
|
|
20
|
+
//# sourceMappingURL=delete-rows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-rows.d.ts","sourceRoot":"","sources":["../../../../src/lib/actions/delete-rows.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;EA4C3B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteRowsAction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const common_1 = require("../common");
|
|
7
|
+
exports.deleteRowsAction = (0, pieces_framework_1.createAction)({
|
|
8
|
+
auth: common_1.bigQueryAuth,
|
|
9
|
+
name: 'delete_rows',
|
|
10
|
+
displayName: 'Delete Rows',
|
|
11
|
+
description: 'Deletes one or more rows from a BigQuery table using a SQL WHERE condition.',
|
|
12
|
+
props: {
|
|
13
|
+
project_id: common_1.projectIdProp,
|
|
14
|
+
dataset_id: common_1.datasetIdProp,
|
|
15
|
+
table_id: common_1.tableIdProp,
|
|
16
|
+
where_clause: pieces_framework_1.Property.LongText({
|
|
17
|
+
displayName: 'WHERE Clause',
|
|
18
|
+
description: 'SQL condition to match the rows to delete. Do not include the WHERE keyword. Example: `status = "inactive" AND created_at < "2023-01-01"`',
|
|
19
|
+
required: true,
|
|
20
|
+
}),
|
|
21
|
+
location: pieces_framework_1.Property.ShortText({
|
|
22
|
+
displayName: 'Location',
|
|
23
|
+
description: 'Dataset location (e.g. US, EU). Leave blank to use the default.',
|
|
24
|
+
required: false,
|
|
25
|
+
}),
|
|
26
|
+
},
|
|
27
|
+
run(context) {
|
|
28
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
var _a;
|
|
30
|
+
const { project_id, dataset_id, table_id, where_clause, location } = context.propsValue;
|
|
31
|
+
const token = yield (0, common_1.getAccessToken)(context.auth);
|
|
32
|
+
const fullTable = `\`${project_id}.${dataset_id}.${table_id}\``;
|
|
33
|
+
const query = `DELETE FROM ${fullTable} WHERE ${where_clause}`;
|
|
34
|
+
const result = yield (0, common_1.runDmlQuery)(token, project_id, query, (_a = location) !== null && _a !== void 0 ? _a : undefined);
|
|
35
|
+
return {
|
|
36
|
+
success: true,
|
|
37
|
+
rows_deleted: result.deletedRowCount,
|
|
38
|
+
job_id: result.jobId,
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=delete-rows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-rows.js","sourceRoot":"","sources":["../../../../src/lib/actions/delete-rows.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,sCAQmB;AAEN,QAAA,gBAAgB,GAAG,IAAA,+BAAY,EAAC;IAC3C,IAAI,EAAE,qBAAY;IAClB,IAAI,EAAE,aAAa;IACnB,WAAW,EAAE,aAAa;IAC1B,WAAW,EACT,6EAA6E;IAC/E,KAAK,EAAE;QACL,UAAU,EAAE,sBAAa;QACzB,UAAU,EAAE,sBAAa;QACzB,QAAQ,EAAE,oBAAW;QACrB,YAAY,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC9B,WAAW,EAAE,cAAc;YAC3B,WAAW,EACT,2IAA2I;YAC7I,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,QAAQ,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC3B,WAAW,EAAE,UAAU;YACvB,WAAW,EACT,iEAAiE;YACnE,QAAQ,EAAE,KAAK;SAChB,CAAC;KACH;IACK,GAAG,CAAC,OAAO;;;YACf,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,GAChE,OAAO,CAAC,UAAU,CAAC;YACrB,MAAM,KAAK,GAAG,MAAM,IAAA,uBAAc,EAAC,OAAO,CAAC,IAAyB,CAAC,CAAC;YAEtE,MAAM,SAAS,GAAG,KAAK,UAAU,IAAI,UAAU,IAAI,QAAQ,IAAI,CAAC;YAChE,MAAM,KAAK,GAAG,eAAe,SAAS,UAAU,YAAY,EAAE,CAAC;YAE/D,MAAM,MAAM,GAAG,MAAM,IAAA,oBAAW,EAC9B,KAAK,EACL,UAAoB,EACpB,KAAK,EACL,MAAC,QAAmB,mCAAI,SAAS,CAClC,CAAC;YAEF,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,YAAY,EAAE,MAAM,CAAC,eAAe;gBACpC,MAAM,EAAE,MAAM,CAAC,KAAK;aACrB,CAAC;QACJ,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const findOneRowAction: import("@activepieces/pieces-framework").IAction<(import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
3
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
4
|
+
}>)[], {
|
|
5
|
+
project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
6
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
7
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
}>)[]>;
|
|
9
|
+
dataset_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
10
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
11
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
12
|
+
}>)[]>;
|
|
13
|
+
table_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
14
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
15
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
16
|
+
}>)[]>;
|
|
17
|
+
where_clause: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
18
|
+
order_by: import("@activepieces/pieces-framework").ShortTextProperty<false>;
|
|
19
|
+
location: import("@activepieces/pieces-framework").ShortTextProperty<false>;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=find-one-row.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-one-row.d.ts","sourceRoot":"","sources":["../../../../src/lib/actions/find-one-row.ts"],"names":[],"mappings":"AAuBA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;EA+E3B,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findOneRowAction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
exports.findOneRowAction = (0, pieces_framework_1.createAction)({
|
|
9
|
+
auth: common_1.bigQueryAuth,
|
|
10
|
+
name: 'find_one_row',
|
|
11
|
+
displayName: 'Find One Row',
|
|
12
|
+
description: 'Find a single row by specifying a WHERE clause and an optional ORDER BY. Returns the first matching row, or empty if none found.',
|
|
13
|
+
props: {
|
|
14
|
+
project_id: common_1.projectIdProp,
|
|
15
|
+
dataset_id: common_1.datasetIdProp,
|
|
16
|
+
table_id: common_1.tableIdProp,
|
|
17
|
+
where_clause: pieces_framework_1.Property.LongText({
|
|
18
|
+
displayName: 'WHERE Clause',
|
|
19
|
+
description: 'SQL condition to filter rows. Do not include the WHERE keyword. Example: `email = "user@example.com"`',
|
|
20
|
+
required: true,
|
|
21
|
+
}),
|
|
22
|
+
order_by: pieces_framework_1.Property.ShortText({
|
|
23
|
+
displayName: 'ORDER BY',
|
|
24
|
+
description: 'Optional column(s) to sort results before picking the first row. Example: `created_at DESC`',
|
|
25
|
+
required: false,
|
|
26
|
+
}),
|
|
27
|
+
location: pieces_framework_1.Property.ShortText({
|
|
28
|
+
displayName: 'Location',
|
|
29
|
+
description: 'Dataset location (e.g. US, EU). Leave blank to use the default.',
|
|
30
|
+
required: false,
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
run(context) {
|
|
34
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
var _a, _b, _c, _d, _e, _f;
|
|
36
|
+
const { project_id, dataset_id, table_id, where_clause, order_by, location, } = context.propsValue;
|
|
37
|
+
const token = yield (0, common_1.getAccessToken)(context.auth);
|
|
38
|
+
const fullTable = `\`${project_id}.${dataset_id}.${table_id}\``;
|
|
39
|
+
const orderPart = order_by ? ` ORDER BY ${order_by}` : '';
|
|
40
|
+
const query = `SELECT * FROM ${fullTable} WHERE ${where_clause}${orderPart} LIMIT 1`;
|
|
41
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
42
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
43
|
+
url: `${common_1.BASE_URL}/projects/${project_id}/queries`,
|
|
44
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
45
|
+
body: Object.assign({ query, useLegacySql: false, maxResults: 1, timeoutMs: 10000 }, (location ? { location } : {})),
|
|
46
|
+
});
|
|
47
|
+
let result = response.body;
|
|
48
|
+
let schema = (_b = (_a = result.schema) === null || _a === void 0 ? void 0 : _a.fields) !== null && _b !== void 0 ? _b : [];
|
|
49
|
+
if (!result.jobComplete) {
|
|
50
|
+
const polled = yield (0, common_1.waitForJobResults)(token, project_id, result.jobReference.jobId, (_c = location) !== null && _c !== void 0 ? _c : undefined);
|
|
51
|
+
result = Object.assign(Object.assign({}, polled), { jobReference: result.jobReference });
|
|
52
|
+
schema = (_e = (_d = polled.schema) === null || _d === void 0 ? void 0 : _d.fields) !== null && _e !== void 0 ? _e : schema;
|
|
53
|
+
}
|
|
54
|
+
const rows = (0, common_1.bigQueryRowsToFlat)(schema, (_f = result.rows) !== null && _f !== void 0 ? _f : []);
|
|
55
|
+
const found = rows.length > 0;
|
|
56
|
+
return Object.assign({ found }, (found ? rows[0] : {}));
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=find-one-row.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-one-row.js","sourceRoot":"","sources":["../../../../src/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|
1
|
+
export declare const findOrCreateRowAction: import("@activepieces/pieces-framework").IAction<(import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
3
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
4
|
+
}>)[], {
|
|
5
|
+
project_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
6
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
7
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
}>)[]>;
|
|
9
|
+
dataset_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
10
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
11
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
12
|
+
}>)[]>;
|
|
13
|
+
table_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, (import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
14
|
+
instructions: import("@activepieces/pieces-framework/dist/src/lib/property/input/markdown-property").MarkDownProperty;
|
|
15
|
+
serviceAccountJson: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
16
|
+
}>)[]>;
|
|
17
|
+
where_clause: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
18
|
+
create_data: import("@activepieces/pieces-framework").JsonProperty<true>;
|
|
19
|
+
location: import("@activepieces/pieces-framework").ShortTextProperty<false>;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=find-or-create-row.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-or-create-row.d.ts","sourceRoot":"","sources":["../../../../src/lib/actions/find-or-create-row.ts"],"names":[],"mappings":"AA8BA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;EAgHhC,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findOrCreateRowAction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
exports.findOrCreateRowAction = (0, pieces_framework_1.createAction)({
|
|
9
|
+
auth: common_1.bigQueryAuth,
|
|
10
|
+
name: 'find_or_create_row',
|
|
11
|
+
displayName: 'Find or Create Record',
|
|
12
|
+
description: 'Searches for a row matching a WHERE clause. If found, returns it. If not found, inserts the provided row data and returns that.',
|
|
13
|
+
props: {
|
|
14
|
+
project_id: common_1.projectIdProp,
|
|
15
|
+
dataset_id: common_1.datasetIdProp,
|
|
16
|
+
table_id: common_1.tableIdProp,
|
|
17
|
+
where_clause: pieces_framework_1.Property.LongText({
|
|
18
|
+
displayName: 'WHERE Clause',
|
|
19
|
+
description: 'SQL condition to search for an existing row. Do not include WHERE. Example: `email = "user@example.com"`',
|
|
20
|
+
required: true,
|
|
21
|
+
}),
|
|
22
|
+
create_data: pieces_framework_1.Property.Json({
|
|
23
|
+
displayName: 'Row to Create (if not found)',
|
|
24
|
+
description: 'A JSON object of column/value pairs to insert if no matching row exists. Example: `{"email": "user@example.com", "name": "Alice"}`',
|
|
25
|
+
required: true,
|
|
26
|
+
}),
|
|
27
|
+
location: pieces_framework_1.Property.ShortText({
|
|
28
|
+
displayName: 'Location',
|
|
29
|
+
description: 'Dataset location (e.g. US, EU). Leave blank to use the default.',
|
|
30
|
+
required: false,
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
run(context) {
|
|
34
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
36
|
+
const { project_id, dataset_id, table_id, where_clause, create_data, location, } = context.propsValue;
|
|
37
|
+
const token = yield (0, common_1.getAccessToken)(context.auth);
|
|
38
|
+
// --- Step 1: Find ---
|
|
39
|
+
const fullTable = `\`${project_id}.${dataset_id}.${table_id}\``;
|
|
40
|
+
const findQuery = `SELECT * FROM ${fullTable} WHERE ${where_clause} LIMIT 1`;
|
|
41
|
+
const findResponse = yield pieces_common_1.httpClient.sendRequest({
|
|
42
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
43
|
+
url: `${common_1.BASE_URL}/projects/${project_id}/queries`,
|
|
44
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
45
|
+
body: Object.assign({ query: findQuery, useLegacySql: false, maxResults: 1, timeoutMs: 10000 }, (location ? { location } : {})),
|
|
46
|
+
});
|
|
47
|
+
let findResult = findResponse.body;
|
|
48
|
+
let schema = (_b = (_a = findResult.schema) === null || _a === void 0 ? void 0 : _a.fields) !== null && _b !== void 0 ? _b : [];
|
|
49
|
+
if (!findResult.jobComplete) {
|
|
50
|
+
const polled = yield (0, common_1.waitForJobResults)(token, project_id, findResult.jobReference.jobId, (_c = location) !== null && _c !== void 0 ? _c : undefined);
|
|
51
|
+
findResult = Object.assign(Object.assign({}, polled), { jobReference: findResult.jobReference });
|
|
52
|
+
schema = (_e = (_d = polled.schema) === null || _d === void 0 ? void 0 : _d.fields) !== null && _e !== void 0 ? _e : schema;
|
|
53
|
+
}
|
|
54
|
+
const existingRows = (0, common_1.bigQueryRowsToFlat)(schema, (_f = findResult.rows) !== null && _f !== void 0 ? _f : []);
|
|
55
|
+
if (existingRows.length > 0) {
|
|
56
|
+
return Object.assign({ found: true, created: false }, existingRows[0]);
|
|
57
|
+
}
|
|
58
|
+
// --- Step 2: Create ---
|
|
59
|
+
const rowData = create_data;
|
|
60
|
+
const insertId = `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
61
|
+
const insertResponse = yield pieces_common_1.httpClient.sendRequest({
|
|
62
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
63
|
+
url: `${common_1.BASE_URL}/projects/${project_id}/datasets/${dataset_id}/tables/${table_id}/insertAll`,
|
|
64
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
65
|
+
body: {
|
|
66
|
+
kind: 'bigquery#tableDataInsertAllRequest',
|
|
67
|
+
rows: [{ insertId, json: rowData }],
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
const errors = (_g = insertResponse.body.insertErrors) !== null && _g !== void 0 ? _g : [];
|
|
71
|
+
if (errors.length > 0) {
|
|
72
|
+
const first = (_h = errors[0]) === null || _h === void 0 ? void 0 : _h.errors[0];
|
|
73
|
+
throw new Error(`Row creation failed: ${(_j = first === null || first === void 0 ? void 0 : first.message) !== null && _j !== void 0 ? _j : 'Unknown error'} (reason: ${(_k = first === null || first === void 0 ? void 0 : first.reason) !== null && _k !== void 0 ? _k : 'unknown'})`);
|
|
74
|
+
}
|
|
75
|
+
return Object.assign({ found: false, created: true, insert_id: insertId }, rowData);
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=find-or-create-row.js.map
|