lucid-extension-sdk 0.0.130 → 0.0.132

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.130",
3
+ "version": "0.0.132",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "sdk/index.js",
6
6
  "types": "sdk/index.d.ts",
@@ -54,6 +54,10 @@ export declare enum OnClickHandlerKeys {
54
54
  OpenBrowserWindow = "OpenBrowserWindow"
55
55
  }
56
56
  export declare const isOnClickHandlerKey: (x: unknown) => x is OnClickHandlerKeys;
57
+ export declare type ImageBadgeSettings = {
58
+ height: number;
59
+ width: number;
60
+ };
57
61
  export interface StencilConfig {
58
62
  /**
59
63
  * How should we generate the stencil/data graphic from the specified field value?
@@ -69,6 +73,21 @@ export interface StencilConfig {
69
73
  * by starting the string with "=", e.g. "=darken("#ffffff", 0.5)"
70
74
  */
71
75
  backgroundColor?: string;
76
+ /**
77
+ * For displayType values that support it, you may provide an override for the
78
+ * foreground color for this data. If this is not provided, the foreground color
79
+ * will default to grey.
80
+ *
81
+ * This may be provided as a literal color hex, e.g. "#00ff00ff" or as a formula
82
+ * by starting the string with "=", e.g. "=darken("#ffffff", 0.5)"
83
+ */
84
+ foregroundColor?: string;
85
+ /**
86
+ * For displayType values that support it, you may provide a height and a width
87
+ * for the image size. Images are 24px by 24px by default.
88
+ *
89
+ */
90
+ imageBadgeSettings?: ImageBadgeSettings;
72
91
  /**
73
92
  * If specified, the result of this formula (executed in the context of the data item
74
93
  * associated with this card) will be used instead of the raw field value when
@@ -114,6 +133,7 @@ export declare type SerializedLucidCardFieldDisplaySettings = {
114
133
  'StencilConfig'?: {
115
134
  /** Since renamed to displayType, but we can't change the serialized name */
116
135
  'getterKey': FieldDisplayType;
136
+ 'fg'?: string;
117
137
  'bg'?: string;
118
138
  'f'?: string;
119
139
  't'?: string;
@@ -121,6 +141,7 @@ export declare type SerializedLucidCardFieldDisplaySettings = {
121
141
  'h'?: HorizontalBadgePos;
122
142
  'v'?: VerticalBadgePos;
123
143
  'onClickHandlerKey'?: OnClickHandlerKeys;
144
+ 'imageBadgeSettings'?: ImageBadgeSettings;
124
145
  };
125
146
  };
126
147
  /** @ignore */
@@ -67,10 +67,12 @@ function serializeLucidCardFieldDisplaySettings(settings) {
67
67
  'f': settings.stencilConfig.valueFormula,
68
68
  't': settings.stencilConfig.tooltipFormula,
69
69
  'l': settings.stencilConfig.linkFormula,
70
+ 'fg': settings.stencilConfig.foregroundColor,
70
71
  'bg': settings.stencilConfig.backgroundColor,
71
72
  'h': settings.stencilConfig.horizontalPosition,
72
73
  'v': settings.stencilConfig.verticalPosition,
73
74
  'onClickHandlerKey': settings.stencilConfig.onClickHandlerKey,
75
+ 'imageBadgeSettings': settings.stencilConfig.imageBadgeSettings,
74
76
  },
75
77
  };
76
78
  }
@@ -83,10 +85,12 @@ function deserializeLucidCardFieldDisplaySettings(settings) {
83
85
  valueFormula: settings['StencilConfig']['f'],
84
86
  tooltipFormula: settings['StencilConfig']['t'],
85
87
  linkFormula: settings['StencilConfig']['l'],
88
+ foregroundColor: settings['StencilConfig']['fg'],
86
89
  backgroundColor: settings['StencilConfig']['bg'],
87
90
  horizontalPosition: settings['StencilConfig']['h'],
88
91
  verticalPosition: settings['StencilConfig']['v'],
89
92
  onClickHandlerKey: settings['StencilConfig']['onClickHandlerKey'],
93
+ imageBadgeSettings: settings['StencilConfig']['imageBadgeSettings'],
90
94
  },
91
95
  };
92
96
  }
@@ -30,6 +30,11 @@ export declare class DataConnectorRequestError extends Error {
30
30
  response: string;
31
31
  constructor(status: number, message: string, response: string);
32
32
  }
33
+ /** Thrown by any APIs the client didn't recognize when parsing */
34
+ export declare class DataConnectorResponseError extends Error {
35
+ response: string;
36
+ constructor(message: string, response: string);
37
+ }
33
38
  declare type ActionTypeForName<Name extends string, Asynchronous = boolean> = Name extends `${DataConnectorActionKeys.Patch}` ? ActionRequest<DataConnectorPatchAction, PatchChange[]> : Name extends `${DataConnectorActionKeys.UnbatchedPatch}` ? ActionRequest<DataConnectorPatchAction, PatchChange[]> : Name extends `${DataConnectorActionKeys.ManageWebhook}` ? ActionRequest<DataConnectorManageWebhookAction, Webhook> : ActionRequest<Asynchronous extends true ? DataConnectorAsynchronousAction : DataConnectorAction>;
34
39
  /** Factory class to define a bunch of action handlers. */
35
40
  export declare class DataConnector {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataConnector = exports.DataConnectorRequestError = exports.DataConnectorRunError = void 0;
3
+ exports.DataConnector = exports.DataConnectorResponseError = exports.DataConnectorRequestError = exports.DataConnectorRunError = void 0;
4
4
  const checks_1 = require("../core/checks");
5
5
  const action_1 = require("./actions/action");
6
6
  const dataconnectoractionkeys_1 = require("./actions/dataconnectoractionkeys");
@@ -29,6 +29,14 @@ class DataConnectorRequestError extends Error {
29
29
  }
30
30
  }
31
31
  exports.DataConnectorRequestError = DataConnectorRequestError;
32
+ /** Thrown by any APIs the client didn't recognize when parsing */
33
+ class DataConnectorResponseError extends Error {
34
+ constructor(message, response) {
35
+ super(message);
36
+ this.response = response;
37
+ }
38
+ }
39
+ exports.DataConnectorResponseError = DataConnectorResponseError;
32
40
  /** Factory class to define a bunch of action handlers. */
33
41
  class DataConnector {
34
42
  constructor(client) {
@@ -19,7 +19,7 @@ class DataConnectorClient {
19
19
  }
20
20
  /** Get a client for DataSource related requests to Lucid */
21
21
  getDataSourceClient(updateToken) {
22
- return new datasourceclient_1.DataSourceClient(`${this.urls.api}data/dataSource/update`, updateToken, this.fetchMethod);
22
+ return new datasourceclient_1.DataSourceClient(this.urls, updateToken, this.fetchMethod);
23
23
  }
24
24
  /** Get a validator to prove a given request came from Lucid */
25
25
  async getSignatureValidator() {
@@ -1,74 +1,26 @@
1
- import { SerializedFieldTypeDefinition } from '../core/data/fieldtypedefinition/fieldtypedefinition';
2
- import { SemanticKind } from '../core/data/fieldtypedefinition/semantickind';
3
- import type { FieldConstraintType } from '../core/data/serializedfield/serializedfielddefinition';
4
- import { SerializedFields } from '../core/data/serializedfield/serializedfields';
5
- import { JsonSerializable } from '../core/jsonserializable';
6
- import type { DataUpdateFilterType } from '../data/dataupdatefiltertype';
7
- import { FieldDefinition, SchemaDefinition } from '../data/schemadefinition';
8
- /**
9
- * Container for an update to a data source
10
- */
11
- export declare type DataSourceRequest = {
12
- /** The current update filter type associated with this request */
13
- updateFilterType?: DataUpdateFilterType;
14
- /** The name of the data source to be added or modified */
15
- dataSourceName: string;
16
- /** Collections to add or update to the data source */
17
- collections: Record<string, CollectionPatch>;
18
- };
19
- declare type SerializedFieldConstraintForApi = {
20
- 'type': FieldConstraintType;
21
- 'details'?: JsonSerializable;
22
- };
23
- declare type SerializedFieldDefinitionForApi = {
24
- 'name': string;
25
- 'type': SerializedFieldTypeDefinition;
26
- 'constraints': SerializedFieldConstraintForApi[];
27
- 'syncSchema'?: string;
28
- 'mapping'?: readonly SemanticKind[];
29
- };
30
- /**
31
- * A patch to a collection or the definition of a new collection to be added. If adding a new collection, a schema must
32
- * be provided. If modifying an existing collection, a schema may be omitted.
33
- **/
34
- export interface CollectionPatch {
35
- /**
36
- * If changing an existing schema only the following changes are allowed:
37
- *
38
- * 1. Adding a nullable field
39
- * 2. Promoting a type of a field to a union of types (`string` -> `string | number`)
40
- * 3. Adding a new variant to a union type (`string | number` -> `string | number | boolean`)
41
- *
42
- * * Removing a field is not allowed (just add `| null` and don't provide the field in patches anymore).
43
- * * Changing a type in a way that any existing legal value is no longer valid for that field is not allowed.
44
- */
45
- schema?: SchemaDefinition;
46
- /** The patch to apply to the collection */
47
- patch: {
48
- /**
49
- * Items to be added or changed in the collection. Mapping from item serialized primary key to
50
- * the sparse patch of the item. See FormattedPrimaryKey.forItem.
51
- **/
52
- items: Map<string, SerializedFields>;
53
- /** Items to remove from the collection, based on the same primary key algorithm. */
54
- itemsDeleted?: string[];
55
- };
56
- }
57
- /** @ignore */
58
- export declare function serializeFieldDefinitionForApi(field: FieldDefinition): SerializedFieldDefinitionForApi;
1
+ import { MetadataPatch, MetadataPatchResponse, MetadataRecord } from './datasourcemetadatatypes';
2
+ import { DataSourceRequest } from './datasourceupdatetypes';
59
3
  /**
60
4
  * Authenticated client for DataSource related requests to Lucid.
61
5
  */
62
6
  export declare class DataSourceClient {
63
- private url;
7
+ private urls;
64
8
  private updateToken;
65
9
  private fetchMethod;
66
- constructor(url: string, updateToken: string, fetchMethod?: import("./defaultfetchfunction").GlobalFetchType);
10
+ private readonly metadataUrl;
11
+ constructor(urls: {
12
+ main: string;
13
+ api: string;
14
+ }, updateToken: string, fetchMethod?: import("./defaultfetchfunction").GlobalFetchType);
67
15
  private formatBody;
68
16
  /** Create or update a datasource. If you create a new collection it must be fully specified in terms of schema and
69
17
  * and items. If it's just an update then the schema can be omitted (if unchanged) and items that already exist can
70
18
  * be partial.*/
71
19
  update(request: DataSourceRequest): Promise<void>;
20
+ /** @ignore until metadata endpoints are made part of the public API */
21
+ getMetadata(keys: string[]): Promise<MetadataRecord[]>;
22
+ /** @ignore until metadata endpoints are made part of the public API */
23
+ patchMetadata(patches: MetadataPatch[]): Promise<MetadataPatchResponse>;
72
24
  }
73
25
  /**
74
26
  * A version of the DataSourceClient that you can use for any automated tests of your data connector.
@@ -77,8 +29,15 @@ export declare class DataSourceClient {
77
29
  export declare class MockDataSourceClient extends DataSourceClient {
78
30
  /** Assign this to your mocked update function */
79
31
  gotUpdate: (request: DataSourceRequest) => void;
32
+ /** Assign this to your mocked update function */
33
+ gotMetadata: (keys: string[]) => MetadataRecord[];
34
+ /** Assign this to your mocked update function */
35
+ patchedMetadata: (patches: MetadataPatch[]) => MetadataPatchResponse;
80
36
  constructor();
81
37
  /** @ignore */
82
38
  update(request: DataSourceRequest): Promise<void>;
39
+ /** @ignore */
40
+ getMetadata(keys: string[]): Promise<MetadataRecord[]>;
41
+ /** @ignore */
42
+ patchMetadata(patches: MetadataPatch[]): Promise<MetadataPatchResponse>;
83
43
  }
84
- export {};
@@ -1,56 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MockDataSourceClient = exports.DataSourceClient = exports.serializeFieldDefinitionForApi = void 0;
4
- const fieldtypedefinition_1 = require("../core/data/fieldtypedefinition/fieldtypedefinition");
5
- const object_1 = require("../core/object");
3
+ exports.MockDataSourceClient = exports.DataSourceClient = void 0;
4
+ const checks_1 = require("../core/checks");
5
+ const validators_1 = require("../core/validators/validators");
6
+ const dataconnector_1 = require("./dataconnector");
7
+ const datasourcemetadatatypes_1 = require("./datasourcemetadatatypes");
8
+ const datasourceupdatetypes_1 = require("./datasourceupdatetypes");
6
9
  const defaultfetchfunction_1 = require("./defaultfetchfunction");
7
10
  const throwunsuccessful_1 = require("./throwunsuccessful");
8
- function serializeFieldConstraintForApi(constraint) {
9
- return {
10
- 'type': constraint.type,
11
- 'details': constraint.value,
12
- };
13
- }
14
- /** @ignore */
15
- function serializeFieldDefinitionForApi(field) {
16
- var _a;
17
- return {
18
- 'name': field.name,
19
- 'type': (0, fieldtypedefinition_1.serializeFieldTypeDefinition)(field.type),
20
- 'constraints': ((_a = field.constraints) !== null && _a !== void 0 ? _a : []).map((x) => serializeFieldConstraintForApi(x)),
21
- 'mapping': field.mapping,
22
- };
23
- }
24
- exports.serializeFieldDefinitionForApi = serializeFieldDefinitionForApi;
25
- function serializeSchemaForApi(schema) {
26
- return {
27
- 'fields': schema.fields.map((x) => serializeFieldDefinitionForApi(x)),
28
- 'primaryKey': schema.primaryKey,
29
- 'fieldLabelOverrides': schema.fieldLabels,
30
- };
31
- }
32
- function serializeCollectionPatch(patch) {
33
- var _a;
34
- return {
35
- 'schema': patch.schema && serializeSchemaForApi(patch.schema),
36
- 'itemsPatch': {
37
- 'items': (0, object_1.fromEntries)(patch.patch.items.entries()),
38
- 'itemsDeleted': (_a = patch.patch.itemsDeleted) !== null && _a !== void 0 ? _a : [],
39
- },
40
- };
41
- }
42
- const assertIsJustRenamed = () => undefined;
43
- assertIsJustRenamed();
44
- assertIsJustRenamed();
45
- assertIsJustRenamed();
46
11
  /**
47
12
  * Authenticated client for DataSource related requests to Lucid.
48
13
  */
49
14
  class DataSourceClient {
50
- constructor(url, updateToken, fetchMethod = defaultfetchfunction_1.globalFetch) {
51
- this.url = url;
15
+ constructor(urls, updateToken, fetchMethod = defaultfetchfunction_1.globalFetch) {
16
+ this.urls = urls;
52
17
  this.updateToken = updateToken;
53
18
  this.fetchMethod = fetchMethod;
19
+ const dataSyncUrl = urls.dataSync;
20
+ this.metadataUrl = (0, checks_1.isString)(dataSyncUrl) ? `${dataSyncUrl}dataSource/metadata` : undefined;
54
21
  }
55
22
  formatBody({ updateFilterType, dataSourceName, collections }) {
56
23
  const upstreamConfig = updateFilterType
@@ -62,7 +29,7 @@ class DataSourceClient {
62
29
  : {};
63
30
  const updateData = {};
64
31
  for (const collectionId in collections) {
65
- updateData[collectionId] = serializeCollectionPatch(collections[collectionId]);
32
+ updateData[collectionId] = (0, datasourceupdatetypes_1.serializeCollectionPatch)(collections[collectionId]);
66
33
  }
67
34
  return {
68
35
  'updateData': updateData,
@@ -74,7 +41,7 @@ class DataSourceClient {
74
41
  * and items. If it's just an update then the schema can be omitted (if unchanged) and items that already exist can
75
42
  * be partial.*/
76
43
  async update(request) {
77
- const response = await this.fetchMethod(this.url, {
44
+ const response = await this.fetchMethod(`${this.urls.api}data/dataSource/update`, {
78
45
  'method': 'POST',
79
46
  'headers': {
80
47
  'Content-Type': 'application/json',
@@ -94,6 +61,74 @@ class DataSourceClient {
94
61
  // return await response.text();
95
62
  // but lets avoid users trying to interpret the response
96
63
  }
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!');
68
+ }
69
+ const encodedKeys = keys.map(encodeURIComponent);
70
+ const urlWithParams = `${this.metadataUrl}?metadataKeys=${encodedKeys.join('&metadataKeys=')}`;
71
+ const response = await this.fetchMethod(urlWithParams, {
72
+ 'method': 'GET',
73
+ 'headers': {
74
+ 'Content-Type': 'application/json',
75
+ 'data-update-token': this.updateToken,
76
+ 'Lucid-Api-Version': '1',
77
+ },
78
+ });
79
+ await (0, throwunsuccessful_1.throwUnsuccessful)(response, 'Error getting data source`s metadata');
80
+ const responseBody = await response.json();
81
+ 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
+ });
88
+ }
89
+ else {
90
+ throw new dataconnector_1.DataConnectorResponseError(`Invalid response to query at '${urlWithParams}'! Expected an array of serialized metadata records`, JSON.stringify(responseBody));
91
+ }
92
+ }
93
+ /** @ignore until metadata endpoints are made part of the public API */
94
+ async patchMetadata(patches) {
95
+ if (this.metadataUrl == null) {
96
+ throw new Error('Attempted to access data sync service metadata endpoints in environment where the URL does not exist!');
97
+ }
98
+ const serializedPatches = patches.map((patch) => {
99
+ return {
100
+ 'key': patch.key,
101
+ 'oldValue': patch.oldValue,
102
+ 'newValue': patch.newValue,
103
+ };
104
+ });
105
+ const response = await this.fetchMethod(this.metadataUrl, {
106
+ 'method': 'PATCH',
107
+ 'headers': {
108
+ 'Content-Type': 'application/json',
109
+ 'data-update-token': this.updateToken,
110
+ 'Lucid-Api-Version': '1',
111
+ },
112
+ body: JSON.stringify(serializedPatches),
113
+ });
114
+ if (response.status === 409) {
115
+ const responseBody = await response.json();
116
+ if ((0, validators_1.arrayValidator)(datasourcemetadatatypes_1.isSerializedMetadataRecord)(responseBody)) {
117
+ return {
118
+ status: 'Conflict',
119
+ records: responseBody.map((record) => {
120
+ return {
121
+ key: record['key'],
122
+ value: record['value'],
123
+ };
124
+ }),
125
+ };
126
+ }
127
+ throw new dataconnector_1.DataConnectorResponseError(`Invalid conflict response to query at '${this.metadataUrl}'! Expected an array of serialized metadata records`, JSON.stringify(responseBody));
128
+ }
129
+ await (0, throwunsuccessful_1.throwUnsuccessful)(response, 'Error patching data source`s metadata');
130
+ return { status: 'NoContent' };
131
+ }
97
132
  }
98
133
  exports.DataSourceClient = DataSourceClient;
99
134
  /**
@@ -102,15 +137,31 @@ exports.DataSourceClient = DataSourceClient;
102
137
  **/
103
138
  class MockDataSourceClient extends DataSourceClient {
104
139
  constructor() {
105
- super('', '');
140
+ super({ main: '', api: '' }, '');
106
141
  /** Assign this to your mocked update function */
107
142
  this.gotUpdate = (request) => {
108
143
  throw new Error(`Didn't mock request: ${JSON.stringify(request)}`);
109
144
  };
145
+ /** Assign this to your mocked update function */
146
+ this.gotMetadata = (request) => {
147
+ throw new Error(`Didn't mock request: ${JSON.stringify(request)}`);
148
+ };
149
+ /** Assign this to your mocked update function */
150
+ this.patchedMetadata = (request) => {
151
+ throw new Error(`Didn't mock request: ${JSON.stringify(request)}`);
152
+ };
110
153
  }
111
154
  /** @ignore */
112
155
  update(request) {
113
156
  return Promise.resolve(this.gotUpdate(request));
114
157
  }
158
+ /** @ignore */
159
+ getMetadata(keys) {
160
+ return Promise.resolve(this.gotMetadata(keys));
161
+ }
162
+ /** @ignore */
163
+ patchMetadata(patches) {
164
+ return Promise.resolve(this.patchedMetadata(patches));
165
+ }
115
166
  }
116
167
  exports.MockDataSourceClient = MockDataSourceClient;
@@ -0,0 +1,23 @@
1
+ import { isString, isUnknown } from '../core/checks';
2
+ export interface MetadataPatch {
3
+ key: string;
4
+ oldValue: unknown;
5
+ newValue: unknown;
6
+ }
7
+ export interface MetadataRecord {
8
+ key: string;
9
+ value: unknown;
10
+ }
11
+ export declare const isSerializedMetadataRecord: (subject: unknown) => subject is import("..").DestructureGuardedTypeObj<{
12
+ key: typeof isString;
13
+ value: typeof isUnknown;
14
+ }>;
15
+ interface NoContent {
16
+ status: 'NoContent';
17
+ }
18
+ interface Conflict {
19
+ status: 'Conflict';
20
+ records: MetadataRecord[];
21
+ }
22
+ export declare type MetadataPatchResponse = NoContent | Conflict;
23
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSerializedMetadataRecord = void 0;
4
+ const checks_1 = require("../core/checks");
5
+ const validators_1 = require("../core/validators/validators");
6
+ exports.isSerializedMetadataRecord = (0, validators_1.objectValidator)({
7
+ 'key': checks_1.isString,
8
+ 'value': checks_1.isUnknown,
9
+ });
@@ -0,0 +1,73 @@
1
+ import { SerializedFieldTypeDefinition } from '../core/data/fieldtypedefinition/fieldtypedefinition';
2
+ import { SemanticKind } from '../core/data/fieldtypedefinition/semantickind';
3
+ import { FieldConstraintType } from '../core/data/serializedfield/serializedfielddefinition';
4
+ import { SerializedFields } from '../core/data/serializedfield/serializedfields';
5
+ import { SerializedLabelOverrides } from '../core/data/serializedfield/serializedschema';
6
+ import { JsonSerializable } from '../core/jsonserializable';
7
+ import { DataUpdateFilterType } from '../data/dataupdatefiltertype';
8
+ import { FieldDefinition, SchemaDefinition } from '../data/schemadefinition';
9
+ /**
10
+ * Container for an update to a data source
11
+ */
12
+ export declare type DataSourceRequest = {
13
+ /** The current update filter type associated with this request */
14
+ updateFilterType?: DataUpdateFilterType;
15
+ /** The name of the data source to be added or modified */
16
+ dataSourceName: string;
17
+ /** Collections to add or update to the data source */
18
+ collections: Record<string, CollectionPatch>;
19
+ };
20
+ declare type SerializedFieldConstraintForApi = {
21
+ 'type': FieldConstraintType;
22
+ 'details'?: JsonSerializable;
23
+ };
24
+ declare type SerializedFieldDefinitionForApi = {
25
+ 'name': string;
26
+ 'type': SerializedFieldTypeDefinition;
27
+ 'constraints': SerializedFieldConstraintForApi[];
28
+ 'syncSchema'?: string;
29
+ 'mapping'?: readonly SemanticKind[];
30
+ };
31
+ declare type SerializedSchemaForApi = {
32
+ 'fields': SerializedFieldDefinitionForApi[];
33
+ 'primaryKey': string[];
34
+ 'fieldLabelOverrides'?: SerializedLabelOverrides | undefined;
35
+ };
36
+ export interface SerializedCollectionPatch {
37
+ 'schema'?: SerializedSchemaForApi;
38
+ 'itemsPatch': {
39
+ 'items': Record<string, SerializedFields>;
40
+ 'itemsDeleted': string[];
41
+ };
42
+ }
43
+ /**
44
+ * A patch to a collection or the definition of a new collection to be added. If adding a new collection, a schema must
45
+ * be provided. If modifying an existing collection, a schema may be omitted.
46
+ **/
47
+ export interface CollectionPatch {
48
+ /**
49
+ * If changing an existing schema only the following changes are allowed:
50
+ *
51
+ * 1. Adding a nullable field
52
+ * 2. Promoting a type of a field to a union of types (`string` -> `string | number`)
53
+ * 3. Adding a new variant to a union type (`string | number` -> `string | number | boolean`)
54
+ *
55
+ * * Removing a field is not allowed (just add `| null` and don't provide the field in patches anymore).
56
+ * * Changing a type in a way that any existing legal value is no longer valid for that field is not allowed.
57
+ */
58
+ schema?: SchemaDefinition;
59
+ /** The patch to apply to the collection */
60
+ patch: {
61
+ /**
62
+ * Items to be added or changed in the collection. Mapping from item serialized primary key to
63
+ * the sparse patch of the item. See FormattedPrimaryKey.forItem.
64
+ **/
65
+ items: Map<string, SerializedFields>;
66
+ /** Items to remove from the collection, based on the same primary key algorithm. */
67
+ itemsDeleted?: string[];
68
+ };
69
+ }
70
+ /** @ignore */
71
+ export declare function serializeFieldDefinitionForApi(field: FieldDefinition): SerializedFieldDefinitionForApi;
72
+ export declare function serializeCollectionPatch(patch: CollectionPatch): SerializedCollectionPatch;
73
+ export {};
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeCollectionPatch = exports.serializeFieldDefinitionForApi = void 0;
4
+ const fieldtypedefinition_1 = require("../core/data/fieldtypedefinition/fieldtypedefinition");
5
+ const object_1 = require("../core/object");
6
+ function serializeFieldConstraintForApi(constraint) {
7
+ return {
8
+ 'type': constraint.type,
9
+ 'details': constraint.value,
10
+ };
11
+ }
12
+ /** @ignore */
13
+ function serializeFieldDefinitionForApi(field) {
14
+ var _a;
15
+ return {
16
+ 'name': field.name,
17
+ 'type': (0, fieldtypedefinition_1.serializeFieldTypeDefinition)(field.type),
18
+ 'constraints': ((_a = field.constraints) !== null && _a !== void 0 ? _a : []).map((x) => serializeFieldConstraintForApi(x)),
19
+ 'mapping': field.mapping,
20
+ };
21
+ }
22
+ exports.serializeFieldDefinitionForApi = serializeFieldDefinitionForApi;
23
+ function serializeSchemaForApi(schema) {
24
+ return {
25
+ 'fields': schema.fields.map((x) => serializeFieldDefinitionForApi(x)),
26
+ 'primaryKey': schema.primaryKey,
27
+ 'fieldLabelOverrides': schema.fieldLabels,
28
+ };
29
+ }
30
+ function serializeCollectionPatch(patch) {
31
+ var _a;
32
+ return {
33
+ 'schema': patch.schema && serializeSchemaForApi(patch.schema),
34
+ 'itemsPatch': {
35
+ 'items': (0, object_1.fromEntries)(patch.patch.items.entries()),
36
+ 'itemsDeleted': (_a = patch.patch.itemsDeleted) !== null && _a !== void 0 ? _a : [],
37
+ },
38
+ };
39
+ }
40
+ exports.serializeCollectionPatch = serializeCollectionPatch;
41
+ const assertIsJustRenamed = () => undefined;
42
+ assertIsJustRenamed();
43
+ assertIsJustRenamed();
44
+ assertIsJustRenamed();
package/sdk/index.d.ts CHANGED
@@ -69,6 +69,8 @@ export * from './dataconnector/actions/serializedactions';
69
69
  export * from './dataconnector/dataconnector';
70
70
  export * from './dataconnector/dataconnectorclient';
71
71
  export * from './dataconnector/datasourceclient';
72
+ export * from './dataconnector/datasourcemetadatatypes';
73
+ export * from './dataconnector/datasourceupdatetypes';
72
74
  export * from './dataconnector/signaturevalidator';
73
75
  export * from './document/blockclasses/blockproxyregistry';
74
76
  export * from './document/blockclasses/cardblockproxy';
package/sdk/index.js CHANGED
@@ -85,6 +85,8 @@ __exportStar(require("./dataconnector/actions/serializedactions"), exports);
85
85
  __exportStar(require("./dataconnector/dataconnector"), exports);
86
86
  __exportStar(require("./dataconnector/dataconnectorclient"), exports);
87
87
  __exportStar(require("./dataconnector/datasourceclient"), exports);
88
+ __exportStar(require("./dataconnector/datasourcemetadatatypes"), exports);
89
+ __exportStar(require("./dataconnector/datasourceupdatetypes"), exports);
88
90
  __exportStar(require("./dataconnector/signaturevalidator"), exports);
89
91
  __exportStar(require("./document/blockclasses/blockproxyregistry"), exports);
90
92
  __exportStar(require("./document/blockclasses/cardblockproxy"), exports);