@flatfile/listener 0.1.0 → 0.1.1

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/.eslintrc.js CHANGED
@@ -1,4 +1,4 @@
1
- module.exports = {
1
+ export default {
2
2
  root: true,
3
3
  extends: ['@flatfile/eslint-config-platform-sdk'],
4
4
  }
@@ -1,5 +1,5 @@
1
1
 
2
- > @flatfile/listener@0.1.0 build
2
+ > @flatfile/listener@0.1.1 build
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,10 +8,10 @@
8
8
  CLI Target: es2020
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.js 25.99 KB
12
- ESM ⚡️ Build success in 112ms
13
- CJS dist/index.cjs 26.82 KB
14
- CJS ⚡️ Build success in 126ms
11
+ ESM dist/index.mjs 25.91 KB
12
+ ESM ⚡️ Build success in 180ms
13
+ CJS dist/index.js 26.77 KB
14
+ CJS ⚡️ Build success in 188ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 5649ms
17
- DTS dist/index.d.ts 7.41 KB
16
+ DTS ⚡️ Build success in 7000ms
17
+ DTS dist/index.d.ts 7.48 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @flatfile/listener
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 356c35d: Minor CI improvements and backwards compatible rename of Client to FlatfileListener
8
+
3
9
  ## 0.1.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -159,7 +159,7 @@ declare abstract class EventDriver {
159
159
  }
160
160
 
161
161
  /**
162
- * The Client
162
+ * The Flatfile Listener
163
163
  *
164
164
  * The Flatfile PubSub Client is just a simple event subscriber. It can
165
165
  * receive events from any PubSub driver. The default drivers are:
@@ -188,35 +188,33 @@ declare abstract class EventDriver {
188
188
  *
189
189
  */
190
190
 
191
- declare class Client extends EventHandler {
191
+ declare class FlatfileListener extends EventHandler {
192
192
  /**
193
193
  * Subscribe to events only within a certain namespace.
194
194
  *
195
195
  * @param namespace
196
196
  * @param cb
197
197
  */
198
- namespace(namespace: string | string[], cb?: SubFn): Client;
198
+ namespace(namespace: string | string[], cb?: SubFn): FlatfileListener;
199
199
  /**
200
200
  * Filter by namespace
201
201
  *
202
202
  * @param filter
203
203
  * @param cb
204
204
  */
205
- filter(filter: EventFilter, cb?: SubFn): Client;
206
- setupFunctions: Array<(...args: any[]) => void>;
207
- beforeMount(cb: SubFn): void;
205
+ filter(filter: EventFilter, cb?: SubFn): FlatfileListener;
208
206
  /**
209
207
  * Start subscribing to events
210
208
  *
211
209
  * @param cb
212
210
  */
213
- static create(cb: SubFn): Client;
211
+ static create(cb: SubFn): FlatfileListener;
214
212
  /**
215
213
  * Mount this client using an acceptable Event Driver
216
214
  */
217
215
  mount(driver: EventDriver): this;
218
216
  }
219
- type SubFn = (client: Client) => void;
217
+ type SubFn = (client: FlatfileListener) => void;
220
218
 
221
219
  declare class Browser extends EventDriver {
222
220
  _accessToken?: string;
@@ -261,4 +259,10 @@ declare class FlatfileVirtualMachine extends EventDriver {
261
259
  mountEventHandler(handler: EventHandler): this;
262
260
  }
263
261
 
264
- export { Arrayable, AuthenticatedClient, Browser, Client, EventCallback, EventFilter, EventHandler, FlatfileEvent, FlatfileVirtualMachine, PollingEventDriver };
262
+ /**
263
+ * Backwards compatibility
264
+ */
265
+ declare class Client extends FlatfileListener {
266
+ }
267
+
268
+ export { Arrayable, AuthenticatedClient, Browser, Client, EventCallback, EventFilter, EventHandler, FlatfileEvent, FlatfileListener, FlatfileVirtualMachine, PollingEventDriver };
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -7,6 +8,10 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
8
  var __commonJS = (cb, mod) => function __require() {
8
9
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
10
  };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
10
15
  var __copyProps = (to, from, except, desc) => {
11
16
  if (from && typeof from === "object" || typeof from === "function") {
12
17
  for (let key of __getOwnPropNames(from))
@@ -23,10 +28,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
28
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
29
  mod
25
30
  ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
32
 
27
33
  // ../../node_modules/ansi-colors/symbols.js
28
34
  var require_symbols = __commonJS({
29
- "../../node_modules/ansi-colors/symbols.js"(exports, module) {
35
+ "../../node_modules/ansi-colors/symbols.js"(exports, module2) {
30
36
  "use strict";
31
37
  var isHyper = typeof process !== "undefined" && process.env.TERM_PROGRAM === "Hyper";
32
38
  var isWindows = typeof process !== "undefined" && process.platform === "win32";
@@ -87,16 +93,16 @@ var require_symbols = __commonJS({
87
93
  radioOn: "\u25C9",
88
94
  warning: "\u26A0"
89
95
  });
90
- module.exports = isWindows && !isHyper ? windows : other;
91
- Reflect.defineProperty(module.exports, "common", { enumerable: false, value: common });
92
- Reflect.defineProperty(module.exports, "windows", { enumerable: false, value: windows });
93
- Reflect.defineProperty(module.exports, "other", { enumerable: false, value: other });
96
+ module2.exports = isWindows && !isHyper ? windows : other;
97
+ Reflect.defineProperty(module2.exports, "common", { enumerable: false, value: common });
98
+ Reflect.defineProperty(module2.exports, "windows", { enumerable: false, value: windows });
99
+ Reflect.defineProperty(module2.exports, "other", { enumerable: false, value: other });
94
100
  }
95
101
  });
96
102
 
97
103
  // ../../node_modules/ansi-colors/index.js
98
104
  var require_ansi_colors = __commonJS({
99
- "../../node_modules/ansi-colors/index.js"(exports, module) {
105
+ "../../node_modules/ansi-colors/index.js"(exports, module2) {
100
106
  "use strict";
101
107
  var isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
102
108
  var ANSI_REGEX = /[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g;
@@ -256,14 +262,28 @@ var require_ansi_colors = __commonJS({
256
262
  colors.define = define;
257
263
  return colors;
258
264
  };
259
- module.exports = create();
260
- module.exports.create = create;
265
+ module2.exports = create();
266
+ module2.exports.create = create;
261
267
  }
262
268
  });
263
269
 
270
+ // src/index.ts
271
+ var src_exports = {};
272
+ __export(src_exports, {
273
+ AuthenticatedClient: () => AuthenticatedClient,
274
+ Browser: () => Browser,
275
+ Client: () => Client,
276
+ EventHandler: () => EventHandler,
277
+ FlatfileEvent: () => FlatfileEvent,
278
+ FlatfileListener: () => FlatfileListener,
279
+ FlatfileVirtualMachine: () => FlatfileVirtualMachine,
280
+ PollingEventDriver: () => PollingEventDriver
281
+ });
282
+ module.exports = __toCommonJS(src_exports);
283
+
264
284
  // src/events/authenticated.client.ts
265
- import { Configuration, DefaultApi } from "@flatfile/api";
266
- import fetch from "node-fetch";
285
+ var import_api = require("@flatfile/api");
286
+ var import_node_fetch = __toESM(require("node-fetch"));
267
287
  var FLATFILE_API_URL = process.env.AGENT_INTERNAL_URL || "http://localhost:3000";
268
288
  var AuthenticatedClient = class {
269
289
  constructor(accessToken, apiUrl) {
@@ -276,16 +296,16 @@ var AuthenticatedClient = class {
276
296
  }
277
297
  const accessToken = this._accessToken;
278
298
  const apiUrl = this._apiUrl;
279
- const ClientConfig = new Configuration({
299
+ const ClientConfig = new import_api.Configuration({
280
300
  basePath: `${apiUrl}/v1`,
281
- fetchApi: fetch,
301
+ fetchApi: import_node_fetch.default,
282
302
  accessToken,
283
303
  headers: {
284
304
  Authorization: `Bearer ${accessToken || "..."}`,
285
305
  "x-disable-hooks": "true"
286
306
  }
287
307
  });
288
- this._api = new DefaultApi(ClientConfig);
308
+ this._api = new import_api.DefaultApi(ClientConfig);
289
309
  return this._api;
290
310
  }
291
311
  fetch(url) {
@@ -297,7 +317,7 @@ var AuthenticatedClient = class {
297
317
  "x-disable-hooks": "true"
298
318
  };
299
319
  const fetchUrl = this._apiUrl + "/" + url;
300
- this._fetchApi = fetch(fetchUrl, {
320
+ this._fetchApi = (0, import_node_fetch.default)(fetchUrl, {
301
321
  headers
302
322
  }).then((resp) => resp.json()).then((resp) => resp.data);
303
323
  return this._fetchApi;
@@ -373,7 +393,7 @@ var FlatfileEvent = class extends AuthenticatedClient {
373
393
  this.context = src.context;
374
394
  this.payload = src.payload;
375
395
  this.target = src.target || "";
376
- this.action = src.context.actionName || "";
396
+ this.action = src.context?.actionName || "";
377
397
  }
378
398
  /**
379
399
  * Should return either event body if expanded already or fetch data from the
@@ -515,7 +535,7 @@ function wildcardMatch(pattern, options) {
515
535
  var index_es_default = wildcardMatch;
516
536
 
517
537
  // src/events/glob.match.ts
518
- import flat from "flat";
538
+ var import_flat = __toESM(require("flat"));
519
539
  function glob(val, filter) {
520
540
  if (!val || typeof val !== "string") {
521
541
  return false;
@@ -528,8 +548,8 @@ function objectMatches(object, filterObject) {
528
548
  throw new Error("You cannot filter a non-object");
529
549
  }
530
550
  let denied = false;
531
- const filter = flat(cleanFilter, { safe: true });
532
- const flattened = flat(object, { safe: true });
551
+ const filter = (0, import_flat.default)(cleanFilter, { safe: true });
552
+ const flattened = (0, import_flat.default)(object, { safe: true });
533
553
  for (const keyPattern in filter) {
534
554
  const keys = filterKeys(flattened, keyPattern);
535
555
  const valuePattern = Array.isArray(filter[keyPattern]) ? filter[keyPattern] : [filter[keyPattern]];
@@ -680,12 +700,8 @@ var EventHandler = class extends AuthenticatedClient {
680
700
  }
681
701
  };
682
702
 
683
- // src/Client.ts
684
- var Client = class extends EventHandler {
685
- constructor() {
686
- super(...arguments);
687
- this.setupFunctions = [];
688
- }
703
+ // src/flatfile.listener.ts
704
+ var FlatfileListener = class extends EventHandler {
689
705
  /**
690
706
  * Subscribe to events only within a certain namespace.
691
707
  *
@@ -702,29 +718,25 @@ var Client = class extends EventHandler {
702
718
  * @param cb
703
719
  */
704
720
  filter(filter, cb) {
705
- const client = new Client(filter);
721
+ const client = new FlatfileListener(filter);
706
722
  this.addNode(client);
707
723
  cb?.(client);
708
724
  return client;
709
725
  }
710
- beforeMount(cb) {
711
- this.setupFunctions.push(cb);
712
- }
713
726
  /**
714
727
  * Start subscribing to events
715
728
  *
716
729
  * @param cb
717
730
  */
718
731
  static create(cb) {
719
- const client = new Client();
720
- client.beforeMount(() => cb(client));
732
+ const client = new FlatfileListener();
733
+ cb(client);
721
734
  return client;
722
735
  }
723
736
  /**
724
737
  * Mount this client using an acceptable Event Driver
725
738
  */
726
739
  mount(driver) {
727
- this.setupFunctions.forEach((f) => f());
728
740
  driver.mountEventHandler(this);
729
741
  return this;
730
742
  }
@@ -784,7 +796,7 @@ var Browser = class extends EventDriver {
784
796
  };
785
797
 
786
798
  // src/event-drivers/Polling.ts
787
- var import_ansi_colors = __toESM(require_ansi_colors(), 1);
799
+ var import_ansi_colors = __toESM(require_ansi_colors());
788
800
  var events = /* @__PURE__ */ new Map();
789
801
  var PollingEventDriver = class extends EventDriver {
790
802
  constructor({
@@ -858,12 +870,18 @@ var FlatfileVirtualMachine = class extends EventDriver {
858
870
  return this;
859
871
  }
860
872
  };
861
- export {
873
+
874
+ // src/index.ts
875
+ var Client = class extends FlatfileListener {
876
+ };
877
+ // Annotate the CommonJS export names for ESM import in node:
878
+ 0 && (module.exports = {
862
879
  AuthenticatedClient,
863
880
  Browser,
864
881
  Client,
865
882
  EventHandler,
866
883
  FlatfileEvent,
884
+ FlatfileListener,
867
885
  FlatfileVirtualMachine,
868
886
  PollingEventDriver
869
- };
887
+ });
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -8,10 +7,6 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
7
  var __commonJS = (cb, mod) => function __require() {
9
8
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
9
  };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
10
  var __copyProps = (to, from, except, desc) => {
16
11
  if (from && typeof from === "object" || typeof from === "function") {
17
12
  for (let key of __getOwnPropNames(from))
@@ -28,11 +23,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
23
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
24
  mod
30
25
  ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
26
 
33
27
  // ../../node_modules/ansi-colors/symbols.js
34
28
  var require_symbols = __commonJS({
35
- "../../node_modules/ansi-colors/symbols.js"(exports, module2) {
29
+ "../../node_modules/ansi-colors/symbols.js"(exports, module) {
36
30
  "use strict";
37
31
  var isHyper = typeof process !== "undefined" && process.env.TERM_PROGRAM === "Hyper";
38
32
  var isWindows = typeof process !== "undefined" && process.platform === "win32";
@@ -93,16 +87,16 @@ var require_symbols = __commonJS({
93
87
  radioOn: "\u25C9",
94
88
  warning: "\u26A0"
95
89
  });
96
- module2.exports = isWindows && !isHyper ? windows : other;
97
- Reflect.defineProperty(module2.exports, "common", { enumerable: false, value: common });
98
- Reflect.defineProperty(module2.exports, "windows", { enumerable: false, value: windows });
99
- Reflect.defineProperty(module2.exports, "other", { enumerable: false, value: other });
90
+ module.exports = isWindows && !isHyper ? windows : other;
91
+ Reflect.defineProperty(module.exports, "common", { enumerable: false, value: common });
92
+ Reflect.defineProperty(module.exports, "windows", { enumerable: false, value: windows });
93
+ Reflect.defineProperty(module.exports, "other", { enumerable: false, value: other });
100
94
  }
101
95
  });
102
96
 
103
97
  // ../../node_modules/ansi-colors/index.js
104
98
  var require_ansi_colors = __commonJS({
105
- "../../node_modules/ansi-colors/index.js"(exports, module2) {
99
+ "../../node_modules/ansi-colors/index.js"(exports, module) {
106
100
  "use strict";
107
101
  var isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
108
102
  var ANSI_REGEX = /[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g;
@@ -262,27 +256,14 @@ var require_ansi_colors = __commonJS({
262
256
  colors.define = define;
263
257
  return colors;
264
258
  };
265
- module2.exports = create();
266
- module2.exports.create = create;
259
+ module.exports = create();
260
+ module.exports.create = create;
267
261
  }
268
262
  });
269
263
 
270
- // src/index.ts
271
- var src_exports = {};
272
- __export(src_exports, {
273
- AuthenticatedClient: () => AuthenticatedClient,
274
- Browser: () => Browser,
275
- Client: () => Client,
276
- EventHandler: () => EventHandler,
277
- FlatfileEvent: () => FlatfileEvent,
278
- FlatfileVirtualMachine: () => FlatfileVirtualMachine,
279
- PollingEventDriver: () => PollingEventDriver
280
- });
281
- module.exports = __toCommonJS(src_exports);
282
-
283
264
  // src/events/authenticated.client.ts
284
- var import_api = require("@flatfile/api");
285
- var import_node_fetch = __toESM(require("node-fetch"), 1);
265
+ import { Configuration, DefaultApi } from "@flatfile/api";
266
+ import fetch from "node-fetch";
286
267
  var FLATFILE_API_URL = process.env.AGENT_INTERNAL_URL || "http://localhost:3000";
287
268
  var AuthenticatedClient = class {
288
269
  constructor(accessToken, apiUrl) {
@@ -295,16 +276,16 @@ var AuthenticatedClient = class {
295
276
  }
296
277
  const accessToken = this._accessToken;
297
278
  const apiUrl = this._apiUrl;
298
- const ClientConfig = new import_api.Configuration({
279
+ const ClientConfig = new Configuration({
299
280
  basePath: `${apiUrl}/v1`,
300
- fetchApi: import_node_fetch.default,
281
+ fetchApi: fetch,
301
282
  accessToken,
302
283
  headers: {
303
284
  Authorization: `Bearer ${accessToken || "..."}`,
304
285
  "x-disable-hooks": "true"
305
286
  }
306
287
  });
307
- this._api = new import_api.DefaultApi(ClientConfig);
288
+ this._api = new DefaultApi(ClientConfig);
308
289
  return this._api;
309
290
  }
310
291
  fetch(url) {
@@ -316,7 +297,7 @@ var AuthenticatedClient = class {
316
297
  "x-disable-hooks": "true"
317
298
  };
318
299
  const fetchUrl = this._apiUrl + "/" + url;
319
- this._fetchApi = (0, import_node_fetch.default)(fetchUrl, {
300
+ this._fetchApi = fetch(fetchUrl, {
320
301
  headers
321
302
  }).then((resp) => resp.json()).then((resp) => resp.data);
322
303
  return this._fetchApi;
@@ -392,7 +373,7 @@ var FlatfileEvent = class extends AuthenticatedClient {
392
373
  this.context = src.context;
393
374
  this.payload = src.payload;
394
375
  this.target = src.target || "";
395
- this.action = src.context.actionName || "";
376
+ this.action = src.context?.actionName || "";
396
377
  }
397
378
  /**
398
379
  * Should return either event body if expanded already or fetch data from the
@@ -534,7 +515,7 @@ function wildcardMatch(pattern, options) {
534
515
  var index_es_default = wildcardMatch;
535
516
 
536
517
  // src/events/glob.match.ts
537
- var import_flat = __toESM(require("flat"), 1);
518
+ import flat from "flat";
538
519
  function glob(val, filter) {
539
520
  if (!val || typeof val !== "string") {
540
521
  return false;
@@ -547,8 +528,8 @@ function objectMatches(object, filterObject) {
547
528
  throw new Error("You cannot filter a non-object");
548
529
  }
549
530
  let denied = false;
550
- const filter = (0, import_flat.default)(cleanFilter, { safe: true });
551
- const flattened = (0, import_flat.default)(object, { safe: true });
531
+ const filter = flat(cleanFilter, { safe: true });
532
+ const flattened = flat(object, { safe: true });
552
533
  for (const keyPattern in filter) {
553
534
  const keys = filterKeys(flattened, keyPattern);
554
535
  const valuePattern = Array.isArray(filter[keyPattern]) ? filter[keyPattern] : [filter[keyPattern]];
@@ -699,12 +680,8 @@ var EventHandler = class extends AuthenticatedClient {
699
680
  }
700
681
  };
701
682
 
702
- // src/Client.ts
703
- var Client = class extends EventHandler {
704
- constructor() {
705
- super(...arguments);
706
- this.setupFunctions = [];
707
- }
683
+ // src/flatfile.listener.ts
684
+ var FlatfileListener = class extends EventHandler {
708
685
  /**
709
686
  * Subscribe to events only within a certain namespace.
710
687
  *
@@ -721,29 +698,25 @@ var Client = class extends EventHandler {
721
698
  * @param cb
722
699
  */
723
700
  filter(filter, cb) {
724
- const client = new Client(filter);
701
+ const client = new FlatfileListener(filter);
725
702
  this.addNode(client);
726
703
  cb?.(client);
727
704
  return client;
728
705
  }
729
- beforeMount(cb) {
730
- this.setupFunctions.push(cb);
731
- }
732
706
  /**
733
707
  * Start subscribing to events
734
708
  *
735
709
  * @param cb
736
710
  */
737
711
  static create(cb) {
738
- const client = new Client();
739
- client.beforeMount(() => cb(client));
712
+ const client = new FlatfileListener();
713
+ cb(client);
740
714
  return client;
741
715
  }
742
716
  /**
743
717
  * Mount this client using an acceptable Event Driver
744
718
  */
745
719
  mount(driver) {
746
- this.setupFunctions.forEach((f) => f());
747
720
  driver.mountEventHandler(this);
748
721
  return this;
749
722
  }
@@ -803,7 +776,7 @@ var Browser = class extends EventDriver {
803
776
  };
804
777
 
805
778
  // src/event-drivers/Polling.ts
806
- var import_ansi_colors = __toESM(require_ansi_colors(), 1);
779
+ var import_ansi_colors = __toESM(require_ansi_colors());
807
780
  var events = /* @__PURE__ */ new Map();
808
781
  var PollingEventDriver = class extends EventDriver {
809
782
  constructor({
@@ -877,13 +850,17 @@ var FlatfileVirtualMachine = class extends EventDriver {
877
850
  return this;
878
851
  }
879
852
  };
880
- // Annotate the CommonJS export names for ESM import in node:
881
- 0 && (module.exports = {
853
+
854
+ // src/index.ts
855
+ var Client = class extends FlatfileListener {
856
+ };
857
+ export {
882
858
  AuthenticatedClient,
883
859
  Browser,
884
860
  Client,
885
861
  EventHandler,
886
862
  FlatfileEvent,
863
+ FlatfileListener,
887
864
  FlatfileVirtualMachine,
888
865
  PollingEventDriver
889
- });
866
+ };
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@flatfile/listener",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A PubSub Listener for configuring and using Flatfile",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
- "type": "module",
9
8
  "scripts": {
10
9
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
11
10
  "build": "tsup src/index.ts --format esm,cjs --dts",
12
11
  "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
13
- "poll": "tsup src/dev.ts --format esm,cjs --watch --dts --onSuccess \"node dist/dev.js\""
12
+ "poll": "tsup src/dev.ts --format esm,cjs --watch --dts --onSuccess \"node dist/dev.js\"",
13
+ "test": "jest --passWithNoTests"
14
14
  },
15
15
  "license": "MIT",
16
16
  "devDependencies": {
@@ -37,7 +37,7 @@ export class FlatfileEvent extends AuthenticatedClient {
37
37
  this.context = src.context // -> [us0_acc_ihjh8943h9w, space_id, workbook_id]
38
38
  this.payload = src.payload
39
39
  this.target = src.target || ''
40
- this.action = src.context.actionName || ''
40
+ this.action = src.context?.actionName || ''
41
41
  }
42
42
 
43
43
  /**
@@ -1,6 +1,6 @@
1
- import { Client, FlatfileVirtualMachine } from '../'
1
+ import { FlatfileListener, FlatfileVirtualMachine } from '../'
2
2
 
3
- const example = Client.create((client) => {
3
+ const example = FlatfileListener.create((client) => {
4
4
  /**
5
5
  * This is a basic hook on events with no sugar on top
6
6
  */
@@ -1,4 +1,4 @@
1
- import { Client } from './Client'
1
+ import { FlatfileListener } from './flatfile.listener'
2
2
 
3
3
  describe('Client', () => {
4
4
  let testFn: jest.Mock
@@ -8,16 +8,16 @@ describe('Client', () => {
8
8
  })
9
9
 
10
10
  describe('triggering', () => {
11
- test('triggers basic event listeners', () => {
12
- const client = Client.create((c) => {
11
+ test('triggers basic event listeners', async () => {
12
+ const client = FlatfileListener.create((c) => {
13
13
  c.on('foo', testFn)
14
14
  })
15
- client.dispatchEvent({ topic: 'foo' })
15
+ await client.dispatchEvent({ topic: 'foo' })
16
16
  expect(testFn).toHaveBeenCalledTimes(1)
17
17
  })
18
18
 
19
19
  test('triggers namespaced event listeners', () => {
20
- const client = Client.create((c) => {
20
+ const client = FlatfileListener.create((c) => {
21
21
  c.on('records:created', testFn)
22
22
  })
23
23
  client.dispatchEvent({ topic: 'records:created' })
@@ -25,7 +25,7 @@ describe('Client', () => {
25
25
  })
26
26
 
27
27
  test('triggers event listener for array of events', () => {
28
- const client = Client.create((c) => {
28
+ const client = FlatfileListener.create((c) => {
29
29
  c.on(['records:created', 'records:updated'], testFn)
30
30
  })
31
31
  client.dispatchEvent({ topic: 'records:created' })
@@ -34,7 +34,7 @@ describe('Client', () => {
34
34
  })
35
35
 
36
36
  test('triggers event listener for wildcard query of events', () => {
37
- const client = Client.create((c) => {
37
+ const client = FlatfileListener.create((c) => {
38
38
  c.on('records:*', testFn)
39
39
  })
40
40
  client.dispatchEvent({ topic: 'records:created' })
@@ -46,7 +46,7 @@ describe('Client', () => {
46
46
 
47
47
  describe('filtering', () => {
48
48
  test('trigger only when filter match - on listener', async () => {
49
- const client = Client.create((c) => {
49
+ const client = FlatfileListener.create((c) => {
50
50
  c.on('records:created', { domain: 'foo' }, testFn)
51
51
  })
52
52
  await client.dispatchEvent({ topic: 'records:created' })
@@ -55,7 +55,7 @@ describe('Client', () => {
55
55
  })
56
56
 
57
57
  test('trigger only when filter match - on scope', async () => {
58
- const client = Client.create((c) => {
58
+ const client = FlatfileListener.create((c) => {
59
59
  c.filter({ domain: 'foo' }, (f) => {
60
60
  f.on('records:created', testFn)
61
61
  })
@@ -66,7 +66,7 @@ describe('Client', () => {
66
66
  })
67
67
 
68
68
  test('multiple layers of filtering', async () => {
69
- const client = Client.create((c) => {
69
+ const client = FlatfileListener.create((c) => {
70
70
  c.filter({ domain: 'foo:*' })
71
71
  .filter({ domain: 'foo:bar' })
72
72
  .use((f) => {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The Client
2
+ * The Flatfile Listener
3
3
  *
4
4
  * The Flatfile PubSub Client is just a simple event subscriber. It can
5
5
  * receive events from any PubSub driver. The default drivers are:
@@ -31,7 +31,7 @@
31
31
  import { EventFilter, EventHandler } from './events'
32
32
  import { EventDriver } from './event-drivers/_EventDriver'
33
33
 
34
- export class Client extends EventHandler {
34
+ export class FlatfileListener extends EventHandler {
35
35
  /**
36
36
  * Subscribe to events only within a certain namespace.
37
37
  *
@@ -49,25 +49,20 @@ export class Client extends EventHandler {
49
49
  * @param cb
50
50
  */
51
51
  filter(filter: EventFilter, cb?: SubFn) {
52
- const client = new Client(filter)
52
+ const client = new FlatfileListener(filter)
53
53
  this.addNode(client)
54
54
  cb?.(client)
55
55
  return client
56
56
  }
57
57
 
58
- setupFunctions: Array<(...args: any[]) => void> = []
59
- public beforeMount(cb: SubFn) {
60
- this.setupFunctions.push(cb)
61
- }
62
-
63
58
  /**
64
59
  * Start subscribing to events
65
60
  *
66
61
  * @param cb
67
62
  */
68
- public static create(cb: SubFn): Client {
69
- const client = new Client()
70
- client.beforeMount(() => cb(client))
63
+ public static create(cb: SubFn): FlatfileListener {
64
+ const client = new FlatfileListener()
65
+ cb(client)
71
66
  return client
72
67
  }
73
68
 
@@ -75,10 +70,9 @@ export class Client extends EventHandler {
75
70
  * Mount this client using an acceptable Event Driver
76
71
  */
77
72
  mount(driver: EventDriver) {
78
- this.setupFunctions.forEach((f) => f())
79
73
  driver.mountEventHandler(this)
80
74
  return this
81
75
  }
82
76
  }
83
77
 
84
- type SubFn = (client: Client) => void
78
+ type SubFn = (client: FlatfileListener) => void
package/src/index.ts CHANGED
@@ -1,3 +1,9 @@
1
- export * from './Client'
1
+ import { FlatfileListener } from './flatfile.listener'
2
+ export * from './flatfile.listener'
2
3
  export * from './event-drivers'
3
4
  export * from './events'
5
+
6
+ /**
7
+ * Backwards compatibility
8
+ */
9
+ export class Client extends FlatfileListener {}