@usebridger/core 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/dist/adapter.d.mts +165 -0
- package/dist/adapter.d.mts.map +1 -0
- package/dist/adapter.mjs +137 -0
- package/dist/adapter.mjs.map +1 -0
- package/dist/errors-B3UWcNDO.mjs +21 -0
- package/dist/errors-B3UWcNDO.mjs.map +1 -0
- package/dist/index.d.mts +1165 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +7217 -0
- package/dist/index.mjs.map +1 -0
- package/dist/namespace-P7WksMj8.mjs +67 -0
- package/dist/namespace-P7WksMj8.mjs.map +1 -0
- package/dist/reconnection--5ulo2FJ.mjs +470 -0
- package/dist/reconnection--5ulo2FJ.mjs.map +1 -0
- package/dist/reconnection-BGpkqq4C.d.mts +1213 -0
- package/dist/reconnection-BGpkqq4C.d.mts.map +1 -0
- package/dist/storage-contract.d.mts +43 -0
- package/dist/storage-contract.d.mts.map +1 -0
- package/dist/storage-contract.mjs +1039 -0
- package/dist/storage-contract.mjs.map +1 -0
- package/dist/types-Cq6JEmsh.d.mts +157 -0
- package/dist/types-Cq6JEmsh.d.mts.map +1 -0
- package/package.json +50 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { _ as StoragePort, c as FindQuery, g as SortDirection, i as CollectionOptions, l as JsonObject, m as Scalar, n as AuthStateStore, t as AuthKeyData, u as JsonValue, y as Where } from "./types-Cq6JEmsh.mjs";
|
|
2
|
+
import { $ as assertCapability, A as GroupParticipant, B as TransportCommands, E as CommandInteraction, G as TransportPacing, H as TransportEventHandler, J as CAPABILITIES, K as TypingKind, M as Interaction, P as MessageKey, Q as assertCanSend, R as TextLimits, U as TransportEventName, V as TransportDeps, W as TransportEvents, X as CapabilityHolder, Y as Capability, c as Contact, et as capabilitiesForSend, g as MessageOf, h as Message, i as ReconnectionState, it as missingCapabilities, k as GroupMetadata, n as ReconnectionPolicy, nt as hasCapability, p as Media, q as Unsubscribe, r as ReconnectionPolicyOptions, rt as isCapability, t as ReconnectionDecision, tt as groupActionCapability, w as ActionInteraction, z as Transport } from "./reconnection-BGpkqq4C.mjs";
|
|
3
|
+
//#region src/message/media.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* O que o transport fornece para cada mídia: metadados e o loader nativo. O core cuida de
|
|
6
|
+
* laziness e cache; o transport só sabe baixar.
|
|
7
|
+
*/
|
|
8
|
+
interface MediaSource {
|
|
9
|
+
readonly mimetype: string;
|
|
10
|
+
/** Tamanho em bytes, quando o transport informa. */
|
|
11
|
+
readonly size?: number | null;
|
|
12
|
+
/** Nome do arquivo, quando a plataforma informa. */
|
|
13
|
+
readonly fileName?: string;
|
|
14
|
+
/** Baixa o conteúdo inteiro. Chamado no máximo uma vez por sucesso. */
|
|
15
|
+
download(): Promise<Buffer>;
|
|
16
|
+
/**
|
|
17
|
+
* Stream nativo, para arquivos grandes sem passar tudo pela memória. Opcional: sem ele,
|
|
18
|
+
* `stream()` cai no `download()` cacheado.
|
|
19
|
+
*/
|
|
20
|
+
stream?(): Promise<ReadableStream<Uint8Array>>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Embrulha o loader do transport numa `Media` lazy: nada é baixado até a primeira chamada,
|
|
24
|
+
* o buffer fica cacheado na própria instância (uma por mensagem) e chamadas concorrentes
|
|
25
|
+
* compartilham a mesma promise.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createMedia(source: MediaSource): Media;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/message/create.d.ts
|
|
30
|
+
/**
|
|
31
|
+
* Campos com valor padrão: o transport só informa quando difere do caso comum. `fromMe` fica
|
|
32
|
+
* obrigatório de propósito: esquecê-lo faria o bot responder às próprias mensagens.
|
|
33
|
+
*/
|
|
34
|
+
type DefaultedKey = "quoted" | "mentions" | "isForwarded" | "isViewOnce" | "isEdited";
|
|
35
|
+
type InitOf<M> = M extends Message ? Omit<M, "is" | "key" | "media" | "attachments" | DefaultedKey> & Partial<Pick<M, DefaultedKey>> & {
|
|
36
|
+
/**
|
|
37
|
+
* Todas as mídias, quando há mais de uma (ADR 0065). Começa pela própria `media`; ausente,
|
|
38
|
+
* vale `[media]`, ou nenhuma nos tipos sem mídia.
|
|
39
|
+
*/
|
|
40
|
+
readonly attachments?: readonly MediaSource[];
|
|
41
|
+
} & (M extends {
|
|
42
|
+
readonly media: Media;
|
|
43
|
+
} ? {
|
|
44
|
+
readonly media: MediaSource;
|
|
45
|
+
} : unknown) : never;
|
|
46
|
+
/**
|
|
47
|
+
* Dados que o transport passa a `createMessage`. Mídia entra como `MediaSource` (o loader
|
|
48
|
+
* nativo); `quoted` entra já normalizado, construído com `createMessage` também. `key` não entra:
|
|
49
|
+
* é derivada dos outros campos.
|
|
50
|
+
*/
|
|
51
|
+
type MessageInit = InitOf<Message>;
|
|
52
|
+
/**
|
|
53
|
+
* Constrói uma `Message` normalizada a partir do que o transport extraiu do formato nativo.
|
|
54
|
+
* Preenche os padrões (`quoted: null`, `mentions: []`, flags `false`) e a `key`, liga `is()` e
|
|
55
|
+
* embrulha a mídia em `Media` lazy com cache por mensagem.
|
|
56
|
+
*/
|
|
57
|
+
export declare function createMessage<I extends MessageInit>(init: I): MessageOf<I["type"]>;
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/storage/errors.d.ts
|
|
60
|
+
/** Operação depois de `StoragePort.close()`. */
|
|
61
|
+
export declare class StorageClosedError extends Error {
|
|
62
|
+
override readonly name = "StorageClosedError";
|
|
63
|
+
constructor();
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/storage/query.d.ts
|
|
67
|
+
type FilterOperator = "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "in";
|
|
68
|
+
/** Uma condição validada; as condições de uma consulta combinam com E. */
|
|
69
|
+
type NormalizedCondition = {
|
|
70
|
+
readonly field: string;
|
|
71
|
+
readonly op: "eq" | "ne";
|
|
72
|
+
readonly value: Scalar;
|
|
73
|
+
} | {
|
|
74
|
+
readonly field: string;
|
|
75
|
+
readonly op: "gt" | "gte" | "lt" | "lte";
|
|
76
|
+
readonly value: string | number;
|
|
77
|
+
} | {
|
|
78
|
+
readonly field: string;
|
|
79
|
+
readonly op: "in";
|
|
80
|
+
readonly value: readonly Scalar[];
|
|
81
|
+
};
|
|
82
|
+
interface NormalizedSort {
|
|
83
|
+
readonly field: string;
|
|
84
|
+
readonly direction: SortDirection;
|
|
85
|
+
}
|
|
86
|
+
interface NormalizedQuery {
|
|
87
|
+
readonly where: readonly NormalizedCondition[];
|
|
88
|
+
readonly orderBy: readonly NormalizedSort[];
|
|
89
|
+
/** `undefined` = sem limite. */
|
|
90
|
+
readonly limit: number | undefined;
|
|
91
|
+
readonly offset: number;
|
|
92
|
+
}
|
|
93
|
+
/** Lança `TypeError` se `field` não serve como campo de filtro, ordenação ou índice. */
|
|
94
|
+
export declare function assertFieldName(field: string): void;
|
|
95
|
+
/** Converte um filtro na lista canônica de condições. `undefined`/`{}` = sem condições. */
|
|
96
|
+
export declare function normalizeWhere<T>(where: Where<T> | undefined): readonly NormalizedCondition[];
|
|
97
|
+
/** Valida a consulta e devolve a forma canônica que o adapter traduz para o engine. */
|
|
98
|
+
export declare function normalizeQuery<T>(query: FindQuery<T> | undefined): NormalizedQuery;
|
|
99
|
+
/** Campos de índice validados e sem repetição. */
|
|
100
|
+
export declare function normalizeIndexes(options: CollectionOptions | undefined): readonly string[];
|
|
101
|
+
/**
|
|
102
|
+
* Cópia JSON de um documento (ou patch) a gravar: exige objeto, recusa o campo reservado `id`
|
|
103
|
+
* e aplica a semântica de `JSON.stringify` (campos `undefined` somem, `NaN`/`Infinity` viram
|
|
104
|
+
* `null`). O adapter grava exatamente o que sai daqui.
|
|
105
|
+
*/
|
|
106
|
+
export declare function normalizeDocument(document: unknown): JsonObject;
|
|
107
|
+
/** Cópia JSON de um valor de KV ou auth state, com a mesma semântica de `JSON.stringify`. */
|
|
108
|
+
export declare function cloneJson<T extends JsonValue>(value: T): T;
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/transport/methods.d.ts
|
|
111
|
+
/** Método de transport que só existe com uma capability. */
|
|
112
|
+
type CapabilityMethod = "react" | "edit" | "delete" | "sendTyping" | "getGroupMetadata" | "updateGroupParticipants";
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/transport/define.d.ts
|
|
115
|
+
/** O que `defineTransport` entrega ao adapter, além das `TransportDeps`. */
|
|
116
|
+
interface TransportKit {
|
|
117
|
+
/** Entrega um evento ao kernel. Erro de handler vai para o log, nunca para o adapter. */
|
|
118
|
+
emit<E extends TransportEventName>(event: E, payload: TransportEvents[E]): void;
|
|
119
|
+
/** Contato da própria sessão, lido em `Transport.self`. Chame ao abrir a conexão. */
|
|
120
|
+
setSelf(contact: Contact | null): void;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* O transport como o adapter o descreve: o contrato `Transport` sem o que `defineTransport`
|
|
124
|
+
* monta (`on`, `self`), com `capabilities` em lista e os métodos de capability opcionais.
|
|
125
|
+
*/
|
|
126
|
+
interface TransportSpec extends Pick<Transport, "connect" | "disconnect" | "send">, Partial<Pick<Transport, CapabilityMethod | "raw" | "isChatAdmin">> {
|
|
127
|
+
readonly name: string;
|
|
128
|
+
readonly capabilities: readonly Capability[];
|
|
129
|
+
readonly native?: unknown;
|
|
130
|
+
readonly limits?: TextLimits;
|
|
131
|
+
readonly pacing?: TransportPacing;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Monta a fábrica do transport (ADR 0037) a partir da descrição que `build` devolve. A descrição
|
|
135
|
+
* inválida lança `TypeError` com todos os problemas, e o `createBot` a converte em
|
|
136
|
+
* `BotConfigError`. Cada método confere a capability antes de chamar o do adapter; o que ele não
|
|
137
|
+
* implementa rejeita com `UnsupportedError`.
|
|
138
|
+
*/
|
|
139
|
+
export declare function defineTransport(build: (deps: TransportDeps, kit: TransportKit) => TransportSpec): (deps: TransportDeps) => Transport;
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/transport/emitter.d.ts
|
|
142
|
+
type Handler<P> = (payload: P) => void | Promise<void>;
|
|
143
|
+
/** Destino dos erros de handlers: o emissor nunca os deixa subir para o adapter. */
|
|
144
|
+
type EmitterErrorHandler<Events> = (error: unknown, event: keyof Events) => void;
|
|
145
|
+
/**
|
|
146
|
+
* Emissor tipado por instância, para os adapters implementarem `Transport.on()` sem estado
|
|
147
|
+
* global. Um handler que falha (síncrono ou rejeitando) não impede os demais: o erro vai para
|
|
148
|
+
* `onError`, porque o adapter, que emite, não tem o que fazer com ele.
|
|
149
|
+
*/
|
|
150
|
+
export declare class TypedEmitter<Events extends object> {
|
|
151
|
+
#private;
|
|
152
|
+
constructor(onError: EmitterErrorHandler<Events>);
|
|
153
|
+
on<E extends keyof Events>(event: E, handler: Handler<Events[E]>): Unsubscribe;
|
|
154
|
+
emit<E extends keyof Events>(event: E, payload: Events[E]): void;
|
|
155
|
+
listenerCount(event: keyof Events): number;
|
|
156
|
+
/** Remove todas as assinaturas (ex.: no `disconnect()` definitivo do adapter). */
|
|
157
|
+
clear(): void;
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/transport/message-key.d.ts
|
|
161
|
+
/** Chave para reagir, editar ou apagar uma mensagem recebida. */
|
|
162
|
+
export declare function messageKey(message: Pick<Message, "id" | "chat" | "sender" | "fromMe">): MessageKey;
|
|
163
|
+
//#endregion
|
|
164
|
+
export { type ActionInteraction, type AuthKeyData, type AuthStateStore, CAPABILITIES, type CapabilityHolder, type CommandInteraction, type EmitterErrorHandler, type FilterOperator, type GroupMetadata, type GroupParticipant, type Interaction, type MediaSource, type MessageInit, type NormalizedCondition, type NormalizedQuery, type NormalizedSort, type ReconnectionDecision, ReconnectionPolicy, type ReconnectionPolicyOptions, type ReconnectionState, type StoragePort, type Transport, type TransportCommands, type TransportDeps, type TransportEventHandler, type TransportEventName, type TransportEvents, type TransportKit, type TransportSpec, type TypingKind, assertCanSend, assertCapability, capabilitiesForSend, groupActionCapability, hasCapability, isCapability, missingCapabilities };
|
|
165
|
+
//# sourceMappingURL=adapter.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.mts","names":[],"sources":["../src/message/media.ts","../src/message/create.ts","../src/storage/errors.ts","../src/storage/query.ts","../src/transport/methods.ts","../src/transport/define.ts","../src/transport/emitter.ts","../src/transport/message-key.ts"],"mappings":";;;;;;;UAMiB;WACN;;WAEA;;WAEA;;EAET,YAAY,QAAQ;;;;;EAKpB,WAAW,QAAQ,eAAe;;;;;;;wBAQpB,YAAY,QAAQ,cAAc;;;;;;;KClB7C;KAIA,OAAO,KAAK,UAAU,UACvB,KAAK,4CAA4C,gBAC/C,QAAQ,KAAK,GAAG;;;;;WAKL,uBAAuB;KAC7B;WAAqB,OAAO;;WAAqB,OAAO;;;;;;;KAQvD,cAAc,OAAO;;;;;;wBAgBjB,cAAc,UAAU,aAAa,MAAM,IAAI,UAAU;;;;qBCxC5D,2BAA2B;oBACpB;EAElB;;;;KCQU;;KAGA;WACG;WAAwB;WAA0B,OAAO;;WAEzD;WACA;WACA;;WAEA;WAAwB;WAAmB,gBAAgB;;UAEzD;WACN;WACA,WAAW;;UAGL;WACN,gBAAgB;WAChB,kBAAkB;;WAElB;WACA;;;wBASK,gBAAgB;;wBAoChB,eAAe,GAAG,OAAO,MAAM,0BAA0B;;wBA6DzD,eAAe,GAAG,OAAO,UAAU,iBAAiB;;wBAepD,iBAAiB,SAAS;;;;;;wBAW1B,kBAAkB,oBAAoB;;wBAUtC,UAAU,UAAU,WAAW,OAAO,IAAI;;;;KC3K9C;;;;UCiBK;;EAEf,KAAK,UAAU,oBAAoB,OAAO,GAAG,SAAS,gBAAgB;;EAEtE,QAAQ,SAAS;;;;;;UAOF,sBACP,KAAK,+CACX,QAAQ,KAAK,WAAW;WACjB;WACA,uBAAuB;WACvB;WACA,SAAS;WACT,SAAS;;;;;;;;wBA8BJ,gBACd,QAAQ,MAAM,eAAe,KAAK,iBAAiB,iBACjD,MAAM,kBAAkB;;;KCzEvB,QAAQ,MAAM,SAAS,aAAa;;KAG7B,oBAAoB,WAAW,gBAAgB,aAAa;;;;;;qBAO3D,aAAa;;EAIxB,YAAY,SAAS,oBAAoB;EAIzC,GAAG,gBAAgB,QAAQ,OAAO,GAAG,SAAS,QAAQ,OAAO,MAAM;EAiBnE,KAAK,gBAAgB,QAAQ,OAAO,GAAG,SAAS,OAAO;EAgBvD,cAAc,aAAa;;EAK3B;;;;;wBCtDc,WACd,SAAS,KAAK,gDACb"}
|
package/dist/adapter.mjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { n as StorageClosedError } from "./errors-B3UWcNDO.mjs";
|
|
2
|
+
import { _ as capabilitiesForSend, a as cloneJson, b as isCapability, c as normalizeQuery, d as messageKey, f as createMedia, g as assertCapability, h as assertCanSend, i as assertFieldName, l as normalizeWhere, m as UnsupportedError, n as capabilityIssues, o as normalizeDocument, p as CAPABILITIES, s as normalizeIndexes, t as ReconnectionPolicy, u as createMessage, v as groupActionCapability, x as missingCapabilities, y as hasCapability } from "./reconnection--5ulo2FJ.mjs";
|
|
3
|
+
//#region src/transport/emitter.ts
|
|
4
|
+
/**
|
|
5
|
+
* Emissor tipado por instância, para os adapters implementarem `Transport.on()` sem estado
|
|
6
|
+
* global. Um handler que falha (síncrono ou rejeitando) não impede os demais: o erro vai para
|
|
7
|
+
* `onError`, porque o adapter, que emite, não tem o que fazer com ele.
|
|
8
|
+
*/
|
|
9
|
+
var TypedEmitter = class {
|
|
10
|
+
#handlers = /* @__PURE__ */ new Map();
|
|
11
|
+
#onError;
|
|
12
|
+
constructor(onError) {
|
|
13
|
+
this.#onError = onError;
|
|
14
|
+
}
|
|
15
|
+
on(event, handler) {
|
|
16
|
+
let set = this.#handlers.get(event);
|
|
17
|
+
if (!set) {
|
|
18
|
+
set = /* @__PURE__ */ new Set();
|
|
19
|
+
this.#handlers.set(event, set);
|
|
20
|
+
}
|
|
21
|
+
const entry = (payload) => handler(payload);
|
|
22
|
+
set.add(entry);
|
|
23
|
+
return () => {
|
|
24
|
+
const current = this.#handlers.get(event);
|
|
25
|
+
if (!current?.delete(entry)) return;
|
|
26
|
+
if (current.size === 0) this.#handlers.delete(event);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
emit(event, payload) {
|
|
30
|
+
const set = this.#handlers.get(event);
|
|
31
|
+
if (!set) return;
|
|
32
|
+
for (const handler of [...set]) try {
|
|
33
|
+
const result = handler(payload);
|
|
34
|
+
if (result instanceof Promise) result.catch((error) => this.#onError(error, event));
|
|
35
|
+
} catch (error) {
|
|
36
|
+
this.#onError(error, event);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
listenerCount(event) {
|
|
40
|
+
return this.#handlers.get(event)?.size ?? 0;
|
|
41
|
+
}
|
|
42
|
+
/** Remove todas as assinaturas (ex.: no `disconnect()` definitivo do adapter). */
|
|
43
|
+
clear() {
|
|
44
|
+
this.#handlers.clear();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/transport/define.ts
|
|
49
|
+
/** Problemas da descrição, um por linha; lista vazia = válida. */
|
|
50
|
+
function transportSpecIssues(value) {
|
|
51
|
+
if (typeof value !== "object" || value === null) return ["a função do defineTransport deve devolver um objeto"];
|
|
52
|
+
const spec = value;
|
|
53
|
+
const issues = [];
|
|
54
|
+
if (typeof spec["name"] !== "string" || spec["name"] === "") issues.push("name deve ser um texto não vazio");
|
|
55
|
+
for (const method of [
|
|
56
|
+
"connect",
|
|
57
|
+
"disconnect",
|
|
58
|
+
"send"
|
|
59
|
+
]) if (typeof spec[method] !== "function") issues.push(`${method} deve ser uma função`);
|
|
60
|
+
const capabilities = spec["capabilities"];
|
|
61
|
+
if (!Array.isArray(capabilities)) {
|
|
62
|
+
issues.push("capabilities deve ser uma lista (ex.: [\"send.text\"])");
|
|
63
|
+
return issues;
|
|
64
|
+
}
|
|
65
|
+
return [...issues, ...capabilityIssues(capabilities, spec)];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Monta a fábrica do transport (ADR 0037) a partir da descrição que `build` devolve. A descrição
|
|
69
|
+
* inválida lança `TypeError` com todos os problemas, e o `createBot` a converte em
|
|
70
|
+
* `BotConfigError`. Cada método confere a capability antes de chamar o do adapter; o que ele não
|
|
71
|
+
* implementa rejeita com `UnsupportedError`.
|
|
72
|
+
*/
|
|
73
|
+
function defineTransport(build) {
|
|
74
|
+
return (deps) => {
|
|
75
|
+
const events = new TypedEmitter((error, event) => deps.log.error("handler de evento do transport falhou", {
|
|
76
|
+
err: error,
|
|
77
|
+
event
|
|
78
|
+
}));
|
|
79
|
+
let self = null;
|
|
80
|
+
const spec = build(deps, {
|
|
81
|
+
emit: (event, payload) => events.emit(event, payload),
|
|
82
|
+
setSelf: (contact) => {
|
|
83
|
+
self = contact;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const issues = transportSpecIssues(spec);
|
|
87
|
+
if (issues.length > 0) {
|
|
88
|
+
const name = typeof spec?.name === "string" ? `"${spec.name}" ` : "";
|
|
89
|
+
throw new TypeError(`transport ${name}inválido:\n- ${issues.join("\n- ")}`);
|
|
90
|
+
}
|
|
91
|
+
return assemble(spec, events, () => self);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function assemble(spec, events, self) {
|
|
95
|
+
const capabilities = new Set(spec.capabilities);
|
|
96
|
+
const holder = {
|
|
97
|
+
name: spec.name,
|
|
98
|
+
capabilities
|
|
99
|
+
};
|
|
100
|
+
/** Confere a capability e chama o método do adapter; sem ele, `UnsupportedError`. */
|
|
101
|
+
const gated = async (capability, call) => {
|
|
102
|
+
assertCapability(holder, capability);
|
|
103
|
+
if (call === void 0) throw new UnsupportedError(capability, spec.name);
|
|
104
|
+
return call(spec);
|
|
105
|
+
};
|
|
106
|
+
const { react, edit, getGroupMetadata, updateGroupParticipants, sendTyping, raw, isChatAdmin } = spec;
|
|
107
|
+
const remove = spec.delete;
|
|
108
|
+
return {
|
|
109
|
+
name: spec.name,
|
|
110
|
+
capabilities,
|
|
111
|
+
get self() {
|
|
112
|
+
return self();
|
|
113
|
+
},
|
|
114
|
+
native: spec.native,
|
|
115
|
+
...spec.limits !== void 0 && { limits: spec.limits },
|
|
116
|
+
...spec.pacing !== void 0 && { pacing: spec.pacing },
|
|
117
|
+
...raw !== void 0 && { raw: (source) => raw.call(spec, source) },
|
|
118
|
+
...isChatAdmin !== void 0 && { isChatAdmin: (chat, contact) => isChatAdmin.call(spec, chat, contact) },
|
|
119
|
+
connect: () => spec.connect(),
|
|
120
|
+
disconnect: () => spec.disconnect(),
|
|
121
|
+
on: (event, handler) => events.on(event, handler),
|
|
122
|
+
send: async (chatId, content, options) => {
|
|
123
|
+
assertCanSend(holder, content, options);
|
|
124
|
+
return spec.send(chatId, content, options);
|
|
125
|
+
},
|
|
126
|
+
react: (key, emoji) => gated("reactions", react && ((s) => react.call(s, key, emoji))),
|
|
127
|
+
edit: (key, text, formatted) => gated("message.edit", edit && ((s) => edit.call(s, key, text, formatted))),
|
|
128
|
+
delete: (key) => gated("message.delete", remove && ((s) => remove.call(s, key))),
|
|
129
|
+
sendTyping: (chatId, kind) => gated("typing", sendTyping && ((s) => sendTyping.call(s, chatId, kind))),
|
|
130
|
+
getGroupMetadata: (groupId) => gated("groups", getGroupMetadata && ((s) => getGroupMetadata.call(s, groupId))),
|
|
131
|
+
updateGroupParticipants: (groupId, participantIds, action) => gated(groupActionCapability(action), updateGroupParticipants && ((s) => updateGroupParticipants.call(s, groupId, participantIds, action)))
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
export { CAPABILITIES, ReconnectionPolicy, StorageClosedError, TypedEmitter, assertCanSend, assertCapability, assertFieldName, capabilitiesForSend, cloneJson, createMedia, createMessage, defineTransport, groupActionCapability, hasCapability, isCapability, messageKey, missingCapabilities, normalizeDocument, normalizeIndexes, normalizeQuery, normalizeWhere };
|
|
136
|
+
|
|
137
|
+
//# sourceMappingURL=adapter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.mjs","names":[],"sources":["../src/transport/emitter.ts","../src/transport/define.ts"],"sourcesContent":["import type { Unsubscribe } from './types.ts';\n\ntype Handler<P> = (payload: P) => void | Promise<void>;\n\n/** Destino dos erros de handlers: o emissor nunca os deixa subir para o adapter. */\nexport type EmitterErrorHandler<Events> = (error: unknown, event: keyof Events) => void;\n\n/**\n * Emissor tipado por instância, para os adapters implementarem `Transport.on()` sem estado\n * global. Um handler que falha (síncrono ou rejeitando) não impede os demais: o erro vai para\n * `onError`, porque o adapter, que emite, não tem o que fazer com ele.\n */\nexport class TypedEmitter<Events extends object> {\n readonly #handlers = new Map<keyof Events, Set<Handler<never>>>();\n readonly #onError: EmitterErrorHandler<Events>;\n\n constructor(onError: EmitterErrorHandler<Events>) {\n this.#onError = onError;\n }\n\n on<E extends keyof Events>(event: E, handler: Handler<Events[E]>): Unsubscribe {\n let set = this.#handlers.get(event);\n if (!set) {\n set = new Set();\n this.#handlers.set(event, set);\n }\n // Wrapper próprio: o mesmo handler assinado duas vezes vira duas assinaturas independentes.\n const entry: Handler<never> = (payload) => handler(payload);\n set.add(entry);\n return () => {\n const current = this.#handlers.get(event);\n if (!current?.delete(entry)) return;\n // Remove o Set vazio para eventos sem assinante não acumularem entradas no Map.\n if (current.size === 0) this.#handlers.delete(event);\n };\n }\n\n emit<E extends keyof Events>(event: E, payload: Events[E]): void {\n const set = this.#handlers.get(event);\n if (!set) return;\n // Cópia: handlers podem (des)assinar durante a emissão sem afetar esta rodada.\n for (const handler of [...set] as Handler<Events[E]>[]) {\n try {\n const result = handler(payload);\n if (result instanceof Promise) {\n result.catch((error: unknown) => this.#onError(error, event));\n }\n } catch (error) {\n this.#onError(error, event);\n }\n }\n }\n\n listenerCount(event: keyof Events): number {\n return this.#handlers.get(event)?.size ?? 0;\n }\n\n /** Remove todas as assinaturas (ex.: no `disconnect()` definitivo do adapter). */\n clear(): void {\n this.#handlers.clear();\n }\n}\n","// Açúcar para o autor de transport (ADR 0080). O adapter descreve só o que é dele (conectar,\n// enviar, os métodos das capabilities que declara), e `defineTransport` monta o `Transport`\n// completo: emissor, `on()`, `self`, a checagem de capability e o `UnsupportedError` do resto.\n\nimport type { Chat, Contact, Message } from '#message/types.ts';\nimport {\n assertCanSend,\n assertCapability,\n type Capability,\n groupActionCapability,\n UnsupportedError,\n} from './capabilities.ts';\nimport { TypedEmitter } from './emitter.ts';\nimport { type CapabilityMethod, capabilityIssues } from './methods.ts';\nimport type {\n Interaction,\n TextLimits,\n Transport,\n TransportDeps,\n TransportEventName,\n TransportEvents,\n TransportPacing,\n} from './types.ts';\n\n/** O que `defineTransport` entrega ao adapter, além das `TransportDeps`. */\nexport interface TransportKit {\n /** Entrega um evento ao kernel. Erro de handler vai para o log, nunca para o adapter. */\n emit<E extends TransportEventName>(event: E, payload: TransportEvents[E]): void;\n /** Contato da própria sessão, lido em `Transport.self`. Chame ao abrir a conexão. */\n setSelf(contact: Contact | null): void;\n}\n\n/**\n * O transport como o adapter o descreve: o contrato `Transport` sem o que `defineTransport`\n * monta (`on`, `self`), com `capabilities` em lista e os métodos de capability opcionais.\n */\nexport interface TransportSpec\n extends Pick<Transport, 'connect' | 'disconnect' | 'send'>,\n Partial<Pick<Transport, CapabilityMethod | 'raw' | 'isChatAdmin'>> {\n readonly name: string;\n readonly capabilities: readonly Capability[];\n readonly native?: unknown;\n readonly limits?: TextLimits;\n readonly pacing?: TransportPacing;\n}\n\n/** Problemas da descrição, um por linha; lista vazia = válida. */\nexport function transportSpecIssues(value: unknown): string[] {\n if (typeof value !== 'object' || value === null) {\n return ['a função do defineTransport deve devolver um objeto'];\n }\n const spec = value as Record<string, unknown>;\n const issues: string[] = [];\n if (typeof spec['name'] !== 'string' || spec['name'] === '') {\n issues.push('name deve ser um texto não vazio');\n }\n for (const method of ['connect', 'disconnect', 'send']) {\n if (typeof spec[method] !== 'function') issues.push(`${method} deve ser uma função`);\n }\n const capabilities = spec['capabilities'];\n if (!Array.isArray(capabilities)) {\n issues.push('capabilities deve ser uma lista (ex.: [\"send.text\"])');\n return issues;\n }\n return [...issues, ...capabilityIssues(capabilities, spec)];\n}\n\n/**\n * Monta a fábrica do transport (ADR 0037) a partir da descrição que `build` devolve. A descrição\n * inválida lança `TypeError` com todos os problemas, e o `createBot` a converte em\n * `BotConfigError`. Cada método confere a capability antes de chamar o do adapter; o que ele não\n * implementa rejeita com `UnsupportedError`.\n */\nexport function defineTransport(\n build: (deps: TransportDeps, kit: TransportKit) => TransportSpec,\n): (deps: TransportDeps) => Transport {\n return (deps) => {\n const events = new TypedEmitter<TransportEvents>((error, event) =>\n deps.log.error('handler de evento do transport falhou', { err: error, event }),\n );\n let self: Contact | null = null;\n const spec = build(deps, {\n emit: (event, payload) => events.emit(event, payload),\n setSelf: (contact) => {\n self = contact;\n },\n });\n const issues = transportSpecIssues(spec);\n if (issues.length > 0) {\n const name = typeof spec?.name === 'string' ? `\"${spec.name}\" ` : '';\n throw new TypeError(`transport ${name}inválido:\\n- ${issues.join('\\n- ')}`);\n }\n return assemble(spec, events, () => self);\n };\n}\n\nfunction assemble(\n spec: TransportSpec,\n events: TypedEmitter<TransportEvents>,\n self: () => Contact | null,\n): Transport {\n const capabilities: ReadonlySet<Capability> = new Set(spec.capabilities);\n const holder = { name: spec.name, capabilities };\n /** Confere a capability e chama o método do adapter; sem ele, `UnsupportedError`. */\n const gated = async <R>(\n capability: Capability,\n call: ((spec: TransportSpec) => Promise<R>) | undefined,\n ): Promise<R> => {\n assertCapability(holder, capability);\n // A coerência foi conferida na montagem: só falta o método se a capability não foi declarada.\n if (call === undefined) throw new UnsupportedError(capability, spec.name);\n return call(spec);\n };\n const { react, edit, getGroupMetadata, updateGroupParticipants, sendTyping, raw, isChatAdmin } =\n spec;\n const remove = spec.delete;\n return {\n name: spec.name,\n capabilities,\n get self() {\n return self();\n },\n native: spec.native,\n ...(spec.limits !== undefined && { limits: spec.limits }),\n ...(spec.pacing !== undefined && { pacing: spec.pacing }),\n ...(raw !== undefined && {\n raw: (source: Message | Interaction) => raw.call(spec, source),\n }),\n ...(isChatAdmin !== undefined && {\n isChatAdmin: (chat: Chat, contact: Contact) => isChatAdmin.call(spec, chat, contact),\n }),\n connect: () => spec.connect(),\n disconnect: () => spec.disconnect(),\n on: (event, handler) => events.on(event, handler),\n send: async (chatId, content, options) => {\n assertCanSend(holder, content, options);\n return spec.send(chatId, content, options);\n },\n react: (key, emoji) => gated('reactions', react && ((s) => react.call(s, key, emoji))),\n edit: (key, text, formatted) =>\n gated('message.edit', edit && ((s) => edit.call(s, key, text, formatted))),\n delete: (key) => gated('message.delete', remove && ((s) => remove.call(s, key))),\n sendTyping: (chatId, kind) =>\n gated('typing', sendTyping && ((s) => sendTyping.call(s, chatId, kind))),\n getGroupMetadata: (groupId) =>\n gated('groups', getGroupMetadata && ((s) => getGroupMetadata.call(s, groupId))),\n updateGroupParticipants: (groupId, participantIds, action) =>\n gated(\n groupActionCapability(action),\n updateGroupParticipants &&\n ((s) => updateGroupParticipants.call(s, groupId, participantIds, action)),\n ),\n };\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/storage/errors.ts
|
|
2
|
+
/** Operação depois de `StoragePort.close()`. */
|
|
3
|
+
var StorageClosedError = class extends Error {
|
|
4
|
+
name = "StorageClosedError";
|
|
5
|
+
constructor() {
|
|
6
|
+
super("Storage fechado: a operação foi chamada depois de close().");
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
/** Plugin com nome que cai no namespace reservado do kernel ou no de outra sessão. */
|
|
10
|
+
var ReservedNamespaceError = class extends Error {
|
|
11
|
+
name = "ReservedNamespaceError";
|
|
12
|
+
namespace;
|
|
13
|
+
constructor(namespace) {
|
|
14
|
+
super(`Namespace de storage "${namespace}" é reservado (prefixo "$" é do kernel; ":" separa a sessão; "@", o tenant). Renomeie o plugin.`);
|
|
15
|
+
this.namespace = namespace;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { StorageClosedError as n, ReservedNamespaceError as t };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=errors-B3UWcNDO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-B3UWcNDO.mjs","names":[],"sources":["../src/storage/errors.ts"],"sourcesContent":["// Erros do contrato de storage. Todo adapter usa estas classes para que quem chama (kernel,\n// plugins, suíte de contrato) trate a falha igual em memória, SQLite ou Postgres.\n\n/** Operação depois de `StoragePort.close()`. */\nexport class StorageClosedError extends Error {\n override readonly name = 'StorageClosedError';\n\n constructor() {\n super('Storage fechado: a operação foi chamada depois de close().');\n }\n}\n\n/** Plugin com nome que cai no namespace reservado do kernel ou no de outra sessão. */\nexport class ReservedNamespaceError extends Error {\n override readonly name = 'ReservedNamespaceError';\n readonly namespace: string;\n\n constructor(namespace: string) {\n super(\n `Namespace de storage \"${namespace}\" é reservado (prefixo \"$\" é do kernel; \":\" separa ` +\n 'a sessão; \"@\", o tenant). Renomeie o plugin.',\n );\n this.namespace = namespace;\n }\n}\n"],"mappings":";;AAIA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,OAAyB;CAEzB,cAAc;EACZ,MAAM,4DAA4D;CACpE;AACF;;AAGA,IAAa,yBAAb,cAA4C,MAAM;CAChD,OAAyB;CACzB;CAEA,YAAY,WAAmB;EAC7B,MACE,yBAAyB,UAAU,gGAErC;EACA,KAAK,YAAY;CACnB;AACF"}
|