@palbase/modules-docs 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present Palbase
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,293 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ CollectionRef: () => CollectionRef,
24
+ DocsClient: () => DocsClient,
25
+ DocumentRef: () => DocumentRef
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/docs-client.ts
30
+ var import_core = require("@palbase/core");
31
+
32
+ // src/document-ref.ts
33
+ var SEGMENT_RE = /^[a-zA-Z0-9_\-]+$/;
34
+ function validateSegment(segment, label) {
35
+ if (!SEGMENT_RE.test(segment)) {
36
+ throw new Error(`Invalid ${label}: "${segment}". Must match ${SEGMENT_RE.source}`);
37
+ }
38
+ }
39
+ var DocumentRef = class {
40
+ path;
41
+ httpClient;
42
+ constructor(httpClient, path) {
43
+ this.httpClient = httpClient;
44
+ this.path = path;
45
+ }
46
+ async set(data) {
47
+ return this.httpClient.request("PUT", `/v1/docs/${this.path}`, {
48
+ body: data
49
+ });
50
+ }
51
+ async get() {
52
+ const response = await this.httpClient.request(
53
+ "GET",
54
+ `/v1/docs/${this.path}`
55
+ );
56
+ if (response.error) {
57
+ return {
58
+ data: null,
59
+ error: response.error,
60
+ status: response.status
61
+ };
62
+ }
63
+ const raw = response.data;
64
+ const snapshot = {
65
+ id: raw?.id ?? this.getDocId(),
66
+ exists: raw?.exists ?? false,
67
+ data: () => raw?.data,
68
+ ref: { path: this.path }
69
+ };
70
+ return { data: snapshot, error: null, status: response.status };
71
+ }
72
+ async update(data) {
73
+ return this.httpClient.request("PATCH", `/v1/docs/${this.path}`, {
74
+ body: data
75
+ });
76
+ }
77
+ async delete() {
78
+ return this.httpClient.request("DELETE", `/v1/docs/${this.path}`);
79
+ }
80
+ collection(name) {
81
+ validateSegment(name, "subcollection name");
82
+ return new CollectionRef(this.httpClient, `${this.path}/${name}`);
83
+ }
84
+ getDocId() {
85
+ const segments = this.path.split("/");
86
+ return segments[segments.length - 1] ?? "";
87
+ }
88
+ };
89
+
90
+ // src/collection-ref.ts
91
+ var SEGMENT_RE2 = /^[a-zA-Z0-9_\-]+$/;
92
+ function validateSegment2(segment, label) {
93
+ if (!SEGMENT_RE2.test(segment)) {
94
+ throw new Error(`Invalid ${label}: "${segment}". Must match ${SEGMENT_RE2.source}`);
95
+ }
96
+ }
97
+ var CollectionRef = class _CollectionRef {
98
+ path;
99
+ httpClient;
100
+ whereClauses = [];
101
+ orderByClauses = [];
102
+ limitValue;
103
+ constructor(httpClient, path) {
104
+ this.httpClient = httpClient;
105
+ this.path = path;
106
+ }
107
+ doc(id) {
108
+ validateSegment2(id, "document ID");
109
+ return new DocumentRef(this.httpClient, `${this.path}/${id}`);
110
+ }
111
+ async add(data) {
112
+ const response = await this.httpClient.request(
113
+ "POST",
114
+ `/v1/docs/${this.path}`,
115
+ { body: data }
116
+ );
117
+ if (response.error || !response.data) {
118
+ return {
119
+ data: null,
120
+ error: response.error,
121
+ status: response.status
122
+ };
123
+ }
124
+ const ref = new DocumentRef(this.httpClient, `${this.path}/${response.data.id}`);
125
+ return { data: ref, error: null, status: response.status };
126
+ }
127
+ where(field, op, value) {
128
+ const clone = this.clone();
129
+ clone.whereClauses.push({ field, op, value });
130
+ return clone;
131
+ }
132
+ orderBy(field, direction) {
133
+ const clone = this.clone();
134
+ clone.orderByClauses.push({ field, direction: direction ?? "asc" });
135
+ return clone;
136
+ }
137
+ limit(n) {
138
+ const clone = this.clone();
139
+ clone.limitValue = n;
140
+ return clone;
141
+ }
142
+ async get() {
143
+ const hasQuery = this.whereClauses.length > 0 || this.orderByClauses.length > 0 || this.limitValue !== void 0;
144
+ if (hasQuery) {
145
+ return this.executeQuery();
146
+ }
147
+ const response = await this.httpClient.request(
148
+ "GET",
149
+ `/v1/docs/${this.path}`
150
+ );
151
+ if (response.error) {
152
+ return { data: null, error: response.error, status: response.status };
153
+ }
154
+ const docs = (response.data?.documents ?? []).map((doc) => this.toSnapshot(doc));
155
+ return {
156
+ data: this.toQuerySnapshot(docs),
157
+ error: null,
158
+ status: response.status
159
+ };
160
+ }
161
+ onSnapshot(callback) {
162
+ const body = this.buildQueryBody();
163
+ let active = true;
164
+ let controller;
165
+ const poll = async () => {
166
+ if (!active) return;
167
+ controller = new AbortController();
168
+ const response = await this.httpClient.request(
169
+ "POST",
170
+ `/v1/docs/${this.path}/listen`,
171
+ { body, signal: controller.signal }
172
+ );
173
+ if (!active) return;
174
+ if (response.data) {
175
+ const docs = (response.data.documents ?? []).map((doc) => this.toSnapshot(doc));
176
+ callback(this.toQuerySnapshot(docs));
177
+ }
178
+ };
179
+ void poll();
180
+ return () => {
181
+ active = false;
182
+ controller?.abort();
183
+ };
184
+ }
185
+ async executeQuery() {
186
+ const body = this.buildQueryBody();
187
+ const response = await this.httpClient.request(
188
+ "POST",
189
+ `/v1/docs/${this.path}/query`,
190
+ { body }
191
+ );
192
+ if (response.error) {
193
+ return { data: null, error: response.error, status: response.status };
194
+ }
195
+ const docs = (response.data?.documents ?? []).map((doc) => this.toSnapshot(doc));
196
+ return {
197
+ data: this.toQuerySnapshot(docs),
198
+ error: null,
199
+ status: response.status
200
+ };
201
+ }
202
+ buildQueryBody() {
203
+ const body = {};
204
+ if (this.whereClauses.length > 0) {
205
+ body["where"] = this.whereClauses.map((w) => ({
206
+ field: w.field,
207
+ op: w.op,
208
+ value: w.value
209
+ }));
210
+ }
211
+ if (this.orderByClauses.length > 0) {
212
+ body["orderBy"] = this.orderByClauses.map((o) => ({
213
+ field: o.field,
214
+ direction: o.direction
215
+ }));
216
+ }
217
+ if (this.limitValue !== void 0) {
218
+ body["limit"] = this.limitValue;
219
+ }
220
+ return body;
221
+ }
222
+ toSnapshot(doc) {
223
+ return {
224
+ id: doc.id,
225
+ exists: true,
226
+ data: () => doc.data,
227
+ ref: { path: `${this.path}/${doc.id}` }
228
+ };
229
+ }
230
+ toQuerySnapshot(docs) {
231
+ return {
232
+ docs,
233
+ empty: docs.length === 0,
234
+ size: docs.length,
235
+ docChanges: () => docs.map((doc) => ({ type: "added", doc }))
236
+ };
237
+ }
238
+ clone() {
239
+ const cloned = new _CollectionRef(this.httpClient, this.path);
240
+ cloned.whereClauses.push(...this.whereClauses);
241
+ cloned.orderByClauses.push(...this.orderByClauses);
242
+ cloned.limitValue = this.limitValue;
243
+ return cloned;
244
+ }
245
+ };
246
+
247
+ // src/docs-client.ts
248
+ var MAX_BATCH_SIZE = 500;
249
+ var SEGMENT_RE3 = /^[a-zA-Z0-9_\-]+$/;
250
+ function validateSegment3(segment, label) {
251
+ if (!SEGMENT_RE3.test(segment)) {
252
+ throw new Error(`Invalid ${label}: "${segment}". Must match ${SEGMENT_RE3.source}`);
253
+ }
254
+ }
255
+ var DocsClient = class {
256
+ httpClient;
257
+ constructor(httpClient) {
258
+ this.httpClient = httpClient;
259
+ }
260
+ collection(name) {
261
+ validateSegment3(name, "collection name");
262
+ return new CollectionRef(this.httpClient, name);
263
+ }
264
+ async batch(operations) {
265
+ if (operations.length > MAX_BATCH_SIZE) {
266
+ return {
267
+ data: null,
268
+ error: new import_core.PalbaseError(
269
+ "batch_too_large",
270
+ `Batch size ${operations.length} exceeds maximum of ${MAX_BATCH_SIZE}`,
271
+ 400
272
+ ),
273
+ status: 400
274
+ };
275
+ }
276
+ if (operations.length === 0) {
277
+ return { data: null, error: null, status: 200 };
278
+ }
279
+ const body = operations.map((op) => ({
280
+ op: op.op,
281
+ path: op.ref.path,
282
+ data: op.data
283
+ }));
284
+ return this.httpClient.request("POST", "/v1/docs/batch", { body });
285
+ }
286
+ };
287
+ // Annotate the CommonJS export names for ESM import in node:
288
+ 0 && (module.exports = {
289
+ CollectionRef,
290
+ DocsClient,
291
+ DocumentRef
292
+ });
293
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/docs-client.ts","../src/document-ref.ts","../src/collection-ref.ts"],"sourcesContent":["export { DocsClient } from './docs-client.js';\nexport { CollectionRef } from './collection-ref.js';\nexport { DocumentRef } from './document-ref.js';\nexport type {\n WhereOperator,\n OrderDirection,\n WhereClause,\n OrderByClause,\n DocumentData,\n DocumentSnapshot,\n DocChange,\n QuerySnapshot,\n SnapshotCallback,\n BatchOperationType,\n BatchOperation,\n} from './types.js';\n","import type { HttpClient, PalbaseResponse } from '@palbase/core';\nimport { PalbaseError } from '@palbase/core';\nimport { CollectionRef } from './collection-ref.js';\nimport type { BatchOperation, DocumentData } from './types.js';\n\nconst MAX_BATCH_SIZE = 500;\nconst SEGMENT_RE = /^[a-zA-Z0-9_\\-]+$/;\n\nfunction validateSegment(segment: string, label: string): void {\n if (!SEGMENT_RE.test(segment)) {\n throw new Error(`Invalid ${label}: \"${segment}\". Must match ${SEGMENT_RE.source}`);\n }\n}\n\nexport class DocsClient {\n private readonly httpClient: HttpClient;\n\n constructor(httpClient: HttpClient) {\n this.httpClient = httpClient;\n }\n\n collection<T = DocumentData>(name: string): CollectionRef<T> {\n validateSegment(name, 'collection name');\n return new CollectionRef<T>(this.httpClient, name);\n }\n\n async batch(operations: BatchOperation[]): Promise<PalbaseResponse<void>> {\n if (operations.length > MAX_BATCH_SIZE) {\n return {\n data: null,\n error: new PalbaseError(\n 'batch_too_large',\n `Batch size ${operations.length} exceeds maximum of ${MAX_BATCH_SIZE}`,\n 400,\n ),\n status: 400,\n };\n }\n\n if (operations.length === 0) {\n return { data: null, error: null, status: 200 };\n }\n\n const body = operations.map((op) => ({\n op: op.op,\n path: op.ref.path,\n data: op.data,\n }));\n\n return this.httpClient.request<void>('POST', '/v1/docs/batch', { body });\n }\n}\n","import type { HttpClient, PalbaseResponse } from '@palbase/core';\nimport { CollectionRef } from './collection-ref.js';\nimport type { DocumentData, DocumentSnapshot } from './types.js';\n\nconst SEGMENT_RE = /^[a-zA-Z0-9_\\-]+$/;\n\nfunction validateSegment(segment: string, label: string): void {\n if (!SEGMENT_RE.test(segment)) {\n throw new Error(`Invalid ${label}: \"${segment}\". Must match ${SEGMENT_RE.source}`);\n }\n}\n\nexport class DocumentRef<T = DocumentData> {\n readonly path: string;\n private readonly httpClient: HttpClient;\n\n constructor(httpClient: HttpClient, path: string) {\n this.httpClient = httpClient;\n this.path = path;\n }\n\n async set(data: T): Promise<PalbaseResponse<void>> {\n return this.httpClient.request<void>('PUT', `/v1/docs/${this.path}`, {\n body: data,\n });\n }\n\n async get(): Promise<PalbaseResponse<DocumentSnapshot<T>>> {\n const response = await this.httpClient.request<{ id: string; data: T; exists: boolean }>(\n 'GET',\n `/v1/docs/${this.path}`,\n );\n\n if (response.error) {\n return {\n data: null,\n error: response.error,\n status: response.status,\n };\n }\n\n const raw = response.data;\n const snapshot: DocumentSnapshot<T> = {\n id: raw?.id ?? this.getDocId(),\n exists: raw?.exists ?? false,\n data: () => raw?.data,\n ref: { path: this.path },\n };\n\n return { data: snapshot, error: null, status: response.status };\n }\n\n async update(data: Partial<T>): Promise<PalbaseResponse<void>> {\n return this.httpClient.request<void>('PATCH', `/v1/docs/${this.path}`, {\n body: data,\n });\n }\n\n async delete(): Promise<PalbaseResponse<void>> {\n return this.httpClient.request<void>('DELETE', `/v1/docs/${this.path}`);\n }\n\n collection(name: string): CollectionRef {\n validateSegment(name, 'subcollection name');\n return new CollectionRef(this.httpClient, `${this.path}/${name}`);\n }\n\n private getDocId(): string {\n const segments = this.path.split('/');\n return segments[segments.length - 1] ?? '';\n }\n}\n","import type { HttpClient, PalbaseResponse } from '@palbase/core';\nimport { DocumentRef } from './document-ref.js';\nimport type {\n DocumentData,\n DocumentSnapshot,\n OrderByClause,\n OrderDirection,\n QuerySnapshot,\n SnapshotCallback,\n WhereClause,\n WhereOperator,\n} from './types.js';\n\nconst SEGMENT_RE = /^[a-zA-Z0-9_\\-]+$/;\n\nfunction validateSegment(segment: string, label: string): void {\n if (!SEGMENT_RE.test(segment)) {\n throw new Error(`Invalid ${label}: \"${segment}\". Must match ${SEGMENT_RE.source}`);\n }\n}\n\nexport class CollectionRef<T = DocumentData> {\n readonly path: string;\n private readonly httpClient: HttpClient;\n private readonly whereClauses: WhereClause[] = [];\n private readonly orderByClauses: OrderByClause[] = [];\n private limitValue: number | undefined;\n\n constructor(httpClient: HttpClient, path: string) {\n this.httpClient = httpClient;\n this.path = path;\n }\n\n doc(id: string): DocumentRef<T> {\n validateSegment(id, 'document ID');\n return new DocumentRef<T>(this.httpClient, `${this.path}/${id}`);\n }\n\n async add(data: T): Promise<PalbaseResponse<DocumentRef<T>>> {\n const response = await this.httpClient.request<{ id: string }>(\n 'POST',\n `/v1/docs/${this.path}`,\n { body: data },\n );\n\n if (response.error || !response.data) {\n return {\n data: null,\n error: response.error,\n status: response.status,\n };\n }\n\n const ref = new DocumentRef<T>(this.httpClient, `${this.path}/${response.data.id}`);\n return { data: ref, error: null, status: response.status };\n }\n\n where(field: string, op: WhereOperator, value: unknown): CollectionRef<T> {\n const clone = this.clone();\n clone.whereClauses.push({ field, op, value });\n return clone;\n }\n\n orderBy(field: string, direction?: OrderDirection): CollectionRef<T> {\n const clone = this.clone();\n clone.orderByClauses.push({ field, direction: direction ?? 'asc' });\n return clone;\n }\n\n limit(n: number): CollectionRef<T> {\n const clone = this.clone();\n clone.limitValue = n;\n return clone;\n }\n\n async get(): Promise<PalbaseResponse<QuerySnapshot<T>>> {\n const hasQuery = this.whereClauses.length > 0 || this.orderByClauses.length > 0 || this.limitValue !== undefined;\n\n if (hasQuery) {\n return this.executeQuery();\n }\n\n const response = await this.httpClient.request<{ documents: { id: string; data: T }[] }>(\n 'GET',\n `/v1/docs/${this.path}`,\n );\n\n if (response.error) {\n return { data: null, error: response.error, status: response.status };\n }\n\n const docs = (response.data?.documents ?? []).map((doc) => this.toSnapshot(doc));\n return {\n data: this.toQuerySnapshot(docs),\n error: null,\n status: response.status,\n };\n }\n\n onSnapshot(callback: SnapshotCallback<T>): () => void {\n const body = this.buildQueryBody();\n\n let active = true;\n let controller: AbortController | undefined;\n\n const poll = async () => {\n if (!active) return;\n controller = new AbortController();\n\n const response = await this.httpClient.request<{ documents: { id: string; data: T }[] }>(\n 'POST',\n `/v1/docs/${this.path}/listen`,\n { body, signal: controller.signal },\n );\n\n if (!active) return;\n\n if (response.data) {\n const docs = (response.data.documents ?? []).map((doc) => this.toSnapshot(doc));\n callback(this.toQuerySnapshot(docs));\n }\n };\n\n // Start initial poll\n void poll();\n\n return () => {\n active = false;\n controller?.abort();\n };\n }\n\n private async executeQuery(): Promise<PalbaseResponse<QuerySnapshot<T>>> {\n const body = this.buildQueryBody();\n\n const response = await this.httpClient.request<{ documents: { id: string; data: T }[] }>(\n 'POST',\n `/v1/docs/${this.path}/query`,\n { body },\n );\n\n if (response.error) {\n return { data: null, error: response.error, status: response.status };\n }\n\n const docs = (response.data?.documents ?? []).map((doc) => this.toSnapshot(doc));\n return {\n data: this.toQuerySnapshot(docs),\n error: null,\n status: response.status,\n };\n }\n\n private buildQueryBody(): Record<string, unknown> {\n const body: Record<string, unknown> = {};\n\n if (this.whereClauses.length > 0) {\n body['where'] = this.whereClauses.map((w) => ({\n field: w.field,\n op: w.op,\n value: w.value,\n }));\n }\n\n if (this.orderByClauses.length > 0) {\n body['orderBy'] = this.orderByClauses.map((o) => ({\n field: o.field,\n direction: o.direction,\n }));\n }\n\n if (this.limitValue !== undefined) {\n body['limit'] = this.limitValue;\n }\n\n return body;\n }\n\n private toSnapshot(doc: { id: string; data: T }): DocumentSnapshot<T> {\n return {\n id: doc.id,\n exists: true,\n data: () => doc.data,\n ref: { path: `${this.path}/${doc.id}` },\n };\n }\n\n private toQuerySnapshot(docs: DocumentSnapshot<T>[]): QuerySnapshot<T> {\n return {\n docs,\n empty: docs.length === 0,\n size: docs.length,\n docChanges: () => docs.map((doc) => ({ type: 'added' as const, doc })),\n };\n }\n\n private clone(): CollectionRef<T> {\n const cloned = new CollectionRef<T>(this.httpClient, this.path);\n cloned.whereClauses.push(...this.whereClauses);\n cloned.orderByClauses.push(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AK,YAAY,IAAI;AAAA,EACnD;AAAA,EAEA,MAAM,MAAM,YAA8D;AACxE,QAAI,WAAW,SAAS,gBAAgB;AACtC,aAAO;AAAA,QACL,MAAM;AAAA,QACN,OAAO,IAAI;AAAA,UACT;AAAA,UACA,cAAc,WAAW,MAAM,uBAAuB,cAAc;AAAA,UACpE;AAAA,QACF;AAAA,QACA,QAAQ;AAAA,MACV;AAAA,IACF;AAEA,QAAI,WAAW,WAAW,GAAG;AAC3B,aAAO,EAAE,MAAM,MAAM,OAAO,MAAM,QAAQ,IAAI;AAAA,IAChD;AAEA,UAAM,OAAO,WAAW,IAAI,CAAC,QAAQ;AAAA,MACnC,IAAI,GAAG;AAAA,MACP,MAAM,GAAG,IAAI;AAAA,MACb,MAAM,GAAG;AAAA,IACX,EAAE;AAEF,WAAO,KAAK,WAAW,QAAc,QAAQ,kBAAkB,EAAE,KAAK,CAAC;AAAA,EACzE;AACF;","names":["SEGMENT_RE","validateSegment","SEGMENT_RE","validateSegment"]}
@@ -0,0 +1,85 @@
1
+ import { HttpClient, PalbaseResponse } from '@palbase/core';
2
+
3
+ type WhereOperator = '==' | '!=' | '<' | '<=' | '>' | '>=' | 'in' | 'array-contains';
4
+ type OrderDirection = 'asc' | 'desc';
5
+ interface WhereClause {
6
+ field: string;
7
+ op: WhereOperator;
8
+ value: unknown;
9
+ }
10
+ interface OrderByClause {
11
+ field: string;
12
+ direction: OrderDirection;
13
+ }
14
+ interface DocumentData {
15
+ [key: string]: unknown;
16
+ }
17
+ interface DocumentSnapshot<T = DocumentData> {
18
+ id: string;
19
+ exists: boolean;
20
+ data(): T | undefined;
21
+ ref: {
22
+ path: string;
23
+ };
24
+ }
25
+ interface DocChange<T = DocumentData> {
26
+ type: 'added' | 'modified' | 'removed';
27
+ doc: DocumentSnapshot<T>;
28
+ }
29
+ interface QuerySnapshot<T = DocumentData> {
30
+ docs: DocumentSnapshot<T>[];
31
+ empty: boolean;
32
+ size: number;
33
+ docChanges(): DocChange<T>[];
34
+ }
35
+ type SnapshotCallback<T = DocumentData> = (snapshot: QuerySnapshot<T>) => void;
36
+ type BatchOperationType = 'set' | 'update' | 'delete';
37
+ interface BatchOperation {
38
+ op: BatchOperationType;
39
+ ref: {
40
+ path: string;
41
+ };
42
+ data?: DocumentData;
43
+ }
44
+
45
+ declare class DocumentRef<T = DocumentData> {
46
+ readonly path: string;
47
+ private readonly httpClient;
48
+ constructor(httpClient: HttpClient, path: string);
49
+ set(data: T): Promise<PalbaseResponse<void>>;
50
+ get(): Promise<PalbaseResponse<DocumentSnapshot<T>>>;
51
+ update(data: Partial<T>): Promise<PalbaseResponse<void>>;
52
+ delete(): Promise<PalbaseResponse<void>>;
53
+ collection(name: string): CollectionRef;
54
+ private getDocId;
55
+ }
56
+
57
+ declare class CollectionRef<T = DocumentData> {
58
+ readonly path: string;
59
+ private readonly httpClient;
60
+ private readonly whereClauses;
61
+ private readonly orderByClauses;
62
+ private limitValue;
63
+ constructor(httpClient: HttpClient, path: string);
64
+ doc(id: string): DocumentRef<T>;
65
+ add(data: T): Promise<PalbaseResponse<DocumentRef<T>>>;
66
+ where(field: string, op: WhereOperator, value: unknown): CollectionRef<T>;
67
+ orderBy(field: string, direction?: OrderDirection): CollectionRef<T>;
68
+ limit(n: number): CollectionRef<T>;
69
+ get(): Promise<PalbaseResponse<QuerySnapshot<T>>>;
70
+ onSnapshot(callback: SnapshotCallback<T>): () => void;
71
+ private executeQuery;
72
+ private buildQueryBody;
73
+ private toSnapshot;
74
+ private toQuerySnapshot;
75
+ private clone;
76
+ }
77
+
78
+ declare class DocsClient {
79
+ private readonly httpClient;
80
+ constructor(httpClient: HttpClient);
81
+ collection<T = DocumentData>(name: string): CollectionRef<T>;
82
+ batch(operations: BatchOperation[]): Promise<PalbaseResponse<void>>;
83
+ }
84
+
85
+ export { type BatchOperation, type BatchOperationType, CollectionRef, type DocChange, DocsClient, type DocumentData, DocumentRef, type DocumentSnapshot, type OrderByClause, type OrderDirection, type QuerySnapshot, type SnapshotCallback, type WhereClause, type WhereOperator };
@@ -0,0 +1,85 @@
1
+ import { HttpClient, PalbaseResponse } from '@palbase/core';
2
+
3
+ type WhereOperator = '==' | '!=' | '<' | '<=' | '>' | '>=' | 'in' | 'array-contains';
4
+ type OrderDirection = 'asc' | 'desc';
5
+ interface WhereClause {
6
+ field: string;
7
+ op: WhereOperator;
8
+ value: unknown;
9
+ }
10
+ interface OrderByClause {
11
+ field: string;
12
+ direction: OrderDirection;
13
+ }
14
+ interface DocumentData {
15
+ [key: string]: unknown;
16
+ }
17
+ interface DocumentSnapshot<T = DocumentData> {
18
+ id: string;
19
+ exists: boolean;
20
+ data(): T | undefined;
21
+ ref: {
22
+ path: string;
23
+ };
24
+ }
25
+ interface DocChange<T = DocumentData> {
26
+ type: 'added' | 'modified' | 'removed';
27
+ doc: DocumentSnapshot<T>;
28
+ }
29
+ interface QuerySnapshot<T = DocumentData> {
30
+ docs: DocumentSnapshot<T>[];
31
+ empty: boolean;
32
+ size: number;
33
+ docChanges(): DocChange<T>[];
34
+ }
35
+ type SnapshotCallback<T = DocumentData> = (snapshot: QuerySnapshot<T>) => void;
36
+ type BatchOperationType = 'set' | 'update' | 'delete';
37
+ interface BatchOperation {
38
+ op: BatchOperationType;
39
+ ref: {
40
+ path: string;
41
+ };
42
+ data?: DocumentData;
43
+ }
44
+
45
+ declare class DocumentRef<T = DocumentData> {
46
+ readonly path: string;
47
+ private readonly httpClient;
48
+ constructor(httpClient: HttpClient, path: string);
49
+ set(data: T): Promise<PalbaseResponse<void>>;
50
+ get(): Promise<PalbaseResponse<DocumentSnapshot<T>>>;
51
+ update(data: Partial<T>): Promise<PalbaseResponse<void>>;
52
+ delete(): Promise<PalbaseResponse<void>>;
53
+ collection(name: string): CollectionRef;
54
+ private getDocId;
55
+ }
56
+
57
+ declare class CollectionRef<T = DocumentData> {
58
+ readonly path: string;
59
+ private readonly httpClient;
60
+ private readonly whereClauses;
61
+ private readonly orderByClauses;
62
+ private limitValue;
63
+ constructor(httpClient: HttpClient, path: string);
64
+ doc(id: string): DocumentRef<T>;
65
+ add(data: T): Promise<PalbaseResponse<DocumentRef<T>>>;
66
+ where(field: string, op: WhereOperator, value: unknown): CollectionRef<T>;
67
+ orderBy(field: string, direction?: OrderDirection): CollectionRef<T>;
68
+ limit(n: number): CollectionRef<T>;
69
+ get(): Promise<PalbaseResponse<QuerySnapshot<T>>>;
70
+ onSnapshot(callback: SnapshotCallback<T>): () => void;
71
+ private executeQuery;
72
+ private buildQueryBody;
73
+ private toSnapshot;
74
+ private toQuerySnapshot;
75
+ private clone;
76
+ }
77
+
78
+ declare class DocsClient {
79
+ private readonly httpClient;
80
+ constructor(httpClient: HttpClient);
81
+ collection<T = DocumentData>(name: string): CollectionRef<T>;
82
+ batch(operations: BatchOperation[]): Promise<PalbaseResponse<void>>;
83
+ }
84
+
85
+ export { type BatchOperation, type BatchOperationType, CollectionRef, type DocChange, DocsClient, type DocumentData, DocumentRef, type DocumentSnapshot, type OrderByClause, type OrderDirection, type QuerySnapshot, type SnapshotCallback, type WhereClause, type WhereOperator };
package/dist/index.js ADDED
@@ -0,0 +1,264 @@
1
+ // src/docs-client.ts
2
+ import { PalbaseError } from "@palbase/core";
3
+
4
+ // src/document-ref.ts
5
+ var SEGMENT_RE = /^[a-zA-Z0-9_\-]+$/;
6
+ function validateSegment(segment, label) {
7
+ if (!SEGMENT_RE.test(segment)) {
8
+ throw new Error(`Invalid ${label}: "${segment}". Must match ${SEGMENT_RE.source}`);
9
+ }
10
+ }
11
+ var DocumentRef = class {
12
+ path;
13
+ httpClient;
14
+ constructor(httpClient, path) {
15
+ this.httpClient = httpClient;
16
+ this.path = path;
17
+ }
18
+ async set(data) {
19
+ return this.httpClient.request("PUT", `/v1/docs/${this.path}`, {
20
+ body: data
21
+ });
22
+ }
23
+ async get() {
24
+ const response = await this.httpClient.request(
25
+ "GET",
26
+ `/v1/docs/${this.path}`
27
+ );
28
+ if (response.error) {
29
+ return {
30
+ data: null,
31
+ error: response.error,
32
+ status: response.status
33
+ };
34
+ }
35
+ const raw = response.data;
36
+ const snapshot = {
37
+ id: raw?.id ?? this.getDocId(),
38
+ exists: raw?.exists ?? false,
39
+ data: () => raw?.data,
40
+ ref: { path: this.path }
41
+ };
42
+ return { data: snapshot, error: null, status: response.status };
43
+ }
44
+ async update(data) {
45
+ return this.httpClient.request("PATCH", `/v1/docs/${this.path}`, {
46
+ body: data
47
+ });
48
+ }
49
+ async delete() {
50
+ return this.httpClient.request("DELETE", `/v1/docs/${this.path}`);
51
+ }
52
+ collection(name) {
53
+ validateSegment(name, "subcollection name");
54
+ return new CollectionRef(this.httpClient, `${this.path}/${name}`);
55
+ }
56
+ getDocId() {
57
+ const segments = this.path.split("/");
58
+ return segments[segments.length - 1] ?? "";
59
+ }
60
+ };
61
+
62
+ // src/collection-ref.ts
63
+ var SEGMENT_RE2 = /^[a-zA-Z0-9_\-]+$/;
64
+ function validateSegment2(segment, label) {
65
+ if (!SEGMENT_RE2.test(segment)) {
66
+ throw new Error(`Invalid ${label}: "${segment}". Must match ${SEGMENT_RE2.source}`);
67
+ }
68
+ }
69
+ var CollectionRef = class _CollectionRef {
70
+ path;
71
+ httpClient;
72
+ whereClauses = [];
73
+ orderByClauses = [];
74
+ limitValue;
75
+ constructor(httpClient, path) {
76
+ this.httpClient = httpClient;
77
+ this.path = path;
78
+ }
79
+ doc(id) {
80
+ validateSegment2(id, "document ID");
81
+ return new DocumentRef(this.httpClient, `${this.path}/${id}`);
82
+ }
83
+ async add(data) {
84
+ const response = await this.httpClient.request(
85
+ "POST",
86
+ `/v1/docs/${this.path}`,
87
+ { body: data }
88
+ );
89
+ if (response.error || !response.data) {
90
+ return {
91
+ data: null,
92
+ error: response.error,
93
+ status: response.status
94
+ };
95
+ }
96
+ const ref = new DocumentRef(this.httpClient, `${this.path}/${response.data.id}`);
97
+ return { data: ref, error: null, status: response.status };
98
+ }
99
+ where(field, op, value) {
100
+ const clone = this.clone();
101
+ clone.whereClauses.push({ field, op, value });
102
+ return clone;
103
+ }
104
+ orderBy(field, direction) {
105
+ const clone = this.clone();
106
+ clone.orderByClauses.push({ field, direction: direction ?? "asc" });
107
+ return clone;
108
+ }
109
+ limit(n) {
110
+ const clone = this.clone();
111
+ clone.limitValue = n;
112
+ return clone;
113
+ }
114
+ async get() {
115
+ const hasQuery = this.whereClauses.length > 0 || this.orderByClauses.length > 0 || this.limitValue !== void 0;
116
+ if (hasQuery) {
117
+ return this.executeQuery();
118
+ }
119
+ const response = await this.httpClient.request(
120
+ "GET",
121
+ `/v1/docs/${this.path}`
122
+ );
123
+ if (response.error) {
124
+ return { data: null, error: response.error, status: response.status };
125
+ }
126
+ const docs = (response.data?.documents ?? []).map((doc) => this.toSnapshot(doc));
127
+ return {
128
+ data: this.toQuerySnapshot(docs),
129
+ error: null,
130
+ status: response.status
131
+ };
132
+ }
133
+ onSnapshot(callback) {
134
+ const body = this.buildQueryBody();
135
+ let active = true;
136
+ let controller;
137
+ const poll = async () => {
138
+ if (!active) return;
139
+ controller = new AbortController();
140
+ const response = await this.httpClient.request(
141
+ "POST",
142
+ `/v1/docs/${this.path}/listen`,
143
+ { body, signal: controller.signal }
144
+ );
145
+ if (!active) return;
146
+ if (response.data) {
147
+ const docs = (response.data.documents ?? []).map((doc) => this.toSnapshot(doc));
148
+ callback(this.toQuerySnapshot(docs));
149
+ }
150
+ };
151
+ void poll();
152
+ return () => {
153
+ active = false;
154
+ controller?.abort();
155
+ };
156
+ }
157
+ async executeQuery() {
158
+ const body = this.buildQueryBody();
159
+ const response = await this.httpClient.request(
160
+ "POST",
161
+ `/v1/docs/${this.path}/query`,
162
+ { body }
163
+ );
164
+ if (response.error) {
165
+ return { data: null, error: response.error, status: response.status };
166
+ }
167
+ const docs = (response.data?.documents ?? []).map((doc) => this.toSnapshot(doc));
168
+ return {
169
+ data: this.toQuerySnapshot(docs),
170
+ error: null,
171
+ status: response.status
172
+ };
173
+ }
174
+ buildQueryBody() {
175
+ const body = {};
176
+ if (this.whereClauses.length > 0) {
177
+ body["where"] = this.whereClauses.map((w) => ({
178
+ field: w.field,
179
+ op: w.op,
180
+ value: w.value
181
+ }));
182
+ }
183
+ if (this.orderByClauses.length > 0) {
184
+ body["orderBy"] = this.orderByClauses.map((o) => ({
185
+ field: o.field,
186
+ direction: o.direction
187
+ }));
188
+ }
189
+ if (this.limitValue !== void 0) {
190
+ body["limit"] = this.limitValue;
191
+ }
192
+ return body;
193
+ }
194
+ toSnapshot(doc) {
195
+ return {
196
+ id: doc.id,
197
+ exists: true,
198
+ data: () => doc.data,
199
+ ref: { path: `${this.path}/${doc.id}` }
200
+ };
201
+ }
202
+ toQuerySnapshot(docs) {
203
+ return {
204
+ docs,
205
+ empty: docs.length === 0,
206
+ size: docs.length,
207
+ docChanges: () => docs.map((doc) => ({ type: "added", doc }))
208
+ };
209
+ }
210
+ clone() {
211
+ const cloned = new _CollectionRef(this.httpClient, this.path);
212
+ cloned.whereClauses.push(...this.whereClauses);
213
+ cloned.orderByClauses.push(...this.orderByClauses);
214
+ cloned.limitValue = this.limitValue;
215
+ return cloned;
216
+ }
217
+ };
218
+
219
+ // src/docs-client.ts
220
+ var MAX_BATCH_SIZE = 500;
221
+ var SEGMENT_RE3 = /^[a-zA-Z0-9_\-]+$/;
222
+ function validateSegment3(segment, label) {
223
+ if (!SEGMENT_RE3.test(segment)) {
224
+ throw new Error(`Invalid ${label}: "${segment}". Must match ${SEGMENT_RE3.source}`);
225
+ }
226
+ }
227
+ var DocsClient = class {
228
+ httpClient;
229
+ constructor(httpClient) {
230
+ this.httpClient = httpClient;
231
+ }
232
+ collection(name) {
233
+ validateSegment3(name, "collection name");
234
+ return new CollectionRef(this.httpClient, name);
235
+ }
236
+ async batch(operations) {
237
+ if (operations.length > MAX_BATCH_SIZE) {
238
+ return {
239
+ data: null,
240
+ error: new PalbaseError(
241
+ "batch_too_large",
242
+ `Batch size ${operations.length} exceeds maximum of ${MAX_BATCH_SIZE}`,
243
+ 400
244
+ ),
245
+ status: 400
246
+ };
247
+ }
248
+ if (operations.length === 0) {
249
+ return { data: null, error: null, status: 200 };
250
+ }
251
+ const body = operations.map((op) => ({
252
+ op: op.op,
253
+ path: op.ref.path,
254
+ data: op.data
255
+ }));
256
+ return this.httpClient.request("POST", "/v1/docs/batch", { body });
257
+ }
258
+ };
259
+ export {
260
+ CollectionRef,
261
+ DocsClient,
262
+ DocumentRef
263
+ };
264
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/docs-client.ts","../src/document-ref.ts","../src/collection-ref.ts"],"sourcesContent":["import type { HttpClient, PalbaseResponse } from '@palbase/core';\nimport { PalbaseError } from '@palbase/core';\nimport { CollectionRef } from './collection-ref.js';\nimport type { BatchOperation, DocumentData } from './types.js';\n\nconst MAX_BATCH_SIZE = 500;\nconst SEGMENT_RE = /^[a-zA-Z0-9_\\-]+$/;\n\nfunction validateSegment(segment: string, label: string): void {\n if (!SEGMENT_RE.test(segment)) {\n throw new Error(`Invalid ${label}: \"${segment}\". Must match ${SEGMENT_RE.source}`);\n }\n}\n\nexport class DocsClient {\n private readonly httpClient: HttpClient;\n\n constructor(httpClient: HttpClient) {\n this.httpClient = httpClient;\n }\n\n collection<T = DocumentData>(name: string): CollectionRef<T> {\n validateSegment(name, 'collection name');\n return new CollectionRef<T>(this.httpClient, name);\n }\n\n async batch(operations: BatchOperation[]): Promise<PalbaseResponse<void>> {\n if (operations.length > MAX_BATCH_SIZE) {\n return {\n data: null,\n error: new PalbaseError(\n 'batch_too_large',\n `Batch size ${operations.length} exceeds maximum of ${MAX_BATCH_SIZE}`,\n 400,\n ),\n status: 400,\n };\n }\n\n if (operations.length === 0) {\n return { data: null, error: null, status: 200 };\n }\n\n const body = operations.map((op) => ({\n op: op.op,\n path: op.ref.path,\n data: op.data,\n }));\n\n return this.httpClient.request<void>('POST', '/v1/docs/batch', { body });\n }\n}\n","import type { HttpClient, PalbaseResponse } from '@palbase/core';\nimport { CollectionRef } from './collection-ref.js';\nimport type { DocumentData, DocumentSnapshot } from './types.js';\n\nconst SEGMENT_RE = /^[a-zA-Z0-9_\\-]+$/;\n\nfunction validateSegment(segment: string, label: string): void {\n if (!SEGMENT_RE.test(segment)) {\n throw new Error(`Invalid ${label}: \"${segment}\". Must match ${SEGMENT_RE.source}`);\n }\n}\n\nexport class DocumentRef<T = DocumentData> {\n readonly path: string;\n private readonly httpClient: HttpClient;\n\n constructor(httpClient: HttpClient, path: string) {\n this.httpClient = httpClient;\n this.path = path;\n }\n\n async set(data: T): Promise<PalbaseResponse<void>> {\n return this.httpClient.request<void>('PUT', `/v1/docs/${this.path}`, {\n body: data,\n });\n }\n\n async get(): Promise<PalbaseResponse<DocumentSnapshot<T>>> {\n const response = await this.httpClient.request<{ id: string; data: T; exists: boolean }>(\n 'GET',\n `/v1/docs/${this.path}`,\n );\n\n if (response.error) {\n return {\n data: null,\n error: response.error,\n status: response.status,\n };\n }\n\n const raw = response.data;\n const snapshot: DocumentSnapshot<T> = {\n id: raw?.id ?? this.getDocId(),\n exists: raw?.exists ?? false,\n data: () => raw?.data,\n ref: { path: this.path },\n };\n\n return { data: snapshot, error: null, status: response.status };\n }\n\n async update(data: Partial<T>): Promise<PalbaseResponse<void>> {\n return this.httpClient.request<void>('PATCH', `/v1/docs/${this.path}`, {\n body: data,\n });\n }\n\n async delete(): Promise<PalbaseResponse<void>> {\n return this.httpClient.request<void>('DELETE', `/v1/docs/${this.path}`);\n }\n\n collection(name: string): CollectionRef {\n validateSegment(name, 'subcollection name');\n return new CollectionRef(this.httpClient, `${this.path}/${name}`);\n }\n\n private getDocId(): string {\n const segments = this.path.split('/');\n return segments[segments.length - 1] ?? '';\n }\n}\n","import type { HttpClient, PalbaseResponse } from '@palbase/core';\nimport { DocumentRef } from './document-ref.js';\nimport type {\n DocumentData,\n DocumentSnapshot,\n OrderByClause,\n OrderDirection,\n QuerySnapshot,\n SnapshotCallback,\n WhereClause,\n WhereOperator,\n} from './types.js';\n\nconst SEGMENT_RE = /^[a-zA-Z0-9_\\-]+$/;\n\nfunction validateSegment(segment: string, label: string): void {\n if (!SEGMENT_RE.test(segment)) {\n throw new Error(`Invalid ${label}: \"${segment}\". Must match ${SEGMENT_RE.source}`);\n }\n}\n\nexport class CollectionRef<T = DocumentData> {\n readonly path: string;\n private readonly httpClient: HttpClient;\n private readonly whereClauses: WhereClause[] = [];\n private readonly orderByClauses: OrderByClause[] = [];\n private limitValue: number | undefined;\n\n constructor(httpClient: HttpClient, path: string) {\n this.httpClient = httpClient;\n this.path = path;\n }\n\n doc(id: string): DocumentRef<T> {\n validateSegment(id, 'document ID');\n return new DocumentRef<T>(this.httpClient, `${this.path}/${id}`);\n }\n\n async add(data: T): Promise<PalbaseResponse<DocumentRef<T>>> {\n const response = await this.httpClient.request<{ id: string }>(\n 'POST',\n `/v1/docs/${this.path}`,\n { body: data },\n );\n\n if (response.error || !response.data) {\n return {\n data: null,\n error: response.error,\n status: response.status,\n };\n }\n\n const ref = new DocumentRef<T>(this.httpClient, `${this.path}/${response.data.id}`);\n return { data: ref, error: null, status: response.status };\n }\n\n where(field: string, op: WhereOperator, value: unknown): CollectionRef<T> {\n const clone = this.clone();\n clone.whereClauses.push({ field, op, value });\n return clone;\n }\n\n orderBy(field: string, direction?: OrderDirection): CollectionRef<T> {\n const clone = this.clone();\n clone.orderByClauses.push({ field, direction: direction ?? 'asc' });\n return clone;\n }\n\n limit(n: number): CollectionRef<T> {\n const clone = this.clone();\n clone.limitValue = n;\n return clone;\n }\n\n async get(): Promise<PalbaseResponse<QuerySnapshot<T>>> {\n const hasQuery = this.whereClauses.length > 0 || this.orderByClauses.length > 0 || this.limitValue !== undefined;\n\n if (hasQuery) {\n return this.executeQuery();\n }\n\n const response = await this.httpClient.request<{ documents: { id: string; data: T }[] }>(\n 'GET',\n `/v1/docs/${this.path}`,\n );\n\n if (response.error) {\n return { data: null, error: response.error, status: response.status };\n }\n\n const docs = (response.data?.documents ?? []).map((doc) => this.toSnapshot(doc));\n return {\n data: this.toQuerySnapshot(docs),\n error: null,\n status: response.status,\n };\n }\n\n onSnapshot(callback: SnapshotCallback<T>): () => void {\n const body = this.buildQueryBody();\n\n let active = true;\n let controller: AbortController | undefined;\n\n const poll = async () => {\n if (!active) return;\n controller = new AbortController();\n\n const response = await this.httpClient.request<{ documents: { id: string; data: T }[] }>(\n 'POST',\n `/v1/docs/${this.path}/listen`,\n { body, signal: controller.signal },\n );\n\n if (!active) return;\n\n if (response.data) {\n const docs = (response.data.documents ?? []).map((doc) => this.toSnapshot(doc));\n callback(this.toQuerySnapshot(docs));\n }\n };\n\n // Start initial poll\n void poll();\n\n return () => {\n active = false;\n controller?.abort();\n };\n }\n\n private async executeQuery(): Promise<PalbaseResponse<QuerySnapshot<T>>> {\n const body = this.buildQueryBody();\n\n const response = await this.httpClient.request<{ documents: { id: string; data: T }[] }>(\n 'POST',\n `/v1/docs/${this.path}/query`,\n { body },\n );\n\n if (response.error) {\n return { data: null, error: response.error, status: response.status };\n }\n\n const docs = (response.data?.documents ?? []).map((doc) => this.toSnapshot(doc));\n return {\n data: this.toQuerySnapshot(docs),\n error: null,\n status: response.status,\n };\n }\n\n private buildQueryBody(): Record<string, unknown> {\n const body: Record<string, unknown> = {};\n\n if (this.whereClauses.length > 0) {\n body['where'] = this.whereClauses.map((w) => ({\n field: w.field,\n op: w.op,\n value: w.value,\n }));\n }\n\n if (this.orderByClauses.length > 0) {\n body['orderBy'] = this.orderByClauses.map((o) => ({\n field: o.field,\n direction: o.direction,\n }));\n }\n\n if (this.limitValue !== undefined) {\n body['limit'] = this.limitValue;\n }\n\n return body;\n }\n\n private toSnapshot(doc: { id: string; data: T }): DocumentSnapshot<T> {\n return {\n id: doc.id,\n exists: true,\n data: () => doc.data,\n ref: { path: `${this.path}/${doc.id}` },\n };\n }\n\n private toQuerySnapshot(docs: DocumentSnapshot<T>[]): QuerySnapshot<T> {\n return {\n docs,\n empty: docs.length === 0,\n size: docs.length,\n docChanges: () => docs.map((doc) => ({ type: 'added' as const, doc })),\n };\n }\n\n private clone(): CollectionRef<T> {\n const cloned = new CollectionRef<T>(this.httpClient, this.path);\n cloned.whereClauses.push(...this.whereClauses);\n cloned.orderByClauses.push(...this.orderByClauses);\n cloned.limitValue = this.limitValue;\n return cloned;\n }\n}\n"],"mappings":";AACA,SAAS,oBAAoB;;;ACG7B,IAAM,aAAa;AAEnB,SAAS,gBAAgB,SAAiB,OAAqB;AAC7D,MAAI,CAAC,WAAW,KAAK,OAAO,GAAG;AAC7B,UAAM,IAAI,MAAM,WAAW,KAAK,MAAM,OAAO,iBAAiB,WAAW,MAAM,EAAE;AAAA,EACnF;AACF;AAEO,IAAM,cAAN,MAAoC;AAAA,EAChC;AAAA,EACQ;AAAA,EAEjB,YAAY,YAAwB,MAAc;AAChD,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,MAAM,IAAI,MAAyC;AACjD,WAAO,KAAK,WAAW,QAAc,OAAO,YAAY,KAAK,IAAI,IAAI;AAAA,MACnE,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,MAAqD;AACzD,UAAM,WAAW,MAAM,KAAK,WAAW;AAAA,MACrC;AAAA,MACA,YAAY,KAAK,IAAI;AAAA,IACvB;AAEA,QAAI,SAAS,OAAO;AAClB,aAAO;AAAA,QACL,MAAM;AAAA,QACN,OAAO,SAAS;AAAA,QAChB,QAAQ,SAAS;AAAA,MACnB;AAAA,IACF;AAEA,UAAM,MAAM,SAAS;AACrB,UAAM,WAAgC;AAAA,MACpC,IAAI,KAAK,MAAM,KAAK,SAAS;AAAA,MAC7B,QAAQ,KAAK,UAAU;AAAA,MACvB,MAAM,MAAM,KAAK;AAAA,MACjB,KAAK,EAAE,MAAM,KAAK,KAAK;AAAA,IACzB;AAEA,WAAO,EAAE,MAAM,UAAU,OAAO,MAAM,QAAQ,SAAS,OAAO;AAAA,EAChE;AAAA,EAEA,MAAM,OAAO,MAAkD;AAC7D,WAAO,KAAK,WAAW,QAAc,S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,iBAAgB,MAAM,iBAAiB;AACvC,WAAO,IAAI,cAAiB,KAAK,YAAY,IAAI;AAAA,EACnD;AAAA,EAEA,MAAM,MAAM,YAA8D;AACxE,QAAI,WAAW,SAAS,gBAAgB;AACtC,aAAO;AAAA,QACL,MAAM;AAAA,QACN,OAAO,IAAI;AAAA,UACT;AAAA,UACA,cAAc,WAAW,MAAM,uBAAuB,cAAc;AAAA,UACpE;AAAA,QACF;AAAA,QACA,QAAQ;AAAA,MACV;AAAA,IACF;AAEA,QAAI,WAAW,WAAW,GAAG;AAC3B,aAAO,EAAE,MAAM,MAAM,OAAO,MAAM,QAAQ,IAAI;AAAA,IAChD;AAEA,UAAM,OAAO,WAAW,IAAI,CAAC,QAAQ;AAAA,MACnC,IAAI,GAAG;AAAA,MACP,MAAM,GAAG,IAAI;AAAA,MACb,MAAM,GAAG;AAAA,IACX,EAAE;AAEF,WAAO,KAAK,WAAW,QAAc,QAAQ,kBAAkB,EAAE,KAAK,CAAC;AAAA,EACzE;AACF;","names":["SEGMENT_RE","validateSegment","SEGMENT_RE","validateSegment"]}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@palbase/modules-docs",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "require": {
13
+ "types": "./dist/index.d.cts",
14
+ "default": "./dist/index.cjs"
15
+ }
16
+ }
17
+ },
18
+ "main": "./dist/index.cjs",
19
+ "module": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "dependencies": {
25
+ "@palbase/core": "0.1.0"
26
+ },
27
+ "devDependencies": {
28
+ "@biomejs/biome": "^2.0.0",
29
+ "tsup": "^8.4.0",
30
+ "typescript": "^5.8.0",
31
+ "vitest": "^3.1.0"
32
+ },
33
+ "scripts": {
34
+ "build": "tsup",
35
+ "test": "vitest run",
36
+ "lint": "biome check src/ __tests__/"
37
+ }
38
+ }