Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lucid-extension-sdk

Package Overview
Dependencies
Maintainers
2
Versions
318
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lucid-extension-sdk - npm Package Compare versions

Comparing version 0.0.278 to 0.0.282

dataconnector/actions/patch.d.ts

42

dataconnector/actions/action.d.ts
import { DataUpdateFilterType } from '../../data/dataupdatefiltertype';
import { DataSourceClient } from '../datasourceclient';
import { PatchChange, PatchChangeCollection } from './patchresponsebody';
import { ItemPatch, Patch } from './patch';
export type CollectionId = string;

@@ -71,36 +71,2 @@ export type ItemPrimaryKey = string;

};
/** A patch to be applied against the 3rd party datasource with changes coming from Lucid */
export declare class Patch {
/** The id of the patch */
id: string;
/** Mapping of item primary keys to new items introduced by Lucid */
itemsAdded: PatchItems;
/** Mapping of item primary keys to sparse changesets of pre-existing items changed by Lucid */
itemsChanged: PatchItems;
/** List of item primary keys deleted by Lucid */
itemsDeleted: string[];
/** */
itemOrderChanged: [string, string | null][] | undefined;
/** The syncSourceId of the changed data source */
syncSourceId: string;
/** The syncCollectionId of the changed collection */
syncCollectionId: CollectionId;
constructor(
/** The id of the patch */
id: string,
/** Mapping of item primary keys to new items introduced by Lucid */
itemsAdded: PatchItems,
/** Mapping of item primary keys to sparse changesets of pre-existing items changed by Lucid */
itemsChanged: PatchItems,
/** List of item primary keys deleted by Lucid */
itemsDeleted: string[],
/** */
itemOrderChanged: [string, string | null][] | undefined,
/** The syncSourceId of the changed data source */
syncSourceId: string,
/** The syncCollectionId of the changed collection */
syncCollectionId: CollectionId);
getChange(collections?: PatchChangeCollection[]): PatchChange;
toJSON(): object;
}
/**

@@ -110,7 +76,7 @@ * A patch action is a kind of synchronous style action. It occurs when data is changed in the Lucid editor. All the

**/
export declare class DataConnectorPatchAction extends DataConnectorAction {
/** changes applied by Lucid */ patches: Patch[];
export declare class DataConnectorPatchAction<P extends Patch = ItemPatch> extends DataConnectorAction {
/** changes applied by Lucid */ patches: P[];
client: DataSourceClient;
constructor(context: DataConnectorActionContext,
/** changes applied by Lucid */ patches: Patch[], client: DataSourceClient, name?: string);
/** changes applied by Lucid */ patches: P[], client: DataSourceClient, name?: string);
}

@@ -117,0 +83,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataConnectorManageWebhookAction = exports.Webhook = exports.DataConnectorPatchAction = exports.Patch = exports.DataConnectorSynchronousAction = exports.DataConnectorAsynchronousAction = exports.DataConnectorAction = exports.DataConnectorActionContext = void 0;
exports.DataConnectorManageWebhookAction = exports.Webhook = exports.DataConnectorPatchAction = exports.DataConnectorSynchronousAction = exports.DataConnectorAsynchronousAction = exports.DataConnectorAction = exports.DataConnectorActionContext = void 0;
const dataconnectoractionkeys_1 = require("./dataconnectoractionkeys");
const patchresponsebody_1 = require("./patchresponsebody");
/**

@@ -65,43 +64,2 @@ * This holds all the contextual information about a give data action.

exports.DataConnectorSynchronousAction = DataConnectorSynchronousAction;
/** A patch to be applied against the 3rd party datasource with changes coming from Lucid */
class Patch {
constructor(
/** The id of the patch */
id,
/** Mapping of item primary keys to new items introduced by Lucid */
itemsAdded,
/** Mapping of item primary keys to sparse changesets of pre-existing items changed by Lucid */
itemsChanged,
/** List of item primary keys deleted by Lucid */
itemsDeleted,
/** */
itemOrderChanged,
/** The syncSourceId of the changed data source */
syncSourceId,
/** The syncCollectionId of the changed collection */
syncCollectionId) {
this.id = id;
this.itemsAdded = itemsAdded;
this.itemsChanged = itemsChanged;
this.itemsDeleted = itemsDeleted;
this.itemOrderChanged = itemOrderChanged;
this.syncSourceId = syncSourceId;
this.syncCollectionId = syncCollectionId;
}
getChange(collections = []) {
return new patchresponsebody_1.PatchChange(this.id, this.syncSourceId, collections);
}
toJSON() {
return {
'Id': this.id,
'ItemsAdded': this.itemsAdded,
'ItemsChanged': this.itemsChanged,
'ItemsDeleted': this.itemsDeleted,
'ItemOrderChanged': this.itemOrderChanged,
'SyncSourceId': this.syncSourceId,
'SyncCollectionId': this.syncCollectionId,
};
}
}
exports.Patch = Patch;
/**

@@ -108,0 +66,0 @@ * A patch action is a kind of synchronous style action. It occurs when data is changed in the Lucid editor. All the

import { isString } from '../../core/checks';
import { DataConnectorClient } from '../dataconnectorclient';
import { DataConnectorAction } from './action';
import { Patch, PatchParser } from './patch';
export declare const actionsHeaderValidator: (subject: unknown) => subject is import("../..").DestructureGuardedTypeObj<{

@@ -9,2 +10,2 @@ 'x-lucid-rsa-nonce': typeof isString;

/** Function to convert the lucid action wire format into a clean list of actions */
export declare function deserializeActions(client: DataConnectorClient, actions: unknown): DataConnectorAction[] | undefined;
export declare function deserializeActions<P extends Patch>(client: DataConnectorClient, actions: unknown, patchParser: PatchParser<P>): DataConnectorAction[] | undefined;

@@ -27,12 +27,3 @@ "use strict";

patches: (0, validators_1.arrayValidator)((0, validators_1.objectValidator)({
patch: (0, validators_1.objectValidator)({
itemsAdded: (0, validators_1.objectOfValidator)(checks_1.isObjectUnsafe),
itemsChanged: (0, validators_1.objectOfValidator)(checks_1.isObjectUnsafe),
itemsDeleted: (0, validators_1.arrayValidator)(checks_1.isString),
itemOrderChanged: (0, validators_1.nullableOption)((0, validators_1.arrayValidator)((0, validators_1.tupleValidator)(checks_1.isString, (0, validators_1.nullable)(checks_1.isString)))),
syncSourceId: checks_1.isString,
syncCollectionId: checks_1.isString,
adapterType: (0, checks_1.isLiteral)('EXTENSION_API'),
syncSchema: checks_1.isUnknown,
}),
patch: checks_1.isUnknown,
id: checks_1.isString,

@@ -43,8 +34,9 @@ })),

});
const parseSerializedPatches = (patches) => {
return patches.map((patch) => {
var _a;
const parseSerializedPatches = (patches, patchParser) => {
return patches
.map((patch) => {
const p = patch['patch'];
return new action_1.Patch(patch['id'], p['itemsAdded'], p['itemsChanged'], p['itemsDeleted'], (_a = p['itemOrderChanged']) !== null && _a !== void 0 ? _a : undefined, p['syncSourceId'], p['syncCollectionId']);
});
return patchParser(patch['id'], p);
})
.filter(checks_1.isDefAndNotNull);
};

@@ -59,3 +51,3 @@ const serializedManageWebhookDataValidator = (0, validators_1.objectValidator)({

/** Function to convert the lucid action wire format into a clean list of actions */
function deserializeActions(client, actions) {
function deserializeActions(client, actions, patchParser) {
const parsedActions = typeof actions === 'string' ? JSON.parse(actions) : actions;

@@ -72,7 +64,17 @@ if (!serializedActionsBaseValidator(parsedActions)) {

}
return data.map((item) => {
const parsedData = data
.map((item) => {
const context = new action_1.DataConnectorActionContext(parsedActions['packageId'], item['packageVersion'], item['userCredential'], parsedActions['dataConnectorName'], parsedActions['dataConnectorName'], parsedActions['documentCollections'], parsedActions['updateFilterType']);
const patches = parseSerializedPatches(item['patches']);
const patches = parseSerializedPatches(item['patches'], patchParser);
if (patches.length < item['patches'].length) {
return undefined;
}
return new action_1.DataConnectorPatchAction(context, patches, client.getDataSourceClient(item['documentUpdateToken']));
});
})
.filter(checks_1.isDefAndNotNull);
if (parsedData.length < data.length) {
console.log(`Failing validation step`);
return;
}
return parsedData;
}

@@ -87,4 +89,9 @@ if (!parsedActions['packageVersion'] || !parsedActions['userCredential']) {

const context = new action_1.DataConnectorActionContext(parsedActions['packageId'], parsedActions['packageVersion'], parsedActions['userCredential'], parsedActions['dataConnectorName'], parsedActions['dataConnectorName'], parsedActions['documentCollections'], parsedActions['updateFilterType']);
const parsedPatches = parseSerializedPatches(data['patches'], patchParser);
if (parsedPatches.length < data['patches'].length) {
console.log(`Failing validation step`);
return;
}
return [
new action_1.DataConnectorPatchAction(context, parseSerializedPatches(data['patches']), client.getDataSourceClient(data['documentUpdateToken']), dataconnectoractionkeys_1.DataConnectorActionKeys.UnbatchedPatch),
new action_1.DataConnectorPatchAction(context, parsedPatches, client.getDataSourceClient(data['documentUpdateToken']), dataconnectoractionkeys_1.DataConnectorActionKeys.UnbatchedPatch),
];

@@ -91,0 +98,0 @@ }

import { DataConnectorAction, DataConnectorAsynchronousAction, DataConnectorManageWebhookAction, DataConnectorPatchAction, Webhook } from './actions/action';
import { DataConnectorActionKeys } from './actions/dataconnectoractionkeys';
import { ItemPatch, Patch, PatchParser } from './actions/patch';
import { PatchChange } from './actions/patchresponsebody';

@@ -45,7 +46,9 @@ import { DataConnectorClient } from './dataconnectorclient';

}
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>;
type ActionTypeForName<P extends Patch, Name extends string, Asynchronous = boolean> = Name extends `${DataConnectorActionKeys.Patch}` ? ActionRequest<DataConnectorPatchAction<P>, PatchChange[]> : Name extends `${DataConnectorActionKeys.UnbatchedPatch}` ? ActionRequest<DataConnectorPatchAction<P>, PatchChange[]> : Name extends `${DataConnectorActionKeys.ManageWebhook}` ? ActionRequest<DataConnectorManageWebhookAction, Webhook> : ActionRequest<Asynchronous extends true ? DataConnectorAsynchronousAction : DataConnectorAction>;
/** Factory class to define a bunch of action handlers. */
export declare class DataConnector {
export declare class DataConnector<P extends Patch = ItemPatch> {
private client;
private patchParser;
constructor(client: DataConnectorClient);
constructor(client: DataConnectorClient, optPatchParser: P extends ItemPatch ? never : PatchParser<P>);
actions: Record<string, {

@@ -60,7 +63,7 @@ actionResponder: ActionRequest<DataConnectorAsynchronousAction>;

/** Factory to define an action request handler */
defineAction<T extends string>(name: T, request: ActionTypeForName<T>, asynchronous?: boolean): DataConnector;
defineAction<T extends string>(name: T, request: ActionTypeForName<P, T>, asynchronous?: boolean): DataConnector<P>;
/** Factory to define an asynchronous action request handler */
defineAsynchronousAction<T extends string>(name: T, request: ActionTypeForName<T, true>): DataConnector;
defineAsynchronousAction<T extends string>(name: T, request: ActionTypeForName<P, T, true>): DataConnector<P>;
/** Factory to define a route handler */
defineRoute(name: string, request: DataConnectorRoute): DataConnector;
defineRoute(name: string, request: DataConnectorRoute): DataConnector<P>;
/** Call a defined action handler and gather its serialized response */

@@ -67,0 +70,0 @@ runAction(url: string, headers: Record<string, string[] | string | undefined>, body: unknown): Promise<{

@@ -9,2 +9,3 @@ "use strict";

const managewebhookresponsebody_1 = require("./actions/managewebhookresponsebody");
const patch_1 = require("./actions/patch");
const patchresponsebody_1 = require("./actions/patchresponsebody");

@@ -55,6 +56,7 @@ const debugserver_1 = require("./debugserver");

class DataConnector {
constructor(client) {
constructor(client, optPatchParser) {
this.client = client;
this.actions = {};
this.routes = {};
this.patchParser = optPatchParser !== null && optPatchParser !== void 0 ? optPatchParser : patch_1.itemPatchParser;
}

@@ -78,3 +80,3 @@ /** Factory to define an action request handler */

const state = new DataConnectorRequestState(new itemrekeyer_1.ItemRekeyer());
const actions = await this.client.parseActions(url, headers, body);
const actions = await this.client.parseActions(url, headers, body, this.patchParser);
if (!actions) {

@@ -81,0 +83,0 @@ console.warn('Received bad request', url, headers, body);

import { JsonObject } from '../core/jsonserializable';
import { DataConnectorAction } from './actions/action';
import { Patch, PatchParser } from './actions/patch';
import { CryptoDependencies } from './cryptodependencies';

@@ -36,3 +37,3 @@ import { DataSourceClient, MockDataSourceClient } from './datasourceclient';

/** Validate and parse an action request from Lucid */
parseActions(url: string, headers: Record<string, string | string[] | unknown>, actions: unknown): Promise<DataConnectorAction[] | undefined>;
parseActions<P extends Patch>(url: string, headers: Record<string, string | string[] | unknown>, actions: unknown, patchParser: PatchParser<P>): Promise<DataConnectorAction[] | undefined>;
/** @ignore */

@@ -39,0 +40,0 @@ getSecretFromWebhook(webhookUpdateToken: string, WebhookValidationSecret: WebhookValidationSecret): Promise<string | undefined>;

@@ -41,3 +41,3 @@ "use strict";

/** Validate and parse an action request from Lucid */
async parseActions(url, headers, actions) {
async parseActions(url, headers, actions, patchParser) {
if (!(0, serializedactions_1.actionsHeaderValidator)(headers)) {

@@ -49,3 +49,3 @@ return;

}
return (0, serializedactions_1.deserializeActions)(this, actions);
return (0, serializedactions_1.deserializeActions)(this, actions, patchParser);
}

@@ -52,0 +52,0 @@ /** @ignore */

@@ -0,1 +1,2 @@

import { Patch } from './actions/patch';
import { DataConnector } from './dataconnector';

@@ -45,4 +46,4 @@ /** @ignore */

/** @ignore */
export declare function routeDebugServer(dataConnector: DataConnector, options: RunDebugServerOptions): ExpressAppLike;
export declare function routeDebugServer<P extends Patch>(dataConnector: DataConnector<P>, options: RunDebugServerOptions): ExpressAppLike;
/** @ignore */
export declare function runDebugServer(dataConnector: DataConnector, options: RunDebugServerOptions): void;
export declare function runDebugServer<P extends Patch>(dataConnector: DataConnector<P>, options: RunDebugServerOptions): void;
import { FormattedPrimaryKey } from '../core/data/fieldspecification';
import { Patch, PatchItems } from './actions/action';
import { PatchItems } from './actions/action';
import { Patch } from './actions/patch';
import { ItemsPatch } from './datasourceupdatetypes';

@@ -4,0 +5,0 @@ export declare class RekeyingMap {

@@ -6,3 +6,3 @@ "use strict";

const object_1 = require("../core/object");
const action_1 = require("./actions/action");
const patch_1 = require("./actions/patch");
const datasourceupdatetypes_1 = require("./datasourceupdatetypes");

@@ -59,3 +59,6 @@ function calculateRekeyingMap(itemsPatch, primaryKey) {

var _a;
return new action_1.Patch(patch.id, this.getRecordWithNewKeys(patch.itemsAdded), this.getRecordWithNewKeys(patch.itemsChanged), patch.itemsDeleted.map((key) => this.getNewKey(key)), (_a = patch.itemOrderChanged) === null || _a === void 0 ? void 0 : _a.map(([a, b]) => [this.getNewKey(a), b && this.getNewKey(b)]), patch.syncSourceId, patch.syncCollectionId);
if (patch instanceof patch_1.ItemPatch) {
return new patch_1.ItemPatch(patch.id, this.getRecordWithNewKeys(patch.itemsAdded), this.getRecordWithNewKeys(patch.itemsChanged), patch.itemsDeleted.map((key) => this.getNewKey(key)), (_a = patch.itemOrderChanged) === null || _a === void 0 ? void 0 : _a.map(([a, b]) => [this.getNewKey(a), b && this.getNewKey(b)]), patch.syncSourceId, patch.syncCollectionId);
}
return patch.clone();
}

@@ -62,0 +65,0 @@ }

{
"name": "lucid-extension-sdk",
"version": "0.0.278",
"version": "0.0.282",
"description": "Utility classes for writing Lucid Software editor extensions",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc