@xyo-network/archivist-cookie 2.85.6

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 (39) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +13 -0
  3. package/dist/browser/CookieArchivist.d.cts +32 -0
  4. package/dist/browser/CookieArchivist.d.cts.map +1 -0
  5. package/dist/browser/CookieArchivist.d.mts +32 -0
  6. package/dist/browser/CookieArchivist.d.mts.map +1 -0
  7. package/dist/browser/CookieArchivist.d.ts +32 -0
  8. package/dist/browser/CookieArchivist.d.ts.map +1 -0
  9. package/dist/browser/index.cjs +156 -0
  10. package/dist/browser/index.cjs.map +1 -0
  11. package/dist/browser/index.d.cts +2 -0
  12. package/dist/browser/index.d.cts.map +1 -0
  13. package/dist/browser/index.d.mts +2 -0
  14. package/dist/browser/index.d.mts.map +1 -0
  15. package/dist/browser/index.d.ts +2 -0
  16. package/dist/browser/index.d.ts.map +1 -0
  17. package/dist/browser/index.js +125 -0
  18. package/dist/browser/index.js.map +1 -0
  19. package/dist/node/CookieArchivist.d.cts +32 -0
  20. package/dist/node/CookieArchivist.d.cts.map +1 -0
  21. package/dist/node/CookieArchivist.d.mts +32 -0
  22. package/dist/node/CookieArchivist.d.mts.map +1 -0
  23. package/dist/node/CookieArchivist.d.ts +32 -0
  24. package/dist/node/CookieArchivist.d.ts.map +1 -0
  25. package/dist/node/index.cjs +171 -0
  26. package/dist/node/index.cjs.map +1 -0
  27. package/dist/node/index.d.cts +2 -0
  28. package/dist/node/index.d.cts.map +1 -0
  29. package/dist/node/index.d.mts +2 -0
  30. package/dist/node/index.d.mts.map +1 -0
  31. package/dist/node/index.d.ts +2 -0
  32. package/dist/node/index.d.ts.map +1 -0
  33. package/dist/node/index.js +135 -0
  34. package/dist/node/index.js.map +1 -0
  35. package/package.json +75 -0
  36. package/src/CookieArchivist.ts +164 -0
  37. package/src/index.ts +1 -0
  38. package/src/spec/testArchivist.ts +50 -0
  39. package/typedoc.json +5 -0
package/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ [![logo][]](https://xyo.network)
2
+
3
+ Part of [sdk-xyo-client-js](https://www.npmjs.com/package/@xyo-network/sdk-xyo-client-js)
4
+
5
+ ## License
6
+
7
+ > See the [LICENSE](LICENSE) file for license details
8
+
9
+ ## Credits
10
+
11
+ [Made with 🔥 and ❄️ by XYO](https://xyo.network)
12
+
13
+ [logo]: https://cdn.xy.company/img/brand/XYO_full_colored.png
@@ -0,0 +1,32 @@
1
+ import { Promisable, PromisableArray } from '@xylabs/promise';
2
+ import { AbstractArchivist } from '@xyo-network/archivist-abstract';
3
+ import { ArchivistConfig, ArchivistModuleEventData, ArchivistParams } from '@xyo-network/archivist-model';
4
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
5
+ import { AnyConfigSchema } from '@xyo-network/module-model';
6
+ import { Payload } from '@xyo-network/payload-model';
7
+ export type CookieArchivistConfigSchema = 'network.xyo.archivist.cookie.config';
8
+ export declare const CookieArchivistConfigSchema: CookieArchivistConfigSchema;
9
+ export type CookieArchivistConfig = ArchivistConfig<{
10
+ domain?: string;
11
+ maxEntries?: number;
12
+ maxEntrySize?: number;
13
+ namespace?: string;
14
+ schema: CookieArchivistConfigSchema;
15
+ }>;
16
+ export type CookieArchivistParams = ArchivistParams<AnyConfigSchema<CookieArchivistConfig>>;
17
+ export declare class CookieArchivist<TParams extends CookieArchivistParams, TEventData extends ArchivistModuleEventData = ArchivistModuleEventData> extends AbstractArchivist<TParams, TEventData> {
18
+ static configSchemas: "network.xyo.archivist.cookie.config"[];
19
+ get domain(): string | undefined;
20
+ get maxEntries(): number;
21
+ get maxEntrySize(): number;
22
+ get namespace(): string;
23
+ get queries(): string[];
24
+ protected allHandler(): PromisableArray<Payload>;
25
+ protected clearHandler(): void | Promise<void>;
26
+ protected commitHandler(): Promise<BoundWitness[]>;
27
+ protected deleteHandler(hashes: string[]): Promise<string[]>;
28
+ protected getHandler(hashes: string[]): Promisable<Payload[]>;
29
+ protected insertHandler(payloads: Payload[]): Promise<Payload[]>;
30
+ private keyFromHash;
31
+ }
32
+ //# sourceMappingURL=CookieArchivist.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CookieArchivist.d.ts","sourceRoot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AAO,CAAC,YAAY,EAAE,CAAC;cAuBxC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;cAexD,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC;cAS7C,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAmB/E,OAAO,CAAC,WAAW;CAGpB"}
@@ -0,0 +1,32 @@
1
+ import { Promisable, PromisableArray } from '@xylabs/promise';
2
+ import { AbstractArchivist } from '@xyo-network/archivist-abstract';
3
+ import { ArchivistConfig, ArchivistModuleEventData, ArchivistParams } from '@xyo-network/archivist-model';
4
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
5
+ import { AnyConfigSchema } from '@xyo-network/module-model';
6
+ import { Payload } from '@xyo-network/payload-model';
7
+ export type CookieArchivistConfigSchema = 'network.xyo.archivist.cookie.config';
8
+ export declare const CookieArchivistConfigSchema: CookieArchivistConfigSchema;
9
+ export type CookieArchivistConfig = ArchivistConfig<{
10
+ domain?: string;
11
+ maxEntries?: number;
12
+ maxEntrySize?: number;
13
+ namespace?: string;
14
+ schema: CookieArchivistConfigSchema;
15
+ }>;
16
+ export type CookieArchivistParams = ArchivistParams<AnyConfigSchema<CookieArchivistConfig>>;
17
+ export declare class CookieArchivist<TParams extends CookieArchivistParams, TEventData extends ArchivistModuleEventData = ArchivistModuleEventData> extends AbstractArchivist<TParams, TEventData> {
18
+ static configSchemas: "network.xyo.archivist.cookie.config"[];
19
+ get domain(): string | undefined;
20
+ get maxEntries(): number;
21
+ get maxEntrySize(): number;
22
+ get namespace(): string;
23
+ get queries(): string[];
24
+ protected allHandler(): PromisableArray<Payload>;
25
+ protected clearHandler(): void | Promise<void>;
26
+ protected commitHandler(): Promise<BoundWitness[]>;
27
+ protected deleteHandler(hashes: string[]): Promise<string[]>;
28
+ protected getHandler(hashes: string[]): Promisable<Payload[]>;
29
+ protected insertHandler(payloads: Payload[]): Promise<Payload[]>;
30
+ private keyFromHash;
31
+ }
32
+ //# sourceMappingURL=CookieArchivist.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CookieArchivist.d.ts","sourceRoot":"","sources":["../../src/CookieArchivist.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,EAIL,eAAe,EAIf,wBAAwB,EACxB,eAAe,EAChB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAE9D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAIpD,MAAM,MAAM,2BAA2B,GAAG,qCAAqC,CAAA;AAC/E,eAAO,MAAM,2BAA2B,EAAE,2BAAmE,CAAA;AAE7G,MAAM,MAAM,qBAAqB,GAAG,eAAe,CAAC;IAClD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,2BAA2B,CAAA;CACpC,CAAC,CAAA;AAEF,MAAM,MAAM,qBAAqB,GAAG,eAAe,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAA;AAE3F,qBAAa,eAAe,CAC1B,OAAO,SAAS,qBAAqB,EACrC,UAAU,SAAS,wBAAwB,GAAG,wBAAwB,CACtE,SAAQ,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC;IAC9C,OAAgB,aAAa,0CAAgC;IAE7D,IAAI,MAAM,uBAET;IAED,IAAI,UAAU,WAGb;IAED,IAAI,YAAY,WAGf;IAED,IAAI,SAAS,WAEZ;IAED,IAAa,OAAO,IAAI,MAAM,EAAE,CAS/B;cAEkB,UAAU,IAAI,eAAe,CAAC,OAAO,CAAC;cAWtC,YAAY,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;cAa9B,aAAa,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;cAuBxC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;cAexD,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC;cAS7C,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAmB/E,OAAO,CAAC,WAAW;CAGpB"}
@@ -0,0 +1,32 @@
1
+ import { Promisable, PromisableArray } from '@xylabs/promise';
2
+ import { AbstractArchivist } from '@xyo-network/archivist-abstract';
3
+ import { ArchivistConfig, ArchivistModuleEventData, ArchivistParams } from '@xyo-network/archivist-model';
4
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
5
+ import { AnyConfigSchema } from '@xyo-network/module-model';
6
+ import { Payload } from '@xyo-network/payload-model';
7
+ export type CookieArchivistConfigSchema = 'network.xyo.archivist.cookie.config';
8
+ export declare const CookieArchivistConfigSchema: CookieArchivistConfigSchema;
9
+ export type CookieArchivistConfig = ArchivistConfig<{
10
+ domain?: string;
11
+ maxEntries?: number;
12
+ maxEntrySize?: number;
13
+ namespace?: string;
14
+ schema: CookieArchivistConfigSchema;
15
+ }>;
16
+ export type CookieArchivistParams = ArchivistParams<AnyConfigSchema<CookieArchivistConfig>>;
17
+ export declare class CookieArchivist<TParams extends CookieArchivistParams, TEventData extends ArchivistModuleEventData = ArchivistModuleEventData> extends AbstractArchivist<TParams, TEventData> {
18
+ static configSchemas: "network.xyo.archivist.cookie.config"[];
19
+ get domain(): string | undefined;
20
+ get maxEntries(): number;
21
+ get maxEntrySize(): number;
22
+ get namespace(): string;
23
+ get queries(): string[];
24
+ protected allHandler(): PromisableArray<Payload>;
25
+ protected clearHandler(): void | Promise<void>;
26
+ protected commitHandler(): Promise<BoundWitness[]>;
27
+ protected deleteHandler(hashes: string[]): Promise<string[]>;
28
+ protected getHandler(hashes: string[]): Promisable<Payload[]>;
29
+ protected insertHandler(payloads: Payload[]): Promise<Payload[]>;
30
+ private keyFromHash;
31
+ }
32
+ //# sourceMappingURL=CookieArchivist.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CookieArchivist.d.ts","sourceRoot":"","sources":["../../src/CookieArchivist.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,EAIL,eAAe,EAIf,wBAAwB,EACxB,eAAe,EAChB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAE9D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAIpD,MAAM,MAAM,2BAA2B,GAAG,qCAAqC,CAAA;AAC/E,eAAO,MAAM,2BAA2B,EAAE,2BAAmE,CAAA;AAE7G,MAAM,MAAM,qBAAqB,GAAG,eAAe,CAAC;IAClD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,2BAA2B,CAAA;CACpC,CAAC,CAAA;AAEF,MAAM,MAAM,qBAAqB,GAAG,eAAe,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAA;AAE3F,qBAAa,eAAe,CAC1B,OAAO,SAAS,qBAAqB,EACrC,UAAU,SAAS,wBAAwB,GAAG,wBAAwB,CACtE,SAAQ,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC;IAC9C,OAAgB,aAAa,0CAAgC;IAE7D,IAAI,MAAM,uBAET;IAED,IAAI,UAAU,WAGb;IAED,IAAI,YAAY,WAGf;IAED,IAAI,SAAS,WAEZ;IAED,IAAa,OAAO,IAAI,MAAM,EAAE,CAS/B;cAEkB,UAAU,IAAI,eAAe,CAAC,OAAO,CAAC;cAWtC,YAAY,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;cAa9B,aAAa,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;cAuBxC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;cAexD,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC;cAS7C,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAmB/E,OAAO,CAAC,WAAW;CAGpB"}
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ CookieArchivist: () => CookieArchivist,
35
+ CookieArchivistConfigSchema: () => CookieArchivistConfigSchema
36
+ });
37
+ module.exports = __toCommonJS(src_exports);
38
+
39
+ // src/CookieArchivist.ts
40
+ var import_assert = require("@xylabs/assert");
41
+ var import_lodash = require("@xylabs/lodash");
42
+ var import_promise = require("@xylabs/promise");
43
+ var import_archivist_abstract = require("@xyo-network/archivist-abstract");
44
+ var import_archivist_model = require("@xyo-network/archivist-model");
45
+ var import_hash = require("@xyo-network/hash");
46
+ var import_payload_wrapper = require("@xyo-network/payload-wrapper");
47
+ var import_js_cookie = __toESM(require("js-cookie"), 1);
48
+ var CookieArchivistConfigSchema = "network.xyo.archivist.cookie.config";
49
+ var CookieArchivist = class extends import_archivist_abstract.AbstractArchivist {
50
+ static {
51
+ __name(this, "CookieArchivist");
52
+ }
53
+ static configSchemas = [
54
+ CookieArchivistConfigSchema
55
+ ];
56
+ get domain() {
57
+ return this.config?.domain;
58
+ }
59
+ get maxEntries() {
60
+ return this.config?.maxEntries ?? 60;
61
+ }
62
+ get maxEntrySize() {
63
+ return this.config?.maxEntrySize ?? 4e3;
64
+ }
65
+ get namespace() {
66
+ return this.config?.namespace ?? "xyoarch";
67
+ }
68
+ get queries() {
69
+ return [
70
+ import_archivist_model.ArchivistAllQuerySchema,
71
+ import_archivist_model.ArchivistDeleteQuerySchema,
72
+ import_archivist_model.ArchivistClearQuerySchema,
73
+ import_archivist_model.ArchivistInsertQuerySchema,
74
+ import_archivist_model.ArchivistCommitQuerySchema,
75
+ ...super.queries
76
+ ];
77
+ }
78
+ allHandler() {
79
+ try {
80
+ return Object.entries(import_js_cookie.default.get()).filter(([key]) => key.startsWith(`${this.namespace}-`)).map(([, value]) => JSON.parse(value));
81
+ } catch (ex) {
82
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`);
83
+ throw ex;
84
+ }
85
+ }
86
+ clearHandler() {
87
+ try {
88
+ Object.entries(import_js_cookie.default.get()).map(([key]) => {
89
+ if (key.startsWith(`${this.namespace}-`)) {
90
+ import_js_cookie.default.remove(key);
91
+ }
92
+ });
93
+ } catch (ex) {
94
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`);
95
+ throw ex;
96
+ }
97
+ }
98
+ async commitHandler() {
99
+ try {
100
+ const payloads = await this.all();
101
+ (0, import_assert.assertEx)(payloads.length > 0, "Nothing to commit");
102
+ const settled = await Promise.allSettled((0, import_lodash.compact)(Object.values((await this.parents()).commit ?? [])?.map(async (parent) => {
103
+ const queryPayload = {
104
+ schema: import_archivist_model.ArchivistInsertQuerySchema
105
+ };
106
+ const query = await this.bindQuery(queryPayload, payloads);
107
+ return (await parent?.query(query[0], query[1]))?.[0];
108
+ })));
109
+ await this.clear();
110
+ return (0, import_lodash.compact)(settled.filter(import_promise.fulfilled).map((result) => result.value));
111
+ } catch (ex) {
112
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`);
113
+ throw ex;
114
+ }
115
+ }
116
+ async deleteHandler(hashes) {
117
+ const payloadPairs = await Promise.all((await this.get(hashes)).map(async (payload) => [
118
+ await import_hash.PayloadHasher.hashAsync(payload),
119
+ payload
120
+ ]));
121
+ const deletedPairs = (0, import_lodash.compact)(await Promise.all(payloadPairs.map(([hash, payload]) => {
122
+ import_js_cookie.default.remove(hash);
123
+ return [
124
+ hash,
125
+ payload
126
+ ];
127
+ })));
128
+ return deletedPairs.map(([hash]) => hash);
129
+ }
130
+ getHandler(hashes) {
131
+ return (0, import_lodash.compact)(hashes.map((hash) => {
132
+ const cookieString = import_js_cookie.default.get(this.keyFromHash(hash));
133
+ return cookieString ? JSON.parse(cookieString) : void 0;
134
+ }));
135
+ }
136
+ async insertHandler(payloads) {
137
+ try {
138
+ const resultPayloads = await Promise.all(payloads.map(async (payload) => {
139
+ const wrapper = import_payload_wrapper.PayloadWrapper.wrap(payload);
140
+ const key = this.keyFromHash(await wrapper.hashAsync());
141
+ const value = JSON.stringify(wrapper.payload());
142
+ (0, import_assert.assertEx)(value.length < this.maxEntrySize, `Payload too large [${wrapper.hashAsync()}, ${value.length}]`);
143
+ import_js_cookie.default.set(key, JSON.stringify(wrapper.payload()));
144
+ return wrapper.payload();
145
+ }));
146
+ return resultPayloads;
147
+ } catch (ex) {
148
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`);
149
+ throw ex;
150
+ }
151
+ }
152
+ keyFromHash(hash) {
153
+ return `${this.namespace}-${hash}`;
154
+ }
155
+ };
156
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/CookieArchivist.ts"],"sourcesContent":["export * from './CookieArchivist'\n","import { assertEx } from '@xylabs/assert'\nimport { compact } from '@xylabs/lodash'\nimport { fulfilled, Promisable, PromisableArray } from '@xylabs/promise'\nimport { AbstractArchivist } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistCommitQuerySchema,\n ArchivistConfig,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuery,\n ArchivistInsertQuerySchema,\n ArchivistModuleEventData,\n ArchivistParams,\n} from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport Cookies from 'js-cookie'\n\nexport type CookieArchivistConfigSchema = 'network.xyo.archivist.cookie.config'\nexport const CookieArchivistConfigSchema: CookieArchivistConfigSchema = 'network.xyo.archivist.cookie.config'\n\nexport type CookieArchivistConfig = ArchivistConfig<{\n domain?: string\n maxEntries?: number\n maxEntrySize?: number\n namespace?: string\n schema: CookieArchivistConfigSchema\n}>\n\nexport type CookieArchivistParams = ArchivistParams<AnyConfigSchema<CookieArchivistConfig>>\n\nexport class CookieArchivist<\n TParams extends CookieArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n> extends AbstractArchivist<TParams, TEventData> {\n static override configSchemas = [CookieArchivistConfigSchema]\n\n get domain() {\n return this.config?.domain\n }\n\n get maxEntries() {\n //all browsers support at least 60 cookies\n return this.config?.maxEntries ?? 60\n }\n\n get maxEntrySize() {\n //all browsers support at least 4000 length per cookie\n return this.config?.maxEntrySize ?? 4000\n }\n\n get namespace() {\n return this.config?.namespace ?? 'xyoarch'\n }\n\n override get queries(): string[] {\n return [\n ArchivistAllQuerySchema,\n ArchivistDeleteQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistCommitQuerySchema,\n ...super.queries,\n ]\n }\n\n protected override allHandler(): PromisableArray<Payload> {\n try {\n return Object.entries(Cookies.get())\n .filter(([key]) => key.startsWith(`${this.namespace}-`))\n .map(([, value]) => JSON.parse(value))\n } catch (ex) {\n console.error(`Error: ${JSON.stringify(ex, null, 2)}`)\n throw ex\n }\n }\n\n protected override clearHandler(): void | Promise<void> {\n try {\n Object.entries(Cookies.get()).map(([key]) => {\n if (key.startsWith(`${this.namespace}-`)) {\n Cookies.remove(key)\n }\n })\n } catch (ex) {\n console.error(`Error: ${JSON.stringify(ex, null, 2)}`)\n throw ex\n }\n }\n\n protected override async commitHandler(): Promise<BoundWitness[]> {\n try {\n const payloads = await this.all()\n assertEx(payloads.length > 0, 'Nothing to commit')\n const settled = await Promise.allSettled(\n compact(\n Object.values((await this.parents()).commit ?? [])?.map(async (parent) => {\n const queryPayload: ArchivistInsertQuery = {\n schema: ArchivistInsertQuerySchema,\n }\n const query = await this.bindQuery(queryPayload, payloads)\n return (await parent?.query(query[0], query[1]))?.[0]\n }),\n ),\n )\n await this.clear()\n return compact(settled.filter(fulfilled).map((result) => result.value))\n } catch (ex) {\n console.error(`Error: ${JSON.stringify(ex, null, 2)}`)\n throw ex\n }\n }\n\n protected override async deleteHandler(hashes: string[]): Promise<string[]> {\n const payloadPairs: [string, Payload][] = await Promise.all(\n (await this.get(hashes)).map<Promise<[string, Payload]>>(async (payload) => [await PayloadHasher.hashAsync(payload), payload]),\n )\n const deletedPairs: [string, Payload][] = compact(\n await Promise.all(\n payloadPairs.map<[string, Payload] | undefined>(([hash, payload]) => {\n Cookies.remove(hash)\n return [hash, payload]\n }),\n ),\n )\n return deletedPairs.map(([hash]) => hash)\n }\n\n protected override getHandler(hashes: string[]): Promisable<Payload[]> {\n return compact(\n hashes.map((hash) => {\n const cookieString = Cookies.get(this.keyFromHash(hash))\n return cookieString ? JSON.parse(cookieString) : undefined\n }),\n )\n }\n\n protected override async insertHandler(payloads: Payload[]): Promise<Payload[]> {\n try {\n const resultPayloads: Payload[] = await Promise.all(\n payloads.map(async (payload) => {\n const wrapper = PayloadWrapper.wrap(payload)\n const key = this.keyFromHash(await wrapper.hashAsync())\n const value = JSON.stringify(wrapper.payload())\n assertEx(value.length < this.maxEntrySize, `Payload too large [${wrapper.hashAsync()}, ${value.length}]`)\n Cookies.set(key, JSON.stringify(wrapper.payload()))\n return wrapper.payload()\n }),\n )\n return resultPayloads\n } catch (ex) {\n console.error(`Error: ${JSON.stringify(ex, null, 2)}`)\n throw ex\n }\n }\n\n private keyFromHash(hash: string) {\n return `${this.namespace}-${hash}`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACAA,oBAAyB;AACzB,oBAAwB;AACxB,qBAAuD;AACvD,gCAAkC;AAClC,6BAUO;AAEP,kBA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AKC,MAAMoC,YAAAA,IAAgBE;IACnD,CAAA,CAAA;EAEJ;EAEA,MAAyBC,cAAc/B,UAAyC;AAC9E,QAAI;AACF,YAAMgC,iBAA4B,MAAM3B,QAAQJ,IAC9CD,SAASX,IAAI,OAAOiC,YAAAA;AAClB,cAAMW,UAAUC,sCAAeC,KAAKb,OAAAA;AACpC,cAAMnC,MAAM,KAAK0C,YAAY,MAAMI,QAAQT,UAAS,CAAA;AACpD,cAAMlC,QAAQC,KAAKK,UAAUqC,QAAQX,QAAO,CAAA;AAC5CpB,oCAASZ,MAAMa,SAAS,KAAK9B,cAAc,sBAAsB4D,QAAQT,UAAS,CAAA,KAAOlC,MAAMa,MAAM,GAAG;AACxGnB,yBAAAA,QAAQoD,IAAIjD,KAAKI,KAAKK,UAAUqC,QAAQX,QAAO,CAAA,CAAA;AAC/C,eAAOW,QAAQX,QAAO;MACxB,CAAA,CAAA;AAEF,aAAOU;IACT,SAASvC,IAAI;AACXC,cAAQC,MAAM,UAAUJ,KAAKK,UAAUH,IAAI,MAAM,CAAA,CAAA,EAAI;AACrD,YAAMA;IACR;EACF;EAEQoC,YAAYH,MAAc;AAChC,WAAO,GAAG,KAAKpD,SAAS,IAAIoD,IAAAA;EAC9B;AACF;","names":["CookieArchivistConfigSchema","CookieArchivist","AbstractArchivist","configSchemas","domain","config","maxEntries","maxEntrySize","namespace","queries","ArchivistAllQuerySchema","ArchivistDeleteQuerySchema","ArchivistClearQuerySchema","ArchivistInsertQuerySchema","ArchivistCommitQuerySchema","allHandler","Object","entries","Cookies","get","filter","key","startsWith","map","value","JSON","parse","ex","console","error","stringify","clearHandler","remove","commitHandler","payloads","all","assertEx","length","settled","Promise","allSettled","compact","values","parents","commit","parent","queryPayload","schema","query","bindQuery","clear","fulfilled","result","deleteHandler","hashes","payloadPairs","payload","PayloadHasher","hashAsync","deletedPairs","hash","getHandler","cookieString","keyFromHash","undefined","insertHandler","resultPayloads","wrapper","PayloadWrapper","wrap","set"]}
@@ -0,0 +1,2 @@
1
+ export * from './CookieArchivist';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './CookieArchivist';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './CookieArchivist';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,125 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/CookieArchivist.ts
5
+ import { assertEx } from "@xylabs/assert";
6
+ import { compact } from "@xylabs/lodash";
7
+ import { fulfilled } from "@xylabs/promise";
8
+ import { AbstractArchivist } from "@xyo-network/archivist-abstract";
9
+ import { ArchivistAllQuerySchema, ArchivistClearQuerySchema, ArchivistCommitQuerySchema, ArchivistDeleteQuerySchema, ArchivistInsertQuerySchema } from "@xyo-network/archivist-model";
10
+ import { PayloadHasher } from "@xyo-network/hash";
11
+ import { PayloadWrapper } from "@xyo-network/payload-wrapper";
12
+ import Cookies from "js-cookie";
13
+ var CookieArchivistConfigSchema = "network.xyo.archivist.cookie.config";
14
+ var CookieArchivist = class extends AbstractArchivist {
15
+ static {
16
+ __name(this, "CookieArchivist");
17
+ }
18
+ static configSchemas = [
19
+ CookieArchivistConfigSchema
20
+ ];
21
+ get domain() {
22
+ return this.config?.domain;
23
+ }
24
+ get maxEntries() {
25
+ return this.config?.maxEntries ?? 60;
26
+ }
27
+ get maxEntrySize() {
28
+ return this.config?.maxEntrySize ?? 4e3;
29
+ }
30
+ get namespace() {
31
+ return this.config?.namespace ?? "xyoarch";
32
+ }
33
+ get queries() {
34
+ return [
35
+ ArchivistAllQuerySchema,
36
+ ArchivistDeleteQuerySchema,
37
+ ArchivistClearQuerySchema,
38
+ ArchivistInsertQuerySchema,
39
+ ArchivistCommitQuerySchema,
40
+ ...super.queries
41
+ ];
42
+ }
43
+ allHandler() {
44
+ try {
45
+ return Object.entries(Cookies.get()).filter(([key]) => key.startsWith(`${this.namespace}-`)).map(([, value]) => JSON.parse(value));
46
+ } catch (ex) {
47
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`);
48
+ throw ex;
49
+ }
50
+ }
51
+ clearHandler() {
52
+ try {
53
+ Object.entries(Cookies.get()).map(([key]) => {
54
+ if (key.startsWith(`${this.namespace}-`)) {
55
+ Cookies.remove(key);
56
+ }
57
+ });
58
+ } catch (ex) {
59
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`);
60
+ throw ex;
61
+ }
62
+ }
63
+ async commitHandler() {
64
+ try {
65
+ const payloads = await this.all();
66
+ assertEx(payloads.length > 0, "Nothing to commit");
67
+ const settled = await Promise.allSettled(compact(Object.values((await this.parents()).commit ?? [])?.map(async (parent) => {
68
+ const queryPayload = {
69
+ schema: ArchivistInsertQuerySchema
70
+ };
71
+ const query = await this.bindQuery(queryPayload, payloads);
72
+ return (await parent?.query(query[0], query[1]))?.[0];
73
+ })));
74
+ await this.clear();
75
+ return compact(settled.filter(fulfilled).map((result) => result.value));
76
+ } catch (ex) {
77
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`);
78
+ throw ex;
79
+ }
80
+ }
81
+ async deleteHandler(hashes) {
82
+ const payloadPairs = await Promise.all((await this.get(hashes)).map(async (payload) => [
83
+ await PayloadHasher.hashAsync(payload),
84
+ payload
85
+ ]));
86
+ const deletedPairs = compact(await Promise.all(payloadPairs.map(([hash, payload]) => {
87
+ Cookies.remove(hash);
88
+ return [
89
+ hash,
90
+ payload
91
+ ];
92
+ })));
93
+ return deletedPairs.map(([hash]) => hash);
94
+ }
95
+ getHandler(hashes) {
96
+ return compact(hashes.map((hash) => {
97
+ const cookieString = Cookies.get(this.keyFromHash(hash));
98
+ return cookieString ? JSON.parse(cookieString) : void 0;
99
+ }));
100
+ }
101
+ async insertHandler(payloads) {
102
+ try {
103
+ const resultPayloads = await Promise.all(payloads.map(async (payload) => {
104
+ const wrapper = PayloadWrapper.wrap(payload);
105
+ const key = this.keyFromHash(await wrapper.hashAsync());
106
+ const value = JSON.stringify(wrapper.payload());
107
+ assertEx(value.length < this.maxEntrySize, `Payload too large [${wrapper.hashAsync()}, ${value.length}]`);
108
+ Cookies.set(key, JSON.stringify(wrapper.payload()));
109
+ return wrapper.payload();
110
+ }));
111
+ return resultPayloads;
112
+ } catch (ex) {
113
+ console.error(`Error: ${JSON.stringify(ex, null, 2)}`);
114
+ throw ex;
115
+ }
116
+ }
117
+ keyFromHash(hash) {
118
+ return `${this.namespace}-${hash}`;
119
+ }
120
+ };
121
+ export {
122
+ CookieArchivist,
123
+ CookieArchivistConfigSchema
124
+ };
125
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/CookieArchivist.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { compact } from '@xylabs/lodash'\nimport { fulfilled, Promisable, PromisableArray } from '@xylabs/promise'\nimport { AbstractArchivist } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistCommitQuerySchema,\n ArchivistConfig,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuery,\n ArchivistInsertQuerySchema,\n ArchivistModuleEventData,\n ArchivistParams,\n} from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport Cookies from 'js-cookie'\n\nexport type CookieArchivistConfigSchema = 'network.xyo.archivist.cookie.config'\nexport const CookieArchivistConfigSchema: CookieArchivistConfigSchema = 'network.xyo.archivist.cookie.config'\n\nexport type CookieArchivistConfig = ArchivistConfig<{\n domain?: string\n maxEntries?: number\n maxEntrySize?: number\n namespace?: string\n schema: CookieArchivistConfigSchema\n}>\n\nexport type CookieArchivistParams = ArchivistParams<AnyConfigSchema<CookieArchivistConfig>>\n\nexport class CookieArchivist<\n TParams extends CookieArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n> extends AbstractArchivist<TParams, TEventData> {\n static override configSchemas = [CookieArchivistConfigSchema]\n\n get domain() {\n return this.config?.domain\n }\n\n get maxEntries() {\n //all browsers support at least 60 cookies\n return this.config?.maxEntries ?? 60\n }\n\n get maxEntrySize() {\n //all browsers support at least 4000 length per cookie\n return this.config?.maxEntrySize ?? 4000\n }\n\n get namespace() {\n return this.config?.namespace ?? 'xyoarch'\n }\n\n override get queries(): string[] {\n return [\n ArchivistAllQuerySchema,\n ArchivistDeleteQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistCommitQuerySchema,\n ...super.queries,\n ]\n }\n\n protected override allHandler(): PromisableArray<Payload> {\n try {\n return Object.entries(Cookies.get())\n .filter(([key]) => key.startsWith(`${this.namespace}-`))\n .map(([, value]) => JSON.parse(value))\n } catch (ex) {\n console.error(`Error: ${JSON.stringify(ex, null, 2)}`)\n throw ex\n }\n }\n\n protected override clearHandler(): void | Promise<void> {\n try {\n Object.entries(Cookies.get()).map(([key]) => {\n if (key.startsWith(`${this.namespace}-`)) {\n Cookies.remove(key)\n }\n })\n } catch (ex) {\n console.error(`Error: ${JSON.stringify(ex, null, 2)}`)\n throw ex\n }\n }\n\n protected override async commitHandler(): Promise<BoundWitness[]> {\n try {\n const payloads = await this.all()\n assertEx(payloads.length > 0, 'Nothing to commit')\n const settled = await Promise.allSettled(\n compact(\n Object.values((await this.parents()).commit ?? [])?.map(async (parent) => {\n const queryPayload: ArchivistInsertQuery = {\n schema: ArchivistInsertQuerySchema,\n }\n const query = await this.bindQuery(queryPayload, payloads)\n return (await parent?.query(query[0], query[1]))?.[0]\n }),\n ),\n )\n await this.clear()\n return compact(settled.filter(fulfilled).map((result) => result.value))\n } catch (ex) {\n console.error(`Error: ${JSON.stringify(ex, null, 2)}`)\n throw ex\n }\n }\n\n protected override async deleteHandler(hashes: string[]): Promise<string[]> {\n const payloadPairs: [string, Payload][] = await Promise.all(\n (await this.get(hashes)).map<Promise<[string, Payload]>>(async (payload) => [await PayloadHasher.hashAsync(payload), payload]),\n )\n const deletedPairs: [string, Payload][] = compact(\n await Promise.all(\n payloadPairs.map<[string, Payload] | undefined>(([hash, payload]) => {\n Cookies.remove(hash)\n return [hash, payload]\n }),\n ),\n )\n return deletedPairs.map(([hash]) => hash)\n }\n\n protected override getHandler(hashes: string[]): Promisable<Payload[]> {\n return compact(\n hashes.map((hash) => {\n const cookieString = Cookies.get(this.keyFromHash(hash))\n return cookieString ? JSON.parse(cookieString) : undefined\n }),\n )\n }\n\n protected override async insertHandler(payloads: Payload[]): Promise<Payload[]> {\n try {\n const resultPayloads: Payload[] = await Promise.all(\n payloads.map(async (payload) => {\n const wrapper = PayloadWrapper.wrap(payload)\n const key = this.keyFromHash(await wrapper.hashAsync())\n const value = JSON.stringify(wrapper.payload())\n assertEx(value.length < this.maxEntrySize, `Payload too large [${wrapper.hashAsync()}, ${value.length}]`)\n Cookies.set(key, JSON.stringify(wrapper.payload()))\n return wrapper.payload()\n }),\n )\n return resultPayloads\n } catch (ex) {\n console.error(`Error: ${JSON.stringify(ex, null, 2)}`)\n throw ex\n }\n }\n\n private keyFromHash(hash: string) {\n return `${this.namespace}-${hash}`\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,eAAe;AACxB,SAASC,iBAA8C;AACvD,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H,IAAAA,CAAAA;AAClD,aAAOE,eAAerC,KAAKC,MAAMoC,YAAAA,IAAgBE;IACnD,CAAA,CAAA;EAEJ;EAEA,MAAyBC,cAAc/B,UAAyC;AAC9E,QAAI;AACF,YAAMgC,iBAA4B,MAAM3B,QAAQJ,IAC9CD,SAASX,IAAI,OAAOiC,YAAAA;AAClB,cAAMW,UAAUC,eAAeC,KAAKb,OAAAA;AACpC,cAAMnC,MAAM,KAAK0C,YAAY,MAAMI,QAAQT,UAAS,CAAA;AACpD,cAAMlC,QAAQC,KAAKK,UAAUqC,QAAQX,QAAO,CAAA;AAC5CpB,iBAASZ,MAAMa,SAAS,KAAK9B,cAAc,sBAAsB4D,QAAQT,UAAS,CAAA,KAAOlC,MAAMa,MAAM,GAAG;AACxGnB,gBAAQoD,IAAIjD,KAAKI,KAAKK,UAAUqC,QAAQX,QAAO,CAAA,CAAA;AAC/C,eAAOW,QAAQX,QAAO;MACxB,CAAA,CAAA;AAEF,aAAOU;IACT,SAASvC,IAAI;AACXC,cAAQC,MAAM,UAAUJ,KAAKK,UAAUH,IAAI,MAAM,CAAA,CAAA,EAAI;AACrD,YAAMA;IACR;EACF;EAEQoC,YAAYH,MAAc;AAChC,WAAO,GAAG,KAAKpD,SAAS,IAAIoD,IAAAA;EAC9B;AACF;","names":["assertEx","compact","fulfilled","AbstractArchivist","ArchivistAllQuerySchema","ArchivistClearQuerySchema","ArchivistCommitQuerySchema","ArchivistDeleteQuerySchema","ArchivistInsertQuerySchema","PayloadHasher","PayloadWrapper","Cookies","CookieArchivistConfigSchema","CookieArchivist","AbstractArchivist","configSchemas","domain","config","maxEntries","maxEntrySize","namespace","queries","ArchivistAllQuerySchema","ArchivistDeleteQuerySchema","ArchivistClearQuerySchema","ArchivistInsertQuerySchema","ArchivistCommitQuerySchema","allHandler","Object","entries","Cookies","get","filter","key","startsWith","map","value","JSON","parse","ex","console","error","stringify","clearHandler","remove","commitHandler","payloads","all","assertEx","length","settled","Promise","allSettled","compact","values","parents","commit","parent","queryPayload","schema","query","bindQuery","clear","fulfilled","result","deleteHandler","hashes","payloadPairs","payload","PayloadHasher","hashAsync","deletedPairs","hash","getHandler","cookieString","keyFromHash","undefined","insertHandler","resultPayloads","wrapper","PayloadWrapper","wrap","set"]}