@dyrected/core 2.5.26 → 2.5.28

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/dist/index.cjs CHANGED
@@ -29,6 +29,7 @@ __export(index_exports, {
29
29
  generateFreshSetupPrompt: () => generateFreshSetupPrompt,
30
30
  normalizeConfig: () => normalizeConfig,
31
31
  parseMongoWhere: () => parseMongoWhere,
32
+ parseSort: () => parseSort,
32
33
  parseSqlWhere: () => parseSqlWhere,
33
34
  runCollectionHooks: () => runCollectionHooks
34
35
  });
@@ -1158,6 +1159,23 @@ function parseMongoWhere(where) {
1158
1159
  return buildClause(where);
1159
1160
  }
1160
1161
 
1162
+ // src/utils/parse-sort.ts
1163
+ var SORT_FIELD_PATTERN = /^([A-Za-z_][A-Za-z0-9_]*)(?:\s+(ASC|DESC))?$/i;
1164
+ function parseSort(sort, fallback = { field: "createdAt", direction: "DESC" }) {
1165
+ if (!sort) return [fallback];
1166
+ const clauses = sort.split(",").map((part) => part.trim()).filter(Boolean).map((part) => {
1167
+ const descByPrefix = part.startsWith("-");
1168
+ const withoutPrefix = descByPrefix ? part.slice(1).trim() : part;
1169
+ const match = withoutPrefix.match(SORT_FIELD_PATTERN);
1170
+ if (!match) return null;
1171
+ return {
1172
+ field: match[1],
1173
+ direction: descByPrefix || match[2]?.toUpperCase() === "DESC" ? "DESC" : "ASC"
1174
+ };
1175
+ }).filter((clause) => Boolean(clause));
1176
+ return clauses.length > 0 ? clauses : [fallback];
1177
+ }
1178
+
1161
1179
  // src/utils/hooks.ts
1162
1180
  async function runCollectionHooks(hooks, args, options = {}) {
1163
1181
  if (!hooks || hooks.length === 0) {
@@ -1338,6 +1356,7 @@ function defineConfig(config) {
1338
1356
  generateFreshSetupPrompt,
1339
1357
  normalizeConfig,
1340
1358
  parseMongoWhere,
1359
+ parseSort,
1341
1360
  parseSqlWhere,
1342
1361
  runCollectionHooks
1343
1362
  });
package/dist/index.d.cts CHANGED
@@ -82,6 +82,13 @@ declare function parseSqlWhere(where: WhereClause, getJsonField: (field: string)
82
82
  */
83
83
  declare function parseMongoWhere(where: WhereClause): Record<string, any>;
84
84
 
85
+ type SortDirection = 'ASC' | 'DESC';
86
+ interface SortClause {
87
+ field: string;
88
+ direction: SortDirection;
89
+ }
90
+ declare function parseSort(sort: string | undefined, fallback?: SortClause): SortClause[];
91
+
85
92
  type AnyHookFn = (args: any) => any;
86
93
  /**
87
94
  * Run a list of hook functions sequentially.
@@ -212,4 +219,4 @@ declare function defineGlobal<TDoc extends object>(config: GlobalConfig<TDoc>):
212
219
  */
213
220
  declare function defineConfig(config: DyrectedConfig): DyrectedConfig;
214
221
 
215
- export { AuthDocFields, CollectionConfig, DyrectedConfig, Field, GlobalConfig, InferDocShape, Prettify, type SetupPromptConfig, type SqlWhereResult, SystemDocFields, UploadDocFields, type WhereClause, type WhereOperator, type WhereOperatorName, defineCollection, defineConfig, defineGlobal, executeFieldAfterRead, executeFieldBeforeChange, generateAIPrompt, generateFreshSetupPrompt, normalizeConfig, parseMongoWhere, parseSqlWhere, runCollectionHooks };
222
+ export { AuthDocFields, CollectionConfig, DyrectedConfig, Field, GlobalConfig, InferDocShape, Prettify, type SetupPromptConfig, type SortClause, type SortDirection, type SqlWhereResult, SystemDocFields, UploadDocFields, type WhereClause, type WhereOperator, type WhereOperatorName, defineCollection, defineConfig, defineGlobal, executeFieldAfterRead, executeFieldBeforeChange, generateAIPrompt, generateFreshSetupPrompt, normalizeConfig, parseMongoWhere, parseSort, parseSqlWhere, runCollectionHooks };
package/dist/index.d.ts CHANGED
@@ -82,6 +82,13 @@ declare function parseSqlWhere(where: WhereClause, getJsonField: (field: string)
82
82
  */
83
83
  declare function parseMongoWhere(where: WhereClause): Record<string, any>;
84
84
 
85
+ type SortDirection = 'ASC' | 'DESC';
86
+ interface SortClause {
87
+ field: string;
88
+ direction: SortDirection;
89
+ }
90
+ declare function parseSort(sort: string | undefined, fallback?: SortClause): SortClause[];
91
+
85
92
  type AnyHookFn = (args: any) => any;
86
93
  /**
87
94
  * Run a list of hook functions sequentially.
@@ -212,4 +219,4 @@ declare function defineGlobal<TDoc extends object>(config: GlobalConfig<TDoc>):
212
219
  */
213
220
  declare function defineConfig(config: DyrectedConfig): DyrectedConfig;
214
221
 
215
- export { AuthDocFields, CollectionConfig, DyrectedConfig, Field, GlobalConfig, InferDocShape, Prettify, type SetupPromptConfig, type SqlWhereResult, SystemDocFields, UploadDocFields, type WhereClause, type WhereOperator, type WhereOperatorName, defineCollection, defineConfig, defineGlobal, executeFieldAfterRead, executeFieldBeforeChange, generateAIPrompt, generateFreshSetupPrompt, normalizeConfig, parseMongoWhere, parseSqlWhere, runCollectionHooks };
222
+ export { AuthDocFields, CollectionConfig, DyrectedConfig, Field, GlobalConfig, InferDocShape, Prettify, type SetupPromptConfig, type SortClause, type SortDirection, type SqlWhereResult, SystemDocFields, UploadDocFields, type WhereClause, type WhereOperator, type WhereOperatorName, defineCollection, defineConfig, defineGlobal, executeFieldAfterRead, executeFieldBeforeChange, generateAIPrompt, generateFreshSetupPrompt, normalizeConfig, parseMongoWhere, parseSort, parseSqlWhere, runCollectionHooks };
package/dist/index.js CHANGED
@@ -983,6 +983,23 @@ function parseMongoWhere(where) {
983
983
  return buildClause(where);
984
984
  }
985
985
 
986
+ // src/utils/parse-sort.ts
987
+ var SORT_FIELD_PATTERN = /^([A-Za-z_][A-Za-z0-9_]*)(?:\s+(ASC|DESC))?$/i;
988
+ function parseSort(sort, fallback = { field: "createdAt", direction: "DESC" }) {
989
+ if (!sort) return [fallback];
990
+ const clauses = sort.split(",").map((part) => part.trim()).filter(Boolean).map((part) => {
991
+ const descByPrefix = part.startsWith("-");
992
+ const withoutPrefix = descByPrefix ? part.slice(1).trim() : part;
993
+ const match = withoutPrefix.match(SORT_FIELD_PATTERN);
994
+ if (!match) return null;
995
+ return {
996
+ field: match[1],
997
+ direction: descByPrefix || match[2]?.toUpperCase() === "DESC" ? "DESC" : "ASC"
998
+ };
999
+ }).filter((clause) => Boolean(clause));
1000
+ return clauses.length > 0 ? clauses : [fallback];
1001
+ }
1002
+
986
1003
  // src/index.ts
987
1004
  function defineCollection(config) {
988
1005
  return config;
@@ -1003,6 +1020,7 @@ export {
1003
1020
  generateFreshSetupPrompt,
1004
1021
  normalizeConfig,
1005
1022
  parseMongoWhere,
1023
+ parseSort,
1006
1024
  parseSqlWhere,
1007
1025
  runCollectionHooks
1008
1026
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dyrected/core",
3
- "version": "2.5.26",
3
+ "version": "2.5.28",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",