@narrative.io/data-collaboration-sdk-ts 0.0.51 → 0.0.52

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.
@@ -1 +1,81 @@
1
- export {};
1
+ /**
2
+ *
3
+ *
4
+ *
5
+ * @see {@link https://github.com/colinhacks/zod} for more information about Zod.
6
+ */
7
+ import { z } from 'zod';
8
+ /**
9
+ * Defines the structure for a budget object.
10
+ *
11
+ * @type {z.ZodObject}
12
+ */
13
+ export const NqlBudgetObj = z.object({
14
+ value: z.number().describe('The value of the budget.'),
15
+ currency: z.enum(['USD']).describe('The currency the budget is described in.'),
16
+ period: z.enum(['CALENDAR_MONTH']).describe('The period over which the budget will be applied.')
17
+ });
18
+ /**
19
+ * A schema object used to validate and infer the structure of NqlQuery.
20
+ *
21
+ * @constant {z.ZodObject} NqlQueryObj
22
+ */
23
+ export const NqlQueryInputObj = z.object({
24
+ nql: z.string().trim().includes('SELECT', {
25
+ message: 'NQL query must contain a SELECT statement.'
26
+ })
27
+ .regex(/^.*\bLIMIT\b.*/is, {
28
+ message: 'NQL query must contain a LIMIT statement.'
29
+ })
30
+ .regex(/^(?!.*\bJOIN\b).*/is, {
31
+ message: 'NQL query cannot contain a JOIN statement.'
32
+ })
33
+ .describe('A NQL query')
34
+ });
35
+ /**
36
+ * A schema object used to validate and infer the structure of NqlPreSelectExpression.
37
+ *
38
+ * @constant {z.ZodEnum} NqlPreSelectExpressionObj
39
+ */
40
+ export const NqlPreSelectExpressionObj = z.enum(['EXPLAIN']).describe('Expression that occurs before the SELECT statement.').optional();
41
+ export const NqlDatabaseObject = z.enum(['narrative']);
42
+ export const NqlTableObject = z.object({
43
+ database: NqlDatabaseObject,
44
+ table: z.enum(['rosetta_stone'])
45
+ });
46
+ export const NqlFieldObj = z.object({
47
+ field: z.string().trim(),
48
+ table: NqlTableObject
49
+ });
50
+ export const NqlFilterUnaryExpressionObj = z.object({
51
+ field: NqlFieldObj,
52
+ operator: z.enum(['IS NULL', 'IS NOT NULL']).describe('The operator to use for the filter. As a standalone operator it only expects the field to be defined.')
53
+ });
54
+ const NqlExpression = z.union([NqlFieldObj, z.string(), z.number(), z.boolean()]);
55
+ export const NqlFilterBinaryExpressionObj = z.object({
56
+ left: NqlExpression,
57
+ operator: z.enum(['=', '!=', '>', '<', '>=', '<=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE']).describe('The operator to use for the filter. As a binary operator it expects both a left and right expression'),
58
+ right: NqlExpression
59
+ });
60
+ export const NqlFilterExpressionObj = z.union([NqlFilterUnaryExpressionObj, NqlFilterBinaryExpressionObj]);
61
+ export const NqlBooleanExpressionObj = z.enum(['AND', 'OR']).describe('The operator to use for the filter. As a standalone operator it only expects the field to be defined.');
62
+ export const NqlWhereObj = z.object({
63
+ booleanExpressions: NqlBooleanExpressionObj.array(),
64
+ filterExpressions: NqlFilterExpressionObj.array()
65
+ }).refine((clause) => {
66
+ return clause.booleanExpressions.length === clause.filterExpressions.length - 1;
67
+ }, {
68
+ message: 'Boolean expression must have one less element than filter expression.'
69
+ });
70
+ export const NqlObj = z.object({
71
+ explain: NqlPreSelectExpressionObj,
72
+ select: NqlFieldObj.array(),
73
+ from: NqlTableObject.array(),
74
+ where: NqlWhereObj,
75
+ limit: NqlBudgetObj,
76
+ sort: z.undefined().describe('Sort is not currently supported in NQL'),
77
+ group: z.undefined().describe('Group is not currently supported in NQL'),
78
+ having: z.undefined().describe('Having is not currently supported in NQL'),
79
+ offset: z.undefined().describe('Offset is not currently supported in NQL'),
80
+ join: z.undefined().describe('Join is not currently supported in NQL')
81
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narrative.io/data-collaboration-sdk-ts",
3
- "version": "0.0.51",
3
+ "version": "0.0.52",
4
4
  "main": "build/index.js",
5
5
  "repository": "github:narrative-io/data-collaboration-sdk-ts",
6
6
  "source": "src/index.ts",
@@ -39,7 +39,8 @@
39
39
  "typescript": "^5.0.2"
40
40
  },
41
41
  "dependencies": {
42
- "mande": "^2.0.3"
42
+ "mande": "^2.0.3",
43
+ "zod": "^3.21.4"
43
44
  },
44
45
  "files": [
45
46
  "build"