@casual-simulation/aux-records 2.0.31 → 2.0.34

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.
@@ -1,5 +1,5 @@
1
1
  import { NotLoggedInError, ServerError } from './Errors';
2
- import { DataRecordsStore, EraseDataStoreResult, GetDataStoreResult, SetDataResult } from './DataRecordsStore';
2
+ import { DataRecordsStore, EraseDataStoreResult, GetDataStoreResult, SetDataResult, ListDataStoreResult } from './DataRecordsStore';
3
3
  import { RecordsController, ValidatePublicRecordKeyFailure } from './RecordsController';
4
4
  /**
5
5
  * Defines a class that is able to manage data (key/value) records.
@@ -24,6 +24,7 @@ export declare class DataRecordsController {
24
24
  */
25
25
  recordData(recordKey: string, address: string, data: string, subjectId: string): Promise<RecordDataResult>;
26
26
  getData(recordName: string, address: string): Promise<GetDataResult>;
27
+ listData(recordName: string, address: string | null): Promise<ListDataResult>;
27
28
  eraseData(recordKey: string, address: string): Promise<EraseDataResult>;
28
29
  }
29
30
  export declare type RecordDataResult = RecordDataSuccess | RecordDataFailure;
@@ -76,4 +77,18 @@ export interface EraseDataFailure {
76
77
  errorCode: ServerError | EraseDataStoreResult['errorCode'] | ValidatePublicRecordKeyFailure['errorCode'];
77
78
  errorMessage: string;
78
79
  }
80
+ export declare type ListDataResult = ListDataSuccess | ListDataFailure;
81
+ export interface ListDataSuccess {
82
+ success: true;
83
+ recordName: string;
84
+ items: {
85
+ data: any;
86
+ address: string;
87
+ }[];
88
+ }
89
+ export interface ListDataFailure {
90
+ success: false;
91
+ errorCode: ServerError | ListDataStoreResult['errorCode'] | 'not_supported';
92
+ errorMessage: string;
93
+ }
79
94
  //# sourceMappingURL=DataRecordsController.d.ts.map
@@ -83,6 +83,32 @@ export class DataRecordsController {
83
83
  };
84
84
  });
85
85
  }
86
+ listData(recordName, address) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ try {
89
+ const result2 = yield this._store.listData(recordName, address);
90
+ if (result2.success === false) {
91
+ return {
92
+ success: false,
93
+ errorCode: result2.errorCode,
94
+ errorMessage: result2.errorMessage,
95
+ };
96
+ }
97
+ return {
98
+ success: true,
99
+ recordName,
100
+ items: result2.items,
101
+ };
102
+ }
103
+ catch (err) {
104
+ return {
105
+ success: false,
106
+ errorCode: 'server_error',
107
+ errorMessage: err.toString(),
108
+ };
109
+ }
110
+ });
111
+ }
86
112
  eraseData(recordKey, address) {
87
113
  return __awaiter(this, void 0, void 0, function* () {
88
114
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"DataRecordsController.js","sourceRoot":"","sources":["DataRecordsController.ts"],"names":[],"mappings":";;;;;;;;;AAYA;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAI9B;;;;OAIG;IACH,YAAY,OAA0B,EAAE,KAAuB;QAC3D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAED;;;;;;;;OAQG;IACG,UAAU,CACZ,SAAiB,EACjB,OAAe,EACf,IAAY,EACZ,SAAiB;;YAEjB,IAAI;gBACA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CACtD,SAAS,CACZ,CAAC;gBACF,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE;oBAC1B,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,MAAM,CAAC,SAAS;wBAC3B,YAAY,EAAE,MAAM,CAAC,YAAY;qBACpC,CAAC;iBACL;gBAED,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;gBACrC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACrC,UAAU,EACV,OAAO,EACP,IAAI,EACJ,MAAM,CAAC,OAAO,EACd,SAAS,CACZ,CAAC;gBAEF,IAAI,OAAO,CAAC,OAAO,KAAK,KAAK,EAAE;oBAC3B,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAA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E,cAAc;oBACzB,YAAY,EAAE,GAAG,CAAC,QAAQ,EAAE;iBAC/B,CAAC;aACL;QACL,CAAC;KAAA;CACJ"}
@@ -18,6 +18,12 @@ export interface DataRecordsStore {
18
18
  * @param address The address that the data is stored at.
19
19
  */
20
20
  getData(recordName: string, address: string): Promise<GetDataStoreResult>;
21
+ /**
22
+ * Lists data stored in the given record starting with the given address.
23
+ * @param recordName The name of the record.
24
+ * @param address The address so start listing items at.
25
+ */
26
+ listData(recordName: string, address: string | null): Promise<ListDataStoreResult>;
21
27
  /**
22
28
  * Deletes the data stored in the given record and address.
23
29
  * @param recordName The name of the record that the data is in.
@@ -52,4 +58,13 @@ export interface EraseDataStoreResult {
52
58
  errorCode?: 'data_not_found' | ServerError;
53
59
  errorMessage?: string;
54
60
  }
61
+ export interface ListDataStoreResult {
62
+ success: boolean;
63
+ items?: {
64
+ data: any;
65
+ address: string;
66
+ }[];
67
+ errorCode?: ServerError;
68
+ errorMessage?: string;
69
+ }
55
70
  //# sourceMappingURL=DataRecordsStore.d.ts.map
@@ -0,0 +1,66 @@
1
+ import { NotLoggedInError, ServerError } from './Errors';
2
+ import { EventRecordsStore, AddEventCountStoreResult, GetEventCountStoreResult } from './EventRecordsStore';
3
+ import { RecordsController, ValidatePublicRecordKeyFailure } from './RecordsController';
4
+ /**
5
+ * Defines a class that is able to manage event (count) records.
6
+ */
7
+ export declare class EventRecordsController {
8
+ private _manager;
9
+ private _store;
10
+ /**
11
+ * Creates a DataRecordsController.
12
+ * @param manager The records manager that should be used to validate record keys.
13
+ * @param store The store that should be used to save data.
14
+ */
15
+ constructor(manager: RecordsController, store: EventRecordsStore);
16
+ /**
17
+ * Adds the given count of events to the total count of events with the given name.
18
+ * @param recordKey The record key that should be used to add the events.
19
+ * @param eventName The name of the events to record.
20
+ * @param count The number of events to add/subtract.
21
+ */
22
+ addCount(recordKey: string, eventName: string, count: number): Promise<AddCountResult>;
23
+ /**
24
+ * Gets the current count of events with the given name from the given record.
25
+ * @param recordName The name of the record.
26
+ * @param eventName The name of the events
27
+ */
28
+ getCount(recordName: string, eventName: string): Promise<GetCountResult>;
29
+ }
30
+ export declare type AddCountResult = AddCountSuccess | AddCountFailure;
31
+ export interface AddCountSuccess {
32
+ success: true;
33
+ recordName: string;
34
+ eventName: string;
35
+ countAdded: number;
36
+ }
37
+ export interface AddCountFailure {
38
+ success: false;
39
+ errorCode: ServerError | NotLoggedInError | ValidatePublicRecordKeyFailure['errorCode'] | AddEventCountStoreResult['errorCode'] | 'not_supported';
40
+ errorMessage: string;
41
+ }
42
+ export declare type GetCountResult = GetCountSuccess | GetCountFailure;
43
+ /**
44
+ * Defines an interface that represents a successful "get data" result.
45
+ */
46
+ export interface GetCountSuccess {
47
+ success: true;
48
+ /**
49
+ * The total count of events.
50
+ */
51
+ count: number;
52
+ /**
53
+ * The name of the record.
54
+ */
55
+ recordName: string;
56
+ /**
57
+ * The name of the event.
58
+ */
59
+ eventName: string;
60
+ }
61
+ export interface GetCountFailure {
62
+ success: false;
63
+ errorCode: ServerError | GetEventCountStoreResult['errorCode'] | 'not_supported';
64
+ errorMessage: string;
65
+ }
66
+ //# sourceMappingURL=EventRecordsController.d.ts.map
@@ -0,0 +1,102 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /**
11
+ * Defines a class that is able to manage event (count) records.
12
+ */
13
+ export class EventRecordsController {
14
+ /**
15
+ * Creates a DataRecordsController.
16
+ * @param manager The records manager that should be used to validate record keys.
17
+ * @param store The store that should be used to save data.
18
+ */
19
+ constructor(manager, store) {
20
+ this._manager = manager;
21
+ this._store = store;
22
+ }
23
+ /**
24
+ * Adds the given count of events to the total count of events with the given name.
25
+ * @param recordKey The record key that should be used to add the events.
26
+ * @param eventName The name of the events to record.
27
+ * @param count The number of events to add/subtract.
28
+ */
29
+ addCount(recordKey, eventName, count) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ try {
32
+ const result = yield this._manager.validatePublicRecordKey(recordKey);
33
+ if (result.success === false) {
34
+ return {
35
+ success: false,
36
+ errorCode: result.errorCode,
37
+ errorMessage: result.errorMessage,
38
+ };
39
+ }
40
+ const recordName = result.recordName;
41
+ const result2 = yield this._store.addEventCount(recordName, eventName, count);
42
+ if (result2.success === true) {
43
+ return {
44
+ success: true,
45
+ countAdded: count,
46
+ eventName: eventName,
47
+ recordName: recordName,
48
+ };
49
+ }
50
+ else {
51
+ return {
52
+ success: false,
53
+ errorCode: result2.errorCode,
54
+ errorMessage: result2.errorMessage,
55
+ };
56
+ }
57
+ }
58
+ catch (err) {
59
+ return {
60
+ success: false,
61
+ errorCode: 'server_error',
62
+ errorMessage: err.toString(),
63
+ };
64
+ }
65
+ });
66
+ }
67
+ /**
68
+ * Gets the current count of events with the given name from the given record.
69
+ * @param recordName The name of the record.
70
+ * @param eventName The name of the events
71
+ */
72
+ getCount(recordName, eventName) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ try {
75
+ const result = yield this._store.getEventCount(recordName, eventName);
76
+ if (result.success) {
77
+ return {
78
+ success: true,
79
+ count: result.count,
80
+ eventName: eventName,
81
+ recordName: recordName,
82
+ };
83
+ }
84
+ else {
85
+ return {
86
+ success: false,
87
+ errorCode: result.errorCode,
88
+ errorMessage: result.errorMessage,
89
+ };
90
+ }
91
+ }
92
+ catch (err) {
93
+ return {
94
+ success: false,
95
+ errorCode: 'server_error',
96
+ errorMessage: err.toString(),
97
+ };
98
+ }
99
+ });
100
+ }
101
+ }
102
+ //# sourceMappingURL=EventRecordsController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventRecordsController.js","sourceRoot":"","sources":["EventRecordsController.ts"],"names":[],"mappings":";;;;;;;;;AAWA;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAI/B;;;;OAIG;IACH,YAAY,OAA0B,EAAE,KAAwB;QAC5D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACG,QAAQ,CACV,SAAiB,EACjB,SAAiB,EACjB,KAAa;;YAEb,IAAI;gBACA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CACtD,SAAS,CACZ,CAAC;gBACF,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE;oBAC1B,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,MAAM,CAAC,SAAS;wBAC3B,YAAY,EAAE,MAAM,CAAC,YAAY;qBACpC,CAAC;iBACL;gBAED,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;gBACrC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAC3C,UAAU,EACV,SAAS,EACT,KAAK,CACR,CAAC;gBAEF,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,EAAE;oBAC1B,OAAO;wBACH,OAAO,EAAE,IAAI;wBACb,UAAU,EAAE,KAAK;wBACjB,SAAS,EAAE,SAAS;wBACpB,UAAU,EAAE,UAAU;qBACzB,CAAC;iBACL;qBAAM;oBACH,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,OAAO,CAAC,SAAS;wBAC5B,YAAY,EAAE,OAAO,CAAC,YAAY;qBACrC,CAAC;iBACL;aACJ;YAAC,OAAO,GAAG,EAAE;gBACV,OAAO;oBACH,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,cAAc;oBACzB,YAAY,EAAE,GAAG,CAAC,QAAQ,EAAE;iBAC/B,CAAC;aACL;QACL,CAAC;KAAA;IAED;;;;OAIG;IACG,QAAQ,CACV,UAAkB,EAClB,SAAiB;;YAEjB,IAAI;gBACA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAC1C,UAAU,EACV,SAAS,CACZ,CAAC;gBAEF,IAAI,MAAM,CAAC,OAAO,EAAE;oBAChB,OAAO;wBACH,OAAO,EAAE,IAAI;wBACb,KAAK,EAAE,MAAM,CAAC,KAAK;wBACnB,SAAS,EAAE,SAAS;wBACpB,UAAU,EAAE,UAAU;qBACzB,CAAC;iBACL;qBAAM;oBACH,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,MAAM,CAAC,SAAS;wBAC3B,YAAY,EAAE,MAAM,CAAC,YAAY;qBACpC,CAAC;iBACL;aACJ;YAAC,OAAO,GAAG,EAAE;gBACV,OAAO;oBACH,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,cAAc;oBACzB,YAAY,EAAE,GAAG,CAAC,QAAQ,EAAE;iBAC/B,CAAC;aACL;QACL,CAAC;KAAA;CACJ"}
@@ -0,0 +1,31 @@
1
+ import { ServerError } from './Errors';
2
+ /**
3
+ * Defines an interface for objects that can store event records.
4
+ */
5
+ export interface EventRecordsStore {
6
+ /**
7
+ * Adds the given count to the given event and record.
8
+ * @param recordName The name of the record.
9
+ * @param eventName The name of the event.
10
+ * @param count The amount to add or subtract.
11
+ */
12
+ addEventCount(recordName: string, eventName: string, count: number): Promise<AddEventCountStoreResult>;
13
+ /**
14
+ * Gets the count stored on the given event and record.
15
+ * @param recordName The name of the record.
16
+ * @param eventName The name of the event.
17
+ */
18
+ getEventCount(recordName: string, eventName: string): Promise<GetEventCountStoreResult>;
19
+ }
20
+ export interface AddEventCountStoreResult {
21
+ success: boolean;
22
+ errorCode?: ServerError;
23
+ errorMessage?: string;
24
+ }
25
+ export interface GetEventCountStoreResult {
26
+ success: boolean;
27
+ count?: number;
28
+ errorCode?: ServerError;
29
+ errorMessage?: string;
30
+ }
31
+ //# sourceMappingURL=EventRecordsStore.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=EventRecordsStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventRecordsStore.js","sourceRoot":"","sources":["EventRecordsStore.ts"],"names":[],"mappings":""}
@@ -1,9 +1,10 @@
1
- import { DataRecordsStore, EraseDataStoreResult, GetDataStoreResult, SetDataResult } from './DataRecordsStore';
1
+ import { DataRecordsStore, EraseDataStoreResult, GetDataStoreResult, ListDataStoreResult, SetDataResult } from './DataRecordsStore';
2
2
  export declare class MemoryDataRecordsStore implements DataRecordsStore {
3
3
  private _buckets;
4
4
  setData(recordName: string, address: string, data: any, publisherId: string, subjectId: string): Promise<SetDataResult>;
5
5
  getData(recordName: string, address: string): Promise<GetDataStoreResult>;
6
6
  eraseData(recordName: string, address: string): Promise<EraseDataStoreResult>;
7
+ listData(recordName: string, address: string): Promise<ListDataStoreResult>;
7
8
  private _getRecord;
8
9
  }
9
10
  //# sourceMappingURL=MemoryDataRecordsStore.d.ts.map
@@ -59,6 +59,24 @@ export class MemoryDataRecordsStore {
59
59
  };
60
60
  });
61
61
  }
62
+ listData(recordName, address) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ let record = this._getRecord(recordName);
65
+ let items = [];
66
+ for (let [key, item] of record.entries()) {
67
+ if (!address || key > address) {
68
+ items.push({
69
+ address: key,
70
+ data: item.data,
71
+ });
72
+ }
73
+ }
74
+ return {
75
+ success: true,
76
+ items,
77
+ };
78
+ });
79
+ }
62
80
  _getRecord(recordName) {
63
81
  let record = this._buckets.get(recordName);
64
82
  if (!record) {
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryDataRecordsStore.js","sourceRoot":"","sources":["MemoryDataRecordsStore.ts"],"names":[],"mappings":";;;;;;;;;AAOA,MAAM,OAAO,sBAAsB;IAAnC;QACY,aAAQ,GAAyC,IAA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CACJ"}
@@ -0,0 +1,8 @@
1
+ import { AddEventCountStoreResult, EventRecordsStore, GetEventCountStoreResult } from './EventRecordsStore';
2
+ export declare class MemoryEventRecordsStore implements EventRecordsStore {
3
+ private _buckets;
4
+ addEventCount(recordName: string, eventName: string, count: number): Promise<AddEventCountStoreResult>;
5
+ getEventCount(recordName: string, eventName: string): Promise<GetEventCountStoreResult>;
6
+ private _getRecord;
7
+ }
8
+ //# sourceMappingURL=MemoryEventRecordsStore.d.ts.map
@@ -0,0 +1,50 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export class MemoryEventRecordsStore {
11
+ constructor() {
12
+ this._buckets = new Map();
13
+ }
14
+ addEventCount(recordName, eventName, count) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const record = this._getRecord(recordName);
17
+ if (record.has(eventName)) {
18
+ let data = record.get(eventName);
19
+ data.count += count;
20
+ }
21
+ else {
22
+ record.set(eventName, {
23
+ count: count,
24
+ });
25
+ }
26
+ return {
27
+ success: true,
28
+ };
29
+ });
30
+ }
31
+ getEventCount(recordName, eventName) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const record = this._getRecord(recordName);
34
+ const count = record.has(eventName) ? record.get(eventName).count : 0;
35
+ return {
36
+ success: true,
37
+ count: count,
38
+ };
39
+ });
40
+ }
41
+ _getRecord(recordName) {
42
+ let record = this._buckets.get(recordName);
43
+ if (!record) {
44
+ record = new Map();
45
+ this._buckets.set(recordName, record);
46
+ }
47
+ return record;
48
+ }
49
+ }
50
+ //# sourceMappingURL=MemoryEventRecordsStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryEventRecordsStore.js","sourceRoot":"","sources":["MemoryEventRecordsStore.ts"],"names":[],"mappings":";;;;;;;;;AAMA,MAAM,OAAO,uBAAuB;IAApC;QACY,aAAQ,GAAyC,IAAI,GAAG,EAAE,CAAC;IA6CvE,CAAC;IA3CS,aAAa,CACf,UAAkB,EAClB,SAAiB,EACjB,KAAa;;YAEb,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YAE3C,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;gBACvB,IAAI,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;gBACjC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC;aACvB;iBAAM;gBACH,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE;oBAClB,KAAK,EAAE,KAAK;iBACf,CAAC,CAAC;aACN;YAED,OAAO;gBACH,OAAO,EAAE,IAAI;aAChB,CAAC;QACN,CAAC;KAAA;IAEK,aAAa,CACf,UAAkB,EAClB,SAAiB;;YAEjB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YAE3C,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAEtE,OAAO;gBACH,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,KAAK;aACf,CAAC;QACN,CAAC;KAAA;IAEO,UAAU,CAAC,UAAkB;QACjC,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,EAAE;YACT,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;SACzC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
package/index.d.ts CHANGED
@@ -7,4 +7,7 @@ export * from './DataRecordsStore';
7
7
  export * from './FileRecordsController';
8
8
  export * from './FileRecordsStore';
9
9
  export * from './MemoryFileRecordsStore';
10
+ export * from './EventRecordsController';
11
+ export * from './EventRecordsStore';
12
+ export * from './MemoryEventRecordsStore';
10
13
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -7,4 +7,7 @@ export * from './DataRecordsStore';
7
7
  export * from './FileRecordsController';
8
8
  export * from './FileRecordsStore';
9
9
  export * from './MemoryFileRecordsStore';
10
+ export * from './EventRecordsController';
11
+ export * from './EventRecordsStore';
12
+ export * from './MemoryEventRecordsStore';
10
13
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@casual-simulation/aux-records",
3
- "version": "2.0.31",
3
+ "version": "2.0.34",
4
4
  "description": "Helpers and managers used by the CasualOS records system.",
5
5
  "keywords": [],
6
6
  "author": "Casual Simulation, Inc.",
@@ -41,5 +41,5 @@
41
41
  "@casual-simulation/crypto": "^2.0.22",
42
42
  "tweetnacl": "1.0.3"
43
43
  },
44
- "gitHead": "7dbb0b8d8d98060b770be7dd6489aae288600846"
44
+ "gitHead": "964c230d49195946f361300aabd29c3ca7da0b66"
45
45
  }