data-api-client 1.3.1 → 2.0.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.
- package/README.md +389 -136
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +69 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/params.d.ts +19 -0
- package/dist/params.d.ts.map +1 -0
- package/dist/params.js +125 -0
- package/dist/query.d.ts +5 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +38 -0
- package/dist/results.d.ts +12 -0
- package/dist/results.d.ts.map +1 -0
- package/dist/results.js +93 -0
- package/dist/transaction.d.ts +4 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +57 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +19 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +150 -0
- package/package.json +37 -9
- package/index.js +0 -625
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,mBAAmB,EAAkB,aAAa,EAA6B,MAAM,SAAS,CAAA;AAyB5G,eAAO,MAAM,IAAI,GAAI,QAAQ,mBAAmB,KAAG,aAkHlD,CAAA"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = void 0;
|
|
4
|
+
const client_rds_data_1 = require("@aws-sdk/client-rds-data");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const query_1 = require("./query");
|
|
7
|
+
const transaction_1 = require("./transaction");
|
|
8
|
+
const init = (params) => {
|
|
9
|
+
const options = typeof params.options === 'object'
|
|
10
|
+
? params.options
|
|
11
|
+
: params.options !== undefined
|
|
12
|
+
? (0, utils_1.error)(`'options' must be an object`)
|
|
13
|
+
: {};
|
|
14
|
+
if (typeof params.region === 'string') {
|
|
15
|
+
options.region = params.region;
|
|
16
|
+
}
|
|
17
|
+
if (params.sslEnabled === false) {
|
|
18
|
+
console.warn('sslEnabled is deprecated. For local development, set options.endpoint instead.');
|
|
19
|
+
}
|
|
20
|
+
const config = {
|
|
21
|
+
engine: typeof params.engine === 'string' ? params.engine : 'pg',
|
|
22
|
+
secretArn: typeof params.secretArn === 'string' ? params.secretArn : (0, utils_1.error)(`'secretArn' string value required`),
|
|
23
|
+
resourceArn: typeof params.resourceArn === 'string' ? params.resourceArn : (0, utils_1.error)(`'resourceArn' string value required`),
|
|
24
|
+
database: typeof params.database === 'string'
|
|
25
|
+
? params.database
|
|
26
|
+
: params.database !== undefined
|
|
27
|
+
? (0, utils_1.error)(`'database' must be a string`)
|
|
28
|
+
: undefined,
|
|
29
|
+
hydrateColumnNames: typeof params.hydrateColumnNames === 'boolean' ? params.hydrateColumnNames : true,
|
|
30
|
+
formatOptions: {
|
|
31
|
+
deserializeDate: typeof params.formatOptions === 'object' && params.formatOptions.deserializeDate === false ? false : true,
|
|
32
|
+
treatAsLocalDate: typeof params.formatOptions === 'object' && params.formatOptions.treatAsLocalDate ? true : false
|
|
33
|
+
},
|
|
34
|
+
RDS: params.client ? params.client : new client_rds_data_1.RDSDataClient(options)
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
query: (...x) => query_1.query.call(undefined, config, ...x),
|
|
38
|
+
transaction: (x) => (0, transaction_1.transaction)(config, x),
|
|
39
|
+
batchExecuteStatement: async (args) => config.RDS.send(new client_rds_data_1.BatchExecuteStatementCommand({
|
|
40
|
+
...args,
|
|
41
|
+
resourceArn: args.resourceArn || config.resourceArn,
|
|
42
|
+
secretArn: args.secretArn || config.secretArn,
|
|
43
|
+
database: args.database || config.database
|
|
44
|
+
})),
|
|
45
|
+
beginTransaction: async (args) => config.RDS.send(new client_rds_data_1.BeginTransactionCommand({
|
|
46
|
+
...(args || {}),
|
|
47
|
+
resourceArn: (args === null || args === void 0 ? void 0 : args.resourceArn) || config.resourceArn,
|
|
48
|
+
secretArn: (args === null || args === void 0 ? void 0 : args.secretArn) || config.secretArn,
|
|
49
|
+
database: (args === null || args === void 0 ? void 0 : args.database) || config.database
|
|
50
|
+
})),
|
|
51
|
+
commitTransaction: async (args) => config.RDS.send(new client_rds_data_1.CommitTransactionCommand({
|
|
52
|
+
...args,
|
|
53
|
+
resourceArn: args.resourceArn || config.resourceArn,
|
|
54
|
+
secretArn: args.secretArn || config.secretArn
|
|
55
|
+
})),
|
|
56
|
+
executeStatement: async (args) => config.RDS.send(new client_rds_data_1.ExecuteStatementCommand({
|
|
57
|
+
...args,
|
|
58
|
+
resourceArn: args.resourceArn || config.resourceArn,
|
|
59
|
+
secretArn: args.secretArn || config.secretArn,
|
|
60
|
+
database: args.database || config.database
|
|
61
|
+
})),
|
|
62
|
+
rollbackTransaction: async (args) => config.RDS.send(new client_rds_data_1.RollbackTransactionCommand({
|
|
63
|
+
...args,
|
|
64
|
+
resourceArn: args.resourceArn || config.resourceArn,
|
|
65
|
+
secretArn: args.secretArn || config.secretArn
|
|
66
|
+
}))
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
exports.init = init;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAC/B,SAAS,IAAI,CAAA"}
|
package/dist/index.js
ADDED
package/dist/params.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { InternalConfig, Parameters, ParameterValue, NamedParameter, FormattedParameter, SqlParamInfo, FormatOptions, SupportedType } from './types';
|
|
2
|
+
export declare const parseParams: (args: any[]) => Parameters[];
|
|
3
|
+
export declare const parseDatabase: (config: InternalConfig, args: any[]) => string | undefined;
|
|
4
|
+
export declare const parseHydrate: (config: InternalConfig, args: any[]) => boolean;
|
|
5
|
+
export declare const parseFormatOptions: (config: InternalConfig, args: any[]) => Required<FormatOptions>;
|
|
6
|
+
export declare const prepareParams: ({ secretArn, resourceArn }: InternalConfig, args: any[]) => {
|
|
7
|
+
secretArn: string;
|
|
8
|
+
resourceArn: string;
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
};
|
|
11
|
+
export declare const normalizeParams: (params: Parameters[]) => (NamedParameter | NamedParameter[])[];
|
|
12
|
+
export declare const processParams: (engine: string, sql: string, sqlParams: Record<string, SqlParamInfo>, params: (NamedParameter | NamedParameter[])[], formatOptions: Required<FormatOptions>, row?: number) => {
|
|
13
|
+
processedParams: (FormattedParameter | FormattedParameter[])[];
|
|
14
|
+
escapedSql: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const formatParam: (n: string, v: ParameterValue, formatOptions: Required<FormatOptions>) => FormattedParameter;
|
|
17
|
+
export declare const splitParams: (p: Record<string, ParameterValue>) => NamedParameter[];
|
|
18
|
+
export declare const formatType: (name: string, value: ParameterValue, type: SupportedType | null | undefined, typeHint: string | undefined, formatOptions: Required<FormatOptions>) => FormattedParameter;
|
|
19
|
+
//# sourceMappingURL=params.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../src/params.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,aAAa,EACd,MAAM,SAAS,CAAA;AAIhB,eAAO,MAAM,WAAW,GAAI,MAAM,GAAG,EAAE,KAAG,UAAU,EAa5C,CAAA;AAGR,eAAO,MAAM,aAAa,GAAI,QAAQ,cAAc,EAAE,MAAM,GAAG,EAAE,KAAG,MAAM,GA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a,CAAC,KACrC,kBAgBF,CAAA"}
|
package/dist/params.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.formatType = exports.splitParams = exports.formatParam = exports.processParams = exports.normalizeParams = exports.prepareParams = exports.parseFormatOptions = exports.parseHydrate = exports.parseDatabase = exports.parseParams = void 0;
|
|
7
|
+
const sqlstring_1 = __importDefault(require("sqlstring"));
|
|
8
|
+
const pg_escape_1 = __importDefault(require("pg-escape"));
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const parseParams = (args) => Array.isArray(args[0].parameters)
|
|
11
|
+
? args[0].parameters
|
|
12
|
+
: typeof args[0].parameters === 'object'
|
|
13
|
+
? [args[0].parameters]
|
|
14
|
+
: Array.isArray(args[1])
|
|
15
|
+
? args[1]
|
|
16
|
+
: typeof args[1] === 'object'
|
|
17
|
+
? [args[1]]
|
|
18
|
+
: args[0].parameters
|
|
19
|
+
? (0, utils_1.error)(`'parameters' must be an object or array`)
|
|
20
|
+
: args[1]
|
|
21
|
+
? (0, utils_1.error)('Parameters must be an object or array')
|
|
22
|
+
: [];
|
|
23
|
+
exports.parseParams = parseParams;
|
|
24
|
+
const parseDatabase = (config, args) => config.transactionId
|
|
25
|
+
? config.database
|
|
26
|
+
: typeof args[0].database === 'string'
|
|
27
|
+
? args[0].database
|
|
28
|
+
: args[0].database
|
|
29
|
+
? (0, utils_1.error)(`'database' must be a string.`)
|
|
30
|
+
: config.database
|
|
31
|
+
? config.database
|
|
32
|
+
: undefined;
|
|
33
|
+
exports.parseDatabase = parseDatabase;
|
|
34
|
+
const parseHydrate = (config, args) => typeof args[0].hydrateColumnNames === 'boolean'
|
|
35
|
+
? args[0].hydrateColumnNames
|
|
36
|
+
: args[0].hydrateColumnNames
|
|
37
|
+
? (0, utils_1.error)(`'hydrateColumnNames' must be a boolean.`)
|
|
38
|
+
: config.hydrateColumnNames;
|
|
39
|
+
exports.parseHydrate = parseHydrate;
|
|
40
|
+
const parseFormatOptions = (config, args) => typeof args[0].formatOptions === 'object'
|
|
41
|
+
? {
|
|
42
|
+
deserializeDate: typeof args[0].formatOptions.deserializeDate === 'boolean'
|
|
43
|
+
? args[0].formatOptions.deserializeDate
|
|
44
|
+
: args[0].formatOptions.deserializeDate
|
|
45
|
+
? (0, utils_1.error)(`'formatOptions.deserializeDate' must be a boolean.`)
|
|
46
|
+
: config.formatOptions.deserializeDate,
|
|
47
|
+
treatAsLocalDate: typeof args[0].formatOptions.treatAsLocalDate == 'boolean'
|
|
48
|
+
? args[0].formatOptions.treatAsLocalDate
|
|
49
|
+
: args[0].formatOptions.treatAsLocalDate
|
|
50
|
+
? (0, utils_1.error)(`'formatOptions.treatAsLocalDate' must be a boolean.`)
|
|
51
|
+
: config.formatOptions.treatAsLocalDate
|
|
52
|
+
}
|
|
53
|
+
: args[0].formatOptions
|
|
54
|
+
? (0, utils_1.error)(`'formatOptions' must be an object.`)
|
|
55
|
+
: config.formatOptions;
|
|
56
|
+
exports.parseFormatOptions = parseFormatOptions;
|
|
57
|
+
const prepareParams = ({ secretArn, resourceArn }, args) => {
|
|
58
|
+
return Object.assign({ secretArn, resourceArn }, typeof args[0] === 'object' ? omit(args[0], ['hydrateColumnNames', 'parameters']) : {});
|
|
59
|
+
};
|
|
60
|
+
exports.prepareParams = prepareParams;
|
|
61
|
+
const omit = (obj, values) => Object.keys(obj).reduce((acc, x) => (values.includes(x) ? acc : Object.assign(acc, { [x]: obj[x] })), {});
|
|
62
|
+
const normalizeParams = (params) => params.reduce((acc, p) => Array.isArray(p)
|
|
63
|
+
? acc.concat([(0, exports.normalizeParams)(p)])
|
|
64
|
+
: (Object.keys(p).length === 2 && 'name' in p && typeof p.value !== 'undefined') ||
|
|
65
|
+
(Object.keys(p).length === 3 &&
|
|
66
|
+
'name' in p &&
|
|
67
|
+
typeof p.value !== 'undefined' &&
|
|
68
|
+
'cast' in p)
|
|
69
|
+
? acc.concat(p)
|
|
70
|
+
: acc.concat(...(0, exports.splitParams)(p)), []);
|
|
71
|
+
exports.normalizeParams = normalizeParams;
|
|
72
|
+
const processParams = (engine, sql, sqlParams, params, formatOptions, row = 0) => {
|
|
73
|
+
return {
|
|
74
|
+
processedParams: params.reduce((acc, p) => {
|
|
75
|
+
if (Array.isArray(p)) {
|
|
76
|
+
const result = (0, exports.processParams)(engine, sql, sqlParams, p, formatOptions, row);
|
|
77
|
+
if (row === 0) {
|
|
78
|
+
sql = result.escapedSql;
|
|
79
|
+
row++;
|
|
80
|
+
}
|
|
81
|
+
return acc.concat([result.processedParams]);
|
|
82
|
+
}
|
|
83
|
+
else if (sqlParams[p.name]) {
|
|
84
|
+
if (sqlParams[p.name].type === 'n_ph') {
|
|
85
|
+
if (p.cast) {
|
|
86
|
+
const regex = new RegExp(':' + p.name + '\\b', 'g');
|
|
87
|
+
sql = sql.replace(regex, engine === 'pg' ? `:${p.name}::${p.cast}` : `CAST(:${p.name} AS ${p.cast})`);
|
|
88
|
+
}
|
|
89
|
+
acc.push((0, exports.formatParam)(p.name, p.value, formatOptions));
|
|
90
|
+
}
|
|
91
|
+
else if (row === 0) {
|
|
92
|
+
const regex = new RegExp('::' + p.name + '\\b', 'g');
|
|
93
|
+
const escapedId = engine === 'pg'
|
|
94
|
+
? pg_escape_1.default.ident(p.value)
|
|
95
|
+
: sqlstring_1.default.escapeId(p.value);
|
|
96
|
+
sql = sql.replace(regex, escapedId);
|
|
97
|
+
}
|
|
98
|
+
return acc;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return acc;
|
|
102
|
+
}
|
|
103
|
+
}, []),
|
|
104
|
+
escapedSql: sql
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
exports.processParams = processParams;
|
|
108
|
+
const formatParam = (n, v, formatOptions) => (0, exports.formatType)(n, v, (0, utils_1.getType)(v), (0, utils_1.getTypeHint)(v), formatOptions);
|
|
109
|
+
exports.formatParam = formatParam;
|
|
110
|
+
const splitParams = (p) => Object.keys(p).reduce((arr, x) => arr.concat({ name: x, value: p[x] }), []);
|
|
111
|
+
exports.splitParams = splitParams;
|
|
112
|
+
const formatType = (name, value, type, typeHint, formatOptions) => {
|
|
113
|
+
return Object.assign(typeHint != null ? { name, typeHint } : { name }, type === null
|
|
114
|
+
? { value }
|
|
115
|
+
: {
|
|
116
|
+
value: {
|
|
117
|
+
[type ? type : (0, utils_1.error)(`'${name}' is an invalid type`)]: type === 'isNull'
|
|
118
|
+
? true
|
|
119
|
+
: (0, utils_1.isDate)(value)
|
|
120
|
+
? (0, utils_1.formatToTimeStamp)(value, formatOptions && formatOptions.treatAsLocalDate)
|
|
121
|
+
: value
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
exports.formatType = formatType;
|
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAc1D,eAAO,MAAM,KAAK,GAChB,MAAM;IAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI,CAAA;CAAE,GAAG,SAAS,EAClE,QAAQ,cAAc,EACtB,GAAG,OAAO,GAAG,EAAE,KACd,OAAO,CAAC,WAAW,CAgErB,CAAA"}
|
package/dist/query.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.query = void 0;
|
|
4
|
+
const client_rds_data_1 = require("@aws-sdk/client-rds-data");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const params_1 = require("./params");
|
|
7
|
+
const results_1 = require("./results");
|
|
8
|
+
const query = async function (config, ..._args) {
|
|
9
|
+
const args = Array.isArray(_args[0]) ? (0, utils_1.flatten)(_args) : _args;
|
|
10
|
+
const sql = (0, utils_1.parseSQL)(args);
|
|
11
|
+
const sqlParams = (0, utils_1.getSqlParams)(sql);
|
|
12
|
+
const hydrateColumnNames = (0, params_1.parseHydrate)(config, args);
|
|
13
|
+
const formatOptions = (0, params_1.parseFormatOptions)(config, args);
|
|
14
|
+
const parameters = (0, params_1.normalizeParams)((0, params_1.parseParams)(args));
|
|
15
|
+
const { processedParams, escapedSql } = (0, params_1.processParams)(config.engine, sql, sqlParams, parameters, formatOptions);
|
|
16
|
+
const isBatch = processedParams.length > 0 && Array.isArray(processedParams[0]);
|
|
17
|
+
const params = Object.assign((0, params_1.prepareParams)(config, args), {
|
|
18
|
+
database: (0, params_1.parseDatabase)(config, args),
|
|
19
|
+
sql: escapedSql
|
|
20
|
+
}, processedParams.length > 0
|
|
21
|
+
?
|
|
22
|
+
{ [isBatch ? 'parameterSets' : 'parameters']: processedParams }
|
|
23
|
+
: {}, hydrateColumnNames && !isBatch ? { includeResultMetadata: true } : {}, config.transactionId ? { transactionId: config.transactionId } : {});
|
|
24
|
+
try {
|
|
25
|
+
const result = await (isBatch
|
|
26
|
+
? config.RDS.send(new client_rds_data_1.BatchExecuteStatementCommand(params))
|
|
27
|
+
: config.RDS.send(new client_rds_data_1.ExecuteStatementCommand(params)));
|
|
28
|
+
return (0, results_1.formatResults)(result, hydrateColumnNames, args[0].includeResultMetadata === true, formatOptions);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
if (this && this.rollback) {
|
|
32
|
+
const rollback = await config.RDS.send(new client_rds_data_1.RollbackTransactionCommand((0, utils_1.pick)(params, ['resourceArn', 'secretArn', 'transactionId'])));
|
|
33
|
+
this.rollback(e, rollback);
|
|
34
|
+
}
|
|
35
|
+
throw e;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.query = query;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExecuteStatementCommandOutput, BatchExecuteStatementCommandOutput, Field } from '@aws-sdk/client-rds-data';
|
|
2
|
+
import type { QueryResult, UpdateResult, FormatOptions } from './types';
|
|
3
|
+
export declare const formatResults: (result: ExecuteStatementCommandOutput | BatchExecuteStatementCommandOutput, hydrate: boolean, includeMeta: boolean, formatOptions: Required<FormatOptions>) => QueryResult;
|
|
4
|
+
export declare const formatRecords: (recs: Field[][] | undefined, columns: {
|
|
5
|
+
label?: string;
|
|
6
|
+
typeName?: string;
|
|
7
|
+
}[] | undefined, hydrate: boolean, formatOptions: Required<FormatOptions>) => any[];
|
|
8
|
+
export declare const formatRecordValue: (value: any, typeName: string | undefined, formatOptions: Required<FormatOptions>) => any;
|
|
9
|
+
export declare const formatUpdateResults: (res: {
|
|
10
|
+
generatedFields?: Field[];
|
|
11
|
+
}[]) => UpdateResult[];
|
|
12
|
+
//# sourceMappingURL=results.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,6BAA6B,EAAE,kCAAkC,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AACxH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAIvE,eAAO,MAAM,aAAa,GACxB,QAAQ,6BAA6B,GAAG,kCAAkC,EAC1E,SAAS,OAAO,EAChB,aAAa,OAAO,EACpB,eAAe,QAAQ,CAAC,aAAa,CAAC,KACrC,WAuBF,CAAA;AAID,eAAO,MAAM,aAAa,GACxB,MAAM,KAAK,EAAE,EAAE,GAAG,SAAS,EAC3B,SAAS;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,SAAS,EAC5D,SAAS,OAAO,EAChB,eAAe,QAAQ,CAAC,aAAa,CAAC,KACrC,GAAG,EAsDL,CAAA;AAsBD,eAAO,MAAM,iBAAiB,GAC5B,OAAO,GAAG,EACV,UAAU,MAAM,GAAG,SAAS,EAC5B,eAAe,QAAQ,CAAC,aAAa,CAAC,KACrC,GAmCF,CAAA;AAGD,eAAO,MAAM,mBAAmB,GAAI,KAAK;IAAE,eAAe,CAAC,EAAE,KAAK,EAAE,CAAA;CAAE,EAAE,KAAG,YAAY,EAGnF,CAAA"}
|
package/dist/results.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatUpdateResults = exports.formatRecordValue = exports.formatRecords = exports.formatResults = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const formatResults = (result, hydrate, includeMeta, formatOptions) => {
|
|
6
|
+
const { columnMetadata, numberOfRecordsUpdated, records, generatedFields, updateResults } = result;
|
|
7
|
+
return Object.assign(includeMeta ? { columnMetadata } : {}, numberOfRecordsUpdated !== undefined && !records ? { numberOfRecordsUpdated } : {}, records
|
|
8
|
+
? {
|
|
9
|
+
records: (0, exports.formatRecords)(records, columnMetadata, hydrate, formatOptions)
|
|
10
|
+
}
|
|
11
|
+
: {}, updateResults ? { updateResults: (0, exports.formatUpdateResults)(updateResults) } : {}, generatedFields && generatedFields.length > 0 ? { insertId: generatedFields[0].longValue } : {});
|
|
12
|
+
};
|
|
13
|
+
exports.formatResults = formatResults;
|
|
14
|
+
const formatRecords = (recs, columns, hydrate, formatOptions) => {
|
|
15
|
+
const fmap = recs && recs[0]
|
|
16
|
+
? recs[0].map((_field, i) => {
|
|
17
|
+
return Object.assign({}, columns ? { label: columns[i].label, typeName: columns[i].typeName } : {});
|
|
18
|
+
})
|
|
19
|
+
: [];
|
|
20
|
+
return recs
|
|
21
|
+
? recs.map((rec) => {
|
|
22
|
+
return rec.reduce((acc, field, i) => {
|
|
23
|
+
if (field.isNull === true) {
|
|
24
|
+
return hydrate
|
|
25
|
+
? Object.assign(acc, { [fmap[i].label]: null })
|
|
26
|
+
: acc.concat(null);
|
|
27
|
+
}
|
|
28
|
+
else if (fmap[i] && fmap[i].field) {
|
|
29
|
+
const value = (0, exports.formatRecordValue)(field[fmap[i].field], fmap[i].typeName, formatOptions);
|
|
30
|
+
return hydrate
|
|
31
|
+
? Object.assign(acc, { [fmap[i].label]: value })
|
|
32
|
+
: acc.concat(value);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
Object.keys(field).map((type) => {
|
|
36
|
+
if (type !== 'isNull' && field[type] !== null) {
|
|
37
|
+
fmap[i]['field'] = type;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const value = (0, exports.formatRecordValue)(field[fmap[i].field], fmap[i].typeName, formatOptions);
|
|
41
|
+
return hydrate
|
|
42
|
+
? Object.assign(acc, { [fmap[i].label]: value })
|
|
43
|
+
: acc.concat(value);
|
|
44
|
+
}
|
|
45
|
+
}, hydrate ? {} : []);
|
|
46
|
+
})
|
|
47
|
+
: [];
|
|
48
|
+
};
|
|
49
|
+
exports.formatRecords = formatRecords;
|
|
50
|
+
const flattenArrayValue = (arrayValue) => {
|
|
51
|
+
if (!arrayValue)
|
|
52
|
+
return [];
|
|
53
|
+
if (arrayValue.stringValues)
|
|
54
|
+
return arrayValue.stringValues.slice();
|
|
55
|
+
if (arrayValue.longValues)
|
|
56
|
+
return arrayValue.longValues.slice();
|
|
57
|
+
if (arrayValue.doubleValues)
|
|
58
|
+
return arrayValue.doubleValues.slice();
|
|
59
|
+
if (arrayValue.booleanValues)
|
|
60
|
+
return arrayValue.booleanValues.slice();
|
|
61
|
+
if (arrayValue.arrayValues) {
|
|
62
|
+
return arrayValue.arrayValues.map((nested) => flattenArrayValue(nested.arrayValue || nested));
|
|
63
|
+
}
|
|
64
|
+
return [];
|
|
65
|
+
};
|
|
66
|
+
const formatRecordValue = (value, typeName, formatOptions) => {
|
|
67
|
+
if (value instanceof Uint8Array) {
|
|
68
|
+
return Buffer.from(value);
|
|
69
|
+
}
|
|
70
|
+
if (value && typeof value === 'object' && typeName && typeName.startsWith('_')) {
|
|
71
|
+
return flattenArrayValue(value);
|
|
72
|
+
}
|
|
73
|
+
if (formatOptions &&
|
|
74
|
+
formatOptions.deserializeDate &&
|
|
75
|
+
typeName &&
|
|
76
|
+
['DATE', 'DATETIME', 'TIMESTAMP', 'TIMESTAMPTZ', 'TIMESTAMP WITH TIME ZONE'].includes(typeName.toUpperCase())) {
|
|
77
|
+
return (0, utils_1.formatFromTimeStamp)(value, (formatOptions && formatOptions.treatAsLocalDate) || typeName === 'TIMESTAMP WITH TIME ZONE');
|
|
78
|
+
}
|
|
79
|
+
else if (typeName === 'JSON') {
|
|
80
|
+
return JSON.parse(value);
|
|
81
|
+
}
|
|
82
|
+
else if (typeName === 'YEAR') {
|
|
83
|
+
return typeof value === 'string' ? parseInt(value, 10) : value;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
exports.formatRecordValue = formatRecordValue;
|
|
90
|
+
const formatUpdateResults = (res) => res.map((x) => {
|
|
91
|
+
return x.generatedFields && x.generatedFields.length > 0 ? { insertId: x.generatedFields[0].longValue } : {};
|
|
92
|
+
});
|
|
93
|
+
exports.formatUpdateResults = formatUpdateResults;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InternalConfig, Transaction, QueryOptions } from './types';
|
|
2
|
+
export declare const transaction: (config: InternalConfig, _args?: Partial<QueryOptions>) => Transaction;
|
|
3
|
+
export declare const commit: (config: InternalConfig, queries: Array<(lastResult: any, allResults: any[]) => any[]>, rollback: (err: Error, status: any) => void) => Promise<any[]>;
|
|
4
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAMxE,eAAO,MAAM,WAAW,GAAI,QAAQ,cAAc,EAAE,QAAQ,OAAO,CAAC,YAAY,CAAC,KAAG,WAgCnF,CAAA;AAGD,eAAO,MAAM,MAAM,GACjB,QAAQ,cAAc,EACtB,SAAS,KAAK,CAAC,CAAC,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,CAAC,EAC7D,UAAU,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI,KAC1C,OAAO,CAAC,GAAG,EAAE,CAiCf,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.commit = exports.transaction = void 0;
|
|
4
|
+
const client_rds_data_1 = require("@aws-sdk/client-rds-data");
|
|
5
|
+
const params_1 = require("./params");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const query_1 = require("./query");
|
|
8
|
+
const transaction = (config, _args) => {
|
|
9
|
+
const args = typeof _args === 'object' ? [_args] : [{}];
|
|
10
|
+
const queries = [];
|
|
11
|
+
let rollback = () => { };
|
|
12
|
+
const txConfig = Object.assign((0, params_1.prepareParams)(config, args), {
|
|
13
|
+
database: (0, params_1.parseDatabase)(config, args),
|
|
14
|
+
hydrateColumnNames: (0, params_1.parseHydrate)(config, args),
|
|
15
|
+
formatOptions: (0, params_1.parseFormatOptions)(config, args),
|
|
16
|
+
RDS: config.RDS,
|
|
17
|
+
engine: config.engine
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
query: function (...args) {
|
|
21
|
+
if (typeof args[0] === 'function') {
|
|
22
|
+
queries.push(args[0]);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
queries.push(() => [...args]);
|
|
26
|
+
}
|
|
27
|
+
return this;
|
|
28
|
+
},
|
|
29
|
+
rollback: function (fn) {
|
|
30
|
+
if (typeof fn === 'function') {
|
|
31
|
+
rollback = fn;
|
|
32
|
+
}
|
|
33
|
+
return this;
|
|
34
|
+
},
|
|
35
|
+
commit: async function () {
|
|
36
|
+
return await (0, exports.commit)(txConfig, queries, rollback);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.transaction = transaction;
|
|
41
|
+
const commit = async (config, queries, rollback) => {
|
|
42
|
+
const results = [];
|
|
43
|
+
const { transactionId } = await config.RDS.send(new client_rds_data_1.BeginTransactionCommand((0, utils_1.pick)(config, ['resourceArn', 'secretArn', 'database'])));
|
|
44
|
+
const txConfig = Object.assign(config, { transactionId });
|
|
45
|
+
for (let i = 0; i < queries.length; i++) {
|
|
46
|
+
const result = await query_1.query.apply({ rollback }, [config, queries[i](results[results.length - 1], results)]);
|
|
47
|
+
results.push(result);
|
|
48
|
+
}
|
|
49
|
+
const { transactionStatus } = await txConfig.RDS.send(new client_rds_data_1.CommitTransactionCommand({
|
|
50
|
+
resourceArn: txConfig.resourceArn,
|
|
51
|
+
secretArn: txConfig.secretArn,
|
|
52
|
+
transactionId: txConfig.transactionId
|
|
53
|
+
}));
|
|
54
|
+
results.push({ transactionStatus });
|
|
55
|
+
return results;
|
|
56
|
+
};
|
|
57
|
+
exports.commit = commit;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { RDSDataClient, RDSDataClientConfig, ExecuteStatementCommandOutput, BatchExecuteStatementCommandOutput, BeginTransactionCommandInput, BeginTransactionCommandOutput, CommitTransactionCommandInput, CommitTransactionCommandOutput, RollbackTransactionCommandInput, RollbackTransactionCommandOutput, ExecuteStatementCommandInput, BatchExecuteStatementCommandInput, ColumnMetadata, ResultSetOptions } from '@aws-sdk/client-rds-data';
|
|
2
|
+
export type SupportedType = 'arrayValue' | 'blobValue' | 'booleanValue' | 'doubleValue' | 'isNull' | 'longValue' | 'stringValue' | 'structValue';
|
|
3
|
+
export interface DataAPIClientConfig {
|
|
4
|
+
resourceArn: string;
|
|
5
|
+
secretArn: string;
|
|
6
|
+
database?: string;
|
|
7
|
+
engine?: 'mysql' | 'pg';
|
|
8
|
+
hydrateColumnNames?: boolean;
|
|
9
|
+
formatOptions?: FormatOptions;
|
|
10
|
+
options?: RDSDataClientConfig;
|
|
11
|
+
client?: RDSDataClient;
|
|
12
|
+
region?: string;
|
|
13
|
+
sslEnabled?: boolean;
|
|
14
|
+
keepAlive?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface FormatOptions {
|
|
17
|
+
deserializeDate?: boolean;
|
|
18
|
+
treatAsLocalDate?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface InternalConfig {
|
|
21
|
+
engine: 'mysql' | 'pg';
|
|
22
|
+
secretArn: string;
|
|
23
|
+
resourceArn: string;
|
|
24
|
+
database?: string;
|
|
25
|
+
hydrateColumnNames: boolean;
|
|
26
|
+
formatOptions: Required<FormatOptions>;
|
|
27
|
+
RDS: RDSDataClient;
|
|
28
|
+
transactionId?: string;
|
|
29
|
+
}
|
|
30
|
+
export type ParameterValue = string | number | boolean | null | Date | Buffer | {
|
|
31
|
+
[key in SupportedType]?: any;
|
|
32
|
+
};
|
|
33
|
+
export interface NamedParameter {
|
|
34
|
+
name: string;
|
|
35
|
+
value: ParameterValue;
|
|
36
|
+
cast?: string;
|
|
37
|
+
}
|
|
38
|
+
export type Parameters = Record<string, ParameterValue> | NamedParameter[];
|
|
39
|
+
export interface QueryOptions {
|
|
40
|
+
sql: string;
|
|
41
|
+
parameters?: Parameters | Parameters[];
|
|
42
|
+
database?: string;
|
|
43
|
+
schema?: string;
|
|
44
|
+
continueAfterTimeout?: boolean;
|
|
45
|
+
includeResultMetadata?: boolean;
|
|
46
|
+
hydrateColumnNames?: boolean;
|
|
47
|
+
transactionId?: string;
|
|
48
|
+
secretArn?: string;
|
|
49
|
+
resourceArn?: string;
|
|
50
|
+
resultSetOptions?: ResultSetOptions;
|
|
51
|
+
formatOptions?: FormatOptions;
|
|
52
|
+
}
|
|
53
|
+
export interface FormattedParameter {
|
|
54
|
+
name: string;
|
|
55
|
+
value?: {
|
|
56
|
+
[key in SupportedType]?: any;
|
|
57
|
+
};
|
|
58
|
+
typeHint?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface SqlParamInfo {
|
|
61
|
+
type: 'n_ph' | 'n_id';
|
|
62
|
+
}
|
|
63
|
+
export interface QueryResult<T = any> {
|
|
64
|
+
records?: T[];
|
|
65
|
+
columnMetadata?: ColumnMetadata[];
|
|
66
|
+
numberOfRecordsUpdated?: number;
|
|
67
|
+
insertId?: number;
|
|
68
|
+
updateResults?: UpdateResult[];
|
|
69
|
+
}
|
|
70
|
+
export interface UpdateResult {
|
|
71
|
+
insertId?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface Transaction {
|
|
74
|
+
query(sql: string, params?: Parameters): Transaction;
|
|
75
|
+
query(options: QueryOptions): Transaction;
|
|
76
|
+
query(fn: (lastResult: any, allResults: any[]) => [string, Parameters?]): Transaction;
|
|
77
|
+
rollback(fn: (error: Error, status: any) => void): Transaction;
|
|
78
|
+
commit(): Promise<any[]>;
|
|
79
|
+
}
|
|
80
|
+
export interface DataAPIClient {
|
|
81
|
+
query<T = any>(sql: string, params?: Parameters | Parameters[]): Promise<QueryResult<T>>;
|
|
82
|
+
query<T = any>(options: QueryOptions): Promise<QueryResult<T>>;
|
|
83
|
+
transaction(options?: Partial<QueryOptions>): Transaction;
|
|
84
|
+
batchExecuteStatement(args: BatchExecuteStatementCommandInput): Promise<BatchExecuteStatementCommandOutput>;
|
|
85
|
+
beginTransaction(args?: BeginTransactionCommandInput): Promise<BeginTransactionCommandOutput>;
|
|
86
|
+
commitTransaction(args: CommitTransactionCommandInput): Promise<CommitTransactionCommandOutput>;
|
|
87
|
+
executeStatement(args: ExecuteStatementCommandInput): Promise<ExecuteStatementCommandOutput>;
|
|
88
|
+
rollbackTransaction(args: RollbackTransactionCommandInput): Promise<RollbackTransactionCommandOutput>;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACnB,6BAA6B,EAC7B,kCAAkC,EAClC,4BAA4B,EAC5B,6BAA6B,EAC7B,6BAA6B,EAC7B,8BAA8B,EAC9B,+BAA+B,EAC/B,gCAAgC,EAChC,4BAA4B,EAC5B,iCAAiC,EACjC,cAAc,EACd,gBAAgB,EACjB,MAAM,0BAA0B,CAAA;AAGjC,MAAM,MAAM,aAAa,GACrB,YAAY,GACZ,WAAW,GACX,cAAc,GACd,aAAa,GACb,QAAQ,GACR,WAAW,GACX,aAAa,GACb,aAAa,CAAA;AAGjB,MAAM,WAAW,mBAAmB;IAElC,WAAW,EAAE,MAAM,CAAA;IAEnB,SAAS,EAAE,MAAM,CAAA;IAEjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IAEvB,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAE5B,aAAa,CAAC,EAAE,aAAa,CAAA;IAE7B,OAAO,CAAC,EAAE,mBAAmB,CAAA;IAE7B,MAAM,CAAC,EAAE,aAAa,CAAA;IAEtB,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAGD,MAAM,WAAW,aAAa;IAE5B,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAGD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,OAAO,GAAG,IAAI,CAA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,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9D,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,WAAW,CAAA;IACzD,qBAAqB,CAAC,IAAI,EAAE,iCAAiC,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAA;IAC3G,gBAAgB,CAAC,IAAI,CAAC,EAAE,4BAA4B,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAA;IAC7F,iBAAiB,CAAC,IAAI,EAAE,6BAA6B,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAA;IAC/F,gBAAgB,CAAC,IAAI,EAAE,4BAA4B,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAA;IAC5F,mBAAmB,CAAC,IAAI,EAAE,+BAA+B,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAA;CACtG"}
|
package/dist/types.js
ADDED
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ParameterValue, SupportedType, SqlParamInfo } from './types';
|
|
2
|
+
export declare const supportedTypes: SupportedType[];
|
|
3
|
+
export declare const error: (...err: any[]) => never;
|
|
4
|
+
export declare const parseSQL: (args: any[]) => string;
|
|
5
|
+
export declare const omit: <T extends Record<string, any>>(obj: T, values: string[]) => Partial<T>;
|
|
6
|
+
export declare const pick: <T extends Record<string, any>, K extends keyof T>(obj: T, values: K[]) => Pick<T, K>;
|
|
7
|
+
export declare const flatten: <T>(arr: T[][]) => T[];
|
|
8
|
+
export declare const getSqlParams: (sql: string) => Record<string, SqlParamInfo>;
|
|
9
|
+
export declare const getType: (val: ParameterValue) => SupportedType | null | undefined;
|
|
10
|
+
export declare const isDate: (val: any) => val is Date;
|
|
11
|
+
export declare const isDateString: (val: string) => boolean;
|
|
12
|
+
export declare const isTimeString: (val: string) => boolean;
|
|
13
|
+
export declare const isDecimalString: (val: string) => boolean;
|
|
14
|
+
export declare const isUUIDString: (val: string) => boolean;
|
|
15
|
+
export declare const isJSONString: (val: string) => boolean;
|
|
16
|
+
export declare const getTypeHint: (val: ParameterValue) => string | undefined;
|
|
17
|
+
export declare const formatToTimeStamp: (date: Date, treatAsLocalDate: boolean) => string;
|
|
18
|
+
export declare const formatFromTimeStamp: (value: string, treatAsLocalDate: boolean) => Date;
|
|
19
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAG1E,eAAO,MAAM,cAAc,EAAE,aAAa,EASzC,CAAA;AAGD,eAAO,MAAM,KAAK,GAAI,GAAG,KAAK,GAAG,EAAE,KAAG,KAErC,CAAA;AAGD,eAAO,MAAM,QAAQ,GAAI,MAAM,GAAG,EAAE,KAAG,MAKI,CAAA;AAG3C,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,EAAE,QAAQ,MAAM,EAAE,KAAG,OAAO,CAAC,CAAC,CACiC,CAAA;AAGzH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,CAAC,EAAE,QAAQ,CAAC,EAAE,KAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAInG,CAAA;AAGH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,KAAG,CAAC,EAA+C,CAAA;AAGxF,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CA8CrE,CAAA;AAID,eAAO,MAAM,OAAO,GAAI,KAAK,cAAc,KAAG,aAAa,GAAG,IAAI,GAAG,SAsBtD,CAAA;AAKf,eAAO,MAAM,MA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