Skip to content

Commit a5b07f9

Browse files
Merge pull request #104 from contentstack/development
DX | 10-11-2025 | Release
2 parents 6534d29 + 5fe8d85 commit a5b07f9

File tree

8 files changed

+264
-8
lines changed

8 files changed

+264
-8
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/datasync-filesystem-sdk",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "JavaScript filesystem SDK to query data synced via @contentstack/datasync-content-store-filesystem",
55
"main": "dist/index.js",
66
"scripts": {

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { merge } from 'lodash'
99
import { defaultConfig } from './config'
1010
import { Stack } from './stack'
11+
export { ERROR_MESSAGES, WARNING_MESSAGES } from './messages'
1112

1213
interface IUserConfig {
1314
contentStore?: {

src/messages.ts

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*!
2+
* Contentstack DataSync Filesystem SDK.
3+
* Centralized error and warning messages
4+
* Copyright (c) Contentstack LLC
5+
* MIT Licensed
6+
*/
7+
8+
/**
9+
* Centralized error and warning messages for the SDK
10+
* This file contains all user-facing messages to ensure consistency and ease of maintenance
11+
*/
12+
export const ERROR_MESSAGES = {
13+
/**
14+
* Error when a key does not exist on a data object
15+
* @param key - The key that was not found
16+
* @param data - The data object that was searched
17+
*/
18+
KEY_NOT_FOUND: (key: string, data: any) =>
19+
`The key '${key}' does not exist on: ${JSON.stringify(data)}`,
20+
21+
/**
22+
* Error for invalid parameters in comparison operators
23+
*/
24+
INVALID_COMPARISON_PARAMS: (type: string) =>
25+
`Kindly provide valid parameters for ${type}`,
26+
27+
/**
28+
* Error for invalid parameters in contained operators
29+
*/
30+
INVALID_CONTAINED_PARAMS: (bool: boolean) =>
31+
`Kindly provide valid parameters for ${bool}`,
32+
33+
/**
34+
* Error for invalid parameters in exists operators
35+
*/
36+
INVALID_EXISTS_PARAMS: (bool: boolean) =>
37+
`Kindly provide valid parameters for ${bool}`,
38+
39+
/**
40+
* Error for invalid parameters in sort methods
41+
*/
42+
INVALID_SORT_PARAMS: (type: string) =>
43+
`Kindly provide valid parameters for sort-${type}`,
44+
45+
/**
46+
* Error when argument should be a number
47+
*/
48+
ARGUMENT_SHOULD_BE_NUMBER: () =>
49+
'Argument should be a number.',
50+
51+
/**
52+
* Error when content type uid is not provided
53+
*/
54+
CONTENT_TYPE_UID_REQUIRED: () =>
55+
'Kindly provide a uid for .contentType()',
56+
57+
/**
58+
* Error when contentType() is not called before entries()
59+
*/
60+
CONTENT_TYPE_REQUIRED_BEFORE_ENTRIES: () =>
61+
'Please call .contentType() before calling .entries()!',
62+
63+
/**
64+
* Error when content type is not found at path
65+
*/
66+
CONTENT_TYPE_NOT_FOUND: (contentTypeUid: string, filePath: string) =>
67+
`Queried content type ${contentTypeUid} was not found at ${filePath}!`,
68+
69+
/**
70+
* Error for invalid parameters in equalTo()
71+
*/
72+
INVALID_EQUAL_TO_PARAMS: () =>
73+
'Kindly provide valid parameters for .equalTo()!',
74+
75+
/**
76+
* Error for invalid parameters in where()
77+
*/
78+
INVALID_WHERE_PARAMS: () =>
79+
'Kindly provide a valid field and expr/fn value for \'.where()\'',
80+
81+
/**
82+
* Error for invalid parameters in query()
83+
*/
84+
INVALID_QUERY_PARAMS: () =>
85+
'Kindly provide valid parameters for \'.query()\'',
86+
87+
/**
88+
* Error for invalid parameters in tags()
89+
*/
90+
INVALID_TAGS_PARAMS: () =>
91+
'Kindly provide valid parameters for \'.tags()\'',
92+
93+
/**
94+
* Error when language code is invalid
95+
*/
96+
INVALID_LANGUAGE_CODE: (languageCode: any) =>
97+
`${languageCode} should be of type string and non-empty!`,
98+
99+
/**
100+
* Error for invalid parameters in include()
101+
*/
102+
INVALID_INCLUDE_PARAMS: () =>
103+
'Kindly pass \'string\' OR \'array\' fields for .include()!',
104+
105+
/**
106+
* Error for invalid parameters in regex()
107+
*/
108+
INVALID_REGEX_PARAMS: () =>
109+
'Kindly provide valid parameters for .regex()!',
110+
111+
/**
112+
* Error for invalid parameters in only()
113+
*/
114+
INVALID_ONLY_PARAMS: () =>
115+
'Kindly provide valid parameters for .only()!',
116+
117+
/**
118+
* Error for invalid parameters in except()
119+
*/
120+
INVALID_EXCEPT_PARAMS: () =>
121+
'Kindly provide valid parameters for .except()!',
122+
123+
/**
124+
* Error for invalid parameters in queryReferences()
125+
*/
126+
INVALID_QUERY_REFERENCES_PARAMS: () =>
127+
'Kindly valid parameters for \'.queryReferences()\'!',
128+
129+
/**
130+
* Error for invalid parameters in referenceDepth()
131+
*/
132+
INVALID_REFERENCE_DEPTH_PARAMS: () =>
133+
'Kindly valid parameters for \'.referenceDepth()\'!',
134+
}
135+
136+
export const WARNING_MESSAGES = {
137+
/**
138+
* Warning for slow .includeReferences() query
139+
*/
140+
INCLUDE_REFERENCES_SLOW: () =>
141+
'.includeReferences(...)',
142+
143+
/**
144+
* Warning when increasing reference depth beyond default
145+
*/
146+
REFERENCE_DEPTH_PERFORMANCE: (referenceDepth: number) =>
147+
`Increasing reference depth beyond ${referenceDepth} may impact performance.`,
148+
}
149+

src/stack.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
getEntriesPath,
2727
segregateQueries,
2828
} from './utils'
29+
import { WARNING_MESSAGES } from './messages'
2930

3031
interface IShelf {
3132
path: string,
@@ -847,7 +848,7 @@ export class Stack {
847848
* @returns {this} - Returns `stack's` instance
848849
*/
849850
public includeReferences(depth?: number) {
850-
console.warn('.includeReferences() is a relatively slow query..!')
851+
console.warn(WARNING_MESSAGES.INCLUDE_REFERENCES_SLOW())
851852
this.q.includeAllReferences = true
852853
if (typeof depth === 'number') {
853854
this.q.referenceDepth = depth
@@ -1069,7 +1070,7 @@ export class Stack {
10691070
this.q.referenceDepth = depth
10701071

10711072
if (depth > this.contentStore.referenceDepth) {
1072-
console.warn(`Increasing reference depth above ${this.contentStore.referenceDepth} may degrade performance!`)
1073+
console.warn(WARNING_MESSAGES.REFERENCE_DEPTH_PERFORMANCE(this.contentStore.referenceDepth))
10731074
}
10741075

10751076
return this

src/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { existsSync } from './fs'
1919
import {
2020
getConfig,
2121
} from './index'
22-
import { sync } from 'mkdirp';
22+
import { sync } from 'mkdirp'
23+
import { ERROR_MESSAGES } from './messages';
2324
const localePaths = Object.create(null)
2425

2526
export const difference = (obj, baseObj) => {
@@ -52,7 +53,7 @@ const buildPath = (pattern, data) => {
5253
if (data[k]) {
5354
pathKeys.push(data[k])
5455
} else {
55-
throw new TypeError(`The key ${k} did not exist on ${JSON.stringify(data)}`)
56+
throw new TypeError(ERROR_MESSAGES.KEY_NOT_FOUND(k, data))
5657
}
5758
} else {
5859
pathKeys.push(patternKeys[i])

typings/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* MIT Licensed
66
*/
77
import { Stack } from './stack';
8+
export { ERROR_MESSAGES, WARNING_MESSAGES } from './messages';
89
interface IUserConfig {
910
contentStore?: {
1011
baseDir?: string;
@@ -53,4 +54,3 @@ export declare class Contentstack {
5354
*/
5455
static Stack(stackArguments: any): Stack;
5556
}
56-
export {};

typings/messages.d.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*!
2+
* Contentstack DataSync Filesystem SDK.
3+
* Centralized error and warning messages
4+
* Copyright (c) Contentstack LLC
5+
* MIT Licensed
6+
*/
7+
/**
8+
* Centralized error and warning messages for the SDK
9+
* This file contains all user-facing messages to ensure consistency and ease of maintenance
10+
*/
11+
export declare const ERROR_MESSAGES: {
12+
/**
13+
* Error when a key does not exist on a data object
14+
* @param key - The key that was not found
15+
* @param data - The data object that was searched
16+
*/
17+
KEY_NOT_FOUND: (key: string, data: any) => string;
18+
/**
19+
* Error for invalid parameters in comparison operators
20+
*/
21+
INVALID_COMPARISON_PARAMS: (type: string) => string;
22+
/**
23+
* Error for invalid parameters in contained operators
24+
*/
25+
INVALID_CONTAINED_PARAMS: (bool: boolean) => string;
26+
/**
27+
* Error for invalid parameters in exists operators
28+
*/
29+
INVALID_EXISTS_PARAMS: (bool: boolean) => string;
30+
/**
31+
* Error for invalid parameters in sort methods
32+
*/
33+
INVALID_SORT_PARAMS: (type: string) => string;
34+
/**
35+
* Error when argument should be a number
36+
*/
37+
ARGUMENT_SHOULD_BE_NUMBER: () => string;
38+
/**
39+
* Error when content type uid is not provided
40+
*/
41+
CONTENT_TYPE_UID_REQUIRED: () => string;
42+
/**
43+
* Error when contentType() is not called before entries()
44+
*/
45+
CONTENT_TYPE_REQUIRED_BEFORE_ENTRIES: () => string;
46+
/**
47+
* Error when content type is not found at path
48+
*/
49+
CONTENT_TYPE_NOT_FOUND: (contentTypeUid: string, filePath: string) => string;
50+
/**
51+
* Error for invalid parameters in equalTo()
52+
*/
53+
INVALID_EQUAL_TO_PARAMS: () => string;
54+
/**
55+
* Error for invalid parameters in where()
56+
*/
57+
INVALID_WHERE_PARAMS: () => string;
58+
/**
59+
* Error for invalid parameters in query()
60+
*/
61+
INVALID_QUERY_PARAMS: () => string;
62+
/**
63+
* Error for invalid parameters in tags()
64+
*/
65+
INVALID_TAGS_PARAMS: () => string;
66+
/**
67+
* Error when language code is invalid
68+
*/
69+
INVALID_LANGUAGE_CODE: (languageCode: any) => string;
70+
/**
71+
* Error for invalid parameters in include()
72+
*/
73+
INVALID_INCLUDE_PARAMS: () => string;
74+
/**
75+
* Error for invalid parameters in regex()
76+
*/
77+
INVALID_REGEX_PARAMS: () => string;
78+
/**
79+
* Error for invalid parameters in only()
80+
*/
81+
INVALID_ONLY_PARAMS: () => string;
82+
/**
83+
* Error for invalid parameters in except()
84+
*/
85+
INVALID_EXCEPT_PARAMS: () => string;
86+
/**
87+
* Error for invalid parameters in queryReferences()
88+
*/
89+
INVALID_QUERY_REFERENCES_PARAMS: () => string;
90+
/**
91+
* Error for invalid parameters in referenceDepth()
92+
*/
93+
INVALID_REFERENCE_DEPTH_PARAMS: () => string;
94+
};
95+
export declare const WARNING_MESSAGES: {
96+
/**
97+
* Warning for slow .includeReferences() query
98+
*/
99+
INCLUDE_REFERENCES_SLOW: () => string;
100+
/**
101+
* Warning when increasing reference depth beyond default
102+
*/
103+
REFERENCE_DEPTH_PERFORMANCE: (referenceDepth: number) => string;
104+
};

0 commit comments

Comments
 (0)