@syncmatters/script-api 1.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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -0
  3. package/api.d.ts +24 -0
  4. package/index.d.ts +3 -0
  5. package/index.js +1 -0
  6. package/lib/coded-error.d.ts +7 -0
  7. package/lib/connection.d.ts +597 -0
  8. package/lib/context.d.ts +58 -0
  9. package/lib/environment.d.ts +4 -0
  10. package/lib/logger.d.ts +20 -0
  11. package/lib/script-error.d.ts +38 -0
  12. package/lib/sync-group.d.ts +85 -0
  13. package/lib/sync.d.ts +392 -0
  14. package/lib/utilities/csv-reader/csv-reader-csv-parse.d.ts +16 -0
  15. package/lib/utilities/csv-reader/csv-reader-fast-csv.d.ts +15 -0
  16. package/lib/utilities/csv-reader/csv-reader.d.ts +2 -0
  17. package/lib/utilities/csv-reader/index.d.ts +2 -0
  18. package/lib/utilities/csv-reader/types.d.ts +48 -0
  19. package/lib/utilities/csv-writer/csv-writer.d.ts +21 -0
  20. package/lib/utilities/date-utils/date-utils.d.ts +37 -0
  21. package/lib/utilities/file-provider/file-provider-buffer.d.ts +11 -0
  22. package/lib/utilities/file-provider/file-provider-disk.d.ts +12 -0
  23. package/lib/utilities/file-provider/file-provider-string.d.ts +11 -0
  24. package/lib/utilities/file-provider/file-provider.d.ts +21 -0
  25. package/lib/utilities/file-utils/file-utils.d.ts +8 -0
  26. package/lib/utilities/html-utils/html-utils.d.ts +1 -0
  27. package/lib/utilities/http-client/fetch-http-client.d.ts +7 -0
  28. package/lib/utilities/http-client/fetch-http-error.d.ts +14 -0
  29. package/lib/utilities/http-client/types.d.ts +62 -0
  30. package/lib/utilities/json-utils/index.d.ts +6 -0
  31. package/lib/utilities/json-utils/json-changed-checker.d.ts +15 -0
  32. package/lib/utilities/json-utils/json-hash.d.ts +4 -0
  33. package/lib/utilities/json-utils/json-values-reader.d.ts +13 -0
  34. package/lib/utilities/json-utils/json-values-types.d.ts +41 -0
  35. package/lib/utilities/json-utils/json-values-writer.d.ts +28 -0
  36. package/lib/utilities/json-utils/lossless-numbers.d.ts +6 -0
  37. package/lib/utilities/json-utils/paths.d.ts +8 -0
  38. package/lib/utilities/kv-store/better-sqlite3/kv-collection-better-sqlite3.d.ts +18 -0
  39. package/lib/utilities/kv-store/better-sqlite3/kv-iterator-better-sqlite3.d.ts +26 -0
  40. package/lib/utilities/kv-store/better-sqlite3/kv-store-better-sqlite3.d.ts +11 -0
  41. package/lib/utilities/kv-store/index.d.ts +4 -0
  42. package/lib/utilities/kv-store/kv-store-benchmark-helpers.d.ts +14 -0
  43. package/lib/utilities/kv-store/shadow/kv-store-shadow.d.ts +29 -0
  44. package/lib/utilities/kv-store/sqlite3/database-sqlite3.d.ts +16 -0
  45. package/lib/utilities/kv-store/sqlite3/kv-collection-sqlite3.d.ts +18 -0
  46. package/lib/utilities/kv-store/sqlite3/kv-iterator-sqlite3.d.ts +21 -0
  47. package/lib/utilities/kv-store/sqlite3/kv-store-sqlite3.d.ts +11 -0
  48. package/lib/utilities/kv-store/sqlite3/statement-sqlite3.d.ts +13 -0
  49. package/lib/utilities/kv-store/types.d.ts +20 -0
  50. package/lib/utilities/name-parser/name-parser.d.ts +6 -0
  51. package/lib/utilities/rate-limiter/rate-limiter-concurrent.d.ts +24 -0
  52. package/lib/utilities/rate-limiter/rate-limiter-rolling.d.ts +18 -0
  53. package/lib/utilities/rate-limiter/rate-limiter.d.ts +15 -0
  54. package/lib/utilities/type-utils/type-utils.d.ts +11 -0
  55. package/lib/utilities/upsert-flags/upsert-flags.d.ts +10 -0
  56. package/lib/utilities/utilities.d.ts +105 -0
  57. package/lib/utilities/www-utils/www-utils.d.ts +14 -0
  58. package/lib/utilities/xlsx-reader/xlsx-reader.d.ts +32 -0
  59. package/lib/utilities/xlsx-writer/xlsx-writer.d.ts +23 -0
  60. package/lib/utilities/xml-utils/xml-utils.d.ts +1 -0
  61. package/lib/utilities/zip-utils/zip-utils.d.ts +29 -0
  62. package/package.json +23 -0
  63. package/sdk-test/sdk-test.d.ts +451 -0
  64. package/sdk-test.d.ts +3 -0
@@ -0,0 +1,38 @@
1
+ import { CodedError } from "./coded-error.js";
2
+ export declare enum ErrorCode {
3
+ None = "SCRIPT_NONE" /** default */,
4
+ InvalidOptionValue = "SCRIPT_INVALID_OPTION_VALUE",
5
+ InvalidArgumentValue = "SCRIPT_INVALID_ARG_VALUE",
6
+ InvalidConnectionId = "SCRIPT_INVALID_CONNECTION_ID",
7
+ InvalidConnectorCode = "SCRIPT_INVALID_CONNECTOR_CODE",
8
+ InvalidScriptCode = "SCRIPT_INVALID_SCRIPT_CODE",
9
+ InvalidObjectId = "SCRIPT_INVALID_OBJECT_ID",
10
+ InvalidIndexFilterValue = "SCRIPT_INVALID_INDEX_FILTER_VALUE",
11
+ InvalidCacheRowKeys = "SCRIPT_INVALID_CACHE_ROW_KEYS",
12
+ InvalidCachePageFormat = "SCRIPT_INVALID_CACHE_PAGE_FORMAT",
13
+ InvalidCacheStateProperty = "SCRIPT_INVALID_CACHE_STATE_PROPERTY",
14
+ InvalidFilePath = "SCRIPT_INVALID_FILE_PATH",
15
+ InvalidRelationshipId = "SCRIPT_INVALID_RELATIONSHIP_ID",
16
+ InvalidRelationshipType = "SCRIPT_INVALID_RELATIONSHIP_TYPE",
17
+ ResourceAlreadyClosed = "SCRIPT_RESOURCE_ALREADY_CLOSED",
18
+ InvalidEmailRecipients = "SCRIPT_INVALID_EMAIL_RECIPIENTS",
19
+ InvalidEmailSubject = "SCRIPT_INVALID_EMAIL_SUBJECT",
20
+ InvalidEmailBody = "SCRIPT_INVALID_EMAIL_BODY",
21
+ InvalidEmailAttachment = "SCRIPT_INVALID_EMAIL_ATTACHMENT",
22
+ InvalidSyncConfiguration = "SCRIPT_INVALID_SYNC_CONFIGURATION",
23
+ InvalidJsonPath = "SCRIPT_INVALID_JSON_PATH",
24
+ InvalidTimeZone = "SCRIPT_INVALID_TIME_ZONE",
25
+ ChildSyncFailure = "SCRIPT_CHILD_SYNC_FAILURE",
26
+ ColumnNotFound = "SCRIPT_COLUMN_NOT_FOUND",
27
+ UnexpectedRowCount = "SCRIPT_UNEXPECTED_ROW_COUNT",
28
+ UnexpectedRowId = "SCRIPT_UNEXPECTED_ROW_ID",
29
+ KvStoreShadowMismatch = "SCRIPT_KV_STORE_SHADOW_MISMATCH"
30
+ }
31
+ /**
32
+ * ConnectorError extends error to expose a meaningful error code e.g.
33
+ * const err = new ScriptError(ErrorCode.InvalidConnectionId, "supplied connectionId was not found");
34
+ */
35
+ export declare class ScriptError extends Error implements CodedError {
36
+ readonly code: string;
37
+ constructor(code: ErrorCode, message?: any);
38
+ }
@@ -0,0 +1,85 @@
1
+ /** Details of a source row and the related destination row */
2
+ export interface MatchedRowPair {
3
+ srcRowId: string;
4
+ destRowId?: string;
5
+ }
6
+ export interface SyncGroupProcessSourceRowsOptions {
7
+ /** Optionally run a selected subset of syncs (blank means run all) */
8
+ syncUids?: Array<string>;
9
+ /** Skip the post-standard-run retry of stored sync errors. Defaults to false. */
10
+ skipRetryErrors?: boolean;
11
+ }
12
+ export interface SyncGroupProcessBySourceIdsOptions {
13
+ /** Sync to run */
14
+ syncUid: string;
15
+ /** Source rows to pass through the selected sync */
16
+ sourceRowIds: Array<string>;
17
+ /** Force the destination record add/update, bypassing any filter */
18
+ force?: boolean;
19
+ }
20
+ export interface SyncGroupProcessErrorsOptions {
21
+ /** Sync to run */
22
+ syncUid: string;
23
+ /** Source rows to pass through the selected sync */
24
+ sourceRowIds?: Array<string>;
25
+ }
26
+ export interface SyncGroup {
27
+ /** Run the sync group to process list/changed source rows, optionally for just some of the syncs that belong to the group */
28
+ processSourceRows(options: SyncGroupProcessSourceRowsOptions): Promise<void>;
29
+ /** Run the sync group to process selected source rows though a specific sync */
30
+ processBySourceIds(options: SyncGroupProcessBySourceIdsOptions): Promise<Array<MatchedRowPair>>;
31
+ /** Run the sync group to process source rows that have errors through a specific sync */
32
+ processErrors(options: SyncGroupProcessErrorsOptions): Promise<void>;
33
+ /** Stored errors for the sync group */
34
+ storedErrors: SyncGroupStoredErrors;
35
+ /** Stored matches for the sync group */
36
+ storedMatches: SyncGroupStoredMatches;
37
+ /** Stored checkpoints for the sync group */
38
+ storedCheckpoints: SyncGroupStoredCheckpoints;
39
+ }
40
+ export interface SyncGroupStoredCheckpoints {
41
+ /** Clear stored checkpoints for a specific sync or set of syncs */
42
+ clear(options: SyncGroupStoredCheckpointsClearOptions): Promise<void>;
43
+ }
44
+ export interface SyncGroupStoredCheckpointsClearOptions {
45
+ /** Clear all checkpoints from all syncs? */
46
+ clearAll?: boolean;
47
+ /** Syncs to clear checkpoints for (if not clearing all) */
48
+ syncs?: Array<{
49
+ syncUid: string;
50
+ }>;
51
+ }
52
+ export interface SyncGroupStoredErrors {
53
+ /** Clear stored errors for a specific sync or set of syncs */
54
+ clear(options: SyncGroupStoredErrorsClearOptions): Promise<void>;
55
+ }
56
+ export interface SyncGroupStoredErrorsClearOptions {
57
+ /** Closed reason for the errors */
58
+ closedReason: string;
59
+ /** Clear all errors from all syncs? */
60
+ clearAll?: boolean;
61
+ /** Syncs to clear errors for (if not clearing all) */
62
+ syncs?: Array<{
63
+ syncUid: string;
64
+ sourceRowIds?: Array<string>;
65
+ }>;
66
+ }
67
+ export interface SyncGroupStoredMatches {
68
+ /** Clear stored matches for a specific sync or set of syncs */
69
+ clear(options: SyncGroupStoredMatchesClearOptions): Promise<void>;
70
+ }
71
+ export interface SyncGroupStoredMatchesClearOptions {
72
+ /** Clear all matches from all syncs? */
73
+ clearAll?: boolean;
74
+ /** Syncs to clear matches for (if not clearing all) */
75
+ syncs?: Array<{
76
+ syncUid: string;
77
+ sourceRowIds?: Array<string>;
78
+ }>;
79
+ }
80
+ export interface SyncGroupStoredMatchesListOptions {
81
+ /** Sync to list matches for */
82
+ syncUid: string;
83
+ /** Source rows to list matches for (blank means list all) */
84
+ sourceRowIds?: Array<string>;
85
+ }
package/lib/sync.d.ts ADDED
@@ -0,0 +1,392 @@
1
+ import { Row, QueryRelatedFilter, QueryMatchFilter, QueryCheckpointFilter, UpsertCleanOptions, UpsertCleanResponse, ObjectFieldConstraints, JsonValuePath, RowMatchRuleType, Logger, Connection } from "../index.js";
2
+ export type GroupRunMode = "Standard" | "SelectedIds" | "Errors";
3
+ export type SyncOptimalBatchSizeOperation = "noFilter" | "idsFilter" | "relatedFilter" | "matchFilter" | "checkpointFilter" | "randomFilter" | "rowFilter" | "upsert" | "delete";
4
+ export type SyncOptimalBatchSizeBatchType = "atomic" | "concurrent" | "splitInsertUpdateAtomic";
5
+ export interface SyncOptimalBatchSizeResponse {
6
+ size: number;
7
+ batchType?: SyncOptimalBatchSizeBatchType;
8
+ }
9
+ /** details passed to an endpoint when starting a session */
10
+ export interface SyncSession {
11
+ /** logger to use to capture data events */
12
+ log: Logger;
13
+ /** syncs endpoints that may exchange data during the session */
14
+ syncs: Array<SyncEndpointsSpecification>;
15
+ }
16
+ /** endpoints required by a sync */
17
+ export interface SyncEndpointsSpecification {
18
+ /** org unique id of the sync */
19
+ syncUid: string;
20
+ /** platform id of the sync */
21
+ syncId: string;
22
+ source: {
23
+ /** type of the source */
24
+ type: "connection" | "script";
25
+ /** org specific id of source endpoint */
26
+ sourceUid: string;
27
+ /** endpoint specific id for the object */
28
+ primaryObjectUid: string;
29
+ /** primary object fields the sync expects to receive in query response (for mapping) */
30
+ fields?: Array<JsonValuePath>;
31
+ /** other objects to be considered when querying for rows changed since a checkpoint */
32
+ relatedObjectTriggers?: Array<{
33
+ objectUid: string;
34
+ relationshipUid?: string;
35
+ }>;
36
+ /** objects & fields the sync expects to receive in query-related responses */
37
+ relatedObjects?: Array<{
38
+ relationshipUid: string;
39
+ fields?: Array<JsonValuePath>;
40
+ }>;
41
+ /** lookup objects & fields the sync expects to receive in query-by-id responses */
42
+ lookupObjects?: Array<{
43
+ lookupUid: string;
44
+ fields?: Array<JsonValuePath>;
45
+ }>;
46
+ };
47
+ destination: {
48
+ /** type of the destination */
49
+ type: "connection" | "script";
50
+ /** org specific id of destination endpoint */
51
+ destinationUid: string;
52
+ /** endpoint specific id for the object */
53
+ primaryObjectUid: string;
54
+ /** primary object fields the sync expects to receive in query response (for mapping) */
55
+ fields?: Array<JsonValuePath>;
56
+ /** lookup objects & fields the sync expects to receive in query-by-id responses */
57
+ lookupObjects?: Array<{
58
+ lookupUid: string;
59
+ fields?: Array<JsonValuePath>;
60
+ }>;
61
+ };
62
+ }
63
+ /** Enpdoints must impliment this interface to exchange data with syncs */
64
+ export interface SyncEndpoint {
65
+ /** called to allow an endpint to perform any required initialization */
66
+ sessionBegin(options: SyncSession): Promise<void>;
67
+ /** called [best effort] once all sync(s) have completed processing this sessions data */
68
+ sessionEnd(options: SyncSession): Promise<void>;
69
+ meta: {
70
+ /** retrieve details of the object on an endpoint */
71
+ objects: () => Promise<SyncEndpointObject[]>;
72
+ /** retrieve details of fields on an object */
73
+ fields: {
74
+ [uid: string]: () => Promise<SyncEndpointFields>;
75
+ };
76
+ /** retrieve details of relationships between object rows */
77
+ relationships: {
78
+ [uid: string]: (options: {
79
+ relationshipUids: Array<string>;
80
+ }) => Promise<Array<SyncEndpointObjectRelationship>>;
81
+ };
82
+ /** [optional] the endpoint can recommend a batch size to used when querying data */
83
+ optimalBatchSize: {
84
+ [uid: string]: (operation: SyncOptimalBatchSizeOperation, relatedFilter?: {
85
+ otherObjectId: string;
86
+ otherRelationshipId: string;
87
+ }, matchFilter?: RowMatchRuleType) => Promise<SyncOptimalBatchSizeResponse>;
88
+ };
89
+ };
90
+ /** query a stream of rows from the endpoint using standardized filters */
91
+ query: {
92
+ [uid: string]: (options: SyncQueryOptions) => SyncQueryResponse;
93
+ };
94
+ /** write a batch of rows to the endpoint */
95
+ upsert?: {
96
+ [uid: string]: (options: SyncUpsertOptions) => Promise<Row[]>;
97
+ };
98
+ /** write a batch of rows to the endpoint */
99
+ upsertClean?: {
100
+ [uid: string]: (options: SyncUpsertCleanOptions) => Promise<UpsertCleanResponse>;
101
+ };
102
+ /** delete a batch of rows from the destination endpoint */
103
+ delete?: {
104
+ [uid: string]: (options: SyncDeleteOptions) => Promise<void>;
105
+ };
106
+ /** the underlying connection that the endpoint is associated with */
107
+ connection?(): Connection;
108
+ }
109
+ /** describes a relationship between rows on an endpoint */
110
+ export interface SyncEndpointObjectRelationship {
111
+ /** unique id for the relationship from this object to the other object (must be unique on this object) */
112
+ uid: string;
113
+ /** display label for the relationship (defaults to the uid) */
114
+ name?: string;
115
+ /** object id of the other object that has a relationship to this object */
116
+ relObjectUid: string;
117
+ /** maximum number of rows on this object that may be returned when this relation is queried for a given row on this object */
118
+ cardinality: "OneToOne" | "OneToMany";
119
+ }
120
+ export interface SyncEndpointObject {
121
+ uid: string;
122
+ name?: string;
123
+ canQuery?: boolean;
124
+ canQueryByIds?: boolean;
125
+ canQueryByCheckpoint?: boolean;
126
+ canQueryList?: boolean;
127
+ canUpsert?: boolean;
128
+ canDelete?: boolean;
129
+ canUpsertClean?: boolean;
130
+ canUpsertFieldOptions?: boolean;
131
+ canAddCustomRelationships?: boolean;
132
+ isCustom?: boolean;
133
+ matchRules?: RowMatchRuleType[];
134
+ }
135
+ /** data type of a field on an endpoint */
136
+ export type SyncEndpointFieldDataType = "string" | "boolean" | "number" | "object" | "array" | "any";
137
+ /** describes a field on an endpoint */
138
+ export interface SyncEndpointField {
139
+ /** full path to the field value in dot notation */
140
+ path: string;
141
+ /** unique id for the field */
142
+ uid: string;
143
+ /** display label for the (defaults to the uid) */
144
+ name?: string;
145
+ /** sort order of the field */
146
+ order?: string;
147
+ /** data type of the field */
148
+ type: SyncEndpointFieldDataType;
149
+ /** for array fields, this defines the data type of each array element*/
150
+ arrayType?: SyncEndpointFieldDataType;
151
+ /** for option/picklist fields, these define the allowed values */
152
+ optionValues?: SyncEndpointFieldOptionValue[];
153
+ /** for option/picklist fields, can the option values be added to / updated? */
154
+ canUpdateOptions?: boolean;
155
+ /** field constraints */
156
+ constraints?: SyncEndpointFieldConstraints;
157
+ /** can this field be referenced in match rules? */
158
+ canMatch?: boolean;
159
+ /** indicates whether this field has child fields */
160
+ hasChildren?: boolean;
161
+ /** indicates this field holds the unique row id required when updating existing rows */
162
+ isId?: boolean;
163
+ /** indicates this field holds an object containing the user defined unique row identifier required
164
+ * for add and update operations, with an indication of the operation type */
165
+ isUserDefinedId?: boolean;
166
+ /** indicates this field is custom */
167
+ isCustom?: boolean;
168
+ }
169
+ export interface SyncEndpointFieldConstraints extends ObjectFieldConstraints {
170
+ }
171
+ /** describes an picklist option on an endpoint field */
172
+ export interface SyncEndpointFieldOptionValue {
173
+ /** system specific unique id to use when referencing the option (insert/update/query) */
174
+ uid: string;
175
+ /** display label (defaults to the uid) */
176
+ name?: string;
177
+ }
178
+ /** describes fields present on an endpoint object */
179
+ export interface SyncEndpointFields {
180
+ queryFields?: SyncEndpointField[];
181
+ queryFile?: boolean;
182
+ upsertFields?: SyncEndpointField[];
183
+ deleteFields?: SyncEndpointField[];
184
+ }
185
+ /** Sync passes these options to the endpoint when executing a query */
186
+ export interface SyncQueryOptions {
187
+ /** logger to use to capture data events */
188
+ log: Logger;
189
+ /** limit the number of rows to return */
190
+ limit?: number;
191
+ /** include any file associated with each row? */
192
+ file?: boolean;
193
+ /** fields expected in the response */
194
+ fields?: Array<JsonValuePath>;
195
+ /** include fields needed to collect rows from selected relationships */
196
+ relationshipFields?: Array<string>;
197
+ /** retrieve a random sample of up to 'limit' records */
198
+ randomFilter?: boolean;
199
+ /** filter for rows by row id (key) */
200
+ idsFilter?: Array<string>;
201
+ /** filter for rows that relate to another objects rows on this endpoint */
202
+ relatedFilter?: QueryRelatedFilter;
203
+ /** filter for rows that meet a specific matching rule */
204
+ matchFilter?: QueryMatchFilter;
205
+ /** collect records changed since a particular checkpoint */
206
+ checkpointFilter?: QueryCheckpointFilter;
207
+ /** row filter options are system-specific and may extend the standard query options */
208
+ rowFilter?: unknown;
209
+ }
210
+ /** Expected response from a sync query */
211
+ export interface SyncQueryResponse {
212
+ rows: AsyncIterableIterator<Row>;
213
+ checkpoint?(): Promise<string | undefined>;
214
+ }
215
+ /** Sync passes these options to the endpoint when performing an upsert */
216
+ export interface SyncUpsertOptions {
217
+ /** logger to use to capture data events */
218
+ log: Logger;
219
+ /** rows to send */
220
+ rows: Array<unknown>;
221
+ }
222
+ /** SyncUpsertCleanOptions holds the upsert record and options to control the process. */
223
+ export interface SyncUpsertCleanOptions extends UpsertCleanOptions {
224
+ /** logger to use to capture data events */
225
+ log: Logger;
226
+ }
227
+ /** Sync passes these options to the endpoint when performing a delete */
228
+ export interface SyncDeleteOptions {
229
+ /** logger to use to capture data events */
230
+ log: Logger;
231
+ /** rows to send */
232
+ rows: Array<unknown>;
233
+ }
234
+ /**
235
+ * SyncLogic holds custom logic to run as rows are passed through a sync.
236
+ */
237
+ export interface SyncLogic {
238
+ /** Execute custom logic before the sync runs */
239
+ beforeRun?(ctx: SyncLogicBeforeRunContext): Promise<void>;
240
+ /** Inspect a source row with previously matched destination row and return true to include in further processing. */
241
+ filterFast?(ctx: SyncLogicFilterFastContext): Promise<boolean>;
242
+ /**
243
+ * Inspect a source row with selected related rows, previously matched destination row and return true to include
244
+ * in further processing
245
+ * */
246
+ filterRelated?(ctx: SyncLogicFilterRelatedContext): Promise<boolean>;
247
+ /**
248
+ * Inspect a source row and matched destination rows. Filter and order the matched candidates to reject and/or prioritize
249
+ * preferred matches. The returned candidates will be checked, in returned order, and if not already matched to a different
250
+ * source row they will be selected as the best match.
251
+ */
252
+ reviewMatches?(ctx: SyncLogicSelectMatchContext): Promise<Array<unknown>>;
253
+ /**
254
+ * Inspect a source row with selected related rows, previously/new matched destination row and return true to include
255
+ * in further processing
256
+ * */
257
+ filterMatched?(ctx: SyncLogicFilterMatchedContext): Promise<boolean>;
258
+ /**
259
+ * Receive the source row, related rows (if any) and output row (if linked) and produce calculated field values for mapping.
260
+ */
261
+ calculate?(ctx: SyncLogicCalcContext): Promise<void>;
262
+ }
263
+ /** Defines how system fields are presented to the sync logic */
264
+ export interface SyncSystemFields {
265
+ /** indicates that the source data is an array rather than an endpoint row */
266
+ sourceIsArrayElement?: boolean;
267
+ /** array element index (blank when not processing an array extracted from a source field) */
268
+ sourceArrayIndex?: number;
269
+ /** id of the primary source row being processed (blank if processing an array element) */
270
+ sourceRowId?: string;
271
+ /** id of the primary dest row being updated (blank if matched to an array element) */
272
+ matchedRowId?: string;
273
+ /** id of the unmatched dest row being processed (for loop related output) */
274
+ unmatchedArrayRowId?: string;
275
+ /** for looping syncs, id of the primary source row being processed */
276
+ parentSourceRowId?: string;
277
+ /** for looping syncs, id of the primary parent dest row being updated */
278
+ parentMatchedRowId?: string;
279
+ }
280
+ /** Defines how related rows are presented to the sync logic */
281
+ export interface SyncRelatedFields {
282
+ [relUid: string]: unknown | Array<unknown>;
283
+ }
284
+ /** Defines how lookup results are presented to the sync logic */
285
+ export interface SyncLookupFields {
286
+ [lookupUid: string]: unknown | Array<unknown>;
287
+ }
288
+ /** Defines how calculated fields are presented to the sync logic */
289
+ export interface SyncCalculatedFields {
290
+ [fieldId: string]: unknown;
291
+ }
292
+ /** Context passed to custom sync logic when executing before the sync runs */
293
+ export interface SyncLogicBeforeRunContext {
294
+ /** the mode of the sync group run */
295
+ groupRunMode: GroupRunMode;
296
+ /** logger to use to capture data events */
297
+ readonly log: Logger;
298
+ /** the source connection */
299
+ readonly srcConn?: () => Promise<Connection>;
300
+ /** the destination connection */
301
+ readonly destConn?: () => Promise<Connection>;
302
+ /** user (custom logic) defined state */
303
+ state: {
304
+ get(): Promise<unknown>;
305
+ set(state?: unknown): Promise<void>;
306
+ };
307
+ /** differential query checkpoints (if any) that will be used when the sync queries for rows */
308
+ checkpoint?: {
309
+ value: string | undefined;
310
+ relatedTriggers?: Array<{
311
+ objectUid: string;
312
+ relationshipUid: string;
313
+ value: string | undefined;
314
+ }>;
315
+ };
316
+ }
317
+ /** Context passed to custom sync logic when evaluating whether the src row should be excluded from processing */
318
+ export interface SyncLogicFilterFastContext {
319
+ /** system fields relevant to the src row */
320
+ readonly system: SyncSystemFields;
321
+ /** the source row being passed through the sync */
322
+ readonly src: unknown;
323
+ /** parent primary source row when processing a loop array element */
324
+ readonly parent?: unknown;
325
+ /** the destination row that the src row was previously matched with, if any */
326
+ readonly dest?: unknown;
327
+ /** the caller requests that, if possible, filters be bypassed */
328
+ force?: boolean;
329
+ }
330
+ /** Context passed to custom sync logic when evaluating whether the src row should be excluded from processing */
331
+ export interface SyncLogicFilterRelatedContext {
332
+ /** system fields relevant to the src row */
333
+ readonly system: SyncSystemFields;
334
+ /** the source row being passed through the sync */
335
+ readonly src: unknown;
336
+ /** parent primary source row when processing a loop array element */
337
+ readonly parent?: unknown;
338
+ /** rows related to the src row from relationships selected for this sync */
339
+ readonly related?: SyncRelatedFields;
340
+ /** the destination row that the src row was previously matched with, if any */
341
+ readonly dest?: unknown;
342
+ /** the caller requests that, if possible, filters be bypassed */
343
+ force?: boolean;
344
+ }
345
+ /** Context passed to custom sync logic when evaluating whether the src row should be excluded from processing */
346
+ export interface SyncLogicFilterMatchedContext {
347
+ /** system fields relevant to the src row */
348
+ readonly system: SyncSystemFields;
349
+ /** the source row being passed through the sync */
350
+ readonly src: unknown;
351
+ /** parent primary source row when processing a loop array element */
352
+ readonly parent?: unknown;
353
+ /** rows related to the src row from relationships selected for this sync */
354
+ readonly related?: SyncRelatedFields;
355
+ /** rows related to the src row from lookups defined on this sync */
356
+ readonly lookups?: SyncLookupFields;
357
+ /** the destination row that the src row has been matched with, if any */
358
+ readonly dest?: unknown;
359
+ /** the caller requests that, if possible, filters be bypassed */
360
+ force?: boolean;
361
+ }
362
+ /** Context passed to custom sync logic when evaluating which, if any, matched destination row should be selected */
363
+ export interface SyncLogicSelectMatchContext {
364
+ /** specification of the match rule that matched the src row to the candidates */
365
+ ruleSpec: {
366
+ /** the index of this match rule (0 is first) */
367
+ index: number;
368
+ /** the type of this match rule */
369
+ type: RowMatchRuleType;
370
+ };
371
+ /** the source row to match */
372
+ readonly src: unknown;
373
+ /** the candidate destination rows to match, sorted as per any user defined sort rules */
374
+ readonly candidates: Array<unknown>;
375
+ }
376
+ /** Context passed to custom sync logic when calculating custom field values */
377
+ export interface SyncLogicCalcContext {
378
+ /** system fields relevant to the src row */
379
+ readonly system: SyncSystemFields;
380
+ /** the source row being passed through the sync */
381
+ readonly src: unknown;
382
+ /** parent primary source row when processing a loop array element */
383
+ readonly parent?: unknown;
384
+ /** rows related to the src row from relationships selected for this sync */
385
+ readonly related?: SyncRelatedFields;
386
+ /** rows related to the src row from lookups defined on this sync */
387
+ readonly lookups?: SyncLookupFields;
388
+ /** the object to populate with calculated values for reference in the mapping phase */
389
+ calculated: SyncCalculatedFields;
390
+ /** the destination row that the src is matched with, if any */
391
+ readonly dest?: unknown;
392
+ }
@@ -0,0 +1,16 @@
1
+ import { CsvReader, CsvReaderOptions } from "./types.js";
2
+ /**
3
+ * {@link CsvReader} using csv-parse: consume the parser as a Node async iterable instead of
4
+ * pause/resume + manual promises (same outcome as the fast-csv implementation, less machinery).
5
+ */
6
+ export declare class CsvReaderCsvParse implements CsvReader {
7
+ #private;
8
+ constructor(options: CsvReaderOptions);
9
+ header(): Promise<string[]>;
10
+ jsDoc(): Promise<string>;
11
+ verifyHeader(required: string[]): Promise<void>;
12
+ rows(): AsyncIterableIterator<any>;
13
+ rowsWithProps(): AsyncIterableIterator<{
14
+ [name: string]: string;
15
+ }>;
16
+ }
@@ -0,0 +1,15 @@
1
+ import { CsvReader, CsvReaderOptions } from "./types.js";
2
+ /**
3
+ * CsvReader implements the CsvReader interface using the fast-csv library.
4
+ */
5
+ export declare class CsvReaderFastCsv implements CsvReader {
6
+ #private;
7
+ constructor(options: CsvReaderOptions);
8
+ header(): Promise<string[]>;
9
+ jsDoc(): Promise<string>;
10
+ verifyHeader(required: string[]): Promise<void>;
11
+ rows(): AsyncIterableIterator<any>;
12
+ rowsWithProps(): AsyncIterableIterator<{
13
+ [name: string]: string;
14
+ }>;
15
+ }
@@ -0,0 +1,2 @@
1
+ import { CsvReader, CsvReaderOptions } from "./types.js";
2
+ export declare function createCsvReader(options: CsvReaderOptions): CsvReader;
@@ -0,0 +1,2 @@
1
+ export * from "./csv-reader.js";
2
+ export * from "./types.js";
@@ -0,0 +1,48 @@
1
+ import { FileProvider } from "../file-provider/file-provider.js";
2
+ /**
3
+ * Options for the CsvReader
4
+ */
5
+ export interface CsvReaderOptions {
6
+ /** source for the csv data */
7
+ source: {
8
+ /** read the data from a fileProvider */
9
+ fileProvider?: FileProvider;
10
+ /** read the data from a string */
11
+ string?: string;
12
+ /** read the data from a ReadableStream */
13
+ stream?: NodeJS.ReadableStream;
14
+ };
15
+ /** indicate whether a header line is absent */
16
+ noHeader?: boolean;
17
+ /**
18
+ * indicate whether to include empty rows/columns with whitespace
19
+ */
20
+ includeEmpty?: boolean;
21
+ /** delimiter that will separate columns. default "," */
22
+ delimiter?: string;
23
+ /** character used to quote fields the contain a delimiter */
24
+ quoteChar?: string;
25
+ /** character used to escape quotes inside a quoted field */
26
+ escapeChar?: string;
27
+ /** number of lines to skip at the beginning of the file */
28
+ skipLines?: number;
29
+ /** parse engine to use (default: 'fast-csv') */
30
+ parseEngine?: "fast-csv" | "csv-parse";
31
+ }
32
+ /**
33
+ * CsvReader parses a csv and emits an async iterator for accessing the next row. The row is an array
34
+ * allowing access to the fields by index or, if the csv has a header, by header name:
35
+ * for await (const row of reader.rows()) {
36
+ * var field1ByName = row["my col name"];
37
+ * var field1ByIndex = row[0];
38
+ * }
39
+ */
40
+ export interface CsvReader {
41
+ header(): Promise<string[]>;
42
+ jsDoc(): Promise<string>;
43
+ verifyHeader(required: string[]): Promise<void>;
44
+ rows(): AsyncIterableIterator<any>;
45
+ rowsWithProps(): AsyncIterableIterator<{
46
+ [name: string]: string;
47
+ }>;
48
+ }
@@ -0,0 +1,21 @@
1
+ import { FileProvider } from "../file-provider/file-provider.js";
2
+ export interface CsvWriterOptions {
3
+ target?: {
4
+ filePath?: string;
5
+ };
6
+ noHeader?: boolean;
7
+ delimiter?: string;
8
+ quoteChar?: string;
9
+ escapeChar?: string;
10
+ prepend?: Buffer | Uint8Array;
11
+ }
12
+ /**
13
+ * CsvWriter writes rows or data to a csv file.
14
+ */
15
+ export declare class CsvWriter {
16
+ constructor(options: CsvWriterOptions);
17
+ write(row: {
18
+ [col: string]: any;
19
+ } | string[]): Promise<void>;
20
+ close(): Promise<FileProvider>;
21
+ }
@@ -0,0 +1,37 @@
1
+ export declare function dateFormat(date: Date | number, options?: {
2
+ format?: "ISO" | "ISODate" | "yyyy-MM-dd HH:mm:ss" | "yyyyMMdd";
3
+ custom?: string;
4
+ tz?: string;
5
+ }): string | undefined;
6
+ export declare function dateParse(text: string, options?: {
7
+ format?: "ISO" | "ISODate" | "yyyy-MM-dd HH:mm:ss" | "yyyyMMdd";
8
+ custom?: string;
9
+ tz?: string;
10
+ }): Date | undefined;
11
+ export type DateTimeFormat = "none" | "unix" | "unix_ms" | "yyyy-MM-dd" | "M/d/yyyy" | "MM/dd/yyyy" | "dd/MM/yyyy" | "iso8601" | "yyyy-MM-dd HH:mm:ss" | "custom";
12
+ export type DateTimeTrunc = "none" | "second" | "minute" | "hour" | "day" | "month" | "year";
13
+ export type DateTimeInterval = "none" | "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "months" | "years";
14
+ export interface DateTransformOptions {
15
+ /** Date/time value to parse */
16
+ input: string | number | undefined;
17
+ /** Format of the input Date/time string */
18
+ inputFormat: DateTimeFormat;
19
+ /** If the input format selected is 'custom' this must hold the format specification */
20
+ inputFormatCustom?: string;
21
+ /** Optional time zone of the input text */
22
+ inputTimeZone?: string;
23
+ /** Operators to apply to the parsed input before serializing */
24
+ dateTimeMath?: Array<{
25
+ count: number;
26
+ interval: DateTimeInterval;
27
+ }>;
28
+ /**Truncation rule to apply to the parsed input before serializing */
29
+ truncate?: DateTimeTrunc;
30
+ /** Format to output the Date/time string */
31
+ outputFormat?: DateTimeFormat;
32
+ /** If the output format selected is 'custom' this must hold the format specification */
33
+ outputFormatCustom?: string;
34
+ /** Optional time zone of the output value */
35
+ outputTimeZone?: string;
36
+ }
37
+ export declare function dateTransform(options: DateTransformOptions): string | number | undefined;