@objectstack/spec 0.1.2 → 0.2.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.
Files changed (58) hide show
  1. package/dist/data/filter.zod.d.ts +295 -0
  2. package/dist/data/filter.zod.d.ts.map +1 -0
  3. package/dist/data/filter.zod.js +226 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -0
  7. package/dist/system/auth.zod.d.ts +2287 -0
  8. package/dist/system/auth.zod.d.ts.map +1 -0
  9. package/dist/system/auth.zod.js +365 -0
  10. package/dist/system/datasource.zod.d.ts +118 -38
  11. package/dist/system/datasource.zod.d.ts.map +1 -1
  12. package/dist/system/datasource.zod.js +25 -6
  13. package/dist/system/driver.zod.d.ts +106 -0
  14. package/dist/system/driver.zod.d.ts.map +1 -1
  15. package/dist/system/driver.zod.js +47 -0
  16. package/dist/system/policy.zod.d.ts +10 -10
  17. package/dist/ui/dashboard.zod.d.ts +10 -10
  18. package/dist/ui/dashboard.zod.d.ts.map +1 -1
  19. package/dist/ui/dashboard.zod.js +3 -2
  20. package/dist/ui/report.zod.d.ts +4 -32
  21. package/dist/ui/report.zod.d.ts.map +1 -1
  22. package/dist/ui/report.zod.js +3 -8
  23. package/json-schema/AccountLinkingConfig.json +27 -0
  24. package/json-schema/AuthConfig.json +606 -0
  25. package/json-schema/AuthPluginConfig.json +28 -0
  26. package/json-schema/AuthStrategy.json +17 -0
  27. package/json-schema/AuthenticationConfig.json +601 -0
  28. package/json-schema/AuthenticationProvider.json +617 -0
  29. package/json-schema/CSRFConfig.json +31 -0
  30. package/json-schema/ComparisonOperator.json +56 -0
  31. package/json-schema/Dashboard.json +20 -0
  32. package/json-schema/DashboardWidget.json +20 -0
  33. package/json-schema/DatabaseAdapter.json +38 -0
  34. package/json-schema/Datasource.json +25 -5
  35. package/json-schema/DatasourceCapabilities.json +25 -5
  36. package/json-schema/DriverCapabilities.json +30 -0
  37. package/json-schema/DriverDefinition.json +25 -5
  38. package/json-schema/DriverInterface.json +30 -0
  39. package/json-schema/EmailPasswordConfig.json +43 -0
  40. package/json-schema/EqualityOperator.json +14 -0
  41. package/json-schema/FieldOperators.json +108 -0
  42. package/json-schema/FilterCondition.json +28 -0
  43. package/json-schema/MagicLinkConfig.json +21 -0
  44. package/json-schema/NormalizedFilter.json +348 -0
  45. package/json-schema/OAuthProvider.json +66 -0
  46. package/json-schema/PasskeyConfig.json +54 -0
  47. package/json-schema/QueryFilter.json +34 -0
  48. package/json-schema/RangeOperator.json +41 -0
  49. package/json-schema/RateLimitConfig.json +36 -0
  50. package/json-schema/Report.json +20 -26
  51. package/json-schema/SessionConfig.json +56 -0
  52. package/json-schema/SetOperator.json +18 -0
  53. package/json-schema/SpecialOperator.json +18 -0
  54. package/json-schema/StandardAuthProvider.json +622 -0
  55. package/json-schema/StringOperator.json +21 -0
  56. package/json-schema/TwoFactorConfig.json +40 -0
  57. package/json-schema/UserFieldMapping.json +47 -0
  58. package/package.json +1 -1
@@ -0,0 +1,295 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Unified Query DSL Specification
4
+ *
5
+ * Based on industry best practices from:
6
+ * - Prisma ORM
7
+ * - Strapi CMS
8
+ * - TypeORM
9
+ * - LoopBack Framework
10
+ *
11
+ * Version: 1.0.0
12
+ * Status: Draft
13
+ *
14
+ * Objective: Define a JSON-based, database-agnostic query syntax standard
15
+ * for data filtering interactions between frontend and backend APIs.
16
+ *
17
+ * Design Principles:
18
+ * 1. Declarative: Frontend describes "what data to get", not "how to query"
19
+ * 2. Database Agnostic: Syntax contains no database-specific directives
20
+ * 3. Type Safe: Structure can be statically inferred by TypeScript
21
+ * 4. Convention over Configuration: Implicit syntax for common queries
22
+ */
23
+ /**
24
+ * Comparison operators for equality and inequality checks.
25
+ * Supported data types: Any
26
+ */
27
+ export declare const EqualityOperatorSchema: z.ZodObject<{
28
+ /** Equal to (default) - SQL: = | MongoDB: $eq */
29
+ $eq: z.ZodOptional<z.ZodAny>;
30
+ /** Not equal to - SQL: <> or != | MongoDB: $ne */
31
+ $ne: z.ZodOptional<z.ZodAny>;
32
+ }, "strip", z.ZodTypeAny, {
33
+ $eq?: any;
34
+ $ne?: any;
35
+ }, {
36
+ $eq?: any;
37
+ $ne?: any;
38
+ }>;
39
+ /**
40
+ * Comparison operators for numeric and date comparisons.
41
+ * Supported data types: Number, Date
42
+ */
43
+ export declare const ComparisonOperatorSchema: z.ZodObject<{
44
+ /** Greater than - SQL: > | MongoDB: $gt */
45
+ $gt: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodDate]>>;
46
+ /** Greater than or equal to - SQL: >= | MongoDB: $gte */
47
+ $gte: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodDate]>>;
48
+ /** Less than - SQL: < | MongoDB: $lt */
49
+ $lt: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodDate]>>;
50
+ /** Less than or equal to - SQL: <= | MongoDB: $lte */
51
+ $lte: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodDate]>>;
52
+ }, "strip", z.ZodTypeAny, {
53
+ $gt?: number | Date | undefined;
54
+ $gte?: number | Date | undefined;
55
+ $lt?: number | Date | undefined;
56
+ $lte?: number | Date | undefined;
57
+ }, {
58
+ $gt?: number | Date | undefined;
59
+ $gte?: number | Date | undefined;
60
+ $lt?: number | Date | undefined;
61
+ $lte?: number | Date | undefined;
62
+ }>;
63
+ /**
64
+ * Set operators for membership checks.
65
+ */
66
+ export declare const SetOperatorSchema: z.ZodObject<{
67
+ /** In list - SQL: IN (?, ?, ?) | MongoDB: $in */
68
+ $in: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
69
+ /** Not in list - SQL: NOT IN (...) | MongoDB: $nin */
70
+ $nin: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ $in?: any[] | undefined;
73
+ $nin?: any[] | undefined;
74
+ }, {
75
+ $in?: any[] | undefined;
76
+ $nin?: any[] | undefined;
77
+ }>;
78
+ /**
79
+ * Range operator for interval checks (closed interval).
80
+ * SQL: BETWEEN ? AND ? | MongoDB: $gte AND $lte
81
+ */
82
+ export declare const RangeOperatorSchema: z.ZodObject<{
83
+ /** Between (inclusive) - takes [min, max] array */
84
+ $between: z.ZodOptional<z.ZodTuple<[z.ZodUnion<[z.ZodNumber, z.ZodDate]>, z.ZodUnion<[z.ZodNumber, z.ZodDate]>], null>>;
85
+ }, "strip", z.ZodTypeAny, {
86
+ $between?: [number | Date, number | Date] | undefined;
87
+ }, {
88
+ $between?: [number | Date, number | Date] | undefined;
89
+ }>;
90
+ /**
91
+ * String pattern matching operators.
92
+ * Note: Case sensitivity should be handled at backend level.
93
+ */
94
+ export declare const StringOperatorSchema: z.ZodObject<{
95
+ /** Contains substring - SQL: LIKE %?% | MongoDB: $regex */
96
+ $contains: z.ZodOptional<z.ZodString>;
97
+ /** Starts with prefix - SQL: LIKE ?% | MongoDB: $regex */
98
+ $startsWith: z.ZodOptional<z.ZodString>;
99
+ /** Ends with suffix - SQL: LIKE %? | MongoDB: $regex */
100
+ $endsWith: z.ZodOptional<z.ZodString>;
101
+ }, "strip", z.ZodTypeAny, {
102
+ $contains?: string | undefined;
103
+ $startsWith?: string | undefined;
104
+ $endsWith?: string | undefined;
105
+ }, {
106
+ $contains?: string | undefined;
107
+ $startsWith?: string | undefined;
108
+ $endsWith?: string | undefined;
109
+ }>;
110
+ /**
111
+ * Special check operators for null and existence.
112
+ */
113
+ export declare const SpecialOperatorSchema: z.ZodObject<{
114
+ /** Is null check - SQL: IS NULL (true) / IS NOT NULL (false) | MongoDB: field: null */
115
+ $null: z.ZodOptional<z.ZodBoolean>;
116
+ /** Field exists check (primarily for NoSQL) - MongoDB: $exists */
117
+ $exist: z.ZodOptional<z.ZodBoolean>;
118
+ }, "strip", z.ZodTypeAny, {
119
+ $null?: boolean | undefined;
120
+ $exist?: boolean | undefined;
121
+ }, {
122
+ $null?: boolean | undefined;
123
+ $exist?: boolean | undefined;
124
+ }>;
125
+ /**
126
+ * All field-level operators combined.
127
+ * These can be applied to individual fields in a filter.
128
+ */
129
+ export declare const FieldOperatorsSchema: z.ZodObject<{
130
+ $eq: z.ZodOptional<z.ZodAny>;
131
+ $ne: z.ZodOptional<z.ZodAny>;
132
+ $gt: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodDate]>>;
133
+ $gte: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodDate]>>;
134
+ $lt: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodDate]>>;
135
+ $lte: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodDate]>>;
136
+ $in: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
137
+ $nin: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
138
+ $between: z.ZodOptional<z.ZodTuple<[z.ZodUnion<[z.ZodNumber, z.ZodDate]>, z.ZodUnion<[z.ZodNumber, z.ZodDate]>], null>>;
139
+ $contains: z.ZodOptional<z.ZodString>;
140
+ $startsWith: z.ZodOptional<z.ZodString>;
141
+ $endsWith: z.ZodOptional<z.ZodString>;
142
+ $null: z.ZodOptional<z.ZodBoolean>;
143
+ $exist: z.ZodOptional<z.ZodBoolean>;
144
+ }, "strip", z.ZodTypeAny, {
145
+ $eq?: any;
146
+ $ne?: any;
147
+ $gt?: number | Date | undefined;
148
+ $gte?: number | Date | undefined;
149
+ $lt?: number | Date | undefined;
150
+ $lte?: number | Date | undefined;
151
+ $in?: any[] | undefined;
152
+ $nin?: any[] | undefined;
153
+ $between?: [number | Date, number | Date] | undefined;
154
+ $contains?: string | undefined;
155
+ $startsWith?: string | undefined;
156
+ $endsWith?: string | undefined;
157
+ $null?: boolean | undefined;
158
+ $exist?: boolean | undefined;
159
+ }, {
160
+ $eq?: any;
161
+ $ne?: any;
162
+ $gt?: number | Date | undefined;
163
+ $gte?: number | Date | undefined;
164
+ $lt?: number | Date | undefined;
165
+ $lte?: number | Date | undefined;
166
+ $in?: any[] | undefined;
167
+ $nin?: any[] | undefined;
168
+ $between?: [number | Date, number | Date] | undefined;
169
+ $contains?: string | undefined;
170
+ $startsWith?: string | undefined;
171
+ $endsWith?: string | undefined;
172
+ $null?: boolean | undefined;
173
+ $exist?: boolean | undefined;
174
+ }>;
175
+ /**
176
+ * Recursive filter type that supports:
177
+ * 1. Implicit equality: { field: value }
178
+ * 2. Explicit operators: { field: { $op: value } }
179
+ * 3. Logical combinations: { $and: [...], $or: [...], $not: {...} }
180
+ * 4. Nested relations: { relation: { field: value } }
181
+ */
182
+ export type FilterCondition = {
183
+ [key: string]: any | z.infer<typeof FieldOperatorsSchema> | FilterCondition;
184
+ } & {
185
+ /** Logical AND - combines all conditions that must be true */
186
+ $and?: FilterCondition[];
187
+ /** Logical OR - at least one condition must be true */
188
+ $or?: FilterCondition[];
189
+ /** Logical NOT - negates the condition */
190
+ $not?: FilterCondition;
191
+ };
192
+ /**
193
+ * Zod schema for recursive filter validation.
194
+ * Uses z.lazy() to handle recursive structure.
195
+ */
196
+ export declare const FilterConditionSchema: z.ZodType<FilterCondition>;
197
+ /**
198
+ * Top-level query filter wrapper.
199
+ * This is typically used as the "where" clause in a query.
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const filter: QueryFilter = {
204
+ * where: {
205
+ * status: "active", // Implicit equality
206
+ * age: { $gte: 18 }, // Explicit operator
207
+ * $or: [ // Logical combination
208
+ * { role: "admin" },
209
+ * { email: { $contains: "@company.com" } }
210
+ * ],
211
+ * profile: { // Nested relation
212
+ * verified: true
213
+ * }
214
+ * }
215
+ * }
216
+ * ```
217
+ */
218
+ export declare const QueryFilterSchema: z.ZodObject<{
219
+ where: z.ZodOptional<z.ZodType<FilterCondition, z.ZodTypeDef, FilterCondition>>;
220
+ }, "strip", z.ZodTypeAny, {
221
+ where?: FilterCondition | undefined;
222
+ }, {
223
+ where?: FilterCondition | undefined;
224
+ }>;
225
+ /**
226
+ * Type-safe filter operators for use in TypeScript.
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * type UserFilter = Filter<User>;
231
+ *
232
+ * const filter: UserFilter = {
233
+ * age: { $gte: 18 },
234
+ * email: { $contains: "@example.com" }
235
+ * };
236
+ * ```
237
+ */
238
+ export type Filter<T = any> = {
239
+ [K in keyof T]?: T[K] | {
240
+ $eq?: T[K];
241
+ $ne?: T[K];
242
+ $gt?: T[K] extends number | Date ? T[K] : never;
243
+ $gte?: T[K] extends number | Date ? T[K] : never;
244
+ $lt?: T[K] extends number | Date ? T[K] : never;
245
+ $lte?: T[K] extends number | Date ? T[K] : never;
246
+ $in?: T[K][];
247
+ $nin?: T[K][];
248
+ $between?: T[K] extends number | Date ? [T[K], T[K]] : never;
249
+ $contains?: T[K] extends string ? string : never;
250
+ $startsWith?: T[K] extends string ? string : never;
251
+ $endsWith?: T[K] extends string ? string : never;
252
+ $null?: boolean;
253
+ $exist?: boolean;
254
+ } | (T[K] extends object ? Filter<T[K]> : never);
255
+ } & {
256
+ $and?: Filter<T>[];
257
+ $or?: Filter<T>[];
258
+ $not?: Filter<T>;
259
+ };
260
+ /**
261
+ * Scalar types supported by the filter system.
262
+ */
263
+ export type Scalar = string | number | boolean | Date | null;
264
+ export type FieldOperators = z.infer<typeof FieldOperatorsSchema>;
265
+ export type QueryFilter = z.infer<typeof QueryFilterSchema>;
266
+ /**
267
+ * Normalized filter AST structure.
268
+ * This is the internal representation after converting all syntactic sugar
269
+ * to explicit operators.
270
+ *
271
+ * Stage 1: Normalization Pass
272
+ * Input: { age: 18, role: "admin" }
273
+ * Output: { $and: [{ age: { $eq: 18 } }, { role: { $eq: "admin" } }] }
274
+ *
275
+ * This simplifies adapter implementation by providing a consistent structure.
276
+ */
277
+ export declare const NormalizedFilterSchema: z.ZodType<any>;
278
+ export type NormalizedFilter = z.infer<typeof NormalizedFilterSchema>;
279
+ /**
280
+ * All supported operator keys.
281
+ * Useful for validation and parsing.
282
+ */
283
+ export declare const FILTER_OPERATORS: readonly ["$eq", "$ne", "$gt", "$gte", "$lt", "$lte", "$in", "$nin", "$between", "$contains", "$startsWith", "$endsWith", "$null", "$exist"];
284
+ /**
285
+ * Logical operator keys.
286
+ */
287
+ export declare const LOGICAL_OPERATORS: readonly ["$and", "$or", "$not"];
288
+ /**
289
+ * All operator keys (field + logical).
290
+ */
291
+ export declare const ALL_OPERATORS: readonly ["$eq", "$ne", "$gt", "$gte", "$lt", "$lte", "$in", "$nin", "$between", "$contains", "$startsWith", "$endsWith", "$null", "$exist", "$and", "$or", "$not"];
292
+ export type FilterOperatorKey = typeof FILTER_OPERATORS[number];
293
+ export type LogicalOperatorKey = typeof LOGICAL_OPERATORS[number];
294
+ export type OperatorKey = typeof ALL_OPERATORS[number];
295
+ //# sourceMappingURL=filter.zod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.zod.d.ts","sourceRoot":"","sources":["../../src/data/filter.zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH;;;GAGG;AACH,eAAO,MAAM,sBAAsB;IACjC,iDAAiD;;IAGjD,kDAAkD;;;;;;;;EAElD,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,wBAAwB;IACnC,2CAA2C;;IAG3C,yDAAyD;;IAGzD,wCAAwC;;IAGxC,sDAAsD;;;;;;;;;;;;EAEtD,CAAC;AAMH;;GAEG;AACH,eAAO,MAAM,iBAAiB;IAC5B,iDAAiD;;IAGjD,sDAAsD;;;;;;;;EAEtD,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB;IAC9B,mDAAmD;;;;;;EAKnD,CAAC;AAMH;;;GAGG;AACH,eAAO,MAAM,oBAAoB;IAC/B,2DAA2D;;IAG3D,0DAA0D;;IAG1D,wDAAwD;;;;;;;;;;EAExD,CAAC;AAMH;;GAEG;AACH,eAAO,MAAM,qBAAqB;IA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7D,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAM5D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAuBjD,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAMtE;;;GAGG;AACH,eAAO,MAAM,gBAAgB,8IAWnB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,iBAAiB,kCAAmC,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,aAAa,qKAAuD,CAAC;AAElF,MAAM,MAAM,iBAAiB,GAAG,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAChE,MAAM,MAAM,kBAAkB,GAAG,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAClE,MAAM,MAAM,WAAW,GAAG,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ALL_OPERATORS = exports.LOGICAL_OPERATORS = exports.FILTER_OPERATORS = exports.NormalizedFilterSchema = exports.QueryFilterSchema = exports.FilterConditionSchema = exports.FieldOperatorsSchema = exports.SpecialOperatorSchema = exports.StringOperatorSchema = exports.RangeOperatorSchema = exports.SetOperatorSchema = exports.ComparisonOperatorSchema = exports.EqualityOperatorSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Unified Query DSL Specification
7
+ *
8
+ * Based on industry best practices from:
9
+ * - Prisma ORM
10
+ * - Strapi CMS
11
+ * - TypeORM
12
+ * - LoopBack Framework
13
+ *
14
+ * Version: 1.0.0
15
+ * Status: Draft
16
+ *
17
+ * Objective: Define a JSON-based, database-agnostic query syntax standard
18
+ * for data filtering interactions between frontend and backend APIs.
19
+ *
20
+ * Design Principles:
21
+ * 1. Declarative: Frontend describes "what data to get", not "how to query"
22
+ * 2. Database Agnostic: Syntax contains no database-specific directives
23
+ * 3. Type Safe: Structure can be statically inferred by TypeScript
24
+ * 4. Convention over Configuration: Implicit syntax for common queries
25
+ */
26
+ // ============================================================================
27
+ // 3.1 Comparison Operators
28
+ // ============================================================================
29
+ /**
30
+ * Comparison operators for equality and inequality checks.
31
+ * Supported data types: Any
32
+ */
33
+ exports.EqualityOperatorSchema = zod_1.z.object({
34
+ /** Equal to (default) - SQL: = | MongoDB: $eq */
35
+ $eq: zod_1.z.any().optional(),
36
+ /** Not equal to - SQL: <> or != | MongoDB: $ne */
37
+ $ne: zod_1.z.any().optional(),
38
+ });
39
+ /**
40
+ * Comparison operators for numeric and date comparisons.
41
+ * Supported data types: Number, Date
42
+ */
43
+ exports.ComparisonOperatorSchema = zod_1.z.object({
44
+ /** Greater than - SQL: > | MongoDB: $gt */
45
+ $gt: zod_1.z.union([zod_1.z.number(), zod_1.z.date()]).optional(),
46
+ /** Greater than or equal to - SQL: >= | MongoDB: $gte */
47
+ $gte: zod_1.z.union([zod_1.z.number(), zod_1.z.date()]).optional(),
48
+ /** Less than - SQL: < | MongoDB: $lt */
49
+ $lt: zod_1.z.union([zod_1.z.number(), zod_1.z.date()]).optional(),
50
+ /** Less than or equal to - SQL: <= | MongoDB: $lte */
51
+ $lte: zod_1.z.union([zod_1.z.number(), zod_1.z.date()]).optional(),
52
+ });
53
+ // ============================================================================
54
+ // 3.2 Set & Range Operators
55
+ // ============================================================================
56
+ /**
57
+ * Set operators for membership checks.
58
+ */
59
+ exports.SetOperatorSchema = zod_1.z.object({
60
+ /** In list - SQL: IN (?, ?, ?) | MongoDB: $in */
61
+ $in: zod_1.z.array(zod_1.z.any()).optional(),
62
+ /** Not in list - SQL: NOT IN (...) | MongoDB: $nin */
63
+ $nin: zod_1.z.array(zod_1.z.any()).optional(),
64
+ });
65
+ /**
66
+ * Range operator for interval checks (closed interval).
67
+ * SQL: BETWEEN ? AND ? | MongoDB: $gte AND $lte
68
+ */
69
+ exports.RangeOperatorSchema = zod_1.z.object({
70
+ /** Between (inclusive) - takes [min, max] array */
71
+ $between: zod_1.z.tuple([
72
+ zod_1.z.union([zod_1.z.number(), zod_1.z.date()]),
73
+ zod_1.z.union([zod_1.z.number(), zod_1.z.date()])
74
+ ]).optional(),
75
+ });
76
+ // ============================================================================
77
+ // 3.3 String-Specific Operators
78
+ // ============================================================================
79
+ /**
80
+ * String pattern matching operators.
81
+ * Note: Case sensitivity should be handled at backend level.
82
+ */
83
+ exports.StringOperatorSchema = zod_1.z.object({
84
+ /** Contains substring - SQL: LIKE %?% | MongoDB: $regex */
85
+ $contains: zod_1.z.string().optional(),
86
+ /** Starts with prefix - SQL: LIKE ?% | MongoDB: $regex */
87
+ $startsWith: zod_1.z.string().optional(),
88
+ /** Ends with suffix - SQL: LIKE %? | MongoDB: $regex */
89
+ $endsWith: zod_1.z.string().optional(),
90
+ });
91
+ // ============================================================================
92
+ // 3.5 Special Operators
93
+ // ============================================================================
94
+ /**
95
+ * Special check operators for null and existence.
96
+ */
97
+ exports.SpecialOperatorSchema = zod_1.z.object({
98
+ /** Is null check - SQL: IS NULL (true) / IS NOT NULL (false) | MongoDB: field: null */
99
+ $null: zod_1.z.boolean().optional(),
100
+ /** Field exists check (primarily for NoSQL) - MongoDB: $exists */
101
+ $exist: zod_1.z.boolean().optional(),
102
+ });
103
+ // ============================================================================
104
+ // Combined Field Operators
105
+ // ============================================================================
106
+ /**
107
+ * All field-level operators combined.
108
+ * These can be applied to individual fields in a filter.
109
+ */
110
+ exports.FieldOperatorsSchema = zod_1.z.object({
111
+ // Equality
112
+ $eq: zod_1.z.any().optional(),
113
+ $ne: zod_1.z.any().optional(),
114
+ // Comparison (numeric/date)
115
+ $gt: zod_1.z.union([zod_1.z.number(), zod_1.z.date()]).optional(),
116
+ $gte: zod_1.z.union([zod_1.z.number(), zod_1.z.date()]).optional(),
117
+ $lt: zod_1.z.union([zod_1.z.number(), zod_1.z.date()]).optional(),
118
+ $lte: zod_1.z.union([zod_1.z.number(), zod_1.z.date()]).optional(),
119
+ // Set & Range
120
+ $in: zod_1.z.array(zod_1.z.any()).optional(),
121
+ $nin: zod_1.z.array(zod_1.z.any()).optional(),
122
+ $between: zod_1.z.tuple([
123
+ zod_1.z.union([zod_1.z.number(), zod_1.z.date()]),
124
+ zod_1.z.union([zod_1.z.number(), zod_1.z.date()])
125
+ ]).optional(),
126
+ // String-specific
127
+ $contains: zod_1.z.string().optional(),
128
+ $startsWith: zod_1.z.string().optional(),
129
+ $endsWith: zod_1.z.string().optional(),
130
+ // Special
131
+ $null: zod_1.z.boolean().optional(),
132
+ $exist: zod_1.z.boolean().optional(),
133
+ });
134
+ /**
135
+ * Zod schema for recursive filter validation.
136
+ * Uses z.lazy() to handle recursive structure.
137
+ */
138
+ exports.FilterConditionSchema = zod_1.z.lazy(() => zod_1.z.record(zod_1.z.string(), zod_1.z.any()).and(zod_1.z.object({
139
+ $and: zod_1.z.array(exports.FilterConditionSchema).optional(),
140
+ $or: zod_1.z.array(exports.FilterConditionSchema).optional(),
141
+ $not: exports.FilterConditionSchema.optional(),
142
+ })));
143
+ // ============================================================================
144
+ // Query Filter Wrapper
145
+ // ============================================================================
146
+ /**
147
+ * Top-level query filter wrapper.
148
+ * This is typically used as the "where" clause in a query.
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const filter: QueryFilter = {
153
+ * where: {
154
+ * status: "active", // Implicit equality
155
+ * age: { $gte: 18 }, // Explicit operator
156
+ * $or: [ // Logical combination
157
+ * { role: "admin" },
158
+ * { email: { $contains: "@company.com" } }
159
+ * ],
160
+ * profile: { // Nested relation
161
+ * verified: true
162
+ * }
163
+ * }
164
+ * }
165
+ * ```
166
+ */
167
+ exports.QueryFilterSchema = zod_1.z.object({
168
+ where: exports.FilterConditionSchema.optional(),
169
+ });
170
+ // ============================================================================
171
+ // Normalization Utilities (Internal Representation)
172
+ // ============================================================================
173
+ /**
174
+ * Normalized filter AST structure.
175
+ * This is the internal representation after converting all syntactic sugar
176
+ * to explicit operators.
177
+ *
178
+ * Stage 1: Normalization Pass
179
+ * Input: { age: 18, role: "admin" }
180
+ * Output: { $and: [{ age: { $eq: 18 } }, { role: { $eq: "admin" } }] }
181
+ *
182
+ * This simplifies adapter implementation by providing a consistent structure.
183
+ */
184
+ exports.NormalizedFilterSchema = zod_1.z.lazy(() => zod_1.z.object({
185
+ $and: zod_1.z.array(zod_1.z.union([
186
+ // Field condition: { field: { $op: value } }
187
+ zod_1.z.record(zod_1.z.string(), exports.FieldOperatorsSchema),
188
+ // Nested logical group
189
+ exports.NormalizedFilterSchema,
190
+ ])).optional(),
191
+ $or: zod_1.z.array(zod_1.z.union([
192
+ zod_1.z.record(zod_1.z.string(), exports.FieldOperatorsSchema),
193
+ exports.NormalizedFilterSchema,
194
+ ])).optional(),
195
+ $not: zod_1.z.union([
196
+ zod_1.z.record(zod_1.z.string(), exports.FieldOperatorsSchema),
197
+ exports.NormalizedFilterSchema,
198
+ ]).optional(),
199
+ }));
200
+ // ============================================================================
201
+ // Constants & Metadata
202
+ // ============================================================================
203
+ /**
204
+ * All supported operator keys.
205
+ * Useful for validation and parsing.
206
+ */
207
+ exports.FILTER_OPERATORS = [
208
+ // Equality
209
+ '$eq', '$ne',
210
+ // Comparison
211
+ '$gt', '$gte', '$lt', '$lte',
212
+ // Set & Range
213
+ '$in', '$nin', '$between',
214
+ // String
215
+ '$contains', '$startsWith', '$endsWith',
216
+ // Special
217
+ '$null', '$exist',
218
+ ];
219
+ /**
220
+ * Logical operator keys.
221
+ */
222
+ exports.LOGICAL_OPERATORS = ['$and', '$or', '$not'];
223
+ /**
224
+ * All operator keys (field + logical).
225
+ */
226
+ exports.ALL_OPERATORS = [...exports.FILTER_OPERATORS, ...exports.LOGICAL_OPERATORS];
package/dist/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from './data/workflow.zod';
15
15
  export * from './data/flow.zod';
16
16
  export * from './data/dataset.zod';
17
17
  export * from './data/query.zod';
18
+ export * from './data/filter.zod';
18
19
  export * from './data/mapping.zod';
19
20
  export * from './data/trigger.zod';
20
21
  export * from './api/contract.zod';
@@ -31,6 +32,7 @@ export * from './system/manifest.zod';
31
32
  export * from './system/datasource.zod';
32
33
  export * from './system/api.zod';
33
34
  export * from './system/identity.zod';
35
+ export * from './system/auth.zod';
34
36
  export * from './system/policy.zod';
35
37
  export * from './system/role.zod';
36
38
  export * from './system/territory.zod';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,gBAAgB,CAAC;AAG/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAG/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,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gB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ __exportStar(require("./data/workflow.zod"), exports);
32
32
  __exportStar(require("./data/flow.zod"), exports);
33
33
  __exportStar(require("./data/dataset.zod"), exports);
34
34
  __exportStar(require("./data/query.zod"), exports);
35
+ __exportStar(require("./data/filter.zod"), exports); // Unified Query DSL
35
36
  __exportStar(require("./data/mapping.zod"), exports);
36
37
  __exportStar(require("./data/trigger.zod"), exports);
37
38
  // API Protocol (Envelopes, Contracts)
@@ -52,6 +53,7 @@ __exportStar(require("./system/manifest.zod"), exports);
52
53
  __exportStar(require("./system/datasource.zod"), exports);
53
54
  __exportStar(require("./system/api.zod"), exports);
54
55
  __exportStar(require("./system/identity.zod"), exports);
56
+ __exportStar(require("./system/auth.zod"), exports);
55
57
  __exportStar(require("./system/policy.zod"), exports);
56
58
  __exportStar(require("./system/role.zod"), exports);
57
59
  __exportStar(require("./system/territory.zod"), exports);