lucid-extension-sdk 0.0.149 → 0.0.152

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.
@@ -7,7 +7,7 @@ export declare function alphabetize(n: number): string;
7
7
  /** @ignore */
8
8
  export declare const MetadataPK = "__PK__";
9
9
  /** @ignore until spreadsheet integration is ready for launch (CHART-51946) */
10
- export declare function makeSerializedImportedCollection(id: string, name: string, rawSchema: string[], data: SerializedFields[], metadata?: {
10
+ export declare function makeSerializedImportedCollection(id: string, hash: string, name: string, rawSchema: string[], data: SerializedFields[], metadata?: {
11
11
  [key: string]: SerializedFields[];
12
12
  }): SerializedImportedCollection;
13
13
  /** @ignore until spreadsheet integration is ready for launch (CHART-51946) */
@@ -99,7 +99,7 @@ function makeSerializedItems(rawItems, oldToNewFields, isMetadata = false) {
99
99
  return serializedItems;
100
100
  }
101
101
  /** @ignore until spreadsheet integration is ready for launch (CHART-51946) */
102
- function makeSerializedImportedCollection(id, name, rawSchema, data, metadata) {
102
+ function makeSerializedImportedCollection(id, hash, name, rawSchema, data, metadata) {
103
103
  const { sheetSchema, oldToNewFields } = makeSchema(rawSchema);
104
104
  const metadataCollections = {};
105
105
  const itemOrderCollection = makeItemOrderCollection(data.length, name);
@@ -120,6 +120,7 @@ function makeSerializedImportedCollection(id, name, rawSchema, data, metadata) {
120
120
  'properties': {
121
121
  'UpstreamType': upstreamupdatetype_1.UpstreamUpdateType.EVENTPULL,
122
122
  'sheetId': id,
123
+ 'hash': hash,
123
124
  },
124
125
  },
125
126
  'Metadata': metadataCollections,
@@ -17,7 +17,6 @@ export declare const isSerializedImportedMetadataCollection: (subject: unknown)
17
17
  /** @ignore until spreadsheet integration is ready for launch (CHART-51946) */
18
18
  export interface SerializedImportedCollection {
19
19
  'Name': string;
20
- 'Id'?: string;
21
20
  'Schema': SerializedSchema;
22
21
  'Items': SerializedDataItems;
23
22
  'UpstreamConfig': {
@@ -13,3 +13,5 @@ export interface JsonObjectConvertible {
13
13
  * Any type that can be natively converted to a string with JSON.stringify.
14
14
  */
15
15
  export declare type JsonSerializable = undefined | null | string | number | boolean | JsonArray | JsonObject;
16
+ export declare function isJsonSerializable(x: unknown): x is JsonSerializable;
17
+ export declare function isJsonObject(x: unknown): x is JsonObject;
@@ -1,2 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isJsonObject = exports.isJsonSerializable = void 0;
4
+ const checks_1 = require("./checks");
5
+ function isJsonSerializable(x) {
6
+ return (x == null ||
7
+ (0, checks_1.isString)(x) ||
8
+ (0, checks_1.isNumber)(x) ||
9
+ (0, checks_1.isBoolean)(x) ||
10
+ ((0, checks_1.isArray)(x) && x.every(isJsonSerializable)) ||
11
+ isJsonObject(x));
12
+ }
13
+ exports.isJsonSerializable = isJsonSerializable;
14
+ function isJsonObject(x) {
15
+ if (!(0, checks_1.isObject)(x)) {
16
+ return false;
17
+ }
18
+ for (const k in x) {
19
+ if (!isJsonSerializable(x[k])) {
20
+ return false;
21
+ }
22
+ }
23
+ return true;
24
+ }
25
+ exports.isJsonObject = isJsonObject;
@@ -0,0 +1,11 @@
1
+ export interface Success<T> {
2
+ value: T;
3
+ }
4
+ export interface Failure<T> {
5
+ error: T;
6
+ }
7
+ export declare type Result<S, F> = Success<S> | Failure<F>;
8
+ export declare function isSuccess<S, F>(res: Result<S, F>): res is Success<S>;
9
+ export declare function isFailure<S, F>(res: Result<S, F>): res is Failure<F>;
10
+ export declare function groupByResultType<S, F>(results: Result<S, F>[]): [Success<S>[], Failure<F>[]];
11
+ export declare function isEqual<S, F>(a: Result<S, F> | undefined, b: Result<S, F> | undefined, valueCompS: (p1: S, p2: S) => boolean, valueCompF: (p1: F, p2: F) => boolean): boolean;
package/core/result.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEqual = exports.groupByResultType = exports.isFailure = exports.isSuccess = void 0;
4
+ const checks_1 = require("./checks");
5
+ function isSuccess(res) {
6
+ return (0, checks_1.isDef)(res.value);
7
+ }
8
+ exports.isSuccess = isSuccess;
9
+ function isFailure(res) {
10
+ return (0, checks_1.isDef)(res.error);
11
+ }
12
+ exports.isFailure = isFailure;
13
+ function groupByResultType(results) {
14
+ const successes = [];
15
+ const failures = [];
16
+ results.forEach((result) => {
17
+ if (isSuccess(result)) {
18
+ successes.push(result);
19
+ }
20
+ else {
21
+ failures.push(result);
22
+ }
23
+ });
24
+ return [successes, failures];
25
+ }
26
+ exports.groupByResultType = groupByResultType;
27
+ function isEqual(a, b, valueCompS, valueCompF) {
28
+ return ((!!a &&
29
+ !!b &&
30
+ ((isSuccess(a) && isSuccess(b) && valueCompS(a.value, b.value)) ||
31
+ (isFailure(a) && isFailure(b) && valueCompF(a.error, b.error)))) ||
32
+ a == b);
33
+ }
34
+ exports.isEqual = isEqual;
@@ -19,9 +19,10 @@ export declare type ImportedResults = {
19
19
  'collectionId': string;
20
20
  'headerRow': number;
21
21
  'schema': SerializedSchema;
22
- 'upstreamConfig': JsonSerializable;
22
+ 'upstreamConfig'?: JsonSerializable;
23
23
  }[];
24
24
  };
25
+ export declare const isImportedResults: (x: unknown) => x is ImportedResults;
25
26
  /** @ignore until spreadsheet integration is ready for launch (CHART-51946) */
26
27
  export declare abstract class LucidSpreadsheetIntegration<CONFIG extends JsonSerializable, SHEET extends JsonSerializable> {
27
28
  abstract labelDescription: string;
@@ -30,5 +31,5 @@ export declare abstract class LucidSpreadsheetIntegration<CONFIG extends JsonSer
30
31
  abstract getSpreadsheetDetailsToImport(): Promise<CONFIG | LucidSpreadsheetIntegrationFailureType>;
31
32
  abstract getMultipleSheetsForSpreadsheetDetails(spreadsheetDetails: CONFIG): Promise<Map<SHEET, string> | LucidSpreadsheetIntegrationFailureType>;
32
33
  abstract getSpreadsheetData(spreadsheetDetails: CONFIG, sheets: SHEET[]): Promise<SerializedImportedDataSource | LucidSpreadsheetIntegrationFailureType>;
33
- abstract importIsComplete(importedResults: ImportedResults): void;
34
+ abstract importIsComplete(syncDataSourceIdNonce: string, importedResults: ImportedResults): void;
34
35
  }
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LucidSpreadsheetIntegration = exports.lucidSpreadsheetIntegrationFailureTypeValidator = exports.LucidSpreadsheetIntegrationFailureType = void 0;
3
+ exports.LucidSpreadsheetIntegration = exports.isImportedResults = exports.lucidSpreadsheetIntegrationFailureTypeValidator = exports.LucidSpreadsheetIntegrationFailureType = void 0;
4
+ const checks_1 = require("../checks");
5
+ const serializedupstreamconfig_1 = require("../data/datasource/serializedupstreamconfig");
6
+ const serializedschema_1 = require("../data/serializedfield/serializedschema");
7
+ const jsonserializable_1 = require("../jsonserializable");
4
8
  const validators_1 = require("../validators/validators");
5
9
  /** @ignore until spreadsheet integration is ready for launch (CHART-51946) */
6
10
  var LucidSpreadsheetIntegrationFailureType;
@@ -11,6 +15,17 @@ var LucidSpreadsheetIntegrationFailureType;
11
15
  })(LucidSpreadsheetIntegrationFailureType = exports.LucidSpreadsheetIntegrationFailureType || (exports.LucidSpreadsheetIntegrationFailureType = {}));
12
16
  /** @ignore until spreadsheet integration is ready for launch (CHART-51946) */
13
17
  exports.lucidSpreadsheetIntegrationFailureTypeValidator = (0, validators_1.stringEnumValidator)(LucidSpreadsheetIntegrationFailureType);
18
+ exports.isImportedResults = (0, validators_1.strictObjectValidator)({
19
+ 'dataSourceId': checks_1.isString,
20
+ 'syncDataSourceId': checks_1.isString,
21
+ 'upstreamConfig': serializedupstreamconfig_1.isSerializedUpstreamConfig,
22
+ 'collections': (0, validators_1.arrayValidator)((0, validators_1.strictObjectValidator)({
23
+ 'collectionId': checks_1.isString,
24
+ 'headerRow': checks_1.isNumber,
25
+ 'schema': serializedschema_1.isSerializedSchema,
26
+ 'upstreamConfig': jsonserializable_1.isJsonSerializable,
27
+ })),
28
+ });
14
29
  /** @ignore until spreadsheet integration is ready for launch (CHART-51946) */
15
30
  class LucidSpreadsheetIntegration {
16
31
  }
@@ -44,7 +44,7 @@ class LucidSpreadsheetIntegrationRegistry {
44
44
  });
45
45
  const importIsCompleteActionName = LucidSpreadsheetIntegrationRegistry.nextHookName();
46
46
  client.registerAction(importIsCompleteActionName, async (message) => {
47
- spreadsheetIntegration.importIsComplete(message['ImportedResults']);
47
+ spreadsheetIntegration.importIsComplete(message['SyncDataSourceIdNonce'], message['ImportedResults']);
48
48
  });
49
49
  const serialized = {
50
50
  'ld': spreadsheetIntegration.labelDescription,
@@ -17,8 +17,22 @@ export declare class DataSourceClient {
17
17
  * and items. If it's just an update then the schema can be omitted (if unchanged) and items that already exist can
18
18
  * be partial.*/
19
19
  update(request: DataSourceRequest): Promise<void>;
20
+ /**
21
+ * When dealing with data, we can often have a very large number of collections in a single data source, and in
22
+ * turn, we may well end up get the values for a very large number of metadata values per collection.
23
+ * Because the endpoints for metadata use query params to encode the metadata names, and because metadata value
24
+ * reads can be easily parallelized, and because URLs have length limits, this function constructs an array of
25
+ * query params that are certain to be short enough that each individual query will be a safe length, while still
26
+ * getting *all* of the requested data.
27
+ * @param keys The metadata keys we are requesting from the data sync service for the corresponding data source.
28
+ * @param prefixes The metadata prefixes we are requesting from the data sync service for the corresponding data source.
29
+ * @returns An array of query params such that each query param is short enough to be safe, but all params combined
30
+ * cover all requested metadata.
31
+ */
32
+ private getLengthLimitedQueryParams;
33
+ private getResponseOrError;
20
34
  /** @ignore until metadata endpoints are made part of the public API */
21
- getMetadata(keys: string[]): Promise<MetadataRecord[]>;
35
+ getMetadata(keys: string[], prefixes?: string[]): Promise<MetadataRecord[]>;
22
36
  /** @ignore until metadata endpoints are made part of the public API */
23
37
  patchMetadata(patches: MetadataPatch[]): Promise<MetadataPatchResponse>;
24
38
  }
@@ -30,14 +44,14 @@ export declare class MockDataSourceClient extends DataSourceClient {
30
44
  /** Assign this to your mocked update function */
31
45
  gotUpdate: (request: DataSourceRequest) => void;
32
46
  /** Assign this to your mocked update function */
33
- gotMetadata: (keys: string[]) => MetadataRecord[];
47
+ gotMetadata: (keys: string[], prefixes: string[]) => MetadataRecord[];
34
48
  /** Assign this to your mocked update function */
35
49
  patchedMetadata: (patches: MetadataPatch[]) => MetadataPatchResponse;
36
50
  constructor();
37
51
  /** @ignore */
38
52
  update(request: DataSourceRequest): Promise<void>;
39
53
  /** @ignore */
40
- getMetadata(keys: string[]): Promise<MetadataRecord[]>;
54
+ getMetadata(keys: string[], prefixes?: string[]): Promise<MetadataRecord[]>;
41
55
  /** @ignore */
42
56
  patchMetadata(patches: MetadataPatch[]): Promise<MetadataPatchResponse>;
43
57
  }
@@ -2,12 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MockDataSourceClient = exports.DataSourceClient = void 0;
4
4
  const checks_1 = require("../core/checks");
5
+ const result_1 = require("../core/result");
5
6
  const validators_1 = require("../core/validators/validators");
6
7
  const dataconnector_1 = require("./dataconnector");
7
8
  const datasourcemetadatatypes_1 = require("./datasourcemetadatatypes");
8
9
  const datasourceupdatetypes_1 = require("./datasourceupdatetypes");
9
10
  const defaultfetchfunction_1 = require("./defaultfetchfunction");
10
11
  const throwunsuccessful_1 = require("./throwunsuccessful");
12
+ const QueryParamLengthLimit = 2000;
11
13
  /**
12
14
  * Authenticated client for DataSource related requests to Lucid.
13
15
  */
@@ -61,14 +63,42 @@ class DataSourceClient {
61
63
  // return await response.text();
62
64
  // but lets avoid users trying to interpret the response
63
65
  }
64
- /** @ignore until metadata endpoints are made part of the public API */
65
- async getMetadata(keys) {
66
- if (this.metadataUrl == null) {
67
- throw new Error('Attempted to access data sync service metadata endpoints in environment where the URL does not exist!');
66
+ /**
67
+ * When dealing with data, we can often have a very large number of collections in a single data source, and in
68
+ * turn, we may well end up get the values for a very large number of metadata values per collection.
69
+ * Because the endpoints for metadata use query params to encode the metadata names, and because metadata value
70
+ * reads can be easily parallelized, and because URLs have length limits, this function constructs an array of
71
+ * query params that are certain to be short enough that each individual query will be a safe length, while still
72
+ * getting *all* of the requested data.
73
+ * @param keys The metadata keys we are requesting from the data sync service for the corresponding data source.
74
+ * @param prefixes The metadata prefixes we are requesting from the data sync service for the corresponding data source.
75
+ * @returns An array of query params such that each query param is short enough to be safe, but all params combined
76
+ * cover all requested metadata.
77
+ */
78
+ getLengthLimitedQueryParams(keys, prefixes) {
79
+ const keyQueryParams = keys.map(encodeURIComponent).map((keyVal) => `metadataKeys=${keyVal}`);
80
+ const prefixQueryParams = prefixes.map(encodeURIComponent).map((prefixVal) => `metadataPrefixes=${prefixVal}`);
81
+ const fullQueryParams = [];
82
+ let currentQueryParam = '';
83
+ let delimiter = '?';
84
+ [...keyQueryParams, ...prefixQueryParams].forEach((param) => {
85
+ currentQueryParam = currentQueryParam.concat(`${delimiter}${param}`);
86
+ if (currentQueryParam.length > QueryParamLengthLimit) {
87
+ fullQueryParams.push(currentQueryParam);
88
+ currentQueryParam = '';
89
+ delimiter = '?';
90
+ }
91
+ else {
92
+ delimiter = '&';
93
+ }
94
+ });
95
+ if (currentQueryParam.length > 0) {
96
+ fullQueryParams.push(currentQueryParam);
68
97
  }
69
- const encodedKeys = keys.map(encodeURIComponent);
70
- const urlWithParams = `${this.metadataUrl}?metadataKeys=${encodedKeys.join('&metadataKeys=')}`;
71
- const response = await this.fetchMethod(urlWithParams, {
98
+ return fullQueryParams;
99
+ }
100
+ async getResponseOrError(url) {
101
+ const response = await this.fetchMethod(url, {
72
102
  'method': 'GET',
73
103
  'headers': {
74
104
  'Content-Type': 'application/json',
@@ -76,19 +106,57 @@ class DataSourceClient {
76
106
  'Lucid-Api-Version': '1',
77
107
  },
78
108
  });
79
- await (0, throwunsuccessful_1.throwUnsuccessful)(response, 'getting data source`s metadata');
109
+ try {
110
+ await (0, throwunsuccessful_1.throwUnsuccessful)(response, 'getting data source`s metadata');
111
+ }
112
+ catch (e) {
113
+ if (e instanceof dataconnector_1.DataConnectorResponseError) {
114
+ return { error: { url, body: e.response } };
115
+ }
116
+ throw e;
117
+ }
80
118
  const responseBody = await response.json();
81
119
  if ((0, validators_1.arrayValidator)(datasourcemetadatatypes_1.isSerializedMetadataRecord)(responseBody)) {
82
- return responseBody.map((rawResponse) => {
83
- return {
84
- key: rawResponse['key'],
85
- value: rawResponse['value'],
86
- };
87
- });
120
+ return {
121
+ value: responseBody.map((rawResponse) => {
122
+ return {
123
+ key: rawResponse['key'],
124
+ value: rawResponse['value'],
125
+ };
126
+ }),
127
+ };
88
128
  }
89
129
  else {
90
- throw new dataconnector_1.DataConnectorResponseError(`Invalid response to query at '${urlWithParams}'! Expected an array of serialized metadata records`, JSON.stringify(responseBody));
130
+ return {
131
+ error: { url, body: responseBody },
132
+ };
133
+ }
134
+ }
135
+ /** @ignore until metadata endpoints are made part of the public API */
136
+ async getMetadata(keys, prefixes = []) {
137
+ if (this.metadataUrl == null) {
138
+ throw new Error('Attempted to access data sync service metadata endpoints in environment where the URL does not exist!');
139
+ }
140
+ const queryParamsList = this.getLengthLimitedQueryParams(keys, prefixes);
141
+ const urlsWithParams = queryParamsList.map((query) => `${this.metadataUrl}${query}`);
142
+ const responsePromises = urlsWithParams.map((url) => this.getResponseOrError(url));
143
+ const responses = await Promise.all(responsePromises);
144
+ const records = [];
145
+ const errors = [];
146
+ responses.forEach((response) => {
147
+ if ((0, result_1.isSuccess)(response)) {
148
+ records.push(...response.value);
149
+ }
150
+ else {
151
+ errors.push(response.error);
152
+ }
153
+ });
154
+ if (errors.length > 0) {
155
+ const message = `Error(s) received accessing URL(s): ${errors.map(({ url }) => url).join(',')}`;
156
+ const allBodies = errors.map(({ body }) => body);
157
+ throw new dataconnector_1.DataConnectorResponseError(message, JSON.stringify(allBodies));
91
158
  }
159
+ return records;
92
160
  }
93
161
  /** @ignore until metadata endpoints are made part of the public API */
94
162
  async patchMetadata(patches) {
@@ -156,8 +224,8 @@ class MockDataSourceClient extends DataSourceClient {
156
224
  return Promise.resolve(this.gotUpdate(request));
157
225
  }
158
226
  /** @ignore */
159
- getMetadata(keys) {
160
- return Promise.resolve(this.gotMetadata(keys));
227
+ getMetadata(keys, prefixes = []) {
228
+ return Promise.resolve(this.gotMetadata(keys, prefixes));
161
229
  }
162
230
  /** @ignore */
163
231
  patchMetadata(patches) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.149",
3
+ "version": "0.0.152",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",