1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8 | });
|
9 | };
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | const sdk_1 = require("./sdk");
|
12 | const types_1 = require("./types");
|
13 | const treelab = new sdk_1.Treelab({ token: 'budTest' });
|
14 | function main() {
|
15 | return __awaiter(this, void 0, void 0, function* () {
|
16 | const workspace = yield treelab.createWorkspace({ name: 'SYSTEM' });
|
17 | const babelCore = yield workspace.createCore({
|
18 | name: 'Babel',
|
19 | color: types_1.Color.red,
|
20 | icon: types_1.Icon.building,
|
21 | });
|
22 | const extCore = yield workspace.createCore({
|
23 | name: 'Extraction',
|
24 | color: types_1.Color.blue,
|
25 | icon: types_1.Icon.coffee,
|
26 | });
|
27 | const limWorkspace = yield treelab.createWorkspace({ name: 'limWorkspace' });
|
28 | const limCore = yield limWorkspace.createCore({
|
29 | name: 'limCore',
|
30 | color: types_1.Color.red,
|
31 | icon: types_1.Icon.building,
|
32 | });
|
33 | const limTable = yield limCore.createTable({
|
34 | name: 'limTable',
|
35 | columns: [
|
36 | { type: types_1.ColumnType.TEXT, name: 'source', order: 0 },
|
37 | { type: types_1.ColumnType.TEXT, name: 'destination', order: 1 },
|
38 | ],
|
39 | data: [['lim真帅'], ['周末去哪里玩']],
|
40 | });
|
41 | const limView = limTable.views.values().next().value;
|
42 | const babelTable = yield babelCore.createTable({
|
43 | name: ' Instances',
|
44 | columns: [
|
45 | { type: types_1.ColumnType.TEXT, name: 'Workspace ID', order: 0 },
|
46 | { type: types_1.ColumnType.TEXT, name: 'Core ID', order: 1 },
|
47 | { type: types_1.ColumnType.TEXT, name: 'Table ID', order: 2 },
|
48 | { type: types_1.ColumnType.TEXT, name: 'View ID', order: 3 },
|
49 | { type: types_1.ColumnType.TEXT, name: 'Source Column ID', order: 4 },
|
50 | { type: types_1.ColumnType.TEXT, name: 'Source Language', order: 5 },
|
51 | { type: types_1.ColumnType.TEXT, name: 'Destination Column ID', order: 6 },
|
52 | { type: types_1.ColumnType.TEXT, name: 'Destination Language', order: 7 },
|
53 | { type: types_1.ColumnType.TEXT, name: 'Activated', order: 8 },
|
54 | { type: types_1.ColumnType.NUMBER, name: 'Number of API Calls', order: 9 },
|
55 | { type: types_1.ColumnType.NUMBER, name: 'Number of Characters Translated', order: 10 },
|
56 | ],
|
57 | data: [
|
58 | [
|
59 | limWorkspace.id,
|
60 | limCore.id,
|
61 | limTable.id,
|
62 | limView.id,
|
63 | [...limView.columns.values()].filter(i => i.columnConfig.name === 'source')[0].id,
|
64 | 'zh_CN',
|
65 | [...limView.columns.values()].filter(i => i.columnConfig.name === 'destination')[0].id,
|
66 | 'en',
|
67 | 'yes',
|
68 | ],
|
69 | ],
|
70 | });
|
71 | const babelConfig = {};
|
72 | babelConfig.workspaceId = workspace.id;
|
73 | babelConfig.coreId = babelCore.id;
|
74 | babelConfig.tableId = babelTable.id;
|
75 | babelConfig.viewId = babelTable.views.keys().next().value;
|
76 | const babelTableView = babelTable.views.values().next().value;
|
77 | const babelTableViewCol = [...babelTableView.columns.values()];
|
78 | babelConfig.columns = {
|
79 | workspaceId: babelTableViewCol.filter(i => i.columnConfig.name === 'Workspace ID')[0].id,
|
80 | coreId: babelTableViewCol.filter(i => i.columnConfig.name === 'Core ID')[0].id,
|
81 | tableId: babelTableViewCol.filter(i => i.columnConfig.name === 'Table ID')[0].id,
|
82 | viewId: babelTableViewCol.filter(i => i.columnConfig.name === 'View ID')[0].id,
|
83 | sourceColumnId: babelTableViewCol.filter(i => i.columnConfig.name === 'Source Column ID')[0].id,
|
84 | sourceLanguage: babelTableViewCol.filter(i => i.columnConfig.name === 'Source Language')[0].id,
|
85 | destinationColumnId: babelTableViewCol.filter(i => i.columnConfig.name === 'Destination Column ID')[0].id,
|
86 | destinationLanguage: babelTableViewCol.filter(i => i.columnConfig.name === 'Destination Language')[0].id,
|
87 | activated: babelTableViewCol.filter(i => i.columnConfig.name === 'Activated')[0].id,
|
88 | numberOfApiCalls: babelTableViewCol.filter(i => i.columnConfig.name === 'Number of API Calls')[0].id,
|
89 | numberOfCharactersTranslated: babelTableViewCol.filter(i => i.columnConfig.name === 'Number of Characters Translated')[0].id,
|
90 | };
|
91 | console.log('babelConfig: ');
|
92 | console.log(babelConfig);
|
93 | const extBudInsTable = yield extCore.createTable({
|
94 | name: 'Bud Instance Table',
|
95 | columns: [
|
96 | { type: types_1.ColumnType.TEXT, name: 'Workspace ID', order: 0 },
|
97 | { type: types_1.ColumnType.TEXT, name: 'Core ID', order: 1 },
|
98 | { type: types_1.ColumnType.TEXT, name: 'Rules', order: 2 },
|
99 | { type: types_1.ColumnType.TEXT, name: 'Activated', order: 3 },
|
100 | ],
|
101 | data: [[limWorkspace.id, limCore.id, '', 'yes']],
|
102 | });
|
103 | const extBudInsView = extBudInsTable.views.values().next().value;
|
104 | const extInsTable = yield extCore.createTable({
|
105 | name: 'Instances',
|
106 | columns: [
|
107 | { type: types_1.ColumnType.TEXT, name: 'Bud Instance ID', order: 0 },
|
108 | { type: types_1.ColumnType.TEXT, name: 'Rule', order: 1 },
|
109 | { type: types_1.ColumnType.TEXT, name: 'Extracted Data', order: 2 },
|
110 | { type: types_1.ColumnType.TEXT, name: 'File', order: 3 },
|
111 | { type: types_1.ColumnType.TEXT, name: 'Extract', order: 4 },
|
112 | { type: types_1.ColumnType.TEXT, name: 'Extracted Time', order: 5 },
|
113 | { type: types_1.ColumnType.TEXT, name: 'Completed Time', order: 6 },
|
114 | ],
|
115 | data: [[extBudInsView.rows.keys().next().value, '', '', '', 'yes']],
|
116 | });
|
117 | const extBudInsCol = [...extBudInsView.columns.values()];
|
118 | const extInsView = extInsTable.views.values().next().value;
|
119 | const extInsCol = [...extInsView.columns.values()];
|
120 | const extConfig = {
|
121 | workspaceId: workspace.id,
|
122 | coreId: extCore.id,
|
123 | budInstance: {
|
124 | tableId: extBudInsTable.id,
|
125 | viewId: extBudInsView.id,
|
126 | columns: {
|
127 | workspaceId: extBudInsCol.filter(i => i.columnConfig.name === 'Workspace ID')[0].id,
|
128 | coreId: extBudInsCol.filter(i => i.columnConfig.name === 'Core ID')[0].id,
|
129 | rules: extBudInsCol.filter(i => i.columnConfig.name === 'Rules')[0].id,
|
130 | activated: extBudInsCol.filter(i => i.columnConfig.name === 'Activated')[0].id,
|
131 | },
|
132 | },
|
133 | extractionInstance: {
|
134 | tableId: extInsTable.id,
|
135 | viewId: extInsView.id,
|
136 | columns: {
|
137 | budInstanceId: extInsCol.filter(i => i.columnConfig.name === 'Bud Instance ID')[0].id,
|
138 | ruleId: extInsCol.filter(i => i.columnConfig.name === 'Rule')[0].id,
|
139 | extractedData: extInsCol.filter(i => i.columnConfig.name === 'Extracted Data')[0].id,
|
140 | file: extInsCol.filter(i => i.columnConfig.name === 'File')[0].id,
|
141 | extract: extInsCol.filter(i => i.columnConfig.name === 'Extract')[0].id,
|
142 | extractTime: extInsCol.filter(i => i.columnConfig.name === 'Extracted Time')[0].id,
|
143 | completedTime: extInsCol.filter(i => i.columnConfig.name === 'Completed Time')[0].id,
|
144 | },
|
145 | },
|
146 | };
|
147 | console.log('\nextractionConfig: ');
|
148 | console.log(extConfig);
|
149 | console.log('\nsuccess');
|
150 | });
|
151 | }
|
152 | main();
|
153 |
|
\ | No newline at end of file |