@gettersethya/mira-collection 0.1.0-alpha.2

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 (111) hide show
  1. package/LICENSE +21 -0
  2. package/dist/src/collection/auth.d.ts +79 -0
  3. package/dist/src/collection/auth.d.ts.map +1 -0
  4. package/dist/src/collection/auth.js +50 -0
  5. package/dist/src/collection/auth.js.map +1 -0
  6. package/dist/src/collection/base.d.ts +64 -0
  7. package/dist/src/collection/base.d.ts.map +1 -0
  8. package/dist/src/collection/base.js +40 -0
  9. package/dist/src/collection/base.js.map +1 -0
  10. package/dist/src/collection/bytes.d.ts +51 -0
  11. package/dist/src/collection/bytes.d.ts.map +1 -0
  12. package/dist/src/collection/bytes.js +51 -0
  13. package/dist/src/collection/bytes.js.map +1 -0
  14. package/dist/src/collection/errors.d.ts +29 -0
  15. package/dist/src/collection/errors.d.ts.map +1 -0
  16. package/dist/src/collection/errors.js +23 -0
  17. package/dist/src/collection/errors.js.map +1 -0
  18. package/dist/src/collection/field.d.ts +300 -0
  19. package/dist/src/collection/field.d.ts.map +1 -0
  20. package/dist/src/collection/field.js +175 -0
  21. package/dist/src/collection/field.js.map +1 -0
  22. package/dist/src/collection/index-builder.d.ts +59 -0
  23. package/dist/src/collection/index-builder.d.ts.map +1 -0
  24. package/dist/src/collection/index-builder.js +43 -0
  25. package/dist/src/collection/index-builder.js.map +1 -0
  26. package/dist/src/collection/index.d.ts +22 -0
  27. package/dist/src/collection/index.d.ts.map +1 -0
  28. package/dist/src/collection/index.js +21 -0
  29. package/dist/src/collection/index.js.map +1 -0
  30. package/dist/src/collection/serialize.d.ts +24 -0
  31. package/dist/src/collection/serialize.d.ts.map +1 -0
  32. package/dist/src/collection/serialize.js +127 -0
  33. package/dist/src/collection/serialize.js.map +1 -0
  34. package/dist/src/collection/types.d.ts +119 -0
  35. package/dist/src/collection/types.d.ts.map +1 -0
  36. package/dist/src/collection/types.js +2 -0
  37. package/dist/src/collection/types.js.map +1 -0
  38. package/dist/src/collection/view.d.ts +57 -0
  39. package/dist/src/collection/view.d.ts.map +1 -0
  40. package/dist/src/collection/view.js +49 -0
  41. package/dist/src/collection/view.js.map +1 -0
  42. package/dist/src/filter/builder.d.ts +127 -0
  43. package/dist/src/filter/builder.d.ts.map +1 -0
  44. package/dist/src/filter/builder.js +72 -0
  45. package/dist/src/filter/builder.js.map +1 -0
  46. package/dist/src/filter/compiler.d.ts +48 -0
  47. package/dist/src/filter/compiler.d.ts.map +1 -0
  48. package/dist/src/filter/compiler.js +132 -0
  49. package/dist/src/filter/compiler.js.map +1 -0
  50. package/dist/src/filter/index.d.ts +6 -0
  51. package/dist/src/filter/index.d.ts.map +1 -0
  52. package/dist/src/filter/index.js +4 -0
  53. package/dist/src/filter/index.js.map +1 -0
  54. package/dist/src/filter/types.d.ts +96 -0
  55. package/dist/src/filter/types.d.ts.map +1 -0
  56. package/dist/src/filter/types.js +44 -0
  57. package/dist/src/filter/types.js.map +1 -0
  58. package/dist/src/index.d.ts +5 -0
  59. package/dist/src/index.d.ts.map +1 -0
  60. package/dist/src/index.js +4 -0
  61. package/dist/src/index.js.map +1 -0
  62. package/dist/src/rule/builder.d.ts +97 -0
  63. package/dist/src/rule/builder.d.ts.map +1 -0
  64. package/dist/src/rule/builder.js +126 -0
  65. package/dist/src/rule/builder.js.map +1 -0
  66. package/dist/src/rule/index.d.ts +3 -0
  67. package/dist/src/rule/index.d.ts.map +1 -0
  68. package/dist/src/rule/index.js +3 -0
  69. package/dist/src/rule/index.js.map +1 -0
  70. package/dist/src/rule/types.d.ts +129 -0
  71. package/dist/src/rule/types.d.ts.map +1 -0
  72. package/dist/src/rule/types.js +2 -0
  73. package/dist/src/rule/types.js.map +1 -0
  74. package/dist/tests/collection/auth.test.d.ts +2 -0
  75. package/dist/tests/collection/auth.test.d.ts.map +1 -0
  76. package/dist/tests/collection/auth.test.js +44 -0
  77. package/dist/tests/collection/auth.test.js.map +1 -0
  78. package/dist/tests/collection/base.test.d.ts +2 -0
  79. package/dist/tests/collection/base.test.d.ts.map +1 -0
  80. package/dist/tests/collection/base.test.js +70 -0
  81. package/dist/tests/collection/base.test.js.map +1 -0
  82. package/dist/tests/collection/bytes.test.d.ts +2 -0
  83. package/dist/tests/collection/bytes.test.d.ts.map +1 -0
  84. package/dist/tests/collection/bytes.test.js +9 -0
  85. package/dist/tests/collection/bytes.test.js.map +1 -0
  86. package/dist/tests/collection/field.test.d.ts +2 -0
  87. package/dist/tests/collection/field.test.d.ts.map +1 -0
  88. package/dist/tests/collection/field.test.js +140 -0
  89. package/dist/tests/collection/field.test.js.map +1 -0
  90. package/dist/tests/collection/index-type.test.d.ts +2 -0
  91. package/dist/tests/collection/index-type.test.d.ts.map +1 -0
  92. package/dist/tests/collection/index-type.test.js +28 -0
  93. package/dist/tests/collection/index-type.test.js.map +1 -0
  94. package/dist/tests/collection/serialize.test.d.ts +2 -0
  95. package/dist/tests/collection/serialize.test.d.ts.map +1 -0
  96. package/dist/tests/collection/serialize.test.js +165 -0
  97. package/dist/tests/collection/serialize.test.js.map +1 -0
  98. package/dist/tests/collection/view.test.d.ts +2 -0
  99. package/dist/tests/collection/view.test.d.ts.map +1 -0
  100. package/dist/tests/collection/view.test.js +66 -0
  101. package/dist/tests/collection/view.test.js.map +1 -0
  102. package/dist/tests/filter/compiler.test.d.ts +2 -0
  103. package/dist/tests/filter/compiler.test.d.ts.map +1 -0
  104. package/dist/tests/filter/compiler.test.js +156 -0
  105. package/dist/tests/filter/compiler.test.js.map +1 -0
  106. package/dist/tests/rule/builder.test.d.ts +2 -0
  107. package/dist/tests/rule/builder.test.d.ts.map +1 -0
  108. package/dist/tests/rule/builder.test.js +290 -0
  109. package/dist/tests/rule/builder.test.js.map +1 -0
  110. package/dist/tsconfig.tsbuildinfo +1 -0
  111. package/package.json +36 -0
@@ -0,0 +1,300 @@
1
+ import type { AnyCollectionDef, EmailConstraintKind, FieldDef, IntegerConstraintKind, NumberConstraintKind, SimpleConstraintKind, TextConstraintKind } from "./types.js";
2
+ /** Common options shared by all field types. */
3
+ type BaseFieldOptions = {
4
+ /** Alternative field name in the database (defaults to the key in the fields map). */
5
+ name?: string;
6
+ /** Whether the field is required (defaults to `true` if no default is set). */
7
+ required?: boolean;
8
+ /** Creates a unique index on this field. */
9
+ unique?: boolean;
10
+ /** Creates a non-unique index on this field. */
11
+ indexed?: boolean;
12
+ /** Default value for the field when creating a record. */
13
+ default?: unknown;
14
+ };
15
+ /**
16
+ * Field builder API.
17
+ * Every method returns a typed `FieldDef` with `.view()` for use in `ViewCollection`.
18
+ *
19
+ * @example
20
+ * const Posts = BaseCollection.define("posts", {
21
+ * title: Field.text({ maxLength: 200 }),
22
+ * body: Field.text({ required: false }),
23
+ * published: Field.boolean({ default: false }),
24
+ * author: Field.relation(Users)
25
+ * })
26
+ */
27
+ export declare const Field: {
28
+ /**
29
+ * A UTF-8 text/string field with optional min/max length constraints.
30
+ * Stored as `TEXT` in SQLite.
31
+ *
32
+ * @param opts.required - Whether the field is required (default: true, unless `default` is set)
33
+ * @param opts.default - Default value for new records
34
+ * @param opts.unique - Create a unique index on this field
35
+ * @param opts.indexed - Create a non-unique index on this field
36
+ * @param opts.name - Alternative column name in the database
37
+ * @param opts.minLength - Minimum string length (validated on create and update)
38
+ * @param opts.maxLength - Maximum string length (validated on create and update)
39
+ * @param opts.error - Callback for custom validation error messages, keyed by constraint kind
40
+ * @returns A text-type FieldDef with `.view()` method
41
+ *
42
+ * @example
43
+ * Field.text({ maxLength: 500, required: true })
44
+ * Field.text({ minLength: 3, maxLength: 100, default: "untitled" })
45
+ */
46
+ text: <O extends BaseFieldOptions & {
47
+ minLength?: number;
48
+ maxLength?: number;
49
+ }>(opts?: O & {
50
+ error?: (kind: TextConstraintKind) => string | undefined;
51
+ }) => FieldDef & {
52
+ kind: "text";
53
+ } & O & {
54
+ error?: (kind: TextConstraintKind) => string | undefined;
55
+ } & {
56
+ view(): FieldDef & {
57
+ kind: "text";
58
+ } & O & {
59
+ error?: (kind: TextConstraintKind) => string | undefined;
60
+ } & {
61
+ viewOnly: true;
62
+ };
63
+ };
64
+ /**
65
+ * A floating-point number field with optional min/max constraints.
66
+ * Stored as `REAL` in SQLite.
67
+ *
68
+ * @param opts.min - Minimum allowed value (inclusive)
69
+ * @param opts.max - Maximum allowed value (inclusive)
70
+ *
71
+ * @example
72
+ * Field.number({ min: 0, max: 100 })
73
+ * Field.number({ required: false })
74
+ */
75
+ number: <O extends BaseFieldOptions & {
76
+ min?: number;
77
+ max?: number;
78
+ }>(opts?: O & {
79
+ error?: (kind: NumberConstraintKind) => string | undefined;
80
+ }) => FieldDef & {
81
+ kind: "number";
82
+ } & O & {
83
+ error?: (kind: NumberConstraintKind) => string | undefined;
84
+ } & {
85
+ view(): FieldDef & {
86
+ kind: "number";
87
+ } & O & {
88
+ error?: (kind: NumberConstraintKind) => string | undefined;
89
+ } & {
90
+ viewOnly: true;
91
+ };
92
+ };
93
+ /**
94
+ * An integer field with optional min/max constraints.
95
+ * Stored as `INTEGER` in SQLite. Values are validated to be whole numbers.
96
+ *
97
+ * @param opts.min - Minimum allowed value (inclusive)
98
+ * @param opts.max - Maximum allowed value (inclusive)
99
+ *
100
+ * @example
101
+ * Field.integer({ min: 1, max: 5 })
102
+ */
103
+ integer: <O extends BaseFieldOptions & {
104
+ min?: number;
105
+ max?: number;
106
+ }>(opts?: O & {
107
+ error?: (kind: IntegerConstraintKind) => string | undefined;
108
+ }) => FieldDef & {
109
+ kind: "integer";
110
+ } & O & {
111
+ error?: (kind: IntegerConstraintKind) => string | undefined;
112
+ } & {
113
+ view(): FieldDef & {
114
+ kind: "integer";
115
+ } & O & {
116
+ error?: (kind: IntegerConstraintKind) => string | undefined;
117
+ } & {
118
+ viewOnly: true;
119
+ };
120
+ };
121
+ /**
122
+ * A boolean (true/false) field.
123
+ * Stored as `INTEGER` (0/1) in SQLite.
124
+ * Typically paired with a `default` value since new records default to false.
125
+ *
126
+ * @param opts.default - Default value (recommended to always set this)
127
+ *
128
+ * @example
129
+ * Field.boolean({ default: false })
130
+ */
131
+ boolean: <O extends Omit<BaseFieldOptions, "default"> & {
132
+ default?: boolean;
133
+ }>(opts?: O & {
134
+ error?: (kind: SimpleConstraintKind) => string | undefined;
135
+ }) => FieldDef & {
136
+ kind: "boolean";
137
+ } & O & {
138
+ error?: (kind: SimpleConstraintKind) => string | undefined;
139
+ } & {
140
+ view(): FieldDef & {
141
+ kind: "boolean";
142
+ } & O & {
143
+ error?: (kind: SimpleConstraintKind) => string | undefined;
144
+ } & {
145
+ viewOnly: true;
146
+ };
147
+ };
148
+ /**
149
+ * A date/time field stored as an ISO 8601 string.
150
+ * Stored as `TEXT` in SQLite. Values should be ISO 8601 strings.
151
+ * The server does not parse or transform date values — they are stored verbatim.
152
+ *
153
+ * @example
154
+ * Field.date({ required: true })
155
+ */
156
+ date: <O extends BaseFieldOptions>(opts?: O & {
157
+ error?: (kind: SimpleConstraintKind) => string | undefined;
158
+ }) => FieldDef & {
159
+ kind: "date";
160
+ } & O & {
161
+ error?: (kind: SimpleConstraintKind) => string | undefined;
162
+ } & {
163
+ view(): FieldDef & {
164
+ kind: "date";
165
+ } & O & {
166
+ error?: (kind: SimpleConstraintKind) => string | undefined;
167
+ } & {
168
+ viewOnly: true;
169
+ };
170
+ };
171
+ /**
172
+ * An email address field with built-in format validation.
173
+ * Stored as `TEXT` in SQLite. The server validates the email format
174
+ * on both create and update operations.
175
+ *
176
+ * @example
177
+ * Field.email({ required: false })
178
+ */
179
+ email: <O extends BaseFieldOptions>(opts?: O & {
180
+ error?: (kind: EmailConstraintKind) => string | undefined;
181
+ }) => FieldDef & {
182
+ kind: "email";
183
+ } & O & {
184
+ error?: (kind: EmailConstraintKind) => string | undefined;
185
+ } & {
186
+ view(): FieldDef & {
187
+ kind: "email";
188
+ } & O & {
189
+ error?: (kind: EmailConstraintKind) => string | undefined;
190
+ } & {
191
+ viewOnly: true;
192
+ };
193
+ };
194
+ /**
195
+ * A JSON field for storing arbitrary structured data.
196
+ * Stored as `TEXT` (JSON string) in SQLite. The server serializes/deserializes
197
+ * values automatically. Can be used for dynamic metadata, nested objects, arrays, etc.
198
+ *
199
+ * @example
200
+ * Field.json({ required: false })
201
+ */
202
+ json: <O extends BaseFieldOptions>(opts?: O & {
203
+ error?: (kind: SimpleConstraintKind) => string | undefined;
204
+ }) => FieldDef & {
205
+ kind: "json";
206
+ } & O & {
207
+ error?: (kind: SimpleConstraintKind) => string | undefined;
208
+ } & {
209
+ view(): FieldDef & {
210
+ kind: "json";
211
+ } & O & {
212
+ error?: (kind: SimpleConstraintKind) => string | undefined;
213
+ } & {
214
+ viewOnly: true;
215
+ };
216
+ };
217
+ /**
218
+ * Auto-incrementing sequence ID (system-managed, hidden from API responses).
219
+ * Stored as `INTEGER` in SQLite with `AUTOINCREMENT`.
220
+ * This field is always present on base and auth collections and does NOT expose
221
+ * `.view()` — it is always a physical column.
222
+ *
223
+ * @example
224
+ * // seqId is automatically included in base/auth collections — typically
225
+ * // only used in ViewCollection where you map a query column to seqId.
226
+ * Field.seqId()
227
+ */
228
+ seqId: (opts?: BaseFieldOptions) => FieldDef;
229
+ /**
230
+ * A file/attachment field referencing an uploaded file.
231
+ * Stored as `TEXT` (filename string) in SQLite. The actual file content is
232
+ * stored in the file storage backend (local disk or S3).
233
+ *
234
+ * When `protected: true`, the file requires a short-lived JWT token to access.
235
+ * Protected files are served via the async token endpoint.
236
+ *
237
+ * @param opts.maxSize - Maximum file size in bytes (use `Bytes.*` helpers)
238
+ * @param opts.mimeTypes - Allowed MIME types (e.g., ["image/jpeg", "image/png"])
239
+ * @param opts.protected - Whether the file requires auth token to access
240
+ *
241
+ * @example
242
+ * Field.file({ maxSize: Bytes.fromMB(5), mimeTypes: ["image/jpeg"] })
243
+ * Field.file({ protected: true, maxSize: Bytes.fromMB(10) })
244
+ *
245
+ * @see Bytes — byte size helpers for maxSize
246
+ */
247
+ file: <O extends BaseFieldOptions & {
248
+ maxSize?: number;
249
+ mimeTypes?: Array<string>;
250
+ protected?: boolean;
251
+ }>(opts?: O & {
252
+ error?: (kind: SimpleConstraintKind) => string | undefined;
253
+ }) => FieldDef & {
254
+ kind: "file";
255
+ } & O & {
256
+ error?: (kind: SimpleConstraintKind) => string | undefined;
257
+ } & {
258
+ view(): FieldDef & {
259
+ kind: "file";
260
+ } & O & {
261
+ error?: (kind: SimpleConstraintKind) => string | undefined;
262
+ } & {
263
+ viewOnly: true;
264
+ };
265
+ };
266
+ /**
267
+ * A relation field referencing another collection's record.
268
+ * Stores the target record's field value (defaults to `"id"`).
269
+ * Resolves collection names at definition time — only the name string survives
270
+ * into the serialized JSON Schema.
271
+ *
272
+ * The `_target` phantom property carries the collection definition at compile time
273
+ * for type inference in `WithExpand`.
274
+ *
275
+ * @param collection - The target collection definition (AnyCollectionDef)
276
+ * @param opts.field - The target field to reference (defaults to `"id"`)
277
+ *
278
+ * @example
279
+ * Field.relation(Users)
280
+ * Field.relation(Users, { field: "email" })
281
+ *
282
+ * @see WithExpand — uses _target to type expanded related records
283
+ */
284
+ relation: <C extends AnyCollectionDef, O extends BaseFieldOptions>(collection: C, opts?: O & {
285
+ field?: (keyof C["fields"] & string) | "id" | "created" | "updated";
286
+ error?: (kind: SimpleConstraintKind) => string | undefined;
287
+ }) => FieldDef & {
288
+ kind: "relation";
289
+ _target: C;
290
+ } & O & {
291
+ view(): FieldDef & {
292
+ kind: "relation";
293
+ _target: C;
294
+ } & O & {
295
+ viewOnly: true;
296
+ };
297
+ };
298
+ };
299
+ export {};
300
+ //# sourceMappingURL=field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../src/collection/field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,QAAQ,EAER,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,YAAY,CAAA;AAEnB,gDAAgD;AAChD,KAAK,gB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kind literal, required literal, etc.) is preserved.
2
+ // Object.assign is used (not spread) because TypeScript infers the intersection type precisely.
3
+ function withView(def) {
4
+ const viewOnlyPatch = { viewOnly: true };
5
+ function view() {
6
+ return Object.assign({}, def, viewOnlyPatch);
7
+ }
8
+ return Object.assign({}, def, { view });
9
+ }
10
+ // Generic field builder — K is the kind literal, O is the caller's opts (preserving required: false, etc.)
11
+ function makeField(kind, opts) {
12
+ const def = { _tag: "FieldDef", kind, ...opts };
13
+ return withView(def);
14
+ }
15
+ /**
16
+ * Field builder API.
17
+ * Every method returns a typed `FieldDef` with `.view()` for use in `ViewCollection`.
18
+ *
19
+ * @example
20
+ * const Posts = BaseCollection.define("posts", {
21
+ * title: Field.text({ maxLength: 200 }),
22
+ * body: Field.text({ required: false }),
23
+ * published: Field.boolean({ default: false }),
24
+ * author: Field.relation(Users)
25
+ * })
26
+ */
27
+ export const Field = {
28
+ /**
29
+ * A UTF-8 text/string field with optional min/max length constraints.
30
+ * Stored as `TEXT` in SQLite.
31
+ *
32
+ * @param opts.required - Whether the field is required (default: true, unless `default` is set)
33
+ * @param opts.default - Default value for new records
34
+ * @param opts.unique - Create a unique index on this field
35
+ * @param opts.indexed - Create a non-unique index on this field
36
+ * @param opts.name - Alternative column name in the database
37
+ * @param opts.minLength - Minimum string length (validated on create and update)
38
+ * @param opts.maxLength - Maximum string length (validated on create and update)
39
+ * @param opts.error - Callback for custom validation error messages, keyed by constraint kind
40
+ * @returns A text-type FieldDef with `.view()` method
41
+ *
42
+ * @example
43
+ * Field.text({ maxLength: 500, required: true })
44
+ * Field.text({ minLength: 3, maxLength: 100, default: "untitled" })
45
+ */
46
+ text: (opts) => makeField("text", opts),
47
+ /**
48
+ * A floating-point number field with optional min/max constraints.
49
+ * Stored as `REAL` in SQLite.
50
+ *
51
+ * @param opts.min - Minimum allowed value (inclusive)
52
+ * @param opts.max - Maximum allowed value (inclusive)
53
+ *
54
+ * @example
55
+ * Field.number({ min: 0, max: 100 })
56
+ * Field.number({ required: false })
57
+ */
58
+ number: (opts) => makeField("number", opts),
59
+ /**
60
+ * An integer field with optional min/max constraints.
61
+ * Stored as `INTEGER` in SQLite. Values are validated to be whole numbers.
62
+ *
63
+ * @param opts.min - Minimum allowed value (inclusive)
64
+ * @param opts.max - Maximum allowed value (inclusive)
65
+ *
66
+ * @example
67
+ * Field.integer({ min: 1, max: 5 })
68
+ */
69
+ integer: (opts) => makeField("integer", opts),
70
+ /**
71
+ * A boolean (true/false) field.
72
+ * Stored as `INTEGER` (0/1) in SQLite.
73
+ * Typically paired with a `default` value since new records default to false.
74
+ *
75
+ * @param opts.default - Default value (recommended to always set this)
76
+ *
77
+ * @example
78
+ * Field.boolean({ default: false })
79
+ */
80
+ boolean: (opts) => makeField("boolean", opts),
81
+ /**
82
+ * A date/time field stored as an ISO 8601 string.
83
+ * Stored as `TEXT` in SQLite. Values should be ISO 8601 strings.
84
+ * The server does not parse or transform date values — they are stored verbatim.
85
+ *
86
+ * @example
87
+ * Field.date({ required: true })
88
+ */
89
+ date: (opts) => makeField("date", opts),
90
+ /**
91
+ * An email address field with built-in format validation.
92
+ * Stored as `TEXT` in SQLite. The server validates the email format
93
+ * on both create and update operations.
94
+ *
95
+ * @example
96
+ * Field.email({ required: false })
97
+ */
98
+ email: (opts) => makeField("email", opts),
99
+ /**
100
+ * A JSON field for storing arbitrary structured data.
101
+ * Stored as `TEXT` (JSON string) in SQLite. The server serializes/deserializes
102
+ * values automatically. Can be used for dynamic metadata, nested objects, arrays, etc.
103
+ *
104
+ * @example
105
+ * Field.json({ required: false })
106
+ */
107
+ json: (opts) => makeField("json", opts),
108
+ /**
109
+ * Auto-incrementing sequence ID (system-managed, hidden from API responses).
110
+ * Stored as `INTEGER` in SQLite with `AUTOINCREMENT`.
111
+ * This field is always present on base and auth collections and does NOT expose
112
+ * `.view()` — it is always a physical column.
113
+ *
114
+ * @example
115
+ * // seqId is automatically included in base/auth collections — typically
116
+ * // only used in ViewCollection where you map a query column to seqId.
117
+ * Field.seqId()
118
+ */
119
+ seqId: (opts) => ({
120
+ _tag: "FieldDef",
121
+ kind: "seqId",
122
+ ...opts
123
+ }),
124
+ /**
125
+ * A file/attachment field referencing an uploaded file.
126
+ * Stored as `TEXT` (filename string) in SQLite. The actual file content is
127
+ * stored in the file storage backend (local disk or S3).
128
+ *
129
+ * When `protected: true`, the file requires a short-lived JWT token to access.
130
+ * Protected files are served via the async token endpoint.
131
+ *
132
+ * @param opts.maxSize - Maximum file size in bytes (use `Bytes.*` helpers)
133
+ * @param opts.mimeTypes - Allowed MIME types (e.g., ["image/jpeg", "image/png"])
134
+ * @param opts.protected - Whether the file requires auth token to access
135
+ *
136
+ * @example
137
+ * Field.file({ maxSize: Bytes.fromMB(5), mimeTypes: ["image/jpeg"] })
138
+ * Field.file({ protected: true, maxSize: Bytes.fromMB(10) })
139
+ *
140
+ * @see Bytes — byte size helpers for maxSize
141
+ */
142
+ file: (opts) => makeField("file", opts),
143
+ /**
144
+ * A relation field referencing another collection's record.
145
+ * Stores the target record's field value (defaults to `"id"`).
146
+ * Resolves collection names at definition time — only the name string survives
147
+ * into the serialized JSON Schema.
148
+ *
149
+ * The `_target` phantom property carries the collection definition at compile time
150
+ * for type inference in `WithExpand`.
151
+ *
152
+ * @param collection - The target collection definition (AnyCollectionDef)
153
+ * @param opts.field - The target field to reference (defaults to `"id"`)
154
+ *
155
+ * @example
156
+ * Field.relation(Users)
157
+ * Field.relation(Users, { field: "email" })
158
+ *
159
+ * @see WithExpand — uses _target to type expanded related records
160
+ */
161
+ relation: (collection, opts) => {
162
+ const targetField = opts?.field ?? "id";
163
+ const { field: _field, ...fieldOpts } = (opts ?? {});
164
+ const def = {
165
+ _tag: "FieldDef",
166
+ kind: "relation",
167
+ targetCollection: collection.name,
168
+ targetField,
169
+ _target: collection,
170
+ ...fieldOpts
171
+ };
172
+ return withView(def);
173
+ }
174
+ };
175
+ //# sourceMappingURL=field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.js","sourceRo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xE,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC;IAE7B;;;;;;;OAOG;IACH,IAAI,EAAE,CACJ,IAAyE,EACzE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC;IAE5B;;;;;;;;;;OAUG;IACH,KAAK,EAAE,CAAC,IAAuB,EAAY,EAAE,CAAC,CAAC;QAC7C,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,OAAO;QACb,GAAG,IAAI;KACR,CAAC;IAEF;;;;;;;;;;;;;;;;;OAiBG;IACH,IAAI,EAAE,CACJ,IAAyE,EACzE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC;IAE5B;;;;;;;;;;;;;;;;;OAiBG;IACH,QAAQ,EAAE,CACR,UAAa,EACb,IAA8I,EAC9I,EAAE;QACF,MAAM,WAAW,GAAG,IAAI,EAAE,KAAK,IAAI,IAAI,CAAA;QACvC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAA2B,CAAA;QAC9E,MAAM,GAAG,GAAG;YACV,IAAI,EAAE,UAAwB;YAC9B,IAAI,EAAE,UAAwB;YAC9B,gBAAgB,EAAE,UAAU,CAAC,IAAI;YACjC,WAAW;YACX,OAAO,EAAE,UAAU;YACnB,GAAG,SAAS;SACsC,CAAA;QACpD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;CACF,CAAA"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A database index entry with field names and uniqueness flag.
3
+ * Created via `Index.on()` or `Index.unique()`.
4
+ */
5
+ export interface IndexEntry<K extends string> {
6
+ readonly fields: Array<K>;
7
+ readonly unique: boolean;
8
+ }
9
+ /**
10
+ * A narrowed version of the Index builder where methods only accept field
11
+ * names from `K`. Used as the argument type for the `indexes` callback.
12
+ */
13
+ export type IndexBuilder<K extends string> = {
14
+ on<F extends K>(...fields: Array<F>): IndexEntry<F>;
15
+ unique<F extends K>(...fields: Array<F>): IndexEntry<F>;
16
+ };
17
+ /**
18
+ * Index builder API.
19
+ * Pass the result to a collection config's `indexes` option.
20
+ *
21
+ * @example
22
+ * BaseCollection.define({
23
+ * name: "posts",
24
+ * fields: { slug: Field.text(), authorId: Field.text() },
25
+ * indexes: [
26
+ * Index.unique("slug"),
27
+ * Index.on("authorId", "createdAt")
28
+ * ]
29
+ * })
30
+ */
31
+ export declare const Index: {
32
+ /**
33
+ * Create a non-unique (plain) index on one or more fields.
34
+ * Composite indexes are created by passing multiple field names — order matters
35
+ * for query performance (leftmost prefix rule).
36
+ *
37
+ * @param fields - One or more field names to include in the index
38
+ * @returns An IndexEntry with `unique: false`
39
+ *
40
+ * @example
41
+ * Index.on("authorId") // single-field index
42
+ * Index.on("authorId", "createdAt") // composite index
43
+ */
44
+ on: <const K extends string>(...fields: Array<K>) => IndexEntry<K>;
45
+ /**
46
+ * Create a unique index on one or more fields.
47
+ * Enforces that the combination of field values is unique across all records.
48
+ * Composite unique indexes check uniqueness across all listed columns together.
49
+ *
50
+ * @param fields - One or more field names to include in the unique constraint
51
+ * @returns An IndexEntry with `unique: true`
52
+ *
53
+ * @example
54
+ * Index.unique("slug") // single-field unique constraint
55
+ * Index.unique("teamId", "name") // composite unique constraint
56
+ */
57
+ unique: <const K extends string>(...fields: Array<K>) => IndexEntry<K>;
58
+ };
59
+ //# sourceMappingURL=index-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-builder.d.ts","sourceRoot":"","sources":["../../../src/collection/index-builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,MAAM;IAC1C,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CACzB;AAED;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI;IAC3C,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;IACnD,MAAM,CAAC,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;CACxD,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK;IAChB;;;;;;;;;;;OAWG;eACQ,CAAC,SAAS,MAAM,aAAa,KAAK,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,CAAC;IAEhE;;;;;;;;;;;OAWG;mBACY,CAAC,SAAS,MAAM,aAAa,KAAK,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,CAAC;CACrE,CAAA"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Index builder API.
3
+ * Pass the result to a collection config's `indexes` option.
4
+ *
5
+ * @example
6
+ * BaseCollection.define({
7
+ * name: "posts",
8
+ * fields: { slug: Field.text(), authorId: Field.text() },
9
+ * indexes: [
10
+ * Index.unique("slug"),
11
+ * Index.on("authorId", "createdAt")
12
+ * ]
13
+ * })
14
+ */
15
+ export const Index = {
16
+ /**
17
+ * Create a non-unique (plain) index on one or more fields.
18
+ * Composite indexes are created by passing multiple field names — order matters
19
+ * for query performance (leftmost prefix rule).
20
+ *
21
+ * @param fields - One or more field names to include in the index
22
+ * @returns An IndexEntry with `unique: false`
23
+ *
24
+ * @example
25
+ * Index.on("authorId") // single-field index
26
+ * Index.on("authorId", "createdAt") // composite index
27
+ */
28
+ on: (...fields) => ({ fields, unique: false }),
29
+ /**
30
+ * Create a unique index on one or more fields.
31
+ * Enforces that the combination of field values is unique across all records.
32
+ * Composite unique indexes check uniqueness across all listed columns together.
33
+ *
34
+ * @param fields - One or more field names to include in the unique constraint
35
+ * @returns An IndexEntry with `unique: true`
36
+ *
37
+ * @example
38
+ * Index.unique("slug") // single-field unique constraint
39
+ * Index.unique("teamId", "name") // composite unique constraint
40
+ */
41
+ unique: (...fields) => ({ fields, unique: true })
42
+ };
43
+ //# sourceMappingURL=index-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-builder.js","sourceRoot":"","sources":["../../../src/collection/index-builder.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB;;;;;;;;;;;OAWG;IACH,EAAE,EAAE,CAAyB,GAAG,MAAgB,EAAiB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAE/F;;;;;;;;;;;OAWG;IACH,MAAM,EAAE,CAAyB,GAAG,MAAgB,EAAiB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;CACnG,CAAA"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Collection definition system.
3
+ *
4
+ * Provides builders for defining collections (base, auth, view), their fields,
5
+ * indexes, and byte-size helpers. The primary entry points are:
6
+ *
7
+ * - `BaseCollection.define()` — standard CRUD collections
8
+ * - `AuthCollection.define()` — auth/user collections with system fields
9
+ * - `ViewCollection.define()` — read-only SQL view collections
10
+ * - `Field.*()` — field type builders
11
+ * - `Index.*()` — index builders
12
+ * - `Bytes.*` — human-readable byte size constants
13
+ */
14
+ export { AuthCollection } from "./auth.js";
15
+ export { BaseCollection } from "./base.js";
16
+ export { Bytes } from "./bytes.js";
17
+ export { ValidationError } from "./errors.js";
18
+ export { Field } from "./field.js";
19
+ export { Index } from "./index-builder.js";
20
+ export type { AnyCollectionDef, CollectionSchema, FieldDef, FieldsMap } from "./types.js";
21
+ export { ViewCollection } from "./view.js";
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collection/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Collection definition system.
3
+ *
4
+ * Provides builders for defining collections (base, auth, view), their fields,
5
+ * indexes, and byte-size helpers. The primary entry points are:
6
+ *
7
+ * - `BaseCollection.define()` — standard CRUD collections
8
+ * - `AuthCollection.define()` — auth/user collections with system fields
9
+ * - `ViewCollection.define()` — read-only SQL view collections
10
+ * - `Field.*()` — field type builders
11
+ * - `Index.*()` — index builders
12
+ * - `Bytes.*` — human-readable byte size constants
13
+ */
14
+ export { AuthCollection } from "./auth.js";
15
+ export { BaseCollection } from "./base.js";
16
+ export { Bytes } from "./bytes.js";
17
+ export { ValidationError } from "./errors.js";
18
+ export { Field } from "./field.js";
19
+ export { Index } from "./index-builder.js";
20
+ export { ViewCollection } from "./view.js";
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/collection/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA"}
@@ -0,0 +1,24 @@
1
+ import type { RuleMap } from "../rule/types.js";
2
+ import type { IndexEntry } from "./index-builder.js";
3
+ import type { CollectionSchema, FieldsMap, JsonSchemaProperty } from "./types.js";
4
+ /**
5
+ * Converts a user-facing field definition map into a JSON Schema `CollectionSchema`.
6
+ *
7
+ * - Automatically injects `seqId` as the first property.
8
+ - Injects system fields (e.g., auth email/password) before user fields.
9
+ - Collects `required` from fields without defaults.
10
+ - Normalizes `unique`/`indexed` flags into `x-indexes`.
11
+ - Merges collection-level indexes from `options.indexes`.
12
+ - Passes through `x-rules` and `x-view-query` if provided.
13
+ *
14
+ * Used internally by `BaseCollection.define()`, `AuthCollection.define()`, and `ViewCollection.define()`.
15
+ */
16
+ export declare function toJSONSchema<K extends "base" | "auth" | "view">(kind: K, _name: string, fields: FieldsMap, options: {
17
+ indexes?: Array<IndexEntry<string>>;
18
+ rules?: RuleMap;
19
+ viewQuery?: string;
20
+ systemFields?: Record<string, JsonSchemaProperty>;
21
+ }): CollectionSchema & {
22
+ "x-collection-kind": K;
23
+ };
24
+ //# sourceMappingURL=serialize.d.ts.map